Search in sources :

Example 1 with PixV3QueryResponse

use of org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse in project ipf by oehf.

the class PixV3QueryResponseTransformer method fromPrpa.

/**
 * Transforms a full PRPA response into the simplified model. Data loss can occur, as the simplified model is not
 * complete.
 *
 * @param response The full PRPA response to transform.
 * @return the simplified response or {@code null} if the input was {@code null}.
 */
public PixV3QueryResponse fromPrpa(final PRPAIN201310UV02Type response) {
    if (response == null) {
        return null;
    }
    final PixV3QueryResponse simpleResponse = new PixV3QueryResponse();
    simpleResponse.setMessageId(response.getId());
    simpleResponse.setSender(this.fromSender(response.getSender()));
    if (!response.getReceiver().isEmpty()) {
        simpleResponse.setReceiver(this.fromReceiver(response.getReceiver().get(0)));
    }
    simpleResponse.setCreationTime(Optional.ofNullable(response.getCreationTime()).map(TS::getValue).map(value -> {
        try {
            return HL7DTM.toZonedDateTime(value);
        } catch (final DataTypeException e) {
            return null;
        }
    }).orElse(null));
    if (!response.getAcknowledgement().isEmpty()) {
        final MCCIMT000300UV01Acknowledgement acknowledgement = response.getAcknowledgement().get(0);
        simpleResponse.setAcknowledgementTypeCode(acknowledgement.getTypeCode().getCode());
        if (acknowledgement.getTargetMessage() != null) {
            simpleResponse.setTargetMessageId(acknowledgement.getTargetMessage().getId());
        }
        simpleResponse.getAcknowledgementDetails().addAll(acknowledgement.getAcknowledgementDetail());
    }
    if (response.getControlActProcess() == null) {
        return simpleResponse;
    }
    final PRPAIN201310UV02MFMIMT700711UV01ControlActProcess controlActProcess = response.getControlActProcess();
    if (controlActProcess.getQueryByParameter() == null) {
        return simpleResponse;
    }
    final PRPAMT201307UV02QueryByParameter queryByParameter = controlActProcess.getQueryByParameter();
    simpleResponse.setQueryId(queryByParameter.getQueryId());
    if (queryByParameter.getParameterList() == null) {
        return simpleResponse;
    }
    final PRPAMT201307UV02ParameterList parameterList = queryByParameter.getParameterList();
    if (!parameterList.getPatientIdentifier().isEmpty()) {
        final List<II> patientIds = parameterList.getPatientIdentifier().get(0).getValue();
        if (!patientIds.isEmpty()) {
            simpleResponse.setQueryPatientId(patientIds.get(0));
        }
    }
    for (final PRPAMT201307UV02DataSource dataSource : parameterList.getDataSource()) {
        if (!dataSource.getValue().isEmpty()) {
            simpleResponse.getDataSourceOids().add(dataSource.getValue().get(0).getRoot());
        }
    }
    final MFMIMT700711UV01QueryAck queryAck = controlActProcess.getQueryAck();
    if (queryAck != null) {
        simpleResponse.setQueryResponseCode(queryAck.getQueryResponseCode().getCode());
    }
    if (controlActProcess.getSubject().isEmpty()) {
        return simpleResponse;
    }
    final PRPAIN201310UV02MFMIMT700711UV01RegistrationEvent registrationEvent = Optional.ofNullable(controlActProcess.getSubject().get(0).getRegistrationEvent()).orElse(null);
    if (registrationEvent == null) {
        return simpleResponse;
    }
    simpleResponse.setCustodianOid(Optional.ofNullable(registrationEvent.getCustodian()).map(MFMIMT700711UV01Custodian::getAssignedEntity).map(COCTMT090003UV01AssignedEntity::getId).map(list -> list.isEmpty() ? null : list.get(0)).map(II::getRoot).orElse(null));
    final PRPAMT201304UV02Patient patient = Optional.ofNullable(registrationEvent.getSubject1()).map(PRPAIN201310UV02MFMIMT700711UV01Subject2::getPatient).orElse(null);
    if (patient == null) {
        return simpleResponse;
    }
    simpleResponse.setProviderOrganization(Optional.ofNullable(patient.getProviderOrganization()).orElse(null));
    if (!patient.getId().isEmpty()) {
        simpleResponse.getPatientIds().addAll(patient.getId());
    }
    if (patient.getPatientPerson() != null) {
        if (!patient.getPatientPerson().getName().isEmpty()) {
            simpleResponse.setPersonName(patient.getPatientPerson().getName().get(0));
        }
        simpleResponse.getPersonIds().addAll(patient.getPatientPerson().getId());
        simpleResponse.getAsOtherIDs().addAll(patient.getPatientPerson().getAsOtherIDs());
    }
    return simpleResponse;
}
Also used : net.ihe.gazelle.hl7v3.datatypes(net.ihe.gazelle.hl7v3.datatypes) Device(org.openehealth.ipf.commons.ihe.hl7v3.core.metadata.Device) COCTMT090003UV01AssignedEntity(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity) net.ihe.gazelle.hl7v3.voc(net.ihe.gazelle.hl7v3.voc) PRPAMT201304UV02Patient(net.ihe.gazelle.hl7v3.prpamt201304UV02.PRPAMT201304UV02Patient) PRPAMT201307UV02QueryByParameter(net.ihe.gazelle.hl7v3.prpamt201307UV02.PRPAMT201307UV02QueryByParameter) net.ihe.gazelle.hl7v3.mccimt000300UV01(net.ihe.gazelle.hl7v3.mccimt000300UV01) HL7DTM(org.openehealth.ipf.commons.ihe.core.HL7DTM) PixV3QueryResponse(org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse) MFMIMT700711UV01Custodian(net.ihe.gazelle.hl7v3.mfmimt700711UV01.MFMIMT700711UV01Custodian) List(java.util.List) PRPAMT201307UV02ParameterList(net.ihe.gazelle.hl7v3.prpamt201307UV02.PRPAMT201307UV02ParameterList) PRPAMT201307UV02PatientIdentifier(net.ihe.gazelle.hl7v3.prpamt201307UV02.PRPAMT201307UV02PatientIdentifier) net.ihe.gazelle.hl7v3.prpain201310UV02(net.ihe.gazelle.hl7v3.prpain201310UV02) PRPAMT201307UV02DataSource(net.ihe.gazelle.hl7v3.prpamt201307UV02.PRPAMT201307UV02DataSource) Optional(java.util.Optional) DataTypeException(ca.uhn.hl7v2.model.DataTypeException) MFMIMT700711UV01QueryAck(net.ihe.gazelle.hl7v3.mfmimt700711UV01.MFMIMT700711UV01QueryAck) PRPAMT201304UV02Person(net.ihe.gazelle.hl7v3.prpamt201304UV02.PRPAMT201304UV02Person) PRPAMT201307UV02ParameterList(net.ihe.gazelle.hl7v3.prpamt201307UV02.PRPAMT201307UV02ParameterList) PixV3QueryResponse(org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse) PRPAMT201304UV02Patient(net.ihe.gazelle.hl7v3.prpamt201304UV02.PRPAMT201304UV02Patient) DataTypeException(ca.uhn.hl7v2.model.DataTypeException) PRPAMT201307UV02DataSource(net.ihe.gazelle.hl7v3.prpamt201307UV02.PRPAMT201307UV02DataSource) MFMIMT700711UV01QueryAck(net.ihe.gazelle.hl7v3.mfmimt700711UV01.MFMIMT700711UV01QueryAck) COCTMT090003UV01AssignedEntity(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity) PRPAMT201307UV02QueryByParameter(net.ihe.gazelle.hl7v3.prpamt201307UV02.PRPAMT201307UV02QueryByParameter)

