Search in sources :

Example 91 with CD

use of org.hl7.v3.CD in project eCRNow by drajer-health.

the class CdaFhirUtilities method getCodeableConceptDisplayForCodeSystem.

public static String getCodeableConceptDisplayForCodeSystem(List<CodeableConcept> cds, String codeSystemUrl, Boolean csOptional) {
    String anyCdDisplay = "";
    Pair<String, Boolean> disp = null;
    if (cds != null && !cds.isEmpty()) {
        for (CodeableConcept cd : cds) {
            disp = getCodeableConceptDisplayForCodeSystem(cd, codeSystemUrl, csOptional);
            if (!StringUtils.isEmpty(disp.getValue0())) {
                // Found a display
                break;
            }
            // If display is at the Codeable Concept level, use it in case we don't find anything else
            if (cd != null && !StringUtils.isEmpty(cd.getText())) {
                anyCdDisplay = cd.getText();
            }
        }
    }
    if (disp != null && !StringUtils.isEmpty(disp.getValue0()))
        return disp.getValue0();
    else if (!StringUtils.isEmpty(anyCdDisplay))
        return anyCdDisplay;
    else
        return CdaGeneratorConstants.UNKNOWN_VALUE;
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 92 with CD

use of org.hl7.v3.CD in project eCRNow by drajer-health.

the class CdaFhirUtilities method getStringForType.

public static String getStringForType(Type dt) {
    if (dt != null) {
        StringBuilder val = new StringBuilder();
        if (dt instanceof Coding) {
            Coding cd = (Coding) dt;
            val.append(getStringForCoding(cd));
        } else if (dt instanceof CodeableConcept) {
            CodeableConcept cd = (CodeableConcept) dt;
            if (!StringUtils.isEmpty(cd.getText())) {
                val.append(cd.getText());
            } else {
                List<Coding> cds = cd.getCoding();
                Boolean first = true;
                for (Coding c : cds) {
                    if (!first) {
                        val.append(CdaGeneratorConstants.SPACE).append(CdaGeneratorConstants.PIPE).append(CdaGeneratorConstants.SPACE);
                    }
                    first = false;
                    val.append(getStringForCoding(c));
                }
            }
        } else if (dt instanceof Quantity) {
            Quantity qt = (Quantity) dt;
            val.append(getStringForQuantity(qt));
        } else if (dt instanceof DateTimeType) {
            DateTimeType d = (DateTimeType) dt;
            val.append(d.getValueAsString());
        } else if (dt instanceof Timing) {
            logger.debug("Found an instance of timing for creating string ");
            Timing t = (Timing) (dt);
            if (t.getRepeat() != null && t.getRepeat().getBounds() != null) {
                logger.debug("Found the bounds element for creating string ");
                String v = getStringForType(t.getRepeat().getBounds());
                val.append(v);
            }
        } else if (dt instanceof Period) {
            Period pt = (Period) dt;
            logger.debug("Found the Period element for creating string");
            if (pt.getStart() != null && pt.getEnd() != null) {
                val.append(pt.getStart().toString()).append(CdaGeneratorConstants.PIPE).append(pt.getEnd().toString());
            } else if (pt.getStart() != null) {
                val.append(pt.getStart().toString());
            } else {
                val.append(CdaGeneratorConstants.UNKNOWN_VALUE);
            }
        } else if (dt instanceof CodeType) {
            CodeType cd = (CodeType) dt;
            val.append(cd.getValue());
        } else if (dt instanceof StringType) {
            StringType st = (StringType) dt;
            val.append(st.getValue());
        }
        logger.debug("Printing the class name {} and value {}", dt.getClass(), val);
        return val.toString();
    }
    return CdaGeneratorConstants.UNKNOWN_VALUE;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) Quantity(org.hl7.fhir.r4.model.Quantity) Period(org.hl7.fhir.r4.model.Period) CodeType(org.hl7.fhir.r4.model.CodeType) List(java.util.List) ArrayList(java.util.ArrayList) Timing(org.hl7.fhir.r4.model.Timing) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 93 with CD

use of org.hl7.v3.CD in project eCRNow by drajer-health.

the class CdaFhirUtilities method getXmlForCodeableConceptWithCDAndValueSetAndVersion.

public static String getXmlForCodeableConceptWithCDAndValueSetAndVersion(String elementName, String code, String codeSystem, String codeSystemName, String valueSet, String valuesetVersion, CodeableConcept cc, String csUrl, String contentRef) {
    StringBuilder retval = new StringBuilder();
    StringBuilder translations = new StringBuilder();
    Boolean foundCodings = false;
    if (cc != null) {
        String dispName = cc.getText();
        List<Coding> cds = cc.getCoding();
        if (cds != null && !cds.isEmpty()) {
            for (Coding cd : cds) {
                if (cd.getCode() != null && !cd.getCode().isEmpty() && code.contentEquals(cd.getCode()) && csUrl.contentEquals(cd.getSystem()) && !foundCodings) {
                    logger.debug(" Found a Coding that matches the CodeSystem and Code {} : {} ", codeSystem, code);
                    if (cd.getDisplay() != null && !cd.getDisplay().isEmpty())
                        dispName = cd.getDisplay();
                    if (elementName.contentEquals(CdaGeneratorConstants.CODE_EL_NAME)) {
                        retval.append(CdaGeneratorUtils.getXmlForCDWithValueSetAndVersionWihoutEndTag(elementName, code, codeSystem, codeSystemName, valueSet, valuesetVersion, dispName));
                        if (!contentRef.isEmpty())
                            retval.append(CdaGeneratorUtils.getXmlForOriginalTextWithReference(contentRef));
                    } else if (elementName.contentEquals(CdaGeneratorConstants.VAL_EL_NAME)) {
                        retval.append(CdaGeneratorUtils.getXmlForValueCDWithValueSetAndVersionWihoutEndTag(elementName, code, codeSystem, codeSystemName, valueSet, valuesetVersion, dispName));
                    }
                    foundCodings = true;
                } else {
                    Pair<String, String> csd = CdaGeneratorConstants.getCodeSystemFromUrl(cd.getSystem());
                    if (!csd.getValue0().isEmpty() && !csd.getValue1().isEmpty()) {
                        if (cd.getDisplay() != null && !cd.getDisplay().isEmpty())
                            dispName = cd.getDisplay();
                        // Create Translations.
                        translations.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.TRANSLATION_EL_NAME, cd.getCode(), csd.getValue0(), csd.getValue1(), dispName));
                    }
                }
            }
        }
    }
    if (foundCodings) {
        retval.append(translations.toString());
        retval.append(CdaGeneratorUtils.getXmlForEndElement(elementName));
    } else {
        String dispName = "";
        if (cc != null && cc.getText() != null && !cc.getText().isEmpty())
            dispName = cc.getText();
        if (elementName.contentEquals(CdaGeneratorConstants.CODE_EL_NAME)) {
            retval.append(CdaGeneratorUtils.getXmlForCDWithValueSetAndVersion(CdaGeneratorConstants.CODE_EL_NAME, code, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.RCTC_OID, ActionRepo.getInstance().getRctcVersion(), dispName, contentRef));
        } else if (elementName.contentEquals(CdaGeneratorConstants.VAL_EL_NAME)) {
            retval.append(CdaGeneratorUtils.getXmlForValueCDWithValueSetAndVersion(code, CdaGeneratorConstants.LOINC_CODESYSTEM_OID, CdaGeneratorConstants.LOINC_CODESYSTEM_NAME, CdaGeneratorConstants.RCTC_OID, ActionRepo.getInstance().getRctcVersion(), dispName));
        }
    }
    return retval.toString();
}
Also used : Coding(org.hl7.fhir.r4.model.Coding)

