diff --git a/handlers/dev/kesimpulan.handlers.go b/handlers/dev/kesimpulan.handlers.go new file mode 100644 index 0000000..781cd66 --- /dev/null +++ b/handlers/dev/kesimpulan.handlers.go @@ -0,0 +1,54 @@ +package dev_handlers + +import ( + "cpone/models" + "cpone/utils" + dev_kesimpulan "cpone/views/dev/kesimpulan" + "fmt" + + "github.com/labstack/echo/v4" + "go.uber.org/zap" +) + +type KesimpulanService interface { + GetListKesimpulanLab(id string) ([]models.ModelKesimpulanLab, error) +} + +func NewKesimpulanHandler(us KesimpulanService) *KesimpulanHandler { + return &KesimpulanHandler{ + KesimpulanService: us, + } +} + +type KesimpulanHandler struct { + KesimpulanService KesimpulanService +} + +func (h *KesimpulanHandler) HandleShowKesimpulanScreen(c echo.Context) error { + logger, _ := zap.NewProduction() + + tableID := utils.GenerateRandomID("tablebody") + id := c.Param("id") + + // table component + dataLab, err := h.KesimpulanService.GetListKesimpulanLab(id) + if err != nil { + defer logger.Sync() + logger.Info("ERROR GET LIST LAB", + zap.Any("error", err), + ) + fmt.Println(dataLab) + return err + } + + logger.Info("CEK DATA", + zap.Any("data lab", dataLab)) + + tableComponentLab := dev_kesimpulan.CardTableKesimpulan("3 Kelainan Pemeriksaan Lab terbesar :", dataLab, tableID) + + content := dev_kesimpulan.MainKesimpulan(tableID, + tableComponentLab) + + view := dev_kesimpulan.ShowKesimpulan("KESIMPULAN", content, dev_kesimpulan.CssKesimpulan(), dev_kesimpulan.JsKesimpulan()) + return utils.View(c, view) +} diff --git a/handlers/routes.go b/handlers/routes.go index 9327160..792791b 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -329,4 +329,9 @@ func SetupRoutesDev(app *echo.Echo, appStore db.AppStore) { dev.GET("/md/bahan/opendelete", devMdBahanHandlers.HandleOpenDeleteMdBahan) dev.POST("/md/bahan/closedeleteform", devMdBahanHandlers.HandleCloseDeleteMdBahan) dev.POST("/md/bahan/delete", devMdBahanHandlers.HandleDeleteMdBahan) + + // Kesimpulan + devKesimpulanServices := dev_services.NewServicesKesimpulan(appStore) + devKesimpuanHandler := dev_handlers.NewKesimpulanHandler(devKesimpulanServices) + dev.GET("/kesimpulan/:id", devKesimpuanHandler.HandleShowKesimpulanScreen) } diff --git a/models/kesimpulan.models.go b/models/kesimpulan.models.go new file mode 100644 index 0000000..768bd76 --- /dev/null +++ b/models/kesimpulan.models.go @@ -0,0 +1,7 @@ +package models + +type ModelKesimpulanLab struct { + Nomor string `db:"nomor"` + Test string `db:"Test"` + Total string `db:"total"` +} diff --git a/services/dev/kesimpulan.services.go b/services/dev/kesimpulan.services.go new file mode 100644 index 0000000..c8abfd8 --- /dev/null +++ b/services/dev/kesimpulan.services.go @@ -0,0 +1,92 @@ +package dev_services + +import ( + "cpone/db" + "cpone/models" + dbx "cpone/package/database" + "fmt" + + "go.uber.org/zap" +) + +func NewServicesKesimpulan(uStore db.AppStore) *KesimpulanServices { + return &KesimpulanServices{ + KesimpulanStore: uStore, + } +} + +type KesimpulanServices struct { + KesimpulanStore db.AppStore +} + +func (k *KesimpulanServices) GetListKesimpulanLab(id string) ([]models.ModelKesimpulanLab, error) { + logger, _ := zap.NewProduction() + var listLab []models.ModelKesimpulanLab + var dataTot []models.ModelKesimpulanLab + + qryTot := `select '' as nomor, + '' as Test, sum(total) as total + from( + select count(*) as total + FROM mgm_header + join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' + join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID + join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID + left join nat_test on Nat_TestCode = Mgm_HeaderNat_TestCode + + where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderType = 'L' + and Mgm_HeaderIsNormal = 'N' + group by Mgm_DetailMcu_KelainanID, Mgm_HeaderType ) x` + + err := dbx.Handlex.Select(&dataTot, qryTot, id) + if err != nil { + defer logger.Sync() + logger.Error("Error get total", + zap.Any("id", id), + zap.Any("total data", dataTot), + ) + // return dataTot, fmt.Errorf("QUERY_FAILED") + } + + // Extracting the Total value + var totalLab string + if len(dataTot) > 0 { + totalLab = dataTot[0].Total + } + + logger.Info("data", + zap.Any("id", id), + zap.Any("cek total", totalLab), + ) + query := `SELECT ROW_NUMBER() OVER () AS nomor, + ifnull(Nat_TestName ,Mcu_KelainanGroupName) as Test, + cast(count(Mgm_HeaderT_OrderHeaderID)/?*100 as decimal(2,0)) as total + + FROM mgm_header + join mgm_detail on Mgm_DetailMgm_HeaderID = Mgm_HeaderID and Mgm_DetailIsActive = 'Y' + join mcu_kelainan on Mgm_DetailMcu_KelainanID = Mcu_KelainanID + join mcu_kelainangroup on Mgm_DetailMcu_KelainanGroupID = Mcu_KelainanGroupID + left join nat_test on Nat_TestCode = Mgm_HeaderNat_TestCode + + where Mgm_HeaderIsActive = 'Y' and Mgm_HeaderMgm_McuID = ? AND Mgm_HeaderType = 'L' + and Mgm_HeaderIsNormal = 'N' + group by Mgm_DetailMcu_KelainanID, Mgm_HeaderType ORDER BY count(Mgm_HeaderT_OrderHeaderID) DESC + LIMIT 3` + + err = dbx.Handlex.Select(&listLab, query, totalLab, id) + + if err != nil { + defer logger.Sync() + logger.Error("Error get data lab", + zap.Any("id", id), + zap.Any("list data", listLab), + ) + return listLab, fmt.Errorf("QUERY_FAILED") + } + + logger.Info("data", + zap.Any("id", id), + zap.Any("cekkkk", listLab), + ) + return listLab, nil +} diff --git a/views/dev/kesimpulan/kesimpulan.templ b/views/dev/kesimpulan/kesimpulan.templ new file mode 100644 index 0000000..fdc2bec --- /dev/null +++ b/views/dev/kesimpulan/kesimpulan.templ @@ -0,0 +1,278 @@ +package dev_kesimpulan + +import ( + "cpone/layout" + "cpone/component/customtextfield" + "cpone/models" +) + +templ MainKesimpulan( + tableID string, + tablecontent templ.Component, +) { +
+ @customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", + Name: "tableID", + Type: "text", + Value: tableID}) +
+

Kesimpulan

+
+ @tablecontent +
+} + +templ CssKesimpulan() { + + + + +} + +templ JsKesimpulan() { +} + +templ ShowKesimpulan(title string, cmp templ.Component, css templ.Component, js templ.Component) { + @layout.PlaygroundLayout(title, css, js) { + @cmp + } +} diff --git a/views/dev/kesimpulan/kesimpulan_templ.go b/views/dev/kesimpulan/kesimpulan_templ.go new file mode 100644 index 0000000..061cf7f --- /dev/null +++ b/views/dev/kesimpulan/kesimpulan_templ.go @@ -0,0 +1,146 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_kesimpulan + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "cpone/component/customtextfield" + "cpone/layout" + "cpone/models" +) + +func MainKesimpulan( + tableID string, + tablecontent templ.Component, +) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = customtextfield.CustomTextFieldv2(models.CustomTextFieldv2Prm{ID: "tableID", + Name: "tableID", + Type: "text", + Value: tableID}).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

