Search in sources :

Example 1 with Component

use of ca.uhn.fhir.model.dstu2.resource.Observation.Component in project eCRNow by drajer-health.

the class Dstu2CdaImmunizationGenerator method generateImmunizationSection.

public static String generateImmunizationSection(Dstu2FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<Immunization> imms = data.getImmunizations();
    if (imms != null && imms.size() > 0) {
        // Generate the component and section end tags
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_SEC_TEMPLATE_ID, CdaGeneratorConstants.IMMUNIZATION_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.IMMUNIZATION_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.IMMUNIZATION_SEC_NAME));
        // add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.IMMUNIZATION_SEC_TITLE));
        // add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<String>();
        list.add(CdaGeneratorConstants.IMM_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.IMM_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // add Table Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // add Body Rows
        int rowNum = 1;
        for (Immunization imm : imms) {
            String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (imm.getVaccineCode() != null && imm.getVaccineCode().getCodingFirstRep() != null && !StringUtils.isEmpty(imm.getVaccineCode().getCodingFirstRep().getDisplay())) {
                medDisplayName = imm.getVaccineCode().getCodingFirstRep().getDisplay();
            }
            String dt = null;
            if (imm.getDate() != null) {
                dt = imm.getDate().toString();
            }
            Map<String, String> bodyvals = new HashMap<String, String>();
            bodyvals.put(CdaGeneratorConstants.IMM_TABLE_COL_1_BODY_CONTENT, medDisplayName);
            bodyvals.put(CdaGeneratorConstants.IMM_TABLE_COL_2_BODY_CONTENT, dt);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
        }
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // End Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        for (Immunization imm : imms) {
            // add the Entries.
            sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // add the medication Act
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.MED_ACT_EL_NAME, CdaGeneratorConstants.MED_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_ACTIVITY_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_ACTIVITY_TEMPLATE_ID, CdaGeneratorConstants.IMMUNIZATION_ACTIVITY_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), imm.getId().getIdPart()));
            // set status code
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            // Set up Effective Time for start and End time.
            sb.append(Dstu2CdaFhirUtilities.getDateTimeTypeXml(imm.getDateElement(), CdaGeneratorConstants.EFF_TIME_EL_NAME));
            // add the consumable presentation.
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForStartElementWithClassCode(CdaGeneratorConstants.MAN_PROD_EL_NAME, CdaGeneratorConstants.MANU_CLASS_CODE));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_MEDICATION_INFORMATION));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.IMMUNIZATION_MEDICATION_INFORMATION, CdaGeneratorConstants.IMMUNIZATION_MEDICATION_INFORMATION_EXT));
            sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            List<CodeableConceptDt> cds = new ArrayList<CodeableConceptDt>();
            cds.add(imm.getVaccineCode());
            sb.append(Dstu2CdaFhirUtilities.getCodeableConceptXml(cds, CdaGeneratorConstants.CODE_EL_NAME, false));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MAN_PROD_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            // End Tags for Entries
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MED_ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_EL_NAME));
        }
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyImmunizations());
    }
    return sb.toString();
}
Also used : Immunization(ca.uhn.fhir.model.dstu2.resource.Immunization) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 2 with Component

use of ca.uhn.fhir.model.dstu2.resource.Observation.Component in project synthea by synthetichealth.

the class FhirDstu2 method observation.

/**
 * Map the given Observation into a FHIR Observation resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Person Entry
 * @param bundle
 *          The Bundle to add to
 * @param encounterEntry
 *          The current Encounter entry
 * @param observation
 *          The Observation
 * @return The added Entry
 */
