diff --git a/README.md b/README.md index fc8ee07..c9ca466 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/facade_app/config/passthrough_config.yml b/facade_app/config/passthrough_config.yml index 097171c..56cd31c 100644 --- a/facade_app/config/passthrough_config.yml +++ b/facade_app/config/passthrough_config.yml @@ -6,5 +6,4 @@ URLs: - "/test/echo" Resources: - "metadata" - - "Patient" - "Consent" diff --git a/facade_app/config/resource_config.yml b/facade_app/config/resource_config.yml index c58bfe6..17e95a1 100644 --- a/facade_app/config/resource_config.yml +++ b/facade_app/config/resource_config.yml @@ -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" diff --git a/facade_app/resources/fhir_facade_server.py b/facade_app/resources/fhir_facade_server.py index 0a5f05e..cea6bbc 100644 --- a/facade_app/resources/fhir_facade_server.py +++ b/facade_app/resources/fhir_facade_server.py @@ -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, diff --git a/facade_app/util/consentAndResourceUtil.py b/facade_app/util/consentAndResourceUtil.py index a617a2d..9d6eb9e 100644 --- a/facade_app/util/consentAndResourceUtil.py +++ b/facade_app/util/consentAndResourceUtil.py @@ -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