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
|
import org.apache.commons.codec.digest.DigestUtils
|
||||||
|
|
||||||
@JvmInline
|
@JvmInline
|
||||||
value class ConditionId(val value: String)
|
value class ConditionId(val value: String) {
|
||||||
|
|
||||||
data class Condition(val id: ConditionId, val version: Int, val icd10: String) {
|
|
||||||
companion object {
|
companion object {
|
||||||
fun generateConditionId(patientId: String, tumorId: String): ConditionId {
|
fun generateConditionId(patientId: String, tumorId: String): ConditionId {
|
||||||
return ConditionId(DigestUtils.sha256Hex("$patientId-$tumorId"))
|
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 {
|
class ConditionInMemoryRepository {
|
||||||
|
|
||||||
private val conditions = mutableMapOf<ConditionId, Condition>()
|
private val conditions = mutableMapOf<ConditionId, Condition>()
|
||||||
@ -25,12 +25,9 @@ class ConditionInMemoryRepository {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveIfNotOlderNewerVersion(condition: Condition): Boolean {
|
fun save(condition: Condition): Boolean {
|
||||||
if ((this.conditions[condition.id]?.version ?: 0) <= condition.version) {
|
this.conditions[condition.id] = condition
|
||||||
this.conditions[condition.id] = condition
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findAll(): List<Condition> {
|
fun findAll(): List<Condition> {
|
||||||
|
@ -37,10 +37,9 @@ class ObdsFhirTopicMonitor(
|
|||||||
|
|
||||||
if (firstEntry.resource.fhirType() == "Condition") {
|
if (firstEntry.resource.fhirType() == "Condition") {
|
||||||
val condition = firstEntry.resource as org.hl7.fhir.r4.model.Condition
|
val condition = firstEntry.resource as org.hl7.fhir.r4.model.Condition
|
||||||
val updated = conditionRepository.saveIfNotOlderNewerVersion(
|
val updated = conditionRepository.save(
|
||||||
Condition(
|
Condition(
|
||||||
ConditionId(condition.id),
|
ConditionId(condition.id),
|
||||||
0,
|
|
||||||
condition.code.coding.first { "http://fhir.de/CodeSystem/bfarm/icd-10-gm" == it.system }.code
|
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 com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import dev.pcvolkmer.oncoanalytics.monitor.StatisticsSink
|
import dev.pcvolkmer.oncoanalytics.monitor.StatisticsSink
|
||||||
import dev.pcvolkmer.oncoanalytics.monitor.conditions.Condition
|
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.conditions.ConditionInMemoryRepository
|
||||||
import dev.pcvolkmer.oncoanalytics.monitor.fetchStatistics
|
import dev.pcvolkmer.oncoanalytics.monitor.fetchStatistics
|
||||||
import org.springframework.beans.factory.annotation.Qualifier
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
@ -53,9 +54,9 @@ class ObdsXmlTopicMonitor(
|
|||||||
|
|
||||||
val updated = conditionRepository.saveIfNewerVersion(
|
val updated = conditionRepository.saveIfNewerVersion(
|
||||||
Condition(
|
Condition(
|
||||||
Condition.generateConditionId(patientId, tumorId),
|
ConditionId.fromPatientIdAndTumorId(patientId, tumorId),
|
||||||
p.payload.version,
|
icd10,
|
||||||
icd10
|
p.payload.version
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user