Search in sources :

Example 1 with CodeDt

use of ca.uhn.fhir.model.primitive.CodeDt in project eCRNow by drajer-health.

the class Dstu2CdaFhirUtilities method getIDataTypeXml.

public static String getIDataTypeXml(IDatatype dt, String elName, Boolean valFlag) {
    if (dt != null) {
        logger.info(" Printing the class name " + dt.getClass());
        String val = "";
        if (dt instanceof CodingDt) {
            CodingDt cd = (CodingDt) dt;
            List<CodingDt> cds = new ArrayList<CodingDt>();
            cds.add(cd);
            if (!valFlag)
                val += getCodingXml(cds, elName);
            else
                val += getCodingXmlForValue(cds, elName);
        } else if (dt instanceof CodeableConceptDt) {
            CodeableConceptDt cd = (CodeableConceptDt) dt;
            List<CodingDt> cds = cd.getCoding();
            if (!valFlag)
                val += getCodingXml(cds, elName);
            else
                val += getCodingXmlForValue(cds, elName);
        } else if (dt instanceof QuantityDt) {
            QuantityDt qt = (QuantityDt) dt;
            val += getQuantityXml(qt, elName, valFlag);
        } else if (dt instanceof DateTimeDt) {
            DateTimeDt d = (DateTimeDt) dt;
            val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
        } else if (dt instanceof PeriodDt) {
            PeriodDt pt = (PeriodDt) dt;
            val += getPeriodXml(pt, elName);
        } else if (dt instanceof CodeDt) {
            CodeDt cd = (CodeDt) dt;
            if (!valFlag)
                val += CdaGeneratorUtils.getXmlForNullCD(elName, CdaGeneratorConstants.NF_NI);
            else
                val += CdaGeneratorUtils.getNFXMLForValue(CdaGeneratorConstants.NF_NI);
        }
        return val;
    }
    return CdaGeneratorConstants.UNKNOWN_VALUE;
}
Also used : CodeDt(ca.uhn.fhir.model.primitive.CodeDt) BoundCodeDt(ca.uhn.fhir.model.primitive.BoundCodeDt) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) BoundCodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) ArrayList(java.util.ArrayList) QuantityDt(ca.uhn.fhir.model.dstu2.composite.QuantityDt) BaseQuantityDt(ca.uhn.fhir.model.base.composite.BaseQuantityDt) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with CodeDt

use of ca.uhn.fhir.model.primitive.CodeDt in project synthea by synthetichealth.

the class FhirDstu2 method basicInfo.

/**
 * Map the given Person to a FHIR Patient resource, and add it to the given Bundle.
 *
 * @param person
 *          The Person
 * @param bundle
 *          The Bundle to add to
 * @param stopTime
 *          Time the simulation ended
 * @return The created Entry
 */
