Search in sources :

Example 66 with Resource

use of org.hl7.fhir.r4.model.Resource in project beneficiary-fhir-data by CMSgov.

the class R4ClaimResponseResourceProviderIT method shouldGetCorrectClaimResponseResourcesByMbiHash.

@Test
void shouldGetCorrectClaimResponseResourcesByMbiHash() {
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    Bundle claimResult = fhirClient.search().forResource(ClaimResponse.class).where(ImmutableMap.of("mbi", Collections.singletonList(new ReferenceParam(RDATestUtils.MBI_OLD_HASH)), "service-date", Arrays.asList(new DateParam("gt1970-07-18"), new DateParam("lt1970-07-30")))).returnBundle(Bundle.class).execute();
    // Sort entries for consistent testing results
    claimResult.getEntry().sort(Comparator.comparing(a -> a.getResource().getId()));
    String expected = testUtils.expectedResponseFor("claimResponseSearch");
    String actual = FhirContext.forR4().newJsonParser().encodeResourceToString(claimResult);
    Set<String> ignorePatterns = new HashSet<>(IGNORE_PATTERNS);
    ignorePatterns.add("\"/id\"");
    ignorePatterns.add("\"/entry/[0-9]+/resource/created\"");
    AssertUtils.assertJsonEquals(expected, actual, ignorePatterns);
}
Also used : RDATestUtils(gov.cms.bfd.server.war.utils.RDATestUtils) Arrays(java.util.Arrays) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) AssertUtils(gov.cms.bfd.server.war.utils.AssertUtils) ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) FhirContext(ca.uhn.fhir.context.FhirContext) BeforeAll(org.junit.jupiter.api.BeforeAll) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Bundle(org.hl7.fhir.r4.model.Bundle) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) ServerTestUtils(gov.cms.bfd.server.war.ServerTestUtils) Comparator(java.util.Comparator) Collections(java.util.Collections) DateParam(ca.uhn.fhir.rest.param.DateParam) ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.r4.model.Bundle) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) DateParam(ca.uhn.fhir.rest.param.DateParam) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 67 with Resource

use of org.hl7.fhir.r4.model.Resource in project beneficiary-fhir-data by CMSgov.

the class R4ClaimResponseResourceProviderIT method shouldGetCorrectMcsClaimResponseResourceById.

@Test
void shouldGetCorrectMcsClaimResponseResourceById() {
    IGenericClient fhirClient = ServerTestUtils.get().createFhirClientV2();
    ClaimResponse claimResult = fhirClient.read().resource(ClaimResponse.class).withId("m-654321").execute();
    String expected = testUtils.expectedResponseFor("claimResponseMcsRead");
    String actual = FhirContext.forR4().newJsonParser().encodeResourceToString(claimResult);
    AssertUtils.assertJsonEquals(expected, actual, IGNORE_PATTERNS);
}
Also used : ClaimResponse(org.hl7.fhir.r4.model.ClaimResponse) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Test(org.junit.jupiter.api.Test)

Example 68 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class Publisher method resource2Json.

private String resource2Json(Resource r) throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
    json.setSuppressXhtml("Snipped for Brevity");
    json.compose(bytes, r);
    bytes.close();
    return new String(bytes.toByteArray());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IParser(org.hl7.fhir.r5.formats.IParser) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 69 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class Publisher method produceSpecMap.

