Skip to content

Commit 9dd8d96

Browse files
Update endpoint statuses and patch returns 202
1 parent d2f6147 commit 9dd8d96

File tree

9 files changed

+50
-45
lines changed

9 files changed

+50
-45
lines changed

sandbox/services/LetterService.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,21 @@ const patchLetter = ({ xRequestId, id, body, xCorrelationId }) => new Promise(
8282
async (resolve, reject) => {
8383
try {
8484
const responseData = await ResponseProvider.patchLetterResponse(body);
85-
const content = await fs.readFile(responseData.responsePath);
86-
const fileData = JSON.parse(content);
87-
85+
if (responseData.responseCode !== 202) {
86+
const content = await fs.readFile(responseData.responsePath);
87+
const fileData = JSON.parse(content);
8888

89-
resolve(Service.successResponse({
90-
xRequestId,
91-
xCorrelationId,
92-
data: fileData,
93-
}, responseData.responseCode));
89+
resolve(Service.successResponse({
90+
xRequestId,
91+
xCorrelationId,
92+
data: fileData,
93+
}, responseData.responseCode));
94+
} else {
95+
resolve(Service.successResponse({
96+
xRequestId,
97+
xCorrelationId,
98+
}, responseData.responseCode));
99+
}
94100
} catch (e) {
95101
reject(Service.rejectResponse(
96102
e.message || 'Invalid input',
@@ -112,10 +118,21 @@ const postLetters = ({ xRequestId, body, xCorrelationId }) => new Promise(
112118
const responseData = await ResponseProvider.postLettersResponse(body);
113119

114120
try {
115-
resolve(Service.successResponse({
116-
xRequestId,
117-
xCorrelationId
118-
}, responseData.responseCode));
121+
if (responseData.responseCode !== 202) {
122+
const content = await fs.readFile(responseData.responsePath);
123+
const fileData = JSON.parse(content);
124+
125+
resolve(Service.successResponse({
126+
xRequestId,
127+
xCorrelationId,
128+
data: fileData,
129+
}, responseData.responseCode));
130+
} else {
131+
resolve(Service.successResponse({
132+
xRequestId,
133+
xCorrelationId,
134+
}, responseData.responseCode));
135+
}
119136
} catch (e) {
120137
reject(Service.rejectResponse(
121138
e.message || 'Invalid input',

sandbox/utils/ResponseProvider.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ async function getLettersResponse(limit) {
7676

7777
async function patchLetterResponse(request) {
7878
const patchLetterFileMap = {
79-
'data/examples/patchLetter/requests/patchLetter_PENDING.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_PENDING.json',responseCode: 200},
80-
'data/examples/patchLetter/requests/patchLetter_ACCEPTED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_ACCEPTED.json',responseCode: 200},
81-
'data/examples/patchLetter/requests/patchLetter_REJECTED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_REJECTED.json',responseCode: 200},
82-
'data/examples/patchLetter/requests/patchLetter_PRINTED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_PRINTED.json',responseCode: 200},
83-
'data/examples/patchLetter/requests/patchLetter_ENCLOSED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_ENCLOSED.json',responseCode: 200},
84-
'data/examples/patchLetter/requests/patchLetter_CANCELLED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_CANCELLED.json',responseCode: 200},
85-
'data/examples/patchLetter/requests/patchLetter_DISPATCHED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_DISPATCHED.json',responseCode: 200},
86-
'data/examples/patchLetter/requests/patchLetter_DELIVERED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_DELIVERED.json',responseCode: 200},
87-
'data/examples/patchLetter/requests/patchLetter_FAILED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_FAILED.json',responseCode: 200},
88-
'data/examples/patchLetter/requests/patchLetter_RETURNED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_RETURNED.json',responseCode: 200},
79+
'data/examples/patchLetter/requests/patchLetter_PENDING.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_PENDING.json',responseCode: 202},
80+
'data/examples/patchLetter/requests/patchLetter_ACCEPTED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_ACCEPTED.json',responseCode: 202},
81+
'data/examples/patchLetter/requests/patchLetter_REJECTED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_REJECTED.json',responseCode: 202},
82+
'data/examples/patchLetter/requests/patchLetter_PRINTED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_PRINTED.json',responseCode: 202},
83+
'data/examples/patchLetter/requests/patchLetter_ENCLOSED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_ENCLOSED.json',responseCode: 202},
84+
'data/examples/patchLetter/requests/patchLetter_CANCELLED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_CANCELLED.json',responseCode: 202},
85+
'data/examples/patchLetter/requests/patchLetter_DISPATCHED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_DISPATCHED.json',responseCode: 202},
86+
'data/examples/patchLetter/requests/patchLetter_DELIVERED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_DELIVERED.json',responseCode: 202},
87+
'data/examples/patchLetter/requests/patchLetter_FAILED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_FAILED.json',responseCode: 202},
88+
'data/examples/patchLetter/requests/patchLetter_RETURNED.json': {responsePath:'data/examples/patchLetter/responses/patchLetter_RETURNED.json',responseCode: 202},
8989
'data/examples/patchLetter/requests/patchLetter_INVALID.json': {responsePath:'data/examples/errors/responses/badRequest.json',responseCode: 400},
9090
'data/examples/patchLetter/requests/patchLetter_NOTFOUND.json': {responsePath:'data/examples/errors/responses/resourceNotFound.json',responseCode: 404},
9191
};

