fn parse_sample_resources(sample_file: &Path) -> Result<Vec<SampleResource>> {
    let file = File::open(sample_file)?;
    let reader = BufReader::new(file);

    let bundle: serde_json::Value = serde_json::from_reader(reader)?;
    let entries = match bundle["entry"].as_array() {
        Some(entries) => Ok(entries.to_owned()),
        None => Err(eyre!(
            "Unable to parse sample Bundle from '{:?}'.",
            sample_file
        )),
    };

    let entries: Vec<SampleResource> = entries?
        .into_iter()
        .map(|e| e["resource"].to_owned())
        .map(|e| SampleResource {
            metadata: SampleResourceMetadata {
                source_file: sample_file.to_path_buf(),
                resource_type: e
                    .get("resourceType")
                    .expect("Sample resource missing resourceType.")
                    .as_str()
                    .expect("Unexpected resourceType type.")
                    .to_owned(),
                source_id: e
                    .get("id")
                    .expect("Sample resource missing ID.")
                    .as_str()
                    .expect("Unexpected id type.")
                    .to_owned(),
            },
            resource_json: e,
        })
        .collect();

    Ok(entries)
}
/// Returns the [SampleResource]s that can be extracted from the specified FHIR `Bundle`.
///
/// Note that this  will read the entire `Bundle` into memory. This works for our needs as Synthea does
/// not tend to generate any one file that is too large to fit in memory; it mostly generates many small
/// files, instead.
///
/// Parameters:
/// * `sample_file`: the `Bundle`-containing file to parse
Returns the [SampleResource]s that can be extracted from the specified FHIR `Bundle`.
Note that this  will read the entire `Bundle` into memory. This works for our needs as Synthea does
not tend to generate any one file that is too large to fit in memory; it mostly generates many small
files, instead.

`sample_file`: the `Bundle`-containing file to parse
Returns the [ SampleResource ] s that can be extracted from the specified FHIR ` Bundle ` . Note that this will read the entire ` Bundle ` into memory . This works for our needs as Synthea does not tend to generate any one file that is too large to fit in memory ; it mostly generates many small files instead . ` sample_file ` : the ` Bundle ` - containing file to parse
fn parse_sample_resources(sample_file: &Path) -> Result<Vec<SampleResource>> {
    let file = File::open(sample_file)?;
    let reader = BufReader::new(file);
    let bundle: serde_json::Value = serde_json::from_reader(reader)?;
    let entries = match bundle["entry"].as_array() {
        Some(entries) => Ok(entries.to_owned()),
        None => Err(eyre!(
            "Unable to parse sample Bundle from '{:?}'.",
            sample_file
        )),
    };
    let entries: Vec<SampleResource> = entries?
        .into_iter()
        .map(|e| e["resource"].to_owned())
        .map(|e| SampleResource {
            metadata: SampleResourceMetadata {
                source_file: sample_file.to_path_buf(),
                resource_type: e
                    .get("resourceType")
                    .expect("Sample resource missing resourceType.")
                    .as_str()
                    .expect("Unexpected resourceType type.")
                    .to_owned(),
                source_id: e
                    .get("id")
                    .expect("Sample resource missing ID.")
                    .as_str()
                    .expect("Unexpected id type.")
                    .to_owned(),
            },
            resource_json: e,
        })
        .collect();
    Ok(entries)
}
fn parse_sample_resources ( sample_file : & Path ) -> Result < Vec < SampleResource > > { let file = File :: open ( sample_file ) ? ; let reader = BufReader :: new ( file ) ; let bundle : serde_json :: Value = serde_json :: from_reader ( reader ) ? ; let entries = match bundle [ " " ] . as_array ( ) { Some ( entries ) => Ok ( entries . to_owned ( ) ) , None => Err ( eyre ! ( " " sample_file ) ) , } ; let entries : Vec < SampleResource > = entries ? . into_iter ( ) . map ( | e | e [ " " ] . to_owned ( ) ) . map ( | e | SampleResource { metadata : SampleResourceMetadata { source_file : sample_file . to_path_buf ( ) , resource_type : e . get ( " " ) . expect ( " " ) . as_str ( ) . expect ( " " ) . to_owned ( ) , source_id : e . get ( " " ) . expect ( " " ) . as_str ( ) . expect ( " " ) . to_owned ( ) , } , resource_json : e , } ) . collect ( ) ; Ok ( entries ) }
Returns the [SampleResource]s that can be extracted from the specified FHIR `Bundle`.
Returns the [ SampleResource ] s that can be extracted from the specified FHIR ` Bundle ` .
sample_file
&Path
sample_file
&Path