Search in sources :

Example 11 with UriType

use of org.hl7.fhir.r4b.model.UriType in project cqf-ruler by DBCG.

the class ProcessMessageProvider method processMessageBundle.

@Operation(name = "$process-message-bundle", idempotent = false)
public Bundle processMessageBundle(HttpServletRequest theServletRequest, RequestDetails theRequestDetails, @OperationParam(name = "content", min = 1, max = 1) @Description(formalDefinition = "The message to process (or, if using asynchronous messaging, it may be a response message to accept)") Bundle theMessageToProcess) {
    logger.info("Validating the Bundle");
    Bundle bundle = theMessageToProcess;
    Boolean errorExists = false;
    OperationOutcome outcome = validateBundle(errorExists, bundle);
    if (!errorExists) {
        IVersionSpecificBundleFactory bundleFactory = this.getFhirContext().newBundleFactory();
        bundle.setId(getUUID());
        bundleFactory.initializeWithBundleResource(bundle);
        Bundle dafBundle = (Bundle) bundleFactory.getResourceBundle();
        dafBundle.setTimestamp(new Date());
        this.getDaoRegistry().getResourceDao(Bundle.class).create(dafBundle);
        MessageHeader messageHeader = null;
        String patientId = null;
        String commId = null;
        List<MessageHeader> headers = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, MessageHeader.class);
        for (MessageHeader mh : headers) {
            messageHeader = mh;
            messageHeader.setId(getUUID());
            Meta meta = messageHeader.getMeta();
            meta.setLastUpdated(new Date());
            messageHeader.setMeta(meta);
        }
        List<IBaseResource> resources = new ArrayList<>();
        List<Patient> patients = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Patient.class);
        for (Patient p : patients) {
            patientId = p.getId();
            p.setId(p.getIdElement().toVersionless());
            resources.add(p);
        }
        List<Bundle> bundles = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Bundle.class);
        for (Bundle b : bundles) {
            patientId = this.processBundle(b, theRequestDetails);
            b.setId(b.getIdElement().toVersionless());
            resources.add(b);
        }
        for (BundleEntryComponent e : bundle.getEntry()) {
            Resource r = e.getResource();
            if (r == null) {
                continue;
            }
            if (r.fhirType().equals("Bundle") || r.fhirType().equals("MessageHeader") || r.fhirType().equals("Patient")) {
                continue;
            }
            r.setId(r.getIdElement().toVersionless());
            resources.add(r);
        }
        if (patientId != null) {
            commId = constructAndSaveCommunication(patientId);
        }
        if (messageHeader == null) {
            messageHeader = constructMessageHeaderResource();
            BundleEntryComponent entryComp = new BundleEntryComponent();
            entryComp.setResource(messageHeader);
            dafBundle.addEntry(entryComp);
        }
        if (commId != null) {
            List<Reference> referenceList = new ArrayList<>();
            Reference commRef = new Reference();
            commRef.setReference("Communication/" + commId);
            referenceList.add(commRef);
            messageHeader.setFocus(referenceList);
        }
        IVersionSpecificBundleFactory newBundleFactory = this.getFhirContext().newBundleFactory();
        newBundleFactory.addResourcesToBundle(resources, BundleTypeEnum.TRANSACTION, theRequestDetails.getFhirServerBase(), null, null);
        Bundle transactionBundle = (Bundle) newBundleFactory.getResourceBundle();
        for (BundleEntryComponent entry : transactionBundle.getEntry()) {
            UriType uri = new UriType(theRequestDetails.getFhirServerBase() + "/" + entry.getResource().fhirType() + "/" + entry.getResource().getIdElement().getIdPart());
            Enumeration<HTTPVerb> method = new Enumeration<>(new HTTPVerbEnumFactory());
            method.setValue(HTTPVerb.PUT);
            entry.setRequest(new BundleEntryRequestComponent(method, uri));
        }
        @SuppressWarnings("unchecked") IFhirSystemDao<Bundle, Meta> fhirSystemDao = this.getDaoRegistry().getSystemDao();
        fhirSystemDao.transaction(theRequestDetails, transactionBundle);
        return dafBundle;
    } else {
        BundleEntryComponent entryComp = new BundleEntryComponent();
        entryComp.setResource(outcome);
        bundle.addEntry(entryComp);
        return bundle;
    }
}
Also used : HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) Meta(org.hl7.fhir.r4.model.Meta) ArrayList(java.util.ArrayList) UriType(org.hl7.fhir.r4.model.UriType) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Enumeration(org.hl7.fhir.r4.model.Enumeration) Bundle(org.hl7.fhir.r4.model.Bundle) Reference(org.hl7.fhir.r4.model.Reference) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) IVersionSpecificBundleFactory(ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory) Patient(org.hl7.fhir.r4.model.Patient) HTTPVerbEnumFactory(org.hl7.fhir.r4.model.Bundle.HTTPVerbEnumFactory) Date(java.util.Date) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) MessageHeader(org.hl7.fhir.r4.model.MessageHeader) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 12 with UriType

