Skip to content

Commit a3a196a

Browse files
committed
Address some of Tim's comments
1 parent 62d107f commit a3a196a

2 files changed

Lines changed: 14 additions & 35 deletions

File tree

packages/postDatedLambda/src/businessLogic.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ import {PSUDataItem} from "@psu-common/commonTypes"
44

55
import {PostDatedSQSMessageWithExistingRecords, PostDatedProcessingResult} from "./types"
66

7-
// defaults to false
8-
const POST_DATED_OVERRIDE = process.env.POST_DATED_OVERRIDE === "true"
9-
10-
// set from environment variable POST_DATED_OVERRIDE_VALUE
11-
const POST_DATED_OVERRIDE_VALUE_ENV = process.env.POST_DATED_OVERRIDE_VALUE ?? "ignore"
12-
let POST_DATED_OVERRIDE_VALUE: PostDatedProcessingResult
13-
switch (POST_DATED_OVERRIDE_VALUE_ENV.toLowerCase()) {
14-
case "matured":
15-
POST_DATED_OVERRIDE_VALUE = PostDatedProcessingResult.MATURED
16-
break
17-
case "immature":
18-
POST_DATED_OVERRIDE_VALUE = PostDatedProcessingResult.IMMATURE
19-
break
20-
default:
21-
POST_DATED_OVERRIDE_VALUE = PostDatedProcessingResult.IGNORE
22-
break
23-
}
24-
257
export function getMostRecentRecord(
268
existingRecords: Array<PSUDataItem>
279
): PSUDataItem {
@@ -53,12 +35,6 @@ export function processMessage(
5335
prescriptionData: message.prescriptionData,
5436
existingRecords: message.existingRecords
5537
})
56-
if (POST_DATED_OVERRIDE) {
57-
logger.info("Post-dated override is enabled, returning override value", {
58-
overrideValue: POST_DATED_OVERRIDE_VALUE
59-
})
60-
return POST_DATED_OVERRIDE_VALUE
61-
}
6238

6339
// The existingRecords array contains all records from the DynamoDB table
6440
// that match this prescription's PrescriptionID
@@ -141,7 +117,7 @@ export function computeTimeUntilMaturity(
141117
}
142118

143119
const lastModified = new Date(prescriptionRecord.LastModified)
144-
const currentTime = new Date()
120+
const currentTime = Date.now()
145121

146-
return (lastModified.getTime() - currentTime.getTime()) / 1000
122+
return (lastModified.getTime() - currentTime) / 1000
147123
}

packages/postDatedLambda/src/databaseClient.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,30 @@ export async function getExistingRecordsByPrescriptionID(
4646
let lastEvaluatedKey
4747
let items: Array<PSUDataItem> = []
4848

49+
logger.info("Querying DynamoDB for existing prescription records", {
50+
prescriptionID: normalizedPrescriptionID,
51+
tableName,
52+
indexName: pharmacyPrescriptionIndexName
53+
})
54+
4955
try {
50-
do {
56+
while (true) {
5157
if (lastEvaluatedKey) {
5258
query.ExclusiveStartKey = lastEvaluatedKey
5359
}
5460

55-
logger.info("Querying DynamoDB for existing prescription records", {
56-
prescriptionID: normalizedPrescriptionID,
57-
tableName,
58-
indexName: pharmacyPrescriptionIndexName
59-
})
60-
6161
const result = await client.send(new QueryCommand(query))
6262

6363
if (result.Items) {
6464
const parsedItems = result.Items.map((item) => unmarshall(item) as PSUDataItem)
65-
items = items.concat(parsedItems)
65+
items.push(parsedItems)
6666
}
6767

6868
lastEvaluatedKey = result.LastEvaluatedKey
69-
} while (lastEvaluatedKey)
69+
if (!lastEvaluatedKey) {
70+
break
71+
}
72+
}
7073

7174
logger.info("Retrieved existing prescription records from DynamoDB", {
7275
prescriptionID: normalizedPrescriptionID,

0 commit comments

Comments
 (0)