private void produceSpecMap() throws IOException {
    SpecMapManager spm = new SpecMapManager("hl7.fhir.core", page.getVersion().toCode(), page.getVersion().toCode(), page.getBuildId(), page.getGenDate(), CANONICAL_BASE);
    for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
        if (sd.hasUserData("path")) {
            spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
            spm.target(sd.getUserString("path").replace("\\", "/"));
        }
    }
    for (StructureDefinition sd : page.getWorkerContext().getExtensionDefinitions()) {
        if (sd.hasUserData("path")) {
            spm.path(sd.getUrl(), sd.getUserString("path").replace("\\", "/"));
            spm.target(sd.getUserString("path").replace("\\", "/"));
        }
    }
    for (String s : page.getCodeSystems().keys()) {
        CodeSystem cs = page.getCodeSystems().get(s);
        if (cs == null && !Utilities.existsInList(s, "http://unitsofmeasure.org", "http://loinc.org", "http://fdasis.nlm.nih.gov", "http://www.nlm.nih.gov/research/umls/rxnorm", "urn:oid:1.2.36.1.2001.1005.17") && !SIDUtilities.isknownCodeSystem(s))
            System.out.println("No code system resource found for " + s);
    }
    for (CodeSystem cs : page.getCodeSystems().getList()) {
        if (cs != null && cs.hasUserData("path")) {
            spm.path(cs.getUrl(), cs.getUserString("path").replace("\\", "/"));
            spm.target(cs.getUserString("path").replace("\\", "/"));
        }
    }
    for (ValueSet vs : page.getValueSets().getList()) {
        if (vs.hasUserData("path")) {
            spm.path(vs.getUrl(), vs.getUserString("path").replace("\\", "/"));
            spm.target(vs.getUserString("path").replace("\\", "/"));
        }
    }
    for (ConceptMap cm : page.getConceptMaps().getList()) {
        if (cm.hasUserData("path")) {
            spm.path(cm.getUrl(), cm.getUserString("path").replace("\\", "/"));
            spm.target(cm.getUserString("path").replace("\\", "/"));
        }
    }
    for (String s : page.getDefinitions().getPageTitles().keySet()) {
        spm.page(s, page.getDefinitions().getPageTitles().get(s));
    }
    for (String n : page.getIni().getPropertyNames("pages")) {
        spm.target(n);
    }
    for (ResourceDefn rd : page.getDefinitions().getResources().values()) {
        spm.target(rd.getName().toLowerCase() + ".html");
        spm.target(rd.getName().toLowerCase() + "-definitions.html");
        spm.target(rd.getName().toLowerCase() + "-mappings.html");
        spm.target(rd.getName().toLowerCase() + "-examples.html");
        spm.target(rd.getName().toLowerCase() + "-profiles.html");
        if (!rd.getOperations().isEmpty())
            spm.target(rd.getName().toLowerCase() + "-operations.html");
        for (Example ex : rd.getExamples()) {
            ImplementationGuideDefn ig = ex.getIg() == null ? null : page.getDefinitions().getIgs().get(ex.getIg());
            String prefix = (ig == null || ig.isCore()) ? "" : ig.getCode() + "/";
            spm.target(prefix + ex.getTitle() + ".html");
        }
    }
    for (Profile p : page.getDefinitions().getPackList()) {
        spm.target(p.getId() + ".html");
    }
    // for (String url : page.getDefinitions().getMapTypes().keySet()) {
    // spm.map(url, page.getDefinitions().getMapTypes().get(url).getPreamble());
    // }
    scanForImages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
    scanForPages(spm, page.getFolders().dstDir, page.getFolders().dstDir);
    for (String url : page.getDefinitions().getRedirectList().keySet()) {
        // http://hl7.org/fhir/ = 20 chars
        spm.target(url.substring(20));
    }
    spm.save(page.getFolders().dstDir + "spec.internals");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSet(org.hl7.fhir.r5.model.ValueSet) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Profile(org.hl7.fhir.definitions.model.Profile)

Example 70 with Resource

use of org.hl7.fhir.r4.model.Resource in project kindling by HL7.

the class Publisher method generateCodeSystemRegistry.

