Search in sources :

Example 1 with UNKNOWN

use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.UNKNOWN in project beneficiary-fhir-data by CMSgov.

the class BeneficiaryTransformerV2 method transform.

/**
 * @param beneficiary the CCW {@link Beneficiary} to transform
 * @param requestHeader {@link RequestHeaders} the holder that contains all supported resource
 *     request headers
 * @return a FHIR {@link Patient} resource that represents the specified {@link Beneficiary}
 */
private static Patient transform(Beneficiary beneficiary, RequestHeaders requestHeader) {
    Objects.requireNonNull(beneficiary);
    Patient patient = new Patient();
    /*
     * Notify end users when they receive Patient records impacted by
     * https://jira.cms.gov/browse/BFD-1566. See the documentation on
     * LoadAppOptions.isFilteringNonNullAndNon2022Benes() for details.
     */
    if (!beneficiary.getSkippedRifRecords().isEmpty()) {
        patient.getMeta().addTag(TransformerConstants.CODING_SYSTEM_BFD_TAGS, TransformerConstants.CODING_BFD_TAGS_DELAYED_BACKDATED_ENROLLMENT, TransformerConstants.CODING_BFD_TAGS_DELAYED_BACKDATED_ENROLLMENT_DISPLAY);
    }
    // Required values not directly mapped
    patient.getMeta().addProfile(ProfileConstants.C4BB_PATIENT_URL);
    patient.setId(beneficiary.getBeneficiaryId());
    // BENE_ID => patient.identifier
    TransformerUtilsV2.addIdentifierSlice(patient, TransformerUtilsV2.createCodeableConcept(TransformerConstants.CODING_SYSTEM_HL7_IDENTIFIER_TYPE, null, TransformerConstants.PATIENT_MB_ID_DISPLAY, "MB"), Optional.of(beneficiary.getBeneficiaryId()), Optional.of(TransformerConstants.CODING_BBAPI_BENE_ID));
    // Unhashed MBI
    if (beneficiary.getMedicareBeneficiaryId().isPresent()) {
        Period mbiPeriod = new Period();
        if (beneficiary.getMbiEffectiveDate().isPresent()) {
            TransformerUtilsV2.setPeriodStart(mbiPeriod, beneficiary.getMbiEffectiveDate().get());
        }
        if (beneficiary.getMbiObsoleteDate().isPresent()) {
            TransformerUtilsV2.setPeriodEnd(mbiPeriod, beneficiary.getMbiObsoleteDate().get());
        }
        addUnhashedIdentifier(patient, beneficiary.getMedicareBeneficiaryId().get(), TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, TransformerUtilsV2.createIdentifierCurrencyExtension(CurrencyIdentifier.CURRENT), mbiPeriod);
    }
    // Add lastUpdated
    TransformerUtilsV2.setLastUpdated(patient, beneficiary.getLastUpdated());
    /**
     * The following logic attempts to distill {@link MedicareBeneficiaryIdHistory} data into only
     * those records which have an endDate present. This is due to the fact that it includes the
     * CURRENT MBI record which was handle previously. Also, the {@link
     * MedicareBeneficiaryIdHistory} table appears to contain spurious records with the only
     * difference is the generated surrogate key identifier.
     */
    if (requestHeader.isMBIinIncludeIdentifiers()) {
        HashMap<LocalDate, MedicareBeneficiaryIdHistory> mbiHistMap = new HashMap<LocalDate, MedicareBeneficiaryIdHistory>();
        for (MedicareBeneficiaryIdHistory mbiHistory : beneficiary.getMedicareBeneficiaryIdHistories()) {
            // and will have been previously provided as the CURRENT rcd.
            if (mbiHistory.getMbiEndDate().isPresent()) {
                mbiHistMap.put(mbiHistory.getMbiEndDate().get(), mbiHistory);
            }
            // would come in ascending order, so any rcd would have a later
            // update date than prev rcd.
            TransformerUtilsV2.updateMaxLastUpdated(patient, mbiHistory.getLastUpdated());
        }
        if (mbiHistMap.size() > 0) {
            Extension historicalIdentifier = TransformerUtilsV2.createIdentifierCurrencyExtension(CurrencyIdentifier.HISTORIC);
            for (MedicareBeneficiaryIdHistory mbi : mbiHistMap.values()) {
                addUnhashedIdentifier(patient, mbi.getMedicareBeneficiaryId().get(), TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, historicalIdentifier, null);
            }
        }
    }
    // support header includeAddressFields from downstream components e.g. BB2
    // per requirement of BFD-379, BB2 always send header includeAddressFields = False
    Boolean addrHdrVal = requestHeader.getValue(R4PatientResourceProvider.HEADER_NAME_INCLUDE_ADDRESS_FIELDS);
    if (addrHdrVal != null && addrHdrVal) {
        patient.addAddress().setState(beneficiary.getStateCode()).setPostalCode(beneficiary.getPostalCode()).setCity(beneficiary.getDerivedCityName().orElse(null)).addLine(beneficiary.getDerivedMailingAddress1().orElse(null)).addLine(beneficiary.getDerivedMailingAddress2().orElse(null)).addLine(beneficiary.getDerivedMailingAddress3().orElse(null)).addLine(beneficiary.getDerivedMailingAddress4().orElse(null)).addLine(beneficiary.getDerivedMailingAddress5().orElse(null)).addLine(beneficiary.getDerivedMailingAddress6().orElse(null));
    } else {
        patient.addAddress().setState(beneficiary.getStateCode()).setPostalCode(beneficiary.getPostalCode());
    }
    if (beneficiary.getBirthDate() != null) {
        patient.setBirthDate(TransformerUtilsV2.convertToDate(beneficiary.getBirthDate()));
    }
    // "Patient.deceased[x]": ["boolean", "dateTime"],
    if (beneficiary.getBeneficiaryDateOfDeath().isPresent()) {
        patient.setDeceased(new DateTimeType(TransformerUtilsV2.convertToDate(beneficiary.getBeneficiaryDateOfDeath().get()), TemporalPrecisionEnum.DAY));
    } else {
        patient.setDeceased(new BooleanType(false));
    }
    char sex = beneficiary.getSex();
    if (sex == Sex.MALE.getCode())
        patient.setGender((AdministrativeGender.MALE));
    else if (sex == Sex.FEMALE.getCode())
        patient.setGender((AdministrativeGender.FEMALE));
    else
        patient.setGender((AdministrativeGender.UNKNOWN));
    if (beneficiary.getRace().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.RACE, beneficiary.getRace().get()));
        // for race category, v2 will just treat all race codes as Unknown (UNK);
        // thus we'll simply pass in the Unknown race code .
        RaceCategory raceCategory = TransformerUtilsV2.getRaceCategory('0');
        Extension raceChildOMBExt1 = new Extension().setValue(new Coding().setCode(raceCategory.toCode()).setSystem(raceCategory.getSystem()).setDisplay(raceCategory.getDisplay())).setUrl("ombCategory");
        Extension raceChildOMBExt2 = new Extension().setValue(new StringType().setValue(raceCategory.getDisplay())).setUrl("text");
        Extension parentOMBRace = new Extension().setUrl(TransformerConstants.CODING_RACE_US);
        parentOMBRace.addExtension(raceChildOMBExt1);
        parentOMBRace.addExtension(raceChildOMBExt2);
        patient.addExtension(parentOMBRace);
    }
    HumanName name = patient.addName().addGiven(beneficiary.getNameGiven()).setFamily(beneficiary.getNameSurname()).setUse(HumanName.NameUse.USUAL);
    if (beneficiary.getNameMiddleInitial().isPresent()) {
        name.addGiven(String.valueOf(beneficiary.getNameMiddleInitial().get()));
    }
    // The reference year of the enrollment data
    if (beneficiary.getBeneEnrollmentReferenceYear().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionDate(CcwCodebookVariable.RFRNC_YR, beneficiary.getBeneEnrollmentReferenceYear()));
    }
    // Monthly Medicare-Medicaid dual eligibility codes
    if (beneficiary.getMedicaidDualEligibilityJanCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_01, beneficiary.getMedicaidDualEligibilityJanCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityFebCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_02, beneficiary.getMedicaidDualEligibilityFebCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityMarCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_03, beneficiary.getMedicaidDualEligibilityMarCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityAprCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_04, beneficiary.getMedicaidDualEligibilityAprCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityMayCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_05, beneficiary.getMedicaidDualEligibilityMayCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityJunCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_06, beneficiary.getMedicaidDualEligibilityJunCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityJulCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_07, beneficiary.getMedicaidDualEligibilityJulCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityAugCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_08, beneficiary.getMedicaidDualEligibilityAugCode()));
    }
    if (beneficiary.getMedicaidDualEligibilitySeptCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_09, beneficiary.getMedicaidDualEligibilitySeptCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityOctCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_10, beneficiary.getMedicaidDualEligibilityOctCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityNovCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_11, beneficiary.getMedicaidDualEligibilityNovCode()));
    }
    if (beneficiary.getMedicaidDualEligibilityDecCode().isPresent()) {
        patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_12, beneficiary.getMedicaidDualEligibilityDecCode()));
    }
    // Last Updated => Patient.meta.lastUpdated
    TransformerUtilsV2.setLastUpdated(patient, beneficiary.getLastUpdated());
    return patient;
}
Also used : HashMap(java.util.HashMap) StringType(org.hl7.fhir.r4.model.StringType) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) MedicareBeneficiaryIdHistory(gov.cms.bfd.model.rif.MedicareBeneficiaryIdHistory) LocalDate(java.time.LocalDate) Extension(org.hl7.fhir.r4.model.Extension) HumanName(org.hl7.fhir.r4.model.HumanName) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) RaceCategory(gov.cms.bfd.server.war.commons.RaceCategory)

