-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added in fastlegeinformasjonEksport api
- Loading branch information
Showing
12 changed files
with
432 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/no/nav/syfo/fastlegeinformasjon/FastlegeinformasjonApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/no/nav/syfo/fastlegeinformasjon/FastlegeinformasjonException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
) |
100 changes: 100 additions & 0 deletions
100
src/main/kotlin/no/nav/syfo/fastlegeinformasjon/FastlegeinformasjonService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.