Merge pull request #51 from dikstub-rssa/fix/anything-moko

Fix/anything moko
This commit is contained in:
Dwi Atmoko Purbo Sakti
2025-10-08 12:27:16 +07:00
committed by GitHub
77 changed files with 1045 additions and 72 deletions
@@ -0,0 +1,2 @@
-- Modify "PersonAddress" table
ALTER TABLE "public"."PersonAddress" ADD COLUMN "PostalCode" character varying(6) NULL;
@@ -0,0 +1,12 @@
-- Create "Midwife" table
CREATE TABLE "public"."Midwife" (
"Id" bigserial NOT NULL,
"CreatedAt" timestamptz NULL,
"UpdatedAt" timestamptz NULL,
"DeletedAt" timestamptz NULL,
"Employee_Id" bigint NULL,
"IHS_Number" character varying(20) NULL,
PRIMARY KEY ("Id"),
CONSTRAINT "uni_Midwife_IHS_Number" UNIQUE ("IHS_Number"),
CONSTRAINT "fk_Midwife_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
@@ -0,0 +1,2 @@
-- Modify "DivisionPosition" table
ALTER TABLE "public"."DivisionPosition" ADD COLUMN "HeadStatus" boolean NULL;
+4 -1
View File
@@ -1,4 +1,4 @@
h1:4thtC22CJCQMIeVkYLmcFOT5w7S+bUUWy9wHZ21OHi8=
h1:+Bnziu7HqAI3VE4WAD5kHgKMKpTnOOy/BEpKYk4D17I=
20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k=
20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0=
20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI=
@@ -28,3 +28,6 @@ h1:4thtC22CJCQMIeVkYLmcFOT5w7S+bUUWy9wHZ21OHi8=
20251006045658.sql h1:3FmGCPCzjgMPdWDRodZTsx3KVaodd9zB9ilib69aewk=
20251006045928.sql h1:Z5g31PmnzNwk/OKdODcxZGm8fjJQdMFK32Xfnt3bRHg=
20251007022859.sql h1:FO03zEfaNEk/aXwY81d5Lp3MoBB9kPQuXlXJ4BPiSR8=
20251008031337.sql h1:l+sxUAGvcTfj3I6kAFHo+T6AYodC9k9GkR+jaKO2xXc=
20251008031554.sql h1:AqrVfIhSzY3PCy8ZlP5W91wn2iznfIuj5qQfubp6/94=
20251008052346.sql h1:kkRzCo2vImbvmG/HMhYcvUQ22IaaYqVSCIaYXtglia8=
@@ -11,12 +11,19 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
IndName string `json:"indName"`
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
IndName string `json:"indName"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code *string `json:"code"`
@@ -12,10 +12,17 @@ type CreateDto struct {
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Regency_Code string `json:"regency-code"`
Code string `json:"code"`
Name string `json:"name"`
Pagination ecore.Pagination
}
type ReadDetailDto struct {
@@ -10,6 +10,7 @@ type CreateDto struct {
Division_Id *uint16 `json:"division_id"`
Code string `json:"code" validate:"maxLength=10"`
Name string `json:"name" validate:"maxLength=50"`
HeadStatus bool `json:"headStatus"`
Employee_Id *uint `json:"employee_id"`
}
@@ -17,6 +18,7 @@ type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
@@ -24,6 +26,7 @@ type FilterDto struct {
Division_Id *uint16 `json:"division-id"`
Code string `json:"code"`
Name string `json:"name"`
HeadStatus *bool `json:"head-status"`
Employee_Id *uint `json:"employee-id"`
}
@@ -53,6 +56,7 @@ type ResponseDto struct {
Division *ed.Division `json:"division,omitempty"`
Code string `json:"code"`
Name string `json:"name"`
HeadStatus bool `json:"headStatus"`
Employee_Id *uint `json:"employee_id"`
Employee *ee.Employee `json:"employee,omitempty"`
}
@@ -62,6 +66,7 @@ func (d DivisionPosition) ToResponse() ResponseDto {
Division_Id: d.Division_Id,
Code: d.Code,
Name: d.Name,
HeadStatus: d.HeadStatus,
Employee_Id: d.Employee_Id,
Employee: d.Employee,
}
@@ -12,6 +12,7 @@ type DivisionPosition struct {
Division *ed.Division `json:"division" gorm:"foreignKey:Division_Id"`
Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"`
HeadStatus bool `json:"head_status"`
Employee_Id *uint `json:"employee_id"`
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
}
+9 -3
View File
@@ -10,12 +10,18 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
Search string `json:"search"`
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code *string `json:"code"`
@@ -17,6 +17,7 @@ type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
@@ -19,6 +19,7 @@ type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
@@ -10,12 +10,18 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
FilterDto
Includes string `json:"includes"`
Preloads []string
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code string `json:"code"`
@@ -13,10 +13,17 @@ type CreateDto struct {
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
Scope_Code *ere.CheckupScopeCode `json:"scope-code"`
Pagination ecore.Pagination
}
type ReadDetailDto struct {
@@ -10,11 +10,18 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code *string `json:"code"`
@@ -10,11 +10,18 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code *string `json:"code"`
@@ -0,0 +1,69 @@
package midwife
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ee "simrs-vx/internal/domain/main-entities/employee"
)
type CreateDto struct {
Employee_Id *uint `json:"employee_id"`
IHS_Number *string `json:"ihs_number" validate:"maxLength=20"`
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Pagination ecore.Pagination
}
type FilterDto struct {
Employee_Id *uint `json:"employee_id"`
IHS_Number *string `json:"ihs_number"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Employee_Id *uint `json:"employee_id"`
IHS_Number *string `json:"ihs_number"`
}
type UpdateDto struct {
Id uint `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint `json:"id"`
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
Count int `json:"count"`
}
type ResponseDto struct {
ecore.Main
Employee_Id *uint `json:"employee_id"`
Employee *ee.Employee `json:"employee,omitempty"`
IHS_Number *string `json:"ihs_number"`
}
func (d Midwife) ToResponse() ResponseDto {
resp := ResponseDto{
Employee_Id: d.Employee_Id,
Employee: d.Employee,
IHS_Number: d.IHS_Number,
}
resp.Main = d.Main
return resp
}
func ToResponseList(data []Midwife) []ResponseDto {
resp := make([]ResponseDto, len(data))
for i, u := range data {
resp[i] = u.ToResponse()
}
return resp
}
@@ -0,0 +1,13 @@
package midwife
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ee "simrs-vx/internal/domain/main-entities/employee"
)
type Midwife struct {
ecore.Main // adjust this according to the needs
Employee_Id *uint `json:"employee_id"`
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
}
@@ -10,6 +10,7 @@ type CreateDto struct {
Rt string `json:"rt" validate:"maxLength=2"`
Rw string `json:"rw" validate:"maxLength=2"`
Village_Code string `json:"village_code" validate:"maxLength=10"`
PostalCode string `json:"postalCode" validate:"maxLength=6"`
}
type ReadListDto struct {
@@ -43,6 +44,7 @@ type ResponseDto struct {
Rt string `json:"rt"`
Rw string `json:"rw"`
Village_Code string `json:"village_code"`
PostalCode string `json:"postalCode"`
}
func (d PersonAddress) ToResponse() ResponseDto {
@@ -52,6 +54,7 @@ func (d PersonAddress) ToResponse() ResponseDto {
Rt: d.Rt,
Rw: d.Rw,
Village_Code: d.Village_Code,
PostalCode: d.PostalCode,
}
resp.Main = d.Main
return resp
@@ -10,5 +10,6 @@ type PersonAddress struct {
Address string `json:"address" gorm:"size:150"`
Rt string `json:"rt" gorm:"size:2"`
Rw string `json:"rw" gorm:"size:2"`
PostalCode string `json:"postalCode" gorm:"size:6"`
Village_Code string `json:"village_code" gorm:"size:10"`
}
@@ -11,10 +11,17 @@ type CreateDto struct {
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
Regency_Code string `json:"regency-code"`
Pagination ecore.Pagination
}
type ReadDetailDto struct {
@@ -11,13 +11,19 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
IndName string `json:"indName"`
Search string `json:"search"`
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
IndName string `json:"indName"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code *string `json:"code"`
+15 -10
View File
@@ -2,6 +2,7 @@ package province
import (
ecore "simrs-vx/internal/domain/base-entities/core"
er "simrs-vx/internal/domain/main-entities/regency"
)
type CreateDto struct {
@@ -10,11 +11,18 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct {
Id int16 `json:"id"`
Code *string `json:"code"`
@@ -36,17 +44,14 @@ type MetaDto struct {
}
type ResponseDto struct {
Id int16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Id int16 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Regencies []*er.Regency `json:"regencies,omitempty"`
}
func (d Province) ToResponse() ResponseDto {
resp := ResponseDto{
Id: d.Id,
Code: d.Code,
Name: d.Name,
}
resp := ResponseDto(d)
return resp
}
+8 -1
View File
@@ -12,10 +12,17 @@ type CreateDto struct {
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Province_Code string `json:"province-code"`
Code string `json:"code"`
Name string `json:"name"`
Pagination ecore.Pagination
}
type ReadDetailDto struct {
+9 -3
View File
@@ -10,12 +10,18 @@ type CreateDto struct {
}
type ReadListDto struct {
Code string `json:"code"`
Name string `json:"name"`
Search string `json:"search"`
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code *string `json:"code"`
+8 -1
View File
@@ -11,10 +11,17 @@ type CreateDto struct {
}
type ReadListDto struct {
FilterDto
Includes string `json:"includes"`
Preloads []string `json:"-"`
Search string `json:"search"`
Pagination ecore.Pagination
}
type FilterDto struct {
District_Code string `json:"district-code"`
Code string `json:"code"`
Name string `json:"name"`
Pagination ecore.Pagination
}
type ReadDetailDto struct {
@@ -31,12 +31,14 @@ const (
ITGCEmpFee ItemGroupCode = "employee-fee"
ITGCDocFee ItemGroupCode = "doctor-fee"
IFGCBuilding InfraGroupCode = "building" // Bangunan
IFGCFloor InfraGroupCode = "floor" // Lantai
IFGCRoom InfraGroupCode = "room" // Ruang
IFGCChamber InfraGroupCode = "chamber" // Kamar
IFGCBed InfraGroupCode = "bed" // Ranjang
IFGCWarehouse InfraGroupCode = "warehouse" // Gudang/Depo
IFGCBuilding InfraGroupCode = "building" // Bangunan
IFGCFloor InfraGroupCode = "floor" // Lantai
IFGCRoom InfraGroupCode = "room" // Ruang
IFGCChamber InfraGroupCode = "chamber" // Kamar
IFGCBed InfraGroupCode = "bed" // Ranjang
IFGCWarehouse InfraGroupCode = "warehouse" // Gudang/Depo
IFGCCounter InfraGroupCode = "counter" // Counter
IFGCPubScreen InfraGroupCode = "public-screen" // Public Screen
UTCReg UnitTypeCode = "reg" // Registrasi
UTCExa UnitTypeCode = "exa" // Pemeriksaan
@@ -47,6 +47,7 @@ import (
medicinemethod "simrs-vx/internal/domain/main-entities/medicine-method"
medicinemix "simrs-vx/internal/domain/main-entities/medicine-mix"
medicinemixitem "simrs-vx/internal/domain/main-entities/medicine-mix-item"
midwife "simrs-vx/internal/domain/main-entities/midwife"
nurse "simrs-vx/internal/domain/main-entities/nurse"
nutritionist "simrs-vx/internal/domain/main-entities/nutritionist"
patient "simrs-vx/internal/domain/main-entities/patient"
@@ -147,5 +148,6 @@ func getMainEntities() []any {
&mcuordersubitem.McuOrderSubItem{},
&consultation.Consultation{},
&chemo.Chemo{},
&midwife.Midwife{},
}
}
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.De
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Device{}).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.DiagnoseSrc{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.District{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination))
@@ -20,5 +20,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.DivisionPosition) {
data.Division_Id = inputSrc.Division_Id
data.Code = inputSrc.Code
data.Name = inputSrc.Name
data.HeadStatus = inputSrc.HeadStatus
data.Employee_Id = inputSrc.Employee_Id
}
@@ -53,6 +53,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.DivisionPosition{}).
Preload("Division").
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
if input.OnlyHaveChildren {
tx = tx.Where(`
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,11 +47,11 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Et
tx = dg.I
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Ethnic{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
+1 -1
View File
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
if input.OnlyHaveChildren {
tx = tx.Where(`
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Installation{}).
@@ -53,6 +53,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.InsuranceCompany{}).
Scopes(gh.Filter(input.FilterDto)).
@@ -53,6 +53,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.It
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Item{}).
Scopes(gh.Filter(input.FilterDto)).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -51,7 +51,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.La
tx = tx.
Model(&e.Language{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Mc
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.McuSrcCategory{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Mc
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.McuSrc{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Mc
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.McuSubSrc{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.MedicalActionSrc{}).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.MedicineGroup{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.MedicineMethod{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -53,9 +53,9 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
tx = tx.Debug().
Model(&e.Medicine{}).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
@@ -0,0 +1,279 @@
package midwife
import (
e "simrs-vx/internal/domain/main-entities/midwife"
"strconv"
dg "github.com/karincake/apem/db-gorm-pg"
d "github.com/karincake/dodol"
pl "simrs-vx/pkg/logger"
pu "simrs-vx/pkg/use-case-helper"
"gorm.io/gorm"
)
const source = "midwife"
func Create(input e.CreateDto) (*d.Data, error) {
data := e.Midwife{}
event := pl.Event{
Feature: "Create",
Source: source,
}
// Start log
pl.SetLogInfo(&event, input, "started", "create")
err := dg.I.Transaction(func(tx *gorm.DB) error {
mwRunner := newMiddlewareRunner(&event, tx)
mwRunner.setMwType(pu.MWTPre)
// Run pre-middleware
if err := mwRunner.RunCreateMiddleware(createPreMw, &input, &data); err != nil {
return err
}
if resData, err := CreateData(input, &event, tx); err != nil {
return err
} else {
data = *resData
}
mwRunner.setMwType(pu.MWTPost)
// Run post-middleware
if err := mwRunner.RunCreateMiddleware(createPostMw, &input, &data); err != nil {
return err
}
pl.SetLogInfo(&event, nil, "complete")
return nil
})
if err != nil {
return nil, err
}
return &d.Data{
Meta: d.II{
"source": source,
"structure": "single-data",
"status": "created",
},
Data: data.ToResponse(),
}, nil
}
func ReadList(input e.ReadListDto) (*d.Data, error) {
var data *e.Midwife
var dataList []e.Midwife
var metaList *e.MetaDto
var err error
event := pl.Event{
Feature: "ReadList",
Source: source,
}
// Start log
pl.SetLogInfo(&event, input, "started", "readList")
err = dg.I.Transaction(func(tx *gorm.DB) error {
mwRunner := newMiddlewareRunner(&event, tx)
mwRunner.setMwType(pu.MWTPre)
// Run pre-middleware
if err := mwRunner.RunReadListMiddleware(readListPreMw, &input, data); err != nil {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
mwRunner.setMwType(pu.MWTPost)
// Run post-middleware
if err := mwRunner.RunReadListMiddleware(readListPostMw, &input, data); err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
return &d.Data{
Meta: d.IS{
"source": source,
"structure": "list-data",
"status": "fetched",
"page_number": strconv.Itoa(metaList.PageNumber),
"page_size": strconv.Itoa(metaList.PageSize),
"record_totalCount": strconv.Itoa(metaList.Count),
"record_currentCount": strconv.Itoa(len(dataList)),
},
Data: e.ToResponseList(dataList),
}, nil
}
func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
var data *e.Midwife
var err error
event := pl.Event{
Feature: "ReadDetail",
Source: source,
}
// Start log
pl.SetLogInfo(&event, input, "started", "readDetail")
err = dg.I.Transaction(func(tx *gorm.DB) error {
mwRunner := newMiddlewareRunner(&event, tx)
mwRunner.setMwType(pu.MWTPre)
// Run pre-middleware
if err := mwRunner.RunReadDetailMiddleware(readDetailPreMw, &input, data); err != nil {
return err
}
if data, err = ReadDetailData(input, &event, tx); err != nil {
return err
}
mwRunner.setMwType(pu.MWTPost)
// Run post-middleware
if err := mwRunner.RunReadDetailMiddleware(readDetailPostMw, &input, data); err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
return &d.Data{
Meta: d.IS{
"source": source,
"structure": "single-data",
"status": "fetched",
},
Data: data.ToResponse(),
}, nil
}
func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
var data *e.Midwife
var err error
event := pl.Event{
Feature: "Update",
Source: source,
}
// Start log
pl.SetLogInfo(&event, input, "started", "update")
err = dg.I.Transaction(func(tx *gorm.DB) error {
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
return err
}
mwRunner := newMiddlewareRunner(&event, tx)
mwRunner.setMwType(pu.MWTPre)
// Run pre-middleware
if err := mwRunner.RunUpdateMiddleware(readDetailPreMw, &rdDto, data); err != nil {
return err
}
if err := UpdateData(input, data, &event, tx); err != nil {
return err
}
pl.SetLogInfo(&event, nil, "complete")
mwRunner.setMwType(pu.MWTPost)
// Run post-middleware
if err := mwRunner.RunUpdateMiddleware(readDetailPostMw, &rdDto, data); err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
return &d.Data{
Meta: d.IS{
"source": source,
"structure": "single-data",
"status": "updated",
},
Data: data.ToResponse(),
}, nil
}
func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
var data *e.Midwife
var err error
event := pl.Event{
Feature: "Delete",
Source: source,
}
// Start log
pl.SetLogInfo(&event, input, "started", "delete")
err = dg.I.Transaction(func(tx *gorm.DB) error {
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
return err
}
mwRunner := newMiddlewareRunner(&event, tx)
mwRunner.setMwType(pu.MWTPre)
// Run pre-middleware
if err := mwRunner.RunDeleteMiddleware(readDetailPreMw, &rdDto, data); err != nil {
return err
}
if err := DeleteData(data, &event, tx); err != nil {
return err
}
mwRunner.setMwType(pu.MWTPost)
// Run post-middleware
if err := mwRunner.RunDeleteMiddleware(readDetailPostMw, &rdDto, data); err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
return &d.Data{
Meta: d.IS{
"source": source,
"structure": "single-data",
"status": "deleted",
},
Data: data.ToResponse(),
}, nil
}
@@ -0,0 +1,22 @@
/*
DESCRIPTION:
Any functions that are used internally by the use-case
*/
package midwife
import (
e "simrs-vx/internal/domain/main-entities/midwife"
)
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Midwife) {
var inputSrc *e.CreateDto
if inputT, ok := any(input).(*e.CreateDto); ok {
inputSrc = inputT
} else {
inputTemp := any(input).(*e.UpdateDto)
inputSrc = &inputTemp.CreateDto
}
data.Employee_Id = inputSrc.Employee_Id
data.IHS_Number = inputSrc.IHS_Number
}
@@ -0,0 +1,157 @@
package midwife
import (
e "simrs-vx/internal/domain/main-entities/midwife"
plh "simrs-vx/pkg/lib-helper"
pl "simrs-vx/pkg/logger"
pu "simrs-vx/pkg/use-case-helper"
dg "github.com/karincake/apem/db-gorm-pg"
gh "github.com/karincake/getuk"
"gorm.io/gorm"
)
func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Midwife, error) {
pl.SetLogInfo(event, nil, "started", "DBCreate")
data := e.Midwife{}
setData(&input, &data)
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if err := tx.Create(&data).Error; err != nil {
return nil, plh.HandleCreateError(input, event, err)
}
pl.SetLogInfo(event, nil, "complete")
return &data, nil
}
func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Midwife, *e.MetaDto, error) {
pl.SetLogInfo(event, input, "started", "DBReadList")
data := []e.Midwife{}
pagination := gh.Pagination{}
count := int64(0)
meta := e.MetaDto{}
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = tx.
Model(&e.Midwife{}).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
if err := tx.Find(&data).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, &meta, nil
}
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-get-fail",
Detail: "Database get failed",
Raw: err,
}
return nil, nil, pl.SetLogError(event, input)
}
meta.Count = int(count)
meta.PageNumber = pagination.PageNumber
meta.PageSize = pagination.PageSize
pl.SetLogInfo(event, nil, "complete")
return data, &meta, nil
}
func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e.Midwife, error) {
pl.SetLogInfo(event, input, "started", "DBReadDetail")
data := e.Midwife{}
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if input.Employee_Id != nil {
tx = tx.Where("\"Employee_Id\" = ?", *input.Employee_Id)
}
if input.Id > 0 {
tx = tx.Where("\"Id\" = ?", input.Id)
}
if err := tx.First(&data).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
return nil, processedErr
}
}
pl.SetLogInfo(event, nil, "complete")
return &data, nil
}
func UpdateData(input e.UpdateDto, data *e.Midwife, event *pl.Event, dbx ...*gorm.DB) error {
pl.SetLogInfo(event, data, "started", "DBUpdate")
setData(&input, data)
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if err := tx.Save(&data).Error; err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-update-fail",
Detail: "Database update failed",
Raw: err,
}
return pl.SetLogError(event, input)
}
pl.SetLogInfo(event, nil, "complete")
return nil
}
func DeleteData(data *e.Midwife, event *pl.Event, dbx ...*gorm.DB) error {
pl.SetLogInfo(event, data, "started", "DBDelete")
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if err := tx.Delete(&data).Error; err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-delete-fail",
Detail: "Database delete failed",
Raw: err,
}
return pl.SetLogError(event, data)
}
pl.SetLogInfo(event, nil, "complete")
return nil
}
@@ -0,0 +1,103 @@
package midwife
import (
e "simrs-vx/internal/domain/main-entities/midwife"
pl "simrs-vx/pkg/logger"
pu "simrs-vx/pkg/use-case-helper"
"gorm.io/gorm"
)
type middlewareRunner struct {
Event *pl.Event
Tx *gorm.DB
MwType pu.MWType
}
// NewMiddlewareExecutor creates a new middleware executor
func newMiddlewareRunner(event *pl.Event, tx *gorm.DB) *middlewareRunner {
return &middlewareRunner{
Event: event,
Tx: tx,
}
}
// ExecuteCreateMiddleware executes create middleware
func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.Midwife) error {
for _, middleware := range middlewares {
logData := pu.GetLogData(input, data)
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
if err := middleware.Func(input, data, me.Tx); err != nil {
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
}
pl.SetLogInfo(me.Event, nil, "complete")
}
return nil
}
func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.Midwife) error {
for _, middleware := range middlewares {
logData := pu.GetLogData(input, data)
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
if err := middleware.Func(input, data, me.Tx); err != nil {
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
}
pl.SetLogInfo(me.Event, nil, "complete")
}
return nil
}
func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Midwife) error {
for _, middleware := range middlewares {
logData := pu.GetLogData(input, data)
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
if err := middleware.Func(input, data, me.Tx); err != nil {
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
}
pl.SetLogInfo(me.Event, nil, "complete")
}
return nil
}
func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Midwife) error {
for _, middleware := range middlewares {
logData := pu.GetLogData(input, data)
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
if err := middleware.Func(input, data, me.Tx); err != nil {
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
}
pl.SetLogInfo(me.Event, nil, "complete")
}
return nil
}
func (me *middlewareRunner) RunDeleteMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Midwife) error {
for _, middleware := range middlewares {
logData := pu.GetLogData(input, data)
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
if err := middleware.Func(input, data, me.Tx); err != nil {
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
}
pl.SetLogInfo(me.Event, nil, "complete")
}
return nil
}
func (me *middlewareRunner) setMwType(mwType pu.MWType) {
me.MwType = mwType
}
@@ -0,0 +1,9 @@
package midwife
// example of middleware
// func init() {
// createPreMw = append(createPreMw,
// CreateMw{Name: "modif-input", Func: pm.ModifInput},
// CreateMw{Name: "check-data", Func: pm.CheckData},
// )
// }
@@ -0,0 +1,44 @@
/*
DESCRIPTION:
A sample, part of the package that contains type, constants, and/or variables.
In this sample it also provides type and variable regarding the needs of the
middleware to separate from main use-case which has the basic CRUD
functionality. The purpose of this is to make the code more maintainable.
*/
package midwife
import (
"gorm.io/gorm"
e "simrs-vx/internal/domain/main-entities/midwife"
)
type createMw struct {
Name string
Func func(input *e.CreateDto, data *e.Midwife, tx *gorm.DB) error
}
type readListMw struct {
Name string
Func func(input *e.ReadListDto, data *e.Midwife, tx *gorm.DB) error
}
type readDetailMw struct {
Name string
Func func(input *e.ReadDetailDto, data *e.Midwife, tx *gorm.DB) error
}
type UpdateMw = readDetailMw
type DeleteMw = readDetailMw
var createPreMw []createMw // preprocess middleware
var createPostMw []createMw // postprocess middleware
var readListPreMw []readListMw // ..
var readListPostMw []readListMw // ..
var readDetailPreMw []readDetailMw
var readDetailPostMw []readDetailMw
var updatePreMw []readDetailMw
var updatePostMw []readDetailMw
var deletePreMw []readDetailMw
var deletePostMw []readDetailMw
@@ -22,4 +22,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PersonAddress) {
data.Rt = inputSrc.Rt
data.Rw = inputSrc.Rw
data.Village_Code = inputSrc.Village_Code
data.PostalCode = inputSrc.PostalCode
}
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Ph
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.PharmacyCompany{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,11 +47,11 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Pr
tx = dg.I
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.ProcedureSrc{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Pr
tx = dg.I
}
tx = tx.
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.Debug().
Model(&e.Province{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination))
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Re
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Regency{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination))
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Sp
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Specialist{}).
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Su
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Subspecialist{}).
+1 -1
View File
@@ -53,7 +53,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Un
}
}
plh.SearchCodeOrName(input.Search, tx)
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Unit{}).
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
+8 -2
View File
@@ -47,11 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Uo
tx = dg.I
}
plh.SearchCodeOrName(input.Search, tx)
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Uom{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("\"CreatedAt\" DESC")
@@ -9,6 +9,7 @@ import (
ed "simrs-vx/internal/domain/main-entities/doctor"
ee "simrs-vx/internal/domain/main-entities/employee"
el "simrs-vx/internal/domain/main-entities/laborant"
em "simrs-vx/internal/domain/main-entities/midwife"
en "simrs-vx/internal/domain/main-entities/nurse"
et "simrs-vx/internal/domain/main-entities/nutritionist"
ep "simrs-vx/internal/domain/main-entities/pharmacist"
@@ -18,6 +19,7 @@ import (
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/employee"
ul "simrs-vx/internal/use-case/main-use-case/laborant"
um "simrs-vx/internal/use-case/main-use-case/midwife"
un "simrs-vx/internal/use-case/main-use-case/nurse"
ut "simrs-vx/internal/use-case/main-use-case/nutritionist"
upe "simrs-vx/internal/use-case/main-use-case/person"
@@ -150,6 +152,14 @@ func Create(input e.CreateDto) (*d.Data, error) {
if _, err := ul.CreateData(createLaborant, &event, tx); err != nil {
return err
}
case ero.UPCMwi:
createMidwife := em.CreateDto{
Employee_Id: &employeeData.Id,
IHS_Number: input.IHS_Number,
}
if _, err := um.CreateData(em.CreateDto(createMidwife), &event, tx); err != nil {
return err
}
default:
return errors.New("invalid employee position")
}
@@ -475,6 +485,26 @@ func Update(input e.UpdateDto) (*d.Data, error) {
if _, err := ul.CreateData(createLab, &event, tx); err != nil {
return err
}
case ero.UPCMwi:
readMidwife := em.ReadDetailDto{Employee_Id: &employeeData.Id}
readMidwifeData, err := um.ReadDetailData(readMidwife, &event, tx)
if err != nil {
return err
}
createMidwife := em.CreateDto{
Employee_Id: &employeeData.Id,
IHS_Number: input.IHS_Number,
}
if readMidwifeData != nil {
if err := um.UpdateData(em.UpdateDto{CreateDto: createMidwife}, readMidwifeData, &event, tx); err != nil {
return err
}
return nil
}
if _, err := um.CreateData(createMidwife, &event, tx); err != nil {
return err
}
default:
return errors.New("invalid employee position")
}
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
return err
}
if len(input.Includes) > 0 {
input.Preloads = pu.GetPreloads(input.Includes)
}
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
return err
}
@@ -47,9 +47,17 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Vi
tx = dg.I
}
if len(input.Preloads) > 0 {
for _, preload := range input.Preloads {
tx = tx.Preload(preload)
}
}
tx = plh.SearchCodeOrName(input.Search, tx)
tx = tx.
Model(&e.Village{}).
Scopes(gh.Filter(input)).
Scopes(gh.Filter(input.FilterDto)).
Count(&count).
Scopes(gh.Paginate(input, &pagination))
+4 -2
View File
@@ -8,10 +8,12 @@ import (
"gorm.io/gorm"
)
func SearchCodeOrName(search string, tx *gorm.DB) {
func SearchCodeOrName(search string, tx *gorm.DB) *gorm.DB {
if search != "" {
tx.Where("\"Code\" ILIKE ? OR \"Name\" ILIKE ?", "%"+search+"%", "%"+search+"%")
tx = tx.Where("\"Code\" ILIKE ? OR \"Name\" ILIKE ?", "%"+search+"%", "%"+search+"%")
}
return tx
}
func HandleCreateError(input any, event *pl.Event, err error) error {