Hi I've been trying to fathom this all day and frankly it's beyond me.
So I've got some json response from a firely c# call and I want to get certain elements into a nice list of objects that are easier to handle and display the data back to the user.
My object
public class eReferral
{
public string Reference { get; set; }
public string Priority { get; set; }
public string Specialty { get; set; }
public string Patient { get; set; }
}
The json
{
"meta": {
"profile": [
"https://fhir.nhs.uk/STU3/StructureDefinition/eRS-FetchWorklist-List-1"
]
},
"resourceType": "List",
"contained": [
{
"id": "Practitioner-021600556514",
"meta": {
"profile": [
"https://fhir.nhs.uk/STU3/StructureDefinition/eRS-Practitioner-1"
]
},
"resourceType": "Practitioner",
"identifier": [
{
"system": "http://fhir.nhs.net/Id/sds-user-id",
"value": "021600556514"
}
]
},
{
"id": "Patient-9462979626",
"meta": {
"profile": [
"https://fhir.nhs.uk/STU3/StructureDefinition/eRS-Patient-1"
]
},
"resourceType": "Patient",
"identifier": [
{
"system": "http://fhir.nhs.net/Id/nhs-number",
"value": "9462979626"
}
]
},
{
"id": "Patient-1000000001",
"meta": {
"profile": [
"https://fhir.nhs.uk/STU3/StructureDefinition/eRS-Patient-1"
]
},
"resourceType": "Patient",
"identifier": [
{
"system": "http://fhir.nhs.net/Id/nhs-number",
"value": "1000000001"
}
]
}
],
"status": "current",
"mode": "snapshot",
"entry": [
{
"extension": [
{
"extension": [
{
"url": "priority",
"valueCodeableConcept": {
"coding": [
{
"system": "https://fhir.nhs.uk/STU3/CodeSystem/eRS-Priority-1",
"code": "ROUTINE"
}
]
}
},
{
"url": "specialty",
"valueCodeableConcept": {
"coding": [
{
"system": "_baseUrl_/STU3/CodeSystem/SPECIALTY",
"code": "CARDIOLOGY"
}
]
}
},
{
"url": "patient",
"valueReference": {
"reference": "#Patient-9462979626"
}
},
{
"url": "eReferralPathwayStart",
"valueDateTime": "2021-09-03T14:09:15.297Z"
},
{
"url": "clinicalInfoPrinted",
"valueBoolean": false
},
{
"url": "requestContextStatus",
"valueCodeableConcept": {
"coding": [
{
"system": "https://fhir.nhs.uk/STU3/CodeSystem/eRS-RequestContextStatus-1",
"code": "NEVER_REVIEWED",
"display": "Never Reviewed"
}
]
}
},
{
"url": "clinicalInfoFirstSubmitted",
"valueDateTime": "2021-09-03T14:09:15.297Z"
},
{
"url": "referralType",
"valueCodeableConcept": {
"coding": [
{
"system": "https://fhir.nhs.uk/STU3/CodeSystem/eRS-ReferralType-1",
"code": "TRIAGE_DEFERRAL"
}
]
}
},
{
"url": "service",
"valueReference": {
"identifier": {
"system": "http://fhir.nhs.net/Id/ers-service",
"value": "11012"
},
"display": "Excellent Cardiology Business Service 12"
}
}
],
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-eRS-ReferralsforReview-WorkListItem-1"
}
],
"item": {
"reference": "ReferralRequest/000000070002"
}
},
{
"extension": [
{
"extension": [
{
"url": "priority",
"valueCodeableConcept": {
"coding": [
{
"system": "https://fhir.nhs.uk/STU3/CodeSystem/eRS-Priority-1",
"code": "ROUTINE"
}
]
}
},
{
"url": "specialty",
"valueCodeableConcept": {
"coding": [
{
"system": "_baseUrl_/STU3/CodeSystem/SPECIALTY",
"code": "CARDIOLOGY"
}
]
}
},
{
"url": "patient",
"valueReference": {
"reference": "#Patient-1000000001"
}
},
{
"url": "allocatedClinician",
"valueReference": {
"reference": "#Practitioner-021600556514"
}
},
{
"url": "eReferralPathwayStart",
"valueDateTime": "2021-09-03T14:09:11.381Z"
},
{
"url": "clinicalInfoPrinted",
"valueBoolean": false
},
{
"url": "requestContextStatus",
"valueCodeableConcept": {
"coding": [
{
"system": "https://fhir.nhs.uk/STU3/CodeSystem/eRS-RequestContextStatus-1",
"code": "NEVER_REVIEWED",
"display": "Never Reviewed"
}
]
}
},
{
"url": "clinicalInfoFirstSubmitted",
"valueDateTime": "2021-09-03T14:09:11.022Z"
},
{
"url": "clinicalInfoLastUpdated",
"valueDateTime": "2021-09-03T14:09:12.573Z"
},
{
"url": "appointmentStart",
"valueDateTime": "2021-09-05T15:09:03.971Z"
},
{
"url": "referralType",
"valueCodeableConcept": {
"coding": [
{
"system": "https://fhir.nhs.uk/STU3/CodeSystem/eRS-ReferralType-1",
"code": "APPOINTMENT"
}
]
}
}
],
"url": "https://fhir.nhs.uk/STU3/StructureDefinition/Extension-eRS-ReferralsforReview-WorkListItem-1"
}
],
"item": {
"reference": "ReferralRequest/000000070001"
}
}
]
}
Currently I've got this.
var response = await _fhirClient.OperationAsync(new Uri(EndPointUrl + "FHIR/STU3/ReferralRequest"), "ers.fetchworklist", paramResource);
var eReferals = new List<eReferral>();
if (response != null)
{
var patientNode = FhirJsonNode.Parse(await response.ToJsonAsync());
var use = patientNode.Children("entry").Children("extension").ToList();
foreach(var x in use)
{
eReferals.Add(new eReferral
{
Priority = x["extension[0]"]
})
}
}
return eReferals;
However I don't know how to referance and get the specific elements e.g "url" : "priority" and get the object at that point.
I might be doing this all wrong and there is a much better way to get the various elements however I've been round the block trying to do this - with a few methods and I'm non the wiser at the end.
Your operation call results in a List resource, where the entries are (references to) ReferralRequest resources. Each entry seems to have a complex extension with more details about the referral request, and from your question/example it looks like you want to create eReferral objects that have the reference value of the ReferralRequest as well as the details for the Patient, specialty and priority from the extension.
If that is the correct assumption, what I would advice is to work with the List resource structure, instead of converting it to json and then back to a structure. When you know the List model, you can access its properties including the extensions. Here's an example where I extract the values that you mentioned:
I do want to add an extra remark, but do not know if you have any control over this: it seems that for the Patient resources, the NHS number is integrated into the technical id. This kind of adding PII to technical identities of FHIR resources is highly discouraged.