33 Box ,
44 Button ,
55 capitalize ,
6+ CircularProgress ,
7+ Container ,
68 FormControlLabel ,
79 Paper ,
810 Radio ,
@@ -22,15 +24,19 @@ import { DocumentReference, Encounter, Patient } from 'fhir/r4b';
2224import { DateTime } from 'luxon' ;
2325import { enqueueSnackbar } from 'notistack' ;
2426import { FC , Fragment , ReactElement , useEffect , useState } from 'react' ;
27+ import { useOystehrAPIClient } from 'src/features/visits/shared/hooks/useOystehrAPIClient' ;
2528import { useApiClients } from 'src/hooks/useAppClients' ;
2629import { useGetEncounter } from 'src/hooks/useEncounter' ;
30+ import { useGetPatientAccount , useGetPatientCoverages } from 'src/hooks/useGetPatient' ;
2731import { useGetPatientPaymentsList } from 'src/hooks/useGetPatientPaymentsList' ;
2832import {
2933 APIError ,
3034 APIErrorCode ,
3135 CashOrCardPayment ,
36+ FHIR_EXTENSION ,
3237 getPaymentVariantFromEncounter ,
3338 isApiError ,
39+ PatientPaymentBenefit ,
3440 PatientPaymentDTO ,
3541 PaymentVariant ,
3642 PostPatientPaymentInput ,
@@ -68,6 +74,7 @@ export default function PatientPaymentList({
6874 responsibleParty,
6975} : PaymentListProps ) : ReactElement {
7076 const { oystehr, oystehrZambda } = useApiClients ( ) ;
77+ const apiClient = useOystehrAPIClient ( ) ;
7178 const theme = useTheme ( ) ;
7279 const [ paymentDialogOpen , setPaymentDialogOpen ] = useState ( false ) ;
7380 const [ sendReceiptByEmailDialogOpen , setSendReceiptByEmailDialogOpen ] = useState ( false ) ;
@@ -88,6 +95,38 @@ export default function PatientPaymentList({
8895 encounterId,
8996 disabled : ! encounterId || ! patient ?. id ,
9097 } ) ;
98+ const { data : insuranceData } = useGetPatientAccount ( {
99+ apiClient,
100+ patientId : patient ?. id ?? null ,
101+ } ) ;
102+
103+ const { data : insuranceCoverages } = useGetPatientCoverages ( {
104+ apiClient,
105+ patientId : patient ?. id ?? null ,
106+ } ) ;
107+
108+ function getPaymentAmountFromPatientBenefit ( {
109+ coverage,
110+ code,
111+ coverageCode,
112+ levelCode,
113+ periodCode,
114+ } : {
115+ coverage : PatientPaymentBenefit [ ] ;
116+ code : string ;
117+ coverageCode : string ;
118+ levelCode : string ;
119+ periodCode : string ;
120+ } ) : number | undefined {
121+ return coverage ?. find (
122+ ( item ) =>
123+ item . code === code &&
124+ item . coverageCode === coverageCode &&
125+ item . levelCode === levelCode &&
126+ item . periodCode === periodCode
127+ ) ?. amountInUSD ;
128+ }
129+
91130 const payments = paymentData ?. payments ?? [ ] ; // Replace with actual payments when available
92131
93132 const stripeCustomerDeletedError =
@@ -233,6 +272,33 @@ export default function PatientPaymentList({
233272 return null ;
234273 } ) ( ) ;
235274
275+ const insurance = insuranceCoverages ?. coverages ?. primary ?. identifier ?. find (
276+ ( temp ) => temp . type ?. coding ?. find ( ( temp ) => temp . code === 'MB' )
277+ ) ?. assigner ;
278+ const insuranceOrganization = insuranceCoverages ?. insuranceOrgs ?. find (
279+ ( organization ) => organization . id === insurance ?. reference ?. replace ( 'Organization/' , '' )
280+ ) ;
281+ const insuranceName = insuranceOrganization ?. name ;
282+ const insuranceNotes = insuranceOrganization ?. extension ?. find (
283+ ( extensionTemp ) => extensionTemp . url === FHIR_EXTENSION . InsurancePlan . notes . url
284+ ) ?. valueString ;
285+
286+ const copayAmount = getPaymentAmountFromPatientBenefit ( {
287+ coverage : insuranceData ?. coverageChecks ?. [ 0 ] ?. copay || [ ] ,
288+ code : 'UC' ,
289+ coverageCode : 'B' ,
290+ levelCode : 'IND' ,
291+ periodCode : '27' ,
292+ } ) ;
293+
294+ const remainingDeductibleAmount = getPaymentAmountFromPatientBenefit ( {
295+ coverage : insuranceData ?. coverageChecks ?. [ 0 ] ?. deductible || [ ] ,
296+ code : '30' ,
297+ coverageCode : 'C' ,
298+ levelCode : 'IND' ,
299+ periodCode : '29' ,
300+ } ) ;
301+
236302 return (
237303 < Paper
238304 sx = { {
@@ -269,6 +335,64 @@ export default function PatientPaymentList({
269335 label = "Self-pay"
270336 />
271337 </ RadioGroup >
338+ < Container
339+ style = { {
340+ backgroundColor : theme . palette . background . default ,
341+ borderRadius : 4 ,
342+ paddingTop : 10 ,
343+ paddingBottom : 10 ,
344+ } }
345+ >
346+ < Typography variant = "h5" sx = { { color : theme . palette . primary . dark } } >
347+ Payment Considerations
348+ </ Typography >
349+ { insuranceData ? (
350+ < >
351+ < Table style = { { tableLayout : 'fixed' } } >
352+ < TableBody >
353+ < TableRow >
354+ < TableCell style = { { fontSize : '16px' } } > Insurance Carrier</ TableCell >
355+ < TableCell style = { { fontSize : '16px' , fontWeight : 'bold' , textAlign : 'right' } } >
356+ { insuranceName ? insuranceName : 'Unknown' }
357+ </ TableCell >
358+ </ TableRow >
359+ < TableRow >
360+ < TableCell style = { { fontSize : '16px' } } > Copay</ TableCell >
361+ < TableCell style = { { fontSize : '16px' , fontWeight : 'bold' , textAlign : 'right' } } >
362+ { copayAmount ? `$${ copayAmount } ` : 'Unknown' }
363+ </ TableCell >
364+ </ TableRow >
365+ < TableRow sx = { { '&:last-child td' : { borderBottom : 'none' } } } >
366+ < TableCell style = { { fontSize : '16px' } } > Remaining Deductible</ TableCell >
367+ < TableCell style = { { fontSize : '16px' , fontWeight : 'bold' , textAlign : 'right' } } >
368+ { remainingDeductibleAmount ? `$${ remainingDeductibleAmount } ` : 'Unknown' }
369+ </ TableCell >
370+ </ TableRow >
371+ </ TableBody >
372+ </ Table >
373+ { insuranceNotes && (
374+ < Container
375+ style = { {
376+ backgroundColor : '#2169F514' ,
377+ borderRadius : 4 ,
378+ marginTop : 5 ,
379+ paddingTop : 10 ,
380+ paddingBottom : 10 ,
381+ } }
382+ >
383+ < Typography variant = "body1" sx = { { color : theme . palette . primary . dark , fontWeight : 'bold' } } >
384+ Notes
385+ </ Typography >
386+ < Typography variant = "body1" style = { { whiteSpace : 'pre' } } >
387+ { insuranceNotes }
388+ </ Typography >
389+ </ Container >
390+ ) }
391+ </ >
392+ ) : (
393+ < CircularProgress />
394+ ) }
395+ </ Container >
272396 { stripeCustomerDeletedError && < StripeErrorAlert /> }
273397 { ! stripeCustomerDeletedError && (
274398 < >
0 commit comments