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

PRMP - 763 Update patient ods using batchupdate script #413

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7303998
[PRMP-763] create new handler to update patient ods codes
steph-torres-nhs Aug 15, 2024
5eef058
[PRMP-763] create test file for new service
steph-torres-nhs Aug 16, 2024
f69c164
[PRMP-763] update handler to call batchupdate
steph-torres-nhs Aug 16, 2024
b35cb85
[PRMP-763] update github actions to include new lambda handler
steph-torres-nhs Aug 19, 2024
6c10d89
[PRMP-763] add init file to scripts
steph-torres-nhs Aug 19, 2024
94f08ae
[PRMP-763] move batch update ods code into services
steph-torres-nhs Aug 19, 2024
22b1842
[PRMP-763] rename function in update_patient_ods_handler
steph-torres-nhs Aug 19, 2024
de49351
[PRMP-763] add os env for dynamo table
steph-torres-nhs Aug 19, 2024
8b185f6
[PRMP-763] add logger to batchupdate
steph-torres-nhs Aug 20, 2024
98af62d
[PRMP-763] add test cases for changed logic in batchupdate
steph-torres-nhs Aug 20, 2024
759f8be
[PMRP-763] add tests for new logic added to BatchUpdate get_updated_g…
steph-torres-nhs Aug 21, 2024
ac2bb2f
[PRMP-763] format and refactor
abid-nhs Aug 29, 2024
7362db8
[PRMP-763] Adjusted ODS code logic for formally vs informally decease…
AndyFlintAnswerDigital Sep 3, 2024
44c9cb6
[PRMP-763] batch ODS code update uses stubbed PDS and handles HTTP er…
AndyFlintAnswerDigital Sep 4, 2024
f66ff88
[PRMP-763] added missing SSMService object for PDS service
AndyFlintAnswerDigital Sep 4, 2024
f53b255
[PRMP-763] fixed HTTPError's reference to status_code
AndyFlintAnswerDigital Sep 4, 2024
b5f65fa
[PRMP-763] Addressing Sonarcloud linting
AndyFlintAnswerDigital Sep 5, 2024
bb6760f
[PRMP-763] removed unused environment variables
AndyFlintAnswerDigital Sep 6, 2024
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
62 changes: 38 additions & 24 deletions .github/workflows/base-lambdas-reusable-deploy-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
name: Deploy create_document_reference_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -56,7 +56,7 @@ jobs:
name: Deploy search_patient_details_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -70,7 +70,7 @@ jobs:
name: Deploy document_reference_search_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -84,7 +84,7 @@ jobs:
name: Deploy delete_document_reference_handler
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -98,7 +98,7 @@ jobs:
name: Deploy document_manifest_job_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -112,7 +112,7 @@ jobs:
name: Deploy bulk_upload_metadata_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -126,7 +126,7 @@ jobs:
name: Deploy TokenRequestHandler
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -140,7 +140,7 @@ jobs:
name: Deploy LoginRedirectHandler
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -154,7 +154,7 @@ jobs:
name: Deploy AuthoriserLambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand Down Expand Up @@ -182,7 +182,7 @@ jobs:
name: Deploy LogoutHandler
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -196,7 +196,7 @@ jobs:
name: Deploy bulk_upload_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -210,7 +210,7 @@ jobs:
name: Deploy report_bulk_upload_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -224,7 +224,7 @@ jobs:
name: Deploy back_channel_logout_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -238,7 +238,7 @@ jobs:
name: Deploy send_feedback_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -252,7 +252,7 @@ jobs:
name: Deploy nems_message_lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -266,7 +266,7 @@ jobs:
name: Deploy feature flags lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -280,7 +280,7 @@ jobs:
name: Deploy virus scan result lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -294,7 +294,7 @@ jobs:
name: Deploy upload confirm result lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -308,7 +308,7 @@ jobs:
name: Deploy update upload state lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -322,7 +322,7 @@ jobs:
name: Deploy data collection lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
sandbox: ${{ inputs.sandbox }}
Expand All @@ -336,9 +336,9 @@ jobs:
name: Deploy statistical report lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
build_branch: ${{ inputs.build_branch }}
sandbox: ${{ inputs.sandbox }}
lambda_handler_name: statistical_report_handler
lambda_aws_name: StatisticalReportLambda
Expand All @@ -350,12 +350,26 @@ jobs:
name: Deploy generate document manifest lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment}}
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch}}
build_branch: ${{ inputs.build_branch }}
sandbox: ${{ inputs.sandbox }}
lambda_handler_name: generate_document_manifest_handler
lambda_aws_name: GenerateDocumentManifest
lambda_layer_names: "core_lambda_layer"
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}

