Skip to content

Commit

Permalink
chore: added in fastlegeinformasjonEksport api
Browse files Browse the repository at this point in the history
  • Loading branch information
MikAoJk committed Sep 13, 2024
1 parent 414d798 commit 7ebf799
Show file tree
Hide file tree
Showing 12 changed files with 432 additions and 2 deletions.
10 changes: 9 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,18 @@ tasks {
bindingFiles.add("$projectDir/src/main/resources/xjb/binding.xml")
}
}
wsdl2java {
register("fastlegeinformasjonEksport") {
wsdl.set(file("$projectDir/src/main/resources/wsdl/fastlegeinformasjonregisteret.wsdl"))
bindingFiles.add("$projectDir/src/main/resources/xjb/binding.xml")
}
}
}


compileKotlin {
dependsOn("wsdl2javaHelsepersonellregisteret")
dependsOn("wsdl2javaHelsepersonellregisteret")
dependsOn("wsdl2javaFastlegeinformasjonEksport")
}

shadowJar {
Expand Down
2 changes: 2 additions & 0 deletions naiserator-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,5 @@ spec:
env:
- name: HELSEPERSONELL_V1_ENDPOINT_URL
value: https://ws.test.nhn.no/v2/HPR/Basic
- name: FASTLEGEINFORMASJON_V2_ENDPOINT_URL
value: https://ws.test.nhn.no/v2/flrexport
2 changes: 2 additions & 0 deletions naiserator-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ spec:
env:
- name: HELSEPERSONELL_V1_ENDPOINT_URL
value: https://ws.nhn.no/v2/HPR/Basic
- name: FASTLEGEINFORMASJON_V2_ENDPOINT_URL
value: https://ws.nhn.no/v2/flrexport
1 change: 1 addition & 0 deletions src/main/kotlin/no/nav/syfo/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ data class Environment(
val applicationPort: Int = getEnvVar("APPLICATION_PORT", "8080").toInt(),
val applicationName: String = getEnvVar("NAIS_APP_NAME", "syfohelsenettproxy"),
val helsepersonellv1EndpointURL: String = getEnvVar("HELSEPERSONELL_V1_ENDPOINT_URL"),
val fastlegeinformasjonv2EndpointURL: String = getEnvVar("FASTLEGEINFORMASJON_V2_ENDPOINT_URL"),
val clientIdV2: String = getEnvVar("AZURE_APP_CLIENT_ID"),
val jwkKeysUrlV2: String = getEnvVar("AZURE_OPENID_CONFIG_JWKS_URI"),
val jwtIssuerV2: String = getEnvVar("AZURE_OPENID_CONFIG_ISSUER"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package no.nav.syfo.fastlegeinformasjon

import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call
import io.ktor.server.request.header
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import no.nav.syfo.logger
import no.nav.syfo.securelog

fun Route.registerFastlegeinformasjonApi(fastlegeinformasjonService: FastlegeinformasjonService) {
get("/fastlegeinformasjon") {
val kommunenr =
call.request.header("kommunenr")
?: run {
call.respond(
HttpStatusCode.BadRequest,
"Mangler header `kommunenr` med kommunenr",
)
logger.warn("Mottatt kall som mangler header kommunenr")
return@get
}

val fastlegeinformasjon = fastlegeinformasjonService.hentFastlegeinformasjon(kommunenr)
securelog.info("fastlegeinformasjon is: ${fastlegeinformasjon.exportGPContractsResult}")

call.respond(fastlegeinformasjon)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package no.nav.syfo.fastlegeinformasjon

import io.ktor.http.HttpStatusCode

class FastlegeinformasjonException(message: String?, cause: Throwable?) :
RuntimeException(message, cause) {
val feilmelding = Feilmelding(message = message)
}

data class Feilmelding(
val status: HttpStatusCode = HttpStatusCode.InternalServerError,
val message: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package no.nav.syfo.fastlegeinformasjon

import javax.xml.ws.soap.SOAPFaultException
import no.nav.syfo.logger
import no.nav.syfo.securelog
import no.nav.syfo.ws.createPort
import no.nhn.register.common2.ArrayOfCode
import no.nhn.register.common2.Code
import no.nhn.schemas.reg.flr.ContractsQueryParameters
import no.nhn.schemas.reg.flr.FlrExportService
import no.nhn.schemas.reg.flr.IFlrExportOperations
import no.nhn.schemas.reg.flr.IFlrExportOperationsExportGPContractsGenericFaultFaultFaultMessage
import org.apache.cxf.binding.soap.SoapMessage
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor
import org.apache.cxf.message.Message
import org.apache.cxf.phase.Phase

class FastlegeinformasjonService(
private val fastlegeInformsjonOperations: IFlrExportOperations,
) {

fun hentFastlegeinformasjon(kommuneNr: String): ExportGPContracts {

val contractsQueryParameters: ContractsQueryParameters =
createContractsQueryParameters(
historicalData = false,
fullPersonInfo = false,
kommuneNr = kommuneNr,
)

return try {
fastlegeInformsjonOperations
.exportGPContracts(contractsQueryParameters)
.let { ws2ExportGPContracts(it) }
.also {
logger.info("Hentet fastlegeinformasjon for kommunenr: $kommuneNr")
securelog.info("Hentet fastlegeinformasjon for kommunenr object: $it")
}
} catch (e: IFlrExportOperationsExportGPContractsGenericFaultFaultFaultMessage) {
logger.error("Helsenett gir ein generisk feilmelding: {}", e.message)
throw FastlegeinformasjonException(message = e.message, cause = e.cause)
} catch (e: SOAPFaultException) {
logger.error("Helsenett gir feilmelding: {}", e.message)
throw FastlegeinformasjonException(message = e.message, cause = e.cause)
}
}

private fun createContractsQueryParameters(
historicalData: Boolean,
fullPersonInfo: Boolean,
kommuneNr: String
): ContractsQueryParameters {

val kode = Code()
kode.codeValue = kommuneNr
kode.simpleType = "kommune"

val arrayOfCode = ArrayOfCode()
arrayOfCode.code.add(kode)

val contractsQueryParameters = ContractsQueryParameters()
contractsQueryParameters.isGetFullPersonInfo = historicalData
contractsQueryParameters.isGetHistoricalData = fullPersonInfo
contractsQueryParameters.municipalities = arrayOfCode

return contractsQueryParameters
}

private fun ws2ExportGPContracts(exportGPContractsResponse: ByteArray): ExportGPContracts =
ExportGPContracts(
exportGPContractsResult = exportGPContractsResponse,
)
}

data class ExportGPContracts(val exportGPContractsResult: ByteArray)

fun fastlegeinformasjonV2(
endpointUrl: String,
serviceuserUsername: String,
serviceuserPassword: String
) =
createPort<FlrExportService>(endpointUrl) {
proxy {
// TODO: Contact someone about this hacky workaround
// talk to HDIR about HPR about they claim to send a ISO-8859-1 but its really UTF-8
// payload
val interceptor =
object : AbstractSoapInterceptor(Phase.RECEIVE) {
override fun handleMessage(message: SoapMessage?) {
if (message != null) {
message[Message.ENCODING] = "utf-8"
}
}
}
inInterceptors.add(interceptor)
inFaultInterceptors.add(interceptor)
}

port { withBasicAuth(serviceuserUsername, serviceuserPassword) }
}
16 changes: 16 additions & 0 deletions src/main/kotlin/no/nav/syfo/plugins/DependencyInjection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import io.ktor.server.application.install
import no.nav.syfo.Environment
import no.nav.syfo.ServiceUser
import no.nav.syfo.application.ApplicationState
import no.nav.syfo.fastlegeinformasjon.FastlegeinformasjonService
import no.nav.syfo.fastlegeinformasjon.fastlegeinformasjonV2
import no.nav.syfo.helsepersonell.HelsepersonellService
import no.nav.syfo.helsepersonell.helsepersonellV1
import no.nav.syfo.helsepersonell.redis.HelsepersonellRedis
Expand All @@ -27,6 +29,7 @@ fun Application.configureModules() {
helsepersonellModule,
authModule,
sfsModule,
fastlegeinformasjonModule,
)
}
}
Expand All @@ -52,4 +55,17 @@ val helsepersonellModule = module {
single { HelsepersonellRedis(get()) }
single { HelsepersonellService(get(), get()) }
}

val fastlegeinformasjonModule = module {
single {
val env = get<Environment>()
val serviceUser = get<ServiceUser>()
fastlegeinformasjonV2(
env.fastlegeinformasjonv2EndpointURL,
serviceUser.serviceuserUsername,
serviceUser.serviceuserPassword,
)
}
single { FastlegeinformasjonService(get()) }
}
val sfsModule = module { single { SykmelderService(get()) } }
4 changes: 4 additions & 0 deletions src/main/kotlin/no/nav/syfo/plugins/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import io.ktor.server.application.Application
import io.ktor.server.auth.authenticate
import io.ktor.server.routing.route
import io.ktor.server.routing.routing
import no.nav.syfo.fastlegeinformasjon.FastlegeinformasjonService
import no.nav.syfo.fastlegeinformasjon.registerFastlegeinformasjonApi
import no.nav.syfo.helsepersonell.HelsepersonellService
import no.nav.syfo.helsepersonell.registerBehandlerApi
import no.nav.syfo.helsepersonell.registerPingApi
Expand All @@ -13,11 +15,13 @@ import org.koin.ktor.ext.inject

fun Application.configureRouting() {
val helsepersonellService by inject<HelsepersonellService>()
val fastlegeinformasjonService by inject<FastlegeinformasjonService>()
val sykmelderService by inject<SykmelderService>()
routing {
route("/api/v2") {
authenticate("servicebrukerAADv2") {
registerBehandlerApi(helsepersonellService)
registerFastlegeinformasjonApi(fastlegeinformasjonService)
registerPingApi(helsepersonellService)
}
}
Expand Down
86 changes: 85 additions & 1 deletion src/main/resources/openapi/documentation.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: "3.0.0"
openapi: "3.1.0"
info:
title: "syfohelsenettproxy API"
description: "syfohelsenettproxy API"
Expand All @@ -7,6 +7,61 @@ servers:
- url: "https://syfohelsenettproxy.intern.dev.nav.no"
description: dev server
paths:
/internal/is_alive:
get:
description: ""
responses:
"200":
description: "OK"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "I'm alive! :)"
"500":
description: "Internal Server Error"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "I'm dead x_x"
/internal/is_ready:
get:
description: ""
responses:
"200":
description: "OK"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "I'm ready! :)"
"500":
description: "Internal Server Error"
content:
text/plain:
schema:
type: "string"
examples:
Example#1:
value: "Please wait! I'm not ready :("
/internal/prometheus:
get:
description: ""
parameters:
- name: "name[]"
in: "query"
required: false
schema:
type: "array"
items:
type: "string"
/api/v2/behandler:
get:
description: ""
Expand Down Expand Up @@ -65,6 +120,25 @@ paths:
'*/*':
schema:
$ref: "#/components/schemas/Behandler"
/api/v2/fastlegeinformasjon:
get:
description: ""
responses:
"400":
description: "Bad Request"
content:
'*/*':
schema:
type: "string"
examples:
Example#1:
value: "Mangler header `kommunenr` med kommunenr"
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/ExportGPContracts"
/api/v2/ping:
get:
description: ""
Expand Down Expand Up @@ -178,6 +252,16 @@ components:
type: "string"
required:
- "godkjenninger"
ExportGPContracts:
type: "object"
properties:
exportGPContractsResult:
type: "array"
items:
type: "string"
format: "byte"
required:
- "exportGPContractsResult"
Person:
type: "object"
properties:
Expand Down
Loading

0 comments on commit 7ebf799

Please sign in to comment.