mirror of
https://github.com/pcvolkmer/onco-analytics-monitor.git
synced 2025-04-19 19:16:52 +00:00
refactor: save condition without version check if intended
This will simply save a condition instead of checking if the same version number is smaller.
This commit is contained in:
parent
cbdb8bd4c9
commit
dceff7a9da
@ -3,9 +3,7 @@ package dev.pcvolkmer.oncoanalytics.monitor.conditions
|
||||
import org.apache.commons.codec.digest.DigestUtils
|
||||
|
||||
@JvmInline
|
||||
value class ConditionId(val value: String)
|
||||
|
||||
data class Condition(val id: ConditionId, val version: Int, val icd10: String) {
|
||||
value class ConditionId(val value: String) {
|
||||
companion object {
|
||||
fun generateConditionId(patientId: String, tumorId: String): ConditionId {
|
||||
return ConditionId(DigestUtils.sha256Hex("$patientId-$tumorId"))
|
||||
@ -13,6 +11,8 @@ data class Condition(val id: ConditionId, val version: Int, val icd10: String) {
|
||||
}
|
||||
}
|
||||
|
||||
data class Condition(val id: ConditionId, val icd10: String, val version: Int = 0)
|
||||
|
||||
class ConditionInMemoryRepository {
|
||||
|
||||
private val conditions = mutableMapOf<ConditionId, Condition>()
|
||||
@ -25,13 +25,10 @@ class ConditionInMemoryRepository {
|
||||
return false
|
||||
}
|
||||
|
||||
fun saveIfNotOlderNewerVersion(condition: Condition): Boolean {
|
||||
if ((this.conditions[condition.id]?.version ?: 0) <= condition.version) {
|
||||
fun save(condition: Condition): Boolean {
|
||||
this.conditions[condition.id] = condition
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun findAll(): List<Condition> {
|
||||
return conditions.values.toList()
|
||||
|
@ -37,10 +37,9 @@ class ObdsFhirTopicMonitor(
|
||||
|
||||
if (firstEntry.resource.fhirType() == "Condition") {
|
||||
val condition = firstEntry.resource as org.hl7.fhir.r4.model.Condition
|
||||
val updated = conditionRepository.saveIfNotOlderNewerVersion(
|
||||
val updated = conditionRepository.save(
|
||||
Condition(
|
||||
ConditionId(condition.id),
|
||||
0,
|
||||
condition.code.coding.first { "http://fhir.de/CodeSystem/bfarm/icd-10-gm" == it.system }.code
|
||||
)
|
||||
)
|
||||
|
@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import dev.pcvolkmer.oncoanalytics.monitor.StatisticsSink
|
||||
import dev.pcvolkmer.oncoanalytics.monitor.conditions.Condition
|
||||
import dev.pcvolkmer.oncoanalytics.monitor.conditions.ConditionId
|
||||
import dev.pcvolkmer.oncoanalytics.monitor.conditions.ConditionInMemoryRepository
|
||||
import dev.pcvolkmer.oncoanalytics.monitor.fetchStatistics
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
@ -53,9 +54,9 @@ class ObdsXmlTopicMonitor(
|
||||
|
||||
val updated = conditionRepository.saveIfNewerVersion(
|
||||
Condition(
|
||||
Condition.generateConditionId(patientId, tumorId),
|
||||
p.payload.version,
|
||||
icd10
|
||||
ConditionId.fromPatientIdAndTumorId(patientId, tumorId),
|
||||
icd10,
|
||||
p.payload.version
|
||||
)
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user