use of org.hl7.fhir.r5.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);
}
}
use of org.hl7.fhir.r5.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());
}
use of org.hl7.fhir.r5.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");
}
use of org.hl7.fhir.r5.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());
}
use of org.hl7.fhir.r5.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);
}
}
Aggregations