1
0
mirror of https://github.com/pcvolkmer/mv64e-etl-processor synced 2025-09-13 09:02:50 +00:00

132 fix consent check (#133)

This commit is contained in:
jlidke
2025-08-18 12:30:19 +02:00
committed by GitHub
parent 3eb1c79cec
commit 7f80224eac
6 changed files with 2136 additions and 2277 deletions

View File

@@ -92,6 +92,7 @@ class AppConfiguration {
restTemplate: RestTemplate,
appFhirConfig: AppFhirConfig
): Generator {
logger.info("Selected 'GpasPseudonym Generator'")
return GpasPseudonymGenerator(configProperties, retryTemplate, restTemplate, appFhirConfig)
}
@@ -102,6 +103,7 @@ class AppConfiguration {
)
@Bean
fun buildinPseudonymGenerator(): Generator {
logger.info("Selected 'BUILDIN Pseudonym Generator'")
return AnonymizingGenerator()
}

View File

@@ -222,60 +222,56 @@ class ConsentProcessor(
/**
* @param consentBundle consent resource
* @param policyAndProvisionCode policyRule and provision code value
* @param policyAndProvisionSystem policyRule and provision system value
* @param targetCode policyRule and provision code value
* @param targetSystem policyRule and provision system value
* @param requestDate date which must be within validation period of provision
* @return type of provision, will be [org.hl7.fhir.r4.model.Consent.ConsentProvisionType.NULL] if none is found.
*/
fun getProvisionTypeByPolicyCode(
consentBundle: Bundle,
policyAndProvisionCode: String?,
policyAndProvisionSystem: String?,
requestDate: Date?
consentBundle: Bundle, targetCode: String?, targetSystem: String?, requestDate: Date?
): Consent.ConsentProvisionType {
val entriesOfInterest = consentBundle.entry.filter { entry ->
entry.resource.isResource && entry.resource.resourceType == ResourceType.Consent && (entry.resource as Consent).status == ConsentState.ACTIVE && checkCoding(
policyAndProvisionCode,
policyAndProvisionSystem,
(entry.resource as Consent).policyRule.codingFirstRep
) && isIsRequestDateInRange(
requestDate, (entry.resource as Consent).provision.period
)
}.map { consentWithTargetPolicy: BundleEntryComponent ->
val provision = (consentWithTargetPolicy.getResource() as Consent).getProvision()
val provisionComponentByCode =
provision.getProvision().stream().filter { prov: ProvisionComponent? ->
checkCoding(
policyAndProvisionCode,
policyAndProvisionSystem,
prov!!.getCodeFirstRep().getCodingFirstRep()
) && isIsRequestDateInRange(
requestDate, prov.getPeriod()
)
}.findFirst()
if (provisionComponentByCode.isPresent) {
// actual provision we search for
return@map provisionComponentByCode.get().getType()
} else {
if (provision.type != null) return provision.type
val isConsentResource =
entry.resource.isResource && entry.resource.resourceType == ResourceType.Consent
val consentIsActive = (entry.resource as Consent).status == ConsentState.ACTIVE
isConsentResource && consentIsActive && checkCoding(
targetCode, targetSystem, (entry.resource as Consent).policyRule.coding
) && isRequestDateInRange(requestDate, (entry.resource as Consent).provision.period)
}.map { entry: BundleEntryComponent ->
val consent = (entry.getResource() as Consent)
consent.provision.provision.filter { subProvision ->
isRequestDateInRange(requestDate, subProvision.period)
// search coding entries of current provision for code and system
subProvision.code.map { c -> c.coding }.flatten().firstOrNull { code ->
targetCode.equals(code.code) && targetSystem.equals(code.system)
} != null
}.map { subProvision ->
subProvision
}
return Consent.ConsentProvisionType.NULL
}.firstOrNull()
}.flatten()
if (entriesOfInterest == null) return Consent.ConsentProvisionType.NULL
return entriesOfInterest
if (!entriesOfInterest.isEmpty()) {
return entriesOfInterest.first().type
}
return Consent.ConsentProvisionType.NULL
}
fun checkCoding(
researchAllowedPolicyOid: String?, researchAllowedPolicySystem: String?, coding: Coding
researchAllowedPolicyOid: String?,
researchAllowedPolicySystem: String?,
policyRules: Collection<Coding>
): Boolean {
return coding.getSystem() == researchAllowedPolicySystem && (coding.getCode() == researchAllowedPolicyOid)
return policyRules.find { code ->
researchAllowedPolicySystem.equals(code.getSystem()) && (researchAllowedPolicyOid.equals(
code.getCode()
))
} != null
}
fun isIsRequestDateInRange(requestdate: Date?, provPeriod: Period): Boolean {
val isRequestDateAfterOrEqualStart = provPeriod.getStart().compareTo(requestdate)
val isRequestDateBeforeOrEqualEnd = provPeriod.getEnd().compareTo(requestdate)
fun isRequestDateInRange(requestDate: Date?, provPeriod: Period): Boolean {
val isRequestDateAfterOrEqualStart = provPeriod.getStart().compareTo(requestDate)
val isRequestDateBeforeOrEqualEnd = provPeriod.getEnd().compareTo(requestDate)
return isRequestDateAfterOrEqualStart <= 0 && isRequestDateBeforeOrEqualEnd >= 0
}

View File

@@ -78,7 +78,7 @@ class ConsentProcessorTest {
val checkResult = consentProcessor.consentGatedCheckAndTryEmbedding(inputMtb)
assertThat(checkResult).isTrue
assertThat(inputMtb.metadata.researchConsents).hasSize(13)
assertThat(inputMtb.metadata.researchConsents).hasSize(26)
}
companion object {
@@ -93,13 +93,13 @@ class ConsentProcessorTest {
)
)
consent.provision.period.start =
Date.from(Instant.parse("2025-06-23T00:00:00.00Z"))
Date.from(Instant.parse("2025-08-15T00:00:00.00Z"))
consent.provision.period.end =
Date.from(Instant.parse("3000-01-01T00:00:00.00Z"))
val addProvision1 = consent.provision.addProvision()
addProvision1.setType(Consent.ConsentProvisionType.fromCode("permit"))
addProvision1.period.start = Date.from(Instant.parse("2025-06-23T00:00:00.00Z"))
addProvision1.period.start = Date.from(Instant.parse("2025-08-15T00:00:00.00Z"))
addProvision1.period.end = Date.from(Instant.parse("3000-01-01T00:00:00.00Z"))
addProvision1.code.addLast(
CodeableConcept(
@@ -113,7 +113,7 @@ class ConsentProcessorTest {
val addProvision2 = consent.provision.addProvision()
addProvision2.setType(Consent.ConsentProvisionType.fromCode("deny"))
addProvision2.period.start = Date.from(Instant.parse("2025-06-23T00:00:00.00Z"))
addProvision2.period.start = Date.from(Instant.parse("2025-08-15T00:00:00.00Z"))
addProvision2.period.end = Date.from(Instant.parse("3000-01-01T00:00:00.00Z"))
addProvision2.code.addLast(
CodeableConcept(
@@ -130,13 +130,14 @@ class ConsentProcessorTest {
@ParameterizedTest
@CsvSource(
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2025-07-23T00:00:00+02:00,PERMIT,expect permit",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2025-06-23T00:00:00+02:00,PERMIT,expect permit date is exactly on start",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2055-06-23T00:00:00+02:00,PERMIT,expect permit date is exactly on end",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2021-06-23T00:00:00+02:00,NULL,date is before start",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2060-06-23T00:00:00+02:00,NULL,date is after end",
"2.16.840.1.113883.3.1937.777.24.5.3.8,XXXX,2025-07-23T00:00:00+02:00,NULL,system not found - therefore expect NULL",
"2.16.840.1.113883.3.1937.777.24.5.3.27,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2025-07-23T00:00:00+02:00,DENY,provision is denied"
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2025-08-15T00:00:00+02:00,PERMIT,expect permit",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2025-08-15T00:00:00+02:00,PERMIT,expect permit date is exactly on start",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2055-08-15T00:00:00+02:00,PERMIT,expect permit date is exactly on end",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2021-08-15T00:00:00+02:00,NULL,date is before start",
"2.16.840.1.113883.3.1937.777.24.5.3.8,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2060-08-15T00:00:00+02:00,NULL,date is after end",
"2.16.840.1.113883.3.1937.777.24.5.3.27,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2025-08-15T00:00:00+02:00,DENY,provision is denied",
"unknownCode,urn:oid:2.16.840.1.113883.3.1937.777.24.5.3,2025-08-15T00:00:00+02:00,NULL,code does not exist - therefore expect NULL",
"2.16.840.1.113883.3.1937.777.24.5.3.8,XXXX,2025-08-15T00:00:00+02:00,NULL,system not found - therefore expect NULL",
)
fun getProvisionTypeByPolicyCode(
code: String?, system: String?, timeStamp: String, expected: String?,
@@ -155,6 +156,27 @@ class ConsentProcessorTest {
.isEqualTo(Consent.ConsentProvisionType.valueOf(expected!!))
}
@Test
fun getProvisionTypeOnEmptyConsent(
) {
val emptyResources = Bundle().addEntry(Bundle.BundleEntryComponent().setResource(Consent()))
val requestDate = Date.from(OffsetDateTime.parse("2025-08-15T00:00:00+02:00").toInstant())
val result: Consent.ConsentProvisionType =
consentProcessor.getProvisionTypeByPolicyCode(
emptyResources,
"anyCode",
"anySystem",
requestDate
)
assertThat(result).isNotNull()
assertThat(result).`as`("empty consent resource - expect NULL")
.isEqualTo(Consent.ConsentProvisionType.NULL)
}
fun getDummyBroadConsentBundle(): Bundle {
val bundle: InputStream?
try {

View File

@@ -97,18 +97,18 @@ class TransformationServiceTest {
assertThat(mvhMetadata).isNotNull
mvhMetadata.modelProjectConsent =
ModelProjectConsent.builder().date(Date.from(Instant.parse("2025-06-23T00:00:00.00Z")))
ModelProjectConsent.builder().date(Date.from(Instant.parse("2025-08-15T00:00:00.00Z")))
.version("1").provisions(
listOf(
Provision.builder().type(ConsentProvision.PERMIT)
.purpose(ModelProjectConsentPurpose.SEQUENCING)
.date(Date.from(Instant.parse("2025-06-23T00:00:00.00Z"))).build(),
.date(Date.from(Instant.parse("2025-08-15T00:00:00.00Z"))).build(),
Provision.builder().type(ConsentProvision.PERMIT)
.purpose(ModelProjectConsentPurpose.REIDENTIFICATION)
.date(Date.from(Instant.parse("2025-06-23T00:00:00.00Z"))).build(),
.date(Date.from(Instant.parse("2025-08-15T00:00:00.00Z"))).build(),
Provision.builder().type(ConsentProvision.DENY)
.purpose(ModelProjectConsentPurpose.CASE_IDENTIFICATION)
.date(Date.from(Instant.parse("2025-06-23T00:00:00.00Z"))).build()
.date(Date.from(Instant.parse("2025-08-15T00:00:00.00Z"))).build()
)
).build()
val consent = ConsentProcessorTest.getDummyGenomDeConsent()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff