use of org.hl7.fhir.dstu2.model.Annotation in project CRD by HL7-DaVinci.
the class FhirRequestProcessor method addNoteToRequest.
public static IBaseResource addNoteToRequest(IBaseResource request, Annotation note) {
IBaseResource output = request;
switch(request.fhirType()) {
case "DeviceRequest":
DeviceRequest deviceRequest = ((DeviceRequest) request).copy();
deviceRequest.addNote(note);
output = deviceRequest;
break;
case "MedicationRequest":
MedicationRequest medicationRequest = ((MedicationRequest) request).copy();
medicationRequest.addNote(note);
output = medicationRequest;
break;
case "MedicationDispense":
MedicationDispense medicationDispense = ((MedicationDispense) request).copy();
medicationDispense.addNote(note);
output = medicationDispense;
break;
case "ServiceRequest":
ServiceRequest serviceRequest = ((ServiceRequest) request).copy();
serviceRequest.addNote(note);
output = serviceRequest;
break;
case "NutritionOrder":
NutritionOrder nutritionOrder = ((NutritionOrder) request).copy();
nutritionOrder.addNote(note);
output = nutritionOrder;
break;
case "SupplyRequest":
case "Appointment":
case "Encounter":
default:
logger.info("Unsupported fhir R4 resource type (" + request.fhirType() + ") when adding note");
throw new RuntimeException("Unsupported fhir R4 resource type " + request.fhirType());
}
return output;
}
use of org.hl7.fhir.dstu2.model.Annotation in project CRD by HL7-DaVinci.
the class CardBuilder method createSuggestionWithNote.
public static Suggestion createSuggestionWithNote(Card card, IBaseResource request, FhirComponentsT fhirComponents, String label, String description, boolean isRecommended, CoverageGuidance coverageGuidance) {
Date now = new Date();
Suggestion requestWithNoteSuggestion = new Suggestion();
requestWithNoteSuggestion.setLabel(label);
requestWithNoteSuggestion.setIsRecommended(isRecommended);
List<Action> actionList = new ArrayList<>();
// build the Annotation
Annotation annotation = new Annotation();
StringType author = new StringType();
author.setValue(card.getSource().getLabel());
annotation.setAuthor(author);
String text = card.getSummary() + ": " + card.getDetail();
annotation.setText(text);
// set the date and time to now
annotation.setTime(now);
IBaseResource resource = FhirRequestProcessor.addNoteToRequest(request, annotation);
try {
// build the Extension with the coverage information
Extension extension = new Extension();
extension.setUrl("http://hl7.org/fhir/us/davinci-crd/StructureDefinition/ext-coverage-information");
Extension coverageInfo = new Extension();
coverageInfo.setUrl("coverageInfo").setValue(coverageGuidance.getCoding());
extension.addExtension(coverageInfo);
Extension coverageExtension = new Extension();
Reference coverageReference = new Reference();
// TODO: get the coverage from the prefetch and pass it into here instead of retrieving it from the request
coverageReference.setReference(FhirRequestProcessor.getCoverageFromRequest(request).getReference());
coverageExtension.setUrl("coverage").setValue(coverageReference);
extension.addExtension(coverageExtension);
Extension date = new Extension();
date.setUrl("date").setValue(new DateType().setValue(now));
extension.addExtension(date);
Extension identifier = new Extension();
String id = UUID.randomUUID().toString();
identifier.setUrl("identifier").setValue(new StringType(id));
extension.addExtension(identifier);
resource = FhirRequestProcessor.addExtensionToRequest(resource, extension);
} catch (NoCoverageException e) {
logger.warn("No Coverage, discrete coverage extension will not be included: " + e.getMessage());
}
Action updateAction = new Action(fhirComponents);
updateAction.setType(Action.TypeEnum.update);
updateAction.setDescription(description);
updateAction.setResource(resource);
actionList.add(updateAction);
requestWithNoteSuggestion.setActions(actionList);
return requestWithNoteSuggestion;
}
use of org.hl7.fhir.dstu2.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.dstu2.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.dstu2.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", ""));
}
}
}
Aggregations