88from decimal import Decimal
99
1010
11- from tests .utils_for_recordprocessor_tests .values_for_recordprocessor_tests import (
11+ from tests .utils_for_recordprocessor_tests .values_for_recordprocessor_tests import (
1212 MockFieldDictionaries ,
13- MockFileRows ,
1413)
1514
1615from tests .utils_for_recordprocessor_tests .utils_for_recordprocessor_tests import (
2221with patch ("os.environ" , MOCK_ENVIRONMENT_DICT ):
2322 # Do not attempt 'from src.mappings import Vaccine' as this imports a different instance of Vaccine
2423 # and tests will break
25- from mappings import Vaccine
2624 from clients import REGION_NAME
2725 from src .process_row import process_row
2826
2927s3_client = boto3_client ("s3" , region_name = REGION_NAME )
3028ROW_DETAILS = MockFieldDictionaries .all_fields
3129Allowed_Operations = {'CREATE' , 'UPDATE' , 'DELETE' }
3230
31+
3332@mock_s3
3433@patch .dict ("os.environ" , MOCK_ENVIRONMENT_DICT )
3534class TestProcessRow (unittest .TestCase ):
@@ -43,23 +42,26 @@ def tearDown(self) -> None:
4342
4443 def test_process_row_success (self ):
4544 """
46- Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
45+ Test that process_row gives the expected output.
46+ These tests check that the row is valid and matches the expected output.
4747 """
48- # set the expected output from 'process_row' in case of success
49- expected_result = {'resourceType' : 'Immunization' , 'status' : 'completed' , 'protocolApplied' : [{'targetDisease' : [], 'doseNumberPositiveInt' : 1 }], 'reasonCode' : [{'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '1037351000000105' }]}], 'recorded' : '2024-09-04' , 'identifier' : [{'value' : 'RSV_002' , 'system' : 'https://www.ravs.england.nhs.uk/' }], 'patient' : {'reference' : '#Patient1' }, 'contained' : [{'id' : 'Patient1' , 'resourceType' : 'Patient' , 'birthDate' : '2008-02-17' , 'gender' : 'male' , 'address' : [{'postalCode' : 'WD25 0DZ' }], 'identifier' : [{'system' : 'https://fhir.nhs.uk/Id/nhs-number' , 'value' : '9732928395' }], 'name' : [{'family' : 'PEEL' , 'given' : ['PHYLIS' ]}]}, {'resourceType' : 'Practitioner' , 'id' : 'Practitioner1' , 'name' : [{'family' : "O'Reilly" , 'given' : ['Ellena' ]}]}], 'vaccineCode' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '42223111000001107' , 'display' : 'Quadrivalent influenza vaccine (split virion, inactivated)' }]}, 'manufacturer' : {'display' : 'Sanofi Pasteur' }, 'expirationDate' : '2024-09-15' , 'lotNumber' : 'BN92478105653' , 'extension' : [{'url' : 'https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure' , 'valueCodeableConcept' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '956951000000104' , 'display' : 'RSV vaccination in pregnancy (procedure)' }]}}], 'occurrenceDateTime' : '2024-09-04T18:33:25+00:00' , 'primarySource' : True , 'site' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '368209003' , 'display' : 'Right arm' }]}, 'route' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '1210999013' , 'display' : 'Intradermal use' }]}, 'doseQuantity' : {'value' : Decimal ('0.3' ), 'unit' : 'Inhalation - unit of product usage' , 'system' : 'http://snomed.info/sct' , 'code' : '2622896019' }, 'performer' : [{'actor' : {'type' : 'Organization' , 'identifier' : {'system' : 'https://fhir.nhs.uk/Id/ods-organization-code' , 'value' : 'RVVKC' }}}, {'actor' : {'reference' : '#Practitioner1' }}], 'location' : {'identifier' : {'value' : 'RJC02' , 'system' : 'https://fhir.nhs.uk/Id/ods-organization-code' }}}
48+ # set the expected output from 'process_row' in case of success
49+ expected_result = {'resourceType' : 'Immunization' , 'status' : 'completed' , 'protocolApplied' : [{'targetDisease' : [], 'doseNumberPositiveInt' : 1 }], 'reasonCode' : [{'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '1037351000000105' }]}], 'recorded' : '2024-09-04' , 'identifier' : [{'value' : 'RSV_002' , 'system' : 'https://www.ravs.england.nhs.uk/' }], 'patient' : {'reference' : '#Patient1' }, 'contained' : [{'id' : 'Patient1' , 'resourceType' : 'Patient' , 'birthDate' : '2008-02-17' , 'gender' : 'male' , 'address' : [{'postalCode' : 'WD25 0DZ' }], 'identifier' : [{'system' : 'https://fhir.nhs.uk/Id/nhs-number' , 'value' : '9732928395' }], 'name' : [{'family' : 'PEEL' , 'given' : ['PHYLIS' ]}]}, {'resourceType' : 'Practitioner' , 'id' : 'Practitioner1' , 'name' : [{'family' : "O'Reilly" , 'given' : ['Ellena' ]}]}], 'vaccineCode' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '42223111000001107' , 'display' : 'Quadrivalent influenza vaccine (split virion, inactivated)' }]}, 'manufacturer' : {'display' : 'Sanofi Pasteur' }, 'expirationDate' : '2024-09-15' , 'lotNumber' : 'BN92478105653' , 'extension' : [{'url' : 'https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure' , 'valueCodeableConcept' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '956951000000104' , 'display' : 'RSV vaccination in pregnancy (procedure)' }]}}], 'occurrenceDateTime' : '2024-09-04T18:33:25+00:00' , 'primarySource' : True , 'site' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '368209003' , 'display' : 'Right arm' }]}, 'route' : {'coding' : [{'system' : 'http://snomed.info/sct' , 'code' : '1210999013' , 'display' : 'Intradermal use' }]}, 'doseQuantity' : {'value' : Decimal ('0.3' ), 'unit' : 'Inhalation - unit of product usage' , 'system' : 'http://snomed.info/sct' , 'code' : '2622896019' },
50+ 'performer' : [{'actor' : {'type' : 'Organization' , 'identifier' : {'system' : 'https://fhir.nhs.uk/Id/ods-organization-code' , 'value' : 'RVVKC' }}}, {'actor' : {'reference' : '#Practitioner1' }}], 'location' : {'identifier' : {'value' : 'RJC02' , 'system' : 'https://fhir.nhs.uk/Id/ods-organization-code' }}}
5051
5152 # call 'process_row' with required details
5253 imms_fhir_resource = process_row ("EMIS" , Allowed_Operations , ROW_DETAILS )
5354 # validate if the response with expected result
5455 self .assertDictEqual (imms_fhir_resource ["fhir_json" ], expected_result )
55-
56+
5657 def test_process_row_invalid_action_flag (self ):
5758 """
58- Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
59+ Test that process_row gives the expected output.
60+ These tests check that the row is valid and matches the expected output.
5961 """
6062 Mock_Row = deepcopy (ROW_DETAILS )
6163 # setting up the invalid action flag other than 'NEW', 'UPDATE' or 'DELETE'
62- Mock_Row ['ACTION_FLAG' ] = 'Invalid'
64+ Mock_Row ['ACTION_FLAG' ] = 'Invalid'
6365
6466 # call 'process_row' with required details
6567 response = process_row ("EMIS" , Allowed_Operations , Mock_Row )
@@ -69,12 +71,13 @@ def test_process_row_invalid_action_flag(self):
6971
7072 def test_process_row_missing_action_flag (self ):
7173 """
72- Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
74+ Test that process_row gives the expected output.
75+ These tests check that the row is valid and matches the expected output.
7376 """
7477
7578 Mock_Row = deepcopy (ROW_DETAILS )
76- # removing action flag from row
77- Mock_Row .pop ('ACTION_FLAG' )
79+ # removing action flag from row
80+ Mock_Row .pop ('ACTION_FLAG' )
7881
7982 # call 'process_row' with required details
8083 response = process_row ("EMIS" , Allowed_Operations , Mock_Row )
@@ -83,26 +86,27 @@ def test_process_row_missing_action_flag(self):
8386
8487 def test_process_row_missing_permission (self ):
8588 """
86- Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
89+ Test that process_row gives the expected output.
90+ These tests check that the row is valid and matches the expected output.
8791 """
8892 # only create and delete permission. Missing update
89- allowed_operation = {'CREATE' , 'DELETE' }
93+ allowed_operation = {'CREATE' , 'DELETE' }
9094 # copy row data with Action_Flag = 'Update'
91- Mock_Row = deepcopy (ROW_DETAILS )
95+ Mock_Row = deepcopy (ROW_DETAILS )
9296
9397 # call 'process_row' with required details
9498 response = process_row ("EMIS" , allowed_operation , Mock_Row )
95-
9699 self .assertEqual (response ['diagnostics' ]['error_type' ], 'NO_PERMISSIONS' )
97100 self .assertEqual (response ['diagnostics' ]['statusCode' ], 403 )
98101
99102 def test_process_row_missing_unique_id (self ):
100103 """
101- Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
104+ Test that process_row gives the expected output.
105+ These tests check that the row is valid and matches the expected output.
102106 """
103107 # copy row data and remove 'UNIQUE_ID'
104- Mock_Row = deepcopy (ROW_DETAILS )
105- Mock_Row .pop ('UNIQUE_ID' )
108+ Mock_Row = deepcopy (ROW_DETAILS )
109+ Mock_Row .pop ('UNIQUE_ID' )
106110 # call 'process_row' with required details
107111 response = process_row ("EMIS" , Allowed_Operations , Mock_Row )
108112
@@ -111,14 +115,15 @@ def test_process_row_missing_unique_id(self):
111115
112116 def test_process_row_missing_unique_id_uri (self ):
113117 """
114- Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
118+ Test that process_row gives the expected output.
119+ These tests check that the row is valid and matches the expected output.
115120 """
116121 # copy row data and remove 'UNIQUE_ID_URI'
117- Mock_Row = deepcopy (ROW_DETAILS )
118- Mock_Row .pop ('UNIQUE_ID_URI' )
122+ Mock_Row = deepcopy (ROW_DETAILS )
123+ Mock_Row .pop ('UNIQUE_ID_URI' )
119124 # call 'process_row' with required details
120125 response = process_row ("EMIS" , Allowed_Operations , Mock_Row )
121-
126+
122127 self .assertEqual (response ['diagnostics' ]['error_message' ], 'UNIQUE_ID or UNIQUE_ID_URI is missing' )
123128 self .assertEqual (response ['diagnostics' ]['statusCode' ], 400 )
124129
0 commit comments