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;
}
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;
}
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);
}
}
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);
}
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);
}
Aggregations