diff --git a/src/billing-form/billing-checkin-form.component.tsx b/src/billing-form/billing-checkin-form.component.tsx index 711495f..6cd6fb6 100644 --- a/src/billing-form/billing-checkin-form.component.tsx +++ b/src/billing-form/billing-checkin-form.component.tsx @@ -1,7 +1,7 @@ import React, { useCallback, useState } from 'react'; import { Dropdown, InlineLoading, InlineNotification } from '@carbon/react'; import { useTranslation } from 'react-i18next'; -import { showSnackbar } from '@openmrs/esm-framework'; +import { showSnackbar, useConfig } from '@openmrs/esm-framework'; import { useCashPoint, useBillableItems, createPatientBill } from './billing-form.resource'; import VisitAttributesForm from './visit-attributes/visit-attributes-form.component'; import styles from './billing-checkin-form.scss'; @@ -20,22 +20,31 @@ const BillingCheckInForm: React.FC = ({ patientUuid, se const { lineItems, isLoading: isLoadingLineItems, error: lineError } = useBillableItems(); const [attributes, setAttributes] = useState([]); const [paymentMethod, setPaymentMethod] = useState(); + const { patientCatergory, catergoryConcepts } = useConfig(); let lineList = []; - 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 shouldBillPatient = + attributes.find((item) => item.attributeType === patientCatergory.paymentDetails)?.value === + catergoryConcepts.payingDetails; + + 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 handleBillingService = ({ selectedItem }) => { const cashPointUuid = cashPoints?.[0]?.uuid ?? ''; @@ -102,7 +111,7 @@ const BillingCheckInForm: React.FC = ({ patientUuid, se return (
- { + {shouldBillPatient && ( <>
{t('billing', 'Billing')}
@@ -115,7 +124,7 @@ const BillingCheckInForm: React.FC = ({ patientUuid, se titleText={t('billableService', 'Billable service')} /> - } + )}
); };