-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from NHSDigital/AMB-1891_Amend_s_flag_integra…
…tion Amb 1891 amend s flag integration
- Loading branch information
Showing
19 changed files
with
759 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,22 @@ | ||
import copy | ||
from filter import Filter | ||
|
||
|
||
def handle_s_flag(imms, patient): | ||
""" | ||
See https://nhsd-confluence.digital.nhs.uk/pages/viewpage.action?pageId=758110223 for details. | ||
Checks if the patient has a restricted flag, and returns the imms resource with the appropriate filtering | ||
applied where necessary. | ||
NOTE: the term 's_flag' is not found in the PDS response. Instead we are searching for a code of | ||
'R' for RESTRICTED in the meta.security field. | ||
""" | ||
try: | ||
patient_is_restricted = str.lower(patient["meta"]["security"][0]["code"]) == "r" | ||
except (KeyError, IndexError): | ||
return imms | ||
|
||
if not patient_is_restricted: | ||
return imms | ||
patient_is_restricted = False | ||
|
||
result = copy.deepcopy(imms) | ||
# NOTE: meta.security is currently restricted to max length of 1 according to PDS, however we are looping | ||
# through all of the items in meta.security for safety in case PDS ever start sending more than one security item. | ||
for item in patient["meta"]["security"]: | ||
if str.upper(item["code"]) == "R": | ||
patient_is_restricted = True | ||
break | ||
|
||
contained_questionnaire = next( | ||
( | ||
record | ||
for record in result.get("contained", []) | ||
if record["resourceType"] == "QuestionnaireResponse" | ||
), | ||
None, | ||
) | ||
|
||
contained_patient = next( | ||
( | ||
record | ||
for record in result.get("contained", []) | ||
if record["resourceType"] == "Patient" | ||
), | ||
None, | ||
) | ||
|
||
# Handle Questionnaire SiteCode | ||
performer_actor_organization = next( | ||
( | ||
item | ||
for item in result["performer"] | ||
if item.get("actor", {}).get("type") == "Organization" | ||
), | ||
None, | ||
) | ||
|
||
if performer_actor_organization: | ||
try: | ||
performer_actor_organization["actor"]["identifier"]["value"] = "N2N9I" | ||
performer_actor_organization["actor"]["identifier"][ | ||
"system" | ||
] = "https://fhir.nhs.uk/Id/ods-organization-code" | ||
del performer_actor_organization["actor"]["display"] | ||
except KeyError: | ||
pass | ||
|
||
if contained_patient: | ||
try: | ||
contained_patient["address"][0]["postalCode"] = "ZZ99 3CZ" | ||
except (KeyError, IndexError): | ||
pass | ||
|
||
|
||
# Handle Questionnaire removals | ||
if contained_questionnaire and contained_questionnaire.get("item"): | ||
for item in contained_questionnaire["item"]: | ||
if "linkId" in item and item["linkId"] == "Consent": | ||
if "answer" in item: | ||
for answer in item["answer"]: | ||
if "valueCoding" in answer: | ||
answer["valueCoding"]["display"] = None # Set display to null | ||
|
||
# Handle reportOrigin | ||
try: | ||
del result["reportOrigin"] | ||
except KeyError: | ||
pass | ||
|
||
# Handle Location | ||
try: | ||
del result["location"] | ||
except KeyError: | ||
pass | ||
|
||
return result | ||
return Filter.s_flag(imms) if patient_is_restricted else imms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.