use of org.hl7.fhir.r5.model.ParameterDefinition in project clinical_quality_language by cqframework.
the class DataRequirementsProcessorTest method TestLibraryDataRequirements.
@Test
public void TestLibraryDataRequirements() {
CqlTranslatorOptions cqlTranslatorOptions = new CqlTranslatorOptions();
cqlTranslatorOptions.getFormats().add(CqlTranslator.Format.JSON);
try {
// CqlTranslator translator = createTranslator("/ecqm/resources/library-EXM506-2.2.000.json", cqlTranslatorOptions);
CqlTranslator translator = createTranslator("CompositeMeasures/cql/BCSComponent.cql", cqlTranslatorOptions);
translator.toELM();
assertTrue(translator.getErrors().isEmpty());
libraryManager.cacheLibrary(translator.getTranslatedLibrary());
DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = dqReqTrans.gatherDataRequirements(libraryManager, translator.getTranslatedLibrary(), cqlTranslatorOptions, null, false);
assertTrue(moduleDefinitionLibrary.getType().getCode("http://terminology.hl7.org/CodeSystem/library-type").equalsIgnoreCase("module-definition"));
List<Extension> directReferenceCodes = moduleDefinitionLibrary.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode");
assertTrue(directReferenceCodes.size() == 5);
Extension directReferenceCode = directReferenceCodes.get(0);
Coding coding = directReferenceCode.getValueCoding();
assertEquals("http://loinc.org", coding.getSystem());
assertEquals("21112-8", coding.getCode());
assertEquals("Birth date", coding.getDisplay());
assertTrue(moduleDefinitionLibrary.getRelatedArtifact().size() >= 45);
RelatedArtifact loincCodeSystem = null;
for (RelatedArtifact relatedArtifact : moduleDefinitionLibrary.getRelatedArtifact()) {
if (relatedArtifact.getType() == RelatedArtifact.RelatedArtifactType.DEPENDSON && relatedArtifact.getResource() != null && relatedArtifact.getResource().equals("http://loinc.org")) {
loincCodeSystem = relatedArtifact;
break;
}
}
assertTrue(loincCodeSystem != null);
assertTrue(moduleDefinitionLibrary.getParameter().size() >= 16);
ParameterDefinition measurementPeriod = null;
for (ParameterDefinition parameter : moduleDefinitionLibrary.getParameter()) {
if (parameter.getName().equals("Measurement Period")) {
measurementPeriod = parameter;
break;
}
}
assertTrue(measurementPeriod != null);
assertTrue(moduleDefinitionLibrary.getDataRequirement().size() >= 15);
DataRequirement diagnosisRequirement = null;
for (DataRequirement requirement : moduleDefinitionLibrary.getDataRequirement()) {
if (requirement.getType() == Enumerations.FHIRAllTypes.CONDITION && requirement.getCodeFilter().size() == 1) {
DataRequirement.DataRequirementCodeFilterComponent cfc = requirement.getCodeFilterFirstRep();
if (cfc.hasPath() && cfc.getPath().equals("code") && cfc.hasValueSet() && cfc.getValueSet().equals("http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1071")) {
diagnosisRequirement = requirement;
break;
}
}
}
assertTrue(diagnosisRequirement != null);
FhirContext context = getFhirContext();
IParser parser = context.newJsonParser();
String moduleDefString = parser.setPrettyPrint(true).encodeResourceToString(moduleDefinitionLibrary);
logger.debug(moduleDefString);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project clinical_quality_language by cqframework.
the class DataRequirementsProcessor method extractParameters.
private List<ParameterDefinition> extractParameters(ElmRequirementsContext context, ElmRequirements requirements, VersionedIdentifier libraryIdentifier, Iterable<ExpressionDef> expressionDefs) {
List<ParameterDefinition> result = new ArrayList<>();
// TODO: Support library qualified parameters
// Until then, name clashes should result in a warning
Map<String, ParameterDefinition> pds = new HashMap<String, ParameterDefinition>();
for (ElmRequirement def : requirements.getParameterDefs()) {
ParameterDefinition pd = toParameterDefinition(def.getLibraryIdentifier(), (ParameterDef) def.getElement());
if (pds.containsKey(pd.getName())) {
ParameterDefinition existingPd = pds.get(pd.getName());
if (!isEquivalentDefinition(existingPd, pd)) {
// Issue a warning that the parameter has a duplicate name but an incompatible type
validationMessages.add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTSUPPORTED, "CQL Library Packaging", String.format("Parameter declaration %s.%s is already defined in a different library with a different type. Parameter binding may result in errors during evaluation.", def.getLibraryIdentifier().getId(), pd.getName()), ValidationMessage.IssueSeverity.WARNING));
}
} else {
pds.put(pd.getName(), pd);
result.add(pd);
}
}
for (ExpressionDef def : expressionDefs) {
if (def != null && !(def instanceof FunctionDef) && (def.getAccessLevel() == null || def.getAccessLevel() == AccessModifier.PUBLIC)) {
result.add(toOutputParameterDefinition(libraryIdentifier, def));
}
}
return result;
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class FHIRRestUtils method toMeasureParameterInfo.
private static MeasureParameterInfo toMeasureParameterInfo(ParameterDefinition parameterDefinition) {
MeasureParameterInfo retVal = new MeasureParameterInfo();
String defaultValue = complicatedTypes.contains(parameterDefinition.getType()) ? complicatedTypeValueConstructor(parameterDefinition) : null;
retVal.name(parameterDefinition.getName()).type(parameterDefinition.getType()).min(parameterDefinition.getMin()).max(parameterDefinition.getMax()).documentation(parameterDefinition.getDocumentation());
Optional.ofNullable(parameterDefinition.getUse()).map(ParameterUse::getDisplay).ifPresent(retVal::setUse);
parameterDefinition.getExtension().stream().filter(MeasureEvaluationSeeder::isDefaultValue).findFirst().map(Extension::getValue).map(x -> {
if (defaultValue != null) {
return defaultValue;
} else
return x.toString();
}).ifPresent(retVal::setDefaultValue);
return retVal;
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class FHIRRestUtilsTest method testConstructAppropriateJsonPeriod.
@Test
public void testConstructAppropriateJsonPeriod() {
ParameterDefinition definition = new ParameterDefinition();
definition.setType("Period");
Extension extension = new Extension();
extension.setUrl("http://ibm.com/fhir/cdm/StructureDefinition/default-value");
Period period = new Period();
Date startDate = Date.from(LocalDate.of(2020, 1, 1).atStartOfDay(ZoneId.systemDefault()).toInstant());
DateTimeType startElement = new DateTimeType(startDate, TemporalPrecisionEnum.DAY);
Date endDate = Date.from(LocalDate.of(2021, 1, 1).atStartOfDay(ZoneId.systemDefault()).toInstant());
DateTimeType endElement = new DateTimeType(endDate, TemporalPrecisionEnum.DAY);
period.setStartElement(startElement);
period.setEndElement(endElement);
extension.setValue(period);
List<Extension> extensions = new ArrayList<>();
extensions.add(extension);
definition.setExtension(extensions);
String defaultResult = FHIRRestUtils.complicatedTypeValueConstructor(definition);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
assertEquals("{\"start\":\"" + formatter.format(startDate) + "\",\"end\":\"" + formatter.format(endDate) + "\"}", defaultResult);
}
use of org.hl7.fhir.r5.model.ParameterDefinition in project quality-measure-and-cohort-service by Alvearie.
the class MeasureEvaluationSeeder method create.
public IMeasureEvaluationSeed create(Measure measure, String periodStart, String periodEnd, String productLine, Map<String, Parameter> parameters) {
// Gather the primary library and all of its dependencies
List<Library> fhirLibraries = libraryDependencyGatherer.gatherForMeasure(measure);
if (CollectionUtils.isEmpty(fhirLibraries)) {
throw new IllegalArgumentException(String.format("No libraries were able to be loaded for %s", measure.getId()));
}
// the "primary" library is always the first library loaded for the measure
Library primaryFhirLibrary = fhirLibraries.get(0);
VersionedIdentifier libraryIdentifier = new VersionedIdentifier().withId(primaryFhirLibrary.getName()).withVersion(primaryFhirLibrary.getVersion());
LibraryLoader libraryLoader = new R4TranslatingLibraryLoader(libraryResolver, new CqlToElmTranslator());
org.cqframework.cql.elm.execution.Library primaryLibrary = libraryLoader.load(libraryIdentifier);
List<Triple<String, String, String>> usingDefs = UsingHelper.getUsingUrlAndVersion(primaryLibrary.getUsings());
if (usingDefs.size() > 1) {
throw new IllegalArgumentException("Evaluation of Measure using multiple Models is not supported at this time.");
}
// Per the above condition, we should only have one model per measure
String lastModelUri = usingDefs.get(usingDefs.size() - 1).getRight();
DataProvider dataProvider = dataProviders.get(lastModelUri);
Context context = createContext(primaryLibrary, lastModelUri, dataProvider, productLine, libraryLoader);
// fhir path: Measure.extension[measureParameter][].valueParameterDefinition.extension[defaultValue]
measure.getExtension().stream().filter(MeasureEvaluationSeeder::isMeasureParameter).map(parameter -> dataProvider.resolvePath(parameter, "valueParameterDefinition")).map(ParameterDefinition.class::cast).forEach(parameterDefinition -> setDefaultValue(context, parameterDefinition));
if (parameters != null) {
parameters.entrySet().stream().forEach(e -> context.setParameter(null, e.getKey(), e.getValue().toCqlType()));
}
// Set measurement period last to make sure we respect periodStart
// and periodEnd date boundaries for an execution.
Interval measurementPeriod = createMeasurePeriod(periodStart, periodEnd);
context.setParameter(null, MEASUREMENT_PERIOD, measurementPeriod);
return new CustomMeasureEvaluationSeed(measure, context, measurementPeriod, dataProvider);
}
Aggregations