Search in sources :

Example 6 with PatientCommunicationComponent

use of org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent 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)) {
        // NF (data found, no errors) is returned in QueryAck.queryResponseCode (control act wrapper)
        // 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");
    }
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) PRPAIN201306UV02MFMIMT700711UV01Subject2(net.ihe.gazelle.hl7v3.prpain201306UV02.PRPAIN201306UV02MFMIMT700711UV01Subject2) PRPAIN201306UV02MFMIMT700711UV01Subject1(net.ihe.gazelle.hl7v3.prpain201306UV02.PRPAIN201306UV02MFMIMT700711UV01Subject1) BL(net.ihe.gazelle.hl7v3.datatypes.BL) MCCIMT000300UV01Acknowledgement(net.ihe.gazelle.hl7v3.mccimt000300UV01.MCCIMT000300UV01Acknowledgement) PRPAMT201310UV02Patient(net.ihe.gazelle.hl7v3.prpamt201310UV02.PRPAMT201310UV02Patient) INT(net.ihe.gazelle.hl7v3.datatypes.INT) HumanName(org.hl7.fhir.r4.model.HumanName) COCTMT030007UVPerson(net.ihe.gazelle.hl7v3.coctmt030007UV.COCTMT030007UVPerson) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) PRPAMT201310UV02OtherIDs(net.ihe.gazelle.hl7v3.prpamt201310UV02.PRPAMT201310UV02OtherIDs) EnFamily(net.ihe.gazelle.hl7v3.datatypes.EnFamily) PRPAMT201310UV02Person(net.ihe.gazelle.hl7v3.prpamt201310UV02.PRPAMT201310UV02Person) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) EnSuffix(net.ihe.gazelle.hl7v3.datatypes.EnSuffix) PRPAIN201306UV02MFMIMT700711UV01RegistrationEvent(net.ihe.gazelle.hl7v3.prpain201306UV02.PRPAIN201306UV02MFMIMT700711UV01RegistrationEvent) PRPAIN201306UV02Type(net.ihe.gazelle.hl7v3.prpain201306UV02.PRPAIN201306UV02Type) II(net.ihe.gazelle.hl7v3.datatypes.II) PRPAIN201306UV02MFMIMT700711UV01ControlActProcess(net.ihe.gazelle.hl7v3.prpain201306UV02.PRPAIN201306UV02MFMIMT700711UV01ControlActProcess) CE(net.ihe.gazelle.hl7v3.datatypes.CE) EnPrefix(net.ihe.gazelle.hl7v3.datatypes.EnPrefix) AD(net.ihe.gazelle.hl7v3.datatypes.AD) JAXBException(javax.xml.bind.JAXBException) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) PRPAMT201310UV02Patient(net.ihe.gazelle.hl7v3.prpamt201310UV02.PRPAMT201310UV02Patient) EnGiven(net.ihe.gazelle.hl7v3.datatypes.EnGiven) EN(net.ihe.gazelle.hl7v3.datatypes.EN) CS(net.ihe.gazelle.hl7v3.datatypes.CS) IntegerType(org.hl7.fhir.r4.model.IntegerType) PRPAMT201310UV02PersonalRelationship(net.ihe.gazelle.hl7v3.prpamt201310UV02.PRPAMT201310UV02PersonalRelationship) ByteArrayInputStream(java.io.ByteArrayInputStream) TEL(net.ihe.gazelle.hl7v3.datatypes.TEL) MCCIMT000300UV01AcknowledgementDetail(net.ihe.gazelle.hl7v3.mccimt000300UV01.MCCIMT000300UV01AcknowledgementDetail) PRPAMT201310UV02LanguageCommunication(net.ihe.gazelle.hl7v3.prpamt201310UV02.PRPAMT201310UV02LanguageCommunication) PN(net.ihe.gazelle.hl7v3.datatypes.PN) IVXBTS(net.ihe.gazelle.hl7v3.datatypes.IVXBTS) IVLTS(net.ihe.gazelle.hl7v3.datatypes.IVLTS) TS(net.ihe.gazelle.hl7v3.datatypes.TS)

Example 7 with PatientCommunicationComponent

use of org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent in project MobileAccessGateway by i4mi.

the class Iti104MergeRequestConverter method doMerge.

/**
 * merge request for ITI-104 transaction
 * @param header
 * @param entriesByReference
 * @return
 * @throws JAXBException
 */
