diff --git a/src/billing-form/billing-checkin-form.component.tsx b/src/billing-form/billing-checkin-form.component.tsx index 82e581d..711495f 100644 --- a/src/billing-form/billing-checkin-form.component.tsx +++ b/src/billing-form/billing-checkin-form.component.tsx @@ -22,28 +22,20 @@ const BillingCheckInForm: React.FC = ({ patientUuid, se const [paymentMethod, setPaymentMethod] = useState(); 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 ?? ''; @@ -110,7 +102,7 @@ const BillingCheckInForm: React.FC = ({ patientUuid, se return (
- {shouldBillPatient && ( + { <>
{t('billing', 'Billing')}
@@ -123,7 +115,7 @@ const BillingCheckInForm: React.FC = ({ patientUuid, se titleText={t('billableService', 'Billable service')} /> - )} + }
); }; diff --git a/src/billing-form/visit-attributes/visit-attributes-form.component.tsx b/src/billing-form/visit-attributes/visit-attributes-form.component.tsx index 46fe257..774b62c 100644 --- a/src/billing-form/visit-attributes/visit-attributes-form.component.tsx +++ b/src/billing-form/visit-attributes/visit-attributes-form.component.tsx @@ -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; @@ -35,6 +36,7 @@ const VisitAttributesForm: React.FC = ({ setAttributes defaultValues: {}, resolver: zodResolver(visitAttributesFormSchema), }); + const patientCatergory = useConfig(); const [paymentDetails, paymentMethods, insuranceSchema, policyNumber, patientCategory] = watch([ 'paymentDetails', 'paymentMethods', @@ -49,15 +51,16 @@ const VisitAttributesForm: React.FC = ({ 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 !== '', @@ -90,13 +93,13 @@ const VisitAttributesForm: React.FC = ({ setAttributes orientation="vertical" legendText={t('paymentDetails', 'Payment Details')} name="payment-details-group"> - - + + )} /> - {paymentDetails === '1c30ee58-82d4-4ea4-a8c1-4bf2f9dfc8cf' && ( + {paymentDetails === patientCatergory.payingDetails && ( = ({ setAttributes /> )} - {paymentMethods === 'beac329b-f1dc-4a33-9e7c-d95821a137a6' && - paymentDetails === '1c30ee58-82d4-4ea4-a8c1-4bf2f9dfc8cf' && ( - <> - ( - field.onChange(e.target.value)} - id="insurance-scheme" - type="text" - labelText={t('insuranceScheme', 'Insurance scheme')} - /> - )} - /> - ( - field.onChange(e.target.value)} - {...field} - id="policy-number" - type="text" - labelText={t('policyNumber', 'Policy number')} - /> - )} - /> - - )} + {paymentMethods === patientCatergory.insuranceDetails && paymentDetails === patientCatergory.payingDetails && ( + <> + ( + field.onChange(e.target.value)} + id="insurance-scheme" + type="text" + labelText={t('insuranceScheme', 'Insurance scheme')} + /> + )} + /> + ( + 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 && ( = ({ 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')} diff --git a/src/config-schema.ts b/src/config-schema.ts index 090a18b..a5eefe4 100644 --- a/src/config-schema.ts +++ b/src/config-schema.ts @@ -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; +}