Search in sources :

Example 51 with CD

use of org.hl7.v3.CD in project MobileAccessGateway by i4mi.

the class Iti93AddRequestConverter method doCreate.

/**
 * add a new patient
 * @param header
 * @param entriesByReference
 * @return
 * @throws JAXBException
 */
public String doCreate(MessageHeader header, Map<String, BundleEntryComponent> entriesByReference) throws JAXBException {
    PRPAIN201301UV02Type resultMsg = new PRPAIN201301UV02Type();
    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_IN201301UV02"));
    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)));
    PRPAIN201301UV02MFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201301UV02MFMIMT700701UV01ControlActProcess();
    resultMsg.setControlActProcess(controlActProcess);
    controlActProcess.setClassCode(ActClassControlAct.CACT);
    controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
    controlActProcess.setCode(new CD("PRPA_TE201301UV02", null, "2.16.840.1.113883.1.18"));
    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();
            PRPAIN201301UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201301UV02MFMIMT700701UV01Subject1();
            controlActProcess.addSubject(subject);
            subject.setTypeCode("SUBJ");
            // ???
            subject.setContextConductionInd(false);
            PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent();
            subject.setRegistrationEvent(registrationEvent);
            registrationEvent.setClassCode(ActClass.REG);
            registrationEvent.setMoodCode(ActMood.EVN);
            // ???
            registrationEvent.setStatusCode(new CS("active", null, null));
            PRPAIN201301UV02MFMIMT700701UV01Subject2 subject1 = new PRPAIN201301UV02MFMIMT700701UV01Subject2();
            registrationEvent.setSubject1(subject1);
            subject1.setTypeCode(ParticipationTargetSubject.SBJ);
            PRPAMT201301UV02Patient patient = new PRPAMT201301UV02Patient();
            subject1.setPatient(patient);
            patient.setClassCode("PAT");
            // ???
            patient.setStatusCode(new CS("active", null, null));
            PRPAMT201301UV02Person patientPerson = new PRPAMT201301UV02Person();
            patient.setPatientPerson(patientPerson);
            patientPerson.setClassCode(EntityClass.PSN);
            patientPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
            // TODO How is the correct mapping done?
            for (Identifier id : in.getIdentifier()) {
                patient.addId(patientIdentifier(id));
            }
            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));
            }
            List<II> orgIds = new ArrayList<II>();
            Organization managingOrg = getManagingOrganization(in);
            // NULL POINTER CHECK
            for (Identifier id : managingOrg.getIdentifier()) {
                orgIds.add(new II(getScheme(id.getSystem()), null));
            }
            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()) {
                    PRPAMT201301UV02LanguageCommunication languageCommunication = new PRPAMT201301UV02LanguageCommunication();
                    languageCommunication.setLanguageCode(transform(pcc.getLanguage()));
                    // NULL POINTER EXCEPTION
                    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(PRPAIN201301UV02Type.class, out, resultMsg);
    String outArray = new String(out.toByteArray());
    return outArray;
}
Also used : HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) PRPAIN201301UV02MFMIMT700701UV01Subject1(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01Subject1) PRPAIN201301UV02MFMIMT700701UV01Subject2(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01Subject2) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) 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) PRPAMT201301UV02Person(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Person) BL(net.ihe.gazelle.hl7v3.datatypes.BL) INT(net.ihe.gazelle.hl7v3.datatypes.INT) PRPAMT201301UV02Patient(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Patient) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Identifier(org.hl7.fhir.r4.model.Identifier) PRPAIN201301UV02MFMIMT700701UV01ControlActProcess(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01ControlActProcess) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) MCCIMT000100UV01Device(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device) ON(net.ihe.gazelle.hl7v3.datatypes.ON) II(net.ihe.gazelle.hl7v3.datatypes.II) CD(net.ihe.gazelle.hl7v3.datatypes.CD) PRPAMT201301UV02LanguageCommunication(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02LanguageCommunication) CE(net.ihe.gazelle.hl7v3.datatypes.CE) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) Patient(org.hl7.fhir.r4.model.Patient) PRPAMT201301UV02Patient(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Patient) PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent) 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) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) COCTMT090003UV01AssignedEntity(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity) PRPAIN201301UV02Type(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02Type) MFMIMT700701UV01Custodian(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01Custodian) MCCIMT000100UV01Receiver(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver) TS(net.ihe.gazelle.hl7v3.datatypes.TS)

Example 52 with CD

use of org.hl7.v3.CD in project MobileAccessGateway by i4mi.

the class Iti104AddRequestConverter method doCreate.

/**
 * add a new patient
 * @param header
 * @param entriesByReference
 * @return
 * @throws JAXBException
 */