deploy_update_patient_ods_lambda:
name: Deploy update patient ods lambda
uses: ./.github/workflows/base-lambdas-reusable-deploy.yml
with:
environment: ${{ inputs.environment }}
python_version: ${{ inputs.python_version }}
build_branch: ${{ inputs.build_branch }}
sandbox: ${{ inputs.sandbox }}
lambda_handler_name: update_patient_ods_handler
lambda_aws_name: UpdatePatientOdsLambda
lambda_layer_names: core_lambda_layer
secrets:
AWS_ASSUME_ROLE: ${{ secrets.AWS_ASSUME_ROLE }}
1 change: 1 addition & 0 deletions lambdas/enums/patient_ods_inactive_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class PatientOdsInactiveStatus(StrEnum):
RESTRICTED = "REST"
SUSPENDED = "SUSP"
DECEASED = "DECE"

Expand Down
34 changes: 34 additions & 0 deletions lambdas/handlers/update_patient_ods_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import tempfile

from services.batch_update_ods_code import BatchUpdate
from utils.audit_logging_setup import LoggingService
from utils.decorators.ensure_env_var import ensure_environment_variables
from utils.decorators.override_error_check import override_error_check
from utils.decorators.set_audit_arg import set_request_context_for_logging

logger = LoggingService(__name__)


@set_request_context_for_logging
@ensure_environment_variables(
names=[
"APPCONFIG_APPLICATION",
"APPCONFIG_CONFIGURATION",
"APPCONFIG_ENVIRONMENT",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NogaNHS can you provide context for this please? Why does this stand out to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use app config for feature flags, and this lambda doesn't use any. (Maybe it should?)

"LLOYD_GEORGE_DYNAMODB_NAME",
NogaNHS marked this conversation as resolved.
Show resolved Hide resolved
"PDS_FHIR_IS_STUBBED",
]
)
@override_error_check
def lambda_handler(event, context):
table_name = os.environ["LLOYD_GEORGE_DYNAMODB_NAME"]
tempdir = tempfile.mkdtemp()
filename = "batch_update_progress.json"

batch_update = BatchUpdate(
table_name=table_name,
progress_store_file_path=f"{tempdir}/{filename}",
)

batch_update.main()
26 changes: 10 additions & 16 deletions lambdas/models/pds_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def get_current_home_address(self) -> Optional[Address]:

def get_ods_code_or_inactive_status_for_gp(self) -> str:
return (
self.get_active_ods_code_for_gp()
PatientOdsInactiveStatus.RESTRICTED if not self.is_unrestricted()
else self.get_active_ods_code_for_gp()
or self.get_status_for_inactive_patient()
or ""
)

def get_active_ods_code_for_gp(self) -> str:
Expand All @@ -165,8 +165,9 @@ def get_active_ods_code_for_gp(self) -> str:
return entry.identifier.value

def get_status_for_inactive_patient(self) -> str:
death_notification_status = self.get_death_notification_status()
if not is_deceased(death_notification_status) and self.is_unrestricted():
if is_formally_deceased(self.get_death_notification_status()):
return PatientOdsInactiveStatus.DECEASED
else:
return PatientOdsInactiveStatus.SUSPENDED

def get_is_active_status(self) -> bool:
Expand Down Expand Up @@ -222,7 +223,7 @@ def get_patient_details(self, nhs_number) -> PatientDetails:
restricted=not self.is_unrestricted(),
generalPracticeOds=self.get_ods_code_or_inactive_status_for_gp(),
active=self.get_is_active_status(),
deceased=is_deceased(death_notification_status),
deceased=is_formally_deceased(death_notification_status),
deathNotificationStatus=death_notification_status,
)

Expand All @@ -236,21 +237,14 @@ def get_minimum_patient_details(self, nhs_number) -> PatientDetails:
givenName=given_name,
familyName=family_name,
birthDate=self.birth_date,
generalPracticeOds=(
self.get_ods_code_or_inactive_status_for_gp()
if self.is_unrestricted()
else ""
),
generalPracticeOds=self.get_ods_code_or_inactive_status_for_gp(),
nhsNumber=self.id,
superseded=bool(nhs_number == id),
restricted=not self.is_unrestricted(),
deceased=is_deceased(death_notification_status),
deceased=is_formally_deceased(death_notification_status),
deathNotificationStatus=death_notification_status,
)


def is_deceased(death_notification_status: Optional[DeathNotificationStatus]) -> bool:
return (
death_notification_status == DeathNotificationStatus.FORMAL
or death_notification_status == DeathNotificationStatus.INFORMAL
)
def is_formally_deceased(death_notification_status: Optional[DeathNotificationStatus]) -> bool:
return death_notification_status == DeathNotificationStatus.FORMAL
Empty file added lambdas/scripts/__init__.py
Empty file.
Loading
Loading