Search in sources :

Example 1 with FhirTerminologyServerR4AdaptorImpl

use of org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl in project ehrbase by ehrbase.

the class FhirTerminologyServerR4AdaptorImplTest method expandValueSetUsingSsl.

@Ignore("Requires SSL configuration")
@Test
public void expandValueSetUsingSsl() throws GeneralSecurityException, IOException {
    SSLContext sslContext = SSLContextBuilder.create().loadKeyMaterial(ResourceUtils.getFile("test-keystore.jks"), "test".toCharArray(), "test".toCharArray()).loadTrustMaterial(ResourceUtils.getFile("test-truststore.jks"), "test".toCharArray(), TrustAllStrategy.INSTANCE).build();
    HttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
    FhirTsProps props = new FhirTsProps();
    props.setCodePath("$[\"expansion\"][\"contains\"][*][\"code\"]");
    props.setDisplayPath("$[\"expansion\"][\"contains\"][*][\"display\"]");
    props.setSystemPath("$[\"expansion\"][\"contains\"][*][\"system\"]");
    props.setTsUrl("https://terminology-highmed.medic.medfak.uni-koeln.de/fhir/");
    try {
        tsserver = new FhirTerminologyServerR4AdaptorImpl(httpClient, props);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<DvCodedText> result = tsserver.expandWithParameters("https://www.netzwerk-universitaetsmedizin.de/fhir/ValueSet/frailty-score", "expand");
    result.forEach((e) -> System.out.println(e.getValue()));
    // 1: Very Severely Frail
    assertThat(result.get(0).getDefiningCode().getCodeString()).isEqualTo("8");
    assertThat(result.get(0).getValue()).isEqualTo("Very Severely Frail");
    // 2: Severely Frail
    assertThat(result.get(1).getDefiningCode().getCodeString()).isEqualTo("7");
    assertThat(result.get(1).getValue()).isEqualTo("Severely Frail");
    // 3: Terminally Ill
    assertThat(result.get(2).getDefiningCode().getCodeString()).isEqualTo("9");
    assertThat(result.get(2).getValue()).isEqualTo("Terminally Ill");
    // 4: Vulnerable
    assertThat(result.get(3).getDefiningCode().getCodeString()).isEqualTo("4");
    assertThat(result.get(3).getValue()).isEqualTo("Vulnerable");
    assertThat(result.size()).isEqualTo(9);
}
Also used : FhirTerminologyServerR4AdaptorImpl(org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) HttpClient(org.apache.http.client.HttpClient) SSLContext(javax.net.ssl.SSLContext) FhirTsProps(org.ehrbase.service.FhirTsProps) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with FhirTerminologyServerR4AdaptorImpl

use of org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl in project ehrbase by ehrbase.

the class FhirTerminologyServerR4AdaptorImplTest method shouldRetrieveValueSet.

@Ignore("This test runs against ontoserver sample inteance. It is deactivated until we have a test FHIR terminology server and the architecture allows to run Spring integration tests.")
@Test
public void shouldRetrieveValueSet() {
    FhirTsProps props = new FhirTsProps();
    props.setCodePath("$[\"expansion\"][\"contains\"][*][\"code\"]");
    props.setDisplayPath("$[\"expansion\"][\"contains\"][*][\"display\"]");
    props.setSystemPath("$[\"expansion\"][\"contains\"][*][\"system\"]");
    props.setTsUrl("https://r4.ontoserver.csiro.au/fhir/");
    try {
        tsserver = new FhirTerminologyServerR4AdaptorImpl(HttpClients.createDefault(), props);
    } catch (Exception e) {
        e.printStackTrace();
    }
    List<DvCodedText> result = tsserver.expandWithParameters("http://hl7.org/fhir/ValueSet/surface", "expand");
    result.forEach((e) -> System.out.println(e.getValue()));
    // 1: Buccal
    assertThat(result.get(0).getDefiningCode().getCodeString()).isEqualTo("B");
    assertThat(result.get(0).getValue()).isEqualTo("Buccal");
    // 2: Distal
    assertThat(result.get(1).getDefiningCode().getCodeString()).isEqualTo("D");
    assertThat(result.get(1).getValue()).isEqualTo("Distal");
    // 3: Distoclusal
    assertThat(result.get(2).getDefiningCode().getCodeString()).isEqualTo("DO");
    assertThat(result.get(2).getValue()).isEqualTo("Distoclusal");
    // 4: Distoincisal
    assertThat(result.get(3).getDefiningCode().getCodeString()).isEqualTo("DI");
    assertThat(result.get(3).getValue()).isEqualTo("Distoincisal");
    assertThat(result.size()).isEqualTo(11);
}
Also used : FhirTerminologyServerR4AdaptorImpl(org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) FhirTsProps(org.ehrbase.service.FhirTsProps) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with FhirTerminologyServerR4AdaptorImpl

use of org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl 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 FhirTerminologyServerR4AdaptorImpl

use of org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl in project ehrbase by ehrbase.

the class WhereVisitorTest method testTerminologyWhereStatementNotSupported.

@Test
public void testTerminologyWhereStatementNotSupported() {
    FhirTerminologyServerR4AdaptorImpl mock = mock(FhirTerminologyServerR4AdaptorImpl.class);
    when(mock.expandWithParameters("http://hl7.org/fhir/ValueSet/animal-breeds", "expand")).thenThrow(new InternalServerException("Terminology server operation failed:'Error response received from FHIR terminology server. " + "HTTP status: 404. Body: {\\\"resourceType\\\":\\\"OperationOutcome\\\",\\\"issue\\\":[{\\\"severity\\\":\\\"error\\\",\\\"code\\\":\\\"not-found\\\",\\\"diagnostics\\\":\\\"" + "[5389b21a-d873-41d0-8c79-4390796c40bc]: Could not find value set http://hl7.org/fhir/ValueSet/animal-breeds. If this is an implicit value set please make sure the url is correct. " + "Implicit values sets for different code systems are specified in https://www.hl7.org/fhir/terminologies-systems.html .\\\"}]}'"));
    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', 'http://hl7.org/fhir/ValueSet/animal-breeds')}";
    ParseTree tree = QueryHelper.setupParseTree(aql);
    Assert.assertThrows(IllegalArgumentException.class, () -> cut.visit(tree));
}
Also used : FhirTerminologyServerR4AdaptorImpl(org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl) InternalServerException(org.ehrbase.api.exception.InternalServerException) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Test(org.junit.Test)

Example 5 with FhirTerminologyServerR4AdaptorImpl

use of org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl in project ehrbase by ehrbase.

the class InvokeVisitorTest method shouldVisitInvokeExpressionValidateOperation.

@Test
public void shouldVisitInvokeExpressionValidateOperation() {
    // postman request for expansion is: GET https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=http://hl7.org/fhir/ValueSet/surface
    FhirTerminologyServerR4AdaptorImpl mock = mock(FhirTerminologyServerR4AdaptorImpl.class);
    when(mock.validate(any())).thenReturn(true);
    WhereVisitor cut = new WhereVisitor(mock);
    String aql = "SELECT o/data[at0002]/events[at0003] AS systolic " + "FROM EHR [ehr_id/value='1234'] " + "CONTAINS COMPOSITION c " + "CONTAINS OBSERVATION o [openEHR-EHR-OBSERVATION.blood_pressure.v1] " + "WHERE c/archetype_details/template_id/value MATCHES {'Flormidal', TERMINOLOGY('validate','http://hl7.org/fhir/4.0','system=http://snomed.info/sct&code=122298005&url=http://snomed.info/sct?fhir_vs&display=Astrovirus RNA assay'), 'Kloralhidrat'}";
    ParseTree tree = QueryHelper.setupParseTree(aql);
    cut.visit(tree);
    List<Object> whereExpression = cut.getWhereExpression();
    assertThat(whereExpression).size().isEqualTo(9);
    I_VariableDefinition where1 = (I_VariableDefinition) whereExpression.get(0);
    I_VariableDefinition expected1 = I_VariableDefinitionHelper.build("archetype_details/template_id/value", null, "c", false, false, false);
    I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(where1, expected1);
    assertThat(whereExpression.get(1)).isEqualTo(" IN ");
    assertThat(whereExpression.get(2)).isEqualTo("(");
    assertThat(whereExpression.get(3)).isEqualTo("'Flormidal'");
    assertThat(whereExpression.get(4)).isEqualTo(",");
    assertThat(whereExpression.get(5)).isEqualTo(true);
    assertThat(whereExpression.get(6)).isEqualTo(",");
    assertThat(whereExpression.get(7)).isEqualTo("'Kloralhidrat'");
    assertThat(whereExpression.get(8)).isEqualTo(")");
}
Also used : FhirTerminologyServerR4AdaptorImpl(org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl) I_VariableDefinition(org.ehrbase.aql.definition.I_VariableDefinition) ParseTree(org.antlr.v4.runtime.tree.ParseTree) Test(org.junit.Test)

Aggregations

FhirTerminologyServerR4AdaptorImpl (org.ehrbase.service.FhirTerminologyServerR4AdaptorImpl)6 Test (org.junit.Test)6 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)4 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)2 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 I_VariableDefinition (org.ehrbase.aql.definition.I_VariableDefinition)2 FhirTsProps (org.ehrbase.service.FhirTsProps)2 Ignore (org.junit.Ignore)2 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)1 ArrayList (java.util.ArrayList)1 SSLContext (javax.net.ssl.SSLContext)1 HttpClient (org.apache.http.client.HttpClient)1 InternalServerException (org.ehrbase.api.exception.InternalServerException)1