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

Amb 1748 create unit tests for validations 10 to 19 #59

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ea74494
Add some unit tests and update validators
Nov 28, 2023
d46179c
Add model invalid report origin text test
Nov 28, 2023
808845a
Resolve conflicts and merge master into validations branch
Nov 29, 2023
98bd76d
Split out validator tests into method and model tests
Nov 29, 2023
971c9d5
Add pre-validation for disease type
Nov 29, 2023
2de4f81
fix validate_recorded in CSV
nathanwall Nov 30, 2023
d5cb275
check if report origin is not a NoneType
nathanwall Nov 30, 2023
fd7f9ed
updated error message for report origin text
nathanwall Nov 30, 2023
7f8cfa6
Start work on pre-validators
nathanwall Dec 1, 2023
206c74b
Add patient name and name_given tests and update validators and add p…
Dec 1, 2023
e40f92b
Merge branch 'master' into AMB-1748-create-unit-tests-for-validations…
Dec 1, 2023
5754180
Add validators and tests for patient family name and birth date and e…
Dec 4, 2023
869e6c4
Add validators and tests for gender, address and address_postal_code …
Dec 4, 2023
02ca91e
Add occurrenceDateTime pre validator and tests
Dec 5, 2023
67bd9d2
validators and tests for fields 8 to 10
nathanwall Dec 5, 2023
c86cb4b
Add test utils file and generic string validation tests methods
Dec 5, 2023
e27d37a
Amend immunization pre validator methods tests to use generic test fu…
Dec 6, 2023
8276931
Amend patient pre validator method tests to use generic functions
Dec 6, 2023
f3157ac
Create generic model tests
nathanwall Dec 6, 2023
01455b1
Add checking of empty string for fields with defined length and fix i…
Dec 6, 2023
62ed0a9
Fix tests and move old code to 'old'
nathanwall Dec 7, 2023
7e69ad1
Add empty list test to generic list test and use generic test functio…
Dec 7, 2023
04de9bc
Merge branch 'AMB-1748-create-unit-tests-for-validations-10-to-19' of…
Dec 7, 2023
77958cf
Amend patient model tests to use generic functions
Dec 7, 2023
444d729
fix for mesh csv test
nathanwall Dec 7, 2023
46a733e
Amend patient model tests to use generic functions
AlexandraBenson Dec 7, 2023
e6affe1
Rename old files, add status validator and tests
AlexandraBenson Dec 7, 2023
df27499
Add validators and tests for items 12 - 16
AlexandraBenson Dec 7, 2023
6a27eb9
Add all remaining validators and tests for 1-19
AlexandraBenson Dec 8, 2023
f516355
Tidy up
AlexandraBenson Dec 8, 2023
31fcc1b
Add to docstrings
AlexandraBenson Dec 8, 2023
ccf84f5
fix mesh tests
nathanwall Dec 8, 2023
4f26ef4
Add clarity to docstrings and comments
AlexandraBenson Dec 8, 2023
dd3e16f
Fix docstrings
AlexandraBenson Dec 8, 2023
76606a0
Handle negative timezones
AlexandraBenson Dec 8, 2023
a973a5e
Remove unneeded code
AlexandraBenson Dec 8, 2023
36bbe01
Fix pathing
AlexandraBenson Dec 8, 2023
060094f
Amend import paths
AlexandraBenson Dec 8, 2023
3f87772
Fix import paths
AlexandraBenson Dec 8, 2023
0ffae84
Fix import paths
AlexandraBenson Dec 8, 2023
fb04c5f
Extract date time testing logic into generic function
AlexandraBenson Dec 11, 2023
92897c1
Rename unclear variable
AlexandraBenson Dec 11, 2023
3641c65
Remove unnecessary imports
AlexandraBenson Dec 11, 2023
8f908c5
Amend name_given to be array of length 1
AlexandraBenson Dec 11, 2023
ef5b837
Amend sample patient data to have only 1 given name
AlexandraBenson Dec 11, 2023
41af6b8
Remove unneeded imports
AlexandraBenson Dec 12, 2023
c91819a
Amend name_given to be array of length 1
AlexandraBenson Dec 12, 2023
b3441f9
Update occurrenceDateTime and status validators
AlexandraBenson Dec 12, 2023
adee2a9
Add validation and tests for non-digits in patient_identifier_value
AlexandraBenson Dec 12, 2023
544b1ea
Update patient_identifier_value to match spec
AlexandraBenson Dec 12, 2023
5d2a52d
Change default args from 0 to None
AlexandraBenson Dec 18, 2023
1aba0cb
Re-order sample data to match FHIR documentation
AlexandraBenson Dec 18, 2023
4c6f299
Remove unnecessary regex from date validator
AlexandraBenson Dec 18, 2023
cf1cf4a
Reorder sample data to match FHIR documentation
AlexandraBenson Dec 19, 2023
48a5cbc
Remove commented out code
AlexandraBenson Dec 20, 2023
4284522
Rename old_nhs_validators file
AlexandraBenson Dec 21, 2023
078e445
Merge branch 'master' into AMB-1748-create-unit-tests-for-validations…
AlexandraBenson Dec 21, 2023
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
48 changes: 0 additions & 48 deletions lambda_code/src/models/FHIRUKImmunization.py

