Skip to content

Commit

Permalink
WIP collect data
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Jan 30, 2022
1 parent 8142473 commit d2c8205
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"java.test.defaultConfig": "test-config",
"java.checkstyle.configuration": "${workspaceFolder}/config/checkstyle/checkstyle.xml",
"java.checkstyle.version": "9.21",
"java.checkstyle.version": "9.2.1",
"cSpell.enabledLanguageIds": [
"java",
"json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.opencds.cqf.ruler.utility.dstu3;

import org.hl7.fhir.dstu3.model.IdType;
import org.opencds.cqf.ruler.utility.Ids;

public class Parameters {

private Parameters() {
}

public static org.hl7.fhir.dstu3.model.Parameters newParameters(IdType theId,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.dstu3.model.Parameters p = newParameters(parts);
p.setId(theId);
return p;
}

public static org.hl7.fhir.dstu3.model.Parameters newParameters(String theIdPart,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
return newParameters((IdType) Ids.newId(org.hl7.fhir.dstu3.model.Parameters.class, theIdPart), parts);
}

public static org.hl7.fhir.dstu3.model.Parameters newParameters(
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.dstu3.model.Parameters p = new org.hl7.fhir.dstu3.model.Parameters();
for (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c : parts) {
p.addParameter(c);
}

return p;
}

public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = new org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent();
c.setName(name);
for (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent p : parts) {
c.addPart(p);
}

return c;
}

public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.dstu3.model.Type value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setValue(value);
return c;
}

public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.dstu3.model.Resource resource,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setResource(resource);
return c;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.opencds.cqf.ruler.utility.r4;

import org.hl7.fhir.r4.model.IdType;
import org.opencds.cqf.ruler.utility.Ids;

public class Parameters {

private Parameters() {
}

public static org.hl7.fhir.r4.model.Parameters newParameters(IdType theId,
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r4.model.Parameters p = newParameters(parts);
p.setId(theId);
return p;
}

public static org.hl7.fhir.r4.model.Parameters newParameters(String theIdPart,
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) {
return newParameters((IdType) Ids.newId(org.hl7.fhir.r4.model.Parameters.class, theIdPart), parts);
}

public static org.hl7.fhir.r4.model.Parameters newParameters(
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r4.model.Parameters p = new org.hl7.fhir.r4.model.Parameters();
for (org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c : parts) {
p.addParameter(c);
}

return p;
}

public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = new org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent();
c.setName(name);
for (org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent p : parts) {
c.addPart(p);
}

return c;
}

public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.r4.model.Type value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setValue(value);
return c;
}

public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.r4.model.Resource resource,
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setResource(resource);
return c;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.opencds.cqf.ruler.utility.r5;

import org.hl7.fhir.r5.model.IdType;
import org.opencds.cqf.ruler.utility.Ids;

public class Parameters {

private Parameters() {
}

public static org.hl7.fhir.r5.model.Parameters newParameters(IdType theId,
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r5.model.Parameters p = newParameters(parts);
p.setId(theId);
return p;
}

public static org.hl7.fhir.r5.model.Parameters newParameters(String theIdPart,
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) {
return newParameters((IdType) Ids.newId(org.hl7.fhir.r5.model.Parameters.class, theIdPart), parts);
}

public static org.hl7.fhir.r5.model.Parameters newParameters(
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r5.model.Parameters p = new org.hl7.fhir.r5.model.Parameters();
for (org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c : parts) {
p.addParameter(c);
}

return p;
}

public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = new org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent();
c.setName(name);
for (org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent p : parts) {
c.addPart(p);
}

return c;
}

public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.r5.model.DataType value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setValue(value);
return c;
}

public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.r5.model.Resource resource,
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setResource(resource);
return c;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ReferenceBuilder() {
public ReferenceBuilder buildReference(String reference) {
complexProperty.setReference(reference);
return this;
}
}