Example 2 with PixV3QueryResponse

use of org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse in project ipf by oehf.

the class PixV3QueryResponseTest method testFromQuery.

@Test
public void testFromQuery() {
    final PixV3QueryRequest query = new PixV3QueryRequest();
    query.getDataSourceOids().add("7.8.9");
    query.setQueryPatientId(new II("123", "1.2.3"));
    query.setQueryId(new II("abc", "4.5.6"));
    query.setReceiver(new Device());
    query.getReceiver().getIds().add(new II("receiver", "1.2"));
    query.setSender(new Device());
    query.getSender().getIds().add(new II("sender", "1.3"));
    query.setMessageId(new II("m1", "1.3.5"));
    final PixV3QueryResponse response = PixV3QueryResponse.fromQuery(query);
    assertEquals(query.getDataSourceOids(), response.getDataSourceOids());
    assertEquals(query.getQueryPatientId(), response.getQueryPatientId());
    assertEquals(query.getQueryId(), response.getQueryId());
    assertEquals(query.getReceiver(), response.getSender());
    assertEquals(query.getSender(), response.getReceiver());
    assertEquals(query.getMessageId(), response.getTargetMessageId());
}
Also used : PixV3QueryRequest(org.openehealth.ipf.commons.ihe.hl7v3.core.requests.PixV3QueryRequest) II(net.ihe.gazelle.hl7v3.datatypes.II) Device(org.openehealth.ipf.commons.ihe.hl7v3.core.metadata.Device) Test(org.junit.jupiter.api.Test)