This file was deleted.

36 changes: 30 additions & 6 deletions lambda_code/src/models/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
"""Constants"""

import re
from datetime import datetime
from typing import Union


class Constants:
genders = {"male", "female", "other", "unknown"}
action_flags = {"completed", "entered-in-error"}
vaccination_not_given_flag: str = "not-done"
vaccination_given_flag: str = "empty"
""" "Constants used for the models"""

# Constants
STATUSES = ("completed", "entered-in-error", "not-done")
PRIMARY_SOURCE = {True, False}
GENDERS = ("male", "female", "other", "unknown")
VACCINATION_NOT_GIVEN_FLAG: str = "not-done"
VACCINATION_GIVEN_FLAG: str = "empty"
lee-richardson-nhs marked this conversation as resolved.
Show resolved Hide resolved
# TODO: valid_disease_types needs updated to reprent agreed list (needs to consider the
# mapping used for converting snomed code to disease type)
VALID_DISEASE_TYPES = {"COVID-19", "FLU"}

@staticmethod
def convert_snomed_code_to_target_disease_type(
snomed_code: str,
) -> Union[str, None]:
"""Convert a disease type snomed code to the disease type"""
# TODO: disease_types needs to change to be the confirmed
# list mapping of snomed to disease type
disease_types = {
"6142004": "FLU",
"840539006": "COVID-19",
"00000": "Invalid disease",
}
return disease_types.get(snomed_code)

@staticmethod
def convert_iso8601_to_datetime(iso_datetime_str):
Expand Down Expand Up @@ -48,10 +72,10 @@ def is_urn_resource(s):

@staticmethod
def if_vaccine_not_give(not_given_flag):
lee-richardson-nhs marked this conversation as resolved.
Show resolved Hide resolved
if not not_given_flag or not_given_flag == Constants.vaccination_given_flag:
lee-richardson-nhs marked this conversation as resolved.
Show resolved Hide resolved
if not not_given_flag or not_given_flag == Constants.VACCINATION_GIVEN_FLAG:
lee-richardson-nhs marked this conversation as resolved.
Show resolved Hide resolved
return False
else:
if not_given_flag == Constants.vaccination_not_given_flag:
if not_given_flag == Constants.VACCINATION_NOT_GIVEN_FLAG:
return True

@staticmethod
Expand Down
10 changes: 6 additions & 4 deletions lambda_code/src/models/csv_immunization.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ def validate_site_code(cls, value):
@validator("ACTION_FLAG", pre=True, always=True)
def validate_action_flag(cls, value):
"""Validate action flag"""
return NHSImmunizationValidators.validate_action_flag(value)
return NHSImmunizationValidators.validate_status(value)

@validator("PERFORMING_PROFESSIONAL_FORENAME", pre=True, always=True)
def validate_professional_forename(cls, v, values):
"""Validate performing professional forename"""
return NHSPractitionerValidators.validate_performing_professional_forename(
v, values.get("PERFORMING_PROFESSIONAL_SURNAME", None)
"FLU", # TODO: This is hardcoded for now. We need to get this from the CSV
values.get("PERFORMING_PROFESSIONAL_SURNAME"),
values.get("PERFORMING_PROFESSIONAL_FORENAME"),
)

@validator("PERFORMING_PROFESSIONAL_BODY_REG_CODE", pre=True, always=True)
Expand All @@ -132,13 +134,13 @@ def validate_professional_reg_code(cls, v, values):
@validator("RECORDED_DATE", pre=True, always=True)
def validate_recorded_date(cls, value):
"""Validate recorded date"""
return NHSImmunizationValidators.validate_recorded_date(value)
return NHSImmunizationValidators.validate_recorded(value)

@validator("REPORT_ORIGIN", pre=True, always=True)
def validate_report_origin(cls, v, values):
"""Validate report origin"""
primary_source = values["PRIMARY_SOURCE"]
return NHSImmunizationValidators.validate_report_origin(v, primary_source)
return NHSImmunizationValidators.validate_report_origin_text(v, primary_source)

@validator("NOT_GIVEN", pre=True, always=True)
def validate_not_given_flag(cls, value):
Expand Down
Loading
Loading