async fn run_operation_post_org(
    server_handle: &dyn ServerHandle,
    operation_state: ServerOperationIterationState<ServerOperationIterationStarting>,
    org: SampleResource,
) -> std::result::Result<
    ServerOperationIterationState<ServerOperationIterationSucceeded>,
    ServerOperationIterationState<ServerOperationIterationFailed>,
> {
    let url = create_org_url(server_handle);

    /*
     * TODO Per the FHIR spec, POST "SHALL" ignore IDs in resources,
     * so any later GETs using the ID in the JSON source would fail.
     * Once I want to start testing GET /Organization (or whatever),
     * I'll have to ensure that my POSTs catch and store the IDs of the resources,
     * as they're created.
     * Also: Spark noncompliantly throws an error due to the ID being in the
     * resource, so I need to strip that out here, too.
     */
    let org = server_handle.plugin().fudge_sample_resource(org);

    let org_metadata = &org.metadata.clone();
    let org_string = match serde_json::to_string(&org.resource_json) {
        Ok(org_string) => org_string,
        Err(err) => {
            return Err(operation_state
                .completed()
                .failed(eyre!(format!("{}", err))));
        }
    };

    let client = match server_handle.client() {
        Ok(client) => client,
        Err(err) => {
            return Err(operation_state
                .completed()
                .failed(eyre!(format!("{}", err))));
        }
    };

    let request_builder = server_handle
        .request_builder(client, http::Method::POST, url.clone())
        .header("Content-Type", "application/fhir+json")
        .body(org_string);
    let response = request_builder
        .send()
        .instrument(trace_span!("POST request", %url))
        .await;

    let operation_state = operation_state.completed();

    match response {
        Ok(response) => {
            let response_status = response.status();
            if !response_status.is_success() {
                let response_body = match response.text().await {
                    Ok(response_body) => response_body,
                    Err(err) => format!("Unable to retrieve response body due to error: '{}'", err),
                };

                let error = eyre!(
                    "The POST to '{}' failed for '{:?}', with status '{}' and body: '{}'",
                    &url,
                    org_metadata,
                    response_status,
                    response_body
                );
                let state = operation_state.failed(error);
                return Err(state);
            }

            // TODO more checks needed
            Ok(operation_state.succeeded())
        }
        Err(err) => Err(operation_state.failed(eyre!(format!("{}", err)))),
    }
}
/// Runs a single iteration of the `POST /Organization` operation and verifies its result, logging out any
/// faults that were found.
///
/// Parameters:
/// * `server_handle`: the [ServerHandle] for the server implementation instance being tested
/// * `operation_state`: the initial state machine for this operation iteration
/// * `org`: the sample `Organization` resource to test with
///
/// Returns the final [ServerOperationIterationState] containing information about the operation's
/// success or failure.
Runs a single iteration of the `POST /Organization` operation and verifies its result, logging out any
faults that were found.



Returns the final [ServerOperationIterationState] containing information about the operation's
success or failure.
Runs a single iteration of the ` POST / Organization ` operation and verifies its result logging out any faults that were found . Returns the final [ ServerOperationIterationState ] containing information about the operation ' s success or failure .
async fn run_operation_post_org(
    server_handle: &dyn ServerHandle,
    operation_state: ServerOperationIterationState<ServerOperationIterationStarting>,
    org: SampleResource,
) -> std::result::Result<
    ServerOperationIterationState<ServerOperationIterationSucceeded>,
    ServerOperationIterationState<ServerOperationIterationFailed>,
