Search in sources :

Example 1 with HTMLClientLogger

use of org.hl7.fhir.r4b.context.HTMLClientLogger in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method connectToTSServer.

public String connectToTSServer(TerminologyClient client, String log) {
    try {
        tlog("Connect to " + client.getAddress());
        txClient = client;
        if (log != null && log.endsWith(".txt")) {
            txLog = new TextClientLogger(log);
        } else {
            txLog = new HTMLClientLogger(log);
        }
        txClient.setLogger(txLog);
        txClient.setUserAgent(userAgent);
        CapabilityStatement cps = txClient.getCapabilitiesStatementQuick();
        setTxCaps(txClient.getTerminologyCapabilities());
        return cps.getSoftware().getVersion();
    } catch (Exception e) {
        throw new FHIRException(formatMessage(canNoTS ? I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER_USE_PARAMETER_TX_NA_TUN_RUN_WITHOUT_USING_TERMINOLOGY_SERVICES_TO_VALIDATE_LOINC_SNOMED_ICDX_ETC_ERROR__ : I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER, e.getMessage()), e);
    }
}
Also used : CapabilityStatement(org.hl7.fhir.r4b.model.CapabilityStatement) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with HTMLClientLogger

use of org.hl7.fhir.r4b.context.HTMLClientLogger in project org.hl7.fhir.core by hapifhir.

the class ClientTest method test_logger.

@Test
@DisplayName("Testing the logger works.")
void test_logger() throws IOException, URISyntaxException, InterruptedException {
    byte[] payload = ByteUtils.resourceToByteArray(patient, true, false);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(new String(payload)));
    HTMLClientLogger mockLogger = Mockito.mock(HTMLClientLogger.class);
    client.setLogger(mockLogger);
    client.issuePostRequest(new URI(serverUrl.toString()), payload, "xml", null, TIMEOUT);
    server.takeRequest();
    Mockito.verify(mockLogger, Mockito.times(1)).logRequest(Mockito.anyString(), Mockito.anyString(), Mockito.anyList(), Mockito.any());
    Mockito.verify(mockLogger, Mockito.times(1)).logResponse(Mockito.anyString(), Mockito.anyList(), Mockito.any());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HTMLClientLogger(org.hl7.fhir.r5.context.HTMLClientLogger) URI(java.net.URI) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with HTMLClientLogger

use of org.hl7.fhir.r4b.context.HTMLClientLogger in project kindling by HL7.

the class BuildWorkerContext method lookupLoinc.

private String lookupLoinc(String code) throws Exception {
    if (true) {
        // (!triedServer || serverOk) {
        try {
            triedServer = true;
            // for this, we use the FHIR client
            if (txClient == null) {
                txClient = new TerminologyClientR5(tsServer);
                this.txLog = new HTMLClientLogger(null);
            }
            Map<String, String> params = new HashMap<String, String>();
            params.put("code", code);
            params.put("system", "http://loinc.org");
            Parameters result = txClient.lookupCode(params);
            for (ParametersParameterComponent p : result.getParameter()) {
                if (p.getName().equals("display"))
                    return ((StringType) p.getValue()).asStringValue();
            }
            throw new Exception("Did not find LOINC code in return values");
        } catch (EFhirClientException e) {
            serverOk = true;
            throw e;
        } catch (Exception e) {
            serverOk = false;
            throw e;
        }
    } else
        throw new Exception("Server is not available");
}
Also used : TerminologyClientR5(org.hl7.fhir.convertors.txClient.TerminologyClientR5) Parameters(org.hl7.fhir.r5.model.Parameters) HashMap(java.util.HashMap) HTMLClientLogger(org.hl7.fhir.r5.context.HTMLClientLogger) UcumException(org.fhir.ucum.UcumException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) ParametersParameterComponent(org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)

Example 4 with HTMLClientLogger

use of org.hl7.fhir.r4b.context.HTMLClientLogger in project org.hl7.fhir.core by hapifhir.

the class ClientTest method test_logger.

@Test
@DisplayName("Testing the logger works.")
void test_logger() throws IOException, URISyntaxException, InterruptedException {
    byte[] payload = ByteUtils.resourceToByteArray(patient, true, false);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(new String(payload)));
    HTMLClientLogger mockLogger = Mockito.mock(HTMLClientLogger.class);
    client.setLogger(mockLogger);
    client.issuePostRequest(new URI(serverUrl.toString()), payload, "xml", null, TIMEOUT);
    server.takeRequest();
    Mockito.verify(mockLogger, Mockito.times(1)).logRequest(Mockito.anyString(), Mockito.anyString(), Mockito.anyList(), Mockito.any());
    Mockito.verify(mockLogger, Mockito.times(1)).logResponse(Mockito.anyString(), Mockito.anyList(), Mockito.any());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HTMLClientLogger(org.hl7.fhir.r4b.context.HTMLClientLogger) URI(java.net.URI)

Example 5 with HTMLClientLogger

use of org.hl7.fhir.r4b.context.HTMLClientLogger in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method connectToTSServer.

public String connectToTSServer(TerminologyClient client, String log) {
    try {
        txLog("Connect to " + client.getAddress());
        txClient = client;
        if (log != null && log.endsWith(".txt")) {
            txLog = new TextClientLogger(log);
        } else {
            txLog = new HTMLClientLogger(log);
        }
        txClient.setLogger(txLog);
        txClient.setUserAgent(userAgent);
        final CapabilityStatement capabilitiesStatementQuick = txCache.hasCapabilityStatement() ? txCache.getCapabilityStatement() : txClient.getCapabilitiesStatementQuick();
        txCache.cacheCapabilityStatement(capabilitiesStatementQuick);
        final TerminologyCapabilities capabilityStatement = txCache.hasTerminologyCapabilities() ? txCache.getTerminologyCapabilities() : txClient.getTerminologyCapabilities();
        txCache.cacheTerminologyCapabilities(capabilityStatement);
        setTxCaps(capabilityStatement);
        return capabilitiesStatementQuick.getSoftware().getVersion();
    } catch (Exception e) {
        throw new FHIRException(formatMessage(canNoTS ? I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER_USE_PARAMETER_TX_NA_TUN_RUN_WITHOUT_USING_TERMINOLOGY_SERVICES_TO_VALIDATE_LOINC_SNOMED_ICDX_ETC_ERROR__ : I18nConstants.UNABLE_TO_CONNECT_TO_TERMINOLOGY_SERVER, e.getMessage()), e);
    }
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) DataFormatException(ca.uhn.fhir.parser.DataFormatException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 DataFormatException (ca.uhn.fhir.parser.DataFormatException)2 URI (java.net.URI)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 HTMLClientLogger (org.hl7.fhir.r5.context.HTMLClientLogger)2 HashMap (java.util.HashMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 UcumException (org.fhir.ucum.UcumException)1 TerminologyClientR5 (org.hl7.fhir.convertors.txClient.TerminologyClientR5)1 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)1 HTMLClientLogger (org.hl7.fhir.r4b.context.HTMLClientLogger)1 CapabilityStatement (org.hl7.fhir.r4b.model.CapabilityStatement)1 Parameters (org.hl7.fhir.r5.model.Parameters)1 ParametersParameterComponent (org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent)1 EFhirClientException (org.hl7.fhir.r5.utils.client.EFhirClientException)1 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1