Merge pull request #192 from dikstub-rssa/fix/anything-moko

feat (encounter): add more filter for list
This commit is contained in:
Dwi Atmoko Purbo Sakti
2025-12-05 14:05:31 +07:00
committed by GitHub
2 changed files with 30 additions and 10 deletions
@@ -78,11 +78,14 @@ type TRujukan struct {
type ReadListDto struct { type ReadListDto struct {
FilterDto FilterDto
Includes string `json:"includes"` Includes string `json:"includes"`
Pagination ecore.Pagination Pagination ecore.Pagination
Person_Name *string `json:"person-name"` Patient_Identifier *string `json:"patient-identifier"`
StartDate *string `json:"start-date"` StartDate *string `json:"start-date"`
EndDate *string `json:"end-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 pa.AuthInfo
} }
@@ -92,7 +95,6 @@ type FilterDto struct {
Patient *ep.Patient `json:"patient,omitempty"` Patient *ep.Patient `json:"patient,omitempty"`
RegisteredAt *time.Time `json:"registeredAt"` RegisteredAt *time.Time `json:"registeredAt"`
Class_Code ere.EncounterClassCode `json:"class-code" validate:"maxLength=10"` Class_Code ere.EncounterClassCode `json:"class-code" validate:"maxLength=10"`
Unit_Code *string `json:"unit-code"`
Specialist_Code *string `json:"specialist-code"` Specialist_Code *string `json:"specialist-code"`
Subspecialist_Code *string `json:"subspecialist-code"` Subspecialist_Code *string `json:"subspecialist-code"`
VisitDate time.Time `json:"visitDate"` VisitDate time.Time `json:"visitDate"`
@@ -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\""). 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)). // TODO: getuk lib need to be updated to support this
Scopes(gh.Filter(input.FilterDto)). 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). Count(&count).
Scopes(gh.Paginate(input, &pagination)). Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC") 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 := tx.Find(&data).Error; err != nil {
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return nil, &meta, nil return nil, &meta, nil