use of org.hl7.fhir.dstu3.model.Ratio in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7ObservationFHIRConversionTest method testObservationSN_valueRatio_colon_result.
@Test
void testObservationSN_valueRatio_colon_result() throws IOException {
String hl7message = baseMessage + "OBX|1|SN|111^LabWithRatio||^2^:^3|";
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
Observation obs = (Observation) obsResource.get(0);
assertTrue(obs.hasValueRatio());
Ratio r = obs.getValueRatio();
assertEquals(2f, r.getNumerator().getValue().floatValue());
assertEquals(3f, r.getDenominator().getValue().floatValue());
}
use of org.hl7.fhir.dstu3.model.Ratio 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.dstu3.model.Ratio in project quality-measure-and-cohort-service by Alvearie.
the class CDMMeasureEvaluation method evaluatePatientMeasure.
/**
* Evaluate a CDM Patient Quality Measure
*
* @param measure CDM Patient Quality Measure
* @param context CQL Engine Execution Context pre-configured for use in
* measure evaluation
* @param patientIds Patient ID(s) of the patient to evaluate (first element when generating INDIVIDUAL type report)
* @param evidenceOptions MeasureEvidenceOptions to indicate whether or not to return evaluated resources and define level results
* @param parameterMap Map of parameter names to Parameter objects
* @param type Type of report to be generated
* @return MeasureReport with population components filled out.
*/
public MeasureReport evaluatePatientMeasure(Measure measure, Context context, List<String> patientIds, MeasureEvidenceOptions evidenceOptions, Map<String, Parameter> parameterMap, MeasureReport.MeasureReportType type) {
context.setExpressionCaching(true);
boolean includeEvaluatedResources = (evidenceOptions != null) ? evidenceOptions.isIncludeEvaluatedResources() : false;
MeasureReport report;
switch(type) {
case INDIVIDUAL:
report = evaluation.evaluatePatientMeasure(measure, context, patientIds.get(0), includeEvaluatedResources);
break;
case SUBJECTLIST:
report = evaluation.evaluatePatientListMeasure(measure, context, patientIds, includeEvaluatedResources);
break;
default:
throw new IllegalStateException("Unsupported measure report type requested: " + type);
}
setReportMeasureToMeasureId(report, measure);
MeasureScoring scoring = MeasureScoring.fromCode(measure.getScoring().getCodingFirstRep().getCode());
switch(scoring) {
case PROPORTION:
case RATIO:
// implement custom logic for CDM care-gaps
Iterator<Measure.MeasureGroupComponent> it = measure.getGroup().iterator();
for (int i = 0; it.hasNext(); i++) {
Measure.MeasureGroupComponent group = it.next();
MeasureReport.MeasureReportGroupComponent reportGroup = report.getGroup().get(i);
boolean evaluateCareGaps = isEligibleForCareGapEvaluation(reportGroup);
for (Measure.MeasureGroupPopulationComponent pop : group.getPopulation()) {
if (pop.getCode().hasCoding(CDMConstants.CDM_CODE_SYSTEM_MEASURE_POPULATION_TYPE, CDMConstants.CARE_GAP)) {
Boolean result = Boolean.FALSE;
if (evaluateCareGaps) {
result = evaluateCriteria(context, pop.getCriteria().getExpression());
}
MeasureReport.MeasureReportGroupPopulationComponent output = new MeasureReport.MeasureReportGroupPopulationComponent();
// need this to differentiate between multiple instances of care-gap
output.setId(pop.getId());
output.setCode(pop.getCode());
output.setCount(result ? 1 : 0);
reportGroup.addPopulation(output);
}
}
}
break;
default:
}
if (context instanceof CDMContext) {
CDMContext defineContext = (CDMContext) context;
// Grab the define results from the expression cache
MeasureEvidenceOptions.DefineReturnOptions defineReturnOptions = (evidenceOptions != null) ? evidenceOptions.getDefineReturnOption() : MeasureEvidenceOptions.DefineReturnOptions.NONE;
addDefineEvaluationToReport(report, defineContext, defineReturnOptions);
}
List<Extension> parameterExtensions = getParameterExtensions(measure, context, parameterMap);
parameterExtensions.forEach(report::addExtension);
return report;
}
use of org.hl7.fhir.dstu3.model.Ratio in project quality-measure-and-cohort-service by Alvearie.
the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testRatio__shouldReturnRatioParameter.
@Test
public void testRatio__shouldReturnRatioParameter() {
ParameterDefinition parameterDefinition = getBaseParameterDefinition("Ratio");
String denominatorString = "1.5";
String numeratorString = "2.5";
BigDecimal denominatorValue = new BigDecimal(denominatorString);
BigDecimal numeratorValue = new BigDecimal(numeratorString);
String unit = "ml";
org.hl7.fhir.r4.model.Ratio fhirValue = new org.hl7.fhir.r4.model.Ratio().setDenominator(new org.hl7.fhir.r4.model.Quantity().setValue(denominatorValue).setUnit(unit)).setNumerator(new org.hl7.fhir.r4.model.Quantity().setValue(numeratorValue).setUnit(unit));
parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
RatioParameter expectedParameter = new RatioParameter().setDenominator(new QuantityParameter().setUnit(unit).setAmount(denominatorString)).setNumerator(new QuantityParameter().setUnit(unit).setAmount(numeratorString));
assertEquals(expectedParameter, R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
use of org.hl7.fhir.dstu3.model.Ratio in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method displayLeaf.
private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return false;
Base e = ew.getBase();
Map<String, String> displayHints = readDisplayHints(defn);
if (name.endsWith("[x]"))
name = name.substring(0, name.length() - 3);
if (!showCodeDetails && e instanceof PrimitiveType && isDefault(displayHints, ((PrimitiveType) e)))
return false;
if (e instanceof StringType) {
x.addText(name + ": " + ((StringType) e).getValue());
return true;
} else if (e instanceof CodeType) {
x.addText(name + ": " + ((CodeType) e).getValue());
return true;
} else if (e instanceof IdType) {
x.addText(name + ": " + ((IdType) e).getValue());
return true;
} else if (e instanceof DateTimeType) {
x.addText(name + ": " + ((DateTimeType) e).toHumanDisplay());
return true;
} else if (e instanceof InstantType) {
x.addText(name + ": " + ((InstantType) e).toHumanDisplay());
return true;
} else if (e instanceof Extension) {
x.addText("Extensions: todo");
return true;
} else if (e instanceof org.hl7.fhir.dstu2.model.DateType) {
x.addText(name + ": " + ((org.hl7.fhir.dstu2.model.DateType) e).toHumanDisplay());
return true;
} else if (e instanceof Enumeration) {
// todo: look up a display name if there is one
x.addText(((Enumeration<?>) e).getValue().toString());
return true;
} else if (e instanceof BooleanType) {
if (((BooleanType) e).getValue()) {
x.addText(name);
return true;
}
} else if (e instanceof CodeableConcept) {
renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
return true;
} else if (e instanceof Coding) {
renderCoding((Coding) e, x, showCodeDetails);
return true;
} else if (e instanceof Annotation) {
renderAnnotation((Annotation) e, x, showCodeDetails);
return true;
} else if (e instanceof org.hl7.fhir.dstu2.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.dstu2.model.IntegerType) e).getValue()));
return true;
} else if (e instanceof org.hl7.fhir.dstu2.model.DecimalType) {
x.addText(((org.hl7.fhir.dstu2.model.DecimalType) e).getValue().toString());
return true;
} else if (e instanceof Identifier) {
renderIdentifier((Identifier) e, x);
return true;
} else if (e instanceof HumanName) {
renderHumanName((HumanName) e, x);
return true;
} else if (e instanceof SampledData) {
renderSampledData((SampledData) e, x);
return true;
} else if (e instanceof Address) {
renderAddress((Address) e, x);
return true;
} else if (e instanceof ContactPoint) {
renderContactPoint((ContactPoint) e, x);
return true;
} else if (e instanceof Timing) {
renderTiming((Timing) e, x);
return true;
} else if (e instanceof Quantity) {
renderQuantity((Quantity) e, x, showCodeDetails);
return true;
} else if (e instanceof Ratio) {
renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
x.addText("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
return true;
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(name + ": ");
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.addText(" --> ");
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
return true;
} else if (e instanceof Reference) {
Reference r = (Reference) e;
if (r.hasDisplayElement())
x.addText(r.getDisplay());
else if (r.hasReferenceElement()) {
ResourceWithReference tr = resolveReference(res, r.getReference());
// getDisplayForReference(tr.getReference()));
x.addText(tr == null ? r.getReference() : "????");
} else
x.addText("??");
return true;
} else if (e instanceof Narrative) {
return false;
} else if (e instanceof Resource) {
return false;
} else if (!(e instanceof Attachment))
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
return false;
}
Aggregations