Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed the medication scripts to pull additional data from mappings #95

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/main/groovy/projects/patientfinder/medication.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ 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
(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
]


Expand All @@ -43,7 +43,7 @@ medication {

final def mapping = getLaborMapping(context)

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

code {
coding {
Expand Down Expand Up @@ -80,8 +80,8 @@ medication {
strength {
if (lflvMap.containsKey(CONCENTRATION_STRENGTH)) {
numerator {
value = lflvMap[CONCENTRATION_STRENGTH][LaborFindingLaborValue.NUMERIC_VALUE]
unit = lflvMap[CONCENTRATION_STRENGTH_UNIT][LaborFindingLaborValue.STRING_VALUE]
value = lflvMap[CONCENTRATION_STRENGTH]
unit = lflvMap[CONCENTRATION_STRENGTH_UNIT]
}
}
}
Expand Down Expand Up @@ -110,18 +110,19 @@ static boolean isFakeEpisode(final def episode) {
return fakeId != null
}

static Map<String, Map> getLflvMap(final def mapping, final Map<String, String> types) {
final Map<String, Map> lflvMap = [:]
static Map<String, Object> getLflvMap(final def mapping, final Map<String, String> types) {
final Map<String, Object> 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 ->
final def lflvForLv = 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]]

if (lflvForLv && lflvForLv[lvType]) {
lflvMap[(lvCode)] = lflvForLv[lvType]
}
}
return lflvMap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package projects.patientfinder

import ca.uhn.fhir.model.api.TemporalPrecisionEnum
import de.kairos.centraxx.fhir.r4.utils.FhirUrls
import de.kairos.fhir.centraxx.metamodel.CrfTemplateField
import de.kairos.fhir.centraxx.metamodel.Episode
Expand All @@ -10,7 +9,6 @@ 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.Unity
import de.kairos.fhir.centraxx.metamodel.enums.DatePrecision
import de.kairos.fhir.centraxx.metamodel.enums.MedicationServiceType
import org.apache.commons.lang3.StringUtils
import org.hl7.fhir.r4.model.MedicationAdministration
Expand All @@ -26,12 +24,12 @@ 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
(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
]


Expand All @@ -43,17 +41,17 @@ final Map PROFILE_TYPES = [
*/
medicationAdministration {

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

if (context.source[medication().serviceType()] != MedicationServiceType.GAB.name()) {
return
}

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

final def mapping = context.source[medication().laborMappings()].find { final def lm ->
lm[LaborMapping.LABOR_FINDING][LaborFinding.LABOR_METHOD][LaborMethod.CODE] == "MedicationAdministration_profile"
}

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

status = MedicationAdministration.MedicationAdministrationStatus.COMPLETED

Expand Down Expand Up @@ -99,7 +97,7 @@ medicationAdministration {

if (lflvMap.containsKey(DOSAGE_SITE)){
site {
text = lflvMap.get(DOSAGE_SITE) as String
text = lflvMap[DOSAGE_SITE] as String
}
}

Expand All @@ -118,7 +116,7 @@ medicationAdministration {
rateQuantity {
value = sanitizeScale(context.source[medication().quantity()] as String)
if (lflvMap.containsKey(DOSAGE_DOSEANDRATE_RATEQUANTITY_UNIT)){
unit = lflvMap.get(DOSAGE_DOSEANDRATE_RATEQUANTITY_UNIT) as String
unit = lflvMap[DOSAGE_DOSEANDRATE_RATEQUANTITY_UNIT] as String
}
}
}
Expand All @@ -138,20 +136,6 @@ static String normalizeDate(final String dateTimeString) {
return dateTimeString != null ? dateTimeString.substring(0, 19) : null
}

static String convertPrecision(final String cxxPrecision) {
if (DatePrecision.EXACT.name() == cxxPrecision) {
return TemporalPrecisionEnum.MILLI.name()
} else if (DatePrecision.DAY.name() == cxxPrecision) {
return TemporalPrecisionEnum.DAY.name()
} else if (DatePrecision.MONTH.name() == cxxPrecision) {
return TemporalPrecisionEnum.MONTH.name()
} else if (DatePrecision.YEAR.name() == cxxPrecision) {
return TemporalPrecisionEnum.YEAR.name()
} else {
return DatePrecision.DAY
}
}

static BigDecimal sanitizeScale(final String numeric) {
return numeric == null || !StringUtils.isNumeric(numeric) ? null : new BigDecimal(numeric).stripTrailingZeros()
}
Expand All @@ -169,18 +153,19 @@ static boolean isFakeEpisode(final def episode) {
return fakeId != null
}

static Map<String, Map> getLflvMap(final def mapping, final Map<String, String> types){
final Map<String, Map> lflvMap = [:]
static Map<String, Object> getLflvMap(final def mapping, final Map<String, String> types) {
final Map<String, Object> 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 ->
final def lflvForLv = 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]]

if (lflvForLv && lflvForLv[lvType]) {
lflvMap[(lvCode)] = lflvForLv[lvType]
}
}
return lflvMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import static de.kairos.fhir.centraxx.metamodel.RootEntities.medication
* @since v.1.41.0, CXX.v.2024.2.0
*/
medicationRequest {

if (context.source[medication().serviceType()] != MedicationServiceType.VER.name()) {
return
}
Expand Down