Skip to content

Commit

Permalink
Merge pull request #154 from MeasureAuthoringTool/MAT-6093-6107
Browse files Browse the repository at this point in the history
MAT-6093 MADiE measure exports - updates to IDs for measure and library resources
  • Loading branch information
adongare authored Sep 6, 2023
2 parents 53fe8e0 + da09b3a commit c0e1501
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public LibraryTranslatorService(LibraryCqlVisitorFactory libCqlVisitorFactory) {
public Library convertToFhirLibrary(CqlLibrary cqlLibrary) {
var visitor = libCqlVisitorFactory.visit(cqlLibrary.getCql());
Library library = new Library();
library.setId(cqlLibrary.getId());
library.setId(cqlLibrary.getCqlLibraryName());
library.setLanguage("en");
library.setName(cqlLibrary.getCqlLibraryName());
library.setVersion(cqlLibrary.getVersion().toString());
Expand All @@ -75,9 +75,6 @@ public Library convertToFhirLibrary(CqlLibrary cqlLibrary) {
identifier.setSystem("https://madie.cms.gov/login");
identifier.setValue(cqlLibrary.getId());
library.setIdentifier(List.of(identifier));

// TODO: probably have to revisit this. Human Readable feature is not yet ready
// result.setText(findHumanReadable(lib.getMeasureId()));
return library;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gov.cms.madie.madiefhirservice.constants.UriConstants;
import gov.cms.madie.madiefhirservice.hapi.HapiFhirServer;
import gov.cms.madie.madiefhirservice.utils.BundleUtil;
import gov.cms.madie.madiefhirservice.utils.FhirResourceHelpers;
import gov.cms.madie.madiefhirservice.utils.ResourceUtils;
import gov.cms.madie.models.library.CqlLibrary;
import gov.cms.madie.models.measure.Measure;
Expand Down Expand Up @@ -108,7 +109,14 @@ public List<Bundle.BundleEntryComponent> createBundleComponentsForLibrariesOfMad

/** Creates BundleEntryComponent for given resource */
public Bundle.BundleEntryComponent getBundleEntryComponent(Resource resource) {
return new Bundle.BundleEntryComponent().setResource(resource);
Bundle.BundleEntryRequestComponent requestComponent =
new Bundle.BundleEntryRequestComponent()
.setMethod(Bundle.HTTPVerb.PUT)
.setUrl(resource.getResourceType() + "/" + resource.getIdPart());
return new Bundle.BundleEntryComponent()
.setFullUrl(FhirResourceHelpers.getFullUrl(resource))
.setResource(resource)
.setRequest(requestComponent);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public org.hl7.fhir.r4.model.Measure createFhirMeasureForMadieMeasure(Measure ma
.setTitle(madieMeasure.getMeasureName())
.setIdentifier(buildMeasureIdentifiers(madieMeasure))
.setExperimental(madieMeasure.getMeasureMetaData().isExperimental())
.setUrl(FhirResourceHelpers.buildMeasureUrl(madieMeasure))
.setUrl(FhirResourceHelpers.buildMeasureUrl(madieMeasure.getCqlLibraryName()))
.setVersion(madieMeasure.getVersion().toString())
.setEffectivePeriod(
getPeriodFromDates(
Expand All @@ -75,7 +75,8 @@ public org.hl7.fhir.r4.model.Measure createFhirMeasureForMadieMeasure(Measure ma
.setRationale(rationale)
.setLibrary(
Collections.singletonList(
new CanonicalType(FhirResourceHelpers.buildLibraryUrl(madieMeasure))))
new CanonicalType(
FhirResourceHelpers.buildLibraryUrl(madieMeasure.getCqlLibraryName()))))
.setPurpose(UNKNOWN)
.setContact(buildContactDetail(madieMeasure.getMeasureMetaData().getSteward(), false))
.setGroup(buildGroups(madieMeasure.getGroups()))
Expand All @@ -90,7 +91,8 @@ public org.hl7.fhir.r4.model.Measure createFhirMeasureForMadieMeasure(Measure ma
.setClinicalRecommendationStatement(
madieMeasure.getMeasureMetaData().getClinicalRecommendation())
.setDate(Date.from(madieMeasure.getLastModifiedAt()))
.setMeta(buildMeasureMeta());
.setMeta(buildMeasureMeta())
.setId(madieMeasure.getCqlLibraryName());

for (Extension ext : buildExtensions(madieMeasure)) {
measure.addExtension(ext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public Map<String, Bundle> getTestCaseExportBundle(Measure measure, List<TestCas
var measureReport = buildMeasureReport(testCase, measure, bundle);
var bundleEntryComponent = FhirResourceHelpers.getBundleEntryComponent(measureReport);
bundleEntryComponent.setFullUrl(
"https://madie.cms.gov/MeasureReport/"
+ measure.getId()
+ "/"
+ testCase.getPatientId().toString());
"https://madie.cms.gov/MeasureReport/" + measureReport.getId());
bundle.getEntry().add(bundleEntryComponent);
testCaseBundle.put(fileName, bundle);
}
Expand All @@ -99,7 +96,7 @@ private MeasureReport buildMeasureReport(
measureReport.setModifierExtension(buildModifierExtension());
measureReport.setStatus(MeasureReport.MeasureReportStatus.COMPLETE);
measureReport.setType(MeasureReport.MeasureReportType.INDIVIDUAL);
measureReport.setMeasure(FhirResourceHelpers.buildMeasureUrl(measure));
measureReport.setMeasure(FhirResourceHelpers.buildMeasureUrl(measure.getCqlLibraryName()));
measureReport.setPeriod(
FhirResourceHelpers.getPeriodFromDates(
getUTCDates(measure.getMeasurementPeriodStart()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.cms.madie.madiefhirservice.utils;

import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import gov.cms.madie.models.measure.Measure;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
Expand All @@ -17,12 +16,18 @@
public class FhirResourceHelpers {

private static String fhirBaseUrl;
private static String madieUrl;

@Value("${fhir-base-url}")
public void setFhirBaseUrl(String url) {
FhirResourceHelpers.fhirBaseUrl = url;
}

@Value("${madie.url}")
public void setMadieUrl(String url) {
FhirResourceHelpers.madieUrl = url;
}

public static Bundle.BundleEntryComponent getBundleEntryComponent(Resource resource) {
return new Bundle.BundleEntryComponent().setResource(resource);
}
Expand All @@ -44,11 +49,22 @@ public static Coding buildCoding(String code, String system, String display) {
return new Coding().setCode(code).setSystem(system).setDisplay(display);
}

public static String buildMeasureUrl(Measure measure) {
return fhirBaseUrl + "/Measure/" + measure.getCqlLibraryName();
public static String buildMeasureUrl(String measureLibraryName) {
return madieUrl + "/Measure/" + measureLibraryName;
}

public static String buildLibraryUrl(String libraryName) {
return fhirBaseUrl + "/Library/" + libraryName;
}

public static String buildLibraryUrl(Measure measure) {
return fhirBaseUrl + "/Library/" + measure.getCqlLibraryName();
public static String getFullUrl(Resource resource) {
String resourceType = String.valueOf(resource.getResourceType());
if ("Measure".equals(resourceType)) {
return buildMeasureUrl(resource.getIdPart());
} else if ("Library".equals(resourceType)) {
return buildLibraryUrl(resource.getIdPart());
} else {
return null;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ madie:
baseUrl: ${CQL_LIBRARY_SERVICE_URL:http://localhost:8082/api}
versioned:
uri: /cql-libraries/versioned
url: ${MADIE_URL:https://madie.cms.gov}

#springdoc:
# swagger-ui:
# path: ${SWAGGER_PATH:/swagger}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public void convertToFhirLibrary() {
Identifier identifier = new Identifier();
identifier.setUse(IdentifierUse.OFFICIAL);
identifier.setSystem("https://madie.cms.gov/login");
identifier.setValue(library.getId());
identifier.setValue(cqlLibrary.getId());
assertThat(library.getIdentifier().get(0).getValue(), is(equalTo(identifier.getValue())));
assertThat(library.getIdentifier().get(0).getSystem(), is(equalTo(identifier.getSystem())));
assertThat(library.getIdentifier().get(0).getUse(), is(equalTo(identifier.getUse())));
assertThat(library.getId(), is(equalTo(cqlLibrary.getCqlLibraryName())));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -120,6 +119,15 @@ public void testCreateMeasureBundle() {
assertThat(measureLibrary.getName(), is(equalTo(madieMeasure.getCqlLibraryName())));
assertThat(measureLibrary.getContent(), is(notNullValue()));
assertThat(measureLibrary.getContent().size(), is(equalTo(2)));
Bundle.BundleEntryRequestComponent measureEntryRequest = bundle.getEntry().get(0).getRequest();
assertThat(
measureEntryRequest.getUrl(), is(equalTo("Measure/" + madieMeasure.getCqlLibraryName())));
assertThat(measureEntryRequest.getMethod(), is(equalTo(Bundle.HTTPVerb.PUT)));

Bundle.BundleEntryRequestComponent libraryEntryRequest = bundle.getEntry().get(1).getRequest();
assertThat(
libraryEntryRequest.getUrl(), is(equalTo("Library/" + madieMeasure.getCqlLibraryName())));
assertThat(libraryEntryRequest.getMethod(), is(equalTo(Bundle.HTTPVerb.PUT)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.core.JsonProcessingException;
import gov.cms.madie.madiefhirservice.constants.UriConstants;
Expand Down Expand Up @@ -83,6 +82,7 @@ public void setUp() throws JsonProcessingException {
getStringFromTestResource("/measures/SimpleFhirMeasureLib/madie_cv_measure.json");
madieCVMeasure = MeasureTestHelper.createMadieMeasureFromJson(cvMeasureJson);
ReflectionTestUtils.setField(fhirResourceHelpers, "fhirBaseUrl", "cms.gov");
ReflectionTestUtils.setField(fhirResourceHelpers, "madieUrl", "madie.cms.gov");
}

@Test
Expand All @@ -96,7 +96,7 @@ public void testCreateFhirMeasureForMadieMeasure() {
measure.getRationale(), is(equalTo(madieMeasure.getMeasureMetaData().getRationale())));
assertThat(measure.getPublisher(), is(equalTo("UNKNOWN")));
assertThat(
measure.getUrl(), is(equalTo("cms.gov/Measure/" + madieMeasure.getCqlLibraryName())));
measure.getUrl(), is(equalTo("madie.cms.gov/Measure/" + madieMeasure.getCqlLibraryName())));
assertThat(
DateFormatUtils.format(measure.getEffectivePeriod().getStart(), "MM/dd/yyyy"),
is(equalTo("01/01/2023")));
Expand Down Expand Up @@ -282,7 +282,8 @@ public void testCreateFhirMeasureForMadieRatioMeasure() {
assertThat(measure.getCopyright(), is(equalTo("testCopyright")));
assertThat(measure.getDisclaimer(), is(equalTo("testDisclaimer")));
assertThat(
measure.getUrl(), is(equalTo("cms.gov/Measure/" + madieRatioMeasure.getCqlLibraryName())));
measure.getUrl(),
is(equalTo("madie.cms.gov/Measure/" + madieRatioMeasure.getCqlLibraryName())));
assertThat(
DateFormatUtils.format(measure.getEffectivePeriod().getStart(), "MM/dd/yyyy"),
is(equalTo("01/01/2023")));
Expand Down Expand Up @@ -408,7 +409,8 @@ public void testCreateFhirMeasureForMadieCVMeasure() {
assertThat(
measure.getRationale(), is(equalTo(madieCVMeasure.getMeasureMetaData().getRationale())));
assertThat(
measure.getUrl(), is(equalTo("cms.gov/Measure/" + madieCVMeasure.getCqlLibraryName())));
measure.getUrl(),
is(equalTo("madie.cms.gov/Measure/" + madieCVMeasure.getCqlLibraryName())));
assertThat(
DateFormatUtils.format(measure.getEffectivePeriod().getStart(), "MM/dd/yyyy"),
is(equalTo("01/01/2022")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void setUp() throws JsonProcessingException {
madieMeasure = MeasureTestHelper.createMadieMeasureFromJson(madieMeasureJson);
testCase = Objects.requireNonNull(madieMeasure).getTestCases().get(0);
ReflectionTestUtils.setField(fhirResourceHelpers, "fhirBaseUrl", "cms.gov");
ReflectionTestUtils.setField(fhirResourceHelpers, "madieUrl", "madie.cms.gov");
}

@Test
Expand All @@ -73,12 +74,10 @@ void getTestCaseExportBundleMulti() {
exportMap.get(
"285d114d-9c36-4d66-b0a0-06f395bbf23d/title-v0.0.000-testcaseseries-testcasetitle");
assertEquals(5, bundle.getEntry().size());
MeasureReport measureReport = (MeasureReport) bundle.getEntry().get(4).getResource();
assertEquals(
"https://madie.cms.gov/MeasureReport/"
+ madieMeasure.getId()
+ "/285d114d-9c36-4d66-b0a0-06f395bbf23d",
"https://madie.cms.gov/MeasureReport/" + measureReport.getIdPart(),
bundle.getEntry().get(4).getFullUrl());
MeasureReport measureReport = (MeasureReport) bundle.getEntry().get(4).getResource();
assertEquals("MeasureReport", measureReport.getResourceType().toString());
assertEquals(
UriConstants.CqfTestCases.CQFM_TEST_CASES,
Expand All @@ -93,7 +92,7 @@ void getTestCaseExportBundleMulti() {
assertEquals("#test case title-parameters", reference.getReference());
assertEquals(MeasureReport.MeasureReportStatus.COMPLETE, measureReport.getStatus());
assertEquals(MeasureReport.MeasureReportType.INDIVIDUAL, measureReport.getType());
assertEquals("cms.gov/Measure/SimpleFhirMeasureLib", measureReport.getMeasure());
assertEquals("madie.cms.gov/Measure/SimpleFhirMeasureLib", measureReport.getMeasure());

assertEquals(
"01/01/2023", DateFormatUtils.format(measureReport.getPeriod().getStart(), "MM/dd/yyyy"));
Expand Down Expand Up @@ -143,7 +142,7 @@ void getTestCaseExportBundleMultiReducedResult() {
assertEquals("#test case title-parameters", reference.getReference());
assertEquals(MeasureReport.MeasureReportStatus.COMPLETE, measureReport.getStatus());
assertEquals(MeasureReport.MeasureReportType.INDIVIDUAL, measureReport.getType());
assertEquals("cms.gov/Measure/SimpleFhirMeasureLib", measureReport.getMeasure());
assertEquals("madie.cms.gov/Measure/SimpleFhirMeasureLib", measureReport.getMeasure());

assertEquals(
"01/01/2023", DateFormatUtils.format(measureReport.getPeriod().getStart(), "MM/dd/yyyy"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"resourceType": "Measure",
"id": "SimpleFhirMeasureLib",
"meta": {
"profile": [
"http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/proportion-measure-cqfm"
Expand Down

0 comments on commit c0e1501

Please sign in to comment.