> {
    let url = create_org_url(server_handle);
    /*
     * TODO Per the FHIR spec, POST "SHALL" ignore IDs in resources,
     * so any later GETs using the ID in the JSON source would fail.
     * Once I want to start testing GET /Organization (or whatever),
     * I'll have to ensure that my POSTs catch and store the IDs of the resources,
     * as they're created.
     * Also: Spark noncompliantly throws an error due to the ID being in the
     * resource, so I need to strip that out here, too.
     */
    let org = server_handle.plugin().fudge_sample_resource(org);
    let org_metadata = &org.metadata.clone();
    let org_string = match serde_json::to_string(&org.resource_json) {
        Ok(org_string) => org_string,
        Err(err) => {
            return Err(operation_state
                .completed()
                .failed(eyre!(format!("{}", err))));
        }
    };
    let client = match server_handle.client() {
        Ok(client) => client,
        Err(err) => {
            return Err(operation_state
                .completed()
                .failed(eyre!(format!("{}", err))));
        }
    };
    let request_builder = server_handle
        .request_builder(client, http::Method::POST, url.clone())
        .header("Content-Type", "application/fhir+json")
        .body(org_string);
    let response = request_builder
        .send()
        .instrument(trace_span!("POST request", %url))
        .await;
    let operation_state = operation_state.completed();
    match response {
        Ok(response) => {
            let response_status = response.status();
            if !response_status.is_success() {
                let response_body = match response.text().await {
                    Ok(response_body) => response_body,
                    Err(err) => format!("Unable to retrieve response body due to error: '{}'", err),
                };
                let error = eyre!(
                    "The POST to '{}' failed for '{:?}', with status '{}' and body: '{}'",
                    &url,
                    org_metadata,
                    response_status,
                    response_body
                );
                let state = operation_state.failed(error);
                return Err(state);
            }
            // TODO more checks needed
            Ok(operation_state.succeeded())
        }
        Err(err) => Err(operation_state.failed(eyre!(format!("{}", err)))),
    }
}
async fn run_operation_post_org ( server_handle : & dyn ServerHandle , operation_state : ServerOperationIterationState < ServerOperationIterationStarting > , org : SampleResource , ) -> std :: result :: Result < ServerOperationIterationState < ServerOperationIterationSucceeded > , ServerOperationIterationState < ServerOperationIterationFailed > , > { let url = create_org_url ( server_handle ) ; /*
     * TODO Per the FHIR spec, POST "SHALL" ignore IDs in resources,
     * so any later GETs using the ID in the JSON source would fail.
     * Once I want to start testing GET /Organization (or whatever),
     * I'll have to ensure that my POSTs catch and store the IDs of the resources,
     * as they're created.
     * Also: Spark noncompliantly throws an error due to the ID being in the
     * resource, so I need to strip that out here, too.
     */ let org = server_handle . plugin ( ) . fudge_sample_resource ( org ) ; let org_metadata = & org . metadata . clone ( ) ; let org_string = match serde_json :: to_string ( & org . resource_json ) { Ok ( org_string ) => org_string , Err ( err ) => { return Err ( operation_state . completed ( ) . failed ( eyre ! ( format ( " " err ) ) ) ) ; } } ; let client = match server_handle . client ( ) { Ok ( client ) => client , Err ( err ) => { return Err ( operation_state . completed ( ) . failed ( eyre ! ( format ( " " err ) ) ) ) ; } } ; let request_builder = server_handle . request_builder ( client , http :: Method :: POST , url . clone ( ) ) . header ( " " , " " ) . body ( org_string ) ; let response = request_builder . send ( ) . instrument ( trace_span ! ( " " url ) ) . await ; let operation_state = operation_state . completed ( ) ; match response { Ok ( response ) => { let response_status = response . status ( ) ; if ! response_status . is_success ( ) { let response_body = match response . text ( ) . await { Ok ( response_body ) => response_body , Err ( err ) => format ! ( " " err ) , } ; let error = eyre ! ( " " url org_metadata response_status response_body ) ; let state = operation_state . failed ( error ) ; return Err ( state ) ; } // TODO more checks needed Ok ( operation_state . succeeded ( ) ) } Err ( err ) => Err ( operation_state . failed ( eyre ! ( format ( " " err ) ) ) ) , } }
Runs a single iteration of the `POST /Organization` operation and verifies its result, logging out any
faults that were found.
Runs a single iteration of the ` POST / Organization ` operation and verifies its result logging out any faults that were found .
server_handle
&dyn ServerHandle
operation_state
ServerOperationIterationState<ServerOperationIterationStarting>
org
SampleResource
server_handle
&dyn ServerHandle
operation_state
ServerOperationIterationState<ServerOperationIterationStarting>
org
SampleResource