use of org.hl7.fhir.r4b.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);
}
use of org.hl7.fhir.r4b.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);
}
use of org.hl7.fhir.r4b.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()));
}
use of org.hl7.fhir.r4b.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()));
}
use of org.hl7.fhir.r4b.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));
}
}
}
}
}
Aggregations