private static Entry observation(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Observation observation) {
    ca.uhn.fhir.model.dstu2.resource.Observation observationResource = new ca.uhn.fhir.model.dstu2.resource.Observation();
    observationResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
    observationResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
    observationResource.setStatus(ObservationStatusEnum.FINAL);
    Code code = observation.codes.get(0);
    observationResource.setCode(mapCodeToCodeableConcept(code, LOINC_URI));
    Code category = new Code("http://hl7.org/fhir/observation-category", observation.category, observation.category);
    observationResource.setCategory(mapCodeToCodeableConcept(category, "http://hl7.org/fhir/observation-category"));
    if (observation.value != null) {
        IDatatype value = mapValueToFHIRType(observation.value, observation.unit);
        observationResource.setValue(value);
    } else if (observation.observations != null && !observation.observations.isEmpty()) {
        // multi-observation (ex blood pressure)
        for (Observation subObs : observation.observations) {
            Component comp = new Component();
            comp.setCode(mapCodeToCodeableConcept(subObs.codes.get(0), LOINC_URI));
            IDatatype value = mapValueToFHIRType(subObs.value, subObs.unit);
            comp.setValue(value);
            observationResource.addComponent(comp);
        }
    }
    observationResource.setEffective(convertFhirDateTime(observation.start, true));
    observationResource.setIssued(new InstantDt(new Date(observation.start)));
    Entry entry = newEntry(rand, bundle, observationResource);
    observation.fullUrl = entry.getFullUrl();
    return entry;
}
Also used : IDatatype(ca.uhn.fhir.model.api.IDatatype) ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) Component(ca.uhn.fhir.model.dstu2.resource.Observation.Component) InstantDt(ca.uhn.fhir.model.primitive.InstantDt)

Example 3 with Component

use of ca.uhn.fhir.model.dstu2.resource.Observation.Component in project eCRNow by drajer-health.

the class Dstu2CdaMedicationGenerator method generateMedicationSection.

public static String generateMedicationSection(Dstu2FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    // List<MedicationStatement> meds = data.getMedications();
    List<MedicationAdministration> meds = data.getMedicationAdministrations();
    if (meds != null && meds.size() > 0) {
        // Generate the component and section end tags
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForNFSection(CdaGeneratorConstants.SECTION_EL_NAME, CdaGeneratorConstants.NF_NI));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ADM_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ADM_SEC_TEMPLATE_ID, CdaGeneratorConstants.MED_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.MED_ADM_SEC_NAME));
        // add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.MED_ADM_SEC_TITLE));
        // add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<String>();
        list.add(CdaGeneratorConstants.MED_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.MED_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // add Table Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // add Body Rows
        int rowNum = 1;
        for (MedicationAdministration med : meds) {
            String medDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (med.getMedication() != null) {
                medDisplayName = Dstu2CdaFhirUtilities.getStringForIDataType(med.getMedication());
            }
            String dt = null;
            if (med.getEffectiveTime() != null) {
                dt = Dstu2CdaFhirUtilities.getStringForIDataType(med.getEffectiveTime());
            }
            Map<String, String> bodyvals = new HashMap<String, String>();
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_1_BODY_CONTENT, medDisplayName);
            bodyvals.put(CdaGeneratorConstants.MED_TABLE_COL_2_BODY_CONTENT, dt);
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
        }
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // End Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        for (MedicationAdministration med : meds) {
            // add the Entries.
            sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // add the medication Act
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.MED_ACT_EL_NAME, CdaGeneratorConstants.MED_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ENTRY_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.MED_ENTRY_TEMPLATE_ID, CdaGeneratorConstants.MED_ENTRY_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), med.getId().getIdPart()));
            // set status code
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            // Set up Effective Time for start and End time.
            sb.append(Dstu2CdaFhirUtilities.getIDataTypeXml(med.getEffectiveTime(), CdaGeneratorConstants.EFF_TIME_EL_NAME, false));
            // Set up Effective Time for Frequency.
            String ds = "";
            String freqInHours = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (med.getDosage() != null) {
                Dosage dsg = med.getDosage();
                if (dsg.getQuantity() != null && dsg.getQuantity().getValue() != null && dsg.getQuantity().getUnit() != null) {
                    // add Dose quantity
                    sb.append(CdaGeneratorUtils.getXmlForQuantity(CdaGeneratorConstants.DOSE_QUANTITY_EL_NAME, dsg.getQuantity().getValue().toString(), dsg.getQuantity().getUnit(), false));
                }
            }
            // add the consumable presentation.
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForStartElementWithClassCode(CdaGeneratorConstants.MAN_PROD_EL_NAME, CdaGeneratorConstants.MANU_CLASS_CODE));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.CONSUMABLE_ENTRY_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.CONSUMABLE_ENTRY_TEMPLATE_ID, CdaGeneratorConstants.CONSUMABLE_ENTRY_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            sb.append(Dstu2CdaFhirUtilities.getIDataTypeXml(med.getMedication(), CdaGeneratorConstants.CODE_EL_NAME, false));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MANU_MAT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MAN_PROD_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.CONSUMABLE_EL_NAME));
            // End Tags for Entries
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.MED_ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_EL_NAME));
        }
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyMedications());
    }
    return sb.toString();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MedicationAdministration(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration) Dosage(ca.uhn.fhir.model.dstu2.resource.MedicationAdministration.Dosage)