Example 3 with PixV3QueryResponse

use of org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse in project ipf by oehf.

the class PixV3QueryResponseTransformerTest method testTransform.

@Test
public void testTransform() throws Exception {
    final PixV3QueryResponseTransformer transformer = new PixV3QueryResponseTransformer();
    final JAXBContext jaxbContext = JAXBContext.newInstance(PRPAIN201310UV02Type.class);
    final PixV3QueryResponse response = getSampleResponse();
    // Transform simple response to JAXB model
    final PRPAIN201310UV02Type prpain201310UV02Type = transformer.toPrpa(response);
    // Marshall JAXB model
    final Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF8");
    final StringWriter stringWriter = new StringWriter();
    marshaller.marshal(prpain201310UV02Type, stringWriter);
    final String xml = stringWriter.toString();
    // Unmarshall JAXB model
    final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    final PRPAIN201310UV02Type parsedPrpain201310UV02Type = (PRPAIN201310UV02Type) unmarshaller.unmarshal(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
    // Transform JAXB model to simple response
    final PixV3QueryResponse parsedResponse = transformer.fromPrpa(parsedPrpain201310UV02Type);
    // The two simple responses should be equal
    assertIiEquals(response.getQueryPatientId(), parsedResponse.getQueryPatientId());
    assertEquals(response.getDataSourceOids(), parsedResponse.getDataSourceOids());
    assertIiEquals(response.getMessageId(), parsedResponse.getMessageId());
    assertIiEquals(response.getQueryId(), parsedResponse.getQueryId());
    assertDeviceEquals(response.getReceiver(), parsedResponse.getReceiver());
    assertDeviceEquals(response.getSender(), parsedResponse.getSender());
    assertEquals(HL7DTM.toSimpleString(response.getCreationTime()), HL7DTM.toSimpleString(parsedResponse.getCreationTime()));
    assertIiEquals(response.getTargetMessageId(), parsedResponse.getTargetMessageId());
    assertEquals(response.getAcknowledgementTypeCode(), parsedResponse.getAcknowledgementTypeCode());
    assertEquals(response.getQueryResponseCode(), parsedResponse.getQueryResponseCode());
    assertIiEquals(response.getPatientIds().get(0), parsedResponse.getPatientIds().get(0));
    assertEquals(response.getCustodianOid(), parsedResponse.getCustodianOid());
    assertEquals(response.getAcknowledgementDetails().get(0).getCode().getCode(), parsedResponse.getAcknowledgementDetails().get(0).getCode().getCode());
    assertEquals(response.getAcknowledgementDetails().get(0).getLocation().get(0).mixed, parsedResponse.getAcknowledgementDetails().get(0).getLocation().get(0).mixed);
    assertEquals(response.getAcknowledgementDetails().get(0).getText().mixed, parsedResponse.getAcknowledgementDetails().get(0).getText().mixed);
    assertEquals(response.getProviderOrganization().getName().get(0).mixed, parsedResponse.getProviderOrganization().getName().get(0).mixed);
    assertEquals(response.getPersonName().mixed, parsedResponse.getPersonName().mixed);
    assertIiEquals(response.getPersonIds().get(0), parsedResponse.getPersonIds().get(0));
    assertIiEquals(response.getAsOtherIDs().get(0).getId().get(0), parsedResponse.getAsOtherIDs().get(0).getId().get(0));
}
Also used : PRPAIN201310UV02Type(net.ihe.gazelle.hl7v3.prpain201310UV02.PRPAIN201310UV02Type) Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) JAXBContext(javax.xml.bind.JAXBContext) PixV3QueryResponse(org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse) Unmarshaller(javax.xml.bind.Unmarshaller) PixV3QueryRequestTransformerTest(org.openehealth.ipf.commons.ihe.hl7v3.core.transform.requests.PixV3QueryRequestTransformerTest) Test(org.junit.jupiter.api.Test)

