@@ -18,19 +18,13 @@ def get_ieds_table():
1818
1919def ieds_check_exist (id : str ) -> bool :
2020 """Check if a record exists in the IEDS table for the given ID."""
21- logger .info (f"ieds_check_exist. Get ID: { id } " )
22- search_patient_pk = f"Patient# { id } "
21+ logger .info (f"Check Id exists ID: { id } " )
22+ items = get_items_from_patient_id ( id , 1 )
2323
24- response = get_ieds_table ().query (
25- IndexName = 'PatientGSI' ,
26- KeyConditionExpression = Key ('PatientPK' ).eq (search_patient_pk ),
27- Limit = 1
28- )
29-
30- items = response .get ('Items' , [])
31- found = len (items ) > 0
32- logger .info (f"ieds_check_exist. Record found: { found } for ID: { id } " )
33- return found
24+ if items or len (items ) > 0 :
25+ logger .info (f"Found patient ID: { id } " )
26+ return True
27+ return False
3428
3529
3630BATCH_SIZE = 25
@@ -49,10 +43,9 @@ def ieds_update_patient_id(old_id: str, new_id: str) -> dict:
4943 logger .info (f"Updating patient ID in IEDS from { old_id } to { new_id } " )
5044
5145 new_patient_pk = f"Patient#{ new_id } "
52- old_patient_pk = f"Patient#{ old_id } "
5346
5447 logger .info ("Getting items to update in IEDS table..." )
55- items_to_update = get_items_from_patient_pk ( old_patient_pk )
48+ items_to_update = get_items_from_patient_id ( old_id )
5649
5750 if not items_to_update :
5851 logger .warning (f"No items found to update for patient ID: { old_id } " )
@@ -63,12 +56,9 @@ def ieds_update_patient_id(old_id: str, new_id: str) -> dict:
6356
6457 transact_items = []
6558
66- logger .info ("loop through items to update..." )
6759 logger .info (f"Items to update: { len (items_to_update )} " )
6860 ieds_table_name = get_ieds_table_name ()
6961 for item in items_to_update :
70- logger .info ("Update item" )
71- logger .info (f"Updating item: { item ['PatientPK' ]} " )
7262 transact_items .append ({
7363 'Update' : {
7464 'TableName' : ieds_table_name ,
@@ -147,14 +137,15 @@ def ieds_update_patient_id(old_id: str, new_id: str) -> dict:
147137# return result
148138
149139
150- def get_items_from_patient_pk (patient_pk : str ) -> list :
151- """Get all items for patient PK."""
152- logger .info (f"Getting items for patient PK: { patient_pk } " )
140+ def get_items_from_patient_id (id : str , limit = BATCH_SIZE ) -> list :
141+ """Get all items for patient ID."""
142+ logger .info (f"Getting items for patient id: { id } " )
143+ patient_pk = f"Patient#{ id } "
153144 try :
154145 response = get_ieds_table ().query (
155146 IndexName = 'PatientGSI' , # query the GSI
156147 KeyConditionExpression = Key ('PatientPK' ).eq (patient_pk ),
157- Limit = BATCH_SIZE
148+ Limit = limit
158149 )
159150
160151 if 'Items' not in response or not response ['Items' ]:
0 commit comments