Search in sources :

Example 61 with Range

use of org.hl7.fhir.r4b.model.Range in project elexis-server by elexis.

the class EncounterResourceProvider method searchReqPatientOptDate.

/**
 * Search for all encounters by the patient id. Optional the date range of the returned
 * encounters can be specified.
 *
 * @param thePatientId
 * @param dates
 * @return
 */
@Search
public List<Encounter> searchReqPatientOptDate(@RequiredParam(name = Encounter.SP_PATIENT) IdType thePatientId, @OptionalParam(name = Encounter.SP_DATE) DateRangeParam dates, @IncludeParam(allow = { "Encounter.diagnosis" }) Set<Include> theIncludes) {
    if (thePatientId != null && !thePatientId.isEmpty()) {
        Optional<IPatient> patient = coreModelService.load(thePatientId.getIdPart(), IPatient.class);
        if (patient.isPresent()) {
            if (patient.get().isPatient()) {
                // migrate encounters first
                migratorService.migratePatientsFindings(thePatientId.getIdPart(), IEncounter.class, null);
                List<IEncounter> findings = findingsService.getPatientsFindings(patient.get().getId(), IEncounter.class);
                if (findings != null && !findings.isEmpty()) {
                    List<Encounter> ret = new ArrayList<Encounter>();
                    for (IEncounter iFinding : findings) {
                        Optional<Encounter> fhirEncounter = getTransformer().getFhirObject(iFinding);
                        fhirEncounter.ifPresent(fe -> {
                            if (dates != null) {
                                if (!DateRangeParamUtil.isPeriodInRange(fe.getPeriod(), dates)) {
                                    return;
                                }
                            }
                            ret.add(fe);
                        });
                    }
                    return ret;
                }
            }
        }
    }
    return null;
}
Also used : IEncounter(ch.elexis.core.findings.IEncounter) ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.r4.model.Encounter) IEncounter(ch.elexis.core.findings.IEncounter) IPatient(ch.elexis.core.model.IPatient) Search(ca.uhn.fhir.rest.annotation.Search)

Example 62 with Range

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

the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.