Example 4 with PixV3QueryResponse

use of org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse in project ipf by oehf.

the class PixV3QueryResponseTransformerTest method getSampleResponse.

public static PixV3QueryResponse getSampleResponse() {
    final PixV3QueryResponse response = PixV3QueryResponse.fromQuery(getSampleQuery());
    response.setDataFound();
    response.setTargetMessageId(new II("m1", "1.3.5"));
    response.setMessageId(new II("m2", "1.3.5"));
    response.getPatientIds().addAll(List.of(new II("9810", "2.16.756.5.30.1.127")));
    response.setCustodianOid("1.4.2");
    response.setProviderOrganization(new COCTMT150003UV03Organization());
    response.getProviderOrganization().getName().add(new ON());
    response.getProviderOrganization().getName().get(0).mixed = List.of("Provider Organization");
    response.setPersonName(new PN());
    response.getPersonName().mixed = List.of("Person Name");
    response.getPersonIds().add(new II("76133761", "1.3.6.1.4.1.12559.11.25.1.19"));
    response.getAsOtherIDs().add(new PRPAMT201304UV02OtherIDs());
    response.getAsOtherIDs().get(0).setId(List.of(new II("1.2.840.114350.1.13", "38273N237")));
    final MCCIMT000300UV01AcknowledgementDetail ad = new MCCIMT000300UV01AcknowledgementDetail();
    ad.setCode(new CE("204", null, null));
    ad.getLocation().add(new ST());
    ad.getLocation().get(0).mixed = List.of("/hl7:PRPA_IN201309UV02/hl7:controlActProcess");
    ad.setText(new ED());
    ad.getText().mixed = List.of("Requested record not found");
    response.getAcknowledgementDetails().add(ad);
    return response;
}
Also used : COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) PRPAMT201304UV02OtherIDs(net.ihe.gazelle.hl7v3.prpamt201304UV02.PRPAMT201304UV02OtherIDs) PixV3QueryResponse(org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse) MCCIMT000300UV01AcknowledgementDetail(net.ihe.gazelle.hl7v3.mccimt000300UV01.MCCIMT000300UV01AcknowledgementDetail)

Aggregations

PixV3QueryResponse (org.openehealth.ipf.commons.ihe.hl7v3.core.responses.PixV3QueryResponse)3 Test (org.junit.jupiter.api.Test)2 Device (org.openehealth.ipf.commons.ihe.hl7v3.core.metadata.Device)2 DataTypeException (ca.uhn.hl7v2.model.DataTypeException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 Optional (java.util.Optional)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 COCTMT090003UV01AssignedEntity (net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity)1 COCTMT150003UV03Organization (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization)1 net.ihe.gazelle.hl7v3.datatypes (net.ihe.gazelle.hl7v3.datatypes)1 II (net.ihe.gazelle.hl7v3.datatypes.II)1 net.ihe.gazelle.hl7v3.mccimt000300UV01 (net.ihe.gazelle.hl7v3.mccimt000300UV01)1 MCCIMT000300UV01AcknowledgementDetail (net.ihe.gazelle.hl7v3.mccimt000300UV01.MCCIMT000300UV01AcknowledgementDetail)1 MFMIMT700711UV01Custodian (net.ihe.gazelle.hl7v3.mfmimt700711UV01.MFMIMT700711UV01Custodian)1 MFMIMT700711UV01QueryAck (net.ihe.gazelle.hl7v3.mfmimt700711UV01.MFMIMT700711UV01QueryAck)1 net.ihe.gazelle.hl7v3.prpain201310UV02 (net.ihe.gazelle.hl7v3.prpain201310UV02)1