Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the performer and organization info for consent resource along … #3230

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Extension
import org.hl7.fhir.r4.model.Flag
Expand Down Expand Up @@ -294,6 +295,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 @@ -326,6 +328,7 @@ fun Resource.appendPractitionerInfo(practitionerId: String?) {
} else {
participant
}
is Consent -> performer = updateReferenceList(performer, practitionerRef)
else -> {}
}
}
Expand Down Expand Up @@ -364,6 +367,13 @@ fun Resource.appendRelatedEntityLocation(
}
}

private fun updateReferenceList(
oldReferenceList: List<Reference>?,
newReference: Reference,
): List<Reference> =
oldReferenceList.orEmpty().filterNot { it.reference.isNullOrEmpty() }.takeIf { it.isNotEmpty() }
ellykits marked this conversation as resolved.
Show resolved Hide resolved
ellykits marked this conversation as resolved.
Show resolved Hide resolved
?: 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 @@ -35,6 +35,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 @@ -896,6 +897,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 @@ -52,6 +52,7 @@ import org.hl7.fhir.r4.model.Basic
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 @@ -1022,6 +1023,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
Loading