private void generateCodeSystemRegistry() throws FileNotFoundException, IOException, Exception {
    XmlParser xml = new XmlParser();
    xml.setOutputStyle(OutputStyle.PRETTY);
    Bundle bnd = (Bundle) xml.parse(new CSFileInputStream(Utilities.path(page.getFolders().srcDir, "namingsystem", "namingsystem-terminologies.xml")));
    for (BundleEntryComponent entry : bnd.getEntry()) {
        NamingSystem ns = (NamingSystem) entry.getResource();
        entry.setFullUrl("http://hl7.org/fhir/NamingSystem/" + ns.getId());
        String url = null;
        for (NamingSystemUniqueIdComponent t : ns.getUniqueId()) {
            if (t.getType() == NamingSystemIdentifierType.URI)
                url = t.getValue();
        }
        if (url != null) {
            if (url.startsWith("http://hl7.org/fhir"))
                page.getDefinitions().addNs(url, "System " + ns.getName(), "terminologies-systems.html#" + url);
            page.getDefinitions().addNs(entry.getFullUrl(), ns.getId(), "terminologies-systems.html#" + url);
        }
    }
    List<String> names = new ArrayList<String>();
    Set<String> urls = new HashSet<>();
    names.addAll(page.getCodeSystems().keys());
    Collections.sort(names);
    for (String n : names) {
        CodeSystem cs = page.getCodeSystems().get(n);
        if (cs != null && !urls.contains(cs.getUrl()) && cs.hasUrl() && !cs.getUrl().startsWith("http://terminology.hl7.org")) {
            urls.add(cs.getUrl());
            if (cs.hasName()) {
                NamingSystem ns = new NamingSystem();
                ns.setId(cs.getId());
                ns.setName(cs.getName());
                ns.setStatus(cs.getStatus());
                if (!ns.hasStatus())
                    ns.setStatus(PublicationStatus.DRAFT);
                ns.setKind(NamingSystemType.CODESYSTEM);
                ns.setPublisher(cs.getPublisher());
                for (ContactDetail c : cs.getContact()) {
                    ContactDetail nc = ns.addContact();
                    nc.setName(c.getName());
                    for (ContactPoint cc : c.getTelecom()) {
                        nc.getTelecom().add(cc);
                    }
                }
                ns.setDate(cs.getDate());
                if (!ns.hasDate())
                    ns.setDate(page.getGenDate().getTime());
                ns.setDescription(cs.getDescription());
                ns.addUniqueId().setType(NamingSystemIdentifierType.URI).setValue(cs.getUrl()).setPreferred(true);
                String oid = CodeSystemUtilities.getOID(cs);
                if (oid != null) {
                    if (oid.startsWith("urn:oid:"))
                        oid = oid.substring(8);
                    ns.addUniqueId().setType(NamingSystemIdentifierType.OID).setValue(oid).setPreferred(false);
                }
                ns.setUserData("path", cs.getUserData("path"));
                bnd.addEntry().setResource(ns).setFullUrl("http://hl7.org/fhir/" + ns.fhirType() + "/" + ns.getId());
            }
        }
    }
    xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.xml")), bnd);
    cloneToXhtml("namingsystem-terminologies", "Terminology Registry", false, "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
    xml.setOutputStyle(OutputStyle.CANONICAL);
    xml.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.xml")), bnd);
    JsonParser json = new JsonParser();
    json.setOutputStyle(OutputStyle.PRETTY);
    json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), bnd);
    jsonToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.json")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
    json.setOutputStyle(OutputStyle.CANONICAL);
    json.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.canonical.json")), bnd);
    RdfParser rdf = new RdfParser();
    rdf.setOutputStyle(OutputStyle.PRETTY);
    rdf.compose(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), bnd);
    ttlToXhtml("namingsystem-terminologies", "Terminology Registry", TextFile.fileToString(Utilities.path(page.getFolders().dstDir, "namingsystem-terminologies.ttl")), "resource-instance:NamingSystem", "Terminology Registry", null, wg("vocab"));
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"grid\">\r\n");
    b.append(" <tr>");
    b.append("<td><b>Name</b></td>");
    b.append("<td><b>Uri</b></td>");
    b.append("<td><b>OID</b></td>");
    b.append("</tr>\r\n");
    for (BundleEntryComponent entry : bnd.getEntry()) {
        NamingSystem ns = (NamingSystem) entry.getResource();
        String uri = "";
        String oid = "";
        for (NamingSystemUniqueIdComponent id : ns.getUniqueId()) {
            if (id.getType() == NamingSystemIdentifierType.URI)
                uri = id.getValue();
            if (id.getType() == NamingSystemIdentifierType.OID)
                oid = id.getValue();
        }
        String link = "terminologies-systems.html#" + uri;
        if (ns.getUserData("path") != null)
            link = ns.getUserString("path");
        b.append(" <tr>");
        b.append("<td><a href=\"" + link + "\">" + Utilities.escapeXml(ns.getName()) + "</a></td>");
        b.append("<td>" + Utilities.escapeXml(uri) + "</td>");
        b.append("<td>" + Utilities.escapeXml(oid) + "</td>");
        b.append("</tr>\r\n");
    }
    b.append("</table>\r\n");
    String html = TextFile.fileToString(page.getFolders().templateDir + "template-example.html").replace("<%example%>", b.toString()).replace("<%example-usage%>", "");
    html = page.processPageIncludes("namingsystem-terminologies.html", html, "resource-instance:NamingSystem", null, bnd, null, "Example", null, null, page.getDefinitions().getWorkgroups().get("fhir"));
    TextFile.stringToFile(html, page.getFolders().dstDir + "namingsystem-terminologies.html");
    cachePage("namingsystem-terminologies.html", html, "Registered Code Systems", false);
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) NamingSystemUniqueIdComponent(org.hl7.fhir.r5.model.NamingSystem.NamingSystemUniqueIdComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) Bundle(org.hl7.fhir.r5.model.Bundle) ArrayList(java.util.ArrayList) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) NamingSystem(org.hl7.fhir.r5.model.NamingSystem) FileOutputStream(java.io.FileOutputStream) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) HashSet(java.util.HashSet) JsonParser(org.hl7.fhir.r5.formats.JsonParser) RdfParser(org.hl7.fhir.r5.formats.RdfParser)

Aggregations

ArrayList (java.util.ArrayList)319 Resource (org.hl7.fhir.r4.model.Resource)312 Test (org.junit.jupiter.api.Test)297 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)270 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)230 FHIRException (org.hl7.fhir.exceptions.FHIRException)201 Test (org.junit.Test)190 IOException (java.io.IOException)181 Bundle (org.hl7.fhir.r4.model.Bundle)169 Date (java.util.Date)147 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)139 List (java.util.List)133 HashMap (java.util.HashMap)131 Patient (org.hl7.fhir.r4.model.Patient)118 FileOutputStream (java.io.FileOutputStream)110 Reference (org.hl7.fhir.r4.model.Reference)109 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)102 File (java.io.File)100 Collectors (java.util.stream.Collectors)95 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)92