Kesimpulan

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tablecontent.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func CssKesimpulan() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var2 := templ.GetChildren(ctx) + if templ_7745c5c3_Var2 == nil { + templ_7745c5c3_Var2 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func JsKesimpulan() templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func ShowKesimpulan(title string, cmp templ.Component, css templ.Component, js templ.Component) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Var5 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Err = cmp.Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer) + } + return templ_7745c5c3_Err + }) + templ_7745c5c3_Err = layout.PlaygroundLayout(title, css, js).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} diff --git a/views/dev/kesimpulan/tableKesimpulan.templ b/views/dev/kesimpulan/tableKesimpulan.templ new file mode 100644 index 0000000..f8bdc2f --- /dev/null +++ b/views/dev/kesimpulan/tableKesimpulan.templ @@ -0,0 +1,46 @@ +package dev_kesimpulan + +import ( + "cpone/component/table" + "cpone/models" +) + +templ CardTableKesimpulan(title string, data []models.ModelKesimpulanLab, tableID string) { +
+
+

+ { title } +

+
+
+
+ @TableKesimpulanLab(data, tableID) +
+
+
+} + +templ TableKesimpulanLab(data []models.ModelKesimpulanLab, + tableID string) { +
+ @tablecomponent.TableV3([]string{"NO", "PEMERIKSAAN", "PERSENTASE"}, + []string{"5%", "70%", "25%"}, + RowKesimpulanLab(data), + ) +
+} + +templ RowKesimpulanLab(data []models.ModelKesimpulanLab) { + if len(data) == 0 { + + Data Tidak Ditemukan + + } + for _, v := range data { + + { v.Nomor } + { v.Test } + { v.Total } % + + } +} diff --git a/views/dev/kesimpulan/tableKesimpulan_templ.go b/views/dev/kesimpulan/tableKesimpulan_templ.go new file mode 100644 index 0000000..70f1db2 --- /dev/null +++ b/views/dev/kesimpulan/tableKesimpulan_templ.go @@ -0,0 +1,181 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.2.663 +package dev_kesimpulan + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +import ( + "cpone/component/table" + "cpone/models" +) + +func CardTableKesimpulan(title string, data []models.ModelKesimpulanLab, tableID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var1 := templ.GetChildren(ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 string + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\kesimpulan\tableKesimpulan.templ`, Line: 12, Col: 11} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = TableKesimpulanLab(data, tableID).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func TableKesimpulanLab(data []models.ModelKesimpulanLab, + tableID string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = tablecomponent.TableV3([]string{"NO", "PEMERIKSAAN", "PERSENTASE"}, + []string{"5%", "70%", "25%"}, + RowKesimpulanLab(data), + ).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +} + +func RowKesimpulanLab(data []models.ModelKesimpulanLab) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Var5 := templ.GetChildren(ctx) + if templ_7745c5c3_Var5 == nil { + templ_7745c5c3_Var5 = templ.NopComponent + } + ctx = templ.ClearChildren(ctx) + if len(data) == 0 { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("Data Tidak Ditemukan") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + for _, v := range data { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var6 string + templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(v.Nomor) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\kesimpulan\tableKesimpulan.templ`, Line: 41, Col: 16} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var7 string + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(v.Test) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\kesimpulan\tableKesimpulan.templ`, Line: 42, Col: 15} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var8 string + templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(v.Total) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views\dev\kesimpulan\tableKesimpulan.templ`, Line: 43, Col: 16} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" %") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +}