use of net.ihe.gazelle.hl7v3.coctmt030007UV.COCTMT030007UVPerson in project MobileAccessGateway by i4mi.
the class Iti78ResponseConverter method translateToFhir.
public List<Patient> translateToFhir(byte[] input, Map<String, Object> parameters) {
try {
// FIX for xmlns:xmlns
String content = new String(input);
content = content.replace("xmlns:xmlns", "xmlns:xxxxx");
List<Patient> response = new ArrayList<Patient>();
PRPAIN201306UV02Type msg = HL7V3Transformer.unmarshallMessage(PRPAIN201306UV02Type.class, new ByteArrayInputStream(content.getBytes()));
PRPAIN201306UV02MFMIMT700711UV01ControlActProcess 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"));
}
List<PRPAIN201306UV02MFMIMT700711UV01Subject1> subjects = controlAct.getSubject();
for (PRPAIN201306UV02MFMIMT700711UV01Subject1 subject : subjects) {
PRPAIN201306UV02MFMIMT700711UV01RegistrationEvent registrationEvent = subject.getRegistrationEvent();
PRPAIN201306UV02MFMIMT700711UV01Subject2 subject1 = registrationEvent.getSubject1();
PRPAMT201310UV02Patient patient = subject1.getPatient();
PRPAMT201310UV02Person patientPerson = patient.getPatientPerson();
if (patient.getId().isEmpty())
continue;
Patient result = new Patient();
boolean idadded = false;
for (II patientId : patient.getId()) {
result.addIdentifier().setSystem(getSystem(patientId.getRoot())).setValue(patientId.getExtension());
if (!idadded) {
result.setId(patientRefCreator.createPatientId(patientId.getRoot(), patientId.getExtension()));
idadded = true;
}
}
for (PRPAMT201310UV02OtherIDs otherIds : patient.getPatientPerson().getAsOtherIDs()) {
for (II patientId : otherIds.getId()) {
result.addIdentifier().setSystem(getSystem(patientId.getRoot())).setValue(patientId.getExtension());
}
}
CS statusCode = patient.getStatusCode();
if (statusCode != null && "active".equals(statusCode.getCode()))
result.setActive(true);
for (PN name : patientPerson.getName()) {
HumanName humanName = new HumanName();
for (EnFamily family : name.getFamily()) {
if ("BR".equals(family.getQualifier())) {
humanName.setUse(NameUse.MAIDEN);
}
humanName.setFamily(val(family));
}
for (EnGiven given : name.getGiven()) {
withQualifier(given, humanName.addGivenElement());
}
for (EnPrefix prefix : name.getPrefix()) {
withQualifier(prefix, humanName.addPrefixElement());
}
for (EnSuffix suffix : name.getSuffix()) {
withQualifier(suffix, humanName.addSuffixElement());
}
if (name.getValidTime() != null)
humanName.setPeriod(transform(name.getValidTime()));
result.addName(humanName);
}
CE gender = patientPerson.getAdministrativeGenderCode();
if (gender != null) {
switch(gender.getCode()) {
case "M":
result.setGender(AdministrativeGender.MALE);
break;
case "F":
result.setGender(AdministrativeGender.FEMALE);
break;
case "A":
result.setGender(AdministrativeGender.OTHER);
break;
case "U":
result.setGender(AdministrativeGender.UNKNOWN);
break;
}
}
TS birthTime = patientPerson.getBirthTime();
if (birthTime != null) {
result.setBirthDateElement(transform(birthTime));
}
for (AD ad : patientPerson.getAddr()) {
result.addAddress(transform(ad));
}
for (TEL tel : patientPerson.getTelecom()) {
result.addTelecom(transform(tel));
}
for (PRPAMT201310UV02LanguageCommunication lang : patientPerson.getLanguageCommunication()) {
CE langCode = lang.getLanguageCode();
PatientCommunicationComponent pcc = new PatientCommunicationComponent();
pcc.setLanguage(transform(langCode));
BL preferred = lang.getPreferenceInd();
if (preferred != null && preferred.getValue().booleanValue())
pcc.setPreferred(true);
result.addCommunication(pcc);
}
TS deceasedTime = patientPerson.getDeceasedTime();
if (deceasedTime != null)
result.setDeceased(transform(deceasedTime));
else {
BL deceased = patientPerson.getDeceasedInd();
if (deceased != null)
result.setDeceased(new BooleanType(deceased.getValue().booleanValue()));
}
INT multiBirthOrder = patientPerson.getMultipleBirthOrderNumber();
if (multiBirthOrder != null) {
result.setMultipleBirth(new IntegerType(multiBirthOrder.getValue()));
} else {
BL multipleBirth = patientPerson.getMultipleBirthInd();
if (multipleBirth != null)
result.setMultipleBirth(new BooleanType(multipleBirth.getValue().booleanValue()));
}
CE maritalStatus = patientPerson.getMaritalStatusCode();
result.setMaritalStatus(transform(maritalStatus));
for (PRPAMT201310UV02PersonalRelationship relationShip : patientPerson.getPersonalRelationship()) {
CE code = relationShip.getCode();
if (code != null && "MTH".equals(code.getCode()) && "2.16.840.1.113883.12.63".equals(code.getCodeSystem())) {
COCTMT030007UVPerson holder = relationShip.getRelationshipHolder1();
if (holder != null && !holder.getName().isEmpty()) {
EN name = holder.getName().get(0);
if (!name.getFamily().isEmpty()) {
String familyName = val(name.getFamily());
result.addExtension("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName", new StringType(familyName));
}
}
}
}
response.add(result);
}
return response;
} catch (JAXBException e) {
e.printStackTrace();
throw new InvalidRequestException("failed parsing response");
}
}
Aggregations