Search in sources :

Example 56 with DecimalType

use of org.hl7.fhir.dstu2016may.model.DecimalType in project pathling by aehrc.

the class TestData method newQuestionnaire.

/**
 * Returns a FHIR Questionnaire resource for testing purposes.
 */
public static Questionnaire newQuestionnaire() {
    final Questionnaire questionnaire = new Questionnaire();
    questionnaire.setId("Questionnaire/1");
    final QuestionnaireItemComponent item = questionnaire.addItem();
    item.addEnableWhen().setAnswer(new DecimalType(TEST_VERY_SMALL_DECIMAL_SCALE_6));
    item.addInitial().setValue(new DecimalType(TEST_VERY_BIG_DECIMAL));
    // This nested item will be discarded on import, as we currently skip recursive elements.
    final QuestionnaireItemComponent nestedItem = item.addItem();
    nestedItem.addInitial().setValue(new DecimalType(TEST_SMALL_DECIMAL));
    return questionnaire;
}
Also used : QuestionnaireItemComponent(org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent)

Example 57 with DecimalType

use of org.hl7.fhir.dstu2016may.model.DecimalType in project redmatch by aehrc.

the class FhirExporter method getValue.

/**
 * Resolves a value.
 *
 * @param value The value specified in the transformation rules.
 * @param fhirType The type of the FHIR attribute where this value will be set.
 * @param vertex A vertex with patient data.
 * @param recordId The id of this record. Used to create the references to FHIR ids.
 * @param enumFactory If the type is an enumeration, this is the factory to create an instance.
 * @param fhirPackage The target FHIR package.
 * @return The value or null if the value cannot be determined. This can also be a list.
 */
