Skip to content

Commit

Permalink
MAR Table: shrink discontinued medicines (#6151)
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Sep 13, 2023
1 parent 2869992 commit d92287c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 41 additions & 2 deletions src/Components/Medicine/PrescriptionAdministrationsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export default function PrescriptionAdministrationsTable({
const { t } = useTranslation();

const [state, setState] = useState<State>();

const [showDiscontinued, setShowDiscontinued] = useState(false);
const [discontinuedCount, setDiscontinuedCount] = useState<number>();

const pagination = useRangePagination({
bounds: state?.administrationsTimeBounds ?? {
start: new Date(),
Expand All @@ -64,8 +68,13 @@ export default function PrescriptionAdministrationsTable({
);

const refetch = useCallback(async () => {
const filters = {
is_prn: prn,
prescription_type: "REGULAR",
};

const res = await dispatch(
list({ is_prn: prn, prescription_type: "REGULAR" })
list(showDiscontinued ? filters : { ...filters, discontinued: false })
);

setState({
Expand All @@ -74,7 +83,14 @@ export default function PrescriptionAdministrationsTable({
),
administrationsTimeBounds: getAdministrationBounds(res.data.results),
});
}, [consultation_id, dispatch]);

if (showDiscontinued === false) {
const discontinuedRes = await dispatch(
list({ ...filters, discontinued: true, limit: 0 })
);
setDiscontinuedCount(discontinuedRes.data.count);
}
}, [consultation_id, showDiscontinued, dispatch]);

useEffect(() => {
refetch();
Expand Down Expand Up @@ -234,6 +250,29 @@ export default function PrescriptionAdministrationsTable({
/>
))}
</tbody>

{showDiscontinued === false && !!discontinuedCount && (
<tfoot>
<tr>
<td colSpan={100}>
<ButtonV2
variant="secondary"
className="w-full"
ghost
onClick={() => setShowDiscontinued(true)}
>
<span className="flex w-full justify-start gap-1 text-sm">
<CareIcon icon="l-eye" className="text-lg" />
<span>
Show <strong>{discontinuedCount}</strong> other
discontinued prescription(s)
</span>
</span>
</ButtonV2>
</td>
</tr>
</tfoot>
)}
</table>

{state?.prescriptions.length === 0 && (
Expand Down
2 changes: 1 addition & 1 deletion src/Redux/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ export const PrescriptionActions = (consultation_external_id: string) => {
const pathParams = { consultation_external_id };

return {
list: (query?: Partial<Prescription>) => {
list: (query?: Record<string, string | boolean | number>) => {
let altKey;
if (query?.is_prn !== undefined) {
altKey = query?.is_prn
Expand Down

0 comments on commit d92287c

Please sign in to comment.