Skip to content

Commit

Permalink
IS-2732: Oppdatere spesifikk behandler fra Adresseregisteret (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe authored Oct 18, 2024
1 parent 5d9fec3 commit b1d54a7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import no.nav.syfo.cronjob.leaderelection.LeaderPodClient
import no.nav.syfo.dialogmelding.DialogmeldingService
import no.nav.syfo.dialogmelding.cronjob.DialogmeldingStatusCronjob
import no.nav.syfo.dialogmelding.status.DialogmeldingStatusService
import java.util.UUID

fun cronjobModule(
applicationState: ApplicationState,
Expand Down Expand Up @@ -53,6 +54,7 @@ fun cronjobModule(
behandlerService = behandlerService,
fastlegeClient = fastlegeClient,
syfohelsenettproxyClient = syfohelsenettproxyClient,
behandlerToBeUpdated = listOf(UUID.fromString("3f5c938d-b16a-4474-a294-9e121e7efd17"))
)

listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class VerifyBehandlereForKontorCronjob(
val behandlerService: BehandlerService,
val fastlegeClient: FastlegeClient,
val syfohelsenettproxyClient: SyfohelsenettproxyClient,
val behandlerToBeUpdated: List<UUID> = emptyList(),
) : DialogmeldingCronjob {
private val runAtHour = 6
private val runDay = DayOfWeek.SUNDAY
Expand Down Expand Up @@ -304,8 +305,10 @@ class VerifyBehandlereForKontorCronjob(
val hprPersonident = Personident(hprBehandlerFnr)
val existingPersonIdent = existingBehandler.personident?.let { Personident(it) }

val doUpdatePersonident = existingPersonIdent == null || existingPersonIdent.isDnrMatchingFnr(hprPersonident)
// TODO: handle remaining case: personident changed, but not DNR from before
val doUpdatePersonident = existingPersonIdent == null ||
existingPersonIdent.isDnrMatchingFnr(hprPersonident) ||
behandlerToBeUpdated.contains(existingBehandler.behandlerRef)

if (doUpdatePersonident) {
behandlerService.updateBehandlerPersonident(
behandlerRef = existingBehandler.behandlerRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import no.nav.syfo.testhelper.UserConstants.BEHANDLER_ETTERNAVN
import no.nav.syfo.testhelper.UserConstants.BEHANDLER_FORNAVN
import no.nav.syfo.testhelper.UserConstants.FASTLEGE_DNR
import no.nav.syfo.testhelper.UserConstants.FASTLEGE_FNR
import no.nav.syfo.testhelper.UserConstants.FASTLEGE_TREDJE_FNR
import no.nav.syfo.testhelper.UserConstants.FASTLEGE_UTEN_KATEGORI_FNR
import no.nav.syfo.testhelper.UserConstants.HERID
import no.nav.syfo.testhelper.UserConstants.HERID_KONTOR_OK
Expand Down Expand Up @@ -75,10 +76,12 @@ class VerifyBehandlereForKontorCronjobSpek : Spek({
),
database = database,
)
val behandlerToBeUpdated = UUID.randomUUID()
val cronJob = VerifyBehandlereForKontorCronjob(
behandlerService = behandlerService,
fastlegeClient = fastlegeClient,
syfohelsenettproxyClient = syfohelsenettproxyClient,
behandlerToBeUpdated = listOf(behandlerToBeUpdated),
)
beforeEachTest {
database.dropData()
Expand Down Expand Up @@ -258,6 +261,31 @@ class VerifyBehandlereForKontorCronjobSpek : Spek({
pBehandlerAfter.herId shouldBeEqualTo HERID.toString()
pBehandlerAfter.kategori shouldBeEqualTo BehandlerKategori.LEGE.name
}
it("Cronjob oppdaterer spesifikk behandler") {
val kontorId = createKontor(HERID_KONTOR_OK)
val pBehandler = createBehandler(
behandlerRef = behandlerToBeUpdated,
kontorId = kontorId,
hprId = HPRID,
personident = FASTLEGE_TREDJE_FNR,
fornavn = "for",
etternavn = "etter",
kategori = BehandlerKategori.LEGE,
)
runBlocking {
cronJob.verifyBehandlereForKontorJob()
}
val behandlerAfter = database.getBehandlereForKontor(kontorId)
behandlerAfter.size shouldBeEqualTo 2
val pBehandlerAfter = behandlerAfter.first { it.hprId == HPRID.toString() }
pBehandlerAfter.id shouldBeEqualTo pBehandler.id
pBehandlerAfter.personident shouldBeEqualTo FASTLEGE_FNR.value
pBehandlerAfter.behandlerRef shouldBeEqualTo pBehandler.behandlerRef
pBehandlerAfter.fornavn shouldBeEqualTo BEHANDLER_FORNAVN
pBehandlerAfter.etternavn shouldBeEqualTo BEHANDLER_ETTERNAVN
pBehandlerAfter.herId shouldBeEqualTo HERID.toString()
pBehandlerAfter.kategori shouldBeEqualTo BehandlerKategori.LEGE.name
}
it("Cronjob legger til ny behandler og invaliderer eksisterende") {
val kontorId = createKontor(HERID_KONTOR_OK)
val pBehandler = createBehandler(kontorId)
Expand Down Expand Up @@ -316,9 +344,10 @@ private fun createBehandler(
fornavn: String = BEHANDLER_FORNAVN,
etternavn: String = BEHANDLER_ETTERNAVN,
kategori: BehandlerKategori = BehandlerKategori.LEGE,
behandlerRef: UUID = UUID.randomUUID(),
) = database.createBehandler(
behandler = Behandler(
behandlerRef = UUID.randomUUID(),
behandlerRef = behandlerRef,
fornavn = fornavn,
mellomnavn = null,
etternavn = etternavn,
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/no/nav/syfo/testhelper/UserConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object UserConstants {
val FASTLEGE_FNR_SUSPENDERT = Personident("12125678912")
val FASTLEGE_DNR = Personident("52125678911")
val FASTLEGE_ANNEN_FNR = Personident(FASTLEGE_FNR.value.replace("2", "4"))
val FASTLEGE_TREDJE_FNR = Personident(FASTLEGE_FNR.value.replace("2", "5"))
val FASTLEGE_UTEN_KATEGORI_FNR = Personident(FASTLEGE_FNR.value.replace("2", "5"))

val BEHANDLER_FORNAVN = "Behandler"
Expand Down

0 comments on commit b1d54a7

Please sign in to comment.