Score:0

Parse and enumerate all the fhir elements

tv flag

I am using the Firely nuget package to parse a Patient FHIR resource from a bundle. The keyValuePair.Value type is object and for complex fhir datatypes contains nested objects. How do I parse and extract all the fhir elements and its values to a csv format?

Is there an easier way to parse and enumerate the elements without having to typecast the resource first and then extract each individual element inside that resource?

string fhirBundle = GetFHIRBundleFromFile();

FhirJsonParser fhirJsonParser = new FhirJsonParser();
Bundle bundle = fhirJsonParser.Parse<Bundle>(fhirBundle);

foreach (var entry in bundle.Entry)
{
    switch (entry.Resource)
    {
        case Patient:
            Patient patient = (Patient)entry.Resource;
            foreach (KeyValuePair<string, object> keyValuePair in patient)
                  Console.WriteLine(keyValuePair.Key + ": " + keyValuePair.Value.ToString());
             
            break;
        default:
            Console.WriteLine("Resource is not of type Patient")   
            break;
    }
}
 
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.