Skip to content

Commit

Permalink
Merge pull request #352 from mild-blue/subtitues_run_fixes
Browse files Browse the repository at this point in the history
allow no answers
  • Loading branch information
kubantjan authored Jul 20, 2021
2 parents d8c845d + 11bc53a commit 5a75211
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ class PatientRepository(
newSuspendedTransaction { Patients.deleteWhere(op = where) }


private fun getAndMapPatients(n: Int? = null, offset: Long = 0, where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null): List<PatientDtoOut> {
private fun getAndMapPatients(
n: Int? = null,
offset: Long = 0,
where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null
): List<PatientDtoOut> {
val vaccination1 = Vaccinations.alias("vaccination1")
val vaccination2 = Vaccinations.alias("vaccination2")

Expand All @@ -199,9 +203,11 @@ class PatientRepository(
.let { if (n != null) it.limit(n, offset) else it }
.toList() // eager fetch all data from the database
.let { data ->
val answers = data.groupBy({ it[Patients.id] }, { it.mapAnswer() })
val answers = data.groupBy({ it[Patients.id] }, { it.mapAnswerOrNull() })
data.distinctBy { it[Patients.id] }
.map { mapPatient(it, answers.getValue(it[Patients.id]), vaccination1, vaccination2) }
.map {
mapPatient(it, answers.getValue(it[Patients.id]).filterNotNull(), vaccination1, vaccination2)
}
}
}

Expand Down Expand Up @@ -261,8 +267,10 @@ class PatientRepository(
)
}

private fun ResultRow.mapAnswer() = AnswerDtoOut(
questionId = this[Answers.questionId],
value = this[Answers.value]
)
private fun ResultRow.mapAnswerOrNull() = getOrNull(Answers.patientId)?.let {
AnswerDtoOut(
questionId = this[Answers.questionId],
value = this[Answers.value]
)
}
}
112 changes: 101 additions & 11 deletions backend/src/test/kotlin/blue/mild/covid/vaxx/requests/isin-rerun.http
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 0
}
###
Expand All @@ -36,7 +36,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 2999
}
###
Expand All @@ -50,7 +50,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 5998
}

Expand All @@ -65,7 +65,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 8997
}

Expand All @@ -80,7 +80,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 11996
}

Expand All @@ -95,7 +95,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 14995
}

Expand All @@ -110,7 +110,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 17994
}

Expand All @@ -125,7 +125,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 20993
}

Expand All @@ -140,7 +140,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 22992
}

Expand All @@ -155,7 +155,7 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 24991
}

Expand All @@ -170,7 +170,97 @@ Authorization: Bearer {{auth_token}}
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 3000,
"patientsCount": 10000,
"patientsOffset": 26990
}

###
POST {{url}}/admin/run-isin-job
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"exportPatientsInfo": true,
"checkVaccinations": true,
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 10000,
"patientsOffset": 29989
}

###
POST {{url}}/admin/run-isin-job
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"exportPatientsInfo": true,
"checkVaccinations": true,
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 10000,
"patientsOffset": 32988
}

###
POST {{url}}/admin/run-isin-job
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"exportPatientsInfo": true,
"checkVaccinations": true,
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 10000,
"patientsOffset": 35987
}

###
POST {{url}}/admin/run-isin-job
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"exportPatientsInfo": true,
"checkVaccinations": true,
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 10000,
"patientsOffset": 38986
}

###
POST {{url}}/admin/run-isin-job
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"exportPatientsInfo": true,
"checkVaccinations": true,
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 10000,
"patientsOffset": 41985
}

###
POST {{url}}/admin/run-isin-job
Content-Type: application/json
Authorization: Bearer {{auth_token}}

{
"exportPatientsInfo": true,
"checkVaccinations": true,
"exportVaccinationsFirstDose": true,
"exportVaccinationsSecondDose": true,
"validatePatients": true,
"patientsCount": 10000,
"patientsOffset": 44984
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package blue.mild.covid.vaxx.routes

import blue.mild.covid.vaxx.dao.model.InsuranceCompany
import blue.mild.covid.vaxx.dao.model.UserRole
import blue.mild.covid.vaxx.dao.model.VaccinationBodyPart
import blue.mild.covid.vaxx.dao.repository.PatientRepository
import blue.mild.covid.vaxx.dao.repository.VaccinationRepository
import blue.mild.covid.vaxx.dto.request.IsinJobDtoIn
import blue.mild.covid.vaxx.dto.request.UserRegistrationDtoIn
import blue.mild.covid.vaxx.dto.response.ApplicationInformationDtoOut
import blue.mild.covid.vaxx.dto.response.IsinJobDtoOut
import blue.mild.covid.vaxx.dto.response.SystemStatisticsDtoOut
import blue.mild.covid.vaxx.service.PasswordHashProvider
import blue.mild.covid.vaxx.service.UserService
import blue.mild.covid.vaxx.utils.ServerTestBase
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.server.testing.handleRequest
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import org.kodein.di.DI
import org.kodein.di.bind
import org.kodein.di.instance
import org.kodein.di.singleton
import java.time.Instant
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import kotlin.test.assertEquals


Expand Down Expand Up @@ -46,4 +61,81 @@ class ServiceRoutesTest : ServerTestBase() {
assertEquals(expected, receive())
}
}

@Test
@Suppress("LongMethod")
fun `it should rerun isin job correctly even if patient has no answers`() = withTestApplication {
val patientRepository by closestDI().instance<PatientRepository>()
val vaccinationRepository by closestDI().instance<VaccinationRepository>()
val userService by closestDI().instance<UserService>()

val patientId = runBlocking {
patientRepository.savePatient(
"alice",
"alice",
12345,
"alice",
"1",
"1",
null,
"email",
InsuranceCompany.CPZP,
"indication",
"remoteHost",
mapOf(),
null
)
}

val userId = runBlocking {
userService.registerUser(
UserRegistrationDtoIn(
firstName = "Test",
lastName = "test",
email = "Test",
password = "test",
role = UserRole.ADMIN
)
)
}

runBlocking {
vaccinationRepository.addVaccination(
patientId,
bodyPart = VaccinationBodyPart.BUTTOCK,
vaccinatedOn = Instant.now(),
vaccineSerialNumber = "test",
vaccineExpiration = LocalDate.parse(
"2200-01-01",
DateTimeFormatter.ISO_LOCAL_DATE
),
userPerformingVaccination = userId.id,
doseNumber = 2
)

}

val expected = IsinJobDtoOut(
0, 1, 0, 0,
0, 0, 0,
0, 0, 0
)
val runWhat = IsinJobDtoIn(
exportPatientsInfo = true,
checkVaccinations = true,
exportVaccinationsFirstDose = true,
exportVaccinationsSecondDose = true,
validatePatients = true
)


handleRequest(HttpMethod.Post, Routes.runIsinJob) {
authorize()
jsonBody(runWhat)
}.run {
expectStatus(HttpStatusCode.OK)
val registration = receive<IsinJobDtoOut>()
assertEquals(expected, registration)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class VaccinationRouteTest : ServerTestBase() {
doseNumber = 1
)
val vaccinationFirstDoseId = handleRequest(HttpMethod.Post, Routes.vaccination) {
authorize()
authorize()
jsonBody(inputFirstDose)
}.run {
expectStatus(HttpStatusCode.OK)
Expand Down

0 comments on commit 5a75211

Please sign in to comment.