Skip to content

Commit

Permalink
Merge pull request #324 from mild-blue/unified_search
Browse files Browse the repository at this point in the history
Unified search
  • Loading branch information
tomaskourim authored Jun 16, 2021
2 parents a3c130b + 4faf8a2 commit e55bffc
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 19,856 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ package blue.mild.covid.vaxx.dto.request.query
import com.papsign.ktor.openapigen.annotations.parameters.QueryParam

data class PatientByPersonalOrInsuranceNumberQueryDtoIn(
@QueryParam("Patient personal number") val personalNumber: String?,
@QueryParam("Patient insurance number") val insuranceNumber: String?
@QueryParam("Patient personal or insurance number") val personalOrInsuranceNumber: String
)
12 changes: 6 additions & 6 deletions backend/src/main/kotlin/blue/mild/covid/vaxx/isin/isin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ private const val PUBLIC_ROOT = "https://apidoc.uzis.cz/api/v1"
private const val TEST_ROOT = "https://apitest.uzis.cz/api/v1"
private const val PRODUCTION_ROOT = "https://api.uzis.cz/api/v1"

// 000 je pro polikliniky - neni to placeholder
// 000 je poradove cislo zarizeni - neni to placeholder
// https://nrpzs.uzis.cz/detail-66375-clinicum-a-s.html#fndtn-detail_uzis
private const val PCZ = "000"
private const val NRZP_CISLO = "184070832"
private const val NRZP_CISLO = "123456789"
// rodne cislo pracovnika je z PDFka
private val pracovnikO = Pracovnik(pcz = PCZ, nrzpCislo = NRZP_CISLO, rodneCislo = "9910190015")
private val pracovnikO = Pracovnik(pcz = PCZ, nrzpCislo = NRZP_CISLO, rodneCislo = "1234567890")
private const val URL_VYTVOR_NEBO_ZMEN_VAKCINACI = "vakcinace/VytvorNeboZmenVakcinaci"
private const val URL_VYTVOR_NEBO_ZMEN_DAVKU = "vakcinace/VytvorNeboZmenDavku"
private const val URL_ZMEN_STAV_VAKCINACE = "vakcinace/ZmenStavVakcinace"
Expand All @@ -72,9 +72,9 @@ data class InputPacient(
val rodneCislo: String
)
private val patients = mapOf(
IsinEnvironment.PUBLIC to InputPacient("Jan", "Kubant", "9002030015"),
IsinEnvironment.PUBLIC to InputPacient("Jan", "Kubant", "1234567890"),
IsinEnvironment.TEST to InputPacient("VICTOR", "BUDIUC", "8208258201"),
IsinEnvironment.PRODUCTION to InputPacient("Jan", "Kubant", "9002030015"),
IsinEnvironment.PRODUCTION to InputPacient("Josef", "Navratil", "1234567890"),
)

// Dummy class to wrap data around paracovnik
Expand Down Expand Up @@ -105,7 +105,7 @@ private val userIdentification = "?pcz=${pracovnik.pcz}&pracovnikNrzpCislo=${pra

