Search in sources :

Example 1 with ContactComponent

use of org.hl7.fhir.r4.model.Patient.ContactComponent in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method createContact.

// patientDetailsToMinimalPatient
/**
 * add a set of contact details into the patient record NB these are
 * Contacts (related people etc) not contactpoints (telecoms)
 *
 * @param patient fhirResource object
 */
private void createContact(Patient patient) {
    // relationships
    Patient.ContactComponent contact = new ContactComponent();
    for (String relationship : new String[] { "Emergency contact", "Next of kin", "Daughter" }) {
        CodeableConcept crelationship = new CodeableConcept();
        crelationship.setText(relationship);
        contact.addRelationship(crelationship);
    }
    // contact address
    Address address = new Address();
    address.addLine("Trevelyan Square");
    address.addLine("Boar Ln");
    address.setPostalCode("LS1 6AE");
    address.setType(AddressType.PHYSICAL);
    address.setUse(AddressUse.HOME);
    contact.setAddress(address);
    // gender
    contact.setGender(AdministrativeGender.FEMALE);
    // telecom
    ContactPoint telecom = new ContactPoint();
    telecom.setSystem(ContactPointSystem.PHONE);
    telecom.setUse(ContactPointUse.MOBILE);
    telecom.setValue("07777123123");
    contact.addTelecom(telecom);
    // Name
    HumanName name = new HumanName();
    name.addGiven("Jane");
    name.setFamily("Jackson");
    List<StringType> prefixList = new ArrayList<>();
    prefixList.add(new StringType("Miss"));
    name.setPrefix(prefixList);
    name.setText("JACKSON Jane (Miss)");
    name.setUse(NameUse.OFFICIAL);
    contact.setName(name);
    patient.addContact(contact);
}
Also used : ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent) ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent)

Example 2 with ContactComponent

use of org.hl7.fhir.r4.model.Patient.ContactComponent in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method createPatient.

Patient createPatient(Account account) {
    Patient patient = new Patient();
    patient.setActive(true);
    patient.setId(account.getId());
    Identifier identifier = new Identifier();
    identifier.setValue(account.getId());
    identifier.setSystem(USER_ID_VALUE_NS);
    patient.addIdentifier(identifier);
    Coding coding = new Coding();
    coding.setSystem("source");
    coding.setCode("sage");
    Meta meta = new Meta();
    meta.setTag(ImmutableList.of(coding));
    patient.setMeta(meta);
    HumanName name = new HumanName();
    if (isNotBlank(account.getFirstName())) {
        name.addGiven(account.getFirstName());
    }
    if (isNotBlank(account.getLastName())) {
        name.setFamily(account.getLastName());
    }
    patient.addName(name);
    Map<String, String> atts = account.getAttributes();
    if (isNotBlank(atts.get("gender"))) {
        if ("female".equalsIgnoreCase(atts.get("gender"))) {
            patient.setGender(AdministrativeGender.FEMALE);
        } else if ("male".equalsIgnoreCase(atts.get("gender"))) {
            patient.setGender(AdministrativeGender.MALE);
        } else {
            patient.setGender(AdministrativeGender.OTHER);
        }
    } else {
        patient.setGender(AdministrativeGender.UNKNOWN);
    }
    if (isNotBlank(atts.get("dob"))) {
        LocalDate localDate = LocalDate.parse(atts.get("dob"));
        patient.setBirthDate(localDate.toDate());
    }
    Address address = new Address();
    if (isNotBlank(atts.get("address1"))) {
        address.addLine(atts.get("address1"));
    }
    if (isNotBlank(atts.get("address2"))) {
        address.addLine(atts.get("address2"));
    }
    if (isNotBlank(atts.get("city"))) {
        address.setCity(atts.get("city"));
    }
    if (isNotBlank(atts.get("state"))) {
        address.setState(atts.get("state"));
    } else {
        address.setState("NY");
    }
    if (isNotBlank(atts.get("zip_code"))) {
        address.setPostalCode(atts.get("zip_code"));
    }
    patient.addAddress(address);
    if (isNotBlank(atts.get("home_phone"))) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.PHONE);
        contact.setValue(atts.get("home_phone"));
        patient.addTelecom(contact);
    }
    if (account.getPhone() != null && TRUE.equals(account.getPhoneVerified())) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.SMS);
        contact.setValue(account.getPhone().getNumber());
        patient.addTelecom(contact);
    }
    if (account.getEmail() != null && TRUE.equals(account.getEmailVerified())) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.EMAIL);
        contact.setValue(account.getEmail());
        patient.addTelecom(contact);
    }
    Reference ref = new Reference("CUZUCK");
    ref.setDisplay("COVID Recovery Corps");
    ContactComponent contact = new ContactComponent();
    contact.setOrganization(ref);
    patient.addContact(contact);
    return patient;
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Identifier(org.hl7.fhir.dstu3.model.Identifier) Address(org.hl7.fhir.dstu3.model.Address) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent) Patient(org.hl7.fhir.dstu3.model.Patient) LocalDate(org.joda.time.LocalDate)

