Skip to content

Commit

Permalink
Merge pull request #93 from kairos-fhir/patientfinder-medications
Browse files Browse the repository at this point in the history
Patientfinder medications
  • Loading branch information
kairosjonas authored Nov 7, 2024
2 parents f3d8555 + 124438b commit aab7e9c
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 273 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.compiler.level>1.8</java.compiler.level>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<kairos-fhir-dsl.version>1.40.0</kairos-fhir-dsl.version>
<kairos-fhir-dsl.version>1.41.0</kairos-fhir-dsl.version>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<gmavenplus-plugin.version>1.9.1</gmavenplus-plugin.version>
Expand Down
2 changes: 2 additions & 0 deletions src/main/groovy/projects/patientfinder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The following imported data sets are supported/tested:

## 2024-11-06
* moved telecom information from Patient.contact.telecom to Patient.telecom
* Removed unused fields from the MedicationRequest and MedicationAdministration scripts
* added Medication script

## 2024-10-17
* Added the export of MedicationRequest requester from LaborMapping
Expand Down
149 changes: 149 additions & 0 deletions src/main/groovy/projects/patientfinder/medication.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package projects.patientfinder

import de.kairos.centraxx.fhir.r4.utils.FhirUrls
import de.kairos.fhir.centraxx.metamodel.CrfTemplateField
import de.kairos.fhir.centraxx.metamodel.Episode
import de.kairos.fhir.centraxx.metamodel.LaborFinding
import de.kairos.fhir.centraxx.metamodel.LaborFindingLaborValue
import de.kairos.fhir.centraxx.metamodel.LaborMapping
import de.kairos.fhir.centraxx.metamodel.LaborMethod
import de.kairos.fhir.centraxx.metamodel.LaborValue
import de.kairos.fhir.centraxx.metamodel.enums.MedicationServiceType
import de.kairos.fhir.dsl.r4.context.Context

import static de.kairos.fhir.centraxx.metamodel.AbstractIdContainer.PSN
import static de.kairos.fhir.centraxx.metamodel.RootEntities.medication

final String DOSAGE_SITE = "dosage.site"
final String DOSAGE_DOSEANDRATE_RATEQUANTITY_UNIT = "dosage.doseAndRate.rateQuantity.unit"
final String VOLUMEINFUSED = "volumeinfused"
final String VOLUMEINFUSED_UOM = "volumeinfused_uom"
final String CONCENTRATION_STRENGTH = "concentration_strength"
final String CONCENTRATION_STRENGTH_UNIT = "concentration_strength_unit"

final Map PROFILE_TYPES = [
DOSAGE_SITE : LaborFindingLaborValue.STRING_VALUE,
DOSAGE_DOSEANDRATE_RATEQUANTITY_UNIT: LaborFindingLaborValue.STRING_VALUE,
VOLUMEINFUSED : LaborFindingLaborValue.NUMERIC_VALUE,
VOLUMEINFUSED_UOM : LaborFindingLaborValue.STRING_VALUE,
CONCENTRATION_STRENGTH : LaborFindingLaborValue.NUMERIC_VALUE,
CONCENTRATION_STRENGTH_UNIT : LaborFindingLaborValue.STRING_VALUE
]


/**
* Represents a CXX MedicationAdministration -> extracts the Medication data
*
* @author Jonas Küttner
* v.1.41.0, CXX.v.2024.4.2
*/
medication {

if (context.source[medication().entitySource()] != "SACT") {
return
}

final def mapping = getLaborMapping(context)

final Map<String, Map> lflvMap = getLflvMap(mapping, PROFILE_TYPES)

id = "Medication/" + context.source[medication().id()]

code {
coding {
system = FhirUrls.System.Medication.BASE_URL
code = context.source[medication().code()] as String
display = context.source[medication().name()] as String
}
}

if (medication().applicationMedium()){
form {
coding {
code = context.source[medication().applicationMedium()] as String
}
}
}

ingredient {
itemCodeableConcept {
if (context.source[medication().agent()]) {
coding {
system = FhirUrls.System.Medication.AGENT
code = context.source[medication().agent()] as String
}
}
if (context.source[medication().agentGroup()]) {
coding {
system = FhirUrls.System.Medication.AGENT_GROUP
code = context.source[medication().agentGroup()] as String
}
}
}

strength {
if (lflvMap.containsKey(CONCENTRATION_STRENGTH)) {
numerator {
value = lflvMap[CONCENTRATION_STRENGTH][LaborFindingLaborValue.NUMERIC_VALUE]
unit = lflvMap[CONCENTRATION_STRENGTH_UNIT][LaborFindingLaborValue.STRING_VALUE]
}
}
}
}
}

/**
* removes milli seconds and time zone.
* @param dateTimeString the date time string
* @return the result might be something like "1989-01-15T00:00:00"
*/
static String normalizeDate(final String dateTimeString) {
return dateTimeString != null ? dateTimeString.substring(0, 19) : null
}

static boolean isFakeEpisode(final def episode) {
if (episode == null) {
return true
}

if (["SACT", "COSD"].contains(episode[Episode.ENTITY_SOURCE])) {
return true
}

final def fakeId = episode[Episode.ID_CONTAINER]?.find { (it[PSN] as String).toUpperCase().startsWith("FAKE") }
return fakeId != null
}

static Map<String, Map> getLflvMap(final def mapping, final Map<String, String> types) {
final Map<String, Map> lflvMap = [:]
if (!mapping) {
return lflvMap
}

types.each { final String lvCode, final String lvType ->
final def lflv = mapping[LaborMapping.LABOR_FINDING][LaborFinding.LABOR_FINDING_LABOR_VALUES].find { final def lflv ->
lflv[LaborFindingLaborValue.CRF_TEMPLATE_FIELD][CrfTemplateField.LABOR_VALUE][LaborValue.CODE] == lvCode
}
if (lflv && lflv[lvType]) {
lflvMap[lvCode] = [key: lflv[lvType]]
}
}
return lflvMap
}

static def getLaborMapping(final Context context){
if (context.source[medication().serviceType()] as MedicationServiceType == MedicationServiceType.GAB) {
return context.source[medication().laborMappings()].find { final def lm ->
lm[LaborMapping.LABOR_FINDING][LaborFinding.LABOR_METHOD][LaborMethod.CODE] == "MedicationAdministration_profile"
}
}

if (context.source[medication().serviceType()] as MedicationServiceType == MedicationServiceType.VER) {
return context.source[medication().laborMappings()].find { final def lm ->
lm[LaborMapping.LABOR_FINDING][LaborFinding.LABOR_METHOD][LaborMethod.CODE] == "MedicationRequest_profile"
}
}

return null
}

Loading

0 comments on commit aab7e9c

Please sign in to comment.