Skip to content

Commit

Permalink
Medicine: Adds type filter for medibase search (#6186)
Browse files Browse the repository at this point in the history
* add type filter for medibase

* Consultation: Verified By Doctor as Dropdown

* add missing model changes

* Revert "add missing model changes"

This reverts commit 149592e.

* Revert "Consultation: Verified By Doctor as Dropdown"

This reverts commit 4113172.
  • Loading branch information
rithviknishad authored Sep 5, 2023
1 parent f535fd3 commit b0c61dc
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
39 changes: 39 additions & 0 deletions src/CAREUI/interactive/Switch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { classNames } from "../../Utils/utils";

interface Props<T extends string> {
tabs: Record<T, string>;
selected: T;
onChange: (tab: T) => void;
size?: "sm" | "md" | "lg";
}

export default function Switch<T extends string>({
size = "sm",
...props
}: Props<T>) {
return (
<ul role="list" className="flex">
{Object.keys(props.tabs).map((tab) => {
return (
<li
key={tab}
tabIndex={0}
className={classNames(
"cursor-pointer select-none border shadow-sm outline-none transition-all duration-200 ease-in-out first:rounded-l last:rounded-r focus:ring-1",
size === "sm" && "px-2 py-1 text-xs",
size === "md" && "px-3 py-2 text-sm",
size === undefined && "px-3 py-2 text-sm",
size === "lg" && "px-4 py-3 text-base",
props.selected === tab
? "border-primary-500 bg-primary-500 font-semibold text-white hover:bg-primary-600 focus:border-primary-500 focus:ring-primary-500"
: "border-gray-400 bg-gray-50 hover:bg-gray-200 focus:border-primary-500 focus:ring-primary-500"
)}
onClick={() => props.onChange(tab as T)}
>
{props.tabs[tab as T]}
</li>
);
})}
</ul>
);
}
30 changes: 28 additions & 2 deletions src/Components/Medicine/MedibaseAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useEffect, useState } from "react";
import Switch from "../../CAREUI/interactive/Switch";
import { useAsyncOptions } from "../../Common/hooks/useAsyncOptions";
import { listMedibaseMedicines } from "../../Redux/actions";
import { Autocomplete } from "../Form/FormFields/Autocomplete";
Expand All @@ -15,8 +17,32 @@ export default function MedibaseAutocompleteFormField(
const { isLoading, options, fetchOptions } =
useAsyncOptions<MedibaseMedicine>("id");

const [query, setQuery] = useState("");
const [type, setType] = useState<MedibaseMedicine["type"]>();

useEffect(() => {
fetchOptions(listMedibaseMedicines(query, type));
}, [query, type]);

return (
<FormField field={field}>
<FormField
field={{
...field,
labelSuffix: (
<Switch
tabs={{
all: "All",
brand: "Brand",
generic: "Generic",
}}
selected={type ?? "all"}
onChange={(type) => {
setType(type === "all" ? undefined : type);
}}
/>
),
}}
>
<Autocomplete
id={field.id}
disabled={field.disabled}
Expand All @@ -34,7 +60,7 @@ export default function MedibaseAutocompleteFormField(
<OptionChip value={option.type} />
)
}
onQuery={(query) => fetchOptions(listMedibaseMedicines(query))}
onQuery={setQuery}
isLoading={isLoading}
/>
</FormField>
Expand Down
8 changes: 6 additions & 2 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HCXClaimModel, HCXPolicyModel } from "../Components/HCX/models";
import {
MedibaseMedicine,
MedicineAdministrationRecord,
Prescription,
} from "../Components/Medicine/models";
Expand Down Expand Up @@ -803,8 +804,11 @@ export const listICD11Diagnosis = (params: object, key: string) => {
return fireRequest("listICD11Diagnosis", [], params, null, key);
};
// Medibase
export const listMedibaseMedicines = (query: string) => {
return fireRequest("listMedibaseMedicines", [], { query });
export const listMedibaseMedicines = (
query: string,
type?: MedibaseMedicine["type"]
) => {
return fireRequest("listMedibaseMedicines", [], { query, type });
};

// Resource
Expand Down

0 comments on commit b0c61dc

Please sign in to comment.