private Base getValue(Value value, Class<?> fhirType, JsonObject vertex, String recordId, Class<?> enumFactory, VersionedFhirPackage fhirPackage) throws IOException {
    // If this is a field-based value then make sure that there is a value and if not return null
    if (value instanceof FieldBasedValue) {
        FieldBasedValue fbv = (FieldBasedValue) value;
        // Account for field ids of the form xx___y
        String fieldId = fbv.getFieldId();
        String shortFieldId = null;
        String regex = "(?<fieldId>.*)___\\d+$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(fieldId);
        if (matcher.find()) {
            shortFieldId = matcher.group("fieldId");
            log.debug("Transformed fieldId into '" + fieldId + "'");
        }
        boolean hasValue = false;
        JsonElement jsonElement = vertex.get(fieldId);
        if (jsonElement != null) {
            String rawValue = jsonElement.getAsString();
            if (!rawValue.isEmpty()) {
                hasValue = true;
            }
        }
        if (!hasValue && shortFieldId != null) {
            jsonElement = vertex.get(shortFieldId);
            if (jsonElement != null) {
                String rawValue = jsonElement.getAsString();
                if (!rawValue.isEmpty()) {
                    hasValue = true;
                }
            }
        }
        if (!hasValue) {
            return null;
        }
    }
    if (value instanceof BooleanValue) {
        return new BooleanType(((BooleanValue) value).getValue());
    } else if (value instanceof CodeLiteralValue) {
        String code = ((CodeLiteralValue) value).getCode();
        return getCode(code, enumFactory);
    } else if (value instanceof ConceptLiteralValue) {
        ConceptLiteralValue clv = (ConceptLiteralValue) value;
        String system = clv.getSystem();
        String code = clv.getCode();
        String display = clv.getDisplay() != null ? clv.getDisplay() : "";
        return getConcept(system, code, display, fhirType);
    } else if (value instanceof DoubleValue) {
        return new DecimalType(((DoubleValue) value).getValue());
    } else if (value instanceof IntegerValue) {
        return new IntegerType(((IntegerValue) value).getValue());
    } else if (value instanceof ReferenceValue) {
        ReferenceValue rv = (ReferenceValue) value;
        Reference ref = new Reference();
        String resourceType = rv.getResourceType();
        String resourceId = rv.getResourceId();
        boolean unique = uniqueIds.contains(resourceType + "<" + resourceId + ">");
        CodeInfo codeInfo = terminologyService.lookup(fhirPackage, resourceType);
        if (codeInfo.isProfile()) {
            resourceType = StringUtils.getLastPath(codeInfo.getBaseResource());
        }
        if (unique) {
            // This is a reference to a unique resource - no need to append row id
            if (fhirResourceMap.containsKey(resourceId)) {
                ref.setReference("/" + resourceType + "/" + resourceId);
            } else {
                log.debug("Did not find resource " + resourceType + "/" + resourceId);
            }
        } else {
            if (fhirResourceMap.containsKey(resourceId + "-" + recordId)) {
                ref.setReference("/" + resourceType + "/" + resourceId + "-" + recordId);
            } else {
                log.debug("Did not find resource " + resourceType + "/" + resourceId + "-" + recordId);
            }
        }
        return ref;
    } else if (value instanceof StringValue) {
        if (fhirType.equals(StringType.class)) {
            return new StringType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(MarkdownType.class)) {
            return new MarkdownType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(IdType.class)) {
            return new IdType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(UriType.class)) {
            return new UriType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(OidType.class)) {
            return new OidType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(UuidType.class)) {
            return new UuidType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(CanonicalType.class)) {
            return new CanonicalType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(UrlType.class)) {
            return new UrlType(((StringValue) value).getStringValue());
        } else {
            throw new TransformationException("Got StringValue for FHIR type " + fhirType.getName() + ". This should not happen!");
        }
    } else if (value instanceof CodeSelectedValue) {
        CodeSelectedValue csv = (CodeSelectedValue) value;
        String fieldId = csv.getFieldId();
        Mapping m = getSelectedMapping(fieldId, vertex);
        if (m == null) {
            throw new TransformationException("Mapping for field " + fieldId + " is required but was not found.");
        }
        return getTarget(m).getCodeElement();
    } else if (value instanceof ConceptSelectedValue) {
        ConceptSelectedValue csv = (ConceptSelectedValue) value;
        String fieldId = csv.getFieldId();
        Mapping m = getSelectedMapping(fieldId, vertex);
        if (m == null) {
            throw new TransformationException("Mapping for field " + fieldId + " is required but was not found.");
        }
        if (fhirType.isAssignableFrom(Coding.class)) {
            return getTarget(m);
        } else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
            return new CodeableConcept().addCoding(getTarget(m));
        } else {
            throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT_SELECTED.");
        }
    } else if (value instanceof ConceptValue) {
        // Ontoserver REDCap plugin format: 74400008|Appendicitis|http://snomed.info/sct
        ConceptValue cv = (ConceptValue) value;
        String fieldId = cv.getFieldId();
        Mapping m = getMapping(fieldId);
        if (m != null) {
            if (fhirType.isAssignableFrom(Coding.class)) {
                return getTarget(m);
            } else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
                return new CodeableConcept().addCoding(getTarget(m));
            } else {
                throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT.");
            }
        } else {
            au.csiro.redmatch.model.Field field = doc.getSchema().getField(fieldId);
            Coding c = field.getCoding(vertex);
            if (c != null) {
                if (fhirType.isAssignableFrom(Coding.class)) {
                    return c;
                } else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
                    return new CodeableConcept().addCoding(c);
                } else {
                    throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT.");
                }
            }
        }
        throw new TransformationException("Could not get concept for field " + fieldId + ".");
    } else if (value instanceof FieldValue) {
        FieldValue fv = (FieldValue) value;
        String fieldId = fv.getFieldId();
        FieldValue.DatePrecision pr = fv.getDatePrecision();
        au.csiro.redmatch.model.Field field = doc.getSchema().getField(fieldId);
        return field.getValue(vertex, fhirType, pr);
    } else {
        throw new TransformationException("Unable to get VALUE for " + value);
    }
}
Also used : CodeInfo(au.csiro.redmatch.terminology.CodeInfo) Matcher(java.util.regex.Matcher) Field(java.lang.reflect.Field) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) Pattern(java.util.regex.Pattern) JsonElement(com.google.gson.JsonElement)

Example 58 with DecimalType

use of org.hl7.fhir.dstu2016may.model.DecimalType in project synthea by synthetichealth.

