Search in sources :

Example 76 with MR

use of org.hl7.fhir.r4.model.codesystems.V3Hl7PublishingDomain.MR in project org.hl7.fhir.core by hapifhir.

the class MeasureValidator method validateMeasureReportGroups.

private void validateMeasureReportGroups(ValidatorHostContext hostContext, MeasureContext m, List<ValidationMessage> errors, Element mr, NodeStack stack, boolean inProgress) {
    if (m.groups().size() == 0) {
        // only validate the report groups if the measure has groups.
        return;
    }
    List<MeasureGroupComponent> groups = new ArrayList<MeasureGroupComponent>();
    List<Element> glist = mr.getChildrenByName("group");
    if (glist.size() == 1 && m.groups().size() == 1) {
        // if there's only one group, it can be ((and usually is) anonymous)
        // but we still check that the code, if both have one, is consistent.
        Element mrg = glist.get(0);
        NodeStack ns = stack.push(mrg, 0, mrg.getProperty().getDefinition(), mrg.getProperty().getDefinition());
        if (m.groups().get(0).hasCode() && mrg.hasChild("code")) {
            CodeableConcept cc = ObjectConverter.readAsCodeableConcept(mrg.getNamedChild("code"));
            if (rule(errors, IssueType.BUSINESSRULE, mrg.line(), mrg.col(), ns.getLiteralPath(), hasUseableCode(cc), I18nConstants.MEASURE_MR_GRP_NO_USABLE_CODE)) {
                rule(errors, IssueType.BUSINESSRULE, mrg.line(), mrg.col(), ns.getLiteralPath(), cc.matches(m.groups().get(0).getCode()), I18nConstants.MEASURE_MR_GRP_NO_WRONG_CODE, DataRenderer.display(context, cc), DataRenderer.display(context, m.groups().get(0).getCode()));
            }
        }
        validateMeasureReportGroup(hostContext, m, m.groups().get(0), errors, mrg, ns, inProgress);
    } else {
        int i = 0;
        for (Element mrg : glist) {
            NodeStack ns = stack.push(mrg, i, mrg.getProperty().getDefinition(), mrg.getProperty().getDefinition());
            CodeableConcept cc = ObjectConverter.readAsCodeableConcept(mrg.getNamedChild("code"));
            if (rule(errors, IssueType.BUSINESSRULE, mrg.line(), mrg.col(), ns.getLiteralPath(), cc != null, I18nConstants.MEASURE_MR_GRP_NO_CODE)) {
                MeasureGroupComponent mg = getGroupForCode(cc, m.measure());
                if (rule(errors, IssueType.BUSINESSRULE, mrg.line(), mrg.col(), ns.getLiteralPath(), mg != null, I18nConstants.MEASURE_MR_GRP_UNK_CODE)) {
                    if (rule(errors, IssueType.BUSINESSRULE, mrg.line(), mrg.col(), ns.getLiteralPath(), !groups.contains(mg), I18nConstants.MEASURE_MR_GRP_DUPL_CODE)) {
                        groups.add(mg);
                        validateMeasureReportGroup(hostContext, m, mg, errors, mrg, ns, inProgress);
                    }
                }
            }
            i++;
        }
        boolean dataCollection = isDataCollection(mr);
        for (MeasureGroupComponent mg : m.groups()) {
            if (!groups.contains(mg)) {
                rule(errors, IssueType.BUSINESSRULE, mr.line(), mr.col(), stack.getLiteralPath(), groups.contains(mg) || dataCollection, I18nConstants.MEASURE_MR_GRP_MISSING_BY_CODE, DataRenderer.display(context, mg.getCode()));
            }
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) MeasureGroupComponent(org.hl7.fhir.r5.model.Measure.MeasureGroupComponent) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 77 with MR

use of org.hl7.fhir.r4.model.codesystems.V3Hl7PublishingDomain.MR in project org.hl7.fhir.core by hapifhir.

the class ValidationTests method test.

@SuppressWarnings("deprecation")
@Test
public void test() throws Exception {
    CacheVerificationLogger logger = new CacheVerificationLogger();
    long setup = System.nanoTime();
    this.name = name;
    System.out.println("---- " + name + " ----------------------------------------------------------------");
    System.out.println("** Core: ");
    String txLog = null;
    if (content.has("txLog")) {
        txLog = content.get("txLog").getAsString();
    }
    version = "5.0";
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    if (content.has("version")) {
        version = content.get("version").getAsString();
    }
    version = VersionUtilities.getMajMin(version);
    if (!ve.containsKey(version)) {
        if (version.startsWith("5.0"))
            ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r5.core#4.5.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R5, true, "4.5.0"));
        else if (version.startsWith("4.3"))
            ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4b.core#4.3.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4B, true, "4.3.0"));
        else if (version.startsWith("4.0"))
            ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r4.core#4.0.1", ValidationEngineTests.DEF_TX, txLog, FhirPublication.R4, true, "4.0.1"));
        else if (version.startsWith("3.0"))
            ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r3.core#3.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.STU3, true, "3.0.2"));
        else if (version.startsWith("1.4"))
            ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2b.core#1.4.0", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2016May, true, "1.4.0"));
        else if (version.startsWith("1.0"))
            ve.put(version, TestUtilities.getValidationEngine("hl7.fhir.r2.core#1.0.2", ValidationEngineTests.DEF_TX, txLog, FhirPublication.DSTU2, true, "1.0.2"));
        else
            throw new Exception("unknown version " + version);
    }
    vCurr = ve.get(version);
    vCurr.getContext().getTxClient().setLogger(logger);
    igLoader = new IgLoader(vCurr.getPcm(), vCurr.getContext(), vCurr.getVersion(), true);
    if (TestingUtilities.fcontexts == null) {
        TestingUtilities.fcontexts = new HashMap<>();
    }
    TestingUtilities.fcontexts.put(version, vCurr.getContext());
    if (content.has("use-test") && !content.get("use-test").getAsBoolean())
        return;
    byte[] testCaseContent = TestingUtilities.loadTestResource("validator", JSONUtil.str(content, "file")).getBytes(StandardCharsets.UTF_8);
    // load and process content
    FhirFormat fmt = determineFormat(content, testCaseContent);
    InstanceValidator val = vCurr.getValidator(fmt);
    val.setWantCheckSnapshotUnchanged(true);
    val.getContext().setClientRetryCount(4);
    val.setDebug(false);
    if (content.has("fetcher") && "standalone".equals(JSONUtil.str(content, "fetcher"))) {
        val.setFetcher(vCurr);
        vCurr.setFetcher(new StandAloneValidatorFetcher(vCurr.getPcm(), vCurr.getContext(), vCurr));
    } else {
        val.setFetcher(this);
    }
    val.setPolicyAdvisor(this);
    if (content.has("allowed-extension-domain"))
        val.getExtensionDomains().add(content.get("allowed-extension-domain").getAsString());
    if (content.has("allowed-extension-domains"))
        for (JsonElement a : content.getAsJsonArray("allowed-extension-domains")) val.getExtensionDomains().add(a.getAsString());
    if (content.has("language"))
        val.setValidationLanguage(content.get("language").getAsString());
    else
        val.setValidationLanguage(null);
    if (content.has("default-version")) {
        val.setBaseOptions(val.getBaseOptions().setVersionFlexible(content.get("default-version").getAsBoolean()));
    } else {
        val.setBaseOptions(val.getBaseOptions().setVersionFlexible(false));
    }
    if (content.has("packages")) {
        for (JsonElement e : content.getAsJsonArray("packages")) {
            String n = e.getAsString();
            InputStream cnt = n.endsWith(".tgz") ? TestingUtilities.loadTestResourceStream("validator", n) : null;
            if (cnt != null) {
                igLoader.loadPackage(NpmPackage.fromPackage(cnt));
            } else {
                igLoader.loadIg(vCurr.getIgs(), vCurr.getBinaries(), n, true);
            }
        }
    }
    if (content.has("crumb-trail")) {
        val.setCrumbTrails(content.get("crumb-trail").getAsBoolean());
    }
    if (content.has("supporting")) {
        for (JsonElement e : content.getAsJsonArray("supporting")) {
            String filename = e.getAsString();
            String contents = TestingUtilities.loadTestResource("validator", filename);
            CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
            val.getContext().cacheResource(mr);
            if (mr instanceof ImplementationGuide) {
                val.getImplementationGuides().add((ImplementationGuide) mr);
            }
        }
    }
    val.getBundleValidationRules().clear();
    if (content.has("bundle-param")) {
        val.getBundleValidationRules().add(new BundleValidationRule(content.getAsJsonObject("bundle-param").get("rule").getAsString(), content.getAsJsonObject("bundle-param").get("profile").getAsString()));
    }
    if (content.has("profiles")) {
        for (JsonElement je : content.getAsJsonArray("profiles")) {
            String filename = je.getAsString();
            String contents = TestingUtilities.loadTestResource("validator", filename);
            StructureDefinition sd = loadProfile(filename, contents, messages, val.isDebug());
            val.getContext().cacheResource(sd);
        }
    }
    List<ValidationMessage> errors = new ArrayList<ValidationMessage>();
    if (content.getAsJsonObject("java").has("debug")) {
        val.setDebug(content.getAsJsonObject("java").get("debug").getAsBoolean());
    } else {
        val.setDebug(false);
    }
    if (content.has("best-practice")) {
        val.setBestPracticeWarningLevel(BestPracticeWarningLevel.valueOf(content.get("best-practice").getAsString()));
    }
    if (content.has("examples")) {
        val.setAllowExamples(content.get("examples").getAsBoolean());
    } else {
        val.setAllowExamples(true);
    }
    if (content.has("security-checks")) {
        val.setSecurityChecks(content.get("security-checks").getAsBoolean());
    }
    if (content.has("logical") == false) {
        val.setAssumeValidRestReferences(content.has("assumeValidRestReferences") ? content.get("assumeValidRestReferences").getAsBoolean() : false);
        System.out.println(String.format("Start Validating (%d to set up)", (System.nanoTime() - setup) / 1000000));
        val.validate(null, errors, new ByteArrayInputStream(testCaseContent), fmt);
        System.out.println(val.reportTimes());
        checkOutcomes(errors, content, null, name);
    }
    if (content.has("profile")) {
        System.out.print("** Profile: ");
        JsonObject profile = content.getAsJsonObject("profile");
        if (profile.has("packages")) {
            for (JsonElement e : profile.getAsJsonArray("packages")) {
                igLoader.loadIg(vCurr.getIgs(), vCurr.getBinaries(), e.getAsString(), true);
            }
        }
        if (profile.getAsJsonObject("java").has("debug")) {
            val.setDebug(profile.getAsJsonObject("java").get("debug").getAsBoolean());
        }
        if (profile.has("supporting")) {
            for (JsonElement e : profile.getAsJsonArray("supporting")) {
                String filename = e.getAsString();
                String contents = TestingUtilities.loadTestResource("validator", filename);
                CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
                val.getContext().cacheResource(mr);
                if (mr instanceof ImplementationGuide) {
                    val.getImplementationGuides().add((ImplementationGuide) mr);
                }
            }
        }
        StructureDefinition sd = null;
        String filename = profile.get("source").getAsString();
        if (Utilities.isAbsoluteUrl(filename)) {
            sd = val.getContext().fetchResource(StructureDefinition.class, filename);
        } else {
            String contents = TestingUtilities.loadTestResource("validator", filename);
            System.out.println("Name: " + name + " - profile : " + profile.get("source").getAsString());
            version = content.has("version") ? content.get("version").getAsString() : Constants.VERSION;
            sd = loadProfile(filename, contents, messages, val.isDebug());
            val.getContext().cacheResource(sd);
        }
        val.setAssumeValidRestReferences(profile.has("assumeValidRestReferences") ? profile.get("assumeValidRestReferences").getAsBoolean() : false);
        List<ValidationMessage> errorsProfile = new ArrayList<ValidationMessage>();
        val.validate(null, errorsProfile, new ByteArrayInputStream(testCaseContent), fmt, asSdList(sd));
        System.out.println(val.reportTimes());
        checkOutcomes(errorsProfile, profile, filename, name);
    }
    if (content.has("logical")) {
        System.out.print("** Logical: ");
        JsonObject logical = content.getAsJsonObject("logical");
        if (logical.has("supporting")) {
            for (JsonElement e : logical.getAsJsonArray("supporting")) {
                String filename = e.getAsString();
                String contents = TestingUtilities.loadTestResource("validator", filename);
                CanonicalResource mr = (CanonicalResource) loadResource(filename, contents);
                if (mr instanceof StructureDefinition) {
                    val.getContext().generateSnapshot((StructureDefinition) mr, true);
                }
                val.getContext().cacheResource(mr);
            }
        }
        if (logical.has("packages")) {
            for (JsonElement e : logical.getAsJsonArray("packages")) {
                igLoader.loadIg(vCurr.getIgs(), vCurr.getBinaries(), e.getAsString(), true);
            }
        }
        List<ValidationMessage> errorsLogical = new ArrayList<ValidationMessage>();
        Element le = val.validate(null, errorsLogical, new ByteArrayInputStream(testCaseContent), fmt);
        if (logical.has("expressions")) {
            FHIRPathEngine fp = new FHIRPathEngine(val.getContext());
            for (JsonElement e : logical.getAsJsonArray("expressions")) {
                String exp = e.getAsString();
                Assert.assertTrue(fp.evaluateToBoolean(null, le, le, le, fp.parse(exp)));
            }
        }
        checkOutcomes(errorsLogical, logical, "logical", name);
    }
    logger.verifyHasNoRequests();
}
Also used : IgLoader(org.hl7.fhir.validation.IgLoader) BundleValidationRule(org.hl7.fhir.r5.utils.validation.BundleValidationRule) InstanceValidator(org.hl7.fhir.validation.instance.InstanceValidator) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JsonElement(com.google.gson.JsonElement) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) FhirFormat(org.hl7.fhir.r5.elementmodel.Manager.FhirFormat) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ByteArrayInputStream(java.io.ByteArrayInputStream) CacheVerificationLogger(org.hl7.fhir.utilities.tests.CacheVerificationLogger) JsonElement(com.google.gson.JsonElement) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) StandAloneValidatorFetcher(org.hl7.fhir.validation.cli.services.StandAloneValidatorFetcher) Test(org.junit.Test)

