CDCgov / prime-reportstream

ReportStream is a public intermediary tool for delivery of data between different parts of the healthcare ecosystem.
https://reportstream.cdc.gov
Creative Commons Zero v1.0 Universal
70 stars 39 forks source link

Investigate the deleteResource function not deleting orphaned resources #12888

Closed thetaurean closed 2 months ago

thetaurean commented 8 months ago

User Story

As ReportStream I want to ensure orphaned resources are removed from a bundle so that irrelevant data is not sent to receivers.

Description/Use Case

While implementing tests for #12279, potential gaps were discovered in the deleteResource bundle helper; some types of orphaned resources are not removed from the bundle and instead just get nulled out. This was observed with a MedicationRequest referencing an observation and at least one other type.

See dev notes for test code which demonstrates the issue.

Risks/Impacts/Considerations

Dev Notes

Here's a test you can add to FHIRBundleHelpersTests.kt to trigger an example

    @Test
    fun `test filterMappedObservations`() {
        val fhirRecord = File(VALID_ROUTING_DATA_URL).readText()
        val bundle = FhirContext.forR4().newJsonParser().parseResource(Bundle::class.java, fhirRecord)
        bundle.getObservations()[0].code.coding[0].addExtension(
            conditionCodeExtensionURL, Coding("SOMESYSTEM", "840539006", "SOMECONDITION")
        )

        val refResource = MedicationRequest()
        val entryComponent = Bundle.BundleEntryComponent()
        refResource.id = "MedicationRequest/123"
        refResource.addBasedOn(Reference(bundle.getObservations()[1].idBase))
        entryComponent.resource = refResource
        bundle.addEntry(entryComponent)

        val filteredBundle = bundle.filterMappedObservations(
            listOf(CodeStringConditionFilter("840539006"))
        )

        val filteredObservations = filteredBundle.getObservations()

        println(filteredBundle.entry.map { it.resource }.filterIsInstance<MedicationRequest>())

        assertThat(filteredObservations.size).isEqualTo(1)
        assertThat(filteredObservations[0].id).isEqualTo("Observation/1667861767955966000.f3f94c27-e225-4aac-b6f5-2750f45dac4f")
        assertThat(filteredBundle.entry.map { it.resource }.filterIsInstance<MedicationRequest>().none {
            it.id == "MedicationRequest/123"
        }).isTrue()
    }

Acceptance Criteria

Andrey-Glazkv commented 8 months ago

Hey team! Please add your planning poker estimate with Zenhub @arnejduranovic @jack-h-wang @jalbinson @JessicaWNava @JFU-NAVA-PBC @jimmyfagan @mkalish @thetaurean

Andrey-Glazkv commented 8 months ago

Please add your planning poker estimate with Zenhub @brick-green

JessicaWNava commented 8 months ago

This seems like a bug, so do we not point it?

Andrey-Glazkv commented 8 months ago

@thetaurean to work on this from design/research perspective

Andrey-Glazkv commented 7 months ago

@arnejduranovic to get together with @jsutantio and @dylansmith-Nava to talk about design part of this one

arnejduranovic commented 2 months ago

Will be resolved by https://github.com/CDCgov/prime-reportstream/issues/14568