Skip to content

Commit

Permalink
IS-2855: Forenkle søk med initialer (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
geir-waagboe authored Dec 2, 2024
1 parent 1d8d906 commit 1f8a716
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,12 @@ class PersonOversiktStatusRepository(private val database: DatabaseInterface) :
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 ? AND " + initials.drop(1).joinToString(" AND ") { "p.name ILIKE ?" }
val nameQuery = "p.name ILIKE ?"
val initialsSearchString = initials.joinToString(separator = "% ", postfix = "%")
return database.connection.use { connection ->
connection.prepareStatement(baseQuery + nameQuery).use {
var parameterIndex = 1
it.setDate(parameterIndex++, Date.valueOf(searchQuery.birthdate))
initials.forEachIndexed { index, param ->
if (index == 0) {
it.setString(parameterIndex++, "$param%")
} else {
it.setString(parameterIndex++, "% $param%")
}
}
it.setDate(1, Date.valueOf(searchQuery.birthdate))
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,23 @@ object PersonoversiktSearchApiSpek : Spek({
}
}

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)
personOversiktStatusRepository.createPersonOversiktStatus(newPersonOversiktStatus)
val searchQueryDTO = SearchQueryDTO(initials = "FN", 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.NoContent
}
}

it("returns nothing when no person matching search") {
val newPersonOversiktStatus =
PersonOversiktStatus(fnr = UserConstants.ARBEIDSTAKER_FNR, navn = "Fornavn Etternavn", fodselsdato = fodselsdato, latestOppfolgingstilfelle = activeOppfolgingstilfelle)
Expand Down

0 comments on commit 1f8a716

Please sign in to comment.