use of org.hl7.fhir.r4b.model.Range in project loinc2hpo by monarch-initiative.
the class ObservationAnalysisFromQnValue method getHPOforObservation.
@Override
public HpoTermId4LoincTest getHPOforObservation() throws ReferenceNotFoundException, AmbiguousReferenceException, UnrecognizedCodeException {
HpoTermId4LoincTest hpoTermId4LoincTest = null;
// find applicable reference range
List<Observation.ObservationReferenceRangeComponent> references = this.references.stream().filter(p -> withinAgeRange(p)).collect(Collectors.toList());
if (references.size() < 1) {
throw new ReferenceNotFoundException();
} else if (references.size() == 1) {
Observation.ObservationReferenceRangeComponent targetReference = references.get(0);
double low = targetReference.hasLow() ? targetReference.getLow().getValue().doubleValue() : Double.MIN_VALUE;
double high = targetReference.hasHigh() ? targetReference.getHigh().getValue().doubleValue() : Double.MAX_VALUE;
double observed = valueQuantity.getValue().doubleValue();
Loinc2HPOCodedValue result;
if (observed < low) {
result = Loinc2HPOCodedValue.fromCode("L");
} else if (observed > high) {
result = Loinc2HPOCodedValue.fromCode("H");
} else {
result = Loinc2HPOCodedValue.fromCode("N");
}
Code resultCode = Code.getNewCode().setSystem(Loinc2HPOCodedValue.CODESYSTEM).setCode(result.toCode());
hpoTermId4LoincTest = annotationMap.get(loincId).loincInterpretationToHPO(resultCode);
} else if (references.size() == 2) {
// what does it mean with multiple references
throw new AmbiguousReferenceException();
} else if (references.size() == 3) {
// it can happen when there is actually one range but coded in three ranges
// e.g. normal 20-30
// in this case, one range ([20, 30]) is sufficient;
// however, it is written as three ranges: ( , 20) [20, 30] (30, )
// We should handle this case
} else {
throw new AmbiguousReferenceException();
}
// if we can still not find an answer, it is probably that we did not have the annotation
if (hpoTermId4LoincTest == null)
throw new UnrecognizedCodeException();
return hpoTermId4LoincTest;
}
use of org.hl7.fhir.r4b.model.Range in project loinc2hpo by monarch-initiative.
the class CodeSystemInternal method init.
@Override
protected void init() {
final Coding BELOWNORMAL = new Coding(INTERNALSYSTEM, "L", "below normal range");
final Coding NORMAL = new Coding(INTERNALSYSTEM, "N", "within normal range");
final Coding ABOVENORMAL = new Coding(INTERNALSYSTEM, "H", "above normal range");
final Coding ABSENCE = new Coding(INTERNALSYSTEM, "NP", "not present");
final Coding PRESENCE = new Coding(INTERNALSYSTEM, "P", "present");
final Coding UNKNOWN = new Coding(INTERNALSYSTEM, "unknown", "unknown");
codes.put(BELOWNORMAL.getCode(), BELOWNORMAL);
codes.put(NORMAL.getCode(), NORMAL);
codes.put(ABOVENORMAL.getCode(), ABOVENORMAL);
codes.put(ABSENCE.getCode(), ABSENCE);
codes.put(PRESENCE.getCode(), PRESENCE);
codes.put(UNKNOWN.getCode(), UNKNOWN);
}
use of org.hl7.fhir.r4b.model.Range in project loinc2hpo by monarch-initiative.
the class ObservationWithValueRangeTest method highHbWithReferenceRange.
/**
* This observation does not have an Interpretation, but we can infer the value to be high
* based on the reference range.
*/
@Test
public void highHbWithReferenceRange() {
Observation observation = highHemoglobinWithValueRangeObservation();
Uberobservation uberobservation = new ObservationDtu3(observation);
LoincId erysInBlood = new LoincId("789-8");
Optional<LoincId> opt = uberobservation.getLoincId();
assertTrue(opt.isPresent());
assertEquals(erysInBlood, opt.get());
Optional<Outcome> outcomeOpt = uberobservation.getOutcome();
assertTrue(outcomeOpt.isPresent());
assertEquals(Outcome.HIGH(), outcomeOpt.get());
}
use of org.hl7.fhir.r4b.model.Range in project clinical_quality_language by cqframework.
the class ElmDataRequirement method applyConditionRequirementTo.
private void applyConditionRequirementTo(ElmConditionRequirement conditionRequirement, Retrieve retrieve, ElmRequirementsContext context) {
if (retrieve.getDataType() == null) {
// If the retrieve has no data type, it is neither useful nor possible to apply requirements to it
return;
}
if (!conditionRequirement.isTargetable()) {
// If the comparand of the condition requirement is not targetable, requirements cannot be applied
return;
}
// if the column is terminology-valued, express as a code filter
// if the column is date-valued, express as a date filter
// else express as an other filter
Property property = conditionRequirement.getProperty().getProperty();
// DataType propertyType = property.getResultType();
// Use the comparison type due to the likelihood of conversion operators along the property
DataType comparisonType = conditionRequirement.getComparand().getExpression().getResultType();
if (comparisonType != null) {
if (context.getTypeResolver().isTerminologyType(comparisonType)) {
CodeFilterElement codeFilter = new CodeFilterElement();
if (property instanceof Search) {
codeFilter.setSearch(property.getPath());
} else {
codeFilter.setProperty(property.getPath());
}
switch(conditionRequirement.getElement().getClass().getSimpleName()) {
case "Equal":
codeFilter.setComparator("=");
break;
case "Equivalent":
codeFilter.setComparator("~");
break;
case "In":
case "InValueSet":
case "AnyInValueSet":
codeFilter.setComparator("in");
break;
}
if (codeFilter.getComparator() != null && (conditionRequirement.isTargetable())) {
codeFilter.setValue(conditionRequirement.getComparand().getExpression());
if (!ComparableElmRequirement.hasCodeFilter(retrieve.getCodeFilter(), codeFilter)) {
retrieve.getCodeFilter().add(codeFilter);
}
}
} else if (context.getTypeResolver().isDateType(comparisonType)) {
DateFilterElement dateFilter = new DateFilterElement();
if (property instanceof Search) {
dateFilter.setSearch(property.getPath());
} else {
dateFilter.setProperty(property.getPath());
}
// Determine operation and appropriate range
// If right is interval-valued
// If the operation is equal, equivalent, same as, in, or included in, the date range is the comparand
Expression comparand = conditionRequirement.getComparand().getExpression();
if (conditionRequirement.isTargetable()) {
if (context.getTypeResolver().isIntervalType(comparisonType)) {
switch(conditionRequirement.getElement().getClass().getSimpleName()) {
case "Equal":
case "Equivalent":
case "SameAs":
case "In":
case "IncludedIn":
dateFilter.setValue(comparand);
break;
case "Before":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(new Start().withOperand(comparand)).withHighClosed(false));
break;
case "SameOrBefore":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(new Start().withOperand(comparand)).withHighClosed(true));
break;
case "After":
dateFilter.setValue(new Interval().withLow(new End().withOperand(comparand)).withLowClosed(false).withHighClosed(true));
break;
case "SameOrAfter":
dateFilter.setValue(new Interval().withLow(new End().withOperand(comparand)).withLowClosed(true).withHighClosed(true));
break;
case "Includes":
case "Meets":
case "MeetsBefore":
case "MeetsAfter":
case "Overlaps":
case "OverlapsBefore":
case "OverlapsAfter":
case "Starts":
case "Ends":
// TODO: Might be better to turn these into date-based conjunctive requirements as part of condition requirement inference
break;
}
} else {
switch(conditionRequirement.getElement().getClass().getSimpleName()) {
case "Equal":
case "Equivalent":
case "SameAs":
dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(true).withHigh(comparand).withHighClosed(true));
break;
case "Less":
case "Before":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(comparand).withHighClosed(false));
break;
case "LessOrEqual":
case "SameOrBefore":
dateFilter.setValue(new Interval().withLowClosed(true).withHigh(comparand).withHighClosed(true));
break;
case "Greater":
case "After":
dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(false).withHighClosed(true));
break;
case "GreaterOrEqual":
case "SameOrAfter":
dateFilter.setValue(new Interval().withLow(comparand).withLowClosed(true).withHighClosed(true));
break;
}
}
}
if (dateFilter.getValue() != null) {
if (!ComparableElmRequirement.hasDateFilter(retrieve.getDateFilter(), dateFilter)) {
retrieve.getDateFilter().add(dateFilter);
}
}
} else {
}
}
}
use of org.hl7.fhir.r4b.model.Range in project dpc-app by CMSgov.
the class GroupResourceUnitTest method makeTestPatients.
private Map<UUID, Patient> makeTestPatients(int count, UUID orgId) {
if (count > 88) {
throw new IllegalStateException("Don't support building more than 88 patients..yet (need a better mbi generator)");
}
final Map<UUID, Patient> patients = Maps.newHashMap();
while (count > 0) {
UUID id = UUID.randomUUID();
Patient patient = FHIRPatientBuilder.newBuild().withMbi(// makes MBI in range 4S41C00AA10 -> 4S41C00AA99
"4S41C00AA" + (count + 10)).withId(id).withTestData().build();
patients.put(id, patient);
count--;
}
return patients;
}
Aggregations