the class FhirR4 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 BundleEntryComponent basicInfo(Person person, Bundle bundle, long stopTime) {
    Patient patientResource = new Patient();
    patientResource.addIdentifier().setSystem(SYNTHEA_IDENTIFIER).setValue((String) person.attributes.get(Person.ID));
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient");
        patientResource.setMeta(meta);
    }
    Code mrnCode = new Code("http://terminology.hl7.org/CodeSystem/v2-0203", "MR", "Medical Record Number");
    patientResource.addIdentifier().setType(mapCodeToCodeableConcept(mrnCode, "http://terminology.hl7.org/CodeSystem/v2-0203")).setSystem("http://hospital.smarthealthit.org").setValue((String) person.attributes.get(Person.ID));
    Code ssnCode = new Code("http://terminology.hl7.org/CodeSystem/v2-0203", "SS", "Social Security Number");
    patientResource.addIdentifier().setType(mapCodeToCodeableConcept(ssnCode, "http://terminology.hl7.org/CodeSystem/v2-0203")).setSystem("http://hl7.org/fhir/sid/us-ssn").setValue((String) person.attributes.get(Person.IDENTIFIER_SSN));
    if (person.attributes.get(Person.IDENTIFIER_DRIVERS) != null) {
        Code driversCode = new Code("http://terminology.hl7.org/CodeSystem/v2-0203", "DL", "Driver's License");
        patientResource.addIdentifier().setType(mapCodeToCodeableConcept(driversCode, "http://terminology.hl7.org/CodeSystem/v2-0203")).setSystem("urn:oid:2.16.840.1.113883.4.3.25").setValue((String) person.attributes.get(Person.IDENTIFIER_DRIVERS));
    }
    if (person.attributes.get(Person.IDENTIFIER_PASSPORT) != null) {
        Code passportCode = new Code("http://terminology.hl7.org/CodeSystem/v2-0203", "PPN", "Passport Number");
        patientResource.addIdentifier().setType(mapCodeToCodeableConcept(passportCode, "http://terminology.hl7.org/CodeSystem/v2-0203")).setSystem(SHR_EXT + "passportNumber").setValue((String) person.attributes.get(Person.IDENTIFIER_PASSPORT));
    }
    if (person.attributes.get(Person.CONTACT_EMAIL) != null) {
        ContactComponent contact = new ContactComponent();
        HumanName contactName = new HumanName();
        contactName.setUse(HumanName.NameUse.OFFICIAL);
        contactName.addGiven((String) person.attributes.get(Person.CONTACT_GIVEN_NAME));
        contactName.setFamily((String) person.attributes.get(Person.CONTACT_FAMILY_NAME));
        contact.setName(contactName);
        contact.addTelecom().setSystem(ContactPointSystem.EMAIL).setUse(ContactPointUse.HOME).setValue((String) person.attributes.get(Person.CONTACT_EMAIL));
        patientResource.addContact(contact);
    }
    if (USE_US_CORE_IG) {
        // We do not yet account for mixed race
        Extension raceExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-race");
        String race = (String) person.attributes.get(Person.RACE);
        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 raceNum = (String) raceEthnicityCodes.get(race);
        Extension raceCodingExtension = new Extension("ombCategory");
        Coding raceCoding = new Coding();
        if (raceDisplay.equals("Other")) {
            raceCoding.setSystem("http://terminology.hl7.org/CodeSystem/v3-NullFlavor");
            raceCoding.setCode("UNK");
            raceCoding.setDisplay("Unknown");
        } else {
            raceCoding.setSystem("urn:oid:2.16.840.1.113883.6.238");
            raceCoding.setCode(raceNum);
            raceCoding.setDisplay(raceDisplay);
        }
        raceCodingExtension.setValue(raceCoding);
        raceExtension.addExtension(raceCodingExtension);
        Extension raceTextExtension = new Extension("text");
        raceTextExtension.setValue(new StringType(raceDisplay));
        raceExtension.addExtension(raceTextExtension);
        patientResource.addExtension(raceExtension);
        // We do not yet account for mixed ethnicity
        Extension ethnicityExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity");
        String ethnicity = (String) person.attributes.get(Person.ETHNICITY);
        String ethnicityDisplay;
        if (ethnicity.equals("hispanic")) {
            ethnicity = "hispanic";
            ethnicityDisplay = "Hispanic or Latino";
        } else {
            ethnicity = "nonhispanic";
            ethnicityDisplay = "Not Hispanic or Latino";
        }
        String ethnicityNum = (String) raceEthnicityCodes.get(ethnicity);
        Extension ethnicityCodingExtension = new Extension("ombCategory");
        Coding ethnicityCoding = new Coding();
        ethnicityCoding.setSystem("urn:oid:2.16.840.1.113883.6.238");
        ethnicityCoding.setCode(ethnicityNum);
        ethnicityCoding.setDisplay(ethnicityDisplay);
        ethnicityCodingExtension.setValue(ethnicityCoding);
        ethnicityExtension.addExtension(ethnicityCodingExtension);
        Extension ethnicityTextExtension = new Extension("text");
        ethnicityTextExtension.setValue(new StringType(ethnicityDisplay));
        ethnicityExtension.addExtension(ethnicityTextExtension);
        patientResource.addExtension(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<PatientCommunicationComponent> communication = new ArrayList<PatientCommunicationComponent>();
    communication.add(new PatientCommunicationComponent(mapCodeToCodeableConcept(languageCode, (String) languageMap.get("system"))));
    patientResource.setCommunication(communication);
    HumanName name = patientResource.addName();
    name.setUse(HumanName.NameUse.OFFICIAL);
    name.addGiven((String) person.attributes.get(Person.FIRST_NAME));
    name.setFamily((String) person.attributes.get(Person.LAST_NAME));
    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) {
        HumanName maidenName = patientResource.addName();
        maidenName.setUse(HumanName.NameUse.MAIDEN);
        maidenName.addGiven((String) person.attributes.get(Person.FIRST_NAME));
        maidenName.setFamily((String) person.attributes.get(Person.MAIDEN_NAME));
        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));
        }
    }
    Extension mothersMaidenNameExtension = new Extension("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");
    String mothersMaidenName = (String) person.attributes.get(Person.NAME_MOTHER);
    mothersMaidenNameExtension.setValue(new StringType(mothersMaidenName));
    patientResource.addExtension(mothersMaidenNameExtension);
    long birthdate = (long) person.attributes.get(Person.BIRTHDATE);
    patientResource.setBirthDate(new Date(birthdate));
    Extension birthSexExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex");
    if (person.attributes.get(Person.GENDER).equals("M")) {
        patientResource.setGender(AdministrativeGender.MALE);
        birthSexExtension.setValue(new CodeType("M"));
    } else if (person.attributes.get(Person.GENDER).equals("F")) {
        patientResource.setGender(AdministrativeGender.FEMALE);
        birthSexExtension.setValue(new CodeType("F"));
    } else if (person.attributes.get(Person.GENDER).equals("UNK")) {
        patientResource.setGender(AdministrativeGender.UNKNOWN);
    }
    if (USE_US_CORE_IG) {
        patientResource.addExtension(birthSexExtension);
    }
    String state = (String) person.attributes.get(Person.STATE);
    if (USE_US_CORE_IG) {
        state = Location.getAbbreviation(state);
    }
    Address 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);
    }
    Address birthplace = new Address();
    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));
    Extension birthplaceExtension = new Extension("http://hl7.org/fhir/StructureDefinition/patient-birthPlace");
    birthplaceExtension.setValue(birthplace);
    patientResource.addExtension(birthplaceExtension);
    if (person.attributes.get(Person.MULTIPLE_BIRTH_STATUS) != null) {
        patientResource.setMultipleBirth(new IntegerType((int) person.attributes.get(Person.MULTIPLE_BIRTH_STATUS)));
    } else {
        patientResource.setMultipleBirth(new BooleanType(false));
    }
    patientResource.addTelecom().setSystem(ContactPointSystem.PHONE).setUse(ContactPointUse.HOME).setValue((String) person.attributes.get(Person.TELECOM));
    String maritalStatus = ((String) person.attributes.get(Person.MARITAL_STATUS));
    if (maritalStatus != null) {
        Code maritalStatusCode = new Code("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus", maritalStatus, maritalStatus);
        patientResource.setMaritalStatus(mapCodeToCodeableConcept(maritalStatusCode, "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus"));
    } else {
        Code maritalStatusCode = new Code("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus", "S", "Never Married");
        patientResource.setMaritalStatus(mapCodeToCodeableConcept(maritalStatusCode, "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus"));
    }
    Point2D.Double coord = person.getLonLat();
    if (coord != null) {
        Extension geolocation = addrResource.addExtension();
        geolocation.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
        geolocation.addExtension("latitude", new DecimalType(coord.getY()));
        geolocation.addExtension("longitude", new DecimalType(coord.getX()));
    }
    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.getSeed() + "  Population seed: " + person.populationSeed;
    patientResource.setText(new Narrative().setStatus(NarrativeStatus.GENERATED).setDiv(new XhtmlNode(NodeType.Element).setValue(generatedBySynthea)));
    if (USE_SHR_EXTENSIONS) {
        patientResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-entity-Patient"));
        // Patient profile requires race, ethnicity, birthsex,
        // MothersMaidenName, FathersName, Person-extension
        patientResource.addExtension().setUrl(SHR_EXT + "shr-actor-FictionalPerson-extension").setValue(new BooleanType(true));
        String fathersName = (String) person.attributes.get(Person.NAME_FATHER);
        Extension fathersNameExtension = new Extension(SHR_EXT + "shr-entity-FathersName-extension", new HumanName().setText(fathersName));
        patientResource.addExtension(fathersNameExtension);
        String ssn = (String) person.attributes.get(Person.IDENTIFIER_SSN);
        Extension ssnExtension = new Extension(SHR_EXT + "shr-demographics-SocialSecurityNumber-extension", new StringType(ssn));
        patientResource.addExtension(ssnExtension);
    }
    // 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) {
        Extension dalyExtension = new Extension(SYNTHEA_EXT + "disability-adjusted-life-years");
        DecimalType daly = new DecimalType(dalyValue);
        dalyExtension.setValue(daly);
        patientResource.addExtension(dalyExtension);
        Extension qalyExtension = new Extension(SYNTHEA_EXT + "quality-adjusted-life-years");
        DecimalType qaly = new DecimalType(qalyValue);
        qalyExtension.setValue(qaly);
        patientResource.addExtension(qalyExtension);
    }
    return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Address(org.hl7.fhir.r4.model.Address) StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.r4.model.HumanName) Coding(org.hl7.fhir.r4.model.Coding) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) Point2D(java.awt.geom.Point2D) Narrative(org.hl7.fhir.r4.model.Narrative) ContactComponent(org.hl7.fhir.r4.model.Patient.ContactComponent) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.r4.model.Extension) IntegerType(org.hl7.fhir.r4.model.IntegerType) CodeType(org.hl7.fhir.r4.model.CodeType) DecimalType(org.hl7.fhir.r4.model.DecimalType) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 59 with DecimalType