Example 2 with UNKNOWN

use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.UNKNOWN in project kindling by HL7.

the class PageProcessor method profileDictionaryLink.

private String profileDictionaryLink(ConstraintStructure profile) {
    String uri = ToolingExtensions.readStringExtension(profile.getResource(), "http://hl7.org/fhir/StructureDefinition/datadictionary");
    if (Utilities.noString(uri))
        return "<!-- no uri -->";
    Dictionary dict = definitions.getDictionaries().get(uri);
    if (dict == null)
        return "<p>This profile specifies that the value of the " + profile.getResource().getSnapshot().getElement().get(0).getPath() + " resource must be a valid Observation as defined in the data dictionary (Unknown? - " + uri + ").</p>";
    else
        return "<p>This profile specifies that the value of the " + profile.getResource().getSnapshot().getElement().get(0).getPath() + " resource must be a valid Observation as defined in the data dictionary <a href=\"" + uri + ".html\">" + dict.getName() + "</a>.</p>";
}
Also used : Dictionary(org.hl7.fhir.definitions.model.Dictionary)

Example 3 with UNKNOWN

use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.UNKNOWN in project kindling by HL7.

the class CDAGenerator method checkType.

private void checkType(TypeRefComponent t) {
    String id = t.getWorkingCode();
    if (Utilities.existsInList(id, "string", "Element", "code", "boolean", "Resource"))
        return;
    for (StructureDefinition sd : structures) {
        if (sd.getId().equals(fix(id)))
            return;
    }
    if (id.equals("http://hl7.org/fhir/cda/StructureDefinition/PN") || id.equals("http://hl7.org/fhir/cda/StructureDefinition/ON"))
        t.setCode("http://hl7.org/fhir/cda/StructureDefinition/EN");
    else if (id.equals("NARRATIVE"))
        t.setCode("xhtml");
    else
        System.out.println("Unknown data type " + id);
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 4 with UNKNOWN

use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.UNKNOWN in project kindling by HL7.

the class TypeParser method convert.

public List<TypeRefComponent> convert(IWorkerContext context, String path, List<TypeRef> types, boolean resource, ElementDefinition ed) throws Exception {
    List<TypeRefComponent> list = new ArrayList<TypeRefComponent>();
    for (TypeRef t : types) {
        // Expand any Resource(A|B|C) references
        if (t.hasParams() && !("Reference".equals(t.getName()) || "canonical".equals(t.getName()))) {
            throw new Exception("Only resource references can specify parameters.  Path " + path);
        }
        if (t.getParams().size() > 0) {
            if (t.getProfile() != null && t.getParams().size() != 1) {
                throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types.  Path " + path);
            }
            if (t.getProfile() != null) {
                TypeRefComponent childType = getTypeComponent(list, t.getName());
                if (t.getVersioning() != null)
                    childType.setVersioning(t.getVersioning());
                if (t.getName().equals("Reference") || t.getName().equals("canonical"))
                    childType.addTargetProfile(t.getProfile());
                else
                    childType.addProfile(t.getProfile());
            } else
                for (String param : t.getParams()) {
                    TypeRefComponent childType = getTypeComponent(list, t.getName());
                    if (t.getVersioning() != null)
                        childType.setVersioning(t.getVersioning());
                    String p = "Any".equals(param) ? "Resource" : param;
                    if (t.getName().equals("Reference") || t.getName().equals("canonical"))
                        childType.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                    else
                        childType.addProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                }
        } else if (t.isWildcardType()) {
            // this list is filled out manually because it may be running before the types referred to have been loaded
            for (String n : TypesUtilities.wildcardTypes(version)) {
                TypeRefComponent tc = new TypeRefComponent().setCode(n);
                if (t.getVersioning() != null)
                    tc.setVersioning(t.getVersioning());
                list.add(tc);
            }
        } else if (Utilities.noString(t.getName()) && t.getProfile() != null) {
            StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getProfile());
            TypeRefComponent tc = getTypeComponent(list, sd != null ? sd.getType() : t.getName());
            if (t.getVersioning() != null)
                tc.setVersioning(t.getVersioning());
            if (t.getName().equals("Reference"))
                tc.addTargetProfile(t.getProfile());
            else
                tc.addProfile(t.getProfile());
        } else if (t.getName().startsWith("=")) {
            if (resource)
                list.add(new TypeRefComponent().setCode("BackboneElement"));
            else
                list.add(new TypeRefComponent().setCode("Element"));
            ToolingExtensions.addStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", t.getName().substring(1));
        } else {
            StructureDefinition sd = context.fetchTypeDefinition(t.getName());
            if (sd == null)
                throw new Exception("Unknown type '" + t.getName() + "'");
            TypeRefComponent tc = getTypeComponent(list, sd.getType());
            if (t.getVersioning() != null)
                tc.setVersioning(t.getVersioning());
            if (t.getName().equals("Reference")) {
                if (t.hasProfile())
                    tc.addTargetProfile(t.getProfile());
            } else if (t.hasProfile())
                tc.addProfile(t.getProfile());
        }
    }
    // no duplicates
    for (TypeRefComponent tr1 : list) {
        for (TypeRefComponent tr2 : list) {
            if (tr1 != tr2) {
                if (tr1.getWorkingCode().equals(tr2.getWorkingCode()))
                    throw new Exception("duplicate code " + tr1.getWorkingCode());
            }
        }
    }
    return list;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList)