public String doMerge(Patient in, Identifier replaced, Reference survivor) throws JAXBException {
    PRPAIN201304UV02Type resultMsg = new PRPAIN201304UV02Type();
    resultMsg.setITSVersion("XML_1.0");
    // String UUID.randomUUID().toString();
    resultMsg.setId(new II(config.getPixQueryOid(), uniqueId()));
    // Now
    resultMsg.setCreationTime(new TS(Timestamp.now().toHL7()));
    resultMsg.setProcessingCode(new CS("T", null, null));
    resultMsg.setProcessingModeCode(new CS("T", null, null));
    resultMsg.setInteractionId(new II("2.16.840.1.113883.1.18", "PRPA_IN201304UV02"));
    resultMsg.setAcceptAckCode(new CS("AL", null, null));
    MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver();
    resultMsg.addReceiver(receiver);
    receiver.setTypeCode(CommunicationFunctionType.RCV);
    MCCIMT000100UV01Device receiverDevice = new MCCIMT000100UV01Device();
    receiver.setDevice(receiverDevice);
    receiverDevice.setClassCode(EntityClassDevice.DEV);
    receiverDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
    receiverDevice.setId(Collections.singletonList(new II(config.getPixReceiverOid(), null)));
    MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender();
    resultMsg.setSender(sender);
    sender.setTypeCode(CommunicationFunctionType.SND);
    MCCIMT000100UV01Device senderDevice = new MCCIMT000100UV01Device();
    sender.setDevice(senderDevice);
    senderDevice.setClassCode(EntityClassDevice.DEV);
    senderDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
    senderDevice.setId(Collections.singletonList(new II(config.getPixMySenderOid(), null)));
    PRPAIN201304UV02MFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201304UV02MFMIMT700701UV01ControlActProcess();
    resultMsg.setControlActProcess(controlActProcess);
    // ???
    controlActProcess.setClassCode(ActClassControlAct.CACT);
    // ???
    controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
    // ???
    controlActProcess.setCode(new CD("PRPA_TE201304UV02", "2.16.840.1.113883.1.18", null));
    if (in == null || replaced.isEmpty())
        throw new InvalidRequestException("Cannot determine Patients to merge");
    PRPAIN201304UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201304UV02MFMIMT700701UV01Subject1();
    controlActProcess.addSubject(subject);
    subject.setTypeCode("SUBJ");
    // ???
    subject.setContextConductionInd(false);
    PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent();
    subject.setRegistrationEvent(registrationEvent);
    registrationEvent.setClassCode(ActClass.REG);
    registrationEvent.setMoodCode(ActMood.EVN);
    // ???
    registrationEvent.setStatusCode(new CS("active", null, null));
    List<MFMIMT700701UV01ReplacementOf> replacementOfList = new ArrayList<MFMIMT700701UV01ReplacementOf>();
    registrationEvent.setReplacementOf(replacementOfList);
    MFMIMT700701UV01ReplacementOf replacementOf = new MFMIMT700701UV01ReplacementOf();
    MFMIMT700701UV01PriorRegistration priorRegistration = new MFMIMT700701UV01PriorRegistration();
    replacementOf.setPriorRegistration(priorRegistration);
    replacementOf.setTypeCode("RPLC");
    priorRegistration.setClassCode(ActClass.REG);
    priorRegistration.setMoodCode(ActMood.EVN);
    priorRegistration.setStatusCode(new CS("obsolete", null, null));
    MFMIMT700701UV01Subject3 subject1 = new MFMIMT700701UV01Subject3();
    priorRegistration.setSubject1(subject1);
    subject1.setTypeCode(ParticipationTargetSubject.SBJ);
    MFMIMT700701UV01PriorRegisteredRole priorRegisteredRole = new MFMIMT700701UV01PriorRegisteredRole();
    subject1.setPriorRegisteredRole(priorRegisteredRole);
    priorRegisteredRole.setClassCode("PAT");
    priorRegisteredRole.addId(patientIdentifier(replaced));
    replacementOfList.add(replacementOf);
    PRPAIN201304UV02MFMIMT700701UV01Subject2 subject2 = new PRPAIN201304UV02MFMIMT700701UV01Subject2();
    registrationEvent.setSubject1(subject2);
    subject2.setTypeCode(ParticipationTargetSubject.SBJ);
    PRPAMT201303UV02Patient patient = new PRPAMT201303UV02Patient();
    patient.setClassCode("PAT");
    subject2.setPatient(patient);
    PRPAMT201302UV02PatientStatusCode statusCode = new PRPAMT201302UV02PatientStatusCode("active", null, null);
    // ???
    patient.setStatusCode(statusCode);
    List<II> orgIds = new ArrayList<II>();
    Set<String> mainIds = new HashSet<String>();
    PRPAMT201303UV02Person patientPerson = new PRPAMT201303UV02Person();
    patientPerson.setClassCode(EntityClass.PSN);
    patientPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
    patient.setPatientPerson(patientPerson);
    Organization managingOrg = getManagingOrganization(in, in.getContained());
    if (managingOrg != null) {
        for (Identifier id : managingOrg.getIdentifier()) {
            orgIds.add(new II(getScheme(id.getSystem()), null));
            mainIds.add(id.getSystem());
        }
    }
    // if (managingOrg==null) managingOrg = getManagingOrganization(basePatient, basePatient.getContained());
    // if (managingOrg==null)  throw new InvalidRequestException("Cannot determine managingOrganization");
    // TODO How is the correct mapping done?
    Identifier id = survivor.getIdentifier();
    PRPAMT201302UV02PatientId patientId = new PRPAMT201302UV02PatientId(getScheme(id.getSystem()), id.getValue());
    patient.addId(patientId);
    for (HumanName name : in.getName()) {
        patientPerson.addName(transform(name));
    }
    COCTMT150003UV03Organization providerOrganization = new COCTMT150003UV03Organization();
    patient.setProviderOrganization(providerOrganization);
    providerOrganization.setClassCode(EntityClassOrganization.ORG);
    providerOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
    providerOrganization.setId(orgIds);
    ON name = null;
    if (managingOrg.hasName()) {
        name = new ON();
        name.setMixed(Collections.singletonList(managingOrg.getName()));
        providerOrganization.setName(Collections.singletonList(name));
    }
    COCTMT150003UV03ContactParty contactParty = new COCTMT150003UV03ContactParty();
    contactParty.setClassCode(RoleClassContact.CON);
    for (ContactPoint contactPoint : managingOrg.getTelecom()) {
        contactParty.addTelecom(transform(contactPoint));
    }
    if (managingOrg != null && managingOrg.hasAddress())
        contactParty.setAddr(new ArrayList<AD>());
    for (Address address : managingOrg.getAddress()) {
        contactParty.addAddr(transform(address));
    }
    if (managingOrg != null && managingOrg.hasContact()) {
        OrganizationContactComponent occ = managingOrg.getContactFirstRep();
        COCTMT150003UV03Person contactPerson = new COCTMT150003UV03Person();
        contactPerson.setClassCode(EntityClass.PSN);
        contactPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
        if (occ.hasName())
            contactPerson.setName(Collections.singletonList(transform(occ.getName())));
        contactParty.setContactPerson(contactPerson);
    }
    providerOrganization.setContactParty(Collections.singletonList(contactParty));
    patientPerson.setBirthTime(transform(in.getBirthDateElement()));
    if (in.hasGender()) {
        switch(in.getGender()) {
            case MALE:
                patientPerson.setAdministrativeGenderCode(new CE("M", "Male", "2.16.840.1.113883.12.1"));
                break;
            case FEMALE:
                patientPerson.setAdministrativeGenderCode(new CE("F", "Female", "2.16.840.1.113883.12.1"));
                break;
            case OTHER:
                patientPerson.setAdministrativeGenderCode(new CE("A", "Ambiguous", "2.16.840.1.113883.12.1"));
                break;
            case UNKNOWN:
                patientPerson.setAdministrativeGenderCode(new CE("U", "Unknown", "2.16.840.1.113883.12.1"));
                break;
        }
    }
    if (in.hasAddress())
        patientPerson.setAddr(new ArrayList<AD>());
    for (Address address : in.getAddress()) {
        patientPerson.addAddr(transform(address));
    }
    for (ContactPoint contactPoint : in.getTelecom()) {
        patientPerson.addTelecom(transform(contactPoint));
    }
    if (in.hasDeceasedBooleanType()) {
        patientPerson.setDeceasedInd(new BL(in.getDeceasedBooleanType().getValue()));
    }
    if (in.hasDeceasedDateTimeType()) {
        patientPerson.setDeceasedTime(transform(in.getDeceasedDateTimeType()));
    }
    if (in.hasMultipleBirthBooleanType()) {
        patientPerson.setMultipleBirthInd(new BL(in.getMultipleBirthBooleanType().getValue()));
    }
    if (in.hasMultipleBirthIntegerType()) {
        patientPerson.setMultipleBirthOrderNumber(new INT(in.getMultipleBirthIntegerType().getValue()));
    }
    if (in.hasMaritalStatus()) {
        patientPerson.setMaritalStatusCode(transform(in.getMaritalStatus()));
    }
    if (in.hasCommunication()) {
        for (PatientCommunicationComponent pcc : in.getCommunication()) {
            PRPAMT201303UV02LanguageCommunication languageCommunication = new PRPAMT201303UV02LanguageCommunication();
            languageCommunication.setLanguageCode(transform(pcc.getLanguage()));
            if (pcc.hasPreferred())
                languageCommunication.setPreferenceInd(new BL(pcc.getPreferred()));
            patientPerson.addLanguageCommunication(languageCommunication);
        }
    }
    MFMIMT700701UV01Custodian custodian = new MFMIMT700701UV01Custodian();
    registrationEvent.setCustodian(custodian);
    custodian.setTypeCode(ParticipationType.CST);
    COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity();
    custodian.setAssignedEntity(assignedEntity);
    assignedEntity.setClassCode(RoleClassAssignedEntity.ASSIGNED);
    List<II> custIds = new ArrayList<II>();
    custIds.add(new II(getScheme(config.getCustodianOid()), null));
    assignedEntity.setId(custIds);
    // assignedEntity.setId(orgIds);
    COCTMT090003UV01Organization assignedOrganization = new COCTMT090003UV01Organization();
    assignedEntity.setAssignedOrganization(assignedOrganization);
    assignedOrganization.setClassCode(EntityClassOrganization.ORG);
    assignedOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
    if (managingOrg != null && managingOrg.hasName()) {
        ON onName = new ON();
        onName.setMixed(Collections.singletonList(managingOrg.getName()));
        assignedOrganization.setName(Collections.singletonList(onName));
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    HL7V3Transformer.marshallMessage(PRPAIN201304UV02Type.class, out, resultMsg);
    String outArray = new String(out.toByteArray());
    return outArray;
}
Also used : COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) EntityClassOrganization(net.ihe.gazelle.hl7v3.voc.EntityClassOrganization) Organization(org.hl7.fhir.r4.model.Organization) PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent) Address(org.hl7.fhir.r4.model.Address) ArrayList(java.util.ArrayList) BL(net.ihe.gazelle.hl7v3.datatypes.BL) MFMIMT700701UV01PriorRegistration(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01PriorRegistration) INT(net.ihe.gazelle.hl7v3.datatypes.INT) PRPAMT201302UV02PatientId(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02PatientId) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Identifier(org.hl7.fhir.r4.model.Identifier) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) MCCIMT000100UV01Device(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device) HashSet(java.util.HashSet) ON(net.ihe.gazelle.hl7v3.datatypes.ON) II(net.ihe.gazelle.hl7v3.datatypes.II) CD(net.ihe.gazelle.hl7v3.datatypes.CD) CE(net.ihe.gazelle.hl7v3.datatypes.CE) PRPAIN201304UV02Type(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02Type) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) PRPAMT201303UV02LanguageCommunication(net.ihe.gazelle.hl7v3.prpamt201303UV02.PRPAMT201303UV02LanguageCommunication) PRPAIN201304UV02MFMIMT700701UV01Subject2(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01Subject2) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PRPAIN201304UV02MFMIMT700701UV01Subject1(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01Subject1) MCCIMT000100UV01Sender(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender) CS(net.ihe.gazelle.hl7v3.datatypes.CS) MFMIMT700701UV01Subject3(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01Subject3) MFMIMT700701UV01PriorRegisteredRole(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01PriorRegisteredRole) COCTMT150003UV03ContactParty(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03ContactParty) COCTMT150003UV03Person(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Person) OrganizationContactComponent(org.hl7.fhir.r4.model.Organization.OrganizationContactComponent) PRPAMT201302UV02PatientStatusCode(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02PatientStatusCode) PRPAMT201303UV02Person(net.ihe.gazelle.hl7v3.prpamt201303UV02.PRPAMT201303UV02Person) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) COCTMT090003UV01AssignedEntity(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity) MFMIMT700701UV01ReplacementOf(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01ReplacementOf) MFMIMT700701UV01Custodian(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01Custodian) MCCIMT000100UV01Receiver(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver) PRPAMT201303UV02Patient(net.ihe.gazelle.hl7v3.prpamt201303UV02.PRPAMT201303UV02Patient) TS(net.ihe.gazelle.hl7v3.datatypes.TS) PRPAIN201304UV02MFMIMT700701UV01ControlActProcess(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess)

