use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testCQLTranslationCustomIGWithTargetUrl.
@Test
public void testCQLTranslationCustomIGWithTargetUrl() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
patient.addExtension(new Extension("http://fakeIg.com/fake-extension", new StringType("fakeValue")));
mockFhirResourceRetrieval(patient);
Library root = getLibrary("test", DEFAULT_RESOURCE_VERSION, "cql/ig-test/Test-1.0.0.cql");
Library helpers = getLibrary("FHIRHelpers", "4.0.0", "cql/fhir-helpers/FHIRHelpers.cql", "text/cql", "cql/fhir-helpers/FHIRHelpers.xml", "application/elm+json");
RelatedArtifact related = new RelatedArtifact();
related.setType(RelatedArtifactType.DEPENDSON);
related.setResource("/Library/" + helpers.getId());
root.addRelatedArtifact(related);
mockFhirResourceRetrieval(root);
mockFhirSingletonBundleRetrieval(helpers);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", root.getId(), "-l", root.getName(), "-v", root.getVersion(), "-c", patient.getId(), "-s", "CQL", "-i", "src/test/resources/modelinfo/ig-with-target-modelinfo-0.0.1.xml" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
System.out.println(output);
verify(1, getRequestedFor(urlEqualTo("/Patient/" + patient.getId() + "?_format=json")));
verify(1, getRequestedFor(urlEqualTo("/Library/" + root.getId() + "?_format=json")));
verify(1, getRequestedFor(urlEqualTo("/Library?url=%2FLibrary%2F" + helpers.getId() + "&_format=json")));
} finally {
tmpFile.delete();
}
}
use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.
the class SparkCqlEvaluator method createDataTypeAliases.
private Map<String, String> createDataTypeAliases(List<ContextDefinition> filteredContexts, CqlToElmTranslator translator) {
Set<String> dataTypes = filteredContexts.stream().map(ContextDefinition::getPrimaryDataType).collect(Collectors.toSet());
Collection<ModelInfo> modelInfos = translator.getRegisteredModelInfos().values();
Map<String, String> dataTypeAliases = new HashMap<>();
for (ModelInfo modelInfo : modelInfos) {
modelInfo.getTypeInfo().stream().filter(ClassInfo.class::isInstance).map(ClassInfo.class::cast).filter(classInfo -> dataTypes.contains(classInfo.getName())).forEach(info -> {
String dataType = info.getName();
QName baseType = ModelUtils.getBaseTypeName(modelInfo, info);
if (baseType != null) {
// for inheritance types
dataTypeAliases.put(dataType, baseType.getLocalPart());
}
Collection<String> choiceTypes = ModelUtils.getChoiceTypeNames(info);
// for choice types
choiceTypes.forEach(choiceType -> dataTypeAliases.put(dataType, choiceType));
});
}
return dataTypeAliases;
}
use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.
the class CustomModelInfoProvider method addModel.
protected void addModel(ModelInfo modelInfo) {
VersionedIdentifier modelId = new VersionedIdentifier().withId(modelInfo.getName()).withVersion(modelInfo.getVersion());
models.put(modelId, modelInfo);
}
use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.
the class ModelUtilsTest method testGetBaseTypeNameIncludedNamespacePrefixMissing.
@Test
public void testGetBaseTypeNameIncludedNamespacePrefixMissing() {
ModelSpecifier otherModel = new ModelSpecifier().withName("Other").withVersion("1.2.3").withUrl("urn:oid:Other");
ModelInfo modelInfo = new ModelInfo();
modelInfo.setName("Dummy");
modelInfo.setVersion("5.4.3");
modelInfo.setUrl("urn:oid:Dummy");
modelInfo.getRequiredModelInfo().add(otherModel);
ClassInfo typeInfo = new ClassInfo();
typeInfo.setName("MyType");
typeInfo.setBaseType("Missing.BaseType");
IllegalArgumentException iex = assertThrows(IllegalArgumentException.class, () -> ModelUtils.getBaseTypeName(modelInfo, typeInfo));
assertTrue(iex.getMessage(), iex.getMessage().contains("Missing"));
assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getName()));
assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getVersion()));
}
use of org.hl7.elm_modelinfo.r1.ModelInfo in project quality-measure-and-cohort-service by Alvearie.
the class ModelUtilsTest method testGetBaseTypeNameNoNamespacePrefix.
@Test
public void testGetBaseTypeNameNoNamespacePrefix() {
ModelInfo modelInfo = new ModelInfo();
modelInfo.setName("Dummy");
modelInfo.setUrl("urn:oid:Dummy");
ClassInfo typeInfo = new ClassInfo();
typeInfo.setName("MyType");
typeInfo.setBaseType("BaseType");
QName qname = ModelUtils.getBaseTypeName(modelInfo, typeInfo);
assertEquals(new QName(modelInfo.getUrl(), "BaseType"), qname);
}
Aggregations