public String doCreate(Patient in, Identifier identifier) throws JAXBException {
    PRPAIN201301UV02Type resultMsg = new PRPAIN201301UV02Type();
    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_IN201301UV02"));
    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)));
    PRPAIN201301UV02MFMIMT700701UV01ControlActProcess controlActProcess = new PRPAIN201301UV02MFMIMT700701UV01ControlActProcess();
    resultMsg.setControlActProcess(controlActProcess);
    controlActProcess.setClassCode(ActClassControlAct.CACT);
    controlActProcess.setMoodCode(XActMoodIntentEvent.EVN);
    controlActProcess.setCode(new CD("PRPA_TE201301UV02", null, "2.16.840.1.113883.1.18"));
    PRPAIN201301UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201301UV02MFMIMT700701UV01Subject1();
    controlActProcess.addSubject(subject);
    subject.setTypeCode("SUBJ");
    // ???
    subject.setContextConductionInd(false);
    PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent();
    subject.setRegistrationEvent(registrationEvent);
    registrationEvent.setClassCode(ActClass.REG);
    registrationEvent.setMoodCode(ActMood.EVN);
    // ???
    registrationEvent.setStatusCode(new CS("active", null, null));
    PRPAIN201301UV02MFMIMT700701UV01Subject2 subject1 = new PRPAIN201301UV02MFMIMT700701UV01Subject2();
    registrationEvent.setSubject1(subject1);
    subject1.setTypeCode(ParticipationTargetSubject.SBJ);
    PRPAMT201301UV02Patient patient = new PRPAMT201301UV02Patient();
    subject1.setPatient(patient);
    patient.setClassCode("PAT");
    // ???
    patient.setStatusCode(new CS("active", null, null));
    PRPAMT201301UV02Person patientPerson = new PRPAMT201301UV02Person();
    patient.setPatientPerson(patientPerson);
    patientPerson.setClassCode(EntityClass.PSN);
    patientPerson.setDeterminerCode(EntityDeterminer.INSTANCE);
    patient.addId(patientIdentifier(identifier));
    // TODO How is the correct mapping done?
    for (Identifier id : in.getIdentifier()) {
        patient.addId(patientIdentifier(id));
    }
    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));
    }
    List<II> orgIds = new ArrayList<II>();
    Organization managingOrg = getManagingOrganization(in);
    // NULL POINTER CHECK
    if (managingOrg != null) {
        for (Identifier id : managingOrg.getIdentifier()) {
            orgIds.add(new II(getScheme(id.getSystem()), null));
        }
    } else {
        Reference org = in.getManagingOrganization();
        if (org != null && org.getIdentifier() != null) {
            orgIds.add(new II(getScheme(org.getIdentifier().getSystem()), null));
        }
    }
    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()) {
            PRPAMT201301UV02LanguageCommunication languageCommunication = new PRPAMT201301UV02LanguageCommunication();
            languageCommunication.setLanguageCode(transform(pcc.getLanguage()));
            // NULL POINTER EXCEPTION
            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 != null && managingOrg.hasName()) {
        name = new ON();
        name.setMixed(Collections.singletonList(managingOrg.getName()));
        providerOrganization.setName(Collections.singletonList(name));
    }
    if (managingOrg != null) {
        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(PRPAIN201301UV02Type.class, out, resultMsg);
    String outArray = new String(out.toByteArray());
    return outArray;
}
Also used : PRPAIN201301UV02MFMIMT700701UV01Subject1(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01Subject1) PRPAIN201301UV02MFMIMT700701UV01Subject2(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01Subject2) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) 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) PRPAMT201301UV02Person(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Person) BL(net.ihe.gazelle.hl7v3.datatypes.BL) INT(net.ihe.gazelle.hl7v3.datatypes.INT) PRPAMT201301UV02Patient(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Patient) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Identifier(org.hl7.fhir.r4.model.Identifier) PRPAIN201301UV02MFMIMT700701UV01ControlActProcess(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01ControlActProcess) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) MCCIMT000100UV01Device(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device) ON(net.ihe.gazelle.hl7v3.datatypes.ON) II(net.ihe.gazelle.hl7v3.datatypes.II) CD(net.ihe.gazelle.hl7v3.datatypes.CD) PRPAMT201301UV02LanguageCommunication(net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02LanguageCommunication) CE(net.ihe.gazelle.hl7v3.datatypes.CE) AD(net.ihe.gazelle.hl7v3.datatypes.AD) Reference(org.hl7.fhir.r4.model.Reference) COCTMT090003UV01Organization(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization) PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MCCIMT000100UV01Sender(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender) CS(net.ihe.gazelle.hl7v3.datatypes.CS) COCTMT150003UV03ContactParty(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03ContactParty) COCTMT150003UV03Person(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Person) OrganizationContactComponent(org.hl7.fhir.r4.model.Organization.OrganizationContactComponent) COCTMT150003UV03Organization(net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization) COCTMT090003UV01AssignedEntity(net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity) PRPAIN201301UV02Type(net.ihe.gazelle.hl7v3.prpain201301UV02.PRPAIN201301UV02Type) MFMIMT700701UV01Custodian(net.ihe.gazelle.hl7v3.mfmimt700701UV01.MFMIMT700701UV01Custodian) MCCIMT000100UV01Receiver(net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver) TS(net.ihe.gazelle.hl7v3.datatypes.TS)

Example 53 with CD

use of org.hl7.v3.CD in project synthea by synthetichealth.

the class FhirStu3 method explanationOfBenefit.

/**
 * Create an explanation of benefit resource for each claim, detailing insurance
 * information.
 *
 * @param personEntry Entry for the person
 * @param bundle The Bundle to add to
 * @param encounterEntry The current Encounter
 * @param claimEntry the Claim object
 * @param person the person the health record belongs to
 * @param encounter the current Encounter as an object
 * @return the added entry
 */
