-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IS-2833: Sjekke duplikatfelt i sykmelding
- Loading branch information
1 parent
f3ddee0
commit c707118
Showing
6 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/kotlin/no/nav/syfo/database/SykmeldingFieldsRepository.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,71 @@ | ||
package no.nav.syfo.database | ||
|
||
import no.nav.syfo.domain.PersonIdent | ||
import java.sql.Connection | ||
import java.sql.SQLException | ||
import java.time.OffsetDateTime | ||
import java.util.UUID | ||
|
||
class SykmeldingFieldsRepository() { | ||
|
||
fun createPersonoppgaveSykmeldingFields( | ||
referanseUUID: UUID, | ||
personident: PersonIdent, | ||
tiltakNav: String?, | ||
tiltakAndre: String?, | ||
bistand: String?, | ||
connection: Connection, | ||
) { | ||
val idList = connection.prepareStatement(CREATE_SYKMELDING_FIELDS).use { | ||
it.setString(1, referanseUUID.toString()) | ||
it.setObject(2, OffsetDateTime.now()) | ||
it.setString(3, personident.value) | ||
it.setString(4, tiltakNav ?: "") | ||
it.setString(5, tiltakAndre ?: "") | ||
it.setString(6, bistand ?: "") | ||
it.executeQuery().toList { getInt("id") } | ||
} | ||
|
||
if (idList.size != 1) { | ||
throw SQLException("Creating sykmelding failed, no rows affected.") | ||
} | ||
} | ||
|
||
fun findExistingPersonoppgaveFromSykmeldingFields( | ||
personident: PersonIdent, | ||
tiltakNav: String?, | ||
tiltakAndre: String?, | ||
bistand: String?, | ||
connection: Connection, | ||
) = connection.prepareStatement(FIND_EXISTING_FROM_SYKMELDING_FIELDS).use { | ||
it.setString(1, personident.value) | ||
it.setString(2, tiltakNav ?: "") | ||
it.setString(3, tiltakAndre ?: "") | ||
it.setString(4, bistand ?: "") | ||
it.executeQuery().toList { getInt("id") }.isNotEmpty() | ||
} | ||
|
||
companion object { | ||
private const val CREATE_SYKMELDING_FIELDS = | ||
""" | ||
INSERT INTO SYKMELDING ( | ||
id, | ||
referanse_uuid, | ||
created_at, | ||
personident, | ||
tiltak_nav, | ||
tiltak_andre, | ||
bistand) | ||
VALUES (DEFAULT, ?, ?, ?, ?, ?, ?) RETURNING id | ||
""" | ||
|
||
private const val FIND_EXISTING_FROM_SYKMELDING_FIELDS = | ||
""" | ||
SELECT id FROM SYKMELDING WHERE | ||
personident = ? AND | ||
tiltak_nav = ? AND | ||
tiltak_andre = ? AND | ||
bistand = ? | ||
""" | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/resources/db/migration/V5_9__create_table_sykmelding.sql
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,11 @@ | ||
CREATE TABLE sykmelding ( | ||
id SERIAL PRIMARY KEY, | ||
created_at TIMESTAMPTZ NOT NULL, | ||
referanse_uuid CHAR(36) NOT NULL, | ||
personident VARCHAR(11) NOT NULL, | ||
tiltak_nav TEXT NOT NULL, | ||
tiltak_andre TEXT NOT NULL, | ||
bistand TEXT NOT NULL | ||
); | ||
|
||
CREATE INDEX ix_sykmelding_personident ON sykmelding(personident); |
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