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;
}
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());
}
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));
}
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;
}
Aggregations