Skip to content

Commit

Permalink
IS-2855: Søk bare med fodselsdato (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe authored Dec 2, 2024
1 parent 1f8a716 commit f52fc95
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import no.nav.syfo.personstatus.domain.SearchQuery
import java.time.LocalDate

data class SearchQueryDTO(
val initials: String,
val initials: String?,
val birthdate: LocalDate,
) {
fun toSearchQuery(): SearchQuery = SearchQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package no.nav.syfo.personstatus.domain
import java.time.LocalDate

data class SearchQuery(
val initials: Initials,
val initials: Initials?,
val birthdate: LocalDate,
)

@JvmInline
value class Initials(val value: String) {
value class Initials(val value: String?) {
init {
require(value.length > 1) { "Initials must be more than one characters long" }
require(value == null || value.length > 1) { "Initials must be null or more than one characters long" }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,20 @@ class PersonOversiktStatusRepository(private val database: DatabaseInterface) :
}

override fun searchPerson(searchQuery: SearchQuery): List<PersonOversiktStatus> {
val initials = searchQuery.initials.value.toList()
val initials = searchQuery.initials?.value?.toList()
val baseQuery =
"SELECT * FROM PERSON_OVERSIKT_STATUS p WHERE (p.oppfolgingstilfelle_end + INTERVAL '16 DAY' >= now() OR $AKTIV_OPPGAVE_WHERE_CLAUSE) AND p.fodselsdato = ? AND "
val nameQuery = "p.name ILIKE ?"
val initialsSearchString = initials.joinToString(separator = "% ", postfix = "%")
"SELECT * FROM PERSON_OVERSIKT_STATUS p WHERE (p.oppfolgingstilfelle_end + INTERVAL '16 DAY' >= now() OR $AKTIV_OPPGAVE_WHERE_CLAUSE) AND p.fodselsdato = ? "
val nameQuery = initials?.let {
"AND p.name ILIKE ? "
} ?: ""
val orderBy = "ORDER BY name ASC"
val initialsSearchString = initials?.joinToString(separator = "% ", postfix = "%")
return database.connection.use { connection ->
connection.prepareStatement(baseQuery + nameQuery).use {
connection.prepareStatement(baseQuery + nameQuery + orderBy).use {
it.setDate(1, Date.valueOf(searchQuery.birthdate))
it.setString(2, initialsSearchString)
if (initials != null) {
it.setString(2, initialsSearchString)
}
it.executeQuery().toList { toPPersonOversiktStatus() }
}.map { it.toPersonOversiktStatus() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,52 @@ object PersonoversiktSearchApiSpek : Spek({
}
}

it("returns sykmeldt person matching search using fodselsdato when veileder has access to person") {
val newPersonOversiktStatus =
PersonOversiktStatus(fnr = UserConstants.ARBEIDSTAKER_FNR, navn = "Fornavn Etternavn", fodselsdato = fodselsdato, latestOppfolgingstilfelle = activeOppfolgingstilfelle)
personOversiktStatusRepository.createPersonOversiktStatus(newPersonOversiktStatus)
val searchQueryDTO = SearchQueryDTO(initials = null, birthdate = fodselsdato)

with(
handleRequest(HttpMethod.Post, url) {
addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
addHeader(HttpHeaders.Authorization, bearerHeader(validToken))
setBody(objectMapper.writeValueAsString(searchQueryDTO))
}
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val personer = objectMapper.readValue<List<PersonOversiktStatusDTO>>(response.content!!)
personer.size shouldBeEqualTo 1
personer.first().fnr shouldBeEqualTo UserConstants.ARBEIDSTAKER_FNR
}
}
it("returns sykmeldte personer matching search using fodselsdato when veileder has access to personer") {
val newPersonOversiktStatus =
PersonOversiktStatus(fnr = UserConstants.ARBEIDSTAKER_FNR, navn = "Fornavn Etternavn", fodselsdato = fodselsdato, latestOppfolgingstilfelle = activeOppfolgingstilfelle)
val newPersonOversiktStatus2 =
PersonOversiktStatus(fnr = UserConstants.ARBEIDSTAKER_2_FNR, navn = "Firstname Etternavn", fodselsdato = fodselsdato, latestOppfolgingstilfelle = activeOppfolgingstilfelle)
val newPersonOversiktStatus3 =
PersonOversiktStatus(fnr = UserConstants.ARBEIDSTAKER_NO_ACCESS, navn = "Forstname Etternavn", fodselsdato = fodselsdato, latestOppfolgingstilfelle = activeOppfolgingstilfelle)
personOversiktStatusRepository.createPersonOversiktStatus(newPersonOversiktStatus)
personOversiktStatusRepository.createPersonOversiktStatus(newPersonOversiktStatus2)
personOversiktStatusRepository.createPersonOversiktStatus(newPersonOversiktStatus3)
val searchQueryDTO = SearchQueryDTO(initials = null, birthdate = fodselsdato)

with(
handleRequest(HttpMethod.Post, url) {
addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
addHeader(HttpHeaders.Authorization, bearerHeader(validToken))
setBody(objectMapper.writeValueAsString(searchQueryDTO))
}
) {
response.status() shouldBeEqualTo HttpStatusCode.OK
val personer = objectMapper.readValue<List<PersonOversiktStatusDTO>>(response.content!!)
personer.size shouldBeEqualTo 2
personer[0].fnr shouldBeEqualTo UserConstants.ARBEIDSTAKER_2_FNR
personer[1].fnr shouldBeEqualTo UserConstants.ARBEIDSTAKER_FNR
}
}

it("does not return sykmeldt person not matching search when veileder has access to person") {
val newPersonOversiktStatus =
PersonOversiktStatus(fnr = UserConstants.ARBEIDSTAKER_FNR, navn = "Fornavn Etternavn", fodselsdato = fodselsdato, latestOppfolgingstilfelle = activeOppfolgingstilfelle)
Expand Down

0 comments on commit f52fc95

Please sign in to comment.