@SuppressWarnings("rawtypes")
private static Entry basicInfo(Person person, Bundle bundle, long stopTime) {
    Patient patientResource = new Patient();
    patientResource.addIdentifier().setSystem("https://github.com/synthetichealth/synthea").setValue((String) person.attributes.get(Person.ID));
    patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.MR).setSystem("http://hospital.smarthealthit.org").setValue((String) person.attributes.get(Person.ID));
    patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.SOCIAL_BENEFICIARY_IDENTIFIER).setSystem("http://hl7.org/fhir/sid/us-ssn").setValue((String) person.attributes.get(Person.IDENTIFIER_SSN));
    if (person.attributes.get(Person.IDENTIFIER_DRIVERS) != null) {
        patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.DL).setSystem("urn:oid:2.16.840.1.113883.4.3.25").setValue((String) person.attributes.get(Person.IDENTIFIER_DRIVERS));
    }
    ExtensionDt raceExtension = new ExtensionDt();
    raceExtension.setUrl("http://hl7.org/fhir/StructureDefinition/us-core-race");
    String race = (String) person.attributes.get(Person.RACE);
    ExtensionDt ethnicityExtension = new ExtensionDt();
    ethnicityExtension.setUrl("http://hl7.org/fhir/StructureDefinition/us-core-ethnicity");
    String ethnicity = (String) person.attributes.get(Person.ETHNICITY);
    String raceDisplay;
    switch(race) {
        case "white":
            raceDisplay = "White";
            break;
        case "black":
            raceDisplay = "Black or African American";
            break;
        case "asian":
            raceDisplay = "Asian";
            break;
        case "native":
            raceDisplay = "American Indian or Alaska Native";
            break;
        case "hawaiian":
            raceDisplay = "Native Hawaiian or Other Pacific Islander";
            break;
        default:
            raceDisplay = "Other";
            break;
    }
    String ethnicityDisplay;
    if (ethnicity.equals("hispanic")) {
        ethnicityDisplay = "Hispanic or Latino";
    } else {
        ethnicityDisplay = "Not Hispanic or Latino";
    }
    Code raceCode = new Code("http://hl7.org/fhir/v3/Race", (String) raceEthnicityCodes.get(race), raceDisplay);
    Code ethnicityCode = new Code("http://hl7.org/fhir/v3/Ethnicity", (String) raceEthnicityCodes.get(ethnicity), ethnicityDisplay);
    raceExtension.setValue(mapCodeToCodeableConcept(raceCode, "http://hl7.org/fhir/v3/Race"));
    ethnicityExtension.setValue(mapCodeToCodeableConcept(ethnicityCode, "http://hl7.org/fhir/v3/Ethnicity"));
    patientResource.addUndeclaredExtension(raceExtension);
    patientResource.addUndeclaredExtension(ethnicityExtension);
    String firstLanguage = (String) person.attributes.get(Person.FIRST_LANGUAGE);
    Map languageMap = (Map) languageLookup.get(firstLanguage);
    Code languageCode = new Code((String) languageMap.get("system"), (String) languageMap.get("code"), (String) languageMap.get("display"));
    List<Communication> communication = new ArrayList<Communication>();
    Communication language = new Communication();
    language.setLanguage(mapCodeToCodeableConcept(languageCode, (String) languageMap.get("system")));
    communication.add(language);
    patientResource.setCommunication(communication);
    HumanNameDt name = patientResource.addName();
    name.setUse(NameUseEnum.OFFICIAL);
    name.addGiven((String) person.attributes.get(Person.FIRST_NAME));
    List<StringDt> officialFamilyNames = new ArrayList<StringDt>();
    officialFamilyNames.add(new StringDt((String) person.attributes.get(Person.LAST_NAME)));
    name.setFamily(officialFamilyNames);
    if (person.attributes.get(Person.NAME_PREFIX) != null) {
        name.addPrefix((String) person.attributes.get(Person.NAME_PREFIX));
    }
    if (person.attributes.get(Person.NAME_SUFFIX) != null) {
        name.addSuffix((String) person.attributes.get(Person.NAME_SUFFIX));
    }
    if (person.attributes.get(Person.MAIDEN_NAME) != null) {
        HumanNameDt maidenName = patientResource.addName();
        maidenName.setUse(NameUseEnum.MAIDEN);
        maidenName.addGiven((String) person.attributes.get(Person.FIRST_NAME));
        List<StringDt> maidenFamilyNames = new ArrayList<StringDt>();
        maidenFamilyNames.add(new StringDt((String) person.attributes.get(Person.MAIDEN_NAME)));
        maidenName.setFamily(maidenFamilyNames);
        if (person.attributes.get(Person.NAME_PREFIX) != null) {
            maidenName.addPrefix((String) person.attributes.get(Person.NAME_PREFIX));
        }
        if (person.attributes.get(Person.NAME_SUFFIX) != null) {
            maidenName.addSuffix((String) person.attributes.get(Person.NAME_SUFFIX));
        }
    }
    ExtensionDt mothersMaidenNameExtension = new ExtensionDt();
    mothersMaidenNameExtension.setUrl("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");
    String mothersMaidenName = (String) person.attributes.get(Person.NAME_MOTHER);
    mothersMaidenNameExtension.setValue(new StringDt(mothersMaidenName));
    patientResource.addUndeclaredExtension(mothersMaidenNameExtension);
    long birthdate = (long) person.attributes.get(Person.BIRTHDATE);
    patientResource.setBirthDate(new DateDt(new Date(birthdate)));
    ExtensionDt birthSexExtension = new ExtensionDt();
    birthSexExtension.setUrl("http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex");
    if (person.attributes.get(Person.GENDER).equals("M")) {
        patientResource.setGender(AdministrativeGenderEnum.MALE);
        birthSexExtension.setValue(new CodeDt("M"));
    } else if (person.attributes.get(Person.GENDER).equals("F")) {
        patientResource.setGender(AdministrativeGenderEnum.FEMALE);
        birthSexExtension.setValue(new CodeDt("F"));
    }
    patientResource.addUndeclaredExtension(birthSexExtension);
    String state = (String) person.attributes.get(Person.STATE);
    AddressDt addrResource = patientResource.addAddress();
    addrResource.addLine((String) person.attributes.get(Person.ADDRESS)).setCity((String) person.attributes.get(Person.CITY)).setPostalCode((String) person.attributes.get(Person.ZIP)).setState(state);
    if (COUNTRY_CODE != null) {
        addrResource.setCountry(COUNTRY_CODE);
    }
    Point2D.Double coord = person.getLonLat();
    if (coord != null) {
        ExtensionDt geolocationExtension = new ExtensionDt();
        geolocationExtension.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
        ExtensionDt latitudeExtension = new ExtensionDt();
        ExtensionDt longitudeExtension = new ExtensionDt();
        latitudeExtension.setUrl("latitude");
        longitudeExtension.setUrl("longitude");
        latitudeExtension.setValue(new DecimalDt(coord.getY()));
        longitudeExtension.setValue(new DecimalDt(coord.getX()));
        geolocationExtension.addUndeclaredExtension(latitudeExtension);
        geolocationExtension.addUndeclaredExtension(longitudeExtension);
        addrResource.addUndeclaredExtension(geolocationExtension);
    }
    AddressDt birthplace = new AddressDt();
    birthplace.setCity((String) person.attributes.get(Person.BIRTH_CITY)).setState((String) person.attributes.get(Person.BIRTH_STATE)).setCountry((String) person.attributes.get(Person.BIRTH_COUNTRY));
    ExtensionDt birthplaceExtension = new ExtensionDt();
    birthplaceExtension.setUrl("http://hl7.org/fhir/StructureDefinition/birthPlace");
    birthplaceExtension.setValue(birthplace);
    patientResource.addUndeclaredExtension(birthplaceExtension);
    if (person.attributes.get(Person.MULTIPLE_BIRTH_STATUS) != null) {
        patientResource.setMultipleBirth(new IntegerDt((int) person.attributes.get(Person.MULTIPLE_BIRTH_STATUS)));
    } else {
        patientResource.setMultipleBirth(new BooleanDt(false));
    }
    patientResource.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setUse(ContactPointUseEnum.HOME).setValue((String) person.attributes.get(Person.TELECOM));
    String maritalStatus = ((String) person.attributes.get(Person.MARITAL_STATUS));
    if (maritalStatus != null) {
        patientResource.setMaritalStatus(MaritalStatusCodesEnum.forCode(maritalStatus.toUpperCase()));
    } else {
        patientResource.setMaritalStatus(MaritalStatusCodesEnum.S);
    }
    if (!person.alive(stopTime)) {
        patientResource.setDeceased(convertFhirDateTime((Long) person.attributes.get(Person.DEATHDATE), true));
    }
    String generatedBySynthea = "Generated by <a href=\"https://github.com/synthetichealth/synthea\">Synthea</a>." + "Version identifier: " + Utilities.SYNTHEA_VERSION + " . " + "  Person seed: " + person.seed + "  Population seed: " + person.populationSeed;
    patientResource.setText(new NarrativeDt(new XhtmlDt(generatedBySynthea), NarrativeStatusEnum.GENERATED));
    // DALY and QALY values
    // we only write the last(current) one to the patient record
    Double dalyValue = (Double) person.attributes.get("most-recent-daly");
    Double qalyValue = (Double) person.attributes.get("most-recent-qaly");
    if (dalyValue != null) {
        ExtensionDt dalyExtension = new ExtensionDt();
        dalyExtension.setUrl(SYNTHEA_EXT + "disability-adjusted-life-years");
        DecimalDt daly = new DecimalDt(dalyValue);
        dalyExtension.setValue(daly);
        patientResource.addUndeclaredExtension(dalyExtension);
        ExtensionDt qalyExtension = new ExtensionDt();
        qalyExtension.setUrl(SYNTHEA_EXT + "quality-adjusted-life-years");
        DecimalDt qaly = new DecimalDt(qalyValue);
        qalyExtension.setValue(qaly);
        patientResource.addUndeclaredExtension(qalyExtension);
    }
    return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}
