search & oagination md pasien
This commit is contained in:
87
services/dev/md.pasien.services.go
Normal file
87
services/dev/md.pasien.services.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package dev_services
|
||||
|
||||
import (
|
||||
"cpone/db"
|
||||
"cpone/models"
|
||||
dbx "cpone/package/database"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewMdPasienServices(uStore db.AppStore) *MdPasienServices {
|
||||
|
||||
return &MdPasienServices{
|
||||
|
||||
MdPasienStore: uStore,
|
||||
}
|
||||
}
|
||||
|
||||
type MdPasienServices struct {
|
||||
MdPasienStore db.AppStore
|
||||
}
|
||||
|
||||
func (su *MdPasienServices) GetListMdPasien(
|
||||
search string,
|
||||
currentPage int,
|
||||
rowPerPage int) ([]models.Pasien, int, error) {
|
||||
var pasienList []models.Pasien
|
||||
var totalData int
|
||||
offset := (currentPage - 1) * rowPerPage
|
||||
prm := "%" + strings.TrimSpace(search) + "%"
|
||||
|
||||
querytotal := `
|
||||
SELECT COUNT(*)
|
||||
FROM m_patient
|
||||
JOIN m_title
|
||||
ON M_PatientM_TitleID = M_TitleID
|
||||
AND M_TitleIsActive = 'Y'
|
||||
WHERE
|
||||
(M_PatientNoReg LIKE ? OR M_PatientName LIKE ?)
|
||||
AND M_PatientIsActive = 'Y'
|
||||
`
|
||||
if err := dbx.Handlex.Get(&totalData, querytotal, prm, prm); err != nil {
|
||||
return nil, 0, fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
query := `
|
||||
SELECT m_patient.*
|
||||
FROM m_patient
|
||||
JOIN m_title
|
||||
ON M_PatientM_TitleID = M_TitleID
|
||||
AND M_TitleIsActive = 'Y'
|
||||
WHERE
|
||||
(M_PatientNoReg LIKE ? OR M_PatientName LIKE ?)
|
||||
AND M_PatientIsActive = 'Y'
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
|
||||
if err := dbx.Handlex.Select(&pasienList, query, prm, prm, rowPerPage, offset); err != nil {
|
||||
return nil, 0, fmt.Errorf("error querying database: %v", err)
|
||||
}
|
||||
totalPage := int(math.Ceil(float64(totalData) / float64(rowPerPage)))
|
||||
|
||||
return pasienList, totalPage, nil
|
||||
|
||||
}
|
||||
func (su *MdPasienServices) GetMdPasienBreadCrumb(title string) (models.BreadCrumbV1, error) {
|
||||
|
||||
ret := models.BreadCrumbV1{
|
||||
Title: "Master Pasien",
|
||||
Item: []models.ItemBreadCrumbV1{
|
||||
{
|
||||
Item: "Dashboard",
|
||||
Url: "/dev/dashboard",
|
||||
},
|
||||
{
|
||||
Item: "Master",
|
||||
Url: "/dev/master",
|
||||
},
|
||||
{
|
||||
Item: "Pasien",
|
||||
Url: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
Reference in New Issue
Block a user