public static Parameter toCohortParameter(Extension extension) {
    Parameter parameter;
    Type extensionValue = extension.getValue();
    if (extensionValue instanceof Base64BinaryType) {
        parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
    } else if (extensionValue instanceof BooleanType) {
        parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
    } else if (extensionValue instanceof DateType) {
        parameter = new DateParameter(((DateType) extensionValue).asStringValue());
    } else if (extensionValue instanceof DateTimeType) {
        parameter = convertDateTimeType((DateTimeType) extensionValue);
    } else if (extensionValue instanceof DecimalType) {
        parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof InstantType) {
        parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof IntegerType) {
        parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
    } else if (extensionValue instanceof StringType) {
        parameter = new StringParameter(((StringType) extensionValue).getValue());
    } else if (extensionValue instanceof TimeType) {
        parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
    } else if (extensionValue instanceof UriType) {
        parameter = new StringParameter(((UriType) extensionValue).getValue());
    } else if (extensionValue instanceof Coding) {
        parameter = convertCoding((Coding) extensionValue);
    } else if (extensionValue instanceof CodeableConcept) {
        parameter = convertCodeableConcept((CodeableConcept) extensionValue);
    } else if (extensionValue instanceof Period) {
        Period castValue = (Period) extensionValue;
        parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
    } else if (extensionValue instanceof Quantity) {
        parameter = convertQuantity((Quantity) extensionValue);
    } else if (extensionValue instanceof Range) {
        Range castValue = (Range) extensionValue;
        parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
    } else if (extensionValue instanceof Ratio) {
        Ratio castValue = (Ratio) extensionValue;
        parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
    } else {
        throw new UnsupportedFhirTypeException(extensionValue);
    }
    return parameter;
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringType(org.hl7.fhir.r4.model.StringType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TimeType(org.hl7.fhir.r4.model.TimeType) UriType(org.hl7.fhir.r4.model.UriType) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Coding(org.hl7.fhir.r4.model.Coding) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) BooleanType(org.hl7.fhir.r4.model.BooleanType) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) Range(org.hl7.fhir.r4.model.Range) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) IntegerType(org.hl7.fhir.r4.model.IntegerType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) StringType(org.hl7.fhir.r4.model.StringType) DecimalType(org.hl7.fhir.r4.model.DecimalType) 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) InstantType(org.hl7.fhir.r4.model.InstantType) UriType(org.hl7.fhir.r4.model.UriType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DecimalType(org.hl7.fhir.r4.model.DecimalType) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 63 with Range

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

the class FHIRRestUtils method complicatedTypeValueConstructor.

static String complicatedTypeValueConstructor(ParameterDefinition parameterDefinition) {
    FhirContext context = FhirContext.forCached(FhirVersionEnum.R4);
    IParser parser = context.newJsonParser();
    String valueKey;
    // In order to use the hapi parser, we cannot translate an extension by itself. The patient object wraps the extension
    Patient patient = new Patient();
    Extension extension = new Extension();
    switch(parameterDefinition.getType()) {
        case "Period":
            Period period = (Period) parameterDefinition.getExtension().get(0).getValue();
            extension.setValue(period);
            patient.addExtension(extension);
            valueKey = "valuePeriod";
            break;
        case "Range":
            Range range = (Range) parameterDefinition.getExtension().get(0).getValue();
            extension.setValue(range);
            patient.addExtension(extension);
            valueKey = "valueRange";
            break;
        case "Quantity":
            Quantity quantity = (Quantity) parameterDefinition.getExtension().get(0).getValue();
            extension.setValue(quantity);
            patient.addExtension(extension);
            valueKey = "valueQuantity";
            break;
        default:
            throw new RuntimeException("Complicated Type" + parameterDefinition.getType() + " not yet implemented");
    }
    String intermediateValue = parser.encodeResourceToString(patient);
    ObjectMapper mapper = new ObjectMapper();
    try {
        JsonNode root = mapper.readTree(intermediateValue);
        JsonNode nameNode = root.path("extension");
        return nameNode.get(0).path(valueKey).toString();
    } catch (JsonProcessingException e) {
        throw new RuntimeException("There was an issue with json translation", e);
    }
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) FhirContext(ca.uhn.fhir.context.FhirContext) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Range(org.hl7.fhir.r4.model.Range) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser)

Example 64 with Range

use of org.hl7.fhir.r4b.model.Range in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeRange.

protected void composeRange(Complex parent, String parentType, String name, Range element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "Range", name, element, index);
    if (element.hasLow())
        composeQuantity(t, "Range", "low", element.getLow(), -1);
    if (element.hasHigh())
        composeQuantity(t, "Range", "high", element.getHigh(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Example 65 with Range

use of org.hl7.fhir.r4b.model.Range in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeRange.

protected void composeRange(Complex parent, String parentType, String name, Range element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "Range", name, element, index);
    if (element.hasLow())
        composeQuantity(t, "Range", "low", element.getLow(), -1);
    if (element.hasHigh())
        composeQuantity(t, "Range", "high", element.getHigh(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Aggregations

Test (org.junit.jupiter.api.Test)18 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)15 Quantity (org.hl7.fhir.r4.model.Quantity)14 Resource (org.hl7.fhir.r4.model.Resource)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Search (ca.uhn.fhir.rest.annotation.Search)11 Trace (com.newrelic.api.agent.Trace)10 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)10 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)9 ArrayList (java.util.ArrayList)9 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)8 Operation (gov.cms.bfd.server.war.Operation)8 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)8 Date (java.util.Date)8 Range (org.hl7.fhir.r4.model.Range)8 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)7 List (java.util.List)7 Bundle (org.hl7.fhir.r4.model.Bundle)7