Also used : HumanNameDt(ca.uhn.fhir.model.dstu2.composite.HumanNameDt) XhtmlDt(ca.uhn.fhir.model.primitive.XhtmlDt) IntegerDt(ca.uhn.fhir.model.primitive.IntegerDt) DecimalDt(ca.uhn.fhir.model.primitive.DecimalDt) ArrayList(java.util.ArrayList) Point2D(java.awt.geom.Point2D) AddressDt(ca.uhn.fhir.model.dstu2.composite.AddressDt) BooleanDt(ca.uhn.fhir.model.primitive.BooleanDt) ExtensionDt(ca.uhn.fhir.model.api.ExtensionDt) Communication(ca.uhn.fhir.model.dstu2.resource.Patient.Communication) CodeDt(ca.uhn.fhir.model.primitive.CodeDt) DateDt(ca.uhn.fhir.model.primitive.DateDt) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) NarrativeDt(ca.uhn.fhir.model.dstu2.composite.NarrativeDt) Date(java.util.Date) StringDt(ca.uhn.fhir.model.primitive.StringDt) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with CodeDt

use of ca.uhn.fhir.model.primitive.CodeDt in project eCRNow by drajer-health.

the class Dstu2CdaFhirUtilities method getStringForIDataType.

public static String getStringForIDataType(IDatatype dt) {
    if (dt != null) {
        logger.info(" Printing the class name " + dt.getClass());
        String val = "";
        if (dt instanceof CodingDt) {
            CodingDt cd = (CodingDt) dt;
            if (cd.getCodeElement() != null && cd.getSystemElement() != null) {
                val += cd.getSystemElement().getValue() + CdaGeneratorConstants.PIPE + cd.getCodeElement().getValue();
            }
        } else if (dt instanceof BaseQuantityDt) {
            QuantityDt qt = (QuantityDt) dt;
            if (qt.getValueElement() != null && qt.getSystemElement() != null && qt.getUnit() != null) {
                val += qt.getValueElement().getValueAsString() + CdaGeneratorConstants.PIPE + qt.getSystemElement().getValueAsString() + CdaGeneratorConstants.PIPE + qt.getUnit();
            }
        } else if (dt instanceof DateTimeDt) {
            DateTimeDt d = (DateTimeDt) dt;
            val += d.getValueAsString();
        } else if (dt instanceof PeriodDt) {
            PeriodDt pt = (PeriodDt) dt;
            if (pt.getStart() != null && pt.getEnd() != null) {
                val += pt.getStart().toString() + CdaGeneratorConstants.PIPE + pt.getEnd().toString();
            } else if (pt.getStart() != null) {
                val += pt.getStart().toString();
            }
        } else if (dt instanceof CodeDt) {
            CodeDt cd = (CodeDt) dt;
            val += cd.getValue();
        }
        return val;
    }
    return CdaGeneratorConstants.UNKNOWN_VALUE;
}
Also used : BaseQuantityDt(ca.uhn.fhir.model.base.composite.BaseQuantityDt) CodeDt(ca.uhn.fhir.model.primitive.CodeDt) BoundCodeDt(ca.uhn.fhir.model.primitive.BoundCodeDt) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt) PeriodDt(ca.uhn.fhir.model.dstu2.composite.PeriodDt) CodingDt(ca.uhn.fhir.model.dstu2.composite.CodingDt) QuantityDt(ca.uhn.fhir.model.dstu2.composite.QuantityDt) BaseQuantityDt(ca.uhn.fhir.model.base.composite.BaseQuantityDt)