private static BundleEntryComponent explanationOfBenefit(BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Person person, BundleEntryComponent claimEntry, Encounter encounter) {
    boolean inpatient = false;
    boolean outpatient = false;
    EncounterType type = EncounterType.fromString(encounter.type);
    if (type == EncounterType.INPATIENT) {
        inpatient = true;
    // Provider enum doesn't include outpatient, but it can still be
    // an encounter type.
    } else if (type == EncounterType.AMBULATORY || type == EncounterType.WELLNESS) {
        outpatient = true;
    }
    ExplanationOfBenefit eob = new ExplanationOfBenefit();
    org.hl7.fhir.dstu3.model.Encounter encounterResource = (org.hl7.fhir.dstu3.model.Encounter) encounterEntry.getResource();
    // will have to deal with different claim types (e.g. inpatient vs outpatient)
    if (inpatient) {
        // https://www.cms.gov/Medicare/Medicare-Fee-for-Service-Payment/AcuteInpatientPPS/Indirect-Medical-Education-IME
        // Extra cost for educational hospitals
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-ime-op-clm-val-amt-extension", 400));
        // DSH payment-- Massachusetts does not make DSH payments at all, so set to 0 for now
        // https://www.cms.gov/Medicare/Medicare-Fee-for-Service-Payment/AcuteInpatientPPS/dsh
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-dsh-op-clm-val-amt-extension", 0));
        // The pass through per diem rate
        // not really defined by CMS
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-pass-thru-per-diem-amt-extension", 0));
        // Professional charge
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-nch-profnl-cmpnt-chrg-amt-extension", 0));
        // total claim PPS charge
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-tot-pps-cptl-amt-extension", 0));
        // Deductible Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-nch-bene-ip-ddctbl-amt-extension", 0));
        // Coinsurance Liability
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-nch-bene-pta-coinsrnc-lblty-amt-extension", 0));
        // Non-covered Charge Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-nch-ip-ncvrd-chrg-amt-extension", 0));
        // Total Deductible/Coinsurance Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-nch-ip-tot-ddctn-amt-extension", 0));
        // PPS Capital DSH Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-pps-cptl-dsprprtnt-shr-amt-extension", 0));
        // PPS Capital Exception Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-pps-cptl-excptn-amt-extension", 0));
        // PPS FSP
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-pps-cptl-fsp-amt-extension", 0));
        // PPS IME
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-pps-cptl-ime-amt-extension", 400));
        // PPS Capital Outlier Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-pps-cptl-outlier-amt-extension", 0));
        // Old capital hold harmless amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-pps-old-cptl-hld-hrmls-amt-extension", 0));
        // NCH DRG Outlier Approved Payment Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-nch-drg-outlier-aprvd-pmt-amt-extension", 0));
        // NCH Beneficiary Blood Deductible Liability Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-nch-bene-blood-ddctbl-lblty-am-extension", 0));
        // Non-payment reason
        eob.addExtension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-mdcr-non-pmt-rsn-cd-extension").setValue(new Coding().setSystem("https://bluebutton.cms.gov/assets/ig/CodeSystem-clm-mdcr-non-pmt-rsn-cd").setDisplay("All other reasons for non-payment").setCode("N"));
        // Prepayment
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-prpayamt-extension", 0));
        // FI or MAC number
        eob.addExtension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-fi-num-extension").setValue(new Identifier().setValue("002000").setSystem("https://bluebutton.cms.gov/assets/ig/CodeSystem-fi-num"));
    } else if (outpatient) {
        // Professional component charge amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-nch-profnl-cmpnt-chrg-amt-extension", 0));
        // Deductible amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-nch-bene-ptb-ddctbl-amt-extension", 0));
        // Coinsurance amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-nch-bene-ptb-coinsrnc-amt-extension", 0));
        // Provider Payment
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-clm-op-prvdr-pmt-amt-extension", 0));
        // Beneficiary payment
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-clm-op-bene-pmt-amt-extension", 0));
        // Beneficiary Blood Deductible Liability Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-nch-bene-blood-ddctbl-lblty-am-extension", 0));
        // Claim Medicare Non Payment Reason Code
        eob.addExtension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-clm-mdcr-non-pmt-rsn-cd-extension").setValue(new Coding().setDisplay("All other reasons for non-payment").setSystem("https://bluebutton.cms.gov/assets/ig/CodeSystem-clm-mdcr-non-pmt-rsn-cd").setCode("N"));
        // NCH Primary Payer Claim Paid Amount
        eob.addExtension(createMoneyExtension("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-prpayamt-extension", 0));
        // FI or MAC number
        eob.addExtension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-fi-num-extension").setValue(new Identifier().setValue("002000").setSystem("https://bluebutton.cms.gov/assets/ig/CodeSystem-fi-num"));
    }
    // according to CMS guidelines claims have 12 months to be
    // billed, so we set the billable period to 1 year after
    // services have ended (the encounter ends).
    Calendar cal = Calendar.getInstance();
    cal.setTime(encounterResource.getPeriod().getEnd());
    cal.add(Calendar.YEAR, 1);
    Period billablePeriod = new Period().setStart(encounterResource.getPeriod().getEnd()).setEnd(cal.getTime());
    if (inpatient) {
        billablePeriod.addExtension(new Extension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-claim-query-cd-extension").setValue(new Coding().setCode("3").setSystem("https://bluebutton.cms.gov/assets/ig/ValueSet-claim-query-cd").setDisplay("Final Bill")));
    } else if (outpatient) {
        billablePeriod.addExtension(new Extension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-claim-query-cd-extension").setValue(new Coding().setCode("3").setSystem("https://bluebutton.cms.gov/assets/ig/ValueSet-claim-query-cd").setDisplay("Final Bill")));
    }
    eob.setBillablePeriod(billablePeriod);
    // cost is hardcoded to be USD in claim so this should be fine as well
    Money totalCost = new Money();
    totalCost.setSystem("urn:iso:std:iso:4217");
    totalCost.setCode("USD");
    totalCost.setValue(encounter.claim.getTotalClaimCost());
    eob.setTotalCost(totalCost);
    // Set References
    eob.setPatient(new Reference(personEntry.getFullUrl()));
    if (encounter.provider != null) {
        // This is what should happen if BlueButton 2.0 wasn't needlessly restrictive
        // String providerUrl = findProviderUrl(encounter.provider, bundle);
        // eob.setOrganization(new Reference().setReference(providerUrl));
        // Instead, we'll create the BlueButton 2.0 reference via identifier...
        Identifier identifier = new Identifier();
        identifier.setValue(encounter.provider.getResourceID());
        eob.setOrganization(new Reference().setIdentifier(identifier));
    }
    String npi = "9999999999";
    if (encounter.clinician != null) {
        npi = encounter.clinician.npi;
    } else if (encounter.provider != null) {
        npi = encounter.provider.npi;
    }
    // Get the insurance info at the time that the encounter happened.
    Payer payer = encounter.claim.payer;
    Coverage coverage = new Coverage();
    coverage.setId("coverage");
    coverage.setType(new CodeableConcept().setText(payer.getName()));
    eob.addContained(coverage);
    ExplanationOfBenefit.InsuranceComponent insuranceComponent = new ExplanationOfBenefit.InsuranceComponent();
    insuranceComponent.setCoverage(new Reference("#coverage"));
    eob.setInsurance(insuranceComponent);
    org.hl7.fhir.dstu3.model.Claim claim = (org.hl7.fhir.dstu3.model.Claim) claimEntry.getResource();
    eob.addIdentifier().setSystem("https://bluebutton.cms.gov/resources/variables/clm_id").setValue(claim.getId());
    // Hardcoded group id
    eob.addIdentifier().setSystem("https://bluebutton.cms.gov/resources/identifier/claim-group").setValue("99999999999");
    eob.setStatus(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.ExplanationOfBenefitStatus.ACTIVE);
    if (!inpatient && !outpatient) {
        eob.setClaim(new Reference().setReference(claimEntry.getFullUrl()));
        List<Reference> recipientList = new ArrayList<>();
        recipientList.add(new Reference().setIdentifier(new Identifier().setSystem("http://hl7.org/fhir/sid/us-npi").setValue(npi)));
        eob.addContained(new ReferralRequest().setStatus(ReferralRequest.ReferralRequestStatus.COMPLETED).setIntent(ReferralRequest.ReferralCategory.ORDER).setSubject(new Reference(personEntry.getFullUrl())).setRequester(new ReferralRequest.ReferralRequestRequesterComponent().setAgent(new Reference().setIdentifier(new Identifier().setSystem("http://hl7.org/fhir/sid/us-npi").setValue(npi)))).setRecipient(recipientList).setId("referral"));
        eob.setReferral(new Reference("#referral"));
        eob.setCreated(encounterResource.getPeriod().getEnd());
    }
    eob.setType(claim.getType());
    List<ExplanationOfBenefit.DiagnosisComponent> eobDiag = new ArrayList<>();
    for (org.hl7.fhir.dstu3.model.Claim.DiagnosisComponent claimDiagnosis : claim.getDiagnosis()) {
        ExplanationOfBenefit.DiagnosisComponent diagnosisComponent = new ExplanationOfBenefit.DiagnosisComponent();
        diagnosisComponent.setDiagnosis(claimDiagnosis.getDiagnosis());
        diagnosisComponent.getType().add(new CodeableConcept().addCoding(new Coding().setCode("principal").setSystem("https://bluebutton.cms.gov/resources/codesystem/diagnosis-type")));
        diagnosisComponent.setSequence(claimDiagnosis.getSequence());
        diagnosisComponent.setPackageCode(claimDiagnosis.getPackageCode());
        diagnosisComponent.addExtension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-clm-poa-ind-sw1-extension").setValue(new Coding().setCode("Y").setSystem("https://bluebutton.cms.gov/assets/ig/CodeSystem-clm-poa-ind-sw1").setDisplay("Diagnosis present at time of admission"));
        eobDiag.add(diagnosisComponent);
    }
    eob.setDiagnosis(eobDiag);
    List<ExplanationOfBenefit.ProcedureComponent> eobProc = new ArrayList<>();
    for (ProcedureComponent proc : claim.getProcedure()) {
        ExplanationOfBenefit.ProcedureComponent p = new ExplanationOfBenefit.ProcedureComponent();
        p.setDate(proc.getDate());
        p.setSequence(proc.getSequence());
        p.setProcedure(proc.getProcedure());
    }
    eob.setProcedure(eobProc);
    List<ExplanationOfBenefit.ItemComponent> eobItem = new ArrayList<>();
    double totalPayment = 0;
    for (ItemComponent item : claim.getItem()) {
        ExplanationOfBenefit.ItemComponent itemComponent = new ExplanationOfBenefit.ItemComponent();
        itemComponent.setSequence(item.getSequence());
        itemComponent.setQuantity(item.getQuantity());
        itemComponent.setUnitPrice(item.getUnitPrice());
        itemComponent.setCareTeamLinkId(item.getCareTeamLinkId());
        if (item.hasService()) {
            itemComponent.setService(item.getService());
        }
        if (!inpatient && !outpatient) {
            itemComponent.setDiagnosisLinkId(item.getDiagnosisLinkId());
            itemComponent.setInformationLinkId(item.getInformationLinkId());
            itemComponent.setNet(item.getNet());
            itemComponent.setEncounter(item.getEncounter());
            itemComponent.setServiced(encounterResource.getPeriod());
            itemComponent.setCategory(new CodeableConcept().addCoding(new Coding().setSystem("https://bluebutton.cms.gov/resources/variables/line_cms_type_srvc_cd").setCode("1").setDisplay("Medical care")));
        }
        if (inpatient) {
            itemComponent.addExtension(new Extension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-inpatient-rev-cntr-ndc-qty-extension").setValue(new Quantity().setValue(0)));
        } else if (outpatient) {
            itemComponent.addExtension(new Extension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-rev-cntr-ndc-qty-extension").setValue(new Quantity().setValue(0)));
            if (itemComponent.hasService()) {
                itemComponent.getService().addExtension(new Extension().setUrl("https://bluebutton.cms.gov/assets/ig/StructureDefinition-bluebutton-outpatient-rev-cntr-ide-ndc-upc-num-extension").setValue(new Coding().setSystem("https://www.accessdata.fda.gov/scripts/cder/ndc").setDisplay("Dummy").setCode("0624")));
            }
        }
        // Location of service, can use switch statement based on
        // encounter type
        String code;
        String display;
        CodeableConcept location = new CodeableConcept();
        EncounterType encounterType = EncounterType.fromString(encounter.type);
        switch(encounterType) {
            case AMBULATORY:
                code = "21";
                display = "Inpatient Hospital";
                break;
            case EMERGENCY:
                code = "23";
                display = "Emergency Room";
                break;
            case INPATIENT:
                code = "21";
                display = "Inpatient Hospital";
                break;
            case URGENTCARE:
                code = "20";
                display = "Urgent Care Facility";
                break;
            case WELLNESS:
                code = "22";
                display = "Outpatient Hospital";
                break;
            default:
                code = "21";
                display = "Inpatient Hospital";
        }
        location.addCoding().setCode(code).setSystem("https://bluebutton.cms.gov/resources/variables/line_place_of_srvc_cd").setDisplay(display);
        itemComponent.setLocation(location);
        // Adjudication
        if (item.hasNet()) {
            // Assume that the patient has already paid deductible and
            // has 20/80 coinsurance
            ExplanationOfBenefit.AdjudicationComponent coinsuranceAmount = new ExplanationOfBenefit.AdjudicationComponent();
            coinsuranceAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_coinsrnc_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Beneficiary Coinsurance Amount"));
            coinsuranceAmount.getAmount().setValue(// 20% coinsurance
            0.2 * item.getNet().getValue().doubleValue()).setSystem(// USD
            "urn:iso:std:iso:4217").setCode("USD");
            ExplanationOfBenefit.AdjudicationComponent lineProviderAmount = new ExplanationOfBenefit.AdjudicationComponent();
            lineProviderAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_prvdr_pmt_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Provider Payment Amount"));
            lineProviderAmount.getAmount().setValue(0.8 * item.getNet().getValue().doubleValue()).setSystem("urn:iso:std:iso:4217").setCode("USD");
            // assume the allowed and submitted amounts are the same for now
            ExplanationOfBenefit.AdjudicationComponent submittedAmount = new ExplanationOfBenefit.AdjudicationComponent();
            submittedAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_sbmtd_chrg_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Submitted Charge Amount"));
            submittedAmount.getAmount().setValue(item.getNet().getValue()).setSystem("urn:iso:std:iso:4217").setCode("USD");
            ExplanationOfBenefit.AdjudicationComponent allowedAmount = new ExplanationOfBenefit.AdjudicationComponent();
            allowedAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_alowd_chrg_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Allowed Charge Amount"));
            allowedAmount.getAmount().setValue(item.getNet().getValue()).setSystem("urn:iso:std:iso:4217").setCode("USD");
            ExplanationOfBenefit.AdjudicationComponent indicatorCode = new ExplanationOfBenefit.AdjudicationComponent();
            indicatorCode.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_prcsg_ind_cd").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Processing Indicator Code"));
            if (!inpatient && !outpatient) {
                indicatorCode.getReason().addCoding().setCode("A").setSystem("https://bluebutton.cms.gov/resources/variables/line_prcsg_ind_cd");
                indicatorCode.getReason().getCodingFirstRep().setDisplay("Allowed");
            }
            // assume deductible is 0
            ExplanationOfBenefit.AdjudicationComponent deductibleAmount = new ExplanationOfBenefit.AdjudicationComponent();
            deductibleAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_bene_ptb_ddctbl_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Beneficiary Part B Deductible Amount"));
            deductibleAmount.getAmount().setValue(0).setSystem("urn:iso:std:iso:4217").setCode("USD");
            List<ExplanationOfBenefit.AdjudicationComponent> adjudicationComponents = new ArrayList<>();
            adjudicationComponents.add(coinsuranceAmount);
            adjudicationComponents.add(lineProviderAmount);
            adjudicationComponents.add(submittedAmount);
            adjudicationComponents.add(allowedAmount);
            adjudicationComponents.add(deductibleAmount);
            adjudicationComponents.add(indicatorCode);
            itemComponent.setAdjudication(adjudicationComponents);
            // the total payment is what the insurance ends up paying
            totalPayment += 0.8 * item.getNet().getValue().doubleValue();
        }
        eobItem.add(itemComponent);
    }
    eob.setItem(eobItem);
    // This will throw a validation error no matter what.  The
    // payment section is required, and it requires a value.
    // The validator will complain that if there is a value, the payment
    // needs a code, but it will also complain if there is a code.
    // There is no way to resolve this error.
    Money payment = new Money();
    payment.setValue(totalPayment).setSystem("urn:iso:std:iso:4217").setCode("USD");
    eob.setPayment(new ExplanationOfBenefit.PaymentComponent().setAmount(payment));
    if (encounter.clinician != null) {
        // This is what should happen if BlueButton 2.0 wasn't needlessly restrictive
        // String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
        // eob.setProvider(new Reference().setReference(practitionerFullUrl));
        // Instead, we'll create the BlueButton 2.0 reference via identifier...
        Identifier identifier = new Identifier();
        identifier.setValue(encounter.clinician.getResourceID());
        eob.setProvider(new Reference().setIdentifier(identifier));
    } else {
        Identifier identifier = new Identifier();
        identifier.setValue("Unknown");
        eob.setProvider(new Reference().setIdentifier(identifier));
    }
    eob.addCareTeam(new ExplanationOfBenefit.CareTeamComponent().setSequence(1).setProvider(new Reference().setIdentifier(new Identifier().setSystem("http://hl7.org/fhir/sid/us-npi").setValue(npi))).setRole(new CodeableConcept().addCoding(new Coding().setCode("primary").setSystem("http://hl7.org/fhir/claimcareteamrole").setDisplay("Primary Care Practitioner"))));
    eob.setType(new CodeableConcept().addCoding(new Coding().setSystem("https://bluebutton.cms.gov/resources/variables/nch_clm_type_cd").setCode("71").setDisplay("Local carrier non-durable medical equipment, prosthetics, orthotics, " + "and supplies (DMEPOS) claim")).addCoding(new Coding().setSystem("https://bluebutton.cms.gov/resources/codesystem/eob-type").setCode("CARRIER").setDisplay("EOB Type")).addCoding(new Coding().setSystem("http://hl7.org/fhir/ex-claimtype").setCode("professional").setDisplay("Claim Type")).addCoding(new Coding().setSystem("https://bluebutton.cms.gov/resources/variables/nch_near_line_rec_ident_cd").setCode("O").setDisplay("Part B physician/supplier claim record (processed by local " + "carriers; can include DMEPOS services)")));
    return newEntry(person, bundle, eob);
}
Also used : ReferralRequest(org.hl7.fhir.dstu3.model.ReferralRequest) ArrayList(java.util.ArrayList) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) ProcedureComponent(org.hl7.fhir.dstu3.model.Claim.ProcedureComponent) Money(org.hl7.fhir.dstu3.model.Money) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) ItemComponent(org.hl7.fhir.dstu3.model.Claim.ItemComponent) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.dstu3.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Payer(org.mitre.synthea.world.agents.Payer) Reference(org.hl7.fhir.dstu3.model.Reference) Calendar(java.util.Calendar) Period(org.hl7.fhir.dstu3.model.Period) SimpleQuantity(org.hl7.fhir.dstu3.model.SimpleQuantity) Quantity(org.hl7.fhir.dstu3.model.Quantity) Coverage(org.hl7.fhir.dstu3.model.Coverage) Extension(org.hl7.fhir.dstu3.model.Extension) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) Claim(org.mitre.synthea.world.concepts.Claim) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 54 with CD