private val configuration = KeyStoreConfiguration(
storePass = getEnv("ISIN_STORE_PASS") ?: "",
storePath = getEnv("ISIN_STORE_PATH") ?: "/home/honza/Desktop/rgu_ws_44797362.pfx",
storePath = getEnv("ISIN_STORE_PATH") ?: "/path/to/isin/certificate.pfx",
storeType = getEnv("ISIN_STORE_TYPE") ?: "JKS",
keyPass = getEnv("ISIN_KEY_PASS") ?: ""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import blue.mild.covid.vaxx.dto.response.OK
import blue.mild.covid.vaxx.dto.response.Ok
import blue.mild.covid.vaxx.dto.response.PatientDtoOut
import blue.mild.covid.vaxx.dto.response.PatientRegistrationResponseDtoOut
import blue.mild.covid.vaxx.error.HttpParametersException
import blue.mild.covid.vaxx.error.IsinValidationException
import blue.mild.covid.vaxx.extensions.asContextAware
import blue.mild.covid.vaxx.extensions.closestDI
Expand Down Expand Up @@ -143,31 +142,16 @@ fun NormalOpenAPIRoute.patientRoutes() {
val principal = principal()
if (logger.isDebugEnabled) {
logger.debug {
"User ${principal.userId} search by personalNumber=${patientQuery.personalNumber} and " +
"insuranceNumber=${patientQuery.insuranceNumber}."
"User ${principal.userId} search by personal or insurance number=${patientQuery.personalOrInsuranceNumber}."
}
} else {
logger.info { "User ${principal.userId} search by personal number or insurance number." }
}

val patient = when {
patientQuery.personalNumber != null && patientQuery.insuranceNumber == null -> {
patientService.getPatientByPersonalNumber(patientQuery.personalNumber)
}
patientQuery.personalNumber == null && patientQuery.insuranceNumber != null -> {
patientService.getPatientByInsuranceNumber(patientQuery.insuranceNumber)
}
patientQuery.personalNumber != null && patientQuery.insuranceNumber != null -> {
throw HttpParametersException("Personal number and insurance number cannot be specified in the same time.")
}
patientQuery.personalNumber == null && patientQuery.insuranceNumber == null -> {
throw HttpParametersException("Personal number or insurance number has to be specified.")
}
else -> {
throw NotImplementedError("This should not happen")
}
}
logger.debug { "Patient found under id ${patient.id}." }
val patient =
patientService.getPatientByPersonalOrInsuranceNumber(patientQuery.personalOrInsuranceNumber)

logger.info { "Patient found under id ${patient.id}." }
respond(patient)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package blue.mild.covid.vaxx.service

import blue.mild.covid.vaxx.dao.model.DatabaseTypeLength
import blue.mild.covid.vaxx.dao.model.EntityId
import blue.mild.covid.vaxx.dao.model.Patients
import blue.mild.covid.vaxx.dao.repository.PatientRepository
import blue.mild.covid.vaxx.dto.internal.ContextAware
import blue.mild.covid.vaxx.dto.request.PatientRegistrationDtoIn
import blue.mild.covid.vaxx.dto.request.PatientUpdateDtoIn
import blue.mild.covid.vaxx.dto.response.PatientDtoOut
import blue.mild.covid.vaxx.error.EntityNotFoundException
import blue.mild.covid.vaxx.error.entityNotFound
import blue.mild.covid.vaxx.utils.formatPhoneNumber
import blue.mild.covid.vaxx.utils.normalizePersonalNumber
Expand Down Expand Up @@ -37,20 +39,35 @@ class PatientService(
/**
* Returns single patient with given personal number or throws exception.
*/
suspend fun getPatientByPersonalNumber(patientPersonalNumber: String): PatientDtoOut =
private suspend fun getPatientByPersonalNumber(patientPersonalNumber: String): PatientDtoOut? =
patientRepository.getAndMapPatientsBy {
Patients.personalNumber eq patientPersonalNumber.normalizePersonalNumber()
}.singleOrNull()?.withSortedAnswers()
?: throw entityNotFound<Patients>(Patients::personalNumber, patientPersonalNumber)

/**
* Returns single patient with given insurance number or throws exception.
*/
suspend fun getPatientByInsuranceNumber(patientInsuranceNumber: String): PatientDtoOut =
patientRepository.getAndMapPatientsBy{
private suspend fun getPatientByInsuranceNumber(patientInsuranceNumber: String): PatientDtoOut? =
patientRepository.getAndMapPatientsBy {
Patients.insuranceNumber eq patientInsuranceNumber.trim()
}.singleOrNull()?.withSortedAnswers()
?: throw entityNotFound<Patients>(Patients::insuranceNumber, patientInsuranceNumber)

/**
* Returns single patient with given personal or insurance number or throws exception.
*/
suspend fun getPatientByPersonalOrInsuranceNumber(patientPersonalOrInsuranceNumber: String): PatientDtoOut {
// TODO theoretically, there could be a patient with an insurance number same as personal number of some other patient.
// In this case, we cannot find the patient with the personal number. https://github.com/mild-blue/covid-vaxx/issues/329
var patient = getPatientByInsuranceNumber(patientPersonalOrInsuranceNumber)
if (patient == null && patientPersonalOrInsuranceNumber.length <= DatabaseTypeLength.PERSONAL_NUMBER) {
patient = getPatientByPersonalNumber(patientPersonalOrInsuranceNumber)
}
return patient ?: throw EntityNotFoundException(
"Patient",
"personal or insurance number",
patientPersonalOrInsuranceNumber
)
}

/**
* Filters the database with the conjunction (and clause) of the given properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"email": "vaxx@mild.blue",
"password": "bluemild"
},
"prod": {
"test": {
"url": "https://covid-vaxx.test.mild.blue/api"
},
"production": {
"url": "https://ockovani.praha7.cz/api"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ GET {{url}}/statistics
Content-Type: application/json
Authorization: Bearer {{auth_token}}



###


POST {{url}}/admin/locations?captcha=1234
Content-Type: application/json
Authorization: Bearer {{auth_token}}
Expand All @@ -47,11 +44,11 @@ Authorization: Bearer {{auth_token}}

{
"locationId": "{{location_id}}",
"from": "2021-06-18T13:00:00.00000000Z",
"to": "2021-06-18T20:00:00.00000000Z",
"bandwidth": 5,
"durationMillis": 75600,
"queueOffset": 4
"from": "2021-06-11T05:00:00.00000000Z",
"to": "2021-06-11T10:45:00.00000000Z",
"bandwidth": 1,
"durationMillis": 300000,
"queueOffset": 0
}

###
Expand All @@ -60,9 +57,9 @@ POST {{url}}/patient?captcha=1234
Content-Type: application/json

{
"firstName": "Adéla",
"lastName": "Kostičková",
"personalNumber": "9151010385",
"firstName": "Tomáš",
"lastName": "Kos",
"insuranceNumber": "1234567890",
"email": "kubant.jan@example.com",
"phoneNumber": {
"countryCode": "CZ",
Expand Down Expand Up @@ -113,7 +110,8 @@ Content-Type: application/json
}
###

GET {{url}}/admin/patient?personalNumber=9151010385
// find patient
GET {{url}}/admin/patient?personalOrInsuranceNumber=1234567989
Content-Type: application/json
Authorization: Bearer {{auth_token}}

Expand All @@ -131,6 +129,7 @@ Authorization: Bearer {{auth_token}}
"patientId":"{{patient_id}}"
}


###

// register user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class PatientRoutesTest : ServerTestBase() {
}

// get patient by personal number
handleRequest(HttpMethod.Get, "${Routes.adminSectionPatient}?personalNumber=${validRegistration.personalNumber}") {
handleRequest(HttpMethod.Get, "${Routes.adminSectionPatient}?personalOrInsuranceNumber=${validRegistration.personalNumber}") {
authorize()
}.run {
expectStatus(HttpStatusCode.OK)
Expand Down
Loading

0 comments on commit e55bffc

Please sign in to comment.