Skip to content

Commit

Permalink
O3-2820 Refactor the billing extension on start visit form
Browse files Browse the repository at this point in the history
  • Loading branch information
ODORA0 committed Feb 7, 2024
1 parent 65b8978 commit 86e1643
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 70 deletions.
40 changes: 16 additions & 24 deletions src/billing-form/billing-checkin-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,20 @@ const BillingCheckInForm: React.FC<BillingCheckInFormProps> = ({ patientUuid, se
const [paymentMethod, setPaymentMethod] = useState<any>();
let lineList = [];

const shouldBillPatient =
attributes.find((item) => item.attributeType === 'caf2124f-00a9-4620-a250-efd8535afd6d')?.value ===
'1c30ee58-82d4-4ea4-a8c1-4bf2f9dfc8cf';

const handleCreateBill = useCallback(
(createBillPayload) => {
shouldBillPatient &&
createPatientBill(createBillPayload).then(
() => {
showSnackbar({ title: 'Patient Bill', subtitle: 'Patient has been billed successfully', kind: 'success' });
},
(error) => {
showSnackbar({
title: 'Patient Bill Error',
subtitle: 'An error has occurred while creating patient bill',
kind: 'error',
});
},
);
},
[shouldBillPatient],
);
const handleCreateBill = useCallback((createBillPayload) => {
createPatientBill(createBillPayload).then(
() => {
showSnackbar({ title: 'Patient Bill', subtitle: 'Patient has been billed successfully', kind: 'success' });
},
(error) => {
showSnackbar({
title: 'Patient Bill Error',
subtitle: 'An error has occurred while creating patient bill',
kind: 'error',
});
},
);
}, []);

const handleBillingService = ({ selectedItem }) => {
const cashPointUuid = cashPoints?.[0]?.uuid ?? '';
Expand Down Expand Up @@ -110,7 +102,7 @@ const BillingCheckInForm: React.FC<BillingCheckInFormProps> = ({ patientUuid, se
return (
<section className={styles.sectionContainer}>
<VisitAttributesForm setAttributes={setAttributes} setPaymentMethod={setPaymentMethod} />
{shouldBillPatient && (
{
<>
<div className={styles.sectionTitle}>{t('billing', 'Billing')}</div>
<div className={styles.sectionField}></div>
Expand All @@ -123,7 +115,7 @@ const BillingCheckInForm: React.FC<BillingCheckInFormProps> = ({ patientUuid, se
titleText={t('billableService', 'Billable service')}
/>
</>
)}
}
</section>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import { TextInput, InlineLoading, ComboBox, RadioButtonGroup, RadioButton } from '@carbon/react';
import { usePaymentMethods } from '../billing-form.resource';
import styles from './visit-attributes-form.scss';
import { useConfig } from '@openmrs/esm-framework';

type VisitAttributesFormProps = {
setAttributes: (state) => void;
Expand Down Expand Up @@ -35,6 +36,7 @@ const VisitAttributesForm: React.FC<VisitAttributesFormProps> = ({ setAttributes
defaultValues: {},
resolver: zodResolver(visitAttributesFormSchema),
});
const patientCatergory = useConfig();
const [paymentDetails, paymentMethods, insuranceSchema, policyNumber, patientCategory] = watch([
'paymentDetails',
'paymentMethods',
Expand All @@ -49,15 +51,16 @@ const VisitAttributesForm: React.FC<VisitAttributesFormProps> = ({ setAttributes
}, [paymentDetails, paymentMethods, insuranceSchema, policyNumber, patientCategory]);

const createVisitAttributesPayload = () => {
const { patientCategory, paymentMethods, policyNumber, paymentDetails } = getValues();
const paymentMethods = getValues();
setPaymentMethod(paymentMethods);
const formPayload = [
{ uuid: 'caf2124f-00a9-4620-a250-efd8535afd6d', value: paymentDetails },
{ uuid: 'c39b684c-250f-4781-a157-d6ad7353bc90', value: paymentMethods },
{ uuid: '0f4f3306-f01b-43c6-af5b-fdb60015cb02', value: policyNumber },
{ uuid: '2d0fa959-6780-41f1-85b1-402045935068', value: insuranceSchema },
{ uuid: '3b9dfac8-9e4d-11ee-8c90-0242ac120002', value: patientCategory },
{ uuid: '919b51c9-8e2e-468f-8354-181bf3e55786', value: true },
patientCatergory.paymentDetails,
patientCatergory.paymentMethods,
patientCatergory.policyNumber,
patientCatergory.insuranceSchema,
patientCatergory.patientCategory,
patientCatergory.formPayloadPending,
true,
];
const visitAttributesPayload = formPayload.filter(
(item) => item.value !== undefined && item.value !== null && item.value !== '',
Expand Down Expand Up @@ -90,13 +93,13 @@ const VisitAttributesForm: React.FC<VisitAttributesFormProps> = ({ setAttributes
orientation="vertical"
legendText={t('paymentDetails', 'Payment Details')}
name="payment-details-group">
<RadioButton labelText="Paying" value="1c30ee58-82d4-4ea4-a8c1-4bf2f9dfc8cf" id="radio-1" />
<RadioButton labelText="Non paying" value="a28d7929-050a-4249-a61a-551e9b8cc102" id="radio-2" />
<RadioButton labelText="Paying" value={patientCatergory.payingDetails} id="radio-1" />
<RadioButton labelText="Non paying" value={patientCatergory.nonPayingDetails} id="radio-2" />
</RadioButtonGroup>
)}
/>

{paymentDetails === '1c30ee58-82d4-4ea4-a8c1-4bf2f9dfc8cf' && (
{paymentDetails === patientCatergory.payingDetails && (
<Controller
control={control}
name="paymentMethods"
Expand All @@ -114,40 +117,39 @@ const VisitAttributesForm: React.FC<VisitAttributesFormProps> = ({ setAttributes
/>
)}

{paymentMethods === 'beac329b-f1dc-4a33-9e7c-d95821a137a6' &&
paymentDetails === '1c30ee58-82d4-4ea4-a8c1-4bf2f9dfc8cf' && (
<>
<Controller
control={control}
name="insuranceScheme"
render={({ field }) => (
<TextInput
className={styles.sectionField}
onChange={(e) => field.onChange(e.target.value)}
id="insurance-scheme"
type="text"
labelText={t('insuranceScheme', 'Insurance scheme')}
/>
)}
/>
<Controller
control={control}
name="policyNumber"
render={({ field }) => (
<TextInput
className={styles.sectionField}
onChange={(e) => field.onChange(e.target.value)}
{...field}
id="policy-number"
type="text"
labelText={t('policyNumber', 'Policy number')}
/>
)}
/>
</>
)}
{paymentMethods === patientCatergory.insuranceDetails && paymentDetails === patientCatergory.payingDetails && (
<>
<Controller
control={control}
name="insuranceScheme"
render={({ field }) => (
<TextInput
className={styles.sectionField}
onChange={(e) => field.onChange(e.target.value)}
id="insurance-scheme"
type="text"
labelText={t('insuranceScheme', 'Insurance scheme')}
/>
)}
/>
<Controller
control={control}
name="policyNumber"
render={({ field }) => (
<TextInput
className={styles.sectionField}
onChange={(e) => field.onChange(e.target.value)}
{...field}
id="policy-number"
type="text"
labelText={t('policyNumber', 'Policy number')}
/>
)}
/>
</>
)}

{paymentDetails === 'a28d7929-050a-4249-a61a-551e9b8cc102' && (
{paymentDetails === patientCatergory.nonPayingDetails && (
<Controller
control={control}
name="patientCategory"
Expand All @@ -157,8 +159,8 @@ const VisitAttributesForm: React.FC<VisitAttributesFormProps> = ({ setAttributes
onChange={({ selectedItem }) => field.onChange(selectedItem?.uuid)}
id="patientCategory"
items={[
{ text: 'Child under 5', uuid: '2d61b762-6e32-4e2e-811f-ac72cbd3600a' },
{ text: 'Student', uuid: '159465AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' },
{ text: 'Child under 5', uuid: patientCatergory.childUnder5 },
{ text: 'Student', uuid: patientCatergory.student },
]}
itemToString={(item) => (item ? item.text : '')}
titleText={t('patientCategory', 'Patient category')}
Expand Down
26 changes: 25 additions & 1 deletion src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
import { Type } from '@openmrs/esm-framework';

export interface BillingConfig {}

export const configSchema = {};
export const configSchema = {
patientCatergory: {
_type: Type.Object,
_description: 'Encounter type UUIDs for TB.',
_default: {
paymentDetails: 'caf2124f-00a9-4620-a250-efd8535afd6d',
paymentMethods: 'c39b684c-250f-4781-a157-d6ad7353bc90',
policyNumber: '0f4f3306-f01b-43c6-af5b-fdb60015cb02',
insuranceSchema: '2d0fa959-6780-41f1-85b1-402045935068',
patientCategory: '3b9dfac8-9e4d-11ee-8c90-0242ac120002',
formPayloadPending: '919b51c9-8e2e-468f-8354-181bf3e55786',
payingDetails: '1c30ee58-82d4-4ea4-a8c1-4bf2f9dfc8cf',
nonPayingDetails: 'a28d7929-050a-4249-a61a-551e9b8cc102',
insuranceDetails: 'beac329b-f1dc-4a33-9e7c-d95821a137a6',
childUnder5: '2d61b762-6e32-4e2e-811f-ac72cbd3600a',
student: '159465AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
},
};

export interface ConfigObject {
patientCatergory: Object;
}

0 comments on commit 86e1643

Please sign in to comment.