use of org.hl7.fhir.dstu2016may.model.DecimalType in project synthea by synthetichealth.

the class FhirStu3 method provider.

/**
 * Map the Provider into a FHIR Organization resource, and add it to the given Bundle.
 * @param bundle The Bundle to add to
 * @param provider The Provider
 * @return The added Entry
 */
protected static BundleEntryComponent provider(Bundle bundle, Provider provider) {
    org.hl7.fhir.dstu3.model.Organization organizationResource = new org.hl7.fhir.dstu3.model.Organization();
    List<CodeableConcept> organizationType = new ArrayList<CodeableConcept>();
    organizationType.add(mapCodeToCodeableConcept(new Code("http://hl7.org/fhir/organization-type", "prov", "Healthcare Provider"), "http://hl7.org/fhir/organization-type"));
    organizationResource.addIdentifier().setSystem("https://github.com/synthetichealth/synthea").setValue((String) provider.getResourceID());
    organizationResource.setId(provider.getResourceID());
    organizationResource.setName(provider.name);
    organizationResource.setType(organizationType);
    Address address = new Address().addLine(provider.address).setCity(provider.city).setPostalCode(provider.zip).setState(provider.state);
    if (COUNTRY_CODE != null) {
        address.setCountry(COUNTRY_CODE);
    }
    organizationResource.addAddress(address);
    Point2D.Double coord = provider.getLonLat();
    if (coord != null) {
        Extension geolocation = address.addExtension();
        geolocation.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
        geolocation.addExtension("latitude", new DecimalType(coord.getY()));
        geolocation.addExtension("longitude", new DecimalType(coord.getX()));
    }
    if (provider.phone != null && !provider.phone.isEmpty()) {
        ContactPoint contactPoint = new ContactPoint().setSystem(ContactPointSystem.PHONE).setValue(provider.phone);
        organizationResource.addTelecom(contactPoint);
    }
    if (USE_SHR_EXTENSIONS) {
        organizationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-entity-Organization"));
        // required fields for this profile are identifier, type, address, and contact
        organizationResource.addIdentifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + provider.getResourceID());
        organizationResource.addContact().setName(new HumanName().setText("Synthetic Provider"));
    }
    return newEntry(bundle, organizationResource, provider.getResourceID());
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Organization(org.hl7.fhir.dstu3.model.Organization) Address(org.hl7.fhir.dstu3.model.Address) ArrayList(java.util.ArrayList) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Extension(org.hl7.fhir.dstu3.model.Extension) Organization(org.hl7.fhir.dstu3.model.Organization) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) HumanName(org.hl7.fhir.dstu3.model.HumanName) Point2D(java.awt.geom.Point2D) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 60 with DecimalType