Example 4 with CodeDt

use of ca.uhn.fhir.model.primitive.CodeDt in project eCRNow by drajer-health.

the class Dstu2CdaSocialHistoryGenerator method generateSocialHistorySection.

public static String generateSocialHistorySection(Dstu2FhirData data, LaunchDetails details) {
    StringBuilder sb = new StringBuilder(2000);
    // Will have to wait to discuss with vendors on Travel History, Pregnancy, and Birth Sex
    // Observations.
    // Then we can generte the entries. Till then it will be empty section.
    CodeDt birthSex = Dstu2CdaFhirUtilities.getCodeExtension(data.getPatient().getUndeclaredExtensions(), CdaGeneratorConstants.FHIR_ARGO_BIRTHSEX_EXT_URL);
    List<Observation> pregObs = data.getPregnancyObs();
    List<Observation> travelHistory = data.getTravelObs();
    if (birthSex != null || (pregObs != null && pregObs.size() > 0) || (travelHistory != null && travelHistory.size() > 0)) {
        sb.append(generateSocialHistorySectionHeader(""));
        sb.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Create Table Header.
        List<String> list = new ArrayList<String>();
        list.add(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_TITLE);
        list.add(CdaGeneratorConstants.SOC_HISTORY_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));
        String birthSexXml = "";
        String pregObsXml = "";
        String travelHistoryXml = "";
        if (birthSex != null) {
            Map<String, String> bodyvals = new HashMap<String, String>();
            bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_1_BODY_CONTENT, CdaGeneratorConstants.BIRTH_SEX_DISPLAY);
            bodyvals.put(CdaGeneratorConstants.SOC_HISTORY_TABLE_COL_2_BODY_CONTENT, Dstu2CdaFhirUtilities.getStringForIDataType(birthSex));
            sb.append(CdaGeneratorUtils.addTableRow(bodyvals, 0));
            birthSexXml = generateBirthSexEntry(data, details, birthSex);
        }
        if (pregObs != null && pregObs.size() > 0) {
            logger.error(" Pregnancy Status Observation Found , translation not implemented ");
        // These are not available in FHIR right now reliably, so nothing to process until further
        // discussion with vendors.
        // Setup Table Text Entries
        // Setup XML Entries
        }
        if (travelHistory != null && travelHistory.size() > 0) {
            logger.error(" Pregnancy Status Observation Found , translation not implemented ");
        // These are not available in FHIR right now reliably, so nothing to process until further
        // discussion with vendors.
        // Setup Table Text Entries
        // Setup XML Entries
        }
        // Close the Table.
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_BODY_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TABLE_EL_NAME));
        sb.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.TEXT_EL_NAME));
        // Add entry
        if (!StringUtils.isEmpty(birthSexXml)) {
            sb.append(birthSexXml);
        }
        if (!StringUtils.isEmpty(pregObsXml)) {
            sb.append(birthSexXml);
        }
        if (!StringUtils.isEmpty(travelHistoryXml)) {
            sb.append(birthSexXml);
        }
        sb.append(generateSocialHistorySectionEndHeader());
    } else {
        sb.append(generateEmptySocialHistorySection());
    }
    return sb.toString();
}
Also used : CodeDt(ca.uhn.fhir.model.primitive.CodeDt) HashMap(java.util.HashMap) Observation(ca.uhn.fhir.model.dstu2.resource.Observation) ArrayList(java.util.ArrayList)

