From 935cc8aef5a3cde6f107be73d70a84fa685338da Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Fri, 5 Dec 2025 14:04:56 +0700 Subject: [PATCH] feat (encounter): add more filter for list --- .../domain/main-entities/encounter/dto.go | 14 +++++----- .../use-case/main-use-case/encounter/lib.go | 26 ++++++++++++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index c039fc0c..9b007097 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -78,11 +78,14 @@ type TRujukan struct { type ReadListDto struct { FilterDto - Includes string `json:"includes"` - Pagination ecore.Pagination - Person_Name *string `json:"person-name"` - StartDate *string `json:"start-date"` - EndDate *string `json:"end-date"` + Includes string `json:"includes"` + Pagination ecore.Pagination + Patient_Identifier *string `json:"patient-identifier"` + StartDate *string `json:"start-date"` + EndDate *string `json:"end-date"` + PaymentMethod_Code *string `json:"paymentMethod-code"` + Status_Code *string `json:"status-code"` + Unit_Code *string `json:"unit-code"` pa.AuthInfo } @@ -92,7 +95,6 @@ type FilterDto struct { Patient *ep.Patient `json:"patient,omitempty"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class-code" validate:"maxLength=10"` - Unit_Code *string `json:"unit-code"` Specialist_Code *string `json:"specialist-code"` Subspecialist_Code *string `json:"subspecialist-code"` VisitDate time.Time `json:"visitDate"` diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index a9a5a307..3baec23a 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -73,17 +73,35 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.En ) } - if input.Person_Name != nil { + if input.Patient_Identifier != nil { tx = tx.Joins("JOIN \"Patient\" ON \"Patient\".\"Id\" = \"Encounter\".\"Patient_Id\""). - Joins("JOIN \"Person\" ON \"Person\".\"Id\" = \"Patient\".\"Person_Id\"").Where("\"Person\".\"Name\" ILIKE ?", "%"+*input.Person_Name+"%") + Joins("JOIN \"Person\" ON \"Person\".\"Id\" = \"Patient\".\"Person_Id\"").Where("\"Person\".\"Name\" ILIKE ? OR \"Patient\".\"Number\" = ?", "%"+*input.Patient_Identifier+"%", *input.Patient_Identifier) } - tx = tx.Debug().Scopes(gh.Preload(input.Includes)). - Scopes(gh.Filter(input.FilterDto)). + // TODO: getuk lib need to be updated to support this + if input.Status_Code != nil { + tx = tx.Where("\"Encounter\".\"Status_Code\" = ?", *input.Status_Code) + } + + if input.Unit_Code != nil { + tx = tx.Where("\"Encounter\".\"Unit_Code\" = ?", *input.Unit_Code) + } + + if input.PaymentMethod_Code != nil { + tx = tx.Where("\"Encounter\".\"PaymentMethod_Code\" = ?", *input.PaymentMethod_Code) + } + + tx = tx.Scopes(gh.Preload(input.Includes)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") + // tx.Debug().Scopes(gh.Preload(input.Includes)). + // Scopes(gh.Filter(input.FilterDto)). + // Count(&count). + // Scopes(gh.Paginate(input, &pagination)). + // Order("\"CreatedAt\" DESC") + if err := tx.Find(&data).Error; err != nil { if err == gorm.ErrRecordNotFound { return nil, &meta, nil