use of org.hl7.fhir.r4b.model.UriType in project cqf-ruler by DBCG.

the class OAuthProvider method extend.

@Override
public void extend(CapabilityStatement metadata) {
    metadata.getRestFirstRep().getSecurity().setCors(securityProperties.getOAuth().getSecurityCors());
    Extension securityExtension = metadata.getRestFirstRep().getSecurity().addExtension();
    securityExtension.setUrl(securityProperties.getOAuth().getSecurityUrl());
    // security.extension.extension
    Extension securityExtExt = securityExtension.addExtension();
    securityExtExt.setUrl(securityProperties.getOAuth().getSecurityExtAuthUrl());
    securityExtExt.setValue(new UriType(securityProperties.getOAuth().getSecurityExtAuthValueUri()));
    Extension securityTokenExt = securityExtension.addExtension();
    securityTokenExt.setUrl(securityProperties.getOAuth().getSecurityExtTokenUrl());
    securityTokenExt.setValue(new UriType(securityProperties.getOAuth().getSecurityExtTokenValueUri()));
    // security.extension.service
    Coding coding = new Coding();
    coding.setSystem(securityProperties.getOAuth().getServiceSystem());
    coding.setCode(securityProperties.getOAuth().getServiceCode());
    coding.setDisplay(securityProperties.getOAuth().getServiceDisplay());
    CodeableConcept codeConcept = new CodeableConcept();
    codeConcept.addCoding(coding);
    metadata.getRestFirstRep().getSecurity().getService().add(codeConcept);
// metadata.getRestFirstRep().getSecurity().getService() //how do we handle "text" on the sample not part of getService
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Coding(org.hl7.fhir.dstu3.model.Coding) UriType(org.hl7.fhir.dstu3.model.UriType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 13 with UriType

use of org.hl7.fhir.r4b.model.UriType in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluatorTest method measure_report_generated___FHIR_measure_parameters_on_measure_report.

@Test
public void measure_report_generated___FHIR_measure_parameters_on_measure_report() throws Exception {
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("TestDummyPopulations", DEFAULT_VERSION, "cql/fhir-measure/test-dummy-populations.xml", ELM_MIME_TYPE);
    Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
    Map<String, Type> measureParameters = new HashMap<>();
    measureParameters.put("base64Param", new Base64BinaryType("AAA"));
    measureParameters.put("booleanParam", new BooleanType(false));
    measureParameters.put("dateParam", new DateType("2020-01-01"));
    measureParameters.put("dateTimeParam", new DateTimeType("2020-01-01T12:00:00"));
    measureParameters.put("decimalParam", new DecimalType(12.0));
    measureParameters.put("instantParam", new InstantType("2020-01-01T12:00:00-04:00"));
    measureParameters.put("integerParam", new IntegerType(1));
    measureParameters.put("stringParam", new StringType("str"));
    measureParameters.put("timeParam", new TimeType("05:30:00"));
    measureParameters.put("uriParam", new UriType("abcde"));
    measureParameters.put("codeableConceptParam", new CodeableConcept().setText("display").addCoding(new Coding().setCode("val").setSystem("sys").setDisplay("display")));
    measureParameters.put("codingParam", new Coding().setCode("v").setSystem("s").setDisplay("d"));
    measureParameters.put("periodParam", new Period().setStart(new Date(1)).setEnd(new Date(2)));
    measureParameters.put("quantityParam", new Quantity().setValue(1).setUnit("g"));
    measureParameters.put("rangeParam", new Range().setLow(new Quantity().setUnit("g").setValue(1)).setHigh(new Quantity().setUnit("g").setValue(5)));
    measureParameters.put("ratioParam", new Ratio().setNumerator(new Quantity().setUnit("g").setValue(1)).setDenominator(new Quantity().setUnit("g").setValue(5)));
    List<Extension> parameterExtensions = measureParameters.entrySet().stream().map(x -> createMeasureParameter(x.getKey(), x.getValue())).collect(Collectors.toList());
    measure.setExtension(parameterExtensions);
    mockFhirResourceRetrieval(measure);
    MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null);
    assertNotNull(report);
    List<String> parameterNames = report.getExtension().stream().filter(x -> x.getUrl().equals(MEASURE_PARAMETER_VALUE_URL)).map(x -> (ParameterDefinition) x.getValue()).map(ParameterDefinition::getName).collect(Collectors.toList());
    // Expected parameters are the ones listed above, plus the special parameters
    // measurement period and product line
    assertEquals(measureParameters.size() + 2, parameterNames.size());
    assertTrue(parameterNames.containsAll(measureParameters.keySet()));
    assertTrue(parameterNames.contains(CDMConstants.MEASUREMENT_PERIOD));
    assertTrue(parameterNames.contains(CDMConstants.PRODUCT_LINE));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_VALUE_URL) Range(org.hl7.fhir.r4.model.Range) StringUtils(org.apache.commons.lang3.StringUtils) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) InvalidOperatorArgument(org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) HumanName(org.hl7.fhir.r4.model.HumanName) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Map(java.util.Map) StringType(org.hl7.fhir.r4.model.StringType) Assert.fail(org.junit.Assert.fail) ParseException(java.text.ParseException) IntegerType(org.hl7.fhir.r4.model.IntegerType) Patient(org.hl7.fhir.r4.model.Patient) DefineReturnOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) DateType(org.hl7.fhir.r4.model.DateType) TimeZone(java.util.TimeZone) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Period(org.hl7.fhir.r4.model.Period) MEASURE_PARAMETER_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_URL) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Collectors(java.util.stream.Collectors) PARAMETER_DEFAULT_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_DEFAULT_URL) TimeType(org.hl7.fhir.r4.model.TimeType) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Assert.assertFalse(org.junit.Assert.assertFalse) Coding(org.hl7.fhir.r4.model.Coding) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Extension(org.hl7.fhir.r4.model.Extension) UriType(org.hl7.fhir.r4.model.UriType) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) Measure(org.hl7.fhir.r4.model.Measure) ArrayList(java.util.ArrayList) Address(org.hl7.fhir.r4.model.Address) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) MEASURE_PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_VALUE_URL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Quantity(org.hl7.fhir.r4.model.Quantity) Ratio(org.hl7.fhir.r4.model.Ratio) MeasureSupplementalDataEvaluation(com.ibm.cohort.engine.cqfruler.MeasureSupplementalDataEvaluation) DecimalType(org.hl7.fhir.r4.model.DecimalType) Before(org.junit.Before) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ListResource(org.hl7.fhir.r4.model.ListResource) Library(org.hl7.fhir.r4.model.Library) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.Test) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) CDMConstants(com.ibm.cohort.engine.cdm.CDMConstants) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) StringType(org.hl7.fhir.r4.model.StringType) TimeType(org.hl7.fhir.r4.model.TimeType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) UriType(org.hl7.fhir.r4.model.UriType) Coding(org.hl7.fhir.r4.model.Coding) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Range(org.hl7.fhir.r4.model.Range) Date(java.util.Date) IntegerType(org.hl7.fhir.r4.model.IntegerType) Extension(org.hl7.fhir.r4.model.Extension) StringType(org.hl7.fhir.r4.model.StringType) IntegerType(org.hl7.fhir.r4.model.IntegerType) DateType(org.hl7.fhir.r4.model.DateType) TimeType(org.hl7.fhir.r4.model.TimeType) BooleanType(org.hl7.fhir.r4.model.BooleanType) UriType(org.hl7.fhir.r4.model.UriType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) DecimalType(org.hl7.fhir.r4.model.DecimalType) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalType(org.hl7.fhir.r4.model.DecimalType) Library(org.hl7.fhir.r4.model.Library) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 14 with UriType

