@@ -301,18 +301,13 @@ def delete_immunization(self, imms_id: str, supplier_system: str) -> None:
301301
302302 def search_immunizations (self , patient_identifier : str , vaccine_types : set ) -> list [dict ]:
303303 """Searches for immunisations by patient identifier (NHS Number) and the vaccination type"""
304- # vacc_type_condition = self._build_vacc_type_key_condition(vaccine_types )
305- is_not_deleted_condition = Attr ( "DeletedAt" ). not_exists () | Attr ( "DeletedAt" ). eq ( "reinstated" )
306- patient_key_condition = Key ( "PatientPK " ).eq ( _make_patient_pk ( patient_identifier ))
304+ nhs_number_key_condition = Key ( "PatientPK" ). eq ( _make_patient_pk ( patient_identifier ) )
305+ vacc_type_condition = self . _build_vacc_type_key_condition ( vaccine_types )
306+ filter_condition = vacc_type_condition & ( Attr ( "DeletedAt " ).not_exists () | Attr ( "DeletedAt" ). eq ( "reinstated" ))
307307
308- ieds_resources = []
308+ ieds_resources = self . get_all_items ( nhs_number_key_condition , filter_condition )
309309
310- for vacc_type in vaccine_types :
311- # Should make these DB keys constants
312- key_condition = patient_key_condition & Key ("PatientSK" ).begins_with (vacc_type )
313- ieds_resources .extend (self .get_all_items (key_condition , is_not_deleted_condition ))
314-
315- if len (ieds_resources ) == 0 :
310+ if not ieds_resources :
316311 return []
317312
318313 # Return a list of the FHIR immunization resource JSON items
@@ -353,15 +348,15 @@ def get_all_items(self, key_condition: ConditionBase, filter_condition: Conditio
353348
354349 return all_items
355350
356- # @staticmethod
357- # def _build_vacc_type_key_condition(vacc_types: set) -> ConditionBase:
358- # vacc_type_condition = None
359- #
360- # for vacc_type in vacc_types:
361- # key_cond = Key ("PatientSK").begins_with(vacc_type)
362- # vacc_type_condition = key_cond if vacc_type_condition is None else vacc_type_condition | key_cond
363- #
364- # return vacc_type_condition
351+ @staticmethod
352+ def _build_vacc_type_key_condition (vacc_types : set ) -> ConditionBase :
353+ vacc_type_condition = None
354+
355+ for vacc_type in vacc_types :
356+ key_cond = Attr ("PatientSK" ).begins_with (vacc_type )
357+ vacc_type_condition = key_cond if vacc_type_condition is None else vacc_type_condition | key_cond
358+
359+ return vacc_type_condition
365360
366361 @staticmethod
367362 def _vaccine_type (patient_sk : str ) -> str :
0 commit comments