mirror of
https://github.com/pcvolkmer/etl-processor.git
synced 2025-07-03 23:12:54 +00:00
Add statistics for state per patient
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
package dev.dnpm.etl.processor.monitoring
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.jdbc.repository.query.Query
|
||||
import org.springframework.data.relational.core.mapping.Embedded
|
||||
import org.springframework.data.relational.core.mapping.Table
|
||||
import org.springframework.data.repository.CrudRepository
|
||||
@ -45,10 +46,20 @@ data class Report(
|
||||
val dataQualityReport: String = ""
|
||||
)
|
||||
|
||||
data class CountedState(
|
||||
val count: Int,
|
||||
val status: RequestStatus,
|
||||
)
|
||||
|
||||
interface RequestRepository : CrudRepository<Request, Long> {
|
||||
|
||||
fun findAllByPatientIdOrderByProcessedAtDesc(patientId: String): List<Request>
|
||||
|
||||
fun findByUuidEquals(uuid: String): Optional<Request>
|
||||
|
||||
@Query("SELECT count(*) AS count, status FROM (" +
|
||||
"SELECT status, rank() OVER (PARTITION BY patient_id ORDER BY processed_at DESC) AS rank FROM request WHERE status NOT IN ('DUPLICATION')" +
|
||||
") rank WHERE rank = 1 GROUP BY status ORDER BY count DESC;")
|
||||
fun findPatientUniqueStates(): List<CountedState>
|
||||
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
package dev.dnpm.etl.processor.web
|
||||
|
||||
import dev.dnpm.etl.processor.monitoring.PatientUniqueState
|
||||
import dev.dnpm.etl.processor.monitoring.RequestRepository
|
||||
import dev.dnpm.etl.processor.monitoring.RequestStatus
|
||||
import org.reactivestreams.Publisher
|
||||
@ -95,6 +96,19 @@ class StatisticsRestController(
|
||||
.sortedBy { it.date }
|
||||
}
|
||||
|
||||
@GetMapping(path = ["requestpatientstates"])
|
||||
fun requestPatientStates(): List<NameValue> {
|
||||
return requestRepository.findPatientUniqueStates().map {
|
||||
val color = when (it.status) {
|
||||
RequestStatus.ERROR -> "red"
|
||||
RequestStatus.WARNING -> "darkorange"
|
||||
RequestStatus.SUCCESS -> "green"
|
||||
else -> "slategray"
|
||||
}
|
||||
NameValue(it.status.toString(), it.count, color)
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(path = ["events"], produces = [MediaType.TEXT_EVENT_STREAM_VALUE])
|
||||
fun updater(): Flux<ServerSentEvent<Any>> {
|
||||
return statisticsUpdateProducer.asFlux().flatMap {
|
||||
@ -105,6 +119,9 @@ class StatisticsRestController(
|
||||
.build(),
|
||||
ServerSentEvent.builder<Any>()
|
||||
.event("requestslastmonth").id("none").data(this.requestsLastMonth())
|
||||
.build(),
|
||||
ServerSentEvent.builder<Any>()
|
||||
.event("requestpatientstates").id("none").data(this.requestPatientStates())
|
||||
.build()
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user