From 1d71358a450826410e5a9983d0ca7757a1ca79fe Mon Sep 17 00:00:00 2001 From: Christopher Seven Phiri Date: Wed, 13 Nov 2024 15:29:56 +0200 Subject: [PATCH] Add env check --- .../fhir/core/uploader/general/FhirClient.kt | 16 ++++++++++------ .../main/kotlin/org/dtree/fhir/core/utils/env.kt | 8 ++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 core/src/main/kotlin/org/dtree/fhir/core/utils/env.kt diff --git a/core/src/main/kotlin/org/dtree/fhir/core/uploader/general/FhirClient.kt b/core/src/main/kotlin/org/dtree/fhir/core/uploader/general/FhirClient.kt index 4635c87..885c201 100644 --- a/core/src/main/kotlin/org/dtree/fhir/core/uploader/general/FhirClient.kt +++ b/core/src/main/kotlin/org/dtree/fhir/core/uploader/general/FhirClient.kt @@ -17,6 +17,7 @@ import org.dtree.fhir.core.models.PatientData import org.dtree.fhir.core.models.parsePatientResources import org.dtree.fhir.core.utils.Logger import org.dtree.fhir.core.utils.createFile +import org.dtree.fhir.core.utils.isDev import org.dtree.fhir.core.utils.logicalId import org.hl7.fhir.instance.model.api.IBaseBundle import org.hl7.fhir.instance.model.api.IBaseResource @@ -41,11 +42,15 @@ class FhirClient(private val dotenv: Dotenv, private val iParser: IParser) { private fun createOkHttpClient(): OkHttpClient { val tokenAuthenticator = TokenAuthenticator.createAuthenticator(dotenv) val authInterceptor = AuthInterceptor(tokenAuthenticator) - val logging = HttpLoggingInterceptor() - logging.setLevel(HttpLoggingInterceptor.Level.BASIC) + val builder = OkHttpClient.Builder() - return OkHttpClient.Builder() - .addInterceptor(logging) + if (dotenv.isDev()) { + val logging = HttpLoggingInterceptor() + logging.setLevel(HttpLoggingInterceptor.Level.BASIC) + builder.addInterceptor(logging) + } + + return builder .addInterceptor(authInterceptor) .readTimeout(2, TimeUnit.MINUTES) .build() @@ -196,11 +201,10 @@ class FhirClient(private val dotenv: Dotenv, private val iParser: IParser) { .setMethod(Bundle.HTTPVerb.GET) .setUrl("List?subject=$patientId&status=current") - println(iParser.encodeResourceToString(bundle)) val data = fhirClient.transaction() .withBundle(bundle) - .prettyPrint() .execute().parsePatientResources(patientId) + val patientData = data.second if (data.first.isNotEmpty()) { diff --git a/core/src/main/kotlin/org/dtree/fhir/core/utils/env.kt b/core/src/main/kotlin/org/dtree/fhir/core/utils/env.kt new file mode 100644 index 0000000..eaec802 --- /dev/null +++ b/core/src/main/kotlin/org/dtree/fhir/core/utils/env.kt @@ -0,0 +1,8 @@ +package org.dtree.fhir.core.utils + +import io.github.cdimascio.dotenv.Dotenv + +fun Dotenv.isDev(): Boolean { + val env = get("ENVIRONMENT", "production") + return env == "development" +} \ No newline at end of file