Use of FHIRPath.API not returning results as expected
I have been struggling sometime with trying to take a FHIR Bundle Response, extract the "entry.resourceType", extract the MRN and Name from the Patient FHIR Response...
Going through learning.intersystems.com, it suggested that I try using fhirPathAPI to parse and search my response for certain values, however I am not sure my syntax is correct. Using the AI code, it suggested to set my tree = "Bundle.entry.resource.resourceType"
ClassMethod Transform(source As HS.FHIRServer.Interop.Response, target As osuwmc.Epic.FHIR.DataStructures.PatientSearch.Record) As%Status
{
Set tSC=$$$OKset tQuickStream = ##Class(HS.SDA3.QuickStream).%OpenId(source.QuickStreamId)
set tRawJSON = ##Class(%Library.DynamicObject).%FromJSON(tQuickStream)
set fhirVersion = $lb("hl7.fhir.r4.core@4.0.1")
set fhirPathAPI = ##class(HS.FHIRPath.API).getInstance(fhirVersion)
set tree = fhirPathAPI.parse("Bundle.entry.resource.resourceType")
do fhirPathAPI.evaluate(tRawJSON, tree, .OUTPUT)
$$$TRACE("FHIRResponseToPatient Transform: FHIR resource type: "_OUTPUT)
return tSC
}however, nothing is returned, but I do see it within the raw JSON that there is an Entry within the Bundle message...
{"resourceType":"Bundle","type":"searchset","total":1,"link":[{"relation":"self","url":"https://xxxxxxxxxxxxxx/fhir-poc/api/FHIR/R4/Patient?identifier=OSUMRN|xxxxxxxxxxx"}],"entry":[{"link":[{"relation":"self","url":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient/xxxxxxxxxxxxxx"}],"fullUrl":"https://ihismufhirnp.osumc.edu/fhir-poc/api/FHIR/R4/Patient/xxxxxxxxxxxxxx","resource":{"resourceType":"Patient","id":"xxxxxxxxxxxxxx","extension":[{"valueCodeableConcept":{"coding":[{"system":"xxxx","code":"male","display":"male"}]},"url":"http://xxxxxxxxxxxxxx/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://xxxxxxxxxxxxxx/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://xxxxxxxxxxxxxx/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":"OSRXRLK0HT3BTSZ"},{"use":"usual","type":{"text":"EPI"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.5.737384.0","value":"E5187"},{"use":"usual","type":{"text":"EXTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.698084","value":"Z5152089"},{"use":"usual","type":{"text":"FHIR"},"system":"http://xxxxxxxxxxxxxx/FHIR/StructureDefinition/patient-dstu2-fhir-id","value":"T2JMC02.7EzU1Fy7Yne0Uo2qv78rgw81tU41q3T2Egc4B"},{"use":"usual","type":{"text":"FHIR STU3"},"system":"http://xxxxxxxxxxxxxx/FHIR/StructureDefinition/patient-fhir-id","value":"xxxxxxxxxxxxxx"},{"use":"usual","type":{"text":"INTERNAL"},"system":"urn:oid:1.2.840.114350.1.13.172.3.7.2.698084","value":" Z5152089"},{"use":"usual","type":{"text":"OSUMRN"},"system":"urn:oid:1.2.840.114350.1.13.172.2.7.5.737384.100","value":"415013564"}],"active":true,"name":[{"use":"official","text":"xxxxx xxxxxx","family":"xxxxxxxx","given":["xxxxx"]},{"use":"usual","text":"xxxx xcxxxx","family":"xxxxxx","given":["xxxxxx"]}],"gender":"male","birthDate":"1956-04-04","deceasedBoolean":false,"managingOrganization":{"reference":"Organization/e1waNSScbiPHZpqWn-ohD0w3","display":"xxxxxxxxxxx"}},"search":{"mode":"match"}}]}
set tree = fhirPathAPI.parse("Bundle.total")I can get the total number of records returned.
How do I get the entry level tree, then iterate through identity and name to get the values I need? I seem not to be able to find any examples or clear documentation on how to handle FHIR responses if you are not hosting the repository but getting data from one.
Comments
I ended up taking the QuickStream response, and creating a dynamic object from the JSON in the quick stream to parse it apart.