Skip to content

Commit

Permalink
Use addOrUpdate when saving CarePlans and dependent resources (#3023)
Browse files Browse the repository at this point in the history
* Use addOrUpdate when saving CarePlans and dependent resources

* Update FhirCarePlanGenerator tests
  • Loading branch information
Rkareko authored Feb 1, 2024
1 parent c075c79 commit ce2fc78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ constructor(
carePlan.contained.clear()

// Save CarePlan only if it has activity, otherwise just save contained/dependent resources
if (output.hasActivity()) defaultRepository.create(true, carePlan)
if (output.hasActivity()) defaultRepository.addOrUpdate(true, carePlan)

dependents.forEach { defaultRepository.create(true, it) }
dependents.forEach { defaultRepository.addOrUpdate(true, it) }

if (carePlan.status == CarePlan.CarePlanStatus.COMPLETED) {
carePlan.activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {

val resourcesSlot = mutableListOf<Resource>()
val booleanSlot = slot<Boolean>()
coEvery { defaultRepository.create(capture(booleanSlot), capture(resourcesSlot)) } returns
emptyList()
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(resourcesSlot)) } just
runs
coEvery { fhirEngine.get<StructureMap>("131373") } returns structureMap
coEvery { fhirEngine.search<CarePlan>(Search(ResourceType.CarePlan)) } returns listOf()

Expand Down Expand Up @@ -578,8 +578,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {

val resourcesSlot = mutableListOf<Resource>()
val booleanSlot = slot<Boolean>()
coEvery { defaultRepository.create(capture(booleanSlot), capture(resourcesSlot)) } returns
emptyList()
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(resourcesSlot)) } just
runs
coEvery { fhirEngine.get<StructureMap>("hh") } returns structureMap
coEvery { fhirEngine.search<CarePlan>(Search(ResourceType.CarePlan)) } returns listOf()

Expand Down Expand Up @@ -645,8 +645,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {

val resourcesSlot = mutableListOf<Resource>()
val booleanSlot = slot<Boolean>()
coEvery { defaultRepository.create(capture(booleanSlot), capture(resourcesSlot)) } returns
emptyList()
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(resourcesSlot)) } just
runs
coEvery { fhirEngine.get<StructureMap>("hh") } returns structureMap
coEvery { fhirEngine.search<CarePlan>(Search(ResourceType.CarePlan)) } returns listOf()

Expand Down Expand Up @@ -820,8 +820,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {
val createdTasksSlot = mutableListOf<Resource>()
val updatedTasksSlot = mutableListOf<Resource>()
val booleanSlot = slot<Boolean>()
coEvery { defaultRepository.create(capture(booleanSlot), capture(createdTasksSlot)) } returns
emptyList()
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(createdTasksSlot)) } just
runs
coEvery { defaultRepository.addOrUpdate(any(), capture(updatedTasksSlot)) } just runs
coEvery { fhirEngine.update(any()) } just runs
coEvery { fhirEngine.get<StructureMap>("528a8603-2e43-4a2e-a33d-1ec2563ffd3e") } returns
Expand Down Expand Up @@ -903,8 +903,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {

val resourcesSlot = mutableListOf<Resource>()
val booleanSlot = slot<Boolean>()
coEvery { defaultRepository.create(capture(booleanSlot), capture(resourcesSlot)) } returns
emptyList()
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(resourcesSlot)) } just
runs
coEvery { fhirEngine.get<StructureMap>("528a8603-2e43-4a2e-a33d-1ec2563ffd3e") } returns
structureMap

Expand Down Expand Up @@ -1552,8 +1552,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {

val resourcesSlot = mutableListOf<Resource>()
val booleanSlot = slot<Boolean>()
coEvery { defaultRepository.create(capture(booleanSlot), capture(resourcesSlot)) } returns
emptyList()
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(resourcesSlot)) } just
runs
coEvery { fhirEngine.get<StructureMap>("63752b18-9f0e-48a7-9a21-d3714be6309a") } returns
structureMap
coEvery { fhirEngine.search<CarePlan>(Search(ResourceType.CarePlan)) } returns emptyList()
Expand Down Expand Up @@ -1584,7 +1584,7 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {
assertEquals(DateTimeType.now().value.makeItReadable(), carePlan.created.makeItReadable())
assertEquals(patient.generalPractitionerFirstRep.extractId(), carePlan.author.extractId())
assertTrue(carePlan.activityFirstRep.outcomeReference.isNotEmpty())
coEvery { defaultRepository.create(capture(booleanSlot), capture(resourcesSlot)) }
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(resourcesSlot)) }
resourcesSlot
.filter { res -> res.resourceType == ResourceType.Task }
.map { it as Task }
Expand Down Expand Up @@ -2091,10 +2091,9 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {
fhirEngine.create(patient)

val resourceSlot = slot<Resource>()
coEvery { defaultRepository.create(any(), capture(resourceSlot)) } answers
coEvery { defaultRepository.addOrUpdate(any(), capture(resourceSlot)) } answers
{
runBlocking(Dispatchers.IO) { fhirEngine.create(resourceSlot.captured) }
listOf()
}
val carePlan =
fhirCarePlanGenerator.generateOrUpdateCarePlan(
Expand Down Expand Up @@ -2150,8 +2149,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {

val resourcesSlot = mutableListOf<Resource>()
val booleanSlot = slot<Boolean>()
coEvery { defaultRepository.create(capture(booleanSlot), capture(resourcesSlot)) } returns
emptyList()
coEvery { defaultRepository.addOrUpdate(capture(booleanSlot), capture(resourcesSlot)) } just
runs
coEvery { fhirEngine.search<CarePlan>(Search(ResourceType.CarePlan)) } returns listOf()
coEvery { fhirEngine.get<StructureMap>(structureMapRegister.logicalId) } returns
structureMapRegister
Expand Down

0 comments on commit ce2fc78

Please sign in to comment.