-
Notifications
You must be signed in to change notification settings - Fork 40
/
error.ts
117 lines (114 loc) · 2.93 KB
/
error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import {
OutboundPatientDiscoveryReq,
OutboundPatientDiscoveryResp,
XCPDGateway,
OutboundPatientDiscoveryRespFaultSchema,
OperationOutcome,
} from "@metriport/ihe-gateway-sdk";
import { PatientRegistryProfile } from "./schema";
import { extractText } from "../../../utils";
export function handleHttpErrorResponse({
httpError,
outboundRequest,
gateway,
}: {
httpError: string;
outboundRequest: OutboundPatientDiscoveryReq;
gateway: XCPDGateway;
}): OutboundPatientDiscoveryRespFaultSchema {
const operationOutcome: OperationOutcome = {
resourceType: "OperationOutcome",
id: outboundRequest.id,
issue: [
{
severity: "error",
code: "http-error",
details: {
text: httpError,
},
},
],
};
return {
id: outboundRequest.id,
timestamp: outboundRequest.timestamp,
responseTimestamp: new Date().toISOString(),
gateway,
patientId: outboundRequest?.patientId,
patientMatch: null,
iheGatewayV2: true,
operationOutcome,
};
}
export function handlePatientErrorResponse({
patientRegistryProfile,
outboundRequest,
gateway,
}: {
patientRegistryProfile: PatientRegistryProfile;
outboundRequest: OutboundPatientDiscoveryReq;
gateway: XCPDGateway;
patientId?: string | undefined;
cxId?: string | undefined;
}): OutboundPatientDiscoveryResp {
const acknowledgementDetail = patientRegistryProfile.acknowledgement?.acknowledgementDetail;
const issue = {
severity: "error",
code: acknowledgementDetail?.code?._code ?? "UK",
details: {
text: acknowledgementDetail?.text
? extractText(acknowledgementDetail.text)
: acknowledgementDetail?.location ?? "unknown",
},
};
const operationOutcome: OperationOutcome = {
resourceType: "OperationOutcome",
id: outboundRequest.id,
issue: [issue],
};
const response: OutboundPatientDiscoveryResp = {
id: outboundRequest.id,
timestamp: outboundRequest.timestamp,
responseTimestamp: new Date().toISOString(),
gateway,
patientId: outboundRequest.patientId,
patientMatch: null,
iheGatewayV2: true,
operationOutcome,
};
return response;
}
export function handleSchemaErrorResponse({
outboundRequest,
gateway,
text = "Zod Schema Error",
}: {
outboundRequest: OutboundPatientDiscoveryReq;
gateway: XCPDGateway;
text?: string;
}): OutboundPatientDiscoveryResp {
const operationOutcome: OperationOutcome = {
resourceType: "OperationOutcome",
id: outboundRequest.id,
issue: [
{
severity: "error",
code: "schema-error",
details: {
text,
},
},
],
};
const response: OutboundPatientDiscoveryResp = {
id: outboundRequest.id,
timestamp: outboundRequest.timestamp,
responseTimestamp: new Date().toISOString(),
gateway,
patientId: outboundRequest.patientId,
patientMatch: null,
iheGatewayV2: true,
operationOutcome,
};
return response;
}