77 lines
2.8 KiB
Go
77 lines
2.8 KiB
Go
package doctor
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
"sismedika.com/sas/westone/types"
|
|
)
|
|
|
|
type Store struct {
|
|
db *sqlx.DB
|
|
}
|
|
|
|
func NewStore(db *sqlx.DB) *Store {
|
|
return &Store{db: db}
|
|
}
|
|
|
|
func (s *Store) SearchDoctor(keyword string, page int, perpage int) ([]types.DoctorResult, error) {
|
|
var list_doctor []types.DoctorResult
|
|
var sqlFilter []string
|
|
|
|
if keyword != "" {
|
|
params := strings.Split(keyword, "+")
|
|
if len(params) > 0 && params[0] != "" {
|
|
sqlFilter = append(sqlFilter, "PersonName LIKE '%"+params[0]+"%'")
|
|
}
|
|
if len(params) > 1 && params[1] != "" {
|
|
sqlFilter = append(sqlFilter, "PersonIdentifierValue = '"+params[1]+"'")
|
|
}
|
|
if len(params) > 2 && params[2] != "" {
|
|
sqlFilter = append(sqlFilter, "DoctorCode = '"+params[2]+"'")
|
|
}
|
|
if len(params) > 3 && params[3] != "" {
|
|
sqlFilter = append(sqlFilter, "PersonBirthDate = '"+params[3]+"'")
|
|
}
|
|
if len(params) > 4 && params[4] != "" {
|
|
sqlFilter = append(sqlFilter, "PersonTelecomValue = '"+params[4]+"'")
|
|
}
|
|
}
|
|
|
|
doctor_tb := `DoctorID, DoctorCode, DoctorIHSNumber, DoctorPersonID`
|
|
|
|
person_tb := `PersonID, PersonName, PersonSalutation, PersonPrefix, PersonSuffix, PersonGender, PersonBirthPlace, PersonBirthDate,
|
|
PersonReligionCode, PersonReligionSystem, PersonBloodTypeCode, PersonBloodTypeSystem, PersonRhesusCode, PersonRhesusSystem,
|
|
PersonEducationCode, PersonEducationSystem, PersonJobClassCode, PersonJobClassSystem, PersonEtnicityCode, PersonEtnicitySystem,
|
|
PersonMaritalBirth, PersonMaritalStatus`
|
|
|
|
person_address_tb := `PersonAddressID, PersonAddressPersonID, PersonAddressIsDefault, PersonAddressUse, PersonAddressType, PersonAddressText,
|
|
PersonAddressLine1, PersonAddressLine2, PersonAddressRegionalCd, PersonAddressRT, PersonAddressRW, PersonAddressCity,
|
|
PersonAddressDistrict, PersonAddressState, PersonAddressCountry`
|
|
|
|
person_identifier_tb := `PersonIdentifierID, PersonIdentifierPersonID, PersonIdentifierUse, PersonIdentifierTypeCode,
|
|
PersonIdentifierTypeSystem, PersonIdentifierCode, PersonIdentifierSystem, PersonIdentifierValue`
|
|
|
|
person_telecom_tb := `PersonTelecomID, PersonTelecomPersonID, PersonTelecomSystem, PersonTelecomValue, PersonTelecomUse`
|
|
|
|
offset := (page - 1) * perpage
|
|
sql := `SELECT ` + doctor_tb + `,` + person_tb + `,` + person_identifier_tb + `,` + person_address_tb + `,` + person_telecom_tb +
|
|
` FROM doctor
|
|
JOIN person ON PersonID = DoctorPersonID
|
|
JOIN person_identifier ON PersonIdentifierPersonID = PersonID
|
|
JOIN person_telecom ON PersonTelecomPersonID = PersonID
|
|
JOIN person_address ON PersonAddressPersonID = PersonID
|
|
WHERE DoctorIsActive = 'Y'`
|
|
|
|
if len(sqlFilter) > 0 {
|
|
sql += " AND " + strings.Join(sqlFilter, " AND ")
|
|
}
|
|
sql += " LIMIT ? OFFSET ?"
|
|
|
|
if err := s.db.Select(&list_doctor, sql, perpage, offset); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return list_doctor, nil
|
|
}
|