Skip to content

Commit

Permalink
Added the performer and organization info for consent resource along … (
Browse files Browse the repository at this point in the history
#3230)

* Added the performer and organization info for consent resource along with unit tests (#3227)

* Refactor implementation

Signed-off-by: Elly Kitoto <[email protected]>

---------

Signed-off-by: Elly Kitoto <[email protected]>
Co-authored-by: Elly Kitoto <[email protected]>
  • Loading branch information
Aleem92 and ellykits authored Jul 18, 2024
1 parent 83595aa commit 9ef20df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.hl7.fhir.r4.model.CodeableConcept
import org.hl7.fhir.r4.model.Coding
import org.hl7.fhir.r4.model.Composition
import org.hl7.fhir.r4.model.Condition
import org.hl7.fhir.r4.model.Consent
import org.hl7.fhir.r4.model.Encounter
import org.hl7.fhir.r4.model.Enumerations
import org.hl7.fhir.r4.model.Extension
Expand Down Expand Up @@ -298,6 +299,7 @@ fun Resource.appendOrganizationInfo(authenticatedOrganizationIds: List<String>?)
is Group -> managingEntity = updateReference(managingEntity, organizationRef)
is Encounter -> serviceProvider = updateReference(serviceProvider, organizationRef)
is Location -> managingOrganization = updateReference(managingOrganization, organizationRef)
is Consent -> organization = updateReferenceList(organization, organizationRef)
else -> {}
}
}
Expand Down Expand Up @@ -330,6 +332,7 @@ fun Resource.appendPractitionerInfo(practitionerId: String?) {
} else {
participant
}
is Consent -> performer = updateReferenceList(performer, practitionerRef)
else -> {}
}
}
Expand Down Expand Up @@ -368,6 +371,14 @@ fun Resource.appendRelatedEntityLocation(
}
}

private fun updateReferenceList(
oldReferenceList: List<Reference>?,
newReference: Reference,
): List<Reference> {
val list = oldReferenceList?.filter { !it.reference.isNullOrEmpty() }
return if (!list.isNullOrEmpty()) list else listOf(newReference)
}

private fun updateReference(oldReference: Reference?, newReference: Reference): Reference =
if (oldReference == null || oldReference.reference.isNullOrEmpty()) {
newReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.hl7.fhir.r4.model.BooleanType
import org.hl7.fhir.r4.model.CodeableConcept
import org.hl7.fhir.r4.model.Coding
import org.hl7.fhir.r4.model.Condition
import org.hl7.fhir.r4.model.Consent
import org.hl7.fhir.r4.model.DateTimeType
import org.hl7.fhir.r4.model.Encounter
import org.hl7.fhir.r4.model.Enumerations
Expand Down Expand Up @@ -901,6 +902,13 @@ class ResourceExtensionTest : RobolectricTest() {
Assert.assertEquals("Organization/12345", patient.managingOrganization.reference)
}

@Test
fun `test Organization Info Appended on Consent Resource`() {
val consent = Consent().apply { this.id = "123456" }
consent.appendOrganizationInfo(listOf("Organization/12345"))
Assert.assertEquals("Organization/12345", consent.organization.first().reference)
}

@Test
fun `prepareQuestionsForEditing should set readOnly correctly when readOnlyLinkIds passed`() {
val questionnaire = Questionnaire()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import org.hl7.fhir.r4.model.BooleanType
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.CodeableConcept
import org.hl7.fhir.r4.model.Coding
import org.hl7.fhir.r4.model.Consent
import org.hl7.fhir.r4.model.DateType
import org.hl7.fhir.r4.model.Encounter
import org.hl7.fhir.r4.model.Enumerations
Expand Down Expand Up @@ -1248,6 +1249,13 @@ class QuestionnaireViewModelTest : RobolectricTest() {
Assert.assertEquals("Practitioner/12345", flag.author.reference)
}

@Test
fun testAddPractitionerInfoAppendedCorrectlyOnConsentResource() {
val consent = Consent().apply { this.id = "123456" }
consent.appendPractitionerInfo("12345")
Assert.assertEquals("Practitioner/12345", consent.performer.first().reference)
}

@Test
fun testSaveExtractedResourcesForEditedQuestionnaire() = runTest {
val questionnaire = extractionQuestionnaire()
Expand Down

0 comments on commit 9ef20df

Please sign in to comment.