Example 4 with Component

use of ca.uhn.fhir.model.dstu2.resource.Observation.Component in project eCRNow by drajer-health.

the class Dstu2CdaProblemGenerator method generateProblemSection.

public static String generateProblemSection(Dstu2FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    List<Condition> conds = data.getConditions();
    if (conds != null && conds.size() > 0) {
        // Generate the component and section end tags
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.COMP_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID));
        sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID, CdaGeneratorConstants.PROB_SEC_TEMPLATE_ID_EXT));
        sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.PROB_SEC_CODE, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.PROB_SEC_NAME));
        // Add Title
        sb.append(CdaGeneratorUtils.getXmlForText(CdaGeneratorConstants.TITLE_EL_NAME, CdaGeneratorConstants.PROB_SEC_TITLE));
        // Add Narrative Text
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<String>();
        list.add(CdaGeneratorConstants.PROB_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.PROB_TABLE_COL_2_TITLE);
        sb.append(CdaGeneratorUtils.getXmlForTableHeader(list, CdaGeneratorConstants.TABLE_BORDER, CdaGeneratorConstants.TABLE_WIDTH));
        // Add Table Body
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // Add Body Rows
        int rowNum = 1;
        for (Condition prob : conds) {
            String probDisplayName = CdaGeneratorConstants.UNKNOWN_VALUE;
            if (prob.getCode() != null && prob.getCode().getCodingFirstRep() != null && !StringUtils.isEmpty(prob.getCode().getCodingFirstRep().getDisplay())) {
                probDisplayName = prob.getCode().getCodingFirstRep().getDisplay();
            }
            Map<String, String> bodyvals = new HashMap<String, String>();
            bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_1_BODY_CONTENT, probDisplayName);
            if (prob.getClinicalStatus() != null && (prob.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.ACTIVE.getCode()) || prob.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.RELAPSE.getCode()))) {
                bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_2_BODY_CONTENT, CdaGeneratorConstants.TABLE_ACTIVE_STATUS);
            } else {
                bodyvals.put(CdaGeneratorConstants.PROB_TABLE_COL_2_BODY_CONTENT, CdaGeneratorConstants.TABLE_RESOLVED_STATUS);
            }
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, rowNum));
            // TODO: ++rowNum or rowNum++
            ++rowNum;
        }
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        // End Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        Boolean triggerCodesAdded = false;
        for (Condition pr : conds) {
            // Add the Entries.
            sb.append(CdaGeneratorUtils.getXmlForActEntry(CdaGeneratorConstants.TYPE_CODE_DEF));
            // Add the problem Concern Act
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.ACT_EL_NAME, CdaGeneratorConstants.ACT_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID, CdaGeneratorConstants.PROB_CONCERN_TEMPLATE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForIIUsingGuid());
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.PROB_CONC_ACT_CODE, CdaGeneratorConstants.HL7_ACT_CLASS_OID, CdaGeneratorConstants.HL7_ACT_CLASS_NAME, CdaGeneratorConstants.PROB_CONC_ACT_NAME));
            if (pr.getClinicalStatus() != null && (pr.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.ACTIVE.getCode()) || pr.getClinicalStatus().contentEquals(ConditionClinicalStatusCodesEnum.RELAPSE.getCode()))) {
                sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.ACTIVE_STATUS));
            } else {
                sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            }
            Pair<Date, TimeZone> onset = null;
            Pair<Date, TimeZone> abatement = null;
            Pair<Date, TimeZone> recorded = null;
            if (pr.getOnset() != null && pr.getOnset() instanceof DateTimeDt) {
                DateTimeDt dt = (DateTimeDt) pr.getOnset();
                onset = new Pair<>(dt.getValue(), dt.getTimeZone());
            }
            if (pr.getAbatement() != null && pr.getAbatement() instanceof DateTimeDt) {
                DateTimeDt dt = (DateTimeDt) pr.getAbatement();
                abatement = new Pair<>(dt.getValue(), dt.getTimeZone());
            }
            if (pr.getDateRecordedElement() != null) {
                recorded = new Pair<>(pr.getDateRecorded(), null);
            }
            sb.append(CdaGeneratorUtils.getXmlForIVLWithTS(CdaGeneratorConstants.EFF_TIME_EL_NAME, recorded, abatement, true));
            // Add the Problem Observation
            sb.append(CdaGeneratorUtils.getXmlForEntryRelationship(CdaGeneratorConstants.ENTRY_REL_SUBJ_CODE));
            sb.append(CdaGeneratorUtils.getXmlForAct(CdaGeneratorConstants.OBS_ACT_EL_NAME, CdaGeneratorConstants.OBS_CLASS_CODE, CdaGeneratorConstants.MOOD_CODE_DEF));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_OBS_TEMPLATE_ID));
            sb.append(CdaGeneratorUtils.getXmlForTemplateId(CdaGeneratorConstants.PROB_OBS_TEMPLATE_ID, CdaGeneratorConstants.PROB_OBS_TEMPALTE_ID_EXT));
            sb.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), pr.getId().getValue()));
            sb.append(CdaGeneratorUtils.getXmlForCDWithoutEndTag(CdaGeneratorConstants.CODE_EL_NAME, CdaGeneratorConstants.DIAGNOSIS_SNOMED, CdaGeneratorConstants.SNOMED_CODESYSTEM_OID, CdaGeneratorConstants.SNOMED_CODESYSTEM_NAME, CdaGeneratorConstants.DIAGNOSIS_DISPLAY_NAME));
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.TRANSLATION_EL_NAME, CdaGeneratorConstants.DIAGNOSIS_LOINC, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.DIAGNOSIS_DISPLAY_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.CODE_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.STATUS_CODE_EL_NAME, CdaGeneratorConstants.COMPLETED_STATUS));
            sb.append(CdaGeneratorUtils.getXmlForIVLWithTS(CdaGeneratorConstants.EFF_TIME_EL_NAME, onset, abatement, true));
            List<CodeableConceptDt> cds = new ArrayList<CodeableConceptDt>();
            cds.add(pr.getCode());
            sb.append(Dstu2CdaFhirUtilities.getCodeableConceptXml(cds, CdaGeneratorConstants.VAL_EL_NAME, true));
            // End Tag for Entry Relationship
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.OBS_ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_REL_EL_NAME));
            if (!triggerCodesAdded) {
                sb.append(addTriggerCodes(data, details, pr, onset, abatement));
                triggerCodesAdded = true;
            }
            // End Tags for Entries
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ACT_EL_NAME));
            sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.ENTRY_EL_NAME));
        }
        // Complete the section end tags.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.SECTION_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.COMP_EL_NAME));
    } else {
        sb.append(generateEmptyProblemSection());
    }
    return sb.toString();
}
Also used : Condition(ca.uhn.fhir.model.dstu2.resource.Condition) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Date(java.util.Date) TimeZone(java.util.TimeZone) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt)

Aggregations

ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)2 Date (java.util.Date)2 IDatatype (ca.uhn.fhir.model.api.IDatatype)1 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)1 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)1 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)1 Immunization (ca.uhn.fhir.model.dstu2.resource.Immunization)1 MedicationAdministration (ca.uhn.fhir.model.dstu2.resource.MedicationAdministration)1 Dosage (ca.uhn.fhir.model.dstu2.resource.MedicationAdministration.Dosage)1 Component (ca.uhn.fhir.model.dstu2.resource.Observation.Component)1 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)1 InstantDt (ca.uhn.fhir.model.primitive.InstantDt)1 TimeZone (java.util.TimeZone)1 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)1 Observation (org.mitre.synthea.world.concepts.HealthRecord.Observation)1