var query = new SearchParams()
.Where("name=" + patientName)
.Include("Patient:general-practitioner");if (entry.Resource.ResourceType == ResourceType.Patient)
{
// build the string with patient information
}var bundle = client.Search<Patient>(query);
Soulakas DImitris"
No problem, I hope I can make things clearer for you.
In FHIR, resources link together through references. These references are basically pointers to the location where more information can be found.
So in Patient, if you look at the definition in the specs, there is the field 'generalPractitioner', which is of type Reference and is 0..*.
This means that in the API the Patient.GeneralPractitioner is a List of references.
If you lookup the Reference type in the specs, you see that the structure offers a field for the 'reference' string itself, but also a 'display' value.
Now you're in luck if your server has stored that display value, because that would mean you can use that value to show the display name, without the need to include the complete Practitioner or Organization resource in your search. You could just use:
var first_care_provider = p.GeneralPractitioner.First().Display;But more often the reference will just have the reference string, and you will need to get the extra data from the server.
This can be done in two ways. The first is to include the general-practitioner in your search, as already described above.
In your loop through the entries, you will need to take a look at p.GeneralPractitioner.First().Reference. Then you will need to look in the Bundle to find this reference inside one of the fullUrls of the entries. If you find it, then you can look at that resource information and get the name of the Organization or Practitioner from it.
Here's a code example for that, but note that I only look at the first care provider that might be in the list and put in only a couple of safeguards against empty data:
foreach (var entry in bundle.Entry)
{
var my_text = "";
if (entry.Resource.ResourceType == ResourceType.Patient)
{
var p = (Patient)entry.Resource;
var GP_name = "";
if (p.GeneralPractitioner.Count > 0)
{
// this gets the reference and converts it to an absolute one if necessary
var GP_id = p.GeneralPractitioner.First().GetAbsoluteUriForReference(entry.GetResourceLocation().AbsoluteUri);
// find the referenced resource in the bundle
var first_GP_resource = bundle.FindEntry(GP_id).First().Resource;
if (first_GP_resource.ResourceType == ResourceType.Practitioner)
{
var prac = (Practitioner)first_GP_resource;
GP_name = "Dr. " + prac.Name.First().Family;
}
else if (first_GP_resource.ResourceType == ResourceType.Organization)
{
var org = (Organization)first_GP_resource;
GP_name = "organization " + org.Name;
}
}
my_text = "id: " + p.Id + " | " + "surname: " + p.Name.First().Family + " | " + "name: " + p.Name.First().Given.FirstOrDefault() + " | " +
"birthdate: " + p.BirthDate + " | " + "gender: " + p.Gender + " | " + "careprovider: " + GP_name + "\r\n";
}
}foreach (var entry in bundle.Entry)
{
var my_text = "";
var p = (Patient)entry.Resource;
var GP_name = "";
if (p.GeneralPractitioner.Count > 0)
{
var first_GP_resource = client.Read<Practitioner>(p.GeneralPractitioner.First().Reference);
GP_name = "Dr. " + first_GP_resource.Name.First().Family;
}
my_text = "id: " + p.Id + " | " + "surname: " + p.Name.First().Family + " | " + "name: " + p.Name.First().Given.FirstOrDefault() + " | " +
"birthdate: " + p.BirthDate + " | " + "gender: " + p.Gender + " | " + "careprovider: " + GP_name + "\r\n";
}