use of org.hl7.fhir.r5.model.Annotation in project loinc2hpo by monarch-initiative.
the class ObservationAnalysisFromInterpretation method getHPOforObservation.
@Override
public HpoTermId4LoincTest getHPOforObservation() throws UnsupportedCodingSystemException, AmbiguousResultsFoundException, AnnotationNotFoundException, UnrecognizedCodeException {
// here we use a map to store the results: since there could be more than one interpretation coding system,
// we try them all and store the results in a map <external code, result in internal code>
Map<Code, Code> results = new HashMap<>();
// get the annotation class for this loinc code
UniversalLoinc2HPOAnnotation annotationForLoinc = annotationMap.get(this.loincId);
if (annotationForLoinc == null)
throw new AnnotationNotFoundException();
// all interpretation codes in different coding systems. Expect one in most cases.
Set<Code> interpretationCodes = getInterpretationCodes();
interpretationCodes.stream().filter(p -> CodeSystemConvertor.getCodeContainer().getCodeSystemMap().containsKey(p.getSystem())).forEach(p -> {
Code internalCode = null;
try {
internalCode = CodeSystemConvertor.convertToInternalCode(p);
results.put(p, internalCode);
} catch (InternalCodeNotFoundException e) {
e.printStackTrace();
}
});
List<Code> distinct = results.values().stream().distinct().collect(Collectors.toList());
if (distinct.size() == 1) {
HpoTermId4LoincTest hpoTermId4LoincTest = annotationForLoinc.loincInterpretationToHPO(distinct.get(0));
if (hpoTermId4LoincTest == null)
throw new UnrecognizedCodeException();
return hpoTermId4LoincTest;
} else {
throw new AmbiguousResultsFoundException();
}
}
use of org.hl7.fhir.r5.model.Annotation 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.r5.model.Annotation in project gpconnect-demonstrator by nhsconnect.
the class WarningCodeExtHelper method addWarningCodeExtensions.
/**
* confidential items are per record but the other two are global values per
* patient
*
* @param warningCodes
* @param list
* @param patientRepository
* @param medicationStatementRepository
* @param structuredAllergySearch
*/
public static void addWarningCodeExtensions(Set<String> warningCodes, ListResource list, PatientRepository patientRepository, MedicationStatementRepository medicationStatementRepository, StructuredAllergySearch structuredAllergySearch) {
String NHS = list.getSubject().getIdentifier().getValue();
PatientEntity patientEntity = patientRepository.findByNhsNumber(NHS);
List<MedicationStatementEntity> medicationStatements = medicationStatementRepository.findByPatientId(patientEntity.getId());
for (MedicationStatementEntity medicationStatement : medicationStatements) {
setFlags(medicationStatement.getWarningCode());
}
List<StructuredAllergyIntoleranceEntity> allergies = structuredAllergySearch.getAllergyIntollerence(NHS);
for (StructuredAllergyIntoleranceEntity allergy : allergies) {
setFlags(allergy.getWarningCode());
}
// check medication_statements for either of the global flags
if (dataInTransit) {
warningCodes.add(DATA_IN_TRANSIT);
}
if (dataAwaitingFiling) {
warningCodes.add(DATA_AWAITING_FILING);
}
StringBuilder sb = new StringBuilder();
warningCodes.forEach(warningCode -> {
if (warningCode != null) {
String warningCodeDisplay = "";
Annotation annotation = new Annotation();
switch(warningCode) {
case CONFIDENTIAL_ITEMS:
warningCodeDisplay = "Confidential Items";
// #266
annotation.setText(CONFIDENTIAL_ITEMS_NOTE);
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
case DATA_IN_TRANSIT:
warningCodeDisplay = "Data in Transit";
Calendar cal = new GregorianCalendar();
Date now = new Date();
cal.setTime(now);
// a week before now
cal.add(Calendar.DAY_OF_YEAR, -7);
// #266
annotation.setText(String.format(DATA_IN_TRANSIT_NOTE, DATE_FORMAT.format(cal.getTime())));
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
case DATA_AWAITING_FILING:
warningCodeDisplay = "Data Awaiting Filing";
// #266
annotation.setText(DATA_AWAITING_FILING_NOTE);
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
default:
break;
}
// #182
Extension warningExt = new Extension(SystemURL.WARNING_CODE, new CodeType(warningCode));
list.addExtension(warningExt);
}
});
// cardinality of note 0..1 #266
if (sb.length() > 0) {
Annotation annotation = null;
if (list.getNote().size() > 0) {
annotation = list.getNote().get(0);
annotation.setText(annotation.getText());
annotation.setText(annotation.getText() + sb.toString());
} else {
annotation = new Annotation();
list.addNote(annotation);
annotation.setText(sb.toString().replaceFirst("^\r\n", ""));
}
}
}
use of org.hl7.fhir.r5.model.Annotation in project bunsen by cerner.
the class FhirEncodersTest method annotation.
@Test
public void annotation() throws FHIRException {
Annotation original = medRequest.getNoteFirstRep();
Annotation decoded = decodedMedRequest.getNoteFirstRep();
Assert.assertEquals(original.getText(), medDataset.select(functions.expr("note[0].text")).head().get(0));
Assert.assertEquals(original.getText(), decoded.getText());
Assert.assertEquals(original.getAuthorReference().getReference(), decoded.getAuthorReference().getReference());
}
use of org.hl7.fhir.r5.model.Annotation in project bunsen by cerner.
the class TestData method newMedRequest.
/**
* Returns a FHIR medication request for testing purposes.
*/
public static MedicationRequest newMedRequest() {
MedicationRequest medReq = new MedicationRequest();
medReq.setId("test-med");
// Medication code
CodeableConcept med = new CodeableConcept();
med.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("582620").setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");
med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");
medReq.setMedication(med);
Annotation annotation = new Annotation();
annotation.setText("Test medication note.");
annotation.setAuthor(new Reference("Provider/example").setDisplay("Example provider."));
medReq.addNote(annotation);
return medReq;
}
Aggregations