Search in sources :

Example 41 with Value

use of org.hl7.fhir.utilities.graphql.Value in project beneficiary-fhir-data by CMSgov.

the class SamhsaMatcherR4FromClaimTransformerV2Test method verifySamhsaMatcherForItemWithMultiCoding.

/**
 * Verify SAMHSA matcher for item with the given system, code and if the expectation is that there
 * should be a match for this combination.
 *
 * @param system the system value of the first coding
 * @param code the code of the first coding
 * @param system2 the system value of the second coding
 * @param code2 the code of the second coding
 * @param shouldMatch if the matcher should match on this combination
 * @param explanationOfBenefit the explanation of benefit
 */
private void verifySamhsaMatcherForItemWithMultiCoding(String system, String code, String system2, String code2, boolean shouldMatch, ExplanationOfBenefit explanationOfBenefit) {
    ExplanationOfBenefit modifiedEob = explanationOfBenefit.copy();
    // Set Top level diagnosis and package code to null so we can test item logic
    for (ExplanationOfBenefit.DiagnosisComponent diagnosisComponent : modifiedEob.getDiagnosis()) {
        CodeableConcept codeableConcept = diagnosisComponent.getDiagnosisCodeableConcept();
        codeableConcept.setCoding(new ArrayList<>());
        diagnosisComponent.setPackageCode(null);
    }
    List<Coding> codings = new ArrayList<>();
    Coding coding = new Coding();
    coding.setSystem(system);
    coding.setCode(code);
    Coding coding2 = new Coding();
    coding2.setSystem(system2);
    coding2.setCode(code2);
    codings.add(coding);
    codings.add(coding2);
    modifiedEob.getItem().get(0).getProductOrService().setCoding(codings);
    assertEquals(shouldMatch, samhsaMatcherV2.test(modifiedEob));
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) ArrayList(java.util.ArrayList) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 42 with Value

use of org.hl7.fhir.utilities.graphql.Value in project beneficiary-fhir-data by CMSgov.

the class R4CoverageResourceProviderIT method searchWithLastUpdated.

/**
 * Verifies that {@link
 * gov.cms.bfd.server.war.stu3.providers.CoverageResourceProvider#searchByBeneficiary} works as
 * expected for a search with a lastUpdated value.
 */
@Test
public void searchWithLastUpdated() {
    List<Object> loadedRecords = ServerTestUtils.get().loadData(Arrays.asList(StaticRifResourceGroup.SAMPLE_A.getResources()));
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Beneficiary beneficiary = loadedRecords.stream().filter(r -> r instanceof Beneficiary).map(r -> (Beneficiary) r).findFirst().get();
    Bundle searchResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).returnBundle(Bundle.class).execute();
    LOGGER.info("Bundle information: database {}, first {}", searchResults.getMeta().getLastUpdated(), searchResults.getEntry().get(0).getResource().getMeta().getLastUpdated());
    Date nowDate = new Date();
    Date secondsAgoDate = Date.from(Instant.now().minusSeconds(100));
    DateRangeParam inBoundsRange = new DateRangeParam().setLowerBoundInclusive(secondsAgoDate).setUpperBoundExclusive(nowDate);
    LOGGER.info("Query Date Range {}", inBoundsRange);
    Bundle searchInBoundsResults = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(inBoundsRange).returnBundle(Bundle.class).execute();
    assertNotNull(searchInBoundsResults);
    assertEquals(MedicareSegment.values().length, searchInBoundsResults.getTotal());
    Date hourAgoDate = Date.from(Instant.now().minusSeconds(3600));
    DateRangeParam outOfBoundsRange = new DateRangeParam(hourAgoDate, secondsAgoDate);
    Bundle searchOutOfBoundsResult = fhirClient.search().forResource(Coverage.class).where(Coverage.BENEFICIARY.hasId(TransformerUtilsV2.buildPatientId(beneficiary))).lastUpdated(outOfBoundsRange).returnBundle(Bundle.class).execute();
    assertNotNull(searchOutOfBoundsResult);
    assertEquals(0, searchOutOfBoundsResult.getTotal());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Date(java.util.Date) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Constants(ca.uhn.fhir.rest.api.Constants) LoggerFactory(org.slf4j.LoggerFactory) PipelineTestUtils(gov.cms.bfd.pipeline.sharedutils.PipelineTestUtils) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) BeforeAll(org.junit.jupiter.api.BeforeAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) StaticRifResourceGroup(gov.cms.bfd.model.rif.samples.StaticRifResourceGroup) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Coverage(org.hl7.fhir.r4.model.Coverage) Logger(org.slf4j.Logger) MedicareSegment(gov.cms.bfd.server.war.commons.MedicareSegment) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TransformerConstants(gov.cms.bfd.server.war.commons.TransformerConstants) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) Coverage(org.hl7.fhir.r4.model.Coverage) Date(java.util.Date) Beneficiary(gov.cms.bfd.model.rif.Beneficiary) Test(org.junit.jupiter.api.Test)

