Skip to content

Commit

Permalink
feat: enable simple consent evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
BoehmDo committed Nov 28, 2024
1 parent 450de67 commit a2f575a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,25 @@ All Resources that are supposed to be accessed via the facade have to be configu
```
Resources:
Observation:
EvaluationStrategy: "date"
Date: "issued"
Subject: "subject/reference"
Encounter:
EvaluationStrategy: "date"
Date: "period/start"
Subject: "subject/reference"
Procedure:
EvaluationStrategy: "date"
Date: "performedPeriod/"
Subject: "subject/reference"
Specimen:
EvaluationStrategy: "date"
Date: "collection/collectedDateTime"
Subject: "subject/reference"
Patient:
EvaluationStrategy: "simple"
Date: ""
Subject: "id"
```

### Provision Configuration
Expand Down
1 change: 0 additions & 1 deletion facade_app/config/passthrough_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ URLs:
- "/test/echo"
Resources:
- "metadata"
- "Patient"
- "Consent"
11 changes: 11 additions & 0 deletions facade_app/config/resource_config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#Add all resources that are supposed to be limited by consent status
#This must include a 'Date' Attribute with a relative Path from the Resource to a necessary Date field including its name
#As well as a similar 'Subject' field with the relative Path to a necessary Patient Identifier
#The 'EvaluationStrategy' can be either 'date' or 'simple', depending on whether the valid period of the configured provisions should be evaluated
#In the case of 'simple', the valid period of the provisions is not evaluated and the consent is only checked for existence
#Therefor the date field can be left empty
#Paths are represented as follows: path/to/the/subject/field
Resources:
Observation:
EvaluationStrategy: "date"
Date: "issued"
Subject: "subject/reference"
Encounter:
EvaluationStrategy: "date"
Date: "period/start"
Subject: "subject/reference"
Procedure:
EvaluationStrategy: "date"
Date: "performedPeriod/"
Subject: "subject/reference"
Specimen:
EvaluationStrategy: "date"
Date: "collection/collectedDateTime"
Subject: "subject/reference"
Patient:
EvaluationStrategy: "simple"
Date: ""
Subject: "id"
4 changes: 2 additions & 2 deletions facade_app/resources/fhir_facade_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def handleRequest(self, resource, search=""):
# Check if resource has been configured properly
if (
RESOURCE_PATHS[resource]["Date"] == ""
or RESOURCE_PATHS[resource]["Subject"] == ""
):
and RESOURCE_PATHS[resource]["EvaluationStrategy"] != "simple"
) or RESOURCE_PATHS[resource]["Subject"] == "":
return (
f"The requested resource has not been configured. Please add the necessary configuration. Or if you dont require consent for the requested resources, use the fhir-server endpoint ({SERVER_URL}) directly.",
403,
Expand Down
57 changes: 34 additions & 23 deletions facade_app/util/consentAndResourceUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,43 @@ def matchResourcesWithConsents(resources, consents, resource_config, provision_c
subject = res["resource"]
for path in resource_config["Subject"].split("/"):
subject = subject[path]

date = res["resource"]
for path in resource_config["Date"].split("/"):
date = date[path]
date = parser.parse(date)
if (
not subject.startswith("Patient/")
and len(resource_config["Subject"].split("/")) == 1
):
subject = "Patient/" + subject

if resource_config["EvaluationStrategy"] == "date":
date = res["resource"]
for path in resource_config["Date"].split("/"):
date = date[path]
date = parser.parse(date)

if subject in provision_time_set:

for provision in provision_time_set[subject]:

start = parser.parse(provision["period"]["start"])
end = parser.parse(provision["period"]["end"])

if provision["type"] == "permit":
if (
date.timestamp() >= start.timestamp()
and date.timestamp() <= end.timestamp()
):
is_consented = True
else:
if (
date.timestamp() >= start.timestamp()
and date.timestamp() <= end.timestamp()
):
is_consented = False
break
if resource_config["EvaluationStrategy"] == "date":

for provision in provision_time_set[subject]:

start = parser.parse(provision["period"]["start"])
end = parser.parse(provision["period"]["end"])

if provision["type"] == "permit":
if (
date.timestamp() >= start.timestamp()
and date.timestamp() <= end.timestamp()
):
is_consented = True
else:
if (
date.timestamp() >= start.timestamp()
and date.timestamp() <= end.timestamp()
):
is_consented = False
break

if resource_config["EvaluationStrategy"] == "simple":
is_consented = True

for prov_code in provision_config["coding"]:
provision_exists = False
Expand Down

0 comments on commit a2f575a

Please sign in to comment.