Example 78 with MR

use of org.hl7.fhir.r4.model.codesystems.V3Hl7PublishingDomain.MR 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 79 with MR

use of org.hl7.fhir.r4.model.codesystems.V3Hl7PublishingDomain.MR 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 80 with MR

use of org.hl7.fhir.r4.model.codesystems.V3Hl7PublishingDomain.MR 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

Test (org.junit.jupiter.api.Test)126 Resource (org.hl7.fhir.r4.model.Resource)86 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)58 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)40 Patient (org.hl7.fhir.r4.model.Patient)36 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)35 Identifier (org.hl7.fhir.r4.model.Identifier)30 Bundle (org.hl7.fhir.r4.model.Bundle)29 MedicationRequest (org.hl7.fhir.r4.model.MedicationRequest)22 Immunization (org.hl7.fhir.r4.model.Immunization)19 Encounter (org.hl7.fhir.r4.model.Encounter)18 Coding (org.hl7.fhir.r4.model.Coding)16 Observation (org.hl7.fhir.r4.model.Observation)15 Organization (org.hl7.fhir.r4.model.Organization)15 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)15 ValueSource (org.junit.jupiter.params.provider.ValueSource)14 ResourceModel (io.github.linuxforhealth.api.ResourceModel)13 Reference (org.hl7.fhir.r4.model.Reference)13 Extension (org.hl7.fhir.r4.model.Extension)11