@palladium-ethiopia/esm-clinical-workflow-app 5.4.2-pre.34 → 5.4.2-pre.35

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.
Files changed (27) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/dist/164.js +1 -1
  3. package/dist/164.js.map +1 -1
  4. package/dist/{160.js → 693.js} +1 -1
  5. package/dist/693.js.map +1 -0
  6. package/dist/ethiopia-esm-clinical-workflow-app.js +1 -1
  7. package/dist/ethiopia-esm-clinical-workflow-app.js.buildmanifest.json +28 -28
  8. package/dist/main.js +4 -4
  9. package/dist/main.js.map +1 -1
  10. package/dist/routes.json +1 -1
  11. package/package.json +1 -1
  12. package/src/config-schema.ts +2 -0
  13. package/src/mru/billing-information/billing-information.resource.ts +60 -59
  14. package/src/mru/billing-information/billing-information.scss +21 -3
  15. package/src/mru/billing-information/billing-information.workspace.tsx +106 -252
  16. package/src/mru/billing-information/components/BillingTypeAttributes.tsx +106 -0
  17. package/src/mru/billing-information/components/CreditSubTypeFields.tsx +145 -0
  18. package/src/mru/billing-information/components/CreditSubTypeSelection.tsx +66 -0
  19. package/src/mru/billing-information/components/FreeSubTypeFields.tsx +7 -0
  20. package/src/mru/billing-information/components/FreeSubTypeSelection.tsx +61 -0
  21. package/src/mru/billing-information/components/index.ts +5 -0
  22. package/src/mru/billing-information/hooks/index.ts +4 -0
  23. package/src/mru/billing-information/hooks/useBillingForm.ts +22 -0
  24. package/src/mru/billing-information/hooks/useBillingType.ts +18 -0
  25. package/src/mru/billing-information/hooks/useCreditCompanies.ts +17 -0
  26. package/src/mru/billing-information/hooks/usePaymentModes.ts +17 -0
  27. package/dist/160.js.map +0 -1