use of org.hl7.v3.CD in project beneficiary-fhir-data by CMSgov.

the class TransformerUtils method addCommonEobInformationInpatientSNF.

/**
 * Adds EOB information to fields that are common between the Inpatient and SNF claim types.
 *
 * @param eob the {@link ExplanationOfBenefit} that fields will be added to by this method
 * @param admissionTypeCd CLM_IP_ADMSN_TYPE_CD: a {@link Character} shared field representing the
 *     admission type cd for the claim
 * @param sourceAdmissionCd CLM_SRC_IP_ADMSN_CD: an {@link Optional}&lt;{@link Character}&gt;
 *     shared field representing the source admission cd for the claim
 * @param noncoveredStayFromDate NCH_VRFD_NCVRD_STAY_FROM_DT: an {@link Optional}&lt;{@link
 *     LocalDate}&gt; shared field representing the non-covered stay from date for the claim
 * @param noncoveredStayThroughDate NCH_VRFD_NCVRD_STAY_THRU_DT: an {@link Optional}&lt;{@link
 *     LocalDate}&gt; shared field representing the non-covered stay through date for the claim
 * @param coveredCareThroughDate NCH_ACTV_OR_CVRD_LVL_CARE_THRU: an {@link Optional}&lt;{@link
 *     LocalDate}&gt; shared field representing the covered stay through date for the claim
 * @param medicareBenefitsExhaustedDate NCH_BENE_MDCR_BNFTS_EXHTD_DT_I: an {@link
 *     Optional}&lt;{@link LocalDate}&gt; shared field representing the medicare benefits
 *     exhausted date for the claim
 * @param diagnosisRelatedGroupCd CLM_DRG_CD: an {@link Optional}&lt;{@link String}&gt; shared
 *     field representing the non-covered stay from date for the claim
 */