Example 8 with PatientCommunicationComponent

use of org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent in project MobileAccessGateway by i4mi.

the class Iti93UpdateRequestConverter method doUpdate.

public String doUpdate(MessageHeader header, Map<String, BundleEntryComponent> entriesByReference) throws JAXBException {
    PRPAIN201302UV02Type resultMsg = new PRPAIN201302UV02Type();
    resultMsg.setITSVersion("XML_1.0");
    // String UUID.randomUUID().toString();
    resultMsg.setId(new II(config.getPixQueryOid(), uniqueId()));
    // Now
    resultMsg.setCreationTime(new TS(Timestamp.now().toHL7()));
    resultMsg.setProcessingCode(new CS("T", null, null));
    resultMsg.setProcessingModeCode(new CS("T", null, null));
    resultMsg.setInteractionId(new II("2.16.840.1.113883.1.18", "PRPA_IN201302UV02"));
    resultMsg.setAcceptAckCode(new CS("AL", null, null));
    MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver();
    resultMsg.addReceiver(receiver);
    receiver.setTypeCode(CommunicationFunctionType.RCV);
    MCCIMT000100UV01Device receiverDevice = new MCCIMT000100UV01Device();
    receiver.setDevice(receiverDevice);
    receiverDevice.setClassCode(EntityClassDevice.DEV);
    receiverDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
    receiverDevice.setId(Collections.singletonList(new II(config.getPixReceiverOid(), null)));
    MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender();
    resultMsg.setSender(sender);
    sender.setTypeCode(CommunicationFunctionType.SND);
    MCCIMT000100UV01Device senderDevice = new MCCIMT000100UV01Device();
    sender.setDevice(senderDevice);
    senderDevice.setClassCode(EntityClassDevice.DEV);
    senderDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
    senderDevice.setId(Collections.singletonList(new II(config.getPixMySenderOid(), null)));
    PRPAIN201302UV02MFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201302UV02MFMIMT700701UV01ControlActProcess();
    resultMsg.setControlActProcess(controlActProcess);
    controlActProcess.setClassCode(ActClassControlAct.CACT);
    controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
    controlActProcess.setCode(new CD("PRPA_TE201302UV02", "2.16.840.1.113883.1.18", null));
    for (BundleEntryComponent entry : entriesByReference.values()) {
        if (entry.getResource() instanceof Patient) {
            HTTPVerb method = entry.getRequest().getMethod();
            if (method == null)
                throw new InvalidRequestException("HTTP verb missing in Bundle for Patient resource.");
            Patient in = (Patient) entry.getResource();
            PRPAIN201302UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201302UV02MFMIMT700701UV01Subject1();
            controlActProcess.addSubject(subject);
            subject.setTypeCode("SUBJ");
            // ???
            subject.setContextConductionInd(false);
            PRPAIN201302UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201302UV02MFMIMT700701UV01RegistrationEvent();
            subject.setRegistrationEvent(registrationEvent);
            registrationEvent.setClassCode(ActClass.REG);
            registrationEvent.setMoodCode(ActMood.EVN);
            // ???
            registrationEvent.setStatusCode(new CS("active", null, null));
            PRPAIN201302UV02MFMIMT700701UV01Subject2 subject1 = new PRPAIN201302UV02MFMIMT700701UV01Subject2();
            registrationEvent.setSubject1(subject1);
            subject1.setTypeCode(ParticipationTargetSubject.SBJ);
            PRPAMT201302UV02Patient patient = new PRPAMT201302UV02Patient();
            subject1.setPatient(patient);
            patient.setClassCode("PAT");
            PRPAMT201302UV02PatientStatusCode statusCode = new PRPAMT201302UV02PatientStatusCode();
            statusCode.setCode("active");
            // ???
            patient.setStatusCode(statusCode);
            PRPAMT201302UV02PatientPatientPerson patientPerson = new PRPAMT201302UV02PatientPatientPerson();
            patient.setPatientPerson(patientPerson);
            patientPerson.setClassCode(EntityClass.PSN);
            patientPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
            patientPerson.setAsOtherIDs(new ArrayList());
            List<II> orgIds = new ArrayList<II>();
            Set<String> mainIds = new HashSet<String>();
            Organization managingOrg = getManagingOrganization(in);
            for (Identifier id : managingOrg.getIdentifier()) {
                orgIds.add(new II(getScheme(id.getSystem()), null));
                mainIds.add(id.getSystem());
            }
            // TODO How is the correct mapping done?
            for (Identifier id : in.getIdentifier()) {
                boolean isOwn = mainIds.contains(id.getSystem());
                if (isOwn)
                    patient.addId(patientIdentifierUpd(id));
                else {
                    PRPAMT201302UV02OtherIDs asOtherIDs = new PRPAMT201302UV02OtherIDs();
                    PRPAMT201302UV02OtherIDsId id2 = new PRPAMT201302UV02OtherIDsId();
                    id2.setRoot(getScheme(id.getSystem()));
                    id2.setExtension(id.getValue());
                    asOtherIDs.setClassCode("PAT");
                    asOtherIDs.setId(Collections.singletonList(id2));
                    COCTMT150002UV01Organization scopingOrganization = new COCTMT150002UV01Organization();
                    scopingOrganization.setClassCode(EntityClassOrganization.ORG);
                    scopingOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
                    List<II> scopeOrgIds = new ArrayList<II>();
                    scopeOrgIds.add(new II(getScheme(id.getSystem()), null));
                    scopingOrganization.setId(scopeOrgIds);
                    asOtherIDs.setScopingOrganization(scopingOrganization);
                    patientPerson.addAsOtherIDs(asOtherIDs);
                }
            }
            for (HumanName name : in.getName()) {
                patientPerson.addName(transform(name));
            }
            patientPerson.setBirthTime(transform(in.getBirthDateElement()));
            if (in.hasGender()) {
                switch(in.getGender()) {
                    case MALE:
                        patientPerson.setAdministrativeGenderCode(new CE("M", "Male", "2.16.840.1.113883.12.1"));
                        break;
                    case FEMALE:
                        patientPerson.setAdministrativeGenderCode(new CE("F", "Female", "2.16.840.1.113883.12.1"));
                        break;
                    case OTHER:
                        patientPerson.setAdministrativeGenderCode(new CE("A", "Ambiguous", "2.16.840.1.113883.12.1"));
                        break;
                    case UNKNOWN:
                        patientPerson.setAdministrativeGenderCode(new CE("U", "Unknown", "2.16.840.1.113883.12.1"));
                        break;
                }
            }
            if (in.hasAddress())
                patientPerson.setAddr(new ArrayList<AD>());
            for (Address address : in.getAddress()) {
                patientPerson.addAddr(transform(address));
            }
            for (ContactPoint contactPoint : in.getTelecom()) {
                patientPerson.addTelecom(transform(contactPoint));
            }
            if (in.hasDeceasedBooleanType()) {
                patientPerson.setDeceasedInd(new BL(in.getDeceasedBooleanType().getValue()));
            }
            if (in.hasDeceasedDateTimeType()) {
                patientPerson.setDeceasedTime(transform(in.getDeceasedDateTimeType()));
            }
            if (in.hasMultipleBirthBooleanType()) {
                patientPerson.setMultipleBirthInd(new BL(in.getMultipleBirthBooleanType().getValue()));
            }
            if (in.hasMultipleBirthIntegerType()) {
                patientPerson.setMultipleBirthOrderNumber(new INT(in.getMultipleBirthIntegerType().getValue()));
            }
            if (in.hasMaritalStatus()) {
                patientPerson.setMaritalStatusCode(transform(in.getMaritalStatus()));
            }
            if (in.hasCommunication()) {
                for (PatientCommunicationComponent pcc : in.getCommunication()) {
                    PRPAMT201302UV02LanguageCommunication languageCommunication = new PRPAMT201302UV02LanguageCommunication();
                    languageCommunication.setLanguageCode(transform(pcc.getLanguage()));
                    if (pcc.hasPreferred())
                        languageCommunication.setPreferenceInd(new BL(pcc.getPreferred()));
                    patientPerson.addLanguageCommunication(languageCommunication);
                }
            }
            COCTMT150003UV03Organization providerOrganization = new COCTMT150003UV03Organization();
            patient.setProviderOrganization(providerOrganization);
            providerOrganization.setClassCode(EntityClassOrganization.ORG);
            providerOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
            providerOrganization.setId(orgIds);
            ON name = null;
            if (managingOrg.hasName()) {
                name = new ON();
                name.setMixed(Collections.singletonList(managingOrg.getName()));
                providerOrganization.setName(Collections.singletonList(name));
            }
            COCTMT150003UV03ContactParty contactParty = new COCTMT150003UV03ContactParty();
            contactParty.setClassCode(RoleClassContact.CON);
            for (ContactPoint contactPoint : managingOrg.getTelecom()) {
                contactParty.addTelecom(transform(contactPoint));
            }
            if (managingOrg.hasAddress())
                contactParty.setAddr(new ArrayList<AD>());
            for (Address address : managingOrg.getAddress()) {
                contactParty.addAddr(transform(address));
            }
            if (managingOrg.hasContact()) {
                OrganizationContactComponent occ = managingOrg.getContactFirstRep();
                COCTMT150003UV03Person contactPerson = new COCTMT150003UV03Person();
                contactPerson.setClassCode(EntityClass.PSN);
                contactPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
                if (occ.hasName())
                    contactPerson.setName(Collections.singletonList(transform(occ.getName())));
                contactParty.setContactPerson(contactPerson);
            }
            providerOrganization.setContactParty(Collections.singletonList(contactParty));
            MFMIMT700701UV01Custodian custodian = new MFMIMT700701UV01Custodian();
            registrationEvent.setCustodian(custodian);
            custodian.setTypeCode(ParticipationType.CST);
            COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity();
            custodian.setAssignedEntity(assignedEntity);
            assignedEntity.setClassCode(RoleClassAssignedEntity.ASSIGNED);
            List<II> custIds = new ArrayList<II>();
            custIds.add(new II(getScheme(config.getCustodianOid()), null));
            assignedEntity.setId(custIds);
            // assignedEntity.setId(orgIds);
            COCTMT090003UV01Organization assignedOrganization = new COCTMT090003UV01Organization();
            assignedEntity.setAssignedOrganization(assignedOrganization);
            assignedOrganization.setClassCode(EntityClassOrganization.ORG);
            assignedOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
            if (managingOrg.hasName()) {
                assignedOrganization.setName(Collections.singletonList(name));
            }
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    HL7V3Transformer.marshallMessage(PRPAIN201302UV02Type.class, out, resultMsg);
    String outArray = new String(out.toByteArray());
    return outArray;
}
Also used : HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) COCTMT150002UV01Organization(net.ihe.gazelle.hl7v3.coctmt150002UV01.COCTMT150002UV01Organization) EntityClassOrganization(net.ihe.gazelle.hl7v3.voc.EntityClassOrganization) Organization(org.hl7.fhir.r4.model.Organization) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) Address(org.hl7.fhir.r4.model.Address) ArrayList(java.util.ArrayList) BL(net.ihe.gazelle.hl7v3.datatypes.BL) INT(net.ihe.gazelle.hl7v3.datatypes.INT) PRPAMT201302UV02OtherIDsId(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02OtherIDsId) PRPAIN201302UV02MFMIMT700701UV01Subject1(net.ihe.gazelle.hl7v3.prpain201302UV02.PRPAIN201302UV02MFMIMT700701UV01Subject1) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) PRPAIN201302UV02MFMIMT700701UV01Subject2(net.ihe.gazelle.hl7v3.prpain201302UV02.PRPAIN201302UV02MFMIMT700701UV01Subject2) Identifier(org.hl7.fhir.r4.model.Identifier) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) PRPAMT201302UV02OtherIDs(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02OtherIDs) MCCIMT000100UV01Device(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device) HashSet(java.util.HashSet) ON(net.ihe.gazelle.hl7v3.datatypes.ON) II(net.ihe.gazelle.hl7v3.datatypes.II) CD(net.ihe.gazelle.hl7v3.datatypes.CD) PRPAMT201302UV02Patient(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02Patient) CE(net.ihe.gazelle.hl7v3.datatypes.CE) PRPAIN201302UV02MFMIMT700701UV01ControlActProcess(net.ihe.gazelle.hl7v3.prpain201302UV02.PRPAIN201302UV02MFMIMT700701UV01ControlActProcess) PRPAIN201302UV02Type(net.ihe.gazelle.hl7v3.prpain201302UV02.PRPAIN201302UV02Type) PRPAMT201302UV02LanguageCommunication(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02LanguageCommunication) PRPAIN201302UV02MFMIMT700701UV01RegistrationEvent(net.ihe.gazelle.hl7v3.prpain201302UV02.PRPAIN201302UV02MFMIMT700701UV01RegistrationEvent) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) Patient(org.hl7.fhir.r4.model.Patient) PRPAMT201302UV02Patient(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02Patient) PRPAMT201301UV02Patient(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MCCIMT000100UV01Sender(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender) CS(net.ihe.gazelle.hl7v3.datatypes.CS) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) COCTMT150003UV03ContactParty(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03ContactParty) COCTMT150003UV03Person(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Person) OrganizationContactComponent(org.hl7.fhir.r4.model.Organization.OrganizationContactComponent) PRPAMT201302UV02PatientStatusCode(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02PatientStatusCode) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) COCTMT090003UV01AssignedEntity(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity) MFMIMT700701UV01Custodian(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01Custodian) MCCIMT000100UV01Receiver(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver) COCTMT150002UV01Organization(net.ihe.gazelle.hl7v3.coctmt150002UV01.COCTMT150002UV01Organization) PRPAMT201302UV02PatientPatientPerson(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02PatientPatientPerson) TS(net.ihe.gazelle.hl7v3.datatypes.TS)

