@@ -37,6 +37,7 @@ import {
3737 Operation ,
3838 createFilterConfig ,
3939 getVariantColorClasses ,
40+ isSameDateRange ,
4041} from "./utils/Utils" ;
4142
4243import { SelectedFacilityUserBadge } from "@/components/ui/multi-filter/facilityUserFilter" ;
@@ -71,10 +72,19 @@ import {
7172 MEDICATION_DISPENSE_STATUS_COLORS ,
7273 MedicationDispenseStatus ,
7374} from "@/types/emr/medicationDispense/medicationDispense" ;
75+ import {
76+ INVENTORY_STATUS_COLORS ,
77+ InventoryStatus ,
78+ InventoryStatusOptions ,
79+ } from "@/types/inventory/product/inventory" ;
7480import {
7581 REQUEST_ORDER_PRIORITY_COLORS ,
7682 RequestOrderPriority ,
7783} from "@/types/inventory/requestOrder/requestOrder" ;
84+ import {
85+ getExpiredDateRange ,
86+ getExpiringSoonDateRange ,
87+ } from "@/Utils/inventory" ;
7888import careConfig from "@careConfig" ;
7989import { Zap } from "lucide-react" ;
8090export const encounterStatusFilter = (
@@ -189,6 +199,7 @@ export const dateFilter = (
189199 label ?: string ,
190200 dateRangeOptions ?: DateRangeOption [ ] ,
191201 disableClear ?: boolean ,
202+ getOperations : ( selected : FilterDateRange ) => Operation [ ] = getDateOperations ,
192203) =>
193204 createFilterConfig ( key , label || t ( "started_date" ) , "date" , [ ] , {
194205 renderSelected : (
@@ -205,7 +216,7 @@ export const dateFilter = (
205216 ) ;
206217 } ,
207218 getOperations : ( selected : FilterValues ) =>
208- getDateOperations ( selected as FilterDateRange ) ,
219+ getOperations ( selected as FilterDateRange ) ,
209220 mode : "single" ,
210221 icon : < CalendarFold className = "w-4 h-4" /> ,
211222 dateRangeOptions,
@@ -684,6 +695,70 @@ export const inventoryPriorityFilter = (
684695 } ,
685696 ) ;
686697
698+ export const inventoryStatusFilter = (
699+ key : string = "status" ,
700+ mode : FilterMode = "single" ,
701+ customOperations ?: Operation [ ] ,
702+ ) =>
703+ createFilterConfig (
704+ key ,
705+ t ( "status" ) ,
706+ "command" ,
707+ InventoryStatusOptions . map ( ( value ) => ( {
708+ value : value ,
709+ label : t ( value ) ,
710+ color : getVariantColorClasses ( INVENTORY_STATUS_COLORS [ value ] ) ,
711+ } ) ) ,
712+ {
713+ renderSelected : ( selected : FilterValues ) => {
714+ const selectedStatus = selected as string [ ] ;
715+ if ( typeof selectedStatus [ 0 ] === "string" ) {
716+ const option = selectedStatus [ 0 ] ;
717+ const variant = INVENTORY_STATUS_COLORS [ option as InventoryStatus ] ;
718+ return (
719+ < GenericSelectedBadge
720+ selectedValue = { option }
721+ selectedLength = { selectedStatus . length }
722+ variant = { variant }
723+ />
724+ ) ;
725+ }
726+ return < > </ > ;
727+ } ,
728+ getOperations : ( ) => customOperations || [ { label : "is" } ] ,
729+ mode,
730+ icon : < CircleDashed className = "size-4" /> ,
731+ showColorIndicators : true ,
732+ } ,
733+ ) ;
734+
735+ export const productExpirationDateFilter = (
736+ key : string = "product_expiration_date" ,
737+ label ?: string ,
738+ ) => {
739+ const expiringSoonRange = getExpiringSoonDateRange ( ) ;
740+
741+ const presetOptions : DateRangeOption [ ] = [
742+ { label : "expired" , getDateRange : getExpiredDateRange } ,
743+ ...( expiringSoonRange
744+ ? [ { label : "expiring_soon" , getDateRange : ( ) => expiringSoonRange } ]
745+ : [ ] ) ,
746+ ] ;
747+
748+ return dateFilter (
749+ key ,
750+ label || t ( "expiration_date" ) ,
751+ presetOptions ,
752+ undefined ,
753+ ( selected ) =>
754+ presetOptions . some ( ( option ) =>
755+ isSameDateRange ( selected , option . getDateRange ( ) ) ,
756+ )
757+ ? [ { label : "is" } ]
758+ : getDateOperations ( selected ) ,
759+ ) ;
760+ } ;
761+
687762export const dispenseStatusFilter = (
688763 key : string = "dispense_status" ,
689764 mode : FilterMode = "single" ,
0 commit comments