Example 43 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class Publisher method addToResourceFeed.

private void addToResourceFeed(ValueSet vs, Bundle dest, String filename) throws Exception {
    maybeFixResourceId(vs, filename);
    if (vs.getId() == null)
        throw new Exception("Resource has no id: " + vs.getName() + " (" + vs.getUrl() + ")");
    if (ResourceUtilities.getById(dest, ResourceType.ValueSet, vs.getId()) != null)
        throw new Exception("Attempt to add duplicate value set " + vs.getId() + " (" + vs.getName() + ")");
    if (!vs.hasText() || !vs.getText().hasDiv()) {
        RendererFactory.factory(vs, page.getRc().copy()).render(vs);
    }
    if (!vs.hasText() || vs.getText().getDiv() == null)
        throw new Exception("Example Value Set " + vs.getId() + " does not have any narrative");
    ResourceUtilities.meta(vs).setLastUpdated(page.getGenDate().getTime());
    if (vs.getUrl().startsWith("http://hl7.org/fhir/") && !vs.getUrl().equals("http://hl7.org/fhir/" + vs.getResourceType().toString() + "/" + vs.getId()))
        throw new Exception("URL mismatch on value set: " + vs.getUrl() + " vs " + "http://hl7.org/fhir/" + vs.getResourceType().toString() + "/" + vs.getId());
    dest.getEntry().add(new BundleEntryComponent().setResource(vs).setFullUrl("http://hl7.org/fhir/" + vs.fhirType() + "/" + vs.getId()));
}
Also used : BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 44 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class Publisher method generateCodeSystemPart2.

private void generateCodeSystemPart2(CodeSystem cs) throws Exception {
    String n = cs.getUserString("filename");
    if (n == null)
        n = "codesystem-" + cs.getId();
    ImplementationGuideDefn ig = (ImplementationGuideDefn) cs.getUserData(ToolResourceUtilities.NAME_RES_IG);
    if (ig != null)
        n = ig.getCode() + File.separator + n;
    if (cs.getText().getDiv().allChildrenAreText() && (Utilities.noString(cs.getText().getDiv().allText()) || !cs.getText().getDiv().allText().matches(".*\\w.*"))) {
        RenderingContext lrc = page.getRc().copy().setLocalPrefix(ig != null ? "../" : "").setTooCostlyNoteEmpty(PageProcessor.TOO_MANY_CODES_TEXT_EMPTY).setTooCostlyNoteNotEmpty(PageProcessor.TOO_MANY_CODES_TEXT_NOT_EMPTY);
        RendererFactory.factory(cs, lrc).render(cs);
    }
    page.getVsValidator().validate(page.getValidationErrors(), n, cs, true, false);
    if (isGenerate) {
        // page.log(" ... "+n, LogMessageType.Process);
        addToResourceFeed(cs, valueSetsFeed, null);
        if (cs.getUserData("path") == null)
            cs.setUserData("path", n + ".html");
        page.setId(cs.getId());
        String sf;
        WorkGroup wg = wg(cs, "vocab");
        try {
            sf = page.processPageIncludes(n + ".html", TextFile.fileToString(page.getFolders().templateDir + "template-cs.html"), "codeSystem", null, n + ".html", cs, null, "Value Set", ig, null, wg);
        } catch (Exception e) {
            throw new Exception("Error processing " + n + ".html: " + e.getMessage(), e);
        }
        sf = addSectionNumbers(n + ".html", "template-codesystem", sf, csCounter(), ig == null ? 0 : 1, null, ig);
        TextFile.stringToFile(sf, page.getFolders().dstDir + n + ".html");
        try {
            String src = page.processPageIncludesForBook(n + ".html", TextFile.fileToString(page.getFolders().templateDir + "template-cs-book.html"), "codeSystem", cs, ig, null);
            cachePage(n + ".html", src, "Code System " + n, false);
            page.setId(null);
        } catch (Exception e) {
            throw new Exception("Error processing " + n + ".html: " + e.getMessage(), e);
        }
        IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
        FileOutputStream s = new FileOutputStream(page.getFolders().dstDir + n + ".json");
        json.compose(s, cs);
        s.close();
        json = new JsonParser().setOutputStyle(OutputStyle.CANONICAL);
        s = new FileOutputStream(page.getFolders().dstDir + n + ".canonical.json");
        json.compose(s, cs);
        s.close();
        IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
        s = new FileOutputStream(page.getFolders().dstDir + n + ".xml");
        xml.compose(s, cs);
        s.close();
        xml = new XmlParser().setOutputStyle(OutputStyle.CANONICAL);
        s = new FileOutputStream(page.getFolders().dstDir + n + ".canonical.xml");
        xml.compose(s, cs);
        s.close();
        // System.out.println(vs.getUrl());
        cloneToXhtml(n, "Definition for Code System " + cs.getName(), false, "codesystem-instance", "Code System", null, wg);
        jsonToXhtml(n, "Definition for Code System " + cs.getName(), resource2Json(cs), "codesystem-instance", "Code System", null, wg);
        ttlToXhtml(n, "Definition for Code System " + cs.getName(), resource2Ttl(cs), "codesystem-instance", "Code System", null, wg);
    }
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) WorkGroup(org.hl7.fhir.definitions.model.WorkGroup) XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 45 with Value

