Search in sources :

Example 1 with MessageHeader

use of org.hl7.fhir.r4.model.MessageHeader in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7MessageTest method test_messageHeader_with_ORU.

@Test
void test_messageHeader_with_ORU() throws IOException {
    ResourceModel rsm = ResourceReader.getInstance().generateResourceModel("resource/MessageHeader");
    HL7FHIRResourceTemplateAttributes attributes = new HL7FHIRResourceTemplateAttributes.Builder().withResourceName("MessageHeader").withResourceModel(rsm).withSegment("MSH").withAdditionalSegments(Lists.newArrayList("EVN")).withIsReferenced(false).withRepeats(false).build();
    HL7FHIRResourceTemplate messageHeaderTemplate = new HL7FHIRResourceTemplate(attributes);
    HL7MessageModel message = new HL7MessageModel("ORU", Lists.newArrayList(messageHeaderTemplate));
    String hl7message = "MSH|^~\\&|Amalga HIS|BUM|New Tester|MS|20111121103141||ORU^R01|2847970-201111211031|P|2.6|||AL|NE|764|ASCII||||||^4086::132:2A57:3C28^IPv6\r" + "EVN|A01|20130617154644||01\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("R01");
    assertThat(msgH.getEventCoding().getDisplay()).isEqualTo("ORU/ACK - Unsolicited transmission of an observation message");
    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/v2-0062");
    assertThat(msgH.getReason().getCoding().get(0).getCode()).isEqualTo("01");
    assertThat(msgH.getReason().getCoding().get(0).getDisplay()).isEqualTo("Patient request");
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ResourceModel(io.github.linuxforhealth.api.ResourceModel) MessageHeader(org.hl7.fhir.r4.model.MessageHeader) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Example 2 with MessageHeader

use of org.hl7.fhir.r4.model.MessageHeader in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7PatientFHIRConversionTest method patient_deceased_conversion_test1.

/**
 * In order to generate messageHeader resource, MSH should have MSH.24.2 as this is required
 * attribute for source attribute, and source is required for MessageHeader resource.
 */
@Test
void patient_deceased_conversion_test1() {
    String patientMsgDeceasedEmpty = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Mouse^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|12345 testing ave^^Minneapolis^MN^55407^^^^MN053|USAA|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|Y|2|USA||||\n";
    String patientMsgNotDeadBooleanN = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Mouse^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|12345 testing ave^^Minneapolis^MN^55407^^^^MN053|USAA|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|Y|2|USA||||N\n";
    String patientMsgDeceasedDateOnlyYYYY = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Mouse^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|12345 testing ave^^Minneapolis^MN^55407^^^^MN053|USAA|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|Y|2|USA|||2006|\n";
    String patientMsgDeceasedDateOnlyYYYYMM = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Mouse^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|12345 testing ave^^Minneapolis^MN^55407^^^^MN053|USAA|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|Y|2|USA|||200611|\n";
    Patient patientObjDeceasedEmpty = PatientUtils.createPatientFromHl7Segment(ftv, patientMsgDeceasedEmpty);
    assertThat(patientObjDeceasedEmpty.hasDeceased()).isFalse();
    assertThat(patientObjDeceasedEmpty.hasDeceasedBooleanType()).isFalse();
    assertThat(patientObjDeceasedEmpty.hasDeceasedDateTimeType()).isFalse();
    Patient patientObjNotDeadBooleanN = PatientUtils.createPatientFromHl7Segment(ftv, patientMsgNotDeadBooleanN);
    assertThat(patientObjNotDeadBooleanN.hasDeceased()).isTrue();
    assertThat(patientObjNotDeadBooleanN.hasDeceasedBooleanType()).isTrue();
    assertThat(patientObjNotDeadBooleanN.getDeceasedBooleanType().booleanValue()).isFalse();
    Patient patientObjDeceasedDateOnlyYYYY = PatientUtils.createPatientFromHl7Segment(ftv, patientMsgDeceasedDateOnlyYYYY);
    assertThat(patientObjDeceasedDateOnlyYYYY.hasDeceased()).isTrue();
    assertThat(patientObjDeceasedDateOnlyYYYY.hasDeceasedDateTimeType()).isTrue();
    assertThat(patientObjDeceasedDateOnlyYYYY.hasDeceasedBooleanType()).isFalse();
    assertThat(patientObjDeceasedDateOnlyYYYY.getDeceasedDateTimeType().asStringValue()).isEqualTo("2006");
    Patient patientObjDeceasedDateOnlyYYYYMM = PatientUtils.createPatientFromHl7Segment(ftv, patientMsgDeceasedDateOnlyYYYYMM);
    assertThat(patientObjDeceasedDateOnlyYYYYMM.hasDeceased()).isTrue();
    assertThat(patientObjDeceasedDateOnlyYYYYMM.hasDeceasedDateTimeType()).isTrue();
    assertThat(patientObjDeceasedDateOnlyYYYYMM.hasDeceasedBooleanType()).isFalse();
    assertThat(patientObjDeceasedDateOnlyYYYYMM.getDeceasedDateTimeType().asStringValue()).isEqualTo("2006-11");
// More related tests in patient_deceased_conversion_test2
}
Also used : Patient(org.hl7.fhir.r4.model.Patient) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with MessageHeader

use of org.hl7.fhir.r4.model.MessageHeader in project hl7v2-fhir-converter by LinuxForHealth.

the class FHIRConverterTest method verifyResult.

private void verifyResult(String json, BundleType expectedBundleType, boolean messageHeaderExpected) {
    FHIRContext context = new FHIRContext();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    assertThat(b.getType()).isEqualTo(expectedBundleType);
    assertThat(b.getId()).isNotNull();
    assertThat(b.getMeta().getLastUpdated()).isNotNull();
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> patientResource = e.stream().filter(v -> ResourceType.Patient == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(patientResource).hasSize(1);
    List<Resource> encounterResource = e.stream().filter(v -> ResourceType.Encounter == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(encounterResource).hasSize(1);
    List<Resource> obsResource = e.stream().filter(v -> ResourceType.Observation == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    // No Observation resource because OBX.2 is type TX
    assertThat(obsResource).isEmpty();
    List<Resource> pracResource = e.stream().filter(v -> ResourceType.Practitioner == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(pracResource).hasSize(4);
    List<Resource> allergyResources = e.stream().filter(v -> ResourceType.AllergyIntolerance == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
    assertThat(allergyResources).hasSize(2);
    if (messageHeaderExpected) {
        List<Resource> messageHeader = e.stream().filter(v -> ResourceType.MessageHeader == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
        assertThat(messageHeader).hasSize(1);
    }
}
Also used : FHIRContext(io.github.linuxforhealth.fhir.FHIRContext) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource)

Example 4 with MessageHeader

use of org.hl7.fhir.r4.model.MessageHeader in project cqf-ruler by DBCG.

the class ProcessMessageProvider method processMessageBundle.

@Operation(name = "$process-message-bundle", idempotent = false)
public Bundle processMessageBundle(HttpServletRequest theServletRequest, RequestDetails theRequestDetails, @OperationParam(name = "content", min = 1, max = 1) @Description(formalDefinition = "The message to process (or, if using asynchronous messaging, it may be a response message to accept)") Bundle theMessageToProcess) {
    logger.info("Validating the Bundle");
    Bundle bundle = theMessageToProcess;
    Boolean errorExists = false;
    OperationOutcome outcome = validateBundle(errorExists, bundle);
    if (!errorExists) {
        IVersionSpecificBundleFactory bundleFactory = this.getFhirContext().newBundleFactory();
        bundle.setId(getUUID());
        bundleFactory.initializeWithBundleResource(bundle);
        Bundle dafBundle = (Bundle) bundleFactory.getResourceBundle();
        dafBundle.setTimestamp(new Date());
        this.getDaoRegistry().getResourceDao(Bundle.class).create(dafBundle);
        MessageHeader messageHeader = null;
        String patientId = null;
        String commId = null;
        List<MessageHeader> headers = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, MessageHeader.class);
        for (MessageHeader mh : headers) {
            messageHeader = mh;
            messageHeader.setId(getUUID());
            Meta meta = messageHeader.getMeta();
            meta.setLastUpdated(new Date());
            messageHeader.setMeta(meta);
        }
        List<IBaseResource> resources = new ArrayList<>();
        List<Patient> patients = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Patient.class);
        for (Patient p : patients) {
            patientId = p.getId();
            p.setId(p.getIdElement().toVersionless());
            resources.add(p);
        }
        List<Bundle> bundles = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Bundle.class);
        for (Bundle b : bundles) {
            patientId = this.processBundle(b, theRequestDetails);
            b.setId(b.getIdElement().toVersionless());
            resources.add(b);
        }
        for (BundleEntryComponent e : bundle.getEntry()) {
            Resource r = e.getResource();
            if (r == null) {
                continue;
            }
            if (r.fhirType().equals("Bundle") || r.fhirType().equals("MessageHeader") || r.fhirType().equals("Patient")) {
                continue;
            }
            r.setId(r.getIdElement().toVersionless());
            resources.add(r);
        }
        if (patientId != null) {
            commId = constructAndSaveCommunication(patientId);
        }
        if (messageHeader == null) {
            messageHeader = constructMessageHeaderResource();
            BundleEntryComponent entryComp = new BundleEntryComponent();
            entryComp.setResource(messageHeader);
            dafBundle.addEntry(entryComp);
        }
        if (commId != null) {
            List<Reference> referenceList = new ArrayList<>();
            Reference commRef = new Reference();
            commRef.setReference("Communication/" + commId);
            referenceList.add(commRef);
            messageHeader.setFocus(referenceList);
        }
        IVersionSpecificBundleFactory newBundleFactory = this.getFhirContext().newBundleFactory();
        newBundleFactory.addResourcesToBundle(resources, BundleTypeEnum.TRANSACTION, theRequestDetails.getFhirServerBase(), null, null);
        Bundle transactionBundle = (Bundle) newBundleFactory.getResourceBundle();
        for (BundleEntryComponent entry : transactionBundle.getEntry()) {
            UriType uri = new UriType(theRequestDetails.getFhirServerBase() + "/" + entry.getResource().fhirType() + "/" + entry.getResource().getIdElement().getIdPart());
            Enumeration<HTTPVerb> method = new Enumeration<>(new HTTPVerbEnumFactory());
            method.setValue(HTTPVerb.PUT);
            entry.setRequest(new BundleEntryRequestComponent(method, uri));
        }
        @SuppressWarnings("unchecked") IFhirSystemDao<Bundle, Meta> fhirSystemDao = this.getDaoRegistry().getSystemDao();
        fhirSystemDao.transaction(theRequestDetails, transactionBundle);
        return dafBundle;
    } else {
        BundleEntryComponent entryComp = new BundleEntryComponent();
        entryComp.setResource(outcome);
        bundle.addEntry(entryComp);
        return bundle;
    }
}
Also used : HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) Meta(org.hl7.fhir.r4.model.Meta) ArrayList(java.util.ArrayList) UriType(org.hl7.fhir.r4.model.UriType) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Enumeration(org.hl7.fhir.r4.model.Enumeration) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IVersionSpecificBundleFactory(ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory) Patient(org.hl7.fhir.r4.model.Patient) HTTPVerbEnumFactory(org.hl7.fhir.r4.model.Bundle.HTTPVerbEnumFactory) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) MessageHeader(org.hl7.fhir.r4.model.MessageHeader) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 5 with MessageHeader

use of org.hl7.fhir.r4.model.MessageHeader in project MobileAccessGateway by i4mi.

the class Iti93AuditStrategy method getEventOutcomeCodeFromResource.

/**
 * Look at the response codes in the bundle entries and derive the ATNA event outcome
 * @param resource FHIR resource
 * @return RFC3881EventOutcomeCode
 */
@Override
protected EventOutcomeIndicator getEventOutcomeCodeFromResource(IBaseResource resource) {
    if (!(resource instanceof Bundle))
        return super.getEventOutcomeCodeFromResource(resource);
    var bundle = (Bundle) resource;
    var messageHeader = bundle.getEntry().stream().map(Bundle.BundleEntryComponent::getResource).filter(MessageHeader.class::isInstance).map(MessageHeader.class::cast).findFirst().orElseThrow(() -> new RuntimeException("ITI-93 bundle must contain MessageHeader"));
    ResponseType result = messageHeader.getResponse().getCode();
    if (result == null)
        return EventOutcomeIndicator.MajorFailure;
    if (result.equals(ResponseType.OK))
        return EventOutcomeIndicator.Success;
    if (result.equals(ResponseType.TRANSIENTERROR))
        return EventOutcomeIndicator.MinorFailure;
    return EventOutcomeIndicator.MajorFailure;
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MessageHeader(org.hl7.fhir.r4.model.MessageHeader) ResponseType(org.hl7.fhir.r4.model.MessageHeader.ResponseType)

Aggregations

BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)11 Bundle (org.hl7.fhir.r4.model.Bundle)9 MessageHeader (org.hl7.fhir.r4.model.MessageHeader)7 Resource (org.hl7.fhir.r4.model.Resource)7 Test (org.junit.jupiter.api.Test)7 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)6 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)5 ArrayList (java.util.ArrayList)5 Reference (org.hl7.fhir.r4.model.Reference)5 Date (java.util.Date)4 CS (net.ihe.gazelle.hl7v3.datatypes.CS)4 PRPAMT201301UV02Patient (net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Patient)4 Patient (org.hl7.fhir.r4.model.Patient)4 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)4 FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 COCTMT090003UV01AssignedEntity (net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity)3 COCTMT090003UV01Organization (net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization)3 COCTMT150003UV03ContactParty (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03ContactParty)3 COCTMT150003UV03Organization (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization)3