use of com.nedap.archie.rm.datatypes.CodePhrase 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));
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project ehrbase by ehrbase.
the class RecordedDvCodedTextTest method testToDB.
@Test
public void testToDB() {
Record record = new EventContextRecord();
DvCodedText dvCodedText = new DvCodedText("testvalue", new CodePhrase("en"), new CodePhrase("UTF-8"), new CodePhrase(new TerminologyId("terminology"), "1224"));
TermMapping termMapping = new TermMapping(new CodePhrase(new TerminologyId("A"), "target"), Character.valueOf('>'), new DvCodedText("purpose", new CodePhrase(new TerminologyId("B"), "BBB")));
List<TermMapping> termMappings = new ArrayList<>();
termMappings.add(termMapping);
dvCodedText.setMappings(termMappings);
new RecordedDvCodedText().toDB(record, EventContext.EVENT_CONTEXT.SETTING, dvCodedText);
DvCodedTextRecord dvCodedTextRecord = record.get(EventContext.EVENT_CONTEXT.SETTING);
assertEquals(">", dvCodedTextRecord.getTermMapping()[0].split("|")[0]);
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project ehrbase by ehrbase.
the class WhereVisitorTest method testTerminologyWhereStatement.
@Test
public void testTerminologyWhereStatement() {
FhirTerminologyServerR4AdaptorImpl mock = mock(FhirTerminologyServerR4AdaptorImpl.class);
List<DvCodedText> result = new ArrayList<>();
TerminologyId terminologyId = new TerminologyId("http://fhir.de/CodeSystem/dimdi/atc");
result.add(new DvCodedText("Heparingruppe", new CodePhrase(terminologyId, "B01AB")));
result.add(new DvCodedText("Heparin", new CodePhrase(terminologyId, "B01AB01")));
result.add(new DvCodedText("Antithrombin III, Antithrombin alfa", new CodePhrase(terminologyId, "B01AB02")));
result.add(new DvCodedText("Dalteparin", new CodePhrase(terminologyId, "B01AB04")));
result.add(new DvCodedText("Nadroparin", new CodePhrase(terminologyId, "B01AB06")));
when(mock.expandWithParameters("https: //www.netzwerk-universitaetsmedizin.de/fhir/ValueSet/anticoagulants-atc", "expand")).thenReturn(result);
WhereVisitor cut = new WhereVisitor(mock);
String aql = "select a_a/data[at0002]/items[at0022] " + "from EHR e " + "contains COMPOSITION a " + "contains EVALUATION a_a[openEHR-EHR-EVALUATION.gender.v1] " + "WHERE a_a/data[at0002]/items[at0022]/value/defining_code/code_string matches{TERMINOLOGY('expand', 'hl7.org/fhir/R4', 'https: //www.netzwerk-universitaetsmedizin.de/fhir/ValueSet/anticoagulants-atc')}";
ParseTree tree = QueryHelper.setupParseTree(aql);
cut.visit(tree);
List<Object> whereExpression = cut.getWhereExpression();
assertThat(whereExpression).size().isEqualTo(13);
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project ehrbase by ehrbase.
the class CompositionServiceImp method getOriginalVersionComposition.
@Override
public Optional<OriginalVersion<Composition>> getOriginalVersionComposition(UUID versionedObjectUid, int version) {
// check for valid version parameter
if ((version == 0) || I_CompositionAccess.getLastVersionNumber(getDataAccess(), versionedObjectUid) < version) {
throw new ObjectNotFoundException("versioned_composition", "No VERSIONED_COMPOSITION with given version: " + version);
}
// retrieve requested object
I_CompositionAccess compositionAccess = I_CompositionAccess.retrieveCompositionVersion(getDataAccess(), versionedObjectUid, version);
if (compositionAccess == null) {
return Optional.empty();
}
// create data for output, i.e. fields of the OriginalVersion<Composition>
ObjectVersionId versionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + version);
DvCodedText lifecycleState = new DvCodedText("complete", new CodePhrase(// TODO: once lifecycle state is supported, get it here dynamically
"532"));
AuditDetails commitAudit = compositionAccess.getAuditDetailsAccess().getAsAuditDetails();
ObjectRef<HierObjectId> contribution = new ObjectRef<>(new HierObjectId(compositionAccess.getContributionId().toString()), "openehr", "contribution");
List<UUID> attestationIdList = I_AttestationAccess.retrieveListOfAttestationsByRef(getDataAccess(), compositionAccess.getAttestationRef());
List<Attestation> attestations = // as default, gets content if available in the following lines
null;
if (!attestationIdList.isEmpty()) {
attestations = new ArrayList<>();
for (UUID id : attestationIdList) {
I_AttestationAccess a = new AttestationAccess(getDataAccess()).retrieveInstance(id);
attestations.add(a.getAsAttestation());
}
}
ObjectVersionId precedingVersionId = null;
// check if there is a preceding version and set it, if available
if (version > 1) {
// in the current scope version is an int and therefore: preceding = current - 1
precedingVersionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + (version - 1));
}
Optional<CompositionDto> compositionDto = retrieve(versionedObjectUid, version);
Composition composition = null;
if (compositionDto.isPresent()) {
composition = compositionDto.get().getComposition();
}
OriginalVersion<Composition> versionComposition = new OriginalVersion<>(versionId, precedingVersionId, composition, lifecycleState, commitAudit, contribution, null, null, attestations);
return Optional.of(versionComposition);
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project ehrbase by ehrbase.
the class FhirTerminologyServerR4AdaptorImpl method expandWithParameters.
@Override
public List<DvCodedText> expandWithParameters(final String valueSetId, String... operationParams) {
// build URL
String urlTsServer = props.getTsUrl();
urlTsServer += "ValueSet/$" + operationParams[0] + "?url=" + valueSetId;
String responseBody;
try {
responseBody = internalGet(urlTsServer);
} catch (IOException e) {
throw new InternalServerException("An error occurred while expanding ValueSet " + valueSetId, e);
}
DocumentContext jsonContext = JsonPath.parse(responseBody);
List<String> codeList = jsonContext.read(props.getCodePath().replace("\\", ""));
List<String> systemList = jsonContext.read(props.getSystemPath());
List<String> displayList = jsonContext.read(props.getDisplayPath());
List<DvCodedText> expansionList = new ArrayList<>();
for (int i = 0; i < codeList.size(); i++) {
TerminologyId termId = new TerminologyId(systemList.get(i));
CodePhrase codePhrase = new CodePhrase(termId, codeList.get(i));
DvCodedText codedText = new DvCodedText(displayList.get(i), codePhrase);
expansionList.add(codedText);
}
return expansionList;
}
Aggregations