use of org.hl7.fhir.utilities.graphql.Value in project kindling by HL7.

the class Publisher method loadValueSets1.

private void loadValueSets1() throws Exception {
    page.log(" ...vocab #1", LogMessageType.Process);
    generateCodeSystemsPart1();
    generateValueSetsPart1();
    for (BindingSpecification cd : page.getDefinitions().getUnresolvedBindings()) {
        String ref = cd.getReference();
        if (ref.startsWith("http://hl7.org/fhir")) {
            // we expect to be able to resolve this
            ValueSet vs = page.getDefinitions().getValuesets().get(ref);
            if (vs == null)
                vs = page.getDefinitions().getExtraValuesets().get(ref);
            if (vs == null)
                vs = page.getWorkerContext().fetchResource(ValueSet.class, ref);
            if (vs == null) {
                if (page.getDefinitions().getBoundValueSets().containsKey(ref))
                    throw new Exception("Unable to resolve the value set reference " + ref + " but found it in load list");
                throw new Exception("Unable to resolve the value set reference " + ref);
            }
            cd.setValueSet(vs);
        } else {
            ValueSet vs = page.getWorkerContext().fetchResource(ValueSet.class, ref);
            if (vs != null)
                cd.setValueSet(vs);
            else if (!ref.startsWith("http://loinc.org/vs/LL"))
                System.out.println("Unresolved value set reference: " + ref);
        }
    }
    for (ImplementationGuideDefn ig : page.getDefinitions().getSortedIgs()) {
        for (BindingSpecification cd : ig.getUnresolvedBindings()) {
            String ref = cd.getReference();
            if (ref.contains("|"))
                ref = ref.substring(0, ref.indexOf("|"));
            ValueSet vs = page.getDefinitions().getValuesets().get(ref);
            if (vs == null)
                vs = ig.getValueSet(ref);
            if (vs == null)
                vs = page.getWorkerContext().fetchResource(ValueSet.class, ref);
            if (vs == null)
                throw new Exception("unable to resolve value set " + ref);
            cd.setValueSet(vs);
        }
    }
}
Also used : BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ValueSet(org.hl7.fhir.r5.model.ValueSet) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Test (org.junit.jupiter.api.Test)222 ArrayList (java.util.ArrayList)183 FHIRException (org.hl7.fhir.exceptions.FHIRException)107 List (java.util.List)97 DisplayName (org.junit.jupiter.api.DisplayName)96 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)89 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)85 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)70 Identifier (org.hl7.fhir.r4.model.Identifier)69 Test (org.junit.Test)66 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)64 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)54 IOException (java.io.IOException)52 Bundle (org.hl7.fhir.r4.model.Bundle)49 Coding (org.hl7.fhir.r4.model.Coding)49 ValueSet (org.hl7.fhir.r5.model.ValueSet)48 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)46 Resource (org.hl7.fhir.r4.model.Resource)46 BigDecimal (java.math.BigDecimal)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)44