Example 94 with CD

use of org.hl7.v3.CD in project eCRNow by drajer-health.

the class FhirGeneratorUtils method getCoding.

public static Coding getCoding(String system, String code, String display) {
    Coding cd = null;
    if (system != null && code != null && !StringUtils.isEmpty(system) && !StringUtils.isEmpty(code)) {
        cd = new Coding();
        cd.setSystem(system);
        cd.setCode(code);
        if (!StringUtils.isEmpty(display))
            cd.setDisplay(display);
    }
    return cd;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding)

Example 95 with CD

use of org.hl7.v3.CD in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationMapper method createMedication.

public Medication createMedication(RCMRMT030101UK04Consumable consumable) {
    if (hasManufacturedMaterial(consumable)) {
        CD code = consumable.getManufacturedProduct().getManufacturedMaterial().getCode();
        if (!medicationMapperContext.contains(code)) {
            Medication medication = new Medication();
            medication.setId(medicationMapperContext.getMedicationId(code));
            medication.setMeta(generateMeta(MEDICATION_URL));
            medication.setCode(codeableConceptMapper.mapToCodeableConceptForMedication(code));
            return medication;
        }
    }
    return null;
}
Also used : CD(org.hl7.v3.CD) Medication(org.hl7.fhir.dstu3.model.Medication)

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