use of org.ehrbase.fhirbridge.service.TerminologyServiceException in project fhir-bridge by ehrbase.
the class DvCodedTextParser method parseFHIRCoding.
public Optional<DvCodedText> parseFHIRCoding(Coding coding) {
if (coding == null) {
return Optional.empty();
}
if (!coding.hasSystem() || !coding.hasCode()) {
throw new ConversionException("Coding must have a system and a code");
}
String display;
if (coding.hasDisplay()) {
display = coding.getDisplay();
} else {
try {
display = getDisplay(coding.getSystem(), coding.getCode()).orElseThrow(() -> new ConversionException("Coding must have a display or TerminologyService must not be null"));
} catch (TerminologyServiceException e) {
throw new ConversionException("Cannot convert coding. Reason: " + e.getMessage(), e);
}
}
CodePhrase codePhrase = new CodePhrase(new TerminologyId(coding.getSystem()), coding.getCode());
return Optional.of(new DvCodedText(display, codePhrase));
}
Aggregations