static void addCommonEobInformationInpatientSNF(ExplanationOfBenefit eob, Character admissionTypeCd, Optional<Character> sourceAdmissionCd, Optional<LocalDate> noncoveredStayFromDate, Optional<LocalDate> noncoveredStayThroughDate, Optional<LocalDate> coveredCareThroughDate, Optional<LocalDate> medicareBenefitsExhaustedDate, Optional<String> diagnosisRelatedGroupCd) {
    // admissionTypeCd
    addInformationWithCode(eob, CcwCodebookVariable.CLM_IP_ADMSN_TYPE_CD, CcwCodebookVariable.CLM_IP_ADMSN_TYPE_CD, admissionTypeCd);
    // sourceAdmissionCd
    if (sourceAdmissionCd.isPresent()) {
        addInformationWithCode(eob, CcwCodebookVariable.CLM_SRC_IP_ADMSN_CD, CcwCodebookVariable.CLM_SRC_IP_ADMSN_CD, sourceAdmissionCd);
    }
    // noncoveredStayFromDate & noncoveredStayThroughDate
    if (noncoveredStayFromDate.isPresent() || noncoveredStayThroughDate.isPresent()) {
        TransformerUtils.validatePeriodDates(noncoveredStayFromDate, noncoveredStayThroughDate);
        SupportingInformationComponent nchVrfdNcvrdStayInfo = TransformerUtils.addInformation(eob, CcwCodebookVariable.NCH_VRFD_NCVRD_STAY_FROM_DT);
        Period nchVrfdNcvrdStayPeriod = new Period();
        if (noncoveredStayFromDate.isPresent())
            nchVrfdNcvrdStayPeriod.setStart(TransformerUtils.convertToDate((noncoveredStayFromDate.get())), TemporalPrecisionEnum.DAY);
        if (noncoveredStayThroughDate.isPresent())
            nchVrfdNcvrdStayPeriod.setEnd(TransformerUtils.convertToDate((noncoveredStayThroughDate.get())), TemporalPrecisionEnum.DAY);
        nchVrfdNcvrdStayInfo.setTiming(nchVrfdNcvrdStayPeriod);
    }
    // coveredCareThroughDate
    if (coveredCareThroughDate.isPresent()) {
        SupportingInformationComponent nchActvOrCvrdLvlCareThruInfo = TransformerUtils.addInformation(eob, CcwCodebookVariable.NCH_ACTV_OR_CVRD_LVL_CARE_THRU);
        nchActvOrCvrdLvlCareThruInfo.setTiming(new DateType(TransformerUtils.convertToDate(coveredCareThroughDate.get())));
    }
    // medicareBenefitsExhaustedDate
    if (medicareBenefitsExhaustedDate.isPresent()) {
        SupportingInformationComponent nchBeneMdcrBnftsExhtdDtIInfo = TransformerUtils.addInformation(eob, CcwCodebookVariable.NCH_BENE_MDCR_BNFTS_EXHTD_DT_I);
        nchBeneMdcrBnftsExhtdDtIInfo.setTiming(new DateType(TransformerUtils.convertToDate(medicareBenefitsExhaustedDate.get())));
    }
    // diagnosisRelatedGroupCd
    if (diagnosisRelatedGroupCd.isPresent()) {
        /*
       * FIXME This is an invalid DiagnosisComponent, since it's missing a (required) ICD code.
       * Instead, stick the DRG on the claim's primary/first diagnosis. SamhsaMatcher uses this
       * field so if this is updated you'll need to update that as well.
       */
        eob.addDiagnosis().setPackageCode(createCodeableConcept(eob, CcwCodebookVariable.CLM_DRG_CD, diagnosisRelatedGroupCd));
    }
}
Also used : SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent) Period(org.hl7.fhir.dstu3.model.Period) DateType(org.hl7.fhir.dstu3.model.DateType)