Example 3 with ContactComponent

use of org.hl7.fhir.r4.model.Patient.ContactComponent 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.seed + "  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 4 with ContactComponent

use of org.hl7.fhir.r4.model.Patient.ContactComponent in project eCRNow by drajer-health.

the class CdaHeaderGenerator method getPatientDetails.

public static String getPatientDetails(Patient p, LaunchDetails details) {
    StringBuilder patientDetails = new StringBuilder();
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.RECORD_TARGET_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.PATIENT_ROLE_EL_NAME));
    List<Identifier> ids = CdaFhirUtilities.getIdentifierForType(p.getIdentifier(), CdaFhirEnumConstants.FHIR_ID_TYPE_MR);
    Boolean addOnce = true;
    if (ids != null && !ids.isEmpty()) {
        for (Identifier id : ids) {
            if (!StringUtils.isEmpty(id.getSystem()) && !StringUtils.isEmpty(id.getValue())) {
                logger.debug("Found Identifier with Type MR");
                String system = CdaGeneratorUtils.getRootOid(id.getSystem(), details.getAssigningAuthorityId());
                patientDetails.append(CdaGeneratorUtils.getXmlForII(system, id.getValue()));
            } else {
                logger.debug("Using Resource Identifier as id");
                if (addOnce) {
                    patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId()));
                    addOnce = false;
                }
            }
        }
    } else {
        logger.debug("Using Resource Identifier as id");
        patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId()));
    }
    // Add Address.
    patientDetails.append(CdaFhirUtilities.getAddressXml(p.getAddress()));
    // Add Telecom (Phone)
    patientDetails.append(CdaFhirUtilities.getTelecomXml(p.getTelecom(), false));
    // Add Telecom (Email)
    patientDetails.append(CdaFhirUtilities.getEmailXml(p.getTelecom()));
    // Add patient
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.PATIENT_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
    patientDetails.append(CdaFhirUtilities.getNameXml(p.getName()));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
    patientDetails.append(CdaFhirUtilities.getGenderXml(p.getGenderElement().getValue()));
    patientDetails.append(CdaFhirUtilities.getDateTypeXml(p.getBirthDateElement(), CdaGeneratorConstants.BIRTH_TIME_EL_NAME));
    if (p.getDeceased() == null || (p.getDeceased() != null && p.getDeceased().isEmpty())) {
        patientDetails.append(CdaGeneratorUtils.getXmlForValue(CdaGeneratorConstants.SDTC_DECEASED_IND, CdaGeneratorConstants.CCDA_FALSE));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForValue(CdaGeneratorConstants.SDTC_DECEASED_IND, CdaGeneratorConstants.CCDA_TRUE));
        if (p.getDeceased() instanceof DateTimeType) {
            DateTimeType d = (DateTimeType) p.getDeceased();
            patientDetails.append(CdaFhirUtilities.getDateTimeTypeXml(d, CdaGeneratorConstants.SDTC_DECEASED_TIME));
        } else {
            patientDetails.append(CdaGeneratorUtils.getXmlForNullEffectiveTime(CdaGeneratorConstants.SDTC_DECEASED_TIME, CdaGeneratorConstants.NF_NI));
        }
    }
    Coding race = CdaFhirUtilities.getCodingExtension(p.getExtension(), CdaGeneratorConstants.FHIR_USCORE_RACE_EXT_URL, CdaGeneratorConstants.OMB_RACE_CATEGORY_URL);
    if (race != null && race.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.RACE_CODE_EL_NAME, race.getCode(), CdaGeneratorConstants.RACE_CODE_SYSTEM, CdaGeneratorConstants.RACE_CODE_SYSTEM_NAME, race.getDisplay()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.RACE_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    Coding ethnicity = CdaFhirUtilities.getCodingExtension(p.getExtension(), CdaGeneratorConstants.FHIR_USCORE_ETHNICITY_EXT_URL, CdaGeneratorConstants.OMB_RACE_CATEGORY_URL);
    if (ethnicity != null && ethnicity.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.ETHNIC_CODE_EL_NAME, ethnicity.getCode(), CdaGeneratorConstants.RACE_CODE_SYSTEM, CdaGeneratorConstants.RACE_CODE_SYSTEM_NAME, ethnicity.getDisplay()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.ETHNIC_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    // Adding Guardian
    if (p.getContact() != null && !p.getContact().isEmpty()) {
        ContactComponent guardianContact = CdaFhirUtilities.getGuardianContact(p.getContact());
        if (guardianContact != null) {
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_EL_NAME));
            // Add address if found
            if (guardianContact.getAddress() != null) {
                logger.debug("Adding Address for Guardian");
                List<Address> addrs = new ArrayList<>();
                addrs.add(guardianContact.getAddress());
                patientDetails.append(CdaFhirUtilities.getAddressXml(addrs));
            }
            // Add Telecom
            patientDetails.append(CdaFhirUtilities.getTelecomXml(guardianContact.getTelecom(), false));
            patientDetails.append(CdaFhirUtilities.getEmailXml(guardianContact.getTelecom()));
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_PERSON_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
            List<HumanName> names = new ArrayList<>();
            names.add(guardianContact.getName());
            patientDetails.append(CdaFhirUtilities.getNameXml(names));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.GUARDIAN_PERSON_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.GUARDIAN_EL_NAME));
        }
    }
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.LANGUAGE_COMM_EL_NAME));
    Coding language = CdaFhirUtilities.getLanguageForCodeSystem(p.getCommunication(), CdaGeneratorConstants.FHIR_LANGUAGE_CODESYSTEM_URL);
    if (language != null && language.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.LANGUAGE_CODE_EL_NAME, language.getCode()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.LANGUAGE_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.LANGUAGE_COMM_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.PATIENT_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.PATIENT_ROLE_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.RECORD_TARGET_EL_NAME));
    return patientDetails.toString();
}
Also used : Address(org.hl7.fhir.r4.model.Address) ArrayList(java.util.ArrayList) HumanName(org.hl7.fhir.r4.model.HumanName) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) ContactComponent(org.hl7.fhir.r4.model.Patient.ContactComponent)

Example 5 with ContactComponent

use of org.hl7.fhir.r4.model.Patient.ContactComponent 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.seed + "  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

Patient (org.hl7.fhir.dstu3.model.Patient)4 ArrayList (java.util.ArrayList)3 ContactComponent (org.hl7.fhir.dstu3.model.Patient.ContactComponent)3 Reference (org.hl7.fhir.dstu3.model.Reference)3 Point2D (java.awt.geom.Point2D)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Address (org.hl7.fhir.dstu3.model.Address)2 Coding (org.hl7.fhir.dstu3.model.Coding)2 HumanName (org.hl7.fhir.dstu3.model.HumanName)2 Meta (org.hl7.fhir.dstu3.model.Meta)2 Address (org.hl7.fhir.r4.model.Address)2 Coding (org.hl7.fhir.r4.model.Coding)2 HumanName (org.hl7.fhir.r4.model.HumanName)2 ContactComponent (org.hl7.fhir.r4.model.Patient.ContactComponent)2 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)2 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)2 Basic (org.hl7.fhir.dstu3.model.Basic)1