1

I tried to get the element like Identifier, Location, Period, ... But not working. How can I get it? My code follow:

    static void Main(string[] args)
    {
        //The fhir server end point address      
        string ServiceRootUrl = "http://stu3.test.pyrohealth.net/fhir";
        //Create a client to send to the server at a given endpoint.
        var FhirClient = new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl);
        // increase timeouts since the server might be powered down
        FhirClient.Timeout = (60 * 1000);

        Console.WriteLine("Press any key to send to server: " + ServiceRootUrl);
        Console.WriteLine();
        Console.ReadKey();
        try
        {
            //Attempt to send the resource to the server endpoint
            Hl7.Fhir.Model.Bundle ReturnedSearchBundle = FhirClient.Search<Hl7.Fhir.Model.Patient>(new string[] { "status=planned" });
            Console.WriteLine(string.Format("Found: {0} Fhirman patients.", ReturnedSearchBundle.Total.ToString()));
            Console.WriteLine("Their logical IDs are:");
            foreach (var Entry in ReturnedSearchBundle.Entry)
            {
                Console.WriteLine("ID: " + Entry.Resource.Id);
                Console.WriteLine("ID2: " + Entry.Identifier);
            }
            Console.WriteLine();
        }
        catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec)
        {
            //Process any Fhir Errors returned as OperationOutcome resource
            Console.WriteLine();
            Console.WriteLine("An error message: " + FhirOpExec.Message);
            Console.WriteLine();
            string xml = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(FhirOpExec.Outcome);
            XDocument xDoc = XDocument.Parse(xml);
            Console.WriteLine(xDoc.ToString());
        }
        catch (Exception GeneralException)
        {
            Console.WriteLine();
            Console.WriteLine("An error message: " + GeneralException.Message);
            Console.WriteLine();
        }
        Console.WriteLine("Press any key to end.");
        Console.ReadKey();
    }

The result is System.Collections.Generic.List`1[Hl7.Fhir.Model.Identifier]

Useme Alehosaini
  • 2,998
  • 6
  • 18
  • 26
quaaan
  • 17
  • 4
  • That means you got a list of identifiers and you’ll have to go through the list to get the data. What does the list contain? – Sami Kuhmonen Dec 20 '20 at 08:18
  • Are you getting any exceptions? Did you step through code to determine where you are failing? put the try block around the line where you create FhirClient incase the constructor is failing. If you are not getting any exceptions than probably the patient isn't in the database. It is possible you are using the wrong database. – jdweng Dec 20 '20 at 12:13

1 Answers1

2

Your search is for a Patient, which does not have a 'status' search parameter nor field. The server you use eliminates the parameter for the search, and sends back a Bundle with Patients in the entries - this is according to the FHIR specification.

The first line in your foreach (Console.WriteLine("ID: " + Entry.Resource.Id);) will output the technical id of the resource. Since there is no Identifier field on the Entry, I assume your second one actually reads Entry.Resource.Identifier. The Patient.identifier field is a 0..* list of Identifiers, so you would have to take one of them. The Identifier datatype in turn is a complex datatype, with usually a system and value field filled in. So, you could do something like this - assuming the Identifier list contains an item:

var patient = (Patient)Entry.Resource;
Console.WriteLine($"Patient identifier: {patient.Identifier[0].System} {patient.Identifier[0].Value}");
Mirjam Baltus
  • 2,035
  • 9
  • 13
  • Thanks for the response. One more, I replaced "status=planned" by "2018-03-16&status=planned" but not work , so what is correct syntax? Thanks – quaaan Dec 21 '20 at 04:50
  • A patient does not have a status, so you cannot search for that. You can search for name, birthdate, address, etc. depending on what the server supports. See http://hl7.org/fhir/STU3/patient.html#search for the list of standard search parameters. – Mirjam Baltus Dec 21 '20 at 08:02
  • Sorry I mean with Encounter, replaced "status=planned" by "date=2018-03-16&status=planned" – quaaan Dec 21 '20 at 09:32
  • That syntax is correct, but the server you mention in your code does not have any results for that search. Check the Bundle.total before you try to do things with the entries. – Mirjam Baltus Dec 21 '20 at 13:27