package/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"pages":[],"extensions":[{"name":"clinical-workflow-triage-dashboard-link","component":"triageDashboardLink","slot":"homepage-dashboard-slot","order":0,"meta":{"name":"clinical-workflow-triage","slot":"clinical-workflow-triage-dashboard-slot","title":"clinical-workflow-triage"}},{"name":"clinical-workflow-triage-dashboard","component":"triageDashboard","slot":"clinical-workflow-triage-dashboard-slot"},{"name":"ewf-mru-dashboard-link","component":"mruLeftPanelLink","slot":"homepage-dashboard-slot","order":1,"meta":{"name":"mru","title":"MRU","path":"mru","slot":"mru-dashboard-slot"}},{"name":"ewf-mru-dashboard","component":"mruDashboard","slot":"mru-dashboard-slot","online":true,"offline":false},{"name":"patient-scoreboard-link","component":"patientScoreboardLink","slot":"homepage-dashboard-slot","order":1,"meta":{"name":"patient-scoreboard","title":"Patient Scoreboard","path":"patient-scoreboard","slot":"patient-scoreboard-slot"}},{"name":"patient-scoreboard","component":"patientScoreboard","slot":"patient-scoreboard-slot","online":true,"offline":false},{"name":"past-visits-detail-overview-shadow","slot":"patient-chart-encounters-dashboard-slot","component":"pastVisitsDetailOverviewShadow","order":0,"meta":{"title":"Visits","view":"visits"},"online":true,"offline":true},{"name":"queue-table-transfer-column","component":"queueTableTransferColumn","slot":"queue-table-transfer-status-slot"},{"name":"transfer-notes-overview-widget","component":"transferNotesOverview","slot":"patient-chart-summary-dashboard-slot","meta":{"fullWidth":false},"order":6}],"workspaces":[{"name":"triage-workspace","component":"triageWorkspace","title":"Triage Form","canMaximize":true,"type":"clinical-form"},{"name":"patient-registration-workspace","component":"patientRegistrationWorkspace","title":"Patient Registration","canMaximize":true,"type":"registration-form"},{"name":"billing-information-workspace","component":"billingInformationWorkspace","title":"Billing Information Workspace","type":"clinical-form"}],"workspaces2":[{"name":"clinical-workflow-patient-form-entry-workspace","component":"@openmrs/esm-patient-forms-app#exportedPatientFormEntryWorkspace","window":"clinical-workflow-window"},{"name":"patient-transfer-form-entry-workspace","component":"@openmrs/esm-patient-forms-app#exportedPatientFormEntryWorkspace","window":"patient-transfer"},{"name":"visit-notes-form-shadow-workspace","component":"visitNotesFormWorkspace","window":"visit-note-shadow"}],"workspaceWindows2":[{"name":"clinical-workflow-window","group":"clinical-workflow-group","width":"wider","canMaximize":true},{"name":"visit-note-shadow","group":"patient-chart","icon":"visitNoteActionButton","order":3},{"name":"patient-transfer","group":"patient-chart","icon":"patientTransferActionButton","order":4,"width":"wider","canMaximize":true}],"workspaceGroups2":[{"name":"clinical-workflow-group","overlay":true,"persistence":"closable"}],"modals":[{"name":"confirm-transfer-dialog","component":"confirmTransferDialog"},{"name":"patient-transfer-details-modal","component":"patientTransferDetailsModal"}],"version":"5.4.2-pre.34"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"pages":[],"extensions":[{"name":"clinical-workflow-triage-dashboard-link","component":"triageDashboardLink","slot":"homepage-dashboard-slot","order":0,"meta":{"name":"clinical-workflow-triage","slot":"clinical-workflow-triage-dashboard-slot","title":"clinical-workflow-triage"}},{"name":"clinical-workflow-triage-dashboard","component":"triageDashboard","slot":"clinical-workflow-triage-dashboard-slot"},{"name":"ewf-mru-dashboard-link","component":"mruLeftPanelLink","slot":"homepage-dashboard-slot","order":1,"meta":{"name":"mru","title":"MRU","path":"mru","slot":"mru-dashboard-slot"}},{"name":"ewf-mru-dashboard","component":"mruDashboard","slot":"mru-dashboard-slot","online":true,"offline":false},{"name":"patient-scoreboard-link","component":"patientScoreboardLink","slot":"homepage-dashboard-slot","order":1,"meta":{"name":"patient-scoreboard","title":"Patient Scoreboard","path":"patient-scoreboard","slot":"patient-scoreboard-slot"}},{"name":"patient-scoreboard","component":"patientScoreboard","slot":"patient-scoreboard-slot","online":true,"offline":false},{"name":"past-visits-detail-overview-shadow","slot":"patient-chart-encounters-dashboard-slot","component":"pastVisitsDetailOverviewShadow","order":0,"meta":{"title":"Visits","view":"visits"},"online":true,"offline":true},{"name":"queue-table-transfer-column","component":"queueTableTransferColumn","slot":"queue-table-transfer-status-slot"},{"name":"transfer-notes-overview-widget","component":"transferNotesOverview","slot":"patient-chart-summary-dashboard-slot","meta":{"fullWidth":false},"order":6}],"workspaces":[{"name":"triage-workspace","component":"triageWorkspace","title":"Triage Form","canMaximize":true,"type":"clinical-form"},{"name":"patient-registration-workspace","component":"patientRegistrationWorkspace","title":"Patient Registration","canMaximize":true,"type":"registration-form"},{"name":"billing-information-workspace","component":"billingInformationWorkspace","title":"Billing Information Workspace","type":"clinical-form"}],"workspaces2":[{"name":"clinical-workflow-patient-form-entry-workspace","component":"@openmrs/esm-patient-forms-app#exportedPatientFormEntryWorkspace","window":"clinical-workflow-window"},{"name":"patient-transfer-form-entry-workspace","component":"@openmrs/esm-patient-forms-app#exportedPatientFormEntryWorkspace","window":"patient-transfer"},{"name":"visit-notes-form-shadow-workspace","component":"visitNotesFormWorkspace","window":"visit-note-shadow"}],"workspaceWindows2":[{"name":"clinical-workflow-window","group":"clinical-workflow-group","width":"wider","canMaximize":true},{"name":"visit-note-shadow","group":"patient-chart","icon":"visitNoteActionButton","order":3},{"name":"patient-transfer","group":"patient-chart","icon":"patientTransferActionButton","order":4,"width":"wider","canMaximize":true}],"workspaceGroups2":[{"name":"clinical-workflow-group","overlay":true,"persistence":"closable"}],"modals":[{"name":"confirm-transfer-dialog","component":"confirmTransferDialog"},{"name":"patient-transfer-details-modal","component":"patientTransferDetailsModal"}],"version":"5.4.2-pre.35"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palladium-ethiopia/esm-clinical-workflow-app",
3
- "version": "5.4.2-pre.34",
3
+ "version": "5.4.2-pre.35",
4
4
  "description": "Express workflow app for OpenMRS 3",
