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);
}
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);
}
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());
}
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");
}
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);
}
Aggregations