Skip to content

Commit

Permalink
Address reports showing duplicate entries per subject (#2668)
Browse files Browse the repository at this point in the history
  • Loading branch information
roywanyaga authored Aug 10, 2023
1 parent c2ecfd0 commit f0585e5
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ constructor(
subjects.add("${Practitioner().resourceType.name}/$practitionerId")
}

val existing =
val existingReports =
retrievePreviouslyGeneratedMeasureReports(
fhirEngine = fhirEngine,
startDateFormatted = startDateFormatted,
Expand All @@ -306,11 +306,23 @@ constructor(
subjects = listOf(),
)

val existingValidReports = mutableListOf<MeasureReport>()

existingReports
?.groupBy { it.subject.reference }
?.forEach { entry ->
if (entry.value.size > 1 && entry.value.distinctBy { it.measure }.size <= 1) {
return@forEach
} else {
existingValidReports.addAll(entry.value)
}
}

// if report is of current month or does not exist generate a new one and replace
// existing
if (endDateFormatted.parseDate(SDF_YYYY_MM_DD)!!
.formatDate(SDF_YYYY_MMM)
.contentEquals(Date().formatDate(SDF_YYYY_MMM)) || existing.isEmpty()
.contentEquals(Date().formatDate(SDF_YYYY_MMM)) || existingValidReports.isEmpty()
) {
withContext(dispatcherProvider.io()) {
fhirEngine.loadCqlLibraryBundle(fhirOperator, config.url)
Expand All @@ -321,11 +333,11 @@ constructor(
startDateFormatted = startDateFormatted,
endDateFormatted = endDateFormatted,
subjects = subjects,
existing = existing,
existing = existingValidReports,
practitionerId = practitionerId,
)
} else {
existing
existingValidReports
}
}

Expand Down

0 comments on commit f0585e5

Please sign in to comment.