Skip to content

Commit

Permalink
Add in-process $evaluate endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
smailliwcs committed Feb 26, 2024
1 parent 81bbd9a commit d36e4b1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import com.lantanagroup.link.FhirDataProvider;
import com.lantanagroup.link.FhirHelper;
import com.lantanagroup.link.Helper;
import com.lantanagroup.link.api.MeasureServiceWrapper;
import com.lantanagroup.link.config.api.ApiConfig;
import com.lantanagroup.link.db.SharedService;
import com.lantanagroup.link.db.model.MeasureDefinition;
import com.lantanagroup.link.db.model.MeasurePackage;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -146,4 +147,34 @@ public void deleteMeasureDefinition(@PathVariable String measureId) {
}
});
}

@PostMapping("/{measureId}/$evaluate")
public MeasureReport evaluate(@PathVariable String measureId, @RequestBody Parameters parameters) {
MeasureDefinition measureDefinition = this.sharedService.getMeasureDefinition(measureId);

if (measureDefinition == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Could not find measure definition %s", measureId));
}

MeasureServiceWrapper measureServiceWrapper = new MeasureServiceWrapper(measureDefinition.getBundle(), null);

DateTimeType periodStart;
DateTimeType periodEnd;
StringType subject;
Bundle additionalData;
try {
periodStart = (DateTimeType) parameters.getParameterValue("periodStart");
periodEnd = (DateTimeType) parameters.getParameterValue("periodEnd");
subject = (StringType) parameters.getParameterValue("subject");
additionalData = (Bundle) parameters.getParameter("additionalData").getResource();
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Failed to parse request body", e);
}

return measureServiceWrapper.evaluate(
periodStart.asStringValue(),
periodEnd.asStringValue(),
subject.asStringValue(),
additionalData);
}
}
33 changes: 33 additions & 0 deletions api/src/main/resources/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,37 @@ paths:
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
/api/measureDef/{measureId}/$evaluate:
post:
tags:
- Measure Definitions
summary: Evaluates the measure using parameters provided in the request body. See the $evaluate-measure operation defined in the base FHIR spec.
operationId: evaluateMeasureDef
parameters:
- name: measureId
in: path
description: The measureId of the measure definition to be evaluated
required: true
schema:
type: string
requestBody:
required: true
description: FHIR Parameters resource containing periodStart, periodEnd, subject, and additionalData
content:
'application/json':
schema:
$ref: '#/components/schemas/FHIR.Parameters'
responses:
'200':
description: successful response with measure report returned
'400':
description: invalid parameters
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
/api/measurePackage:
get:
tags:
Expand Down Expand Up @@ -2588,6 +2619,8 @@ components:
type: array
items:
type: string
FHIR.Parameters:
type: object
FHIR.Extension:
type: object
properties:
Expand Down

0 comments on commit d36e4b1

Please sign in to comment.