use of org.hl7.fhir.r4b.model.Observation in project kindling by HL7.
the class ADLImporter method execute.
private void execute() throws Exception {
// load config
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
adlConfig = builder.parse(new FileInputStream(config)).getDocumentElement();
// load ADL
builder = factory.newDocumentBuilder();
adl = builder.parse(new FileInputStream(source)).getDocumentElement();
check("root", adl.getNamespaceURI(), "http://schemas.openehr.org/v1", "Wrong namespace for ADL XML");
check("root", adl.getNodeName(), "archetype", "Wrong XML for ADL XML");
check("root", XMLUtil.getNamedChild(adl, "adl_version").getTextContent(), "1.4", "unsupported ADL version");
String id = XMLUtil.getFirstChild(XMLUtil.getNamedChild(adl, "archetype_id")).getTextContent().split("\\.")[1];
String baseType = XMLUtil.getNamedChild(XMLUtil.getNamedChild(adl, "definition"), "rm_type_name").getTextContent();
if (!baseType.equals("OBSERVATION"))
return;
// load texts from ontology
List<Element> set = new ArrayList<Element>();
Element ontology = XMLUtil.getNamedChild(adl, "ontology");
Element term_definitions = XMLUtil.getNamedChild(ontology, "term_definitions");
set.clear();
XMLUtil.getNamedChildren(term_definitions, "items", set);
for (Element item : set) {
processTextItem(item);
}
// create structure definition
StructureDefinition sd = new StructureDefinition();
sd.setId("netha-" + id);
sd.setUrl("http://hl7.org/fhir/StructureDefinition/" + sd.getId());
sd.setKind(StructureDefinitionKind.LOGICAL);
populateMetadata(set, sd);
// load data and protocol
Element definition = XMLUtil.getNamedChild(adl, "definition");
NodeTreeEntry root = new NodeTreeEntry();
root.typeName = XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent();
root.atCode = XMLUtil.getNamedChild(definition, "node_id").getTextContent();
root.name = generateToken(root.atCode, true);
sd.setName(root.name);
root.cardinality = readCardinality("root", XMLUtil.getNamedChild(definition, "occurrences"));
set.clear();
XMLUtil.getNamedChildren(definition, "attributes", set);
for (Element item : set) {
// we're actually skipping this level - we don't care about data protocol etc.
// XMLUtil.getNamedChild(XMLUtil.getNamedChild(item, "children"), "attributes");
Element attributes = item;
loadChildren(root.atCode, root, attributes);
}
dumpChildren("", root);
genElements(sd, root.name, root);
// save
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
System.out.println("done. saved as " + dest);
}
use of org.hl7.fhir.r4b.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7EncounterFHIRConversionTest method testEncounterReferencesObservationAndDiagnosis.
/**
* Testing Encounter correctly references Observation AND Diagnosis when both are present.
*/
@Test
void testEncounterReferencesObservationAndDiagnosis() throws IOException {
String hl7message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.6|\n" + "PID|||1234^^^^MR||DOE^JANE^|||F|||||||||||||||||||||\n" + "PV1|1|O|Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||\n" + "OBX|1|SN|24467-3^CD3+CD4+ (T4 helper) cells [#/volume] in Blood^LN||=^440|{Cells}/uL^cells per microliter^UCUM|649-1346 cells/mcL|L|||F\r" + "DG1|1|ICD10|^Ovarian Cancer|||||||||||||||||||||\r";
String json = ftv.convert(hl7message, OPTIONS);
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
assertThat(encounterResource).hasSize(1);
Encounter enc = (Encounter) encounterResource.get(0);
List<Reference> reasonRefs = enc.getReasonReference();
assertEquals(2, reasonRefs.size());
// Guess at the order of the references
Reference refObservation = reasonRefs.get(0);
Reference refCondition = reasonRefs.get(1);
// If guessed wrong, reverse them
if (!refObservation.getReference().contains("Observation")) {
refObservation = reasonRefs.get(1);
refCondition = reasonRefs.get(0);
}
assertTrue(refObservation.getReference().contains("Observation"));
assertTrue(refCondition.getReference().contains("Condition"));
}
use of org.hl7.fhir.r4b.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_content_test.
@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_content_test(String segment) {
String documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||TEXT||||201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + // Next three lines create an attachment
"OBX|1|TX|||ECHOCARDIOGRAPHIC REPORT||||||F|||202101010000|||\n" + "OBX|2|TX|||NORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH||||||F|||202101010000|||\n" + "OBX|3|TX|||HYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%||||||F|||202101010000|||\n";
DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
DocumentReference.DocumentReferenceContentComponent content = report.getContentFirstRep();
// Future TXA.3, currently always defaults to text/plain
assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
// TXA.7 date
assertThat(content.getAttachment().getCreationElement().toString()).containsPattern("2018-01-18T03:46:00");
assertThat(content.getAttachment().hasData()).isTrue();
String decodedData = new String(Base64.getDecoder().decode(content.getAttachment().getDataElement().getValueAsString()));
assertThat(decodedData).isEqualTo("ECHOCARDIOGRAPHIC REPORT\nNORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH\nHYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%");
// TODO: Determine if we need to look at anything other than OBX.2 when it is TX
// Leave this test in place as a reminder
documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||||||201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + // TODO: find better code for this test which is to see that OBX.2 is the fallback.
"OBX|1|SN|||||||||F";
report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
content = report.getContentFirstRep();
// Because the OBX is not TX, the content is put in an Observation
// FHIR requires a Content element, so only a minimal one is created.
// Future OBX.2 is the backup for content type, but currently always defaults to text/plain
assertThat(content.getAttachment().hasContentType()).isTrue();
// Currently always defaults to text/plain
assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
// TXA.7 date
assertThat(content.getAttachment().getCreationElement().toString()).containsPattern("2018-01-18T03:46:00");
assertThat(content.getAttachment().hasData()).isFalse();
// Test that content is created even if TXA.7 is empty
documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + // Ensure that empty TXA.7 still works
"TXA|1||||||||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + "OBX|1|SN|||||||||F";
report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
content = report.getContentFirstRep();
// Because the OBX is not TX, the content is put in an Observation
// FHIR requires a Content element, so only a minimal one is created.
// Currently always defaults to text/plain
assertThat(content.getAttachment().hasContentType()).isTrue();
// Currently always defaults to text/plain, even if not data for content
assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
// No TXA.7 date
assertThat(content.getAttachment().hasCreationElement()).isFalse();
assertThat(content.getAttachment().hasData()).isFalse();
}
use of org.hl7.fhir.r4b.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7EventTypeFHIRConversionTest method validateEVNsegmentWithOBXreference.
@Test
void validateEVNsegmentWithOBXreference() {
// When there is an OBX record, it should create a reason reference in the encounter segment
String hl7message = "MSH|^~\\&|||||||ADT^A01^ADT_A01|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6||||||\r" + "EVN||||7525|||\r" + "PV1|1|I||R|||||||||R|1||||||||||||||||||||||||||||||200603150624|200603150625|||||||\r" + "OBX|1|CWE|DQW^Some text 1^SNM3|||||||||||||||||||||\r";
String json = ftv.convert(hl7message, OPTIONS);
assertThat(json).isNotBlank();
FHIRContext context = new FHIRContext(true, false);
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
// Find the Observation in the bundle
List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
// Find the encounter from the FHIR bundle.
List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(encounterResource).hasSize(1);
Encounter encounter = (Encounter) encounterResource.get(0);
assertThat(encounter.hasReasonReference()).isTrue();
assertThat(encounter.getReasonReference()).hasSize(1);
// Check that the cross reference is equal to the Observation id
assertThat(encounter.getReasonReferenceFirstRep().getReference()).hasToString(obs.getId());
}
use of org.hl7.fhir.r4b.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MDMMessageTest method test_mdm_ORDER_with_OBXnotTX.
@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void test_mdm_ORDER_with_OBXnotTX(String message) throws IOException {
// Also check NTE working for MDM messages.
String hl7message = "MSH|^~\\&|HNAM|W|RAD_IMAGING_REPORT|W|20180118111520||" + message + "|<MESSAGEID>|P|2.6\r" + "EVN||20150502090000|\r" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\r" + "PV1||O||||||||||||||||||||||||||||||||||||||||||199501102300\r" + "ORC|NW|622470H432|||||^^^^^R||||||||||||||\r" + "OBR|1|622470H432|102397CE432|||20170725143849|20180102|||||||||||||||||RAD|O||^^^^^R||||REASON_ID_1^REASON_TEXT_1||||\r" + // ServiceRequest NTE has a practitioner reference in NTE.5
"NTE|1|O|TEST ORC/OBR NOTE AA line 1||Pract1ID^Pract1Last^Pract1First|\n" + "NTE|2|O|TEST NOTE AA line 2|\n" + "TXA|1|HP^History and physical examination|TX||||201801171442||||||||||||AV|||||\r" + "OBX|1|NM|Most Current Weight^Most current measured weight (actual)||90|kg\r" + // Observation NTE has a practitioner reference in second NTE.5. Annotation uses the first valid NTE.5
"NTE|1|L|TEST OBX NOTE BB line 1|\n" + "NTE|2|L|TEST NOTE BB line 2||Pract2ID^Pract2Last^Pract2First|\n";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
// Check for the expected resources
List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
// from EVN, PV1
assertThat(encounterResource).hasSize(1);
List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
// from PID
assertThat(patientResource).hasSize(1);
List<Resource> serviceRequestResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
// from ORC, OBR
assertThat(serviceRequestResource).hasSize(1);
// Light check that ServiceRequest contains NTE for ORC/OBR; Deep check of NTE in Hl7NoteFHIRConverterTest.
ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequestResource.get(0), ResourceUtils.context);
assertThat(serviceRequest.hasNote()).isTrue();
assertThat(serviceRequest.getNote()).hasSize(1);
// NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
// Must use getTextElement().getValueAsString() to see untrimmed contents.
assertThat(serviceRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST ORC/OBR NOTE AA line 1 \nTEST NOTE AA line 2");
assertThat(serviceRequest.getNote().get(0).hasAuthorReference()).isTrue();
List<Resource> documentReferenceResource = ResourceUtils.getResourceList(e, ResourceType.DocumentReference);
// from TXA
assertThat(documentReferenceResource).hasSize(1);
List<Resource> observationResources = ResourceUtils.getResourceList(e, ResourceType.Observation);
// from OBX(not type TX)
assertThat(observationResources).hasSize(1);
// Light check that Observation contains NTE for OBX; Deep check of NTE in Hl7NoteFHIRConverterTest.
Observation observation = ResourceUtils.getResourceObservation(observationResources.get(0), ResourceUtils.context);
// Validate the note contents and reference existance.
assertThat(observation.hasNote()).isTrue();
assertThat(observation.getNote()).hasSize(1);
// NOTE: the note contains an Annotation, which contains a MarkdownType that has the string.
// Must use getTextElement().getValueAsString() to see untrimmed contents.
assertThat(observation.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST OBX NOTE BB line 1 \nTEST NOTE BB line 2");
assertThat(observation.getNote().get(0).hasAuthorReference()).isTrue();
// Two Practitioners, one for the serviceRequest, one for the Observation
List<Resource> practitioners = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
// from NTE.4 references
assertThat(practitioners).hasSize(2);
// Confirm that no extra resources are created
assertThat(e.size()).isEqualTo(7);
}
Aggregations