use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class R4RestFhirTerminologyProviderTest method inOperationReturnsFalseWhenFhirReturnsFalse.
@Test
public void inOperationReturnsFalseWhenFhirReturnsFalse() throws Exception {
ValueSetInfo info = new ValueSetInfo();
info.setId("urn:oid:Test");
Code code = new Code();
code.setSystem(TEST_SYSTEM);
code.setCode(TEST_CODE);
code.setDisplay(TEST_DISPLAY);
Parameters parameters = new Parameters();
parameters.getParameterFirstRep().setName("result").setValue(new BooleanType(false));
mockFhirResourceRetrieval("/ValueSet/Test/$validate-code?code=" + urlencode(code.getCode()) + "&system=" + urlencode(code.getSystem()) + "&_format=json", parameters);
boolean result = provider.in(code, info);
assertFalse(result);
}
use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class R4RestFhirTerminologyProviderTest method expandOperationReturnsCorrectCodesMoreThanZero.
@Test
public void expandOperationReturnsCorrectCodesMoreThanZero() {
ValueSetInfo info = new ValueSetInfo();
info.setId("urn:oid:Test");
ValueSet valueSet = new ValueSet();
valueSet.setId("Test");
valueSet.getExpansion().getContainsFirstRep().setSystem(TEST_SYSTEM).setCode(TEST_CODE);
Parameters parameters = new Parameters();
parameters.getParameterFirstRep().setName("return").setResource(valueSet);
mockFhirResourceRetrieval("/ValueSet/Test/$expand?_format=json", parameters);
Iterable<Code> codes = provider.expand(info);
List<Code> list = StreamSupport.stream(codes.spliterator(), false).collect(Collectors.toList());
assertEquals(list.size(), 1);
assertEquals(list.get(0).getSystem(), TEST_SYSTEM);
assertEquals(list.get(0).getCode(), TEST_CODE);
}
use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class R4RestFhirTerminologyProviderTest method inOperationReturnsTrueWhenFhirReturnsTrue.
@Test
public void inOperationReturnsTrueWhenFhirReturnsTrue() throws Exception {
ValueSetInfo info = new ValueSetInfo();
info.setId("urn:oid:Test");
Code code = new Code();
code.setSystem(TEST_SYSTEM);
code.setCode(TEST_CODE);
code.setDisplay(TEST_DISPLAY);
Parameters parameters = new Parameters();
parameters.getParameterFirstRep().setName("result").setValue(new BooleanType(true));
mockFhirResourceRetrieval("/ValueSet/Test/$validate-code?code=" + urlencode(code.getCode()) + "&system=" + urlencode(code.getSystem()) + "&_format=json", parameters);
boolean result = provider.in(code, info);
assertTrue(result);
}
use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class R4FileSystemFhirTerminologyProvider method in.
/* (non-Javadoc)
*
* Returns true if the provided code exists in the provided ValueSet
*
* @see org.opencds.cqf.cql.engine.terminology.TerminologyProvider#in(org.opencds.cqf.cql.engine.runtime.Code, org.opencds.cqf.cql.engine.terminology.ValueSetInfo)
*/
@Override
public boolean in(Code code, ValueSetInfo valueSetInfo) {
LOG.debug("Entry: in() ValueSet.getId=[{}] version=[{}]", valueSetInfo.getId(), valueSetInfo.getVersion());
loadFromFile(valueSetInfo);
VersionedIdentifier valueSetIdentifier = createVersionedIdentifierForValueSet(valueSetInfo);
// get the valueSet codes from the cache if it is there
Map<String, Set<String>> codesToCodeSystems = valueSetToCodesCache.get(valueSetIdentifier);
if (codesToCodeSystems != null) {
Set<String> systems = codesToCodeSystems.get(code.getCode());
// if systems is null/empty, then the code isn't in the valueset
if (systems != null && !systems.isEmpty()) {
if (code.getSystem() == null) {
// are codes with more than 1 codesystem present in the valueset, throw an error
if (systems.size() > 1) {
throw new IllegalArgumentException("Ambiguous code lookup of code[" + code.getCode() + "] under valueset[" + valueSetIdentifier.getId() + "]");
} else {
return true;
}
} else {
return systems.contains(code.getSystem());
}
}
}
LOG.debug("Exit: in() ValueSet.getId=[{}] version=[{}]", valueSetInfo.getId(), valueSetInfo.getVersion());
return false;
}
use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.
the class ValueSetUtil method createArtifact.
public static ValueSetArtifact createArtifact(InputStream is, Map<String, String> customCodeSystem) throws IOException {
XSSFSheet informationSheet;
try (XSSFWorkbook wb = new XSSFWorkbook(is)) {
informationSheet = wb.getSheetAt(wb.getSheetIndex("Expansion List"));
} catch (IllegalArgumentException e) {
throw new RuntimeException("Spreadsheet is missing required sheet \"Expansion List\"", e);
}
ValueSet valueSet = new ValueSet();
boolean inCodesSection = false;
valueSet.setStatus(Enumerations.PublicationStatus.ACTIVE);
HashMap<CodeSystemKey, List<ValueSet.ConceptReferenceComponent>> codeSystemToCodes = new HashMap<>();
String url = "http://cts.nlm.nih.gov/fhir/ValueSet/";
String identifier = null;
for (Row currentRow : informationSheet) {
String code = currentRow.getCell(0) == null ? "" : currentRow.getCell(0).getStringCellValue();
if (!code.equals("") && currentRow.getCell(1) != null && !inCodesSection) {
String value;
switch(currentRow.getCell(1).getCellType()) {
case NUMERIC:
value = Double.toString(currentRow.getCell(1).getNumericCellValue());
break;
case STRING:
value = currentRow.getCell(1).getStringCellValue();
break;
default:
throw new RuntimeException("Cell type does not match either String or Numeric for key " + code);
}
switch(currentRow.getCell(0).getStringCellValue().toLowerCase()) {
case "value set name":
valueSet.setName(value);
valueSet.setTitle(value);
break;
case "id":
valueSet.setId(value);
identifier = value;
break;
case "oid":
if (valueSet.getId() == null) {
valueSet.setId(value);
identifier = value;
}
break;
case "url":
// fallthrough
url = value.endsWith("/") ? value : value + "/";
case "definition version":
valueSet.setVersion(value);
break;
case "code":
inCodesSection = true;
break;
default:
break;
}
} else if (inCodesSection) {
String display = currentRow.getCell(1).getStringCellValue();
String codeSystemEntry = currentRow.getCell(2).getStringCellValue();
String codeSystemVersion = currentRow.getCell(3).getStringCellValue();
String codeSystem;
if (codeSystemEntry.startsWith("http://") || codeSystemEntry.startsWith("https://")) {
codeSystem = codeSystemEntry;
} else if (customCodeSystem != null && customCodeSystem.get(codeSystemEntry) != null) {
codeSystem = customCodeSystem.get(codeSystemEntry);
} else {
codeSystem = CodeSystemLookup.getUrlFromName(codeSystemEntry);
}
if (codeSystem == null) {
throw new IllegalArgumentException("Unmatched Code System! " + codeSystemEntry + " not found!");
}
ValueSet.ConceptReferenceComponent concept = new ValueSet.ConceptReferenceComponent();
concept.setCode(code);
concept.setDisplay(display);
List<ValueSet.ConceptReferenceComponent> conceptsSoFar = codeSystemToCodes.computeIfAbsent(new CodeSystemKey(codeSystem, codeSystemVersion), x -> new ArrayList<>());
conceptsSoFar.add(concept);
}
}
if (identifier == null || identifier.equals("")) {
throw new RuntimeException("There must be an Identifier specified! Please populate the ID field");
}
valueSet.setUrl(url + identifier);
valueSet.setId(identifier);
ValueSet.ValueSetComposeComponent compose = new ValueSet.ValueSetComposeComponent();
for (Entry<CodeSystemKey, List<ConceptReferenceComponent>> singleInclude : codeSystemToCodes.entrySet()) {
ValueSet.ConceptSetComponent component = new ValueSet.ConceptSetComponent();
component.setSystem(singleInclude.getKey().getCodeSystem());
component.setVersion(singleInclude.getKey().getCodeSystemVersion());
component.setConcept(singleInclude.getValue());
compose.addInclude(component);
}
valueSet.setCompose(compose);
ValueSetArtifact artifact = new ValueSetArtifact();
artifact.setName(valueSet.getName());
artifact.setFhirResource(valueSet);
artifact.setUrl(valueSet.getUrl());
return artifact;
}
Aggregations