Search in sources :

Example 1 with CodePhrase

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));
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) TerminologyServiceException(org.ehrbase.fhirbridge.service.TerminologyServiceException)

Example 2 with 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]);
}
Also used : TermMapping(com.nedap.archie.rm.datavalues.TermMapping) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedTextRecord(org.ehrbase.jooq.pg.udt.records.DvCodedTextRecord) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) ArrayList(java.util.ArrayList) Record(org.jooq.Record) CodePhraseRecord(org.ehrbase.jooq.pg.udt.records.CodePhraseRecord) DvCodedTextRecord(org.ehrbase.jooq.pg.udt.records.DvCodedTextRecord) EventContextRecord(org.ehrbase.jooq.pg.tables.records.EventContextRecord) EventContextRecord(org.ehrbase.jooq.pg.tables.records.EventContextRecord) Test(org.junit.Test)

Example 3 with CodePhrase

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);
}
Also used : FhirTerminologyServerR4AdaptorImpl(org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) ArrayList(java.util.ArrayList) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Test(org.junit.Test)

Example 4 with CodePhrase

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);
}
Also used : OriginalVersion(com.nedap.archie.rm.changecontrol.OriginalVersion) Composition(com.nedap.archie.rm.composition.Composition) VersionedComposition(com.nedap.archie.rm.ehr.VersionedComposition) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) I_AttestationAccess(org.ehrbase.dao.access.interfaces.I_AttestationAccess) I_AttestationAccess(org.ehrbase.dao.access.interfaces.I_AttestationAccess) AttestationAccess(org.ehrbase.dao.access.jooq.AttestationAccess) ObjectVersionId(com.nedap.archie.rm.support.identification.ObjectVersionId) Attestation(com.nedap.archie.rm.generic.Attestation) ObjectNotFoundException(org.ehrbase.api.exception.ObjectNotFoundException) CompositionDto(org.ehrbase.response.ehrscape.CompositionDto) I_CompositionAccess(org.ehrbase.dao.access.interfaces.I_CompositionAccess) AuditDetails(com.nedap.archie.rm.generic.AuditDetails) ObjectRef(com.nedap.archie.rm.support.identification.ObjectRef) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId)

Example 5 with CodePhrase

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;
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) InternalServerException(org.ehrbase.api.exception.InternalServerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DocumentContext(com.jayway.jsonpath.DocumentContext)

Aggregations

CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)71 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)60 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)56 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)16 Composition (com.nedap.archie.rm.composition.Composition)12 DvText (com.nedap.archie.rm.datavalues.DvText)12 ArrayList (java.util.ArrayList)8 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 RMObject (com.nedap.archie.rm.RMObject)5 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)5 FlatPathDto (org.ehrbase.webtemplate.path.flat.FlatPathDto)5 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)4 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)4 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)4 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)4 Entry (com.nedap.archie.rm.composition.Entry)3