api dashboard antrian per kategori

This commit is contained in:
renaldybrada
2026-02-03 13:45:43 +07:00
parent 3aebfc4efe
commit 1f760ff9d5
8 changed files with 251 additions and 0 deletions
+39
View File
@@ -111,6 +111,31 @@ const docTemplate = `{
}
}
},
"/dashboard/antrian-per-kategori/": {
"get": {
"tags": [
"Dashboard"
],
"summary": "Get Antrian Per Kategori",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dashboard.AntrianPerKategori"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/shared.BaseErrorResponse"
}
}
}
}
},
"/reference/dokter/": {
"get": {
"tags": [
@@ -494,6 +519,20 @@ const docTemplate = `{
}
}
},
"dashboard.AntrianPerKategori": {
"type": "object",
"properties": {
"id_kategori": {
"type": "integer"
},
"jumlah_antrean": {
"type": "integer"
},
"kategori": {
"type": "string"
}
}
},
"dokter.DokterResponse": {
"type": "object",
"properties": {
+39
View File
@@ -105,6 +105,31 @@
}
}
},
"/dashboard/antrian-per-kategori/": {
"get": {
"tags": [
"Dashboard"
],
"summary": "Get Antrian Per Kategori",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dashboard.AntrianPerKategori"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/shared.BaseErrorResponse"
}
}
}
}
},
"/reference/dokter/": {
"get": {
"tags": [
@@ -488,6 +513,20 @@
}
}
},
"dashboard.AntrianPerKategori": {
"type": "object",
"properties": {
"id_kategori": {
"type": "integer"
},
"jumlah_antrean": {
"type": "integer"
},
"kategori": {
"type": "string"
}
}
},
"dokter.DokterResponse": {
"type": "object",
"properties": {
+25
View File
@@ -128,6 +128,15 @@ definitions:
tindakanTambahan:
type: string
type: object
dashboard.AntrianPerKategori:
properties:
id_kategori:
type: integer
jumlah_antrean:
type: integer
kategori:
type: string
type: object
dokter.DokterResponse:
properties:
hfis_code:
@@ -294,6 +303,22 @@ paths:
summary: Create Antrian Operasi
tags:
- Antrian Operasi
/dashboard/antrian-per-kategori/:
get:
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/dashboard.AntrianPerKategori'
type: array
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/shared.BaseErrorResponse'
summary: Get Antrian Per Kategori
tags:
- Dashboard
/reference/dokter/:
get:
parameters:
+40
View File
@@ -0,0 +1,40 @@
package dashboard
import (
"net/http"
baseResponse "antrian-operasi/internal/shared"
"github.com/gin-gonic/gin"
)
type DashboardHandler struct {
repo IDashboardRepository
}
func NewDashboardHandler(repo IDashboardRepository) DashboardHandler {
return DashboardHandler{repo}
}
// GetAntrianPerKategori godoc
// @Summary Get Antrian Per Kategori
// @Tags Dashboard
// @Success 200 {object} []AntrianPerKategori
// @Failure 500 {object} shared.BaseErrorResponse
// @Router /dashboard/antrian-per-kategori/ [get]
func (h DashboardHandler) GetAntrianPerKategori(c *gin.Context) {
data, err := h.repo.GetAntrianPerKategori(c)
if err != nil {
errorResponse := baseResponse.BaseErrorResponse{
Success: false,
Code: 500,
Message: err.Error(),
}
c.JSON(http.StatusInternalServerError, errorResponse)
return
}
response := baseResponse.ToBaseResponse(data, true, 200, "success get jumlah antrian per kategori")
c.JSON(http.StatusOK, response)
}
+7
View File
@@ -0,0 +1,7 @@
package dashboard
type AntrianPerKategori struct {
IdKategori int `db:"Kategori_operasi" json:"id_kategori"`
Kategori string `db:"Kategori" json:"kategori"`
JmlAntrian int `db:"jumlah_antrean" json:"jumlah_antrean"`
}
+82
View File
@@ -0,0 +1,82 @@
package dashboard
import (
"antrian-operasi/internal/database"
queryUtils "antrian-operasi/internal/utils/query"
"github.com/gin-gonic/gin"
)
const DB_NAME = "db_antrian"
const TBL_NAME = "data_pasien_operasi"
type IDashboardRepository interface {
GetAntrianPerKategori(c *gin.Context) ([]AntrianPerKategori, error)
}
type dashboardRepo struct {
queryBuilder *queryUtils.QueryBuilder
db database.Service
}
func NewRepository(dbService database.Service) IDashboardRepository {
queryBuilder := queryUtils.NewQueryBuilder(queryUtils.DBTypePostgreSQL).
SetAllowedColumns([]string{
"Kategori_operasi",
"Kategori",
"jumlah_antrean",
})
queryBuilder.SetSecurityOptions(false, 100)
return dashboardRepo{
queryBuilder: queryBuilder,
db: dbService,
}
}
func (r dashboardRepo) GetAntrianPerKategori(c *gin.Context) ([]AntrianPerKategori, error) {
var result []AntrianPerKategori
query := queryUtils.DynamicQuery{
From: TBL_NAME,
Aliases: "dpo",
Fields: []queryUtils.SelectField{
{Expression: "dpo.Kategori_operasi", Alias: "Kategori_operasi"},
{Expression: "dko.Kategori", Alias: "Kategori"},
{Expression: "COUNT(dpo.id)", Alias: "jumlah_antrean"},
},
GroupBy: []string{"dpo.Kategori_operasi", "dko.Kategori"},
Sort: []queryUtils.SortField{
{Column: "dpo.Kategori_operasi", Order: "DESC"},
},
}
query.Joins = []queryUtils.Join{
{
Type: "LEFT",
Table: "daftar_kategori_operasi",
Alias: "dko",
OnConditions: queryUtils.FilterGroup{
Filters: []queryUtils.DynamicFilter{
{
Column: "dpo.Kategori_operasi", Operator: queryUtils.OpEqual, Value: "dko.id",
},
},
},
},
}
dbconn, err := r.db.GetSQLXDB(DB_NAME)
if err != nil {
return result, err
}
err = r.queryBuilder.ExecuteQuery(
c, dbconn, query, &result)
if err != nil {
return result, err
}
return result, nil
}
+14
View File
@@ -0,0 +1,14 @@
package dashboard
import (
"antrian-operasi/internal/database"
"github.com/gin-gonic/gin"
)
func RegisterRoutes(r *gin.RouterGroup, dbService database.Service) {
dashboardRepo := NewRepository(dbService)
dashboardHandler := NewDashboardHandler(dashboardRepo)
r.GET("/antrian-per-kategori", dashboardHandler.GetAntrianPerKategori)
}
+5
View File
@@ -4,6 +4,7 @@ import (
"antrian-operasi/internal/config"
"antrian-operasi/internal/database"
antrianoperasi "antrian-operasi/internal/domain/antrian_operasi"
"antrian-operasi/internal/domain/dashboard"
"antrian-operasi/internal/domain/reference/dokter"
"antrian-operasi/internal/domain/reference/kategori"
"antrian-operasi/internal/domain/reference/pasien"
@@ -42,6 +43,10 @@ func RegisterRoutes(cfg *config.Config, dbService database.Service) *gin.Engine
dokter.RegisterRoutes(reference, dbService)
pasien.RegisterRoutes(reference, dbService)
}
dboard := api.Group("dashboard")
{
dashboard.RegisterRoutes(dboard, dbService)
}
return router
}