use of net.ihe.gazelle.hl7v3.prpain201310UV02.PRPAIN201310UV02Type in project MobileAccessGateway by i4mi.
the class Iti83ResponseConverter method translateToFhir.
public Parameters translateToFhir(byte[] input, Map<String, Object> parameters) {
try {
// FIX for xmlns:xmlns
String content = new String(input);
content = content.replace("xmlns:xmlns", "xmlns:xxxxx");
PRPAIN201310UV02Type msg = HL7V3Transformer.unmarshallMessage(PRPAIN201310UV02Type.class, new ByteArrayInputStream(content.getBytes()));
Parameters query = (Parameters) parameters.get(Utils.KEPT_BODY);
List<Type> targetSystemList = (List<Type>) query.getParameters("targetSystem");
Parameters response = new Parameters();
PRPAIN201310UV02MFMIMT700711UV01ControlActProcess controlAct = msg.getControlActProcess();
List<MCCIMT000300UV01Acknowledgement> acks = msg.getAcknowledgement();
String errtext = "";
for (MCCIMT000300UV01Acknowledgement ack : acks) {
for (MCCIMT000300UV01AcknowledgementDetail ackDetail : ack.getAcknowledgementDetail()) {
if (ackDetail.getText() != null)
errtext += toText(ackDetail.getText());
}
}
// OK NF AE
String queryResponseCode = controlAct.getQueryAck().getQueryResponseCode().getCode();
if ("NF".equals(queryResponseCode)) {
throw new ResourceNotFoundException("sourceIdentifier Patient Identifier not found", error(IssueType.NOTFOUND, errtext.length() > 0 ? errtext : "sourceIdentifier Patient Identifier not found"));
}
if ("AE".equals(queryResponseCode)) {
throw new InvalidRequestException("sourceIdentifier Assigning Authority not found", error(IssueType.INVALID, errtext.length() > 0 ? errtext : "sourceIdentifier Assigning Authority not found"));
}
Set<String> acceptedTargetSystem = new HashSet<String>();
Set<String> noDuplicates = new HashSet<String>();
if (targetSystemList != null) {
for (Type targetSystemType : targetSystemList) {
UriType targetSystem = (UriType) targetSystemType;
acceptedTargetSystem.add(targetSystem.getValue());
}
}
List<PRPAIN201310UV02MFMIMT700711UV01Subject1> subjects = controlAct.getSubject();
for (PRPAIN201310UV02MFMIMT700711UV01Subject1 subject : subjects) {
boolean targetIdAdded = false;
List<II> ids = new ArrayList<II>();
ids.addAll(subject.getRegistrationEvent().getSubject1().getPatient().getId());
for (var otherId : subject.getRegistrationEvent().getSubject1().getPatient().getPatientPerson().getAsOtherIDs()) {
ids.addAll(otherId.getId());
}
for (II ii : ids) {
String root = ii.getRoot();
String extension = ii.getExtension();
if (!noDuplicates.contains(root) && (acceptedTargetSystem.isEmpty() || acceptedTargetSystem.contains("urn:oid:" + root))) {
response.addParameter().setName("targetIdentifier").setValue((new Identifier()).setSystem("urn:oid:" + root).setValue(extension));
noDuplicates.add(root);
}
if (!targetIdAdded && root.equals(config.getOidMpiPid())) {
response.addParameter().setName("targetId").setValue(patientRefCreator.createPatientReference(root, extension));
targetIdAdded = true;
}
}
}
return response;
} catch (JAXBException e) {
e.printStackTrace();
throw new InvalidRequestException("failed parsing response");
}
}
use of net.ihe.gazelle.hl7v3.prpain201310UV02.PRPAIN201310UV02Type 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 net.ihe.gazelle.hl7v3.prpain201310UV02.PRPAIN201310UV02Type in project ipf by oehf.
the class PixV3QueryResponseTransformer method toPrpa.
/**
* Transforms a simplified response into the full PRPA model.
*
* @param simpleResponse The simplified response to transform.
* @return the PRPA model response or {@code null} if the input was {@code null}.
*/
public PRPAIN201310UV02Type toPrpa(final PixV3QueryResponse simpleResponse) {
if (simpleResponse == null) {
return null;
}
// Prepare response with fixed values
final PRPAIN201310UV02Type response = new PRPAIN201310UV02Type();
response.setITSVersion("XML_1.0");
response.setInteractionId(new II("2.16.840.1.113883.1.6", "PRPA_IN201310UV02"));
response.setProcessingCode(new CS("P", null, null));
response.setProcessingModeCode(new CS("T", null, null));
response.setAcceptAckCode(new CS("NE", null, null));
final MCCIMT000300UV01Acknowledgement acknowledgement = new MCCIMT000300UV01Acknowledgement();
response.getAcknowledgement().add(acknowledgement);
final PRPAIN201310UV02MFMIMT700711UV01ControlActProcess controlActProcess = new PRPAIN201310UV02MFMIMT700711UV01ControlActProcess();
controlActProcess.setClassCode(ActClassControlAct.CACT);
controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
controlActProcess.setCode(new CD("PRPA_TE201310UV02", null, null));
response.setControlActProcess(controlActProcess);
final MFMIMT700711UV01QueryAck queryAck = new MFMIMT700711UV01QueryAck();
controlActProcess.setQueryAck(queryAck);
final PRPAMT201307UV02QueryByParameter queryByParameter = new PRPAMT201307UV02QueryByParameter();
queryByParameter.setStatusCode(new CS("new", null, null));
queryByParameter.setResponsePriorityCode(new CS("I", null, null));
queryByParameter.setParameterList(new PRPAMT201307UV02ParameterList());
controlActProcess.setQueryByParameter(queryByParameter);
// Fill response with given data
response.setCreationTime(new TS());
response.getCreationTime().setValue(HL7DTM.toSimpleString(simpleResponse.getCreationTime()));
response.setId(simpleResponse.getMessageId());
response.setReceiver(List.of(toReceiver(simpleResponse.getReceiver())));
response.setSender(toSender(simpleResponse.getSender()));
queryByParameter.setQueryId(simpleResponse.getQueryId());
final PRPAMT201307UV02PatientIdentifier patientIdentifier = new PRPAMT201307UV02PatientIdentifier();
patientIdentifier.setValue(List.of(simpleResponse.getQueryPatientId()));
patientIdentifier.setSemanticsText(new ST());
patientIdentifier.getSemanticsText().mixed = List.of("Patient.id");
queryByParameter.getParameterList().setPatientIdentifier(List.of(patientIdentifier));
for (final String dataSourceOid : simpleResponse.getDataSourceOids()) {
final PRPAMT201307UV02DataSource dataSource = new PRPAMT201307UV02DataSource();
dataSource.setValue(List.of(new II(dataSourceOid, null)));
dataSource.setSemanticsText(new ST());
dataSource.getSemanticsText().mixed = List.of("DataSource.id");
queryByParameter.getParameterList().getDataSource().add(dataSource);
}
acknowledgement.setTypeCode(new CS(simpleResponse.getAcknowledgementTypeCode(), null, null));
acknowledgement.setTargetMessage(new MCCIMT000300UV01TargetMessage());
acknowledgement.getTargetMessage().setId(simpleResponse.getTargetMessageId());
acknowledgement.getAcknowledgementDetail().addAll(simpleResponse.getAcknowledgementDetails());
queryAck.setQueryId(simpleResponse.getQueryId());
queryAck.setQueryResponseCode(new CS(simpleResponse.getQueryResponseCode(), null, null));
queryAck.setStatusCode(new CS("deliveredResponse", null, null));
if (!"OK".equals(simpleResponse.getQueryResponseCode())) {
// If the query response code is not OK, no RegistrationEvent shall be returned
return response;
}
final PRPAIN201310UV02MFMIMT700711UV01Subject1 subject = new PRPAIN201310UV02MFMIMT700711UV01Subject1();
subject.setTypeCode("SUBJ");
controlActProcess.getSubject().add(subject);
final PRPAIN201310UV02MFMIMT700711UV01RegistrationEvent registrationEvent = new PRPAIN201310UV02MFMIMT700711UV01RegistrationEvent();
registrationEvent.setStatusCode(new CS("ACTIVE", null, null));
registrationEvent.setClassCode(ActClass.REG);
registrationEvent.setMoodCode(ActMood.EVN);
subject.setRegistrationEvent(registrationEvent);
final PRPAIN201310UV02MFMIMT700711UV01Subject2 subject1 = new PRPAIN201310UV02MFMIMT700711UV01Subject2();
subject1.setTypeCode(ParticipationTargetSubject.SBJ);
registrationEvent.setSubject1(subject1);
final PRPAMT201304UV02Patient patient = new PRPAMT201304UV02Patient();
patient.setClassCode("PAT");
patient.setStatusCode(new CS("ACTIVE", null, null));
patient.setId(simpleResponse.getPatientIds());
patient.setProviderOrganization(simpleResponse.getProviderOrganization());
subject1.setPatient(patient);
final PRPAMT201304UV02Person person = new PRPAMT201304UV02Person();
person.setClassCode(EntityClass.PSN);
person.setDeterminerCode(EntityDeterminer.INSTANCE);
if (simpleResponse.getPersonName() != null) {
person.getName().add(simpleResponse.getPersonName());
}
person.getId().addAll(simpleResponse.getPersonIds());
person.getAsOtherIDs().addAll(simpleResponse.getAsOtherIDs());
patient.setPatientPerson(person);
final MFMIMT700711UV01Custodian custodian = new MFMIMT700711UV01Custodian();
custodian.setTypeCode(ParticipationType.CST);
registrationEvent.setCustodian(custodian);
final COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity();
assignedEntity.setClassCode(RoleClassAssignedEntity.ASSIGNED);
assignedEntity.getId().add(new II(simpleResponse.getCustodianOid(), null));
custodian.setAssignedEntity(assignedEntity);
return response;
}
use of net.ihe.gazelle.hl7v3.prpain201310UV02.PRPAIN201310UV02Type 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));
}
Aggregations