Example 55 with CD

use of org.hl7.v3.CD in project beneficiary-fhir-data by CMSgov.

the class TransformerUtilsV2 method addCommonEobInformationInpatientSNF.

/**
 * Adds EOB information to fields that are common between the Inpatient and SNF claim types.
 *
 * @param eob the {@link ExplanationOfBenefit} that fields will be added to by this method
 * @param admissionTypeCd CLM_IP_ADMSN_TYPE_CD: a {@link Character} shared field representing the
 *     admission type cd for the claim
 * @param sourceAdmissionCd CLM_SRC_IP_ADMSN_CD: an {@link Optional}&lt;{@link Character}&gt;
 *     shared field representing the source admission cd for the claim
 * @param noncoveredStayFromDate NCH_VRFD_NCVRD_STAY_FROM_DT: an {@link Optional}&lt;{@link
 *     LocalDate}&gt; shared field representing the non-covered stay from date for the claim
 * @param noncoveredStayThroughDate NCH_VRFD_NCVRD_STAY_THRU_DT: an {@link Optional}&lt;{@link
 *     LocalDate}&gt; shared field representing the non-covered stay through date for the claim
 * @param coveredCareThroughDate NCH_ACTV_OR_CVRD_LVL_CARE_THRU: an {@link Optional}&lt;{@link
 *     LocalDate}&gt; shared field representing the covered stay through date for the claim
 * @param medicareBenefitsExhaustedDate NCH_BENE_MDCR_BNFTS_EXHTD_DT_I: an {@link
 *     Optional}&lt;{@link LocalDate}&gt; shared field representing the medicare benefits
 *     exhausted date for the claim
 * @param diagnosisRelatedGroupCd CLM_DRG_CD: an {@link Optional}&lt;{@link String}&gt; shared
 *     field representing the non-covered stay from date for the claim
 */
