Skip to content

Commit

Permalink
PRMDR 0000 - bugs fixes (#358)
Browse files Browse the repository at this point in the history
* LG validator changes following pilot bugs
  • Loading branch information
NogaNHS authored May 2, 2024
1 parent 29af215 commit f21ddcf
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 60 deletions.
31 changes: 16 additions & 15 deletions lambdas/models/pds_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Address(BaseModel):
model_config = conf

use: str
period: Period
period: Optional[Period] = None
postal_code: Optional[str] = ""


class Name(BaseModel):
use: str
period: Period
given: list[str]
period: Optional[Period] = None
given: Optional[list[str]] = None
family: str


Expand All @@ -36,21 +36,21 @@ class Meta(BaseModel):


class GPIdentifier(BaseModel):
system: Optional[str]
system: Optional[str] = ""
value: str
period: Optional[Period]
period: Optional[Period] = None


class GeneralPractitioner(BaseModel):
id: Optional[str]
type: Optional[str]
id: Optional[str] = ""
type: Optional[str] = ""
identifier: GPIdentifier


class PatientDetails(BaseModel):
model_config = conf

given_Name: Optional[list[str]] = []
given_name: Optional[list[str]] = [""]
family_name: Optional[str] = ""
birth_date: Optional[date] = None
postal_code: Optional[str] = ""
Expand All @@ -69,7 +69,7 @@ class Patient(BaseModel):
address: Optional[list[Address]] = []
name: list[Name]
meta: Meta
general_practitioner: Optional[list[GeneralPractitioner]] = []
general_practitioner: Optional[list[GeneralPractitioner]] = None

def get_security(self) -> Security:
security = self.meta.security[0] if self.meta.security[0] else None
Expand All @@ -90,16 +90,17 @@ def get_current_usual_name(self) -> [Optional[Name]]:
return entry

def get_current_home_address(self) -> Optional[Address]:
if self.is_unrestricted():
if self.is_unrestricted() and self.address:
for entry in self.address:
if entry.use.lower() == "home":
return entry

def get_active_ods_code_for_gp(self) -> str:
for entry in self.general_practitioner:
gp_end_date = entry.identifier.period.end
if not gp_end_date or gp_end_date >= date.today():
return entry.identifier.value
if self.general_practitioner:
for entry in self.general_practitioner:
gp_end_date = entry.identifier.period.end
if not gp_end_date or gp_end_date >= date.today():
return entry.identifier.value
return ""

def get_is_active_status(self) -> bool:
Expand All @@ -113,7 +114,7 @@ def get_patient_details(self, nhs_number) -> PatientDetails:
birthDate=self.birth_date,
postalCode=(
self.get_current_home_address().postal_code
if self.is_unrestricted()
if self.is_unrestricted() and self.address
else ""
),
nhsNumber=self.id,
Expand Down
6 changes: 3 additions & 3 deletions lambdas/scripts/batch_update_ods_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ def build_progress_dict(self, dynamodb_records: list[dict]) -> dict:
progress_dict[nhs_number].doc_ref_ids.append(doc_ref_id)
pds_code_at_current_row = ods_code
if progress_dict[nhs_number].prev_ods_code != pds_code_at_current_row:
progress_dict[nhs_number].prev_ods_code = (
"[multiple ods codes in records]"
)
progress_dict[
nhs_number
].prev_ods_code = "[multiple ods codes in records]"

self.logger.info(f"Totally {len(progress_dict)} patients found in record.")
return progress_dict
Expand Down
6 changes: 3 additions & 3 deletions lambdas/services/create_document_reference_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def create_document_reference_request(
400, LambdaError.CreateDocInvalidType
)

url_responses[document_reference.file_name] = (
self.prepare_pre_signed_url(document_reference)
)
url_responses[
document_reference.file_name
] = self.prepare_pre_signed_url(document_reference)

if lg_documents:
validate_lg_files(lg_documents, nhs_number)
Expand Down
12 changes: 6 additions & 6 deletions lambdas/services/document_reference_search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def get_document_references(self, nhs_number: str):
for table_name in list_of_table_names:
logger.info(f"Searching for results in {table_name}")

documents: list[DocumentReference] = (
self.fetch_documents_from_table_with_filter(
nhs_number,
table_name,
query_filter=delete_filter_expression,
)
documents: list[
DocumentReference
] = self.fetch_documents_from_table_with_filter(
nhs_number,
table_name,
query_filter=delete_filter_expression,
)

results.extend(
Expand Down
7 changes: 7 additions & 0 deletions lambdas/tests/unit/helpers/data/pds/pds_patient_response.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import copy

PDS_PATIENT = {
"resourceType": "Patient",
"id": "9000000009",
Expand Down Expand Up @@ -524,3 +526,8 @@
},
},
}
PDS_PATIENT_WITH_MIDDLE_NAME = copy.deepcopy(PDS_PATIENT)
PDS_PATIENT_WITH_MIDDLE_NAME["name"][0]["given"].append("Jake")

PDS_PATIENT_WITHOUT_ADDRESS = copy.deepcopy(PDS_PATIENT)
PDS_PATIENT_WITHOUT_ADDRESS.pop("address")
21 changes: 21 additions & 0 deletions lambdas/tests/unit/models/test_pds_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
PDS_PATIENT_RESTRICTED,
PDS_PATIENT_WITH_GP_END_DATE,
PDS_PATIENT_WITHOUT_ACTIVE_GP,
PDS_PATIENT_WITHOUT_ADDRESS,
)
from tests.unit.helpers.data.pds.utils import create_patient
from utils.utilities import validate_nhs_number
Expand Down Expand Up @@ -109,3 +110,23 @@ def test_not_raise_error_when_gp_end_date_is_in_the_future():
patient.get_minimum_patient_details(patient.id)
except ValueError:
assert False, "No active GP practice for the patient"


def test_get_minimum_patient_details_missing_address():
patient = create_patient(PDS_PATIENT_WITHOUT_ADDRESS)

expected_patient_details = PatientDetails(
givenName=["Jane"],
familyName="Smith",
birthDate="2010-10-22",
postalCode="",
nhsNumber="9000000009",
superseded=False,
restricted=False,
generalPracticeOds="Y12345",
active=True,
)

result = patient.get_patient_details(patient.id)

assert expected_patient_details == result
Loading

0 comments on commit f21ddcf

Please sign in to comment.