feat (patient): add search by identifier and nik only
This commit is contained in:
@@ -91,7 +91,8 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
|
||||
Preload("Person.Contacts").
|
||||
Preload("Person.Relatives.Village.District.Regency.Province").
|
||||
Preload("Person.Addresses.Village.District.Regency.Province").
|
||||
Preload("Person.Addresses.PostalRegion.Village.District.Regency.Province")
|
||||
Preload("Person.Addresses.PostalRegion.Village.District.Regency.Province").
|
||||
Preload("Person.Insurances.InsuranceCompany")
|
||||
|
||||
if err := tx.First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
@@ -157,6 +158,7 @@ func SearchData(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) (*e.Patient
|
||||
pl.SetLogInfo(event, input, "started", "DBSearch")
|
||||
|
||||
var patient e.Patient
|
||||
var err error
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
@@ -167,15 +169,25 @@ func SearchData(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) (*e.Patient
|
||||
|
||||
// Preload associations for complete data
|
||||
tx = tx.Preload(clause.Associations)
|
||||
tx = tx.Preload("Person.Addresses")
|
||||
tx = tx.Preload("Person.Contacts")
|
||||
tx = tx.Preload("Person.Relatives")
|
||||
tx = tx.Preload("Person.Addresses").
|
||||
Preload("Person.Contacts").
|
||||
Preload("Person.Relatives").
|
||||
Preload("Person.Insurances")
|
||||
|
||||
// Search by patient number OR person's resident identity number (exact match)
|
||||
err := tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
|
||||
Where("\"Patient\".\"Number\" = ? OR \"Person\".\"ResidentIdentityNumber\" = ?",
|
||||
input.Search, input.Search).
|
||||
First(&patient).Error
|
||||
switch input.Mode {
|
||||
case e.SMIdent:
|
||||
// Search by patient number OR person's resident identity number (exact match) OR person's name (partial match)
|
||||
err = tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
|
||||
Where("\"Patient\".\"Number\" = ? OR \"Person\".\"ResidentIdentityNumber\" = ? OR \"Person\".\"Name\" ILIKE ?",
|
||||
input.Search, input.Search, "%"+input.Search+"%").
|
||||
First(&patient).Error
|
||||
case e.SMNik:
|
||||
// Search by patient person's resident identity number (exact match)
|
||||
err = tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
|
||||
Where("\"Person\".\"ResidentIdentityNumber\" = ?",
|
||||
input.Search).
|
||||
First(&patient).Error
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if processedErr := pu.HandleSearchError(err, event, source, input.Search, patient); processedErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user