use of org.hl7.fhir.dstu2016may.model.DecimalType in project synthea by synthetichealth.

the class FhirStu3 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 BundleEntryComponent 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));
    Code mrnCode = new Code("http://hl7.org/fhir/v2/0203", "MR", "Medical Record Number");
    patientResource.addIdentifier().setType(mapCodeToCodeableConcept(mrnCode, "http://hl7.org/fhir/v2/0203")).setSystem("http://hospital.smarthealthit.org").setValue((String) person.attributes.get(Person.ID));
    Code ssnCode = new Code("http://hl7.org/fhir/identifier-type", "SB", "Social Security Number");
    patientResource.addIdentifier().setType(mapCodeToCodeableConcept(ssnCode, "http://hl7.org/fhir/identifier-type")).setSystem("http://hl7.org/fhir/sid/us-ssn").setValue((String) person.attributes.get(Person.IDENTIFIER_SSN));
    if (person.attributes.get(Person.IDENTIFIER_DRIVERS) != null) {
        Code driversCode = new Code("http://hl7.org/fhir/v2/0203", "DL", "Driver's License");
        patientResource.addIdentifier().setType(mapCodeToCodeableConcept(driversCode, "http://hl7.org/fhir/v2/0203")).setSystem("urn:oid:2.16.840.1.113883.4.3.25").setValue((String) person.attributes.get(Person.IDENTIFIER_DRIVERS));
    }
    if (person.attributes.get(Person.IDENTIFIER_PASSPORT) != null) {
        Code passportCode = new Code("http://hl7.org/fhir/v2/0203", "PPN", "Passport Number");
        patientResource.addIdentifier().setType(mapCodeToCodeableConcept(passportCode, "http://hl7.org/fhir/v2/0203")).setSystem(SHR_EXT + "passportNumber").setValue((String) person.attributes.get(Person.IDENTIFIER_PASSPORT));
    }
    if (person.attributes.get(Person.CONTACT_EMAIL) != null) {
        ContactComponent contact = new ContactComponent();
        HumanName contactName = new HumanName();
        contactName.setUse(HumanName.NameUse.OFFICIAL);
        contactName.addGiven((String) person.attributes.get(Person.CONTACT_GIVEN_NAME));
        contactName.setFamily((String) person.attributes.get(Person.CONTACT_FAMILY_NAME));
        contact.setName(contactName);
        contact.addTelecom().setSystem(ContactPointSystem.EMAIL).setUse(ContactPointUse.HOME).setValue((String) person.attributes.get(Person.CONTACT_EMAIL));
        patientResource.addContact(contact);
    }
    // We do not yet account for mixed race
    Extension raceExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-race");
    String race = (String) person.attributes.get(Person.RACE);
    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 raceNum = (String) raceEthnicityCodes.get(race);
    Extension raceCodingExtension = new Extension("ombCategory");
    Coding raceCoding = new Coding();
    if (raceDisplay.equals("Other")) {
        raceCoding.setSystem("http://hl7.org/fhir/v3/NullFlavor");
        raceCoding.setCode("UNK");
        raceCoding.setDisplay("Unknown");
    } else {
        raceCoding.setSystem("urn:oid:2.16.840.1.113883.6.238");
        raceCoding.setCode(raceNum);
        raceCoding.setDisplay(raceDisplay);
    }
    raceCodingExtension.setValue(raceCoding);
    raceExtension.addExtension(raceCodingExtension);
    Extension raceTextExtension = new Extension("text");
    raceTextExtension.setValue(new StringType(raceDisplay));
    raceExtension.addExtension(raceTextExtension);
    patientResource.addExtension(raceExtension);
    // We do not yet account for mixed ethnicity
    Extension ethnicityExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity");
    String ethnicity = (String) person.attributes.get(Person.ETHNICITY);
    String ethnicityDisplay;
    if (ethnicity.equals("hispanic")) {
        ethnicity = "hispanic";
        ethnicityDisplay = "Hispanic or Latino";
    } else {
        ethnicity = "nonhispanic";
        ethnicityDisplay = "Not Hispanic or Latino";
    }
    String ethnicityNum = (String) raceEthnicityCodes.get(ethnicity);
    Extension ethnicityCodingExtension = new Extension("ombCategory");
    Coding ethnicityCoding = new Coding();
    ethnicityCoding.setSystem("urn:oid:2.16.840.1.113883.6.238");
    ethnicityCoding.setCode(ethnicityNum);
    ethnicityCoding.setDisplay(ethnicityDisplay);
    ethnicityCodingExtension.setValue(ethnicityCoding);
    ethnicityExtension.addExtension(ethnicityCodingExtension);
    Extension ethnicityTextExtension = new Extension("text");
    ethnicityTextExtension.setValue(new StringType(ethnicityDisplay));
    ethnicityExtension.addExtension(ethnicityTextExtension);
    patientResource.addExtension(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<PatientCommunicationComponent> communication = new ArrayList<PatientCommunicationComponent>();
    communication.add(new PatientCommunicationComponent(mapCodeToCodeableConcept(languageCode, (String) languageMap.get("system"))));
    patientResource.setCommunication(communication);
    HumanName name = patientResource.addName();
    name.setUse(HumanName.NameUse.OFFICIAL);
    name.addGiven((String) person.attributes.get(Person.FIRST_NAME));
    name.setFamily((String) person.attributes.get(Person.LAST_NAME));
    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) {
        HumanName maidenName = patientResource.addName();
        maidenName.setUse(HumanName.NameUse.MAIDEN);
        maidenName.addGiven((String) person.attributes.get(Person.FIRST_NAME));
        maidenName.setFamily((String) person.attributes.get(Person.MAIDEN_NAME));
        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));
        }
    }
    Extension mothersMaidenNameExtension = new Extension("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");
    String mothersMaidenName = (String) person.attributes.get(Person.NAME_MOTHER);
    mothersMaidenNameExtension.setValue(new StringType(mothersMaidenName));
    patientResource.addExtension(mothersMaidenNameExtension);
    long birthdate = (long) person.attributes.get(Person.BIRTHDATE);
    patientResource.setBirthDate(new Date(birthdate));
    Extension birthSexExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex");
    if (person.attributes.get(Person.GENDER).equals("M")) {
        patientResource.setGender(AdministrativeGender.MALE);
        birthSexExtension.setValue(new CodeType("M"));
    } else if (person.attributes.get(Person.GENDER).equals("F")) {
        patientResource.setGender(AdministrativeGender.FEMALE);
        birthSexExtension.setValue(new CodeType("F"));
    }
    patientResource.addExtension(birthSexExtension);
    String state = (String) person.attributes.get(Person.STATE);
    Address 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);
    }
    Address birthplace = new Address();
    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));
    Extension birthplaceExtension = new Extension("http://hl7.org/fhir/StructureDefinition/birthPlace");
    birthplaceExtension.setValue(birthplace);
    patientResource.addExtension(birthplaceExtension);
    if (person.attributes.get(Person.MULTIPLE_BIRTH_STATUS) != null) {
        patientResource.setMultipleBirth(new IntegerType((int) person.attributes.get(Person.MULTIPLE_BIRTH_STATUS)));
    } else {
        patientResource.setMultipleBirth(new BooleanType(false));
    }
    patientResource.addTelecom().setSystem(ContactPoint.ContactPointSystem.PHONE).setUse(ContactPoint.ContactPointUse.HOME).setValue((String) person.attributes.get(Person.TELECOM));
    String maritalStatus = ((String) person.attributes.get(Person.MARITAL_STATUS));
    if (maritalStatus != null) {
        Code maritalStatusCode = new Code("http://hl7.org/fhir/v3/MaritalStatus", maritalStatus, maritalStatus);
        patientResource.setMaritalStatus(mapCodeToCodeableConcept(maritalStatusCode, "http://hl7.org/fhir/v3/MaritalStatus"));
    } else {
        Code maritalStatusCode = new Code("http://hl7.org/fhir/v3/MaritalStatus", "S", "Never Married");
        patientResource.setMaritalStatus(mapCodeToCodeableConcept(maritalStatusCode, "http://hl7.org/fhir/v3/MaritalStatus"));
    }
    Point2D.Double coord = person.getLonLat();
    if (coord != null) {
        Extension geolocation = addrResource.addExtension();
        geolocation.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
        geolocation.addExtension("latitude", new DecimalType(coord.getY()));
        geolocation.addExtension("longitude", new DecimalType(coord.getX()));
    }
    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.getSeed() + "  Population seed: " + person.populationSeed;
    patientResource.setText(new Narrative().setStatus(NarrativeStatus.GENERATED).setDiv(new XhtmlNode(NodeType.Element).setValue(generatedBySynthea)));
    if (USE_SHR_EXTENSIONS) {
        patientResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-entity-Patient"));
        // Patient profile requires race, ethnicity, birthsex,
        // MothersMaidenName, FathersName, Person-extension
        patientResource.addExtension().setUrl(SHR_EXT + "shr-actor-FictionalPerson-extension").setValue(new BooleanType(true));
        String fathersName = (String) person.attributes.get(Person.NAME_FATHER);
        Extension fathersNameExtension = new Extension(SHR_EXT + "shr-entity-FathersName-extension", new HumanName().setText(fathersName));
        patientResource.addExtension(fathersNameExtension);
        String ssn = (String) person.attributes.get(Person.IDENTIFIER_SSN);
        Extension ssnExtension = new Extension(SHR_EXT + "shr-demographics-SocialSecurityNumber-extension", new StringType(ssn));
        patientResource.addExtension(ssnExtension);
        Basic personResource = new Basic();
        // the only required field on this patient resource is code
        Coding fixedCode = new Coding("http://standardhealthrecord.org/fhir/basic-resource-type", "shr-entity-Person", "shr-entity-Person");
        personResource.setCode(new CodeableConcept().addCoding(fixedCode));
        Meta personMeta = new Meta();
        personMeta.addProfile(SHR_EXT + "shr-entity-Person");
        personResource.setMeta(personMeta);
        BundleEntryComponent personEntry = newEntry(person, bundle, personResource);
        patientResource.addExtension().setUrl(SHR_EXT + "shr-entity-Person-extension").setValue(new Reference(personEntry.getFullUrl()));
    }
    // 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) {
        Extension dalyExtension = new Extension(SYNTHEA_EXT + "disability-adjusted-life-years");
        DecimalType daly = new DecimalType(dalyValue);
        dalyExtension.setValue(daly);
        patientResource.addExtension(dalyExtension);
        Extension qalyExtension = new Extension(SYNTHEA_EXT + "quality-adjusted-life-years");
        DecimalType qaly = new DecimalType(qalyValue);
        qalyExtension.setValue(qaly);
        patientResource.addExtension(qalyExtension);
    }
    return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Basic(org.hl7.fhir.dstu3.model.Basic) Address(org.hl7.fhir.dstu3.model.Address) StringType(org.hl7.fhir.dstu3.model.StringType) ArrayList(java.util.ArrayList) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu3.model.HumanName) Coding(org.hl7.fhir.dstu3.model.Coding) PatientCommunicationComponent(org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent) Point2D(java.awt.geom.Point2D) Narrative(org.hl7.fhir.dstu3.model.Narrative) ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Patient(org.hl7.fhir.dstu3.model.Patient) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.dstu3.model.Extension) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) CodeType(org.hl7.fhir.dstu3.model.CodeType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Aggregations

DecimalType (org.hl7.fhir.r4.model.DecimalType)48 Test (org.junit.jupiter.api.Test)47 Coding (org.hl7.fhir.r4.model.Coding)44 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)42 Money (org.hl7.fhir.r4.model.Money)41 BigDecimal (java.math.BigDecimal)40 ArrayList (java.util.ArrayList)38 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)36 BenefitComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent)31 UcumException (org.fhir.ucum.UcumException)29 DecimalType (org.hl7.fhir.r4b.model.DecimalType)22 DecimalType (org.hl7.fhir.r5.model.DecimalType)20 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 Decimal (org.fhir.ucum.Decimal)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)14 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 Pair (org.fhir.ucum.Pair)12 Base (org.hl7.fhir.r4b.model.Base)12 Base (org.hl7.fhir.r5.model.Base)12 AdjudicationComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent)8