public ReferenceBuilder buildIdentifier(Identifier identifier) {
complexProperty.setIdentifier(identifier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.opencds.cqf.ruler.cr.r4.provider;

import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters;
import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart;

import java.util.ArrayList;
import java.util.List;

import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Measure;
import org.hl7.fhir.r4.model.MeasureReport;
Expand All @@ -27,45 +26,38 @@ public class CollectDataProvider extends DaoRegistryOperationProvider {
private MeasureEvaluateProvider measureEvaluateProvider;

@Operation(name = "$collect-data", idempotent = true, type = Measure.class)
public Parameters collectData(RequestDetails theRequestDetails, @IdParam IdType theId, @OperationParam(name = "periodStart") String periodStart,
@OperationParam(name = "periodEnd") String periodEnd, @OperationParam(name = "patient") String patientRef,
@OperationParam(name = "practitioner") String practitionerRef,
@OperationParam(name = "lastReceivedOn") String lastReceivedOn) throws FHIRException {
public Parameters collectData(RequestDetails theRequestDetails, @IdParam IdType theId,
@OperationParam(name = "periodStart") String periodStart,
@OperationParam(name = "periodEnd") String periodEnd, @OperationParam(name = "patient") String patientRef,
@OperationParam(name = "practitioner") String practitionerRef,
@OperationParam(name = "lastReceivedOn") String lastReceivedOn) {

MeasureReport report = measureEvaluateProvider.evaluateMeasure(theRequestDetails, theId, periodStart, periodEnd, null, patientRef, practitionerRef, lastReceivedOn, null);
report.setType(MeasureReport.MeasureReportType.DATACOLLECTION);
report.setGroup(null);
MeasureReport report = measureEvaluateProvider.evaluateMeasure(theRequestDetails, theId, periodStart, periodEnd,
null, patientRef, practitionerRef, lastReceivedOn, null);
report.setType(MeasureReport.MeasureReportType.DATACOLLECTION);
report.setGroup(null);

Parameters parameters = new Parameters();
parameters.addParameter(new Parameters.ParametersParameterComponent().setName("measureReport").setResource(report));
Parameters parameters = newParameters(newPart("measureReport", report));

addEvaluatedResourcesToParameters(report, parameters);
addEvaluatedResourcesToParameters(report, parameters);

return parameters;
return parameters;
}

private List<IAnyResource> addEvaluatedResources(MeasureReport report){
List<IAnyResource> resources = new ArrayList<>();
for (Reference evaluatedResource : report.getEvaluatedResource()) {
IIdType theEvaluatedId = evaluatedResource.getReferenceElement();
String resourceType = theEvaluatedId.getResourceType();
if (resourceType != null) {
IBaseResource resourceBase = getDaoRegistry().getResourceDao(resourceType).read(theEvaluatedId);
if (resourceBase instanceof Resource) {
Resource resource = (Resource) resourceBase;
resources.add(resource);
}
}
}
return resources;
private List<Resource> readEvaluatedResources(MeasureReport report) {
List<Resource> resources = new ArrayList<>();
for (Reference reference : report.getEvaluatedResource()) {
Resource resource = read(reference.getReferenceElement());
if (resource != null) {
resources.add(resource);
}
}

return resources;
}

private void addEvaluatedResourcesToParameters(MeasureReport report, Parameters parameters) {
List<IAnyResource> resources;
resources = addEvaluatedResources(report);
resources.forEach(resource -> {
parameters.addParameter(new Parameters.ParametersParameterComponent().setName("resource").setResource((Resource) resource));
}
);
readEvaluatedResources(report)
.forEach(resource -> parameters.addParameter(newPart("resource", resource)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.opencds.cqf.ruler.ra.RAConfig;
import org.opencds.cqf.ruler.ra.RAProperties;
import org.opencds.cqf.ruler.test.RestIntegrationTest;
import org.opencds.cqf.ruler.test.Urls;
import org.opencds.cqf.ruler.test.utility.Urls;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.opencds.cqf.ruler.behavior.IdCreator;
import org.opencds.cqf.ruler.behavior.ResourceCreator;
import org.opencds.cqf.ruler.test.behavior.ResourceLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.opencds.cqf.ruler.Application;
import org.opencds.cqf.ruler.behavior.IdCreator;
import org.opencds.cqf.ruler.behavior.ResourceCreator;
import org.opencds.cqf.ruler.test.behavior.ResourceLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Import;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.opencds.cqf.ruler.test;
package org.opencds.cqf.ruler.test.behavior;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -56,7 +56,7 @@ public default IBaseResource parseResource(String encoding, String resourceStrin
throw new IllegalArgumentException(
String.format("Expected encoding xml, or json. %s is not a valid encoding", encoding));
}

return parser.parseResource(resourceString);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.opencds.cqf.ruler.test;
package org.opencds.cqf.ruler.test.utility;

/**
* This interface provides test utility functions for creating IGenericClients
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.apache.commons.validator.routines.UrlValidator;
import org.junit.jupiter.api.Test;
import org.opencds.cqf.ruler.test.utility.Urls;

public class UrlsTest {
@Test
Expand Down

0 comments on commit d2c8205

Please sign in to comment.