Aggregations

CodeDt (ca.uhn.fhir.model.primitive.CodeDt)4 ArrayList (java.util.ArrayList)3 BaseQuantityDt (ca.uhn.fhir.model.base.composite.BaseQuantityDt)2 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)2 PeriodDt (ca.uhn.fhir.model.dstu2.composite.PeriodDt)2 QuantityDt (ca.uhn.fhir.model.dstu2.composite.QuantityDt)2 BoundCodeDt (ca.uhn.fhir.model.primitive.BoundCodeDt)2 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)2 HashMap (java.util.HashMap)2 ExtensionDt (ca.uhn.fhir.model.api.ExtensionDt)1 AddressDt (ca.uhn.fhir.model.dstu2.composite.AddressDt)1 BoundCodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt)1 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)1 HumanNameDt (ca.uhn.fhir.model.dstu2.composite.HumanNameDt)1 NarrativeDt (ca.uhn.fhir.model.dstu2.composite.NarrativeDt)1 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)1 Patient (ca.uhn.fhir.model.dstu2.resource.Patient)1 Communication (ca.uhn.fhir.model.dstu2.resource.Patient.Communication)1 BooleanDt (ca.uhn.fhir.model.primitive.BooleanDt)1 DateDt (ca.uhn.fhir.model.primitive.DateDt)1