Skip to content

Commit

Permalink
MAT-6093, MAT-6107 and MAT-6147
Browse files Browse the repository at this point in the history
  • Loading branch information
adongare committed Sep 6, 2023
1 parent 3f5276e commit 452a0fc
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 33 deletions.
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,11 +109,14 @@ public List<Bundle.BundleEntryComponent> createBundleComponentsForLibrariesOfMad

/** Creates BundleEntryComponent for given resource */
public Bundle.BundleEntryComponent getBundleEntryComponent(Resource resource) {
Bundle.HTTPVerb bundleVerb = Bundle.HTTPVerb.fromCode("PUT");
String url = resource.getResourceType() + "/" + resource.getId();
Bundle.BundleEntryRequestComponent requestComponent =
new Bundle.BundleEntryRequestComponent().setMethod(bundleVerb).setUrl(url);
return new Bundle.BundleEntryComponent().setResource(resource).setRequest(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 @@ -33,7 +33,6 @@
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.*;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import gov.cms.madie.madiefhirservice.constants.UriConstants;
Expand All @@ -46,9 +45,6 @@
public class MeasureTranslatorService {
public static final String UNKNOWN = "UNKNOWN";

@Value("${madie.url}")
private String madieUrl;

public org.hl7.fhir.r4.model.Measure createFhirMeasureForMadieMeasure(Measure madieMeasure) {
Organization steward = madieMeasure.getMeasureMetaData().getSteward();
String copyright = madieMeasure.getMeasureMetaData().getCopyright();
Expand All @@ -63,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 @@ -79,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 @@ -96,7 +93,6 @@ public org.hl7.fhir.r4.model.Measure createFhirMeasureForMadieMeasure(Measure ma
.setDate(Date.from(madieMeasure.getLastModifiedAt()))
.setMeta(buildMeasureMeta());
measure.setId(madieMeasure.getCqlLibraryName());
measure.setUrl(madieUrl + "/Measure/" + 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;
}
}
}
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,8 @@ 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, "fhirBaseUrl", "cms.gov");
ReflectionTestUtils.setField(fhirResourceHelpers, "madieUrl", "https://madie.cms.gov");
}

@Test
Expand All @@ -96,7 +97,8 @@ 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("https://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 +284,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("https://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 +411,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("https://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 452a0fc

Please sign in to comment.