specification/api/components/documentation/patchLetter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Use this endpoint to update the status of a letter by submitting the new status in the request body, optionally providing a reason code and text.
44

5-
When you make a PATCH request with your application, the endpoint will respond with a successful (200) response code, along with the updated patient resource or an unsuccessful (4xx/5xx) response.
5+
When you make a PATCH request with your application, the endpoint will respond with an accepted (202) response code or an unsuccessful (4xx/5xx) response.
66

77
Rate limiting applies. On excess requests, you may receive **429 Too Many Requests** (example error code(s): `NOTIFY_QUOTA`). Back off and retry later.
88

specification/api/components/endpoints/createMI.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ responses:
1111
$ref: "../responses/postMI201.yml"
1212
'400':
1313
$ref: "../responses/errors/badRequest.yml"
14-
'404':
15-
$ref: "../responses/errors/resourceNotFound.yml"
1614
'429':
1715
$ref: "../responses/errors/tooManyRequests.yml"
1816
'500':

specification/api/components/endpoints/listLetters.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ responses:
1414
$ref: "../responses/getLetters200.yml"
1515
'400':
1616
$ref: "../responses/errors/listLetters/listLettersBadRequest.yml"
17-
'404':
18-
$ref: "../responses/errors/resourceNotFound.yml"
1917
'429':
2018
$ref: "../responses/errors/tooManyRequests.yml"
2119
'500':

specification/api/components/endpoints/patchLetter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ description:
55
requestBody:
66
$ref: "../requests/patchLetterRequest.yml"
77
responses:
8-
"200":
9-
$ref: "../responses/patchLetter200.yml"
8+
"202":
9+
$ref: "../responses/patchLetter202.yml"
1010
"400":
1111
$ref: "../responses/errors/patchLetter/patchLetterBadRequest.yml"
1212
"404":

specification/api/components/endpoints/postLetters.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ requestBody:
99
responses:
1010
'202':
1111
$ref: "../responses/postLetters202.yml"
12-
'404':
13-
$ref: "../responses/errors/resourceNotFound.yml"
12+
'400':
13+
$ref: "../responses/errors/badRequest.yml"
1414
'429':
1515
$ref: "../responses/errors/tooManyRequests.yml"
1616
'500':

specification/api/components/responses/patchLetter200.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: 202 (Accepted) Acknowledges Letter resource update has been received
2+
headers:
3+
X-Request-ID:
4+
$ref: "../responseHeaders/xRequestId.yml"
5+
X-Correlation-ID:
6+
$ref: "../responseHeaders/xCorrelationId.yml"

0 commit comments

Comments
 (0)