use of org.hl7.fhir.dstu3.model.MessageHeader in project cqf-ruler by DBCG.
the class ProcessMessageProvider method constructMessageHeaderResource.
private MessageHeader constructMessageHeaderResource() {
String message = "{\"resourceType\": \"MessageHeader\",\"id\": \"messageheader-example-reportheader\",\"meta\": {\"versionId\": \"1\",\"lastUpdated\": \"2020-11-29T02:03:28.045+00:00\",\"profile\": [\"http://hl7.org/fhir/us/medmorph/StructureDefinition/us-ph-messageheader\"]},\"extension\": [{\"url\": \"http://hl7.org/fhir/us/medmorph/StructureDefinition/ext-dataEncrypted\",\"valueBoolean\": false},{\"url\":\"http://hl7.org/fhir/us/medmorph/StructureDefinition/ext-messageProcessingCategory\",\"valueCode\": \"consequence\"}],\"eventCoding\": {\"system\": \"http://hl7.org/fhir/us/medmorph/CodeSystem/us-ph-messageheader-message-types\",\"code\": \"cancer-report-message\"},\"destination\": [{\"name\": \"PHA endpoint\",\"endpoint\": \"http://example.pha.org/fhir\"}],\"source\": {\"name\": \"Healthcare Organization\",\"software\": \"Backend Service App\",\"version\": \"3.1.45.AABB\",\"contact\": {\"system\": \"phone\",\"value\": \"+1 (917) 123 4567\"},\"endpoint\": \"http://example.healthcare.org/fhir\"},\"reason\": {\"coding\": [{\"system\": \"http://hl7.org/fhir/us/medmorph/CodeSystem/us-ph-triggerdefinition-namedevents\",\"code\": \"encounter-close\"}]}}";
MessageHeader messageHeader = (MessageHeader) this.getFhirContext().newJsonParser().parseResource(message);
messageHeader.setId(getUUID());
return messageHeader;
}
use of org.hl7.fhir.dstu3.model.MessageHeader in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ORUMessageTest method test_oru_multipleOBXofDifferentTypes.
/**
* ORU messages with an OBR and multiple OBX segments create records only for non TX type OBX
* The OBX type TX are added to the presentedForm as an attachment for the diagnostic
* @throws IOException
*/
// Suppress warnings about too many assertions in a test. Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
@Test
void test_oru_multipleOBXofDifferentTypes() throws IOException {
String json = ftv.convert(new File("src/test/resources/ORU-multiline-short.hl7"), OPTIONS_PRETTYPRINT);
assertThat(json).isNotBlank();
LOGGER.debug("FHIR json result:\n" + json);
// Verify conversion
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
Assertions.assertSame(BundleType.COLLECTION, b.getType(), "Bundle type not expected");
List<BundleEntryComponent> e = b.getEntry();
// Verify that the right resources have been created
List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
assertThat(patientResource).hasSize(1);
List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
assertThat(encounterResource).hasSize(1);
List<Resource> organizationResource = ResourceUtils.getResourceList(e, ResourceType.Organization);
// We expect an organization created from an Encounter.serviceProvider reference
assertThat(organizationResource).hasSize(1);
List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
assertThat(practitionerResource).hasSize(4);
List<Resource> messageHeader = ResourceUtils.getResourceList(e, ResourceType.MessageHeader);
assertThat(messageHeader).hasSize(1);
// Verify Diagnostic Report is created as expected
List<Resource> reportResource = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
assertThat(reportResource).hasSize(1);
List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
assertThat(servReqResource).hasSize(1);
// Verify there are no extra resources created
assertThat(e).hasSize(10);
// Verify no observations are created
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
// TODO: When NTE is implemented, then update this to one.
assertThat(obsResource).isEmpty();
// /////////////////////////////////////////
// Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
// /////////////////////////////////////////
DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(reportResource.get(0), context);
// Verify status from OBR.25
assertThat(diag.getStatus().toCode()).isEqualTo("final");
// Verify category from OBR.24
assertThat(diag.getCategory()).hasSize(1);
DatatypeUtils.checkCommonCodeableConceptAssertions(diag.getCategoryFirstRep(), "CT", "CAT Scan", "http://terminology.hl7.org/CodeSystem/v2-0074", "CT");
// Verify code from OBR.4; This tests scenario of the code not being in the default loinc system.
assertThat(diag.hasCode()).isTrue();
List<Coding> codings = diag.getCode().getCoding();
assertThat(codings).hasSize(1);
Coding coding = codings.get(0);
assertThat(coding.hasDisplay()).isTrue();
assertThat(coding.getDisplay()).hasToString("ECHO CARDIOGRAM COMPLETE");
assertThat(coding.hasCode()).isTrue();
assertThat(coding.getCode()).hasToString("1487");
assertThat(coding.hasSystem()).isFalse();
// Verify encounter reference
assertThat(diag.getEncounter().isEmpty()).isFalse();
// Verify subject reference
assertThat(diag.getSubject().isEmpty()).isFalse();
// Verify effectiveDateTime from OBR.7 and OBR.8
// This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2020-08-02T12:44:55+08:00");
// Verify issued from OBR.22
assertThat(diag.getIssued()).isNull();
// Verify resultsInterpreter from OBR.32
assertThat(diag.getResultsInterpreter()).isEmpty();
// Verify basedOn is ref to the ServiceRequest created for ORC or OBR
assertThat(diag.getBasedOn()).hasSize(1);
assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
// Verify specimen reference
List<Reference> spmRef = diag.getSpecimen();
assertThat(spmRef).isEmpty();
// Verify result reference
List<Reference> obsRef = diag.getResult();
assertThat(obsRef).isEmpty();
// Verify attachment to diagnostic report
List<Attachment> attachments = diag.getPresentedForm();
Assertions.assertEquals(1, attachments.size(), "Unexpected number of attachments");
Attachment a = attachments.get(0);
Assertions.assertTrue(a.getContentType().equalsIgnoreCase("text/plain"), "Incorrect content type");
Assertions.assertTrue(a.getLanguage().equalsIgnoreCase("en"), "Incorrect language");
// Verify data attachment after decoding
String decoded = new String(Base64.getDecoder().decode(a.getDataElement().getValueAsString()));
System.out.println("Decoded: '" + decoded + "'");
Assertions.assertEquals("\n[PII] Emergency Department\nED Encounter Arrival Date: [ADDRESS] [PERSONALNAME]:", decoded, "Incorrect data");
Assertions.assertTrue(a.getTitle().equalsIgnoreCase("ECHO CARDIOGRAM COMPLETE"), "Incorrect title");
// Verify creation data is persisted correctly - 2020-08-02T12:44:55+08:00
Calendar c = Calendar.getInstance();
// needed to completely clear out calendar object
c.clear();
c.set(2020, 7, 2, 12, 44, 55);
c.setTimeZone(TimeZone.getTimeZone(ZoneId.of("+08:00")));
Date d = c.getTime();
Assertions.assertEquals(d, a.getCreation(), "Incorrect creation date");
// //////////////////////////////////
for (Resource res : obsResource) {
// Verify encounter reference exists
Observation obs = (Observation) res;
assertThat(obs.getEncounter().isEmpty()).isFalse();
assertThat(obs.getEncounter().getReference().substring(0, 10)).isEqualTo("Encounter/");
// Verify subject reference to Patient exists
assertThat(obs.getSubject().isEmpty()).isFalse();
assertThat(obs.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
}
}
use of org.hl7.fhir.dstu3.model.MessageHeader in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ORUMessageTest method test_oru_multipleOBXWithMixedType.
/**
* Verifies ORU messages with mixed OBX types
*
* @throws IOException
*/
@Test
// Suppress warnings about too many assertions in a test. Justification: creating a FHIR message is very costly; we need to check many asserts per creation for efficiency.
@java.lang.SuppressWarnings("squid:S5961")
void test_oru_multipleOBXWithMixedType() throws IOException {
String json = ftv.convert(new File("src/test/resources/ORU-multiline-short-mixed.hl7"), OPTIONS_PRETTYPRINT);
assertThat(json).isNotBlank();
LOGGER.debug("FHIR json result:\n" + json);
// Verify conversion
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
Bundle b = (Bundle) bundleResource;
assertThat(bundleResource).isNotNull();
Assertions.assertSame(BundleType.COLLECTION, b.getType(), "Bundle type not expected");
List<BundleEntryComponent> e = b.getEntry();
// Verify that the right resources have been created
List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
assertThat(patientResource).hasSize(1);
List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
assertThat(encounterResource).hasSize(1);
List<Resource> organizationResource = ResourceUtils.getResourceList(e, ResourceType.Organization);
// We expect an organization created from an Encounter.serviceProvider reference
assertThat(organizationResource).hasSize(1);
List<Resource> practitionerResource = ResourceUtils.getResourceList(e, ResourceType.Practitioner);
assertThat(practitionerResource).hasSize(4);
List<Resource> messageHeader = ResourceUtils.getResourceList(e, ResourceType.MessageHeader);
assertThat(messageHeader).hasSize(1);
// Verify one Observation is created (from the ST, not the TX)
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
// TODO: When NTE is implemented, then update this.
assertThat(obsResource).hasSize(1);
// Verify Diagnostic Report is created as expected
List<Resource> reportResource = ResourceUtils.getResourceList(e, ResourceType.DiagnosticReport);
assertThat(reportResource).hasSize(1);
List<Resource> servReqResource = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
assertThat(servReqResource).hasSize(1);
// Verify there are no extra resources created
assertThat(e).hasSize(11);
// /////////////////////////////////////////
// Now confirm content of the diagnosticReport because we don't have separate tests for DiagnosticReport
// /////////////////////////////////////////
DiagnosticReport diag = ResourceUtils.getResourceDiagnosticReport(reportResource.get(0), context);
// Verify status from OBR.25
assertThat(diag.getStatus().toCode()).isEqualTo("final");
// Verify category from OBR.24
assertThat(diag.getCategory()).hasSize(1);
assertThat(diag.getCategory().get(0).getCoding()).hasSize(1);
assertThat(diag.getCategory().get(0).getCoding().get(0).getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0074");
assertThat(diag.getCategory().get(0).getCoding().get(0).getCode()).isEqualTo("CT");
assertThat(diag.getCategory().get(0).getCoding().get(0).getDisplay()).isEqualTo("CAT Scan");
assertThat(diag.getCategory().get(0).getText()).isEqualTo("CT");
// Verify code from OBR.4; This tests scenario of the code not being in the default loinc system.
assertThat(diag.hasCode()).isTrue();
List<Coding> codings = diag.getCode().getCoding();
assertThat(codings).hasSize(1);
Coding coding = codings.get(0);
assertThat(coding.hasDisplay()).isTrue();
assertThat(coding.getDisplay()).hasToString("ECHO CARDIOGRAM COMPLETE");
assertThat(coding.hasCode()).isTrue();
assertThat(coding.getCode()).hasToString("1487");
assertThat(coding.hasSystem()).isFalse();
// Verify encounter reference
assertThat(diag.getEncounter().isEmpty()).isFalse();
// Verify subject reference
assertThat(diag.getSubject().isEmpty()).isFalse();
// Verify effectiveDateTime from OBR.7 and OBR.8
// This also verifies the type, confirming effectiveDateTime was set rather than effectivePeriod
assertThat(diag.getEffectiveDateTimeType().asStringValue()).isEqualTo("2020-08-02T12:44:55+08:00");
// Verify issued from OBR.22
assertThat(diag.getIssued()).isNull();
// Verify resultsInterpreter from OBR.32
assertThat(diag.getResultsInterpreter()).isEmpty();
// Verify basedOn is ref to the ServiceRequest created for ORC or OBR
assertThat(diag.getBasedOn()).hasSize(1);
assertThat(diag.getBasedOn().get(0).getReference().substring(0, 15)).isEqualTo("ServiceRequest/");
// Verify specimen reference
List<Reference> spmRef = diag.getSpecimen();
assertThat(spmRef).isEmpty();
// Verify result reference
List<Reference> obsRef = diag.getResult();
assertThat(obsRef).isNotEmpty().hasSize(1);
assertThat(obsRef.get(0).isEmpty()).isFalse();
// No attachment created since OBX with TX and no id is not first
List<Attachment> attachments = diag.getPresentedForm();
Assertions.assertEquals(0, attachments.size(), "Unexpected number of attachments");
// //////////////////////////////////
for (Resource res : obsResource) {
// Verify encounter reference exists
Observation obs = (Observation) res;
assertThat(obs.getEncounter().isEmpty()).isFalse();
assertThat(obs.getEncounter().getReference().substring(0, 10)).isEqualTo("Encounter/");
// Verify subject reference to Patient exists
assertThat(obs.getSubject().isEmpty()).isFalse();
assertThat(obs.getSubject().getReference().substring(0, 8)).isEqualTo("Patient/");
}
}
use of org.hl7.fhir.dstu3.model.MessageHeader in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7MessageTest method test_messageHeader_with_ADT.
@Test
void test_messageHeader_with_ADT() throws IOException {
ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/MessageHeader");
HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("MessageHeader").withResourceModel(rsm).withSegment("MSH").withIsReferenced(false).withRepeats(false).build();
HL7FHIRResourceTemplate messageHeaderTemplate = new HL7FHIRResourceTemplate(attributes);
HL7MessageModel message = new HL7MessageModel("ADT", Lists.newArrayList(messageHeaderTemplate));
String hl7message = "MSH|^~\\&|Amalga HIS|BUM|New Tester|MS|20111121103141||ADT^A01|2847970-201111211031|P|2.6|||AL|NE|764|||||||^4086::132:2A57:3C28^IPv6\r" + "EVN|A01|20130617154644\r" + "PID|1|465 306 5961|000010016^^^MR~000010017^^^MR~000010018^^^MR|407623|Wood^Patrick^^Sr^MR||19700101|female|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||\r" + "NK1|1|Wood^John^^^MR|Father||999-9999\r" + "NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999\r" + "PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||";
String json = message.convert(hl7message, engine);
assertThat(json).isNotBlank();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> messageHeader = e.stream().filter(v -> ResourceType.MessageHeader == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(messageHeader).hasSize(1);
MessageHeader msgH = ResourceUtils.getResourceMessageHeader(messageHeader.get(0), context);
assertThat(msgH.getId()).isNotNull();
assertThat(msgH.getEventCoding()).isNotNull();
assertThat(msgH.getEventCoding().getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0003");
assertThat(msgH.getEventCoding().getCode()).isEqualTo("A01");
assertThat(msgH.getEventCoding().getDisplay()).isEqualTo("ADT/ACK - Admit/visit notification");
assertThat(msgH.getDestination()).hasSize(1);
assertThat(msgH.getDestinationFirstRep().getName()).isEqualTo("New Tester");
assertThat(msgH.getDestinationFirstRep().getEndpoint()).isEqualTo("MS");
assertThat(msgH.getSource()).isNotNull();
assertThat(msgH.getSource().getName()).isEqualTo("Amalga HIS");
assertThat(msgH.getReason()).isNotNull();
assertThat(msgH.getReason().getCoding().get(0).getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/message-reasons-encounter");
assertThat(msgH.getReason().getCoding().get(0).getCode()).isEqualTo("admit");
assertThat(msgH.getReason().getCoding().get(0).getDisplay()).isEqualTo("Admit");
}
use of org.hl7.fhir.dstu3.model.MessageHeader in project integration-adaptor-111 by nhsconnect.
the class EncounterReportBundleService method createEncounterBundle.
public Bundle createEncounterBundle(POCDMT000002UK01ClinicalDocument1 clinicalDocument, ItkReportHeader header, String messageId) throws XmlException {
Bundle bundle = createBundle(clinicalDocument);
MessageHeader messageHeader = messageHeaderService.createMessageHeader(header, messageId, clinicalDocument.getEffectiveTime().getValue());
List<HealthcareService> healthcareServiceList = healthcareServiceMapper.mapHealthcareService(clinicalDocument);
List<PractitionerRole> authorPractitionerRoles = practitionerRoleMapper.mapAuthorRoles(clinicalDocument.getAuthorArray());
Optional<PractitionerRole> responsibleParty = practitionerRoleMapper.mapResponsibleParty(clinicalDocument);
Encounter encounter = encounterMapper.mapEncounter(clinicalDocument, authorPractitionerRoles, responsibleParty, messageHeader.getEvent());
Consent consent = consentMapper.mapConsent(clinicalDocument, encounter);
List<QuestionnaireResponse> questionnaireResponseList = pathwayUtil.getQuestionnaireResponses(clinicalDocument, encounter.getSubject(), resourceUtil.createReference(encounter));
Condition condition = conditionMapper.mapCondition(clinicalDocument, encounter, questionnaireResponseList);
List<CarePlan> carePlans = carePlanMapper.mapCarePlan(clinicalDocument, encounter, condition);
Device device = deviceMapper.mapDevice();
ReferralRequest referralRequest = referralRequestMapper.mapReferralRequest(clinicalDocument, encounter, healthcareServiceList, resourceUtil.createReference(condition), resourceUtil.createReference(device));
Composition composition = compositionMapper.mapComposition(clinicalDocument, encounter, carePlans, questionnaireResponseList, referralRequest, authorPractitionerRoles);
List<Observation> observations = observationMapper.mapObservations(clinicalDocument, encounter);
RelatedPerson relatedPerson = relatedPersonMapper.createEmergencyContactRelatedPerson(clinicalDocument, encounter);
addMessageHeader(bundle, messageHeader);
addEncounter(bundle, encounter);
addServiceProvider(bundle, encounter);
addParticipants(bundle, encounter);
addLocation(bundle, encounter);
addSubject(bundle, encounter);
addHealthcareService(bundle, healthcareServiceList);
addIncomingReferral(bundle, referralRequest);
addAppointment(bundle, encounter);
addEntry(bundle, composition);
addCarePlan(bundle, carePlans);
addEntry(bundle, consent);
addEntry(bundle, condition);
addQuestionnaireResponses(bundle, questionnaireResponseList);
addObservations(bundle, observations);
addPractitionerRoles(bundle, authorPractitionerRoles, responsibleParty);
addRelatedPerson(bundle, relatedPerson);
addEntry(bundle, device);
ListResource listResource = getReferenceFromBundle(bundle, clinicalDocument, encounter, device);
addEntry(bundle, listResource);
return bundle;
}
Aggregations