Skip to content

Commit 6a47812

Browse files
committed
fix: stylistic changes following pfp
1 parent 0d242cf commit 6a47812

5 files changed

Lines changed: 153 additions & 63 deletions

File tree

packages/cdk/resources/Apis.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,31 @@ export interface ApisProps {
1818
readonly csocApiGatewayDestination: string
1919
readonly deployCheckPrescriptionStatusUpdate: boolean
2020
readonly exposeGetStatusUpdates: boolean
21-
functions: {[key: string]: TypescriptLambdaFunction}
22-
stateMachines: {[key: string]: ExpressStateMachine}
21+
readonly functions: {
22+
readonly status: TypescriptLambdaFunction
23+
readonly capabilityStatement: TypescriptLambdaFunction
24+
readonly nhsNotifyUpdateCallback: TypescriptLambdaFunction
25+
readonly getStatusUpdates: TypescriptLambdaFunction
26+
readonly checkPrescriptionStatusUpdates?: TypescriptLambdaFunction
27+
}
28+
readonly stateMachines: {
29+
readonly updatePrescriptionStatus: ExpressStateMachine
30+
readonly format1UpdatePrescriptionsStatus: ExpressStateMachine
31+
}
2332
}
2433

2534
export class Apis extends Construct {
26-
apis: {[key: string]: RestApiGateway}
27-
endpoints: {[key: string]: Construct}
35+
public readonly apis: {
36+
readonly api: RestApiGateway
37+
}
38+
public readonly endpoints: {
39+
readonly rootResource: Construct
40+
readonly format1UpdatePrescriptionStatusEndpoint: StateMachineEndpoint
41+
readonly status: LambdaEndpoint
42+
readonly capabilityStatement: LambdaEndpoint
43+
readonly notificationDeliveryStatusCallback: LambdaEndpoint
44+
readonly checkPrescriptionStatusUpdates?: LambdaEndpoint
45+
}
2846

2947
public constructor(scope: Construct, id: string, props: ApisProps) {
3048
super(scope, id)
@@ -105,24 +123,25 @@ export class Apis extends Construct {
105123
lambdaFunction: props.functions.capabilityStatement
106124
})
107125

108-
this.endpoints = {
109-
rootResource,
110-
format1UpdatePrescriptionStatusEndpoint: format1PsuEndpoint,
111-
status: statusEndpoint,
112-
capabilityStatement: capabilityStatementEndpoint,
113-
notificationDeliveryStatusCallback: notifyCallbackEndpoint
114-
}
115-
116126
// GET /checkprescriptionstatusupdates — conditional Lambda proxy integration
127+
let checkPsu : LambdaEndpoint | undefined
117128
if (props.deployCheckPrescriptionStatusUpdate) {
118-
const checkPsu = new LambdaEndpoint(this, "CheckPrescriptionStatusUpdatesEndpoint", {
129+
checkPsu = new LambdaEndpoint(this, "CheckPrescriptionStatusUpdatesEndpoint", {
119130
parentResource: rootResource,
120131
resourceName: "checkprescriptionstatusupdates",
121132
method: HttpMethod.GET,
122133
restApiGatewayRole: apiGateway.role,
123134
lambdaFunction: props.functions.checkPrescriptionStatusUpdates
124135
})
125-
this.endpoints.checkPrescriptionStatusUpdates = checkPsu
136+
}
137+
138+
this.endpoints = {
139+
rootResource,
140+
format1UpdatePrescriptionStatusEndpoint: format1PsuEndpoint,
141+
status: statusEndpoint,
142+
capabilityStatement: capabilityStatementEndpoint,
143+
notificationDeliveryStatusCallback: notifyCallbackEndpoint,
144+
checkPrescriptionStatusUpdates: checkPsu
126145
}
127146

128147
// POST /get-status-updates — conditional Lambda integration (non-proxy)

packages/cdk/resources/Functions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@ export interface FunctionsProps {
3131
const baseDir = resolve(__dirname, "../../..")
3232

3333
export class Functions extends Construct {
34-
functions: {[key: string]: TypescriptLambdaFunction}
34+
public readonly functions: {
35+
readonly updatePrescriptionStatus: TypescriptLambdaFunction
36+
readonly convertRequestToFhirFormat: TypescriptLambdaFunction
37+
readonly getStatusUpdates: TypescriptLambdaFunction
38+
readonly status: TypescriptLambdaFunction
39+
readonly capabilityStatement: TypescriptLambdaFunction
40+
readonly nhsNotifyUpdateCallback: TypescriptLambdaFunction
41+
readonly notifyProcessor: TypescriptLambdaFunction
42+
readonly postDatedNotifyLambda: TypescriptLambdaFunction
43+
readonly checkPrescriptionStatusUpdates?: TypescriptLambdaFunction
44+
}
3545

3646
public constructor(scope: Construct, id: string, props: FunctionsProps) {
3747
super(scope, id)

packages/cdk/resources/StateMachineDefinitions/Format1UpdatePrescriptionsStatus.ts

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,40 @@ export class Format1UpdatePrescriptionsStatusDefinition extends Construct {
2323
) {
2424
super(scope, id)
2525

26-
const catchAllError = new Pass(this, "CatchAllError", {
26+
const catchAllError = this.createCatchAllError()
27+
const callConvertRequestToFhirFormat = this.createCallConvertRequestToFhirFormat(
28+
props.convertRequestToFhirFormatFunction,
29+
catchAllError
30+
)
31+
const callUpdatePrescriptionStatus = this.createCallUpdatePrescriptionStatus(
32+
props.updatePrescriptionStatusFunction,
33+
catchAllError
34+
)
35+
36+
this.definition = Chain
37+
.start(callConvertRequestToFhirFormat)
38+
.next(
39+
new Choice(this, "Convert Request to FHIR result")
40+
.when(
41+
Condition.jsonata("{% $convertStatusCode != 200 %}"),
42+
this.createFailedConvertRequestToFhir()
43+
)
44+
.otherwise(
45+
callUpdatePrescriptionStatus
46+
.next(
47+
new Choice(this, "Check Update Prescription Status Result")
48+
.when(
49+
Condition.jsonata("{% $updateStatusCode = 409 %}"),
50+
this.createTranslate409To202()
51+
)
52+
.otherwise(new Pass(this, "End State"))
53+
)
54+
)
55+
)
56+
}
57+
58+
private createCatchAllError(): Pass {
59+
return new Pass(this, "CatchAllError", {
2760
outputs: {
2861
Payload: {
2962
statusCode: 500,
@@ -38,10 +71,17 @@ export class Format1UpdatePrescriptionsStatusDefinition extends Construct {
3871
}
3972
}
4073
})
74+
}
4175

76+
private createCallConvertRequestToFhirFormat(
77+
convertRequestToFhirFormatFunction: IFunction,
78+
catchAllError: Pass
79+
): LambdaInvoke {
4280
const callConvertRequestToFhirFormat = new LambdaInvoke(
43-
this, "Call Convert Request To Fhir Format", {
44-
lambdaFunction: props.convertRequestToFhirFormatFunction,
81+
this,
82+
"Call Convert Request To Fhir Format",
83+
{
84+
lambdaFunction: convertRequestToFhirFormatFunction,
4585
assign: {
4686
convertStatusCode: "{% $states.result.Payload.statusCode %}",
4787
convertHeaders: "{% $states.result.Payload.headers %}",
@@ -50,8 +90,11 @@ export class Format1UpdatePrescriptionsStatusDefinition extends Construct {
5090
}
5191
)
5292
callConvertRequestToFhirFormat.addCatch(catchAllError)
93+
return callConvertRequestToFhirFormat
94+
}
5395

54-
const failedConvertRequestToFhir = new Pass(this, "Failed Convert Request to FHIR", {
96+
private createFailedConvertRequestToFhir(): Pass {
97+
return new Pass(this, "Failed Convert Request to FHIR", {
5598
outputs: {
5699
Payload: {
57100
statusCode: "{% $convertStatusCode %}",
@@ -60,10 +103,17 @@ export class Format1UpdatePrescriptionsStatusDefinition extends Construct {
60103
}
61104
}
62105
})
106+
}
63107

108+
private createCallUpdatePrescriptionStatus(
109+
updatePrescriptionStatusFunction: IFunction,
110+
catchAllError: Pass
111+
): LambdaInvoke {
64112
const callUpdatePrescriptionStatus = new LambdaInvoke(
65-
this, "Call Update Prescription Status", {
66-
lambdaFunction: props.updatePrescriptionStatusFunction,
113+
this,
114+
"Call Update Prescription Status",
115+
{
116+
lambdaFunction: updatePrescriptionStatusFunction,
67117
payload: TaskInput.fromObject({
68118
body: "{% $string($convertBody) %}",
69119
headers: "{% $convertHeaders %}"
@@ -75,8 +125,11 @@ export class Format1UpdatePrescriptionsStatusDefinition extends Construct {
75125
}
76126
)
77127
callUpdatePrescriptionStatus.addCatch(catchAllError)
128+
return callUpdatePrescriptionStatus
129+
}
78130

79-
const translate409To202 = new Pass(this, "Translate 409 to 202", {
131+
private createTranslate409To202(): Pass {
132+
return new Pass(this, "Translate 409 to 202", {
80133
outputs: {
81134
Payload: {
82135
statusCode: 202,
@@ -96,28 +149,5 @@ export class Format1UpdatePrescriptionsStatusDefinition extends Construct {
96149
}
97150
}
98151
})
99-
100-
const endState = new Pass(this, "End State")
101-
102-
const checkConvertResult = new Choice(this, "Convert Request to FHIR result")
103-
const convertNotOk = Condition.jsonata("{% $convertStatusCode != 200 %}")
104-
105-
const checkUpdateResult = new Choice(this, "Check Update Prescription Status Result")
106-
const updateIs409 = Condition.jsonata("{% $updateStatusCode = 409 %}")
107-
108-
this.definition = Chain
109-
.start(callConvertRequestToFhirFormat)
110-
.next(
111-
checkConvertResult
112-
.when(convertNotOk, failedConvertRequestToFhir)
113-
.otherwise(
114-
callUpdatePrescriptionStatus
115-
.next(
116-
checkUpdateResult
117-
.when(updateIs409, translate409To202)
118-
.otherwise(endState)
119-
)
120-
)
121-
)
122152
}
123153
}

packages/cdk/resources/StateMachineDefinitions/UpdatePrescriptionStatus.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,30 @@ export class UpdatePrescriptionStatusDefinition extends Construct {
2222
) {
2323
super(scope, id)
2424

25-
const catchAllError = new Pass(this, "CatchAllError", {
25+
const catchAllError = this.createCatchAllError()
26+
const callFhirValidation = this.createCallFhirValidation(
27+
props.fhirValidationFunction,
28+
catchAllError
29+
)
30+
const callUpdatePrescriptionStatus = this.createCallUpdatePrescriptionStatus(
31+
props.updatePrescriptionStatusFunction,
32+
catchAllError
33+
)
34+
35+
this.definition = Chain
36+
.start(callFhirValidation)
37+
.next(
38+
new Choice(this, "Do FHIR Validation Errors Exist")
39+
.when(
40+
Condition.jsonata("{% $fhirValidationErrorCount > 0 %}"),
41+
this.createReturnFailedFhirValidationErrors()
42+
)
43+
.otherwise(callUpdatePrescriptionStatus)
44+
)
45+
}
46+
47+
private createCatchAllError(): Pass {
48+
return new Pass(this, "CatchAllError", {
2649
outputs: {
2750
Payload: {
2851
statusCode: 500,
@@ -37,18 +60,23 @@ export class UpdatePrescriptionStatusDefinition extends Construct {
3760
}
3861
}
3962
})
63+
}
4064

65+
private createCallFhirValidation(fhirValidationFunction: IFunction, catchAllError: Pass): LambdaInvoke {
4166
const callFhirValidation = new LambdaInvoke(this, "Call FHIR Validation", {
42-
lambdaFunction: props.fhirValidationFunction,
67+
lambdaFunction: fhirValidationFunction,
4368
assign: {
4469
fhirValidationResponse: "{% $states.result.Payload %}",
4570
fhirValidationErrorCount:
4671
"{% $count($states.result.Payload.issue[severity = 'error']) %}"
4772
}
4873
})
4974
callFhirValidation.addCatch(catchAllError)
75+
return callFhirValidation
76+
}
5077

51-
const returnFailedFhirValidationErrors = new Pass(this, "Return Failed FHIR Validation Errors", {
78+
private createReturnFailedFhirValidationErrors(): Pass {
79+
return new Pass(this, "Return Failed FHIR Validation Errors", {
5280
outputs: {
5381
Payload: {
5482
statusCode: 400,
@@ -60,23 +88,20 @@ export class UpdatePrescriptionStatusDefinition extends Construct {
6088
}
6189
}
6290
})
91+
}
6392

93+
private createCallUpdatePrescriptionStatus(
94+
updatePrescriptionStatusFunction: IFunction,
95+
catchAllError: Pass
96+
): LambdaInvoke {
6497
const callUpdatePrescriptionStatus = new LambdaInvoke(
65-
this, "Call Update Prescription Status", {
66-
lambdaFunction: props.updatePrescriptionStatusFunction
98+
this,
99+
"Call Update Prescription Status",
100+
{
101+
lambdaFunction: updatePrescriptionStatusFunction
67102
}
68103
)
69104
callUpdatePrescriptionStatus.addCatch(catchAllError)
70-
71-
const doFhirValidationErrorsExist = new Choice(this, "Do FHIR Validation Errors Exist")
72-
const hasErrors = Condition.jsonata("{% $fhirValidationErrorCount > 0 %}")
73-
74-
this.definition = Chain
75-
.start(callFhirValidation)
76-
.next(
77-
doFhirValidationErrorsExist
78-
.when(hasErrors, returnFailedFhirValidationErrors)
79-
.otherwise(callUpdatePrescriptionStatus)
80-
)
105+
return callUpdatePrescriptionStatus
81106
}
82107
}

packages/cdk/resources/StateMachines.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ import {Format1UpdatePrescriptionsStatusDefinition} from "./StateMachineDefiniti
99
export interface StateMachinesProps {
1010
readonly stackName: string
1111
readonly logRetentionInDays: number
12-
readonly functions: {[key: string]: TypescriptLambdaFunction}
12+
readonly functions: {
13+
readonly updatePrescriptionStatus: TypescriptLambdaFunction
14+
readonly convertRequestToFhirFormat: TypescriptLambdaFunction
15+
}
1316
}
1417

1518
export class StateMachines extends Construct {
16-
stateMachines: {[key: string]: ExpressStateMachine}
19+
public readonly stateMachines: {
20+
readonly updatePrescriptionStatus: ExpressStateMachine
21+
readonly format1UpdatePrescriptionsStatus: ExpressStateMachine
22+
}
1723

1824
public constructor(scope: Construct, id: string, props: StateMachinesProps) {
1925
super(scope, id)

0 commit comments

Comments
 (0)