Example 5 with UNKNOWN

use of org.hl7.fhir.r4.model.Encounter.EncounterStatus.UNKNOWN in project kindling by HL7.

the class OldSpreadsheetParser method readOperations.

private void readOperations(List<Operation> oplist, Sheet sheet) throws Exception {
    Map<String, Operation> ops = new HashMap<String, Operation>();
    Map<String, OperationParameter> params = new HashMap<String, OperationParameter>();
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String name = sheet.getColumn(row, "Name");
            String use = sheet.getColumn(row, "Use");
            String doco = sheet.getColumn(row, "Documentation");
            String type = sheet.getColumn(row, "Type");
            List<OperationExample> examples = loadOperationExamples(sheet.getColumn(row, "Example.Request"), sheet.getColumn(row, "Example.Response"));
            List<OperationExample> examples2 = loadOperationExamples(sheet.getColumn(row, "Example2.Request"), sheet.getColumn(row, "Example2.Response"));
            if (name != null && !name.equals("") && !name.startsWith("!")) {
                if (!name.contains(".")) {
                    if (!type.equals("operation"))
                        throw new Exception("Invalid type on operation " + type + " at " + getLocation(row));
                    if (!name.toLowerCase().equals(name))
                        throw new Exception("Invalid name on operation " + name + " - must be all lower case (use dashes) at " + getLocation(row));
                    params.clear();
                    boolean system = false;
                    boolean istype = false;
                    boolean instance = false;
                    for (String c : use.split("\\|")) {
                        c = c.trim();
                        if ("system".equalsIgnoreCase(c))
                            system = true;
                        else if ("resource".equalsIgnoreCase(c))
                            istype = true;
                        else if ("instance".equalsIgnoreCase(c))
                            instance = true;
                        else
                            throw new Exception("unknown operation use code " + c + " at " + getLocation(row));
                    }
                    Operation op = new Operation(name, system, istype, instance, sheet.getColumn(row, "Type"), sheet.getColumn(row, "Title"), doco, sheet.getColumn(row, "Footer"), examples, parseBoolean(sheet.getColumn(row, "Idempotent"), row, false));
                    op.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
                    op.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
                    op.setFooter2(sheet.getColumn(row, "Footer2"));
                    op.setFmm(sheet.getColumn(row, "fmm"));
                    op.getExamples2().addAll(examples2);
                    oplist.add(op);
                    ops.put(name, op);
                } else {
                    String context = name.substring(0, name.lastIndexOf('.'));
                    String pname = name.substring(name.lastIndexOf('.') + 1);
                    Operation operation;
                    List<OperationParameter> plist;
                    if (context.contains(".")) {
                        String opname = name.substring(0, name.indexOf('.'));
                        // inside of a tuple
                        if (!Utilities.noString(use))
                            throw new Exception("Tuple parameters: use must be blank at " + getLocation(row));
                        operation = ops.get(opname);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + opname + "' at " + getLocation(row));
                        OperationParameter param = params.get(context);
                        if (param == null)
                            throw new Exception("Tuple parameter '" + context + "' not found at " + getLocation(row));
                        if (!param.getFhirType().equals("Tuple"))
                            throw new Exception("Tuple parameter '" + context + "' type must be Tuple at " + getLocation(row));
                        plist = param.getParts();
                    } else {
                        if (!use.equals("in") && !use.equals("out"))
                            throw new Exception("Only allowed use is 'in' or 'out' at " + getLocation(row));
                        operation = ops.get(context);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + context + "' at " + getLocation(row));
                        plist = operation.getParameters();
                    }
                    String profile = sheet.getColumn(row, "Profile");
                    String min = sheet.getColumn(row, "Min");
                    String max = sheet.getColumn(row, "Max");
                    OperationParameter p = new OperationParameter(pname, use, doco, Integer.parseInt(min), max, type, sheet.getColumn(row, "Search Type"), profile);
                    String bs = sheet.getColumn(row, "Binding");
                    if (!Utilities.noString(bs))
                        p.setBs(bindings.get(bs));
                    plist.add(p);
                    params.put(name, p);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) Operation(org.hl7.fhir.definitions.model.Operation) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)51 ArrayList (java.util.ArrayList)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)36 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)27 Test (org.junit.jupiter.api.Test)23 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)20 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)18 Reference (org.hl7.fhir.r4.model.Reference)17 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)17 HashMap (java.util.HashMap)15 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)15 Coding (org.hl7.fhir.r4.model.Coding)14 Identifier (org.hl7.fhir.r4.model.Identifier)14 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)13 Patient (org.hl7.fhir.r4.model.Patient)13 IOException (java.io.IOException)12 Header (org.apache.http.Header)11 Test (org.junit.Test)11 File (java.io.File)10 URISyntaxException (java.net.URISyntaxException)10