From 7e9914998f86fe7d813febfe7c2f556746ad566b Mon Sep 17 00:00:00 2001 From: vanilia Date: Sun, 2 Nov 2025 18:38:08 +0700 Subject: [PATCH 01/55] add rehab --- .../domain/main-entities/encounter/dto.go | 3 + internal/domain/main-entities/rehab/dto.go | 70 +++++ internal/use-case/main-use-case/rehab/case.go | 275 ++++++++++++++++++ .../use-case/main-use-case/rehab/helper.go | 23 ++ internal/use-case/main-use-case/rehab/lib.go | 144 +++++++++ .../main-use-case/rehab/middleware-runner.go | 103 +++++++ .../main-use-case/rehab/middleware.go | 9 + .../use-case/main-use-case/rehab/tycovar.go | 44 +++ 8 files changed, 671 insertions(+) create mode 100644 internal/domain/main-entities/rehab/dto.go create mode 100644 internal/use-case/main-use-case/rehab/case.go create mode 100644 internal/use-case/main-use-case/rehab/helper.go create mode 100644 internal/use-case/main-use-case/rehab/lib.go create mode 100644 internal/use-case/main-use-case/rehab/middleware-runner.go create mode 100644 internal/use-case/main-use-case/rehab/middleware.go create mode 100644 internal/use-case/main-use-case/rehab/tycovar.go diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 89f12caf..6a716d6e 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -16,6 +16,7 @@ import ( // internal - domain - main-entities evs "simrs-vx/internal/domain/bpjs-entities/vclaim-sep" + eam "simrs-vx/internal/domain/main-entities/ambulatory" ea "simrs-vx/internal/domain/main-entities/appointment" ed "simrs-vx/internal/domain/main-entities/doctor" ee "simrs-vx/internal/domain/main-entities/employee" @@ -48,6 +49,8 @@ type CreateDto struct { Appointment_Id *uint `json:"appointment_id"` RefTypeCode ere.RefTypeCode `json:"refTypeCode"` NewStatus bool `json:"newStatus"` + Ambulatory *eam.CreateDto `json:"ambulatory"` + Re pa.AuthInfo } diff --git a/internal/domain/main-entities/rehab/dto.go b/internal/domain/main-entities/rehab/dto.go new file mode 100644 index 00000000..0cec61d8 --- /dev/null +++ b/internal/domain/main-entities/rehab/dto.go @@ -0,0 +1,70 @@ +package rehab + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ed "simrs-vx/internal/domain/main-entities/doctor" +) + +type CreateDto struct { + Encounter_Id *uint `json:"encounter_id"` + Doctor_Id *uint `json:"doctor_id"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Encounter_Id *uint `json:"encounter-id"` + Doctor_Id *uint `json:"doctor-id"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` + Includes string `json:"includes"` +} + +type UpdateDto struct { + Id uint16 `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint16 `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Encounter_Id *uint `json:"encounter_id"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` +} + +func (d Rehab) ToResponse() ResponseDto { + resp := ResponseDto{ + Encounter_Id: d.Encounter_Id, + Doctor_Id: d.Doctor_Id, + Doctor: d.Doctor, + AllocatedVisitCount: d.AllocatedVisitCount, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []Rehab) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/use-case/main-use-case/rehab/case.go b/internal/use-case/main-use-case/rehab/case.go new file mode 100644 index 00000000..0d7a243e --- /dev/null +++ b/internal/use-case/main-use-case/rehab/case.go @@ -0,0 +1,275 @@ +package rehab + +import ( + e "simrs-vx/internal/domain/main-entities/rehab" + "strconv" + + pl "simrs-vx/pkg/logger" + pu "simrs-vx/pkg/use-case-helper" + + dg "github.com/karincake/apem/db-gorm-pg" + d "github.com/karincake/dodol" + "gorm.io/gorm" +) + +const source = "rehab" + +func Create(input e.CreateDto) (*d.Data, error) { + data := e.Rehab{} + + 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.Rehab + var dataList []e.Rehab + 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 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.Rehab + 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: input.Id} + var data *e.Rehab + 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: input.Id} + var data *e.Rehab + 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 + +} diff --git a/internal/use-case/main-use-case/rehab/helper.go b/internal/use-case/main-use-case/rehab/helper.go new file mode 100644 index 00000000..5c06ca0a --- /dev/null +++ b/internal/use-case/main-use-case/rehab/helper.go @@ -0,0 +1,23 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package rehab + +import ( + e "simrs-vx/internal/domain/main-entities/rehab" +) + +func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Rehab) { + var inputSrc *e.CreateDto + if inputT, ok := any(input).(*e.CreateDto); ok { + inputSrc = inputT + } else { + inputTemp := any(input).(*e.UpdateDto) + inputSrc = &inputTemp.CreateDto + } + + data.Encounter_Id = inputSrc.Encounter_Id + data.Doctor_Id = inputSrc.Doctor_Id + data.AllocatedVisitCount = inputSrc.AllocatedVisitCount +} diff --git a/internal/use-case/main-use-case/rehab/lib.go b/internal/use-case/main-use-case/rehab/lib.go new file mode 100644 index 00000000..faee1b35 --- /dev/null +++ b/internal/use-case/main-use-case/rehab/lib.go @@ -0,0 +1,144 @@ +package rehab + +import ( + "errors" + e "simrs-vx/internal/domain/main-entities/rehab" + 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.Rehab, error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + data := e.Rehab{} + 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.Rehab, *e.MetaDto, error) { + pl.SetLogInfo(event, input, "started", "DBReadList") + data := []e.Rehab{} + pagination := gh.Pagination{} + count := int64(0) + meta := e.MetaDto{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + tx = tx. + Model(&e.Rehab{}). + Scopes(gh.Preload(input.Includes)). + Scopes(gh.Filter(input.FilterDto)). + Count(&count). + Scopes(gh.Paginate(input, &pagination)). + Order("\"CreatedAt\" DESC") + + if err := tx.Find(&data).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, &meta, nil + } + return nil, nil, plh.HandleListError(input, event, err) + } + + 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.Rehab, error) { + pl.SetLogInfo(event, input, "started", "DBReadDetail") + data := e.Rehab{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if err := tx. + Scopes(gh.Preload(input.Includes)). + First(&data, input.Id). + 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.Rehab, 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.Rehab, 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 +} diff --git a/internal/use-case/main-use-case/rehab/middleware-runner.go b/internal/use-case/main-use-case/rehab/middleware-runner.go new file mode 100644 index 00000000..8c0af77a --- /dev/null +++ b/internal/use-case/main-use-case/rehab/middleware-runner.go @@ -0,0 +1,103 @@ +package rehab + +import ( + e "simrs-vx/internal/domain/main-entities/rehab" + 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.Rehab) 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.Rehab) 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.Rehab) 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.Rehab) 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.Rehab) 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 +} diff --git a/internal/use-case/main-use-case/rehab/middleware.go b/internal/use-case/main-use-case/rehab/middleware.go new file mode 100644 index 00000000..dadf6b9b --- /dev/null +++ b/internal/use-case/main-use-case/rehab/middleware.go @@ -0,0 +1,9 @@ +package rehab + +// example of middleware +// func init() { +// createPreMw = append(createPreMw, +// CreateMw{Name: "modif-input", Func: pm.ModifInput}, +// CreateMw{Name: "check-data", Func: pm.CheckData}, +// ) +// } diff --git a/internal/use-case/main-use-case/rehab/tycovar.go b/internal/use-case/main-use-case/rehab/tycovar.go new file mode 100644 index 00000000..4899ec44 --- /dev/null +++ b/internal/use-case/main-use-case/rehab/tycovar.go @@ -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 rehab + +import ( + "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/rehab" +) + +type createMw struct { + Name string + Func func(input *e.CreateDto, data *e.Rehab, tx *gorm.DB) error +} + +type readListMw struct { + Name string + Func func(input *e.ReadListDto, data *e.Rehab, tx *gorm.DB) error +} + +type readDetailMw struct { + Name string + Func func(input *e.ReadDetailDto, data *e.Rehab, 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 From 616f90096865b24a0930b17c3e2ade01eb255150 Mon Sep 17 00:00:00 2001 From: vanilia Date: Sun, 2 Nov 2025 18:53:35 +0700 Subject: [PATCH 02/55] add rehab --- internal/domain/main-entities/ambulatory/dto.go | 17 ++++++++++------- internal/domain/main-entities/encounter/dto.go | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/domain/main-entities/ambulatory/dto.go b/internal/domain/main-entities/ambulatory/dto.go index 455f7f02..42ece735 100644 --- a/internal/domain/main-entities/ambulatory/dto.go +++ b/internal/domain/main-entities/ambulatory/dto.go @@ -2,13 +2,13 @@ package ambulatory import ( ecore "simrs-vx/internal/domain/base-entities/core" - ee "simrs-vx/internal/domain/main-entities/encounter" ere "simrs-vx/internal/domain/references/encounter" ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"` + Encounter_Id *uint `json:"encounter_id"` + Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"` + VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` } type ReadListDto struct { @@ -43,13 +43,16 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Class_Code ere.AmbulatoryClassCode `json:"class_code"` + Encounter_Id *uint `json:"encounter_id"` + Class_Code ere.AmbulatoryClassCode `json:"class_code"` + VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` } func (d Ambulatory) ToResponse() ResponseDto { - resp := ResponseDto{} + resp := ResponseDto{ + Class_Code: d.Class_Code, + VisitMode_Code: d.VisitMode_Code, + } resp.Main = d.Main return resp } diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 6a716d6e..d20d53cf 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -22,6 +22,7 @@ import ( ee "simrs-vx/internal/domain/main-entities/employee" eir "simrs-vx/internal/domain/main-entities/internal-reference" ep "simrs-vx/internal/domain/main-entities/patient" + er "simrs-vx/internal/domain/main-entities/rehab/base" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" eu "simrs-vx/internal/domain/main-entities/unit" @@ -50,7 +51,7 @@ type CreateDto struct { RefTypeCode ere.RefTypeCode `json:"refTypeCode"` NewStatus bool `json:"newStatus"` Ambulatory *eam.CreateDto `json:"ambulatory"` - Re + Rehab *er.Basic `json:"rehab"` pa.AuthInfo } From 16bb34b8b404a3b947f0513d0df7438cc804bfc3 Mon Sep 17 00:00:00 2001 From: vanilia Date: Sun, 2 Nov 2025 20:58:13 +0700 Subject: [PATCH 03/55] add validation for class_code ambulatory --- .../encounter/request-validation.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index 025298fc..5963abcb 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -63,3 +63,26 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) return true } + +func validateRequestCreate(w http.ResponseWriter, i e.CreateDto) (valid bool) { + switch { + case i.Class_Code == ere.ECAmbulatory: + if i.Ambulatory == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "ambulatory required", + }) + } + } + + if i.Class_Code == ere.ECAmbulatory && i.Ambulatory.Class_Code == ere.ACCRme && i.Ambulatory.VisitMode_Code == ere.VMCAdm { + if *i.Rehab.AllocatedVisitCount == 0 { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "rehab.AllocatedVisitCode required", + }) + return + } + } + return +} From 79f5c2c7dbf9ccadf7283b4fc6c83b99584e3a5d Mon Sep 17 00:00:00 2001 From: vanilia Date: Sun, 2 Nov 2025 21:02:49 +0700 Subject: [PATCH 04/55] update dto encounter --- internal/domain/main-entities/encounter/dto.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index d20d53cf..e4b9a521 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -19,7 +19,9 @@ import ( eam "simrs-vx/internal/domain/main-entities/ambulatory" ea "simrs-vx/internal/domain/main-entities/appointment" ed "simrs-vx/internal/domain/main-entities/doctor" + eem "simrs-vx/internal/domain/main-entities/emergency" ee "simrs-vx/internal/domain/main-entities/employee" + ei "simrs-vx/internal/domain/main-entities/inpatient" eir "simrs-vx/internal/domain/main-entities/internal-reference" ep "simrs-vx/internal/domain/main-entities/patient" er "simrs-vx/internal/domain/main-entities/rehab/base" @@ -51,6 +53,8 @@ type CreateDto struct { RefTypeCode ere.RefTypeCode `json:"refTypeCode"` NewStatus bool `json:"newStatus"` Ambulatory *eam.CreateDto `json:"ambulatory"` + Emergency *eem.CreateDto `json:"emergency"` + Inpatient *ei.Inpatient `json:"inpatient"` Rehab *er.Basic `json:"rehab"` pa.AuthInfo From 388072ef517e064521afcda4bb3b7701e627a0fe Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Mon, 3 Nov 2025 08:03:09 +0700 Subject: [PATCH 05/55] feat/trx-order: ref changes for MCU --- .../domain/main-entities/mcu-order/dto.go | 1 + .../domain/main-entities/mcu-order/entity.go | 3 +-- .../main-entities/mcu-src-category/dto.go | 22 +++++++++---------- .../main-entities/mcu-src-category/entity.go | 10 ++++----- .../domain/references/clinical/clinical.go | 6 +++++ .../domain/references/encounter/encounter.go | 6 ----- .../main-use-case/mcu-order/helper.go | 1 + 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/internal/domain/main-entities/mcu-order/dto.go b/internal/domain/main-entities/mcu-order/dto.go index 3d042c2f..e63a3e08 100644 --- a/internal/domain/main-entities/mcu-order/dto.go +++ b/internal/domain/main-entities/mcu-order/dto.go @@ -28,6 +28,7 @@ type CreateDto struct { Number uint8 `json:"number"` Temperature float64 `json:"temperature"` UrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"urgencyLevel_code"` + Scope_Code ercl.McuScopeCode `json:"scope_code"` pa.AuthInfo } diff --git a/internal/domain/main-entities/mcu-order/entity.go b/internal/domain/main-entities/mcu-order/entity.go index d2b81e58..bf4e2e77 100644 --- a/internal/domain/main-entities/mcu-order/entity.go +++ b/internal/domain/main-entities/mcu-order/entity.go @@ -8,7 +8,6 @@ import ( ercl "simrs-vx/internal/domain/references/clinical" erc "simrs-vx/internal/domain/references/common" - ere "simrs-vx/internal/domain/references/encounter" ) type McuOrder struct { @@ -23,7 +22,7 @@ type McuOrder struct { Number uint8 `json:"number"` Temperature float64 `json:"temperature"` UrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"urgencyLevel_code" gorm:"not null;size:15"` - Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"index;size:10"` + Scope_Code ercl.McuScopeCode `json:"scope_code" gorm:"index;size:10"` } func (d McuOrder) IsCompleted() bool { diff --git a/internal/domain/main-entities/mcu-src-category/dto.go b/internal/domain/main-entities/mcu-src-category/dto.go index 278c5e5c..c1988790 100644 --- a/internal/domain/main-entities/mcu-src-category/dto.go +++ b/internal/domain/main-entities/mcu-src-category/dto.go @@ -3,13 +3,13 @@ package division import ( ecore "simrs-vx/internal/domain/base-entities/core" - ere "simrs-vx/internal/domain/references/encounter" + erc "simrs-vx/internal/domain/references/clinical" ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=20"` - Name string `json:"name" validate:"maxLength=50"` - Scope_Code *ere.CheckupScopeCode `json:"scope_code" validate:"maxLength=10"` + Code string `json:"code" validate:"maxLength=20"` + Name string `json:"name" validate:"maxLength=50"` + Scope_Code erc.McuScopeCode `json:"scope_code" validate:"maxLength=10"` } type ReadListDto struct { @@ -20,10 +20,10 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` - Scope_Code *ere.CheckupScopeCode `json:"scope-code"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code string `json:"code"` + Name string `json:"name"` + Scope_Code *erc.McuScopeCode `json:"scope-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { @@ -48,9 +48,9 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Code string `json:"code"` - Name string `json:"name"` - Scope_Code *ere.CheckupScopeCode `json:"scope_code"` + Code string `json:"code"` + Name string `json:"name"` + Scope_Code erc.McuScopeCode `json:"scope_code"` } func (d McuSrcCategory) ToResponse() ResponseDto { diff --git a/internal/domain/main-entities/mcu-src-category/entity.go b/internal/domain/main-entities/mcu-src-category/entity.go index 3a0d08ca..8fc801b9 100644 --- a/internal/domain/main-entities/mcu-src-category/entity.go +++ b/internal/domain/main-entities/mcu-src-category/entity.go @@ -2,12 +2,12 @@ package division import ( ecore "simrs-vx/internal/domain/base-entities/core" - ere "simrs-vx/internal/domain/references/encounter" + erc "simrs-vx/internal/domain/references/clinical" ) type McuSrcCategory struct { - ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:20"` - Name string `json:"name" gorm:"size:50"` - Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"index;size:10"` + ecore.SmallMain // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:20"` + Name string `json:"name" gorm:"size:50"` + Scope_Code erc.McuScopeCode `json:"scope_code" gorm:"index;size:10"` } diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index c0eb3594..9b2af591 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -9,6 +9,7 @@ type ( InstructionCode string HeadToToeCode string McuUrgencyLevelCode string + McuScopeCode string SoapiTypeCode string MedicalAction string VehicleTypeCode string @@ -113,6 +114,11 @@ const ( MULCPF McuUrgencyLevelCode = "priority-form" // Form Prioritas MULCRT McuUrgencyLevelCode = "routine" // Pemeriksaan Rutin + MSCRad McuScopeCode = "rad" // Pemeriksaan Rutin + MSCCpLab McuScopeCode = "cp-lab" // Pemeriksaan Rutin + MSCApLab McuScopeCode = "ap-lab" // Pemeriksaan Rutin + MSCMicLab McuScopeCode = "mic-lab" // Pemeriksaan Rutin + STCEarlyNurse SoapiTypeCode = "early-nurse" // Kajian Awal Medis STCEEarlyMedic SoapiTypeCode = "early-medic" // Kajian Awal Rehab Medis STCEarlyRehab SoapiTypeCode = "early-rehab" // Kajian Awal Rehab Medik diff --git a/internal/domain/references/encounter/encounter.go b/internal/domain/references/encounter/encounter.go index eeccb8fe..c2d150be 100644 --- a/internal/domain/references/encounter/encounter.go +++ b/internal/domain/references/encounter/encounter.go @@ -8,7 +8,6 @@ type ( PersonConditionCode string EmergencyClassCode string OutpatientClassCode string - CheckupScopeCode string AmbulatoryClassCode string InpatientClassCode string UploadCode string @@ -64,11 +63,6 @@ const ( OCCHcu OutpatientClassCode = "hcu" // HCU OCCVk OutpatientClassCode = "vk" // Verlos kamer - CSCLab CheckupScopeCode = "lab" // Laboratorium - CSCMLab CheckupScopeCode = "mic-lab" // Microbacterial Laboratorium - CSCPLab CheckupScopeCode = "pa-lab" // Patology Anatomy Laboratorium - CSCRad CheckupScopeCode = "radiology" // Radiology - ACCReg AmbulatoryClassCode = "reg" // Regular ACCRme AmbulatoryClassCode = "rme" // Rehab Medik ACCCad AmbulatoryClassCode = "chemo-adm" // Chemotherapy diff --git a/internal/use-case/main-use-case/mcu-order/helper.go b/internal/use-case/main-use-case/mcu-order/helper.go index c7d6fc6f..7c21f1f6 100644 --- a/internal/use-case/main-use-case/mcu-order/helper.go +++ b/internal/use-case/main-use-case/mcu-order/helper.go @@ -28,4 +28,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuOrder) { data.Temperature = inputSrc.Temperature data.UrgencyLevel_Code = inputSrc.UrgencyLevel_Code data.Doctor_Id = inputSrc.Doctor_Id + data.Scope_Code = inputSrc.Scope_Code } From 9c39966bea1b2d6dac1fa31e6525b638fce021c1 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Mon, 3 Nov 2025 14:57:04 +0700 Subject: [PATCH 06/55] dev: hotfix, adjust auth's attributes --- internal/lib/auth/tycovar.go | 14 ++++++------ .../main-use-case/authentication/case.go | 22 +++++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/internal/lib/auth/tycovar.go b/internal/lib/auth/tycovar.go index 881a9072..44426d4b 100644 --- a/internal/lib/auth/tycovar.go +++ b/internal/lib/auth/tycovar.go @@ -13,13 +13,13 @@ type AuthInfo struct { User_Name string User_ContractPosition_code string Employee_Position_Code *string - Employee_Id *int - Doctor_Id *int - Nurse_Id *int - Midwife_Id *int - Nutritionist_Id *int - Laborant_Id *int - Pharmachist_Id *int + Employee_Id *uint + Doctor_Id *uint + Nurse_Id *uint + Midwife_Id *uint + Nutritionist_Id *uint + Laborant_Id *uint + Pharmachist_Id *uint Intern_Position_Code *string Roles []string // User_DivisionPositions []DivisionPosition diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 6c645208..d00889ee 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -308,14 +308,14 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err data.User_ContractPosition_code = checkStrClaims(claims, "contractPosition_code") data.Employee_Position_Code = checkStrPtrClaims(claims, "employee_position_code") - data.Doctor_Id = checkIntPtrClaims(claims, "doctor_id") - data.Nurse_Id = checkIntPtrClaims(claims, "nurse_id") - data.Midwife_Id = checkIntPtrClaims(claims, "midwife_id") - data.Nutritionist_Id = checkIntPtrClaims(claims, "nutritionist_id") - data.Laborant_Id = checkIntPtrClaims(claims, "laborant_id") - data.Pharmachist_Id = checkIntPtrClaims(claims, "pharmachist_id") + data.Doctor_Id = checkUntPtrClaims(claims, "doctor_id") + data.Nurse_Id = checkUntPtrClaims(claims, "nurse_id") + data.Midwife_Id = checkUntPtrClaims(claims, "midwife_id") + data.Nutritionist_Id = checkUntPtrClaims(claims, "nutritionist_id") + data.Laborant_Id = checkUntPtrClaims(claims, "laborant_id") + data.Pharmachist_Id = checkUntPtrClaims(claims, "pharmachist_id") data.Intern_Position_Code = checkStrPtrClaims(claims, "intern_position_code") - data.Employee_Id = checkIntPtrClaims(claims, "employee_id") + data.Employee_Id = checkUntPtrClaims(claims, "employee_id") return } return nil, d.FieldError{Code: "token", Message: "token-invalid"} @@ -354,3 +354,11 @@ func checkIntPtrClaims(claim map[string]interface{}, key string) *int { } return nil } + +func checkUntPtrClaims(claim map[string]interface{}, key string) *uint { + if v, exist := claim[key]; exist && v != nil { + val := uint(v.(float64)) + return &val + } + return nil +} From 8e35aafca2450e0398b3ec32245374f46ed03d38 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Mon, 3 Nov 2025 14:59:03 +0700 Subject: [PATCH 07/55] feat/trx-orders: changed set value for Doctor_Id and the setData --- internal/use-case/main-use-case/prescription/helper.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/use-case/main-use-case/prescription/helper.go b/internal/use-case/main-use-case/prescription/helper.go index 8b85884a..35c55512 100644 --- a/internal/use-case/main-use-case/prescription/helper.go +++ b/internal/use-case/main-use-case/prescription/helper.go @@ -37,7 +37,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Prescription) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + // data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Id = inputSrc.AuthInfo.Doctor_Id data.IssuedAt = inputSrc.IssuedAt } From ec877d73c23fafd19023c0d90fd310bab5fe42cd Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 3 Nov 2025 15:44:03 +0700 Subject: [PATCH 08/55] feat (control-letter): add crud, renaming sync directory --- .../main-entities/control-letter/dto.go | 11 +- .../main-handler/consultation/handler.go | 2 +- .../main-handler/control-letter/handler.go | 71 +++++ .../interface/main-handler/main-handler.go | 2 + .../.keep | 0 .../main-use-case/control-letter/case.go | 299 ++++++++++++++++++ .../main-use-case/control-letter/helper.go | 25 ++ .../main-use-case/control-letter/lib.go | 144 +++++++++ .../control-letter/middleware-runner.go | 103 ++++++ .../control-letter/middleware.go | 9 + .../main-use-case/control-letter/tycovar.go | 44 +++ .../.keep | 0 pkg/use-case-helper/use-case-helper.go | 7 + 13 files changed, 711 insertions(+), 6 deletions(-) create mode 100644 internal/interface/main-handler/control-letter/handler.go rename internal/use-case/{main-sync-case => main-sync-use-case}/.keep (100%) create mode 100644 internal/use-case/main-use-case/control-letter/case.go create mode 100644 internal/use-case/main-use-case/control-letter/helper.go create mode 100644 internal/use-case/main-use-case/control-letter/lib.go create mode 100644 internal/use-case/main-use-case/control-letter/middleware-runner.go create mode 100644 internal/use-case/main-use-case/control-letter/middleware.go create mode 100644 internal/use-case/main-use-case/control-letter/tycovar.go rename internal/use-case/{simgos-sync-case => simgos-sync-use-case}/.keep (100%) diff --git a/internal/domain/main-entities/control-letter/dto.go b/internal/domain/main-entities/control-letter/dto.go index 270ff7b5..4beadd69 100644 --- a/internal/domain/main-entities/control-letter/dto.go +++ b/internal/domain/main-entities/control-letter/dto.go @@ -41,7 +41,8 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id uint16 `json:"id"` + Includes string `json:"includes"` } type UpdateDto struct { @@ -69,13 +70,13 @@ type MetaDto struct { type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` Unit_Id *uint `json:"unit_id"` - Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` + Unit *eu.Unit `json:"unit,omitempty"` Specialist_Id *uint `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"` + Specialist *es.Specialist `json:"specialist,omitempty"` Subspecialist_Id *uint `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` Date *time.Time `json:"date"` } diff --git a/internal/interface/main-handler/consultation/handler.go b/internal/interface/main-handler/consultation/handler.go index 2810d2f3..e67accd4 100644 --- a/internal/interface/main-handler/consultation/handler.go +++ b/internal/interface/main-handler/consultation/handler.go @@ -1,4 +1,4 @@ -package device +package consultation import ( "net/http" diff --git a/internal/interface/main-handler/control-letter/handler.go b/internal/interface/main-handler/control-letter/handler.go new file mode 100644 index 00000000..d6a73fe0 --- /dev/null +++ b/internal/interface/main-handler/control-letter/handler.go @@ -0,0 +1,71 @@ +package controlletter + +import ( + "net/http" + + rw "github.com/karincake/risoles" + sf "github.com/karincake/semprit" + + // ua "github.com/karincake/tumpeng/auth/svc" + + e "simrs-vx/internal/domain/main-entities/control-letter" + u "simrs-vx/internal/use-case/main-use-case/control-letter" +) + +type myBase struct{} + +var O myBase + +func (obj myBase) Create(w http.ResponseWriter, r *http.Request) { + dto := e.CreateDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + res, err := u.Create(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { + dto := e.ReadListDto{} + sf.UrlQueryParam(&dto, *r.URL) + res, err := u.ReadList(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + dto := e.ReadDetailDto{} + dto.Id = uint16(id) + res, err := u.ReadDetail(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.UpdateDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + dto.Id = uint(id) + res, err := u.Update(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.DeleteDto{} + dto.Id = uint(id) + res, err := u.Delete(dto) + rw.DataResponse(w, res, err) +} diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index bedf3b71..baea92da 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -10,6 +10,7 @@ import ( auth "simrs-vx/internal/interface/main-handler/authentication" chemo "simrs-vx/internal/interface/main-handler/chemo" consultation "simrs-vx/internal/interface/main-handler/consultation" + controlletter "simrs-vx/internal/interface/main-handler/control-letter" counter "simrs-vx/internal/interface/main-handler/counter" deviceorder "simrs-vx/internal/interface/main-handler/device-order" deviceorderitem "simrs-vx/internal/interface/main-handler/device-order-item" @@ -251,6 +252,7 @@ func SetRoutes() http.Handler { "PATCH /{id}/reject": chemo.O.Reject, }) + hc.RegCrud(r, "/v1/control-letter", controlletter.O) hc.RegCrud(r, "/v1/internal-reference", internalreference.O) hc.RegCrud(r, "/v1/ambulance-transport-req", ambulancetransportrequest.O) hc.RegCrud(r, "/v1/responsible-doctor-hist", responsibledoctorhist.O) diff --git a/internal/use-case/main-sync-case/.keep b/internal/use-case/main-sync-use-case/.keep similarity index 100% rename from internal/use-case/main-sync-case/.keep rename to internal/use-case/main-sync-use-case/.keep diff --git a/internal/use-case/main-use-case/control-letter/case.go b/internal/use-case/main-use-case/control-letter/case.go new file mode 100644 index 00000000..7ff38a63 --- /dev/null +++ b/internal/use-case/main-use-case/control-letter/case.go @@ -0,0 +1,299 @@ +package controlletter + +import ( + "errors" + "strconv" + + e "simrs-vx/internal/domain/main-entities/control-letter" + ue "simrs-vx/internal/use-case/main-use-case/encounter" + + 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 = "control-letter" + +func Create(input e.CreateDto) (*d.Data, error) { + data := e.ControlLetter{} + + 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 pu.IsDateBeforeNow(input.Date) { + return errors.New("date is in the past") + } + + // check if encounter is done + if ue.IsDone(*input.Encounter_Id, &event, tx) { + return errors.New("encounter is already done") + } + + 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.ControlLetter + var dataList []e.ControlLetter + 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 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.ControlLetter + 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 + } + + input.Includes = "encounter,unit,specialist,subspecialist" + + 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.ControlLetter + 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 pu.IsDateBeforeNow(input.Date) { + return errors.New("date is in the past") + } + + // check if encounter is done + if ue.IsDone(*input.Encounter_Id, &event, tx) { + return errors.New("encounter is already done") + } + + 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.ControlLetter + 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 + +} diff --git a/internal/use-case/main-use-case/control-letter/helper.go b/internal/use-case/main-use-case/control-letter/helper.go new file mode 100644 index 00000000..9b1d3b23 --- /dev/null +++ b/internal/use-case/main-use-case/control-letter/helper.go @@ -0,0 +1,25 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package controlletter + +import ( + e "simrs-vx/internal/domain/main-entities/control-letter" +) + +func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ControlLetter) { + var inputSrc *e.CreateDto + if inputT, ok := any(input).(*e.CreateDto); ok { + inputSrc = inputT + } else { + inputTemp := any(input).(*e.UpdateDto) + inputSrc = &inputTemp.CreateDto + } + + data.Encounter_Id = inputSrc.Encounter_Id + data.Unit_Id = inputSrc.Unit_Id + data.Specialist_Id = inputSrc.Specialist_Id + data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Date = inputSrc.Date +} diff --git a/internal/use-case/main-use-case/control-letter/lib.go b/internal/use-case/main-use-case/control-letter/lib.go new file mode 100644 index 00000000..5f82a856 --- /dev/null +++ b/internal/use-case/main-use-case/control-letter/lib.go @@ -0,0 +1,144 @@ +package controlletter + +import ( + e "simrs-vx/internal/domain/main-entities/control-letter" + + 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.ControlLetter, error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + data := e.ControlLetter{} + 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.ControlLetter, *e.MetaDto, error) { + pl.SetLogInfo(event, input, "started", "DBReadList") + data := []e.ControlLetter{} + pagination := gh.Pagination{} + count := int64(0) + meta := e.MetaDto{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + tx = tx. + Model(&e.ControlLetter{}). + Scopes(gh.Preload(input.Includes)). + 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 + } + return nil, nil, plh.HandleListError(input, event, err) + } + + 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.ControlLetter, error) { + pl.SetLogInfo(event, input, "started", "DBReadDetail") + data := e.ControlLetter{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if input.Includes != "" { + tx = tx.Scopes(gh.Preload(input.Includes)) + } + + if err := tx.First(&data, input.Id).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.ControlLetter, 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.ControlLetter, 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 +} diff --git a/internal/use-case/main-use-case/control-letter/middleware-runner.go b/internal/use-case/main-use-case/control-letter/middleware-runner.go new file mode 100644 index 00000000..6335de13 --- /dev/null +++ b/internal/use-case/main-use-case/control-letter/middleware-runner.go @@ -0,0 +1,103 @@ +package controlletter + +import ( + e "simrs-vx/internal/domain/main-entities/control-letter" + 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.ControlLetter) 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.ControlLetter) 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.ControlLetter) 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.ControlLetter) 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.ControlLetter) 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 +} diff --git a/internal/use-case/main-use-case/control-letter/middleware.go b/internal/use-case/main-use-case/control-letter/middleware.go new file mode 100644 index 00000000..42ae506c --- /dev/null +++ b/internal/use-case/main-use-case/control-letter/middleware.go @@ -0,0 +1,9 @@ +package controlletter + +// example of middleware +// func init() { +// createPreMw = append(createPreMw, +// CreateMw{Name: "modif-input", Func: pm.ModifInput}, +// CreateMw{Name: "check-data", Func: pm.CheckData}, +// ) +// } diff --git a/internal/use-case/main-use-case/control-letter/tycovar.go b/internal/use-case/main-use-case/control-letter/tycovar.go new file mode 100644 index 00000000..1f19c991 --- /dev/null +++ b/internal/use-case/main-use-case/control-letter/tycovar.go @@ -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 controlletter + +import ( + "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/control-letter" +) + +type createMw struct { + Name string + Func func(input *e.CreateDto, data *e.ControlLetter, tx *gorm.DB) error +} + +type readListMw struct { + Name string + Func func(input *e.ReadListDto, data *e.ControlLetter, tx *gorm.DB) error +} + +type readDetailMw struct { + Name string + Func func(input *e.ReadDetailDto, data *e.ControlLetter, 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 diff --git a/internal/use-case/simgos-sync-case/.keep b/internal/use-case/simgos-sync-use-case/.keep similarity index 100% rename from internal/use-case/simgos-sync-case/.keep rename to internal/use-case/simgos-sync-use-case/.keep diff --git a/pkg/use-case-helper/use-case-helper.go b/pkg/use-case-helper/use-case-helper.go index 0df8fe3e..a80595bb 100644 --- a/pkg/use-case-helper/use-case-helper.go +++ b/pkg/use-case-helper/use-case-helper.go @@ -143,3 +143,10 @@ func GetTimeNow() *time.Time { tmp := time.Now() return &tmp } + +func IsDateBeforeNow(t *time.Time) bool { + if t == nil { + return false + } + return t.Before(time.Now()) +} From 8a3a140cdec7772c7925208be5e84b223b9edda3 Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 4 Nov 2025 10:26:11 +0700 Subject: [PATCH 09/55] adjustment encounter --- .../domain/main-entities/encounter/dto.go | 10 +- .../main-handler/encounter/handler.go | 5 + .../encounter/request-validation.go | 25 +- .../main-use-case/ambulatory/helper.go | 1 + .../use-case/main-use-case/encounter/case.go | 148 +++++++---- .../use-case/main-use-case/encounter/lib.go | 245 ++++++++++++++++++ .../use-case/main-use-case/soapi/helper.go | 16 ++ internal/use-case/main-use-case/soapi/lib.go | 20 ++ 8 files changed, 403 insertions(+), 67 deletions(-) diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index e4b9a521..0d5e1aae 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -16,15 +16,11 @@ import ( // internal - domain - main-entities evs "simrs-vx/internal/domain/bpjs-entities/vclaim-sep" - eam "simrs-vx/internal/domain/main-entities/ambulatory" ea "simrs-vx/internal/domain/main-entities/appointment" ed "simrs-vx/internal/domain/main-entities/doctor" - eem "simrs-vx/internal/domain/main-entities/emergency" ee "simrs-vx/internal/domain/main-entities/employee" - ei "simrs-vx/internal/domain/main-entities/inpatient" eir "simrs-vx/internal/domain/main-entities/internal-reference" ep "simrs-vx/internal/domain/main-entities/patient" - er "simrs-vx/internal/domain/main-entities/rehab/base" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" eu "simrs-vx/internal/domain/main-entities/unit" @@ -52,10 +48,8 @@ type CreateDto struct { Appointment_Id *uint `json:"appointment_id"` RefTypeCode ere.RefTypeCode `json:"refTypeCode"` NewStatus bool `json:"newStatus"` - Ambulatory *eam.CreateDto `json:"ambulatory"` - Emergency *eem.CreateDto `json:"emergency"` - Inpatient *ei.Inpatient `json:"inpatient"` - Rehab *er.Basic `json:"rehab"` + VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` // if subClass_Code is rehab + AllocatedVisitCount *int `json:"allocatedVisitCount"` pa.AuthInfo } diff --git a/internal/interface/main-handler/encounter/handler.go b/internal/interface/main-handler/encounter/handler.go index ed8b1fbc..b66abe76 100644 --- a/internal/interface/main-handler/encounter/handler.go +++ b/internal/interface/main-handler/encounter/handler.go @@ -26,10 +26,15 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) { if err != nil { rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil) } + dto := e.CreateDto{} if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } + if valid := validateRequestCreate(w, dto); !valid { + return + } + dto.AuthInfo = *authInfo res, err := u.Create(dto) rw.DataResponse(w, res, err) diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index 5963abcb..d3a7afe4 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -67,22 +67,17 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) func validateRequestCreate(w http.ResponseWriter, i e.CreateDto) (valid bool) { switch { case i.Class_Code == ere.ECAmbulatory: - if i.Ambulatory == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "ambulatory required", - }) + // field allocatedVisitCount required if ambulatory visitMode_Code is adm + if ere.AmbulatoryClassCode(*i.SubClass_Code) == ere.ACCRme && *i.VisitMode_Code == ere.VMCAdm { + if *i.AllocatedVisitCount == 0 { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "allocatedVisitCount required", + }) + return + } } } - if i.Class_Code == ere.ECAmbulatory && i.Ambulatory.Class_Code == ere.ACCRme && i.Ambulatory.VisitMode_Code == ere.VMCAdm { - if *i.Rehab.AllocatedVisitCount == 0 { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "rehab.AllocatedVisitCode required", - }) - return - } - } - return + return true } diff --git a/internal/use-case/main-use-case/ambulatory/helper.go b/internal/use-case/main-use-case/ambulatory/helper.go index f78f0b65..bdd9b106 100644 --- a/internal/use-case/main-use-case/ambulatory/helper.go +++ b/internal/use-case/main-use-case/ambulatory/helper.go @@ -22,6 +22,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Ambulatory) { data.Encounter_Id = inputSrc.Encounter_Id data.Class_Code = inputSrc.Class_Code + data.VisitMode_Code = inputSrc.VisitMode_Code } func CheckClassCode(input *string) (ere.AmbulatoryClassCode, error) { diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 11b17e2b..cb886eee 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -25,6 +25,7 @@ import ( eem "simrs-vx/internal/domain/main-entities/employee" e "simrs-vx/internal/domain/main-entities/encounter" ei "simrs-vx/internal/domain/main-entities/inpatient" + er "simrs-vx/internal/domain/main-entities/rehab" erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" es "simrs-vx/internal/domain/main-entities/soapi" @@ -36,6 +37,7 @@ import ( ue "simrs-vx/internal/use-case/main-use-case/emergency" uem "simrs-vx/internal/use-case/main-use-case/employee" ui "simrs-vx/internal/use-case/main-use-case/inpatient" + ur "simrs-vx/internal/use-case/main-use-case/rehab" urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist" us "simrs-vx/internal/use-case/main-use-case/soapi" ) @@ -46,6 +48,7 @@ var now = time.Now() func Create(input e.CreateDto) (*d.Data, error) { data := e.Encounter{} + createSoapi := []es.CreateDto{} event := pl.Event{ Feature: "Create", @@ -55,6 +58,33 @@ func Create(input e.CreateDto) (*d.Data, error) { // Start log pl.SetLogInfo(&event, input, "started", "create") + // validate SubClass + var subCode interface{} + subCode, err := verifyClassCode(input) + if err != nil { + return nil, err + } + + // verify whether the allocated visit count has not exceeded the limit + if input.Class_Code == ere.ECAmbulatory && subCode.(ere.AmbulatoryClassCode) == ere.ACCRme && + *input.VisitMode_Code == ere.VMCSeries { + + dataEncounter, valid, err := verifyAllocatedVisitCount(input, &event) + if err != nil { + return nil, err + } + + if !valid { + return nil, err + } + + // get data soapi + createSoapi, err = getSoapiEncounterAdm(dataEncounter, &event) + if err != nil { + return nil, err + } + } + // check if patient is new in the hospital dataPatient, err := ReadList(e.ReadListDto{ FilterDto: e.FilterDto{Patient_Id: input.Patient_Id}, @@ -62,7 +92,6 @@ func Create(input e.CreateDto) (*d.Data, error) { if err != nil { return nil, err } - if list, ok := dataPatient.Data.([]e.ResponseDto); ok { if len(list) < 1 { input.NewStatus = true @@ -83,6 +112,7 @@ func Create(input e.CreateDto) (*d.Data, error) { input.Adm_Employee_Id = &emp.Id } + // create encounter if resData, err := CreateData(input, &event, tx); err != nil { return err } else { @@ -91,52 +121,57 @@ func Create(input e.CreateDto) (*d.Data, error) { switch input.Class_Code { case ere.ECAmbulatory: - subCode, err := ua.CheckClassCode(input.SubClass_Code) - if err != nil { - return err - } + subCodeAmbulatory := subCode.(ere.AmbulatoryClassCode) ambCreate := ea.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCode, + Encounter_Id: &data.Id, + Class_Code: subCodeAmbulatory, + VisitMode_Code: *input.VisitMode_Code, } _, err = ua.CreateData(ambCreate, &event, tx) if err != nil { return err } - if subCode == ere.ACCCac || subCode == ere.ACCCad { + if subCodeAmbulatory == ere.ACCCac || subCodeAmbulatory == ere.ACCCad { chemoCreate := ec.CreateDto{ Encounter_Id: &data.Id, Status_Code: erc.DVCNew, SrcUnit_Id: input.Unit_Id, } - _, err = uc.CreateData(chemoCreate, &event, tx) if err != nil { return err } } - case ere.ECEmergency: - subCode, err := ue.CheckClassCode(input.SubClass_Code) - if err != nil { - return err + + if subCodeAmbulatory == ere.ACCRme && *input.VisitMode_Code == ere.VMCAdm { + // create data rehab + if _, err = ur.CreateData(er.CreateDto{ + Encounter_Id: &data.Id, + Doctor_Id: input.Appointment_Doctor_Id, + AllocatedVisitCount: input.AllocatedVisitCount}, &event, tx); err != nil { + return err + } + } else if subCodeAmbulatory == ere.ACCRme && *input.VisitMode_Code == ere.VMCSeries { + // Insert Soapi + if err = us.CreateBulkData(createSoapi, data.Id, &event, tx); err != nil { + return err + } } + + case ere.ECEmergency: emerCreate := ee.CreateDto{ Encounter_Id: &data.Id, - Class_Code: subCode, + Class_Code: subCode.(ere.EmergencyClassCode), } _, err = ue.CreateData(emerCreate, &event, tx) if err != nil { return err } case ere.ECInpatient: - subCode, err := ui.CheckClassCode(input.SubClass_Code) - if err != nil { - return err - } inpCreate := ei.CreateDto{ Encounter_Id: &data.Id, - Class_Code: subCode, + Class_Code: subCode.(ere.InpatientClassCode), Infra_Id: input.Infra_Id, } _, err = ui.CreateData(inpCreate, &event, tx) @@ -148,11 +183,10 @@ func Create(input e.CreateDto) (*d.Data, error) { } // insert adm_employee_hist - if _, err := uaeh.Create(eaeh.CreateDto{ + if _, err := uaeh.CreateData(eaeh.CreateDto{ Encounter_Id: &data.Main.Id, Employee_Id: data.Adm_Employee_Id, - StartedAt: &now, - }); err != nil { + StartedAt: &now}, &event, tx); err != nil { return err } @@ -430,8 +464,16 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - if err := checkSoapiByDocExists(data.Id, &event, tx); err != nil { - return err + if data.Class_Code == ere.ECAmbulatory { + // validate if soapi exist + err = getSoapiByTypeCode(input.Id, &event, "check-out") + if err != nil { + return err + } + } else { + if err := checkSoapiByDocExists(data.Id, &event, tx); err != nil { + return err + } } if err := updateDischargeData(input, data, &event, tx); err != nil { @@ -557,7 +599,7 @@ func UpdateStatusCode(input e.UpdateStatusDto) (*d.Data, error) { } func CheckIn(input e.CheckinDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Rehab"} var data *e.Encounter var err error @@ -580,23 +622,11 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } // validate if soapi exist - dataSoapi, err := us.ReadList(es.ReadListDto{FilterDto: es.FilterDto{Encounter_Id: &input.Id}}) + err = getSoapiByTypeCode(input.Id, &event, "check-in") if err != nil { return nil, err } - if list, ok := dataSoapi.Data.([]es.ResponseDto); ok { - if len(list) > 0 { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-state-mismatch", - Detail: "soapi already exist", - Raw: errors.New("soapi already exist"), - } - return nil, pl.SetLogError(&event, input) - } - } - err = dg.I.Transaction(func(tx *gorm.DB) error { pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail") if data, err = ReadDetailData(rdDto, &event, tx); err != nil { @@ -621,11 +651,10 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } //insert responsible_doctor_hist - if _, err = urdh.Create(erdh.CreateDto{ + if _, err = urdh.CreateData(erdh.CreateDto{ Encounter_Id: &input.Id, Doctor_Id: input.Responsible_Doctor_Id, - StartedAt: input.StartedAt, - }); err != nil { + StartedAt: input.StartedAt}, &event, tx); err != nil { return err } } @@ -638,11 +667,10 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } // insert responsible_doctor_hist - if _, err = uaeh.Create(eaeh.CreateDto{ + if _, err = uaeh.CreateData(eaeh.CreateDto{ Encounter_Id: &input.Id, Employee_Id: input.Adm_Employee_Id, - StartedAt: input.StartedAt, - }); err != nil { + StartedAt: input.StartedAt}, &event, tx); err != nil { return err } } @@ -652,6 +680,15 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { return err } + if err := updateRehabDoctor(er.UpdateDto{ + CreateDto: er.CreateDto{ + Encounter_Id: &data.Id, + Doctor_Id: input.Responsible_Doctor_Id, + }, + }, &event, tx); err != nil { + return err + } + pl.SetLogInfo(&event, nil, "complete") return nil @@ -688,3 +725,26 @@ func validateForeignKey(input e.CheckinDto) error { return nil } + +func verifyClassCode(input e.CreateDto) (subCode interface{}, err error) { + switch input.Class_Code { + case ere.ECAmbulatory: + subCode, err = ua.CheckClassCode(input.SubClass_Code) + if err != nil { + return nil, err + } + case ere.ECEmergency: + subCode, err = ue.CheckClassCode(input.SubClass_Code) + if err != nil { + return nil, err + } + case ere.ECInpatient: + subCode, err = ui.CheckClassCode(input.SubClass_Code) + if err != nil { + return nil, err + } + default: + return nil, errors.New("invalid encounter class code") + } + return +} diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 3327bcfa..ed41e15f 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -3,6 +3,12 @@ package encounter import ( // std "errors" + "fmt" + erc "simrs-vx/internal/domain/references/clinical" + ere "simrs-vx/internal/domain/references/encounter" + ero "simrs-vx/internal/domain/references/organization" + "strings" + // external dg "github.com/karincake/apem/db-gorm-pg" gh "github.com/karincake/getuk" @@ -15,8 +21,11 @@ import ( // internal eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist" + ea "simrs-vx/internal/domain/main-entities/ambulatory" e "simrs-vx/internal/domain/main-entities/encounter" + er "simrs-vx/internal/domain/main-entities/rehab" erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" + es "simrs-vx/internal/domain/main-entities/soapi" ) func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Encounter, error) { @@ -333,3 +342,239 @@ func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*go pl.SetLogInfo(event, nil, "complete") return nil } + +func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, bool, error) { + pl.SetLogInfo(event, nil, "started", "DBGetRecentEncounterAdm") + + var ( + tx = dg.I + recentEncounterAdm e.Encounter + countEncounterSeries int64 + ) + + err := tx. + Scopes(gh.Preload("Rehab,Responsible_Doctor")). + Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). + Where("\"Patient_Id\" = ?", i.Patient_Id). + Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRme, ere.VMCAdm). + Order("\"CreatedAt\" DESC"). + First(&recentEncounterAdm).Error + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "read-recentEncounter-fail", + Detail: "Database read failed", + Raw: err, + } + return e.Encounter{}, false, pl.SetLogError(event, i) + } + + err = tx. + Model(&e.Encounter{}). + Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). + Where("\"Patient_Id\" = ?", i.Patient_Id). + Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ECAmbulatory, ere.VMCSeries). + Where("\"CreatedAt\" > ?", recentEncounterAdm.CreatedAt). + Count(&countEncounterSeries).Error + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "read-countEncounter-fail", + Detail: "Database read failed", + Raw: err, + } + return e.Encounter{}, false, pl.SetLogError(event, i) + } + + return recentEncounterAdm, countEncounterSeries < int64(*recentEncounterAdm.Rehab.AllocatedVisitCount), nil +} + +func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) { + var data []es.Soapi + + pl.SetLogInfo(event, enc, "started", "DBReadList") + + if enc.Responsible_Doctor == nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "no responsible-doctor found", + Detail: "Encounter does not have responsible-doctor", + } + } + + err = dg.I. + Model(&es.Soapi{}). + Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). + Where("\"Encounter_Id\" = ?", enc.Id). + Where("\"Employee\".\"Position_Code\" = ?", ero.EPCDoc). + Where("\"Soapi\".\"TypeCode\" IN ?", []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc}). + Where("\"Soapi\".\"Employee_Id\" = ?", *enc.Responsible_Doctor.Employee_Id). + Find(&data).Error + + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Raw: err, + } + + if errors.Is(err, gorm.ErrRecordNotFound) { + event.ErrInfo.Code = "data-not-found" + event.ErrInfo.Detail = "Data not found" + return nil, pl.SetLogError(event, enc) + } + + event.ErrInfo.Code = "read-fail" + event.ErrInfo.Detail = "Database read failed" + return nil, pl.SetLogError(event, enc) + } + + pl.SetLogInfo(event, nil, "complete") + + for _, s := range data { + // set data soapi for copy + dataSoapi = append(dataSoapi, es.CreateDto{ + Employee_Id: s.Employee_Id, + Time: s.Time, + TypeCode: s.TypeCode, + Value: s.Value, + }) + } + + if len(dataSoapi) < 2 { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "missing-soapi", + Detail: fmt.Sprintf("Missing required Soapi types"), + } + return nil, pl.SetLogError(event, enc) + } + return +} + +func getSoapiByTypeCode(encounterId uint, event *pl.Event, mode string) (err error) { + pl.SetLogInfo(event, encounterId, "started", "DBReadList") + + var ( + dataAmbulatory ea.Ambulatory + dataSoapi []es.Soapi + ) + + // Get Data Ambulatory + if err = dg.I. + Where("\"Encounter_Id\" = ?", encounterId). + First(&dataAmbulatory).Error; err != nil { + return setDBError(event, err, encounterId) + } + + // Set Query for get data Soapi + tx := dg.I. + Model(&es.Soapi{}). + Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). + Where("\"Encounter_Id\" = ?", encounterId). + Where("\"Employee\".\"Position_Code\" = ?", ero.EPCDoc) + + // Set Case + switch { + case dataAmbulatory.Class_Code == ere.ACCReg: + tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", erc.STCEEarlyMedic) + case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc}) + case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", erc.STCEarlyRehab) + } + + if err = tx.Find(&dataSoapi).Error; err != nil { + return setDBError(event, err, encounterId) + } + + pl.SetLogInfo(event, nil, "complete") + return validateExistedSoapi(dataSoapi, &dataAmbulatory, event, mode) +} + +func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, event *pl.Event, mode string) error { + typeExist := make(map[erc.SoapiTypeCode]bool) + for _, s := range dataSoapi { + typeExist[s.TypeCode] = true + } + + required := []erc.SoapiTypeCode{} + + switch { + case dataAmbulatory.Class_Code == ere.ACCReg: + required = []erc.SoapiTypeCode{erc.STCEEarlyMedic} + case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + required = []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCEarlyRehab, erc.STCFunc} + case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + required = []erc.SoapiTypeCode{erc.STCEarlyRehab} + } + + var missing, existing []string + for _, code := range required { + if typeExist[code] { + existing = append(existing, string(code)) + } else { + missing = append(missing, string(code)) + } + } + + switch mode { + case "check-in": + if len(existing) > 0 { + return setSoapiError(event, fmt.Sprintf("Soapi type(s) %s exist, can't check-in", strings.Join(existing, ", "))) + } + case "check-out": + if len(missing) > 0 { + return setSoapiError(event, fmt.Sprintf("Soapi type(s) %s not found, can't check-out", strings.Join(missing, ", "))) + } + } + + return nil +} + +func setSoapiError(event *pl.Event, detail string) error { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "invalid-soapi-state", + Detail: detail, + } + return pl.SetLogError(event, detail) +} + +func setDBError(event *pl.Event, err error, ctx any) error { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Raw: err, + Code: "read-fail", + Detail: "Database read failed", + } + return pl.SetLogError(event, ctx) +} + +func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, "started", "DBUpdate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + result := tx. + Model(&er.Rehab{}). + Where("\"Encounter_Id\" = (?)", input.Encounter_Id). + Update("\"Doctor_Id\"", input.Doctor_Id) + + if result.Error != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-update-fail", + Detail: "Database update failed", + Raw: result.Error, + } + return pl.SetLogError(event, input) + } + + pl.SetLogInfo(event, nil, "complete") + return nil +} diff --git a/internal/use-case/main-use-case/soapi/helper.go b/internal/use-case/main-use-case/soapi/helper.go index 5a94848a..ae396270 100644 --- a/internal/use-case/main-use-case/soapi/helper.go +++ b/internal/use-case/main-use-case/soapi/helper.go @@ -23,3 +23,19 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Soapi) { data.TypeCode = inputSrc.TypeCode data.Value = inputSrc.Value } + +func setBulkData(input []e.CreateDto, encounterId uint) []e.Soapi { + var data []e.Soapi + + for _, v := range input { + data = append(data, e.Soapi{ + Encounter_Id: &encounterId, + Employee_Id: v.Employee_Id, + Time: v.Time, + TypeCode: v.TypeCode, + Value: v.Value, + }) + } + + return data +} diff --git a/internal/use-case/main-use-case/soapi/lib.go b/internal/use-case/main-use-case/soapi/lib.go index 7e551505..57bb5d23 100644 --- a/internal/use-case/main-use-case/soapi/lib.go +++ b/internal/use-case/main-use-case/soapi/lib.go @@ -138,3 +138,23 @@ func DeleteData(data *e.Soapi, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, nil, "complete") return nil } + +func CreateBulkData(input []e.CreateDto, encounterId uint, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + data := setBulkData(input, encounterId) + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if err := tx.Create(&data).Error; err != nil { + return plh.HandleCreateError(input, event, err) + } + + pl.SetLogInfo(event, nil, "complete") + return nil +} From 0f9305427c0f2e5d57bf42797a9c676b98edaf1e Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 4 Nov 2025 11:11:24 +0700 Subject: [PATCH 10/55] encounter-adjustment-finish --- internal/use-case/main-use-case/encounter/case.go | 8 +++++++- internal/use-case/main-use-case/encounter/lib.go | 11 ++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index cb886eee..8cff1e21 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -75,7 +75,13 @@ func Create(input e.CreateDto) (*d.Data, error) { } if !valid { - return nil, err + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "visit-limit-exceeded", + Detail: "Encounter has exceeded the allowed number of visits", + Raw: errors.New("visit count exceeds allowed limit"), + } + return nil, pl.SetLogError(&event, input) } // get data soapi diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index ed41e15f..b840f6e1 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -370,11 +370,12 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo } err = tx. + Debug(). Model(&e.Encounter{}). Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). Where("\"Patient_Id\" = ?", i.Patient_Id). - Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ECAmbulatory, ere.VMCSeries). - Where("\"CreatedAt\" > ?", recentEncounterAdm.CreatedAt). + Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRme, ere.VMCSeries). + Where("\"Encounter\".\"CreatedAt\" > ?", recentEncounterAdm.CreatedAt). Count(&countEncounterSeries).Error if err != nil { event.Status = "failed" @@ -402,7 +403,7 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea } } - err = dg.I. + err = dg.I.Debug(). Model(&es.Soapi{}). Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). Where("\"Encounter_Id\" = ?", enc.Id). @@ -478,7 +479,7 @@ func getSoapiByTypeCode(encounterId uint, event *pl.Event, mode string) (err err case dataAmbulatory.Class_Code == ere.ACCReg: tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", erc.STCEEarlyMedic) case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCAdm: - tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc}) + tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc, erc.STCEarlyRehab}) case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCSeries: tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", erc.STCEarlyRehab) } @@ -503,7 +504,7 @@ func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, e case dataAmbulatory.Class_Code == ere.ACCReg: required = []erc.SoapiTypeCode{erc.STCEEarlyMedic} case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCAdm: - required = []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCEarlyRehab, erc.STCFunc} + required = []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc, erc.STCEarlyRehab} case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCSeries: required = []erc.SoapiTypeCode{erc.STCEarlyRehab} } From c6eaaa2c10c0c2ff798c1bc78fe877c23342818d Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 4 Nov 2025 14:05:56 +0700 Subject: [PATCH 11/55] finish adjustment encounter --- .../encounter/request-validation.go | 2 +- .../use-case/main-use-case/encounter/case.go | 66 ++- .../main-use-case/encounter/helper.go | 387 +++++++++++++++++- .../use-case/main-use-case/encounter/lib.go | 288 +------------ 4 files changed, 415 insertions(+), 328 deletions(-) diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index d3a7afe4..b7d31e71 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -68,7 +68,7 @@ func validateRequestCreate(w http.ResponseWriter, i e.CreateDto) (valid bool) { switch { case i.Class_Code == ere.ECAmbulatory: // field allocatedVisitCount required if ambulatory visitMode_Code is adm - if ere.AmbulatoryClassCode(*i.SubClass_Code) == ere.ACCRme && *i.VisitMode_Code == ere.VMCAdm { + if ere.AmbulatoryClassCode(*i.SubClass_Code) == ere.ACCRehab && *i.VisitMode_Code == ere.VMCAdm { if *i.AllocatedVisitCount == 0 { rw.DataResponse(w, nil, d.FieldError{ Code: dataValidationFail, diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index fa55f222..ef70d9c2 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -38,7 +38,6 @@ import ( uem "simrs-vx/internal/use-case/main-use-case/employee" ui "simrs-vx/internal/use-case/main-use-case/inpatient" ur "simrs-vx/internal/use-case/main-use-case/rehab" - urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist" us "simrs-vx/internal/use-case/main-use-case/soapi" ) @@ -66,7 +65,7 @@ func Create(input e.CreateDto) (*d.Data, error) { } // verify whether the allocated visit count has not exceeded the limit - if input.Class_Code == ere.ECAmbulatory && subCode.(ere.AmbulatoryClassCode) == ere.ACCRme && + if input.Class_Code == ere.ECAmbulatory && subCode.(ere.AmbulatoryClassCode) == ere.ACCRehab && *input.VisitMode_Code == ere.VMCSeries { dataEncounter, valid, err := verifyAllocatedVisitCount(input, &event) @@ -150,7 +149,7 @@ func Create(input e.CreateDto) (*d.Data, error) { } } - if subCodeAmbulatory == ere.ACCRme && *input.VisitMode_Code == ere.VMCAdm { + if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCAdm { // create data rehab if _, err = ur.CreateData(er.CreateDto{ Encounter_Id: &data.Id, @@ -158,7 +157,7 @@ func Create(input e.CreateDto) (*d.Data, error) { AllocatedVisitCount: input.AllocatedVisitCount}, &event, tx); err != nil { return err } - } else if subCodeAmbulatory == ere.ACCRme && *input.VisitMode_Code == ere.VMCSeries { + } else if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCSeries { // Insert Soapi if err = us.CreateBulkData(createSoapi, data.Id, &event, tx); err != nil { return err @@ -442,7 +441,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { } func CheckOut(input e.DischargeDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Ambulatory"} var data *e.Encounter var err error @@ -470,13 +469,14 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - if data.Class_Code == ere.ECAmbulatory { + if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) { // validate if soapi exist - err = getSoapiByTypeCode(input.Id, &event, "check-out") + err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-out") if err != nil { return err } } else { + // chemo TBC if err := checkSoapiByDocExists(data.Id, &event, tx); err != nil { return err } @@ -605,7 +605,7 @@ func UpdateStatusCode(input e.UpdateStatusDto) (*d.Data, error) { } func CheckIn(input e.CheckinDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Rehab"} + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Rehab,Ambulatory"} var data *e.Encounter var err error @@ -627,12 +627,6 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { input.StartedAt = &now } - // validate if soapi exist - err = getSoapiByTypeCode(input.Id, &event, "check-in") - if err != nil { - return nil, err - } - err = dg.I.Transaction(func(tx *gorm.DB) error { pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail") if data, err = ReadDetailData(rdDto, &event, tx); err != nil { @@ -649,34 +643,34 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - // Insert responsible_doctor_hist if responsible_doctor_id has changed && update latest history - if data.Responsible_Doctor_Id == nil || *input.Responsible_Doctor_Id != *data.Responsible_Doctor_Id { - // update finishedAt in latest responsible_doctor_hist - if err = updateLatestResponsibleDoctorHist(input, &event, tx); err != nil { + // validate if soapi exist + if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) { + err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-in") + if err != nil { return err } + } - //insert responsible_doctor_hist - if _, err = urdh.CreateData(erdh.CreateDto{ - Encounter_Id: &input.Id, + // Insert responsible_doctor_hist if responsible_doctor_id has changed && update latest history + if data.Responsible_Doctor_Id == nil || *input.Responsible_Doctor_Id != *data.Responsible_Doctor_Id { + // upsert responsibleDoctorHist + if err = upsertResponsibleDoctorHist(erdh.CreateDto{ + Encounter_Id: &data.Id, Doctor_Id: input.Responsible_Doctor_Id, - StartedAt: input.StartedAt}, &event, tx); err != nil { + StartedAt: input.StartedAt, + }, &event, tx); err != nil { return err } } // Insert adm_employee_hist if adm_employee_id has changed && update latest history if input.Adm_Employee_Id != nil && *input.Adm_Employee_Id != *data.Adm_Employee_Id { - // update finishedAt in latest adm_employee_hist - if err = updateLatestAdmEmployeeHist(input, &event, tx); err != nil { - return err - } - - // insert responsible_doctor_hist - if _, err = uaeh.CreateData(eaeh.CreateDto{ - Encounter_Id: &input.Id, + // upsert admEmployeeHist + if err = upsertAdmEmployeeHist(eaeh.CreateDto{ + Encounter_Id: &data.Id, Employee_Id: input.Adm_Employee_Id, - StartedAt: input.StartedAt}, &event, tx); err != nil { + StartedAt: input.StartedAt, + }, &event, tx); err != nil { return err } } @@ -686,13 +680,13 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { return err } - if err := updateRehabDoctor(er.UpdateDto{ - CreateDto: er.CreateDto{ + if data.Ambulatory.Class_Code == ere.ACCRehab { + if err := updateRehabDoctor(er.UpdateDto{CreateDto: er.CreateDto{ Encounter_Id: &data.Id, Doctor_Id: input.Responsible_Doctor_Id, - }, - }, &event, tx); err != nil { - return err + }}, &event, tx); err != nil { + return err + } } pl.SetLogInfo(&event, nil, "complete") diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index c5eb155e..4bf7be60 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -7,17 +7,25 @@ package encounter import ( "errors" "fmt" - uir "simrs-vx/internal/use-case/main-use-case/internal-reference" "strings" "time" + dg "github.com/karincake/apem/db-gorm-pg" "gorm.io/gorm" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" + ercl "simrs-vx/internal/domain/references/clinical" + erc "simrs-vx/internal/domain/references/common" + ere "simrs-vx/internal/domain/references/encounter" + erg "simrs-vx/internal/domain/references/organization" + + eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist" + ea "simrs-vx/internal/domain/main-entities/ambulatory" edo "simrs-vx/internal/domain/main-entities/device-order" ed "simrs-vx/internal/domain/main-entities/doctor" + e "simrs-vx/internal/domain/main-entities/encounter" emo "simrs-vx/internal/domain/main-entities/material-order" emco "simrs-vx/internal/domain/main-entities/mcu-order" em "simrs-vx/internal/domain/main-entities/medication" @@ -26,20 +34,21 @@ import ( emmi "simrs-vx/internal/domain/main-entities/medicine-mix-item" ep "simrs-vx/internal/domain/main-entities/prescription" epi "simrs-vx/internal/domain/main-entities/prescription-item" + er "simrs-vx/internal/domain/main-entities/rehab" + erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" eu "simrs-vx/internal/domain/main-entities/unit" // udo "simrs-vx/internal/use-case/main-use-case/device-order" es "simrs-vx/internal/domain/main-entities/soapi" + uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist" + uir "simrs-vx/internal/use-case/main-use-case/internal-reference" um "simrs-vx/internal/use-case/main-use-case/medication" umei "simrs-vx/internal/use-case/main-use-case/medication-item" umi "simrs-vx/internal/use-case/main-use-case/medicine-mix" ummi "simrs-vx/internal/use-case/main-use-case/medicine-mix-item" up "simrs-vx/internal/use-case/main-use-case/prescription" upi "simrs-vx/internal/use-case/main-use-case/prescription-item" - - e "simrs-vx/internal/domain/main-entities/encounter" - erc "simrs-vx/internal/domain/references/common" - erg "simrs-vx/internal/domain/references/organization" + urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist" ) func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { @@ -432,3 +441,371 @@ func getDoctors(doctorIds []uint, event *pl.Event, tx *gorm.DB) ([]ed.Doctor, er } return doctors, nil } + +func upsertResponsibleDoctorHist(input erdh.CreateDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + var latest erdh.ResponsibleDoctorHist + err := tx. + Where("\"Encounter_Id\" = ?", input.Encounter_Id). + Order("\"CreatedAt\" DESC"). + Limit(1). + First(&latest).Error + + switch { + case errors.Is(err, gorm.ErrRecordNotFound): + // Insert + if _, err = urdh.CreateData(input, event, tx); err != nil { + return err + } + case err != nil: + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "read-fail", + Detail: "Failed to read responsible doctor history", + Raw: err, + } + return pl.SetLogError(event, input) + default: + // Update + if err := tx.Model(&latest).Updates(map[string]interface{}{ + "Doctor_Id": input.Doctor_Id, + "StartedAt": input.StartedAt, + "UpdatedAt": time.Now(), + }).Error; err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "update-fail", + Detail: "Failed to update responsible doctor history", + Raw: err, + } + return pl.SetLogError(event, input) + } + } + pl.SetLogInfo(event, input, "complete") + return nil +} + +func upsertAdmEmployeeHist(input eaeh.CreateDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + var latest eaeh.AdmEmployeeHist + err := tx. + Where("\"Encounter_Id\" = ?", input.Encounter_Id). + Order("\"CreatedAt\" DESC"). + Limit(1). + First(&latest).Error + + switch { + case errors.Is(err, gorm.ErrRecordNotFound): + // Insert + if _, err = uaeh.CreateData(input, event, tx); err != nil { + return err + } + case err != nil: + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "read-fail", + Detail: "Failed to read responsible doctor history", + Raw: err, + } + return pl.SetLogError(event, input) + + default: + // Update + if err := tx.Model(&latest).Updates(map[string]interface{}{ + "Employee_Id": input.Employee_Id, + "StartedAt": input.StartedAt, + "UpdatedAt": time.Now(), + }).Error; err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "update-fail", + Detail: "Failed to update responsible doctor history", + Raw: err, + } + return pl.SetLogError(event, input) + } + } + pl.SetLogInfo(event, input, "complete") + + return nil +} + +func updateLatestResponsibleDoctorHist(input e.CheckinDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, "started", "DBUpdate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + subQuery := tx. + Select("\"Id\""). + Model(&erdh.ResponsibleDoctorHist{}). + Where("\"Encounter_Id\" = ?", input.Id). + Order("\"CreatedAt\" DESC"). + Limit(1) + + result := tx. + Model(&erdh.ResponsibleDoctorHist{}). + Where("\"Id\" = (?)", subQuery). + Update("\"FinishedAt\"", input.StartedAt) + + if result.Error != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-update-fail", + Detail: "Database update failed", + Raw: result.Error, + } + return pl.SetLogError(event, input) + } + + if result.RowsAffected == 0 { + pl.SetLogInfo(event, input, "no previous data found to update") + return nil + } + + pl.SetLogInfo(event, nil, "complete") + return nil +} + +func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, "started", "DBUpdate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + subQuery := tx. + Select("\"Id\""). + Model(&eaeh.AdmEmployeeHist{}). + Where("\"Encounter_Id\" = ?", input.Id). + Order("\"CreatedAt\" DESC"). + Limit(1) + + result := tx. + Model(&eaeh.AdmEmployeeHist{}). + Where("\"Id\" = (?)", subQuery). + Update("\"FinishedAt\"", input.StartedAt) + + if result.Error != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-update-fail", + Detail: "Database update failed", + Raw: result.Error, + } + return pl.SetLogError(event, input) + } + + if result.RowsAffected == 0 { + pl.SetLogInfo(event, input, "no previous data found to update") + return nil + } + + pl.SetLogInfo(event, nil, "complete") + return nil +} + +func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) { + var data []es.Soapi + + pl.SetLogInfo(event, enc, "started", "DBReadList") + + if enc.Responsible_Doctor == nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "no responsible-doctor found", + Detail: "Encounter does not have responsible-doctor", + } + } + + err = dg.I.Debug(). + Model(&es.Soapi{}). + Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). + Where("\"Encounter_Id\" = ?", enc.Id). + Where("\"Employee\".\"Position_Code\" = ?", erg.EPCDoc). + Where("\"Soapi\".\"TypeCode\" IN ?", []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc}). + Where("\"Soapi\".\"Employee_Id\" = ?", *enc.Responsible_Doctor.Employee_Id). + Find(&data).Error + + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Raw: err, + } + + if errors.Is(err, gorm.ErrRecordNotFound) { + event.ErrInfo.Code = "data-not-found" + event.ErrInfo.Detail = "Data not found" + return nil, pl.SetLogError(event, enc) + } + + event.ErrInfo.Code = "read-fail" + event.ErrInfo.Detail = "Database read failed" + return nil, pl.SetLogError(event, enc) + } + + pl.SetLogInfo(event, nil, "complete") + + for _, s := range data { + // set data soapi for copy + dataSoapi = append(dataSoapi, es.CreateDto{ + Employee_Id: s.Employee_Id, + Time: s.Time, + TypeCode: s.TypeCode, + Value: s.Value, + }) + } + + if len(dataSoapi) < 2 { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "missing-soapi", + Detail: fmt.Sprintf("Missing required Soapi types"), + } + return nil, pl.SetLogError(event, enc) + } + return +} + +func getSoapiByTypeCode(encounterId uint, dataAmbulatory ea.Ambulatory, event *pl.Event, mode string) (err error) { + pl.SetLogInfo(event, encounterId, "started", "DBReadList") + + var ( + dataSoapi []es.Soapi + ) + + // Set Query for get data Soapi + tx := dg.I. + Model(&es.Soapi{}). + Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). + Where("\"Encounter_Id\" = ?", encounterId). + Where("\"Employee\".\"Position_Code\" = ?", erg.EPCDoc) + + // Set Case + switch { + case dataAmbulatory.Class_Code == ere.ACCReg: + tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEEarlyMedic) + case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab}) + case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEarlyRehab) + } + + if err = tx.Find(&dataSoapi).Error; err != nil { + return setDBError(event, err, encounterId) + } + + pl.SetLogInfo(event, nil, "complete") + return validateExistedSoapi(dataSoapi, &dataAmbulatory, event, mode) +} + +func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, event *pl.Event, mode string) error { + typeExist := make(map[ercl.SoapiTypeCode]bool) + for _, s := range dataSoapi { + typeExist[s.TypeCode] = true + } + + required := []ercl.SoapiTypeCode{} + + switch { + case dataAmbulatory.Class_Code == ere.ACCReg: + required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic} + case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab} + case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + required = []ercl.SoapiTypeCode{ercl.STCEarlyRehab} + } + + var missing, existing []string + for _, code := range required { + if typeExist[code] { + existing = append(existing, string(code)) + } else { + missing = append(missing, string(code)) + } + } + + switch mode { + case "check-in": + if len(existing) > 0 { + return setSoapiError(event, fmt.Sprintf("Soapi type(s) %s exist, can't check-in", strings.Join(existing, ", "))) + } + case "check-out": + if len(missing) > 0 { + return setSoapiError(event, fmt.Sprintf("Soapi type(s) %s not found, can't check-out", strings.Join(missing, ", "))) + } + } + + return nil +} + +func setSoapiError(event *pl.Event, detail string) error { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "invalid-soapi-state", + Detail: detail, + } + return pl.SetLogError(event, detail) +} + +func setDBError(event *pl.Event, err error, ctx any) error { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Raw: err, + Code: "read-fail", + Detail: "Database read failed", + } + return pl.SetLogError(event, ctx) +} + +func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, "started", "DBUpdate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + result := tx. + Model(&er.Rehab{}). + Where("\"Encounter_Id\" = (?)", input.Encounter_Id). + Update("\"Doctor_Id\"", input.Doctor_Id) + + if result.Error != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-update-fail", + Detail: "Database update failed", + Raw: result.Error, + } + return pl.SetLogError(event, input) + } + + pl.SetLogInfo(event, nil, "complete") + return nil +} diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index b840f6e1..d80fd513 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -3,29 +3,17 @@ package encounter import ( // std "errors" - "fmt" - erc "simrs-vx/internal/domain/references/clinical" ere "simrs-vx/internal/domain/references/encounter" - ero "simrs-vx/internal/domain/references/organization" - "strings" - // external dg "github.com/karincake/apem/db-gorm-pg" gh "github.com/karincake/getuk" "gorm.io/gorm" - // pkg plh "simrs-vx/pkg/lib-helper" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" - // internal - eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist" - ea "simrs-vx/internal/domain/main-entities/ambulatory" e "simrs-vx/internal/domain/main-entities/encounter" - er "simrs-vx/internal/domain/main-entities/rehab" - erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" - es "simrs-vx/internal/domain/main-entities/soapi" ) func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Encounter, error) { @@ -261,88 +249,6 @@ func updateCheckInData(input e.CheckinDto, data *e.Encounter, event *pl.Event, d return nil } -func updateLatestResponsibleDoctorHist(input e.CheckinDto, event *pl.Event, dbx ...*gorm.DB) error { - pl.SetLogInfo(event, "started", "DBUpdate") - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - subQuery := tx. - Select("\"Id\""). - Model(&erdh.ResponsibleDoctorHist{}). - Where("\"Encounter_Id\" = ?", input.Id). - Order("\"CreatedAt\" DESC"). - Limit(1) - - result := tx. - Model(&erdh.ResponsibleDoctorHist{}). - Where("\"Id\" = (?)", subQuery). - Update("\"FinishedAt\"", input.StartedAt) - - if result.Error != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-update-fail", - Detail: "Database update failed", - Raw: result.Error, - } - return pl.SetLogError(event, input) - } - - if result.RowsAffected == 0 { - pl.SetLogInfo(event, input, "no previous data found to update") - return nil - } - - pl.SetLogInfo(event, nil, "complete") - return nil -} - -func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*gorm.DB) error { - pl.SetLogInfo(event, "started", "DBUpdate") - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - subQuery := tx. - Select("\"Id\""). - Model(&eaeh.AdmEmployeeHist{}). - Where("\"Encounter_Id\" = ?", input.Id). - Order("\"CreatedAt\" DESC"). - Limit(1) - - result := tx. - Model(&eaeh.AdmEmployeeHist{}). - Where("\"Id\" = (?)", subQuery). - Update("\"FinishedAt\"", input.StartedAt) - - if result.Error != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-update-fail", - Detail: "Database update failed", - Raw: result.Error, - } - return pl.SetLogError(event, input) - } - - if result.RowsAffected == 0 { - pl.SetLogInfo(event, input, "no previous data found to update") - return nil - } - - pl.SetLogInfo(event, nil, "complete") - return nil -} - func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, bool, error) { pl.SetLogInfo(event, nil, "started", "DBGetRecentEncounterAdm") @@ -356,7 +262,7 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo Scopes(gh.Preload("Rehab,Responsible_Doctor")). Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). Where("\"Patient_Id\" = ?", i.Patient_Id). - Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRme, ere.VMCAdm). + Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCAdm). Order("\"CreatedAt\" DESC"). First(&recentEncounterAdm).Error if err != nil { @@ -374,7 +280,7 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo Model(&e.Encounter{}). Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). Where("\"Patient_Id\" = ?", i.Patient_Id). - Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRme, ere.VMCSeries). + Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCSeries). Where("\"Encounter\".\"CreatedAt\" > ?", recentEncounterAdm.CreatedAt). Count(&countEncounterSeries).Error if err != nil { @@ -389,193 +295,3 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo return recentEncounterAdm, countEncounterSeries < int64(*recentEncounterAdm.Rehab.AllocatedVisitCount), nil } - -func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) { - var data []es.Soapi - - pl.SetLogInfo(event, enc, "started", "DBReadList") - - if enc.Responsible_Doctor == nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "no responsible-doctor found", - Detail: "Encounter does not have responsible-doctor", - } - } - - err = dg.I.Debug(). - Model(&es.Soapi{}). - Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). - Where("\"Encounter_Id\" = ?", enc.Id). - Where("\"Employee\".\"Position_Code\" = ?", ero.EPCDoc). - Where("\"Soapi\".\"TypeCode\" IN ?", []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc}). - Where("\"Soapi\".\"Employee_Id\" = ?", *enc.Responsible_Doctor.Employee_Id). - Find(&data).Error - - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Raw: err, - } - - if errors.Is(err, gorm.ErrRecordNotFound) { - event.ErrInfo.Code = "data-not-found" - event.ErrInfo.Detail = "Data not found" - return nil, pl.SetLogError(event, enc) - } - - event.ErrInfo.Code = "read-fail" - event.ErrInfo.Detail = "Database read failed" - return nil, pl.SetLogError(event, enc) - } - - pl.SetLogInfo(event, nil, "complete") - - for _, s := range data { - // set data soapi for copy - dataSoapi = append(dataSoapi, es.CreateDto{ - Employee_Id: s.Employee_Id, - Time: s.Time, - TypeCode: s.TypeCode, - Value: s.Value, - }) - } - - if len(dataSoapi) < 2 { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "missing-soapi", - Detail: fmt.Sprintf("Missing required Soapi types"), - } - return nil, pl.SetLogError(event, enc) - } - return -} - -func getSoapiByTypeCode(encounterId uint, event *pl.Event, mode string) (err error) { - pl.SetLogInfo(event, encounterId, "started", "DBReadList") - - var ( - dataAmbulatory ea.Ambulatory - dataSoapi []es.Soapi - ) - - // Get Data Ambulatory - if err = dg.I. - Where("\"Encounter_Id\" = ?", encounterId). - First(&dataAmbulatory).Error; err != nil { - return setDBError(event, err, encounterId) - } - - // Set Query for get data Soapi - tx := dg.I. - Model(&es.Soapi{}). - Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). - Where("\"Encounter_Id\" = ?", encounterId). - Where("\"Employee\".\"Position_Code\" = ?", ero.EPCDoc) - - // Set Case - switch { - case dataAmbulatory.Class_Code == ere.ACCReg: - tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", erc.STCEEarlyMedic) - case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCAdm: - tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc, erc.STCEarlyRehab}) - case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCSeries: - tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", erc.STCEarlyRehab) - } - - if err = tx.Find(&dataSoapi).Error; err != nil { - return setDBError(event, err, encounterId) - } - - pl.SetLogInfo(event, nil, "complete") - return validateExistedSoapi(dataSoapi, &dataAmbulatory, event, mode) -} - -func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, event *pl.Event, mode string) error { - typeExist := make(map[erc.SoapiTypeCode]bool) - for _, s := range dataSoapi { - typeExist[s.TypeCode] = true - } - - required := []erc.SoapiTypeCode{} - - switch { - case dataAmbulatory.Class_Code == ere.ACCReg: - required = []erc.SoapiTypeCode{erc.STCEEarlyMedic} - case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCAdm: - required = []erc.SoapiTypeCode{erc.STCEEarlyMedic, erc.STCFunc, erc.STCEarlyRehab} - case dataAmbulatory.Class_Code == ere.ACCRme && dataAmbulatory.VisitMode_Code == ere.VMCSeries: - required = []erc.SoapiTypeCode{erc.STCEarlyRehab} - } - - var missing, existing []string - for _, code := range required { - if typeExist[code] { - existing = append(existing, string(code)) - } else { - missing = append(missing, string(code)) - } - } - - switch mode { - case "check-in": - if len(existing) > 0 { - return setSoapiError(event, fmt.Sprintf("Soapi type(s) %s exist, can't check-in", strings.Join(existing, ", "))) - } - case "check-out": - if len(missing) > 0 { - return setSoapiError(event, fmt.Sprintf("Soapi type(s) %s not found, can't check-out", strings.Join(missing, ", "))) - } - } - - return nil -} - -func setSoapiError(event *pl.Event, detail string) error { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "invalid-soapi-state", - Detail: detail, - } - return pl.SetLogError(event, detail) -} - -func setDBError(event *pl.Event, err error, ctx any) error { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Raw: err, - Code: "read-fail", - Detail: "Database read failed", - } - return pl.SetLogError(event, ctx) -} - -func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { - pl.SetLogInfo(event, "started", "DBUpdate") - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - result := tx. - Model(&er.Rehab{}). - Where("\"Encounter_Id\" = (?)", input.Encounter_Id). - Update("\"Doctor_Id\"", input.Doctor_Id) - - if result.Error != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-update-fail", - Detail: "Database update failed", - Raw: result.Error, - } - return pl.SetLogError(event, input) - } - - pl.SetLogInfo(event, nil, "complete") - return nil -} From 97e6437a4ce8eaa3e8defbd93c161abfd87586f6 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Tue, 4 Nov 2025 15:13:09 +0700 Subject: [PATCH 12/55] feat (control-letter): add doctor_id --- internal/domain/main-entities/control-letter/dto.go | 7 +++++++ internal/use-case/main-use-case/control-letter/helper.go | 1 + 2 files changed, 8 insertions(+) diff --git a/internal/domain/main-entities/control-letter/dto.go b/internal/domain/main-entities/control-letter/dto.go index 4beadd69..c2bab776 100644 --- a/internal/domain/main-entities/control-letter/dto.go +++ b/internal/domain/main-entities/control-letter/dto.go @@ -12,6 +12,7 @@ import ( // internal - domain - main-entities + ed "simrs-vx/internal/domain/main-entities/doctor" ee "simrs-vx/internal/domain/main-entities/encounter" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" @@ -23,6 +24,7 @@ type CreateDto struct { Unit_Id *uint `json:"unit_id"` Specialist_Id *uint `json:"specialist_id"` Subspecialist_Id *uint `json:"subspecialist_id"` + Doctor_Id *uint `json:"doctor_id"` Date *time.Time `json:"date"` } @@ -37,6 +39,7 @@ type FilterDto struct { Unit_Id *uint `json:"unit-id"` Specialist_Id *uint `json:"specialist-id"` Subspecialist_Id *uint `json:"subspecialist-id"` + Doctor_Id *uint `json:"doctor-id"` Date *time.Time `json:"date"` } @@ -77,6 +80,8 @@ type ResponseDto struct { Specialist *es.Specialist `json:"specialist,omitempty"` Subspecialist_Id *uint `json:"subspecialist_id"` Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` Date *time.Time `json:"date"` } @@ -90,6 +95,8 @@ func (d ControlLetter) ToResponse() ResponseDto { Specialist: d.Specialist, Subspecialist_Id: d.Subspecialist_Id, Subspecialist: d.Subspecialist, + Doctor_Id: d.Doctor_Id, + Doctor: d.Doctor, Date: d.Date, } resp.Main = d.Main diff --git a/internal/use-case/main-use-case/control-letter/helper.go b/internal/use-case/main-use-case/control-letter/helper.go index 9b1d3b23..5cc943c5 100644 --- a/internal/use-case/main-use-case/control-letter/helper.go +++ b/internal/use-case/main-use-case/control-letter/helper.go @@ -21,5 +21,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ControlLetter) { data.Unit_Id = inputSrc.Unit_Id data.Specialist_Id = inputSrc.Specialist_Id data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Doctor_Id = inputSrc.Doctor_Id data.Date = inputSrc.Date } From 66ee63a9b65e6b71554d81e63086c2d1f1c82d13 Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 4 Nov 2025 15:29:57 +0700 Subject: [PATCH 13/55] add therapy protocol --- internal/domain/main-entities/chemo/dto.go | 2 + .../main-entities/therapy-protocol/dto.go | 107 ++++++ .../interface/main-handler/chemo/handler.go | 5 + .../interface/main-handler/main-handler.go | 2 + .../main-handler/therapy-protocol/handler.go | 73 +++++ internal/use-case/main-use-case/chemo/case.go | 2 + .../main-use-case/therapy-protocol/case.go | 310 ++++++++++++++++++ .../main-use-case/therapy-protocol/helper.go | 34 ++ .../main-use-case/therapy-protocol/lib.go | 145 ++++++++ .../therapy-protocol/middleware-runner.go | 103 ++++++ .../therapy-protocol/middleware.go | 9 + .../main-use-case/therapy-protocol/tycovar.go | 44 +++ 12 files changed, 836 insertions(+) create mode 100644 internal/domain/main-entities/therapy-protocol/dto.go create mode 100644 internal/interface/main-handler/therapy-protocol/handler.go create mode 100644 internal/use-case/main-use-case/therapy-protocol/case.go create mode 100644 internal/use-case/main-use-case/therapy-protocol/helper.go create mode 100644 internal/use-case/main-use-case/therapy-protocol/lib.go create mode 100644 internal/use-case/main-use-case/therapy-protocol/middleware-runner.go create mode 100644 internal/use-case/main-use-case/therapy-protocol/middleware.go create mode 100644 internal/use-case/main-use-case/therapy-protocol/tycovar.go diff --git a/internal/domain/main-entities/chemo/dto.go b/internal/domain/main-entities/chemo/dto.go index 8317b259..653b5409 100644 --- a/internal/domain/main-entities/chemo/dto.go +++ b/internal/domain/main-entities/chemo/dto.go @@ -52,6 +52,8 @@ type DeleteDto struct { type VerifyDto struct { Id uint16 `json:"id"` Status_Code erc.DataVerifiedCode `json:"status_code"` + Bed *string `json:"bed" validate:"required"` + Needs *string `json:"needs" validate:"required"` pa.AuthInfo } diff --git a/internal/domain/main-entities/therapy-protocol/dto.go b/internal/domain/main-entities/therapy-protocol/dto.go new file mode 100644 index 00000000..f7a5f2e4 --- /dev/null +++ b/internal/domain/main-entities/therapy-protocol/dto.go @@ -0,0 +1,107 @@ +package therapy_protocol + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/encounter" + "simrs-vx/internal/domain/references/common" +) + +type CreateDto struct { + Encounter_Id *uint `json:"encounter_id"` + Doctor_Id *uint `json:"doctor_id"` + Anamnesis *string `json:"anamnesis" validate:"maxLength=2048"` + MedicalDiagnoses *string `json:"medicalDiagnoses"` + FunctionDiagnoses *string `json:"functionDiagnoses"` + Procedures *string `json:"procedures"` + SupportingExams *string `json:"supportingExams" validate:"maxLength=2048"` + Instruction *string `json:"instruction" validate:"maxLength=2048"` + Evaluation *string `json:"evaluation" validate:"maxLength=2048"` + WorkCauseStatus *string `json:"workCauseStatus"` + Frequency *uint `json:"frequency"` + IntervalUnit_Code *common.TimeUnitCode `json:"intervalUnit_code" validate:"maxLength=10"` + Duration *uint `json:"duration"` + DurationUnit_Code *common.TimeUnitCode `json:"durationUnit_code" validate:"maxLength=10"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Encounter_Id *uint `json:"encounter-id"` + Doctor_Id *uint `json:"doctor-id"` +} + +type ReadDetailDto struct { + Id uint `json:"id"` + Includes string `json:"includes"` +} + +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 + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + Anamnesis *string `json:"anamnesis"` + MedicalDiagnoses *string `json:"medicalDiagnoses"` + FunctionDiagnoses *string `json:"functionDiagnoses"` + Procedures *string `json:"procedures"` + SupportingExams *string `json:"supportingExams"` + Instruction *string `json:"instruction"` + Evaluation *string `json:"evaluation"` + WorkCauseStatus *string `json:"workCauseStatus"` + Frequency *uint `json:"frequency"` + IntervalUnit_Code *common.TimeUnitCode `json:"intervalUnit_code"` + Duration *uint `json:"duration"` + DurationUnit_Code *common.TimeUnitCode `json:"durationUnit_code"` +} + +func (d TherapyProtocol) ToResponse() ResponseDto { + resp := ResponseDto{ + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Doctor_Id: d.Doctor_Id, + Doctor: d.Doctor, + Anamnesis: d.Anamnesis, + MedicalDiagnoses: d.MedicalDiagnoses, + FunctionDiagnoses: d.FunctionDiagnoses, + Procedures: d.Procedures, + SupportingExams: d.SupportingExams, + Instruction: d.Instruction, + Evaluation: d.Evaluation, + WorkCauseStatus: d.WorkCauseStatus, + Frequency: d.Frequency, + IntervalUnit_Code: d.IntervalUnit_Code, + Duration: d.Duration, + DurationUnit_Code: d.DurationUnit_Code, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []TherapyProtocol) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/interface/main-handler/chemo/handler.go b/internal/interface/main-handler/chemo/handler.go index 90552020..18435479 100644 --- a/internal/interface/main-handler/chemo/handler.go +++ b/internal/interface/main-handler/chemo/handler.go @@ -84,11 +84,16 @@ func (obj myBase) Verify(w http.ResponseWriter, r *http.Request) { } dto := e.VerifyDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + dto.Id = uint16(id) authInfo, err := pa.GetAuthInfo(r) if err != nil { rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil) } + dto.AuthInfo = *authInfo dto.Status_Code = erc.DVCVerified res, err := u.Verify(dto) diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index baea92da..554de761 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -94,6 +94,7 @@ import ( specialistposition "simrs-vx/internal/interface/main-handler/specialist-position" subspecialist "simrs-vx/internal/interface/main-handler/subspecialist" subspecialistposition "simrs-vx/internal/interface/main-handler/subspecialist-position" + therapyprotocol "simrs-vx/internal/interface/main-handler/therapy-protocol" unit "simrs-vx/internal/interface/main-handler/unit" unitposition "simrs-vx/internal/interface/main-handler/unit-position" uom "simrs-vx/internal/interface/main-handler/uom" @@ -257,6 +258,7 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/ambulance-transport-req", ambulancetransportrequest.O) hc.RegCrud(r, "/v1/responsible-doctor-hist", responsibledoctorhist.O) hc.RegCrud(r, "/v1/adm-employee-hist", admemployeehist.O) + hc.RegCrud(r, "/v1/therapy-protocol", therapyprotocol.O) /******************** actor ********************/ hc.RegCrud(r, "/v1/person", person.O) diff --git a/internal/interface/main-handler/therapy-protocol/handler.go b/internal/interface/main-handler/therapy-protocol/handler.go new file mode 100644 index 00000000..2d9efc3b --- /dev/null +++ b/internal/interface/main-handler/therapy-protocol/handler.go @@ -0,0 +1,73 @@ +package therapy_protocol + +import ( + "net/http" + + rw "github.com/karincake/risoles" + sf "github.com/karincake/semprit" + + // ua "github.com/karincake/tumpeng/auth/svc" + + e "simrs-vx/internal/domain/main-entities/therapy-protocol" + u "simrs-vx/internal/use-case/main-use-case/therapy-protocol" +) + +type myBase struct{} + +var O myBase + +func (obj myBase) Create(w http.ResponseWriter, r *http.Request) { + dto := e.CreateDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + res, err := u.Create(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { + dto := e.ReadListDto{} + sf.UrlQueryParam(&dto, *r.URL) + res, err := u.ReadList(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + dto := e.ReadDetailDto{} + + sf.UrlQueryParam(&dto, *r.URL) + dto.Id = uint(id) + res, err := u.ReadDetail(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.UpdateDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + dto.Id = uint(id) + res, err := u.Update(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.DeleteDto{} + dto.Id = uint(id) + res, err := u.Delete(dto) + rw.DataResponse(w, res, err) +} diff --git a/internal/use-case/main-use-case/chemo/case.go b/internal/use-case/main-use-case/chemo/case.go index 541faa04..f7b3c7d3 100644 --- a/internal/use-case/main-use-case/chemo/case.go +++ b/internal/use-case/main-use-case/chemo/case.go @@ -311,6 +311,8 @@ func Verify(input e.VerifyDto) (*d.Data, error) { data.VerifiedAt = pu.GetTimeNow() data.Status_Code = input.Status_Code data.VerifiedBy_User_Id = &input.AuthInfo.User_Id + data.Bed = input.Bed + data.Needs = input.Needs err = tx.Save(&data).Error if err != nil { diff --git a/internal/use-case/main-use-case/therapy-protocol/case.go b/internal/use-case/main-use-case/therapy-protocol/case.go new file mode 100644 index 00000000..93cf05a4 --- /dev/null +++ b/internal/use-case/main-use-case/therapy-protocol/case.go @@ -0,0 +1,310 @@ +package therapy_protocol + +import ( + "strconv" + + "gorm.io/gorm" + + pl "simrs-vx/pkg/logger" + pu "simrs-vx/pkg/use-case-helper" + + dg "github.com/karincake/apem/db-gorm-pg" + d "github.com/karincake/dodol" + + ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/encounter" + e "simrs-vx/internal/domain/main-entities/therapy-protocol" + + ud "simrs-vx/internal/use-case/main-use-case/doctor" + ue "simrs-vx/internal/use-case/main-use-case/encounter" +) + +const source = "therapy-protocol" + +func Create(input e.CreateDto) (*d.Data, error) { + data := e.TherapyProtocol{} + + event := pl.Event{ + Feature: "Create", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "create") + + // validate foreign key + if err := validateForeignKey(input); err != nil { + return nil, err + } + + 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.TherapyProtocol + var dataList []e.TherapyProtocol + 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 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.TherapyProtocol + 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: input.Id} + var data *e.TherapyProtocol + var err error + + event := pl.Event{ + Feature: "Update", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "update") + + // validate foreign key + if err := validateForeignKey(input.CreateDto); err != nil { + return nil, err + } + + 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: input.Id} + var data *e.TherapyProtocol + 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 + +} + +func validateForeignKey(input e.CreateDto) error { + // validate encounter + if input.Encounter_Id != nil { + if _, err := ue.ReadDetail(ee.ReadDetailDto{Id: uint16(*input.Encounter_Id)}); err != nil { + return err + } + } + + // validate doctor_id + if input.Doctor_Id != nil { + if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Doctor_Id)}); err != nil { + return err + } + } + + return nil +} diff --git a/internal/use-case/main-use-case/therapy-protocol/helper.go b/internal/use-case/main-use-case/therapy-protocol/helper.go new file mode 100644 index 00000000..12e48747 --- /dev/null +++ b/internal/use-case/main-use-case/therapy-protocol/helper.go @@ -0,0 +1,34 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package therapy_protocol + +import ( + e "simrs-vx/internal/domain/main-entities/therapy-protocol" +) + +func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.TherapyProtocol) { + var inputSrc *e.CreateDto + if inputT, ok := any(input).(*e.CreateDto); ok { + inputSrc = inputT + } else { + inputTemp := any(input).(*e.UpdateDto) + inputSrc = &inputTemp.CreateDto + } + + data.Encounter_Id = inputSrc.Encounter_Id + data.Doctor_Id = inputSrc.Doctor_Id + data.Anamnesis = inputSrc.Anamnesis + data.MedicalDiagnoses = inputSrc.MedicalDiagnoses + data.FunctionDiagnoses = inputSrc.FunctionDiagnoses + data.Procedures = inputSrc.Procedures + data.SupportingExams = inputSrc.SupportingExams + data.Instruction = inputSrc.Instruction + data.Evaluation = inputSrc.Evaluation + data.WorkCauseStatus = inputSrc.WorkCauseStatus + data.Frequency = inputSrc.Frequency + data.IntervalUnit_Code = inputSrc.IntervalUnit_Code + data.Duration = inputSrc.Duration + data.DurationUnit_Code = inputSrc.DurationUnit_Code +} diff --git a/internal/use-case/main-use-case/therapy-protocol/lib.go b/internal/use-case/main-use-case/therapy-protocol/lib.go new file mode 100644 index 00000000..550ef327 --- /dev/null +++ b/internal/use-case/main-use-case/therapy-protocol/lib.go @@ -0,0 +1,145 @@ +package therapy_protocol + +import ( + "errors" + e "simrs-vx/internal/domain/main-entities/therapy-protocol" + + 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.TherapyProtocol, error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + data := e.TherapyProtocol{} + 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.TherapyProtocol, *e.MetaDto, error) { + pl.SetLogInfo(event, input, "started", "DBReadList") + data := []e.TherapyProtocol{} + pagination := gh.Pagination{} + count := int64(0) + meta := e.MetaDto{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + tx = tx. + Model(&e.TherapyProtocol{}). + Scopes(gh.Preload(input.Includes)). + Scopes(gh.Filter(input.FilterDto)). + Count(&count). + Scopes(gh.Paginate(input, &pagination)). + Order("\"CreatedAt\" DESC") + + if err := tx.Find(&data).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, &meta, nil + } + return nil, nil, plh.HandleListError(input, event, err) + } + + 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.TherapyProtocol, error) { + pl.SetLogInfo(event, input, "started", "DBReadDetail") + data := e.TherapyProtocol{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if err := tx. + Scopes(gh.Preload(input.Includes)). + First(&data, input.Id). + 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.TherapyProtocol, 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.TherapyProtocol, 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 +} diff --git a/internal/use-case/main-use-case/therapy-protocol/middleware-runner.go b/internal/use-case/main-use-case/therapy-protocol/middleware-runner.go new file mode 100644 index 00000000..4391b63a --- /dev/null +++ b/internal/use-case/main-use-case/therapy-protocol/middleware-runner.go @@ -0,0 +1,103 @@ +package therapy_protocol + +import ( + e "simrs-vx/internal/domain/main-entities/therapy-protocol" + 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.TherapyProtocol) 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.TherapyProtocol) 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.TherapyProtocol) 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.TherapyProtocol) 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.TherapyProtocol) 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 +} diff --git a/internal/use-case/main-use-case/therapy-protocol/middleware.go b/internal/use-case/main-use-case/therapy-protocol/middleware.go new file mode 100644 index 00000000..a2f3626f --- /dev/null +++ b/internal/use-case/main-use-case/therapy-protocol/middleware.go @@ -0,0 +1,9 @@ +package therapy_protocol + +// example of middleware +// func init() { +// createPreMw = append(createPreMw, +// CreateMw{Name: "modif-input", Func: pm.ModifInput}, +// CreateMw{Name: "check-data", Func: pm.CheckData}, +// ) +// } diff --git a/internal/use-case/main-use-case/therapy-protocol/tycovar.go b/internal/use-case/main-use-case/therapy-protocol/tycovar.go new file mode 100644 index 00000000..a027e334 --- /dev/null +++ b/internal/use-case/main-use-case/therapy-protocol/tycovar.go @@ -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 therapy_protocol + +import ( + "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/therapy-protocol" +) + +type createMw struct { + Name string + Func func(input *e.CreateDto, data *e.TherapyProtocol, tx *gorm.DB) error +} + +type readListMw struct { + Name string + Func func(input *e.ReadListDto, data *e.TherapyProtocol, tx *gorm.DB) error +} + +type readDetailMw struct { + Name string + Func func(input *e.ReadDetailDto, data *e.TherapyProtocol, 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 From 28927d4c8b3d5d979ef78edf053d14bc1b60824b Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 4 Nov 2025 16:13:19 +0700 Subject: [PATCH 14/55] add chemo protocol --- .../main-entities/adm-employee-hist/dto.go | 5 +- .../main-entities/chemo-protocol/dto.go | 91 ++++++ .../responsible-doctor-hist/dto.go | 5 +- .../main-handler/chemo-protocol/handler.go | 72 +++++ .../interface/main-handler/main-handler.go | 2 + .../main-use-case/adm-employee-hist/lib.go | 21 +- .../main-use-case/chemo-protocol/case.go | 277 ++++++++++++++++++ .../main-use-case/chemo-protocol/helper.go | 28 ++ .../main-use-case/chemo-protocol/lib.go | 147 ++++++++++ .../chemo-protocol/middleware-runner.go | 103 +++++++ .../chemo-protocol/middleware.go | 9 + .../main-use-case/chemo-protocol/tycovar.go | 44 +++ .../responsible-doctor-hist/lib.go | 21 +- 13 files changed, 787 insertions(+), 38 deletions(-) create mode 100644 internal/domain/main-entities/chemo-protocol/dto.go create mode 100644 internal/interface/main-handler/chemo-protocol/handler.go create mode 100644 internal/use-case/main-use-case/chemo-protocol/case.go create mode 100644 internal/use-case/main-use-case/chemo-protocol/helper.go create mode 100644 internal/use-case/main-use-case/chemo-protocol/lib.go create mode 100644 internal/use-case/main-use-case/chemo-protocol/middleware-runner.go create mode 100644 internal/use-case/main-use-case/chemo-protocol/middleware.go create mode 100644 internal/use-case/main-use-case/chemo-protocol/tycovar.go diff --git a/internal/domain/main-entities/adm-employee-hist/dto.go b/internal/domain/main-entities/adm-employee-hist/dto.go index 9a5d838f..a3500060 100644 --- a/internal/domain/main-entities/adm-employee-hist/dto.go +++ b/internal/domain/main-entities/adm-employee-hist/dto.go @@ -28,9 +28,8 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code *string `json:"code"` - Includes string `json:"includes"` + Id uint16 `json:"id"` + Includes string `json:"includes"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/chemo-protocol/dto.go b/internal/domain/main-entities/chemo-protocol/dto.go new file mode 100644 index 00000000..04ea0023 --- /dev/null +++ b/internal/domain/main-entities/chemo-protocol/dto.go @@ -0,0 +1,91 @@ +package chemo_protocol + +import ( + // std + "time" + + // internal - domain - references + erc "simrs-vx/internal/domain/references/common" + + // internal - domain - main-entities + ecore "simrs-vx/internal/domain/base-entities/core" + ee "simrs-vx/internal/domain/main-entities/encounter" +) + +type CreateDto struct { + Encounter_Id *uint `json:"encounter_id"` + Patient_Weight *float32 `json:"patient_weight"` + Patient_Height *float32 `json:"patient_height"` + Diagnoses *string `json:"diagnoses"` + Duration *uint `json:"duration"` + DurationUnit_Code *erc.TimeUnitCode `json:"durationUnit_code"` + StartDate *time.Time `json:"startDate"` + EndDate *time.Time `json:"endDate"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Encounter_Id *uint `json:"encounter-id"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` + Includes string `json:"includes"` +} + +type UpdateDto struct { + Id uint16 `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint16 `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Patient_Weight *float32 `json:"patient_weight"` + Patient_Height *float32 `json:"patient_height"` + Diagnoses *string `json:"diagnoses"` + Duration *uint `json:"duration"` + DurationUnit_Code *erc.TimeUnitCode `json:"durationUnit_code"` + StartDate *time.Time `json:"startDate"` + EndDate *time.Time `json:"endDate"` +} + +func (d ChemoProtocol) ToResponse() ResponseDto { + resp := ResponseDto{ + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Patient_Weight: d.Patient_Weight, + Patient_Height: d.Patient_Height, + Diagnoses: d.Diagnoses, + Duration: d.Duration, + DurationUnit_Code: d.DurationUnit_Code, + StartDate: d.StartDate, + EndDate: d.EndDate, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []ChemoProtocol) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/responsible-doctor-hist/dto.go b/internal/domain/main-entities/responsible-doctor-hist/dto.go index 342faffa..68c8dd21 100644 --- a/internal/domain/main-entities/responsible-doctor-hist/dto.go +++ b/internal/domain/main-entities/responsible-doctor-hist/dto.go @@ -28,9 +28,8 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code *string `json:"code"` - Includes string `json:"includes"` + Id uint16 `json:"id"` + Includes string `json:"includes"` } type UpdateDto struct { diff --git a/internal/interface/main-handler/chemo-protocol/handler.go b/internal/interface/main-handler/chemo-protocol/handler.go new file mode 100644 index 00000000..60d9db4d --- /dev/null +++ b/internal/interface/main-handler/chemo-protocol/handler.go @@ -0,0 +1,72 @@ +package chemo_protocol + +import ( + "net/http" + + rw "github.com/karincake/risoles" + sf "github.com/karincake/semprit" + + // ua "github.com/karincake/tumpeng/auth/svc" + e "simrs-vx/internal/domain/main-entities/chemo-protocol" + u "simrs-vx/internal/use-case/main-use-case/chemo-protocol" +) + +type myBase struct{} + +var O myBase + +func (obj myBase) Create(w http.ResponseWriter, r *http.Request) { + dto := e.CreateDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + res, err := u.Create(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { + dto := e.ReadListDto{} + sf.UrlQueryParam(&dto, *r.URL) + res, err := u.ReadList(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + dto := e.ReadDetailDto{} + sf.UrlQueryParam(&dto, *r.URL) + + dto.Id = uint16(id) + res, err := u.ReadDetail(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.UpdateDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + dto.Id = uint16(id) + res, err := u.Update(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.DeleteDto{} + dto.Id = uint16(id) + res, err := u.Delete(dto) + rw.DataResponse(w, res, err) +} diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 554de761..1c703b64 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -9,6 +9,7 @@ import ( ambulancetransportrequest "simrs-vx/internal/interface/main-handler/ambulance-transport-req" auth "simrs-vx/internal/interface/main-handler/authentication" chemo "simrs-vx/internal/interface/main-handler/chemo" + chemoprotocol "simrs-vx/internal/interface/main-handler/chemo-protocol" consultation "simrs-vx/internal/interface/main-handler/consultation" controlletter "simrs-vx/internal/interface/main-handler/control-letter" counter "simrs-vx/internal/interface/main-handler/counter" @@ -259,6 +260,7 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/responsible-doctor-hist", responsibledoctorhist.O) hc.RegCrud(r, "/v1/adm-employee-hist", admemployeehist.O) hc.RegCrud(r, "/v1/therapy-protocol", therapyprotocol.O) + hc.RegCrud(r, "/v1/chemo-protocol", chemoprotocol.O) /******************** actor ********************/ hc.RegCrud(r, "/v1/person", person.O) diff --git a/internal/use-case/main-use-case/adm-employee-hist/lib.go b/internal/use-case/main-use-case/adm-employee-hist/lib.go index dc03b28a..6bdcbe22 100644 --- a/internal/use-case/main-use-case/adm-employee-hist/lib.go +++ b/internal/use-case/main-use-case/adm-employee-hist/lib.go @@ -75,29 +75,18 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e pl.SetLogInfo(event, input, "started", "DBReadDetail") data := e.AdmEmployeeHist{} - var tx, getData *gorm.DB + var tx *gorm.DB if len(dbx) > 0 { tx = dbx[0] } else { tx = dg.I } - switch { - case input.Id != 0: - getData = tx.First(&data, input.Id) - case input.Code != nil && *input.Code != "": - getData = tx.Where("code = ?", *input.Code).First(&data) - default: - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-read-detail-fail", - Detail: "either Id or Code must be provided", - } + if err := tx. + Scopes(gh.Preload(input.Includes)). + First(&data, input.Id). + Error; err != nil { - return nil, pl.SetLogError(event, nil) - } - - if err := getData.Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/chemo-protocol/case.go b/internal/use-case/main-use-case/chemo-protocol/case.go new file mode 100644 index 00000000..4e007d28 --- /dev/null +++ b/internal/use-case/main-use-case/chemo-protocol/case.go @@ -0,0 +1,277 @@ +package chemo_protocol + +import ( + "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" + + e "simrs-vx/internal/domain/main-entities/chemo-protocol" +) + +const source = "chemo-protocol" + +func Create(input e.CreateDto) (*d.Data, error) { + data := e.ChemoProtocol{} + + 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.ChemoProtocol + var dataList []e.ChemoProtocol + 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 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.ChemoProtocol + 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: input.Id} + var data *e.ChemoProtocol + 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: input.Id} + var data *e.ChemoProtocol + 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 + +} diff --git a/internal/use-case/main-use-case/chemo-protocol/helper.go b/internal/use-case/main-use-case/chemo-protocol/helper.go new file mode 100644 index 00000000..885e6fbb --- /dev/null +++ b/internal/use-case/main-use-case/chemo-protocol/helper.go @@ -0,0 +1,28 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package chemo_protocol + +import ( + e "simrs-vx/internal/domain/main-entities/chemo-protocol" +) + +func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ChemoProtocol) { + var inputSrc *e.CreateDto + if inputT, ok := any(input).(*e.CreateDto); ok { + inputSrc = inputT + } else { + inputTemp := any(input).(*e.UpdateDto) + inputSrc = &inputTemp.CreateDto + } + + data.Encounter_Id = inputSrc.Encounter_Id + data.Patient_Weight = inputSrc.Patient_Weight + data.Patient_Height = inputSrc.Patient_Height + data.Diagnoses = inputSrc.Diagnoses + data.Duration = inputSrc.Duration + data.DurationUnit_Code = inputSrc.DurationUnit_Code + data.StartDate = inputSrc.StartDate + data.EndDate = inputSrc.EndDate +} diff --git a/internal/use-case/main-use-case/chemo-protocol/lib.go b/internal/use-case/main-use-case/chemo-protocol/lib.go new file mode 100644 index 00000000..22e8808c --- /dev/null +++ b/internal/use-case/main-use-case/chemo-protocol/lib.go @@ -0,0 +1,147 @@ +package chemo_protocol + +import ( + "errors" + + plh "simrs-vx/pkg/lib-helper" + pl "simrs-vx/pkg/logger" + pu "simrs-vx/pkg/use-case-helper" + + "gorm.io/gorm" + + dg "github.com/karincake/apem/db-gorm-pg" + gh "github.com/karincake/getuk" + + e "simrs-vx/internal/domain/main-entities/chemo-protocol" +) + +func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.ChemoProtocol, error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + data := e.ChemoProtocol{} + 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.ChemoProtocol, *e.MetaDto, error) { + pl.SetLogInfo(event, input, "started", "DBReadList") + data := []e.ChemoProtocol{} + pagination := gh.Pagination{} + count := int64(0) + meta := e.MetaDto{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + tx = tx. + Model(&e.ChemoProtocol{}). + Scopes(gh.Preload(input.Includes)). + Scopes(gh.Filter(input.FilterDto)). + Count(&count). + Scopes(gh.Paginate(input, &pagination)). + Order("\"CreatedAt\" DESC") + + if err := tx.Find(&data).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, &meta, nil + } + return nil, nil, plh.HandleListError(input, event, err) + } + + 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.ChemoProtocol, error) { + pl.SetLogInfo(event, input, "started", "DBReadDetail") + data := e.ChemoProtocol{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if err := tx. + Scopes(gh.Preload(input.Includes)). + First(&data, input.Id). + 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.ChemoProtocol, 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.ChemoProtocol, 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 +} diff --git a/internal/use-case/main-use-case/chemo-protocol/middleware-runner.go b/internal/use-case/main-use-case/chemo-protocol/middleware-runner.go new file mode 100644 index 00000000..7c932d7b --- /dev/null +++ b/internal/use-case/main-use-case/chemo-protocol/middleware-runner.go @@ -0,0 +1,103 @@ +package chemo_protocol + +import ( + e "simrs-vx/internal/domain/main-entities/chemo-protocol" + 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.ChemoProtocol) 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.ChemoProtocol) 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.ChemoProtocol) 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.ChemoProtocol) 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.ChemoProtocol) 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 +} diff --git a/internal/use-case/main-use-case/chemo-protocol/middleware.go b/internal/use-case/main-use-case/chemo-protocol/middleware.go new file mode 100644 index 00000000..a438fd1c --- /dev/null +++ b/internal/use-case/main-use-case/chemo-protocol/middleware.go @@ -0,0 +1,9 @@ +package chemo_protocol + +// example of middleware +// func init() { +// createPreMw = append(createPreMw, +// CreateMw{Name: "modif-input", Func: pm.ModifInput}, +// CreateMw{Name: "check-data", Func: pm.CheckData}, +// ) +// } diff --git a/internal/use-case/main-use-case/chemo-protocol/tycovar.go b/internal/use-case/main-use-case/chemo-protocol/tycovar.go new file mode 100644 index 00000000..f4822996 --- /dev/null +++ b/internal/use-case/main-use-case/chemo-protocol/tycovar.go @@ -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 chemo_protocol + +import ( + "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/chemo-protocol" +) + +type createMw struct { + Name string + Func func(input *e.CreateDto, data *e.ChemoProtocol, tx *gorm.DB) error +} + +type readListMw struct { + Name string + Func func(input *e.ReadListDto, data *e.ChemoProtocol, tx *gorm.DB) error +} + +type readDetailMw struct { + Name string + Func func(input *e.ReadDetailDto, data *e.ChemoProtocol, 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 diff --git a/internal/use-case/main-use-case/responsible-doctor-hist/lib.go b/internal/use-case/main-use-case/responsible-doctor-hist/lib.go index d91294fe..3f035d5e 100644 --- a/internal/use-case/main-use-case/responsible-doctor-hist/lib.go +++ b/internal/use-case/main-use-case/responsible-doctor-hist/lib.go @@ -75,29 +75,18 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e pl.SetLogInfo(event, input, "started", "DBReadDetail") data := e.ResponsibleDoctorHist{} - var tx, getData *gorm.DB + var tx *gorm.DB if len(dbx) > 0 { tx = dbx[0] } else { tx = dg.I } - switch { - case input.Id != 0: - getData = tx.First(&data, input.Id) - case input.Code != nil && *input.Code != "": - getData = tx.Where("code = ?", *input.Code).First(&data) - default: - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-read-detail-fail", - Detail: "either Id or Code must be provided", - } + if err := tx. + Scopes(gh.Preload(input.Includes)). + First(&data, input.Id). + Error; err != nil { - return nil, pl.SetLogError(event, nil) - } - - if err := getData.Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } From 4173b20165db8f1377f9e75023c71201452a351d Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 4 Nov 2025 16:27:47 +0700 Subject: [PATCH 15/55] delete debug --- internal/domain/main-entities/ambulatory/dto.go | 1 + internal/domain/main-entities/encounter/dto.go | 4 ++-- internal/use-case/main-use-case/encounter/helper.go | 2 +- internal/use-case/main-use-case/encounter/lib.go | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/domain/main-entities/ambulatory/dto.go b/internal/domain/main-entities/ambulatory/dto.go index 42ece735..f580467a 100644 --- a/internal/domain/main-entities/ambulatory/dto.go +++ b/internal/domain/main-entities/ambulatory/dto.go @@ -50,6 +50,7 @@ type ResponseDto struct { func (d Ambulatory) ToResponse() ResponseDto { resp := ResponseDto{ + Encounter_Id: d.Encounter_Id, Class_Code: d.Class_Code, VisitMode_Code: d.VisitMode_Code, } diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 0d5e1aae..6782b18c 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -48,8 +48,8 @@ type CreateDto struct { Appointment_Id *uint `json:"appointment_id"` RefTypeCode ere.RefTypeCode `json:"refTypeCode"` NewStatus bool `json:"newStatus"` - VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` // if subClass_Code is rehab - AllocatedVisitCount *int `json:"allocatedVisitCount"` + VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` // if subClass_Code is rehab + AllocatedVisitCount *int `json:"allocatedVisitCount"` // if subClass_Code is rehab and VisitMode_Code is "adm" pa.AuthInfo } diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 4bf7be60..67cef58b 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -641,7 +641,7 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea } } - err = dg.I.Debug(). + err = dg.I. Model(&es.Soapi{}). Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). Where("\"Encounter_Id\" = ?", enc.Id). diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index d80fd513..0c51a8d6 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -276,7 +276,6 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo } err = tx. - Debug(). Model(&e.Encounter{}). Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). Where("\"Patient_Id\" = ?", i.Patient_Id). From 5c8c5511d9c51c65257136d22fc2d28ed4bf8a28 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 5 Nov 2025 11:18:38 +0700 Subject: [PATCH 16/55] migration from server --- cmd/main-migration/migrations/atlas.sum | 142 ++++++++++++------------ 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 40b66b02..d2c79b63 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,71 +1,71 @@ -h1:drtrRtMhlNYK0c9wV3CUkJvXwWgrD8xGPPJy9wlcvNA= -20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= -20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= -20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= -20250908062323.sql h1:oXl6Z143tOpIl4EfP4B8JNU8LrMvVmHEtCgAfiB4gs8= -20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= -20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= -20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= -20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= -20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= -20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= -20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= -20250917045138.sql h1:jKe1Z0uOLG4SGBYM+S/3P+/zMPztmgoderD5swnMuCg= -20250917093645.sql h1:cNI3Pbz1R3LxvIXLuexafJFCXUXrmuFCgXXJ2sG+FW0= -20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= -20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= -20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= -20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= -20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ= -20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg= -20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34= -20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= -20250930140351.sql h1:9AAEG1AnOAH+o0+oHL5G7I8vqlWOhwRlCGyyCpT/y1Q= -20251002085604.sql h1:3xZ68eYp4urXRnvotNH1XvG2mYOSDV/j3zHEZ/txg5E= -20251003032030.sql h1:HB+mQ2lXMNomHDpaRhB/9IwYI9/YiDO5eOJ+nAQH/jw= -20251005060450.sql h1:LbtCE2b+8osM3CvnmQJH1uCPtn+d7WchsslBOz8bL3Q= -20251006041122.sql h1:MlS7f21z06sutnf9dIekt5fuHJr4lgcQ4uCuCXAGsfc= -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:nxnXmooIJ6r1mmzwnw+6efxLfc/k9h2aE6RMptPRons= -20251008073620.sql h1:6YsJp1W4SmQJ1lxpqF27BBlDC1zqhw7Yhc7pLzQTY6M= -20251009042854.sql h1:nkBV+R6j0fg7/JY6wH3eb5Vv0asJLnXmb6lINfT/GLQ= -20251009052657.sql h1:EPvdsib5rzCGPryd10HShGKvFPwM/R5S2lIVwtYxpms= -20251010031743.sql h1:T8IZmx8/btRFKLzTe78MzcBsPJNodnLvB0tby9QkirQ= -20251010070721.sql h1:5NQUk/yOV6sABLCB7swx++YIOyJe6MnU+yt1nRzde5w= -20251010072711.sql h1:ZJNqR2piyu8xJhBvVABSlnGEoKSKae3wuEs+wshPe4k= -20251013044536.sql h1:0Xjw8fNILiT8nnfrJDZgQnPf3dntmIoilbapnih8AE4= -20251013051438.sql h1:lfSuw5mgJnePBJamvhZ81osFIouXeiIEiSZ/evdwo48= -20251013081808.sql h1:ijgjNX08G6GBjA/ks8EKtb7P7Y7Cg7zbhqEOruGnv6M= -20251014060047.sql h1:0jqj49WTtneEIMQDBoo4c095ZGi8sCrA8NnHBrPU6D8= -20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg= -20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14= -20251015045455.sql h1:MeLWmMhAOAz8b15Dd7IAQnt6JxjSml02XCXK22C0Lpg= -20251016010845.sql h1:4BncQdDOasRZJkzVJrSJJA7091A9VPNVx/faUCUPhBM= -20251016011023.sql h1:9JB9eFZKURK5RoCVDKR6glSvdJ8NTXrN7K/4q51zkz4= -20251016062912.sql h1:ACNn0fe+EMqUt3hoY+Dr3uqAV/QICBa1+mIW7fUc9Fk= -20251017060617.sql h1:4T3t9ifWrEQTPMSM0XJ98pF7Qdt+UfgtMui17bhrnWI= -20251017082207.sql h1:8vLG1l/saRRMHXkyA4nelJyjaSddhZd6r7R+Uo4JS/c= -20251018032635.sql h1:2xey5gnO3y2XSOrU8MLlIfoylPKbRGDRtHDD07B3MbQ= -20251018040322.sql h1:k/pdNiSoT8zFPqNQ/avOD0vYkNh3BTD64IlHrfVXr7I= -20251019093915.sql h1:hFcQE0y+p5dZiVwePGsRGto9m/q6kJNiUZbVDd5Rnjk= -20251020062553.sql h1:Iw7hulcm5iRQlfW+ygA4iTPxLqkxx6h9vXMXEwUAHKs= -20251021041042.sql h1:wMgSivBV2A0NDcsLmKGIp0kMcVh2IODSG9b4dgzCaOM= -20251021075552.sql h1:8gfSMAglflNO6L0sSzxFNEubYN8/O4thT7OQT+WH+3M= -20251023044432.sql h1:MkvajJs3bfk9+wHvQ43/ccAluJEBARm1gWr1u92ccLA= -20251024034832.sql h1:x3s3VEVYLOSKLAFxJGb2+c1FyTMMvPE+9k4Ew7rKQaI= -20251024074315.sql h1:EjAjelgi5qAfcRq/8vPTlGGYHvAKxNTllm8f0SzZDns= -20251025013451.sql h1:6hnuIiwYiG+6nLhOY/+Yyn+I6ZCFNRZxrJNqBV6HLqE= -20251025013609.sql h1:evPJaTD8WxYRMOJZHkSr7ONLx9PYxT+ankzQt9c/sJ0= -20251027075128.sql h1:/iFQBM1sytjqpyQSOx61q33gnorMgxTiFVSuL6bQqsM= -20251027091406.sql h1:eCZGtUkxAzEAqpC9UsGpP8Df9mS0DEOqSl885LgqpvM= -20251102002037.sql h1:lFJbuoZ2LMQnUNGdcwHVY3Xlfslgzu9t2WByT8yfOZI= -20251102091932.sql h1:rmdhb5m+P+fU8jROBZNyeYgZKuQvucsuljXv4ZVzvks= -20251103081637.sql h1:tf3BcwTeIw+oxMEisKDDfyKnBfalTLs8b0PJA8JWYxY= -20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk= -20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= -20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= -20251104084135.sql h1:Y4coFrHgDXd/DM8ihEy+qMkOSrO8M4SI4shRCJIiBBA= +h1:XcM4BDP+DX+wOQ5ldDbxOZWeqFBrXyFHkmVIlIdlfBs= +20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY= +20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= +20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI= +20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= +20250908073811.sql h1:gOi5cnGG1htlpfizybYmUIT0vYjZTBfXiI0nPSYK2u8= +20250908073839.sql h1:cWNDA4YikjoOteAJuNLFILjQUJPFB6o8Wxreiek4QyI= +20250910055902.sql h1:nxxOGnU0BbH/v3IPgeIOXOwH8d3tKomw7h6FTeMnnBs= +20250915123412.sql h1:mz7SiWfrdf0qE1VTSAAnA/147d6gyp6ry5vZ2bR9SH0= +20250916043819.sql h1:RHXVtmMkB6wfv06HfPyHMBmUfIpFt1xveafNz0kwKnE= +20250917040616.sql h1:MYVDht+akBlzQGKNu2hTTTLPEcH1bxT/Q8MK6WEtuhs= +20250917040751.sql h1:J79YyS2JzWgh5oKXMTgh67uo3gLxKaAsxRiZmSIfjBs= +20250917045138.sql h1:/SM1N4O8X3yxpoJgMEARmS1uOkuLKsTOy4PLsRCOKaQ= +20250917093645.sql h1:PNBTGZ7s10e5b5+Tie8YfVQBN0zKtJ5T34oK1iOUEb4= +20250918073552.sql h1:jG7+g3i8ODYaJdcdZz12v3nbsZ5mB9wG6kWnGyTQIRI= +20250918073742.sql h1:j+rgw7puxE7s+phqPVZHmPk0af3rcaA56Itp86y1suY= +20250918074745.sql h1:rPmP4DXs6OnY4Vp+xO/z9jFpJt/RrJ52SJJjIIxeDvc= +20250923025134.sql h1:2r6pcwnBSU5Y9Czk1OHBoh4yZXiMtEca9X8843fTEX0= +20250924051317.sql h1:iUAk2gsGoEGIPQ0lEEUp8maMSId8emNbP+kP712ABIA= +20250929034321.sql h1:UlpALNVmdi95zOIT0yc6ZyTj9bBjQEIpZhvgrc52M+k= +20250929034428.sql h1:feF+H4nDyHh5bdx48Oiz0A1qecZfi6v3qTTdjzJ45Dg= +20250930025550.sql h1:6XT1kXI3Z3ZIxxmvT7poufZWWCW0QiejZPaFV5wBnjI= +20250930140351.sql h1:HxnmAbh9gCy8jwl/9ycGktiByaUripsjFFvohofY2CY= +20251002085604.sql h1:SjLPi+ZN6qDccK3DaEQCgNsZpPwr5kynWXwbwEsziCI= +20251003032030.sql h1:oHfxNSuqTxU8Zaf9H+h8TuUb1Da03wcyc6hZjDrUQ2s= +20251005060450.sql h1:GIuCcrd4MwjmXpvbzDzPYL18BV3QaZZ+Y2FmEzjvi0E= +20251006041122.sql h1:uNDQbSw0M08lYoMvUNlQtS3iDzpPM1ixT13ugSAoWjE= +20251006045658.sql h1:z+t7yCK54Q4SSiF9kUyUhkYB2F+kzSW9TB7ogxd9wzw= +20251006045928.sql h1:1lATLFLp4BWwGZqAjZdP0Dc6ypNXiYcwjoNkqGa8NFE= +20251007022859.sql h1:HXXwWrkyvzJzJGAt9mGskCRBBV/c1JfPmfjDocmJhQ4= +20251008031337.sql h1:Ln5pCF3Hxa5foHZLcds+z/us2eH6VAhhEj3w0TAGlVs= +20251008031554.sql h1:aB4MUS2lmqG0//4HKUWorcPSpWya0VC4QItvGyskEVI= +20251008052346.sql h1:MI3AZgU5XcwZT2OvvlWAxdRtL0eJ3jjRwt56IY1+pRU= +20251008073620.sql h1:sztWXuSNYwpEraaSapSsYwno75LO5H/N7ob7OJQ8X/A= +20251009042854.sql h1:TnPXj+dCJls3IU//cuqJZymyBzZMKs7ayazfgtAFRxM= +20251009052657.sql h1:leXbs0CP8r5dRilmYyLRk1MICqak3ea1/LWMtFrijqQ= +20251010031743.sql h1:SgHNY/lQ88G2F4nZyMfiOkDntb+gtOR+nEQLqXBTwv4= +20251010070721.sql h1:AnJnhXsMzDvK4AFgYw6B16Kpo/hljrZtcpc9m2VOSHQ= +20251010072711.sql h1:aXPTtNwLcTuw8C/yAxwxvqs0ayEjNzI1uuE0vE3ERa8= +20251013044536.sql h1:7Pq6JcvTpPBYDCW2dz3HdgUwY65HlhEVWy9TiG8iONE= +20251013051438.sql h1:X6t8bkqpUYYokBunSufMQUe5vCg0VyO6dxbm7ngosUc= +20251013081808.sql h1:495pLguXL2Ozh+ycn4UYZgZbn6WbjXNbyZUc3JU8qhI= +20251014060047.sql h1:nCgImMRGHhziiW57O1ofWaXCAPGaCOHN7PldQ3OSmM4= +20251014063537.sql h1:2cLmID79jP6cuQ1YJaWTtghFiM1GtHMC0ZQl30Hpy1M= +20251014063720.sql h1:bzLKKVAjSHgDFoiI/glj7t1ETlSAKx+AlsIAaP0ru2g= +20251015045455.sql h1:S547+UugQhlTRcn1Lm1IfqT5RNPttIWIiD+RTx69YaE= +20251016010845.sql h1:c9DUvxl17pUkf0azdYGM/YDzYxIJkLcfZOcMI4rL+R0= +20251016011023.sql h1:u3ivg83bXgYHBbojbWpemLxPE9Dmmj53B6LXo664jxw= +20251016062912.sql h1:W9n1hWchfYkqNX9LO9uxFxEXAb/iY+Pexjnhmp6PbgI= +20251017060617.sql h1:VU6yZ2+LfHpDZ3+TIH40t3F5YXPCpTppuF9+uSqa4b8= +20251017082207.sql h1:QshZslfedckz7iDpSGmPyY9sP6dy6ckHbs8L1TuXIA4= +20251018032635.sql h1:M1U/9W/F9wlW5YDmVAmHFfUJU7FWFaX0DblpfZcYWrE= +20251018040322.sql h1:Zk/vw0e6AzWFO2ElLOzB+OrSz6k+h1Ynxp0TImAzxwY= +20251019093915.sql h1:3Q0kPiZwJnHn5rAvdh0w1LBdiA7W2xBmZWncoPXb044= +20251020062553.sql h1:mJwC/J8GzPAIXckNMvy1f/Nguk2VVf8roD/Raclhbao= +20251021041042.sql h1:d1BAOGAQhqr+oOwcpAVozUsTh457VSDEk2qQFavGG58= +20251021075552.sql h1:TNChGQ1Zlr/1iQ6qvK4iDTAJpe6L/z/M6e/O0SkQVaM= +20251023044432.sql h1:GA2AdJk2ULyjr6igtu9C/CEi4YUIks8r9jXGGaCvPsk= +20251024034832.sql h1:RXmbEhMkOLK5g1QL6up8iRPcwYfo89oLP26ZHvrUK9o= +20251024074315.sql h1:3GnPQSbuAAfMa8oWDyBjhXqn1j1zunY/w0ydX0IGPrA= +20251025013451.sql h1:5eNrA9LDxA4i5CCP7wSyOgFZ6t6jBWVil+oGzJpkJ2E= +20251025013609.sql h1:+N6EHc1kv3hqf16CUhXe+UITPmoxOPfi4MECLmJXNrc= +20251027075128.sql h1:PQflgsjce/p2ClbybLtdehdPNDcMZ9Lb1vd98xd0K8E= +20251027091406.sql h1:bYXV57GvodCMjg0/ox+XKGIAGhrDlVuJ1wO4foNEKtQ= +20251102002037.sql h1:ZcwULsJU2lI9t5pX7ukmfAHSx4ZxdxLUX6jzLDc2SrU= +20251102091932.sql h1:A6y9j4wAqm4/HfMDxhpy/ChDn3UNRVN99KGgSCX+e18= +20251103081637.sql h1:RFqJNhJItSwJQaMP5IcQ14mL7eQ3EJjGZua9zLWzwMU= +20251104042334.sql h1:BbjLAwImggvI6489FQgD+S/AaafeiZut8k19TdH7XUE= +20251104043530.sql h1:Y0sOQqgnHxd5vKPA4+4fAGGdWCv6duKAYgHnjRJZUIc= +20251104080952.sql h1:hDHzFs/k+NhPYJ64ifbVp+nTJLMCG5MIMJU1zBMP0V0= +20251104084135.sql h1:p97mW1MPtPrMWJKy/KZqvymMO/vlelnXp43N9bZVCTI= From cd775e33664151e7ac11d8c652511a20fa56567e Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Wed, 5 Nov 2025 11:03:47 +0700 Subject: [PATCH 17/55] feat/trx-order: added entities for antibiotic --- .../main-entities/antibiotic-in-use/dto.go | 76 +++++++++++++++++++ .../main-entities/antibiotic-in-use/entity.go | 15 ++++ .../antibiotic-src-category/dto.go | 66 ++++++++++++++++ .../antibiotic-src-category/entity.go | 11 +++ .../main-entities/antibiotic-src/dto.go | 76 +++++++++++++++++++ .../main-entities/antibiotic-src/entity.go | 17 +++++ internal/interface/migration/main-entities.go | 4 + 7 files changed, 265 insertions(+) create mode 100644 internal/domain/main-entities/antibiotic-in-use/dto.go create mode 100644 internal/domain/main-entities/antibiotic-in-use/entity.go create mode 100644 internal/domain/main-entities/antibiotic-src-category/dto.go create mode 100644 internal/domain/main-entities/antibiotic-src-category/entity.go create mode 100644 internal/domain/main-entities/antibiotic-src/dto.go create mode 100644 internal/domain/main-entities/antibiotic-src/entity.go diff --git a/internal/domain/main-entities/antibiotic-in-use/dto.go b/internal/domain/main-entities/antibiotic-in-use/dto.go new file mode 100644 index 00000000..7fbce2dd --- /dev/null +++ b/internal/domain/main-entities/antibiotic-in-use/dto.go @@ -0,0 +1,76 @@ +package antibioticinuse + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + eas "simrs-vx/internal/domain/main-entities/antibiotic-src" + emo "simrs-vx/internal/domain/main-entities/mcu-order" + erc "simrs-vx/internal/domain/references/common" + "time" +) + +type CreateDto struct { + McuOrder_Id *uint `json:"mcuOrder_id"` + AntibioticSrc_Id *uint `json:"antibioticSrc_id"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + McuOrder_Id *uint `json:"mcu-order-id"` + AntibioticSrc_Id *uint `json:"mcu-src-id"` + Result *string `json:"result"` + Status_Code erc.DataStatusCode `json:"status-code"` +} +type ReadDetailDto struct { + Id uint `json:"id"` +} + +type UpdateDto struct { + Id uint `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint `json:"id"` +} + +type SetScheduleDto struct { + Id uint `json:"id"` + ExaminationDate *time.Time `json:"examinationDate"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + McuOrder_Id *uint `json:"mcuOrder_id"` + McuOrder *emo.McuOrder `json:"mcuOrder,omitempty"` + AntibioticSrc_Id *uint `json:"antibioticSrc_id"` + Antibiotic *eas.CreateDto `json:"mcuSrc,omitempty"` +} + +func (d AntibioticInUse) ToResponse() ResponseDto { + resp := ResponseDto{ + McuOrder_Id: d.McuOrder_Id, + McuOrder: d.McuOrder, + AntibioticSrc_Id: d.AntibioticSrc_Id, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []AntibioticInUse) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/antibiotic-in-use/entity.go b/internal/domain/main-entities/antibiotic-in-use/entity.go new file mode 100644 index 00000000..6d924d4f --- /dev/null +++ b/internal/domain/main-entities/antibiotic-in-use/entity.go @@ -0,0 +1,15 @@ +package antibioticinuse + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + eas "simrs-vx/internal/domain/main-entities/antibiotic-src" + emo "simrs-vx/internal/domain/main-entities/mcu-order" +) + +type AntibioticInUse struct { + ecore.Main // adjust this according to the needs + McuOrder_Id *uint `json:"mcuOrder_id" gorm:"uniqueIndex:idx_order_src"` + McuOrder *emo.McuOrder `json:"mcuOrder,omitempty" gorm:"foreignKey:McuOrder_Id;references:Id"` + AntibioticSrc_Id *uint `json:"antibioticSrcSrc_id" gorm:"uniqueIndex:idx_order_src"` + AntibioticSrc *eas.AntibioticSrc `json:"antibioticSrc,omitempty" gorm:"foreignKey:AntibioticSrc_Id;references:Id"` +} diff --git a/internal/domain/main-entities/antibiotic-src-category/dto.go b/internal/domain/main-entities/antibiotic-src-category/dto.go new file mode 100644 index 00000000..90f420fb --- /dev/null +++ b/internal/domain/main-entities/antibiotic-src-category/dto.go @@ -0,0 +1,66 @@ +package antibioticsrccategory + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type CreateDto struct { + Code string `json:"code" validate:"maxLength=20"` + Name string `json:"name" validate:"maxLength=50"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Sort string `json:"sort"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Code string `json:"code"` + Name string `json:"name"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` + Code *string `json:"code"` +} + +type UpdateDto struct { + Id uint16 `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint16 `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.SmallMain + Code string `json:"code"` + Name string `json:"name"` +} + +func (d AntibioticSrcCategory) ToResponse() ResponseDto { + resp := ResponseDto{ + Code: d.Code, + Name: d.Name, + } + resp.SmallMain = d.SmallMain + return resp +} + +func ToResponseList(data []AntibioticSrcCategory) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/antibiotic-src-category/entity.go b/internal/domain/main-entities/antibiotic-src-category/entity.go new file mode 100644 index 00000000..31169d9d --- /dev/null +++ b/internal/domain/main-entities/antibiotic-src-category/entity.go @@ -0,0 +1,11 @@ +package antibioticsrccategory + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type AntibioticSrcCategory struct { + ecore.SmallMain // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:20"` + Name string `json:"name" gorm:"size:50"` +} diff --git a/internal/domain/main-entities/antibiotic-src/dto.go b/internal/domain/main-entities/antibiotic-src/dto.go new file mode 100644 index 00000000..9a7a2846 --- /dev/null +++ b/internal/domain/main-entities/antibiotic-src/dto.go @@ -0,0 +1,76 @@ +package antibioticsrc + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ei "simrs-vx/internal/domain/main-entities/item" +) + +type CreateDto struct { + Code string `json:"code" validate:"maxLength=20"` + Name string `json:"name" validate:"maxLength=50"` + AntibioticSrcCategory_Code *string `json:"antibioticSrcCategory_code" validate:"maxLength=20"` + Item_Id *uint `json:"item_id"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Sort string `json:"sort"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Code string `json:"code"` + Name string `json:"name"` + AntibioticSrcCategory_Code *string `json:"antibiotic-src-category-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` + Code *string `json:"code"` +} + +type UpdateDto struct { + Id uint16 `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint16 `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Code string `json:"code"` + Name string `json:"name"` + AntibioticSrcCategory_Code *string `json:"antibioticSrcCategory_code"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty"` +} + +func (d AntibioticSrc) ToResponse() ResponseDto { + resp := ResponseDto{ + Code: d.Code, + Name: d.Name, + AntibioticSrcCategory_Code: d.AntibioticSrcCategory_Code, + Item_Id: d.Item_Id, + Item: d.Item, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []AntibioticSrc) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/antibiotic-src/entity.go b/internal/domain/main-entities/antibiotic-src/entity.go new file mode 100644 index 00000000..83089e07 --- /dev/null +++ b/internal/domain/main-entities/antibiotic-src/entity.go @@ -0,0 +1,17 @@ +package antibioticsrc + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + easc "simrs-vx/internal/domain/main-entities/antibiotic-src-category" + ei "simrs-vx/internal/domain/main-entities/item" +) + +type AntibioticSrc struct { + ecore.Main // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:20"` + Name string `json:"name" gorm:"size:50"` + AntibioticSrcCategory_Code *string `json:"antibioticSrcCategory_code" gorm:"size:20"` + AntibioticSrcCategory *easc.AntibioticSrcCategory `json:"antibioticSrcCategory,omitempty" gorm:"foreignKey:AntibioticSrcCategory_Code;references:Code"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` +} diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 6507202e..0248a0d1 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -5,6 +5,8 @@ import ( admemployeehist "simrs-vx/internal/domain/main-entities/adm-employee-hist" ambulancetransportreq "simrs-vx/internal/domain/main-entities/ambulance-transport-req" ambulatory "simrs-vx/internal/domain/main-entities/ambulatory" + antibioticinuse "simrs-vx/internal/domain/main-entities/antibiotic-in-use" + antibioticsrccategory "simrs-vx/internal/domain/main-entities/antibiotic-src-category" appointment "simrs-vx/internal/domain/main-entities/appointment" chemo "simrs-vx/internal/domain/main-entities/chemo" consultation "simrs-vx/internal/domain/main-entities/consultation" @@ -172,6 +174,8 @@ func getMainEntities() []any { &mcuorderitem.McuOrderItem{}, &mcusubsrc.McuSubSrc{}, &mcuordersubitem.McuOrderSubItem{}, + &antibioticsrccategory.AntibioticSrcCategory{}, + &antibioticinuse.AntibioticInUse{}, &consultation.Consultation{}, &chemo.Chemo{}, &midwife.Midwife{}, From c5643420f117e91b4dab1e8b2ebfb7fe86482ab1 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Wed, 5 Nov 2025 11:50:07 +0700 Subject: [PATCH 18/55] feat/tex-orders: updated migration --- .../migrations/20251105044629.sql | 38 +++++ cmd/main-migration/migrations/atlas.sum | 143 +++++++++--------- 2 files changed, 110 insertions(+), 71 deletions(-) create mode 100644 cmd/main-migration/migrations/20251105044629.sql diff --git a/cmd/main-migration/migrations/20251105044629.sql b/cmd/main-migration/migrations/20251105044629.sql new file mode 100644 index 00000000..24ba9d05 --- /dev/null +++ b/cmd/main-migration/migrations/20251105044629.sql @@ -0,0 +1,38 @@ +-- Create "AntibioticSrcCategory" table +CREATE TABLE "public"."AntibioticSrcCategory" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_AntibioticSrcCategory_Code" UNIQUE ("Code") +); +-- Create "AntibioticSrc" table +CREATE TABLE "public"."AntibioticSrc" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "AntibioticSrcCategory_Code" character varying(20) NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_AntibioticSrc_Code" UNIQUE ("Code"), + CONSTRAINT "fk_AntibioticSrc_AntibioticSrcCategory" FOREIGN KEY ("AntibioticSrcCategory_Code") REFERENCES "public"."AntibioticSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AntibioticSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "AntibioticInUse" table +CREATE TABLE "public"."AntibioticInUse" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "McuOrder_Id" bigint NULL, + "AntibioticSrc_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_AntibioticInUse_AntibioticSrc" FOREIGN KEY ("AntibioticSrc_Id") REFERENCES "public"."AntibioticSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AntibioticInUse_McuOrder" FOREIGN KEY ("McuOrder_Id") REFERENCES "public"."McuOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index d2c79b63..b51ad522 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,71 +1,72 @@ -h1:XcM4BDP+DX+wOQ5ldDbxOZWeqFBrXyFHkmVIlIdlfBs= -20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY= -20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= -20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI= -20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= -20250908073811.sql h1:gOi5cnGG1htlpfizybYmUIT0vYjZTBfXiI0nPSYK2u8= -20250908073839.sql h1:cWNDA4YikjoOteAJuNLFILjQUJPFB6o8Wxreiek4QyI= -20250910055902.sql h1:nxxOGnU0BbH/v3IPgeIOXOwH8d3tKomw7h6FTeMnnBs= -20250915123412.sql h1:mz7SiWfrdf0qE1VTSAAnA/147d6gyp6ry5vZ2bR9SH0= -20250916043819.sql h1:RHXVtmMkB6wfv06HfPyHMBmUfIpFt1xveafNz0kwKnE= -20250917040616.sql h1:MYVDht+akBlzQGKNu2hTTTLPEcH1bxT/Q8MK6WEtuhs= -20250917040751.sql h1:J79YyS2JzWgh5oKXMTgh67uo3gLxKaAsxRiZmSIfjBs= -20250917045138.sql h1:/SM1N4O8X3yxpoJgMEARmS1uOkuLKsTOy4PLsRCOKaQ= -20250917093645.sql h1:PNBTGZ7s10e5b5+Tie8YfVQBN0zKtJ5T34oK1iOUEb4= -20250918073552.sql h1:jG7+g3i8ODYaJdcdZz12v3nbsZ5mB9wG6kWnGyTQIRI= -20250918073742.sql h1:j+rgw7puxE7s+phqPVZHmPk0af3rcaA56Itp86y1suY= -20250918074745.sql h1:rPmP4DXs6OnY4Vp+xO/z9jFpJt/RrJ52SJJjIIxeDvc= -20250923025134.sql h1:2r6pcwnBSU5Y9Czk1OHBoh4yZXiMtEca9X8843fTEX0= -20250924051317.sql h1:iUAk2gsGoEGIPQ0lEEUp8maMSId8emNbP+kP712ABIA= -20250929034321.sql h1:UlpALNVmdi95zOIT0yc6ZyTj9bBjQEIpZhvgrc52M+k= -20250929034428.sql h1:feF+H4nDyHh5bdx48Oiz0A1qecZfi6v3qTTdjzJ45Dg= -20250930025550.sql h1:6XT1kXI3Z3ZIxxmvT7poufZWWCW0QiejZPaFV5wBnjI= -20250930140351.sql h1:HxnmAbh9gCy8jwl/9ycGktiByaUripsjFFvohofY2CY= -20251002085604.sql h1:SjLPi+ZN6qDccK3DaEQCgNsZpPwr5kynWXwbwEsziCI= -20251003032030.sql h1:oHfxNSuqTxU8Zaf9H+h8TuUb1Da03wcyc6hZjDrUQ2s= -20251005060450.sql h1:GIuCcrd4MwjmXpvbzDzPYL18BV3QaZZ+Y2FmEzjvi0E= -20251006041122.sql h1:uNDQbSw0M08lYoMvUNlQtS3iDzpPM1ixT13ugSAoWjE= -20251006045658.sql h1:z+t7yCK54Q4SSiF9kUyUhkYB2F+kzSW9TB7ogxd9wzw= -20251006045928.sql h1:1lATLFLp4BWwGZqAjZdP0Dc6ypNXiYcwjoNkqGa8NFE= -20251007022859.sql h1:HXXwWrkyvzJzJGAt9mGskCRBBV/c1JfPmfjDocmJhQ4= -20251008031337.sql h1:Ln5pCF3Hxa5foHZLcds+z/us2eH6VAhhEj3w0TAGlVs= -20251008031554.sql h1:aB4MUS2lmqG0//4HKUWorcPSpWya0VC4QItvGyskEVI= -20251008052346.sql h1:MI3AZgU5XcwZT2OvvlWAxdRtL0eJ3jjRwt56IY1+pRU= -20251008073620.sql h1:sztWXuSNYwpEraaSapSsYwno75LO5H/N7ob7OJQ8X/A= -20251009042854.sql h1:TnPXj+dCJls3IU//cuqJZymyBzZMKs7ayazfgtAFRxM= -20251009052657.sql h1:leXbs0CP8r5dRilmYyLRk1MICqak3ea1/LWMtFrijqQ= -20251010031743.sql h1:SgHNY/lQ88G2F4nZyMfiOkDntb+gtOR+nEQLqXBTwv4= -20251010070721.sql h1:AnJnhXsMzDvK4AFgYw6B16Kpo/hljrZtcpc9m2VOSHQ= -20251010072711.sql h1:aXPTtNwLcTuw8C/yAxwxvqs0ayEjNzI1uuE0vE3ERa8= -20251013044536.sql h1:7Pq6JcvTpPBYDCW2dz3HdgUwY65HlhEVWy9TiG8iONE= -20251013051438.sql h1:X6t8bkqpUYYokBunSufMQUe5vCg0VyO6dxbm7ngosUc= -20251013081808.sql h1:495pLguXL2Ozh+ycn4UYZgZbn6WbjXNbyZUc3JU8qhI= -20251014060047.sql h1:nCgImMRGHhziiW57O1ofWaXCAPGaCOHN7PldQ3OSmM4= -20251014063537.sql h1:2cLmID79jP6cuQ1YJaWTtghFiM1GtHMC0ZQl30Hpy1M= -20251014063720.sql h1:bzLKKVAjSHgDFoiI/glj7t1ETlSAKx+AlsIAaP0ru2g= -20251015045455.sql h1:S547+UugQhlTRcn1Lm1IfqT5RNPttIWIiD+RTx69YaE= -20251016010845.sql h1:c9DUvxl17pUkf0azdYGM/YDzYxIJkLcfZOcMI4rL+R0= -20251016011023.sql h1:u3ivg83bXgYHBbojbWpemLxPE9Dmmj53B6LXo664jxw= -20251016062912.sql h1:W9n1hWchfYkqNX9LO9uxFxEXAb/iY+Pexjnhmp6PbgI= -20251017060617.sql h1:VU6yZ2+LfHpDZ3+TIH40t3F5YXPCpTppuF9+uSqa4b8= -20251017082207.sql h1:QshZslfedckz7iDpSGmPyY9sP6dy6ckHbs8L1TuXIA4= -20251018032635.sql h1:M1U/9W/F9wlW5YDmVAmHFfUJU7FWFaX0DblpfZcYWrE= -20251018040322.sql h1:Zk/vw0e6AzWFO2ElLOzB+OrSz6k+h1Ynxp0TImAzxwY= -20251019093915.sql h1:3Q0kPiZwJnHn5rAvdh0w1LBdiA7W2xBmZWncoPXb044= -20251020062553.sql h1:mJwC/J8GzPAIXckNMvy1f/Nguk2VVf8roD/Raclhbao= -20251021041042.sql h1:d1BAOGAQhqr+oOwcpAVozUsTh457VSDEk2qQFavGG58= -20251021075552.sql h1:TNChGQ1Zlr/1iQ6qvK4iDTAJpe6L/z/M6e/O0SkQVaM= -20251023044432.sql h1:GA2AdJk2ULyjr6igtu9C/CEi4YUIks8r9jXGGaCvPsk= -20251024034832.sql h1:RXmbEhMkOLK5g1QL6up8iRPcwYfo89oLP26ZHvrUK9o= -20251024074315.sql h1:3GnPQSbuAAfMa8oWDyBjhXqn1j1zunY/w0ydX0IGPrA= -20251025013451.sql h1:5eNrA9LDxA4i5CCP7wSyOgFZ6t6jBWVil+oGzJpkJ2E= -20251025013609.sql h1:+N6EHc1kv3hqf16CUhXe+UITPmoxOPfi4MECLmJXNrc= -20251027075128.sql h1:PQflgsjce/p2ClbybLtdehdPNDcMZ9Lb1vd98xd0K8E= -20251027091406.sql h1:bYXV57GvodCMjg0/ox+XKGIAGhrDlVuJ1wO4foNEKtQ= -20251102002037.sql h1:ZcwULsJU2lI9t5pX7ukmfAHSx4ZxdxLUX6jzLDc2SrU= -20251102091932.sql h1:A6y9j4wAqm4/HfMDxhpy/ChDn3UNRVN99KGgSCX+e18= -20251103081637.sql h1:RFqJNhJItSwJQaMP5IcQ14mL7eQ3EJjGZua9zLWzwMU= -20251104042334.sql h1:BbjLAwImggvI6489FQgD+S/AaafeiZut8k19TdH7XUE= -20251104043530.sql h1:Y0sOQqgnHxd5vKPA4+4fAGGdWCv6duKAYgHnjRJZUIc= -20251104080952.sql h1:hDHzFs/k+NhPYJ64ifbVp+nTJLMCG5MIMJU1zBMP0V0= -20251104084135.sql h1:p97mW1MPtPrMWJKy/KZqvymMO/vlelnXp43N9bZVCTI= +h1:6MaKjqJ77v0HFibPPeCdp8Bwg2qOZlEKNgHWc2zq6T0= +20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= +20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= +20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= +20250908062323.sql h1:oXl6Z143tOpIl4EfP4B8JNU8LrMvVmHEtCgAfiB4gs8= +20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= +20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= +20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= +20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= +20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= +20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= +20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= +20250917045138.sql h1:jKe1Z0uOLG4SGBYM+S/3P+/zMPztmgoderD5swnMuCg= +20250917093645.sql h1:cNI3Pbz1R3LxvIXLuexafJFCXUXrmuFCgXXJ2sG+FW0= +20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= +20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= +20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= +20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= +20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ= +20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg= +20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34= +20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= +20250930140351.sql h1:9AAEG1AnOAH+o0+oHL5G7I8vqlWOhwRlCGyyCpT/y1Q= +20251002085604.sql h1:3xZ68eYp4urXRnvotNH1XvG2mYOSDV/j3zHEZ/txg5E= +20251003032030.sql h1:HB+mQ2lXMNomHDpaRhB/9IwYI9/YiDO5eOJ+nAQH/jw= +20251005060450.sql h1:LbtCE2b+8osM3CvnmQJH1uCPtn+d7WchsslBOz8bL3Q= +20251006041122.sql h1:MlS7f21z06sutnf9dIekt5fuHJr4lgcQ4uCuCXAGsfc= +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:nxnXmooIJ6r1mmzwnw+6efxLfc/k9h2aE6RMptPRons= +20251008073620.sql h1:6YsJp1W4SmQJ1lxpqF27BBlDC1zqhw7Yhc7pLzQTY6M= +20251009042854.sql h1:nkBV+R6j0fg7/JY6wH3eb5Vv0asJLnXmb6lINfT/GLQ= +20251009052657.sql h1:EPvdsib5rzCGPryd10HShGKvFPwM/R5S2lIVwtYxpms= +20251010031743.sql h1:T8IZmx8/btRFKLzTe78MzcBsPJNodnLvB0tby9QkirQ= +20251010070721.sql h1:5NQUk/yOV6sABLCB7swx++YIOyJe6MnU+yt1nRzde5w= +20251010072711.sql h1:ZJNqR2piyu8xJhBvVABSlnGEoKSKae3wuEs+wshPe4k= +20251013044536.sql h1:0Xjw8fNILiT8nnfrJDZgQnPf3dntmIoilbapnih8AE4= +20251013051438.sql h1:lfSuw5mgJnePBJamvhZ81osFIouXeiIEiSZ/evdwo48= +20251013081808.sql h1:ijgjNX08G6GBjA/ks8EKtb7P7Y7Cg7zbhqEOruGnv6M= +20251014060047.sql h1:0jqj49WTtneEIMQDBoo4c095ZGi8sCrA8NnHBrPU6D8= +20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg= +20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14= +20251015045455.sql h1:MeLWmMhAOAz8b15Dd7IAQnt6JxjSml02XCXK22C0Lpg= +20251016010845.sql h1:4BncQdDOasRZJkzVJrSJJA7091A9VPNVx/faUCUPhBM= +20251016011023.sql h1:9JB9eFZKURK5RoCVDKR6glSvdJ8NTXrN7K/4q51zkz4= +20251016062912.sql h1:ACNn0fe+EMqUt3hoY+Dr3uqAV/QICBa1+mIW7fUc9Fk= +20251017060617.sql h1:4T3t9ifWrEQTPMSM0XJ98pF7Qdt+UfgtMui17bhrnWI= +20251017082207.sql h1:8vLG1l/saRRMHXkyA4nelJyjaSddhZd6r7R+Uo4JS/c= +20251018032635.sql h1:2xey5gnO3y2XSOrU8MLlIfoylPKbRGDRtHDD07B3MbQ= +20251018040322.sql h1:k/pdNiSoT8zFPqNQ/avOD0vYkNh3BTD64IlHrfVXr7I= +20251019093915.sql h1:hFcQE0y+p5dZiVwePGsRGto9m/q6kJNiUZbVDd5Rnjk= +20251020062553.sql h1:Iw7hulcm5iRQlfW+ygA4iTPxLqkxx6h9vXMXEwUAHKs= +20251021041042.sql h1:wMgSivBV2A0NDcsLmKGIp0kMcVh2IODSG9b4dgzCaOM= +20251021075552.sql h1:8gfSMAglflNO6L0sSzxFNEubYN8/O4thT7OQT+WH+3M= +20251023044432.sql h1:MkvajJs3bfk9+wHvQ43/ccAluJEBARm1gWr1u92ccLA= +20251024034832.sql h1:x3s3VEVYLOSKLAFxJGb2+c1FyTMMvPE+9k4Ew7rKQaI= +20251024074315.sql h1:EjAjelgi5qAfcRq/8vPTlGGYHvAKxNTllm8f0SzZDns= +20251025013451.sql h1:6hnuIiwYiG+6nLhOY/+Yyn+I6ZCFNRZxrJNqBV6HLqE= +20251025013609.sql h1:evPJaTD8WxYRMOJZHkSr7ONLx9PYxT+ankzQt9c/sJ0= +20251027075128.sql h1:/iFQBM1sytjqpyQSOx61q33gnorMgxTiFVSuL6bQqsM= +20251027091406.sql h1:eCZGtUkxAzEAqpC9UsGpP8Df9mS0DEOqSl885LgqpvM= +20251102002037.sql h1:lFJbuoZ2LMQnUNGdcwHVY3Xlfslgzu9t2WByT8yfOZI= +20251102091932.sql h1:rmdhb5m+P+fU8jROBZNyeYgZKuQvucsuljXv4ZVzvks= +20251103081637.sql h1:tf3BcwTeIw+oxMEisKDDfyKnBfalTLs8b0PJA8JWYxY= +20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk= +20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= +20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= +20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= +20251105044629.sql h1:aS4nm+7hPU3krzm5qouyEf1+d+aAPtlkQ2zgxgV9rXs= From 34af55c1521fe1d6d5380cc0ba2699b2f92ad082 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Wed, 5 Nov 2025 13:10:06 +0700 Subject: [PATCH 19/55] feat (control-letter): remove includes value on read detail --- internal/use-case/main-use-case/control-letter/case.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/use-case/main-use-case/control-letter/case.go b/internal/use-case/main-use-case/control-letter/case.go index 7ff38a63..6f28c43e 100644 --- a/internal/use-case/main-use-case/control-letter/case.go +++ b/internal/use-case/main-use-case/control-letter/case.go @@ -150,8 +150,6 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { return err } - input.Includes = "encounter,unit,specialist,subspecialist" - if data, err = ReadDetailData(input, &event, tx); err != nil { return err } From c94a9e47fb2e952b69b7ff4988498cf80d9b4c5a Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Wed, 5 Nov 2025 13:14:24 +0700 Subject: [PATCH 20/55] feat (control-letter): add query param --- internal/interface/main-handler/control-letter/handler.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/interface/main-handler/control-letter/handler.go b/internal/interface/main-handler/control-letter/handler.go index d6a73fe0..b0714b25 100644 --- a/internal/interface/main-handler/control-letter/handler.go +++ b/internal/interface/main-handler/control-letter/handler.go @@ -38,6 +38,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { return } dto := e.ReadDetailDto{} + sf.UrlQueryParam(&dto, *r.URL) dto.Id = uint16(id) res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) From d1d63b7bb397da34842f4370dd8053b944c7a3ca Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Wed, 5 Nov 2025 19:17:45 +0700 Subject: [PATCH 21/55] feat/trx-orders: removed Item from AntibioticSrc --- cmd/main-migration/migrations/20251105121808.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 5 +++-- internal/domain/main-entities/antibiotic-src/dto.go | 4 ++-- internal/domain/main-entities/antibiotic-src/entity.go | 5 ++--- 4 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 cmd/main-migration/migrations/20251105121808.sql diff --git a/cmd/main-migration/migrations/20251105121808.sql b/cmd/main-migration/migrations/20251105121808.sql new file mode 100644 index 00000000..41c1edf0 --- /dev/null +++ b/cmd/main-migration/migrations/20251105121808.sql @@ -0,0 +1,2 @@ +-- Modify "AntibioticSrc" table +ALTER TABLE "public"."AntibioticSrc" DROP COLUMN "Item_Id"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index b51ad522..88a3f39c 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:6MaKjqJ77v0HFibPPeCdp8Bwg2qOZlEKNgHWc2zq6T0= +h1:c6psxONIBPkfVLCpAnWAm81SgT25UQT6hgO8KAG6O5M= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -69,4 +69,5 @@ h1:6MaKjqJ77v0HFibPPeCdp8Bwg2qOZlEKNgHWc2zq6T0= 20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= 20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= 20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= -20251105044629.sql h1:aS4nm+7hPU3krzm5qouyEf1+d+aAPtlkQ2zgxgV9rXs= +20251105044629.sql h1:4NU27HeKUNFsV82LacnwmnCSAH0pSbZR9J9/ZESRs6M= +20251105121808.sql h1:uPFEHJ6pZbuo8+3giskNg4I91MrNRgrR1dMIe7kL+4g= diff --git a/internal/domain/main-entities/antibiotic-src/dto.go b/internal/domain/main-entities/antibiotic-src/dto.go index 9a7a2846..dd453ae3 100644 --- a/internal/domain/main-entities/antibiotic-src/dto.go +++ b/internal/domain/main-entities/antibiotic-src/dto.go @@ -60,8 +60,8 @@ func (d AntibioticSrc) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, AntibioticSrcCategory_Code: d.AntibioticSrcCategory_Code, - Item_Id: d.Item_Id, - Item: d.Item, + // Item_Id: d.Item_Id, + // Item: d.Item, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/antibiotic-src/entity.go b/internal/domain/main-entities/antibiotic-src/entity.go index 83089e07..6cb8cc85 100644 --- a/internal/domain/main-entities/antibiotic-src/entity.go +++ b/internal/domain/main-entities/antibiotic-src/entity.go @@ -3,7 +3,6 @@ package antibioticsrc import ( ecore "simrs-vx/internal/domain/base-entities/core" easc "simrs-vx/internal/domain/main-entities/antibiotic-src-category" - ei "simrs-vx/internal/domain/main-entities/item" ) type AntibioticSrc struct { @@ -12,6 +11,6 @@ type AntibioticSrc struct { Name string `json:"name" gorm:"size:50"` AntibioticSrcCategory_Code *string `json:"antibioticSrcCategory_code" gorm:"size:20"` AntibioticSrcCategory *easc.AntibioticSrcCategory `json:"antibioticSrcCategory,omitempty" gorm:"foreignKey:AntibioticSrcCategory_Code;references:Code"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + // Item_Id *uint `json:"item_id"` + // Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } From 42265e95f747fb7756870f82a525e780ee47c997 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 11:04:40 +0700 Subject: [PATCH 22/55] doctor all ids into code --- .../migrations/20251106035305.sql | 4 +++ .../migrations/20251106040137.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 6 ++-- .../domain/main-entities/doctor/entity.go | 30 +++++++++++-------- .../domain/main-entities/employee/entity.go | 18 ++++++----- .../domain/references/encounter/encounter.go | 1 + 6 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106035305.sql create mode 100644 cmd/main-migration/migrations/20251106040137.sql diff --git a/cmd/main-migration/migrations/20251106035305.sql b/cmd/main-migration/migrations/20251106035305.sql new file mode 100644 index 00000000..d2ab1e94 --- /dev/null +++ b/cmd/main-migration/migrations/20251106035305.sql @@ -0,0 +1,4 @@ +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" ADD COLUMN "SIP_ExpiredDate" timestamptz NULL, ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL, ADD CONSTRAINT "uni_Doctor_Specialist_Code" UNIQUE ("Specialist_Code"), ADD CONSTRAINT "uni_Doctor_Subspecialist_Code" UNIQUE ("Subspecialist_Code"), ADD CONSTRAINT "uni_Doctor_Unit_Code" UNIQUE ("Unit_Code"); +-- Modify "Employee" table +ALTER TABLE "public"."Employee" ADD COLUMN "Contract_ExpiredDate" timestamptz NULL; diff --git a/cmd/main-migration/migrations/20251106040137.sql b/cmd/main-migration/migrations/20251106040137.sql new file mode 100644 index 00000000..f9cb71cc --- /dev/null +++ b/cmd/main-migration/migrations/20251106040137.sql @@ -0,0 +1,2 @@ +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" DROP CONSTRAINT "uni_Doctor_Specialist_Code", DROP CONSTRAINT "uni_Doctor_Subspecialist_Code", DROP CONSTRAINT "uni_Doctor_Unit_Code"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 88a3f39c..d6b62389 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:c6psxONIBPkfVLCpAnWAm81SgT25UQT6hgO8KAG6O5M= +h1:yLtZj2e+mxp2L0eRUjFUIrC1GID4BB3/8x6LaHS+v10= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -70,4 +70,6 @@ h1:c6psxONIBPkfVLCpAnWAm81SgT25UQT6hgO8KAG6O5M= 20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= 20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= 20251105044629.sql h1:4NU27HeKUNFsV82LacnwmnCSAH0pSbZR9J9/ZESRs6M= -20251105121808.sql h1:uPFEHJ6pZbuo8+3giskNg4I91MrNRgrR1dMIe7kL+4g= +20251105121808.sql h1:fii6LjqWYjrm/pEIqttfvJI6QEUL49gque8wYHh1+yI= +20251106035305.sql h1:hRkWZYLQvjmROqlu9xvuXrPQcBKf6yUGTTbSd0lKbmI= +20251106040137.sql h1:ifT65MV7h0sws5EGBOGefRqxSaZqapEeupuhHMJipyw= diff --git a/internal/domain/main-entities/doctor/entity.go b/internal/domain/main-entities/doctor/entity.go index ec882838..014c6c17 100644 --- a/internal/domain/main-entities/doctor/entity.go +++ b/internal/domain/main-entities/doctor/entity.go @@ -6,19 +6,25 @@ import ( es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" eu "simrs-vx/internal/domain/main-entities/unit" + "time" ) type Doctor struct { - ecore.Main // adjust this according to the needs - Code *string `json:"code" gorm:"unique;size:20"` - 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"` - SIP_Number *string `json:"sip_number" gorm:"unique;size:20"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` + ecore.Main // adjust this according to the needs + Code *string `json:"code" gorm:"unique;size:20"` + 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"` + SIP_Number *string `json:"sip_number" gorm:"unique;size:20"` + SIP_ExpiredDate *time.Time `json:"sip_expiredDate"` + Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code" gorm:"size:10"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` + // Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` + Specialist_Id *uint16 `json:"specialist_id"` + Specialist_Code *string `json:"specialist_code" gorm:"size:10"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` + Subspecialist_Id *uint16 `json:"subspecialist_id"` + Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` } diff --git a/internal/domain/main-entities/employee/entity.go b/internal/domain/main-entities/employee/entity.go index 7a770be0..299ae021 100644 --- a/internal/domain/main-entities/employee/entity.go +++ b/internal/domain/main-entities/employee/entity.go @@ -6,15 +6,17 @@ import ( eu "simrs-vx/internal/domain/main-entities/user" erc "simrs-vx/internal/domain/references/common" erg "simrs-vx/internal/domain/references/organization" + "time" ) type Employee struct { - ecore.Main // adjust this according to the needs - User_Id *uint `json:"user_id"` - User *eu.User `json:"user,omitempty" gorm:"foreignKey:User_Id;references:Id"` - Person_Id *uint `json:"person_id"` - Person *ep.Person `json:"person,omitempty" gorm:"foreignKey:Person_Id;references:Id"` - Position_Code *erg.EmployeePositionCode `json:"position_code" gorm:"size:20"` - Number *string `json:"number" gorm:"size:20"` - Status_Code erc.ActiveStatusCode `json:"status_code" gorm:"not null;size:10"` + ecore.Main // adjust this according to the needs + User_Id *uint `json:"user_id"` + User *eu.User `json:"user,omitempty" gorm:"foreignKey:User_Id;references:Id"` + Person_Id *uint `json:"person_id"` + Person *ep.Person `json:"person,omitempty" gorm:"foreignKey:Person_Id;references:Id"` + Position_Code *erg.EmployeePositionCode `json:"position_code" gorm:"size:20"` + Number *string `json:"number" gorm:"size:20"` + Contract_ExpiredDate *time.Time `json:"contract_expiredDate"` + Status_Code erc.ActiveStatusCode `json:"status_code" gorm:"not null;size:10"` } diff --git a/internal/domain/references/encounter/encounter.go b/internal/domain/references/encounter/encounter.go index f7c8fdc8..45ee8c89 100644 --- a/internal/domain/references/encounter/encounter.go +++ b/internal/domain/references/encounter/encounter.go @@ -43,6 +43,7 @@ const ( DMCExtRef DischargeMethodCode = "external" // Rujuk Faskes Lain DMCDeath DischargeMethodCode = "death" // Meninggal DMCDeathOnArrival DischargeMethodCode = "death-on-arrival" // Meninggal Saat Tiba + DMCRunAway DischargeMethodCode = "run-away" // Melarikan Diri TCAmbulance TransportationCode = "ambulance" // Ambulans TCCar TransportationCode = "car" // Mobil From 9ebcb604c60a77ce08eb985d90bcbe267420929e Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 11:12:28 +0700 Subject: [PATCH 23/55] wip --- internal/domain/main-entities/doctor/dto.go | 75 ++++++++++--------- internal/domain/main-entities/user/dto.go | 8 +- .../use-case/main-use-case/doctor/helper.go | 6 +- internal/use-case/main-use-case/user/case.go | 14 ++-- 4 files changed, 53 insertions(+), 50 deletions(-) diff --git a/internal/domain/main-entities/doctor/dto.go b/internal/domain/main-entities/doctor/dto.go index 0abcd99b..67290551 100644 --- a/internal/domain/main-entities/doctor/dto.go +++ b/internal/domain/main-entities/doctor/dto.go @@ -6,16 +6,18 @@ import ( es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" eu "simrs-vx/internal/domain/main-entities/unit" + "time" ) type CreateDto struct { - Code *string `json:"code" validate:"maxLength=20"` - Employee_Id *uint `json:"employee_id"` - IHS_Number *string `json:"ihs_number"` - SIP_Number *string `json:"sip_number"` - Unit_Id *uint16 `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Code *string `json:"code" validate:"maxLength=20"` + Employee_Id *uint `json:"employee_id"` + IHS_Number *string `json:"ihs_number"` + SIP_Number *string `json:"sip_number"` + SIP_ExpiredDate *time.Time `json:"sip_expiredDate"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` } type ReadListDto struct { @@ -25,13 +27,14 @@ type ReadListDto struct { } type FilterDto struct { - Code *string `json:"code"` - Employee_Id *uint `json:"employee-id"` - IHS_Number *string `json:"ihs-number" validate:"maxLength=20"` - SIP_Number *string `json:"sip-number" validate:"maxLength=20"` - Unit_Id *uint `json:"unit-id"` - Specialist_Id *uint16 `json:"specialist-id"` - Subspecialist_Id *uint16 `json:"subspecialist-id"` + Code *string `json:"code"` + Employee_Id *uint `json:"employee-id"` + IHS_Number *string `json:"ihs-number" validate:"maxLength=20"` + SIP_Number *string `json:"sip-number" validate:"maxLength=20"` + SIP_ExpiredDate *string `json:"sip-expiredDate"` + Unit_Code *string `json:"unit-code"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` } type ReadDetailDto struct { @@ -59,32 +62,32 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code *string `json:"code"` - Employee_Id *uint `json:"employee_id"` - Employee *ee.Employee `json:"employee,omitempty"` - IHS_Number *string `json:"ihs_number"` - SIP_Number *string `json:"sip_number"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty" ` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` + Code *string `json:"code"` + Employee_Id *uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty"` + IHS_Number *string `json:"ihs_number"` + SIP_Number *string `json:"sip_number"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty" ` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` } func (d Doctor) ToResponse() ResponseDto { resp := ResponseDto{ - Code: d.Code, - Employee_Id: d.Employee_Id, - Employee: d.Employee, - IHS_Number: d.IHS_Number, - SIP_Number: d.SIP_Number, - Unit_Id: d.Unit_Id, - Unit: d.Unit, - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, - Subspecialist: d.Subspecialist, + Code: d.Code, + Employee_Id: d.Employee_Id, + Employee: d.Employee, + IHS_Number: d.IHS_Number, + SIP_Number: d.SIP_Number, + Unit_Code: d.Unit_Code, + Unit: d.Unit, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Subspecialist_Code: d.Subspecialist_Code, + Subspecialist: d.Subspecialist, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/user/dto.go b/internal/domain/main-entities/user/dto.go index c3a84737..fd4b3f2c 100644 --- a/internal/domain/main-entities/user/dto.go +++ b/internal/domain/main-entities/user/dto.go @@ -24,10 +24,10 @@ type CreateDto struct { Employee *EmployeUpdateDto `json:"employee"` IHS_Number *string `json:"ihs_number" validate:"maxLength=20"` SIP_Number *string `json:"sip_number" validate:"maxLength=20"` - Unit_Id *uint16 `json:"unit_id"` - Infra_Id *uint16 `json:"infra_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Unit_Code *string `json:"unit_code"` + Infra_Code *string `json:"infra_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` ContractPosition_Code erg.ContractPositionCode `json:"contractPosition_code" gorm:"not null;size:20"` } diff --git a/internal/use-case/main-use-case/doctor/helper.go b/internal/use-case/main-use-case/doctor/helper.go index b62045c7..344d1c0e 100644 --- a/internal/use-case/main-use-case/doctor/helper.go +++ b/internal/use-case/main-use-case/doctor/helper.go @@ -21,7 +21,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Doctor) { data.Employee_Id = inputSrc.Employee_Id data.IHS_Number = inputSrc.IHS_Number data.SIP_Number = inputSrc.SIP_Number - data.Unit_Id = inputSrc.Unit_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Unit_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Code + data.Subspecialist_Code = inputSrc.Code } diff --git a/internal/use-case/main-use-case/user/case.go b/internal/use-case/main-use-case/user/case.go index 8e452e62..a1df7e25 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -108,13 +108,13 @@ func Create(input e.CreateDto) (*d.Data, error) { switch input.Employee.Position_Code { case ero.EPCDoc: createDoc := ed.CreateDto{ - Code: input.Code, - Employee_Id: &employeeData.Id, - IHS_Number: input.IHS_Number, - SIP_Number: input.SIP_Number, - Unit_Id: input.Unit_Id, - Specialist_Id: input.Specialist_Id, - Subspecialist_Id: input.Subspecialist_Id, + Code: input.Code, + Employee_Id: &employeeData.Id, + IHS_Number: input.IHS_Number, + SIP_Number: input.SIP_Number, + Unit_Code: input.Unit_Code, + Specialist_Code: input.Specialist_Code, + Subspecialist_Code: input.Subspecialist_Code, } if _, err := ud.CreateData(createDoc, &event, tx); err != nil { return err From 867a68ac26b57a79b50cb677188004a1f0cc4801 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 11:14:34 +0700 Subject: [PATCH 24/55] nurse ids into codes --- cmd/main-migration/migrations/20251106041333.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 7 ++++--- internal/domain/main-entities/nurse/entity.go | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106041333.sql diff --git a/cmd/main-migration/migrations/20251106041333.sql b/cmd/main-migration/migrations/20251106041333.sql new file mode 100644 index 00000000..0e4cc5c0 --- /dev/null +++ b/cmd/main-migration/migrations/20251106041333.sql @@ -0,0 +1,2 @@ +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Infra_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index d6b62389..f53af38c 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:yLtZj2e+mxp2L0eRUjFUIrC1GID4BB3/8x6LaHS+v10= +h1:NYYeyYMn4chXAE9qYJ8cipPYeNoXL7Ukmc/Y1w4d+wo= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -71,5 +71,6 @@ h1:yLtZj2e+mxp2L0eRUjFUIrC1GID4BB3/8x6LaHS+v10= 20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= 20251105044629.sql h1:4NU27HeKUNFsV82LacnwmnCSAH0pSbZR9J9/ZESRs6M= 20251105121808.sql h1:fii6LjqWYjrm/pEIqttfvJI6QEUL49gque8wYHh1+yI= -20251106035305.sql h1:hRkWZYLQvjmROqlu9xvuXrPQcBKf6yUGTTbSd0lKbmI= -20251106040137.sql h1:ifT65MV7h0sws5EGBOGefRqxSaZqapEeupuhHMJipyw= +20251106035305.sql h1:oQ7BwnxPuwY2q98adIVc+lNwL/Sz1OceLJeClDo9/TI= +20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= +20251106041333.sql h1:gIxxRLcPtsGRH6whsDFG8BDZu9G4XAiQj5WPcXb/5gU= diff --git a/internal/domain/main-entities/nurse/entity.go b/internal/domain/main-entities/nurse/entity.go index 9768c622..54f06fd1 100644 --- a/internal/domain/main-entities/nurse/entity.go +++ b/internal/domain/main-entities/nurse/entity.go @@ -14,7 +14,9 @@ type Nurse struct { Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"` Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code" gorm:"size:10"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` } From 379b34d5baa79995c8a2f8d8fbb598c4f4656f53 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 11:18:37 +0700 Subject: [PATCH 25/55] wip --- internal/domain/main-entities/nurse/dto.go | 16 ++++++++-------- .../use-case/main-use-case/nurse/helper.go | 4 ++-- internal/use-case/main-use-case/user/case.go | 18 +++++++++++------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/internal/domain/main-entities/nurse/dto.go b/internal/domain/main-entities/nurse/dto.go index 7b7b283c..f48014dd 100644 --- a/internal/domain/main-entities/nurse/dto.go +++ b/internal/domain/main-entities/nurse/dto.go @@ -11,8 +11,8 @@ type CreateDto struct { Code *string `json:"code" validate:"maxLength=20"` Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number" validate:"maxLength=20"` - Unit_Id *uint16 `json:"unit_id"` - Infra_Id *uint16 `json:"infra_id"` + Unit_Code *string `json:"unit_code"` + Infra_Code *string `json:"infra_code"` } type ReadListDto struct { @@ -25,8 +25,8 @@ type FilterDto struct { Code *string `json:"code"` Employee_Id *uint `json:"employee-id"` IHS_Number *string `json:"ihs-number"` - Unit_Id *uint16 `json:"unit-id"` - Infra_Id *uint16 `json:"infra-id"` + Unit_Code *string `json:"unit-code"` + Infra_Code *string `json:"infra-code"` } type ReadDetailDto struct { Id uint16 `json:"id"` @@ -56,9 +56,9 @@ type ResponseDto struct { Employee_Id *uint `json:"employee_id"` Employee *ee.Employee `json:"employee,omitempty"` IHS_Number *string `json:"ihs_number"` - Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Infra *ei.Infra `json:"infra,omitempty"` } @@ -68,9 +68,9 @@ func (d Nurse) ToResponse() ResponseDto { Employee_Id: d.Employee_Id, Employee: d.Employee, IHS_Number: d.IHS_Number, - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, - Infra_Id: d.Infra_Id, + Infra_Code: d.Infra_Code, Infra: d.Infra, } resp.Main = d.Main diff --git a/internal/use-case/main-use-case/nurse/helper.go b/internal/use-case/main-use-case/nurse/helper.go index 003230b3..49078088 100644 --- a/internal/use-case/main-use-case/nurse/helper.go +++ b/internal/use-case/main-use-case/nurse/helper.go @@ -20,6 +20,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Nurse) { data.Code = inputSrc.Code data.Employee_Id = inputSrc.Employee_Id data.IHS_Number = inputSrc.IHS_Number - data.Unit_Id = inputSrc.Unit_Id - data.Infra_Id = inputSrc.Infra_Id + data.Unit_Code = inputSrc.Unit_Code + data.Infra_Code = inputSrc.Infra_Code } diff --git a/internal/use-case/main-use-case/user/case.go b/internal/use-case/main-use-case/user/case.go index a1df7e25..94ee6801 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -124,8 +124,8 @@ func Create(input e.CreateDto) (*d.Data, error) { Code: input.Code, Employee_Id: &employeeData.Id, IHS_Number: input.IHS_Number, - Unit_Id: input.Unit_Id, - Infra_Id: input.Infra_Id, + Unit_Code: input.Unit_Code, + Infra_Code: input.Infra_Code, } if _, err := un.CreateData(createNurse, &event, tx); err != nil { return err @@ -396,11 +396,13 @@ func Update(input e.UpdateDto) (*d.Data, error) { return err } createDoc := ed.CreateDto{ - Code: input.Code, - Employee_Id: &employeeData.Id, - IHS_Number: input.IHS_Number, - SIP_Number: input.SIP_Number, - Unit_Id: input.Unit_Id, + Code: input.Code, + Employee_Id: &employeeData.Id, + IHS_Number: input.IHS_Number, + SIP_Number: input.SIP_Number, + Unit_Code: input.Unit_Code, + Specialist_Code: input.Specialist_Code, + Subspecialist_Code: input.Subspecialist_Code, } if readDocData != nil { if err := ud.UpdateData(ed.UpdateDto{CreateDto: createDoc}, readDocData, &event, tx); err != nil { @@ -422,6 +424,8 @@ func Update(input e.UpdateDto) (*d.Data, error) { Code: input.Code, Employee_Id: &employeeData.Id, IHS_Number: input.IHS_Number, + Unit_Code: input.Unit_Code, + Infra_Code: input.Infra_Code, } if readNurData != nil { if err := un.UpdateData(en.UpdateDto{CreateDto: createNur}, readNurData, &event, tx); err != nil { From 2580d38b723bf7b9fe572708134743b09e726ec6 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 11:21:45 +0700 Subject: [PATCH 26/55] specialist intern ids into codes --- .../migrations/20251106042006.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 5 +++-- .../main-entities/specialist-intern/entity.go | 20 ++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106042006.sql diff --git a/cmd/main-migration/migrations/20251106042006.sql b/cmd/main-migration/migrations/20251106042006.sql new file mode 100644 index 00000000..a3f2f609 --- /dev/null +++ b/cmd/main-migration/migrations/20251106042006.sql @@ -0,0 +1,2 @@ +-- Modify "SpecialistIntern" table +ALTER TABLE "public"."SpecialistIntern" ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index f53af38c..8922bef3 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:NYYeyYMn4chXAE9qYJ8cipPYeNoXL7Ukmc/Y1w4d+wo= +h1:Ke31uEMAxNobMdza6/1rFlWnbE7Z1dHVAAfRi+oXi4E= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -73,4 +73,5 @@ h1:NYYeyYMn4chXAE9qYJ8cipPYeNoXL7Ukmc/Y1w4d+wo= 20251105121808.sql h1:fii6LjqWYjrm/pEIqttfvJI6QEUL49gque8wYHh1+yI= 20251106035305.sql h1:oQ7BwnxPuwY2q98adIVc+lNwL/Sz1OceLJeClDo9/TI= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= -20251106041333.sql h1:gIxxRLcPtsGRH6whsDFG8BDZu9G4XAiQj5WPcXb/5gU= +20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= +20251106042006.sql h1:sVi3ilQnUapkKBzNi/z495eK4ivCF9ssU/D3oEldokM= diff --git a/internal/domain/main-entities/specialist-intern/entity.go b/internal/domain/main-entities/specialist-intern/entity.go index 9df0ed53..482c9b5a 100644 --- a/internal/domain/main-entities/specialist-intern/entity.go +++ b/internal/domain/main-entities/specialist-intern/entity.go @@ -9,13 +9,15 @@ import ( ) type SpecialistIntern struct { - ecore.Main // adjust this according to the needs - Person_Id *uint `json:"person_id"` - Person *ep.Person `json:"person,omitempty" gorm:"foreignKey:Person_Id"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` - User_Id *uint `json:"user_id"` - User *eu.User `json:"user,omitempty" gorm:"foreignKey:User_Id"` + ecore.Main // adjust this according to the needs + Person_Id *uint `json:"person_id"` + Person *ep.Person `json:"person,omitempty" gorm:"foreignKey:Person_Id"` + Specialist_Id *uint16 `json:"specialist_id"` + Specialist_Code *string `json:"specialist_code" gorm:"size:10"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` + Subspecialist_Id *uint16 `json:"subspecialist_id"` + Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` + User_Id *uint `json:"user_id"` + User *eu.User `json:"user,omitempty" gorm:"foreignKey:User_Id"` } From 3126230f3e2e15200fd6e709298f7e7991e8bf41 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 11:28:55 +0700 Subject: [PATCH 27/55] refactor (doctor,nurse,specialist-intern): done --- .../main-entities/specialist-intern/dto.go | 48 +++++++++---------- .../interface/main-handler/doctor/handler.go | 6 +-- .../interface/main-handler/main-handler.go | 5 +- .../interface/main-handler/nurse/handler.go | 6 +-- .../main-use-case/specialist-intern/helper.go | 4 +- internal/use-case/main-use-case/user/case.go | 16 +++---- 6 files changed, 41 insertions(+), 44 deletions(-) diff --git a/internal/domain/main-entities/specialist-intern/dto.go b/internal/domain/main-entities/specialist-intern/dto.go index 2d01c861..bf87b00e 100644 --- a/internal/domain/main-entities/specialist-intern/dto.go +++ b/internal/domain/main-entities/specialist-intern/dto.go @@ -9,10 +9,10 @@ import ( ) type CreateDto struct { - Person_Id *uint `json:"person_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - User_Id *uint `json:"user_id"` + Person_Id *uint `json:"person_id"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + User_Id *uint `json:"user_id"` } type ReadListDto struct { @@ -22,10 +22,10 @@ type ReadListDto struct { } type FilterDto struct { - Person_Id *uint `json:"person-id"` - Specialist_Id *uint16 `json:"specialist-id"` - Subspecialist_Id *uint16 `json:"subspecialist-id"` - User_Id *uint `json:"user-id"` + Person_Id *uint `json:"person-id"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` + User_Id *uint `json:"user-id"` } type ReadDetailDto struct { @@ -50,26 +50,26 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Person_Id *uint `json:"person_id"` - Person *ep.Person `json:"person,omitempty"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` - User_Id *uint `json:"user_id"` - User *eu.User `json:"user,omitempty"` + Person_Id *uint `json:"person_id"` + Person *ep.Person `json:"person,omitempty"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` + User_Id *uint `json:"user_id"` + User *eu.User `json:"user,omitempty"` } func (d SpecialistIntern) ToResponse() ResponseDto { resp := ResponseDto{ - Person_Id: d.Person_Id, - Person: d.Person, - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, - Subspecialist: d.Subspecialist, - User_Id: d.User_Id, - User: d.User, + Person_Id: d.Person_Id, + Person: d.Person, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Subspecialist_Code: d.Subspecialist_Code, + Subspecialist: d.Subspecialist, + User_Id: d.User_Id, + User: d.User, } resp.Main = d.Main return resp diff --git a/internal/interface/main-handler/doctor/handler.go b/internal/interface/main-handler/doctor/handler.go index 27281884..ee1252ad 100644 --- a/internal/interface/main-handler/doctor/handler.go +++ b/internal/interface/main-handler/doctor/handler.go @@ -33,7 +33,7 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) + id := rw.ValidateInt(w, "code", r.PathValue("code")) if id <= 0 { return } @@ -44,7 +44,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) + id := rw.ValidateInt(w, "code", r.PathValue("code")) if id <= 0 { return } @@ -59,7 +59,7 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) + id := rw.ValidateInt(w, "code", r.PathValue("code")) if id <= 0 { return } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 1c703b64..0a6a917a 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -35,9 +35,8 @@ import ( soapi "simrs-vx/internal/interface/main-handler/soapi" /******************** actor ********************/ - doctor "simrs-vx/internal/interface/main-handler/doctor" + employee "simrs-vx/internal/interface/main-handler/employee" - nurse "simrs-vx/internal/interface/main-handler/nurse" nutritionist "simrs-vx/internal/interface/main-handler/nutritionist" patient "simrs-vx/internal/interface/main-handler/patient" person "simrs-vx/internal/interface/main-handler/person" @@ -268,8 +267,6 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/person-contact", personcontact.O) hc.RegCrud(r, "/v1/person-insurance", personinsurance.O) hc.RegCrud(r, "/v1/employee", employee.O) - hc.RegCrud(r, "/v1/doctor", doctor.O) - hc.RegCrud(r, "/v1/nurse", nurse.O) hc.RegCrud(r, "/v1/nutritionist", nutritionist.O) hc.RegCrud(r, "/v1/pharmacist", pharmacist.O) hk.GroupRoutes("/v1/user", r, hk.MapHandlerFunc{ diff --git a/internal/interface/main-handler/nurse/handler.go b/internal/interface/main-handler/nurse/handler.go index 6df7a18e..8817ae14 100644 --- a/internal/interface/main-handler/nurse/handler.go +++ b/internal/interface/main-handler/nurse/handler.go @@ -33,7 +33,7 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) + id := rw.ValidateInt(w, "code", r.PathValue("code")) if id <= 0 { return } @@ -44,7 +44,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) + id := rw.ValidateInt(w, "code", r.PathValue("code")) if id <= 0 { return } @@ -59,7 +59,7 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) + id := rw.ValidateInt(w, "code", r.PathValue("code")) if id <= 0 { return } diff --git a/internal/use-case/main-use-case/specialist-intern/helper.go b/internal/use-case/main-use-case/specialist-intern/helper.go index 36b989d8..91bd2afc 100644 --- a/internal/use-case/main-use-case/specialist-intern/helper.go +++ b/internal/use-case/main-use-case/specialist-intern/helper.go @@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.SpecialistIntern) { } data.Person_Id = inputSrc.Person_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code data.User_Id = inputSrc.User_Id } diff --git a/internal/use-case/main-use-case/user/case.go b/internal/use-case/main-use-case/user/case.go index 94ee6801..7c66b153 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -87,10 +87,10 @@ func Create(input e.CreateDto) (*d.Data, error) { if input.ContractPosition_Code == ero.CSCInt { createInt := esi.CreateDto{ - Person_Id: input.Person_Id, - Specialist_Id: input.Specialist_Id, - Subspecialist_Id: input.Subspecialist_Id, - User_Id: &data.Id, + Person_Id: input.Person_Id, + Specialist_Code: input.Specialist_Code, + Subspecialist_Code: input.Subspecialist_Code, + User_Id: &data.Id, } if _, err := usi.CreateData(createInt, &event, tx); err != nil { return err @@ -359,10 +359,10 @@ func Update(input e.UpdateDto) (*d.Data, error) { return err } createInt := esi.CreateDto{ - User_Id: &data.Id, - Person_Id: input.Person_Id, - Specialist_Id: input.Specialist_Id, - Subspecialist_Id: input.Subspecialist_Id, + User_Id: &data.Id, + Person_Id: input.Person_Id, + Specialist_Code: input.Specialist_Code, + Subspecialist_Code: input.Subspecialist_Code, } if readIntData != nil { if err := usi.UpdateData(esi.UpdateDto{CreateDto: createInt}, readIntData, &event, tx); err != nil { From 9fb919229b4a5c32240b5cac32f3203e97fbd6f9 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 11:39:36 +0700 Subject: [PATCH 28/55] remove ids --- internal/domain/main-entities/nurse/dto.go | 8 ++++---- internal/domain/main-entities/nurse/entity.go | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/domain/main-entities/nurse/dto.go b/internal/domain/main-entities/nurse/dto.go index 7b7b283c..11047235 100644 --- a/internal/domain/main-entities/nurse/dto.go +++ b/internal/domain/main-entities/nurse/dto.go @@ -56,9 +56,9 @@ type ResponseDto struct { Employee_Id *uint `json:"employee_id"` Employee *ee.Employee `json:"employee,omitempty"` IHS_Number *string `json:"ihs_number"` - Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Infra *ei.Infra `json:"infra,omitempty"` } @@ -68,9 +68,9 @@ func (d Nurse) ToResponse() ResponseDto { Employee_Id: d.Employee_Id, Employee: d.Employee, IHS_Number: d.IHS_Number, - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, - Infra_Id: d.Infra_Id, + Infra_Code: d.Infra_Code, Infra: d.Infra, } resp.Main = d.Main diff --git a/internal/domain/main-entities/nurse/entity.go b/internal/domain/main-entities/nurse/entity.go index 54f06fd1..cb1df0a8 100644 --- a/internal/domain/main-entities/nurse/entity.go +++ b/internal/domain/main-entities/nurse/entity.go @@ -13,10 +13,8 @@ type Nurse struct { 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"` - Unit_Id *uint16 `json:"unit_id"` Unit_Code *string `json:"unit_code" gorm:"size:10"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - Infra_Id *uint16 `json:"infra_id"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` Infra_Code *string `json:"infra_code" gorm:"size:10"` - Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` + Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"` } From a2015a5c7e405ddcab254ef97f92d0d6ec0454b0 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 12:08:36 +0700 Subject: [PATCH 29/55] removes ids on doctor,nurse,specialist-intern --- .../migrations/20251106050412.sql | 8 ++++ cmd/main-migration/migrations/atlas.sum | 5 ++- .../domain/main-entities/doctor/entity.go | 26 ++++++------- .../main-entities/prescription/entity.go | 1 + .../main-entities/specialist-intern/entity.go | 6 +-- internal/lib/auth/tycovar.go | 12 +++--- .../main-use-case/authentication/case.go | 38 +++++++++---------- .../use-case/main-use-case/encounter/lib.go | 6 ++- .../main-use-case/prescription/helper.go | 2 +- 9 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106050412.sql diff --git a/cmd/main-migration/migrations/20251106050412.sql b/cmd/main-migration/migrations/20251106050412.sql new file mode 100644 index 00000000..11ef2a96 --- /dev/null +++ b/cmd/main-migration/migrations/20251106050412.sql @@ -0,0 +1,8 @@ +-- Modify "Prescription" table +ALTER TABLE "public"."Prescription" ADD COLUMN "Doctor_Code" character varying(20) NULL; +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" DROP CONSTRAINT "fk_Doctor_Specialist", DROP CONSTRAINT "fk_Doctor_Subspecialist", DROP CONSTRAINT "fk_Doctor_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", ADD CONSTRAINT "fk_Doctor_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Doctor_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Doctor_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" DROP CONSTRAINT "fk_Nurse_Infra", DROP CONSTRAINT "fk_Nurse_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Infra_Id", ADD CONSTRAINT "fk_Nurse_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Nurse_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "SpecialistIntern" table +ALTER TABLE "public"."SpecialistIntern" DROP CONSTRAINT "fk_SpecialistIntern_Specialist", DROP CONSTRAINT "fk_SpecialistIntern_Subspecialist", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", ADD CONSTRAINT "fk_SpecialistIntern_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_SpecialistIntern_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 8922bef3..79b67fa2 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:Ke31uEMAxNobMdza6/1rFlWnbE7Z1dHVAAfRi+oXi4E= +h1:97IUzyfSecffgKmYYs+a+HW5thHnIY3OuWDTQYy3hGQ= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -74,4 +74,5 @@ h1:Ke31uEMAxNobMdza6/1rFlWnbE7Z1dHVAAfRi+oXi4E= 20251106035305.sql h1:oQ7BwnxPuwY2q98adIVc+lNwL/Sz1OceLJeClDo9/TI= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= -20251106042006.sql h1:sVi3ilQnUapkKBzNi/z495eK4ivCF9ssU/D3oEldokM= +20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= diff --git a/internal/domain/main-entities/doctor/entity.go b/internal/domain/main-entities/doctor/entity.go index 014c6c17..506271a2 100644 --- a/internal/domain/main-entities/doctor/entity.go +++ b/internal/domain/main-entities/doctor/entity.go @@ -10,21 +10,17 @@ import ( ) type Doctor struct { - ecore.Main // adjust this according to the needs - Code *string `json:"code" gorm:"unique;size:20"` - 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"` - SIP_Number *string `json:"sip_number" gorm:"unique;size:20"` - SIP_ExpiredDate *time.Time `json:"sip_expiredDate"` - Unit_Id *uint16 `json:"unit_id"` - Unit_Code *string `json:"unit_code" gorm:"size:10"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - // Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` - Specialist_Id *uint16 `json:"specialist_id"` + ecore.Main // adjust this according to the needs + Code *string `json:"code" gorm:"unique;size:20"` + 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"` + SIP_Number *string `json:"sip_number" gorm:"unique;size:20"` + SIP_ExpiredDate *time.Time `json:"sip_expiredDate"` + Unit_Code *string `json:"unit_code" gorm:"size:10"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` Specialist_Code *string `json:"specialist_code" gorm:"size:10"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` } diff --git a/internal/domain/main-entities/prescription/entity.go b/internal/domain/main-entities/prescription/entity.go index bdc2d2fb..c32c9d9e 100644 --- a/internal/domain/main-entities/prescription/entity.go +++ b/internal/domain/main-entities/prescription/entity.go @@ -15,6 +15,7 @@ type Prescription struct { Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code" gorm:"size:20"` Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` IssuedAt *time.Time `json:"issuedAt"` Status_Code erc.DataStatusCode `json:"status_code"` diff --git a/internal/domain/main-entities/specialist-intern/entity.go b/internal/domain/main-entities/specialist-intern/entity.go index 482c9b5a..5d87e1a7 100644 --- a/internal/domain/main-entities/specialist-intern/entity.go +++ b/internal/domain/main-entities/specialist-intern/entity.go @@ -12,12 +12,10 @@ type SpecialistIntern struct { ecore.Main // adjust this according to the needs Person_Id *uint `json:"person_id"` Person *ep.Person `json:"person,omitempty" gorm:"foreignKey:Person_Id"` - Specialist_Id *uint16 `json:"specialist_id"` Specialist_Code *string `json:"specialist_code" gorm:"size:10"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` User_Id *uint `json:"user_id"` User *eu.User `json:"user,omitempty" gorm:"foreignKey:User_Id"` } diff --git a/internal/lib/auth/tycovar.go b/internal/lib/auth/tycovar.go index 44426d4b..467bd1b6 100644 --- a/internal/lib/auth/tycovar.go +++ b/internal/lib/auth/tycovar.go @@ -14,12 +14,12 @@ type AuthInfo struct { User_ContractPosition_code string Employee_Position_Code *string Employee_Id *uint - Doctor_Id *uint - Nurse_Id *uint - Midwife_Id *uint - Nutritionist_Id *uint - Laborant_Id *uint - Pharmachist_Id *uint + Doctor_Code *string + Nurse_Code *string + Midwife_Code *string + Nutritionist_Code *string + Laborant_Code *string + Pharmachist_Code *string Intern_Position_Code *string Roles []string // User_DivisionPositions []DivisionPosition diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index d00889ee..6a980d71 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -136,17 +136,17 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { if doctor.Id == 0 { return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: el.GenMessage("auth-noDoctor")}} } - atClaims["doctor_id"] = doctor.Id - outputData["doctor_id"] = doctor.Id + atClaims["doctor_code"] = doctor.Code + outputData["doctor_code"] = doctor.Code // specialist - if doctor.Specialist_Id != nil { - atClaims["specialist_id"] = doctor.Specialist_Id - outputData["specialist_id"] = doctor.Specialist_Id + if doctor.Specialist_Code != nil { + atClaims["specialist_code"] = doctor.Specialist_Code + outputData["specialist_code"] = doctor.Specialist_Code } - if doctor.Subspecialist_Id != nil { - atClaims["subspecialist_id"] = doctor.Subspecialist_Id - outputData["subspecialist_id"] = doctor.Subspecialist_Id + if doctor.Subspecialist_Code != nil { + atClaims["subspecialist_code"] = doctor.Subspecialist_Code + outputData["subspecialist_code"] = doctor.Subspecialist_Code } case erg.EPCNur: empData := en.Nurse{} @@ -154,16 +154,16 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { if empData.Id == 0 { return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: el.GenMessage("auth-noNurse")}} } - atClaims["nurse_id"] = empData.Id - outputData["nurse_id"] = empData.Id + atClaims["nurse_code"] = empData.Code + outputData["nurse_code"] = empData.Code case erg.EPCMwi: empData := em.Midwife{} dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData) if empData.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: el.GenMessage("auth-noNurse")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noMidwife", Message: el.GenMessage("auth-noMidwife")}} } - atClaims["nurse_id"] = empData.Id - outputData["nurse_id"] = empData.Id + atClaims["midwife_code"] = empData.Code + outputData["midwife_code"] = empData.Code } errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}} @@ -308,12 +308,12 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err data.User_ContractPosition_code = checkStrClaims(claims, "contractPosition_code") data.Employee_Position_Code = checkStrPtrClaims(claims, "employee_position_code") - data.Doctor_Id = checkUntPtrClaims(claims, "doctor_id") - data.Nurse_Id = checkUntPtrClaims(claims, "nurse_id") - data.Midwife_Id = checkUntPtrClaims(claims, "midwife_id") - data.Nutritionist_Id = checkUntPtrClaims(claims, "nutritionist_id") - data.Laborant_Id = checkUntPtrClaims(claims, "laborant_id") - data.Pharmachist_Id = checkUntPtrClaims(claims, "pharmachist_id") + data.Doctor_Code = checkStrPtrClaims(claims, "doctor_string") + data.Nurse_Code = checkStrPtrClaims(claims, "nurse_string") + data.Midwife_Code = checkStrPtrClaims(claims, "midwife_string") + data.Nutritionist_Code = checkStrPtrClaims(claims, "nutritionist_string") + data.Laborant_Code = checkStrPtrClaims(claims, "laborant_string") + data.Pharmachist_Code = checkStrPtrClaims(claims, "pharmachist_string") data.Intern_Position_Code = checkStrPtrClaims(claims, "intern_position_code") data.Employee_Id = checkUntPtrClaims(claims, "employee_id") return diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 0c51a8d6..18a632c3 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -4,10 +4,12 @@ import ( // std "errors" ere "simrs-vx/internal/domain/references/encounter" + // external dg "github.com/karincake/apem/db-gorm-pg" gh "github.com/karincake/getuk" "gorm.io/gorm" + // pkg plh "simrs-vx/pkg/lib-helper" pl "simrs-vx/pkg/logger" @@ -56,8 +58,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.En } tx = tx.Model(&e.Encounter{}) - if input.AuthInfo.Doctor_Id != nil { - tx.Where("\"Responsible_Doctor_Id\" = ?", *input.AuthInfo.Doctor_Id) + if input.AuthInfo.Doctor_Code != nil { + tx.Where("\"Responsible_Doctor_Id\" = ?", *input.AuthInfo.Doctor_Code) // TODO: fix this } tx.Scopes(gh.Preload(input.Includes)). diff --git a/internal/use-case/main-use-case/prescription/helper.go b/internal/use-case/main-use-case/prescription/helper.go index 35c55512..92fd4531 100644 --- a/internal/use-case/main-use-case/prescription/helper.go +++ b/internal/use-case/main-use-case/prescription/helper.go @@ -38,7 +38,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Prescription) { data.Encounter_Id = inputSrc.Encounter_Id // data.Doctor_Id = inputSrc.Doctor_Id - data.Doctor_Id = inputSrc.AuthInfo.Doctor_Id + data.Doctor_Code = inputSrc.AuthInfo.Doctor_Code data.IssuedAt = inputSrc.IssuedAt } From 03aceaac0b8ebbb5044267e9e9150209bf84370f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 6 Nov 2025 12:09:32 +0700 Subject: [PATCH 30/55] migration from server --- cmd/main-migration/migrations/atlas.sum | 154 ++++++++++++------------ 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 8922bef3..90d23a8a 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,77 +1,77 @@ -h1:Ke31uEMAxNobMdza6/1rFlWnbE7Z1dHVAAfRi+oXi4E= -20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= -20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= -20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= -20250908062323.sql h1:oXl6Z143tOpIl4EfP4B8JNU8LrMvVmHEtCgAfiB4gs8= -20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= -20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= -20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= -20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= -20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= -20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= -20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= -20250917045138.sql h1:jKe1Z0uOLG4SGBYM+S/3P+/zMPztmgoderD5swnMuCg= -20250917093645.sql h1:cNI3Pbz1R3LxvIXLuexafJFCXUXrmuFCgXXJ2sG+FW0= -20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= -20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= -20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= -20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= -20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ= -20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg= -20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34= -20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= -20250930140351.sql h1:9AAEG1AnOAH+o0+oHL5G7I8vqlWOhwRlCGyyCpT/y1Q= -20251002085604.sql h1:3xZ68eYp4urXRnvotNH1XvG2mYOSDV/j3zHEZ/txg5E= -20251003032030.sql h1:HB+mQ2lXMNomHDpaRhB/9IwYI9/YiDO5eOJ+nAQH/jw= -20251005060450.sql h1:LbtCE2b+8osM3CvnmQJH1uCPtn+d7WchsslBOz8bL3Q= -20251006041122.sql h1:MlS7f21z06sutnf9dIekt5fuHJr4lgcQ4uCuCXAGsfc= -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:nxnXmooIJ6r1mmzwnw+6efxLfc/k9h2aE6RMptPRons= -20251008073620.sql h1:6YsJp1W4SmQJ1lxpqF27BBlDC1zqhw7Yhc7pLzQTY6M= -20251009042854.sql h1:nkBV+R6j0fg7/JY6wH3eb5Vv0asJLnXmb6lINfT/GLQ= -20251009052657.sql h1:EPvdsib5rzCGPryd10HShGKvFPwM/R5S2lIVwtYxpms= -20251010031743.sql h1:T8IZmx8/btRFKLzTe78MzcBsPJNodnLvB0tby9QkirQ= -20251010070721.sql h1:5NQUk/yOV6sABLCB7swx++YIOyJe6MnU+yt1nRzde5w= -20251010072711.sql h1:ZJNqR2piyu8xJhBvVABSlnGEoKSKae3wuEs+wshPe4k= -20251013044536.sql h1:0Xjw8fNILiT8nnfrJDZgQnPf3dntmIoilbapnih8AE4= -20251013051438.sql h1:lfSuw5mgJnePBJamvhZ81osFIouXeiIEiSZ/evdwo48= -20251013081808.sql h1:ijgjNX08G6GBjA/ks8EKtb7P7Y7Cg7zbhqEOruGnv6M= -20251014060047.sql h1:0jqj49WTtneEIMQDBoo4c095ZGi8sCrA8NnHBrPU6D8= -20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg= -20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14= -20251015045455.sql h1:MeLWmMhAOAz8b15Dd7IAQnt6JxjSml02XCXK22C0Lpg= -20251016010845.sql h1:4BncQdDOasRZJkzVJrSJJA7091A9VPNVx/faUCUPhBM= -20251016011023.sql h1:9JB9eFZKURK5RoCVDKR6glSvdJ8NTXrN7K/4q51zkz4= -20251016062912.sql h1:ACNn0fe+EMqUt3hoY+Dr3uqAV/QICBa1+mIW7fUc9Fk= -20251017060617.sql h1:4T3t9ifWrEQTPMSM0XJ98pF7Qdt+UfgtMui17bhrnWI= -20251017082207.sql h1:8vLG1l/saRRMHXkyA4nelJyjaSddhZd6r7R+Uo4JS/c= -20251018032635.sql h1:2xey5gnO3y2XSOrU8MLlIfoylPKbRGDRtHDD07B3MbQ= -20251018040322.sql h1:k/pdNiSoT8zFPqNQ/avOD0vYkNh3BTD64IlHrfVXr7I= -20251019093915.sql h1:hFcQE0y+p5dZiVwePGsRGto9m/q6kJNiUZbVDd5Rnjk= -20251020062553.sql h1:Iw7hulcm5iRQlfW+ygA4iTPxLqkxx6h9vXMXEwUAHKs= -20251021041042.sql h1:wMgSivBV2A0NDcsLmKGIp0kMcVh2IODSG9b4dgzCaOM= -20251021075552.sql h1:8gfSMAglflNO6L0sSzxFNEubYN8/O4thT7OQT+WH+3M= -20251023044432.sql h1:MkvajJs3bfk9+wHvQ43/ccAluJEBARm1gWr1u92ccLA= -20251024034832.sql h1:x3s3VEVYLOSKLAFxJGb2+c1FyTMMvPE+9k4Ew7rKQaI= -20251024074315.sql h1:EjAjelgi5qAfcRq/8vPTlGGYHvAKxNTllm8f0SzZDns= -20251025013451.sql h1:6hnuIiwYiG+6nLhOY/+Yyn+I6ZCFNRZxrJNqBV6HLqE= -20251025013609.sql h1:evPJaTD8WxYRMOJZHkSr7ONLx9PYxT+ankzQt9c/sJ0= -20251027075128.sql h1:/iFQBM1sytjqpyQSOx61q33gnorMgxTiFVSuL6bQqsM= -20251027091406.sql h1:eCZGtUkxAzEAqpC9UsGpP8Df9mS0DEOqSl885LgqpvM= -20251102002037.sql h1:lFJbuoZ2LMQnUNGdcwHVY3Xlfslgzu9t2WByT8yfOZI= -20251102091932.sql h1:rmdhb5m+P+fU8jROBZNyeYgZKuQvucsuljXv4ZVzvks= -20251103081637.sql h1:tf3BcwTeIw+oxMEisKDDfyKnBfalTLs8b0PJA8JWYxY= -20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk= -20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= -20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= -20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= -20251105044629.sql h1:4NU27HeKUNFsV82LacnwmnCSAH0pSbZR9J9/ZESRs6M= -20251105121808.sql h1:fii6LjqWYjrm/pEIqttfvJI6QEUL49gque8wYHh1+yI= -20251106035305.sql h1:oQ7BwnxPuwY2q98adIVc+lNwL/Sz1OceLJeClDo9/TI= -20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= -20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= -20251106042006.sql h1:sVi3ilQnUapkKBzNi/z495eK4ivCF9ssU/D3oEldokM= +h1:lDfnkzBVHYhHwd5okbIRgBk5zo9kmeAK9Ideg1SsSw4= +20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY= +20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= +20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI= +20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= +20250908073811.sql h1:gOi5cnGG1htlpfizybYmUIT0vYjZTBfXiI0nPSYK2u8= +20250908073839.sql h1:cWNDA4YikjoOteAJuNLFILjQUJPFB6o8Wxreiek4QyI= +20250910055902.sql h1:nxxOGnU0BbH/v3IPgeIOXOwH8d3tKomw7h6FTeMnnBs= +20250915123412.sql h1:mz7SiWfrdf0qE1VTSAAnA/147d6gyp6ry5vZ2bR9SH0= +20250916043819.sql h1:RHXVtmMkB6wfv06HfPyHMBmUfIpFt1xveafNz0kwKnE= +20250917040616.sql h1:MYVDht+akBlzQGKNu2hTTTLPEcH1bxT/Q8MK6WEtuhs= +20250917040751.sql h1:J79YyS2JzWgh5oKXMTgh67uo3gLxKaAsxRiZmSIfjBs= +20250917045138.sql h1:/SM1N4O8X3yxpoJgMEARmS1uOkuLKsTOy4PLsRCOKaQ= +20250917093645.sql h1:PNBTGZ7s10e5b5+Tie8YfVQBN0zKtJ5T34oK1iOUEb4= +20250918073552.sql h1:jG7+g3i8ODYaJdcdZz12v3nbsZ5mB9wG6kWnGyTQIRI= +20250918073742.sql h1:j+rgw7puxE7s+phqPVZHmPk0af3rcaA56Itp86y1suY= +20250918074745.sql h1:rPmP4DXs6OnY4Vp+xO/z9jFpJt/RrJ52SJJjIIxeDvc= +20250923025134.sql h1:2r6pcwnBSU5Y9Czk1OHBoh4yZXiMtEca9X8843fTEX0= +20250924051317.sql h1:iUAk2gsGoEGIPQ0lEEUp8maMSId8emNbP+kP712ABIA= +20250929034321.sql h1:UlpALNVmdi95zOIT0yc6ZyTj9bBjQEIpZhvgrc52M+k= +20250929034428.sql h1:feF+H4nDyHh5bdx48Oiz0A1qecZfi6v3qTTdjzJ45Dg= +20250930025550.sql h1:6XT1kXI3Z3ZIxxmvT7poufZWWCW0QiejZPaFV5wBnjI= +20250930140351.sql h1:HxnmAbh9gCy8jwl/9ycGktiByaUripsjFFvohofY2CY= +20251002085604.sql h1:SjLPi+ZN6qDccK3DaEQCgNsZpPwr5kynWXwbwEsziCI= +20251003032030.sql h1:oHfxNSuqTxU8Zaf9H+h8TuUb1Da03wcyc6hZjDrUQ2s= +20251005060450.sql h1:GIuCcrd4MwjmXpvbzDzPYL18BV3QaZZ+Y2FmEzjvi0E= +20251006041122.sql h1:uNDQbSw0M08lYoMvUNlQtS3iDzpPM1ixT13ugSAoWjE= +20251006045658.sql h1:z+t7yCK54Q4SSiF9kUyUhkYB2F+kzSW9TB7ogxd9wzw= +20251006045928.sql h1:1lATLFLp4BWwGZqAjZdP0Dc6ypNXiYcwjoNkqGa8NFE= +20251007022859.sql h1:HXXwWrkyvzJzJGAt9mGskCRBBV/c1JfPmfjDocmJhQ4= +20251008031337.sql h1:Ln5pCF3Hxa5foHZLcds+z/us2eH6VAhhEj3w0TAGlVs= +20251008031554.sql h1:aB4MUS2lmqG0//4HKUWorcPSpWya0VC4QItvGyskEVI= +20251008052346.sql h1:MI3AZgU5XcwZT2OvvlWAxdRtL0eJ3jjRwt56IY1+pRU= +20251008073620.sql h1:sztWXuSNYwpEraaSapSsYwno75LO5H/N7ob7OJQ8X/A= +20251009042854.sql h1:TnPXj+dCJls3IU//cuqJZymyBzZMKs7ayazfgtAFRxM= +20251009052657.sql h1:leXbs0CP8r5dRilmYyLRk1MICqak3ea1/LWMtFrijqQ= +20251010031743.sql h1:SgHNY/lQ88G2F4nZyMfiOkDntb+gtOR+nEQLqXBTwv4= +20251010070721.sql h1:AnJnhXsMzDvK4AFgYw6B16Kpo/hljrZtcpc9m2VOSHQ= +20251010072711.sql h1:aXPTtNwLcTuw8C/yAxwxvqs0ayEjNzI1uuE0vE3ERa8= +20251013044536.sql h1:7Pq6JcvTpPBYDCW2dz3HdgUwY65HlhEVWy9TiG8iONE= +20251013051438.sql h1:X6t8bkqpUYYokBunSufMQUe5vCg0VyO6dxbm7ngosUc= +20251013081808.sql h1:495pLguXL2Ozh+ycn4UYZgZbn6WbjXNbyZUc3JU8qhI= +20251014060047.sql h1:nCgImMRGHhziiW57O1ofWaXCAPGaCOHN7PldQ3OSmM4= +20251014063537.sql h1:2cLmID79jP6cuQ1YJaWTtghFiM1GtHMC0ZQl30Hpy1M= +20251014063720.sql h1:bzLKKVAjSHgDFoiI/glj7t1ETlSAKx+AlsIAaP0ru2g= +20251015045455.sql h1:S547+UugQhlTRcn1Lm1IfqT5RNPttIWIiD+RTx69YaE= +20251016010845.sql h1:c9DUvxl17pUkf0azdYGM/YDzYxIJkLcfZOcMI4rL+R0= +20251016011023.sql h1:u3ivg83bXgYHBbojbWpemLxPE9Dmmj53B6LXo664jxw= +20251016062912.sql h1:W9n1hWchfYkqNX9LO9uxFxEXAb/iY+Pexjnhmp6PbgI= +20251017060617.sql h1:VU6yZ2+LfHpDZ3+TIH40t3F5YXPCpTppuF9+uSqa4b8= +20251017082207.sql h1:QshZslfedckz7iDpSGmPyY9sP6dy6ckHbs8L1TuXIA4= +20251018032635.sql h1:M1U/9W/F9wlW5YDmVAmHFfUJU7FWFaX0DblpfZcYWrE= +20251018040322.sql h1:Zk/vw0e6AzWFO2ElLOzB+OrSz6k+h1Ynxp0TImAzxwY= +20251019093915.sql h1:3Q0kPiZwJnHn5rAvdh0w1LBdiA7W2xBmZWncoPXb044= +20251020062553.sql h1:mJwC/J8GzPAIXckNMvy1f/Nguk2VVf8roD/Raclhbao= +20251021041042.sql h1:d1BAOGAQhqr+oOwcpAVozUsTh457VSDEk2qQFavGG58= +20251021075552.sql h1:TNChGQ1Zlr/1iQ6qvK4iDTAJpe6L/z/M6e/O0SkQVaM= +20251023044432.sql h1:GA2AdJk2ULyjr6igtu9C/CEi4YUIks8r9jXGGaCvPsk= +20251024034832.sql h1:RXmbEhMkOLK5g1QL6up8iRPcwYfo89oLP26ZHvrUK9o= +20251024074315.sql h1:3GnPQSbuAAfMa8oWDyBjhXqn1j1zunY/w0ydX0IGPrA= +20251025013451.sql h1:5eNrA9LDxA4i5CCP7wSyOgFZ6t6jBWVil+oGzJpkJ2E= +20251025013609.sql h1:+N6EHc1kv3hqf16CUhXe+UITPmoxOPfi4MECLmJXNrc= +20251027075128.sql h1:PQflgsjce/p2ClbybLtdehdPNDcMZ9Lb1vd98xd0K8E= +20251027091406.sql h1:bYXV57GvodCMjg0/ox+XKGIAGhrDlVuJ1wO4foNEKtQ= +20251102002037.sql h1:ZcwULsJU2lI9t5pX7ukmfAHSx4ZxdxLUX6jzLDc2SrU= +20251102091932.sql h1:A6y9j4wAqm4/HfMDxhpy/ChDn3UNRVN99KGgSCX+e18= +20251103081637.sql h1:RFqJNhJItSwJQaMP5IcQ14mL7eQ3EJjGZua9zLWzwMU= +20251104042334.sql h1:BbjLAwImggvI6489FQgD+S/AaafeiZut8k19TdH7XUE= +20251104043530.sql h1:Y0sOQqgnHxd5vKPA4+4fAGGdWCv6duKAYgHnjRJZUIc= +20251104080952.sql h1:hDHzFs/k+NhPYJ64ifbVp+nTJLMCG5MIMJU1zBMP0V0= +20251104084135.sql h1:p97mW1MPtPrMWJKy/KZqvymMO/vlelnXp43N9bZVCTI= +20251105044629.sql h1:E4BkVD3YyWvd0D18jA57EwTmkeoAMUWrdTCEwdPHA1U= +20251105121808.sql h1:kyMNzaJLyVtS1QpkX7cnVvhQmrrIE8m3GxUWwrMeyUo= +20251106035305.sql h1:VInVWBP1xpEhVIm1+ymuPzu0joxV2oS4qkNIyQvmTSU= +20251106040137.sql h1:7glRO1VAgq89H6zhM6M50iLwMT0w2sb96DUGrvfXZo4= +20251106041333.sql h1:/2wLmx8awSYhVpusDPAI+VeYJOLeLCWsNaF79gl1lg8= +20251106042006.sql h1:05AZyIbRJi1W08ETScADyAhI3elW0bXaWizlCpDfFCI= From 4e001555bb0e02a4c46b30486427806a3bba34b3 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 12:17:49 +0700 Subject: [PATCH 31/55] migration from server --- cmd/main-migration/Makefile | 36 +- cmd/main-migration/README-ATLAS.MD | 116 +- cmd/main-migration/atlas.hcl.example | 42 +- cmd/main-migration/migration.go | 18 +- .../migrations/20250904105930.sql | 1370 ++++++++--------- .../migrations/20250904141448.sql | 20 +- .../migrations/20250908062237.sql | 192 +-- .../migrations/20250908062323.sql | 4 +- .../migrations/20250908073811.sql | 4 +- .../migrations/20250908073839.sql | 4 +- .../migrations/20250910055902.sql | 4 +- .../migrations/20250915123412.sql | 292 ++-- .../migrations/20250916043819.sql | 28 +- .../migrations/20250917040616.sql | 16 +- .../migrations/20250917040751.sql | 4 +- .../migrations/20250917045138.sql | 4 +- .../migrations/20250917093645.sql | 8 +- .../migrations/20250918073552.sql | 20 +- .../migrations/20250918073742.sql | 62 +- .../migrations/20250918074745.sql | 4 +- .../migrations/20250923025134.sql | 34 +- .../migrations/20250924051317.sql | 4 +- .../migrations/20250929034321.sql | 4 +- .../migrations/20250929034428.sql | 4 +- .../migrations/20250930025550.sql | 12 +- .../migrations/20250930140351.sql | 8 +- .../migrations/20251002085604.sql | 4 +- .../migrations/20251003032030.sql | 12 +- .../migrations/20251005060450.sql | 48 +- .../migrations/20251006041122.sql | 4 +- .../migrations/20251006045658.sql | 4 +- .../migrations/20251006045928.sql | 4 +- .../migrations/20251007022859.sql | 4 +- .../migrations/20251008031337.sql | 4 +- .../migrations/20251008031554.sql | 24 +- .../migrations/20251008052346.sql | 4 +- .../migrations/20251008073620.sql | 4 +- .../migrations/20251009042854.sql | 18 +- .../migrations/20251009052657.sql | 16 +- .../migrations/20251010031743.sql | 12 +- .../migrations/20251010070721.sql | 30 +- .../migrations/20251010072711.sql | 4 +- .../migrations/20251013044536.sql | 28 +- .../migrations/20251013051438.sql | 4 +- .../migrations/20251013081808.sql | 32 +- .../migrations/20251014060047.sql | 72 +- .../migrations/20251014063537.sql | 32 +- .../migrations/20251014063720.sql | 52 +- .../migrations/20251015045455.sql | 4 +- .../migrations/20251016010845.sql | 4 +- .../migrations/20251016011023.sql | 34 +- .../migrations/20251016062912.sql | 108 +- .../migrations/20251017060617.sql | 4 +- .../migrations/20251017082207.sql | 4 +- .../migrations/20251018032635.sql | 8 +- .../migrations/20251018040322.sql | 26 +- .../migrations/20251019093915.sql | 30 +- .../migrations/20251020062553.sql | 4 +- .../migrations/20251021041042.sql | 120 +- .../migrations/20251021075552.sql | 16 +- .../migrations/20251023044432.sql | 180 +-- .../migrations/20251024034832.sql | 24 +- .../migrations/20251024074315.sql | 4 +- .../migrations/20251025013451.sql | 8 +- .../migrations/20251025013609.sql | 24 +- .../migrations/20251027075128.sql | 4 +- .../migrations/20251027091406.sql | 4 +- .../migrations/20251102002037.sql | 12 +- .../migrations/20251102091932.sql | 4 +- .../migrations/20251103081637.sql | 34 +- .../migrations/20251104042334.sql | 4 +- .../migrations/20251104043530.sql | 38 +- .../migrations/20251104080952.sql | 4 +- .../migrations/20251104084135.sql | 34 +- .../migrations/20251105044629.sql | 76 +- .../migrations/20251105121808.sql | 4 +- .../migrations/20251106035305.sql | 8 +- .../migrations/20251106040137.sql | 4 +- .../migrations/20251106041333.sql | 4 +- .../migrations/20251106042006.sql | 4 +- 80 files changed, 1785 insertions(+), 1785 deletions(-) diff --git a/cmd/main-migration/Makefile b/cmd/main-migration/Makefile index e83356e5..f445a815 100644 --- a/cmd/main-migration/Makefile +++ b/cmd/main-migration/Makefile @@ -1,18 +1,18 @@ -# Makefile for Atlas migrations - -# Default environment -ENV ?= gorm - -.PHONY: diff apply hash - -## Generate a new migration diff -diff: - atlas migrate diff --env $(ENV) - -## Apply migrations to the database -apply: - atlas migrate apply --env $(ENV) - -## Calculate the schema hash -hash: - atlas migrate hash +# Makefile for Atlas migrations + +# Default environment +ENV ?= gorm + +.PHONY: diff apply hash + +## Generate a new migration diff +diff: + atlas migrate diff --env $(ENV) + +## Apply migrations to the database +apply: + atlas migrate apply --env $(ENV) + +## Calculate the schema hash +hash: + atlas migrate hash diff --git a/cmd/main-migration/README-ATLAS.MD b/cmd/main-migration/README-ATLAS.MD index da249823..ec2869ef 100644 --- a/cmd/main-migration/README-ATLAS.MD +++ b/cmd/main-migration/README-ATLAS.MD @@ -1,59 +1,59 @@ -# Database Migration with Atlas - -This project uses [Atlas](https://atlasgo.io/) for database schema management and migrations. - -## 📋 Prerequisites - -1. **Download and Install Atlas CLI** - Run the following command in PowerShell or Git Bash: - - ```sh - curl -sSf https://atlasgo.sh | sh - ``` - Verify installation: - - ```sh - atlas version - ``` - -2. Install GORM Provider - Run inside your Go project: - - ```sh - go get -u ariga.io/atlas-provider-gorm - ``` - -3. Create atlas.hcl configuration file - Just create an atlas.hcl file in your project root as example given at atlas.hcl.example -4. Create migrations folder - ```sh - mkdir migrations - ``` -5. Usage -You can use the provided Makefile for common commands: - - Generate a migration diff - ```sh - make diff - ``` - - Apply migrations - ```sh - make apply - ``` - - Compute schema hash - ```sh - make hash - ``` - - If you don’t have make installed, you can run the Atlas commands directly: - ```sh - atlas migrate diff --env gorm - ``` - ```sh - atlas migrate apply --env gorm - ``` - ```sh - atlas migrate hash +# Database Migration with Atlas + +This project uses [Atlas](https://atlasgo.io/) for database schema management and migrations. + +## 📋 Prerequisites + +1. **Download and Install Atlas CLI** + Run the following command in PowerShell or Git Bash: + + ```sh + curl -sSf https://atlasgo.sh | sh + ``` + Verify installation: + + ```sh + atlas version + ``` + +2. Install GORM Provider + Run inside your Go project: + + ```sh + go get -u ariga.io/atlas-provider-gorm + ``` + +3. Create atlas.hcl configuration file + Just create an atlas.hcl file in your project root as example given at atlas.hcl.example +4. Create migrations folder + ```sh + mkdir migrations + ``` +5. Usage +You can use the provided Makefile for common commands: + + Generate a migration diff + ```sh + make diff + ``` + + Apply migrations + ```sh + make apply + ``` + + Compute schema hash + ```sh + make hash + ``` + + If you don’t have make installed, you can run the Atlas commands directly: + ```sh + atlas migrate diff --env gorm + ``` + ```sh + atlas migrate apply --env gorm + ``` + ```sh + atlas migrate hash ``` \ No newline at end of file diff --git a/cmd/main-migration/atlas.hcl.example b/cmd/main-migration/atlas.hcl.example index 857d1352..3d02232d 100644 --- a/cmd/main-migration/atlas.hcl.example +++ b/cmd/main-migration/atlas.hcl.example @@ -1,22 +1,22 @@ -data "external_schema" "gorm" { - program = [ - "go", - "run", - "-mod=mod", - ".", - ] -} - -env "gorm" { - src = data.external_schema.gorm.url - dev = "" // dsn db to check the diff - migration { - dir = "file://migrations" - } - url = "" // dsn db to apply - format { - migrate { - diff = "{{ sql . \" \" }}" - } - } +data "external_schema" "gorm" { + program = [ + "go", + "run", + "-mod=mod", + ".", + ] +} + +env "gorm" { + src = data.external_schema.gorm.url + dev = "" // dsn db to check the diff + migration { + dir = "file://migrations" + } + url = "" // dsn db to apply + format { + migrate { + diff = "{{ sql . \" \" }}" + } + } } \ No newline at end of file diff --git a/cmd/main-migration/migration.go b/cmd/main-migration/migration.go index dd28a55f..c0c1283c 100644 --- a/cmd/main-migration/migration.go +++ b/cmd/main-migration/migration.go @@ -1,9 +1,9 @@ -package main - -import ( - m "simrs-vx/internal/interface/migration" -) - -func main() { - m.Migrate(m.Main) -} +package main + +import ( + m "simrs-vx/internal/interface/migration" +) + +func main() { + m.Migrate(m.Main) +} diff --git a/cmd/main-migration/migrations/20250904105930.sql b/cmd/main-migration/migrations/20250904105930.sql index 39175bfb..ae541404 100644 --- a/cmd/main-migration/migrations/20250904105930.sql +++ b/cmd/main-migration/migrations/20250904105930.sql @@ -1,685 +1,685 @@ --- Create "DiagnoseSrc" table -CREATE TABLE "public"."DiagnoseSrc" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(2048) NULL, - "IndName" character varying(2048) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_DiagnoseSrc_Code" UNIQUE ("Code") -); --- Create "PharmacyCompany" table -CREATE TABLE "public"."PharmacyCompany" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(100) NULL, - "Regency_Code" character varying(4) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_PharmacyCompany_Code" UNIQUE ("Code") -); --- Create "Uom" table -CREATE TABLE "public"."Uom" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Uom_Code" UNIQUE ("Code") -); --- Create "Counter" table -CREATE TABLE "public"."Counter" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(30) NULL, - "Number" smallint NULL, - "Parent_Id" integer NULL, - "Type_Code" text NULL, - "Queue_Code" character varying(5) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Counter_Code" UNIQUE ("Code") -); --- Create "Item" table -CREATE TABLE "public"."Item" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(50) NULL, - "Name" character varying(100) NULL, - "ItemGroup_Code" character varying(10) NULL, - "Uom_Code" character varying(10) NULL, - "Infra_Id" integer NULL, - "Stock" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Item_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Item_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Infra" table -CREATE TABLE "public"."Infra" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "InfraGroup_Code" character varying(10) NULL, - "Parent_Id" integer NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Infra_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Device" table -CREATE TABLE "public"."Device" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NOT NULL, - "Uom_Code" character varying(10) NULL, - "Infra_Id" integer NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Device_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Device_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Device_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Device_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Province" table -CREATE TABLE "public"."Province" ( - "Id" smallserial NOT NULL, - "Code" character varying(2) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Province_Code" UNIQUE ("Code") -); --- Create "Regency" table -CREATE TABLE "public"."Regency" ( - "Id" serial NOT NULL, - "Province_Code" character varying(2) NULL, - "Code" character varying(4) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Regency_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Province_Regencies" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "District" table -CREATE TABLE "public"."District" ( - "Id" bigserial NOT NULL, - "Regency_Code" character varying(4) NULL, - "Code" character varying(6) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_District_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Regency_Districts" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Division" table -CREATE TABLE "public"."Division" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "Parent_Id" smallint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Division_Code" UNIQUE ("Code") -); --- Create "DivisionPosition" table -CREATE TABLE "public"."DivisionPosition" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Division_Id" integer NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_DivisionPosition_Code" UNIQUE ("Code"), - CONSTRAINT "fk_DivisionPosition_Division" FOREIGN KEY ("Division_Id") REFERENCES "public"."Division" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Ethnic" table -CREATE TABLE "public"."Ethnic" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Ethnic_Code" UNIQUE ("Code") -); --- Create "Language" table -CREATE TABLE "public"."Language" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Language_Code" UNIQUE ("Code") -); --- Create "Person" table -CREATE TABLE "public"."Person" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Name" character varying(150) NOT NULL, - "FrontTitle" character varying(50) NULL, - "EndTitle" character varying(50) NULL, - "BirthDate" timestamptz NULL, - "BirthRegency_Code" character varying(4) NULL, - "Gender_Code" character varying(10) NULL, - "ResidentIdentityNumber" character varying(16) NULL, - "PassportNumber" character varying(20) NULL, - "DrivingLicenseNumber" character varying(20) NULL, - "Religion_Code" character varying(10) NULL, - "Education_Code" character varying(10) NULL, - "Ocupation_Code" character varying(15) NULL, - "Ocupation_Name" character varying(50) NULL, - "Ethnic_Code" character varying(20) NULL, - "Language_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Person_DrivingLicenseNumber" UNIQUE ("DrivingLicenseNumber"), - CONSTRAINT "uni_Person_PassportNumber" UNIQUE ("PassportNumber"), - CONSTRAINT "uni_Person_ResidentIdentityNumber" UNIQUE ("ResidentIdentityNumber"), - CONSTRAINT "fk_Person_Ethnic" FOREIGN KEY ("Ethnic_Code") REFERENCES "public"."Ethnic" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Person_Language" FOREIGN KEY ("Language_Code") REFERENCES "public"."Language" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "User" table -CREATE TABLE "public"."User" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Name" character varying(25) NOT NULL, - "Password" character varying(255) NOT NULL, - "Status_Code" character varying(10) NOT NULL, - "FailedLoginCount" smallint NULL, - "Position_Code" character varying(20) NOT NULL, - "LoginAttemptCount" bigint NULL, - "LastSuccessLogin" timestamptz NULL, - "LastAllowdLogin" timestamptz NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_User_Name" UNIQUE ("Name") -); --- Create "Employee" table -CREATE TABLE "public"."Employee" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "User_Id" bigint NULL, - "Person_Id" bigint NULL, - "Division_Code" character varying(10) NULL, - "Number" character varying(20) NULL, - "Status_Code" character varying(10) NOT NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Employee_Division" FOREIGN KEY ("Division_Code") REFERENCES "public"."Division" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Employee_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Employee_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Installation" table -CREATE TABLE "public"."Installation" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "EncounterClass_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Installation_Code" UNIQUE ("Code") -); --- Create "Unit" table -CREATE TABLE "public"."Unit" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Installation_Id" integer NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "Type_Code" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Unit_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Unit_Installation" FOREIGN KEY ("Installation_Id") REFERENCES "public"."Installation" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Specialist" table -CREATE TABLE "public"."Specialist" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "Unit_Id" integer NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Specialist_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Specialist_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Subspecialist" table -CREATE TABLE "public"."Subspecialist" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "Specialist_Id" integer NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Subspecialist_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Subspecialist_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Doctor" table -CREATE TABLE "public"."Doctor" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Employee_Id" bigint NULL, - "IHS_Number" character varying(20) NULL, - "SIP_Number" character varying(20) NULL, - "Unit_Id" integer NULL, - "Specialist_Id" integer NULL, - "Subspecialist_Id" integer NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Doctor_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Doctor_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Doctor_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Doctor_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "DoctorFee" table -CREATE TABLE "public"."DoctorFee" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Doctor_Id" bigint NULL, - "FeeType_Code" character varying(11) NULL, - "Price" numeric NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_DoctorFee_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_DoctorFee_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Patient" table -CREATE TABLE "public"."Patient" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Person_Id" bigint NULL, - "RegisteredAt" timestamptz NULL, - "Status_Code" character varying(10) NOT NULL, - "Number" character varying(15) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Patient_Number" UNIQUE ("Number"), - CONSTRAINT "fk_Patient_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Encounter" table -CREATE TABLE "public"."Encounter" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Patient_Id" bigint NULL, - "RegisteredAt" timestamptz NULL, - "Class_Code" character varying(10) NOT NULL, - "Unit_Id" bigint NULL, - "Specialist_Id" integer NULL, - "Subspecialist_Id" integer NULL, - "VisitDate" timestamptz NULL, - "Assignment_Doctor_Id" bigint NULL, - "Responsible_Doctor_Id" bigint NULL, - "DischardeMethod_Code" character varying(10) NULL, - "RefSource_Name" character varying(100) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Encounter_Assignment_Doctor" FOREIGN KEY ("Assignment_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Encounter_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Encounter_Responsible_Doctor" FOREIGN KEY ("Responsible_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Encounter_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Encounter_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Encounter_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "InsuranceCompany" table -CREATE TABLE "public"."InsuranceCompany" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "Regency_Code" character varying(4) NULL, - "Address" character varying(100) NULL, - "PhoneNumber" character varying(20) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_InsuranceCompany_Code" UNIQUE ("Code"), - CONSTRAINT "fk_InsuranceCompany_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "ItemPrice" table -CREATE TABLE "public"."ItemPrice" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Item_Id" bigint NULL, - "Price" numeric NULL, - "InsuranceCompany_Code" character varying(20) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_ItemPrice_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Code") REFERENCES "public"."InsuranceCompany" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_ItemPrice_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Laborant" table -CREATE TABLE "public"."Laborant" ( - "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 "fk_Laborant_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Material" table -CREATE TABLE "public"."Material" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "Uom_Code" character varying(10) NULL, - "Infra_Id" integer NULL, - "Stock" bigint NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Material_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Material_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Material_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Material_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "McuSrcCategory" table -CREATE TABLE "public"."McuSrcCategory" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "Scope_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_McuSrcCategory_Code" UNIQUE ("Code") -); --- Create "McuSrc" table -CREATE TABLE "public"."McuSrc" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "CheckupCategory_Code" character varying(20) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_McuSrc_Code" UNIQUE ("Code"), - CONSTRAINT "fk_McuSrc_CheckupCategory" FOREIGN KEY ("CheckupCategory_Code") REFERENCES "public"."McuSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "MedicalActionSrc" table -CREATE TABLE "public"."MedicalActionSrc" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_MedicalActionSrc_Code" UNIQUE ("Code"), - CONSTRAINT "fk_MedicalActionSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "ProcedureSrc" table -CREATE TABLE "public"."ProcedureSrc" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(2048) NULL, - "IndName" character varying(2048) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_ProcedureSrc_Code" UNIQUE ("Code") -); --- Create "MedicalActionSrcItem" table -CREATE TABLE "public"."MedicalActionSrcItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "MedicalActionSrc_Id" bigint NULL, - "ProcedureSrc_Id" bigint NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_MedicalActionSrcItem_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc" FOREIGN KEY ("MedicalActionSrc_Id") REFERENCES "public"."MedicalActionSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc" FOREIGN KEY ("ProcedureSrc_Id") REFERENCES "public"."ProcedureSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "MedicineGroup" table -CREATE TABLE "public"."MedicineGroup" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_MedicineGroup_Code" UNIQUE ("Code") -); --- Create "MedicineMethod" table -CREATE TABLE "public"."MedicineMethod" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_MedicineMethod_Code" UNIQUE ("Code") -); --- Create "Medicine" table -CREATE TABLE "public"."Medicine" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "MedicineGroup_Code" character varying(10) NULL, - "MedicineMethod_Code" character varying(10) NULL, - "Uom_Code" character varying(10) NULL, - "Dose" smallint NULL, - "Infra_Id" integer NULL, - "Stock" bigint NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Medicine_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Medicine_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Medicine_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Medicine_MedicineGroup" FOREIGN KEY ("MedicineGroup_Code") REFERENCES "public"."MedicineGroup" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Medicine_MedicineMethod" FOREIGN KEY ("MedicineMethod_Code") REFERENCES "public"."MedicineMethod" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Medicine_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "MedicineMix" table -CREATE TABLE "public"."MedicineMix" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id") -); --- Create "MedicineMixItem" table -CREATE TABLE "public"."MedicineMixItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "MedicineMix_Id" bigint NULL, - "Medicine_Id" bigint NULL, - "Dose" smallint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_MedicineMixItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_MedicineMixItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Nurse" table -CREATE TABLE "public"."Nurse" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Employee_Id" bigint NULL, - "IHS_Number" character varying(20) NULL, - "Unit_Id" integer NULL, - "Infra_Id" integer NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Nurse_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Nurse_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Nurse_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Nutritionist" table -CREATE TABLE "public"."Nutritionist" ( - "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 "fk_Nutritionist_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "PersonAddress" table -CREATE TABLE "public"."PersonAddress" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Person_Id" bigint NULL, - "Address" character varying(150) NULL, - "Rt" character varying(2) NULL, - "Rw" character varying(2) NULL, - "Village_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Person_Addresses" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "PersonContact" table -CREATE TABLE "public"."PersonContact" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Person_Id" bigint NULL, - "Type_Code" character varying(15) NULL, - "Value" character varying(100) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Person_Contacts" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Village" table -CREATE TABLE "public"."Village" ( - "Id" bigserial NOT NULL, - "District_Code" character varying(6) NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Village_Code" UNIQUE ("Code"), - CONSTRAINT "fk_District_Villages" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "PersonRelative" table -CREATE TABLE "public"."PersonRelative" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Person_Id" bigint NULL, - "Relationship_Code" character varying(100) NOT NULL, - "Name" character varying(100) NULL, - "Address" character varying(100) NULL, - "Village_Code" character varying(10) NULL, - "Gender_Code" character varying(10) NULL, - "PhoneNumber" character varying(30) NULL, - "Education_Code" character varying(10) NULL, - "Occupation_Code" character varying(10) NULL, - "Occupation_Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_PersonRelative_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Person_Relatives" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Pharmacist" table -CREATE TABLE "public"."Pharmacist" ( - "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 "fk_Pharmacist_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "PracticeSchedule" table -CREATE TABLE "public"."PracticeSchedule" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Doctor_Id" bigint NULL, - "Unit_Code" character varying(10) NULL, - "Day_Code" smallint NULL, - "StartTime" character varying(5) NULL, - "EndTime" character varying(5) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_PracticeSchedule_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_PracticeSchedule_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Room" table -CREATE TABLE "public"."Room" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Infra_Id" integer NULL, - "Unit_Id" integer NULL, - "Specialist_Id" integer NULL, - "Subspecialist_Id" integer NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Room_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Room_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Room_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Room_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "SpecialistIntern" table -CREATE TABLE "public"."SpecialistIntern" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Person_Id" bigint NULL, - "Specialist_Id" integer NULL, - "Subspecialist_Id" integer NULL, - "User_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_SpecialistIntern_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_SpecialistIntern_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_SpecialistIntern_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_SpecialistIntern_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "DiagnoseSrc" table +CREATE TABLE "public"."DiagnoseSrc" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(2048) NULL, + "IndName" character varying(2048) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_DiagnoseSrc_Code" UNIQUE ("Code") +); +-- Create "PharmacyCompany" table +CREATE TABLE "public"."PharmacyCompany" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(100) NULL, + "Regency_Code" character varying(4) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_PharmacyCompany_Code" UNIQUE ("Code") +); +-- Create "Uom" table +CREATE TABLE "public"."Uom" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Uom_Code" UNIQUE ("Code") +); +-- Create "Counter" table +CREATE TABLE "public"."Counter" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(30) NULL, + "Number" smallint NULL, + "Parent_Id" integer NULL, + "Type_Code" text NULL, + "Queue_Code" character varying(5) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Counter_Code" UNIQUE ("Code") +); +-- Create "Item" table +CREATE TABLE "public"."Item" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(50) NULL, + "Name" character varying(100) NULL, + "ItemGroup_Code" character varying(10) NULL, + "Uom_Code" character varying(10) NULL, + "Infra_Id" integer NULL, + "Stock" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Item_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Item_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Infra" table +CREATE TABLE "public"."Infra" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "InfraGroup_Code" character varying(10) NULL, + "Parent_Id" integer NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Infra_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Device" table +CREATE TABLE "public"."Device" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NOT NULL, + "Uom_Code" character varying(10) NULL, + "Infra_Id" integer NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Device_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Device_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Device_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Device_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Province" table +CREATE TABLE "public"."Province" ( + "Id" smallserial NOT NULL, + "Code" character varying(2) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Province_Code" UNIQUE ("Code") +); +-- Create "Regency" table +CREATE TABLE "public"."Regency" ( + "Id" serial NOT NULL, + "Province_Code" character varying(2) NULL, + "Code" character varying(4) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Regency_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Province_Regencies" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "District" table +CREATE TABLE "public"."District" ( + "Id" bigserial NOT NULL, + "Regency_Code" character varying(4) NULL, + "Code" character varying(6) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_District_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Regency_Districts" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Division" table +CREATE TABLE "public"."Division" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "Parent_Id" smallint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Division_Code" UNIQUE ("Code") +); +-- Create "DivisionPosition" table +CREATE TABLE "public"."DivisionPosition" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Division_Id" integer NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_DivisionPosition_Code" UNIQUE ("Code"), + CONSTRAINT "fk_DivisionPosition_Division" FOREIGN KEY ("Division_Id") REFERENCES "public"."Division" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Ethnic" table +CREATE TABLE "public"."Ethnic" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Ethnic_Code" UNIQUE ("Code") +); +-- Create "Language" table +CREATE TABLE "public"."Language" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Language_Code" UNIQUE ("Code") +); +-- Create "Person" table +CREATE TABLE "public"."Person" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(150) NOT NULL, + "FrontTitle" character varying(50) NULL, + "EndTitle" character varying(50) NULL, + "BirthDate" timestamptz NULL, + "BirthRegency_Code" character varying(4) NULL, + "Gender_Code" character varying(10) NULL, + "ResidentIdentityNumber" character varying(16) NULL, + "PassportNumber" character varying(20) NULL, + "DrivingLicenseNumber" character varying(20) NULL, + "Religion_Code" character varying(10) NULL, + "Education_Code" character varying(10) NULL, + "Ocupation_Code" character varying(15) NULL, + "Ocupation_Name" character varying(50) NULL, + "Ethnic_Code" character varying(20) NULL, + "Language_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Person_DrivingLicenseNumber" UNIQUE ("DrivingLicenseNumber"), + CONSTRAINT "uni_Person_PassportNumber" UNIQUE ("PassportNumber"), + CONSTRAINT "uni_Person_ResidentIdentityNumber" UNIQUE ("ResidentIdentityNumber"), + CONSTRAINT "fk_Person_Ethnic" FOREIGN KEY ("Ethnic_Code") REFERENCES "public"."Ethnic" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Person_Language" FOREIGN KEY ("Language_Code") REFERENCES "public"."Language" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "User" table +CREATE TABLE "public"."User" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(25) NOT NULL, + "Password" character varying(255) NOT NULL, + "Status_Code" character varying(10) NOT NULL, + "FailedLoginCount" smallint NULL, + "Position_Code" character varying(20) NOT NULL, + "LoginAttemptCount" bigint NULL, + "LastSuccessLogin" timestamptz NULL, + "LastAllowdLogin" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_User_Name" UNIQUE ("Name") +); +-- Create "Employee" table +CREATE TABLE "public"."Employee" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "User_Id" bigint NULL, + "Person_Id" bigint NULL, + "Division_Code" character varying(10) NULL, + "Number" character varying(20) NULL, + "Status_Code" character varying(10) NOT NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Employee_Division" FOREIGN KEY ("Division_Code") REFERENCES "public"."Division" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Employee_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Employee_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Installation" table +CREATE TABLE "public"."Installation" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "EncounterClass_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Installation_Code" UNIQUE ("Code") +); +-- Create "Unit" table +CREATE TABLE "public"."Unit" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Installation_Id" integer NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "Type_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Unit_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Unit_Installation" FOREIGN KEY ("Installation_Id") REFERENCES "public"."Installation" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Specialist" table +CREATE TABLE "public"."Specialist" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "Unit_Id" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Specialist_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Specialist_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Subspecialist" table +CREATE TABLE "public"."Subspecialist" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "Specialist_Id" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Subspecialist_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Subspecialist_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Doctor" table +CREATE TABLE "public"."Doctor" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Employee_Id" bigint NULL, + "IHS_Number" character varying(20) NULL, + "SIP_Number" character varying(20) NULL, + "Unit_Id" integer NULL, + "Specialist_Id" integer NULL, + "Subspecialist_Id" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Doctor_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Doctor_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Doctor_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Doctor_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "DoctorFee" table +CREATE TABLE "public"."DoctorFee" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Doctor_Id" bigint NULL, + "FeeType_Code" character varying(11) NULL, + "Price" numeric NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_DoctorFee_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_DoctorFee_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Patient" table +CREATE TABLE "public"."Patient" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "RegisteredAt" timestamptz NULL, + "Status_Code" character varying(10) NOT NULL, + "Number" character varying(15) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Patient_Number" UNIQUE ("Number"), + CONSTRAINT "fk_Patient_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Encounter" table +CREATE TABLE "public"."Encounter" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Patient_Id" bigint NULL, + "RegisteredAt" timestamptz NULL, + "Class_Code" character varying(10) NOT NULL, + "Unit_Id" bigint NULL, + "Specialist_Id" integer NULL, + "Subspecialist_Id" integer NULL, + "VisitDate" timestamptz NULL, + "Assignment_Doctor_Id" bigint NULL, + "Responsible_Doctor_Id" bigint NULL, + "DischardeMethod_Code" character varying(10) NULL, + "RefSource_Name" character varying(100) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Encounter_Assignment_Doctor" FOREIGN KEY ("Assignment_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Responsible_Doctor" FOREIGN KEY ("Responsible_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "InsuranceCompany" table +CREATE TABLE "public"."InsuranceCompany" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "Regency_Code" character varying(4) NULL, + "Address" character varying(100) NULL, + "PhoneNumber" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_InsuranceCompany_Code" UNIQUE ("Code"), + CONSTRAINT "fk_InsuranceCompany_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "ItemPrice" table +CREATE TABLE "public"."ItemPrice" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Item_Id" bigint NULL, + "Price" numeric NULL, + "InsuranceCompany_Code" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ItemPrice_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Code") REFERENCES "public"."InsuranceCompany" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ItemPrice_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Laborant" table +CREATE TABLE "public"."Laborant" ( + "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 "fk_Laborant_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Material" table +CREATE TABLE "public"."Material" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "Uom_Code" character varying(10) NULL, + "Infra_Id" integer NULL, + "Stock" bigint NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Material_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Material_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Material_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Material_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "McuSrcCategory" table +CREATE TABLE "public"."McuSrcCategory" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "Scope_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_McuSrcCategory_Code" UNIQUE ("Code") +); +-- Create "McuSrc" table +CREATE TABLE "public"."McuSrc" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "CheckupCategory_Code" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_McuSrc_Code" UNIQUE ("Code"), + CONSTRAINT "fk_McuSrc_CheckupCategory" FOREIGN KEY ("CheckupCategory_Code") REFERENCES "public"."McuSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MedicalActionSrc" table +CREATE TABLE "public"."MedicalActionSrc" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_MedicalActionSrc_Code" UNIQUE ("Code"), + CONSTRAINT "fk_MedicalActionSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "ProcedureSrc" table +CREATE TABLE "public"."ProcedureSrc" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(2048) NULL, + "IndName" character varying(2048) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_ProcedureSrc_Code" UNIQUE ("Code") +); +-- Create "MedicalActionSrcItem" table +CREATE TABLE "public"."MedicalActionSrcItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "MedicalActionSrc_Id" bigint NULL, + "ProcedureSrc_Id" bigint NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MedicalActionSrcItem_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc" FOREIGN KEY ("MedicalActionSrc_Id") REFERENCES "public"."MedicalActionSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc" FOREIGN KEY ("ProcedureSrc_Id") REFERENCES "public"."ProcedureSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MedicineGroup" table +CREATE TABLE "public"."MedicineGroup" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_MedicineGroup_Code" UNIQUE ("Code") +); +-- Create "MedicineMethod" table +CREATE TABLE "public"."MedicineMethod" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_MedicineMethod_Code" UNIQUE ("Code") +); +-- Create "Medicine" table +CREATE TABLE "public"."Medicine" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "MedicineGroup_Code" character varying(10) NULL, + "MedicineMethod_Code" character varying(10) NULL, + "Uom_Code" character varying(10) NULL, + "Dose" smallint NULL, + "Infra_Id" integer NULL, + "Stock" bigint NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Medicine_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Medicine_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Medicine_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Medicine_MedicineGroup" FOREIGN KEY ("MedicineGroup_Code") REFERENCES "public"."MedicineGroup" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Medicine_MedicineMethod" FOREIGN KEY ("MedicineMethod_Code") REFERENCES "public"."MedicineMethod" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Medicine_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MedicineMix" table +CREATE TABLE "public"."MedicineMix" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id") +); +-- Create "MedicineMixItem" table +CREATE TABLE "public"."MedicineMixItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "MedicineMix_Id" bigint NULL, + "Medicine_Id" bigint NULL, + "Dose" smallint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MedicineMixItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MedicineMixItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Nurse" table +CREATE TABLE "public"."Nurse" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Employee_Id" bigint NULL, + "IHS_Number" character varying(20) NULL, + "Unit_Id" integer NULL, + "Infra_Id" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Nurse_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Nurse_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Nurse_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Nutritionist" table +CREATE TABLE "public"."Nutritionist" ( + "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 "fk_Nutritionist_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "PersonAddress" table +CREATE TABLE "public"."PersonAddress" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "Address" character varying(150) NULL, + "Rt" character varying(2) NULL, + "Rw" character varying(2) NULL, + "Village_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Person_Addresses" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "PersonContact" table +CREATE TABLE "public"."PersonContact" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "Type_Code" character varying(15) NULL, + "Value" character varying(100) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Person_Contacts" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Village" table +CREATE TABLE "public"."Village" ( + "Id" bigserial NOT NULL, + "District_Code" character varying(6) NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Village_Code" UNIQUE ("Code"), + CONSTRAINT "fk_District_Villages" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "PersonRelative" table +CREATE TABLE "public"."PersonRelative" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "Relationship_Code" character varying(100) NOT NULL, + "Name" character varying(100) NULL, + "Address" character varying(100) NULL, + "Village_Code" character varying(10) NULL, + "Gender_Code" character varying(10) NULL, + "PhoneNumber" character varying(30) NULL, + "Education_Code" character varying(10) NULL, + "Occupation_Code" character varying(10) NULL, + "Occupation_Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_PersonRelative_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Person_Relatives" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Pharmacist" table +CREATE TABLE "public"."Pharmacist" ( + "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 "fk_Pharmacist_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "PracticeSchedule" table +CREATE TABLE "public"."PracticeSchedule" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Doctor_Id" bigint NULL, + "Unit_Code" character varying(10) NULL, + "Day_Code" smallint NULL, + "StartTime" character varying(5) NULL, + "EndTime" character varying(5) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_PracticeSchedule_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_PracticeSchedule_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Room" table +CREATE TABLE "public"."Room" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Infra_Id" integer NULL, + "Unit_Id" integer NULL, + "Specialist_Id" integer NULL, + "Subspecialist_Id" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Room_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Room_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Room_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Room_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "SpecialistIntern" table +CREATE TABLE "public"."SpecialistIntern" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "Specialist_Id" integer NULL, + "Subspecialist_Id" integer NULL, + "User_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_SpecialistIntern_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_SpecialistIntern_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_SpecialistIntern_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_SpecialistIntern_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20250904141448.sql b/cmd/main-migration/migrations/20250904141448.sql index 56a113ca..b2f69b7c 100644 --- a/cmd/main-migration/migrations/20250904141448.sql +++ b/cmd/main-migration/migrations/20250904141448.sql @@ -1,10 +1,10 @@ --- Modify "Doctor" table -ALTER TABLE "public"."Doctor" ADD CONSTRAINT "uni_Doctor_IHS_Number" UNIQUE ("IHS_Number"), ADD CONSTRAINT "uni_Doctor_SIP_Number" UNIQUE ("SIP_Number"); --- Modify "Laborant" table -ALTER TABLE "public"."Laborant" ADD CONSTRAINT "uni_Laborant_IHS_Number" UNIQUE ("IHS_Number"); --- Modify "Nurse" table -ALTER TABLE "public"."Nurse" ADD CONSTRAINT "uni_Nurse_IHS_Number" UNIQUE ("IHS_Number"); --- Modify "Nutritionist" table -ALTER TABLE "public"."Nutritionist" ADD CONSTRAINT "uni_Nutritionist_IHS_Number" UNIQUE ("IHS_Number"); --- Modify "Pharmacist" table -ALTER TABLE "public"."Pharmacist" ADD CONSTRAINT "uni_Pharmacist_IHS_Number" UNIQUE ("IHS_Number"); +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" ADD CONSTRAINT "uni_Doctor_IHS_Number" UNIQUE ("IHS_Number"), ADD CONSTRAINT "uni_Doctor_SIP_Number" UNIQUE ("SIP_Number"); +-- Modify "Laborant" table +ALTER TABLE "public"."Laborant" ADD CONSTRAINT "uni_Laborant_IHS_Number" UNIQUE ("IHS_Number"); +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" ADD CONSTRAINT "uni_Nurse_IHS_Number" UNIQUE ("IHS_Number"); +-- Modify "Nutritionist" table +ALTER TABLE "public"."Nutritionist" ADD CONSTRAINT "uni_Nutritionist_IHS_Number" UNIQUE ("IHS_Number"); +-- Modify "Pharmacist" table +ALTER TABLE "public"."Pharmacist" ADD CONSTRAINT "uni_Pharmacist_IHS_Number" UNIQUE ("IHS_Number"); diff --git a/cmd/main-migration/migrations/20250908062237.sql b/cmd/main-migration/migrations/20250908062237.sql index cc509de4..5a01ab09 100644 --- a/cmd/main-migration/migrations/20250908062237.sql +++ b/cmd/main-migration/migrations/20250908062237.sql @@ -1,96 +1,96 @@ --- Create "Appointment" table -CREATE TABLE "public"."Appointment" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "PracticeSchedule_Id" bigint NULL, - "Patient_Id" bigint NULL, - "Person_ResidentIdentityNumber" character varying(16) NULL, - "Person_Name" character varying(100) NULL, - "Person_PhoneNumber" character varying(30) NULL, - "PaymentMethod_Code" character varying(10) NULL, - "RefNumber" character varying(20) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Appointment_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Appointment_PracticeSchedule" FOREIGN KEY ("PracticeSchedule_Id") REFERENCES "public"."PracticeSchedule" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" ADD COLUMN "Appointment_Doctor_Id" bigint NULL, ADD COLUMN "Appointment_Id" bigint NULL, ADD COLUMN "EarlyEducation" text NULL, ADD COLUMN "MedicalDischargeEducation" text NULL, ADD COLUMN "AdmDischargeEducation" text NULL, ADD COLUMN "DischargeReason" text NULL, ADD CONSTRAINT "fk_Encounter_Appointment" FOREIGN KEY ("Appointment_Id") REFERENCES "public"."Appointment" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Appointment_Doctor" FOREIGN KEY ("Appointment_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Create "Adime" table -CREATE TABLE "public"."Adime" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Employee_Id" bigint NULL, - "Time" timestamptz NULL, - "Value" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Adime_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Adime_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Ambulatory" table -CREATE TABLE "public"."Ambulatory" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Class_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Ambulatory_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Emergency" table -CREATE TABLE "public"."Emergency" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Class_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Emergency_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Inpatient" table -CREATE TABLE "public"."Inpatient" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Class_Code" character varying(10) NULL, - "Infra_Id" integer NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Inpatient_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Inpatient_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Sbar" table -CREATE TABLE "public"."Sbar" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Employee_Id" bigint NULL, - "Time" timestamptz NULL, - "Value" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Sbar_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Sbar_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Soapi" table -CREATE TABLE "public"."Soapi" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Employee_Id" bigint NULL, - "Time" timestamptz NULL, - "Value" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Soapi_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Soapi_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "Appointment" table +CREATE TABLE "public"."Appointment" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "PracticeSchedule_Id" bigint NULL, + "Patient_Id" bigint NULL, + "Person_ResidentIdentityNumber" character varying(16) NULL, + "Person_Name" character varying(100) NULL, + "Person_PhoneNumber" character varying(30) NULL, + "PaymentMethod_Code" character varying(10) NULL, + "RefNumber" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Appointment_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Appointment_PracticeSchedule" FOREIGN KEY ("PracticeSchedule_Id") REFERENCES "public"."PracticeSchedule" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "Appointment_Doctor_Id" bigint NULL, ADD COLUMN "Appointment_Id" bigint NULL, ADD COLUMN "EarlyEducation" text NULL, ADD COLUMN "MedicalDischargeEducation" text NULL, ADD COLUMN "AdmDischargeEducation" text NULL, ADD COLUMN "DischargeReason" text NULL, ADD CONSTRAINT "fk_Encounter_Appointment" FOREIGN KEY ("Appointment_Id") REFERENCES "public"."Appointment" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Appointment_Doctor" FOREIGN KEY ("Appointment_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Create "Adime" table +CREATE TABLE "public"."Adime" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Employee_Id" bigint NULL, + "Time" timestamptz NULL, + "Value" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Adime_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Adime_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Ambulatory" table +CREATE TABLE "public"."Ambulatory" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Class_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Ambulatory_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Emergency" table +CREATE TABLE "public"."Emergency" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Class_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Emergency_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Inpatient" table +CREATE TABLE "public"."Inpatient" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Class_Code" character varying(10) NULL, + "Infra_Id" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Inpatient_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Inpatient_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Sbar" table +CREATE TABLE "public"."Sbar" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Employee_Id" bigint NULL, + "Time" timestamptz NULL, + "Value" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Sbar_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Sbar_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Soapi" table +CREATE TABLE "public"."Soapi" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Employee_Id" bigint NULL, + "Time" timestamptz NULL, + "Value" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Soapi_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Soapi_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20250908062323.sql b/cmd/main-migration/migrations/20250908062323.sql index cc63543f..f6e757f5 100644 --- a/cmd/main-migration/migrations/20250908062323.sql +++ b/cmd/main-migration/migrations/20250908062323.sql @@ -1,2 +1,2 @@ --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" DROP COLUMN "Assignment_Doctor_Id"; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" DROP COLUMN "Assignment_Doctor_Id"; diff --git a/cmd/main-migration/migrations/20250908073811.sql b/cmd/main-migration/migrations/20250908073811.sql index ead1e965..330ce9a8 100644 --- a/cmd/main-migration/migrations/20250908073811.sql +++ b/cmd/main-migration/migrations/20250908073811.sql @@ -1,2 +1,2 @@ --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" ADD COLUMN "DischargeMethod_Code" character varying(10) NULL; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "DischargeMethod_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20250908073839.sql b/cmd/main-migration/migrations/20250908073839.sql index 43710589..75fb2190 100644 --- a/cmd/main-migration/migrations/20250908073839.sql +++ b/cmd/main-migration/migrations/20250908073839.sql @@ -1,2 +1,2 @@ --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" DROP COLUMN "DischardeMethod_Code"; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" DROP COLUMN "DischardeMethod_Code"; diff --git a/cmd/main-migration/migrations/20250910055902.sql b/cmd/main-migration/migrations/20250910055902.sql index 19583065..0ecfebf0 100644 --- a/cmd/main-migration/migrations/20250910055902.sql +++ b/cmd/main-migration/migrations/20250910055902.sql @@ -1,2 +1,2 @@ --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" ADD COLUMN "Status_Code" character varying(10) NULL; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "Status_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20250915123412.sql b/cmd/main-migration/migrations/20250915123412.sql index 5bb948f0..5fdf5b78 100644 --- a/cmd/main-migration/migrations/20250915123412.sql +++ b/cmd/main-migration/migrations/20250915123412.sql @@ -1,146 +1,146 @@ --- Create "DeviceOrder" table -CREATE TABLE "public"."DeviceOrder" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_DeviceOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "DeviceOrderItem" table -CREATE TABLE "public"."DeviceOrderItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "DeviceOrder_Id" bigint NULL, - "Device_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_DeviceOrderItem_Device" FOREIGN KEY ("Device_Id") REFERENCES "public"."Device" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_DeviceOrderItem_DeviceOrder" FOREIGN KEY ("DeviceOrder_Id") REFERENCES "public"."DeviceOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "MaterialOrder" table -CREATE TABLE "public"."MaterialOrder" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_MaterialOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "MaterialOrderItem" table -CREATE TABLE "public"."MaterialOrderItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "MaterialOrder_Id" bigint NULL, - "Material_Id" bigint NULL, - "Count" integer NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_MaterialOrderItem_Material" FOREIGN KEY ("Material_Id") REFERENCES "public"."Material" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_MaterialOrderItem_MaterialOrder" FOREIGN KEY ("MaterialOrder_Id") REFERENCES "public"."MaterialOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "McuOrder" table -CREATE TABLE "public"."McuOrder" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Status_Code" character varying(10) NOT NULL, - "Doctor_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_McuOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_McuOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "McuOrderItem" table -CREATE TABLE "public"."McuOrderItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "McuOrder_Id" bigint NULL, - "McuSrc_Id" bigint NULL, - "Result" text NULL, - "Status_Code" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_McuOrderItem_McuOrder" FOREIGN KEY ("McuOrder_Id") REFERENCES "public"."McuOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_McuOrderItem_McuSrc" FOREIGN KEY ("McuSrc_Id") REFERENCES "public"."McuSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Medication" table -CREATE TABLE "public"."Medication" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "IssuedAt" timestamptz NULL, - "Pharmacist_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Medication_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Medication_Pharmacist" FOREIGN KEY ("Pharmacist_Id") REFERENCES "public"."Pharmacist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "MedicationItem" table -CREATE TABLE "public"."MedicationItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Medication_Id" bigint NULL, - "IsMix" boolean NULL, - "Medicine_Id" bigint NULL, - "MedicineMix_Id" bigint NULL, - "Usage" smallint NULL, - "Interval" smallint NULL, - "IntervalUnit_Code" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_MedicationItem_Medication" FOREIGN KEY ("Medication_Id") REFERENCES "public"."Medication" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_MedicationItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_MedicationItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "MedicationItemDist" table -CREATE TABLE "public"."MedicationItemDist" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "MedicationItem_Id" bigint NULL, - "DateTime" timestamptz NULL, - "Remain" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_MedicationItemDist_MedicationItem" FOREIGN KEY ("MedicationItem_Id") REFERENCES "public"."MedicationItem" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Prescription" table -CREATE TABLE "public"."Prescription" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Doctor_Id" bigint NULL, - "IssuedAt" timestamptz NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Prescription_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Prescription_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "PrescriptionItem" table -CREATE TABLE "public"."PrescriptionItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Prescription_Id" bigint NULL, - "IsMix" boolean NULL, - "Medicine_Id" bigint NULL, - "MedicineMix_Id" bigint NULL, - "Usage" smallint NULL, - "Interval" smallint NULL, - "IntervalUnit_Code" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_PrescriptionItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_PrescriptionItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_PrescriptionItem_Prescription" FOREIGN KEY ("Prescription_Id") REFERENCES "public"."Prescription" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "DeviceOrder" table +CREATE TABLE "public"."DeviceOrder" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_DeviceOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "DeviceOrderItem" table +CREATE TABLE "public"."DeviceOrderItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "DeviceOrder_Id" bigint NULL, + "Device_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_DeviceOrderItem_Device" FOREIGN KEY ("Device_Id") REFERENCES "public"."Device" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_DeviceOrderItem_DeviceOrder" FOREIGN KEY ("DeviceOrder_Id") REFERENCES "public"."DeviceOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MaterialOrder" table +CREATE TABLE "public"."MaterialOrder" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MaterialOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MaterialOrderItem" table +CREATE TABLE "public"."MaterialOrderItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "MaterialOrder_Id" bigint NULL, + "Material_Id" bigint NULL, + "Count" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MaterialOrderItem_Material" FOREIGN KEY ("Material_Id") REFERENCES "public"."Material" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MaterialOrderItem_MaterialOrder" FOREIGN KEY ("MaterialOrder_Id") REFERENCES "public"."MaterialOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "McuOrder" table +CREATE TABLE "public"."McuOrder" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Status_Code" character varying(10) NOT NULL, + "Doctor_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_McuOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_McuOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "McuOrderItem" table +CREATE TABLE "public"."McuOrderItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "McuOrder_Id" bigint NULL, + "McuSrc_Id" bigint NULL, + "Result" text NULL, + "Status_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_McuOrderItem_McuOrder" FOREIGN KEY ("McuOrder_Id") REFERENCES "public"."McuOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_McuOrderItem_McuSrc" FOREIGN KEY ("McuSrc_Id") REFERENCES "public"."McuSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Medication" table +CREATE TABLE "public"."Medication" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "IssuedAt" timestamptz NULL, + "Pharmacist_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Medication_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Medication_Pharmacist" FOREIGN KEY ("Pharmacist_Id") REFERENCES "public"."Pharmacist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MedicationItem" table +CREATE TABLE "public"."MedicationItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Medication_Id" bigint NULL, + "IsMix" boolean NULL, + "Medicine_Id" bigint NULL, + "MedicineMix_Id" bigint NULL, + "Usage" smallint NULL, + "Interval" smallint NULL, + "IntervalUnit_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MedicationItem_Medication" FOREIGN KEY ("Medication_Id") REFERENCES "public"."Medication" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MedicationItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MedicationItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MedicationItemDist" table +CREATE TABLE "public"."MedicationItemDist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "MedicationItem_Id" bigint NULL, + "DateTime" timestamptz NULL, + "Remain" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MedicationItemDist_MedicationItem" FOREIGN KEY ("MedicationItem_Id") REFERENCES "public"."MedicationItem" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Prescription" table +CREATE TABLE "public"."Prescription" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Doctor_Id" bigint NULL, + "IssuedAt" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Prescription_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Prescription_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "PrescriptionItem" table +CREATE TABLE "public"."PrescriptionItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Prescription_Id" bigint NULL, + "IsMix" boolean NULL, + "Medicine_Id" bigint NULL, + "MedicineMix_Id" bigint NULL, + "Usage" smallint NULL, + "Interval" smallint NULL, + "IntervalUnit_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_PrescriptionItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_PrescriptionItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_PrescriptionItem_Prescription" FOREIGN KEY ("Prescription_Id") REFERENCES "public"."Prescription" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20250916043819.sql b/cmd/main-migration/migrations/20250916043819.sql index 1abe147b..63c18973 100644 --- a/cmd/main-migration/migrations/20250916043819.sql +++ b/cmd/main-migration/migrations/20250916043819.sql @@ -1,14 +1,14 @@ --- Modify "DeviceOrder" table -ALTER TABLE "public"."DeviceOrder" ADD COLUMN "Status_Code" text NULL; --- Modify "DeviceOrderItem" table -ALTER TABLE "public"."DeviceOrderItem" ADD COLUMN "Count" smallint NULL; --- Modify "MaterialOrder" table -ALTER TABLE "public"."MaterialOrder" ADD COLUMN "Status_Code" text NULL; --- Modify "Medication" table -ALTER TABLE "public"."Medication" ADD COLUMN "Status_Code" text NULL; --- Modify "MedicationItem" table -ALTER TABLE "public"."MedicationItem" ALTER COLUMN "Usage" TYPE numeric, ADD COLUMN "IsRedeemed" boolean NULL; --- Modify "PrescriptionItem" table -ALTER TABLE "public"."PrescriptionItem" ALTER COLUMN "Usage" TYPE numeric; --- Modify "MedicationItemDist" table -ALTER TABLE "public"."MedicationItemDist" ALTER COLUMN "Remain" TYPE numeric, ADD COLUMN "Nurse_Id" bigint NULL, ADD CONSTRAINT "fk_MedicationItemDist_Nurse" FOREIGN KEY ("Nurse_Id") REFERENCES "public"."Nurse" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "DeviceOrder" table +ALTER TABLE "public"."DeviceOrder" ADD COLUMN "Status_Code" text NULL; +-- Modify "DeviceOrderItem" table +ALTER TABLE "public"."DeviceOrderItem" ADD COLUMN "Count" smallint NULL; +-- Modify "MaterialOrder" table +ALTER TABLE "public"."MaterialOrder" ADD COLUMN "Status_Code" text NULL; +-- Modify "Medication" table +ALTER TABLE "public"."Medication" ADD COLUMN "Status_Code" text NULL; +-- Modify "MedicationItem" table +ALTER TABLE "public"."MedicationItem" ALTER COLUMN "Usage" TYPE numeric, ADD COLUMN "IsRedeemed" boolean NULL; +-- Modify "PrescriptionItem" table +ALTER TABLE "public"."PrescriptionItem" ALTER COLUMN "Usage" TYPE numeric; +-- Modify "MedicationItemDist" table +ALTER TABLE "public"."MedicationItemDist" ALTER COLUMN "Remain" TYPE numeric, ADD COLUMN "Nurse_Id" bigint NULL, ADD CONSTRAINT "fk_MedicationItemDist_Nurse" FOREIGN KEY ("Nurse_Id") REFERENCES "public"."Nurse" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20250917040616.sql b/cmd/main-migration/migrations/20250917040616.sql index 71fc13e7..3e3ea6d3 100644 --- a/cmd/main-migration/migrations/20250917040616.sql +++ b/cmd/main-migration/migrations/20250917040616.sql @@ -1,8 +1,8 @@ --- Modify "MedicationItem" table -ALTER TABLE "public"."MedicationItem" ADD COLUMN "Quantity" numeric NULL; --- Modify "MedicineMix" table -ALTER TABLE "public"."MedicineMix" ADD COLUMN "Note" text NULL; --- Modify "Prescription" table -ALTER TABLE "public"."Prescription" ADD COLUMN "Status_Code" text NULL; --- Modify "PrescriptionItem" table -ALTER TABLE "public"."PrescriptionItem" ADD COLUMN "Quantity" numeric NULL; +-- Modify "MedicationItem" table +ALTER TABLE "public"."MedicationItem" ADD COLUMN "Quantity" numeric NULL; +-- Modify "MedicineMix" table +ALTER TABLE "public"."MedicineMix" ADD COLUMN "Note" text NULL; +-- Modify "Prescription" table +ALTER TABLE "public"."Prescription" ADD COLUMN "Status_Code" text NULL; +-- Modify "PrescriptionItem" table +ALTER TABLE "public"."PrescriptionItem" ADD COLUMN "Quantity" numeric NULL; diff --git a/cmd/main-migration/migrations/20250917040751.sql b/cmd/main-migration/migrations/20250917040751.sql index 0b8f243b..b78a03a8 100644 --- a/cmd/main-migration/migrations/20250917040751.sql +++ b/cmd/main-migration/migrations/20250917040751.sql @@ -1,2 +1,2 @@ --- Modify "MedicationItem" table -ALTER TABLE "public"."MedicationItem" ADD COLUMN "Note" character varying(1024) NULL; +-- Modify "MedicationItem" table +ALTER TABLE "public"."MedicationItem" ADD COLUMN "Note" character varying(1024) NULL; diff --git a/cmd/main-migration/migrations/20250917045138.sql b/cmd/main-migration/migrations/20250917045138.sql index b40ade76..a572cf95 100644 --- a/cmd/main-migration/migrations/20250917045138.sql +++ b/cmd/main-migration/migrations/20250917045138.sql @@ -1,2 +1,2 @@ --- Modify "MedicineMixItem" table -ALTER TABLE "public"."MedicineMixItem" DROP CONSTRAINT "fk_MedicineMixItem_MedicineMix", ADD CONSTRAINT "fk_MedicineMix_MixItems" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MedicineMixItem" table +ALTER TABLE "public"."MedicineMixItem" DROP CONSTRAINT "fk_MedicineMixItem_MedicineMix", ADD CONSTRAINT "fk_MedicineMix_MixItems" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20250917093645.sql b/cmd/main-migration/migrations/20250917093645.sql index b0922c6a..db4c5e13 100644 --- a/cmd/main-migration/migrations/20250917093645.sql +++ b/cmd/main-migration/migrations/20250917093645.sql @@ -1,4 +1,4 @@ --- Modify "MedicineMix" table -ALTER TABLE "public"."MedicineMix" DROP COLUMN "Note"; --- Modify "MedicineMixItem" table -ALTER TABLE "public"."MedicineMixItem" ADD COLUMN "Note" text NULL; +-- Modify "MedicineMix" table +ALTER TABLE "public"."MedicineMix" DROP COLUMN "Note"; +-- Modify "MedicineMixItem" table +ALTER TABLE "public"."MedicineMixItem" ADD COLUMN "Note" text NULL; diff --git a/cmd/main-migration/migrations/20250918073552.sql b/cmd/main-migration/migrations/20250918073552.sql index 1b45e5d4..cc438c30 100644 --- a/cmd/main-migration/migrations/20250918073552.sql +++ b/cmd/main-migration/migrations/20250918073552.sql @@ -1,10 +1,10 @@ --- Modify "McuOrder" table -ALTER TABLE "public"."McuOrder" ADD COLUMN "SpecimenPickTime" timestamptz NULL, ADD COLUMN "ExaminationDate" timestamptz NULL, ADD COLUMN "Number" smallint NULL, ADD COLUMN "Temperature" numeric NULL, ADD COLUMN "McuUrgencyLevel_Code" character varying(10) NOT NULL; --- Modify "McuOrderItem" table -ALTER TABLE "public"."McuOrderItem" ADD COLUMN "ExaminationDate" timestamptz NULL; --- Create index "idx_order_src" to table: "McuOrderItem" -CREATE UNIQUE INDEX "idx_order_src" ON "public"."McuOrderItem" ("McuOrder_Id", "McuSrc_Id"); --- Modify "PersonRelative" table -ALTER TABLE "public"."PersonRelative" ADD COLUMN "Responsible" boolean NULL; --- Modify "McuSrc" table -ALTER TABLE "public"."McuSrc" ALTER COLUMN "Id" TYPE bigint, ADD COLUMN "Item_Id" bigint NULL, ADD CONSTRAINT "fk_McuSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "McuOrder" table +ALTER TABLE "public"."McuOrder" ADD COLUMN "SpecimenPickTime" timestamptz NULL, ADD COLUMN "ExaminationDate" timestamptz NULL, ADD COLUMN "Number" smallint NULL, ADD COLUMN "Temperature" numeric NULL, ADD COLUMN "McuUrgencyLevel_Code" character varying(10) NOT NULL; +-- Modify "McuOrderItem" table +ALTER TABLE "public"."McuOrderItem" ADD COLUMN "ExaminationDate" timestamptz NULL; +-- Create index "idx_order_src" to table: "McuOrderItem" +CREATE UNIQUE INDEX "idx_order_src" ON "public"."McuOrderItem" ("McuOrder_Id", "McuSrc_Id"); +-- Modify "PersonRelative" table +ALTER TABLE "public"."PersonRelative" ADD COLUMN "Responsible" boolean NULL; +-- Modify "McuSrc" table +ALTER TABLE "public"."McuSrc" ALTER COLUMN "Id" TYPE bigint, ADD COLUMN "Item_Id" bigint NULL, ADD CONSTRAINT "fk_McuSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20250918073742.sql b/cmd/main-migration/migrations/20250918073742.sql index 28611d73..b6559d7e 100644 --- a/cmd/main-migration/migrations/20250918073742.sql +++ b/cmd/main-migration/migrations/20250918073742.sql @@ -1,31 +1,31 @@ --- Create "McuSubSrc" table -CREATE TABLE "public"."McuSubSrc" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "McuSrc_Id" bigint NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_McuSubSrc_Code" UNIQUE ("Code"), - CONSTRAINT "fk_McuSubSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_McuSubSrc_McuSrc" FOREIGN KEY ("McuSrc_Id") REFERENCES "public"."McuSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "McuOrderSubItem" table -CREATE TABLE "public"."McuOrderSubItem" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "McuSubSrc_Id" bigint NULL, - "McuOrderItem_Id" bigint NULL, - "Result" text NULL, - "Status_Code" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_McuOrderSubItem_McuOrderItem" FOREIGN KEY ("McuOrderItem_Id") REFERENCES "public"."McuOrderItem" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_McuOrderSubItem_McuSubSrc" FOREIGN KEY ("McuSubSrc_Id") REFERENCES "public"."McuSubSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create index "idx_order_sub_src" to table: "McuOrderSubItem" -CREATE UNIQUE INDEX "idx_order_sub_src" ON "public"."McuOrderSubItem" ("McuSubSrc_Id", "McuOrderItem_Id"); +-- Create "McuSubSrc" table +CREATE TABLE "public"."McuSubSrc" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "McuSrc_Id" bigint NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_McuSubSrc_Code" UNIQUE ("Code"), + CONSTRAINT "fk_McuSubSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_McuSubSrc_McuSrc" FOREIGN KEY ("McuSrc_Id") REFERENCES "public"."McuSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "McuOrderSubItem" table +CREATE TABLE "public"."McuOrderSubItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "McuSubSrc_Id" bigint NULL, + "McuOrderItem_Id" bigint NULL, + "Result" text NULL, + "Status_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_McuOrderSubItem_McuOrderItem" FOREIGN KEY ("McuOrderItem_Id") REFERENCES "public"."McuOrderItem" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_McuOrderSubItem_McuSubSrc" FOREIGN KEY ("McuSubSrc_Id") REFERENCES "public"."McuSubSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create index "idx_order_sub_src" to table: "McuOrderSubItem" +CREATE UNIQUE INDEX "idx_order_sub_src" ON "public"."McuOrderSubItem" ("McuSubSrc_Id", "McuOrderItem_Id"); diff --git a/cmd/main-migration/migrations/20250918074745.sql b/cmd/main-migration/migrations/20250918074745.sql index 365227cb..edf84f66 100644 --- a/cmd/main-migration/migrations/20250918074745.sql +++ b/cmd/main-migration/migrations/20250918074745.sql @@ -1,2 +1,2 @@ --- Modify "McuOrder" table -ALTER TABLE "public"."McuOrder" ALTER COLUMN "McuUrgencyLevel_Code" TYPE character varying(15); +-- Modify "McuOrder" table +ALTER TABLE "public"."McuOrder" ALTER COLUMN "McuUrgencyLevel_Code" TYPE character varying(15); diff --git a/cmd/main-migration/migrations/20250923025134.sql b/cmd/main-migration/migrations/20250923025134.sql index 57a04744..e0665b1c 100644 --- a/cmd/main-migration/migrations/20250923025134.sql +++ b/cmd/main-migration/migrations/20250923025134.sql @@ -1,17 +1,17 @@ --- Create "Consultation" table -CREATE TABLE "public"."Consultation" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Case" character varying(2048) NULL, - "Solution" character varying(2048) NULL, - "Unit_Id" bigint NULL, - "Doctor_Id" bigint NULL, - "RepliedAt" timestamptz NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Consultation_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Consultation_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Consultation_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "Consultation" table +CREATE TABLE "public"."Consultation" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Case" character varying(2048) NULL, + "Solution" character varying(2048) NULL, + "Unit_Id" bigint NULL, + "Doctor_Id" bigint NULL, + "RepliedAt" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Consultation_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Consultation_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Consultation_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20250924051317.sql b/cmd/main-migration/migrations/20250924051317.sql index f0f58947..1ebb0438 100644 --- a/cmd/main-migration/migrations/20250924051317.sql +++ b/cmd/main-migration/migrations/20250924051317.sql @@ -1,2 +1,2 @@ --- Modify "Person" table -ALTER TABLE "public"."Person" ADD COLUMN "ResidentIdentityFileUrl" character varying(1024) NULL, ADD COLUMN "PassportFileUrl" character varying(1024) NULL, ADD COLUMN "DrivingLicenseFileUrl" character varying(1024) NULL, ADD COLUMN "FamilyIdentityFileUrl" character varying(1024) NULL; +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD COLUMN "ResidentIdentityFileUrl" character varying(1024) NULL, ADD COLUMN "PassportFileUrl" character varying(1024) NULL, ADD COLUMN "DrivingLicenseFileUrl" character varying(1024) NULL, ADD COLUMN "FamilyIdentityFileUrl" character varying(1024) NULL; diff --git a/cmd/main-migration/migrations/20250929034321.sql b/cmd/main-migration/migrations/20250929034321.sql index bfdc5021..8c47f9c4 100644 --- a/cmd/main-migration/migrations/20250929034321.sql +++ b/cmd/main-migration/migrations/20250929034321.sql @@ -1,2 +1,2 @@ --- Modify "Soapi" table -ALTER TABLE "public"."Soapi" ADD COLUMN "TypeCode" text NULL; +-- Modify "Soapi" table +ALTER TABLE "public"."Soapi" ADD COLUMN "TypeCode" text NULL; diff --git a/cmd/main-migration/migrations/20250929034428.sql b/cmd/main-migration/migrations/20250929034428.sql index 84a214a5..9b7b69ea 100644 --- a/cmd/main-migration/migrations/20250929034428.sql +++ b/cmd/main-migration/migrations/20250929034428.sql @@ -1,2 +1,2 @@ --- Modify "Soapi" table -ALTER TABLE "public"."Soapi" ALTER COLUMN "TypeCode" TYPE character varying(11); +-- Modify "Soapi" table +ALTER TABLE "public"."Soapi" ALTER COLUMN "TypeCode" TYPE character varying(11); diff --git a/cmd/main-migration/migrations/20250930025550.sql b/cmd/main-migration/migrations/20250930025550.sql index cb24b7fc..f3902808 100644 --- a/cmd/main-migration/migrations/20250930025550.sql +++ b/cmd/main-migration/migrations/20250930025550.sql @@ -1,6 +1,6 @@ --- Modify "MedicationItem" table -ALTER TABLE "public"."MedicationItem" ALTER COLUMN "Usage" TYPE character varying(255), ADD COLUMN "Frequency" integer NULL, ADD COLUMN "Dose" numeric NULL; --- Modify "PrescriptionItem" table -ALTER TABLE "public"."PrescriptionItem" ALTER COLUMN "Usage" TYPE character varying(255), ADD COLUMN "Frequency" integer NULL, ADD COLUMN "Dose" numeric NULL; --- Modify "MedicineMix" table -ALTER TABLE "public"."MedicineMix" ADD COLUMN "Uom_Code" character varying(10) NULL, ADD CONSTRAINT "fk_MedicineMix_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MedicationItem" table +ALTER TABLE "public"."MedicationItem" ALTER COLUMN "Usage" TYPE character varying(255), ADD COLUMN "Frequency" integer NULL, ADD COLUMN "Dose" numeric NULL; +-- Modify "PrescriptionItem" table +ALTER TABLE "public"."PrescriptionItem" ALTER COLUMN "Usage" TYPE character varying(255), ADD COLUMN "Frequency" integer NULL, ADD COLUMN "Dose" numeric NULL; +-- Modify "MedicineMix" table +ALTER TABLE "public"."MedicineMix" ADD COLUMN "Uom_Code" character varying(10) NULL, ADD CONSTRAINT "fk_MedicineMix_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20250930140351.sql b/cmd/main-migration/migrations/20250930140351.sql index c98fd12a..6c226a81 100644 --- a/cmd/main-migration/migrations/20250930140351.sql +++ b/cmd/main-migration/migrations/20250930140351.sql @@ -1,4 +1,4 @@ --- Rename a column from "CheckupCategory_Code" to "McuSrcCategory_Code" -ALTER TABLE "public"."McuSrc" RENAME COLUMN "CheckupCategory_Code" TO "McuSrcCategory_Code"; --- Modify "McuSrc" table -ALTER TABLE "public"."McuSrc" DROP CONSTRAINT "fk_McuSrc_CheckupCategory", ADD CONSTRAINT "fk_McuSrc_McuSrcCategory" FOREIGN KEY ("McuSrcCategory_Code") REFERENCES "public"."McuSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Rename a column from "CheckupCategory_Code" to "McuSrcCategory_Code" +ALTER TABLE "public"."McuSrc" RENAME COLUMN "CheckupCategory_Code" TO "McuSrcCategory_Code"; +-- Modify "McuSrc" table +ALTER TABLE "public"."McuSrc" DROP CONSTRAINT "fk_McuSrc_CheckupCategory", ADD CONSTRAINT "fk_McuSrc_McuSrcCategory" FOREIGN KEY ("McuSrcCategory_Code") REFERENCES "public"."McuSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251002085604.sql b/cmd/main-migration/migrations/20251002085604.sql index e215cd13..62302ec6 100644 --- a/cmd/main-migration/migrations/20251002085604.sql +++ b/cmd/main-migration/migrations/20251002085604.sql @@ -1,2 +1,2 @@ --- Modify "Division" table -ALTER TABLE "public"."Division" ALTER COLUMN "Parent_Id" TYPE integer, ADD CONSTRAINT "fk_Division_Childrens" FOREIGN KEY ("Parent_Id") REFERENCES "public"."Division" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Division" table +ALTER TABLE "public"."Division" ALTER COLUMN "Parent_Id" TYPE integer, ADD CONSTRAINT "fk_Division_Childrens" FOREIGN KEY ("Parent_Id") REFERENCES "public"."Division" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251003032030.sql b/cmd/main-migration/migrations/20251003032030.sql index 2bdf73ba..210b76ac 100644 --- a/cmd/main-migration/migrations/20251003032030.sql +++ b/cmd/main-migration/migrations/20251003032030.sql @@ -1,6 +1,6 @@ --- Modify "Infra" table -ALTER TABLE "public"."Infra" ADD CONSTRAINT "fk_Infra_Childrens" FOREIGN KEY ("Parent_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "DeviceOrder" table -ALTER TABLE "public"."DeviceOrder" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_DeviceOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "MaterialOrder" table -ALTER TABLE "public"."MaterialOrder" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_MaterialOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ADD CONSTRAINT "fk_Infra_Childrens" FOREIGN KEY ("Parent_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "DeviceOrder" table +ALTER TABLE "public"."DeviceOrder" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_DeviceOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MaterialOrder" table +ALTER TABLE "public"."MaterialOrder" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_MaterialOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251005060450.sql b/cmd/main-migration/migrations/20251005060450.sql index 7ec05f92..652117a4 100644 --- a/cmd/main-migration/migrations/20251005060450.sql +++ b/cmd/main-migration/migrations/20251005060450.sql @@ -1,24 +1,24 @@ --- Modify "Person" table -ALTER TABLE "public"."Person" ADD COLUMN "Nationality" text NULL; --- Create "Chemo" table -CREATE TABLE "public"."Chemo" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Status_Code" text NULL, - "VerifiedAt" timestamptz NULL, - "VerifiedBy_User_Id" bigint NULL, - "SrcUnit_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Chemo_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Chemo_SrcUnit" FOREIGN KEY ("SrcUnit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Chemo_VerifiedBy" FOREIGN KEY ("VerifiedBy_User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Rename a column from "Unit_Id" to "DstUnit_Id" -ALTER TABLE "public"."Consultation" RENAME COLUMN "Unit_Id" TO "DstUnit_Id"; --- Rename a column from "Doctor_Id" to "DstDoctor_Id" -ALTER TABLE "public"."Consultation" RENAME COLUMN "Doctor_Id" TO "DstDoctor_Id"; --- Modify "Consultation" table -ALTER TABLE "public"."Consultation" DROP CONSTRAINT "fk_Consultation_Doctor", DROP CONSTRAINT "fk_Consultation_Unit", DROP COLUMN "Case", ALTER COLUMN "Solution" TYPE character varying(10240), ADD COLUMN "Date" timestamptz NULL, ADD COLUMN "Problem" character varying(10240) NULL, ADD CONSTRAINT "fk_Consultation_DstDoctor" FOREIGN KEY ("DstDoctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Consultation_DstUnit" FOREIGN KEY ("DstUnit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD COLUMN "Nationality" text NULL; +-- Create "Chemo" table +CREATE TABLE "public"."Chemo" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Status_Code" text NULL, + "VerifiedAt" timestamptz NULL, + "VerifiedBy_User_Id" bigint NULL, + "SrcUnit_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Chemo_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Chemo_SrcUnit" FOREIGN KEY ("SrcUnit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Chemo_VerifiedBy" FOREIGN KEY ("VerifiedBy_User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Rename a column from "Unit_Id" to "DstUnit_Id" +ALTER TABLE "public"."Consultation" RENAME COLUMN "Unit_Id" TO "DstUnit_Id"; +-- Rename a column from "Doctor_Id" to "DstDoctor_Id" +ALTER TABLE "public"."Consultation" RENAME COLUMN "Doctor_Id" TO "DstDoctor_Id"; +-- Modify "Consultation" table +ALTER TABLE "public"."Consultation" DROP CONSTRAINT "fk_Consultation_Doctor", DROP CONSTRAINT "fk_Consultation_Unit", DROP COLUMN "Case", ALTER COLUMN "Solution" TYPE character varying(10240), ADD COLUMN "Date" timestamptz NULL, ADD COLUMN "Problem" character varying(10240) NULL, ADD CONSTRAINT "fk_Consultation_DstDoctor" FOREIGN KEY ("DstDoctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Consultation_DstUnit" FOREIGN KEY ("DstUnit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251006041122.sql b/cmd/main-migration/migrations/20251006041122.sql index 24ace4a9..e63133eb 100644 --- a/cmd/main-migration/migrations/20251006041122.sql +++ b/cmd/main-migration/migrations/20251006041122.sql @@ -1,2 +1,2 @@ --- Modify "DivisionPosition" table -ALTER TABLE "public"."DivisionPosition" ADD COLUMN "Employee_Id" bigint NULL, ADD CONSTRAINT "fk_DivisionPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "DivisionPosition" table +ALTER TABLE "public"."DivisionPosition" ADD COLUMN "Employee_Id" bigint NULL, ADD CONSTRAINT "fk_DivisionPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251006045658.sql b/cmd/main-migration/migrations/20251006045658.sql index a8c3a4d7..e14e6231 100644 --- a/cmd/main-migration/migrations/20251006045658.sql +++ b/cmd/main-migration/migrations/20251006045658.sql @@ -1,2 +1,2 @@ --- Modify "Person" table -ALTER TABLE "public"."Person" ADD COLUMN "CommunicationIssueStatus" boolean NULL, ADD COLUMN "Disabillity" character varying(100) NULL; +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD COLUMN "CommunicationIssueStatus" boolean NULL, ADD COLUMN "Disabillity" character varying(100) NULL; diff --git a/cmd/main-migration/migrations/20251006045928.sql b/cmd/main-migration/migrations/20251006045928.sql index f495a26d..22fabb45 100644 --- a/cmd/main-migration/migrations/20251006045928.sql +++ b/cmd/main-migration/migrations/20251006045928.sql @@ -1,2 +1,2 @@ --- Rename a column from "Disabillity" to "Disability" -ALTER TABLE "public"."Person" RENAME COLUMN "Disabillity" TO "Disability"; +-- Rename a column from "Disabillity" to "Disability" +ALTER TABLE "public"."Person" RENAME COLUMN "Disabillity" TO "Disability"; diff --git a/cmd/main-migration/migrations/20251007022859.sql b/cmd/main-migration/migrations/20251007022859.sql index 03b0890b..4fd21d6c 100644 --- a/cmd/main-migration/migrations/20251007022859.sql +++ b/cmd/main-migration/migrations/20251007022859.sql @@ -1,2 +1,2 @@ --- Modify "Patient" table -ALTER TABLE "public"."Patient" ADD COLUMN "NewBornStatus" boolean NULL; +-- Modify "Patient" table +ALTER TABLE "public"."Patient" ADD COLUMN "NewBornStatus" boolean NULL; diff --git a/cmd/main-migration/migrations/20251008031337.sql b/cmd/main-migration/migrations/20251008031337.sql index fd2aff8a..a28ad527 100644 --- a/cmd/main-migration/migrations/20251008031337.sql +++ b/cmd/main-migration/migrations/20251008031337.sql @@ -1,2 +1,2 @@ --- Modify "PersonAddress" table -ALTER TABLE "public"."PersonAddress" ADD COLUMN "PostalCode" character varying(6) NULL; +-- Modify "PersonAddress" table +ALTER TABLE "public"."PersonAddress" ADD COLUMN "PostalCode" character varying(6) NULL; diff --git a/cmd/main-migration/migrations/20251008031554.sql b/cmd/main-migration/migrations/20251008031554.sql index 58cee318..6327ebfb 100644 --- a/cmd/main-migration/migrations/20251008031554.sql +++ b/cmd/main-migration/migrations/20251008031554.sql @@ -1,12 +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 -); +-- 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 +); diff --git a/cmd/main-migration/migrations/20251008052346.sql b/cmd/main-migration/migrations/20251008052346.sql index d664f92d..d726c20e 100644 --- a/cmd/main-migration/migrations/20251008052346.sql +++ b/cmd/main-migration/migrations/20251008052346.sql @@ -1,2 +1,2 @@ --- Modify "DivisionPosition" table -ALTER TABLE "public"."DivisionPosition" ADD COLUMN "HeadStatus" boolean NULL; +-- Modify "DivisionPosition" table +ALTER TABLE "public"."DivisionPosition" ADD COLUMN "HeadStatus" boolean NULL; diff --git a/cmd/main-migration/migrations/20251008073620.sql b/cmd/main-migration/migrations/20251008073620.sql index f3d9cf60..06f86561 100644 --- a/cmd/main-migration/migrations/20251008073620.sql +++ b/cmd/main-migration/migrations/20251008073620.sql @@ -1,2 +1,2 @@ --- Modify "Infra" table -ALTER TABLE "public"."Infra" ALTER COLUMN "InfraGroup_Code" TYPE character varying(15); +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ALTER COLUMN "InfraGroup_Code" TYPE character varying(15); diff --git a/cmd/main-migration/migrations/20251009042854.sql b/cmd/main-migration/migrations/20251009042854.sql index c8b5ec23..e38c46d6 100644 --- a/cmd/main-migration/migrations/20251009042854.sql +++ b/cmd/main-migration/migrations/20251009042854.sql @@ -1,9 +1,9 @@ --- Create "PostalCode" table -CREATE TABLE "public"."PostalCode" ( - "Id" bigserial NOT NULL, - "Code" character varying(5) NULL, - "Village_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_PostalCode_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Village_PostalCodes" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "PostalCode" table +CREATE TABLE "public"."PostalCode" ( + "Id" bigserial NOT NULL, + "Code" character varying(5) NULL, + "Village_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_PostalCode_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Village_PostalCodes" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251009052657.sql b/cmd/main-migration/migrations/20251009052657.sql index 5655a577..af68a0e4 100644 --- a/cmd/main-migration/migrations/20251009052657.sql +++ b/cmd/main-migration/migrations/20251009052657.sql @@ -1,8 +1,8 @@ --- Modify "Regency" table -ALTER TABLE "public"."Regency" DROP CONSTRAINT "fk_Province_Regencies", ALTER COLUMN "Id" TYPE bigint, ADD CONSTRAINT "fk_Regency_Province" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "District" table -ALTER TABLE "public"."District" DROP CONSTRAINT "fk_Regency_Districts", ADD CONSTRAINT "fk_District_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "Village" table -ALTER TABLE "public"."Village" DROP CONSTRAINT "fk_District_Villages", ADD CONSTRAINT "fk_Village_District" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "PostalCode" table -ALTER TABLE "public"."PostalCode" DROP CONSTRAINT "fk_Village_PostalCodes", ADD CONSTRAINT "fk_PostalCode_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Regency" table +ALTER TABLE "public"."Regency" DROP CONSTRAINT "fk_Province_Regencies", ALTER COLUMN "Id" TYPE bigint, ADD CONSTRAINT "fk_Regency_Province" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "District" table +ALTER TABLE "public"."District" DROP CONSTRAINT "fk_Regency_Districts", ADD CONSTRAINT "fk_District_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Village" table +ALTER TABLE "public"."Village" DROP CONSTRAINT "fk_District_Villages", ADD CONSTRAINT "fk_Village_District" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "PostalCode" table +ALTER TABLE "public"."PostalCode" DROP CONSTRAINT "fk_Village_PostalCodes", ADD CONSTRAINT "fk_PostalCode_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251010031743.sql b/cmd/main-migration/migrations/20251010031743.sql index 1dea016a..0fb84b12 100644 --- a/cmd/main-migration/migrations/20251010031743.sql +++ b/cmd/main-migration/migrations/20251010031743.sql @@ -1,6 +1,6 @@ --- Modify "Person" table -ALTER TABLE "public"."Person" ADD CONSTRAINT "fk_Person_BirthRegency" FOREIGN KEY ("BirthRegency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Rename a column from "PostalCode" to "PostalCode_Code" -ALTER TABLE "public"."PersonAddress" RENAME COLUMN "PostalCode" TO "PostalCode_Code"; --- Modify "PersonAddress" table -ALTER TABLE "public"."PersonAddress" ADD CONSTRAINT "fk_PersonAddress_PostalCode" FOREIGN KEY ("PostalCode_Code") REFERENCES "public"."PostalCode" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD CONSTRAINT "fk_Person_BirthRegency" FOREIGN KEY ("BirthRegency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Rename a column from "PostalCode" to "PostalCode_Code" +ALTER TABLE "public"."PersonAddress" RENAME COLUMN "PostalCode" TO "PostalCode_Code"; +-- Modify "PersonAddress" table +ALTER TABLE "public"."PersonAddress" ADD CONSTRAINT "fk_PersonAddress_PostalCode" FOREIGN KEY ("PostalCode_Code") REFERENCES "public"."PostalCode" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251010070721.sql b/cmd/main-migration/migrations/20251010070721.sql index ee030931..fe65c513 100644 --- a/cmd/main-migration/migrations/20251010070721.sql +++ b/cmd/main-migration/migrations/20251010070721.sql @@ -1,15 +1,15 @@ --- Create "PostalRegion" table -CREATE TABLE "public"."PostalRegion" ( - "Id" bigserial NOT NULL, - "Village_Code" character varying(10) NULL, - "Code" character varying(5) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_PostalRegion_Code" UNIQUE ("Code"), - CONSTRAINT "fk_PostalRegion_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Rename a column from "PostalCode_Code" to "PostalRegion_Code" -ALTER TABLE "public"."PersonAddress" RENAME COLUMN "PostalCode_Code" TO "PostalRegion_Code"; --- Modify "PersonAddress" table -ALTER TABLE "public"."PersonAddress" DROP CONSTRAINT "fk_PersonAddress_PostalCode", ADD COLUMN "LocationType_Code" character varying(10) NULL, ADD CONSTRAINT "fk_PersonAddress_PostalRegion" FOREIGN KEY ("PostalRegion_Code") REFERENCES "public"."PostalRegion" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Drop "PostalCode" table -DROP TABLE "public"."PostalCode"; +-- Create "PostalRegion" table +CREATE TABLE "public"."PostalRegion" ( + "Id" bigserial NOT NULL, + "Village_Code" character varying(10) NULL, + "Code" character varying(5) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_PostalRegion_Code" UNIQUE ("Code"), + CONSTRAINT "fk_PostalRegion_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Rename a column from "PostalCode_Code" to "PostalRegion_Code" +ALTER TABLE "public"."PersonAddress" RENAME COLUMN "PostalCode_Code" TO "PostalRegion_Code"; +-- Modify "PersonAddress" table +ALTER TABLE "public"."PersonAddress" DROP CONSTRAINT "fk_PersonAddress_PostalCode", ADD COLUMN "LocationType_Code" character varying(10) NULL, ADD CONSTRAINT "fk_PersonAddress_PostalRegion" FOREIGN KEY ("PostalRegion_Code") REFERENCES "public"."PostalRegion" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Drop "PostalCode" table +DROP TABLE "public"."PostalCode"; diff --git a/cmd/main-migration/migrations/20251010072711.sql b/cmd/main-migration/migrations/20251010072711.sql index f4b24a4f..b57a06de 100644 --- a/cmd/main-migration/migrations/20251010072711.sql +++ b/cmd/main-migration/migrations/20251010072711.sql @@ -1,2 +1,2 @@ --- Modify "PersonAddress" table -ALTER TABLE "public"."PersonAddress" ADD CONSTRAINT "fk_PersonAddress_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "PersonAddress" table +ALTER TABLE "public"."PersonAddress" ADD CONSTRAINT "fk_PersonAddress_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251013044536.sql b/cmd/main-migration/migrations/20251013044536.sql index 84bdf0b0..175487d1 100644 --- a/cmd/main-migration/migrations/20251013044536.sql +++ b/cmd/main-migration/migrations/20251013044536.sql @@ -1,14 +1,14 @@ --- Create "CheckoutPolies" table -CREATE TABLE "public"."CheckoutPolies" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Unit_Id" integer NULL, - "Doctor_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_CheckoutPolies_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_CheckoutPolies_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_CheckoutPolies_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "CheckoutPolies" table +CREATE TABLE "public"."CheckoutPolies" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Unit_Id" integer NULL, + "Doctor_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_CheckoutPolies_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_CheckoutPolies_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_CheckoutPolies_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251013051438.sql b/cmd/main-migration/migrations/20251013051438.sql index 791f3384..8a1ee2d4 100644 --- a/cmd/main-migration/migrations/20251013051438.sql +++ b/cmd/main-migration/migrations/20251013051438.sql @@ -1,2 +1,2 @@ --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" ALTER COLUMN "DischargeMethod_Code" TYPE character varying(16); +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ALTER COLUMN "DischargeMethod_Code" TYPE character varying(16); diff --git a/cmd/main-migration/migrations/20251013081808.sql b/cmd/main-migration/migrations/20251013081808.sql index 03bf02ce..871c8aba 100644 --- a/cmd/main-migration/migrations/20251013081808.sql +++ b/cmd/main-migration/migrations/20251013081808.sql @@ -1,16 +1,16 @@ --- Create "InternalReference" table -CREATE TABLE "public"."InternalReference" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Unit_Id" integer NULL, - "Doctor_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_InternalReference_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_InternalReference_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_InternalReference_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Drop "CheckoutPolies" table -DROP TABLE "public"."CheckoutPolies"; +-- Create "InternalReference" table +CREATE TABLE "public"."InternalReference" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Unit_Id" integer NULL, + "Doctor_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_InternalReference_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_InternalReference_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_InternalReference_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Drop "CheckoutPolies" table +DROP TABLE "public"."CheckoutPolies"; diff --git a/cmd/main-migration/migrations/20251014060047.sql b/cmd/main-migration/migrations/20251014060047.sql index 1d13853a..4503f7c8 100644 --- a/cmd/main-migration/migrations/20251014060047.sql +++ b/cmd/main-migration/migrations/20251014060047.sql @@ -1,36 +1,36 @@ --- Create "VClaimSepHist" table -CREATE TABLE "public"."VClaimSepHist" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "RequestPayload" text NULL, - "ResponseBody" text NULL, - "Message" text NULL, - PRIMARY KEY ("Id") -); --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" ADD COLUMN "PaymentMethod_Code" character varying(10) NULL, ADD COLUMN "InsuranceCompany_Id" bigint NULL, ADD COLUMN "Member_Number" character varying(20) NULL, ADD COLUMN "Ref_Number" character varying(20) NULL, ADD COLUMN "Trx_Number" character varying(20) NULL, ADD COLUMN "Adm_Employee_Id" bigint NULL, ADD CONSTRAINT "uni_Encounter_Member_Number" UNIQUE ("Member_Number"), ADD CONSTRAINT "uni_Encounter_Ref_Number" UNIQUE ("Ref_Number"), ADD CONSTRAINT "uni_Encounter_Trx_Number" UNIQUE ("Trx_Number"), ADD CONSTRAINT "fk_Encounter_Adm_Employee" FOREIGN KEY ("Adm_Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Id") REFERENCES "public"."InsuranceCompany" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Create "VClaimSep" table -CREATE TABLE "public"."VClaimSep" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Number" character varying(19) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_VClaimSep_Number" UNIQUE ("Number"), - CONSTRAINT "fk_Encounter_VclaimSep" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "VClaimSepPrint" table -CREATE TABLE "public"."VClaimSepPrint" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "VclaimSep_Number" character varying(19) NULL, - "Counter" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_VClaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VClaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "VClaimSepHist" table +CREATE TABLE "public"."VClaimSepHist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "RequestPayload" text NULL, + "ResponseBody" text NULL, + "Message" text NULL, + PRIMARY KEY ("Id") +); +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "PaymentMethod_Code" character varying(10) NULL, ADD COLUMN "InsuranceCompany_Id" bigint NULL, ADD COLUMN "Member_Number" character varying(20) NULL, ADD COLUMN "Ref_Number" character varying(20) NULL, ADD COLUMN "Trx_Number" character varying(20) NULL, ADD COLUMN "Adm_Employee_Id" bigint NULL, ADD CONSTRAINT "uni_Encounter_Member_Number" UNIQUE ("Member_Number"), ADD CONSTRAINT "uni_Encounter_Ref_Number" UNIQUE ("Ref_Number"), ADD CONSTRAINT "uni_Encounter_Trx_Number" UNIQUE ("Trx_Number"), ADD CONSTRAINT "fk_Encounter_Adm_Employee" FOREIGN KEY ("Adm_Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Id") REFERENCES "public"."InsuranceCompany" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Create "VClaimSep" table +CREATE TABLE "public"."VClaimSep" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Number" character varying(19) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_VClaimSep_Number" UNIQUE ("Number"), + CONSTRAINT "fk_Encounter_VclaimSep" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "VClaimSepPrint" table +CREATE TABLE "public"."VClaimSepPrint" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "VclaimSep_Number" character varying(19) NULL, + "Counter" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_VClaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VClaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251014063537.sql b/cmd/main-migration/migrations/20251014063537.sql index 7b77b3d9..4186478d 100644 --- a/cmd/main-migration/migrations/20251014063537.sql +++ b/cmd/main-migration/migrations/20251014063537.sql @@ -1,16 +1,16 @@ --- Create "VclaimSep" table -CREATE TABLE "public"."VclaimSep" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Number" character varying(19) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_VclaimSep_Number" UNIQUE ("Number"), - CONSTRAINT "fk_Encounter_VclaimSep" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Modify "VClaimSepPrint" table -ALTER TABLE "public"."VClaimSepPrint" DROP CONSTRAINT "fk_VClaimSepPrint_VclaimSep", ADD CONSTRAINT "fk_VClaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VclaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Drop "VClaimSep" table -DROP TABLE "public"."VClaimSep"; +-- Create "VclaimSep" table +CREATE TABLE "public"."VclaimSep" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Number" character varying(19) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_VclaimSep_Number" UNIQUE ("Number"), + CONSTRAINT "fk_Encounter_VclaimSep" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Modify "VClaimSepPrint" table +ALTER TABLE "public"."VClaimSepPrint" DROP CONSTRAINT "fk_VClaimSepPrint_VclaimSep", ADD CONSTRAINT "fk_VClaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VclaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Drop "VClaimSep" table +DROP TABLE "public"."VClaimSep"; diff --git a/cmd/main-migration/migrations/20251014063720.sql b/cmd/main-migration/migrations/20251014063720.sql index 0763c12b..4512cb5e 100644 --- a/cmd/main-migration/migrations/20251014063720.sql +++ b/cmd/main-migration/migrations/20251014063720.sql @@ -1,26 +1,26 @@ --- Create "VclaimSepHist" table -CREATE TABLE "public"."VclaimSepHist" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "RequestPayload" text NULL, - "ResponseBody" text NULL, - "Message" text NULL, - PRIMARY KEY ("Id") -); --- Create "VclaimSepPrint" table -CREATE TABLE "public"."VclaimSepPrint" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "VclaimSep_Number" character varying(19) NULL, - "Counter" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_VclaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VclaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Drop "VClaimSepHist" table -DROP TABLE "public"."VClaimSepHist"; --- Drop "VClaimSepPrint" table -DROP TABLE "public"."VClaimSepPrint"; +-- Create "VclaimSepHist" table +CREATE TABLE "public"."VclaimSepHist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "RequestPayload" text NULL, + "ResponseBody" text NULL, + "Message" text NULL, + PRIMARY KEY ("Id") +); +-- Create "VclaimSepPrint" table +CREATE TABLE "public"."VclaimSepPrint" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "VclaimSep_Number" character varying(19) NULL, + "Counter" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_VclaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VclaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Drop "VClaimSepHist" table +DROP TABLE "public"."VClaimSepHist"; +-- Drop "VClaimSepPrint" table +DROP TABLE "public"."VClaimSepPrint"; diff --git a/cmd/main-migration/migrations/20251015045455.sql b/cmd/main-migration/migrations/20251015045455.sql index f2b6be7a..ed3ccede 100644 --- a/cmd/main-migration/migrations/20251015045455.sql +++ b/cmd/main-migration/migrations/20251015045455.sql @@ -1,2 +1,2 @@ --- Modify "Chemo" table -ALTER TABLE "public"."Chemo" ADD COLUMN "ClassCode" text NULL; +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" ADD COLUMN "ClassCode" text NULL; diff --git a/cmd/main-migration/migrations/20251016010845.sql b/cmd/main-migration/migrations/20251016010845.sql index edbbb414..6463b8ef 100644 --- a/cmd/main-migration/migrations/20251016010845.sql +++ b/cmd/main-migration/migrations/20251016010845.sql @@ -1,2 +1,2 @@ --- Rename a column from "ClassCode" to "Class_Code" -ALTER TABLE "public"."Chemo" RENAME COLUMN "ClassCode" TO "Class_Code"; +-- Rename a column from "ClassCode" to "Class_Code" +ALTER TABLE "public"."Chemo" RENAME COLUMN "ClassCode" TO "Class_Code"; diff --git a/cmd/main-migration/migrations/20251016011023.sql b/cmd/main-migration/migrations/20251016011023.sql index 12e51e7d..945037f7 100644 --- a/cmd/main-migration/migrations/20251016011023.sql +++ b/cmd/main-migration/migrations/20251016011023.sql @@ -1,17 +1,17 @@ --- Create "PersonInsurance" table -CREATE TABLE "public"."PersonInsurance" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Person_Id" bigint NULL, - "InsuranceCompany_Id" bigint NULL, - "Ref_Number" character varying(20) NULL, - "DefaultStatus" boolean NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_PersonInsurance_Ref_Number" UNIQUE ("Ref_Number"), - CONSTRAINT "fk_PersonInsurance_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Id") REFERENCES "public"."InsuranceCompany" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Person_Insurances" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create index "idx_person_insurance" to table: "PersonInsurance" -CREATE UNIQUE INDEX "idx_person_insurance" ON "public"."PersonInsurance" ("Person_Id", "DefaultStatus"); +-- Create "PersonInsurance" table +CREATE TABLE "public"."PersonInsurance" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "InsuranceCompany_Id" bigint NULL, + "Ref_Number" character varying(20) NULL, + "DefaultStatus" boolean NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_PersonInsurance_Ref_Number" UNIQUE ("Ref_Number"), + CONSTRAINT "fk_PersonInsurance_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Id") REFERENCES "public"."InsuranceCompany" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Person_Insurances" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create index "idx_person_insurance" to table: "PersonInsurance" +CREATE UNIQUE INDEX "idx_person_insurance" ON "public"."PersonInsurance" ("Person_Id", "DefaultStatus"); diff --git a/cmd/main-migration/migrations/20251016062912.sql b/cmd/main-migration/migrations/20251016062912.sql index b9208471..f5fd01cb 100644 --- a/cmd/main-migration/migrations/20251016062912.sql +++ b/cmd/main-migration/migrations/20251016062912.sql @@ -1,54 +1,54 @@ --- Create "AmbulanceTransportReq" table -CREATE TABLE "public"."AmbulanceTransportReq" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Patient_Id" bigint NULL, - "Diagnoses" character varying(1024) NULL, - "RequestData" timestamptz NULL, - "UsageDate" timestamptz NULL, - "Address" character varying(100) NULL, - "RtRw" character varying(10) NULL, - "Province_Code" character varying(2) NULL, - "Regency_Code" character varying(4) NULL, - "District_Code" character varying(6) NULL, - "Village_Code" character varying(10) NULL, - "Facility_Code" character varying(10) NULL, - "Needs_Code" character varying(10) NULL, - "Contact_Name" character varying(100) NULL, - "Contact_Relationship_Code" character varying(10) NULL, - "Contact_PhoneNumber" character varying(20) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_AmbulanceTransportReq_District" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_AmbulanceTransportReq_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_AmbulanceTransportReq_Province" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_AmbulanceTransportReq_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_AmbulanceTransportReq_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "Vehicle" table -CREATE TABLE "public"."Vehicle" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Type_Code" text NULL, - "PoliceNumber" text NULL, - "FrameNumber" text NULL, - "RegNumber" text NULL, - "AvailableStatus" boolean NULL, - PRIMARY KEY ("Id") -); --- Create "VehicleHist" table -CREATE TABLE "public"."VehicleHist" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Vehicle_Id" bigint NULL, - "Date" timestamptz NULL, - "Data" text NULL, - "Crud_Code" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_VehicleHist_Vehicle" FOREIGN KEY ("Vehicle_Id") REFERENCES "public"."Vehicle" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "AmbulanceTransportReq" table +CREATE TABLE "public"."AmbulanceTransportReq" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Patient_Id" bigint NULL, + "Diagnoses" character varying(1024) NULL, + "RequestData" timestamptz NULL, + "UsageDate" timestamptz NULL, + "Address" character varying(100) NULL, + "RtRw" character varying(10) NULL, + "Province_Code" character varying(2) NULL, + "Regency_Code" character varying(4) NULL, + "District_Code" character varying(6) NULL, + "Village_Code" character varying(10) NULL, + "Facility_Code" character varying(10) NULL, + "Needs_Code" character varying(10) NULL, + "Contact_Name" character varying(100) NULL, + "Contact_Relationship_Code" character varying(10) NULL, + "Contact_PhoneNumber" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_AmbulanceTransportReq_District" FOREIGN KEY ("District_Code") REFERENCES "public"."District" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AmbulanceTransportReq_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AmbulanceTransportReq_Province" FOREIGN KEY ("Province_Code") REFERENCES "public"."Province" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AmbulanceTransportReq_Regency" FOREIGN KEY ("Regency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AmbulanceTransportReq_Village" FOREIGN KEY ("Village_Code") REFERENCES "public"."Village" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Vehicle" table +CREATE TABLE "public"."Vehicle" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Type_Code" text NULL, + "PoliceNumber" text NULL, + "FrameNumber" text NULL, + "RegNumber" text NULL, + "AvailableStatus" boolean NULL, + PRIMARY KEY ("Id") +); +-- Create "VehicleHist" table +CREATE TABLE "public"."VehicleHist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Vehicle_Id" bigint NULL, + "Date" timestamptz NULL, + "Data" text NULL, + "Crud_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_VehicleHist_Vehicle" FOREIGN KEY ("Vehicle_Id") REFERENCES "public"."Vehicle" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251017060617.sql b/cmd/main-migration/migrations/20251017060617.sql index 8e3acbd2..ed6a5b78 100644 --- a/cmd/main-migration/migrations/20251017060617.sql +++ b/cmd/main-migration/migrations/20251017060617.sql @@ -1,2 +1,2 @@ --- Modify "MedicalActionSrc" table -ALTER TABLE "public"."MedicalActionSrc" ADD COLUMN "Type_Code" character varying(20) NULL; +-- Modify "MedicalActionSrc" table +ALTER TABLE "public"."MedicalActionSrc" ADD COLUMN "Type_Code" character varying(20) NULL; diff --git a/cmd/main-migration/migrations/20251017082207.sql b/cmd/main-migration/migrations/20251017082207.sql index 732c8d71..e7c1ebd3 100644 --- a/cmd/main-migration/migrations/20251017082207.sql +++ b/cmd/main-migration/migrations/20251017082207.sql @@ -1,2 +1,2 @@ --- Modify "Item" table -ALTER TABLE "public"."Item" ALTER COLUMN "ItemGroup_Code" TYPE character varying(15); +-- Modify "Item" table +ALTER TABLE "public"."Item" ALTER COLUMN "ItemGroup_Code" TYPE character varying(15); diff --git a/cmd/main-migration/migrations/20251018032635.sql b/cmd/main-migration/migrations/20251018032635.sql index d8c5a2c9..edd59e74 100644 --- a/cmd/main-migration/migrations/20251018032635.sql +++ b/cmd/main-migration/migrations/20251018032635.sql @@ -1,4 +1,4 @@ --- Modify "Employee" table -ALTER TABLE "public"."Employee" ADD COLUMN "Position_Code" character varying(20) NULL; --- Rename a column from "Position_Code" to "ContractPosition_Code" -ALTER TABLE "public"."User" RENAME COLUMN "Position_Code" TO "ContractPosition_Code"; +-- Modify "Employee" table +ALTER TABLE "public"."Employee" ADD COLUMN "Position_Code" character varying(20) NULL; +-- Rename a column from "Position_Code" to "ContractPosition_Code" +ALTER TABLE "public"."User" RENAME COLUMN "Position_Code" TO "ContractPosition_Code"; diff --git a/cmd/main-migration/migrations/20251018040322.sql b/cmd/main-migration/migrations/20251018040322.sql index d35e9199..9de5e2b8 100644 --- a/cmd/main-migration/migrations/20251018040322.sql +++ b/cmd/main-migration/migrations/20251018040322.sql @@ -1,13 +1,13 @@ --- Create "Intern" table -CREATE TABLE "public"."Intern" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Person_Id" bigint NULL, - "Position_Code" character varying(20) NULL, - "User_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Intern_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Intern_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "Intern" table +CREATE TABLE "public"."Intern" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "Position_Code" character varying(20) NULL, + "User_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Intern_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Intern_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251019093915.sql b/cmd/main-migration/migrations/20251019093915.sql index add924ea..89c4087e 100644 --- a/cmd/main-migration/migrations/20251019093915.sql +++ b/cmd/main-migration/migrations/20251019093915.sql @@ -1,15 +1,15 @@ --- -- Rename a column from "Position_Code" to "ContractPosition_Code" --- ALTER TABLE "public"."User" RENAME COLUMN "Position_Code" TO "ContractPosition_Code"; --- -- Create "Intern" table --- CREATE TABLE "public"."Intern" ( --- "Id" bigserial NOT NULL, --- "CreatedAt" timestamptz NULL, --- "UpdatedAt" timestamptz NULL, --- "DeletedAt" timestamptz NULL, --- "Person_Id" bigint NULL, --- "Position_Code" character varying(20) NULL, --- "User_Id" bigint NULL, --- PRIMARY KEY ("Id"), --- CONSTRAINT "fk_Intern_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, --- CONSTRAINT "fk_Intern_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION --- ); +-- -- Rename a column from "Position_Code" to "ContractPosition_Code" +-- ALTER TABLE "public"."User" RENAME COLUMN "Position_Code" TO "ContractPosition_Code"; +-- -- Create "Intern" table +-- CREATE TABLE "public"."Intern" ( +-- "Id" bigserial NOT NULL, +-- "CreatedAt" timestamptz NULL, +-- "UpdatedAt" timestamptz NULL, +-- "DeletedAt" timestamptz NULL, +-- "Person_Id" bigint NULL, +-- "Position_Code" character varying(20) NULL, +-- "User_Id" bigint NULL, +-- PRIMARY KEY ("Id"), +-- CONSTRAINT "fk_Intern_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, +-- CONSTRAINT "fk_Intern_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +-- ); diff --git a/cmd/main-migration/migrations/20251020062553.sql b/cmd/main-migration/migrations/20251020062553.sql index a1e72bdd..0ed8501b 100644 --- a/cmd/main-migration/migrations/20251020062553.sql +++ b/cmd/main-migration/migrations/20251020062553.sql @@ -1,2 +1,2 @@ --- Rename a column from "RequestData" to "RequestDate" -ALTER TABLE "public"."AmbulanceTransportReq" RENAME COLUMN "RequestData" TO "RequestDate"; +-- Rename a column from "RequestData" to "RequestDate" +ALTER TABLE "public"."AmbulanceTransportReq" RENAME COLUMN "RequestData" TO "RequestDate"; diff --git a/cmd/main-migration/migrations/20251021041042.sql b/cmd/main-migration/migrations/20251021041042.sql index 43701307..2ff8aa1b 100644 --- a/cmd/main-migration/migrations/20251021041042.sql +++ b/cmd/main-migration/migrations/20251021041042.sql @@ -1,60 +1,60 @@ --- Create "DeathCause" table -CREATE TABLE "public"."DeathCause" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NOT NULL, - "Value" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_DeathCause_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "EduAssessment" table -CREATE TABLE "public"."EduAssessment" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NOT NULL, - "GeneralEdus" text NULL, - "SpecialEdus" text NULL, - "Assessments" text NULL, - "Plan" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_EduAssessment_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "GeneralConsent" table -CREATE TABLE "public"."GeneralConsent" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NOT NULL, - "Value" text NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_GeneralConsent_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "TherapyProtocol" table -CREATE TABLE "public"."TherapyProtocol" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NOT NULL, - "Doctor_Id" bigint NULL, - "Anamnesis" character varying(2048) NULL, - "MedicalDiagnoses" text NULL, - "FunctionDiagnoses" text NULL, - "Procedures" text NULL, - "SupportingExams" character varying(2048) NULL, - "Instruction" character varying(2048) NULL, - "Evaluation" character varying(2048) NULL, - "WorkCauseStatus" character varying(2048) NULL, - "Frequency" bigint NULL, - "IntervalUnit_Code" character varying(10) NULL, - "Duration" bigint NULL, - "DurationUnit_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_TherapyProtocol_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_TherapyProtocol_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "DeathCause" table +CREATE TABLE "public"."DeathCause" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NOT NULL, + "Value" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_DeathCause_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "EduAssessment" table +CREATE TABLE "public"."EduAssessment" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NOT NULL, + "GeneralEdus" text NULL, + "SpecialEdus" text NULL, + "Assessments" text NULL, + "Plan" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_EduAssessment_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "GeneralConsent" table +CREATE TABLE "public"."GeneralConsent" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NOT NULL, + "Value" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_GeneralConsent_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "TherapyProtocol" table +CREATE TABLE "public"."TherapyProtocol" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NOT NULL, + "Doctor_Id" bigint NULL, + "Anamnesis" character varying(2048) NULL, + "MedicalDiagnoses" text NULL, + "FunctionDiagnoses" text NULL, + "Procedures" text NULL, + "SupportingExams" character varying(2048) NULL, + "Instruction" character varying(2048) NULL, + "Evaluation" character varying(2048) NULL, + "WorkCauseStatus" character varying(2048) NULL, + "Frequency" bigint NULL, + "IntervalUnit_Code" character varying(10) NULL, + "Duration" bigint NULL, + "DurationUnit_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_TherapyProtocol_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_TherapyProtocol_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251021075552.sql b/cmd/main-migration/migrations/20251021075552.sql index ead1e95b..c8f30e60 100644 --- a/cmd/main-migration/migrations/20251021075552.sql +++ b/cmd/main-migration/migrations/20251021075552.sql @@ -1,8 +1,8 @@ --- Rename a column from "DischargeMethod_Code" to "Discharge_Method_Code" -ALTER TABLE "public"."Encounter" RENAME COLUMN "DischargeMethod_Code" TO "Discharge_Method_Code"; --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" ADD COLUMN "Discharge_Date" timestamptz NULL; --- Modify "DeathCause" table -ALTER TABLE "public"."DeathCause" DROP CONSTRAINT "fk_DeathCause_Encounter", ADD CONSTRAINT "fk_Encounter_DeathCause" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "InternalReference" table -ALTER TABLE "public"."InternalReference" DROP CONSTRAINT "fk_InternalReference_Encounter", ADD CONSTRAINT "fk_Encounter_InternalReferences" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Rename a column from "DischargeMethod_Code" to "Discharge_Method_Code" +ALTER TABLE "public"."Encounter" RENAME COLUMN "DischargeMethod_Code" TO "Discharge_Method_Code"; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "Discharge_Date" timestamptz NULL; +-- Modify "DeathCause" table +ALTER TABLE "public"."DeathCause" DROP CONSTRAINT "fk_DeathCause_Encounter", ADD CONSTRAINT "fk_Encounter_DeathCause" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" DROP CONSTRAINT "fk_InternalReference_Encounter", ADD CONSTRAINT "fk_Encounter_InternalReferences" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251023044432.sql b/cmd/main-migration/migrations/20251023044432.sql index 6a1d962b..e15529e4 100644 --- a/cmd/main-migration/migrations/20251023044432.sql +++ b/cmd/main-migration/migrations/20251023044432.sql @@ -1,90 +1,90 @@ --- Create "AdmEmployeeHist" table -CREATE TABLE "public"."AdmEmployeeHist" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Employee_Id" bigint NULL, - "StartedAt" timestamptz NULL, - "FinishedAt" timestamptz NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_AdmEmployeeHist_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "InstallationPosition" table -CREATE TABLE "public"."InstallationPosition" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Installation_Id" integer NOT NULL, - "Code" character varying(10) NOT NULL, - "Name" character varying(30) NOT NULL, - "HeadStatus" boolean NULL, - "Employee_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_InstallationPosition_Code" UNIQUE ("Code"), - CONSTRAINT "fk_InstallationPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_InstallationPosition_Installation" FOREIGN KEY ("Installation_Id") REFERENCES "public"."Installation" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "ResponsibleDoctorHist" table -CREATE TABLE "public"."ResponsibleDoctorHist" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Doctor_Id" bigint NULL, - "StartedAt" timestamptz NULL, - "FinishedAt" timestamptz NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_ResponsibleDoctorHist_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "SpecialistPosition" table -CREATE TABLE "public"."SpecialistPosition" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Specialist_Id" integer NOT NULL, - "Code" character varying(10) NOT NULL, - "Name" character varying(30) NOT NULL, - "HeadStatus" boolean NULL, - "Employee_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_SpecialistPosition_Code" UNIQUE ("Code"), - CONSTRAINT "fk_SpecialistPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_SpecialistPosition_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "SubspecialistPosition" table -CREATE TABLE "public"."SubspecialistPosition" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Subspecialist_Id" integer NOT NULL, - "Code" character varying(10) NOT NULL, - "Name" character varying(30) NOT NULL, - "HeadStatus" boolean NULL, - "Employee_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_SubspecialistPosition_Code" UNIQUE ("Code"), - CONSTRAINT "fk_SubspecialistPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_SubspecialistPosition_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "UnitPosition" table -CREATE TABLE "public"."UnitPosition" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Unit_Id" integer NOT NULL, - "Code" character varying(10) NOT NULL, - "Name" character varying(30) NOT NULL, - "HeadStatus" boolean NULL, - "Employee_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_UnitPosition_Code" UNIQUE ("Code"), - CONSTRAINT "fk_UnitPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_UnitPosition_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "AdmEmployeeHist" table +CREATE TABLE "public"."AdmEmployeeHist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Employee_Id" bigint NULL, + "StartedAt" timestamptz NULL, + "FinishedAt" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_AdmEmployeeHist_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "InstallationPosition" table +CREATE TABLE "public"."InstallationPosition" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Installation_Id" integer NOT NULL, + "Code" character varying(10) NOT NULL, + "Name" character varying(30) NOT NULL, + "HeadStatus" boolean NULL, + "Employee_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_InstallationPosition_Code" UNIQUE ("Code"), + CONSTRAINT "fk_InstallationPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_InstallationPosition_Installation" FOREIGN KEY ("Installation_Id") REFERENCES "public"."Installation" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "ResponsibleDoctorHist" table +CREATE TABLE "public"."ResponsibleDoctorHist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Doctor_Id" bigint NULL, + "StartedAt" timestamptz NULL, + "FinishedAt" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ResponsibleDoctorHist_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "SpecialistPosition" table +CREATE TABLE "public"."SpecialistPosition" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Specialist_Id" integer NOT NULL, + "Code" character varying(10) NOT NULL, + "Name" character varying(30) NOT NULL, + "HeadStatus" boolean NULL, + "Employee_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_SpecialistPosition_Code" UNIQUE ("Code"), + CONSTRAINT "fk_SpecialistPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_SpecialistPosition_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "SubspecialistPosition" table +CREATE TABLE "public"."SubspecialistPosition" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Subspecialist_Id" integer NOT NULL, + "Code" character varying(10) NOT NULL, + "Name" character varying(30) NOT NULL, + "HeadStatus" boolean NULL, + "Employee_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_SubspecialistPosition_Code" UNIQUE ("Code"), + CONSTRAINT "fk_SubspecialistPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_SubspecialistPosition_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "UnitPosition" table +CREATE TABLE "public"."UnitPosition" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Unit_Id" integer NOT NULL, + "Code" character varying(10) NOT NULL, + "Name" character varying(30) NOT NULL, + "HeadStatus" boolean NULL, + "Employee_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_UnitPosition_Code" UNIQUE ("Code"), + CONSTRAINT "fk_UnitPosition_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_UnitPosition_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251024034832.sql b/cmd/main-migration/migrations/20251024034832.sql index 05794c82..11620cd2 100644 --- a/cmd/main-migration/migrations/20251024034832.sql +++ b/cmd/main-migration/migrations/20251024034832.sql @@ -1,12 +1,12 @@ --- Modify "Doctor" table -ALTER TABLE "public"."Doctor" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Doctor_Code" UNIQUE ("Code"); --- Modify "Laborant" table -ALTER TABLE "public"."Laborant" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Laborant_Code" UNIQUE ("Code"); --- Modify "Midwife" table -ALTER TABLE "public"."Midwife" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Midwife_Code" UNIQUE ("Code"); --- Modify "Nurse" table -ALTER TABLE "public"."Nurse" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Nurse_Code" UNIQUE ("Code"); --- Modify "Nutritionist" table -ALTER TABLE "public"."Nutritionist" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Nutritionist_Code" UNIQUE ("Code"); --- Modify "Pharmacist" table -ALTER TABLE "public"."Pharmacist" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Pharmacist_Code" UNIQUE ("Code"); +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Doctor_Code" UNIQUE ("Code"); +-- Modify "Laborant" table +ALTER TABLE "public"."Laborant" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Laborant_Code" UNIQUE ("Code"); +-- Modify "Midwife" table +ALTER TABLE "public"."Midwife" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Midwife_Code" UNIQUE ("Code"); +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Nurse_Code" UNIQUE ("Code"); +-- Modify "Nutritionist" table +ALTER TABLE "public"."Nutritionist" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Nutritionist_Code" UNIQUE ("Code"); +-- Modify "Pharmacist" table +ALTER TABLE "public"."Pharmacist" ADD COLUMN "Code" character varying(20) NULL, ADD CONSTRAINT "uni_Pharmacist_Code" UNIQUE ("Code"); diff --git a/cmd/main-migration/migrations/20251024074315.sql b/cmd/main-migration/migrations/20251024074315.sql index 99b3b76b..c2fd95d9 100644 --- a/cmd/main-migration/migrations/20251024074315.sql +++ b/cmd/main-migration/migrations/20251024074315.sql @@ -1,2 +1,2 @@ --- Modify "Employee" table -ALTER TABLE "public"."Employee" DROP COLUMN "Division_Code"; +-- Modify "Employee" table +ALTER TABLE "public"."Employee" DROP COLUMN "Division_Code"; diff --git a/cmd/main-migration/migrations/20251025013451.sql b/cmd/main-migration/migrations/20251025013451.sql index 0296b0f5..9a36b294 100644 --- a/cmd/main-migration/migrations/20251025013451.sql +++ b/cmd/main-migration/migrations/20251025013451.sql @@ -1,4 +1,4 @@ --- Modify "Patient" table -ALTER TABLE "public"."Patient" ADD COLUMN "RegisteredBy_User_Name" character varying(100) NULL; --- Modify "Person" table -ALTER TABLE "public"."Person" ADD COLUMN "Confidence" character varying(512) NULL, ADD COLUMN "MaritalStatus_Code" character varying(10) NULL; +-- Modify "Patient" table +ALTER TABLE "public"."Patient" ADD COLUMN "RegisteredBy_User_Name" character varying(100) NULL; +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD COLUMN "Confidence" character varying(512) NULL, ADD COLUMN "MaritalStatus_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20251025013609.sql b/cmd/main-migration/migrations/20251025013609.sql index 9793d86a..2084c529 100644 --- a/cmd/main-migration/migrations/20251025013609.sql +++ b/cmd/main-migration/migrations/20251025013609.sql @@ -1,12 +1,12 @@ --- Create "VclaimMember" table -CREATE TABLE "public"."VclaimMember" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "CardNumber" character varying(20) NULL, - "Person_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_VclaimMember_CardNumber" UNIQUE ("CardNumber"), - CONSTRAINT "fk_Person_VclaimMember" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "VclaimMember" table +CREATE TABLE "public"."VclaimMember" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "CardNumber" character varying(20) NULL, + "Person_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_VclaimMember_CardNumber" UNIQUE ("CardNumber"), + CONSTRAINT "fk_Person_VclaimMember" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251027075128.sql b/cmd/main-migration/migrations/20251027075128.sql index 6d583866..7077e18a 100644 --- a/cmd/main-migration/migrations/20251027075128.sql +++ b/cmd/main-migration/migrations/20251027075128.sql @@ -1,2 +1,2 @@ --- Modify "Encounter" table -ALTER TABLE "public"."Encounter" ADD COLUMN "StartedAt" timestamptz NULL, ADD COLUMN "FinishedAt" timestamptz NULL, ADD COLUMN "RefType_Code" text NULL, ADD COLUMN "NewStatus" boolean NULL; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "StartedAt" timestamptz NULL, ADD COLUMN "FinishedAt" timestamptz NULL, ADD COLUMN "RefType_Code" text NULL, ADD COLUMN "NewStatus" boolean NULL; diff --git a/cmd/main-migration/migrations/20251027091406.sql b/cmd/main-migration/migrations/20251027091406.sql index 25df3058..1783d48a 100644 --- a/cmd/main-migration/migrations/20251027091406.sql +++ b/cmd/main-migration/migrations/20251027091406.sql @@ -1,2 +1,2 @@ --- Modify "Patient" table -ALTER TABLE "public"."Patient" ADD COLUMN "Parent_Number" character varying(15) NULL, ADD CONSTRAINT "fk_Patient_Parent" FOREIGN KEY ("Parent_Number") REFERENCES "public"."Patient" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Patient" table +ALTER TABLE "public"."Patient" ADD COLUMN "Parent_Number" character varying(15) NULL, ADD CONSTRAINT "fk_Patient_Parent" FOREIGN KEY ("Parent_Number") REFERENCES "public"."Patient" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251102002037.sql b/cmd/main-migration/migrations/20251102002037.sql index 14a39ae1..7caa59b9 100644 --- a/cmd/main-migration/migrations/20251102002037.sql +++ b/cmd/main-migration/migrations/20251102002037.sql @@ -1,6 +1,6 @@ --- Modify "McuOrder" table -ALTER TABLE "public"."McuOrder" ADD COLUMN "Scope_Code" character varying(10) NULL; --- Create index "idx_McuOrder_Scope_Code" to table: "McuOrder" -CREATE INDEX "idx_McuOrder_Scope_Code" ON "public"."McuOrder" ("Scope_Code"); --- Create index "idx_McuSrcCategory_Scope_Code" to table: "McuSrcCategory" -CREATE INDEX "idx_McuSrcCategory_Scope_Code" ON "public"."McuSrcCategory" ("Scope_Code"); +-- Modify "McuOrder" table +ALTER TABLE "public"."McuOrder" ADD COLUMN "Scope_Code" character varying(10) NULL; +-- Create index "idx_McuOrder_Scope_Code" to table: "McuOrder" +CREATE INDEX "idx_McuOrder_Scope_Code" ON "public"."McuOrder" ("Scope_Code"); +-- Create index "idx_McuSrcCategory_Scope_Code" to table: "McuSrcCategory" +CREATE INDEX "idx_McuSrcCategory_Scope_Code" ON "public"."McuSrcCategory" ("Scope_Code"); diff --git a/cmd/main-migration/migrations/20251102091932.sql b/cmd/main-migration/migrations/20251102091932.sql index f10eadd3..a492130e 100644 --- a/cmd/main-migration/migrations/20251102091932.sql +++ b/cmd/main-migration/migrations/20251102091932.sql @@ -1,2 +1,2 @@ --- Rename a column from "McuUrgencyLevel_Code" to "UrgencyLevel_Code" -ALTER TABLE "public"."McuOrder" RENAME COLUMN "McuUrgencyLevel_Code" TO "UrgencyLevel_Code"; +-- Rename a column from "McuUrgencyLevel_Code" to "UrgencyLevel_Code" +ALTER TABLE "public"."McuOrder" RENAME COLUMN "McuUrgencyLevel_Code" TO "UrgencyLevel_Code"; diff --git a/cmd/main-migration/migrations/20251103081637.sql b/cmd/main-migration/migrations/20251103081637.sql index ca898d90..3232c88b 100644 --- a/cmd/main-migration/migrations/20251103081637.sql +++ b/cmd/main-migration/migrations/20251103081637.sql @@ -1,17 +1,17 @@ --- Create "ControlLetter" table -CREATE TABLE "public"."ControlLetter" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Unit_Id" bigint NULL, - "Specialist_Id" bigint NULL, - "Subspecialist_Id" bigint NULL, - "Date" timestamptz NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_ControlLetter_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_ControlLetter_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_ControlLetter_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_ControlLetter_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "ControlLetter" table +CREATE TABLE "public"."ControlLetter" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Unit_Id" bigint NULL, + "Specialist_Id" bigint NULL, + "Subspecialist_Id" bigint NULL, + "Date" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ControlLetter_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ControlLetter_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ControlLetter_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ControlLetter_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251104042334.sql b/cmd/main-migration/migrations/20251104042334.sql index 7628d821..ac661e10 100644 --- a/cmd/main-migration/migrations/20251104042334.sql +++ b/cmd/main-migration/migrations/20251104042334.sql @@ -1,2 +1,2 @@ --- Modify "Chemo" table -ALTER TABLE "public"."Chemo" DROP COLUMN "Class_Code", ADD COLUMN "Bed" character varying(1024) NULL, ADD COLUMN "Needs" character varying(2048) NULL; +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" DROP COLUMN "Class_Code", ADD COLUMN "Bed" character varying(1024) NULL, ADD COLUMN "Needs" character varying(2048) NULL; diff --git a/cmd/main-migration/migrations/20251104043530.sql b/cmd/main-migration/migrations/20251104043530.sql index 0d34792a..7e76865c 100644 --- a/cmd/main-migration/migrations/20251104043530.sql +++ b/cmd/main-migration/migrations/20251104043530.sql @@ -1,19 +1,19 @@ --- Modify "Ambulatory" table -ALTER TABLE "public"."Ambulatory" DROP CONSTRAINT "fk_Ambulatory_Encounter", ADD COLUMN "VisitMode_Code" text NULL, ADD CONSTRAINT "fk_Encounter_Ambulatory" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "Emergency" table -ALTER TABLE "public"."Emergency" DROP CONSTRAINT "fk_Emergency_Encounter", ADD CONSTRAINT "fk_Encounter_Emergency" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Modify "Inpatient" table -ALTER TABLE "public"."Inpatient" DROP CONSTRAINT "fk_Inpatient_Encounter", ADD CONSTRAINT "fk_Encounter_Inpatient" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; --- Create "Rehab" table -CREATE TABLE "public"."Rehab" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Doctor_Id" bigint NULL, - "AllocatedVisitCount" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_Rehab_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Rehab_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Modify "Ambulatory" table +ALTER TABLE "public"."Ambulatory" DROP CONSTRAINT "fk_Ambulatory_Encounter", ADD COLUMN "VisitMode_Code" text NULL, ADD CONSTRAINT "fk_Encounter_Ambulatory" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Emergency" table +ALTER TABLE "public"."Emergency" DROP CONSTRAINT "fk_Emergency_Encounter", ADD CONSTRAINT "fk_Encounter_Emergency" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Inpatient" table +ALTER TABLE "public"."Inpatient" DROP CONSTRAINT "fk_Inpatient_Encounter", ADD CONSTRAINT "fk_Encounter_Inpatient" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Create "Rehab" table +CREATE TABLE "public"."Rehab" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Doctor_Id" bigint NULL, + "AllocatedVisitCount" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Rehab_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Rehab_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251104080952.sql b/cmd/main-migration/migrations/20251104080952.sql index 24fcc6a5..14e62172 100644 --- a/cmd/main-migration/migrations/20251104080952.sql +++ b/cmd/main-migration/migrations/20251104080952.sql @@ -1,2 +1,2 @@ --- Modify "ControlLetter" table -ALTER TABLE "public"."ControlLetter" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_ControlLetter_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ControlLetter" table +ALTER TABLE "public"."ControlLetter" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_ControlLetter_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251104084135.sql b/cmd/main-migration/migrations/20251104084135.sql index 8c50d914..fa2c3276 100644 --- a/cmd/main-migration/migrations/20251104084135.sql +++ b/cmd/main-migration/migrations/20251104084135.sql @@ -1,17 +1,17 @@ --- Create "ChemoProtocol" table -CREATE TABLE "public"."ChemoProtocol" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Encounter_Id" bigint NULL, - "Patient_Weight" numeric NULL, - "Patient_Height" numeric NULL, - "Diagnoses" text NULL, - "Duration" bigint NULL, - "DurationUnit_Code" character varying(10) NULL, - "StartDate" timestamptz NULL, - "EndDate" timestamptz NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_ChemoProtocol_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "ChemoProtocol" table +CREATE TABLE "public"."ChemoProtocol" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Patient_Weight" numeric NULL, + "Patient_Height" numeric NULL, + "Diagnoses" text NULL, + "Duration" bigint NULL, + "DurationUnit_Code" character varying(10) NULL, + "StartDate" timestamptz NULL, + "EndDate" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ChemoProtocol_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251105044629.sql b/cmd/main-migration/migrations/20251105044629.sql index 24ba9d05..48780f06 100644 --- a/cmd/main-migration/migrations/20251105044629.sql +++ b/cmd/main-migration/migrations/20251105044629.sql @@ -1,38 +1,38 @@ --- Create "AntibioticSrcCategory" table -CREATE TABLE "public"."AntibioticSrcCategory" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_AntibioticSrcCategory_Code" UNIQUE ("Code") -); --- Create "AntibioticSrc" table -CREATE TABLE "public"."AntibioticSrc" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "AntibioticSrcCategory_Code" character varying(20) NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_AntibioticSrc_Code" UNIQUE ("Code"), - CONSTRAINT "fk_AntibioticSrc_AntibioticSrcCategory" FOREIGN KEY ("AntibioticSrcCategory_Code") REFERENCES "public"."AntibioticSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_AntibioticSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); --- Create "AntibioticInUse" table -CREATE TABLE "public"."AntibioticInUse" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "McuOrder_Id" bigint NULL, - "AntibioticSrc_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "fk_AntibioticInUse_AntibioticSrc" FOREIGN KEY ("AntibioticSrc_Id") REFERENCES "public"."AntibioticSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_AntibioticInUse_McuOrder" FOREIGN KEY ("McuOrder_Id") REFERENCES "public"."McuOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); +-- Create "AntibioticSrcCategory" table +CREATE TABLE "public"."AntibioticSrcCategory" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_AntibioticSrcCategory_Code" UNIQUE ("Code") +); +-- Create "AntibioticSrc" table +CREATE TABLE "public"."AntibioticSrc" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "AntibioticSrcCategory_Code" character varying(20) NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_AntibioticSrc_Code" UNIQUE ("Code"), + CONSTRAINT "fk_AntibioticSrc_AntibioticSrcCategory" FOREIGN KEY ("AntibioticSrcCategory_Code") REFERENCES "public"."AntibioticSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AntibioticSrc_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "AntibioticInUse" table +CREATE TABLE "public"."AntibioticInUse" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "McuOrder_Id" bigint NULL, + "AntibioticSrc_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_AntibioticInUse_AntibioticSrc" FOREIGN KEY ("AntibioticSrc_Id") REFERENCES "public"."AntibioticSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_AntibioticInUse_McuOrder" FOREIGN KEY ("McuOrder_Id") REFERENCES "public"."McuOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251105121808.sql b/cmd/main-migration/migrations/20251105121808.sql index 41c1edf0..2010b216 100644 --- a/cmd/main-migration/migrations/20251105121808.sql +++ b/cmd/main-migration/migrations/20251105121808.sql @@ -1,2 +1,2 @@ --- Modify "AntibioticSrc" table -ALTER TABLE "public"."AntibioticSrc" DROP COLUMN "Item_Id"; +-- Modify "AntibioticSrc" table +ALTER TABLE "public"."AntibioticSrc" DROP COLUMN "Item_Id"; diff --git a/cmd/main-migration/migrations/20251106035305.sql b/cmd/main-migration/migrations/20251106035305.sql index d2ab1e94..a85728fc 100644 --- a/cmd/main-migration/migrations/20251106035305.sql +++ b/cmd/main-migration/migrations/20251106035305.sql @@ -1,4 +1,4 @@ --- Modify "Doctor" table -ALTER TABLE "public"."Doctor" ADD COLUMN "SIP_ExpiredDate" timestamptz NULL, ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL, ADD CONSTRAINT "uni_Doctor_Specialist_Code" UNIQUE ("Specialist_Code"), ADD CONSTRAINT "uni_Doctor_Subspecialist_Code" UNIQUE ("Subspecialist_Code"), ADD CONSTRAINT "uni_Doctor_Unit_Code" UNIQUE ("Unit_Code"); --- Modify "Employee" table -ALTER TABLE "public"."Employee" ADD COLUMN "Contract_ExpiredDate" timestamptz NULL; +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" ADD COLUMN "SIP_ExpiredDate" timestamptz NULL, ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL, ADD CONSTRAINT "uni_Doctor_Specialist_Code" UNIQUE ("Specialist_Code"), ADD CONSTRAINT "uni_Doctor_Subspecialist_Code" UNIQUE ("Subspecialist_Code"), ADD CONSTRAINT "uni_Doctor_Unit_Code" UNIQUE ("Unit_Code"); +-- Modify "Employee" table +ALTER TABLE "public"."Employee" ADD COLUMN "Contract_ExpiredDate" timestamptz NULL; diff --git a/cmd/main-migration/migrations/20251106040137.sql b/cmd/main-migration/migrations/20251106040137.sql index f9cb71cc..3b702be1 100644 --- a/cmd/main-migration/migrations/20251106040137.sql +++ b/cmd/main-migration/migrations/20251106040137.sql @@ -1,2 +1,2 @@ --- Modify "Doctor" table -ALTER TABLE "public"."Doctor" DROP CONSTRAINT "uni_Doctor_Specialist_Code", DROP CONSTRAINT "uni_Doctor_Subspecialist_Code", DROP CONSTRAINT "uni_Doctor_Unit_Code"; +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" DROP CONSTRAINT "uni_Doctor_Specialist_Code", DROP CONSTRAINT "uni_Doctor_Subspecialist_Code", DROP CONSTRAINT "uni_Doctor_Unit_Code"; diff --git a/cmd/main-migration/migrations/20251106041333.sql b/cmd/main-migration/migrations/20251106041333.sql index 0e4cc5c0..c33a9c92 100644 --- a/cmd/main-migration/migrations/20251106041333.sql +++ b/cmd/main-migration/migrations/20251106041333.sql @@ -1,2 +1,2 @@ --- Modify "Nurse" table -ALTER TABLE "public"."Nurse" ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Infra_Code" character varying(10) NULL; +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Infra_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20251106042006.sql b/cmd/main-migration/migrations/20251106042006.sql index a3f2f609..1e95edc7 100644 --- a/cmd/main-migration/migrations/20251106042006.sql +++ b/cmd/main-migration/migrations/20251106042006.sql @@ -1,2 +1,2 @@ --- Modify "SpecialistIntern" table -ALTER TABLE "public"."SpecialistIntern" ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL; +-- Modify "SpecialistIntern" table +ALTER TABLE "public"."SpecialistIntern" ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL; From 827c40dd069f818c6eb231cfa9d0b8a790734c12 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 6 Nov 2025 12:18:16 +0700 Subject: [PATCH 32/55] migration from server --- cmd/main-migration/migrations/atlas.sum | 97 ++++--------------------- 1 file changed, 15 insertions(+), 82 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index e8641831..bb6413e8 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,6 +1,8 @@ -h1:lDfnkzBVHYhHwd5okbIRgBk5zo9kmeAK9Ideg1SsSw4= -20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY=20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= -20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI=20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= +h1:PwMC7qEOPDdica7/V7qlIoAcAg48skkmfckAfhLgXHk= +20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY= +20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= +20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI= +20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= 20250908073811.sql h1:gOi5cnGG1htlpfizybYmUIT0vYjZTBfXiI0nPSYK2u8= 20250908073839.sql h1:cWNDA4YikjoOteAJuNLFILjQUJPFB6o8Wxreiek4QyI= 20250910055902.sql h1:nxxOGnU0BbH/v3IPgeIOXOwH8d3tKomw7h6FTeMnnBs= @@ -64,82 +66,13 @@ h1:lDfnkzBVHYhHwd5okbIRgBk5zo9kmeAK9Ideg1SsSw4= 20251102091932.sql h1:A6y9j4wAqm4/HfMDxhpy/ChDn3UNRVN99KGgSCX+e18= 20251103081637.sql h1:RFqJNhJItSwJQaMP5IcQ14mL7eQ3EJjGZua9zLWzwMU= 20251104042334.sql h1:BbjLAwImggvI6489FQgD+S/AaafeiZut8k19TdH7XUE= -20251104043530.sq -h1:97IUzyfSecffgKmYYs+a+HW5thHnIY3OuWDTQYy3hGQ= -20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= -20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= -20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= -20250908062323.sql h1:oXl6Z143tOpIl4EfP4B8JNU8LrMvVmHEtCgAfiB4gs8= -20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= -20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= -20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= -20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= -20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= -20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= -20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= -20250917045138.sql h1:jKe1Z0uOLG4SGBYM+S/3P+/zMPztmgoderD5swnMuCg= -20250917093645.sql h1:cNI3Pbz1R3LxvIXLuexafJFCXUXrmuFCgXXJ2sG+FW0= -20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= -20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= -20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= -20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= -20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ= -20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg= -20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34= -20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= -20250930140351.sql h1:9AAEG1AnOAH+o0+oHL5G7I8vqlWOhwRlCGyyCpT/y1Q= -20251002085604.sql h1:3xZ68eYp4urXRnvotNH1XvG2mYOSDV/j3zHEZ/txg5E= -20251003032030.sql h1:HB+mQ2lXMNomHDpaRhB/9IwYI9/YiDO5eOJ+nAQH/jw= -20251005060450.sql h1:LbtCE2b+8osM3CvnmQJH1uCPtn+d7WchsslBOz8bL3Q= -20251006041122.sql h1:MlS7f21z06sutnf9dIekt5fuHJr4lgcQ4uCuCXAGsfc= -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:nxnXmooIJ6r1mmzwnw+6efxLfc/k9h2aE6RMptPRons= -20251008073620.sql h1:6YsJp1W4SmQJ1lxpqF27BBlDC1zqhw7Yhc7pLzQTY6M= -20251009042854.sql h1:nkBV+R6j0fg7/JY6wH3eb5Vv0asJLnXmb6lINfT/GLQ= -20251009052657.sql h1:EPvdsib5rzCGPryd10HShGKvFPwM/R5S2lIVwtYxpms= -20251010031743.sql h1:T8IZmx8/btRFKLzTe78MzcBsPJNodnLvB0tby9QkirQ= -20251010070721.sql h1:5NQUk/yOV6sABLCB7swx++YIOyJe6MnU+yt1nRzde5w= -20251010072711.sql h1:ZJNqR2piyu8xJhBvVABSlnGEoKSKae3wuEs+wshPe4k= -20251013044536.sql h1:0Xjw8fNILiT8nnfrJDZgQnPf3dntmIoilbapnih8AE4= -20251013051438.sql h1:lfSuw5mgJnePBJamvhZ81osFIouXeiIEiSZ/evdwo48= -20251013081808.sql h1:ijgjNX08G6GBjA/ks8EKtb7P7Y7Cg7zbhqEOruGnv6M= -20251014060047.sql h1:0jqj49WTtneEIMQDBoo4c095ZGi8sCrA8NnHBrPU6D8= -20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg= -20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14= -20251015045455.sql h1:MeLWmMhAOAz8b15Dd7IAQnt6JxjSml02XCXK22C0Lpg= -20251016010845.sql h1:4BncQdDOasRZJkzVJrSJJA7091A9VPNVx/faUCUPhBM= -20251016011023.sql h1:9JB9eFZKURK5RoCVDKR6glSvdJ8NTXrN7K/4q51zkz4= -20251016062912.sql h1:ACNn0fe+EMqUt3hoY+Dr3uqAV/QICBa1+mIW7fUc9Fk= -20251017060617.sql h1:4T3t9ifWrEQTPMSM0XJ98pF7Qdt+UfgtMui17bhrnWI= -20251017082207.sql h1:8vLG1l/saRRMHXkyA4nelJyjaSddhZd6r7R+Uo4JS/c= -20251018032635.sql h1:2xey5gnO3y2XSOrU8MLlIfoylPKbRGDRtHDD07B3MbQ= -20251018040322.sql h1:k/pdNiSoT8zFPqNQ/avOD0vYkNh3BTD64IlHrfVXr7I= -20251019093915.sql h1:hFcQE0y+p5dZiVwePGsRGto9m/q6kJNiUZbVDd5Rnjk= -20251020062553.sql h1:Iw7hulcm5iRQlfW+ygA4iTPxLqkxx6h9vXMXEwUAHKs= -20251021041042.sql h1:wMgSivBV2A0NDcsLmKGIp0kMcVh2IODSG9b4dgzCaOM= -20251021075552.sql h1:8gfSMAglflNO6L0sSzxFNEubYN8/O4thT7OQT+WH+3M= -20251023044432.sql h1:MkvajJs3bfk9+wHvQ43/ccAluJEBARm1gWr1u92ccLA= -20251024034832.sql h1:x3s3VEVYLOSKLAFxJGb2+c1FyTMMvPE+9k4Ew7rKQaI= -20251024074315.sql h1:EjAjelgi5qAfcRq/8vPTlGGYHvAKxNTllm8f0SzZDns= -20251025013451.sql h1:6hnuIiwYiG+6nLhOY/+Yyn+I6ZCFNRZxrJNqBV6HLqE= -20251025013609.sql h1:evPJaTD8WxYRMOJZHkSr7ONLx9PYxT+ankzQt9c/sJ0= -20251027075128.sql h1:/iFQBM1sytjqpyQSOx61q33gnorMgxTiFVSuL6bQqsM= -20251027091406.sql h1:eCZGtUkxAzEAqpC9UsGpP8Df9mS0DEOqSl885LgqpvM= -20251102002037.sql h1:lFJbuoZ2LMQnUNGdcwHVY3Xlfslgzu9t2WByT8yfOZI= -20251102091932.sql h1:rmdhb5m+P+fU8jROBZNyeYgZKuQvucsuljXv4ZVzvks= -20251103081637.sql h1:tf3BcwTeIw+oxMEisKDDfyKnBfalTLs8b0PJA8JWYxY= -20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk= -20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= -20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= -20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= -20251105044629.sql h1:4NU27HeKUNFsV82LacnwmnCSAH0pSbZR9J9/ZESRs6M= -20251105121808.sql h1:fii6LjqWYjrm/pEIqttfvJI6QEUL49gque8wYHh1+yI= -20251106035305.sql h1:oQ7BwnxPuwY2q98adIVc+lNwL/Sz1OceLJeClDo9/TI= -20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= -20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= -20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251104043530.sql h1:Y0sOQqgnHxd5vKPA4+4fAGGdWCv6duKAYgHnjRJZUIc= +20251104080952.sql h1:hDHzFs/k+NhPYJ64ifbVp+nTJLMCG5MIMJU1zBMP0V0= +20251104084135.sql h1:p97mW1MPtPrMWJKy/KZqvymMO/vlelnXp43N9bZVCTI= +20251105044629.sql h1:E4BkVD3YyWvd0D18jA57EwTmkeoAMUWrdTCEwdPHA1U= +20251105121808.sql h1:kyMNzaJLyVtS1QpkX7cnVvhQmrrIE8m3GxUWwrMeyUo= +20251106035305.sql h1:VInVWBP1xpEhVIm1+ymuPzu0joxV2oS4qkNIyQvmTSU= +20251106040137.sql h1:7glRO1VAgq89H6zhM6M50iLwMT0w2sb96DUGrvfXZo4= +20251106041333.sql h1:/2wLmx8awSYhVpusDPAI+VeYJOLeLCWsNaF79gl1lg8= +20251106042006.sql h1:05AZyIbRJi1W08ETScADyAhI3elW0bXaWizlCpDfFCI= +20251106050412.sql h1:0102Z6ifzlwDjvU9jveuzULJvlo+Lc/UwyCeHUrwx18= From 7423621a301154a681caefca77dfc8150f3cb258 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 13:34:49 +0700 Subject: [PATCH 33/55] prescription ids into codes --- .../migrations/20251106063418.sql | 2 + cmd/main-migration/migrations/atlas.sum | 157 +++++++++--------- .../domain/main-entities/prescription/dto.go | 8 +- .../main-entities/prescription/entity.go | 3 +- .../main-use-case/prescription/helper.go | 1 - 5 files changed, 86 insertions(+), 85 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106063418.sql diff --git a/cmd/main-migration/migrations/20251106063418.sql b/cmd/main-migration/migrations/20251106063418.sql new file mode 100644 index 00000000..c04659a3 --- /dev/null +++ b/cmd/main-migration/migrations/20251106063418.sql @@ -0,0 +1,2 @@ +-- Modify "Prescription" table +ALTER TABLE "public"."Prescription" DROP CONSTRAINT "fk_Prescription_Doctor", DROP COLUMN "Doctor_Id", ADD CONSTRAINT "fk_Prescription_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index bb6413e8..70ff0699 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,78 +1,79 @@ -h1:PwMC7qEOPDdica7/V7qlIoAcAg48skkmfckAfhLgXHk= -20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY= -20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= -20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI= -20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= -20250908073811.sql h1:gOi5cnGG1htlpfizybYmUIT0vYjZTBfXiI0nPSYK2u8= -20250908073839.sql h1:cWNDA4YikjoOteAJuNLFILjQUJPFB6o8Wxreiek4QyI= -20250910055902.sql h1:nxxOGnU0BbH/v3IPgeIOXOwH8d3tKomw7h6FTeMnnBs= -20250915123412.sql h1:mz7SiWfrdf0qE1VTSAAnA/147d6gyp6ry5vZ2bR9SH0= -20250916043819.sql h1:RHXVtmMkB6wfv06HfPyHMBmUfIpFt1xveafNz0kwKnE= -20250917040616.sql h1:MYVDht+akBlzQGKNu2hTTTLPEcH1bxT/Q8MK6WEtuhs= -20250917040751.sql h1:J79YyS2JzWgh5oKXMTgh67uo3gLxKaAsxRiZmSIfjBs= -20250917045138.sql h1:/SM1N4O8X3yxpoJgMEARmS1uOkuLKsTOy4PLsRCOKaQ= -20250917093645.sql h1:PNBTGZ7s10e5b5+Tie8YfVQBN0zKtJ5T34oK1iOUEb4= -20250918073552.sql h1:jG7+g3i8ODYaJdcdZz12v3nbsZ5mB9wG6kWnGyTQIRI= -20250918073742.sql h1:j+rgw7puxE7s+phqPVZHmPk0af3rcaA56Itp86y1suY= -20250918074745.sql h1:rPmP4DXs6OnY4Vp+xO/z9jFpJt/RrJ52SJJjIIxeDvc= -20250923025134.sql h1:2r6pcwnBSU5Y9Czk1OHBoh4yZXiMtEca9X8843fTEX0= -20250924051317.sql h1:iUAk2gsGoEGIPQ0lEEUp8maMSId8emNbP+kP712ABIA= -20250929034321.sql h1:UlpALNVmdi95zOIT0yc6ZyTj9bBjQEIpZhvgrc52M+k= -20250929034428.sql h1:feF+H4nDyHh5bdx48Oiz0A1qecZfi6v3qTTdjzJ45Dg= -20250930025550.sql h1:6XT1kXI3Z3ZIxxmvT7poufZWWCW0QiejZPaFV5wBnjI= -20250930140351.sql h1:HxnmAbh9gCy8jwl/9ycGktiByaUripsjFFvohofY2CY= -20251002085604.sql h1:SjLPi+ZN6qDccK3DaEQCgNsZpPwr5kynWXwbwEsziCI= -20251003032030.sql h1:oHfxNSuqTxU8Zaf9H+h8TuUb1Da03wcyc6hZjDrUQ2s= -20251005060450.sql h1:GIuCcrd4MwjmXpvbzDzPYL18BV3QaZZ+Y2FmEzjvi0E= -20251006041122.sql h1:uNDQbSw0M08lYoMvUNlQtS3iDzpPM1ixT13ugSAoWjE= -20251006045658.sql h1:z+t7yCK54Q4SSiF9kUyUhkYB2F+kzSW9TB7ogxd9wzw= -20251006045928.sql h1:1lATLFLp4BWwGZqAjZdP0Dc6ypNXiYcwjoNkqGa8NFE= -20251007022859.sql h1:HXXwWrkyvzJzJGAt9mGskCRBBV/c1JfPmfjDocmJhQ4= -20251008031337.sql h1:Ln5pCF3Hxa5foHZLcds+z/us2eH6VAhhEj3w0TAGlVs= -20251008031554.sql h1:aB4MUS2lmqG0//4HKUWorcPSpWya0VC4QItvGyskEVI= -20251008052346.sql h1:MI3AZgU5XcwZT2OvvlWAxdRtL0eJ3jjRwt56IY1+pRU= -20251008073620.sql h1:sztWXuSNYwpEraaSapSsYwno75LO5H/N7ob7OJQ8X/A= -20251009042854.sql h1:TnPXj+dCJls3IU//cuqJZymyBzZMKs7ayazfgtAFRxM= -20251009052657.sql h1:leXbs0CP8r5dRilmYyLRk1MICqak3ea1/LWMtFrijqQ= -20251010031743.sql h1:SgHNY/lQ88G2F4nZyMfiOkDntb+gtOR+nEQLqXBTwv4= -20251010070721.sql h1:AnJnhXsMzDvK4AFgYw6B16Kpo/hljrZtcpc9m2VOSHQ= -20251010072711.sql h1:aXPTtNwLcTuw8C/yAxwxvqs0ayEjNzI1uuE0vE3ERa8= -20251013044536.sql h1:7Pq6JcvTpPBYDCW2dz3HdgUwY65HlhEVWy9TiG8iONE= -20251013051438.sql h1:X6t8bkqpUYYokBunSufMQUe5vCg0VyO6dxbm7ngosUc= -20251013081808.sql h1:495pLguXL2Ozh+ycn4UYZgZbn6WbjXNbyZUc3JU8qhI= -20251014060047.sql h1:nCgImMRGHhziiW57O1ofWaXCAPGaCOHN7PldQ3OSmM4= -20251014063537.sql h1:2cLmID79jP6cuQ1YJaWTtghFiM1GtHMC0ZQl30Hpy1M= -20251014063720.sql h1:bzLKKVAjSHgDFoiI/glj7t1ETlSAKx+AlsIAaP0ru2g= -20251015045455.sql h1:S547+UugQhlTRcn1Lm1IfqT5RNPttIWIiD+RTx69YaE= -20251016010845.sql h1:c9DUvxl17pUkf0azdYGM/YDzYxIJkLcfZOcMI4rL+R0= -20251016011023.sql h1:u3ivg83bXgYHBbojbWpemLxPE9Dmmj53B6LXo664jxw= -20251016062912.sql h1:W9n1hWchfYkqNX9LO9uxFxEXAb/iY+Pexjnhmp6PbgI= -20251017060617.sql h1:VU6yZ2+LfHpDZ3+TIH40t3F5YXPCpTppuF9+uSqa4b8= -20251017082207.sql h1:QshZslfedckz7iDpSGmPyY9sP6dy6ckHbs8L1TuXIA4= -20251018032635.sql h1:M1U/9W/F9wlW5YDmVAmHFfUJU7FWFaX0DblpfZcYWrE= -20251018040322.sql h1:Zk/vw0e6AzWFO2ElLOzB+OrSz6k+h1Ynxp0TImAzxwY= -20251019093915.sql h1:3Q0kPiZwJnHn5rAvdh0w1LBdiA7W2xBmZWncoPXb044= -20251020062553.sql h1:mJwC/J8GzPAIXckNMvy1f/Nguk2VVf8roD/Raclhbao= -20251021041042.sql h1:d1BAOGAQhqr+oOwcpAVozUsTh457VSDEk2qQFavGG58= -20251021075552.sql h1:TNChGQ1Zlr/1iQ6qvK4iDTAJpe6L/z/M6e/O0SkQVaM= -20251023044432.sql h1:GA2AdJk2ULyjr6igtu9C/CEi4YUIks8r9jXGGaCvPsk= -20251024034832.sql h1:RXmbEhMkOLK5g1QL6up8iRPcwYfo89oLP26ZHvrUK9o= -20251024074315.sql h1:3GnPQSbuAAfMa8oWDyBjhXqn1j1zunY/w0ydX0IGPrA= -20251025013451.sql h1:5eNrA9LDxA4i5CCP7wSyOgFZ6t6jBWVil+oGzJpkJ2E= -20251025013609.sql h1:+N6EHc1kv3hqf16CUhXe+UITPmoxOPfi4MECLmJXNrc= -20251027075128.sql h1:PQflgsjce/p2ClbybLtdehdPNDcMZ9Lb1vd98xd0K8E= -20251027091406.sql h1:bYXV57GvodCMjg0/ox+XKGIAGhrDlVuJ1wO4foNEKtQ= -20251102002037.sql h1:ZcwULsJU2lI9t5pX7ukmfAHSx4ZxdxLUX6jzLDc2SrU= -20251102091932.sql h1:A6y9j4wAqm4/HfMDxhpy/ChDn3UNRVN99KGgSCX+e18= -20251103081637.sql h1:RFqJNhJItSwJQaMP5IcQ14mL7eQ3EJjGZua9zLWzwMU= -20251104042334.sql h1:BbjLAwImggvI6489FQgD+S/AaafeiZut8k19TdH7XUE= -20251104043530.sql h1:Y0sOQqgnHxd5vKPA4+4fAGGdWCv6duKAYgHnjRJZUIc= -20251104080952.sql h1:hDHzFs/k+NhPYJ64ifbVp+nTJLMCG5MIMJU1zBMP0V0= -20251104084135.sql h1:p97mW1MPtPrMWJKy/KZqvymMO/vlelnXp43N9bZVCTI= -20251105044629.sql h1:E4BkVD3YyWvd0D18jA57EwTmkeoAMUWrdTCEwdPHA1U= -20251105121808.sql h1:kyMNzaJLyVtS1QpkX7cnVvhQmrrIE8m3GxUWwrMeyUo= -20251106035305.sql h1:VInVWBP1xpEhVIm1+ymuPzu0joxV2oS4qkNIyQvmTSU= -20251106040137.sql h1:7glRO1VAgq89H6zhM6M50iLwMT0w2sb96DUGrvfXZo4= -20251106041333.sql h1:/2wLmx8awSYhVpusDPAI+VeYJOLeLCWsNaF79gl1lg8= -20251106042006.sql h1:05AZyIbRJi1W08ETScADyAhI3elW0bXaWizlCpDfFCI= -20251106050412.sql h1:0102Z6ifzlwDjvU9jveuzULJvlo+Lc/UwyCeHUrwx18= +h1:5MZVEgV5zVF7bZ9mXYoi2ck0e9iRd7Ecib3j5OFA4/g= +20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= +20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= +20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= +20250908062323.sql h1:oXl6Z143tOpIl4EfP4B8JNU8LrMvVmHEtCgAfiB4gs8= +20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= +20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= +20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= +20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= +20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= +20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= +20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= +20250917045138.sql h1:jKe1Z0uOLG4SGBYM+S/3P+/zMPztmgoderD5swnMuCg= +20250917093645.sql h1:cNI3Pbz1R3LxvIXLuexafJFCXUXrmuFCgXXJ2sG+FW0= +20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= +20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= +20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= +20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= +20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ= +20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg= +20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34= +20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= +20250930140351.sql h1:9AAEG1AnOAH+o0+oHL5G7I8vqlWOhwRlCGyyCpT/y1Q= +20251002085604.sql h1:3xZ68eYp4urXRnvotNH1XvG2mYOSDV/j3zHEZ/txg5E= +20251003032030.sql h1:HB+mQ2lXMNomHDpaRhB/9IwYI9/YiDO5eOJ+nAQH/jw= +20251005060450.sql h1:LbtCE2b+8osM3CvnmQJH1uCPtn+d7WchsslBOz8bL3Q= +20251006041122.sql h1:MlS7f21z06sutnf9dIekt5fuHJr4lgcQ4uCuCXAGsfc= +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:nxnXmooIJ6r1mmzwnw+6efxLfc/k9h2aE6RMptPRons= +20251008073620.sql h1:6YsJp1W4SmQJ1lxpqF27BBlDC1zqhw7Yhc7pLzQTY6M= +20251009042854.sql h1:nkBV+R6j0fg7/JY6wH3eb5Vv0asJLnXmb6lINfT/GLQ= +20251009052657.sql h1:EPvdsib5rzCGPryd10HShGKvFPwM/R5S2lIVwtYxpms= +20251010031743.sql h1:T8IZmx8/btRFKLzTe78MzcBsPJNodnLvB0tby9QkirQ= +20251010070721.sql h1:5NQUk/yOV6sABLCB7swx++YIOyJe6MnU+yt1nRzde5w= +20251010072711.sql h1:ZJNqR2piyu8xJhBvVABSlnGEoKSKae3wuEs+wshPe4k= +20251013044536.sql h1:0Xjw8fNILiT8nnfrJDZgQnPf3dntmIoilbapnih8AE4= +20251013051438.sql h1:lfSuw5mgJnePBJamvhZ81osFIouXeiIEiSZ/evdwo48= +20251013081808.sql h1:ijgjNX08G6GBjA/ks8EKtb7P7Y7Cg7zbhqEOruGnv6M= +20251014060047.sql h1:0jqj49WTtneEIMQDBoo4c095ZGi8sCrA8NnHBrPU6D8= +20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg= +20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14= +20251015045455.sql h1:MeLWmMhAOAz8b15Dd7IAQnt6JxjSml02XCXK22C0Lpg= +20251016010845.sql h1:4BncQdDOasRZJkzVJrSJJA7091A9VPNVx/faUCUPhBM= +20251016011023.sql h1:9JB9eFZKURK5RoCVDKR6glSvdJ8NTXrN7K/4q51zkz4= +20251016062912.sql h1:ACNn0fe+EMqUt3hoY+Dr3uqAV/QICBa1+mIW7fUc9Fk= +20251017060617.sql h1:4T3t9ifWrEQTPMSM0XJ98pF7Qdt+UfgtMui17bhrnWI= +20251017082207.sql h1:8vLG1l/saRRMHXkyA4nelJyjaSddhZd6r7R+Uo4JS/c= +20251018032635.sql h1:2xey5gnO3y2XSOrU8MLlIfoylPKbRGDRtHDD07B3MbQ= +20251018040322.sql h1:k/pdNiSoT8zFPqNQ/avOD0vYkNh3BTD64IlHrfVXr7I= +20251019093915.sql h1:hFcQE0y+p5dZiVwePGsRGto9m/q6kJNiUZbVDd5Rnjk= +20251020062553.sql h1:Iw7hulcm5iRQlfW+ygA4iTPxLqkxx6h9vXMXEwUAHKs= +20251021041042.sql h1:wMgSivBV2A0NDcsLmKGIp0kMcVh2IODSG9b4dgzCaOM= +20251021075552.sql h1:8gfSMAglflNO6L0sSzxFNEubYN8/O4thT7OQT+WH+3M= +20251023044432.sql h1:MkvajJs3bfk9+wHvQ43/ccAluJEBARm1gWr1u92ccLA= +20251024034832.sql h1:x3s3VEVYLOSKLAFxJGb2+c1FyTMMvPE+9k4Ew7rKQaI= +20251024074315.sql h1:EjAjelgi5qAfcRq/8vPTlGGYHvAKxNTllm8f0SzZDns= +20251025013451.sql h1:6hnuIiwYiG+6nLhOY/+Yyn+I6ZCFNRZxrJNqBV6HLqE= +20251025013609.sql h1:evPJaTD8WxYRMOJZHkSr7ONLx9PYxT+ankzQt9c/sJ0= +20251027075128.sql h1:/iFQBM1sytjqpyQSOx61q33gnorMgxTiFVSuL6bQqsM= +20251027091406.sql h1:eCZGtUkxAzEAqpC9UsGpP8Df9mS0DEOqSl885LgqpvM= +20251102002037.sql h1:lFJbuoZ2LMQnUNGdcwHVY3Xlfslgzu9t2WByT8yfOZI= +20251102091932.sql h1:rmdhb5m+P+fU8jROBZNyeYgZKuQvucsuljXv4ZVzvks= +20251103081637.sql h1:tf3BcwTeIw+oxMEisKDDfyKnBfalTLs8b0PJA8JWYxY= +20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk= +20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= +20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= +20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= +20251105044629.sql h1:4NU27HeKUNFsV82LacnwmnCSAH0pSbZR9J9/ZESRs6M= +20251105121808.sql h1:fii6LjqWYjrm/pEIqttfvJI6QEUL49gque8wYHh1+yI= +20251106035305.sql h1:oQ7BwnxPuwY2q98adIVc+lNwL/Sz1OceLJeClDo9/TI= +20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= +20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= +20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= diff --git a/internal/domain/main-entities/prescription/dto.go b/internal/domain/main-entities/prescription/dto.go index f0c6901e..9c73c0ee 100644 --- a/internal/domain/main-entities/prescription/dto.go +++ b/internal/domain/main-entities/prescription/dto.go @@ -14,7 +14,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` IssuedAt *time.Time `json:"issuedAt"` Status_Code erc.DataStatusCode `json:"status_code"` @@ -29,7 +29,7 @@ type ReadListDto struct { type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` - Doctor_Id *uint `json:"doctor-id"` + Doctor_Code *string `json:"doctor-code"` IssuedAt *time.Time `json:"issuedAt"` Status_Code *erc.DataStatusCode `json:"status-code"` } @@ -58,7 +58,7 @@ type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` IssuedAt *time.Time `json:"issuedAt"` Status_Code erc.DataStatusCode `json:"status_code"` @@ -68,7 +68,7 @@ func (d Prescription) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, Encounter: d.Encounter, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, IssuedAt: d.IssuedAt, Status_Code: d.Status_Code, diff --git a/internal/domain/main-entities/prescription/entity.go b/internal/domain/main-entities/prescription/entity.go index c32c9d9e..849e8083 100644 --- a/internal/domain/main-entities/prescription/entity.go +++ b/internal/domain/main-entities/prescription/entity.go @@ -14,9 +14,8 @@ type Prescription struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` Doctor_Code *string `json:"doctor_code" gorm:"size:20"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` IssuedAt *time.Time `json:"issuedAt"` Status_Code erc.DataStatusCode `json:"status_code"` } diff --git a/internal/use-case/main-use-case/prescription/helper.go b/internal/use-case/main-use-case/prescription/helper.go index 92fd4531..7260699e 100644 --- a/internal/use-case/main-use-case/prescription/helper.go +++ b/internal/use-case/main-use-case/prescription/helper.go @@ -37,7 +37,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Prescription) { } data.Encounter_Id = inputSrc.Encounter_Id - // data.Doctor_Id = inputSrc.Doctor_Id data.Doctor_Code = inputSrc.AuthInfo.Doctor_Code data.IssuedAt = inputSrc.IssuedAt } From 4aabf4ad5209a0e6304db6633e840fd5e174fd9a Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 14:23:51 +0700 Subject: [PATCH 34/55] specialist, subscpecialist, specialist-position, subspecialist-position ids into codes --- .../migrations/20251106071906.sql | 8 +++ cmd/main-migration/migrations/atlas.sum | 3 +- .../specialist-position/base/entity.go | 1 + .../main-entities/specialist-position/dto.go | 57 ++++++++++--------- .../domain/main-entities/specialist/dto.go | 25 ++++---- .../domain/main-entities/specialist/entity.go | 1 + .../subspecialist-position/base/entity.go | 15 ++--- .../subspecialist-position/dto.go | 57 ++++++++++--------- .../subspecialist/base/entity.go | 1 + .../domain/main-entities/subspecialist/dto.go | 27 ++++----- .../interface/main-handler/main-handler.go | 8 +-- .../specialist-position/handler.go | 18 +++--- .../main-handler/specialist/handler.go | 18 +++--- .../subspecialist-position/handler.go | 18 +++--- .../main-handler/subspecialist/handler.go | 18 +++--- .../main-use-case/specialist-position/case.go | 2 +- .../specialist-position/helper.go | 2 +- .../main-use-case/specialist-position/lib.go | 2 +- .../use-case/main-use-case/specialist/case.go | 4 +- .../main-use-case/specialist/helper.go | 2 +- .../subspecialist-position/case.go | 6 +- .../subspecialist-position/helper.go | 2 +- .../subspecialist-position/lib.go | 4 +- .../main-use-case/subspecialist/case.go | 4 +- .../main-use-case/subspecialist/lib.go | 7 +++ .../handler-crud-helper.go | 34 +++++++++++ 26 files changed, 201 insertions(+), 143 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106071906.sql diff --git a/cmd/main-migration/migrations/20251106071906.sql b/cmd/main-migration/migrations/20251106071906.sql new file mode 100644 index 00000000..66793656 --- /dev/null +++ b/cmd/main-migration/migrations/20251106071906.sql @@ -0,0 +1,8 @@ +-- Modify "Specialist" table +ALTER TABLE "public"."Specialist" ADD COLUMN "Unit_Code" character varying(10) NULL; +-- Modify "SpecialistPosition" table +ALTER TABLE "public"."SpecialistPosition" ADD COLUMN "Specialist_Code" character varying(10) NULL; +-- Modify "Subspecialist" table +ALTER TABLE "public"."Subspecialist" ADD COLUMN "Specialist_Code" character varying(10) NULL; +-- Modify "SubspecialistPosition" table +ALTER TABLE "public"."SubspecialistPosition" ADD COLUMN "Subspecialist_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 70ff0699..fd8a8979 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:5MZVEgV5zVF7bZ9mXYoi2ck0e9iRd7Ecib3j5OFA4/g= +h1:CT5nygEUOdVE27HmnMPqwLegXYbJ41grmTvFn7AH8D8= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -77,3 +77,4 @@ h1:5MZVEgV5zVF7bZ9mXYoi2ck0e9iRd7Ecib3j5OFA4/g= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= 20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= 20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= diff --git a/internal/domain/main-entities/specialist-position/base/entity.go b/internal/domain/main-entities/specialist-position/base/entity.go index 5910689e..5db268cd 100644 --- a/internal/domain/main-entities/specialist-position/base/entity.go +++ b/internal/domain/main-entities/specialist-position/base/entity.go @@ -8,6 +8,7 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs Specialist_Id *uint16 `json:"specialist_id" gorm:"not null"` + Specialist_Code *string `json:"specialist_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` HeadStatus bool `json:"headStatus"` diff --git a/internal/domain/main-entities/specialist-position/dto.go b/internal/domain/main-entities/specialist-position/dto.go index 0641fb12..beebab28 100644 --- a/internal/domain/main-entities/specialist-position/dto.go +++ b/internal/domain/main-entities/specialist-position/dto.go @@ -7,11 +7,11 @@ import ( ) type CreateDto struct { - Specialist_Id *uint16 `json:"specialist_id" validate:"required"` - Code string `json:"code" validate:"maxLength=10;required"` - Name string `json:"name" validate:"maxLength=30;required"` - HeadStatus bool `json:"headStatus"` - Employee_Id *uint `json:"employee_id"` + Specialist_Code *string `json:"specialist_code" validate:"required"` + Code string `json:"code" validate:"maxLength=10;required"` + Name string `json:"name" validate:"maxLength=30;required"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` } type ReadListDto struct { @@ -22,26 +22,27 @@ type ReadListDto struct { } type FilterDto struct { - Specialist_Id *uint16 `json:"specialist-id"` - Code string `json:"code"` - Name string `json:"name"` - HeadStatus *bool `json:"head-status"` - Employee_Id *uint `json:"employee-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Specialist_Code *string `json:"specialist-code"` + Code string `json:"code"` + Name string `json:"name"` + HeadStatus *bool `json:"head-status"` + Employee_Id *uint `json:"employee-id"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,24 +53,24 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,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"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,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"` } func (d SpecialistPosition) ToResponse() ResponseDto { resp := ResponseDto{ - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Code: d.Code, - Name: d.Name, - HeadStatus: d.HeadStatus, - Employee_Id: d.Employee_Id, - Employee: d.Employee, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Code: d.Code, + Name: d.Name, + HeadStatus: d.HeadStatus, + Employee_Id: d.Employee_Id, + Employee: d.Employee, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/specialist/dto.go b/internal/domain/main-entities/specialist/dto.go index 8724b9c5..a67a830f 100644 --- a/internal/domain/main-entities/specialist/dto.go +++ b/internal/domain/main-entities/specialist/dto.go @@ -8,9 +8,9 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Unit_Id *uint16 `json:"unit_id"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + Unit_Code *string `json:"unit_code"` } type ReadListDto struct { @@ -21,25 +21,26 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` - Unit_Id *uint16 `json:"unit-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code string `json:"code"` + Name string `json:"name"` + Unit_Code *string `json:"unit-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Includes string `json:"includes"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,7 +53,7 @@ type ResponseDto struct { ecore.SmallMain Code string `json:"code"` Name string `json:"name"` - Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty"` SpecialistPositions []espb.Basic `json:"specialistPositions,omitempty"` Subspecialists []essb.Basic `json:"subspecialists,omitempty"` @@ -63,7 +64,7 @@ func (d Specialist) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, Unit: d.Unit, - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, SpecialistPositions: d.SpecialistPositions, Subspecialists: d.Subspecialists, } diff --git a/internal/domain/main-entities/specialist/entity.go b/internal/domain/main-entities/specialist/entity.go index 9efb83b0..912d433f 100644 --- a/internal/domain/main-entities/specialist/entity.go +++ b/internal/domain/main-entities/specialist/entity.go @@ -12,6 +12,7 @@ type Specialist struct { Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code" gorm:"size:10"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id"` SpecialistPositions []eub.Basic `json:"specialistPositions,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` Subspecialists []essb.Basic `json:"subspecialists,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` diff --git a/internal/domain/main-entities/subspecialist-position/base/entity.go b/internal/domain/main-entities/subspecialist-position/base/entity.go index 147fcecb..a0bd0834 100644 --- a/internal/domain/main-entities/subspecialist-position/base/entity.go +++ b/internal/domain/main-entities/subspecialist-position/base/entity.go @@ -6,13 +6,14 @@ import ( ) type Basic struct { - ecore.SmallMain // adjust this according to the needs - Subspecialist_Id *uint16 `json:"subspecialist_id" gorm:"not null"` - Code string `json:"code" gorm:"unique;size:10;not null"` - Name string `json:"name" gorm:"size:30;not null"` - HeadStatus bool `json:"headStatus"` - Employee_Id *uint `json:"employee_id"` - Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` + ecore.SmallMain // adjust this according to the needs + Subspecialist_Id *uint16 `json:"subspecialist_id" gorm:"not null"` + Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` + Code string `json:"code" gorm:"unique;size:10;not null"` + Name string `json:"name" gorm:"size:30;not null"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` } func (Basic) TableName() string { diff --git a/internal/domain/main-entities/subspecialist-position/dto.go b/internal/domain/main-entities/subspecialist-position/dto.go index 3c65841e..13532ab8 100644 --- a/internal/domain/main-entities/subspecialist-position/dto.go +++ b/internal/domain/main-entities/subspecialist-position/dto.go @@ -7,11 +7,11 @@ import ( ) type CreateDto struct { - Subspecialist_Id *uint16 `json:"subspecialist_id" validate:"required"` - Code string `json:"code" validate:"maxLength=10;required"` - Name string `json:"name" validate:"maxLength=30;required"` - HeadStatus bool `json:"headStatus"` - Employee_Id *uint `json:"employee_id"` + Subspecialist_Code *string `json:"subspecialist_code" validate:"required"` + Code string `json:"code" validate:"maxLength=10;required"` + Name string `json:"name" validate:"maxLength=30;required"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` } type ReadListDto struct { @@ -22,26 +22,27 @@ type ReadListDto struct { } type FilterDto struct { - Subspecialist_Id *uint16 `json:"subspecialist-id"` - Code string `json:"code"` - Name string `json:"name"` - HeadStatus *bool `json:"head-status"` - Employee_Id *uint `json:"employee-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Subspecialist_Code *string `json:"subspecialist-code"` + Code string `json:"code"` + Name string `json:"name"` + HeadStatus *bool `json:"head-status"` + Employee_Id *uint `json:"employee-id"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,24 +53,24 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *es.Subspecialist `json:"subspecialist,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"` + Subspecialist_Code *string `json:"subspecialist_id"` + Subspecialist *es.Subspecialist `json:"subspecialist,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"` } func (d SubspecialistPosition) ToResponse() ResponseDto { resp := ResponseDto{ - Subspecialist_Id: d.Subspecialist_Id, - Subspecialist: d.Subspecialist, - Code: d.Code, - Name: d.Name, - HeadStatus: d.HeadStatus, - Employee_Id: d.Employee_Id, - Employee: d.Employee, + Subspecialist_Code: d.Subspecialist_Code, + Subspecialist: d.Subspecialist, + Code: d.Code, + Name: d.Name, + HeadStatus: d.HeadStatus, + Employee_Id: d.Employee_Id, + Employee: d.Employee, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/subspecialist/base/entity.go b/internal/domain/main-entities/subspecialist/base/entity.go index bc516360..c89cb8f2 100644 --- a/internal/domain/main-entities/subspecialist/base/entity.go +++ b/internal/domain/main-entities/subspecialist/base/entity.go @@ -9,6 +9,7 @@ type Basic struct { Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` Specialist_Id *uint16 `json:"specialist_id"` + Specialist_Code *string `json:"specialist_code" gorm:"size:10"` } func (Basic) TableName() string { diff --git a/internal/domain/main-entities/subspecialist/dto.go b/internal/domain/main-entities/subspecialist/dto.go index 9a93394d..5ec895d6 100644 --- a/internal/domain/main-entities/subspecialist/dto.go +++ b/internal/domain/main-entities/subspecialist/dto.go @@ -27,18 +27,19 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Includes string `json:"includes"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -49,20 +50,20 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Code string `json:"code"` - Name string `json:"name"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist []espb.Basic `json:"subspecialistPositions,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + Specialist_Code *string `json:"specialist_ccode"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Subspecialist []espb.Basic `json:"subspecialistPositions,omitempty"` } func (d Subspecialist) ToResponse() ResponseDto { resp := ResponseDto{ - Code: d.Code, - Name: d.Name, - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Subspecialist: d.SubspecialistPositions, + Code: d.Code, + Name: d.Name, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Subspecialist: d.SubspecialistPositions, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 0a6a917a..abed5f2d 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -314,16 +314,16 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/medical-action-src", medicalactionsrc.O) hc.RegCrud(r, "/v1/medical-action-src-item", medicalactionsrcitem.O) hc.RegCrud(r, "/v1/language", language.O) - hc.RegCrud(r, "/v1/specialist", specialist.O) - hc.RegCrud(r, "/v1/subspecialist", subspecialist.O) hc.RegCrud(r, "/v1/mcu-sub-src", mcusubsrc.O) hc.RegCrud(r, "/v1/vehicle", vehicle.O) hc.RegCrud(r, "/v1/vehicle-hist", vehiclehist.O) hc.RegCrud(r, "/v1/edu-assessment", eduassesment.O) hc.RegCrud(r, "/v1/installation-position", installationposition.O) hc.RegCrud(r, "/v1/unit-position", unitposition.O) - hc.RegCrud(r, "/v1/specialist-position", specialistposition.O) - hc.RegCrud(r, "/v1/subspecialist-position", subspecialistposition.O) + hc.RegCrudByCode(r, "/v1/specialist", specialist.O) + hc.RegCrudByCode(r, "/v1/subspecialist", subspecialist.O) + hc.RegCrudByCode(r, "/v1/specialist-position", specialistposition.O) + hc.RegCrudByCode(r, "/v1/subspecialist-position", subspecialistposition.O) hc.RegCrud(r, "/v1/village", village.O) hc.RegCrud(r, "/v1/district", district.O) diff --git a/internal/interface/main-handler/specialist-position/handler.go b/internal/interface/main-handler/specialist-position/handler.go index d16c2c7e..4d6376a1 100644 --- a/internal/interface/main-handler/specialist-position/handler.go +++ b/internal/interface/main-handler/specialist-position/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/specialist/handler.go b/internal/interface/main-handler/specialist/handler.go index d3a074d8..246da8f4 100644 --- a/internal/interface/main-handler/specialist/handler.go +++ b/internal/interface/main-handler/specialist/handler.go @@ -33,21 +33,21 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} sf.UrlQueryParam(&dto, *r.URL) - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -55,19 +55,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/subspecialist-position/handler.go b/internal/interface/main-handler/subspecialist-position/handler.go index d8e27b14..e33c62b8 100644 --- a/internal/interface/main-handler/subspecialist-position/handler.go +++ b/internal/interface/main-handler/subspecialist-position/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/subspecialist/handler.go b/internal/interface/main-handler/subspecialist/handler.go index c4b933b4..0e5a41d0 100644 --- a/internal/interface/main-handler/subspecialist/handler.go +++ b/internal/interface/main-handler/subspecialist/handler.go @@ -33,21 +33,21 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} sf.UrlQueryParam(&dto, *r.URL) - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -55,19 +55,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/main-use-case/specialist-position/case.go b/internal/use-case/main-use-case/specialist-position/case.go index c3c469e6..2addf80d 100644 --- a/internal/use-case/main-use-case/specialist-position/case.go +++ b/internal/use-case/main-use-case/specialist-position/case.go @@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { func validateForeignKey(input e.CreateDto) error { // validate installation_id - if _, err := us.ReadDetail(es.ReadDetailDto{Id: *input.Specialist_Id}); err != nil { + if _, err := us.ReadDetail(es.ReadDetailDto{Code: input.Specialist_Code}); err != nil { return err } diff --git a/internal/use-case/main-use-case/specialist-position/helper.go b/internal/use-case/main-use-case/specialist-position/helper.go index 6c3d6434..43aaeb20 100644 --- a/internal/use-case/main-use-case/specialist-position/helper.go +++ b/internal/use-case/main-use-case/specialist-position/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.SpecialistPosition) inputSrc = &inputTemp.CreateDto } - data.Specialist_Id = inputSrc.Specialist_Id + data.Specialist_Code = inputSrc.Specialist_Code data.Code = inputSrc.Code data.Name = inputSrc.Name data.HeadStatus = inputSrc.HeadStatus diff --git a/internal/use-case/main-use-case/specialist-position/lib.go b/internal/use-case/main-use-case/specialist-position/lib.go index 3ae54f50..13c84f28 100644 --- a/internal/use-case/main-use-case/specialist-position/lib.go +++ b/internal/use-case/main-use-case/specialist-position/lib.go @@ -83,7 +83,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e } switch { - case input.Id != 0: + case input.Id != nil: getData = tx.First(&data, input.Id) case input.Code != nil && *input.Code != "": getData = tx.Where("code = ?", *input.Code).First(&data) diff --git a/internal/use-case/main-use-case/specialist/case.go b/internal/use-case/main-use-case/specialist/case.go index 229544be..c51a0002 100644 --- a/internal/use-case/main-use-case/specialist/case.go +++ b/internal/use-case/main-use-case/specialist/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Specialist var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Specialist var err error diff --git a/internal/use-case/main-use-case/specialist/helper.go b/internal/use-case/main-use-case/specialist/helper.go index 9c1e42fc..5c59b1cf 100644 --- a/internal/use-case/main-use-case/specialist/helper.go +++ b/internal/use-case/main-use-case/specialist/helper.go @@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Specialist) { data.Code = inputSrc.Code data.Name = inputSrc.Name - data.Unit_Id = inputSrc.Unit_Id + data.Unit_Code = inputSrc.Unit_Code } diff --git a/internal/use-case/main-use-case/subspecialist-position/case.go b/internal/use-case/main-use-case/subspecialist-position/case.go index d954427a..0069a753 100644 --- a/internal/use-case/main-use-case/subspecialist-position/case.go +++ b/internal/use-case/main-use-case/subspecialist-position/case.go @@ -175,7 +175,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.SubspecialistPosition var err error @@ -235,7 +235,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.SubspecialistPosition var err error @@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { func validateForeignKey(input e.CreateDto) error { // validate installation_id - if _, err := us.ReadDetail(es.ReadDetailDto{Id: *input.Subspecialist_Id}); err != nil { + if _, err := us.ReadDetail(es.ReadDetailDto{Code: input.Subspecialist_Code}); err != nil { return err } diff --git a/internal/use-case/main-use-case/subspecialist-position/helper.go b/internal/use-case/main-use-case/subspecialist-position/helper.go index 1f4c9b2b..16ff54e0 100644 --- a/internal/use-case/main-use-case/subspecialist-position/helper.go +++ b/internal/use-case/main-use-case/subspecialist-position/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.SubspecialistPositi inputSrc = &inputTemp.CreateDto } - data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Subspecialist_Code = inputSrc.Subspecialist_Code data.Code = inputSrc.Code data.Name = inputSrc.Name data.HeadStatus = inputSrc.HeadStatus diff --git a/internal/use-case/main-use-case/subspecialist-position/lib.go b/internal/use-case/main-use-case/subspecialist-position/lib.go index 136e982e..edb422dd 100644 --- a/internal/use-case/main-use-case/subspecialist-position/lib.go +++ b/internal/use-case/main-use-case/subspecialist-position/lib.go @@ -83,10 +83,10 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e } switch { - case input.Id != 0: + case input.Id != nil: getData = tx.First(&data, input.Id) case input.Code != nil && *input.Code != "": - getData = tx.Where("code = ?", *input.Code).First(&data) + getData = tx.Where("\"Code\" = ?", *input.Code).First(&data) default: event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ diff --git a/internal/use-case/main-use-case/subspecialist/case.go b/internal/use-case/main-use-case/subspecialist/case.go index 50498b2a..42366adf 100644 --- a/internal/use-case/main-use-case/subspecialist/case.go +++ b/internal/use-case/main-use-case/subspecialist/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Subspecialist var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Subspecialist var err error diff --git a/internal/use-case/main-use-case/subspecialist/lib.go b/internal/use-case/main-use-case/subspecialist/lib.go index 46ec11f2..a6c4dbc5 100644 --- a/internal/use-case/main-use-case/subspecialist/lib.go +++ b/internal/use-case/main-use-case/subspecialist/lib.go @@ -81,6 +81,13 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + if err := tx. Scopes(gh.Preload(input.Includes)). First(&data, input.Id).Error; err != nil { diff --git a/pkg/handler-crud-helper/handler-crud-helper.go b/pkg/handler-crud-helper/handler-crud-helper.go index d7da62f4..df475094 100644 --- a/pkg/handler-crud-helper/handler-crud-helper.go +++ b/pkg/handler-crud-helper/handler-crud-helper.go @@ -40,3 +40,37 @@ func RegCrud(r *http.ServeMux, path string, mwAndRouter ...any) { "DELETE /{id}": c.Delete, }) } + +func RegCrudByCode(r *http.ServeMux, path string, mwAndRouter ...any) { + sLength := len(mwAndRouter) + + mwCandidates := mwAndRouter[:sLength-1] + mwList := []hk.HandlerMw{} + for i := range mwCandidates { + // have to do it manually, since casting directly results unexpected result + myType := reflect.TypeOf(mwCandidates[i]) + if myType.String() != "func(http.Handler) http.Handler" { + panic("non middleware included as middleware") + } + mwList = append(mwList, mwCandidates[i].(func(http.Handler) http.Handler)) + + // if g, okHandler := mwCandidates[i].(func(http.Handler) http.Handler); !okHandler { + // panic("non middleware included") + // } else { + // mwList = append(mwList, g) + // } + } + + c, ok := mwAndRouter[sLength-1].(CrudBase) + if !ok { + panic("non CrudBase used in the last paramter") + } + + hk.GroupRoutes(path, r, mwList, hk.MapHandlerFunc{ + "POST /": c.Create, + "GET /": c.GetList, + "GET /{code}": c.GetDetail, + "PATCH /{code}": c.Update, + "DELETE /{code}": c.Delete, + }) +} From e821dc0347879c0f607b03b223e8429ede768778 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 14:32:54 +0700 Subject: [PATCH 35/55] remove ids fk --- cmd/main-migration/migrations/20251106073157.sql | 8 ++++++++ cmd/main-migration/migrations/atlas.sum | 3 ++- .../specialist-position/base/entity.go | 1 - .../main-entities/specialist-position/entity.go | 2 +- .../domain/main-entities/specialist/entity.go | 7 +++---- .../subspecialist-position/base/entity.go | 1 - .../subspecialist-position/entity.go | 2 +- .../main-entities/subspecialist/base/entity.go | 1 - .../domain/main-entities/subspecialist/dto.go | 16 ++++++++-------- .../domain/main-entities/subspecialist/entity.go | 4 ++-- .../main-use-case/subspecialist/helper.go | 2 +- 11 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106073157.sql diff --git a/cmd/main-migration/migrations/20251106073157.sql b/cmd/main-migration/migrations/20251106073157.sql new file mode 100644 index 00000000..1cac4860 --- /dev/null +++ b/cmd/main-migration/migrations/20251106073157.sql @@ -0,0 +1,8 @@ +-- Modify "Specialist" table +ALTER TABLE "public"."Specialist" DROP CONSTRAINT "fk_Specialist_Unit", DROP COLUMN "Unit_Id", ADD CONSTRAINT "fk_Specialist_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "SpecialistPosition" table +ALTER TABLE "public"."SpecialistPosition" DROP CONSTRAINT "fk_SpecialistPosition_Specialist", DROP COLUMN "Specialist_Id", ADD CONSTRAINT "fk_SpecialistPosition_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Subspecialist" table +ALTER TABLE "public"."Subspecialist" DROP CONSTRAINT "fk_Subspecialist_Specialist", DROP COLUMN "Specialist_Id", ADD CONSTRAINT "fk_Subspecialist_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "SubspecialistPosition" table +ALTER TABLE "public"."SubspecialistPosition" DROP CONSTRAINT "fk_SubspecialistPosition_Subspecialist", DROP COLUMN "Subspecialist_Id", ADD CONSTRAINT "fk_SubspecialistPosition_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index fd8a8979..a0715aa2 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:CT5nygEUOdVE27HmnMPqwLegXYbJ41grmTvFn7AH8D8= +h1:cgdcTn/j8rHYtIwewbtRo4C+ybSGaJgHR2Fpstbj6/o= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -78,3 +78,4 @@ h1:CT5nygEUOdVE27HmnMPqwLegXYbJ41grmTvFn7AH8D8= 20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= 20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= 20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= diff --git a/internal/domain/main-entities/specialist-position/base/entity.go b/internal/domain/main-entities/specialist-position/base/entity.go index 5db268cd..b4a0abb2 100644 --- a/internal/domain/main-entities/specialist-position/base/entity.go +++ b/internal/domain/main-entities/specialist-position/base/entity.go @@ -7,7 +7,6 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs - Specialist_Id *uint16 `json:"specialist_id" gorm:"not null"` Specialist_Code *string `json:"specialist_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` diff --git a/internal/domain/main-entities/specialist-position/entity.go b/internal/domain/main-entities/specialist-position/entity.go index 26c1d27f..429e5554 100644 --- a/internal/domain/main-entities/specialist-position/entity.go +++ b/internal/domain/main-entities/specialist-position/entity.go @@ -7,5 +7,5 @@ import ( type SpecialistPosition struct { esb.Basic - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` } diff --git a/internal/domain/main-entities/specialist/entity.go b/internal/domain/main-entities/specialist/entity.go index 912d433f..4fef90a5 100644 --- a/internal/domain/main-entities/specialist/entity.go +++ b/internal/domain/main-entities/specialist/entity.go @@ -11,9 +11,8 @@ type Specialist struct { ecore.SmallMain // adjust this according to the needs Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` - Unit_Id *uint16 `json:"unit_id"` Unit_Code *string `json:"unit_code" gorm:"size:10"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id"` - SpecialistPositions []eub.Basic `json:"specialistPositions,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` - Subspecialists []essb.Basic `json:"subspecialists,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` + SpecialistPositions []eub.Basic `json:"specialistPositions,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` + Subspecialists []essb.Basic `json:"subspecialists,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` } diff --git a/internal/domain/main-entities/subspecialist-position/base/entity.go b/internal/domain/main-entities/subspecialist-position/base/entity.go index a0bd0834..cb98dff6 100644 --- a/internal/domain/main-entities/subspecialist-position/base/entity.go +++ b/internal/domain/main-entities/subspecialist-position/base/entity.go @@ -7,7 +7,6 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs - Subspecialist_Id *uint16 `json:"subspecialist_id" gorm:"not null"` Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` diff --git a/internal/domain/main-entities/subspecialist-position/entity.go b/internal/domain/main-entities/subspecialist-position/entity.go index 28a205ed..2deaf8b7 100644 --- a/internal/domain/main-entities/subspecialist-position/entity.go +++ b/internal/domain/main-entities/subspecialist-position/entity.go @@ -7,5 +7,5 @@ import ( type SubspecialistPosition struct { esb.Basic - Subspecialist *es.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Subspecialist *es.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` } diff --git a/internal/domain/main-entities/subspecialist/base/entity.go b/internal/domain/main-entities/subspecialist/base/entity.go index c89cb8f2..a94fb76d 100644 --- a/internal/domain/main-entities/subspecialist/base/entity.go +++ b/internal/domain/main-entities/subspecialist/base/entity.go @@ -8,7 +8,6 @@ type Basic struct { ecore.SmallMain // adjust this according to the needs Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` - Specialist_Id *uint16 `json:"specialist_id"` Specialist_Code *string `json:"specialist_code" gorm:"size:10"` } diff --git a/internal/domain/main-entities/subspecialist/dto.go b/internal/domain/main-entities/subspecialist/dto.go index 5ec895d6..6e10b573 100644 --- a/internal/domain/main-entities/subspecialist/dto.go +++ b/internal/domain/main-entities/subspecialist/dto.go @@ -7,9 +7,9 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Specialist_Id *uint16 `json:"specialist_id"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + Specialist_Code *string `json:"specialist_code"` } type ReadListDto struct { @@ -20,10 +20,10 @@ type ReadListDto struct { } type FilterDto struct { - Code *string `json:"code"` - Name *string `json:"name"` - Specialist_Id *uint16 `json:"specialist-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code *string `json:"code"` + Name *string `json:"name"` + Specialist_Code *string `json:"specialist-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { @@ -52,7 +52,7 @@ type ResponseDto struct { ecore.SmallMain Code string `json:"code"` Name string `json:"name"` - Specialist_Code *string `json:"specialist_ccode"` + Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty"` Subspecialist []espb.Basic `json:"subspecialistPositions,omitempty"` } diff --git a/internal/domain/main-entities/subspecialist/entity.go b/internal/domain/main-entities/subspecialist/entity.go index f2ff5d8e..44a40d4a 100644 --- a/internal/domain/main-entities/subspecialist/entity.go +++ b/internal/domain/main-entities/subspecialist/entity.go @@ -8,6 +8,6 @@ import ( type Subspecialist struct { esb.Basic - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - SubspecialistPositions []espb.Basic `json:"subspecialistPositions,omitempty" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` + SubspecialistPositions []espb.Basic `json:"subspecialistPositions,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` } diff --git a/internal/use-case/main-use-case/subspecialist/helper.go b/internal/use-case/main-use-case/subspecialist/helper.go index 5d04093f..08d64941 100644 --- a/internal/use-case/main-use-case/subspecialist/helper.go +++ b/internal/use-case/main-use-case/subspecialist/helper.go @@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Subspecialist) { data.Code = inputSrc.Code data.Name = inputSrc.Name - data.Specialist_Id = inputSrc.Specialist_Id + data.Specialist_Code = inputSrc.Specialist_Code } From 5ba60938df98909020425756037b190a7ca72c0b Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 14:46:06 +0700 Subject: [PATCH 36/55] division, division-position ids into codes --- cmd/main-migration/migrations/20251106074218.sql | 4 ++++ cmd/main-migration/migrations/atlas.sum | 3 ++- .../domain/main-entities/division-position/base/entity.go | 1 + internal/domain/main-entities/division/entity.go | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 cmd/main-migration/migrations/20251106074218.sql diff --git a/cmd/main-migration/migrations/20251106074218.sql b/cmd/main-migration/migrations/20251106074218.sql new file mode 100644 index 00000000..f7536b57 --- /dev/null +++ b/cmd/main-migration/migrations/20251106074218.sql @@ -0,0 +1,4 @@ +-- Modify "Division" table +ALTER TABLE "public"."Division" ADD COLUMN "Parent_Code" character varying(10) NULL; +-- Modify "DivisionPosition" table +ALTER TABLE "public"."DivisionPosition" ADD COLUMN "Division_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index a0715aa2..5a963973 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:cgdcTn/j8rHYtIwewbtRo4C+ybSGaJgHR2Fpstbj6/o= +h1:aVDoCaB6Gy2SKHrUbR2KDqH9ByMHPVcYzTGW5846kt8= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -79,3 +79,4 @@ h1:cgdcTn/j8rHYtIwewbtRo4C+ybSGaJgHR2Fpstbj6/o= 20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= 20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= 20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= diff --git a/internal/domain/main-entities/division-position/base/entity.go b/internal/domain/main-entities/division-position/base/entity.go index ce8f3175..b2635553 100644 --- a/internal/domain/main-entities/division-position/base/entity.go +++ b/internal/domain/main-entities/division-position/base/entity.go @@ -8,6 +8,7 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs Division_Id *uint16 `json:"division_id"` + Division_Code *string `json:"division_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` HeadStatus bool `json:"headStatus"` diff --git a/internal/domain/main-entities/division/entity.go b/internal/domain/main-entities/division/entity.go index 4051c138..bcef1c7f 100644 --- a/internal/domain/main-entities/division/entity.go +++ b/internal/domain/main-entities/division/entity.go @@ -10,6 +10,7 @@ type Division struct { Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` Parent_Id *uint16 `json:"parent_id"` + Parent_Code *string `json:"parent_code" gorm:"size:10"` Parent *Division `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"` Childrens []Division `json:"childrens" gorm:"foreignKey:Parent_Id"` // may need references to self DivisionPositions []edpb.Basic `json:"divisionPositions,omitempty" gorm:"foreignKey:Division_Id;references:Id"` From b597b76092b58c3aa8f92efe4fca2941023895e1 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 15:24:42 +0700 Subject: [PATCH 37/55] division, division-position ids into codes --- .../migrations/20251106081846.sql | 6 ++ cmd/main-migration/migrations/atlas.sum | 3 +- .../division-position/base/entity.go | 1 - .../main-entities/division-position/dto.go | 55 ++++++++++--------- .../main-entities/division-position/entity.go | 2 +- internal/domain/main-entities/division/dto.go | 25 +++++---- .../domain/main-entities/division/entity.go | 9 ++- .../main-handler/division-position/handler.go | 18 +++--- .../main-handler/division/handler.go | 18 +++--- .../interface/main-handler/main-handler.go | 4 +- .../main-use-case/division-position/case.go | 4 +- .../main-use-case/division-position/helper.go | 2 +- .../main-use-case/division-position/lib.go | 9 ++- .../use-case/main-use-case/division/case.go | 4 +- .../use-case/main-use-case/division/helper.go | 2 +- .../use-case/main-use-case/division/lib.go | 9 ++- 16 files changed, 96 insertions(+), 75 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106081846.sql diff --git a/cmd/main-migration/migrations/20251106081846.sql b/cmd/main-migration/migrations/20251106081846.sql new file mode 100644 index 00000000..352d6a39 --- /dev/null +++ b/cmd/main-migration/migrations/20251106081846.sql @@ -0,0 +1,6 @@ +-- Create index "idx_Division_Code" to table: "Division" +CREATE UNIQUE INDEX "idx_Division_Code" ON "public"."Division" ("Code"); +-- Modify "Division" table +ALTER TABLE "public"."Division" DROP CONSTRAINT "uni_Division_Code", DROP CONSTRAINT "fk_Division_Childrens", DROP COLUMN "Parent_Id", ADD CONSTRAINT "fk_Division_Childrens" FOREIGN KEY ("Parent_Code") REFERENCES "public"."Division" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "DivisionPosition" table +ALTER TABLE "public"."DivisionPosition" DROP CONSTRAINT "fk_DivisionPosition_Division", DROP COLUMN "Division_Id", ADD CONSTRAINT "fk_DivisionPosition_Division" FOREIGN KEY ("Division_Code") REFERENCES "public"."Division" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 5a963973..9f504821 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:aVDoCaB6Gy2SKHrUbR2KDqH9ByMHPVcYzTGW5846kt8= +h1:gZkp4dTWkJKTmsiLhz5DI6QMvJuBGfurq4lkNKPThjU= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -80,3 +80,4 @@ h1:aVDoCaB6Gy2SKHrUbR2KDqH9ByMHPVcYzTGW5846kt8= 20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= 20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= 20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= diff --git a/internal/domain/main-entities/division-position/base/entity.go b/internal/domain/main-entities/division-position/base/entity.go index b2635553..6cf79b45 100644 --- a/internal/domain/main-entities/division-position/base/entity.go +++ b/internal/domain/main-entities/division-position/base/entity.go @@ -7,7 +7,6 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs - Division_Id *uint16 `json:"division_id"` Division_Code *string `json:"division_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` diff --git a/internal/domain/main-entities/division-position/dto.go b/internal/domain/main-entities/division-position/dto.go index b93e0e98..55af6bf8 100644 --- a/internal/domain/main-entities/division-position/dto.go +++ b/internal/domain/main-entities/division-position/dto.go @@ -7,11 +7,11 @@ import ( ) 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"` + Division_Code *string `json:"division_code"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` } type ReadListDto struct { @@ -22,26 +22,27 @@ type ReadListDto struct { } 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"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Division_Code *string `json:"division-code"` + Code string `json:"code"` + Name string `json:"name"` + HeadStatus *bool `json:"head-status"` + Employee_Id *uint `json:"employee-id"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,23 +53,23 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Division_Id *uint16 `json:"division_id"` - 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"` + Division_Code *string `json:"division_code"` + 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"` } func (d DivisionPosition) ToResponse() ResponseDto { resp := ResponseDto{ - Division_Id: d.Division_Id, - Code: d.Code, - Name: d.Name, - HeadStatus: d.HeadStatus, - Employee_Id: d.Employee_Id, - Employee: d.Employee, + Division_Code: d.Division_Code, + Code: d.Code, + Name: d.Name, + HeadStatus: d.HeadStatus, + Employee_Id: d.Employee_Id, + Employee: d.Employee, } resp.SmallMain = d.SmallMain if d.Division != nil { diff --git a/internal/domain/main-entities/division-position/entity.go b/internal/domain/main-entities/division-position/entity.go index d71ba01c..d654d21f 100644 --- a/internal/domain/main-entities/division-position/entity.go +++ b/internal/domain/main-entities/division-position/entity.go @@ -7,5 +7,5 @@ import ( type DivisionPosition struct { eb.Basic - Division *ed.Division `json:"division" gorm:"foreignKey:Division_Id;references:Id"` + Division *ed.Division `json:"division" gorm:"foreignKey:Division_Code;references:Code"` } diff --git a/internal/domain/main-entities/division/dto.go b/internal/domain/main-entities/division/dto.go index 38915b56..30f0b238 100644 --- a/internal/domain/main-entities/division/dto.go +++ b/internal/domain/main-entities/division/dto.go @@ -6,9 +6,9 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Parent_Id *uint16 `json:"parent_id"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + Parent_Code *string `json:"parent_code"` } type ReadListDto struct { @@ -20,25 +20,26 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` - Parent_Id *uint16 `json:"parent-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code string `json:"code"` + Name string `json:"name"` + Parent_Code *string `json:"parent-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Includes string `json:"includes"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -51,7 +52,7 @@ type ResponseDto struct { ecore.SmallMain Code string `json:"code"` Name string `json:"name"` - Parent_Id *uint16 `json:"parent_id"` + Parent_Code *string `json:"parent_code"` Parent *Division `json:"parent,omitempty"` Childrens []Division `json:"childrens,omitempty"` DivisionPosition []edpb.Basic `json:"divisionPositions,omitempty"` @@ -61,7 +62,7 @@ func (d Division) ToResponse() ResponseDto { resp := ResponseDto{ Code: d.Code, Name: d.Name, - Parent_Id: d.Parent_Id, + Parent_Code: d.Parent_Code, Parent: d.Parent, Childrens: d.Childrens, DivisionPosition: d.DivisionPositions, diff --git a/internal/domain/main-entities/division/entity.go b/internal/domain/main-entities/division/entity.go index bcef1c7f..d79e9e86 100644 --- a/internal/domain/main-entities/division/entity.go +++ b/internal/domain/main-entities/division/entity.go @@ -7,11 +7,10 @@ import ( type Division struct { ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` + Code string `json:"code" gorm:"uniqueIndex;size:10"` Name string `json:"name" gorm:"size:50"` - Parent_Id *uint16 `json:"parent_id"` Parent_Code *string `json:"parent_code" gorm:"size:10"` - Parent *Division `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"` - Childrens []Division `json:"childrens" gorm:"foreignKey:Parent_Id"` // may need references to self - DivisionPositions []edpb.Basic `json:"divisionPositions,omitempty" gorm:"foreignKey:Division_Id;references:Id"` + Parent *Division `json:"parent" gorm:"foreignKey:Parent_Code;references:Code"` + Childrens []Division `json:"childrens" gorm:"foreignKey:Parent_Code;references:Code"` // may need references to self + DivisionPositions []edpb.Basic `json:"divisionPositions,omitempty" gorm:"foreignKey:Division_Code;references:Code"` } diff --git a/internal/interface/main-handler/division-position/handler.go b/internal/interface/main-handler/division-position/handler.go index 180b96ea..3b0f9627 100644 --- a/internal/interface/main-handler/division-position/handler.go +++ b/internal/interface/main-handler/division-position/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/division/handler.go b/internal/interface/main-handler/division/handler.go index ee4cbea5..640c180e 100644 --- a/internal/interface/main-handler/division/handler.go +++ b/internal/interface/main-handler/division/handler.go @@ -33,21 +33,21 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} sf.UrlQueryParam(&dto, *r.URL) - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -55,19 +55,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index abed5f2d..071e7e24 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -290,8 +290,8 @@ func SetRoutes() http.Handler { }) /******************** sources ********************/ - hc.RegCrud(r, "/v1/division", division.O) - hc.RegCrud(r, "/v1/division-position", divisionposition.O) + hc.RegCrudByCode(r, "/v1/division", division.O) + hc.RegCrudByCode(r, "/v1/division-position", divisionposition.O) hc.RegCrud(r, "/v1/installation", installation.O) hc.RegCrud(r, "/v1/unit", unit.O) hc.RegCrud(r, "/v1/pharmacy-company", pharmacycompany.O) diff --git a/internal/use-case/main-use-case/division-position/case.go b/internal/use-case/main-use-case/division-position/case.go index 159e9edc..0490bcfe 100644 --- a/internal/use-case/main-use-case/division-position/case.go +++ b/internal/use-case/main-use-case/division-position/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.DivisionPosition var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.DivisionPosition var err error diff --git a/internal/use-case/main-use-case/division-position/helper.go b/internal/use-case/main-use-case/division-position/helper.go index 482dbc4e..c3e0c71b 100644 --- a/internal/use-case/main-use-case/division-position/helper.go +++ b/internal/use-case/main-use-case/division-position/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.DivisionPosition) { inputSrc = &inputTemp.CreateDto } - data.Division_Id = inputSrc.Division_Id + data.Division_Code = inputSrc.Division_Code data.Code = inputSrc.Code data.Name = inputSrc.Name data.HeadStatus = inputSrc.HeadStatus diff --git a/internal/use-case/main-use-case/division-position/lib.go b/internal/use-case/main-use-case/division-position/lib.go index d1327d47..e5036812 100644 --- a/internal/use-case/main-use-case/division-position/lib.go +++ b/internal/use-case/main-use-case/division-position/lib.go @@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } - if err := tx.First(&data, input.Id).Error; err != nil { + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + 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 } diff --git a/internal/use-case/main-use-case/division/case.go b/internal/use-case/main-use-case/division/case.go index daabd2f8..c955aed7 100644 --- a/internal/use-case/main-use-case/division/case.go +++ b/internal/use-case/main-use-case/division/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Division var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Division var err error diff --git a/internal/use-case/main-use-case/division/helper.go b/internal/use-case/main-use-case/division/helper.go index c0341ee0..2bb7a932 100644 --- a/internal/use-case/main-use-case/division/helper.go +++ b/internal/use-case/main-use-case/division/helper.go @@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Division) { data.Code = inputSrc.Code data.Name = inputSrc.Name - data.Parent_Id = inputSrc.Parent_Id + data.Parent_Code = inputSrc.Parent_Code } diff --git a/internal/use-case/main-use-case/division/lib.go b/internal/use-case/main-use-case/division/lib.go index 56ce34f7..62a10d5b 100644 --- a/internal/use-case/main-use-case/division/lib.go +++ b/internal/use-case/main-use-case/division/lib.go @@ -91,9 +91,16 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + if err := tx. Scopes(gh.Preload(input.Includes)). - First(&data, input.Id).Error; err != nil { + First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } From 42b1b48e36d1be9c653dda5a7271be7969d7f837 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 15:32:05 +0700 Subject: [PATCH 38/55] unit,unit-position,installation-position ids into codes --- cmd/main-migration/migrations/20251106082844.sql | 6 ++++++ cmd/main-migration/migrations/atlas.sum | 3 ++- .../installation-position/base/entity.go | 15 ++++++++------- .../main-entities/unit-position/base/entity.go | 1 + internal/domain/main-entities/unit/entity.go | 15 ++++++++------- 5 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106082844.sql diff --git a/cmd/main-migration/migrations/20251106082844.sql b/cmd/main-migration/migrations/20251106082844.sql new file mode 100644 index 00000000..c94fb359 --- /dev/null +++ b/cmd/main-migration/migrations/20251106082844.sql @@ -0,0 +1,6 @@ +-- Modify "InstallationPosition" table +ALTER TABLE "public"."InstallationPosition" ADD COLUMN "Installation_Code" character varying(10) NULL; +-- Modify "Unit" table +ALTER TABLE "public"."Unit" ADD COLUMN "Installation_Code" character varying(10) NULL; +-- Modify "UnitPosition" table +ALTER TABLE "public"."UnitPosition" ADD COLUMN "Unit_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 9f504821..8833af3a 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:gZkp4dTWkJKTmsiLhz5DI6QMvJuBGfurq4lkNKPThjU= +h1:w/qs7zN2FLnTjsmLVrFnMQWMxp3LYDJa0RLY74HVK0g= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -81,3 +81,4 @@ h1:gZkp4dTWkJKTmsiLhz5DI6QMvJuBGfurq4lkNKPThjU= 20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= 20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= 20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= diff --git a/internal/domain/main-entities/installation-position/base/entity.go b/internal/domain/main-entities/installation-position/base/entity.go index 02fbbe84..e5e8c589 100644 --- a/internal/domain/main-entities/installation-position/base/entity.go +++ b/internal/domain/main-entities/installation-position/base/entity.go @@ -6,13 +6,14 @@ import ( ) type Basic struct { - ecore.SmallMain // adjust this according to the needs - Installation_Id *uint16 `json:"installation_id" gorm:"not null"` - Code string `json:"code" gorm:"unique;size:10;not null"` - Name string `json:"name" gorm:"size:30;not null"` - HeadStatus bool `json:"headStatus"` - Employee_Id *uint `json:"employee_id"` - Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` + ecore.SmallMain // adjust this according to the needs + Installation_Id *uint16 `json:"installation_id" gorm:"not null"` + Installation_Code *string `json:"installation_code" gorm:"size:10"` + Code string `json:"code" gorm:"unique;size:10;not null"` + Name string `json:"name" gorm:"size:30;not null"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` } func (Basic) TableName() string { diff --git a/internal/domain/main-entities/unit-position/base/entity.go b/internal/domain/main-entities/unit-position/base/entity.go index b8e6a63a..e7376e51 100644 --- a/internal/domain/main-entities/unit-position/base/entity.go +++ b/internal/domain/main-entities/unit-position/base/entity.go @@ -8,6 +8,7 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs Unit_Id *uint16 `json:"unit_id" gorm:"not null"` + Unit_Code *string `json:"unit_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` HeadStatus bool `json:"headStatus"` diff --git a/internal/domain/main-entities/unit/entity.go b/internal/domain/main-entities/unit/entity.go index 2142790f..254bc163 100644 --- a/internal/domain/main-entities/unit/entity.go +++ b/internal/domain/main-entities/unit/entity.go @@ -8,11 +8,12 @@ import ( ) type Unit struct { - ecore.SmallMain // adjust this according to the needs - Installation_Id *uint16 `json:"installation_id"` - Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Id"` - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - Type_Code *ero.UnitTypeCode `json:"type_code"` - UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` + ecore.SmallMain // adjust this according to the needs + Installation_Id *uint16 `json:"installation_id"` + Installation_Code *string `json:"installation_code" gorm:"size:10"` + Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Id"` + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + Type_Code *ero.UnitTypeCode `json:"type_code"` + UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` } From 6ed038eb543ebd8dffae80c314e4fa5311ae6382 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 15:48:32 +0700 Subject: [PATCH 39/55] unit, unit-position,installation-position removes ids --- .../installation-position/base/entity.go | 1 - .../installation-position/dto.go | 57 ++++++++++--------- .../installation-position/entity.go | 2 +- .../main-entities/installation/entity.go | 2 +- .../unit-position/base/entity.go | 1 - .../domain/main-entities/unit-position/dto.go | 15 ++--- internal/domain/main-entities/unit/dto.go | 45 ++++++++------- internal/domain/main-entities/unit/entity.go | 5 +- .../installation-position/handler.go | 18 +++--- .../interface/main-handler/main-handler.go | 16 +++--- .../main-handler/unit-position/handler.go | 18 +++--- .../interface/main-handler/unit/handler.go | 18 +++--- .../installation-position/case.go | 6 +- .../installation-position/helper.go | 2 +- .../installation-position/lib.go | 4 +- .../main-use-case/unit-position/case.go | 6 +- .../main-use-case/unit-position/helper.go | 2 +- .../main-use-case/unit-position/lib.go | 2 +- internal/use-case/main-use-case/unit/case.go | 4 +- .../use-case/main-use-case/unit/helper.go | 2 +- internal/use-case/main-use-case/unit/lib.go | 9 ++- 21 files changed, 121 insertions(+), 114 deletions(-) diff --git a/internal/domain/main-entities/installation-position/base/entity.go b/internal/domain/main-entities/installation-position/base/entity.go index e5e8c589..3ebc171b 100644 --- a/internal/domain/main-entities/installation-position/base/entity.go +++ b/internal/domain/main-entities/installation-position/base/entity.go @@ -7,7 +7,6 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs - Installation_Id *uint16 `json:"installation_id" gorm:"not null"` Installation_Code *string `json:"installation_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` diff --git a/internal/domain/main-entities/installation-position/dto.go b/internal/domain/main-entities/installation-position/dto.go index aada7443..12e13afc 100644 --- a/internal/domain/main-entities/installation-position/dto.go +++ b/internal/domain/main-entities/installation-position/dto.go @@ -7,11 +7,11 @@ import ( ) type CreateDto struct { - Installation_Id *uint16 `json:"installation_id" validate:"required"` - Code string `json:"code" validate:"maxLength=10;required"` - Name string `json:"name" validate:"maxLength=30;required"` - HeadStatus bool `json:"headStatus"` - Employee_Id *uint `json:"employee_id"` + Installation_Code *string `json:"installation_code" validate:"required"` + Code string `json:"code" validate:"maxLength=10;required"` + Name string `json:"name" validate:"maxLength=30;required"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` } type ReadListDto struct { @@ -22,26 +22,27 @@ type ReadListDto struct { } type FilterDto struct { - Installation_Id *uint16 `json:"installation-id"` - Code string `json:"code"` - Name string `json:"name"` - HeadStatus *bool `json:"head-status"` - Employee_Id *uint `json:"employee-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Installation_Code *string `json:"installation-code"` + Code string `json:"code"` + Name string `json:"name"` + HeadStatus *bool `json:"head-status"` + Employee_Id *uint `json:"employee-id"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,24 +53,24 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Installation_Id *uint16 `json:"installation_id"` - Installation *ei.Installation `json:"installation,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"` + Installation_Code *string `json:"installation_code"` + Installation *ei.Installation `json:"installation,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"` } func (d InstallationPosition) ToResponse() ResponseDto { resp := ResponseDto{ - Installation_Id: d.Installation_Id, - Installation: d.Installation, - Code: d.Code, - Name: d.Name, - HeadStatus: d.HeadStatus, - Employee_Id: d.Employee_Id, - Employee: d.Employee, + Installation_Code: d.Installation_Code, + Installation: d.Installation, + Code: d.Code, + Name: d.Name, + HeadStatus: d.HeadStatus, + Employee_Id: d.Employee_Id, + Employee: d.Employee, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/installation-position/entity.go b/internal/domain/main-entities/installation-position/entity.go index 48e95ac5..ba8ddece 100644 --- a/internal/domain/main-entities/installation-position/entity.go +++ b/internal/domain/main-entities/installation-position/entity.go @@ -7,5 +7,5 @@ import ( type InstallationPosition struct { eib.Basic // adjust this according to the needs - Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_Id;references:Id"` + Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_Code;references:Code"` } diff --git a/internal/domain/main-entities/installation/entity.go b/internal/domain/main-entities/installation/entity.go index dea63a45..5cc82430 100644 --- a/internal/domain/main-entities/installation/entity.go +++ b/internal/domain/main-entities/installation/entity.go @@ -11,5 +11,5 @@ type Installation struct { Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code" gorm:"size:10"` - InstallationPositions []eipb.Basic `json:"installationPositions,omitempty" gorm:"foreignKey:Installation_Id;references:Id"` + InstallationPositions []eipb.Basic `json:"installationPositions,omitempty" gorm:"foreignKey:Installation_Code;references:Code"` } diff --git a/internal/domain/main-entities/unit-position/base/entity.go b/internal/domain/main-entities/unit-position/base/entity.go index e7376e51..eb046dfc 100644 --- a/internal/domain/main-entities/unit-position/base/entity.go +++ b/internal/domain/main-entities/unit-position/base/entity.go @@ -7,7 +7,6 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs - Unit_Id *uint16 `json:"unit_id" gorm:"not null"` Unit_Code *string `json:"unit_code" gorm:"size:10"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` diff --git a/internal/domain/main-entities/unit-position/dto.go b/internal/domain/main-entities/unit-position/dto.go index cc52c493..856cec77 100644 --- a/internal/domain/main-entities/unit-position/dto.go +++ b/internal/domain/main-entities/unit-position/dto.go @@ -7,7 +7,7 @@ import ( ) type CreateDto struct { - Unit_Id *uint16 `json:"unit_id" validate:"required"` + Unit_Code *string `json:"unit_code" validate:"required"` Code string `json:"code" validate:"maxLength=10;required"` Name string `json:"name" validate:"maxLength=30;required"` HeadStatus bool `json:"headStatus"` @@ -22,7 +22,7 @@ type ReadListDto struct { } type FilterDto struct { - Unit_Id *uint16 `json:"unit-id"` + Unit_Code *string `json:"unit-code"` Code string `json:"code"` Name string `json:"name"` HeadStatus *bool `json:"head-status"` @@ -31,17 +31,18 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,7 +53,7 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty"` Code string `json:"code"` Name string `json:"name"` @@ -63,7 +64,7 @@ type ResponseDto struct { func (d UnitPosition) ToResponse() ResponseDto { resp := ResponseDto{ - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, Code: d.Code, Name: d.Name, diff --git a/internal/domain/main-entities/unit/dto.go b/internal/domain/main-entities/unit/dto.go index e47afed9..f272ecec 100644 --- a/internal/domain/main-entities/unit/dto.go +++ b/internal/domain/main-entities/unit/dto.go @@ -7,9 +7,9 @@ import ( ) type CreateDto struct { - Installation_Id *uint16 `json:"installation_id"` - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` + Installation_Code *string `json:"installation_code"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` } type ReadListDto struct { @@ -20,26 +20,27 @@ type ReadListDto struct { } type FilterDto struct { - Installation_Id *uint16 `json:"installation-id"` - Code string `json:"code"` - Name string `json:"name"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Installation_Code *string `json:"installation-code"` + Code string `json:"code"` + Name string `json:"name"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` - Installation_Id *uint16 `json:"installation_id"` - Code *string `json:"code"` - Includes string `json:"includes"` + Id *uint16 `json:"id"` + Installation_Code *string `json:"installation_code"` + Code *string `json:"code"` + Includes string `json:"includes"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -50,19 +51,19 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Installation_Id *uint16 `json:"installation_id"` - Installation *ei.Installation `json:"installation,omitempty"` - Code string `json:"code"` - Name string `json:"name"` - UnitPositions []eipb.Basic `json:"unitPositions,omitempty"` + Installation_Code *string `json:"installation_code"` + Installation *ei.Installation `json:"installation,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + UnitPositions []eipb.Basic `json:"unitPositions,omitempty"` } func (d Unit) ToResponse() ResponseDto { resp := ResponseDto{ - Installation_Id: d.Installation_Id, - Code: d.Code, - Name: d.Name, - UnitPositions: d.UnitPositions, + Installation_Code: d.Installation_Code, + Code: d.Code, + Name: d.Name, + UnitPositions: d.UnitPositions, } resp.SmallMain = d.SmallMain if d.Installation != nil { diff --git a/internal/domain/main-entities/unit/entity.go b/internal/domain/main-entities/unit/entity.go index 254bc163..97db9885 100644 --- a/internal/domain/main-entities/unit/entity.go +++ b/internal/domain/main-entities/unit/entity.go @@ -9,11 +9,10 @@ import ( type Unit struct { ecore.SmallMain // adjust this according to the needs - Installation_Id *uint16 `json:"installation_id"` Installation_Code *string `json:"installation_code" gorm:"size:10"` - Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Id"` + Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Code;references:Code"` Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` Type_Code *ero.UnitTypeCode `json:"type_code"` - UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` + UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` } diff --git a/internal/interface/main-handler/installation-position/handler.go b/internal/interface/main-handler/installation-position/handler.go index 59f35340..57a439be 100644 --- a/internal/interface/main-handler/installation-position/handler.go +++ b/internal/interface/main-handler/installation-position/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 071e7e24..925f9dc6 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -292,8 +292,14 @@ func SetRoutes() http.Handler { /******************** sources ********************/ hc.RegCrudByCode(r, "/v1/division", division.O) hc.RegCrudByCode(r, "/v1/division-position", divisionposition.O) - hc.RegCrud(r, "/v1/installation", installation.O) - hc.RegCrud(r, "/v1/unit", unit.O) + hc.RegCrudByCode(r, "/v1/installation", installation.O) + hc.RegCrudByCode(r, "/v1/unit", unit.O) + hc.RegCrudByCode(r, "/v1/installation-position", installationposition.O) + hc.RegCrudByCode(r, "/v1/unit-position", unitposition.O) + hc.RegCrudByCode(r, "/v1/specialist", specialist.O) + hc.RegCrudByCode(r, "/v1/subspecialist", subspecialist.O) + hc.RegCrudByCode(r, "/v1/specialist-position", specialistposition.O) + hc.RegCrudByCode(r, "/v1/subspecialist-position", subspecialistposition.O) hc.RegCrud(r, "/v1/pharmacy-company", pharmacycompany.O) hc.RegCrud(r, "/v1/diagnose-src", diagnosesrc.O) hc.RegCrud(r, "/v1/procedure-src", proceduresrc.O) @@ -318,12 +324,6 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/vehicle", vehicle.O) hc.RegCrud(r, "/v1/vehicle-hist", vehiclehist.O) hc.RegCrud(r, "/v1/edu-assessment", eduassesment.O) - hc.RegCrud(r, "/v1/installation-position", installationposition.O) - hc.RegCrud(r, "/v1/unit-position", unitposition.O) - hc.RegCrudByCode(r, "/v1/specialist", specialist.O) - hc.RegCrudByCode(r, "/v1/subspecialist", subspecialist.O) - hc.RegCrudByCode(r, "/v1/specialist-position", specialistposition.O) - hc.RegCrudByCode(r, "/v1/subspecialist-position", subspecialistposition.O) hc.RegCrud(r, "/v1/village", village.O) hc.RegCrud(r, "/v1/district", district.O) diff --git a/internal/interface/main-handler/unit-position/handler.go b/internal/interface/main-handler/unit-position/handler.go index 82b89465..7780e80d 100644 --- a/internal/interface/main-handler/unit-position/handler.go +++ b/internal/interface/main-handler/unit-position/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/unit/handler.go b/internal/interface/main-handler/unit/handler.go index a94ce74e..f31667a2 100644 --- a/internal/interface/main-handler/unit/handler.go +++ b/internal/interface/main-handler/unit/handler.go @@ -33,21 +33,21 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} sf.UrlQueryParam(&dto, *r.URL) - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -55,19 +55,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/main-use-case/installation-position/case.go b/internal/use-case/main-use-case/installation-position/case.go index f9458c0b..73e64630 100644 --- a/internal/use-case/main-use-case/installation-position/case.go +++ b/internal/use-case/main-use-case/installation-position/case.go @@ -175,7 +175,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.InstallationPosition var err error @@ -235,7 +235,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.InstallationPosition var err error @@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { func validateForeignKey(input e.CreateDto) error { // validate installation_id - if _, err := ui.ReadDetail(ei.ReadDetailDto{Id: *input.Installation_Id}); err != nil { + if _, err := ui.ReadDetail(ei.ReadDetailDto{Code: input.Installation_Code}); err != nil { return err } diff --git a/internal/use-case/main-use-case/installation-position/helper.go b/internal/use-case/main-use-case/installation-position/helper.go index 640993c8..2d36d402 100644 --- a/internal/use-case/main-use-case/installation-position/helper.go +++ b/internal/use-case/main-use-case/installation-position/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.InstallationPositio inputSrc = &inputTemp.CreateDto } - data.Installation_Id = inputSrc.Installation_Id + data.Installation_Code = inputSrc.Installation_Code data.Code = inputSrc.Code data.Name = inputSrc.Name data.HeadStatus = inputSrc.HeadStatus diff --git a/internal/use-case/main-use-case/installation-position/lib.go b/internal/use-case/main-use-case/installation-position/lib.go index bb33356f..d0cf72b3 100644 --- a/internal/use-case/main-use-case/installation-position/lib.go +++ b/internal/use-case/main-use-case/installation-position/lib.go @@ -83,10 +83,10 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e } switch { - case input.Id != 0: + case input.Id != nil: getData = tx.First(&data, input.Id) case input.Code != nil && *input.Code != "": - getData = tx.Where("code = ?", *input.Code).First(&data) + getData = tx.Where("\"Code\" = ?", *input.Code).First(&data) default: event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ diff --git a/internal/use-case/main-use-case/unit-position/case.go b/internal/use-case/main-use-case/unit-position/case.go index f3bd2840..47ea67cd 100644 --- a/internal/use-case/main-use-case/unit-position/case.go +++ b/internal/use-case/main-use-case/unit-position/case.go @@ -175,7 +175,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.UnitPosition var err error @@ -235,7 +235,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.UnitPosition var err error @@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { func validateForeignKey(input e.CreateDto) error { // validate installation_id - if _, err := uu.ReadDetail(eu.ReadDetailDto{Id: *input.Unit_Id}); err != nil { + if _, err := uu.ReadDetail(eu.ReadDetailDto{Code: &input.Code}); err != nil { return err } diff --git a/internal/use-case/main-use-case/unit-position/helper.go b/internal/use-case/main-use-case/unit-position/helper.go index c1db758d..827dfcc3 100644 --- a/internal/use-case/main-use-case/unit-position/helper.go +++ b/internal/use-case/main-use-case/unit-position/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.UnitPosition) { inputSrc = &inputTemp.CreateDto } - data.Unit_Id = inputSrc.Unit_Id + data.Unit_Code = inputSrc.Unit_Code data.Code = inputSrc.Code data.Name = inputSrc.Name data.HeadStatus = inputSrc.HeadStatus diff --git a/internal/use-case/main-use-case/unit-position/lib.go b/internal/use-case/main-use-case/unit-position/lib.go index c58edd4e..d6f42936 100644 --- a/internal/use-case/main-use-case/unit-position/lib.go +++ b/internal/use-case/main-use-case/unit-position/lib.go @@ -83,7 +83,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e } switch { - case input.Id != 0: + case input.Id != nil: getData = tx.First(&data, input.Id) case input.Code != nil && *input.Code != "": getData = tx.Where("code = ?", *input.Code).First(&data) diff --git a/internal/use-case/main-use-case/unit/case.go b/internal/use-case/main-use-case/unit/case.go index e11dbd21..650c4511 100644 --- a/internal/use-case/main-use-case/unit/case.go +++ b/internal/use-case/main-use-case/unit/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Unit var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Unit var err error diff --git a/internal/use-case/main-use-case/unit/helper.go b/internal/use-case/main-use-case/unit/helper.go index f7729ec9..8ee7f7e6 100644 --- a/internal/use-case/main-use-case/unit/helper.go +++ b/internal/use-case/main-use-case/unit/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Unit) { inputSrc = &inputTemp.CreateDto } - data.Installation_Id = inputSrc.Installation_Id + data.Installation_Code = inputSrc.Installation_Code data.Code = inputSrc.Code data.Name = inputSrc.Name } diff --git a/internal/use-case/main-use-case/unit/lib.go b/internal/use-case/main-use-case/unit/lib.go index 1a3e5652..3ec4a10c 100644 --- a/internal/use-case/main-use-case/unit/lib.go +++ b/internal/use-case/main-use-case/unit/lib.go @@ -81,9 +81,16 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + if err := tx. Scopes(gh.Preload(input.Includes)). - First(&data, input.Id).Error; err != nil { + First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } From b83e8971dccbe5cd440322a086a4bb762f014405 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 16:00:48 +0700 Subject: [PATCH 40/55] missing sql file for unit, installation --- cmd/main-migration/migrations/20251106090021.sql | 6 ++++++ cmd/main-migration/migrations/atlas.sum | 3 ++- internal/domain/main-entities/unit-position/entity.go | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106090021.sql diff --git a/cmd/main-migration/migrations/20251106090021.sql b/cmd/main-migration/migrations/20251106090021.sql new file mode 100644 index 00000000..c75c26e2 --- /dev/null +++ b/cmd/main-migration/migrations/20251106090021.sql @@ -0,0 +1,6 @@ +-- Modify "InstallationPosition" table +ALTER TABLE "public"."InstallationPosition" DROP CONSTRAINT "fk_InstallationPosition_Installation", DROP COLUMN "Installation_Id", ADD CONSTRAINT "fk_InstallationPosition_Installation" FOREIGN KEY ("Installation_Code") REFERENCES "public"."Installation" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Unit" table +ALTER TABLE "public"."Unit" DROP CONSTRAINT "fk_Unit_Installation", DROP COLUMN "Installation_Id", ADD CONSTRAINT "fk_Unit_Installation" FOREIGN KEY ("Installation_Code") REFERENCES "public"."Installation" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "UnitPosition" table +ALTER TABLE "public"."UnitPosition" DROP CONSTRAINT "fk_UnitPosition_Unit", DROP COLUMN "Unit_Id", ADD CONSTRAINT "fk_UnitPosition_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 8833af3a..dc9df4a2 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:w/qs7zN2FLnTjsmLVrFnMQWMxp3LYDJa0RLY74HVK0g= +h1:Jut0rnI38bZU7g1hei5bIcYGzWrt4KxfWzasGJcbwi0= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -82,3 +82,4 @@ h1:w/qs7zN2FLnTjsmLVrFnMQWMxp3LYDJa0RLY74HVK0g= 20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= 20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= 20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= diff --git a/internal/domain/main-entities/unit-position/entity.go b/internal/domain/main-entities/unit-position/entity.go index 9966cd4a..a7598049 100644 --- a/internal/domain/main-entities/unit-position/entity.go +++ b/internal/domain/main-entities/unit-position/entity.go @@ -7,5 +7,5 @@ import ( type UnitPosition struct { eub.Basic - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` } From 883249ab8c021dd87a56f2e4fa9dcaa4babd0a35 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 16:09:20 +0700 Subject: [PATCH 41/55] fix (specialist): fix read detail data --- internal/use-case/main-use-case/specialist/lib.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/use-case/main-use-case/specialist/lib.go b/internal/use-case/main-use-case/specialist/lib.go index 3e35d004..069f5fbb 100644 --- a/internal/use-case/main-use-case/specialist/lib.go +++ b/internal/use-case/main-use-case/specialist/lib.go @@ -81,9 +81,16 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + if err := tx. Scopes(gh.Preload(input.Includes)). - First(&data, input.Id).Error; err != nil { + First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } From 590e91726a74d8b35d21b3e3cf5f373b2a210b1f Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 16:23:52 +0700 Subject: [PATCH 42/55] add detail on soapi coonstlist --- .../domain/references/clinical/clinical.go | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index 01d0461c..c5d949e2 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -25,6 +25,7 @@ type ( ) const ( + SCDetail SubjectCode = "detail" // Detail SCPrimaryComplain SubjectCode = "pri-complain" // Keluhan Utama SCSecComplain SubjectCode = "sec-complain" // Secondary Complaint SCCurrentDiseaseHistory SubjectCode = "cur-disea-hist" // Current Disease History @@ -35,6 +36,7 @@ const ( SCMedicationHistory SubjectCode = "med-hist" // Medication History SCBloodType SubjectCode = "blood-type" // Blood Type + Detail ObjectCode = "detail" // Detail OCConsciousnessLevel ObjectCode = "consc-level" // Tingkat Kesadaran OCConsciousnessLevelDet ObjectCode = "consc-level-det" // Detail Tingkat Kesadaran OCSystolicBloodPressure ObjectCode = "syst-bp" // Tekanan Darah Systolic @@ -64,6 +66,7 @@ const ( OCHeight ObjectCode = "height" // Tinggi Badan OCHeadToToe ObjectCode = "head-to-toe" // Kepala Sampai Kaki + ACDetail AssessmentCode = "detail" // Detail ACEarlyDiag AssessmentCode = "early-diag" // Diagnosis Awal ACLateDiag AssessmentCode = "late-diag" // Diagnosis Akhir ACSecDiag AssessmentCode = "sec-diag" // Diagnosis Sekunder @@ -194,7 +197,7 @@ type Soapi struct { // ---------------- SUBJECT ---------------- type SubjectSection struct { - Note string `json:"note,omitempty"` + Detail string `json:"detail,omitempty"` PrimComplain string `json:"prim-compl,omitempty"` SecComplainQ string `json:"sec-compl,omitempty"` PrimaryComplain string `json:"pri-complain,omitempty"` @@ -210,7 +213,7 @@ type SubjectSection struct { // ---------------- OBJECT ---------------- type ObjectSection struct { - Note string `json:"note,omitempty"` + Detail string `json:"detail,omitempty"` ConsciousnessLevel string `json:"consc-level,omitempty"` ConsciousnessLevelDet string `json:"consc-level-det,omitempty"` SystolicBloodPressure string `json:"syst-bp,omitempty"` @@ -243,9 +246,16 @@ type ObjectSection struct { // ---------------- ASSESSMENT ---------------- type AssessmentSection struct { - EarlyDiagnosis DiagnosisDetail `json:"early-diag,omitempty"` - LateDiagnosis DiagnosisDetail `json:"late-diag,omitempty"` - SecondaryDiag DiagnosisDetail `json:"sec-diag,omitempty"` + Detail string `json:"detail,omitempty"` + EarlyDiagnosis DiagnosisDetail `json:"early-diag,omitempty"` + LateDiagnosis DiagnosisDetail `json:"late-diag,omitempty"` + SecondaryDiag DiagnosisDetail `json:"sec-diag,omitempty"` + EarlyDiagnosisMed DiagnosisDetail `json:"early-med-diag,omitempty"` + LateDiagnosisMed DiagnosisDetail `json:"late-med-diag,omitempty"` + SecondaryDiagnosisMed DiagnosisDetail `json:"sec-med-diag,omitempty"` + EarlyDiagnosisFunc DiagnosisDetail `json:"early-func-diag,omitempty"` + LateDiagnosisFunc DiagnosisDetail `json:"late-func-diag,omitempty"` + SecondaryDiagnosisFunc DiagnosisDetail `json:"sec-func-diag,omitempty"` } // nested object {note, codes} From a73d7745e3ef90cc412fd361e4f7c0e1c2dcd6b3 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 6 Nov 2025 16:02:44 +0700 Subject: [PATCH 43/55] feat/sso-auth: added models --- .../domain/main-entities/auth-partner/dto.go | 67 +++++++++++++++++ .../main-entities/auth-partner/entity.go | 12 ++++ internal/domain/main-entities/ext-user/dto.go | 71 +++++++++++++++++++ .../domain/main-entities/ext-user/entity.go | 16 +++++ 4 files changed, 166 insertions(+) create mode 100644 internal/domain/main-entities/auth-partner/dto.go create mode 100644 internal/domain/main-entities/auth-partner/entity.go create mode 100644 internal/domain/main-entities/ext-user/dto.go create mode 100644 internal/domain/main-entities/ext-user/entity.go diff --git a/internal/domain/main-entities/auth-partner/dto.go b/internal/domain/main-entities/auth-partner/dto.go new file mode 100644 index 00000000..651ca4b7 --- /dev/null +++ b/internal/domain/main-entities/auth-partner/dto.go @@ -0,0 +1,67 @@ +package authpartner + +import ( + // internal - domain - main-entities + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type CreateDto struct { + Code string `json:"code"` + Name string `json:"name"` + SecretKey string `json:"secretKey"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Code *string `json:"code"` + Name *string `json:"name"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` +} + +type UpdateDto struct { + Id uint16 `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint16 `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Code string `json:"code"` + Name string `json:"name"` + SecretKey string `json:"secretKey"` +} + +func (d AuthPartner) ToResponse() ResponseDto { + resp := ResponseDto{ + Code: d.Code, + Name: d.Name, + SecretKey: d.SecretKey, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []AuthPartner) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/auth-partner/entity.go b/internal/domain/main-entities/auth-partner/entity.go new file mode 100644 index 00000000..3a8cf4e6 --- /dev/null +++ b/internal/domain/main-entities/auth-partner/entity.go @@ -0,0 +1,12 @@ +package authpartner + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type AuthPartner struct { + ecore.Main // adjust this according to the needs + Code string `json:"code" gorm:"size:50"` + Name string `json:"name" gorm:"size:100"` + SecretKey string `json:"secretKey" gorm:"size:255"` +} diff --git a/internal/domain/main-entities/ext-user/dto.go b/internal/domain/main-entities/ext-user/dto.go new file mode 100644 index 00000000..4b434c55 --- /dev/null +++ b/internal/domain/main-entities/ext-user/dto.go @@ -0,0 +1,71 @@ +package extuser + +import ( + // internal - domain - main-entities + ecore "simrs-vx/internal/domain/base-entities/core" + eap "simrs-vx/internal/domain/main-entities/auth-partner" +) + +type CreateDto struct { + Name string `json:"name"` + AuthPartner_Code string `json:"authPartner_code"` + User_Name string `json:"user_name"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Name *string `json:"name"` + AuthPartner_Code *string `json:"authPartner_code"` + User_Name *string `json:"user_name"` +} + +type ReadDetailDto struct { + Id uint `json:"id"` +} + +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 + Name string `json:"name"` + AuthPartner_Code string `json:"authPartner_code"` + AuthPartner *eap.AuthPartner `json:"authPartner,omitempty"` + User_Name string `json:"user_name"` +} + +func (d ExtUser) ToResponse() ResponseDto { + resp := ResponseDto{ + Name: d.Name, + AuthPartner_Code: d.AuthPartner_Code, + AuthPartner: d.AuthPartner, + User_Name: d.User_Name, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []ExtUser) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} \ No newline at end of file diff --git a/internal/domain/main-entities/ext-user/entity.go b/internal/domain/main-entities/ext-user/entity.go new file mode 100644 index 00000000..ae293667 --- /dev/null +++ b/internal/domain/main-entities/ext-user/entity.go @@ -0,0 +1,16 @@ +package extuser + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + eap "simrs-vx/internal/domain/main-entities/auth-partner" + eau "simrs-vx/internal/domain/main-entities/user" +) + +type ExtUser struct { + ecore.Main // adjust this according to the needs + Name string `json:"name" gorm:"size:100"` + AuthPartner_Code string `json:"authPartner_code" gorm:"size:30"` + AuthPartner *eap.AuthPartner `json:"authPartner,omitempty" gorm:"foreignKey:AuthPartner_Code;references:Code"` + User_Name string `json:"user_name" gorm:"size:50"` + User *eau.User `json:"user,omitempty" gorm:"foreignKey:User_Name;references:Name"` +} From 6a2a8cc63c3f1551db619a65fad659c28a9c3a49 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 6 Nov 2025 18:13:26 +0700 Subject: [PATCH 44/55] dev: hotfix, cleaning + shortent code for auth --- .../main-use-case/authentication/case.go | 115 ++++++---------- .../main-use-case/authentication/helper.go | 129 +++++++++--------- 2 files changed, 103 insertions(+), 141 deletions(-) diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 6a980d71..6cf94142 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -9,28 +9,28 @@ import ( "github.com/golang-jwt/jwt" "github.com/google/uuid" - - "simrs-vx/internal/domain/main-entities/intern" - eu "simrs-vx/internal/domain/main-entities/user" - - pa "simrs-vx/internal/lib/auth" - el "simrs-vx/pkg/logger" - p "simrs-vx/pkg/password" - - ed "simrs-vx/internal/domain/main-entities/doctor" - ee "simrs-vx/internal/domain/main-entities/employee" - em "simrs-vx/internal/domain/main-entities/midwife" - en "simrs-vx/internal/domain/main-entities/nurse" - erc "simrs-vx/internal/domain/references/common" - erg "simrs-vx/internal/domain/references/organization" - a "github.com/karincake/apem" dg "github.com/karincake/apem/db-gorm-pg" ms "github.com/karincake/apem/ms-redis" d "github.com/karincake/dodol" l "github.com/karincake/lepet" + + pa "simrs-vx/internal/lib/auth" + pl "simrs-vx/pkg/logger" + p "simrs-vx/pkg/password" + + ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/employee" + "simrs-vx/internal/domain/main-entities/intern" + em "simrs-vx/internal/domain/main-entities/midwife" + en "simrs-vx/internal/domain/main-entities/nurse" + eu "simrs-vx/internal/domain/main-entities/user" + erc "simrs-vx/internal/domain/references/common" + erg "simrs-vx/internal/domain/references/organization" ) +const source = "authentication" + var authCfg AuthCfg func init() { @@ -40,13 +40,18 @@ func init() { // Generates token and store in redis at one place // just return the error code func GenToken(input eu.LoginDto) (*d.Data, error) { + event := pl.Event{ + Feature: "Create", + Source: source, + } + // Get User user := &eu.User{Name: input.Name} // if input.Position_Code != "" { // user.Position_Code = input.Position_Code // } if errCode := getAndCheck(user, user); errCode != "" { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: el.GenMessage(errCode)}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: pl.GenMessage(errCode)}} } if user.LoginAttemptCount > 5 { @@ -54,7 +59,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { now := time.Now() lastAllowdLogin := user.LastAllowdLogin if lastAllowdLogin.After(now.Add(-time.Hour * 1)) { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: el.GenMessage("auth-login-tooMany")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: pl.GenMessage("auth-login-tooMany")}} } else { tn := time.Now() user.LastAllowdLogin = &tn @@ -65,18 +70,18 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { tn := time.Now() user.LastAllowdLogin = &tn dg.I.Save(&user) - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: el.GenMessage("auth-login-tooMany")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: pl.GenMessage("auth-login-tooMany")}} } } if !p.Check(input.Password, user.Password) { user.LoginAttemptCount++ dg.I.Save(&user) - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-incorrect", Message: el.GenMessage("auth-login-incorrect")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-incorrect", Message: pl.GenMessage("auth-login-incorrect")}} } else if user.Status_Code == erc.USCBlocked { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-blocked", Message: el.GenMessage("auth-login-blocked")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-blocked", Message: pl.GenMessage("auth-login-blocked")}} } else if user.Status_Code == erc.USCNew { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-unverified", Message: el.GenMessage("auth-login-unverified")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-unverified", Message: pl.GenMessage("auth-login-unverified")}} } // Access token prep @@ -115,7 +120,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { employee := ee.Employee{} dg.I.Where("\"User_Id\" = ?", user.Id).First(&employee) if employee.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noEmployee", Message: el.GenMessage("auth-noEmployee")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noEmployee", Message: pl.GenMessage("auth-noEmployee")}} } atClaims["employee_id"] = employee.Id outputData["employee_id"] = employee.Id @@ -134,7 +139,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { doctor := ed.Doctor{} dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&doctor) if doctor.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: el.GenMessage("auth-noDoctor")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: pl.GenMessage("auth-noDoctor")}} } atClaims["doctor_code"] = doctor.Code outputData["doctor_code"] = doctor.Code @@ -152,7 +157,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { empData := en.Nurse{} dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData) if empData.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: el.GenMessage("auth-noNurse")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: pl.GenMessage("auth-noNurse")}} } atClaims["nurse_code"] = empData.Code outputData["nurse_code"] = empData.Code @@ -160,40 +165,40 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { empData := em.Midwife{} dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData) if empData.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noMidwife", Message: el.GenMessage("auth-noMidwife")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noMidwife", Message: pl.GenMessage("auth-noMidwife")}} } atClaims["midwife_code"] = empData.Code outputData["midwife_code"] = empData.Code } - errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}} + errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: pl.GenMessage("auth-getData-failed")}} // division position - divisionPositions, err := getDivisionPosition(employee.Id) + divisionPositions, err := getDivisionPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // installation position - installationPositions, err := getInstallationPosition(employee.Id) + installationPositions, err := getInstallationPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // unit position - unitPositions, err := getUnitPosition(employee.Id) + unitPositions, err := getUnitPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // specialist position - specialistPositions, err := getSpecialistPosition(employee.Id) + specialistPositions, err := getSpecialistPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // subspecialist position - subspecialistPositions, err := getSubspecialistPosition(employee.Id) + subspecialistPositions, err := getSubspecialistPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } @@ -220,7 +225,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { at := jwt.NewWithClaims(jwt.SigningMethodHS256, atClaims) ats, err := at.SignedString([]byte(atSecretKey)) if err != nil { - return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: el.GenMessage("token-sign-err")}} + return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: pl.GenMessage("token-sign-err")}} } outputData["accessToken"] = ats @@ -283,21 +288,21 @@ func VerifyToken(r *http.Request, tokenType TokenType) (data *jwt.Token, errCode func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) { token, errCode, errDetail := VerifyToken(r, tokenType) if errCode != "" { - return nil, d.FieldError{Code: errCode, Message: el.GenMessage(errCode, errDetail)} + return nil, d.FieldError{Code: errCode, Message: pl.GenMessage(errCode, errDetail)} } claims, ok := token.Claims.(jwt.MapClaims) if ok && token.Valid { accessUuid, ok := claims["uuid"].(string) if !ok { - return nil, d.FieldError{Code: "token-invalid", Message: el.GenMessage("token-invalid", "uuid not available")} + return nil, d.FieldError{Code: "token-invalid", Message: pl.GenMessage("token-invalid", "uuid not available")} } user_id, myErr := strconv.ParseInt(fmt.Sprintf("%.f", claims["user_id"]), 10, 64) if myErr != nil { - return nil, d.FieldError{Code: "token-invalid", Message: el.GenMessage("token-invalid", "uuid is not available")} + return nil, d.FieldError{Code: "token-invalid", Message: pl.GenMessage("token-invalid", "uuid is not available")} } accessUuidRedis := ms.I.Get(accessUuid) if accessUuidRedis.String() == "" { - return nil, d.FieldError{Code: "token-unidentified", Message: el.GenMessage("token-unidentified")} + return nil, d.FieldError{Code: "token-unidentified", Message: pl.GenMessage("token-unidentified")} } data = &pa.AuthInfo{ @@ -324,41 +329,3 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err func GetConfig() { a.ParseCfg(&authCfg) } - -func checkStrClaims(claim map[string]interface{}, key string) string { - if v, exist := claim[key]; exist && v != nil { - return v.(string) - } - return "" -} - -func checkStrPtrClaims(claim map[string]interface{}, key string) *string { - if v, exist := claim[key]; exist && v != nil { - val := v.(string) - return &val - } - return nil -} - -func checkIntClaims(claim map[string]interface{}, key string) int { - if v, exist := claim[key]; exist && v != nil { - return v.(int) - } - return 0 -} - -func checkIntPtrClaims(claim map[string]interface{}, key string) *int { - if v, exist := claim[key]; exist && v != nil { - val := int(v.(float64)) - return &val - } - return nil -} - -func checkUntPtrClaims(claim map[string]interface{}, key string) *uint { - if v, exist := claim[key]; exist && v != nil { - val := uint(v.(float64)) - return &val - } - return nil -} diff --git a/internal/use-case/main-use-case/authentication/helper.go b/internal/use-case/main-use-case/authentication/helper.go index bec64518..a919cfe9 100644 --- a/internal/use-case/main-use-case/authentication/helper.go +++ b/internal/use-case/main-use-case/authentication/helper.go @@ -1,6 +1,10 @@ package authentication import ( + dg "github.com/karincake/apem/db-gorm-pg" + + pl "simrs-vx/pkg/logger" + edp "simrs-vx/internal/domain/main-entities/division-position" eip "simrs-vx/internal/domain/main-entities/installation-position" esp "simrs-vx/internal/domain/main-entities/specialist-position" @@ -12,8 +16,6 @@ import ( usp "simrs-vx/internal/use-case/main-use-case/specialist-position" ussp "simrs-vx/internal/use-case/main-use-case/subspecialist-position" uup "simrs-vx/internal/use-case/main-use-case/unit-position" - - dg "github.com/karincake/apem/db-gorm-pg" ) // just return the error code @@ -28,43 +30,21 @@ func getAndCheck(input, condition any) (eCode string) { return "" } -func getDivisionPosition(employee_id uint) ([]string, error) { +func getDivisionPosition(employee_id uint, event *pl.Event) ([]string, error) { var result []string - // var employee ee.Employee - // if err := dg.I.Where("\"Employee_Id\" = ?", employee_id).First(&employee).Error; err != nil { - // if err == gorm.ErrRecordNotFound { - // return result, nil - // } - // return result, errors.New("no employee found") - // } - - //var divisionPositions []edp.DivisionPosition - //err := dg.I. - // Preload("Division"). - // Where("\"Employee_Id\" = ?", employee_id). - // Find(&divisionPositions).Error - //if err != nil { - // if err == gorm.ErrRecordNotFound { - // return result, nil - // } - // return result, err - //} - // get data division_position based on employee_id - dataDivisionPosition, err := udp.ReadList(edp.ReadListDto{ + data, _, err := udp.ReadListData(edp.ReadListDto{ FilterDto: edp.FilterDto{Employee_Id: &employee_id}, - Includes: "division"}) + Includes: "Division"}, event) if err != nil { return nil, err } - if list, ok := dataDivisionPosition.Data.([]edp.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Division != nil { - result = append(result, "div-"+dp.Division.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Division != nil { + result = append(result, "div-"+dp.Division.Code+"-"+dp.Code) } } } @@ -72,23 +52,21 @@ func getDivisionPosition(employee_id uint) ([]string, error) { return result, nil } -func getInstallationPosition(employeeId uint) ([]string, error) { +func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataInstallationPosition, err := uip.ReadList(eip.ReadListDto{ + data, _, err := uip.ReadListData(eip.ReadListDto{ FilterDto: eip.FilterDto{Employee_Id: &employeeId}, - Includes: "installation"}) + Includes: "installation"}, event) if err != nil { return nil, err } - if list, ok := dataInstallationPosition.Data.([]eip.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Installation != nil { - result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Installation != nil { + result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code) } } } @@ -96,23 +74,21 @@ func getInstallationPosition(employeeId uint) ([]string, error) { return result, nil } -func getUnitPosition(employeeId uint) ([]string, error) { +func getUnitPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataUnitPosition, err := uup.ReadList(eup.ReadListDto{ + data, _, err := uup.ReadListData(eup.ReadListDto{ FilterDto: eup.FilterDto{Employee_Id: &employeeId}, - Includes: "unit"}) + Includes: "unit"}, event) if err != nil { return nil, err } - if list, ok := dataUnitPosition.Data.([]eup.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Unit != nil { - result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Unit != nil { + result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code) } } } @@ -120,23 +96,21 @@ func getUnitPosition(employeeId uint) ([]string, error) { return result, nil } -func getSpecialistPosition(employeeId uint) ([]string, error) { +func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataSpecialistPosition, err := usp.ReadList(esp.ReadListDto{ + data, _, err := usp.ReadListData(esp.ReadListDto{ FilterDto: esp.FilterDto{Employee_Id: &employeeId}, - Includes: "specialist"}) + Includes: "specialist"}, event) if err != nil { return nil, err } - if list, ok := dataSpecialistPosition.Data.([]esp.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Specialist != nil { - result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Specialist != nil { + result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code) } } } @@ -144,26 +118,47 @@ func getSpecialistPosition(employeeId uint) ([]string, error) { return result, nil } -func getSubspecialistPosition(employeeId uint) ([]string, error) { +func getSubspecialistPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataSubspecialistPosition, err := ussp.ReadList(essp.ReadListDto{ + data, _, err := ussp.ReadListData(essp.ReadListDto{ FilterDto: essp.FilterDto{Employee_Id: &employeeId}, - Includes: "subspecialist"}) + Includes: "subspecialist"}, event) if err != nil { return nil, err } - if list, ok := dataSubspecialistPosition.Data.([]essp.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Subspecialist != nil { - result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Subspecialist != nil { + result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code) } } } return result, nil } + +func checkStrClaims(claim map[string]interface{}, key string) string { + if v, exist := claim[key]; exist && v != nil { + return v.(string) + } + return "" +} + +func checkStrPtrClaims(claim map[string]interface{}, key string) *string { + if v, exist := claim[key]; exist && v != nil { + val := v.(string) + return &val + } + return nil +} + +func checkUntPtrClaims(claim map[string]interface{}, key string) *uint { + if v, exist := claim[key]; exist && v != nil { + val := uint(v.(float64)) + return &val + } + return nil +} From 355c7053afa5f85098f1ce9edabde3191712fe54 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 6 Nov 2025 18:23:51 +0700 Subject: [PATCH 45/55] migration: updated sum for whatever the reason is --- cmd/main-migration/migrations/atlas.sum | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index dc9df4a2..d274aba5 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:Jut0rnI38bZU7g1hei5bIcYGzWrt4KxfWzasGJcbwi0= +h1:ZADUaOWJ3ITHhas6LbAgWte6gK6FX1BJEn9Wfoynmnk= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,11 +75,11 @@ h1:Jut0rnI38bZU7g1hei5bIcYGzWrt4KxfWzasGJcbwi0= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= From ad3501c1daace32cdc70c88694bc953dbb63dce9 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 6 Nov 2025 21:42:19 +0700 Subject: [PATCH 46/55] feat/sso-auth: improved the entities --- .../domain/main-entities/auth-partner/dto.go | 5 +++- internal/domain/main-entities/ext-user/dto.go | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/internal/domain/main-entities/auth-partner/dto.go b/internal/domain/main-entities/auth-partner/dto.go index 651ca4b7..2b1589fb 100644 --- a/internal/domain/main-entities/auth-partner/dto.go +++ b/internal/domain/main-entities/auth-partner/dto.go @@ -15,6 +15,7 @@ type ReadListDto struct { FilterDto Includes string `json:"includes"` Pagination ecore.Pagination + Sort string `json:"sort"` } type FilterDto struct { @@ -23,7 +24,9 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` + Includes string `json:"includes"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/ext-user/dto.go b/internal/domain/main-entities/ext-user/dto.go index 4b434c55..653dab92 100644 --- a/internal/domain/main-entities/ext-user/dto.go +++ b/internal/domain/main-entities/ext-user/dto.go @@ -16,16 +16,19 @@ type ReadListDto struct { FilterDto Includes string `json:"includes"` Pagination ecore.Pagination + Sort string `json:"sort"` } type FilterDto struct { Name *string `json:"name"` AuthPartner_Code *string `json:"authPartner_code"` User_Name *string `json:"user_name"` + Includes string `json:"includes"` } type ReadDetailDto struct { - Id uint `json:"id"` + Id uint `json:"id"` + Includes string `json:"includes"` } type UpdateDto struct { @@ -45,18 +48,18 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Name string `json:"name"` - AuthPartner_Code string `json:"authPartner_code"` - AuthPartner *eap.AuthPartner `json:"authPartner,omitempty"` - User_Name string `json:"user_name"` + Name string `json:"name"` + AuthPartner_Code string `json:"authPartner_code"` + AuthPartner *eap.AuthPartner `json:"authPartner,omitempty"` + User_Name string `json:"user_name"` } func (d ExtUser) ToResponse() ResponseDto { resp := ResponseDto{ - Name: d.Name, - AuthPartner_Code: d.AuthPartner_Code, - AuthPartner: d.AuthPartner, - User_Name: d.User_Name, + Name: d.Name, + AuthPartner_Code: d.AuthPartner_Code, + AuthPartner: d.AuthPartner, + User_Name: d.User_Name, } resp.Main = d.Main return resp @@ -68,4 +71,4 @@ func ToResponseList(data []ExtUser) []ResponseDto { resp[i] = u.ToResponse() } return resp -} \ No newline at end of file +} From d4e58e4f73407ee5b05f18a917382efdb16e2818 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 6 Nov 2025 21:48:42 +0700 Subject: [PATCH 47/55] feat/sso-auth: added the migration --- .../migrations/20251106144745.sql | 26 +++++++++++++++++++ cmd/main-migration/migrations/atlas.sum | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 cmd/main-migration/migrations/20251106144745.sql diff --git a/cmd/main-migration/migrations/20251106144745.sql b/cmd/main-migration/migrations/20251106144745.sql new file mode 100644 index 00000000..4e10ec66 --- /dev/null +++ b/cmd/main-migration/migrations/20251106144745.sql @@ -0,0 +1,26 @@ +-- Create "AuthPartner" table +CREATE TABLE "public"."AuthPartner" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(50) NULL, + "Name" character varying(100) NULL, + "SecretKey" character varying(255) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_AuthPartner_Code" UNIQUE ("Code"), + CONSTRAINT "uni_AuthPartner_Name" UNIQUE ("Name") +); +-- Create "ExtUser" table +CREATE TABLE "public"."ExtUser" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(100) NULL, + "AuthPartner_Code" character varying(30) NULL, + "User_Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ExtUser_AuthPartner" FOREIGN KEY ("AuthPartner_Code") REFERENCES "public"."AuthPartner" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ExtUser_User" FOREIGN KEY ("User_Name") REFERENCES "public"."User" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index d274aba5..e1e6989d 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:ZADUaOWJ3ITHhas6LbAgWte6gK6FX1BJEn9Wfoynmnk= +h1:Zokt/6mjNJdmX2YBvxbhlp1P6FPkkfjVhx2W7FY10Bk= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -83,3 +83,4 @@ h1:ZADUaOWJ3ITHhas6LbAgWte6gK6FX1BJEn9Wfoynmnk= 20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= 20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= 20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:yuma9OS/QMlH+mIjClgx7DBg//zbPnljeVFP9AladjI= From afde2f7cf4b73436947204e2aa4fac775b5bed5f Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 6 Nov 2025 21:48:42 +0700 Subject: [PATCH 48/55] feat/sso-auth: added the migration --- .../migrations/20251106144745.sql | 26 +++++++++++++++++++ cmd/main-migration/migrations/atlas.sum | 3 ++- internal/interface/migration/main-entities.go | 4 +++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 cmd/main-migration/migrations/20251106144745.sql diff --git a/cmd/main-migration/migrations/20251106144745.sql b/cmd/main-migration/migrations/20251106144745.sql new file mode 100644 index 00000000..4e10ec66 --- /dev/null +++ b/cmd/main-migration/migrations/20251106144745.sql @@ -0,0 +1,26 @@ +-- Create "AuthPartner" table +CREATE TABLE "public"."AuthPartner" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(50) NULL, + "Name" character varying(100) NULL, + "SecretKey" character varying(255) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_AuthPartner_Code" UNIQUE ("Code"), + CONSTRAINT "uni_AuthPartner_Name" UNIQUE ("Name") +); +-- Create "ExtUser" table +CREATE TABLE "public"."ExtUser" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(100) NULL, + "AuthPartner_Code" character varying(30) NULL, + "User_Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ExtUser_AuthPartner" FOREIGN KEY ("AuthPartner_Code") REFERENCES "public"."AuthPartner" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ExtUser_User" FOREIGN KEY ("User_Name") REFERENCES "public"."User" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index d274aba5..e1e6989d 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:ZADUaOWJ3ITHhas6LbAgWte6gK6FX1BJEn9Wfoynmnk= +h1:Zokt/6mjNJdmX2YBvxbhlp1P6FPkkfjVhx2W7FY10Bk= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -83,3 +83,4 @@ h1:ZADUaOWJ3ITHhas6LbAgWte6gK6FX1BJEn9Wfoynmnk= 20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= 20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= 20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:yuma9OS/QMlH+mIjClgx7DBg//zbPnljeVFP9AladjI= diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index af9fe034..9c5486d1 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -8,6 +8,7 @@ import ( antibioticinuse "simrs-vx/internal/domain/main-entities/antibiotic-in-use" antibioticsrccategory "simrs-vx/internal/domain/main-entities/antibiotic-src-category" appointment "simrs-vx/internal/domain/main-entities/appointment" + authpartner "simrs-vx/internal/domain/main-entities/auth-partner" chemo "simrs-vx/internal/domain/main-entities/chemo" chemoprotocol "simrs-vx/internal/domain/main-entities/chemo-protocol" consultation "simrs-vx/internal/domain/main-entities/consultation" @@ -28,6 +29,7 @@ import ( employee "simrs-vx/internal/domain/main-entities/employee" encounter "simrs-vx/internal/domain/main-entities/encounter" ethnic "simrs-vx/internal/domain/main-entities/ethnic" + extuser "simrs-vx/internal/domain/main-entities/ext-user" generalconsent "simrs-vx/internal/domain/main-entities/general-consent" infra "simrs-vx/internal/domain/main-entities/infra" inpatient "simrs-vx/internal/domain/main-entities/inpatient" @@ -105,7 +107,9 @@ import ( func getMainEntities() []any { return []any{ + &authpartner.AuthPartner{}, &user.User{}, + &extuser.ExtUser{}, &division.Division{}, &divisionposition.DivisionPosition{}, &installation.Installation{}, From 72e0a1ce24b6cdcbbf2fa3685766579363b5f644 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Fri, 7 Nov 2025 08:19:21 +0700 Subject: [PATCH 49/55] feat/sso-auth: moved ext-user to user-fes --- .../domain/main-entities/{ext-user => user-fes}/dto.go | 7 ++++--- .../domain/main-entities/{ext-user => user-fes}/entity.go | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) rename internal/domain/main-entities/{ext-user => user-fes}/dto.go (91%) rename internal/domain/main-entities/{ext-user => user-fes}/entity.go (90%) diff --git a/internal/domain/main-entities/ext-user/dto.go b/internal/domain/main-entities/user-fes/dto.go similarity index 91% rename from internal/domain/main-entities/ext-user/dto.go rename to internal/domain/main-entities/user-fes/dto.go index 653dab92..6cb3636b 100644 --- a/internal/domain/main-entities/ext-user/dto.go +++ b/internal/domain/main-entities/user-fes/dto.go @@ -1,4 +1,5 @@ -package extuser +// FES = From External Source +package userfes import ( // internal - domain - main-entities @@ -54,7 +55,7 @@ type ResponseDto struct { User_Name string `json:"user_name"` } -func (d ExtUser) ToResponse() ResponseDto { +func (d UserFes) ToResponse() ResponseDto { resp := ResponseDto{ Name: d.Name, AuthPartner_Code: d.AuthPartner_Code, @@ -65,7 +66,7 @@ func (d ExtUser) ToResponse() ResponseDto { return resp } -func ToResponseList(data []ExtUser) []ResponseDto { +func ToResponseList(data []UserFes) []ResponseDto { resp := make([]ResponseDto, len(data)) for i, u := range data { resp[i] = u.ToResponse() diff --git a/internal/domain/main-entities/ext-user/entity.go b/internal/domain/main-entities/user-fes/entity.go similarity index 90% rename from internal/domain/main-entities/ext-user/entity.go rename to internal/domain/main-entities/user-fes/entity.go index ae293667..7356166c 100644 --- a/internal/domain/main-entities/ext-user/entity.go +++ b/internal/domain/main-entities/user-fes/entity.go @@ -1,4 +1,5 @@ -package extuser +// FES = From External Source +package userfes import ( ecore "simrs-vx/internal/domain/base-entities/core" @@ -6,7 +7,7 @@ import ( eau "simrs-vx/internal/domain/main-entities/user" ) -type ExtUser struct { +type UserFes struct { ecore.Main // adjust this according to the needs Name string `json:"name" gorm:"size:100"` AuthPartner_Code string `json:"authPartner_code" gorm:"size:30"` From bfbbb38220676b023923da7ecd1a5023120bf126 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Fri, 7 Nov 2025 13:52:30 +0700 Subject: [PATCH 50/55] room ids into codes --- .../migrations/20251107064812.sql | 2 ++ .../migrations/20251107064937.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 6 ++++-- .../domain/main-entities/room/base/entity.go | 20 +++++++++++-------- .../interface/main-handler/main-handler.go | 4 ++++ 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 cmd/main-migration/migrations/20251107064812.sql create mode 100644 cmd/main-migration/migrations/20251107064937.sql diff --git a/cmd/main-migration/migrations/20251107064812.sql b/cmd/main-migration/migrations/20251107064812.sql new file mode 100644 index 00000000..2e5c78cf --- /dev/null +++ b/cmd/main-migration/migrations/20251107064812.sql @@ -0,0 +1,2 @@ +-- Modify "Room" table +ALTER TABLE "public"."Room" ADD COLUMN "Infra_Coode" character varying(10) NULL, ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20251107064937.sql b/cmd/main-migration/migrations/20251107064937.sql new file mode 100644 index 00000000..d1111390 --- /dev/null +++ b/cmd/main-migration/migrations/20251107064937.sql @@ -0,0 +1,2 @@ +-- Rename a column from "Infra_Coode" to "Infra_Code" +ALTER TABLE "public"."Room" RENAME COLUMN "Infra_Coode" TO "Infra_Code"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index fbab0579..83124cd0 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:3ftGXqIy9GWTwv7IK2HRZfSfwoKU5tLlKS8C1O91tDM= +h1:jXSMbKW9P12r6gmXKCW2NR6uOlJDF5wR2bjF61lxk94= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -84,4 +84,6 @@ h1:3ftGXqIy9GWTwv7IK2HRZfSfwoKU5tLlKS8C1O91tDM= 20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= 20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= 20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:JoINgSA4u4SUeF+rfTqTUDEWyZBpKMDULDfVdbE5g9E= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= +20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= diff --git a/internal/domain/main-entities/room/base/entity.go b/internal/domain/main-entities/room/base/entity.go index e45a441d..2ac690b6 100644 --- a/internal/domain/main-entities/room/base/entity.go +++ b/internal/domain/main-entities/room/base/entity.go @@ -8,14 +8,18 @@ import ( ) type Basic struct { - ecore.SmallMain // adjust this according to the needs - Infra_Id *uint16 `json:"infra_id"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` + ecore.SmallMain // adjust this according to the needs + Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` + Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code" gorm:"size:10"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id"` + Specialist_Id *uint16 `json:"specialist_id"` + Specialist_Code *string `json:"specialist_code" gorm:"size:10"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` + Subspecialist_Id *uint16 `json:"subspecialist_id"` + Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` } func (Basic) TableName() string { diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 925f9dc6..e974564b 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -36,7 +36,9 @@ import ( /******************** actor ********************/ + doctor "simrs-vx/internal/interface/main-handler/doctor" employee "simrs-vx/internal/interface/main-handler/employee" + nurse "simrs-vx/internal/interface/main-handler/nurse" nutritionist "simrs-vx/internal/interface/main-handler/nutritionist" patient "simrs-vx/internal/interface/main-handler/patient" person "simrs-vx/internal/interface/main-handler/person" @@ -267,6 +269,8 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/person-contact", personcontact.O) hc.RegCrud(r, "/v1/person-insurance", personinsurance.O) hc.RegCrud(r, "/v1/employee", employee.O) + hc.RegCrudByCode(r, "/v1/doctor", doctor.O) + hc.RegCrudByCode(r, "/v1/nurse", nurse.O) hc.RegCrud(r, "/v1/nutritionist", nutritionist.O) hc.RegCrud(r, "/v1/pharmacist", pharmacist.O) hk.GroupRoutes("/v1/user", r, hk.MapHandlerFunc{ From feb54bd2f5b1cfbfe66e374168286dcc5167fdc8 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 7 Nov 2025 13:54:39 +0700 Subject: [PATCH 51/55] migration from server --- cmd/main-migration/migrations/atlas.sum | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 83124cd0..70dd468c 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:jXSMbKW9P12r6gmXKCW2NR6uOlJDF5wR2bjF61lxk94= +h1:mPG9xfcT+aorrateezmQ8OvETRVigtmHiY1O8i2dpwg= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,15 +75,15 @@ h1:jXSMbKW9P12r6gmXKCW2NR6uOlJDF5wR2bjF61lxk94= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= -20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= From a944105f72f273621167c99ea2003524fac47670 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Fri, 7 Nov 2025 15:28:32 +0700 Subject: [PATCH 52/55] infra, room, item, medicine, device, material ids into codes --- .../migrations/20251107071420.sql | 6 ++ .../migrations/20251107074318.sql | 4 ++ .../migrations/20251107075050.sql | 4 ++ .../migrations/20251107080604.sql | 2 + .../migrations/20251107081830.sql | 6 ++ cmd/main-migration/migrations/atlas.sum | 31 +++++---- internal/domain/main-entities/device/dto.go | 17 ++--- .../domain/main-entities/device/entity.go | 2 + internal/domain/main-entities/infra/dto.go | 41 +++++------ internal/domain/main-entities/infra/entity.go | 7 +- internal/domain/main-entities/item/dto.go | 15 ++-- internal/domain/main-entities/item/entity.go | 1 + internal/domain/main-entities/material/dto.go | 69 ++++++++++--------- .../domain/main-entities/material/entity.go | 2 + internal/domain/main-entities/medicine/dto.go | 27 ++++---- .../domain/main-entities/medicine/entity.go | 2 + .../domain/main-entities/room/base/entity.go | 10 +-- internal/domain/main-entities/room/dto.go | 48 ++++++------- internal/domain/main-entities/room/entity.go | 2 +- .../interface/main-handler/device/handler.go | 18 ++--- .../interface/main-handler/infra/handler.go | 18 ++--- .../interface/main-handler/item/handler.go | 18 ++--- .../interface/main-handler/main-handler.go | 10 +-- .../main-handler/material/handler.go | 18 ++--- .../main-handler/medicine/handler.go | 18 ++--- .../use-case/main-use-case/device/case.go | 4 +- .../use-case/main-use-case/device/helper.go | 8 +-- internal/use-case/main-use-case/device/lib.go | 7 ++ .../use-case/main-use-case/division/lib.go | 2 +- internal/use-case/main-use-case/infra/case.go | 8 +-- .../use-case/main-use-case/infra/helper.go | 12 ++-- internal/use-case/main-use-case/infra/lib.go | 11 ++- internal/use-case/main-use-case/item/case.go | 4 +- .../use-case/main-use-case/item/helper.go | 2 +- .../use-case/main-use-case/material/case.go | 4 +- .../use-case/main-use-case/material/helper.go | 8 +-- .../use-case/main-use-case/medicine/case.go | 4 +- .../use-case/main-use-case/medicine/helper.go | 8 +-- .../use-case/main-use-case/medicine/lib.go | 9 ++- .../use-case/main-use-case/room/helper.go | 8 +-- 40 files changed, 277 insertions(+), 218 deletions(-) create mode 100644 cmd/main-migration/migrations/20251107071420.sql create mode 100644 cmd/main-migration/migrations/20251107074318.sql create mode 100644 cmd/main-migration/migrations/20251107075050.sql create mode 100644 cmd/main-migration/migrations/20251107080604.sql create mode 100644 cmd/main-migration/migrations/20251107081830.sql diff --git a/cmd/main-migration/migrations/20251107071420.sql b/cmd/main-migration/migrations/20251107071420.sql new file mode 100644 index 00000000..a9727884 --- /dev/null +++ b/cmd/main-migration/migrations/20251107071420.sql @@ -0,0 +1,6 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ADD COLUMN "Parent_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; +-- Create index "idx_Infra_Code" to table: "Infra" +CREATE UNIQUE INDEX "idx_Infra_Code" ON "public"."Infra" ("Code"); +-- Modify "Room" table +ALTER TABLE "public"."Room" DROP CONSTRAINT "fk_Room_Specialist", DROP CONSTRAINT "fk_Room_Subspecialist", DROP CONSTRAINT "fk_Room_Unit", DROP COLUMN "Infra_Id", DROP COLUMN "Unit_Id", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", ADD CONSTRAINT "fk_Room_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Room_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Room_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251107074318.sql b/cmd/main-migration/migrations/20251107074318.sql new file mode 100644 index 00000000..5156b74e --- /dev/null +++ b/cmd/main-migration/migrations/20251107074318.sql @@ -0,0 +1,4 @@ +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" DROP CONSTRAINT "fk_Nurse_Infra"; +-- Modify "Infra" table +ALTER TABLE "public"."Infra" DROP CONSTRAINT "uni_Infra_Code"; diff --git a/cmd/main-migration/migrations/20251107075050.sql b/cmd/main-migration/migrations/20251107075050.sql new file mode 100644 index 00000000..fee27fee --- /dev/null +++ b/cmd/main-migration/migrations/20251107075050.sql @@ -0,0 +1,4 @@ +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" ADD CONSTRAINT "fk_Nurse_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Room" table +ALTER TABLE "public"."Room" ADD CONSTRAINT "fk_Room_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251107080604.sql b/cmd/main-migration/migrations/20251107080604.sql new file mode 100644 index 00000000..246be1fa --- /dev/null +++ b/cmd/main-migration/migrations/20251107080604.sql @@ -0,0 +1,2 @@ +-- Modify "Item" table +ALTER TABLE "public"."Item" ADD COLUMN "Infra_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20251107081830.sql b/cmd/main-migration/migrations/20251107081830.sql new file mode 100644 index 00000000..a7490211 --- /dev/null +++ b/cmd/main-migration/migrations/20251107081830.sql @@ -0,0 +1,6 @@ +-- Modify "Device" table +ALTER TABLE "public"."Device" ADD COLUMN "Infra_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; +-- Modify "Material" table +ALTER TABLE "public"."Material" ADD COLUMN "Infra_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; +-- Modify "Medicine" table +ALTER TABLE "public"."Medicine" ADD COLUMN "Infra_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 70dd468c..440bd74d 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:mPG9xfcT+aorrateezmQ8OvETRVigtmHiY1O8i2dpwg= +h1:A8U7W3JZbEUXu6uzF9wfKvSgX/j+G1nQoxchM989kiw= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,15 +75,20 @@ h1:mPG9xfcT+aorrateezmQ8OvETRVigtmHiY1O8i2dpwg= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= -20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= -20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= -20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= -20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= +20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= +20251107071420.sql h1:Q+e+OqjdiuK/sghDQ5NxjU+u2zYl+vh/eRBlUz9Idhg= +20251107074318.sql h1:VbOWMw2rClEWgMnDSejXPqXkFoQ4odVsHn3/UAEiCYA= +20251107075050.sql h1:ZZaKJEWXIJ94/0/2Gzzz+HXjmebEs5eP8iUIot26/c8= +20251107080604.sql h1:aq+tINa0ULCZlJcUK2jaeGh6rRH4jJz3e2NrK47m0Ec= +20251107081830.sql h1:Bl9kniyLWeMqd3nrvgCgiUpdcJWp8qX1F41JAM1WbiE= diff --git a/internal/domain/main-entities/device/dto.go b/internal/domain/main-entities/device/dto.go index 1c874576..36e90a0c 100644 --- a/internal/domain/main-entities/device/dto.go +++ b/internal/domain/main-entities/device/dto.go @@ -8,11 +8,11 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Uom_Code string `json:"uom_code" validate:"maxLength=10"` - Infra_Id *uint16 `json:"infra_id"` - Item_Id *uint `json:"item_id"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + Uom_Code string `json:"uom_code" validate:"maxLength=10"` + Infra_Code *string `json:"infra_code"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -32,17 +32,18 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { diff --git a/internal/domain/main-entities/device/entity.go b/internal/domain/main-entities/device/entity.go index ca54c08d..c68b7c3e 100644 --- a/internal/domain/main-entities/device/entity.go +++ b/internal/domain/main-entities/device/entity.go @@ -14,7 +14,9 @@ type Device struct { Uom_Code string `json:"uom_code" gorm:"size:10"` Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code" gorm:"size:50"` Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/infra/dto.go b/internal/domain/main-entities/infra/dto.go index de566fad..28ff8d93 100644 --- a/internal/domain/main-entities/infra/dto.go +++ b/internal/domain/main-entities/infra/dto.go @@ -9,15 +9,15 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" validate:"maxLength=15"` - Parent_Id *uint16 `json:"parent_id"` - Item_Id *uint `json:"item_id"` - Unit_Id *uint16 `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Infra_Id *uint16 `json:"-"` // for room + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" validate:"maxLength=15"` + Parent_Code *string `json:"parent_code"` + Item_Id *uint `json:"-"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + Infra_Code *string `json:"infra_code"` // for room } type ReadListDto struct { @@ -32,24 +32,25 @@ type FilterDto struct { Code string `json:"code"` Name string `json:"name"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup-code"` - Parent_Id *uint16 `json:"parent-id"` - Item_Id *uint `json:"item-id"` + Parent_Code *string `json:"parent-code"` + Item_Id *string `json:"item-code"` Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code *string `json:"code"` - Item_Id *uint `json:"item_id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` + Item_Code *string `json:"item_code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -63,10 +64,10 @@ type ResponseDto struct { Code string `json:"code"` Name string `json:"name"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code"` - Parent_Id *uint16 `json:"parent_id"` + Parent_Code *string `json:"parent_code"` Parent *Infra `json:"parent,omitempty"` Childrens []Infra `json:"childrens,omitempty"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *ei.Item `json:"item,omitempty"` Rooms []erb.Basic `json:"rooms,omitempty"` } @@ -76,10 +77,10 @@ func (d Infra) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, InfraGroup_Code: d.InfraGroup_Code, - Parent_Id: d.Parent_Id, + Parent_Code: d.Parent_Code, Parent: d.Parent, Childrens: d.Childrens, - Item_Id: d.Item_Id, + Item_Code: d.Item_Code, Item: d.Item, Rooms: d.Rooms, } diff --git a/internal/domain/main-entities/infra/entity.go b/internal/domain/main-entities/infra/entity.go index 3d8c6f99..dfc19e3d 100644 --- a/internal/domain/main-entities/infra/entity.go +++ b/internal/domain/main-entities/infra/entity.go @@ -3,6 +3,7 @@ package infra import ( ecore "simrs-vx/internal/domain/base-entities/core" ei "simrs-vx/internal/domain/main-entities/item" + erb "simrs-vx/internal/domain/main-entities/room/base" ero "simrs-vx/internal/domain/references/organization" @@ -10,13 +11,15 @@ import ( type Infra struct { ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` + Code string `json:"code" gorm:"uniqueIndex;size:10"` Name string `json:"name" gorm:"size:50"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" gorm:"size:15"` Parent_Id *uint16 `json:"parent_id"` + Parent_Code *string `json:"parent_code" gorm:"size:10"` Parent *Infra `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"` Childrens []Infra `json:"childrens" gorm:"foreignKey:Parent_Id"` // may need references to self Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code" gorm:"size:50"` Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` - Rooms []erb.Basic `json:"rooms" gorm:"foreignKey:Infra_Id"` + Rooms []erb.Basic `json:"rooms" gorm:"foreignKey:Infra_Code;references:Code"` } diff --git a/internal/domain/main-entities/item/dto.go b/internal/domain/main-entities/item/dto.go index 22be4c1a..f20ce217 100644 --- a/internal/domain/main-entities/item/dto.go +++ b/internal/domain/main-entities/item/dto.go @@ -11,7 +11,7 @@ type CreateDto struct { Name string `json:"name" validate:"maxLength=100"` ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code" validate:"maxLength=10"` Uom_Code *string `json:"uom_code" validate:"maxLength=10"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Stock *int `json:"stock"` } @@ -27,23 +27,24 @@ type FilterDto struct { Name string `json:"name"` ItemGroup_Code ero.ItemGroupCode `json:"itemGroup-code"` Uom_Code *string `json:"uom-code"` - Infra_Id *uint16 `json:"infra-id"` + Infra_Code *string `json:"infra-code"` Stock *int `json:"stock"` Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -59,7 +60,7 @@ type ResponseDto struct { ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code"` Uom_Code *string `json:"uom_code"` Uom *eu.Uom `json:"uom,omitempty"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Stock *int `json:"stock"` } @@ -70,7 +71,7 @@ func (d Item) ToResponse() ResponseDto { ItemGroup_Code: d.ItemGroup_Code, Uom_Code: d.Uom_Code, Uom: d.Uom, - Infra_Id: d.Infra_Id, + Infra_Code: d.Infra_Code, Stock: d.Stock, } resp.Main = d.Main diff --git a/internal/domain/main-entities/item/entity.go b/internal/domain/main-entities/item/entity.go index e0ff4e21..406c57e6 100644 --- a/internal/domain/main-entities/item/entity.go +++ b/internal/domain/main-entities/item/entity.go @@ -15,5 +15,6 @@ type Item struct { Uom_Code *string `json:"uom_code" gorm:"size:10"` Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` Stock *int `json:"stock"` } diff --git a/internal/domain/main-entities/material/dto.go b/internal/domain/main-entities/material/dto.go index 18a93723..fbedbf43 100644 --- a/internal/domain/main-entities/material/dto.go +++ b/internal/domain/main-entities/material/dto.go @@ -8,12 +8,12 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Uom_Code string `json:"uom_code" validate:"maxLength=10"` - Infra_Id *uint16 `json:"infra_id"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + Uom_Code string `json:"uom_code" validate:"maxLength=10"` + Infra_Code *string `json:"infra_code"` + Stock *int `json:"stock"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -24,28 +24,29 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom-code"` - Infra_Id *uint16 `json:"infra-id"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom-code"` + Infra_Code *string `json:"infra-code"` + Stock *int `json:"stock"` + Item_Code *string `json:"item-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Item_Id *uint `json:"item_id"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -56,28 +57,28 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Uom *eu.Uom `json:"uom,omitempty"` - Infra_Id *uint16 `json:"infra_id"` - Infra *ein.Infra `json:"infra,omitempty"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Uom *eu.Uom `json:"uom,omitempty"` + Infra_Code *string `json:"infra_code"` + Infra *ein.Infra `json:"infra,omitempty"` + Stock *int `json:"stock"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty"` } func (d Material) ToResponse() ResponseDto { resp := ResponseDto{ - Code: d.Code, - Name: d.Name, - Uom_Code: d.Uom_Code, - Uom: d.Uom, - Infra_Id: d.Infra_Id, - Infra: d.Infra, - Stock: d.Stock, - Item_Id: d.Item_Id, - Item: d.Item, + Code: d.Code, + Name: d.Name, + Uom_Code: d.Uom_Code, + Uom: d.Uom, + Infra_Code: d.Infra_Code, + Infra: d.Infra, + Stock: d.Stock, + Item_Code: d.Item_Code, + Item: d.Item, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/material/entity.go b/internal/domain/main-entities/material/entity.go index cdfd8bfd..50e6907e 100644 --- a/internal/domain/main-entities/material/entity.go +++ b/internal/domain/main-entities/material/entity.go @@ -14,8 +14,10 @@ type Material struct { Uom_Code string `json:"uom_code" gorm:"size:10"` Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` Stock *int `json:"stock"` Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code" gorm:"size:50"` Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/medicine/dto.go b/internal/domain/main-entities/medicine/dto.go index 82431fc1..945db1e5 100644 --- a/internal/domain/main-entities/medicine/dto.go +++ b/internal/domain/main-entities/medicine/dto.go @@ -16,9 +16,9 @@ type CreateDto struct { MedicineMethod_Code *string `json:"medicineMethod_code" validate:"maxLength=10"` Uom_Code *string `json:"uom_code" validate:"maxLength=10"` Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -35,25 +35,26 @@ type FilterDto struct { MedicineMethod_Code *string `json:"medicineMethod-code"` Uom_Code *string `json:"uom-code"` Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra-id"` + Infra_Code *string `json:"infra-code"` Stock *int `json:"stock"` - Item_Id *uint `json:"item-id"` + Item_Code *string `json:"item-code"` Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code *string `json:"code"` - Item_Id *uint `json:"item_id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` + Item_Code *uint `json:"item_code"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -73,10 +74,10 @@ type ResponseDto struct { Uom_Code *string `json:"uom_code"` Uom *eu.Uom `json:"uom"` Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Infra *ein.Infra `json:"infra,omitempty"` Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *eit.Item `json:"item,omitempty"` } @@ -91,10 +92,10 @@ func (d Medicine) ToResponse() ResponseDto { Uom_Code: d.Uom_Code, Uom: d.Uom, Dose: d.Dose, - Infra_Id: d.Infra_Id, + Infra_Code: d.Infra_Code, Infra: d.Infra, Stock: d.Stock, - Item_Id: d.Item_Id, + Item_Code: d.Item_Code, Item: d.Item, } resp.Main = d.Main diff --git a/internal/domain/main-entities/medicine/entity.go b/internal/domain/main-entities/medicine/entity.go index d538f496..bbcfec78 100644 --- a/internal/domain/main-entities/medicine/entity.go +++ b/internal/domain/main-entities/medicine/entity.go @@ -21,8 +21,10 @@ type Medicine struct { Uom *eu.Uom `json:"uom" gorm:"foreignKey:Uom_Code;references:Code"` Dose uint8 `json:"dose"` Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` Stock *int `json:"stock"` Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code" gorm:"size:50"` Item *eit.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/room/base/entity.go b/internal/domain/main-entities/room/base/entity.go index 2ac690b6..d5651ac9 100644 --- a/internal/domain/main-entities/room/base/entity.go +++ b/internal/domain/main-entities/room/base/entity.go @@ -9,17 +9,13 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs - Infra_Id *uint16 `json:"infra_id"` Infra_Code *string `json:"infra_code" gorm:"size:10"` - Unit_Id *uint16 `json:"unit_id"` Unit_Code *string `json:"unit_code" gorm:"size:10"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id"` - Specialist_Id *uint16 `json:"specialist_id"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` Specialist_Code *string `json:"specialist_code" gorm:"size:10"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` } func (Basic) TableName() string { diff --git a/internal/domain/main-entities/room/dto.go b/internal/domain/main-entities/room/dto.go index 0ca2e8d4..2ff41c3a 100644 --- a/internal/domain/main-entities/room/dto.go +++ b/internal/domain/main-entities/room/dto.go @@ -9,10 +9,10 @@ import ( ) type CreateDto struct { - Infra_Id *uint16 `json:"infra_id"` - Unit_Id *uint16 `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Infra_Code *string `json:"infra_code"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` } type ReadListDto struct { @@ -22,10 +22,10 @@ type ReadListDto struct { } type FilterDto struct { - Infra_Id *uint16 `json:"infra-id"` - Unit_Id *uint16 `json:"unit-id"` - Specialist_Id *uint16 `json:"specialist-id"` - Subspecialist_Id *uint16 `json:"subspecialist-id"` + Infra_Code *string `json:"infra-code"` + Unit_Code *string `json:"unit-code"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` } type ReadDetailDto struct { @@ -49,26 +49,26 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Infra_Id *uint16 `json:"infra_id"` - Infra *ei.Infra `json:"infra,omitempty"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` + Infra_Code *string `json:"infra_code"` + Infra *ei.Infra `json:"infra,omitempty"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` } func (d Room) ToResponse() ResponseDto { resp := ResponseDto{ - Infra_Id: d.Infra_Id, - Infra: d.Infra, - Unit_Id: d.Unit_Id, - Unit: d.Unit, - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, - Subspecialist: d.Subspecialist, + Infra_Code: d.Infra_Code, + Infra: d.Infra, + Unit_Code: d.Unit_Code, + Unit: d.Unit, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Subspecialist_Code: d.Subspecialist_Code, + Subspecialist: d.Subspecialist, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/room/entity.go b/internal/domain/main-entities/room/entity.go index 346c7741..49fb8cc6 100644 --- a/internal/domain/main-entities/room/entity.go +++ b/internal/domain/main-entities/room/entity.go @@ -7,5 +7,5 @@ import ( type Room struct { ebase.Basic - Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id"` + Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"` } diff --git a/internal/interface/main-handler/device/handler.go b/internal/interface/main-handler/device/handler.go index 1a3cb18d..c827f20f 100644 --- a/internal/interface/main-handler/device/handler.go +++ b/internal/interface/main-handler/device/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/infra/handler.go b/internal/interface/main-handler/infra/handler.go index 71a8f1ec..fedccf48 100644 --- a/internal/interface/main-handler/infra/handler.go +++ b/internal/interface/main-handler/infra/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/item/handler.go b/internal/interface/main-handler/item/handler.go index 124be7ef..a786e86b 100644 --- a/internal/interface/main-handler/item/handler.go +++ b/internal/interface/main-handler/item/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index e974564b..6d0548e9 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -304,22 +304,22 @@ func SetRoutes() http.Handler { hc.RegCrudByCode(r, "/v1/subspecialist", subspecialist.O) hc.RegCrudByCode(r, "/v1/specialist-position", specialistposition.O) hc.RegCrudByCode(r, "/v1/subspecialist-position", subspecialistposition.O) + hc.RegCrudByCode(r, "/v1/infra", infra.O) hc.RegCrud(r, "/v1/pharmacy-company", pharmacycompany.O) hc.RegCrud(r, "/v1/diagnose-src", diagnosesrc.O) hc.RegCrud(r, "/v1/procedure-src", proceduresrc.O) hc.RegCrud(r, "/v1/uom", uom.O) - hc.RegCrud(r, "/v1/item", item.O) + hc.RegCrudByCode(r, "/v1/item", item.O) hc.RegCrud(r, "/v1/item-price", itemprice.O) - hc.RegCrud(r, "/v1/infra", infra.O) hc.RegCrud(r, "/v1/medicine-group", medicinegroup.O) hc.RegCrud(r, "/v1/medicine-method", medicinemethod.O) hc.RegCrud(r, "/v1/mcu-src-category", mcusrccategory.O) hc.RegCrud(r, "/v1/mcu-src", mcusrc.O) hc.RegCrud(r, "/v1/ethnic", ethnic.O) hc.RegCrud(r, "/v1/insurance-company", insurancecompany.O) - hc.RegCrud(r, "/v1/medicine", medicine.O) - hc.RegCrud(r, "/v1/device", device.O) - hc.RegCrud(r, "/v1/material", material.O) + hc.RegCrudByCode(r, "/v1/medicine", medicine.O) + hc.RegCrudByCode(r, "/v1/device", device.O) + hc.RegCrudByCode(r, "/v1/material", material.O) hc.RegCrud(r, "/v1/doctor-fee", doctorfee.O) hc.RegCrud(r, "/v1/medical-action-src", medicalactionsrc.O) hc.RegCrud(r, "/v1/medical-action-src-item", medicalactionsrcitem.O) diff --git a/internal/interface/main-handler/material/handler.go b/internal/interface/main-handler/material/handler.go index 2b152625..10de8a92 100644 --- a/internal/interface/main-handler/material/handler.go +++ b/internal/interface/main-handler/material/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/medicine/handler.go b/internal/interface/main-handler/medicine/handler.go index 5a5b28e0..b6a3f185 100644 --- a/internal/interface/main-handler/medicine/handler.go +++ b/internal/interface/main-handler/medicine/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/main-use-case/device/case.go b/internal/use-case/main-use-case/device/case.go index ff548a4b..126dff9f 100644 --- a/internal/use-case/main-use-case/device/case.go +++ b/internal/use-case/main-use-case/device/case.go @@ -169,7 +169,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Device var err error @@ -225,7 +225,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Device var err error diff --git a/internal/use-case/main-use-case/device/helper.go b/internal/use-case/main-use-case/device/helper.go index 08964464..21956cc5 100644 --- a/internal/use-case/main-use-case/device/helper.go +++ b/internal/use-case/main-use-case/device/helper.go @@ -30,8 +30,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Device) { data.Code = inputSrc.Code data.Name = inputSrc.Name data.Uom_Code = inputSrc.Uom_Code - data.Item_Id = inputSrc.Item_Id - data.Infra_Id = inputSrc.Infra_Id + data.Item_Code = inputSrc.Item_Code + data.Infra_Code = inputSrc.Infra_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -40,13 +40,13 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { Name: input.Name, ItemGroup_Code: ero.ITGCDevice, Uom_Code: &input.Uom_Code, - Infra_Id: input.Infra_Id, + Infra_Code: input.Infra_Code, } item, err := ui.CreateData(itemCreate, event, tx) if err != nil { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/device/lib.go b/internal/use-case/main-use-case/device/lib.go index 664db248..63c8cedb 100644 --- a/internal/use-case/main-use-case/device/lib.go +++ b/internal/use-case/main-use-case/device/lib.go @@ -81,6 +81,13 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", *input.Id) + } + if err := tx.First(&data, input.Id).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr diff --git a/internal/use-case/main-use-case/division/lib.go b/internal/use-case/main-use-case/division/lib.go index 62a10d5b..0b45ba11 100644 --- a/internal/use-case/main-use-case/division/lib.go +++ b/internal/use-case/main-use-case/division/lib.go @@ -52,7 +52,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di EXISTS ( SELECT 1 FROM "Division" c - WHERE c."Parent_Id" = "Division"."Id" + WHERE c."Parent_Code" = "Division"."Code" ) `) } diff --git a/internal/use-case/main-use-case/infra/case.go b/internal/use-case/main-use-case/infra/case.go index 7c227e8b..4771f3cb 100644 --- a/internal/use-case/main-use-case/infra/case.go +++ b/internal/use-case/main-use-case/infra/case.go @@ -38,12 +38,12 @@ func Create(input e.CreateDto) (*d.Data, error) { } if input.InfraGroup_Code == ero.IFGCRoom { - if input.Parent_Id == nil { + if input.Parent_Code == nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-create-fail", - Detail: "parent_id is required", - Raw: errors.New("parent_id is required"), + Detail: "parent_code is required", + Raw: errors.New("parent_code is required"), } return pl.SetLogError(&event, input) @@ -59,7 +59,7 @@ func Create(input e.CreateDto) (*d.Data, error) { } if input.InfraGroup_Code == ero.IFGCRoom { - input.Infra_Id = &data.Id + input.Infra_Code = &data.Code if err := createRoom(&input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/infra/helper.go b/internal/use-case/main-use-case/infra/helper.go index 35388c85..2e6dc383 100644 --- a/internal/use-case/main-use-case/infra/helper.go +++ b/internal/use-case/main-use-case/infra/helper.go @@ -29,7 +29,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Infra) { data.Code = inputSrc.Code data.Name = inputSrc.Name data.InfraGroup_Code = inputSrc.InfraGroup_Code - data.Parent_Id = inputSrc.Parent_Id + data.Parent_Code = inputSrc.Parent_Code data.Item_Id = inputSrc.Item_Id } @@ -42,7 +42,7 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { tmp := "unit" return &tmp }(), - Infra_Id: input.Parent_Id, + Infra_Code: input.Parent_Code, } item, err := ui.CreateData(itemCreate, event, tx) if err != nil { @@ -55,10 +55,10 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { func createRoom(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { roomCreate := er.CreateDto{ - Infra_Id: input.Infra_Id, - Unit_Id: input.Unit_Id, - Specialist_Id: input.Specialist_Id, - Subspecialist_Id: input.Subspecialist_Id, + Infra_Code: input.Infra_Code, + Unit_Code: input.Unit_Code, + Specialist_Code: input.Specialist_Code, + Subspecialist_Code: input.Subspecialist_Code, } _, err := ur.CreateData(roomCreate, event, tx) if err != nil { diff --git a/internal/use-case/main-use-case/infra/lib.go b/internal/use-case/main-use-case/infra/lib.go index 234104bb..67062b31 100644 --- a/internal/use-case/main-use-case/infra/lib.go +++ b/internal/use-case/main-use-case/infra/lib.go @@ -52,7 +52,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In EXISTS ( SELECT 1 FROM "Infra" c - WHERE c."Parent_Id" = "Infra"."Id" + WHERE c."Parent_Code" = "Infra"."Code" ) `) } @@ -91,6 +91,13 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", *input.Id) + } + tx = tx.Preload("Parent"). Preload("Childrens"). Preload("Item"). @@ -99,7 +106,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e Preload("Rooms.Subspecialist"). Preload("Rooms.Unit") - if err := tx.First(&data, input.Id).Error; err != nil { + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/item/case.go b/internal/use-case/main-use-case/item/case.go index 914d777f..58ce3213 100644 --- a/internal/use-case/main-use-case/item/case.go +++ b/internal/use-case/main-use-case/item/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Item var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Item var err error diff --git a/internal/use-case/main-use-case/item/helper.go b/internal/use-case/main-use-case/item/helper.go index 0ebfcd37..6f7e0c57 100644 --- a/internal/use-case/main-use-case/item/helper.go +++ b/internal/use-case/main-use-case/item/helper.go @@ -21,6 +21,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Item) { data.Name = inputSrc.Name data.ItemGroup_Code = inputSrc.ItemGroup_Code data.Uom_Code = inputSrc.Uom_Code - data.Infra_Id = inputSrc.Infra_Id + data.Infra_Code = inputSrc.Infra_Code data.Stock = inputSrc.Stock } diff --git a/internal/use-case/main-use-case/material/case.go b/internal/use-case/main-use-case/material/case.go index 42346dc6..5f5cec55 100644 --- a/internal/use-case/main-use-case/material/case.go +++ b/internal/use-case/main-use-case/material/case.go @@ -169,7 +169,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Material var err error @@ -225,7 +225,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Material var err error diff --git a/internal/use-case/main-use-case/material/helper.go b/internal/use-case/main-use-case/material/helper.go index 9cfefe27..ee415107 100644 --- a/internal/use-case/main-use-case/material/helper.go +++ b/internal/use-case/main-use-case/material/helper.go @@ -30,8 +30,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Material) { data.Name = inputSrc.Name data.Uom_Code = inputSrc.Uom_Code data.Stock = inputSrc.Stock - data.Item_Id = inputSrc.Item_Id - data.Infra_Id = inputSrc.Infra_Id + data.Item_Code = inputSrc.Item_Code + data.Infra_Code = inputSrc.Infra_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -40,7 +40,7 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { Name: input.Name, ItemGroup_Code: ero.ITGCMaterial, Uom_Code: &input.Uom_Code, - Infra_Id: input.Infra_Id, + Infra_Code: input.Infra_Code, Stock: input.Stock, } item, err := ui.CreateData(itemCreate, event, tx) @@ -48,6 +48,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/medicine/case.go b/internal/use-case/main-use-case/medicine/case.go index 5855d33c..3e5bee2d 100644 --- a/internal/use-case/main-use-case/medicine/case.go +++ b/internal/use-case/main-use-case/medicine/case.go @@ -169,7 +169,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Medicine var err error @@ -225,7 +225,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Medicine var err error diff --git a/internal/use-case/main-use-case/medicine/helper.go b/internal/use-case/main-use-case/medicine/helper.go index 388be819..1cf35762 100644 --- a/internal/use-case/main-use-case/medicine/helper.go +++ b/internal/use-case/main-use-case/medicine/helper.go @@ -33,9 +33,9 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Medicine) { data.MedicineMethod_Code = inputSrc.MedicineMethod_Code data.Uom_Code = inputSrc.Uom_Code data.Dose = inputSrc.Dose - data.Infra_Id = inputSrc.Infra_Id + data.Infra_Code = inputSrc.Infra_Code data.Stock = inputSrc.Stock - data.Item_Id = inputSrc.Item_Id + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -44,7 +44,7 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { Name: input.Name, ItemGroup_Code: ero.ITGCMedicine, Uom_Code: input.Uom_Code, - Infra_Id: input.Infra_Id, + Infra_Code: input.Infra_Code, Stock: input.Stock, } item, err := ui.CreateData(itemCreate, event, tx) @@ -52,6 +52,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/medicine/lib.go b/internal/use-case/main-use-case/medicine/lib.go index 3b9d2fa1..f9fccb2e 100644 --- a/internal/use-case/main-use-case/medicine/lib.go +++ b/internal/use-case/main-use-case/medicine/lib.go @@ -81,8 +81,15 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", *input.Id) + } + tx = tx.Preload("Item") - if err := tx.First(&data, input.Id).Error; err != nil { + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/room/helper.go b/internal/use-case/main-use-case/room/helper.go index cc64e8c5..5e97a653 100644 --- a/internal/use-case/main-use-case/room/helper.go +++ b/internal/use-case/main-use-case/room/helper.go @@ -17,8 +17,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Room) { inputSrc = &inputTemp.CreateDto } - data.Infra_Id = inputSrc.Infra_Id - data.Unit_Id = inputSrc.Unit_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Infra_Code = inputSrc.Infra_Code + data.Unit_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code } From c9d7400dad11fc473bd75642ba2bb748de0b0b40 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 7 Nov 2025 15:34:05 +0700 Subject: [PATCH 53/55] migration from server --- cmd/main-migration/migrations/atlas.sum | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 440bd74d..153eb372 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:A8U7W3JZbEUXu6uzF9wfKvSgX/j+G1nQoxchM989kiw= +h1:D7TdOht9cEt91EEPEvi05Frs3ZFC+Uz+y4K+bebB3BI= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,20 +75,20 @@ h1:A8U7W3JZbEUXu6uzF9wfKvSgX/j+G1nQoxchM989kiw= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= -20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= -20251107071420.sql h1:Q+e+OqjdiuK/sghDQ5NxjU+u2zYl+vh/eRBlUz9Idhg= -20251107074318.sql h1:VbOWMw2rClEWgMnDSejXPqXkFoQ4odVsHn3/UAEiCYA= -20251107075050.sql h1:ZZaKJEWXIJ94/0/2Gzzz+HXjmebEs5eP8iUIot26/c8= -20251107080604.sql h1:aq+tINa0ULCZlJcUK2jaeGh6rRH4jJz3e2NrK47m0Ec= -20251107081830.sql h1:Bl9kniyLWeMqd3nrvgCgiUpdcJWp8qX1F41JAM1WbiE= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= +20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= +20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= +20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= +20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= From e3b601f70385489265fbb5ed3c37562653ffa3cc Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Fri, 7 Nov 2025 16:17:16 +0700 Subject: [PATCH 54/55] infra, item remove parent_id, infra_id --- .../migrations/20251107091033.sql | 4 ++ .../migrations/20251107091209.sql | 2 + .../migrations/20251107091541.sql | 2 + cmd/main-migration/migrations/atlas.sum | 39 ++++++++++--------- internal/domain/main-entities/infra/dto.go | 12 +++--- internal/domain/main-entities/infra/entity.go | 10 ++--- internal/domain/main-entities/item/entity.go | 1 - .../use-case/main-use-case/infra/helper.go | 4 +- internal/use-case/main-use-case/infra/lib.go | 2 +- 9 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 cmd/main-migration/migrations/20251107091033.sql create mode 100644 cmd/main-migration/migrations/20251107091209.sql create mode 100644 cmd/main-migration/migrations/20251107091541.sql diff --git a/cmd/main-migration/migrations/20251107091033.sql b/cmd/main-migration/migrations/20251107091033.sql new file mode 100644 index 00000000..dc0a8f60 --- /dev/null +++ b/cmd/main-migration/migrations/20251107091033.sql @@ -0,0 +1,4 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ALTER COLUMN "Code" SET NOT NULL; +-- Modify "Item" table +ALTER TABLE "public"."Item" DROP COLUMN "Infra_Id"; diff --git a/cmd/main-migration/migrations/20251107091209.sql b/cmd/main-migration/migrations/20251107091209.sql new file mode 100644 index 00000000..d10ae684 --- /dev/null +++ b/cmd/main-migration/migrations/20251107091209.sql @@ -0,0 +1,2 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" DROP CONSTRAINT "fk_Infra_Childrens", DROP CONSTRAINT "fk_Infra_Item", DROP COLUMN "Parent_Id", ADD CONSTRAINT "fk_Infra_Childrens" FOREIGN KEY ("Parent_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251107091541.sql b/cmd/main-migration/migrations/20251107091541.sql new file mode 100644 index 00000000..a3445d0c --- /dev/null +++ b/cmd/main-migration/migrations/20251107091541.sql @@ -0,0 +1,2 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" DROP COLUMN "Item_Id"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 153eb372..30f9fd3c 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:D7TdOht9cEt91EEPEvi05Frs3ZFC+Uz+y4K+bebB3BI= +h1:6umIsneejLUg0V9wUaB2HuCvEHD+2v/dwbxg+y23+wo= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,20 +75,23 @@ h1:D7TdOht9cEt91EEPEvi05Frs3ZFC+Uz+y4K+bebB3BI= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= -20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= -20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= -20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= -20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= -20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= -20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= -20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= -20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= -20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= +20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= +20251107071420.sql h1:Q+e+OqjdiuK/sghDQ5NxjU+u2zYl+vh/eRBlUz9Idhg= +20251107074318.sql h1:VbOWMw2rClEWgMnDSejXPqXkFoQ4odVsHn3/UAEiCYA= +20251107075050.sql h1:ZZaKJEWXIJ94/0/2Gzzz+HXjmebEs5eP8iUIot26/c8= +20251107080604.sql h1:aq+tINa0ULCZlJcUK2jaeGh6rRH4jJz3e2NrK47m0Ec= +20251107081830.sql h1:Bl9kniyLWeMqd3nrvgCgiUpdcJWp8qX1F41JAM1WbiE= +20251107091033.sql h1:ETTCaAHBT6wipXrEGXIepxLMdD2LNzprPAp99+jnW0w= +20251107091209.sql h1:BUI9JlTzZxCdVHsrRbOye7m47AJEvXNhCaCVv/HzILs= +20251107091541.sql h1:/tW2uXv/o0Q2E4lQzlYNgEftvDqjf3c2AQpZ83Vb6zc= diff --git a/internal/domain/main-entities/infra/dto.go b/internal/domain/main-entities/infra/dto.go index 28ff8d93..dfe271e5 100644 --- a/internal/domain/main-entities/infra/dto.go +++ b/internal/domain/main-entities/infra/dto.go @@ -13,7 +13,7 @@ type CreateDto struct { Name string `json:"name" validate:"maxLength=50"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" validate:"maxLength=15"` Parent_Code *string `json:"parent_code"` - Item_Id *uint `json:"-"` + Item_Code *string `json:"-"` Unit_Code *string `json:"unit_code"` Specialist_Code *string `json:"specialist_code"` Subspecialist_Code *string `json:"subspecialist_code"` @@ -78,11 +78,11 @@ func (d Infra) ToResponse() ResponseDto { Name: d.Name, InfraGroup_Code: d.InfraGroup_Code, Parent_Code: d.Parent_Code, - Parent: d.Parent, - Childrens: d.Childrens, - Item_Code: d.Item_Code, - Item: d.Item, - Rooms: d.Rooms, + // Parent: d.Parent, + Childrens: d.Childrens, + Item_Code: d.Item_Code, + Item: d.Item, + Rooms: d.Rooms, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/infra/entity.go b/internal/domain/main-entities/infra/entity.go index dfc19e3d..51cc8eaa 100644 --- a/internal/domain/main-entities/infra/entity.go +++ b/internal/domain/main-entities/infra/entity.go @@ -11,15 +11,13 @@ import ( type Infra struct { ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"uniqueIndex;size:10"` + Code string `json:"code" gorm:"uniqueIndex;size:10;not null"` Name string `json:"name" gorm:"size:50"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" gorm:"size:15"` - Parent_Id *uint16 `json:"parent_id"` Parent_Code *string `json:"parent_code" gorm:"size:10"` - Parent *Infra `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"` - Childrens []Infra `json:"childrens" gorm:"foreignKey:Parent_Id"` // may need references to self - Item_Id *uint `json:"item_id"` + Parent *Infra `json:"parent" gorm:"foreignKey:Parent_Code;references:Code"` + Childrens []Infra `json:"childrens" gorm:"foreignKey:Parent_Code;references:Code"` Item_Code *string `json:"item_code" gorm:"size:50"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` Rooms []erb.Basic `json:"rooms" gorm:"foreignKey:Infra_Code;references:Code"` } diff --git a/internal/domain/main-entities/item/entity.go b/internal/domain/main-entities/item/entity.go index 406c57e6..fc721713 100644 --- a/internal/domain/main-entities/item/entity.go +++ b/internal/domain/main-entities/item/entity.go @@ -14,7 +14,6 @@ type Item struct { ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code" gorm:"size:15"` Uom_Code *string `json:"uom_code" gorm:"size:10"` Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` - Infra_Id *uint16 `json:"infra_id"` Infra_Code *string `json:"infra_code" gorm:"size:10"` Stock *int `json:"stock"` } diff --git a/internal/use-case/main-use-case/infra/helper.go b/internal/use-case/main-use-case/infra/helper.go index 2e6dc383..81de5389 100644 --- a/internal/use-case/main-use-case/infra/helper.go +++ b/internal/use-case/main-use-case/infra/helper.go @@ -30,7 +30,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Infra) { data.Name = inputSrc.Name data.InfraGroup_Code = inputSrc.InfraGroup_Code data.Parent_Code = inputSrc.Parent_Code - data.Item_Id = inputSrc.Item_Id + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -49,7 +49,7 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/infra/lib.go b/internal/use-case/main-use-case/infra/lib.go index 67062b31..5e0592c3 100644 --- a/internal/use-case/main-use-case/infra/lib.go +++ b/internal/use-case/main-use-case/infra/lib.go @@ -126,7 +126,7 @@ func UpdateData(input e.UpdateDto, data *e.Infra, event *pl.Event, dbx ...*gorm. } else { tx = dg.I } - data.Parent = nil + // data.Parent = nil data.Childrens = nil data.Item = nil data.Rooms = nil From 8d9fe70d41002560da3157da26c06cb5de335aec Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 7 Nov 2025 16:21:03 +0700 Subject: [PATCH 55/55] migration from server --- cmd/main-migration/migrations/atlas.sum | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 30f9fd3c..0da32e52 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:6umIsneejLUg0V9wUaB2HuCvEHD+2v/dwbxg+y23+wo= +h1:69CxJYTc7MIeFR2nLQwjoba/TUnw7lIzVApYkI34yss= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,23 +75,23 @@ h1:6umIsneejLUg0V9wUaB2HuCvEHD+2v/dwbxg+y23+wo= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= -20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= -20251107071420.sql h1:Q+e+OqjdiuK/sghDQ5NxjU+u2zYl+vh/eRBlUz9Idhg= -20251107074318.sql h1:VbOWMw2rClEWgMnDSejXPqXkFoQ4odVsHn3/UAEiCYA= -20251107075050.sql h1:ZZaKJEWXIJ94/0/2Gzzz+HXjmebEs5eP8iUIot26/c8= -20251107080604.sql h1:aq+tINa0ULCZlJcUK2jaeGh6rRH4jJz3e2NrK47m0Ec= -20251107081830.sql h1:Bl9kniyLWeMqd3nrvgCgiUpdcJWp8qX1F41JAM1WbiE= -20251107091033.sql h1:ETTCaAHBT6wipXrEGXIepxLMdD2LNzprPAp99+jnW0w= -20251107091209.sql h1:BUI9JlTzZxCdVHsrRbOye7m47AJEvXNhCaCVv/HzILs= -20251107091541.sql h1:/tW2uXv/o0Q2E4lQzlYNgEftvDqjf3c2AQpZ83Vb6zc= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= +20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= +20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= +20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= +20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= +20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= +20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= +20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI=