@@ -31,15 +31,16 @@ import org.hl7.fhir.instance.model.api.IBaseParameters
31
31
import org.hl7.fhir.instance.model.api.IBaseResource
32
32
import org.hl7.fhir.r4.model.CanonicalType
33
33
import org.hl7.fhir.r4.model.IdType
34
+ import org.hl7.fhir.r4.model.Measure
34
35
import org.hl7.fhir.r4.model.MeasureReport
35
36
import org.hl7.fhir.r4.model.Parameters
36
37
import org.hl7.fhir.r4.model.PlanDefinition
37
38
import org.hl7.fhir.r4.model.Reference
38
39
import org.opencds.cqf.fhir.cql.EvaluationSettings
39
40
import org.opencds.cqf.fhir.cql.LibraryEngine
40
41
import org.opencds.cqf.fhir.cr.measure.MeasureEvaluationOptions
42
+ import org.opencds.cqf.fhir.cr.measure.common.MeasureEvalType
41
43
import org.opencds.cqf.fhir.cr.measure.common.MeasureReportType
42
- import org.opencds.cqf.fhir.cr.measure.r4.R4MeasureProcessor
43
44
import org.opencds.cqf.fhir.cr.plandefinition.PlanDefinitionProcessor
44
45
import org.opencds.cqf.fhir.utility.monad.Eithers
45
46
import org.opencds.cqf.fhir.utility.repository.ProxyRepository
@@ -72,8 +73,8 @@ internal constructor(
72
73
MeasureEvaluationOptions ().apply { evaluationSettings = this @FhirOperator.evaluationSettings }
73
74
74
75
private val libraryProcessor = LibraryEngine (repository, evaluationSettings)
76
+ private val measureProcessor = FhirEngineR4MeasureProcessor (repository, measureEvaluationOptions)
75
77
private val planDefinitionProcessor = PlanDefinitionProcessor (repository, evaluationSettings)
76
- private val measureProcessor = R4MeasureProcessor (repository, measureEvaluationOptions)
77
78
78
79
/* *
79
80
* The function evaluates a FHIR library against the database.
@@ -154,6 +155,58 @@ internal constructor(
154
155
return report
155
156
}
156
157
158
+ @WorkerThread
159
+ fun evaluateMeasure (
160
+ measure : Measure ,
161
+ start : String ,
162
+ end : String ,
163
+ reportType : String ,
164
+ subjectId : String? = null,
165
+ practitioner : String? = null,
166
+ additionalData : IBaseBundle ? = null,
167
+ parameters : Parameters ? = null,
168
+ ): MeasureReport {
169
+ val subject =
170
+ if (! practitioner.isNullOrBlank()) {
171
+ checkAndAddType(practitioner, " Practitioner" )
172
+ } else if (! subjectId.isNullOrBlank()) {
173
+ checkAndAddType(subjectId, " Patient" )
174
+ } else {
175
+ // List of null is required to run population-level measures
176
+ null
177
+ }
178
+
179
+ val subjectIds = listOf (subject)
180
+
181
+ val evalType =
182
+ MeasureEvalType .fromCode(reportType)
183
+ .orElse(
184
+ if (subjectIds.isNotEmpty() && subjectIds[0 ] != null ) {
185
+ MeasureEvalType .SUBJECT
186
+ } else {
187
+ MeasureEvalType .POPULATION
188
+ },
189
+ ) as MeasureEvalType
190
+
191
+ val report =
192
+ measureProcessor.evaluateMeasure(
193
+ /* measure = */ measure,
194
+ /* periodStart = */ start,
195
+ /* periodEnd = */ end,
196
+ /* reportType = */ reportType,
197
+ /* subjectIds = */ subjectIds,
198
+ /* additionalData = */ additionalData,
199
+ /* parameters = */ parameters,
200
+ /* evalType = */ evalType,
201
+ )
202
+
203
+ // add subject reference for non-individual reportTypes
204
+ if (report.type.name == MeasureReportType .SUMMARY .name && ! subject.isNullOrBlank()) {
205
+ report.setSubject(Reference (subject))
206
+ }
207
+ return report
208
+ }
209
+
157
210
/* *
158
211
* Generates a [CarePlan] based on the provided inputs.
159
212
*
0 commit comments