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