Example 9 with PatientCommunicationComponent

use of org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent in project MobileAccessGateway by i4mi.

the class Iti93MergeRequestConverter method doMerge.

/**
 * merge request for ITI-93 transaction
 * @param header
 * @param entriesByReference
 * @return
 * @throws JAXBException
 */
public String doMerge(MessageHeader header, Map<String, BundleEntryComponent> entriesByReference) throws JAXBException {
    PRPAIN201304UV02Type resultMsg = new PRPAIN201304UV02Type();
    resultMsg.setITSVersion("XML_1.0");
    // String UUID.randomUUID().toString();
    resultMsg.setId(new II(config.getPixQueryOid(), uniqueId()));
    // Now
    resultMsg.setCreationTime(new TS(Timestamp.now().toHL7()));
    resultMsg.setProcessingCode(new CS("T", null, null));
    resultMsg.setProcessingModeCode(new CS("T", null, null));
    resultMsg.setInteractionId(new II("2.16.840.1.113883.1.18", "PRPA_IN201304UV02"));
    resultMsg.setAcceptAckCode(new CS("AL", null, null));
    MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver();
    resultMsg.addReceiver(receiver);
    receiver.setTypeCode(CommunicationFunctionType.RCV);
    MCCIMT000100UV01Device receiverDevice = new MCCIMT000100UV01Device();
    receiver.setDevice(receiverDevice);
    receiverDevice.setClassCode(EntityClassDevice.DEV);
    receiverDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
    receiverDevice.setId(Collections.singletonList(new II(config.getPixReceiverOid(), null)));
    MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender();
    resultMsg.setSender(sender);
    sender.setTypeCode(CommunicationFunctionType.SND);
    MCCIMT000100UV01Device senderDevice = new MCCIMT000100UV01Device();
    sender.setDevice(senderDevice);
    senderDevice.setClassCode(EntityClassDevice.DEV);
    senderDevice.setDeterminerCode(EntityDeterminer.INSTANCE);
    senderDevice.setId(Collections.singletonList(new II(config.getPixMySenderOid(), null)));
    PRPAIN201304UV02MFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201304UV02MFMIMT700701UV01ControlActProcess();
    resultMsg.setControlActProcess(controlActProcess);
    // ???
    controlActProcess.setClassCode(ActClassControlAct.CACT);
    // ???
    controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
    // ???
    controlActProcess.setCode(new CD("PRPA_TE201304UV02", "2.16.840.1.113883.1.18", null));
    for (BundleEntryComponent entry : entriesByReference.values()) {
        // BundleEntryComponent entry = entriesByReference.get(ref.getReference());
        HTTPVerb method = entry.getRequest().getMethod();
        if (method == null)
            throw new InvalidRequestException("HTTP verb missing in Bundle for Patient resource.");
        Patient basePatient = (Patient) entry.getResource();
        Patient in = null;
        List<Patient> replaced = new ArrayList<Patient>();
        for (PatientLinkComponent linked : basePatient.getLink()) {
            if (linked.getType().equals(LinkType.REPLACEDBY)) {
                Reference other = linked.getOther();
                Patient otherPatient = findPatient(other, entriesByReference, basePatient);
                in = otherPatient;
                replaced.add(basePatient);
            } else if (linked.getType().equals(LinkType.REPLACES)) {
                Reference other = linked.getOther();
                Patient otherPatient = findPatient(other, entriesByReference, basePatient);
                in = basePatient;
                replaced.add(otherPatient);
            }
        }
        if (in == null || replaced.isEmpty())
            throw new InvalidRequestException("Cannot determine Patients to merge");
        PRPAIN201304UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201304UV02MFMIMT700701UV01Subject1();
        controlActProcess.addSubject(subject);
        subject.setTypeCode("SUBJ");
        // ???
        subject.setContextConductionInd(false);
        PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent();
        subject.setRegistrationEvent(registrationEvent);
        registrationEvent.setClassCode(ActClass.REG);
        registrationEvent.setMoodCode(ActMood.EVN);
        // ???
        registrationEvent.setStatusCode(new CS("active", null, null));
        List<MFMIMT700701UV01ReplacementOf> replacementOfList = new ArrayList<MFMIMT700701UV01ReplacementOf>();
        registrationEvent.setReplacementOf(replacementOfList);
        for (Patient replacedPatient : replaced) {
            MFMIMT700701UV01ReplacementOf replacementOf = new MFMIMT700701UV01ReplacementOf();
            MFMIMT700701UV01PriorRegistration priorRegistration = new MFMIMT700701UV01PriorRegistration();
            replacementOf.setPriorRegistration(priorRegistration);
            replacementOf.setTypeCode("RPLC");
            priorRegistration.setClassCode(ActClass.REG);
            priorRegistration.setMoodCode(ActMood.EVN);
            priorRegistration.setStatusCode(new CS("obsolete", null, null));
            MFMIMT700701UV01Subject3 subject1 = new MFMIMT700701UV01Subject3();
            priorRegistration.setSubject1(subject1);
            subject1.setTypeCode(ParticipationTargetSubject.SBJ);
            MFMIMT700701UV01PriorRegisteredRole priorRegisteredRole = new MFMIMT700701UV01PriorRegisteredRole();
            subject1.setPriorRegisteredRole(priorRegisteredRole);
            priorRegisteredRole.setClassCode("PAT");
            for (Identifier id : replacedPatient.getIdentifier()) {
                priorRegisteredRole.addId(patientIdentifier(id));
            }
            replacementOfList.add(replacementOf);
        }
        PRPAIN201304UV02MFMIMT700701UV01Subject2 subject1 = new PRPAIN201304UV02MFMIMT700701UV01Subject2();
        registrationEvent.setSubject1(subject1);
        subject1.setTypeCode(ParticipationTargetSubject.SBJ);
        PRPAMT201303UV02Patient patient = new PRPAMT201303UV02Patient();
        patient.setClassCode("PAT");
        subject1.setPatient(patient);
        PRPAMT201302UV02PatientStatusCode statusCode = new PRPAMT201302UV02PatientStatusCode("active", null, null);
        // ???
        patient.setStatusCode(statusCode);
        List<II> orgIds = new ArrayList<II>();
        Set<String> mainIds = new HashSet<String>();
        PRPAMT201303UV02Person patientPerson = new PRPAMT201303UV02Person();
        patientPerson.setClassCode(EntityClass.PSN);
        patientPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
        patient.setPatientPerson(patientPerson);
        Organization managingOrg = getManagingOrganization(in, basePatient.getContained());
        for (Identifier id : managingOrg.getIdentifier()) {
            orgIds.add(new II(getScheme(id.getSystem()), null));
            mainIds.add(id.getSystem());
        }
        if (managingOrg == null)
            managingOrg = getManagingOrganization(basePatient, basePatient.getContained());
        if (managingOrg == null)
            throw new InvalidRequestException("Cannot determine managingOrganization");
        // TODO How is the correct mapping done?
        for (Identifier id : in.getIdentifier()) {
            PRPAMT201302UV02PatientId patientId = new PRPAMT201302UV02PatientId(getScheme(id.getSystem()), id.getValue());
            patient.addId(patientId);
        }
        for (HumanName name : in.getName()) {
            patientPerson.addName(transform(name));
        }
        COCTMT150003UV03Organization providerOrganization = new COCTMT150003UV03Organization();
        patient.setProviderOrganization(providerOrganization);
        providerOrganization.setClassCode(EntityClassOrganization.ORG);
        providerOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
        providerOrganization.setId(orgIds);
        ON name = null;
        if (managingOrg.hasName()) {
            name = new ON();
            name.setMixed(Collections.singletonList(managingOrg.getName()));
            providerOrganization.setName(Collections.singletonList(name));
        }
        COCTMT150003UV03ContactParty contactParty = new COCTMT150003UV03ContactParty();
        contactParty.setClassCode(RoleClassContact.CON);
        for (ContactPoint contactPoint : managingOrg.getTelecom()) {
            contactParty.addTelecom(transform(contactPoint));
        }
        if (managingOrg.hasAddress())
            contactParty.setAddr(new ArrayList<AD>());
        for (Address address : managingOrg.getAddress()) {
            contactParty.addAddr(transform(address));
        }
        if (managingOrg.hasContact()) {
            OrganizationContactComponent occ = managingOrg.getContactFirstRep();
            COCTMT150003UV03Person contactPerson = new COCTMT150003UV03Person();
            contactPerson.setClassCode(EntityClass.PSN);
            contactPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
            if (occ.hasName())
                contactPerson.setName(Collections.singletonList(transform(occ.getName())));
            contactParty.setContactPerson(contactPerson);
        }
        providerOrganization.setContactParty(Collections.singletonList(contactParty));
        patientPerson.setBirthTime(transform(in.getBirthDateElement()));
        if (in.hasGender()) {
            switch(in.getGender()) {
                case MALE:
                    patientPerson.setAdministrativeGenderCode(new CE("M", "Male", "2.16.840.1.113883.12.1"));
                    break;
                case FEMALE:
                    patientPerson.setAdministrativeGenderCode(new CE("F", "Female", "2.16.840.1.113883.12.1"));
                    break;
                case OTHER:
                    patientPerson.setAdministrativeGenderCode(new CE("A", "Ambiguous", "2.16.840.1.113883.12.1"));
                    break;
                case UNKNOWN:
                    patientPerson.setAdministrativeGenderCode(new CE("U", "Unknown", "2.16.840.1.113883.12.1"));
                    break;
            }
        }
        if (in.hasAddress())
            patientPerson.setAddr(new ArrayList<AD>());
        for (Address address : in.getAddress()) {
            patientPerson.addAddr(transform(address));
        }
        for (ContactPoint contactPoint : in.getTelecom()) {
            patientPerson.addTelecom(transform(contactPoint));
        }
        if (in.hasDeceasedBooleanType()) {
            patientPerson.setDeceasedInd(new BL(in.getDeceasedBooleanType().getValue()));
        }
        if (in.hasDeceasedDateTimeType()) {
            patientPerson.setDeceasedTime(transform(in.getDeceasedDateTimeType()));
        }
        if (in.hasMultipleBirthBooleanType()) {
            patientPerson.setMultipleBirthInd(new BL(in.getMultipleBirthBooleanType().getValue()));
        }
        if (in.hasMultipleBirthIntegerType()) {
            patientPerson.setMultipleBirthOrderNumber(new INT(in.getMultipleBirthIntegerType().getValue()));
        }
        if (in.hasMaritalStatus()) {
            patientPerson.setMaritalStatusCode(transform(in.getMaritalStatus()));
        }
        if (in.hasCommunication()) {
            for (PatientCommunicationComponent pcc : in.getCommunication()) {
                PRPAMT201303UV02LanguageCommunication languageCommunication = new PRPAMT201303UV02LanguageCommunication();
                languageCommunication.setLanguageCode(transform(pcc.getLanguage()));
                if (pcc.hasPreferred())
                    languageCommunication.setPreferenceInd(new BL(pcc.getPreferred()));
                patientPerson.addLanguageCommunication(languageCommunication);
            }
        }
        MFMIMT700701UV01Custodian custodian = new MFMIMT700701UV01Custodian();
        registrationEvent.setCustodian(custodian);
        custodian.setTypeCode(ParticipationType.CST);
        COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity();
        custodian.setAssignedEntity(assignedEntity);
        assignedEntity.setClassCode(RoleClassAssignedEntity.ASSIGNED);
        List<II> custIds = new ArrayList<II>();
        custIds.add(new II(getScheme(config.getCustodianOid()), null));
        assignedEntity.setId(custIds);
        // assignedEntity.setId(orgIds);
        COCTMT090003UV01Organization assignedOrganization = new COCTMT090003UV01Organization();
        assignedEntity.setAssignedOrganization(assignedOrganization);
        assignedOrganization.setClassCode(EntityClassOrganization.ORG);
        assignedOrganization.setDeterminerCode(EntityDeterminer.INSTANCE);
        if (managingOrg.hasName()) {
            ON onName = new ON();
            onName.setMixed(Collections.singletonList(managingOrg.getName()));
            assignedOrganization.setName(Collections.singletonList(onName));
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    HL7V3Transformer.marshallMessage(PRPAIN201304UV02Type.class, out, resultMsg);
    String outArray = new String(out.toByteArray());
    return outArray;
}
Also used : HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01RegistrationEvent) Address(org.hl7.fhir.r4.model.Address) ArrayList(java.util.ArrayList) PRPAMT201302UV02PatientId(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02PatientId) Identifier(org.hl7.fhir.r4.model.Identifier) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) HashSet(java.util.HashSet) II(net.ihe.gazelle.hl7v3.datatypes.II) PRPAIN201304UV02Type(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02Type) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) PRPAMT201303UV02LanguageCommunication(net.ihe.gazelle.hl7v3.prpamt201303UV02.PRPAMT201303UV02LanguageCommunication) MFMIMT700701UV01PriorRegisteredRole(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01PriorRegisteredRole) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) COCTMT150003UV03Person(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Person) OrganizationContactComponent(org.hl7.fhir.r4.model.Organization.OrganizationContactComponent) PRPAMT201302UV02PatientStatusCode(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02PatientStatusCode) PRPAMT201303UV02Person(net.ihe.gazelle.hl7v3.prpamt201303UV02.PRPAMT201303UV02Person) COCTMT090003UV01AssignedEntity(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity) MFMIMT700701UV01ReplacementOf(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01ReplacementOf) MFMIMT700701UV01Custodian(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01Custodian) MCCIMT000100UV01Receiver(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver) PRPAMT201303UV02Patient(net.ihe.gazelle.hl7v3.prpamt201303UV02.PRPAMT201303UV02Patient) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) EntityClassOrganization(net.ihe.gazelle.hl7v3.voc.EntityClassOrganization) Organization(org.hl7.fhir.r4.model.Organization) PatientLinkComponent(org.hl7.fhir.r4.model.Patient.PatientLinkComponent) BL(net.ihe.gazelle.hl7v3.datatypes.BL) MFMIMT700701UV01PriorRegistration(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01PriorRegistration) INT(net.ihe.gazelle.hl7v3.datatypes.INT) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) MCCIMT000100UV01Device(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device) ON(net.ihe.gazelle.hl7v3.datatypes.ON) CD(net.ihe.gazelle.hl7v3.datatypes.CD) CE(net.ihe.gazelle.hl7v3.datatypes.CE) Reference(org.hl7.fhir.r4.model.Reference) PRPAMT201301UV02Patient(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Patient) PRPAMT201303UV02Patient(net.ihe.gazelle.hl7v3.prpamt201303UV02.PRPAMT201303UV02Patient) Patient(org.hl7.fhir.r4.model.Patient) PRPAMT201302UV02Patient(net.ihe.gazelle.hl7v3.prpamt201302UV02.PRPAMT201302UV02Patient) PRPAIN201304UV02MFMIMT700701UV01Subject2(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01Subject2) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PRPAIN201304UV02MFMIMT700701UV01Subject1(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01Subject1) MCCIMT000100UV01Sender(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender) CS(net.ihe.gazelle.hl7v3.datatypes.CS) MFMIMT700701UV01Subject3(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01Subject3) COCTMT150003UV03ContactParty(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03ContactParty) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) TS(net.ihe.gazelle.hl7v3.datatypes.TS) PRPAIN201304UV02MFMIMT700701UV01ControlActProcess(net.ihe.gazelle.hl7v3.prpain201304UV02.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess)

Aggregations

ArrayList (java.util.ArrayList)9 HumanName (org.hl7.fhir.r4.model.HumanName)8 PatientCommunicationComponent (org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent)8 BL (net.ihe.gazelle.hl7v3.datatypes.BL)7 CE (net.ihe.gazelle.hl7v3.datatypes.CE)7 CS (net.ihe.gazelle.hl7v3.datatypes.CS)7 II (net.ihe.gazelle.hl7v3.datatypes.II)7 INT (net.ihe.gazelle.hl7v3.datatypes.INT)7 TS (net.ihe.gazelle.hl7v3.datatypes.TS)7 Address (org.hl7.fhir.r4.model.Address)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 COCTMT090003UV01AssignedEntity (net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity)6 COCTMT090003UV01Organization (net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization)6 COCTMT150003UV03ContactParty (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03ContactParty)6 COCTMT150003UV03Organization (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization)6 COCTMT150003UV03Person (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Person)6 CD (net.ihe.gazelle.hl7v3.datatypes.CD)6 ON (net.ihe.gazelle.hl7v3.datatypes.ON)6 MCCIMT000100UV01Device (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device)6 MCCIMT000100UV01Receiver (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver)6