@openmrs/esm-billing-app 1.0.2-pre.811 → 1.0.2-pre.814

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,3 @@
1
- import { useContext } from 'react';
2
- import dayjs from 'dayjs';
3
1
  import isEmpty from 'lodash-es/isEmpty';
4
2
  import sortBy from 'lodash-es/sortBy';
5
3
  import useSWR from 'swr';
@@ -12,29 +10,31 @@ import {
12
10
  type SessionLocation,
13
11
  useOpenmrsFetchAll,
14
12
  } from '@openmrs/esm-framework';
15
- import { apiBasePath, omrsDateFormat } from './constants';
16
- import type { MappedBill, PatientInvoice, BillableItem } from './types';
17
- import SelectedDateContext from './hooks/selectedDateContext';
13
+ import { apiBasePath } from './constants';
14
+ import type {
15
+ MappedBill,
16
+ PatientInvoice,
17
+ BillableItem,
18
+ BillPaymentPayload,
19
+ CreateBillPayload,
20
+ UpdateBillPayload,
21
+ } from './types';
22
+
23
+ const mapBillProperties = (bill: PatientInvoice): MappedBill => {
24
+ const status =
25
+ bill.lineItems.length > 1
26
+ ? bill.lineItems.some((item) => item.paymentStatus === 'PENDING')
27
+ ? 'PENDING'
28
+ : 'PAID'
29
+ : bill.status;
18
30
 
19
- export const useBills = (patientUuid: string = '', billStatus: string = '') => {
20
- const { selectedDate } = useContext(SelectedDateContext);
21
- const endDate = dayjs().endOf('day').format(omrsDateFormat);
22
- const url = `${apiBasePath}bill?q=&v=full`;
23
-
24
- const patientUrl = `${apiBasePath}bill?patientUuid=${patientUuid}&v=full`;
25
-
26
- const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: { results: Array<PatientInvoice> } }>(
27
- isEmpty(patientUuid) ? url : patientUrl,
28
- openmrsFetch,
29
- );
30
-
31
- const mapBillProperties = (bill: PatientInvoice): MappedBill => ({
31
+ return {
32
32
  id: bill?.id,
33
33
  uuid: bill?.uuid,
34
34
  patientName: bill?.patient?.display.split('-')?.[1],
35
35
  identifier: bill?.patient?.display.split('-')?.[0],
36
36
  patientUuid: bill?.patient?.uuid,
37
- status: bill.lineItems.some((item) => item.paymentStatus === 'PENDING') ? 'PENDING' : 'PAID',
37
+ status,
38
38
  receiptNumber: bill?.receiptNumber,
39
39
  cashier: bill?.cashier,
40
40
  cashPointUuid: bill?.cashPoint?.uuid,
@@ -42,11 +42,23 @@ export const useBills = (patientUuid: string = '', billStatus: string = '') => {
42
42
  cashPointLocation: bill?.cashPoint?.location?.display,
43
43
  dateCreated: bill?.dateCreated ? formatDate(parseDate(bill.dateCreated), { mode: 'wide' }) : '--',
44
44
  lineItems: bill?.lineItems,
45
- billingService: bill?.lineItems.map((bill) => bill?.item || bill?.billableService || '--').join(' '),
46
- payments: bill?.payments,
45
+ billingService: bill?.lineItems.map((lineItem) => lineItem?.item || lineItem?.billableService || '--').join(' '),
46
+ payments: bill.payments,
47
47
  display: bill?.display,
48
48
  totalAmount: bill?.lineItems?.map((item) => item.price * item.quantity).reduce((prev, curr) => prev + curr, 0),
49
- });
49
+ tenderedAmount: bill?.payments?.map((item) => item.amountTendered).reduce((prev, curr) => prev + curr, 0),
50
+ };
51
+ };
52
+
53
+ export const useBills = (patientUuid: string = '', billStatus: string = '') => {
54
+ const url = `${apiBasePath}bill?q=&v=full`;
55
+
56
+ const patientUrl = `${apiBasePath}bill?patientUuid=${patientUuid}&v=full`;
57
+
58
+ const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: { results: Array<PatientInvoice> } }>(
59
+ isEmpty(patientUuid) ? url : patientUrl,
60
+ openmrsFetch,
61
+ );
50
62
 
51
63
  const sortedBills = sortBy(data?.data?.results ?? [], ['dateCreated']).reverse();
52
64
  const filteredBills = billStatus === '' ? sortedBills : sortedBills?.filter((bill) => bill?.status === billStatus);
@@ -68,31 +80,6 @@ export const useBill = (billUuid: string) => {
68
80
  openmrsFetch,
69
81
  );
70
82
 
71
- const mapBillProperties = (bill: PatientInvoice): MappedBill => ({
72
- id: bill?.id,
73
- uuid: bill?.uuid,
74
- patientName: bill?.patient?.display.split('-')?.[1],
75
- identifier: bill?.patient?.display.split('-')?.[0],
76
- patientUuid: bill?.patient?.uuid,
77
- status:
78
- bill.lineItems.length > 1
79
- ? bill.lineItems.some((item) => item.paymentStatus === 'PENDING')
80
- ? 'PENDING'
81
- : 'PAID'
82
- : bill.status,
83
- receiptNumber: bill?.receiptNumber,
84
- cashier: bill?.cashier,
85
- cashPointUuid: bill?.cashPoint?.uuid,
86
- cashPointName: bill?.cashPoint?.name,
87
- cashPointLocation: bill?.cashPoint?.location?.display,
88
- dateCreated: bill?.dateCreated ? formatDate(parseDate(bill.dateCreated), { mode: 'wide' }) : '--',
89
- lineItems: bill?.lineItems,
90
- billingService: bill?.lineItems.map((bill) => bill.item).join(' '),
91
- payments: bill.payments,
92
- totalAmount: bill?.lineItems?.map((item) => item.price * item.quantity).reduce((prev, curr) => prev + curr, 0),
93
- tenderedAmount: bill?.payments?.map((item) => item.amountTendered).reduce((prev, curr) => prev + curr, 0),
94
- });
95
-
96
83
  const formattedBill = data?.data ? mapBillProperties(data?.data) : null;
97
84
 
98
85
  return {
@@ -104,7 +91,7 @@ export const useBill = (billUuid: string) => {
104
91
  };
105
92
  };
106
93
 
107
- export const processBillPayment = (payload, billUuid: string) => {
94
+ export const processBillPayment = (payload: BillPaymentPayload, billUuid: string) => {
108
95
  const url = `${apiBasePath}bill/${billUuid}`;
109
96
 
110
97
  return openmrsFetch(url, {
@@ -139,7 +126,7 @@ export function useBillableServices() {
139
126
  return useOpenmrsFetchAll<BillableItem>(url);
140
127
  }
141
128
 
142
- export const processBillItems = (payload) => {
129
+ export const processBillItems = (payload: CreateBillPayload) => {
143
130
  const url = `${apiBasePath}bill`;
144
131
  return openmrsFetch(url, {
145
132
  method: 'POST',
@@ -150,7 +137,7 @@ export const processBillItems = (payload) => {
150
137
  });
151
138
  };
152
139
 
153
- export const updateBillItems = (payload) => {
140
+ export const updateBillItems = (payload: UpdateBillPayload) => {
154
141
  const url = `${apiBasePath}bill/${payload.uuid}`;
155
142
  return openmrsFetch(url, {
156
143
  method: 'POST',
@@ -1,4 +1,4 @@
1
- import { type MappedBill } from '../../types';
1
+ import { type MappedBill, type BillableService } from '../../types';
2
2
  import { type Payment } from './payments.component';
3
3
 
4
4
  export const createPaymentPayload = (
@@ -6,7 +6,7 @@ export const createPaymentPayload = (
6
6
  patientUuid: string,
7
7
  formValues: Array<Payment>,
8
8
  amountDue: number,
9
- billableServices: Array<any>,
9
+ billableServices: Array<BillableService>,
10
10
  ) => {
11
11
  const { cashier } = bill;
12
12
  const totalAmount = bill.totalAmount ?? 0;
@@ -48,7 +48,13 @@ export const createPaymentPayload = (
48
48
  return processedPayment;
49
49
  };
50
50
 
51
- export const getBillableServiceUuid = (billableServices: Array<any>, serviceName: string) => {
52
- return billableServices.length ? billableServices.find((service) => service.name === serviceName).uuid : null;
51
+ export const getBillableServiceUuid = (billableServices: Array<BillableService>, serviceName: string) => {
52
+ if (!billableServices.length) {
53
+ return null;
54
+ }
55
+ const service = billableServices.find((service) => service.name === serviceName);
56
+ return service?.uuid ?? null;
53
57
  };
54
- const processBillItem = (item) => (item.item || item.billableService)?.split(':')[0];
58
+
59
+ const processBillItem = (item: { item?: string; billableService?: string }) =>
60
+ (item.item || item.billableService)?.split(':')[0];
@@ -1,3 +1,5 @@
1
+ import { type OpenmrsResource } from '@openmrs/esm-framework';
2
+
1
3
  export interface MappedBill {
2
4
  uuid: string;
3
5
  id: number;
@@ -121,13 +123,21 @@ export interface Payment {
121
123
  resourceVersion: string;
122
124
  }
123
125
 
126
+ export type PaymentPayload = {
127
+ amount: number;
128
+ amountTendered: number;
129
+ attributes: Array<Attribute>;
130
+ instanceType: string;
131
+ dateCreated?: Date | number;
132
+ };
133
+
124
134
  export interface PatientInvoice {
125
135
  uuid: string;
126
136
  display: string;
127
137
  voided: boolean;
128
138
  voidReason: string | null;
129
- adjustedBy: any[];
130
- billAdjusted: any;
139
+ adjustedBy: Array<OpenmrsResource>;
140
+ billAdjusted: OpenmrsResource | null;
131
141
  cashPoint: CashPoint;
132
142
  cashier: Provider;
133
143
  dateCreated: string;
@@ -136,7 +146,7 @@ export interface PatientInvoice {
136
146
  payments: Payment[];
137
147
  receiptNumber: string;
138
148
  status: string;
139
- adjustmentReason: any;
149
+ adjustmentReason: string | null;
140
150
  id: number;
141
151
  resourceVersion: string;
142
152
  }
@@ -156,7 +166,7 @@ export interface FacilityDetail {
156
166
  }
157
167
 
158
168
  export type ServiceConcept = {
159
- uuid: any;
169
+ uuid: string;
160
170
  concept: {
161
171
  uuid: string;
162
172
  display: string;
@@ -203,3 +213,46 @@ export interface BillableService {
203
213
  concept?: ServiceConcept;
204
214
  servicePrices: Array<ServicePrice>;
205
215
  }
216
+
217
+ export type BillPaymentPayload = {
218
+ cashPoint: string;
219
+ cashier: string;
220
+ lineItems: Array<LineItem>;
221
+ payments: Array<PaymentPayload>;
222
+ patient: string;
223
+ status?: string;
224
+ };
225
+
226
+ export type CreateBillPayload = {
227
+ cashPoint: string;
228
+ cashier: string;
229
+ lineItems: Array<LineItem>;
230
+ payments: Array<PaymentPayload>;
231
+ patient: string;
232
+ status: string;
233
+ };
234
+
235
+ export type UpdateBillPayload = {
236
+ cashPoint: string;
237
+ cashier: string;
238
+ lineItems: Array<LineItem>;
239
+ patient: string;
240
+ status: string;
241
+ uuid: string;
242
+ payments?: Array<PaymentPayload>;
243
+ };
244
+
245
+ export type CreateBillableServicePayload = {
246
+ name: string;
247
+ shortName: string;
248
+ serviceStatus: string;
249
+ serviceType?: string;
250
+ concept?: string;
251
+ servicePrices: Array<{
252
+ name: string;
253
+ price: number;
254
+ paymentMode: string;
255
+ }>;
256
+ };
257
+
258
+ export type UpdateBillableServicePayload = Partial<CreateBillableServicePayload>;