Skip to content

Commit 92c7a44

Browse files
committed
handle missing wc info during create lab
1 parent 278c4b9 commit 92c7a44

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

apps/ehr/src/features/external-labs/pages/CreateExternalLabOrder.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
} from '@mui/material';
1818
import Oystehr from '@oystehr/sdk';
1919
import { enqueueSnackbar } from 'notistack';
20-
import React, { useEffect, useMemo, useState } from 'react';
21-
import { useNavigate } from 'react-router-dom';
20+
import React, { ReactElement, useEffect, useMemo, useState } from 'react';
21+
import { Link, useNavigate } from 'react-router-dom';
2222
import { ActionsList } from 'src/components/ActionsList';
2323
import { DeleteIconButton } from 'src/components/DeleteIconButton';
2424
import DetailPageContainer from 'src/features/common/DetailPageContainer';
@@ -36,6 +36,7 @@ import {
3636
} from 'src/features/visits/shared/stores/appointment/appointment.store';
3737
import { useDebounce } from 'src/shared/hooks/useDebounce';
3838
import {
39+
APIErrorCode,
3940
CreateLabPaymentMethod,
4041
DiagnosisDTO,
4142
getAttendingPractitionerId,
@@ -64,7 +65,7 @@ export const CreateExternalLabOrder: React.FC<CreateExternalLabOrdersProps> = ()
6465
const theme = useTheme();
6566
const { oystehrZambda } = useApiClients();
6667
const navigate = useNavigate();
67-
const [error, setError] = useState<string[] | undefined>(undefined);
68+
const [error, setError] = useState<(string | ReactElement)[] | undefined>(undefined);
6869
const [submitting, setSubmitting] = useState<boolean>(false);
6970
const apiClient = useOystehrAPIClient();
7071
const {
@@ -215,7 +216,17 @@ export const CreateExternalLabOrder: React.FC<CreateExternalLabOrdersProps> = ()
215216
const sdkError = e as Oystehr.OystehrSdkError;
216217
console.log('error creating external lab order', sdkError.code, sdkError.message);
217218
const errorMessage = [sdkError.message];
218-
setError(errorMessage);
219+
if (sdkError.code === APIErrorCode.MISSING_WC_INFO_FOR_LABS) {
220+
setError([
221+
<>
222+
Information necessary to submit labs is missing. Please navigate to{' '}
223+
<Link to={`/visit/${appointment?.id}`}>visit details</Link> and complete all Worker's Compensation
224+
Information.
225+
</>,
226+
]);
227+
} else {
228+
setError(errorMessage);
229+
}
219230
}
220231
} else if (!paramsSatisfied) {
221232
const errorMessage = [];
@@ -617,9 +628,7 @@ export const CreateExternalLabOrder: React.FC<CreateExternalLabOrdersProps> = ()
617628
error.length > 0 &&
618629
error.map((msg, idx) => (
619630
<Grid item xs={12} sx={{ textAlign: 'right', paddingTop: 1 }} key={idx}>
620-
<Typography sx={{ color: theme.palette.error.main }}>
621-
{typeof msg === 'string' ? msg : JSON.stringify(msg, null, 2)}
622-
</Typography>
631+
<Typography sx={{ color: theme.palette.error.main }}>{msg}</Typography>
623632
</Grid>
624633
))}
625634
</Grid>

packages/utils/lib/types/errors/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum APIErrorCode {
5151
EXTERNAL_LAB_GENERAL = 4400,
5252
MISSING_NLM_API_KEY_ERROR = 4401,
5353
IN_HOUSE_LAB_GENERAL = 4402,
54+
MISSING_WC_INFO_FOR_LABS = 4403,
5455

5556
// 45xx
5657
STRIPE_PAYMENT_ERROR_GENERIC = 4500,
@@ -335,6 +336,13 @@ export const EXTERNAL_LAB_ERROR = (message: string): APIError => {
335336
message,
336337
};
337338
};
339+
340+
export const EXTERNAL_LAB_ERROR_MISSING_WC_INFO = (message: string): APIError => {
341+
return {
342+
code: APIErrorCode.MISSING_WC_INFO_FOR_LABS,
343+
message,
344+
};
345+
};
338346
export const ORDER_SUBMITTED_MESSAGE = 'Order is already submitted';
339347

340348
export const IN_HOUSE_LAB_ERROR = (message: string): APIError => {

packages/zambdas/src/ehr/lab/external/create-lab-order/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
CreateLabPaymentMethod,
2727
createOrderNumber,
2828
EXTERNAL_LAB_ERROR,
29+
EXTERNAL_LAB_ERROR_MISSING_WC_INFO,
2930
FHIR_IDC10_VALUESET_SYSTEM,
3031
flattenBundleResources,
3132
getAttendingPractitionerId,
@@ -763,13 +764,16 @@ const getAdditionalResources = async (
763764

764765
if (selectedPaymentMethod === LabPaymentMethod.WorkersComp) {
765766
if (workersCompAccounts.length !== 1) {
766-
throw new Error(`Incorrect number of workers comp accounts found: ${workersCompAccounts.length}`);
767+
console.log(`Incorrect number of workers comp accounts found: ${workersCompAccounts.length}`);
768+
throw EXTERNAL_LAB_ERROR_MISSING_WC_INFO(
769+
`Information necessary to submit labs is missing. Please navigate to visit details and complete all Worker's Compensation Information.`
770+
);
767771
}
768772

769773
if (!workersCompInsurance) {
770774
console.log(`workersCompInsurance not found for encounter: ${encounter.id}`);
771-
throw EXTERNAL_LAB_ERROR(
772-
`Insurance information is missing. Please review paperwork and confirm all workers compensation information is entered`
775+
throw EXTERNAL_LAB_ERROR_MISSING_WC_INFO(
776+
`Information necessary to submit labs is missing. Please navigate to visit details and complete all Worker's Compensation Information.`
773777
);
774778
}
775779

packages/zambdas/src/ehr/lab/external/get-create-lab-order-resources/index.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ const getResources = async (
210210
const appointment = appointments.find((resource) => resource.id === appointmentId);
211211
const appointmentIsWorkersComp = appointment ? isAppointmentWorkersComp(appointment) : false;
212212
console.log('appointmentIsWorkersComp', appointmentIsWorkersComp);
213-
let encounterIsWorkersComp = false;
214213

215214
// doing some validation that the workers comp account is properly linked to the encounter
216215
// oystehr labs depends on this account for submitting workers comp labs
@@ -221,25 +220,15 @@ const getResources = async (
221220
(account) => account.id
222221
)}`
223222
);
224-
throw EXTERNAL_LAB_ERROR(
225-
'Information necessary to submit labs is missing. Please review paperwork and confirm all workers compensation information is entered.'
226-
);
227223
}
228-
const workersCompAccount = workersCompAccounts[0];
229-
230-
console.log('checking that workers comp account is associated with this encounter');
231-
console.log('workersCompAccount', workersCompAccount.id);
232-
console.log('encounter.account', JSON.stringify(encounter?.account));
233-
234-
encounterIsWorkersComp = !!encounter?.account?.some((ref) => ref.reference === `Account/${workersCompAccount.id}`);
235224
}
236225

237226
return {
238227
coverages,
239228
accounts,
240229
labOrgsGUIDs,
241230
orderingLocationDetails: { orderingLocationIds, orderingLocations },
242-
isWorkersCompEncounter: appointmentIsWorkersComp && encounterIsWorkersComp,
231+
isWorkersCompEncounter: appointmentIsWorkersComp,
243232
};
244233
};
245234

0 commit comments

Comments
 (0)