Skip to content

Commit

Permalink
Add env check
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenreup committed Nov 13, 2024
1 parent a42b579 commit 1d71358
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()) {
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/kotlin/org/dtree/fhir/core/utils/env.kt
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 1d71358

Please sign in to comment.