Question
· 14 hr ago

FHIR Patient Resource Response does not map to FHIRModel.R4.Patient

I am receiving a FHIR response bundle back with a resource of patient. Using fromDao, I attempted to take the stream and put it into FHIRModel.R4.Patient but it is not mapping correctly. When I attempt to take FHIRModel.R4.Patient and write it out using toString(), all I am seeing is the resource

{"resourceType":"Patient"}

so the response is not mapping correctly to FHIRModel.R4.Patient. How have others handled this? Do I need to translate it to an SDA since it does fit the model format?

Product version: IRIS 2024.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2024.1 (Build 267_2U) Tue Apr 30 2024 16:06:39 EDT [HealthConnect:7.2.0-1.r1]
Discussion (4)2
Log in or sign up to continue

Hello @Scott Roth 

I directly import JSON via fromDao method and It works for me. Did you get any errors while importing?

Set patient = {"resourceType":"Patient","id":"example","text":{"status":"generated","div":"<div xmlns=\"http://www.w3.org/1999/xhtml\">John Doe</div>"},"identifier":[{"use":"usual","type":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/v2-0203","code":"MR","display":"Medical Record Number"}]},"system":"http://hospital.smarthealth.org","value":"123456"}],"active":true,"name":[{"use":"official","family":"Doe","given":["John"]}],"telecom":[{"system":"phone","value":"+1 555-123-4567","use":"mobile"},{"system":"email","value":"john.doe@example.com","use":"home"}],"gender":"male","birthDate":"1980-01-01","address":[{"use":"home","line":["123 Main Street"],"city":"Anytown","state":"CA","postalCode":"90210","country":"USA"}]}
Set r4Patient = ##class(HS.FHIRModel.R4.Patient).fromDao(patient)
Write r4Patient.toString()

I attempted that..

DEVCLIN>set patient = {"resourceType":"Bundle","type":"searchset","total":1,"link":[{"relation":"self","url":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient?identifier=OSUMRN|415012765"}],"entry":[{"link":[{"relation":"self","url":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient/efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3"}],"fullUrl":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient/efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3","resource":{"resourceType":"Patient","id":"efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3","extension":[{"valueCodeableConcept":{"coding":[{"system":"urn:oid:1.2.840.114350.1.13.172.3.7.10.698084.130.768080.39128","code":"male","display":"male"}]},"url":"http://open.epic.com/FHIR/StructureDefinition/extension/legal-sex"},{"valueCodeableConcept":{"coding":[{"system":"urn:oid:1.2.840.114350.1.13.172.3.7.10.698084.130.768080.35144","code":"male","display":"male"}]},"url":"http://open.epic.com/FHIR/StructureDefinition/extension/sex-for-clinical-use"},{"extension":[{"valueCoding":{"system":"http://terminology.hl7.org/CodeSystem/v3-NullFlavor","code":"UNK","display":"Unknown"},"url":"ombCategory"},{"valueString":"Unknown","url":"text"}],"url":"http://hl7.org/fhir/us/core/StructureDefinition/us-core-race"},{"extension":[{"valueString":"Unknown","url":"text"}],"url":"http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity"},{"valueCode":"248153007","url":"http://hl7.org/fhir/us/core/StructureDefinition/us-core-sex"},{"valueCodeableConcept":{"coding":[{"system":"http://loinc.org","code":"LA29518-0","display":"he/him/his/his/himself"}]},"url":"http://open.epic.com/FHIR/StructureDefinition/extension/calculated-pronouns-to-use-for-text"}],"identifier":[{"use":"usual","type":{"text":"CEID"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.3.688884.100","value":"OSRDR3259GL4948"},{"use":"usual","type":{"text":"EPI"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.5.737384.0","value":"E4377"},{"use":"usual","type":{"text":"EXTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.698084","value":"Z5151278"},{"use":"usual","type":{"text":"FHIR"},"system":"http://open.epic.com/FHIR/StructureDefinition/patient-dstu2-fhir-id","value":"TCPNfJueZx8Fjvm4g.lzD.vutNNRpQMfDXDRXJVlKkpcB"},{"use":"usual","type":{"text":"FHIR STU3"},"system":"http://open.epic.com/FHIR/StructureDefinition/patient-fhir-id","value":"efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3"},{"use":"usual","type":{"text":"INTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.698084","value":"  Z5151278"},{"use":"usual","type":{"text":"OSUMRN"},"system":"urn:oid:1.2.840.114350.1.13.172.2.7.5.737384.100","value":"415012765"},{"use":"usual","type":{"text":"WPRINTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.878082","value":"2545814"}],"active":true,"name":[{"use":"official","text":"Case Stontest","family":"Stontest","given":["Case"]},{"use":"usual","text":"Case Stontest","family":"Stontest","given":["Case"]}],"gender":"male","birthDate":"1995-02-27","deceasedBoolean":false,"managingOrganization":{"reference":"Organization/eQi5EjSoIVOTHT0BXoZ4mNA3","display":"WILSON HEALTH"}},"search":{"mode":"match"}}]}

DEVCLIN>set r4Patient = ##class(HS.FHIRModel.R4.Patient).fromDao(patient)

DEVCLIN>zwrite r4Patient.toString()
"{""resourceType"":""Bundle"",""link"":[{}]}"

DEVCLIN>

I tried that however the zrwrite r4Patient.toString() didn't properly parse out the transaction

DEVCLIN>set patient = {"resourceType":"Bundle","type":"searchset","total":1,"link":[{"relation":"self","url":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient?identifier=OSUMRN|415012765"}],"entry":[{"link":[{"relation":"self","url":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient/efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3"}],"fullUrl":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient/efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3","resource":{"resourceType":"Patient","id":"efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3","extension":[{"valueCodeableConcept":{"coding":[{"system":"urn:oid:1.2.840.114350.1.13.172.3.7.10.698084.130.768080.39128","code":"male","display":"male"}]},"url":"http://open.epic.com/FHIR/StructureDefinition/extension/legal-sex"},{"valueCodeableConcept":{"coding":[{"system":"urn:oid:1.2.840.114350.1.13.172.3.7.10.698084.130.768080.35144","code":"male","display":"male"}]},"url":"http://open.epic.com/FHIR/StructureDefinition/extension/sex-for-clinical-use"},{"extension":[{"valueCoding":{"system":"http://terminology.hl7.org/CodeSystem/v3-NullFlavor","code":"UNK","display":"Unknown"},"url":"ombCategory"},{"valueString":"Unknown","url":"text"}],"url":"http://hl7.org/fhir/us/core/StructureDefinition/us-core-race"},{"extension":[{"valueString":"Unknown","url":"text"}],"url":"http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity"},{"valueCode":"248153007","url":"http://hl7.org/fhir/us/core/StructureDefinition/us-core-sex"},{"valueCodeableConcept":{"coding":[{"system":"http://loinc.org","code":"LA29518-0","display":"he/him/his/his/himself"}]},"url":"http://open.epic.com/FHIR/StructureDefinition/extension/calculated-pronouns-to-use-for-text"}],"identifier":[{"use":"usual","type":{"text":"CEID"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.3.688884.100","value":"OSRDR3259GL4948"},{"use":"usual","type":{"text":"EPI"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.5.737384.0","value":"E4377"},{"use":"usual","type":{"text":"EXTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.698084","value":"Z5151278"},{"use":"usual","type":{"text":"FHIR"},"system":"http://open.epic.com/FHIR/StructureDefinition/patient-dstu2-fhir-id","value":"TCPNfJueZx8Fjvm4g.lzD.vutNNRpQMfDXDRXJVlKkpcB"},{"use":"usual","type":{"text":"FHIR STU3"},"system":"http://open.epic.com/FHIR/StructureDefinition/patient-fhir-id","value":"efz6cSnh6If5cehlzObXZuO7BwSc77oXLYSL-92FLdec3"},{"use":"usual","type":{"text":"INTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.698084","value":"  Z5151278"},{"use":"usual","type":{"text":"OSUMRN"},"system":"urn:oid:1.2.840.114350.1.13.172.2.7.5.737384.100","value":"415012765"},{"use":"usual","type":{"text":"WPRINTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.878082","value":"2545814"}],"active":true,"name":[{"use":"official","text":"Case Stontest","family":"Stontest","given":["Case"]},{"use":"usual","text":"Case Stontest","family":"Stontest","given":["Case"]}],"gender":"male","birthDate":"1995-02-27","deceasedBoolean":false,"managingOrganization":{"reference":"Organization/eQi5EjSoIVOTHT0BXoZ4mNA3","display":"WILSON HEALTH"}},"search":{"mode":"match"}}]}

DEVCLIN>set r4Patient = ##class(HS.FHIRModel.R4.Patient).fromDao(patient)

DEVCLIN>zwrite r4Patient.toString()
"{""resourceType"":""Bundle"",""link"":[{}]}"

DEVCLIN>

The HS.FHIRModel.R4.Patient class in  IRIS directly represents the FHIR R4 Patient resource as defined. When a FHIR Bundle is loaded using HS.FHIRModel.R4.Bundle.fromDao(), each resource in the bundle's entry.resource is automatically mapped to the correct HS.FHIRModel.R4.* subclass (e.g., Patient, Encounter, AllergyIntolerance) based on its resourceType. There’s no need for manual casting — the object model handles the typing internally.

here is the sample code

Set bundle={"resourceType":"Bundle","type":"searchset","total":3,"entry":[{"fullUrl":"https://example.org/fhir/Patient/patient-1","resource":{"resourceType":"Patient","id":"patient-1","name":[{"family":"Doe","given":["John"]}],"gender":"male","birthDate":"1985-02-15"},"search":{"mode":"match"}},{"fullUrl":"https://example.org/fhir/Encounter/encounter-1","resource":{"resourceType":"Encounter","id":"encounter-1","status":"finished","class":{"system":"http://terminology.hl7.org/CodeSystem/v3-ActCode","code":"AMB","display":"ambulatory"},"subject":{"reference":"Patient/patient-1"},"period":{"start":"2023-07-01T10:00:00Z","end":"2023-07-01T10:30:00Z"}},"search":{"mode":"include"}},{"fullUrl":"https://example.org/fhir/AllergyIntolerance/allergy-1","resource":{"resourceType":"AllergyIntolerance","id":"allergy-1","clinicalStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical","code":"active"}]},"verificationStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-verification","code":"confirmed"}]},"type":"allergy","category":["food"],"criticality":"high","code":{"coding":[{"system":"http://snomed.info/sct","code":"227493005","display":"Cashew nuts"}],"text":"Allergy to cashews"},"patient":{"reference":"Patient/patient-1"},"reaction":[{"manifestation":[{"coding":[{"system":"http://snomed.info/sct","code":"271807003","display":"Skin rash"}]}],"severity":"moderate"}]},"search":{"mode":"include"}}]}                                                                                             
set fhirModelBundle = ##class(HS.FHIRModel.R4.Bundle).fromDao(bundle)  
;
Zwrite fhirModelBundle.entry.list.size()
3
;
Zwrite fhirModelBundle.entry.list.get(0).toDao() ; patient
{"fullUrl":"https://example.org/fhir/Patient/patient-1","resource":{"resourceType":"Patient","id":"patient-1","name":[{"family":"Doe","given":["John"]}],"gender":"male","birthDate":"1985-02-15"},"search":{"mode":"match"}}  ; <DYNAMIC OBJECT>                        
;
Zwrite fhirModelBundle.entry.list.get(1).toDao() ; encounter
{"fullUrl":"https://example.org/fhir/Encounter/encounter-1","resource":{"resourceType":"Encounter","id":"encounter-1","status":"finished","class":{"system":"http://terminology.hl7.org/CodeSystem/v3-ActCode","code":"AMB","display":"ambulatory"},"subject":{"reference":"Patient/patient-1"},"period":{"start":"2023-07-01T10:00:00Z","end":"2023-07-01T10:30:00Z"}},"search":{"mode":"include"}}  ; <DYNAMIC OBJECT>                                                                                                                         
;
Zwrite fhirModelBundle.entry.list.get(2).toDao() ; Allergy
{"fullUrl":"https://example.org/fhir/AllergyIntolerance/allergy-1","resource":{"resourceType":"AllergyIntolerance","id":"allergy-1","clinicalStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical","code":"active"}]},"verificationStatus":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/allergyintolerance-verification","code":"confirmed"}]},"type":"allergy","category":["food"],"criticality":"high","code":{"coding":[{"system":"http://snomed.info/sct","code":"227493005","display":"Cashew nuts"}],"text":"Allergy to cashews"},"patient":{"reference":"Patient/patient-1"},"reaction":[{"manifestation":[{"coding":[{"system":"http://snomed.info/sct","code":"271807003","display":"Skin rash"}]}],"severity":"moderate"}]},"search":{"mode":"include"}}  ; <DYNAMIC OBJECT>