use of org.hl7.fhir.r4b.model.UriType in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testUri__shouldReturnStringParameter.

@Test
public void testUri__shouldReturnStringParameter() {
    ParameterDefinition parameterDefinition = getBaseParameterDefinition("uri");
    String uriString = "a-b-c-d-e-f-g";
    UriType fhirValue = new UriType(uriString);
    parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
    assertEquals(new StringParameter(uriString), R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
Also used : StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) UriType(org.hl7.fhir.r4.model.UriType) Test(org.junit.Test)

Example 15 with UriType

use of org.hl7.fhir.r4b.model.UriType in project quality-measure-and-cohort-service by Alvearie.

the class R4RestFhirTerminologyProvider method lookup.

/**
 * This is a small patch to the OSS implementation to use named-parameter lookup on
 * the operation response instead of just assuming a positional location.
 */
@Override
public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException {
    Parameters respParam = fhirClient.operation().onType(CodeSystem.class).named("lookup").withParameter(Parameters.class, "code", new CodeType(code.getCode())).andParameter("system", new UriType(codeSystem.getId())).execute();
    StringType display = (StringType) respParam.getParameter("display");
    if (display != null) {
        code.withDisplay(display.getValue());
    }
    return code.withSystem(codeSystem.getId());
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) CodeType(org.hl7.fhir.r4.model.CodeType) UriType(org.hl7.fhir.r4.model.UriType)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)60 UriType (org.hl7.fhir.r5.model.UriType)45 ArrayList (java.util.ArrayList)42 UriType (org.hl7.fhir.r4.model.UriType)41 UriType (org.hl7.fhir.r4b.model.UriType)29 UriType (org.hl7.fhir.dstu3.model.UriType)26 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)22 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)19 List (java.util.List)17 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)15 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 UriType (org.hl7.fhir.dstu2016may.model.UriType)12 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)12 Coding (org.hl7.fhir.r4.model.Coding)12 IOException (java.io.IOException)11 StringType (org.hl7.fhir.r4.model.StringType)10 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)10 StringType (org.hl7.fhir.r5.model.StringType)10