static void addCommonEobInformationInpatientSNF(ExplanationOfBenefit eob, Character admissionTypeCd, Optional<Character> sourceAdmissionCd, Optional<LocalDate> noncoveredStayFromDate, Optional<LocalDate> noncoveredStayThroughDate, Optional<LocalDate> coveredCareThroughDate, Optional<LocalDate> medicareBenefitsExhaustedDate, Optional<String> diagnosisRelatedGroupCd) {
    // CLM_IP_ADMSN_TYPE_CD => ExplanationOfBenefit.supportingInfo.code
    addInformationWithCode(eob, CcwCodebookVariable.CLM_IP_ADMSN_TYPE_CD, CcwCodebookVariable.CLM_IP_ADMSN_TYPE_CD, admissionTypeCd);
    // CLM_SRC_IP_ADMSN_CD => ExplanationOfBenefit.supportingInfo.code
    if (sourceAdmissionCd.isPresent()) {
        addInformationWithCode(eob, CcwCodebookVariable.CLM_SRC_IP_ADMSN_CD, CcwCodebookVariable.CLM_SRC_IP_ADMSN_CD, sourceAdmissionCd);
    }
    // ExplanationOfBenefit.supportingInfo.timingPeriod
    if (noncoveredStayFromDate.isPresent() || noncoveredStayThroughDate.isPresent()) {
        validatePeriodDates(noncoveredStayFromDate, noncoveredStayThroughDate);
        SupportingInformationComponent nchVrfdNcvrdStayInfo = addInformation(eob, CcwCodebookVariable.NCH_VRFD_NCVRD_STAY_FROM_DT);
        Period nchVrfdNcvrdStayPeriod = new Period();
        noncoveredStayFromDate.ifPresent(d -> nchVrfdNcvrdStayPeriod.setStart(convertToDate(d), TemporalPrecisionEnum.DAY));
        noncoveredStayThroughDate.ifPresent(d -> nchVrfdNcvrdStayPeriod.setEnd(convertToDate(d), TemporalPrecisionEnum.DAY));
        nchVrfdNcvrdStayInfo.setTiming(nchVrfdNcvrdStayPeriod);
    }
    // ExplanationOfBenefit.supportingInfo.timingDate
    if (coveredCareThroughDate.isPresent()) {
        SupportingInformationComponent nchActvOrCvrdLvlCareThruInfo = TransformerUtilsV2.addInformation(eob, CcwCodebookVariable.NCH_ACTV_OR_CVRD_LVL_CARE_THRU);
        nchActvOrCvrdLvlCareThruInfo.setTiming(new DateType(TransformerUtilsV2.convertToDate(coveredCareThroughDate.get())));
    }
    // ExplanationOfBenefit.supportingInfo.timingDate
    if (medicareBenefitsExhaustedDate.isPresent()) {
        SupportingInformationComponent nchBeneMdcrBnftsExhtdDtIInfo = TransformerUtilsV2.addInformation(eob, CcwCodebookVariable.NCH_BENE_MDCR_BNFTS_EXHTD_DT_I);
        nchBeneMdcrBnftsExhtdDtIInfo.setTiming(new DateType(TransformerUtilsV2.convertToDate(medicareBenefitsExhaustedDate.get())));
    }
    // diagnosisRelatedGroupCd
    // CLM_DRG_CD => ExplanationOfBenefit.supportingInfo
    diagnosisRelatedGroupCd.ifPresent(cd -> addInformationWithCode(eob, CcwCodebookVariable.CLM_DRG_CD, CcwCodebookVariable.CLM_DRG_CD, cd));
}
Also used : SupportingInformationComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.SupportingInformationComponent) Period(org.hl7.fhir.r4.model.Period) DateType(org.hl7.fhir.r4.model.DateType)

Aggregations

ArrayList (java.util.ArrayList)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 Coding (org.hl7.fhir.r4.model.Coding)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 CD (net.ihe.gazelle.hl7v3.datatypes.CD)7 CS (net.ihe.gazelle.hl7v3.datatypes.CS)7 II (net.ihe.gazelle.hl7v3.datatypes.II)7 TS (net.ihe.gazelle.hl7v3.datatypes.TS)7 MCCIMT000100UV01Device (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device)7 MCCIMT000100UV01Receiver (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver)7 MCCIMT000100UV01Sender (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender)7 Identifier (org.hl7.fhir.r4.model.Identifier)7 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)7 IOException (java.io.IOException)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)5