5
5
  "keywords": [
6
6
  "openmrs",
@@ -25,6 +25,7 @@ export const configSchema = {
25
25
  creditType: '5cd1eb62-e006-4146-bd22-80bc4d5bd2f7',
26
26
  creditTypeDetails: 'd824aa96-d2c7-4a52-aa8d-03f60a516083',
27
27
  freeType: '7523ecfe-b8f1-4e7f-80a7-1a495b15ace4',
28
+ paymentAttributesSummary: '3cc0102e-6c1f-41db-af72-4be6aa9eb27a',
28
29
  },
29
30
  },
30
31
  visitTypeUuid: {
@@ -125,6 +126,7 @@ export type ClinicalWorkflowConfig = {
125
126
  creditType: string;
126
127
  creditTypeDetails: string;
127
128
  freeType: string;
129
+ paymentAttributesSummary: string;
128
130
  };
129
131
  visitTypeUuid: string;
130
132
  identifierSourceUuid: string;
@@ -3,59 +3,45 @@ import { z } from 'zod';
3
3
  // Create the billing form schema factory with conditional validation based on skip logic
4
4
  import type { TFunction } from 'i18next';
5
5
 
6
- export const createBillingFormSchema = (t: TFunction) => {
6
+ export const createBillingFormSchema = (
7
+ t: TFunction,
8
+ billingTypes?: Array<{ uuid: string; name?: string; attributeTypes?: Array<{ uuid: string; required?: boolean }> }>,
9
+ ) => {
7
10
  return z
8
11
  .object({
9
- billingType: z.enum(['credit', 'free', 'cash']).optional(),
10
- creditType: z.string().optional(),
11
- name: z.string().optional(),
12
- code: z.string().optional(),
13
- id: z.string().optional(),
14
- expiryDate: z.string().optional(),
15
- zone: z.string().optional(),
16
- freeType: z.string().optional(),
12
+ billingTypeUuid: z.string().optional(),
13
+ creditSubType: z.string().optional(),
14
+ freeSubType: z.string().optional(),
15
+ attributes: z.record(z.string(), z.any()).optional(),
17
16
  })
18
17
  .superRefine((data, ctx) => {
19
18
  // Billing type is required on submit
20
- if (!data.billingType) {
19
+ if (!data.billingTypeUuid) {
21
20
  ctx.addIssue({
22
21
  code: z.ZodIssueCode.custom,
23
22
  message: t('billingTypeRequired', 'Billing type is required'),
24
- path: ['billingType'],
23
+ path: ['billingTypeUuid'],
25
24
  });
26
25
  return;
27
26
  }
28
27
 
29
- // Credit billing type validation
30
- if (data.billingType === 'credit') {
31
- // Credit type is required
32
- if (!data.creditType || data.creditType.trim() === '') {
33
- ctx.addIssue({
34
- code: z.ZodIssueCode.custom,
35
- message: t('creditTypeRequired', 'Credit type is required'),
36
- path: ['creditType'],
37
- });
38
- }
39
-
40
- // If creditType is insurance, require additional fields
41
- if (data.creditType === 'insurance') {
42
- if (!data.id || data.id.trim() === '') {
43
- ctx.addIssue({
44
- code: z.ZodIssueCode.custom,
45
- message: t('idRequired', 'ID is required'),
46
- path: ['id'],
47
- });
48
- }
49
- }
50
- }
51
-
52
- // Free billing type validation
53
- if (data.billingType === 'free') {
54
- if (!data.freeType || data.freeType.trim() === '') {
55
- ctx.addIssue({
56
- code: z.ZodIssueCode.custom,
57
- message: t('freeTypeRequired', 'Free type is required'),
58
- path: ['freeType'],
28
+ // Validate required attributes for the selected billing type
29
+ if (billingTypes && data.billingTypeUuid) {
30
+ const selectedBillingType = billingTypes.find((bt) => bt.uuid === data.billingTypeUuid);
31
+ if (selectedBillingType?.attributeTypes) {
32
+ selectedBillingType.attributeTypes.forEach((attrType) => {
33
+ if (attrType.required) {
34
+ const attrValue = data.attributes?.[attrType.uuid];
35
+ if (!attrValue || (typeof attrValue === 'string' && attrValue.trim() === '')) {
36
+ ctx.addIssue({
37
+ code: z.ZodIssueCode.custom,
38
+ message: t('attributeRequired', '{{attributeName}} is required', {
39
+ attributeName: attrType.uuid,
40
+ }),
41
+ path: ['attributes', attrType.uuid],
42
+ });
43
+ }
44
+ }
59
45
  });
60
46
  }
61
47
  }
@@ -98,33 +84,48 @@ export const createBillingInformationVisitAttribute = (
98
84
  billingFormData: BillingFormData,
99
85
  visitAttributeTypeUuidsMap: {
100
86
  paymentMethod: string;
101
- creditType: string;
102
- creditTypeDetails: string;
103
- freeType: string;
87
+ paymentAttributesSummary?: string;
104
88
  },
105
89
  ) => {
106
- const { billingType, creditType, name, code, id, expiryDate, zone, freeType } = billingFormData;
90
+ const { billingTypeUuid, attributes } = billingFormData;
107
91
 
108
- const formObject = {
109
- paymentMethod: billingType,
110
- creditType: creditType,
111
- creditTypeDetails: {
112
- name: name,
113
- code: code,
114
- id: id,
115
- expiryDate: expiryDate,
116
- zone: zone,
117
- },
118
- freeType: freeType,
119
- };
92
+ const visitAttributePayload: Array<{ attributeType: { uuid: string } | string; value: string }> = [];
93
+
94
+ // Add billing method
95
+ if (billingTypeUuid && visitAttributeTypeUuidsMap.paymentMethod) {
96
+ visitAttributePayload.push({
97
+ attributeType: visitAttributeTypeUuidsMap.paymentMethod,
98
+ value: billingTypeUuid,
99
+ });
100
+ }
101
+
102
+ // Save sub attributes (from attributes object) as a stringified object under the paymentAttributesSummary key
103
+ // Format: {attributeUuid: value}
104
+ // Only includes sub attributes, not the main paymentMethod attribute
105
+ if (visitAttributeTypeUuidsMap.paymentAttributesSummary && attributes) {
106
+ const paymentAttributesObject: Record<string, any> = {};
107
+
108
+ // Add sub attributes from the attributes object using their UUIDs as keys
109
+ Object.entries(attributes).forEach(([attrTypeUuid, value]) => {
110
+ if (value !== undefined && value !== null && value !== '') {
111
+ paymentAttributesObject[attrTypeUuid] = value;
112
+ }
113
+ });
120
114
 
121
- const visitAttributePayload = transformFormObjectToVisitAttributes(formObject, visitAttributeTypeUuidsMap);
115
+ // Only add the summary if there are sub attributes to save
116
+ if (Object.keys(paymentAttributesObject).length > 0) {
117
+ visitAttributePayload.push({
118
+ attributeType: visitAttributeTypeUuidsMap.paymentAttributesSummary,
119
+ value: JSON.stringify(paymentAttributesObject),
120
+ });
121
+ }
122
+ }
122
123
 
123
124
  return visitAttributePayload;
124
125
  };
125
126
 
126
127
  export const updateVisitWithBillingInformation = (
127
- visitAttributePayload: Array<{ attributeType: string; value: string }>,
128
+ visitAttributePayload: Array<{ attributeType: { uuid: string } | string; value: string }>,
128
129
  visitUuid: string,
129
130
  ) => {
130
131
  return openmrsFetch(`${restBaseUrl}/visit/${visitUuid}`, {
@@ -24,18 +24,35 @@
24
24
 
25
25
  .billingInformationContainer {
26
26
  margin: spacing.$spacing-05;
27
+ overflow-y: visible;
27
28
  height: 100%;
28
- overflow-y: auto;
29
+ border: solid red 1px;
29
30
  }
30
31
 
32
+ .paymentTypeSwitcher {
33
+ display: flex;
34
+ flex-direction: row;
35
+ justify-content: space-evenly;
36
+ // flex-wrap: wrap;
37
+ border: none;
38
+ outline: none;
39
+ padding: 2px;
40
+ }
41
+
42
+ // .paymentTypeSwitch {
43
+ // margin-bottom: spacing.$spacing-03;
44
+ // border: solid #a6c8ff;
45
+ // }
46
+
31
47
  .creditDetailsContainer {
32
48
  display: flex;
33
49
  flex-direction: column;
34
50
  gap: spacing.$spacing-05;
35
51
  margin-top: spacing.$spacing-03;
36
- min-height: 45rem;
52
+ height: auto;
37
53
  border: 1px solid colors.$gray-20;
38
54
  padding: spacing.$spacing-03;
55
+ overflow: visible;
39
56
  }
40
57
 
41
58
  .freeDetailsContainer {
@@ -43,9 +60,10 @@
43
60
  flex-direction: column;
44
61
  gap: spacing.$spacing-05;
45
62
  margin-top: spacing.$spacing-03;
46
- min-height: 20rem;
63
+ height: auto;
47
64
  border: 1px solid colors.$gray-20;
48
65
  padding: spacing.$spacing-03;
66
+ overflow: visible;
49
67
  }
50
68
 
51
69
  .creditTypeDetailsContainer {
@@ -1,37 +1,29 @@
1
- import React, { useEffect, useMemo } from 'react';
2
- import {
3
- Button,
4
- ButtonSet,
5
- InlineLoading,
6
- ContentSwitcher,
7
- Dropdown,
8
- Switch,
9
- TextInput,
10
- Form,
11
- FormGroup,
12
- } from '@carbon/react';
1
+ import React, { useEffect } from 'react';
2
+ import { Button, ButtonSet, InlineLoading, ContentSwitcher, Switch, Form } from '@carbon/react';
13
3
  import {
14
4
  DefaultWorkspaceProps,
15
5
  ExtensionSlot,
16
6
  usePatient,
17
- OpenmrsDatePicker,
18
7
  useConfig,
19
8
  useVisit,
20
9
  showSnackbar,
21
10
  } from '@openmrs/esm-framework';
22
11
  import { useTranslation } from 'react-i18next';
23
- import type { TFunction } from 'i18next';
24
-
25
- import { useForm, Controller, Control, FieldErrors, useWatch } from 'react-hook-form';
26
- import { zodResolver } from '@hookform/resolvers/zod';
27
12
 
28
13
  import {
29
14
  type BillingFormData,
30
- createBillingFormSchema,
31
15
  createBillingInformationVisitAttribute,
32
16
  updateVisitWithBillingInformation,
33
17
  } from './billing-information.resource';
34
18
  import type { ClinicalWorkflowConfig } from '../../config-schema';
19
+ import { usePaymentModes, useCreditCompanies, useBillingForm, useBillingType } from './hooks';
20
+ import {
21
+ BillingTypeAttributes,
22
+ CreditSubTypeSelection,
23
+ FreeSubTypeSelection,
24
+ CreditSubTypeFields,
25
+ FreeSubTypeFields,
26
+ } from './components';
35
27
  import styles from './billing-information.scss';
36
28
 
37
29
  type BillingInformationWorkspaceProps = DefaultWorkspaceProps & {
@@ -48,30 +40,30 @@ const BillingInformationWorkspace: React.FC<BillingInformationWorkspaceProps> =
48
40
  const { patient, isLoading } = usePatient(patientUuid);
49
41
  const { activeVisit, mutate: mutateVisit } = useVisit(patientUuid);
50
42
  const { billingVisitAttributeTypes } = useConfig<ClinicalWorkflowConfig>();
51
- const billingFormSchema = useMemo(() => createBillingFormSchema(t), [t]);
52
43
 
44
+ // Custom hooks for data fetching
45
+ const { billingTypes } = usePaymentModes();
46
+
47
+ // Form management hook
53
48
  const {
54
49
  control,
55
50
  handleSubmit,
56
51
  watch,
57
52
  setValue,
58
53
  formState: { errors, isDirty },
59
- } = useForm<BillingFormData>({
60
- resolver: zodResolver(billingFormSchema),
61
- mode: 'onTouched',
62
- defaultValues: {
63
- billingType: undefined,
64
- creditType: '',
65
- name: '',
66
- code: '',
67
- id: '',
68
- expiryDate: '',
69
- zone: '',
70
- freeType: '',
71
- },
72
- });
54
+ } = useBillingForm(t, billingTypes);
55
+
56
+ // Watch form values
57
+ const billingTypeUuid = watch('billingTypeUuid');
58
+ const creditSubType = watch('creditSubType');
59
+ const freeSubType = watch('freeSubType');
60
+ const attributes = watch('attributes') || {};
61
+
62
+ // Billing type logic hook
63
+ const { selectedBillingType, isCreditType, isFreeType } = useBillingType(billingTypes, billingTypeUuid);
73
64
 
74
- const billingType = watch('billingType');
65
+ // Fetch credit companies conditionally
66
+ const { creditCompanies } = useCreditCompanies(isCreditType && creditSubType === 'creditCompany');
75
67
 
76
68
  const onSubmit = async (data: BillingFormData) => {
77
69
  try {
@@ -101,35 +93,24 @@ const BillingInformationWorkspace: React.FC<BillingInformationWorkspaceProps> =
101
93
  }
102
94
  };
103
95
 
104
- const handleBillingTypeChange = (type: 'credit' | 'free' | 'cash') => {
105
- // Clear form fields to avoid carrying over values from previous billing type
106
- setValue('billingType', type, { shouldDirty: true });
107
- setValue('creditType', '', { shouldDirty: false });
108
- setValue('name', '', { shouldDirty: false });
109
- setValue('code', '', { shouldDirty: false });
110
- setValue('id', '', { shouldDirty: false });
111
- setValue('expiryDate', '', { shouldDirty: false });
112
- setValue('zone', '', { shouldDirty: false });
113
- setValue('freeType', '', { shouldDirty: false });
96
+ const handleBillingTypeChange = (uuid: string) => {
97
+ // Clear attributes and sub-types when changing billing type
98
+ setValue('billingTypeUuid', uuid, { shouldDirty: true });
99
+ setValue('creditSubType', undefined, { shouldDirty: false });
100
+ setValue('freeSubType', undefined, { shouldDirty: false });
101
+ setValue('attributes', {}, { shouldDirty: false });
114
102
  };
115
103
 
116
104
  const getSelectedIndex = () => {
117
- if (billingType === 'cash') {
118
- return 0;
105
+ if (!billingTypeUuid) {
106
+ return -1;
119
107
  }
120
- if (billingType === 'free') {
121
- return 1;
122
- }
123
- if (billingType === 'credit') {
124
- return 2;
125
- }
126
- return -1;
108
+ return billingTypes.findIndex((bt) => bt.uuid === billingTypeUuid);
127
109
  };
128
110
 
129
111
  const handleContentSwitcherChange = ({ index }: { index: number }) => {
130
- const types: ('cash' | 'free' | 'credit')[] = ['cash', 'free', 'credit'];
131
- if (index >= 0 && index < types.length) {
132
- handleBillingTypeChange(types[index]);
112
+ if (index >= 0 && index < billingTypes.length) {
113
+ handleBillingTypeChange(billingTypes[index].uuid);
133
114
  }
134
115
  };
135
116
 
@@ -141,6 +122,8 @@ const BillingInformationWorkspace: React.FC<BillingInformationWorkspaceProps> =
141
122
  return <InlineLoading status="active" iconDescription="Loading" description="Loading billing information..." />;
142
123
  }
143
124
 
125
+ //
126
+
144
127
  return (
145
128
  <>
146
129
  {patient && (
@@ -156,14 +139,75 @@ const BillingInformationWorkspace: React.FC<BillingInformationWorkspaceProps> =
156
139
  <Form onSubmit={handleSubmit(onSubmit)}>
157
140
  <div className={styles.billingInformationContainer}>
158
141
  <p className={styles.sectionTitle}>{t('paymentMethods', 'Payment Methods')}</p>
159
- <ContentSwitcher onChange={handleContentSwitcherChange} selectedIndex={getSelectedIndex()} size="md">
160
- <Switch name="cash" text={t('cash', 'Cash')} />
161
- <Switch name="free" text={t('free', 'Free')} />
162
- <Switch name="credit" text={t('credit', 'Credit')} />
142
+
143
+ <ContentSwitcher
144
+ className={styles.paymentTypeSwitcher}
145
+ onChange={handleContentSwitcherChange}
146
+ selectedIndex={getSelectedIndex()}
147
+ size="md">
148
+ {billingTypes?.map((billingType) => (
149
+ <Switch
150
+ className={styles.paymentTypeSwitch}
151
+ key={billingType.uuid}
152
+ name={billingType.uuid}
153
+ text={billingType.name}
154
+ />
155
+ ))}
163
156
  </ContentSwitcher>
164
157
 
165
- {billingType === 'credit' && <CreditDetails control={control} errors={errors} t={t} />}
166
- {billingType === 'free' && <FreeDetails control={control} errors={errors} t={t} />}
158
+ {/* Credit sub-type selection */}
159
+ {isCreditType && (
160
+ <CreditSubTypeSelection
161
+ control={control}
162
+ errors={errors}
163
+ t={t}
164
+ creditSubType={creditSubType}
165
+ setValue={setValue}
166
+ />
167
+ )}
168
+
169
+ {/* Free sub-type selection */}
170
+ {isFreeType && (
171
+ <FreeSubTypeSelection
172
+ control={control}
173
+ errors={errors}
174
+ t={t}
175
+ freeSubType={freeSubType}
176
+ setValue={setValue}
177
+ />
178
+ )}
179
+
180
+ {/* Conditional fields based on Credit sub-type */}
181
+ {isCreditType && creditSubType && (
182
+ <CreditSubTypeFields
183
+ control={control}
184
+ errors={errors}
185
+ t={t}
186
+ creditSubType={creditSubType}
187
+ creditCompanies={creditCompanies}
188
+ attributes={attributes}
189
+ setValue={setValue}
190
+ />
191
+ )}
192
+
193
+ {/* Conditional fields based on Free sub-type */}
194
+ {isFreeType && freeSubType && <FreeSubTypeFields />}
195
+
196
+ {/* Default attribute types for other billing types */}
197
+ {selectedBillingType &&
198
+ !isCreditType &&
199
+ !isFreeType &&
200
+ selectedBillingType.attributeTypes &&
201
+ selectedBillingType.attributeTypes.length > 0 && (
202
+ <BillingTypeAttributes
203
+ control={control}
204
+ errors={errors}
205
+ t={t}
206
+ attributeTypes={selectedBillingType.attributeTypes}
207
+ attributes={attributes}
208
+ setValue={setValue}
209
+ />
210
+ )}
167
211
  </div>
168
212
  <ButtonSet className={styles.buttonSet}>
169
213
  <Button className={styles.button} kind="secondary" onClick={() => closeWorkspace()}>
@@ -179,193 +223,3 @@ const BillingInformationWorkspace: React.FC<BillingInformationWorkspaceProps> =
179
223
  };
180
224
 
181
225
  export default BillingInformationWorkspace;
182
-
183
- type CreditDetailsProps = {
184
- control: Control<BillingFormData>;
185
- errors: FieldErrors<BillingFormData>;
186
- t: TFunction;
187
- };
188
-
189
- const CreditDetails: React.FC<CreditDetailsProps> = ({ control, errors, t }) => {
190
- const creditType = useWatch({
191
- control,
192
- name: 'creditType',
193
- });
194
-
195
- const creditTypeOptions = [
196
- {
197
- id: 'chbi',
198
- text: t('chbi', 'CHBI'),
199
- },
200
- {
201
- id: 'shi',
202
- text: t('shi', 'SHI'),
203
- },
204
- {
205
- id: 'creditCompanies',
206
- text: t('creditCompanies', 'Credit Companies'),
207
- },
208
- {
209
- id: 'insurance',
210
- text: t('insurance', 'Insurance'),
211
- },
212
- ];
213
-
214
- const showCreditCompanyFields = creditType === 'creditCompanies' || creditType === 'insurance';
215
-
216
- return (
217
- <FormGroup className={styles.creditDetailsContainer} legendText={t('creditDetails', 'Credit Details')}>
218
- <Controller
219
- name="creditType"
220
- control={control}
221
- render={({ field: { onChange, value } }) => (
222
- <Dropdown
223
- id="credit-type"
224
- invalid={!!errors.creditType}
225
- invalidText={errors.creditType?.message || 'invalid selection'}
226
- itemToString={(item) => item?.text ?? ''}
227
- items={creditTypeOptions}
228
- label="Credit"
229
- titleText="Credit"
230
- type="default"
231
- selectedItem={creditTypeOptions.find((item) => item.id === value) || null}
232
- onChange={({ selectedItem }) => onChange(selectedItem?.id || '')}
233
- />
234
- )}
235
- />
236
-
237
- {showCreditCompanyFields && (
238
- <FormGroup
239
- legendText={t('creditTypeDetails', 'Credit Type Details')}
240
- className={styles.creditTypeDetailsContainer}>
241
- <Controller
242
- name="id"
243
- control={control}
244
- render={({ field: { onChange, value } }) => (
245
- <TextInput
246
- id="credit-id"
247
- labelText={t('id', 'ID')}
248
- value={value || ''}
249
- onChange={(e) => onChange(e.target.value)}
250
- placeholder={t('enterId', 'Enter ID')}
251
- invalid={!!errors.id}
252
- invalidText={errors.id?.message}
253
- />
254
- )}
255
- />
256
-
257
- <Controller
258
- name="name"
259
- control={control}
260
- render={({ field: { onChange, value } }) => (
261
- <TextInput
262
- id="credit-name"
263
- labelText={t('name', 'Name')}
264
- value={value || ''}
265
- onChange={(e) => onChange(e.target.value)}
266
- placeholder={t('enterName', 'Enter name')}
267
- invalid={!!errors.name}
268
- invalidText={errors.name?.message}
269
- />
270
- )}
271
- />
272
-
273
- <Controller
274
- name="code"
275
- control={control}
276
- render={({ field: { onChange, value } }) => (
277
- <TextInput
278
- id="credit-code"
279
- labelText={t('code', 'Code')}
280
- value={value || ''}
281
- onChange={(e) => onChange(e.target.value)}
282
- placeholder={t('enterCode', 'Enter code')}
283
- invalid={!!errors.code}
284
- invalidText={errors.code?.message}
285
- />
286
- )}
287
- />
288
-
289
- <Controller
290
- name="expiryDate"
291
- control={control}
292
- render={({ field: { onChange, value } }) => (
293
- <OpenmrsDatePicker
294
- id="credit-expiry-date"
295
- labelText={t('expiryDate', 'Expiry Date')}
296
- minDate={new Date()}
297
- value={value || ''}
298
- onChange={(date) => {
299
- const dateValue = typeof date === 'string' ? date : date.toISOString().split('T')[0];
300
- onChange(dateValue);
301
- }}
302
- />
303
- )}
304
- />
305
- <Controller
306
- name="zone"
307
- control={control}
308
- render={({ field: { onChange, value } }) => (
309
- <TextInput
310
- id="credit-zone"
311
- labelText={t('zone', 'Zone')}
312
- value={value || ''}
313
- onChange={(e) => onChange(e.target.value)}
314
- placeholder={t('enterZone', 'Enter zone')}
315
- invalid={!!errors.zone}
316
- invalidText={errors.zone?.message}
317
- />
318
- )}
319
- />
320
- </FormGroup>
321
- )}
322
- </FormGroup>
323
- );
324
- };
325
-
326
- type FreeDetailsProps = {
327
- control: Control<BillingFormData>;
328
- errors: FieldErrors<BillingFormData>;
329
- t: TFunction;
330
- };
331
-
332
- const FreeDetails: React.FC<FreeDetailsProps> = ({ control, errors, t }) => {
333
- const items = [
334
- {
335
- id: 'staff',
336
- text: t('staff', 'Staff'),
337
- },
338
- {
339
- id: '24Hours',
340
- text: t('24Hours', '24 Hours'),
341
- },
342
- {
343
- id: 'exempted',
344
- text: t('exempted', 'Exempted'),
345
- },
346
- ];
347
-
348
- return (
349
- <FormGroup className={styles.freeDetailsContainer} legendText={t('freeDetails', 'Free Details')}>
350
- <Controller
351
- name="freeType"
352
- control={control}
353
- render={({ field: { onChange, value } }) => (
354
- <Dropdown
355
- id="free-type"
356
- hideLabel={true}
357
- invalid={!!errors.freeType}
358
- invalidText={errors.freeType?.message || 'invalid selection'}
359
- itemToString={(item) => item?.text ?? ''}
360
- items={items}
361
- label={t('selectOption', 'Select a free type')}
362
- titleText={t('selectOption', 'Select a free type')}
363
- type="default"
364
- selectedItem={items.find((item) => item.id === value) || null}
365
- onChange={({ selectedItem }) => onChange(selectedItem?.id || '')}
366
- />
367
- )}
368
- />
369
- </FormGroup>
370
- );
371
- };