Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKiprotich350 authored Jan 17, 2025
2 parents 8ac746a + 03dc198 commit beb1aa5
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 1,119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Diagnosis,
Package,
PatientBenefit,
SHAIntervension,
SHAIntervention,
shifIdentifiersResponse,
} from '../types';

Expand Down Expand Up @@ -52,10 +52,10 @@ export const packages = [
},
] as Array<Package>;

export const intervensions = patientBenefits.map(({ interventionCode, interventionName }) => ({
export const interventions = patientBenefits.map(({ interventionCode, interventionName }) => ({
interventionCode,
interventionName,
})) as Array<SHAIntervension>;
})) as Array<SHAIntervention>;

export const coverageEligibilityResponse = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import useProvider from '../../hooks/useProvider';
import { PatientBenefit } from '../../types';
import { preAuthenticateBenefit, preauthSchema } from '../benefits-package.resources';
import styles from './benefits-pre-auth-form.scss';
import PackageIntervensions from './package-intervensions.component';
import PackageInterventions from './package-interventions.component';
import { ErrorState } from '@openmrs/esm-patient-common-lib';

type BenefitsPreAuth = z.infer<typeof preauthSchema>;
Expand Down Expand Up @@ -240,8 +240,9 @@ const BenefitPreAuthForm: React.FC<BenefitPreAuthFormProps> = ({ closeWorkspace,
</Column>
{selectedPackageObservable && (
<Column>
<PackageIntervensions
<PackageInterventions
category={packages.find((package_) => package_.uuid === selectedPackageObservable)?.packageCode ?? ''}
patientUuid={patientUuid}
/>
</Column>
)}
Expand All @@ -255,7 +256,7 @@ const BenefitPreAuthForm: React.FC<BenefitPreAuthFormProps> = ({ closeWorkspace,
invalid={form.formState.errors[field.name]?.message}
invalidText={form.formState.errors[field.name]?.message}
id="diagnoses"
titleText={t('diagnosis', 'Diagnosis')}
titleText={t('finalDiagnosis', 'Final Diagnosis')}
selectedItems={field.value}
label="Choose option"
items={diagnoses.map((r) => r.id)}
Expand All @@ -279,7 +280,7 @@ const BenefitPreAuthForm: React.FC<BenefitPreAuthFormProps> = ({ closeWorkspace,
<Button className={styles.button} kind="secondary" onClick={closeWorkspace}>
{t('discard', 'Discard')}
</Button>
<Button className={styles.button} kind="primary" type="submit">
<Button className={styles.button} kind="primary" type="submit" disabled={isSubmitting}>
{isSubmitting ? (
<>
<Loading className={styles.button_spinner} withOverlay={false} small /> {t('submitting', 'Submitting')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,57 @@
import { InlineLoading, InlineNotification, MultiSelect } from '@carbon/react';
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { z } from 'zod';
import { useInterventions } from '../../hooks/useInterventions';
import { InterventionsFilter, toQueryParams, useInterventions } from '../../hooks/useInterventions';
import { eligibilityRequestShema } from '../benefits-package.resources';
import { usePatient } from '@openmrs/esm-framework';

type EligibilityRequest = z.infer<typeof eligibilityRequestShema>;

type PackageIntervensionsProps = {
type PackageInterventionsProps = {
category: string;
patientUuid: string;
};
const PackageIntervensions: React.FC<PackageIntervensionsProps> = ({ category }) => {
const { error, interventions, isLoading } = useInterventions(category);
const PackageInterventions: React.FC<PackageInterventionsProps> = ({ category, patientUuid }) => {
const [filters, setFilters] = useState<InterventionsFilter>({ package_code: category });
const { error: patientError, isLoading: isPatientLoading, patient } = usePatient(patientUuid);
const { error, interventions, isLoading } = useInterventions(filters);

const form = useFormContext<EligibilityRequest>();
const { t } = useTranslation();

useEffect(() => {
setFilters((state) => ({
...state,
package_code: category,
applicable_gender: patient?.gender === 'male' ? 'MALE' : patient?.gender === 'female' ? 'FEMALE' : undefined,
}));
}, [category, patient]);

useEffect(() => {
form.setValue('interventions', []);
}, [category]);

Check warning on line 34 in packages/esm-billing-app/src/benefits-package/forms/package-interventions.component.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has a missing dependency: 'form'. Either include it or remove the dependency array

if (isLoading) {
return <InlineLoading status="active" iconDescription="Loading" description="Loading intervensions..." />;
if (isLoading || isPatientLoading) {
return (
<InlineLoading
status="active"
iconDescription="Loading"
description={t('loadingInterventions', 'Loading interventions') + '...'}
/>
);
}

if (error) {
if (error || patientError) {
return (
<InlineNotification
aria-label="closes notification"
kind="error"
lowContrast={true}
statusIconDescription="notification"
title={t('failure', 'Error loading intervensions')}
title={t('failure', 'Error loading interventions')}
subtitle={error?.message ?? patientError?.message}
/>
);
}
Expand Down Expand Up @@ -60,4 +80,4 @@ const PackageIntervensions: React.FC<PackageIntervensionsProps> = ({ category })
);
};

export default PackageIntervensions;
export default PackageInterventions;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Controller, FormProvider, useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import { z } from 'zod';
import PackageIntervensions from '../../../benefits-package/forms/package-intervensions.component';
import PackageInterventions from '../../../benefits-package/forms/package-interventions.component';
import { formatDate } from '../../../helpers/functions';
import { useSystemSetting } from '../../../hooks/getMflCode';
import usePackages from '../../../hooks/usePackages';
Expand Down Expand Up @@ -314,8 +314,9 @@ const ClaimsForm: React.FC<ClaimsFormProps> = ({ bill, selectedLineItems }) => {
{selectedPackageObservable && (
<Column>
<Layer className={styles.input}>
<PackageIntervensions
<PackageInterventions
category={packages.find((package_) => package_.uuid === selectedPackageObservable)?.packageCode ?? ''}
patientUuid={patientUuid}
/>
</Layer>
</Column>
Expand Down
Loading

0 comments on commit beb1aa5

Please sign in to comment.