Search in sources :

Example 66 with Bundle

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

use of org.hl7.fhir.r4.model.Bundle 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)

Example 68 with Bundle

use of org.hl7.fhir.r4.model.Bundle 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 69 with Bundle

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

the class Publisher method buildFeedsAndMaps.

private void buildFeedsAndMaps() {
    page.setResourceBundle(new Bundle());
    page.getResourceBundle().setId("resources");
    page.getResourceBundle().setType(BundleType.COLLECTION);
    page.getResourceBundle().setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
    profileBundle = new Bundle();
    profileBundle.setId("profiles-others");
    profileBundle.setType(BundleType.COLLECTION);
    profileBundle.setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
    page.setTypeBundle(new Bundle());
    page.getTypeBundle().setId("types");
    page.getTypeBundle().setType(BundleType.COLLECTION);
    page.getTypeBundle().setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
    valueSetsFeed = new Bundle();
    valueSetsFeed.setId("valuesets");
    valueSetsFeed.setType(BundleType.COLLECTION);
    valueSetsFeed.setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
    dataElements = new Bundle();
    dataElements.setId("dataelements");
    dataElements.setType(BundleType.COLLECTION);
    dataElements.setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
    conceptMapsFeed = new Bundle();
    conceptMapsFeed.setId("conceptmaps");
    conceptMapsFeed.setType(BundleType.COLLECTION);
    conceptMapsFeed.setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
    externals = new Bundle();
    externals.setId("externals");
    externals.setType(BundleType.COLLECTION);
    externals.setMeta(new Meta().setLastUpdated(page.getGenDate().getTime()));
}
Also used : Meta(org.hl7.fhir.r5.model.Meta) Bundle(org.hl7.fhir.r5.model.Bundle)

Example 70 with Bundle

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

the class Publisher method checkBundleURLs.

/**
 * This is not true of bundles generally, but it is true of all the
 * conformance bundles produced by the spec:
 *
 * all entries must have a fullUrl, and it must equal http://hl7.org/fhir/[type]/[id]
 *
 * @param bnd - the bundle to check
 */
private void checkBundleURLs(Bundle bnd) {
    int i = 0;
    for (BundleEntryComponent e : bnd.getEntry()) {
        i++;
        if (!e.getResource().hasUserData("external.url")) {
            if (!e.hasFullUrl())
                page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "no Full URL on entry " + Integer.toString(i), IssueSeverity.ERROR));
            else if (!e.getFullUrl().endsWith("/" + e.getResource().getResourceType().toString() + "/" + e.getResource().getId()) && e.getResource().getResourceType() != ResourceType.CodeSystem)
                page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "URL doesn't match resource and id on entry " + Integer.toString(i) + " : " + e.getFullUrl() + " should end with /" + e.getResource().getResourceType().toString() + "/" + e.getResource().getId(), IssueSeverity.ERROR));
            else if (!e.getFullUrl().equals("http://hl7.org/fhir/" + e.getResource().getResourceType().toString() + "/" + e.getResource().getId()) && e.getResource().getResourceType() != ResourceType.CodeSystem)
                page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "URL is non-FHIR " + Integer.toString(i) + " : " + e.getFullUrl() + " should start with http://hl7.org/fhir/ for HL7-defined artifacts", IssueSeverity.WARNING));
            if (e.getResource() instanceof CanonicalResource) {
                CanonicalResource m = (CanonicalResource) e.getResource();
                String url = m.getUrl();
                if (url != null && url.startsWith("http://hl7.org/fhir") && !SIDUtilities.isKnownSID(url)) {
                    if (!page.getVersion().toCode().equals(m.getVersion()))
                        page.getValidationErrors().add(new ValidationMessage(Source.Publisher, IssueType.INVALID, -1, -1, "Bundle " + bnd.getId(), "definitions in FHIR space should have the correct version (url = " + url + ", version = " + m.getVersion() + ")", IssueSeverity.ERROR));
                }
            }
        }
    }
}
Also used : BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Aggregations

Bundle (org.hl7.fhir.r4.model.Bundle)603 Bundle (org.hl7.fhir.dstu3.model.Bundle)357 Test (org.junit.Test)343 Test (org.junit.jupiter.api.Test)316 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)306 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)192 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)167 Date (java.util.Date)159 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)151 ArrayList (java.util.ArrayList)147 List (java.util.List)143 Resource (org.hl7.fhir.r4.model.Resource)128 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)116 HashMap (java.util.HashMap)113 Collectors (java.util.stream.Collectors)108 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)106 Patient (org.hl7.fhir.r4.model.Patient)93 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)85 Observation (org.hl7.fhir.r4.model.Observation)79 IOException (java.io.IOException)77