@@ -51,6 +51,10 @@ export const filterOutFutureReduceToLatestUpdates = (
5151 const updateTime = Date . parse ( item . lastUpdateDateTime )
5252 return updateTime <= currentTime
5353 } )
54+ logger . info ( "filtered future post-dated updates" , {
55+ count_dropped : ( items . length - validTimeUpdates . length ) ,
56+ count_received : items . length , inputPrescription, validTimeUpdates
57+ } )
5458
5559 // group by itemId and separate post-dated from regular updates
5660 const itemGroups : Record < string , { regular : itemType | null , postDated : itemType | null } > = { }
@@ -79,6 +83,7 @@ export const filterOutFutureReduceToLatestUpdates = (
7983 }
8084 }
8185 } )
86+ logger . info ( "grouped updates by itemId and type" , { itemGroups} )
8287
8388 // flatten both regular and post-dated updates into single array
8489 // but exclude post-dated updates if they have been revoked by a subsequent regular update
@@ -96,12 +101,16 @@ export const filterOutFutureReduceToLatestUpdates = (
96101 }
97102 }
98103 } )
104+ logger . info ( "flattened updates into unique items" , {
105+ validTimeCount : validTimeUpdates . length , uniqueItemsCount : uniqueItems . length , itemGroups, uniqueItems
106+ } )
99107
100108 const result : outputPrescriptionType = {
101109 prescriptionID : inputPrescription . prescriptionID ,
102110 onboarded : items . length > 0 , // consider onboarded even if all updates were post-dated
103111 items : uniqueItems
104112 }
113+ logger . info ( "returning updates result" , { result} )
105114 return result
106115}
107116
0 commit comments