Skip to content

Commit

Permalink
Merge pull request #47 from neumichel/master
Browse files Browse the repository at this point in the history
observation: corrected label of PBMC profile - specimen: added specim…
  • Loading branch information
kairosmike authored Feb 19, 2024
2 parents cd7cd98 + 7504136 commit 77458ce
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 43 deletions.
85 changes: 47 additions & 38 deletions src/main/groovy/projects/cxx/napkon/ibdw/observation.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,66 @@ import static de.kairos.fhir.centraxx.metamodel.RootEntities.laborMapping
*/
observation {
// 0. Filter patients
//final def patientList = ["lims_643282707", "lims_745748710"]
//final def currentPatientId = context.source[laborMapping().relatedPatient().idContainer()]?.find {
// "NAPKON" == it[IdContainer.ID_CONTAINER_TYPE]?.getAt(IdContainerType.CODE)
//}
//final boolean belongsToExcludedPatient = patientList.contains(currentPatientId[IdContainer.PSN])
// final def patientList = ["lims_768700553"] //, "lims_745748710"]
// final def currentPatientId = context.source[laborMapping().relatedPatient().idContainer()]?.find {
// "NAPKON" == it[IdContainer.ID_CONTAINER_TYPE]?.getAt(IdContainerType.CODE)
// }
// final boolean belongsToExcludedPatient = patientList.contains(currentPatientId[IdContainer.PSN])
//
//if (belongsToExcludedPatient) {
// return
//}
// if (!belongsToExcludedPatient) {
// return
// }

// Filter sample category
final SampleCategory category = context.source[laborMapping().sample().sampleCategory()] as SampleCategory

final boolean isSampleMapping = LaborMappingType.SAMPLELABORMAPPING == context.source[laborMapping().mappingType()] as LaborMappingType
final boolean isDzhkMethod = ["DZHKFLAB"].contains(context.source[laborMapping().laborFinding().laborMethod().code()])
if (!(isSampleMapping && isDzhkMethod)) {
final boolean isNumMethod = ["DZHKFLAB", 'NUM_PBMC_ISOLIERUNG'].contains(context.source[laborMapping().laborFinding().laborMethod().code()])
if (!(isSampleMapping && isNumMethod)) {
return
}

final SimpleDateFormat isoDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
final SimpleDateFormat numDateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss")
// final SimpleDateFormat isoDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
// final SimpleDateFormat numDateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss")

final def extSampleId = context.source[laborMapping().sample().idContainer()]?.find { final def entry ->
// 2. Filter NAPKON-ID Mapping exists
String napkonMappingExists = ""
if (category == SampleCategory.MASTER) {
napkonMappingExists = context.source[laborMapping().sample().idContainer()]?.find { final def entry ->
"NAPKONSMP" == entry[SampleIdContainer.ID_CONTAINER_TYPE]?.getAt(IdContainerType.CODE)
}
}
final def extSampleId = context.source[laborMapping().sample().idContainer()]?.find { final def entry ->
"NAPKONSMP" == entry[SampleIdContainer.ID_CONTAINER_TYPE]?.getAt(IdContainerType.CODE)
}

if (!extSampleId) {
if (!napkonMappingExists) {
return
}

// Filter samples older than specified date
String sampleReceptionDate = ""
if (category == SampleCategory.MASTER) {
sampleReceptionDate = context.source[laborMapping().sample().receiptDate().date()]
} else if (category == SampleCategory.ALIQUOTGROUP) {
sampleReceptionDate = context.source[laborMapping().sample().parent().receiptDate().date()]
} else if (category == SampleCategory.DERIVED) {
sampleReceptionDate = context.source[laborMapping().sample().parent().parent().receiptDate().date()]
}
if (sampleReceptionDate < "2022-03-01T23:59:59+01:00") {
return
}
// String receptionDate = ""
// if (category == SampleCategory.MASTER) {
// receptionDate = context.source[laborMapping().sample().receiptDate().date()]
// } else if (category == SampleCategory.ALIQUOTGROUP) {
// receptionDate = context.source[laborMapping().sample().parent().receiptDate().date()]
// } else if (category == SampleCategory.DERIVED) {
// receptionDate = context.source[laborMapping().sample().parent().parent().receiptDate().date()]
// }
// if (receptionDate == null || receptionDate < "2023-01-01T00:00:00.000+01:00") {
// return
// }

// Observation date from sample reception timestamp
// Observation label from laborFinding timestamp
final Date observationDate = isoDateFormat.parse(context.source[laborMapping().sample().receiptDate().date()] as String)
String observationCode = ""
if (observationDate) {
observationCode = "Biomaterial-Zentrifugation_" + extSampleId[SampleIdContainer.PSN] + "_" + numDateFormat.format(observationDate)
}
else {
// Do not create observation if observationDate is NULL
return
}
// println("observationDate: " + context.source[laborMapping().laborFinding().findingDate().date()])
// Date observationDate = isoDateFormat.parse(context.source[laborMapping().laborFinding().findingDate().date()] as String)
// String observationCode = ""
// if (observationDate) {
// observationCode = "Biomaterial-Zentrifugation_" + extSampleId[SampleIdContainer.PSN] + "_" + numDateFormat.format(observationDate)
// }
// else {
// // Do not create observation if observationDate is NULL
// return
// }

// Update resource - ignore missing elements
// extension {
Expand All @@ -103,7 +109,8 @@ observation {

code {
coding {
code = observationCode
// code = observationCode
code = context.source[laborMapping().laborFinding().shortName()] as String
system = "urn:centraxx"
}
}
Expand Down Expand Up @@ -143,7 +150,9 @@ observation {
}
}

effectiveDateTime = observationDate
// effectiveDateTime = observationDate
effectiveDateTime = context.source[laborMapping().laborFinding().findingDate().date()]


method {
coding {
Expand Down
23 changes: 18 additions & 5 deletions src/main/groovy/projects/cxx/napkon/ibdw/specimen.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import de.kairos.fhir.centraxx.metamodel.IdContainerType
import de.kairos.fhir.centraxx.metamodel.SampleIdContainer
import de.kairos.fhir.centraxx.metamodel.enums.SampleCategory
import de.kairos.fhir.centraxx.metamodel.enums.SampleKind
import org.hl7.fhir.r4.model.CodeableConcept
import org.slf4j.ILoggerFactory

import java.text.SimpleDateFormat

Expand Down Expand Up @@ -33,13 +35,14 @@ import static de.kairos.fhir.centraxx.metamodel.RootEntities.sample

specimen {
// 0. Filter patients
// final def patientList = ["lims_670161596"] //["lims_643282707", "lims_745748710"]
// final def patientList = ["lims_911069062"] //["lims_643282707", "lims_745748710"]
// final def currentPatientId = context.source[sample().patientContainer().idContainer()]?.find {
// "NAPKON" == it[IdContainer.ID_CONTAINER_TYPE]?.getAt(IdContainerType.CODE)
// }
// final boolean belongsToIncludedPatient = patientList.contains(currentPatientId[IdContainer.PSN])
//
// if (!belongsToIncludedPatient) {
// System.out.println("Ignored patient: " + currentPatientId[IdContainer.PSN])
// return
// }

Expand Down Expand Up @@ -71,7 +74,10 @@ specimen {
}

// 3. Filter Existing Storage Location assigned
final Boolean sampleExists = ("swisslabProben" != context.source[sample().sampleLocation().locationId()])
// if ("swisslabProben" == context.source[sample().sampleLocation().locationId()]) {
// return
// }
Boolean sampleExists = ("swisslabProben" != context.source[sample().sampleLocation().locationId()])

// 4. Filter samples that are still existing and have not been retrieved (no sampleAbstraction)
// TODO: Modify to check for existing sampleAbstraction as soon as available in a future CXX release
Expand Down Expand Up @@ -106,8 +112,11 @@ specimen {
// } else if (category == SampleCategory.DERIVED) {
// receptionDate = context.source[sample().parent().parent().receiptDate().date()]
// }
// if (receptionDate != null && receptionDate < "2022-03-01T23:59:59+01:00") {
//// System.out.println("receptionDate for " + category + " sample " + context.source[sample().id()] + ": " + receptionDate)
//
// //System.out.println("receptionDate for " + category + " sample " + context.source[sample().id()] + ": " + receptionDate)
//
// if (receptionDate == null || receptionDate < "2023-01-01T00:00:00.000+01:00") {
// //System.out.println("sample ignored")
// return
// }

Expand Down Expand Up @@ -139,7 +148,7 @@ specimen {
} as Map<String, Object>

// 7: cross-mapping of the ids of MASTER samples. The sample id of the ibdw is provided as external sampled id to NUM.
// The external sample id (NAPKONSMP) of ibdw is provided as sample id to NUM.
// The external sample id of ibdw is provided as sample id to NUM.
if (context.source[sample().sampleCategory()] as SampleCategory == SampleCategory.MASTER) {
idContainersMap.each { final String idContainerCode, final Object idContainer ->
if (idContainer) {
Expand Down Expand Up @@ -352,6 +361,10 @@ specimen {
}
}

note {
text = context.source[sample().note()]
}

extension {
url = FhirUrls.Extension.SAMPLE_CATEGORY
valueCoding {
Expand Down

0 comments on commit 77458ce

Please sign in to comment.