feat (encounter): add more filter for list

This commit is contained in:
dpurbosakti
2025-12-05 14:04:56 +07:00
parent 91e40cc2b7
commit 935cc8aef5
2 changed files with 30 additions and 10 deletions
@@ -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