From 7d0f42aba252753507ba2c7c017921a9683be23d Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 13 Nov 2025 04:30:12 +0700 Subject: [PATCH 01/39] feat/dockerize: added the Dockerfile --- Dockerfile-main-api | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Dockerfile-main-api diff --git a/Dockerfile-main-api b/Dockerfile-main-api new file mode 100644 index 00000000..821cd4a2 --- /dev/null +++ b/Dockerfile-main-api @@ -0,0 +1,12 @@ +FROM golang:1.24.10 AS builder +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -o ./cmd/main-api/main-api ./cmd/main-api/main.go + +FROM alpine:latest +WORKDIR /app +COPY --from=builder /src/cmd/main-api/main-api . +COPY --from=builder /src/cmd/main-api/config.yml . +CMD ["./main-api"] From 7734e184dce9b34bd69171737cbb06227ee71df0 Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 4 Dec 2025 11:35:03 +0700 Subject: [PATCH 02/39] adjust hard delete in patient --- internal/use-case/main-use-case/patient/lib.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/use-case/main-use-case/patient/lib.go b/internal/use-case/main-use-case/patient/lib.go index e615c854..e1a5fc42 100644 --- a/internal/use-case/main-use-case/patient/lib.go +++ b/internal/use-case/main-use-case/patient/lib.go @@ -141,7 +141,7 @@ func DeleteData(data *e.Patient, event *pl.Event, dbx ...*gorm.DB) error { tx = dg.I } - if err := tx.Delete(&data).Error; err != nil { + if err := tx.Unscoped().Delete(&data).Error; err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-delete-fail", From 320ce99b0ee41a30c7818840d0681a2a9b12abf6 Mon Sep 17 00:00:00 2001 From: ari Date: Thu, 4 Dec 2025 13:52:24 +0700 Subject: [PATCH 03/39] update procedure report main api --- .../domain/main-entities/action-report/dto.go | 90 -------------- .../main-entities/action-report/entity.go | 51 -------- .../main-entities/procedure-report/dto.go | 110 ++++++++++++++++++ .../main-entities/procedure-report/entity.go | 68 +++++++++++ .../domain/references/clinical/clinical.go | 39 ++++--- .../interface/main-handler/main-handler.go | 4 +- .../handler.go | 4 +- internal/interface/migration/main-entities.go | 4 +- .../main-use-case/action-report/helper.go | 28 ----- .../case.go | 18 +-- .../main-use-case/procedure-report/helper.go | 39 +++++++ .../lib.go | 22 ++-- .../middleware-runner.go | 14 +-- .../middleware.go | 2 +- .../tycovar.go | 10 +- 15 files changed, 277 insertions(+), 226 deletions(-) delete mode 100644 internal/domain/main-entities/action-report/dto.go delete mode 100644 internal/domain/main-entities/action-report/entity.go create mode 100644 internal/domain/main-entities/procedure-report/dto.go create mode 100644 internal/domain/main-entities/procedure-report/entity.go rename internal/interface/main-handler/{action-report => procedure-report}/handler.go (93%) delete mode 100644 internal/use-case/main-use-case/action-report/helper.go rename internal/use-case/main-use-case/{action-report => procedure-report}/case.go (95%) create mode 100644 internal/use-case/main-use-case/procedure-report/helper.go rename internal/use-case/main-use-case/{action-report => procedure-report}/lib.go (83%) rename internal/use-case/main-use-case/{action-report => procedure-report}/middleware-runner.go (86%) rename internal/use-case/main-use-case/{action-report => procedure-report}/middleware.go (89%) rename internal/use-case/main-use-case/{action-report => procedure-report}/tycovar.go (74%) diff --git a/internal/domain/main-entities/action-report/dto.go b/internal/domain/main-entities/action-report/dto.go deleted file mode 100644 index 45c26d17..00000000 --- a/internal/domain/main-entities/action-report/dto.go +++ /dev/null @@ -1,90 +0,0 @@ -package actionreport - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" - ee "simrs-vx/internal/domain/main-entities/encounter" - "time" - - pa "simrs-vx/internal/lib/auth" -) - -type CreateDto struct { - Encounter_Id uint64 `json:"encounter_id" validate:"required"` - Date *time.Time `json:"date" validate:"required"` - Doctor_Code string `json:"doctor_code" validate:"required"` - Operator_Employe_Id uint `json:"operator_employe_id" validate:"required"` - Assistant_Employe_Id uint `json:"assistant_employe_id" validate:"required"` - Instrumentor_Employe_Id uint `json:"instrumentor_employe_id" validate:"required"` - Diagnose *string `json:"diagnose"` - Nurse_Code string `json:"nurse_code" validate:"required"` - Value string `json:"value" validate:"required"` - - pa.AuthInfo -} - -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"` -} - -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 uint64 `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Date *time.Time `json:"date"` - Doctor_Code string `json:"doctor_code"` - Operator_Employe_Id uint `json:"operator_employe_id"` - Assistant_Employe_Id uint `json:"assistant_employe_id"` - Instrumentor_Employe_Id uint `json:"instrumentor_employe_id"` - Diagnose *string `json:"diagnose"` - Nurse_Code string `json:"nurse_code"` - Value *string `json:"value"` -} - -func (d ActionReport) ToResponse() ResponseDto { - resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Encounter: d.Encounter, - Date: d.Date, - Doctor_Code: d.Doctor_Code, - Operator_Employe_Id: d.Operator_Employe_Id, - Assistant_Employe_Id: d.Assistant_Employe_Id, - Instrumentor_Employe_Id: d.Instrumentor_Employe_Id, - Nurse_Code: d.Nurse_Code, - Value: &d.Value, - } - resp.Main = d.Main - return resp -} - -func ToResponseList(data []ActionReport) []ResponseDto { - resp := make([]ResponseDto, len(data)) - for i, u := range data { - resp[i] = u.ToResponse() - } - return resp -} diff --git a/internal/domain/main-entities/action-report/entity.go b/internal/domain/main-entities/action-report/entity.go deleted file mode 100644 index 8447a2e5..00000000 --- a/internal/domain/main-entities/action-report/entity.go +++ /dev/null @@ -1,51 +0,0 @@ -package actionreport - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" - ed "simrs-vx/internal/domain/main-entities/doctor" - eem "simrs-vx/internal/domain/main-entities/employee" - ee "simrs-vx/internal/domain/main-entities/encounter" - en "simrs-vx/internal/domain/main-entities/nurse" - "time" -) - -type ActionReport struct { - ecore.Main // adjust this according to the needs - Encounter_Id uint64 `json:"encounter_id" gorm:"foreignKey"` - Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Date *time.Time `json:"date" gorm:"not null;size:20"` - Doctor_Code string `json:"doctor_code" gorm:"size:10"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` - Operator_Employe_Id uint `json:"operator_employe_id"` - Operator_Employe *eem.Employee `json:"operator_employe,omitempty" gorm:"foreignKey:Operator_Employe_Id;references:Id"` - Assistant_Employe_Id uint `json:"assistant_employe_id"` - Instrumentor_Employe_Id uint `json:"instrumentor_employe_id"` - Instrumentor_Employe *eem.Employee `json:"instrumentor_employe,omitempty" gorm:"foreignKey:Instrumentor_Employe_Id;references:Id"` - Diagnose *string `json:"diagnose" gorm:"size:1024"` - Nurse_Code string `json:"nurse_code" gorm:"size:10"` - Nurse *en.Nurse `json:"nurse,omitempty" gorm:"foreignKey:Nurse_Code;references:Code"` - Value string `json:"value"` - // SurgerySize_Code *string `json:"surgerySize_code" gorm:"size:10"` - // Billing_Code *string `json:"billing_code" gorm:"size:10"` - // SurgerySystem_Code *string `json:"surgerySystem_code" gorm:"size:10"` - // StartAt *string `json:"startAt" gorm:"size:20"` - // EndAt *string `json:"endAt" gorm:"size:20"` - // AnesthesiaStartAt *string `json:"anesthesiaStartAt" gorm:"size:20"` - // AnesthesiaEndAt *string `json:"anesthesiaEndAt" gorm:"size:20"` - // SurgeryType_Code *string `json:"surgeryType_code" gorm:"size:10"` - // SurgeryStage_Code *string `json:"surgeryStage_code" gorm:"size:10"` - // BornMortality_Code *string `json:"bornMortality_code" gorm:"size:10"` - // BornLocation_Code *string `json:"bornLocation_code" gorm:"size:10"` - // Weight *string `json:"weight" gorm:"size:10"` - // BornNotes *string `json:"bornNotes" gorm:"size:1024"` - // Description *string `json:"notes" gorm:"size:1024"` - // BleedingAmount *uint16 `json:"bleedingAmount" gorm:"size:10"` - // BloodInType_Code *string `json:"bloodInType_code" gorm:"size:10"` - // BloodInAmount *uint16 `json:"bloodInAmount" gorm:"size:10"` - // Brand *string `json:"brand" gorm:"size:100"` - // ImplantName *string `json:"implantName" gorm:"size:100"` - // ImplantRegisterNumber *string `json:"implantRegisterNumber" gorm:"size:100"` - // ImplantCompanionName *string `json:"implantCompanionName" gorm:"size:100"` - // SpecimentDest_Code *string `json:"specimentDest" gorm:"size:100"` - // TissueInfo *string `json:"tissueInfo" gorm:"size:100"` -} diff --git a/internal/domain/main-entities/procedure-report/dto.go b/internal/domain/main-entities/procedure-report/dto.go new file mode 100644 index 00000000..9cd400be --- /dev/null +++ b/internal/domain/main-entities/procedure-report/dto.go @@ -0,0 +1,110 @@ +package procedurereport + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ee "simrs-vx/internal/domain/main-entities/encounter" + "time" + + pa "simrs-vx/internal/lib/auth" +) + +type CreateDto struct { + Encounter_Id uint64 `json:"encounter_id" validate:"required"` + Date *time.Time `json:"date" validate:"required"` + Doctor_Code string `json:"doctor_code" validate:"required"` + Operator_Name string `json:"operator_name" validate:"required"` + Assistant_Name string `json:"assistant_name" validate:"required"` + Instrumentor_Name string `json:"instrumentor_name" validate:"required"` + Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code" validate:"required"` + Anesthesia_Nurse_Name string `json:"anesthesia_nurse_name" validate:"required"` + Diagnose *string `json:"diagnose"` + Nurse_Name string `json:"nurse_name" validate:"required"` + ProcedureValue string `json:"procedure_value" validate:"required"` + ExecutionValue string `json:"execution_value" validate:"required"` + Type string `json:"type" validate:"required"` + + pa.AuthInfo + + // PROPER + // Operator_Employe_Id uint `json:"operator_employe_id" validate:"required"` + // Assistant_Employe_Id uint `json:"assistant_employe_id" validate:"required"` + // Instrumentor_Employe_Id uint `json:"instrumentor_employe_id" validate:"required"` + // Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code" validate:"required"` + // Anesthesia_Nurse_Employe_Id uint `json:"anesthesia_nurse_employe_id" validate:"required"` + // Nurse_Code string `json:"nurse_code" validate:"required"` +} + +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"` +} + +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 uint64 `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Date *time.Time `json:"date"` + Doctor_Code string `json:"doctor_code"` + Operator_Name string `json:"operator_name"` + Assistant_Name string `json:"assistant_name"` + Instrumentor_Name string `json:"instrumentor_name"` + Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code"` + Anesthesia_Nurse_Name string `json:"anesthesia_nurse_name"` + Diagnose *string `json:"diagnose"` + Nurse_Name string `json:"nurse_name"` + ProcedureValue *string `json:"procedure_value"` + ExecutionValue *string `json:"execution_value"` + Type string `json:"type"` +} + +func (d ProcedureReport) ToResponse() ResponseDto { + resp := ResponseDto{ + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Date: d.Date, + Doctor_Code: d.Doctor_Code, + Operator_Name: d.Operator_Name, + Assistant_Name: d.Assistant_Name, + Instrumentor_Name: d.Instrumentor_Name, + Anesthesia_Doctor_Code: d.Anesthesia_Doctor_Code, + Anesthesia_Nurse_Name: d.Anesthesia_Nurse_Name, + Nurse_Name: d.Nurse_Name, + ProcedureValue: &d.ProcedureValue, + ExecutionValue: &d.ExecutionValue, + Type: d.Type, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []ProcedureReport) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/procedure-report/entity.go b/internal/domain/main-entities/procedure-report/entity.go new file mode 100644 index 00000000..f25bf604 --- /dev/null +++ b/internal/domain/main-entities/procedure-report/entity.go @@ -0,0 +1,68 @@ +package procedurereport + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ed "simrs-vx/internal/domain/main-entities/doctor" + eem "simrs-vx/internal/domain/main-entities/employee" + ee "simrs-vx/internal/domain/main-entities/encounter" + "time" +) + +type ProcedureReport struct { + ecore.Main // adjust this according to the needs + Encounter_Id uint64 `json:"encounter_id" gorm:"foreignKey"` + Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + Date *time.Time `json:"date" gorm:"not null;size:20"` + Doctor_Code string `json:"doctor_code" gorm:"size:10"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` + Operator_Name string `json:"operator_name"` + Assistant_Name string `json:"assistant_name"` + Instrumentor_Name string `json:"instrumentor_name"` + Diagnose *string `json:"diagnose" gorm:"size:1024"` + Nurse_Name string `json:"nurse_code" gorm:"size:10"` + Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code" gorm:"size:10"` + Anesthesia *eem.Employee `json:"anesthesia,omitempty" gorm:"foreignKey:Anesthesia_Doctor_Code;references:Code"` + Anesthesia_Nurse_Name string `json:"anesthesia_nurse_name"` + ProcedureValue string `json:"procedure_value"` + ExecutionValue string `json:"execution_value"` + Type string `json:"type"` + + // SurgerySize_Code *string `json:"surgerySize_code" gorm:"size:10"` + // Billing_Code *string `json:"billing_code" gorm:"size:10"` + // SurgerySystem_Code *string `json:"surgerySystem_code" gorm:"size:10"` + // StartAt *string `json:"startAt" gorm:"size:20"` + // EndAt *string `json:"endAt" gorm:"size:20"` + // AnesthesiaStartAt *string `json:"anesthesiaStartAt" gorm:"size:20"` + // AnesthesiaEndAt *string `json:"anesthesiaEndAt" gorm:"size:20"` + // SurgeryType_Code *string `json:"surgeryType_code" gorm:"size:10"` + // SurgeryStage_Code *string `json:"surgeryStage_code" gorm:"size:10"` + // BornMortality_Code *string `json:"bornMortality_code" gorm:"size:10"` + // BornLocation_Code *string `json:"bornLocation_code" gorm:"size:10"` + // Weight *string `json:"weight" gorm:"size:10"` + // BornNotes *string `json:"bornNotes" gorm:"size:1024"` + // Description *string `json:"notes" gorm:"size:1024"` + // BleedingAmount *uint16 `json:"bleedingAmount" gorm:"size:10"` + // BloodInType_Code *string `json:"bloodInType_code" gorm:"size:10"` + // BloodInAmount *uint16 `json:"bloodInAmount" gorm:"size:10"` + // Brand *string `json:"brand" gorm:"size:100"` + // ImplantName *string `json:"implantName" gorm:"size:100"` + // ImplantRegisterNumber *string `json:"implantRegisterNumber" gorm:"size:100"` + // ImplantCompanionName *string `json:"implantCompanionName" gorm:"size:100"` + // SpecimentDest_Code *string `json:"specimentDest" gorm:"size:100"` + // TissueInfo *string `json:"tissueInfo" gorm:"size:100"` + + //PROPER + // Doctor_Code string `json:"doctor_code" gorm:"size:10"` + // Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` + // Operator_Employe_Id uint `json:"operator_employe_id"` + // Operator_Employe *eem.Employee `json:"operator_employe,omitempty" gorm:"foreignKey:Operator_Employe_Id;references:Id"` + // Assistant_Employe_Id uint `json:"assistant_employe_id"` + // Instrumentor_Employe_Id uint `json:"instrumentor_employe_id"` + // Instrumentor_Employe *eem.Employee `json:"instrumentor_employe,omitempty" gorm:"foreignKey:Instrumentor_Employe_Id;references:Id"` + // Nurse_Code string `json:"nurse_code" gorm:"size:10"` + // Nurse *en.Nurse `json:"nurse,omitempty" gorm:"foreignKey:Nurse_Code;references:Code"` + // Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code" gorm:"size:10"` + // Anesthesia *eem.Employee `json:"anesthesia,omitempty" gorm:"foreignKey:Anesthesia_Doctor_Code;references:Code"` + // Anesthesia_Nurse_Employe_Id uint `json:"anesthesia_nurse_employe_id"` + // Anesthesia_Nurse *eem.Employee `json:"anesthesia_nurse,omitempty" gorm:"foreignKey:Anesthesia_Nurse_Employe_Id;references:Id"` +} diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index a9d3fc2b..3054c130 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -204,26 +204,26 @@ const ( MSCMicroLab McuScopeCode = "micro-lab" MSCApLab McuScopeCode = "ap-lab" - SSCSmall SurgerySizeCode = "" - SSCMedium SurgerySizeCode = "" - SSCLarge SurgerySizeCode = "" - SSCSpecial SurgerySizeCode = "" + SSCSmall SurgerySizeCode = "small" + SSCMedium SurgerySizeCode = "medium" + SSCLarge SurgerySizeCode = "large" + SSCSpecial SurgerySizeCode = "special" - SSyCCito SurgerySystemCode = "" - SSyCUrgent SurgerySystemCode = "" - SSyCEfective SurgerySystemCode = "" - SSyCSpecial SurgerySystemCode = "" + SSyCCito SurgerySystemCode = "cito" + SSyCUrgent SurgerySystemCode = "urgent" + SSyCEfective SurgerySystemCode = "efective" + SSyCSpecial SurgerySystemCode = "special" - STCClean SurgeryTypeCode = "" - STCCleanCtm SurgeryTypeCode = "" - STCUncleanCtm SurgeryTypeCode = "" - STCUnclean SurgeryTypeCode = "" + STCClean SurgeryTypeCode = "clean" + STCCleanCtm SurgeryTypeCode = "clean-ctm" + STCUncleanCtm SurgeryTypeCode = "unclean-ctm" + STCUnclean SurgeryTypeCode = "unclean" - SStCFirst SurgeryStageCode = "" - SStCRepeat SurgeryStageCode = "" + SStCFirst SurgeryStageCode = "first" + SStCRepeat SurgeryStageCode = "repeat" - BMCAlive BornMortalityCode = "" - BMCDead BornMortalityCode = "" + BMCAlive BornMortalityCode = "alive" + BMCDead BornMortalityCode = "dead" BLCExtMiw BornLocationCode = "" BLCExtDoc BornLocationCode = "" @@ -360,8 +360,11 @@ type HeadToToe struct { BodyOthers string `json:"body-others,omitempty"` } -type RecordAction struct { - Procedures []string `json:"procedures"` +type ProcedureRecord struct { + Procedures []CodeWithName `json:"procedures"` +} + +type ProcedureExecution struct { SurgerySize_Code *string `json:"surgerySize_code"` Billing_Code *string `json:"billing_code"` SurgerySystem_Code *string `json:"surgerySystem_code"` diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index d7c482e0..86b0c2aa 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -4,7 +4,6 @@ import ( "net/http" /******************** main / transaction ********************/ - actionreport "simrs-vx/internal/interface/main-handler/action-report" adime "simrs-vx/internal/interface/main-handler/adime" admemployeehist "simrs-vx/internal/interface/main-handler/adm-employee-hist" ambulancetransportrequest "simrs-vx/internal/interface/main-handler/ambulance-transport-req" @@ -34,6 +33,7 @@ import ( practiceschedule "simrs-vx/internal/interface/main-handler/practice-schedule" prescription "simrs-vx/internal/interface/main-handler/prescription" prescriptionitem "simrs-vx/internal/interface/main-handler/prescription-item" + procedurereport "simrs-vx/internal/interface/main-handler/procedure-report" procedureroomorder "simrs-vx/internal/interface/main-handler/procedure-room-order" procedureroomorderitem "simrs-vx/internal/interface/main-handler/procedure-room-order-item" responsibledoctorhist "simrs-vx/internal/interface/main-handler/responsible-doctor-hist" @@ -176,7 +176,7 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/sbar", auth.GuardMW, sbar.O) hc.RegCrud(r, "/v1/prescription-item", prescriptionitem.O) hc.RegCrud(r, "/v1/device-order-item", deviceorderitem.O) - hc.RegCrud(r, "/v1/action-report", auth.GuardMW, actionreport.O) + hc.RegCrud(r, "/v1/procedure-report", auth.GuardMW, procedurereport.O) hc.RegCrud(r, "/v1/material-order-item", materialorderitem.O) hk.GroupRoutes("/v1/encounter", r, auth.GuardMW, hk.MapHandlerFunc{ diff --git a/internal/interface/main-handler/action-report/handler.go b/internal/interface/main-handler/procedure-report/handler.go similarity index 93% rename from internal/interface/main-handler/action-report/handler.go rename to internal/interface/main-handler/procedure-report/handler.go index 0fdd1851..a648463b 100644 --- a/internal/interface/main-handler/action-report/handler.go +++ b/internal/interface/main-handler/procedure-report/handler.go @@ -8,8 +8,8 @@ import ( // ua "github.com/karincake/tumpeng/auth/svc" - e "simrs-vx/internal/domain/main-entities/action-report" - u "simrs-vx/internal/use-case/main-use-case/action-report" + e "simrs-vx/internal/domain/main-entities/procedure-report" + u "simrs-vx/internal/use-case/main-use-case/procedure-report" pa "simrs-vx/internal/lib/auth" diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 34530d78..8b43f165 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -1,7 +1,6 @@ package migration import ( - actionreport "simrs-vx/internal/domain/main-entities/action-report" adime "simrs-vx/internal/domain/main-entities/adime" admemployeehist "simrs-vx/internal/domain/main-entities/adm-employee-hist" ambulancetransportreq "simrs-vx/internal/domain/main-entities/ambulance-transport-req" @@ -82,6 +81,7 @@ import ( practiceschedule "simrs-vx/internal/domain/main-entities/practice-schedule" prescription "simrs-vx/internal/domain/main-entities/prescription" prescriptionitem "simrs-vx/internal/domain/main-entities/prescription-item" + procedurereport "simrs-vx/internal/domain/main-entities/procedure-report" procedureroom "simrs-vx/internal/domain/main-entities/procedure-room" procedureroomorder "simrs-vx/internal/domain/main-entities/procedure-room-order" procedureroomorderitem "simrs-vx/internal/domain/main-entities/procedure-room-order-item" @@ -234,6 +234,6 @@ func getMainEntities() []any { &resume.Resume{}, &vclaimreference.VclaimReference{}, &screening.Screening{}, - &actionreport.ActionReport{}, + &procedurereport.ProcedureReport{}, } } diff --git a/internal/use-case/main-use-case/action-report/helper.go b/internal/use-case/main-use-case/action-report/helper.go deleted file mode 100644 index efe4532e..00000000 --- a/internal/use-case/main-use-case/action-report/helper.go +++ /dev/null @@ -1,28 +0,0 @@ -/* -DESCRIPTION: -Any functions that are used internally by the use-case -*/ -package actionreport - -import ( - e "simrs-vx/internal/domain/main-entities/action-report" -) - -func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ActionReport) { - 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.Date = inputSrc.Date - data.Doctor_Code = inputSrc.Doctor_Code - data.Operator_Employe_Id = inputSrc.Operator_Employe_Id - data.Assistant_Employe_Id = inputSrc.Assistant_Employe_Id - data.Instrumentor_Employe_Id = inputSrc.Instrumentor_Employe_Id - data.Nurse_Code = inputSrc.Nurse_Code - data.Value = inputSrc.Value -} diff --git a/internal/use-case/main-use-case/action-report/case.go b/internal/use-case/main-use-case/procedure-report/case.go similarity index 95% rename from internal/use-case/main-use-case/action-report/case.go rename to internal/use-case/main-use-case/procedure-report/case.go index 2ae0f268..e44cfaee 100644 --- a/internal/use-case/main-use-case/action-report/case.go +++ b/internal/use-case/main-use-case/procedure-report/case.go @@ -1,10 +1,10 @@ -package actionreport +package procedurereport import ( "errors" "strconv" - e "simrs-vx/internal/domain/main-entities/action-report" + e "simrs-vx/internal/domain/main-entities/procedure-report" dg "github.com/karincake/apem/db-gorm-pg" d "github.com/karincake/dodol" @@ -15,10 +15,10 @@ import ( "gorm.io/gorm" ) -const source = "action-report" +const source = "procedure-report" func Create(input e.CreateDto) (*d.Data, error) { - data := e.ActionReport{} + data := e.ProcedureReport{} event := pl.Event{ Feature: "Create", @@ -85,8 +85,8 @@ func Create(input e.CreateDto) (*d.Data, error) { } func ReadList(input e.ReadListDto) (*d.Data, error) { - var data *e.ActionReport - var dataList []e.ActionReport + var data *e.ProcedureReport + var dataList []e.ProcedureReport var metaList *e.MetaDto var err error @@ -138,7 +138,7 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { } func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { - var data *e.ActionReport + var data *e.ProcedureReport var err error event := pl.Event{ @@ -186,7 +186,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { func Update(input e.UpdateDto) (*d.Data, error) { rdDto := e.ReadDetailDto{Id: input.Id} - var data *e.ActionReport + var data *e.ProcedureReport var err error event := pl.Event{ @@ -242,7 +242,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { func Delete(input e.DeleteDto) (*d.Data, error) { rdDto := e.ReadDetailDto{Id: input.Id} - var data *e.ActionReport + var data *e.ProcedureReport var err error event := pl.Event{ diff --git a/internal/use-case/main-use-case/procedure-report/helper.go b/internal/use-case/main-use-case/procedure-report/helper.go new file mode 100644 index 00000000..9fb87778 --- /dev/null +++ b/internal/use-case/main-use-case/procedure-report/helper.go @@ -0,0 +1,39 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package procedurereport + +import ( + e "simrs-vx/internal/domain/main-entities/procedure-report" +) + +func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ProcedureReport) { + 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.Date = inputSrc.Date + data.Doctor_Code = inputSrc.Doctor_Code + data.Operator_Name = inputSrc.Operator_Name + data.Assistant_Name = inputSrc.Assistant_Name + data.Instrumentor_Name = inputSrc.Instrumentor_Name + data.Anesthesia_Doctor_Code = inputSrc.Anesthesia_Doctor_Code + data.Anesthesia_Nurse_Name = inputSrc.Anesthesia_Nurse_Name + data.Diagnose = inputSrc.Diagnose + data.Nurse_Name = inputSrc.Nurse_Name + data.ProcedureValue = inputSrc.ProcedureValue + data.ExecutionValue = inputSrc.ExecutionValue + data.Type = inputSrc.Type + + //PROPER + // data.Operator_Employe_Id = inputSrc.Operator_Employe_Id + // data.Assistant_Employe_Id = inputSrc.Assistant_Employe_Id + // data.Instrumentor_Employe_Id = inputSrc.Instrumentor_Employe_Id + // data.Nurse_Code = inputSrc.Nurse_Code +} diff --git a/internal/use-case/main-use-case/action-report/lib.go b/internal/use-case/main-use-case/procedure-report/lib.go similarity index 83% rename from internal/use-case/main-use-case/action-report/lib.go rename to internal/use-case/main-use-case/procedure-report/lib.go index 5a272cce..0588a944 100644 --- a/internal/use-case/main-use-case/action-report/lib.go +++ b/internal/use-case/main-use-case/procedure-report/lib.go @@ -1,7 +1,7 @@ -package actionreport +package procedurereport import ( - e "simrs-vx/internal/domain/main-entities/action-report" + e "simrs-vx/internal/domain/main-entities/procedure-report" plh "simrs-vx/pkg/lib-helper" pl "simrs-vx/pkg/logger" @@ -12,10 +12,10 @@ import ( "gorm.io/gorm" ) -func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.ActionReport, error) { +func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.ProcedureReport, error) { pl.SetLogInfo(event, nil, "started", "DBCreate") - data := e.ActionReport{} + data := e.ProcedureReport{} setData(&input, &data) var tx *gorm.DB @@ -33,9 +33,9 @@ func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.ActionR return &data, nil } -func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.ActionReport, *e.MetaDto, error) { +func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.ProcedureReport, *e.MetaDto, error) { pl.SetLogInfo(event, input, "started", "DBReadList") - data := []e.ActionReport{} + data := []e.ProcedureReport{} pagination := gh.Pagination{} count := int64(0) meta := e.MetaDto{} @@ -48,7 +48,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Ac } tx = tx. - Model(&e.ActionReport{}). + Model(&e.ProcedureReport{}). Scopes(gh.Preload(input.Includes)). Scopes(gh.Filter(input.FilterDto)). Count(&count). @@ -70,9 +70,9 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Ac return data, &meta, nil } -func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e.ActionReport, error) { +func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e.ProcedureReport, error) { pl.SetLogInfo(event, input, "started", "DBReadDetail") - data := e.ActionReport{} + data := e.ProcedureReport{} var tx *gorm.DB if len(dbx) > 0 { @@ -91,7 +91,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e return &data, nil } -func UpdateData(input e.UpdateDto, data *e.ActionReport, event *pl.Event, dbx ...*gorm.DB) error { +func UpdateData(input e.UpdateDto, data *e.ProcedureReport, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, data, "started", "DBUpdate") setData(&input, data) @@ -116,7 +116,7 @@ func UpdateData(input e.UpdateDto, data *e.ActionReport, event *pl.Event, dbx .. return nil } -func DeleteData(data *e.ActionReport, event *pl.Event, dbx ...*gorm.DB) error { +func DeleteData(data *e.ProcedureReport, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, data, "started", "DBDelete") var tx *gorm.DB if len(dbx) > 0 { diff --git a/internal/use-case/main-use-case/action-report/middleware-runner.go b/internal/use-case/main-use-case/procedure-report/middleware-runner.go similarity index 86% rename from internal/use-case/main-use-case/action-report/middleware-runner.go rename to internal/use-case/main-use-case/procedure-report/middleware-runner.go index e2544169..c849ef28 100644 --- a/internal/use-case/main-use-case/action-report/middleware-runner.go +++ b/internal/use-case/main-use-case/procedure-report/middleware-runner.go @@ -1,7 +1,7 @@ -package actionreport +package procedurereport import ( - e "simrs-vx/internal/domain/main-entities/action-report" + e "simrs-vx/internal/domain/main-entities/procedure-report" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" @@ -23,7 +23,7 @@ func newMiddlewareRunner(event *pl.Event, tx *gorm.DB) *middlewareRunner { } // ExecuteCreateMiddleware executes create middleware -func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.ActionReport) error { +func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.ProcedureReport) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -38,7 +38,7 @@ func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e return nil } -func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.ActionReport) error { +func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.ProcedureReport) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -53,7 +53,7 @@ func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, inpu return nil } -func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.ActionReport) error { +func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.ProcedureReport) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -68,7 +68,7 @@ func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, return nil } -func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.ActionReport) error { +func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.ProcedureReport) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -83,7 +83,7 @@ func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, inpu return nil } -func (me *middlewareRunner) RunDeleteMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.ActionReport) error { +func (me *middlewareRunner) RunDeleteMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.ProcedureReport) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) diff --git a/internal/use-case/main-use-case/action-report/middleware.go b/internal/use-case/main-use-case/procedure-report/middleware.go similarity index 89% rename from internal/use-case/main-use-case/action-report/middleware.go rename to internal/use-case/main-use-case/procedure-report/middleware.go index 50254de2..157d4e2e 100644 --- a/internal/use-case/main-use-case/action-report/middleware.go +++ b/internal/use-case/main-use-case/procedure-report/middleware.go @@ -1,4 +1,4 @@ -package actionreport +package procedurereport // example of middleware // func init() { diff --git a/internal/use-case/main-use-case/action-report/tycovar.go b/internal/use-case/main-use-case/procedure-report/tycovar.go similarity index 74% rename from internal/use-case/main-use-case/action-report/tycovar.go rename to internal/use-case/main-use-case/procedure-report/tycovar.go index 9eebfabd..3fb449c3 100644 --- a/internal/use-case/main-use-case/action-report/tycovar.go +++ b/internal/use-case/main-use-case/procedure-report/tycovar.go @@ -6,27 +6,27 @@ 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 actionreport +package procedurereport import ( "gorm.io/gorm" - e "simrs-vx/internal/domain/main-entities/action-report" + e "simrs-vx/internal/domain/main-entities/procedure-report" ) type createMw struct { Name string - Func func(input *e.CreateDto, data *e.ActionReport, tx *gorm.DB) error + Func func(input *e.CreateDto, data *e.ProcedureReport, tx *gorm.DB) error } type readListMw struct { Name string - Func func(input *e.ReadListDto, data *e.ActionReport, tx *gorm.DB) error + Func func(input *e.ReadListDto, data *e.ProcedureReport, tx *gorm.DB) error } type readDetailMw struct { Name string - Func func(input *e.ReadDetailDto, data *e.ActionReport, tx *gorm.DB) error + Func func(input *e.ReadDetailDto, data *e.ProcedureReport, tx *gorm.DB) error } type UpdateMw = readDetailMw From 9d3a872eba9ccd8b9cd34fabc0d4fab8f0a8078b Mon Sep 17 00:00:00 2001 From: ari Date: Thu, 4 Dec 2025 14:01:57 +0700 Subject: [PATCH 04/39] update migration --- .../migrations/20251201104439.sql | 28 +++++++++++++------ .../migrations/20251201113804.sql | 4 +-- .../migrations/20251201113858.sql | 4 +-- .../migrations/20251201114751.sql | 4 +-- .../migrations/20251201114913.sql | 4 +-- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/cmd/main-migration/migrations/20251201104439.sql b/cmd/main-migration/migrations/20251201104439.sql index 50f60b6b..832d10e2 100644 --- a/cmd/main-migration/migrations/20251201104439.sql +++ b/cmd/main-migration/migrations/20251201104439.sql @@ -1,5 +1,5 @@ --- Create "ActionReport" table -CREATE TABLE "public"."ActionReport" ( +-- Create "ProcedureReport" table +CREATE TABLE "public"."ProcedureReport" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, @@ -7,13 +7,23 @@ CREATE TABLE "public"."ActionReport" ( "Encounter_Id" bigint NULL, "Date" character varying(20) NOT NULL, "Doctor_Code" character varying(10) NULL, - "Operator_Employe_Id" bigint NULL, - "Assistant_Employe_Id" bigint NULL, - "Instrumentor_Employe_Id" bigint NULL, + "Operator_Name" character varying(120) NULL, + "Assistant_Name" character varying(120) NULL, + "Instrumentor_Name" character varying(120) NULL, "Diagnose" character varying(1024) NULL, - "Procedures" character varying(10240) NULL, - "Nurse_Code" character varying(10) NULL, - "Value" text NULL, + "Nurse_Name" character varying(120) NULL, + "ProcedureValue" text NULL, + "ExecutionValue" text NULL, + "Type" character varying(10) NULL, PRIMARY KEY ("Id"), - CONSTRAINT "fk_ActionReport_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION + CONSTRAINT "fk_ProcedureReport_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); + +-- PROPER + -- "Operator_Employe_Id" bigint NULL, + -- "Assistant_Employe_Id" bigint NULL, + -- "Instrumentor_Employe_Id" bigint NULL, + -- "Diagnose" character varying(1024) NULL, + -- "Procedures" character varying(10240) NULL, + -- "Nurse_Code" character varying(10) NULL, + diff --git a/cmd/main-migration/migrations/20251201113804.sql b/cmd/main-migration/migrations/20251201113804.sql index 0f5c5123..8cecb5fe 100644 --- a/cmd/main-migration/migrations/20251201113804.sql +++ b/cmd/main-migration/migrations/20251201113804.sql @@ -1,2 +1,2 @@ --- Modify "ActionReport" table -ALTER TABLE "public"."ActionReport" DROP COLUMN "Date", DROP COLUMN "Procedures"; +-- Modify "ProcedureReport" table +ALTER TABLE "public"."ProcedureReport" DROP COLUMN "Date", DROP COLUMN "Procedures"; diff --git a/cmd/main-migration/migrations/20251201113858.sql b/cmd/main-migration/migrations/20251201113858.sql index fd6fddc9..bc77d02c 100644 --- a/cmd/main-migration/migrations/20251201113858.sql +++ b/cmd/main-migration/migrations/20251201113858.sql @@ -1,2 +1,2 @@ --- Modify "ActionReport" table -ALTER TABLE "public"."ActionReport" ADD COLUMN "Date" timestamptz NOT NULL; +-- Modify "ProcedureReport" table +ALTER TABLE "public"."ProcedureReport" ADD COLUMN "Date" timestamptz NOT NULL; diff --git a/cmd/main-migration/migrations/20251201114751.sql b/cmd/main-migration/migrations/20251201114751.sql index 6611b811..339ee39c 100644 --- a/cmd/main-migration/migrations/20251201114751.sql +++ b/cmd/main-migration/migrations/20251201114751.sql @@ -1,2 +1,2 @@ --- Modify "ActionReport" table -ALTER TABLE "public"."ActionReport" ADD CONSTRAINT "fk_ActionReport_Instrumentor_Employe" FOREIGN KEY ("Instrumentor_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ActionReport_Nurse" FOREIGN KEY ("Nurse_Code") REFERENCES "public"."Nurse" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ActionReport_Operator_Employe" FOREIGN KEY ("Operator_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ProcedureReport" table +ALTER TABLE "public"."ProcedureReport" ADD CONSTRAINT "fk_ProcedureReport_Instrumentor_Employe" FOREIGN KEY ("Instrumentor_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ProcedureReport_Nurse" FOREIGN KEY ("Nurse_Code") REFERENCES "public"."Nurse" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ProcedureReport_Operator_Employe" FOREIGN KEY ("Operator_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251201114913.sql b/cmd/main-migration/migrations/20251201114913.sql index 5155ed37..85c0281c 100644 --- a/cmd/main-migration/migrations/20251201114913.sql +++ b/cmd/main-migration/migrations/20251201114913.sql @@ -1,2 +1,2 @@ --- Modify "ActionReport" table -ALTER TABLE "public"."ActionReport" ADD CONSTRAINT "fk_ActionReport_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ProcedureReport" table +ALTER TABLE "public"."ProcedureReport" ADD CONSTRAINT "fk_ProcedureReport_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; From 1a92e4539c161ee7287d326c8e96ff88d8a46455 Mon Sep 17 00:00:00 2001 From: ari Date: Thu, 4 Dec 2025 14:03:41 +0700 Subject: [PATCH 05/39] update query --- cmd/main-migration/migrations/20251201104439.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/main-migration/migrations/20251201104439.sql b/cmd/main-migration/migrations/20251201104439.sql index 832d10e2..6862ccde 100644 --- a/cmd/main-migration/migrations/20251201104439.sql +++ b/cmd/main-migration/migrations/20251201104439.sql @@ -10,6 +10,8 @@ CREATE TABLE "public"."ProcedureReport" ( "Operator_Name" character varying(120) NULL, "Assistant_Name" character varying(120) NULL, "Instrumentor_Name" character varying(120) NULL, + "Anesthesia_Doctor_Code" character varying(10) NULL, + "Anesthesia_Nurse_Name" character varying(120) NULL, "Diagnose" character varying(1024) NULL, "Nurse_Name" character varying(120) NULL, "ProcedureValue" text NULL, From dc75980e307a8639df1c549e43282fe2350f7ca2 Mon Sep 17 00:00:00 2001 From: ari Date: Fri, 5 Dec 2025 09:31:13 +0700 Subject: [PATCH 06/39] update const --- .../domain/references/clinical/clinical.go | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index 3054c130..44de34b6 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -30,6 +30,7 @@ type ( BornMortalityCode string BornLocationCode string SpecimentDestCode string + ProcedureReportType string ) const ( @@ -225,16 +226,19 @@ const ( BMCAlive BornMortalityCode = "alive" BMCDead BornMortalityCode = "dead" - BLCExtMiw BornLocationCode = "" - BLCExtDoc BornLocationCode = "" - BLCTradMiw BornLocationCode = "" - BLCLocalMed BornLocationCode = "" - BLCExtParamedic BornLocationCode = "" + BLCExtMiw BornLocationCode = "ext-miw" + BLCExtDoc BornLocationCode = "ext-doc" + BLCTradMiw BornLocationCode = "trad-miw" + BLCLocalMed BornLocationCode = "local-med" + BLCExtParamedic BornLocationCode = "ext-paramedic" - SDCAp SpecimentDestCode = "" - SDCMicro SpecimentDestCode = "" - SDCLab SpecimentDestCode = "" - SDCNone SpecimentDestCode = "" + SDCAp SpecimentDestCode = "ap" + SDCMicro SpecimentDestCode = "micro" + SDCLab SpecimentDestCode = "lab" + SDCNone SpecimentDestCode = "none" + + PRTProcedure ProcedureReportType = "procedure" + PRTSurgery ProcedureReportType = "surgery" ) type Soapi struct { From ff0b7f1fab3617cf0f0fc0252222acd236651222 Mon Sep 17 00:00:00 2001 From: ari Date: Fri, 5 Dec 2025 09:39:30 +0700 Subject: [PATCH 07/39] update non required val --- internal/domain/main-entities/procedure-report/dto.go | 8 ++++---- internal/domain/main-entities/procedure-report/entity.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/domain/main-entities/procedure-report/dto.go b/internal/domain/main-entities/procedure-report/dto.go index 9cd400be..b27191a4 100644 --- a/internal/domain/main-entities/procedure-report/dto.go +++ b/internal/domain/main-entities/procedure-report/dto.go @@ -15,8 +15,8 @@ type CreateDto struct { Operator_Name string `json:"operator_name" validate:"required"` Assistant_Name string `json:"assistant_name" validate:"required"` Instrumentor_Name string `json:"instrumentor_name" validate:"required"` - Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code" validate:"required"` - Anesthesia_Nurse_Name string `json:"anesthesia_nurse_name" validate:"required"` + Anesthesia_Doctor_Code *string `json:"anesthesia_doctor_code"` + Anesthesia_Nurse_Name *string `json:"anesthesia_nurse_name"` Diagnose *string `json:"diagnose"` Nurse_Name string `json:"nurse_name" validate:"required"` ProcedureValue string `json:"procedure_value" validate:"required"` @@ -72,8 +72,8 @@ type ResponseDto struct { Operator_Name string `json:"operator_name"` Assistant_Name string `json:"assistant_name"` Instrumentor_Name string `json:"instrumentor_name"` - Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code"` - Anesthesia_Nurse_Name string `json:"anesthesia_nurse_name"` + Anesthesia_Doctor_Code *string `json:"anesthesia_doctor_code"` + Anesthesia_Nurse_Name *string `json:"anesthesia_nurse_name"` Diagnose *string `json:"diagnose"` Nurse_Name string `json:"nurse_name"` ProcedureValue *string `json:"procedure_value"` diff --git a/internal/domain/main-entities/procedure-report/entity.go b/internal/domain/main-entities/procedure-report/entity.go index f25bf604..82d178f2 100644 --- a/internal/domain/main-entities/procedure-report/entity.go +++ b/internal/domain/main-entities/procedure-report/entity.go @@ -20,9 +20,9 @@ type ProcedureReport struct { Instrumentor_Name string `json:"instrumentor_name"` Diagnose *string `json:"diagnose" gorm:"size:1024"` Nurse_Name string `json:"nurse_code" gorm:"size:10"` - Anesthesia_Doctor_Code string `json:"anesthesia_doctor_code" gorm:"size:10"` + Anesthesia_Doctor_Code *string `json:"anesthesia_doctor_code" gorm:"size:10"` Anesthesia *eem.Employee `json:"anesthesia,omitempty" gorm:"foreignKey:Anesthesia_Doctor_Code;references:Code"` - Anesthesia_Nurse_Name string `json:"anesthesia_nurse_name"` + Anesthesia_Nurse_Name *string `json:"anesthesia_nurse_name"` ProcedureValue string `json:"procedure_value"` ExecutionValue string `json:"execution_value"` Type string `json:"type"` From 5bc3c8783ee012e5999ba0cd7a2ba01104a758b9 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Fri, 5 Dec 2025 16:08:22 +0700 Subject: [PATCH 08/39] feat (item): update handle buying price and selling price --- internal/domain/main-entities/item/dto.go | 2 ++ internal/use-case/main-use-case/item/helper.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/internal/domain/main-entities/item/dto.go b/internal/domain/main-entities/item/dto.go index 53e3c763..a25c5a7a 100644 --- a/internal/domain/main-entities/item/dto.go +++ b/internal/domain/main-entities/item/dto.go @@ -13,6 +13,8 @@ type CreateDto struct { Uom_Code *string `json:"uom_code" validate:"maxLength=10"` Infra_Code *string `json:"infra_code"` Stock *int `json:"stock"` + BuyingPrice *float64 `json:"buyingPrice"` + SellingPrice *float64 `json:"sellingPrice"` } type ReadListDto struct { diff --git a/internal/use-case/main-use-case/item/helper.go b/internal/use-case/main-use-case/item/helper.go index 6f7e0c57..2de4c1bd 100644 --- a/internal/use-case/main-use-case/item/helper.go +++ b/internal/use-case/main-use-case/item/helper.go @@ -23,4 +23,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Item) { data.Uom_Code = inputSrc.Uom_Code data.Infra_Code = inputSrc.Infra_Code data.Stock = inputSrc.Stock + data.BuyingPrice = inputSrc.BuyingPrice + data.SellingPrice = inputSrc.SellingPrice } From 019a413e9b56b77703e160283103335b775ea95a Mon Sep 17 00:00:00 2001 From: ari Date: Sat, 6 Dec 2025 08:36:05 +0700 Subject: [PATCH 09/39] update --- internal/domain/main-entities/procedure-report/entity.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/domain/main-entities/procedure-report/entity.go b/internal/domain/main-entities/procedure-report/entity.go index 82d178f2..81a888b6 100644 --- a/internal/domain/main-entities/procedure-report/entity.go +++ b/internal/domain/main-entities/procedure-report/entity.go @@ -3,7 +3,6 @@ package procedurereport import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" - eem "simrs-vx/internal/domain/main-entities/employee" ee "simrs-vx/internal/domain/main-entities/encounter" "time" ) @@ -19,9 +18,9 @@ type ProcedureReport struct { Assistant_Name string `json:"assistant_name"` Instrumentor_Name string `json:"instrumentor_name"` Diagnose *string `json:"diagnose" gorm:"size:1024"` - Nurse_Name string `json:"nurse_code" gorm:"size:10"` + Nurse_Name string `json:"nurse_name" gorm:"size:10"` Anesthesia_Doctor_Code *string `json:"anesthesia_doctor_code" gorm:"size:10"` - Anesthesia *eem.Employee `json:"anesthesia,omitempty" gorm:"foreignKey:Anesthesia_Doctor_Code;references:Code"` + Anesthesia_Doctor *ed.Doctor `json:"anesthesia,omitempty" gorm:"foreignKey:Anesthesia_Doctor_Code;references:Code"` Anesthesia_Nurse_Name *string `json:"anesthesia_nurse_name"` ProcedureValue string `json:"procedure_value"` ExecutionValue string `json:"execution_value"` From 17403278149789644c6c86b79bda7a33c63d0b3e Mon Sep 17 00:00:00 2001 From: ari Date: Sat, 6 Dec 2025 09:54:05 +0700 Subject: [PATCH 10/39] update migration issue --- .../migrations/20251201104439.sql | 30 ++++++------------- .../migrations/20251201113804.sql | 4 +-- .../migrations/20251201113858.sql | 4 +-- .../migrations/20251201114751.sql | 4 +-- .../migrations/20251201114913.sql | 4 +-- .../migrations/20251206021053.sql | 26 ++++++++++++++++ .../main-entities/procedure-report/dto.go | 9 +++--- .../main-entities/procedure-report/entity.go | 2 +- .../main-use-case/procedure-report/helper.go | 2 +- 9 files changed, 50 insertions(+), 35 deletions(-) create mode 100644 cmd/main-migration/migrations/20251206021053.sql diff --git a/cmd/main-migration/migrations/20251201104439.sql b/cmd/main-migration/migrations/20251201104439.sql index 6862ccde..50f60b6b 100644 --- a/cmd/main-migration/migrations/20251201104439.sql +++ b/cmd/main-migration/migrations/20251201104439.sql @@ -1,5 +1,5 @@ --- Create "ProcedureReport" table -CREATE TABLE "public"."ProcedureReport" ( +-- Create "ActionReport" table +CREATE TABLE "public"."ActionReport" ( "Id" bigserial NOT NULL, "CreatedAt" timestamptz NULL, "UpdatedAt" timestamptz NULL, @@ -7,25 +7,13 @@ CREATE TABLE "public"."ProcedureReport" ( "Encounter_Id" bigint NULL, "Date" character varying(20) NOT NULL, "Doctor_Code" character varying(10) NULL, - "Operator_Name" character varying(120) NULL, - "Assistant_Name" character varying(120) NULL, - "Instrumentor_Name" character varying(120) NULL, - "Anesthesia_Doctor_Code" character varying(10) NULL, - "Anesthesia_Nurse_Name" character varying(120) NULL, + "Operator_Employe_Id" bigint NULL, + "Assistant_Employe_Id" bigint NULL, + "Instrumentor_Employe_Id" bigint NULL, "Diagnose" character varying(1024) NULL, - "Nurse_Name" character varying(120) NULL, - "ProcedureValue" text NULL, - "ExecutionValue" text NULL, - "Type" character varying(10) NULL, + "Procedures" character varying(10240) NULL, + "Nurse_Code" character varying(10) NULL, + "Value" text NULL, PRIMARY KEY ("Id"), - CONSTRAINT "fk_ProcedureReport_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION + CONSTRAINT "fk_ActionReport_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); - --- PROPER - -- "Operator_Employe_Id" bigint NULL, - -- "Assistant_Employe_Id" bigint NULL, - -- "Instrumentor_Employe_Id" bigint NULL, - -- "Diagnose" character varying(1024) NULL, - -- "Procedures" character varying(10240) NULL, - -- "Nurse_Code" character varying(10) NULL, - diff --git a/cmd/main-migration/migrations/20251201113804.sql b/cmd/main-migration/migrations/20251201113804.sql index 8cecb5fe..0f5c5123 100644 --- a/cmd/main-migration/migrations/20251201113804.sql +++ b/cmd/main-migration/migrations/20251201113804.sql @@ -1,2 +1,2 @@ --- Modify "ProcedureReport" table -ALTER TABLE "public"."ProcedureReport" DROP COLUMN "Date", DROP COLUMN "Procedures"; +-- Modify "ActionReport" table +ALTER TABLE "public"."ActionReport" DROP COLUMN "Date", DROP COLUMN "Procedures"; diff --git a/cmd/main-migration/migrations/20251201113858.sql b/cmd/main-migration/migrations/20251201113858.sql index bc77d02c..fd6fddc9 100644 --- a/cmd/main-migration/migrations/20251201113858.sql +++ b/cmd/main-migration/migrations/20251201113858.sql @@ -1,2 +1,2 @@ --- Modify "ProcedureReport" table -ALTER TABLE "public"."ProcedureReport" ADD COLUMN "Date" timestamptz NOT NULL; +-- Modify "ActionReport" table +ALTER TABLE "public"."ActionReport" ADD COLUMN "Date" timestamptz NOT NULL; diff --git a/cmd/main-migration/migrations/20251201114751.sql b/cmd/main-migration/migrations/20251201114751.sql index 339ee39c..6611b811 100644 --- a/cmd/main-migration/migrations/20251201114751.sql +++ b/cmd/main-migration/migrations/20251201114751.sql @@ -1,2 +1,2 @@ --- Modify "ProcedureReport" table -ALTER TABLE "public"."ProcedureReport" ADD CONSTRAINT "fk_ProcedureReport_Instrumentor_Employe" FOREIGN KEY ("Instrumentor_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ProcedureReport_Nurse" FOREIGN KEY ("Nurse_Code") REFERENCES "public"."Nurse" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ProcedureReport_Operator_Employe" FOREIGN KEY ("Operator_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ActionReport" table +ALTER TABLE "public"."ActionReport" ADD CONSTRAINT "fk_ActionReport_Instrumentor_Employe" FOREIGN KEY ("Instrumentor_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ActionReport_Nurse" FOREIGN KEY ("Nurse_Code") REFERENCES "public"."Nurse" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ActionReport_Operator_Employe" FOREIGN KEY ("Operator_Employe_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251201114913.sql b/cmd/main-migration/migrations/20251201114913.sql index 85c0281c..5155ed37 100644 --- a/cmd/main-migration/migrations/20251201114913.sql +++ b/cmd/main-migration/migrations/20251201114913.sql @@ -1,2 +1,2 @@ --- Modify "ProcedureReport" table -ALTER TABLE "public"."ProcedureReport" ADD CONSTRAINT "fk_ProcedureReport_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ActionReport" table +ALTER TABLE "public"."ActionReport" ADD CONSTRAINT "fk_ActionReport_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251206021053.sql b/cmd/main-migration/migrations/20251206021053.sql new file mode 100644 index 00000000..03ab3bfb --- /dev/null +++ b/cmd/main-migration/migrations/20251206021053.sql @@ -0,0 +1,26 @@ +-- Create "ProcedureReport" table +CREATE TABLE "public"."ProcedureReport" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Date" timestamptz NOT NULL, + "Doctor_Code" character varying(10) NULL, + "Operator_Name" text NULL, + "Assistant_Name" text NULL, + "Instrumentor_Name" text NULL, + "Diagnose" character varying(1024) NULL, + "Nurse_Name" character varying(10) NULL, + "Anesthesia_Doctor_Code" character varying(10) NULL, + "Anesthesia_Nurse_Name" text NULL, + "ProcedureValue" text NULL, + "ExecutionValue" text NULL, + "Type_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ProcedureReport_Anesthesia_Doctor" FOREIGN KEY ("Anesthesia_Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ProcedureReport_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ProcedureReport_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Drop "ActionReport" table +DROP TABLE "public"."ActionReport"; diff --git a/internal/domain/main-entities/procedure-report/dto.go b/internal/domain/main-entities/procedure-report/dto.go index b27191a4..ec815b43 100644 --- a/internal/domain/main-entities/procedure-report/dto.go +++ b/internal/domain/main-entities/procedure-report/dto.go @@ -21,7 +21,7 @@ type CreateDto struct { Nurse_Name string `json:"nurse_name" validate:"required"` ProcedureValue string `json:"procedure_value" validate:"required"` ExecutionValue string `json:"execution_value" validate:"required"` - Type string `json:"type" validate:"required"` + Type_Code string `json:"type_code" validate:"required"` pa.AuthInfo @@ -41,7 +41,8 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` + Encounter_Id *uint `json:"encounter-id"` + Type_Code string `json:"type-code"` } type ReadDetailDto struct { @@ -78,7 +79,7 @@ type ResponseDto struct { Nurse_Name string `json:"nurse_name"` ProcedureValue *string `json:"procedure_value"` ExecutionValue *string `json:"execution_value"` - Type string `json:"type"` + Type_Code string `json:"type_code"` } func (d ProcedureReport) ToResponse() ResponseDto { @@ -95,7 +96,7 @@ func (d ProcedureReport) ToResponse() ResponseDto { Nurse_Name: d.Nurse_Name, ProcedureValue: &d.ProcedureValue, ExecutionValue: &d.ExecutionValue, - Type: d.Type, + Type_Code: d.Type_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/procedure-report/entity.go b/internal/domain/main-entities/procedure-report/entity.go index 81a888b6..4a8a7032 100644 --- a/internal/domain/main-entities/procedure-report/entity.go +++ b/internal/domain/main-entities/procedure-report/entity.go @@ -24,7 +24,7 @@ type ProcedureReport struct { Anesthesia_Nurse_Name *string `json:"anesthesia_nurse_name"` ProcedureValue string `json:"procedure_value"` ExecutionValue string `json:"execution_value"` - Type string `json:"type"` + Type_Code string `json:"type_code"` // SurgerySize_Code *string `json:"surgerySize_code" gorm:"size:10"` // Billing_Code *string `json:"billing_code" gorm:"size:10"` diff --git a/internal/use-case/main-use-case/procedure-report/helper.go b/internal/use-case/main-use-case/procedure-report/helper.go index 9fb87778..e16711e5 100644 --- a/internal/use-case/main-use-case/procedure-report/helper.go +++ b/internal/use-case/main-use-case/procedure-report/helper.go @@ -29,7 +29,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ProcedureReport) { data.Nurse_Name = inputSrc.Nurse_Name data.ProcedureValue = inputSrc.ProcedureValue data.ExecutionValue = inputSrc.ExecutionValue - data.Type = inputSrc.Type + data.Type_Code = inputSrc.Type_Code //PROPER // data.Operator_Employe_Id = inputSrc.Operator_Employe_Id From 2cc7af845da640d67b82d6803167372792fbb5d5 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 8 Dec 2025 15:15:25 +0700 Subject: [PATCH 11/39] feat (patient): add patient employee checker --- internal/lib/auth/tycovar.go | 4 ++++ .../use-case/main-use-case/patient/case.go | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/internal/lib/auth/tycovar.go b/internal/lib/auth/tycovar.go index c673eb04..c746b795 100644 --- a/internal/lib/auth/tycovar.go +++ b/internal/lib/auth/tycovar.go @@ -103,3 +103,7 @@ func (a AuthInfo) IsNurseIntern() bool { func (a AuthInfo) HasEmployeePosition() bool { return a.Employee_Position_Code != nil } + +func (a AuthInfo) IsReg() bool { + return a.Employee_Position_Code != nil && *a.Employee_Position_Code == string(ero.EPCReg) +} diff --git a/internal/use-case/main-use-case/patient/case.go b/internal/use-case/main-use-case/patient/case.go index 24aa4394..a53072fe 100644 --- a/internal/use-case/main-use-case/patient/case.go +++ b/internal/use-case/main-use-case/patient/case.go @@ -50,6 +50,16 @@ func Create(input e.CreateDto) (*d.Data, error) { return nil, pl.SetLogError(&event, input) } + if !input.AuthInfo.IsReg() { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "auth-forbidden", + Detail: "user role is not allowed to create patient, only 'reg' position is allowed", + Raw: errors.New("authentication failed"), + } + return nil, pl.SetLogError(&event, input) + } + input.RegisteredBy_User_Name = &input.AuthInfo.User_Name err := dg.I.Transaction(func(tx *gorm.DB) error { @@ -256,6 +266,16 @@ func Update(input e.UpdateDto) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "update") mwRunner := newMiddlewareRunner(&event) + if !input.AuthInfo.IsReg() { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "auth-forbidden", + Detail: "user role is not allowed to create patient, only 'reg' position is allowed", + Raw: errors.New("authentication failed"), + } + 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 { From 9b4b6949df5d35b0aec3a4754ba9cd3760f74696 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 8 Dec 2025 16:02:40 +0700 Subject: [PATCH 12/39] feat (patient): add guard for reg and sys --- internal/lib/auth/tycovar.go | 4 ++++ internal/use-case/main-use-case/patient/case.go | 15 ++------------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/lib/auth/tycovar.go b/internal/lib/auth/tycovar.go index c746b795..a958fa6a 100644 --- a/internal/lib/auth/tycovar.go +++ b/internal/lib/auth/tycovar.go @@ -107,3 +107,7 @@ func (a AuthInfo) HasEmployeePosition() bool { func (a AuthInfo) IsReg() bool { return a.Employee_Position_Code != nil && *a.Employee_Position_Code == string(ero.EPCReg) } + +func (a AuthInfo) IsSys() bool { + return a.User_ContractPosition_Code == string(ero.CSCSys) +} diff --git a/internal/use-case/main-use-case/patient/case.go b/internal/use-case/main-use-case/patient/case.go index a53072fe..f82d114d 100644 --- a/internal/use-case/main-use-case/patient/case.go +++ b/internal/use-case/main-use-case/patient/case.go @@ -39,18 +39,7 @@ func Create(input e.CreateDto) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "create") mwRunner := newMiddlewareRunner(&event) - // check if user has employee position - if !input.AuthInfo.HasEmployeePosition() { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "auth-forbidden", - Detail: "user has no employee position", - Raw: errors.New("authentication failed"), - } - return nil, pl.SetLogError(&event, input) - } - - if !input.AuthInfo.IsReg() { + if !input.AuthInfo.IsReg() || !input.AuthInfo.IsSys() { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "auth-forbidden", @@ -266,7 +255,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "update") mwRunner := newMiddlewareRunner(&event) - if !input.AuthInfo.IsReg() { + if !input.AuthInfo.IsReg() || !input.AuthInfo.IsSys() { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "auth-forbidden", From 569fb22080b4ac3a9f0118041ebe29079972a963 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 8 Dec 2025 16:06:14 +0700 Subject: [PATCH 13/39] fix (patient): fix condition --- internal/use-case/main-use-case/patient/case.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/use-case/main-use-case/patient/case.go b/internal/use-case/main-use-case/patient/case.go index f82d114d..da636263 100644 --- a/internal/use-case/main-use-case/patient/case.go +++ b/internal/use-case/main-use-case/patient/case.go @@ -39,7 +39,7 @@ func Create(input e.CreateDto) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "create") mwRunner := newMiddlewareRunner(&event) - if !input.AuthInfo.IsReg() || !input.AuthInfo.IsSys() { + if !input.AuthInfo.IsReg() && !input.AuthInfo.IsSys() { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "auth-forbidden", @@ -255,7 +255,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "update") mwRunner := newMiddlewareRunner(&event) - if !input.AuthInfo.IsReg() || !input.AuthInfo.IsSys() { + if !input.AuthInfo.IsReg() && !input.AuthInfo.IsSys() { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "auth-forbidden", From 6811ef062390f2e1f11550b7251744ec98d5d4e1 Mon Sep 17 00:00:00 2001 From: ari Date: Tue, 9 Dec 2025 10:13:50 +0700 Subject: [PATCH 14/39] update --- cmd/main-migration/migrations/20251209030538.sql | 2 ++ internal/domain/main-entities/procedure-report/entity.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 cmd/main-migration/migrations/20251209030538.sql diff --git a/cmd/main-migration/migrations/20251209030538.sql b/cmd/main-migration/migrations/20251209030538.sql new file mode 100644 index 00000000..4f0ad77f --- /dev/null +++ b/cmd/main-migration/migrations/20251209030538.sql @@ -0,0 +1,2 @@ +-- Modify "ProcedureReport" table +ALTER TABLE "public"."ProcedureReport" ALTER COLUMN "Nurse_Name" TYPE text; diff --git a/internal/domain/main-entities/procedure-report/entity.go b/internal/domain/main-entities/procedure-report/entity.go index 4a8a7032..cf084bd4 100644 --- a/internal/domain/main-entities/procedure-report/entity.go +++ b/internal/domain/main-entities/procedure-report/entity.go @@ -18,7 +18,7 @@ type ProcedureReport struct { Assistant_Name string `json:"assistant_name"` Instrumentor_Name string `json:"instrumentor_name"` Diagnose *string `json:"diagnose" gorm:"size:1024"` - Nurse_Name string `json:"nurse_name" gorm:"size:10"` + Nurse_Name string `json:"nurse_name"` Anesthesia_Doctor_Code *string `json:"anesthesia_doctor_code" gorm:"size:10"` Anesthesia_Doctor *ed.Doctor `json:"anesthesia,omitempty" gorm:"foreignKey:Anesthesia_Doctor_Code;references:Code"` Anesthesia_Nurse_Name *string `json:"anesthesia_nurse_name"` From e68b5fe01983c5934245424aeeef988fceaf72c7 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Tue, 9 Dec 2025 10:24:20 +0700 Subject: [PATCH 15/39] fix (patient): missing authinfo on update --- internal/interface/main-handler/patient/handler.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/interface/main-handler/patient/handler.go b/internal/interface/main-handler/patient/handler.go index 41fca562..9fb981fc 100644 --- a/internal/interface/main-handler/patient/handler.go +++ b/internal/interface/main-handler/patient/handler.go @@ -59,11 +59,17 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { return } + authInfo, err := pa.GetAuthInfo(r) + if err != nil { + rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil) + } + dto := e.UpdateDto{} if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } dto.Id = uint(id) + dto.AuthInfo = *authInfo res, err := u.Update(dto) rw.DataResponse(w, res, err) } From 30fa443e3e31c9baf3cf1defc7c7abae41524727 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Tue, 9 Dec 2025 12:46:20 +0700 Subject: [PATCH 16/39] wip --- .../vclaim-sep-control-letter/dto.go | 53 ++++++++ .../vclaim-sep-control-letter/plugin.go | 124 ++++++++++++++++++ .../vclaim-sep-control-letter/tycovar.go | 87 ++++++++++++ .../vclaim-sep-control-letter/helper.go | 2 +- .../vclaim-sep-control-letter/middleware.go | 15 ++- .../main-use-case/generate-file/helper.go | 23 +--- .../main-use-case/generate-file/tycovar.go | 56 +------- 7 files changed, 285 insertions(+), 75 deletions(-) create mode 100644 internal/use-case/bpjs-plugin/vclaim-sep-control-letter/plugin.go create mode 100644 internal/use-case/bpjs-plugin/vclaim-sep-control-letter/tycovar.go diff --git a/internal/domain/bpjs-entities/vclaim-sep-control-letter/dto.go b/internal/domain/bpjs-entities/vclaim-sep-control-letter/dto.go index 19530c2c..1974e66c 100644 --- a/internal/domain/bpjs-entities/vclaim-sep-control-letter/dto.go +++ b/internal/domain/bpjs-entities/vclaim-sep-control-letter/dto.go @@ -1,7 +1,13 @@ package vclaimsepcontrolletter import ( + "encoding/json" + "fmt" + "time" + ecore "simrs-vx/internal/domain/base-entities/core" + + pu "simrs-vx/pkg/use-case-helper" ) type CreateDto struct { @@ -9,6 +15,7 @@ type CreateDto struct { Number *string `json:"number" gorm:"unique;size:20"` Value *string `json:"value"` FileUrl *string `json:"fileUrl" gorm:"unique;size:1024"` + RequestPayload string `json:"requestPayload" validate:"maxLength=1024"` } type ReadListDto struct { @@ -69,3 +76,49 @@ func ToResponseList(data []VclaimSepControlLetter) []ResponseDto { } return resp } + +func (c CreateDto) RequestPayloadIntoJson() ([]byte, error) { + payload := map[string]interface{}{} + err := json.Unmarshal([]byte(c.RequestPayload), &payload) + if err != nil { + return nil, err + } + return json.Marshal(payload) +} + +type ResponseForPDF struct { + Number string `json:"noSuratKontrol"` + PlannedControlDate string `json:"tglRencanaKontrol"` + IssuedDate string `json:"tglTerbit"` + Doctor_Name string `json:"namaDokter"` + DstUnit_Name string `json:"namaPoliTujuan"` + ResponsibleDoctor_Name string `json:"namaDokterPembuat"` + VclaimSep VclaimSep `json:"sep"` +} + +type VclaimSep struct { + VclaimMember VclaimMember `json:"peserta"` + Diagnose string `json:"diagnosa"` + Number string `json:"noSep"` +} + +type VclaimMember struct { + CardNumber string `json:"noKartu"` + Name string `json:"nama"` + BirthDate string `json:"tglLahir"` + Gender string `json:"kelamin"` +} + +func (v ResponseForPDF) GenerateNameWithGender() string { + gender := "Perempuan" + if v.VclaimSep.VclaimMember.Gender == "L" { + gender = "Laki-Laki" + } + + return fmt.Sprintf("%s (%s)", v.VclaimSep.VclaimMember.Name, gender) +} + +func (v ResponseForPDF) GenerateBirthDate() string { + t, _ := time.Parse("2006-01-02", v.VclaimSep.VclaimMember.BirthDate) + return pu.FormatIndonesianDate(t) +} diff --git a/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/plugin.go b/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/plugin.go new file mode 100644 index 00000000..b8460713 --- /dev/null +++ b/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/plugin.go @@ -0,0 +1,124 @@ +package vclaimsepcontrolletter + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "net/http" + e "simrs-vx/internal/domain/bpjs-entities/vclaim-sep-control-letter" + + ibpjs "simrs-vx/internal/infra/bpjs" + + "gorm.io/gorm" +) + +func CreateSepControlLetter(input *e.CreateDto, data *e.VclaimSepControlLetter, tx *gorm.DB) error { + payload, err := input.RequestPayloadIntoJson() + if err != nil { + return err + } + req, err := http.NewRequest("POST", ibpjs.O.BaseUrl+"RencanaKontrol", bytes.NewBuffer(payload)) + if err != nil { + return err + } + req.Header.Set("Content-Type", "application/json") + + resp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + + var vresp Response + if err := json.Unmarshal(body, &vresp); err != nil { + return fmt.Errorf("failed to parse response JSON: %w", err) + } + + if vresp.MetaData.Code != "200" { + return fmt.Errorf("failed to create sep control letter: %s", vresp.MetaData.Message) + } + + pdfNeeds, err := vresp.ToPDFNeeds() + if err != nil { + return err + } + tmp := string(pdfNeeds) + input.Value = &tmp + + return nil +} + +// func ReadDetailSep(input *e.ReadDetailDto, data *e.VclaimSep, tx *gorm.DB) error { +// endpoint := fmt.Sprintf("sep/%s", input.Number) +// req, err := http.NewRequest("GET", ibpjs.O.BaseUrl+endpoint, nil) +// if err != nil { +// return err +// } +// req.Header.Set("Content-Type", "application/json") + +// resp, err := http.DefaultClient.Do(req) +// if err != nil { +// return err +// } +// defer resp.Body.Close() + +// body, err := io.ReadAll(resp.Body) +// if err != nil { +// return err +// } + +// var detail e.SepResponse +// if err := json.Unmarshal(body, &detail); err != nil { +// return fmt.Errorf("failed to parse response JSON: %w", err) +// } + +// data.Detail = detail.Response + +// return nil +// } + +// func DeleteSep(input *e.DeleteDto, data *e.VclaimSep, tx *gorm.DB) error { +// payload := e.SepDeleteRequest{} +// payload.Request.TSep.NoSep = *input.Number +// payload.Request.TSep.User = "Coba Ws" + +// jsonPayload, err := json.Marshal(payload) +// if err != nil { +// return err +// } + +// req, err := http.NewRequest("DELETE", ibpjs.O.BaseUrl+"sep", bytes.NewBuffer(jsonPayload)) +// if err != nil { +// return err +// } + +// req.Header.Set("Content-Type", "application/json") + +// resp, err := http.DefaultClient.Do(req) +// if err != nil { +// return err +// } +// defer resp.Body.Close() + +// body, err := io.ReadAll(resp.Body) +// if err != nil { +// return err +// } + +// var detail e.SepResponse +// if err := json.Unmarshal(body, &detail); err != nil { +// return fmt.Errorf("failed to parse response JSON: %w", err) +// } + +// if detail.MetaData.Message == SepNotFound { +// return fmt.Errorf("sep with number %s not found", *data.Number) +// } + +// return nil +// } diff --git a/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/tycovar.go b/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/tycovar.go new file mode 100644 index 00000000..c732afa5 --- /dev/null +++ b/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/tycovar.go @@ -0,0 +1,87 @@ +package vclaimsepcontrolletter + +import ( + "encoding/json" + + e "simrs-vx/internal/domain/bpjs-entities/vclaim-sep-control-letter" +) + +type SuratKontrol struct { + NoSuratKontrol string `json:"noSuratKontrol"` + TglRencanaKontrol string `json:"tglRencanaKontrol"` + TglTerbit string `json:"tglTerbit"` + JnsKontrol string `json:"jnsKontrol"` + PoliTujuan string `json:"poliTujuan"` + NamaPoliTujuan string `json:"namaPoliTujuan"` + KodeDokter string `json:"kodeDokter"` + NamaDokter string `json:"namaDokter"` + FlagKontrol string `json:"flagKontrol"` + KodeDokterPembuat *string `json:"kodeDokterPembuat"` + NamaDokterPembuat *string `json:"namaDokterPembuat"` + NamaJnsKontrol string `json:"namaJnsKontrol"` + Sep Sep `json:"sep"` +} + +type Sep struct { + NoSep string `json:"noSep"` + TglSep string `json:"tglSep"` + JnsPelayanan string `json:"jnsPelayanan"` + Poli string `json:"poli"` + Diagnosa string `json:"diagnosa"` + Peserta Peserta `json:"peserta"` + ProvUmum ProvUmum `json:"provUmum"` + ProvPerujuk ProvPerujuk `json:"provPerujuk"` +} + +type Peserta struct { + NoKartu string `json:"noKartu"` + Nama string `json:"nama"` + TglLahir string `json:"tglLahir"` + Kelamin string `json:"kelamin"` + HakKelas string `json:"hakKelas"` +} + +type ProvUmum struct { + KdProvider string `json:"kdProvider"` + NmProvider string `json:"nmProvider"` +} + +type ProvPerujuk struct { + KdProviderPerujuk string `json:"kdProviderPerujuk"` + NmProviderPerujuk string `json:"nmProviderPerujuk"` + AsalRujukan string `json:"asalRujukan"` + NoRujukan string `json:"noRujukan"` + TglRujukan string `json:"tglRujukan"` +} + +type Response struct { + MetaData MetaData `json:"metaData"` + Response *SuratKontrol `json:"response"` // nullable +} + +type MetaData struct { + Code string `json:"code"` + Message string `json:"message"` +} + +func (r Response) ToPDFNeeds() ([]byte, error) { + response := e.ResponseForPDF{ + Number: r.Response.Sep.NoSep, + PlannedControlDate: r.Response.TglRencanaKontrol, + IssuedDate: r.Response.TglTerbit, + Doctor_Name: r.Response.NamaDokter, + DstUnit_Name: r.Response.NamaPoliTujuan, + ResponsibleDoctor_Name: *r.Response.NamaDokterPembuat, + VclaimSep: e.VclaimSep{ + VclaimMember: e.VclaimMember{ + CardNumber: r.Response.Sep.Peserta.NoKartu, + Name: r.Response.Sep.Peserta.Nama, + BirthDate: r.Response.Sep.Peserta.TglLahir, + Gender: r.Response.Sep.Peserta.Kelamin, + }, + Diagnose: r.Response.Sep.Diagnosa, + Number: r.Response.Sep.NoSep, + }, + } + return json.Marshal(response) +} diff --git a/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/helper.go b/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/helper.go index 891e7c4d..c878d00b 100644 --- a/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/helper.go +++ b/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/helper.go @@ -20,5 +20,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.VclaimSepControlLet data.VclaimSep_Number = inputSrc.VclaimSep_Number data.Number = inputSrc.Number data.Value = inputSrc.Value - data.FileUrl = inputSrc.FileUrl + // data.FileUrl = inputSrc.FileUrl } diff --git a/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/middleware.go b/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/middleware.go index 57262cc2..0cca1159 100644 --- a/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/middleware.go +++ b/internal/use-case/bpjs-use-case/vclaim-sep-control-letter/middleware.go @@ -1,9 +1,12 @@ package vclaimsepcontrolletter +import ( + pvscl "simrs-vx/internal/use-case/bpjs-plugin/vclaim-sep-control-letter" +) + // example of middleware -// func init() { -// createPreMw = append(createPreMw, -// CreateMw{Name: "modif-input", Func: pm.ModifInput}, -// CreateMw{Name: "check-data", Func: pm.CheckData}, -// ) -// } +func init() { + createPreMw = append(createPreMw, + createMw{Name: "create-sep-control-letter", Func: pvscl.CreateSepControlLetter}, + ) +} diff --git a/internal/use-case/main-use-case/generate-file/helper.go b/internal/use-case/main-use-case/generate-file/helper.go index a0e7c1e2..adcdc16d 100644 --- a/internal/use-case/main-use-case/generate-file/helper.go +++ b/internal/use-case/main-use-case/generate-file/helper.go @@ -183,9 +183,9 @@ func generateCL(input GenerateDto, event pl.Event, tx *gorm.DB) (*ResponseDto, e } // map template data - clData := VclaimControlLetter{} - if input.Data != nil { - err := json.Unmarshal([]byte(*input.Data), &clData) + clData := evscl.ResponseForPDF{} + if cl.Value != nil { + err := json.Unmarshal([]byte(*cl.Value), &clData) if err != nil { event.ErrInfo = pl.ErrorInfo{ Code: "data-unmarshal-fail", @@ -195,22 +195,11 @@ func generateCL(input GenerateDto, event pl.Event, tx *gorm.DB) (*ResponseDto, e return nil, err } } else { - return nil, errors.New("there is no data to be used") + return nil, errors.New("there is no value to be used") } - if cl == nil { - createCL := evscl.CreateDto{ - VclaimSep_Number: &clData.VclaimSep.Number, - Number: &clData.Number, - Value: input.Data, - } - if cl, err = uvscl.CreateData(createCL, &event, tx); err != nil { - return nil, err - } - - } // get encounter id by vclaim sep number - vs, err := uvs.ReadDetailData(evs.ReadDetailDto{Number: &clData.VclaimSep.Number}, &event) + vs, err := uvs.ReadDetailData(evs.ReadDetailDto{Number: cl.VclaimSep_Number}, &event) if err != nil { return nil, err } @@ -220,7 +209,7 @@ func generateCL(input GenerateDto, event pl.Event, tx *gorm.DB) (*ResponseDto, e input.Encounter_Id = vs.Encounter_Id input.UseA5Lanscape = true - templateData := clData.generateTemplateData() + templateData := generateTemplateData(clData) // generate file urlPub, err := generateFile(input, templateData) if err != nil { diff --git a/internal/use-case/main-use-case/generate-file/tycovar.go b/internal/use-case/main-use-case/generate-file/tycovar.go index a8fd5ef5..fd62787a 100644 --- a/internal/use-case/main-use-case/generate-file/tycovar.go +++ b/internal/use-case/main-use-case/generate-file/tycovar.go @@ -1,15 +1,11 @@ package generatefile import ( - "fmt" - "time" - + evscl "simrs-vx/internal/domain/bpjs-entities/vclaim-sep-control-letter" erc "simrs-vx/internal/domain/references/common" ere "simrs-vx/internal/domain/references/encounter" er "simrs-vx/internal/domain/main-entities/resume" - - pu "simrs-vx/pkg/use-case-helper" ) type GeneralConsentPDF struct { @@ -105,28 +101,6 @@ type GenerateDto struct { Data *string `json:"data"` } -type VclaimControlLetter struct { - Number string `json:"noSuratKontrol"` - PlannedControlDate string `json:"tglRencanaKontrol"` - Doctor_Name string `json:"namaDokter"` - DstUnit_Name string `json:"namaPoliTujuan"` - ResponsibleDoctor_Name string `json:"namaDokterPembuat"` - VclaimSep VclaimSep `json:"sep"` -} - -type VclaimSep struct { - VclaimMember VclaimMember `json:"peserta"` - Diagnose string `json:"diagnosa"` - Number string `json:"noSep"` -} - -type VclaimMember struct { - CardNumber string `json:"noKartu"` - Name string `json:"nama"` - BirthDate string `json:"tglLahir"` - Gender string `json:"kelamin"` -} - type GeneratePDFdto struct { TemplatePath string TemplateData any @@ -149,37 +123,17 @@ const ( TDNSB TemplateDocsName = "screening-form-b.html" ) -func (v VclaimControlLetter) generateTemplateData() ControlLetterPDF { - +func generateTemplateData(v evscl.ResponseForPDF) ControlLetterPDF { return ControlLetterPDF{ Number: v.Number, Doctor_Name: v.Doctor_Name, DstUnit_Name: v.DstUnit_Name, CardNumber: v.VclaimSep.VclaimMember.CardNumber, - Name: v.generateNameWithGender(), - BirthDate: v.generateBirthDate(), + Name: v.GenerateNameWithGender(), + BirthDate: v.GenerateBirthDate(), Diagnose: v.VclaimSep.Diagnose, PlanDate: v.PlannedControlDate, ResponsibleDoctor_Name: v.ResponsibleDoctor_Name, - PrintDate: generatePrintDate(), + PrintDate: v.IssuedDate, } } - -func (v VclaimControlLetter) generateNameWithGender() string { - gender := "Perempuan" - if v.VclaimSep.VclaimMember.Gender == "L" { - gender = "Laki-Laki" - } - - return fmt.Sprintf("%s (%s)", v.VclaimSep.VclaimMember.Name, gender) -} - -func (v VclaimControlLetter) generateBirthDate() string { - t, _ := time.Parse("2006-01-02", v.VclaimSep.VclaimMember.BirthDate) - return pu.FormatIndonesianDate(t) -} - -func generatePrintDate() string { - now := time.Now() - return now.Format("2006/01/02") -} From 7ef090bd17ef2c1cb09f572efcb2e86c07155e21 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Tue, 9 Dec 2025 12:50:24 +0700 Subject: [PATCH 17/39] update atlas, remove unnecessary code --- cmd/main-migration/migrations/atlas.sum | 14 ++++++++------ internal/interface/main-handler/patient/handler.go | 5 ----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index ac03c936..d81f6ccb 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:SSn9Za93bvbyBNVuGwpy9R/E/+1hm802NevovuLsplc= +h1:1Uh0B/nQPbiGKWcusDCZ9KUDAIGODzb8qSNiz7+yqrU= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -149,8 +149,10 @@ h1:SSn9Za93bvbyBNVuGwpy9R/E/+1hm802NevovuLsplc= 20251205211957.sql h1:3fvtZ/mBWsTIXllXMFOuCLJsp4MivVP56dunehlU0yo= 20251205214433.sql h1:rn3++FEfX7ntcJcOmCEuOMnr27TZqH0KMGRppzFwFTc= 20251205221124.sql h1:CRruUvGZqlVDBmbQSVEl4wFm+uq30AurMMDI6sb8jxg= -20251207020537.sql h1:JspoBMoP1Yk854vtNniepvATINUpODQ9idKiMkNL0OU= -20251207212015.sql h1:pEH0+QnQ5WXNizxcToLk+8XYaAb6q6WJ1/MJViRVtNQ= -20251207221222.sql h1:gpl3V4/3AGqO3WLCpWW2GAtwuhpmNuBqXMiP61wVHX0= -20251209022744.sql h1:0WXCKpMDFAe/aVnosMGmCYp3mw+FIu+foX14sYmq750= -20251209025908.sql h1:MgO50it1hj7Jj8BD5yKjW8OLC9qS3FFEdelqIsLT1v8= +20251206021053.sql h1:bpuEocu4lOhZ7oLuxd//22dzjfNgU2iaWEqSD1mVwoU= +20251207020537.sql h1:m6uh4NHVF3EKNTVMqOmuBSDFD9oCQk5mAwo05fT46G4= +20251207212015.sql h1:UPelYGTeUR6rm8mU8dfNzgRDEDun0UQ4tkgsaDljn30= +20251207221222.sql h1:bTfUCvCf2UPh+BA2IY2PHQafb9DwY9nhH5FRuMEHy+0= +20251209022744.sql h1:y5/PAiZH/fYCpDJpkQdNRJwWICHH2iNIwM1V+S1P6KA= +20251209025908.sql h1:p3kZA8kyEj+mQZSrdY3k2K1NojQzFJh/MlZJ0Oy6t/k= +20251209030538.sql h1:zltV6/Fu2zJW0/lVBl7MdnWuJcqNTUIRcqYYZ8Fi1wo= diff --git a/internal/interface/main-handler/patient/handler.go b/internal/interface/main-handler/patient/handler.go index ce1c6c52..dc6c3ff5 100644 --- a/internal/interface/main-handler/patient/handler.go +++ b/internal/interface/main-handler/patient/handler.go @@ -69,11 +69,6 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { return } - authInfo, err := pa.GetAuthInfo(r) - if err != nil { - rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil) - } - dto.Id = uint(id) dto.AuthInfo = *authInfo res, err := u.Update(dto) From e3869ea5e996f6dbe866dff16fc348cd3dec5938 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 9 Dec 2025 12:52:30 +0700 Subject: [PATCH 18/39] migration from server --- cmd/main-migration/migrations/atlas.sum | 164 ++++++++++++------------ 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index d81f6ccb..cc3978f3 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:1Uh0B/nQPbiGKWcusDCZ9KUDAIGODzb8qSNiz7+yqrU= +h1:rEaAvMVRfUZCdhjipT3pYEoprBT8VTGN1C6p59FvR3Y= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,84 +75,84 @@ h1:1Uh0B/nQPbiGKWcusDCZ9KUDAIGODzb8qSNiz7+yqrU= 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:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= -20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= -20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= -20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= -20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= -20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= -20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= -20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= -20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= -20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= -20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= -20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= -20251110052049.sql h1:232T2x8xTczJl9nk4jxJpZXhoOGYthhxjJ7nK8Jd8vg= -20251110062042.sql h1:WnfVUXrzYoj8qdkkjO9/JQQ8agGd4GfSHQdMjo7LDAg= -20251110063202.sql h1:hSzGfwVMWa6q3vwIQZUkxKgBNCzHjB+6GKy54zfV+oQ= -20251110063633.sql h1:/VpofIAqNS1CnazEnpW/+evbzn9Kew3xDW48r57M+Xg= -20251110085551.sql h1:bFZwSmfvVbTUr/enWB82WqjG88gpqcZ6s45btUvO0uo= -20251110091516.sql h1:KkJMwPQuaZQhiqnKrNQrgP12gw9rV8T3P2o3mtGTcvY= -20251110091948.sql h1:I4odAYrJdvNf1jPw6ppDC0XdI7v6vKBACg/ABwUgA7I= -20251110092729.sql h1:l1out8soEmVP6dNjaIOtGYo6QDcoJZRI8X1sjZ5ZGmo= -20251110093522.sql h1:nsz8jCxGjEdr/bz9g+4ozfZzIP803xONjVmucad1GMc= -20251110100258.sql h1:IBqt1VZj5WjQ+l9aAFGHOCCBtzb03KlLLihFLut7itg= -20251110100545.sql h1:6/LV7751iyKxE2xI6vO1zly+aHUwxXD/IBwLcVpKxqM= -20251110155448.sql h1:kFPobJB+cpflsXBAWUwy3lohuWvrb/VRlXnhJWl7i3Y= -20251111072601.sql h1:ch8F+yVhsSM5xY+TwMLY3PxdLa4Wuhtj76oyw79R7Js= -20251111073546.sql h1:cCv0NPscADAOBahRVqtDWFs6G2t7n+4a+RwlF8vk/c4= -20251111074148.sql h1:70TsV83u1gQ5TktI13K7NQiyCCa35Td2aR6CNtKUa4U= -20251111074652.sql h1:ddfQ/sRKMezPM75xBFTGytUQX5AwZ3znrJVpg73gKPA= -20251111082257.sql h1:ZsdLY1ROouos0l3oS0lkeSiuKLEUGbVvBhpcM2AVhkw= -20251111111017.sql h1:qrJ93dNtQwcuAvpsP/lAK/H63C4cinXrsVaPmWsTqkU= -20251113101344.sql h1:xaOZvAUP1fFfnO+syEFOzJUIg5lTfBe5AWHPbBWuCLA= -20251113120533.sql h1:f3/U1Ve2yF2zSMhkt+xtwF8wUYfUKYwgbNeGfE37EW4= -20251114062746.sql h1:FInLaEFQByESEwFJKuKnuUSTKmcDpi3ZXaxkKwz2+D8= -20251117005942.sql h1:wD3BWrUSmo1HlW16V3lkaBkJvbAZ0fNk77te7J9NhOc= -20251117075427.sql h1:TqU9VKZa3I8YNXUGQWY3WVBYN+1FvyyaKy0hB1jgAho= -20251118074929.sql h1:p1KsWqCuR1JXA/jVO5BmOhCcaQ8clT7t0YRszAhPFbg= -20251119063438.sql h1:NVGM0X/LHD37EaPl8SNzkNiZDJ7AB1QR+LLwLh6WRdg= -20251119065730.sql h1:U5lzk1WvMB0bw3kwckou7jkEt4bwdYItwHr2Vxqe7w4= -20251119072302.sql h1:qCuI2WMEMF/XNbjV+RXPjBnuCKLu1Fia+mR9HiLWBIs= -20251119072450.sql h1:Xg+bTwqGyKPNFEQhJylvpz1wifdfmDJvcAq6vmNf0Ng= -20251120005512.sql h1:Ek6qpacAI/qVuTYxKno+uJyzn7s5z9pf3t7VA8gTzm4= -20251120074415.sql h1:NNUeJVA03EeBHJhHqPXEZoDv/PnC6yK1/cRhmukyaJo= -20251121033803.sql h1:/vfvFX/3pzSCIHnSbMUT9EMBDykOpVkvyfeTEle9Vas= -20251124071457.sql h1:qg2dhCL9YwD13xnfJ175lW/p6MGfzFKaBqd908FByRc= -20251125125303.sql h1:4JSFv1Pmhbe9tqpLXgO63OwYnGsalStgUXKVWPyc1YE= -20251126064057.sql h1:vAdhz5Nn/gGJy0UKZAEldeXv8HpHtJU/t8ygDVIbTsU= -20251201081333.sql h1:PoC8ADRdwDuohDTB74yW/DaB42igdYa4B6humbrEJBk= -20251201104439.sql h1:tpqdrOf9d2aGwZshqm62nG6SXnfVaO/g6A7z0efPS14= -20251201113804.sql h1:kIEmVoETJXBkab2Q+b3y/pP84eF8W2BdQ47amHCnc+c= -20251201113858.sql h1:KLXKZO5XTQPoEU0YLHE8Fhg9WPKpSN3wNgYPJ+RGFcg= -20251201114751.sql h1:HM17diiPknfSHAmP+kJGP6GzToaPU9/NT+KQBpf3Jq0= -20251201114913.sql h1:gqucFgHFFLA6n/Rdz486cZH5xkaJuwefESLJMJLDue8= -20251202030445.sql h1:QWBVfTepT7DaXP5E0BYoxNM0JwKIQ2qIMXzI4kbz/qE= -20251202044430.sql h1:4QZH9lz0GrQ9rzP1AJ+hJgGalNpp+8FCRckNK7xaTbU= -20251202064000.sql h1:/EN7sT1ol/91qW1aXWrzX+Mc3XOC/7f/LtfA0JRHpbg= -20251202130629.sql h1:9mvalqfhqGCdkcJepJDzHprU2xb0i5sYys1Htf62ioo= -20251202160848.sql h1:Kd2/TziKSMezrt4XgbjQcYvY/Lo9rX0qw7/Lz0/oyKk= -20251202180207.sql h1:IHmSMIO3ia+YV5GULixbdlV1joaUAWtnjQHPd8+HKiM= -20251202231005.sql h1:lua0KKoeBptSfs/6ehZE6Azo6YUlNkOJwGFyb1HQWkY= -20251203205052.sql h1:nk0VK2Uv4bHE3SBfHo/aevVZxtHzr7zAzvmMU8TCCtk= -20251205073858.sql h1:46qqXnArgJmzGE/WO7v7Ev8Jh7BudDiGbdANexq/5Dk= -20251205211957.sql h1:3fvtZ/mBWsTIXllXMFOuCLJsp4MivVP56dunehlU0yo= -20251205214433.sql h1:rn3++FEfX7ntcJcOmCEuOMnr27TZqH0KMGRppzFwFTc= -20251205221124.sql h1:CRruUvGZqlVDBmbQSVEl4wFm+uq30AurMMDI6sb8jxg= -20251206021053.sql h1:bpuEocu4lOhZ7oLuxd//22dzjfNgU2iaWEqSD1mVwoU= -20251207020537.sql h1:m6uh4NHVF3EKNTVMqOmuBSDFD9oCQk5mAwo05fT46G4= -20251207212015.sql h1:UPelYGTeUR6rm8mU8dfNzgRDEDun0UQ4tkgsaDljn30= -20251207221222.sql h1:bTfUCvCf2UPh+BA2IY2PHQafb9DwY9nhH5FRuMEHy+0= -20251209022744.sql h1:y5/PAiZH/fYCpDJpkQdNRJwWICHH2iNIwM1V+S1P6KA= -20251209025908.sql h1:p3kZA8kyEj+mQZSrdY3k2K1NojQzFJh/MlZJ0Oy6t/k= -20251209030538.sql h1:zltV6/Fu2zJW0/lVBl7MdnWuJcqNTUIRcqYYZ8Fi1wo= +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= +20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= +20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= +20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= +20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= +20251110063202.sql h1:A117DuZmZ6U0jWHA3DISnr+yvBjKIr1ObrUr047YezQ= +20251110063633.sql h1:qTiC0F19JnhUIXF4LGJQ21jEV6kKGyhTr1x2kimFqPQ= +20251110085551.sql h1:HZcJM0RSC6HBaUSjKBE8MgDG8Vn9f3LmwA/OnT9Cp7I= +20251110091516.sql h1:W3AQhQLgirEWuCObbLl+Prdrbq6k6EEY1xcoWsmbog4= +20251110091948.sql h1:3tsITMrZr/T+L4wqUMz8sHS229jCJl4T0Nu3dMccxH8= +20251110092729.sql h1:uU+k88RH/e0Ns4/SmJl03RVYPscBAPuiLfxR6CJqaf0= +20251110093522.sql h1:O7upSj8VNjzvroL4IU59bfxKATOkAVGBArcUbVNq9aM= +20251110100258.sql h1://JSArUMNI3/gAtYDx2VN94C198SFW0ANjgs+p6eCRM= +20251110100545.sql h1:ENPOqeJYRpMI4e8VCKwaQgaql8se6pIidAhG2cjskBg= +20251110155448.sql h1:VW9KE0jxWy4flZ28sdXmhY6JWd6eKAX/cVL8KWRVii4= +20251111072601.sql h1:99WWzGjcDDFNC2cHRfPu4MBLWNrgPMY5HAYUbmIcVRA= +20251111073546.sql h1:iIGwFNfUgStdczw/PXTH3SD84xAyxrbZICofc3M8TMk= +20251111074148.sql h1:mzkezSKwCV2bTZ/0BHiTCX5qAy4uHpwar1xzwAH15Ko= +20251111074652.sql h1:lYh4/3BHV24pgPC0pP4RUKb+XtL/6AsZGPItRpnzBiQ= +20251111082257.sql h1:+cIZ1lf8HYGSL6t6U88plLKk8nOO1YVdV7h3YOM84ds= +20251111111017.sql h1:xzlhR2xLfOj4ddYlesS+bpEeDrxiAf5ILNOspsbZjBU= +20251113101344.sql h1:vSzThY3p6XYTj0dJ2uFVkHmlytyrFAnGE58CJLx364I= +20251113120533.sql h1:lfjgdqRGo/EohrVw8sWlFbDjh3ASTsfQ6pr3qjafqvc= +20251114062746.sql h1:6DLYjfJ60PkAABZTXvOwSE+xrU25oyoX7gpYlBnA9cw= +20251117005942.sql h1:0XoJKca8IOaB9QKFVF/qPY7jKcIgh6m/LODQuE06SAs= +20251117075427.sql h1:LhY2urosfoSu1/vkHmgsNP4JA4DuWBs9gL59yMqcF8M= +20251118074929.sql h1:3RWBD6BziQVw6WSfthgoVuhTELHER9NrIuZm4hY/F1A= +20251119063438.sql h1:EVTG3ZrHjCmM95YPASZTRPiwHrG6e33A2vO4hLSAaBQ= +20251119065730.sql h1:s98wnZOCW6NbnwDS3H53XIQ60u6B9bDwBLNvy5+Rn64= +20251119072302.sql h1:ZL+VHekLYqgNtOFKlj02WHrAk11dtTxQkmyTKE8IOzY= +20251119072450.sql h1:SiJy2vpSvoPFw4J1SW7HjGSJzrqR62NsjRYAeabV+kc= +20251120005512.sql h1:hJUaWXYJ3HiSquBTw8OKhymjA4O43ehAMGfiOY8W87Q= +20251120074415.sql h1:dNmcqZHqfZwi/wtYvO/pSFgImN2scXL0p/7g0+HLp0s= +20251121033803.sql h1:onlddYGo+tQdGaEdJPqdsx3sncGnwEvqMSCksF6vjjI= +20251124071457.sql h1:ikQLIXFikUbkUd55uJBmEvqLGEC9t0db+Om4TQsWP7M= +20251125125303.sql h1:OLKbNPO36AHtIDursW9AeBvf60sahQKC1iOjHmpx0MA= +20251126064057.sql h1:6al3PTWbw/WGiBcrRrVWppOMLtG+eRaH/qSLbnmh1kQ= +20251201081333.sql h1:dD+jcisoUYnxRYWdtVcnxbDeYjUW12/R/qarYQr+utg= +20251201104439.sql h1:h4tz5uetbCKeOI3agSVmAeh6jUfECYy0LhQ7HooYhzg= +20251201113804.sql h1:DdUzqfLdy4AUpVSRFDrIJXntGmtKgZrtvv8MAT4mMxs= +20251201113858.sql h1:XSpicm4aWjrfeY5EYIiw8Ios9v7BGfzZJxpW/57Qwqs= +20251201114751.sql h1:qx+ShdHLacVFcRwwGrW1zMKFHOjMGdnusk7CEfyV8ig= +20251201114913.sql h1:6l/m2/6fmTIjFmKio0QmB8oTwBDCHTIkbuYTODQ7Gwk= +20251202030445.sql h1:5+6ss5KdN6pll8Qtf0RGGyy/BURNO3dBgIBJOzDb624= +20251202044430.sql h1:nJtlQDGj7ZJtJ07NYcF41JCn9ck50GyDPoitTOe8P/s= +20251202064000.sql h1:yzSMOPZrpvQf+u6CxD6LwNySNH9Ip1u70UEf2vWI5w4= +20251202130629.sql h1:u79EiiYq5irxCcjlOHQcACnCKS05XPDDsL4TzLGrNQA= +20251202160848.sql h1:Aq5rVLbrL4vvNnmfk82V22GTteWVTSq9vk2SYzi3EBo= +20251202180207.sql h1:J0Orufzpi+tNhd5+9eLvonKhYc/WMceVHO1WDVRrHAM= +20251202231005.sql h1:DBunbxmAfPYiO5mHspc4dyTTVFoKrHkZSwk/Ieu5oFA= +20251203205052.sql h1:67NoN6JhDfChBA13dmErBSRDiC1gdVBb2F+8SMzpm4U= +20251205073858.sql h1:q6kLxs713H2BeVmC4cN6OnWz4Vj4k3G1iemqQnddmL8= +20251205211957.sql h1:aYPG5ESbHjhLRf8Dym1IMLBW2eRuafafoL46vpiRbWs= +20251205214433.sql h1:X9NOCU2CenDxnXe3kOyUB11Zikk+yO9yWNYAwFs/Bms= +20251205221124.sql h1:8ZXiMoNKQIMwXoLzrC44EQpXDUyEP16MiDOwUc9FI0s= +20251206021053.sql h1:jntV1lOgr4viO5wfavoTergWBSYDCbqw7L/UkhwuCYM= +20251207020537.sql h1:UIeD0lLOmo80REhicPlYsjj99xYYybPBph8ewZOQa2M= +20251207212015.sql h1:gMDRyRTNMyH9iNG/9cTflLUf60r5qMteaaTcQoDzNAI= +20251207221222.sql h1:FT+HGmIpvm+Y3w7DmENoeJWHBHjucDPQXPl8xyBRn9Y= +20251209022744.sql h1:eRmSp7hnpz5Mded7sBkc2+VZX6xKzU95rIzZOJC9Lhw= +20251209025908.sql h1:ZDtWUIuMIAcjQ/mMdDXbrbk+De9T2TGqprXcVSZOoT4= +20251209030538.sql h1:iTQimic8fGvHU10V7PSpSe9I0YpRFuNjOeOLY0eGMp8= From 792c7cc9d4b883c2003d825da530325897e752f5 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Tue, 9 Dec 2025 13:43:41 +0700 Subject: [PATCH 19/39] feat/user: added registration entity --- .../migrations/20251209064304.sql | 12 ++++ cmd/main-migration/migrations/atlas.sum | 5 +- .../domain/main-entities/registration/dto.go | 71 +++++++++++++++++++ .../main-entities/registration/entity.go | 15 ++++ internal/interface/migration/main-entities.go | 2 + 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 cmd/main-migration/migrations/20251209064304.sql create mode 100644 internal/domain/main-entities/registration/dto.go create mode 100644 internal/domain/main-entities/registration/entity.go diff --git a/cmd/main-migration/migrations/20251209064304.sql b/cmd/main-migration/migrations/20251209064304.sql new file mode 100644 index 00000000..fc289e20 --- /dev/null +++ b/cmd/main-migration/migrations/20251209064304.sql @@ -0,0 +1,12 @@ +-- Create "Registration" table +CREATE TABLE "public"."Registration" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Employee_Id" bigint NULL, + "Installation_Code" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Registration_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Registration_Installation" FOREIGN KEY ("Installation_Code") REFERENCES "public"."Installation" ("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 3ec1b876..c953a07b 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:qjr3k9/ymXjw1nopw49c6+fWtu0n+H8sQgsioqUC9Fo= +h1:JGe2DnXv3QZTmdne3HWeAGA4rppck8cJaiZ0RgoM+Sg= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -144,4 +144,5 @@ h1:qjr3k9/ymXjw1nopw49c6+fWtu0n+H8sQgsioqUC9Fo= 20251202160848.sql h1:Kd2/TziKSMezrt4XgbjQcYvY/Lo9rX0qw7/Lz0/oyKk= 20251202180207.sql h1:IHmSMIO3ia+YV5GULixbdlV1joaUAWtnjQHPd8+HKiM= 20251202231005.sql h1:lua0KKoeBptSfs/6ehZE6Azo6YUlNkOJwGFyb1HQWkY= -20251203205052.sql h1:az/hGpk7u4YKT7gU+UuEw9guqB9AqdckPF1cYavQ3CA= +20251203205052.sql h1:nk0VK2Uv4bHE3SBfHo/aevVZxtHzr7zAzvmMU8TCCtk= +20251209064304.sql h1:/vp48I71991yaVsOw/g+eFsFydgLGEo+Xfen7Lp8WB4= diff --git a/internal/domain/main-entities/registration/dto.go b/internal/domain/main-entities/registration/dto.go new file mode 100644 index 00000000..b7837aee --- /dev/null +++ b/internal/domain/main-entities/registration/dto.go @@ -0,0 +1,71 @@ +package doctor + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ee "simrs-vx/internal/domain/main-entities/employee" + ei "simrs-vx/internal/domain/main-entities/installation" +) + +type CreateDto struct { + Employee_Id uint `json:"employee_id"` + Installation_Code string `json:"installation_code" validate:"maxLength=20"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Employee_Id *uint `json:"employee-id"` + Installation_Code *string `json:"installation-code"` +} + +type ReadDetailDto struct { + Id *uint16 `json:"id"` + Code *string `json:"code"` + Employee_Id *uint `json:"employee_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 + Employee_Id uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty"` + Installation_Code string `json:"installation_code"` + Installation *ei.Installation `json:"installation,omitempty"` +} + +func (d Registration) ToResponse() ResponseDto { + resp := ResponseDto{ + Employee_Id: d.Employee_Id, + Employee: d.Employee, + Installation_Code: d.Installation_Code, + Installation: d.Installation, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []Registration) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/registration/entity.go b/internal/domain/main-entities/registration/entity.go new file mode 100644 index 00000000..52d81f40 --- /dev/null +++ b/internal/domain/main-entities/registration/entity.go @@ -0,0 +1,15 @@ +package doctor + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ee "simrs-vx/internal/domain/main-entities/employee" + ei "simrs-vx/internal/domain/main-entities/installation" +) + +type Registration struct { + ecore.Main // adjust this according to the needs + Employee_Id uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` + Installation_Code string `json:"installation_code" gorm:"size:20"` + Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_Code;references:Code"` +} diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 34530d78..aa4ed3f6 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -88,6 +88,7 @@ import ( proceduresrc "simrs-vx/internal/domain/main-entities/procedure-src" province "simrs-vx/internal/domain/main-entities/province" regency "simrs-vx/internal/domain/main-entities/regency" + registration "simrs-vx/internal/domain/main-entities/registration" rehab "simrs-vx/internal/domain/main-entities/rehab" responsibledoctorhist "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" resume "simrs-vx/internal/domain/main-entities/resume" @@ -140,6 +141,7 @@ func getMainEntities() []any { &proceduresrc.ProcedureSrc{}, &employee.Employee{}, &intern.Intern{}, + ®istration.Registration{}, &doctor.Doctor{}, &nurse.Nurse{}, &nutritionist.Nutritionist{}, From 143b873c1134f7a9d75e948d66db4ccb20222057 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Tue, 9 Dec 2025 14:02:30 +0700 Subject: [PATCH 20/39] migration: adjust person entity --- .../migrations/20251209070128.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 16 ++++++++++++++-- internal/domain/main-entities/person/dto.go | 18 ++++++++++-------- internal/domain/main-entities/person/entity.go | 1 + 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 cmd/main-migration/migrations/20251209070128.sql diff --git a/cmd/main-migration/migrations/20251209070128.sql b/cmd/main-migration/migrations/20251209070128.sql new file mode 100644 index 00000000..fb0caac3 --- /dev/null +++ b/cmd/main-migration/migrations/20251209070128.sql @@ -0,0 +1,2 @@ +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD COLUMN "BirthPlace" text NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index c953a07b..b828c76d 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:JGe2DnXv3QZTmdne3HWeAGA4rppck8cJaiZ0RgoM+Sg= +h1:YJzcjq4dKD7GKlV0GJ88TOtZgg0JRDcVMlAe5ZYT9/U= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -145,4 +145,16 @@ h1:JGe2DnXv3QZTmdne3HWeAGA4rppck8cJaiZ0RgoM+Sg= 20251202180207.sql h1:IHmSMIO3ia+YV5GULixbdlV1joaUAWtnjQHPd8+HKiM= 20251202231005.sql h1:lua0KKoeBptSfs/6ehZE6Azo6YUlNkOJwGFyb1HQWkY= 20251203205052.sql h1:nk0VK2Uv4bHE3SBfHo/aevVZxtHzr7zAzvmMU8TCCtk= -20251209064304.sql h1:/vp48I71991yaVsOw/g+eFsFydgLGEo+Xfen7Lp8WB4= +20251205073858.sql h1:46qqXnArgJmzGE/WO7v7Ev8Jh7BudDiGbdANexq/5Dk= +20251205211957.sql h1:3fvtZ/mBWsTIXllXMFOuCLJsp4MivVP56dunehlU0yo= +20251205214433.sql h1:rn3++FEfX7ntcJcOmCEuOMnr27TZqH0KMGRppzFwFTc= +20251205221124.sql h1:CRruUvGZqlVDBmbQSVEl4wFm+uq30AurMMDI6sb8jxg= +20251206021053.sql h1:bpuEocu4lOhZ7oLuxd//22dzjfNgU2iaWEqSD1mVwoU= +20251207020537.sql h1:m6uh4NHVF3EKNTVMqOmuBSDFD9oCQk5mAwo05fT46G4= +20251207212015.sql h1:UPelYGTeUR6rm8mU8dfNzgRDEDun0UQ4tkgsaDljn30= +20251207221222.sql h1:bTfUCvCf2UPh+BA2IY2PHQafb9DwY9nhH5FRuMEHy+0= +20251209022744.sql h1:y5/PAiZH/fYCpDJpkQdNRJwWICHH2iNIwM1V+S1P6KA= +20251209025908.sql h1:p3kZA8kyEj+mQZSrdY3k2K1NojQzFJh/MlZJ0Oy6t/k= +20251209030538.sql h1:zltV6/Fu2zJW0/lVBl7MdnWuJcqNTUIRcqYYZ8Fi1wo= +20251209064304.sql h1:Mj6Zh+2b/4AkM1HjnJGjAs788kVN0UaL34jeaKQIjT0= +20251209070128.sql h1:rdqSlAmJS5XSc1w9dka3C53zwgibQwRIUqBcgmIPoTM= diff --git a/internal/domain/main-entities/person/dto.go b/internal/domain/main-entities/person/dto.go index 588379df..dbab95b0 100644 --- a/internal/domain/main-entities/person/dto.go +++ b/internal/domain/main-entities/person/dto.go @@ -19,6 +19,7 @@ type CreateDto struct { FrontTitle *string `json:"frontTitle" validate:"maxLength=50"` EndTitle *string `json:"endTitle" validate:"maxLength=50"` BirthDate *time.Time `json:"birthDate,omitempty"` + BirthPlace *string `json:"birthPlace" validate:"maxLength=4"` BirthRegency_Code *string `json:"birthRegency_code" validate:"maxLength=4"` Gender_Code *erp.GenderCode `json:"gender_code"` ResidentIdentityNumber *string `json:"residentIdentityNumber" validate:"nik;maxLength=16"` @@ -46,14 +47,13 @@ type ReadListDto struct { type FilterDto struct { Name string `json:"name"` - FrontTitle *string `json:"frontTitle"` - EndTitle *string `json:"endTitle"` - BirthDate *time.Time `json:"birthDate,omitempty"` - BirthRegency_Code *string `json:"birthRegency-code"` + FrontTitle *string `json:"front-title"` + EndTitle *string `json:"end-title"` + BirthDate *time.Time `json:"birth-date,omitempty"` Gender_Code *erp.GenderCode `json:"gender-code"` - ResidentIdentityNumber *string `json:"residentIdentityNumber"` - PassportNumber *string `json:"passportNumber"` - DrivingLicenseNumber *string `json:"drivingLicenseNumber"` + ResidentIdentityNumber *string `json:"resident-identity-number"` + PassportNumber *string `json:"passport-number"` + DrivingLicenseNumber *string `json:"driving-license-number"` Religion_Code *erp.ReligionCode `json:"religion-code"` Education_Code *erp.EducationCode `json:"education-code"` Ocupation_Code *erp.OcupationCode `json:"occupation-code"` @@ -61,7 +61,7 @@ type FilterDto struct { Nationality *string `json:"nationality"` Ethnic_Code *string `json:"ethnic-code"` Language_Code *string `json:"language-code"` - CommunicationIssueStatus bool `json:"communicationIssueStatus"` + CommunicationIssueStatus bool `json:"communication-issue-status"` Disability *string `json:"disability"` } @@ -94,6 +94,7 @@ type ResponseDto struct { FrontTitle *string `json:"frontTitle"` EndTitle *string `json:"endTitle"` BirthDate *time.Time `json:"birthDate,omitempty"` + BirthPlace *string `json:"birthPlace"` BirthRegency_Code *string `json:"birthRegency_code"` BirthRegency *er.Regency `json:"birthRegency,omitempty"` Gender_Code *erp.GenderCode `json:"gender_code"` @@ -128,6 +129,7 @@ func (d *Person) ToResponse() ResponseDto { FrontTitle: d.FrontTitle, EndTitle: d.EndTitle, BirthDate: d.BirthDate, + BirthPlace: d.BirthPlace, BirthRegency_Code: d.BirthRegency_Code, BirthRegency: d.BirthRegency, Gender_Code: d.Gender_Code, diff --git a/internal/domain/main-entities/person/entity.go b/internal/domain/main-entities/person/entity.go index 3c7d8629..10626229 100644 --- a/internal/domain/main-entities/person/entity.go +++ b/internal/domain/main-entities/person/entity.go @@ -23,6 +23,7 @@ type Person struct { FrontTitle *string `json:"frontTitle" gorm:"size:50"` EndTitle *string `json:"endTitle" gorm:"size:50"` BirthDate *time.Time `json:"birthDate,omitempty"` + BirthPlace *string `json:"birthPlace,omitempty"` BirthRegency_Code *string `json:"birthRegency_code" gorm:"size:4"` BirthRegency *er.Regency `json:"birthRegency,omitempty" gorm:"foreignKey:BirthRegency_Code;references:Code"` Gender_Code *erp.GenderCode `json:"gender_code" gorm:"size:10"` From 550b629bcbc6148011d708de663aac9db47529ae Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Tue, 9 Dec 2025 14:24:07 +0700 Subject: [PATCH 21/39] feat/user: adjust some entities --- internal/domain/main-entities/registration/dto.go | 6 +++--- internal/domain/main-entities/user/dto.go | 3 ++- .../use-case/main-use-case/person-address/lib.go | 13 ++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/internal/domain/main-entities/registration/dto.go b/internal/domain/main-entities/registration/dto.go index b7837aee..ea842e95 100644 --- a/internal/domain/main-entities/registration/dto.go +++ b/internal/domain/main-entities/registration/dto.go @@ -23,9 +23,9 @@ type FilterDto struct { } type ReadDetailDto struct { - Id *uint16 `json:"id"` - Code *string `json:"code"` - Employee_Id *uint `json:"employee_id"` + Id *uint `json:"id"` + Employee_Id *uint `json:"employee_id"` + Includes string `json:"includes"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/user/dto.go b/internal/domain/main-entities/user/dto.go index fd4b3f2c..acd189a0 100644 --- a/internal/domain/main-entities/user/dto.go +++ b/internal/domain/main-entities/user/dto.go @@ -24,8 +24,9 @@ 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_Code *string `json:"unit_code"` Infra_Code *string `json:"infra_code"` + Installation_Code *string `json:"installation_code"` + Unit_Code *string `json:"unit_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/person-address/lib.go b/internal/use-case/main-use-case/person-address/lib.go index 94cbfa69..8a07aba6 100644 --- a/internal/use-case/main-use-case/person-address/lib.go +++ b/internal/use-case/main-use-case/person-address/lib.go @@ -2,6 +2,8 @@ package personaddress import ( e "simrs-vx/internal/domain/main-entities/person-address" + "strconv" + "strings" plh "simrs-vx/pkg/lib-helper" pl "simrs-vx/pkg/logger" @@ -179,10 +181,19 @@ func CreateOrUpdateBatch(input []e.UpdateDto, event *pl.Event, tx ...*gorm.DB) e } setData(&input[idx], &data[idx]) if err := dbx.Create(&data[idx]).Error; err != nil { + errMsg := err.Error() + additionalMessage := "" + // FK error + if strings.Contains(errMsg, "violates foreign key") { + pos := strings.Index(errMsg, "violates foreign key") + additionalMessage = ", " + errMsg[pos:] + } + // Got another errot, put it down below + // .... event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-create-fail", - Detail: "Database insert failed", + Detail: "data insert failed at PersonAddres[" + strconv.Itoa(idx) + "]" + additionalMessage, Raw: err, } return pl.SetLogError(event, input) From 36e65abfac59ba7586208f029ad9e0df2f53d5fd Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Tue, 9 Dec 2025 14:24:28 +0700 Subject: [PATCH 22/39] feat/user: employee regisgtration flow --- .../main-use-case/registration/case.go | 276 ++++++++++++++++++ .../main-use-case/registration/helper.go | 22 ++ .../main-use-case/registration/lib.go | 179 ++++++++++++ .../registration/middleware-runner.go | 103 +++++++ .../main-use-case/registration/middleware.go | 9 + .../main-use-case/registration/tycovar.go | 44 +++ internal/use-case/main-use-case/user/case.go | 10 +- 7 files changed, 642 insertions(+), 1 deletion(-) create mode 100644 internal/use-case/main-use-case/registration/case.go create mode 100644 internal/use-case/main-use-case/registration/helper.go create mode 100644 internal/use-case/main-use-case/registration/lib.go create mode 100644 internal/use-case/main-use-case/registration/middleware-runner.go create mode 100644 internal/use-case/main-use-case/registration/middleware.go create mode 100644 internal/use-case/main-use-case/registration/tycovar.go diff --git a/internal/use-case/main-use-case/registration/case.go b/internal/use-case/main-use-case/registration/case.go new file mode 100644 index 00000000..06d48899 --- /dev/null +++ b/internal/use-case/main-use-case/registration/case.go @@ -0,0 +1,276 @@ +package doctor + +import ( + "strconv" + + dg "github.com/karincake/apem/db-gorm-pg" + d "github.com/karincake/dodol" + "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/registration" + + pl "simrs-vx/pkg/logger" + pu "simrs-vx/pkg/use-case-helper" +) + +const source = "doctor" + +func Create(input e.CreateDto) (*d.Data, error) { + data := e.Registration{} + + 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.Registration + var dataList []e.Registration + 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.Registration + 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.Registration + 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.Registration + 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/registration/helper.go b/internal/use-case/main-use-case/registration/helper.go new file mode 100644 index 00000000..186e7f44 --- /dev/null +++ b/internal/use-case/main-use-case/registration/helper.go @@ -0,0 +1,22 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package doctor + +import ( + e "simrs-vx/internal/domain/main-entities/registration" +) + +func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Registration) { + var inputSrc *e.CreateDto + if inputT, ok := any(input).(*e.CreateDto); ok { + inputSrc = inputT + } else { + inputTemp := any(input).(*e.UpdateDto) + inputSrc = &inputTemp.CreateDto + } + + data.Employee_Id = inputSrc.Employee_Id + data.Installation_Code = inputSrc.Installation_Code +} diff --git a/internal/use-case/main-use-case/registration/lib.go b/internal/use-case/main-use-case/registration/lib.go new file mode 100644 index 00000000..7d28bb9a --- /dev/null +++ b/internal/use-case/main-use-case/registration/lib.go @@ -0,0 +1,179 @@ +package doctor + +import ( + "fmt" + e "simrs-vx/internal/domain/main-entities/registration" + + 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.Registration, error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + data := e.Registration{} + 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.Registration, *e.MetaDto, error) { + pl.SetLogInfo(event, input, "started", "DBReadList") + data := []e.Registration{} + 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.Registration{}). + 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.Registration, error) { + pl.SetLogInfo(event, input, "started", "DBReadDetail") + data := e.Registration{} + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if input.Employee_Id != nil { + tx = tx.Where("\"Employee_Id\" = ?", *input.Employee_Id) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + fmt.Println(input.Includes) + if err := tx.Scopes(gh.Preload(input.Includes)).First(&data).Error; err != nil { + if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { + return nil, processedErr + } + } + + pl.SetLogInfo(event, nil, "complete") + return &data, nil +} + +func UpdateData(input e.UpdateDto, data *e.Registration, 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.Registration, 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 +} + +func GetIdByUserId(user_id *uint, event *pl.Event, dbx ...*gorm.DB) (*uint, error) { + pl.SetLogInfo(event, nil, "started", "DBGetIdByUserId") + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + var doctor_id uint + + err := tx.Model(&e.Registration{}). + Select("\"Doctor\".\"Id\" as doctor_id"). + Joins("JOIN \"Employee\" as e ON e.\"Id\" = \"Doctor\".\"Employee_Id\""). + Where("e.\"User_Id\" = ?", user_id). + Scan(&doctor_id).Error + + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-get-fail", + Detail: "Database get failed", + Raw: err, + } + return nil, pl.SetLogError(event, user_id) + } + + pl.SetLogInfo(event, nil, "complete") + return &doctor_id, nil +} diff --git a/internal/use-case/main-use-case/registration/middleware-runner.go b/internal/use-case/main-use-case/registration/middleware-runner.go new file mode 100644 index 00000000..d68f8de9 --- /dev/null +++ b/internal/use-case/main-use-case/registration/middleware-runner.go @@ -0,0 +1,103 @@ +package doctor + +import ( + e "simrs-vx/internal/domain/main-entities/registration" + 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.Registration) 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.Registration) 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.Registration) 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.Registration) 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.Registration) 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/registration/middleware.go b/internal/use-case/main-use-case/registration/middleware.go new file mode 100644 index 00000000..b6bfc120 --- /dev/null +++ b/internal/use-case/main-use-case/registration/middleware.go @@ -0,0 +1,9 @@ +package doctor + +// 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/registration/tycovar.go b/internal/use-case/main-use-case/registration/tycovar.go new file mode 100644 index 00000000..bda8f4f8 --- /dev/null +++ b/internal/use-case/main-use-case/registration/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 doctor + +import ( + "gorm.io/gorm" + + e "simrs-vx/internal/domain/main-entities/registration" +) + +type createMw struct { + Name string + Func func(input *e.CreateDto, data *e.Registration, tx *gorm.DB) error +} + +type readListMw struct { + Name string + Func func(input *e.ReadListDto, data *e.Registration, tx *gorm.DB) error +} + +type readDetailMw struct { + Name string + Func func(input *e.ReadDetailDto, data *e.Registration, 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/user/case.go b/internal/use-case/main-use-case/user/case.go index f6faec22..f360336a 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -13,6 +13,7 @@ import ( en "simrs-vx/internal/domain/main-entities/nurse" et "simrs-vx/internal/domain/main-entities/nutritionist" ep "simrs-vx/internal/domain/main-entities/pharmacist" + er "simrs-vx/internal/domain/main-entities/registration" esi "simrs-vx/internal/domain/main-entities/specialist-intern" e "simrs-vx/internal/domain/main-entities/user" @@ -26,6 +27,7 @@ import ( upa "simrs-vx/internal/use-case/main-use-case/person-address" upc "simrs-vx/internal/use-case/main-use-case/person-contact" up "simrs-vx/internal/use-case/main-use-case/pharmacist" + ur "simrs-vx/internal/use-case/main-use-case/registration" usi "simrs-vx/internal/use-case/main-use-case/specialist-intern" erc "simrs-vx/internal/domain/references/common" @@ -167,7 +169,13 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } case ero.EPCReg, ero.EPCScr: - // do nothing + createSub := er.CreateDto{ + Employee_Id: employeeData.Id, + Installation_Code: *input.Installation_Code, + } + if _, err := ur.CreateData(createSub, &event, tx); err != nil { + return err + } default: return errors.New("invalid employee position") } From 591f6e6311742ac5a3b4bdcb63779dfcc195b8eb Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 9 Dec 2025 15:30:29 +0700 Subject: [PATCH 23/39] add entity sync --- .../migrations/20251209083238.sql | 72 +++++++++++++++++++ .../migrations/atlas.sum | 5 +- .../domain/simgos-entities/m-dokter/entity.go | 24 +++++++ .../simgos-entities/m_perawat/entity.go | 52 ++++++++++++++ .../domain/sync-entities/doctor/entity.go | 29 ++++++++ internal/domain/sync-entities/nurse/entity.go | 29 ++++++++ .../migration/simgossync-entities.go | 8 +++ 7 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 cmd/simgos-sync-migration/migrations/20251209083238.sql create mode 100644 internal/domain/simgos-entities/m-dokter/entity.go create mode 100644 internal/domain/simgos-entities/m_perawat/entity.go create mode 100644 internal/domain/sync-entities/doctor/entity.go create mode 100644 internal/domain/sync-entities/nurse/entity.go diff --git a/cmd/simgos-sync-migration/migrations/20251209083238.sql b/cmd/simgos-sync-migration/migrations/20251209083238.sql new file mode 100644 index 00000000..9e3f07eb --- /dev/null +++ b/cmd/simgos-sync-migration/migrations/20251209083238.sql @@ -0,0 +1,72 @@ +-- Create "DoctorLink" table +CREATE TABLE "public"."DoctorLink" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Simx_Id" bigint NULL, + "Simgos_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_DoctorLink_Simgos_Id" UNIQUE ("Simgos_Id"), + CONSTRAINT "uni_DoctorLink_Simx_Id" UNIQUE ("Simx_Id") +); +-- Create "DoctorSimgosLog" table +CREATE TABLE "public"."DoctorSimgosLog" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Value" text NULL, + "Date" timestamptz NULL, + "Status" text NULL, + "ErrMessage" text NULL, + PRIMARY KEY ("Id") +); +-- Create "DoctorSimxLog" table +CREATE TABLE "public"."DoctorSimxLog" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Value" text NULL, + "Date" timestamptz NULL, + "Status" text NULL, + "ErrMessage" text NULL, + PRIMARY KEY ("Id") +); +-- Create "NurseLink" table +CREATE TABLE "public"."NurseLink" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Simx_Id" bigint NULL, + "Simgos_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_NurseLink_Simgos_Id" UNIQUE ("Simgos_Id"), + CONSTRAINT "uni_NurseLink_Simx_Id" UNIQUE ("Simx_Id") +); +-- Create "NurseSimgosLog" table +CREATE TABLE "public"."NurseSimgosLog" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Value" text NULL, + "Date" timestamptz NULL, + "Status" text NULL, + "ErrMessage" text NULL, + PRIMARY KEY ("Id") +); +-- Create "NurseSimxLog" table +CREATE TABLE "public"."NurseSimxLog" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Value" text NULL, + "Date" timestamptz NULL, + "Status" text NULL, + "ErrMessage" text NULL, + PRIMARY KEY ("Id") +); diff --git a/cmd/simgos-sync-migration/migrations/atlas.sum b/cmd/simgos-sync-migration/migrations/atlas.sum index e82a5610..c06e3535 100644 --- a/cmd/simgos-sync-migration/migrations/atlas.sum +++ b/cmd/simgos-sync-migration/migrations/atlas.sum @@ -1,8 +1,9 @@ -h1:6YZBXq/r79I5tuYyY1+CBzhZsSeukHSs8MyHCC5QuV4= +h1:D3uD6s7yxMG7Roi9DCeYuLeRazZmQnd3rHMmUWf6YMM= 20251113035508.sql h1:rjDlu6yDdy5xv6nrCOr7NialrLSLT23pzduYNq29Hf0= 20251114071129.sql h1:Z0GQ5bJo3C+tplaWzxT8n3J9HLkEaVsRVp5nn7bmYow= 20251117041601.sql h1:l/RPG5mObqCSBjO4mzG+wTq2ieSycvlfOSz4czpUdWY= 20251118082246.sql h1:xLUwA+EvKWIg3X/TJvu7rqbtBzONiINfag5NJpMV29E= 20251118082915.sql h1:hP6FmUVFuADIN2cDg2Z1l7Wx7PQRb+IYQDvKD7J8VAM= 20251126115527.sql h1:Bvg+Y7k+h5s+/UaezUyJb7J7uzEJS7U5Z/RoCixcUtI= -20251201093443.sql h1:m18tksKG3OzbkxXkhfKUUqbkxnJ0VBPi3Cw34Tbywyc= +20251201093443.sql h1:dyiD1WzU9D6RjGhF0AtGfGLEsG6yocuk3HbcZWt9ZRQ= +20251209083238.sql h1:83pG5dPfMh8v0QognjeacK6s3fGxQ0nkijxtKL5y3Dc= diff --git a/internal/domain/simgos-entities/m-dokter/entity.go b/internal/domain/simgos-entities/m-dokter/entity.go new file mode 100644 index 00000000..47cbba6f --- /dev/null +++ b/internal/domain/simgos-entities/m-dokter/entity.go @@ -0,0 +1,24 @@ +package m_dokter + +import "time" + +type MDokter struct { + Kddokter uint `gorm:"column:kddokter;primaryKey;autoIncrement" json:"kddokter"` + Kdpoly uint `gorm:"column:kdpoly" json:"kdpoly"` + Namadokter string `gorm:"column:namadokter" json:"namadokter"` + Kdprofesi *uint `gorm:"column:kdprofesi" json:"kdprofesi"` + Namaprofesi *string `gorm:"column:namaprofesi" json:"namaprofesi"` + Aktif uint16 `gorm:"column:aktif" json:"aktif"` + KdSMF *string `gorm:"column:kdsmf" json:"kdsmf"` + KodeDPJP *string `gorm:"column:kode_dpjp" json:"kode_dpjp"` + NIP *string `gorm:"column:nip" json:"nip"` + Kategori *string `gorm:"column:kategori" json:"kategori"` + TglAkhirSIP *time.Time `gorm:"column:tgl_akhir_sip" json:"tgl_akhir_sip"` + NoHP *string `gorm:"column:no_hp" json:"no_hp"` + Email *string `gorm:"column:email" json:"email"` + TglAkhirSPK *time.Time `gorm:"column:tgl_akhir_spk" json:"tgl_akhir_spk"` +} + +func (MDokter) TableName() string { + return "m_dokter" +} diff --git a/internal/domain/simgos-entities/m_perawat/entity.go b/internal/domain/simgos-entities/m_perawat/entity.go new file mode 100644 index 00000000..c110ba11 --- /dev/null +++ b/internal/domain/simgos-entities/m_perawat/entity.go @@ -0,0 +1,52 @@ +package m_perawat + +import ( + "time" +) + +type MPerawat struct { + Idperawat *uint `json:"idperawat" gorm:"column:idperawat;primaryKey"` + NIP string `json:"nip" gorm:"column:nip"` + UnitKerja *uint `json:"unit_kerja" gorm:"column:unit_kerja"` + Ruang *string `json:"ruang" gorm:"column:ruang"` + Nama string `json:"nama" gorm:"column:nama"` + Tempat *string `json:"tempat" gorm:"column:tempat"` + TglLahir *time.Time `json:"tgllahir" gorm:"column:tgllahir"` + JenisKelamin *string `json:"jeniskelamin" gorm:"column:jeniskelamin"` + Alamat *string `json:"alamat" gorm:"column:alamat"` + Kelurahan *string `json:"kelurahan" gorm:"column:kelurahan"` + Kdkecamatan *uint `json:"kdkecamatan" gorm:"column:kdkecamatan"` + Kota *string `json:"kota" gorm:"column:kota"` + KdProvinsi *uint `json:"kdprovinsi" gorm:"column:kdprovinsi"` + NoTelp *string `json:"notelp" gorm:"column:notelp"` + NoKTP *string `json:"noktp" gorm:"column:noktp"` + Status *uint `json:"status" gorm:"column:status"` + Agama *uint `json:"agama" gorm:"column:agama"` + Pendidikan *uint `json:"pendidikan" gorm:"column:pendidikan"` + AlamatKTP *string `json:"alamat_ktp" gorm:"column:alamat_ktp"` + JabFung *string `json:"jabfung" gorm:"column:jabfung"` + JabStruk *string `json:"jabstruk" gorm:"column:jabstruk"` + LamKer *string `json:"lamker" gorm:"column:lamker"` + TemKer *string `json:"temker" gorm:"column:temker"` + TemKer2 *string `json:"temker2" gorm:"column:temker2"` + PelManKep *string `json:"pelmankep" gorm:"column:pelmankep"` + PelTekKepGaw *string `json:"peltekkepgaw" gorm:"column:peltekkepgaw"` + PelTekKepMedah *string `json:"peltekkepmedah" gorm:"column:peltekkepmedah"` + PelTekKepNak *string `json:"peltekkepnak" gorm:"column:peltekkepnak"` + PelTekKepMat *string `json:"peltekkepmat" gorm:"column:peltekkepmat"` + PelTekKepJiwa *string `json:"peltekkepjiwa" gorm:"column:peltekkepjiwa"` + TemKerTuj *string `json:"temkertuj" gorm:"column:temkertuj"` + TemKerTuj2 *string `json:"temkertuj2" gorm:"column:temkertuj2"` + TglMutasi *time.Time `json:"tglmutasi" gorm:"column:tglmutasi"` + Alasan *string `json:"alasan" gorm:"column:alasan"` + TglKeluar *time.Time `json:"tglkeluar" gorm:"column:tglkeluar"` + ProgPendidikan *uint `json:"progpendidikan" gorm:"column:progpendidikan"` + ProgPeng *string `json:"progpeng" gorm:"column:progpeng"` + JabLain *string `json:"jablain" gorm:"column:jablain"` + PPA uint `json:"ppa" gorm:"column:ppa"` + Aktif uint `json:"aktif" gorm:"column:aktif"` +} + +func (MPerawat) TableName() string { + return "m_perawat" +} diff --git a/internal/domain/sync-entities/doctor/entity.go b/internal/domain/sync-entities/doctor/entity.go new file mode 100644 index 00000000..6a112a01 --- /dev/null +++ b/internal/domain/sync-entities/doctor/entity.go @@ -0,0 +1,29 @@ +package doctor + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + erc "simrs-vx/internal/domain/references/common" + "time" +) + +type DoctorLink struct { + ecore.Main + Simx_Id uint `json:"simx_id" gorm:"unique"` + Simgos_Id uint `json:"simgos_id" gorm:"unique"` +} + +type DoctorSimxLog struct { + ecore.Main + Value *string `json:"value"` + Date *time.Time `json:"date"` + Status erc.ProcessStatusCode `json:"status"` + ErrMessage *string `json:"errMessage"` +} + +type DoctorSimgosLog struct { + ecore.Main + Value *string `json:"value"` + Date *time.Time `json:"date"` + Status erc.ProcessStatusCode `json:"status"` + ErrMessage *string `json:"errMessage"` +} diff --git a/internal/domain/sync-entities/nurse/entity.go b/internal/domain/sync-entities/nurse/entity.go new file mode 100644 index 00000000..fdf78d38 --- /dev/null +++ b/internal/domain/sync-entities/nurse/entity.go @@ -0,0 +1,29 @@ +package nurse + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + erc "simrs-vx/internal/domain/references/common" + "time" +) + +type NurseLink struct { + ecore.Main + Simx_Id uint `json:"simx_id" gorm:"unique"` + Simgos_Id uint `json:"simgos_id" gorm:"unique"` +} + +type NurseSimxLog struct { + ecore.Main + Value *string `json:"value"` + Date *time.Time `json:"date"` + Status erc.ProcessStatusCode `json:"status"` + ErrMessage *string `json:"errMessage"` +} + +type NurseSimgosLog struct { + ecore.Main + Value *string `json:"value"` + Date *time.Time `json:"date"` + Status erc.ProcessStatusCode `json:"status"` + ErrMessage *string `json:"errMessage"` +} diff --git a/internal/interface/migration/simgossync-entities.go b/internal/interface/migration/simgossync-entities.go index 2c479521..0480a1e1 100644 --- a/internal/interface/migration/simgossync-entities.go +++ b/internal/interface/migration/simgossync-entities.go @@ -3,9 +3,11 @@ package migration import ( /************** Source ***************/ division "simrs-vx/internal/domain/sync-entities/division" + doctor "simrs-vx/internal/domain/sync-entities/doctor" encounter "simrs-vx/internal/domain/sync-entities/encounter" installation "simrs-vx/internal/domain/sync-entities/installation" internalreference "simrs-vx/internal/domain/sync-entities/internal-reference" + nurse "simrs-vx/internal/domain/sync-entities/nurse" patient "simrs-vx/internal/domain/sync-entities/patient" soapi "simrs-vx/internal/domain/sync-entities/soapi" specialist "simrs-vx/internal/domain/sync-entities/specialist" @@ -42,5 +44,11 @@ func getSyncEntities() []any { &soapi.SoapiLink{}, &soapi.SoapiSimxLog{}, &soapi.SoapiSimgosLog{}, + &doctor.DoctorLink{}, + &doctor.DoctorSimxLog{}, + &doctor.DoctorSimgosLog{}, + &nurse.NurseLink{}, + &nurse.NurseSimxLog{}, + &nurse.NurseSimgosLog{}, } } From bd1d5bdde688c890d94d4375bbc2a40b81280aed Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Tue, 9 Dec 2025 15:50:17 +0700 Subject: [PATCH 24/39] feat/user: moved Registration to Registrator --- .../migrations/20251209084929.sql | 14 ++++++ cmd/main-migration/migrations/atlas.sum | 5 ++- .../{registration => registrator}/dto.go | 6 +-- .../{registration => registrator}/entity.go | 4 +- internal/domain/main-entities/user/dto.go | 44 ++++++++++++------- internal/interface/migration/main-entities.go | 4 +- .../main-use-case/authentication/helper.go | 11 +++++ .../{registration => registrator}/case.go | 18 ++++---- .../{registration => registrator}/helper.go | 6 +-- .../{registration => registrator}/lib.go | 32 +++++++------- .../middleware-runner.go | 14 +++--- .../middleware.go | 2 +- .../{registration => registrator}/tycovar.go | 10 ++--- internal/use-case/main-use-case/user/case.go | 4 +- 14 files changed, 105 insertions(+), 69 deletions(-) create mode 100644 cmd/main-migration/migrations/20251209084929.sql rename internal/domain/main-entities/{registration => registrator}/dto.go (92%) rename internal/domain/main-entities/{registration => registrator}/entity.go (93%) rename internal/use-case/main-use-case/{registration => registrator}/case.go (95%) rename internal/use-case/main-use-case/{registration => registrator}/helper.go (83%) rename internal/use-case/main-use-case/{registration => registrator}/lib.go (84%) rename internal/use-case/main-use-case/{registration => registrator}/middleware-runner.go (87%) rename internal/use-case/main-use-case/{registration => registrator}/middleware.go (91%) rename internal/use-case/main-use-case/{registration => registrator}/tycovar.go (75%) diff --git a/cmd/main-migration/migrations/20251209084929.sql b/cmd/main-migration/migrations/20251209084929.sql new file mode 100644 index 00000000..c67550ae --- /dev/null +++ b/cmd/main-migration/migrations/20251209084929.sql @@ -0,0 +1,14 @@ +-- Create "Registrator" table +CREATE TABLE "public"."Registrator" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Employee_Id" bigint NULL, + "Installation_Code" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Registrator_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Registrator_Installation" FOREIGN KEY ("Installation_Code") REFERENCES "public"."Installation" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Drop "Registration" table +DROP TABLE "public"."Registration"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index b828c76d..9c137d56 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:YJzcjq4dKD7GKlV0GJ88TOtZgg0JRDcVMlAe5ZYT9/U= +h1:B/ZKq0d90aqLf0EvQfND4cd8ZRHcmxfzKF2N1lpSeIs= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -157,4 +157,5 @@ h1:YJzcjq4dKD7GKlV0GJ88TOtZgg0JRDcVMlAe5ZYT9/U= 20251209025908.sql h1:p3kZA8kyEj+mQZSrdY3k2K1NojQzFJh/MlZJ0Oy6t/k= 20251209030538.sql h1:zltV6/Fu2zJW0/lVBl7MdnWuJcqNTUIRcqYYZ8Fi1wo= 20251209064304.sql h1:Mj6Zh+2b/4AkM1HjnJGjAs788kVN0UaL34jeaKQIjT0= -20251209070128.sql h1:rdqSlAmJS5XSc1w9dka3C53zwgibQwRIUqBcgmIPoTM= +20251209070128.sql h1:ip4wNCIF/UFQlNo6KpFG87/XA08aG3/Rf5zpxz3xioY= +20251209084929.sql h1:Z5higP1Ecq5UPWhrWZ5UCrxddMNqiJi8PbCNvGBE48A= diff --git a/internal/domain/main-entities/registration/dto.go b/internal/domain/main-entities/registrator/dto.go similarity index 92% rename from internal/domain/main-entities/registration/dto.go rename to internal/domain/main-entities/registrator/dto.go index ea842e95..5f0d4517 100644 --- a/internal/domain/main-entities/registration/dto.go +++ b/internal/domain/main-entities/registrator/dto.go @@ -1,4 +1,4 @@ -package doctor +package registrator import ( ecore "simrs-vx/internal/domain/base-entities/core" @@ -51,7 +51,7 @@ type ResponseDto struct { Installation *ei.Installation `json:"installation,omitempty"` } -func (d Registration) ToResponse() ResponseDto { +func (d Registrator) ToResponse() ResponseDto { resp := ResponseDto{ Employee_Id: d.Employee_Id, Employee: d.Employee, @@ -62,7 +62,7 @@ func (d Registration) ToResponse() ResponseDto { return resp } -func ToResponseList(data []Registration) []ResponseDto { +func ToResponseList(data []Registrator) []ResponseDto { resp := make([]ResponseDto, len(data)) for i, u := range data { resp[i] = u.ToResponse() diff --git a/internal/domain/main-entities/registration/entity.go b/internal/domain/main-entities/registrator/entity.go similarity index 93% rename from internal/domain/main-entities/registration/entity.go rename to internal/domain/main-entities/registrator/entity.go index 52d81f40..31998c1c 100644 --- a/internal/domain/main-entities/registration/entity.go +++ b/internal/domain/main-entities/registrator/entity.go @@ -1,4 +1,4 @@ -package doctor +package registrator import ( ecore "simrs-vx/internal/domain/base-entities/core" @@ -6,7 +6,7 @@ import ( ei "simrs-vx/internal/domain/main-entities/installation" ) -type Registration struct { +type Registrator struct { ecore.Main // adjust this according to the needs Employee_Id uint `json:"employee_id"` Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` diff --git a/internal/domain/main-entities/user/dto.go b/internal/domain/main-entities/user/dto.go index acd189a0..bb030df3 100644 --- a/internal/domain/main-entities/user/dto.go +++ b/internal/domain/main-entities/user/dto.go @@ -13,23 +13,24 @@ import ( ) type CreateDto struct { - Name string `json:"name" validate:"maxLength=25"` - Password string `json:"password" validate:"maxLength=255"` + Name string `json:"name" validate:"required;maxLength=50"` + Password string `json:"password" validate:"required;maxLength=255"` + ContractPosition_Code erg.ContractPositionCode `json:"contractPosition_code" gorm:"not null;size:20" validate:"required"` Status_Code erc.UserStatusCode `json:"status_code" validate:"maxLength=10"` - Person_Id *uint `json:"-"` - Person *ep.UpdateDto `json:"person"` - PersonAddresses []epa.UpdateDto `json:"personAddresses"` - PersonContacts []epc.UpdateDto `json:"personContacts"` - Code *string `json:"code" validate:"maxLength=20"` - Employee *EmployeUpdateDto `json:"employee"` - IHS_Number *string `json:"ihs_number" validate:"maxLength=20"` - SIP_Number *string `json:"sip_number" validate:"maxLength=20"` - Infra_Code *string `json:"infra_code"` - Installation_Code *string `json:"installation_code"` - Unit_Code *string `json:"unit_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"` + + Employee *EmployeUpdateDto `json:"employee"` + Person *ep.UpdateDto `json:"person"` + PersonAddresses []epa.UpdateDto `json:"personAddresses"` + PersonContacts []epc.UpdateDto `json:"personContacts"` + Person_Id *uint `json:"-"` + Code *string `json:"code" validate:"maxLength=20"` + IHS_Number *string `json:"ihs_number" validate:"maxLength=20"` + SIP_Number *string `json:"sip_number" validate:"maxLength=20"` + Installation_Code *string `json:"installation_code"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + Infra_Code *string `json:"infra_code"` } type ReadListDto struct { @@ -88,11 +89,20 @@ func (d *User) ToResponse() ResponseDto { type EmployeUpdateDto struct { Id uint `json:"id"` User_Id *uint `json:"-"` - Person_Id *uint `json:"-"` Division_Code *string `json:"division_code"` Number *string `json:"number" validate:"maxLength=20"` Position_Code erg.EmployeePositionCode `json:"position_code" validate:"maxLength=20"` Status_Code erc.ActiveStatusCode `json:"status_code" validate:"maxLength=10"` + Person_Id *uint `json:"-"` + // TODO: Extras + // Code *string `json:"code" validate:"maxLength=20"` + // IHS_Number *string `json:"ihs_number" validate:"maxLength=20"` + // SIP_Number *string `json:"sip_number" validate:"maxLength=20"` + // Installation_Code *string `json:"installation_code"` + // Unit_Code *string `json:"unit_code"` + // Specialist_Code *string `json:"specialist_code"` + // Subspecialist_Code *string `json:"subspecialist_code"` + // Infra_Code *string `json:"infra_code"` } func ToResponseList(data []User) []ResponseDto { diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 147419e5..af3b35d3 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -96,7 +96,7 @@ import ( radiologymcuorder "simrs-vx/internal/domain/main-entities/radiology-mcu-order" radiologymcuorderitem "simrs-vx/internal/domain/main-entities/radiology-mcu-order-item" regency "simrs-vx/internal/domain/main-entities/regency" - registration "simrs-vx/internal/domain/main-entities/registration" + registrator "simrs-vx/internal/domain/main-entities/registrator" rehab "simrs-vx/internal/domain/main-entities/rehab" responsibledoctorhist "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" resume "simrs-vx/internal/domain/main-entities/resume" @@ -149,7 +149,7 @@ func getMainEntities() []any { &proceduresrc.ProcedureSrc{}, &employee.Employee{}, &intern.Intern{}, - ®istration.Registration{}, + ®istrator.Registrator{}, &doctor.Doctor{}, &nurse.Nurse{}, &nutritionist.Nutritionist{}, diff --git a/internal/use-case/main-use-case/authentication/helper.go b/internal/use-case/main-use-case/authentication/helper.go index d8c54751..3a8154b6 100644 --- a/internal/use-case/main-use-case/authentication/helper.go +++ b/internal/use-case/main-use-case/authentication/helper.go @@ -26,6 +26,7 @@ import ( em "simrs-vx/internal/domain/main-entities/midwife" en "simrs-vx/internal/domain/main-entities/nurse" ep "simrs-vx/internal/domain/main-entities/pharmacist" + er "simrs-vx/internal/domain/main-entities/registrator" esp "simrs-vx/internal/domain/main-entities/specialist-position" essp "simrs-vx/internal/domain/main-entities/subspecialist-position" eup "simrs-vx/internal/domain/main-entities/unit-position" @@ -265,6 +266,16 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out } atClaims["pharmacist_code"] = empData.Code outputData["pharmacist_code"] = empData.Code + case erg.EPCReg: + empData := er.Registrator{} + dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData) + if empData.Id == 0 { + return d.FieldErrors{"authentication": d.FieldError{Code: "auth-noRegistrator", Message: pl.GenMessage("auth-noRegistrator")}} + } + atClaims["registrator_id"] = empData.Id + outputData["registrator_id"] = empData.Id + atClaims["installation_code"] = empData.Installation_Code + outputData["installation_code"] = empData.Installation_Code } errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: pl.GenMessage("auth-getData-failed")}} diff --git a/internal/use-case/main-use-case/registration/case.go b/internal/use-case/main-use-case/registrator/case.go similarity index 95% rename from internal/use-case/main-use-case/registration/case.go rename to internal/use-case/main-use-case/registrator/case.go index 06d48899..64313b97 100644 --- a/internal/use-case/main-use-case/registration/case.go +++ b/internal/use-case/main-use-case/registrator/case.go @@ -1,4 +1,4 @@ -package doctor +package registrator import ( "strconv" @@ -7,16 +7,16 @@ import ( d "github.com/karincake/dodol" "gorm.io/gorm" - e "simrs-vx/internal/domain/main-entities/registration" + e "simrs-vx/internal/domain/main-entities/registrator" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" ) -const source = "doctor" +const source = "registrator" func Create(input e.CreateDto) (*d.Data, error) { - data := e.Registration{} + data := e.Registrator{} event := pl.Event{ Feature: "Create", @@ -66,8 +66,8 @@ func Create(input e.CreateDto) (*d.Data, error) { } func ReadList(input e.ReadListDto) (*d.Data, error) { - var data *e.Registration - var dataList []e.Registration + var data *e.Registrator + var dataList []e.Registrator var metaList *e.MetaDto var err error @@ -119,7 +119,7 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { } func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { - var data *e.Registration + var data *e.Registrator var err error event := pl.Event{ @@ -167,7 +167,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { func Update(input e.UpdateDto) (*d.Data, error) { rdDto := e.ReadDetailDto{Id: input.Id} - var data *e.Registration + var data *e.Registrator var err error event := pl.Event{ @@ -223,7 +223,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { func Delete(input e.DeleteDto) (*d.Data, error) { rdDto := e.ReadDetailDto{Id: &input.Id} - var data *e.Registration + var data *e.Registrator var err error event := pl.Event{ diff --git a/internal/use-case/main-use-case/registration/helper.go b/internal/use-case/main-use-case/registrator/helper.go similarity index 83% rename from internal/use-case/main-use-case/registration/helper.go rename to internal/use-case/main-use-case/registrator/helper.go index 186e7f44..68482b0b 100644 --- a/internal/use-case/main-use-case/registration/helper.go +++ b/internal/use-case/main-use-case/registrator/helper.go @@ -2,13 +2,13 @@ DESCRIPTION: Any functions that are used internally by the use-case */ -package doctor +package registrator import ( - e "simrs-vx/internal/domain/main-entities/registration" + e "simrs-vx/internal/domain/main-entities/registrator" ) -func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Registration) { +func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Registrator) { var inputSrc *e.CreateDto if inputT, ok := any(input).(*e.CreateDto); ok { inputSrc = inputT diff --git a/internal/use-case/main-use-case/registration/lib.go b/internal/use-case/main-use-case/registrator/lib.go similarity index 84% rename from internal/use-case/main-use-case/registration/lib.go rename to internal/use-case/main-use-case/registrator/lib.go index 7d28bb9a..694f9441 100644 --- a/internal/use-case/main-use-case/registration/lib.go +++ b/internal/use-case/main-use-case/registrator/lib.go @@ -1,8 +1,8 @@ -package doctor +package registrator import ( "fmt" - e "simrs-vx/internal/domain/main-entities/registration" + e "simrs-vx/internal/domain/main-entities/registrator" plh "simrs-vx/pkg/lib-helper" pl "simrs-vx/pkg/logger" @@ -13,10 +13,10 @@ import ( "gorm.io/gorm" ) -func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Registration, error) { +func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Registrator, error) { pl.SetLogInfo(event, nil, "started", "DBCreate") - data := e.Registration{} + data := e.Registrator{} setData(&input, &data) var tx *gorm.DB @@ -34,9 +34,9 @@ func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Registr return &data, nil } -func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Registration, *e.MetaDto, error) { +func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Registrator, *e.MetaDto, error) { pl.SetLogInfo(event, input, "started", "DBReadList") - data := []e.Registration{} + data := []e.Registrator{} pagination := gh.Pagination{} count := int64(0) meta := e.MetaDto{} @@ -49,7 +49,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Re } tx = tx. - Model(&e.Registration{}). + Model(&e.Registrator{}). Scopes(gh.Preload(input.Includes)). Scopes(gh.Filter(input.FilterDto)). Count(&count). @@ -71,9 +71,9 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Re return data, &meta, nil } -func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e.Registration, error) { +func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e.Registrator, error) { pl.SetLogInfo(event, input, "started", "DBReadDetail") - data := e.Registration{} + data := e.Registrator{} var tx *gorm.DB if len(dbx) > 0 { @@ -99,7 +99,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e return &data, nil } -func UpdateData(input e.UpdateDto, data *e.Registration, event *pl.Event, dbx ...*gorm.DB) error { +func UpdateData(input e.UpdateDto, data *e.Registrator, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, data, "started", "DBUpdate") setData(&input, data) @@ -124,7 +124,7 @@ func UpdateData(input e.UpdateDto, data *e.Registration, event *pl.Event, dbx .. return nil } -func DeleteData(data *e.Registration, event *pl.Event, dbx ...*gorm.DB) error { +func DeleteData(data *e.Registrator, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, data, "started", "DBDelete") var tx *gorm.DB if len(dbx) > 0 { @@ -156,13 +156,13 @@ func GetIdByUserId(user_id *uint, event *pl.Event, dbx ...*gorm.DB) (*uint, erro tx = dg.I } - var doctor_id uint + var registrator_id uint - err := tx.Model(&e.Registration{}). - Select("\"Doctor\".\"Id\" as doctor_id"). + err := tx.Model(&e.Registrator{}). + Select("\"Doctor\".\"Id\" as registrator_id"). Joins("JOIN \"Employee\" as e ON e.\"Id\" = \"Doctor\".\"Employee_Id\""). Where("e.\"User_Id\" = ?", user_id). - Scan(&doctor_id).Error + Scan(®istrator_id).Error if err != nil { event.Status = "failed" @@ -175,5 +175,5 @@ func GetIdByUserId(user_id *uint, event *pl.Event, dbx ...*gorm.DB) (*uint, erro } pl.SetLogInfo(event, nil, "complete") - return &doctor_id, nil + return ®istrator_id, nil } diff --git a/internal/use-case/main-use-case/registration/middleware-runner.go b/internal/use-case/main-use-case/registrator/middleware-runner.go similarity index 87% rename from internal/use-case/main-use-case/registration/middleware-runner.go rename to internal/use-case/main-use-case/registrator/middleware-runner.go index d68f8de9..e0488ca7 100644 --- a/internal/use-case/main-use-case/registration/middleware-runner.go +++ b/internal/use-case/main-use-case/registrator/middleware-runner.go @@ -1,7 +1,7 @@ -package doctor +package registrator import ( - e "simrs-vx/internal/domain/main-entities/registration" + e "simrs-vx/internal/domain/main-entities/registrator" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" @@ -23,7 +23,7 @@ func newMiddlewareRunner(event *pl.Event, tx *gorm.DB) *middlewareRunner { } // ExecuteCreateMiddleware executes create middleware -func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.Registration) error { +func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.Registrator) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -38,7 +38,7 @@ func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e return nil } -func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.Registration) error { +func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.Registrator) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -53,7 +53,7 @@ func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, inpu return nil } -func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Registration) error { +func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Registrator) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -68,7 +68,7 @@ func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, return nil } -func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Registration) error { +func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Registrator) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) @@ -83,7 +83,7 @@ func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, inpu return nil } -func (me *middlewareRunner) RunDeleteMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Registration) error { +func (me *middlewareRunner) RunDeleteMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Registrator) error { for _, middleware := range middlewares { logData := pu.GetLogData(input, data) diff --git a/internal/use-case/main-use-case/registration/middleware.go b/internal/use-case/main-use-case/registrator/middleware.go similarity index 91% rename from internal/use-case/main-use-case/registration/middleware.go rename to internal/use-case/main-use-case/registrator/middleware.go index b6bfc120..c47ed8e0 100644 --- a/internal/use-case/main-use-case/registration/middleware.go +++ b/internal/use-case/main-use-case/registrator/middleware.go @@ -1,4 +1,4 @@ -package doctor +package registrator // example of middleware // func init() { diff --git a/internal/use-case/main-use-case/registration/tycovar.go b/internal/use-case/main-use-case/registrator/tycovar.go similarity index 75% rename from internal/use-case/main-use-case/registration/tycovar.go rename to internal/use-case/main-use-case/registrator/tycovar.go index bda8f4f8..565e186f 100644 --- a/internal/use-case/main-use-case/registration/tycovar.go +++ b/internal/use-case/main-use-case/registrator/tycovar.go @@ -6,27 +6,27 @@ 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 doctor +package registrator import ( "gorm.io/gorm" - e "simrs-vx/internal/domain/main-entities/registration" + e "simrs-vx/internal/domain/main-entities/registrator" ) type createMw struct { Name string - Func func(input *e.CreateDto, data *e.Registration, tx *gorm.DB) error + Func func(input *e.CreateDto, data *e.Registrator, tx *gorm.DB) error } type readListMw struct { Name string - Func func(input *e.ReadListDto, data *e.Registration, tx *gorm.DB) error + Func func(input *e.ReadListDto, data *e.Registrator, tx *gorm.DB) error } type readDetailMw struct { Name string - Func func(input *e.ReadDetailDto, data *e.Registration, tx *gorm.DB) error + Func func(input *e.ReadDetailDto, data *e.Registrator, tx *gorm.DB) error } type UpdateMw = readDetailMw diff --git a/internal/use-case/main-use-case/user/case.go b/internal/use-case/main-use-case/user/case.go index f360336a..1ea8c6ea 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -13,7 +13,7 @@ import ( en "simrs-vx/internal/domain/main-entities/nurse" et "simrs-vx/internal/domain/main-entities/nutritionist" ep "simrs-vx/internal/domain/main-entities/pharmacist" - er "simrs-vx/internal/domain/main-entities/registration" + er "simrs-vx/internal/domain/main-entities/registrator" esi "simrs-vx/internal/domain/main-entities/specialist-intern" e "simrs-vx/internal/domain/main-entities/user" @@ -27,7 +27,7 @@ import ( upa "simrs-vx/internal/use-case/main-use-case/person-address" upc "simrs-vx/internal/use-case/main-use-case/person-contact" up "simrs-vx/internal/use-case/main-use-case/pharmacist" - ur "simrs-vx/internal/use-case/main-use-case/registration" + ur "simrs-vx/internal/use-case/main-use-case/registrator" usi "simrs-vx/internal/use-case/main-use-case/specialist-intern" erc "simrs-vx/internal/domain/references/common" From 4bbde1867a4b43cdc60b535760e3d2664da48430 Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 9 Dec 2025 19:20:58 +0700 Subject: [PATCH 25/39] add seeder --- .../domain/simgos-entities/m-login/entity.go | 22 ++ .../simgos-entities/m-pegawai/entity.go | 38 ++++ internal/interface/migration/migration.go | 1 - .../seeder/doctor/handler.go | 18 ++ .../simgos-sync-handler.go | 8 + .../simgos-sync-use-case/new/doctor/case.go | 194 ++++++++++++++++++ .../simgos-sync-use-case/new/doctor/helper.go | 54 +++++ .../simgos-sync-use-case/new/doctor/lib.go | 186 +++++++++++++++++ .../seeder/doctor/seeder.go | 136 ++++++++++++ 9 files changed, 656 insertions(+), 1 deletion(-) create mode 100644 internal/domain/simgos-entities/m-login/entity.go create mode 100644 internal/domain/simgos-entities/m-pegawai/entity.go create mode 100644 internal/interface/simgos-sync-handler/seeder/doctor/handler.go create mode 100644 internal/use-case/simgos-sync-use-case/new/doctor/case.go create mode 100644 internal/use-case/simgos-sync-use-case/new/doctor/helper.go create mode 100644 internal/use-case/simgos-sync-use-case/new/doctor/lib.go create mode 100644 internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go diff --git a/internal/domain/simgos-entities/m-login/entity.go b/internal/domain/simgos-entities/m-login/entity.go new file mode 100644 index 00000000..a2967d1d --- /dev/null +++ b/internal/domain/simgos-entities/m-login/entity.go @@ -0,0 +1,22 @@ +package m_login + +type MLogin struct { + NIP string `gorm:"column:nip;primaryKey"` + Password string `gorm:"column:pwd"` + SesReg string `gorm:"column:ses_reg"` + KdPerawat uint `gorm:"column:kdperawat"` + KdDokter uint `gorm:"column:kddokter"` + NamaPegawai string `gorm:"column:nama_pegawai"` + Roles int `gorm:"column:roles"` + KdUnit uint `gorm:"column:kdunit"` + Departemen string `gorm:"column:departemen"` + StDokterRajalEksekutif *uint16 `gorm:"column:st_dokter_rajal_eksekutif"` + StDokterRajalReguler *uint16 `gorm:"column:st_dokter_rajal_reguler"` + StDokterRajalEmergency *uint16 `gorm:"column:st_dokter_rajal_emergency"` + NIPB *string `gorm:"column:nipb"` + Aktif uint16 `gorm:"column:aktif"` +} + +func (MLogin) TableName() string { + return "m_login" +} diff --git a/internal/domain/simgos-entities/m-pegawai/entity.go b/internal/domain/simgos-entities/m-pegawai/entity.go new file mode 100644 index 00000000..24552b6c --- /dev/null +++ b/internal/domain/simgos-entities/m-pegawai/entity.go @@ -0,0 +1,38 @@ +package m_pegawai + +import "time" + +type MPegawai struct { + NoPeg uint `gorm:"column:no_peg;primaryKey"` + NamaPeg string `gorm:"column:nama_peg"` + NIPB string `gorm:"column:nipb"` + Gol string `gorm:"column:gol"` + SatuanKerja string `gorm:"column:satuan_kerja"` + Ruang string `gorm:"column:ruang"` + Pendidikan string `gorm:"column:pendidikan"` + Tenaga string `gorm:"column:tenaga"` + Tenaga1 string `gorm:"column:tenaga1"` + Tenaga2 string `gorm:"column:tenaga2"` + TMTMasuk *time.Time `gorm:"column:tmt_masuk"` + TempatLahir string `gorm:"column:tmp_lahir"` + TanggalLahir *time.Time `gorm:"column:tgl_lahir"` + Alamat string `gorm:"column:alamat"` + Telepon string `gorm:"column:telepon"` + HP string `gorm:"column:hp"` + Karpeg string `gorm:"column:karpeg"` + Kelamin string `gorm:"column:kelamin"` + Agama string `gorm:"column:agama"` + StatusTubel uint16 `gorm:"column:status_tubel"` // smallint → bool + NIK string `gorm:"column:nik"` + Seksi string `gorm:"column:seksi"` + TMTAwalSIP *time.Time `gorm:"column:tmt_awal_sip"` + TMTAkhirSIPStr *time.Time `gorm:"column:tmt_akhir_sip_str"` + NoSIP string `gorm:"column:no_sip"` + NoSTR string `gorm:"column:no_str"` + LoginID string `gorm:"column:login_id"` + CodeKasir string `gorm:"column:code_kasir"` +} + +func (MPegawai) TableName() string { + return "m_pegawai" +} diff --git a/internal/interface/migration/migration.go b/internal/interface/migration/migration.go index 15341164..78a3987f 100644 --- a/internal/interface/migration/migration.go +++ b/internal/interface/migration/migration.go @@ -39,5 +39,4 @@ func getEntities(input string) []any { func Migrate(input string) { loader(input) - } diff --git a/internal/interface/simgos-sync-handler/seeder/doctor/handler.go b/internal/interface/simgos-sync-handler/seeder/doctor/handler.go new file mode 100644 index 00000000..38c11cc4 --- /dev/null +++ b/internal/interface/simgos-sync-handler/seeder/doctor/handler.go @@ -0,0 +1,18 @@ +package doctor + +import ( + "net/http" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/doctor" + + rw "github.com/karincake/risoles" +) + +type myBase struct{} + +var O myBase + +func (obj myBase) Seeder(w http.ResponseWriter, r *http.Request) { + + err := doctor.SeedDoctor() + rw.DataResponse(w, nil, err) +} diff --git a/internal/interface/simgos-sync-handler/simgos-sync-handler.go b/internal/interface/simgos-sync-handler/simgos-sync-handler.go index a47b38d4..f4837d70 100644 --- a/internal/interface/simgos-sync-handler/simgos-sync-handler.go +++ b/internal/interface/simgos-sync-handler/simgos-sync-handler.go @@ -30,6 +30,8 @@ import ( "simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist" "simrs-vx/internal/interface/simgos-sync-handler/new/unit" + ds "simrs-vx/internal/interface/simgos-sync-handler/seeder/doctor" + oldpatient "simrs-vx/internal/interface/simgos-sync-handler/old/patient" oauth "simrs-vx/internal/interface/simgos-sync-handler/old/authentication" // just a reminder, an openauth @@ -76,6 +78,12 @@ func SetRoutes() http.Handler { }) hc.SyncCrud(r, prefixnew+"/v1/soapi", soapi.O) + /******************** SvcToNew ******************/ + prefixseeder := "/new-seeder" + hk.GroupRoutes(prefixseeder+"/v1", r, hk.MapHandlerFunc{ + "POST /doctor": ds.O.Seeder, + }) + /******************** SvcToNew ******************/ prefixold := "/old-to-new" hk.GroupRoutes(prefixold+"/v1/patient", r, oauth.OldGuardMW, hk.MapHandlerFunc{ diff --git a/internal/use-case/simgos-sync-use-case/new/doctor/case.go b/internal/use-case/simgos-sync-use-case/new/doctor/case.go new file mode 100644 index 00000000..75ac9f4a --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/new/doctor/case.go @@ -0,0 +1,194 @@ +package doctor + +import ( + pl "simrs-vx/pkg/logger" + + d "github.com/karincake/dodol" + "gorm.io/gorm" + + db "simrs-vx/pkg/dualtrx-helper" + + elog "simrs-vx/internal/domain/sync-entities/log" +) + +const source = "division" + +//func Create(input e.CreateDto) (*d.Data, error) { +// var ( +// sgData *esimgos.MUnit +// syncLink *esync.DivisionLink +// err error +// ) +// +// event := pl.Event{ +// Feature: "Create", +// Source: source, +// } +// +// // Start log +// pl.SetLogInfo(&event, input, "started", "create") +// +// err = db.WithDualTx(func(tx *db.Dualtx) error { +// // STEP 1: Insert to simgos +// sgData, err = CreateSimgosData(input, &event, tx.Simgos) +// if err != nil { +// return err +// } +// +// // STEP 2: Insert to Link +// syncLink, err = CreateLinkData(*input.Id, sgData.KodeUnit, &event, tx.Sync) +// if err != nil { +// return err +// } +// +// return nil +// }) +// +// if err != nil { +// if syncLink != nil { +// go func() { _ = DeleteLinkData(syncLink, &event) }() +// } +// return nil, err +// } +// +// pl.SetLogInfo(&event, nil, "complete") +// +// return &d.Data{ +// Meta: d.II{ +// "source": source, +// "structure": "single-data", +// "status": "created", +// }, +// }, nil +//} + +func CreateSimxLog(input elog.SimxLogDto) (*d.Data, error) { + event := pl.Event{ + Feature: "Create", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "create") + + tx := db.NewTx() + err := tx.Sync.Transaction(func(tx *gorm.DB) error { + // Insert to Log + if err := CreateLogData(input, &event, tx); err != nil { + return err + } + + return nil + }) + + if err != nil { + return nil, err + } + + pl.SetLogInfo(&event, nil, "complete") + + return &d.Data{ + Meta: d.II{ + "source": source, + "structure": "single-data", + "status": "created", + }, + }, nil +} + +//func Update(input e.UpdateDto) (*d.Data, error) { +// event := pl.Event{ +// Feature: "Update", +// Source: source, +// } +// +// // Start log +// pl.SetLogInfo(&event, input, "started", "update") +// +// // STEP 1: Get Link +// syncLink, err := ReadDetailLinkData(*input.Id, &event) +// if err != nil { +// return nil, err +// } +// +// tx := db.NewTx() +// err = tx.Simgos.Transaction(func(tx *gorm.DB) error { +// // Step 2: Update Simgos +// if err = UpdateSimgosData(input, syncLink, &event, tx); err != nil { +// return err +// } +// +// return nil +// }) +// +// pl.SetLogInfo(&event, nil, "complete") +// +// return &d.Data{ +// Meta: d.IS{ +// "source": source, +// "structure": "single-data", +// "status": "updated", +// }, +// }, nil +//} + +//func Delete(input e.DeleteDto) (*d.Data, error) { +// var isLinkDeleted bool +// +// event := pl.Event{ +// Feature: "Delete", +// Source: source, +// } +// +// // Start log +// pl.SetLogInfo(&event, input, "started", "delete") +// +// // STEP 1: Get Link +// syncLink, err := ReadDetailLinkData(*input.Id, &event) +// if err != nil { +// return nil, err +// } +// +// // STEP 2: Get Simgos +// sgData, err := ReadDetailSimgosData(uint16(syncLink.Simgos_Id), &event) +// if err != nil { +// return nil, err +// } +// +// err = db.WithDualTx(func(tx *db.Dualtx) error { +// // STEP 3: Delete Simgos +// err = HardDeleteSimgosData(sgData, &event, tx.Simgos) +// if err != nil { +// return err +// } +// +// // STEP 4: Delete Link +// err = DeleteLinkData(syncLink, &event, tx.Sync) +// if err != nil { +// return err +// } +// +// isLinkDeleted = true +// return nil +// }) +// +// if err != nil { +// if isLinkDeleted { +// go func() { +// _, _ = CreateLinkData(uint(*input.Id), sgData.KodeUnit, &event) +// }() +// } +// return nil, err +// } +// +// pl.SetLogInfo(&event, nil, "complete") +// +// return &d.Data{ +// Meta: d.IS{ +// "source": source, +// "structure": "single-data", +// "status": "deleted", +// }, +// }, nil +// +//} diff --git a/internal/use-case/simgos-sync-use-case/new/doctor/helper.go b/internal/use-case/simgos-sync-use-case/new/doctor/helper.go new file mode 100644 index 00000000..71fa4cfc --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/new/doctor/helper.go @@ -0,0 +1,54 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package doctor + +import ( + "encoding/json" + erc "simrs-vx/internal/domain/references/common" + + esync "simrs-vx/internal/domain/sync-entities/doctor" + esyncLog "simrs-vx/internal/domain/sync-entities/log" +) + +//func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T) (data esimgos.MDokter) { +// var inputSrc *e.CreateDto +// if inputT, ok := any(input).(*e.CreateDto); ok { +// inputSrc = inputT +// } else { +// inputTemp := any(input).(*e.UpdateDto) +// inputSrc = &inputTemp.CreateDto +// } +// +// data.NamaUnit = inputSrc.Name +// return +//} + +func setDataSimxLog(input *esyncLog.SimxLogDto) (data esync.DoctorSimxLog) { + // encode to JSON + jsonData, _ := json.MarshalIndent(input.Payload, "", " ") + jsonString := string(jsonData) + + var status erc.ProcessStatusCode + if input.IsSuccess { + status = erc.PSCSuccess + } else { + status = erc.PSCFailed + if input.ErrMessage != nil { + data.ErrMessage = input.ErrMessage + } + } + + data.Value = &jsonString + data.Date = &now + data.Status = status + + return +} + +func setDataSimxLink(simxId, simgosId uint) (data esync.DoctorLink) { + data.Simx_Id = simxId + data.Simgos_Id = simgosId + return +} diff --git a/internal/use-case/simgos-sync-use-case/new/doctor/lib.go b/internal/use-case/simgos-sync-use-case/new/doctor/lib.go new file mode 100644 index 00000000..b9b6e7cf --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/new/doctor/lib.go @@ -0,0 +1,186 @@ +package doctor + +import ( + plh "simrs-vx/pkg/lib-helper" + pl "simrs-vx/pkg/logger" + pu "simrs-vx/pkg/use-case-helper" + "time" + + dg "github.com/karincake/apem/db-gorm-pg" + "gorm.io/gorm" + + esync "simrs-vx/internal/domain/sync-entities/doctor" + esynclog "simrs-vx/internal/domain/sync-entities/log" +) + +var now = time.Now() + +//func CreateSimgosData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*esimgos.MDokter, error) { +// pl.SetLogInfo(event, nil, "started", "DBCreate") +// +// data := setDataSimgos(&input) +// +// var tx *gorm.DB +// if len(dbx) > 0 { +// tx = dbx[0] +// } else { +// tx = dg.IS["simrs"] +// } +// +// if err := tx.Create(&data).Error; err != nil { +// return nil, plh.HandleCreateError(input, event, err) +// } +// +// pl.SetLogInfo(event, nil, "complete") +// return &data, nil +//} + +//func ReadDetailSimgosData(simgosId uint16, event *pl.Event) (*esimgos.MUnit, error) { +// pl.SetLogInfo(event, simgosId, "started", "DBReadDetail") +// data := esimgos.MUnit{} +// +// var tx = dg.IS["simrs"] +// +// if err := tx. +// Where("\"kode_unit\" = ?", simgosId). +// First(&data).Error; err != nil { +// if processedErr := pu.HandleReadError(err, event, source, simgosId, data); processedErr != nil { +// return nil, processedErr +// } +// } +// +// pl.SetLogInfo(event, nil, "complete") +// return &data, nil +//} + +//func UpdateSimgosData(input e.UpdateDto, dataSimgos *esync.DivisionLink, event *pl.Event, dbx ...*gorm.DB) error { +// pl.SetLogInfo(event, input, "started", "DBUpdate") +// +// data := setDataSimgos(&input) +// data.KodeUnit = dataSimgos.Simgos_Id +// +// var tx *gorm.DB +// if len(dbx) > 0 { +// tx = dbx[0] +// } else { +// tx = dg.IS["simrs"] +// } +// +// 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 HardDeleteSimgosData(data *esimgos.MUnit, 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.IS["simrs"] +// } +// +// 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 +//} + +func CreateLinkData(simxId, simgosId uint, event *pl.Event, dbx ...*gorm.DB) (*esync.DoctorLink, error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + data := setDataSimxLink(simxId, simgosId) + + 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(data, event, err) + } + + pl.SetLogInfo(event, nil, "complete") + return &data, nil +} + +func ReadDetailLinkData(simxId uint16, event *pl.Event) (*esync.DoctorLink, error) { + pl.SetLogInfo(event, simxId, "started", "DBReadDetail") + data := esync.DoctorLink{} + + var tx = dg.I + + if err := tx. + Where("\"Simx_Id\" = ?", simxId). + First(&data).Error; err != nil { + if processedErr := pu.HandleReadError(err, event, source, simxId, data); processedErr != nil { + return nil, processedErr + } + } + + pl.SetLogInfo(event, nil, "complete") + return &data, nil +} + +func DeleteLinkData(data *esync.DoctorLink, 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 +} + +func CreateLogData(input esynclog.SimxLogDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, nil, "started", "DBCreate") + data := setDataSimxLog(&input) + + 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 +} diff --git a/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go new file mode 100644 index 00000000..e993b27b --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go @@ -0,0 +1,136 @@ +package doctor + +import ( + "bytes" + "encoding/json" + "io" + "net/http" + cfg "simrs-vx/internal/infra/sync-cfg" + pl "simrs-vx/pkg/logger" + "strconv" + + db "simrs-vx/pkg/dualtrx-helper" + + erg "simrs-vx/internal/domain/references/organization" + + ed "simrs-vx/internal/domain/simgos-entities/m-dokter" + el "simrs-vx/internal/domain/simgos-entities/m-login" + ep "simrs-vx/internal/domain/simgos-entities/m-pegawai" + + epr "simrs-vx/internal/domain/main-entities/person" + es "simrs-vx/internal/domain/main-entities/user" + + ud "simrs-vx/internal/use-case/simgos-sync-use-case/new/doctor" +) + +type User struct { + Doctor ed.MDokter `gorm:"embedded"` + Employee ep.MPegawai `gorm:"embedded"` + Login el.MLogin `gorm:"embedded"` +} + +var path = "user" + +func SeedDoctor() error { + tx := db.NewTx() + var users []User + + err := tx.Simgos.Table("m_dokter"). + Select(` + m_dokter.*, + l.*, + p.* + `). + Joins(`LEFT JOIN m_login l ON l.kddokter = m_dokter.kddokter`). + Joins(`LEFT JOIN m_pegawai p ON p.no_peg = m_dokter.kddokter`). + Where(`m_dokter.aktif = ?`, 1). + Order(`m_dokter.kddokter DESC`). + Limit(10). + Scan(&users).Error + + if err != nil { + return err + } + + // mapping + doctorsimx := []es.CreateDto{} + for i, d := range users { + kddokter := strconv.Itoa(int(d.Doctor.Kddokter)) + doctorsimx = append(doctorsimx, es.CreateDto{ + Name: d.Login.NIP, + Password: "1234", + ContractPosition_Code: erg.CSCEmp, + Code: &kddokter, + Person: &epr.UpdateDto{ + CreateDto: epr.CreateDto{ + Name: d.Employee.NamaPeg, + BirthPlace: &d.Employee.TempatLahir, + }, + }, + Employee: &es.EmployeUpdateDto{ + Position_Code: erg.EPCDoc, + }, + }) + + // create request body + jsonUser, err := json.Marshal(doctorsimx[i]) + if err != nil { + return err + } + + reqBody := bytes.NewBuffer(jsonUser) + // send data to main-api + resp, err := send(http.MethodPost, path, reqBody, "von") + if err != nil { + return err + } + + type MetaData struct { + Source string `json:"source"` + Status string `json:"status"` + Structure string `json:"structure"` + } + + type MainApiResp struct { + Meta MetaData `json:"meta"` + Data es.User `json:"data"` + } + + // getting response + var data MainApiResp + err = json.Unmarshal(resp, &data) + if err != nil { + return err + } + + if _, err := ud.CreateLinkData(data.Data.Id, d.Doctor.Kddokter, &pl.Event{}); err != nil { + return err + } + } + + return nil + +} + +func send(method string, endpoint string, body *bytes.Buffer, username string) ([]byte, error) { + var url string = cfg.O.NewHost + "/v1" + endpoint + var reader io.Reader = nil + if body != nil { + reader = body + } + req, err := http.NewRequest(method, url, reader) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-Sync-Source", cfg.O.OldSource) + req.Header.Set("X-Sync-SecretKey", cfg.O.NewSecretKey) + req.Header.Set("X-Sync-UserName", username) + resp, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + respBody, _ := io.ReadAll(resp.Body) + return respBody, nil +} From aced63686fe5ef5065d2244700c0c7a30349cd4e Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Wed, 10 Dec 2025 06:29:49 +0700 Subject: [PATCH 26/39] feat/dockerize: finsihed --- Dockerfile-main-api | 1 + Dockerfile-simgos-sync-api | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 Dockerfile-simgos-sync-api diff --git a/Dockerfile-main-api b/Dockerfile-main-api index 821cd4a2..0c75acfa 100644 --- a/Dockerfile-main-api +++ b/Dockerfile-main-api @@ -9,4 +9,5 @@ FROM alpine:latest WORKDIR /app COPY --from=builder /src/cmd/main-api/main-api . COPY --from=builder /src/cmd/main-api/config.yml . +EXPOSE 8000 CMD ["./main-api"] diff --git a/Dockerfile-simgos-sync-api b/Dockerfile-simgos-sync-api new file mode 100644 index 00000000..35660a2f --- /dev/null +++ b/Dockerfile-simgos-sync-api @@ -0,0 +1,13 @@ +FROM golang:1.24.10 AS builder +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -o ./cmd/simgos-sync-api/simgos-sync-api ./cmd/simgos-sync-api/main.go + +FROM alpine:latest +WORKDIR /app +COPY --from=builder /src/cmd/simgos-sync-api/simgos-sync-api . +COPY --from=builder /src/cmd/simgos-sync-api/config.yml . +EXPOSE 8000 +CMD ["./simgos-sync-api"] From c8fc0d7e61cad3b29a48a72688167e0b36a2e32b Mon Sep 17 00:00:00 2001 From: vanilia Date: Wed, 10 Dec 2025 12:14:48 +0700 Subject: [PATCH 27/39] on going --- cmd/main-migration/migrations/atlas.sum | 9 +- cmd/simgos-sync-api/main.go | 4 +- .../{m_perawat => m-perawat}/entity.go | 0 .../seeder/nurse/handler.go | 18 ++ .../simgos-sync-handler.go | 6 +- .../simgos-sync-use-case/new/nurse/case.go | 194 ++++++++++++++++++ .../simgos-sync-use-case/new/nurse/helper.go | 54 +++++ .../simgos-sync-use-case/new/nurse/lib.go | 186 +++++++++++++++++ .../seeder/doctor/seeder.go | 122 +++++------ .../simgos-sync-use-case/seeder/helper.go | 86 ++++++++ .../seeder/nurse/seeder.go | 164 +++++++++++++++ 11 files changed, 776 insertions(+), 67 deletions(-) rename internal/domain/simgos-entities/{m_perawat => m-perawat}/entity.go (100%) create mode 100644 internal/interface/simgos-sync-handler/seeder/nurse/handler.go create mode 100644 internal/use-case/simgos-sync-use-case/new/nurse/case.go create mode 100644 internal/use-case/simgos-sync-use-case/new/nurse/helper.go create mode 100644 internal/use-case/simgos-sync-use-case/new/nurse/lib.go create mode 100644 internal/use-case/simgos-sync-use-case/seeder/helper.go create mode 100644 internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 9c137d56..2e221903 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:B/ZKq0d90aqLf0EvQfND4cd8ZRHcmxfzKF2N1lpSeIs= +h1:EHAhH6MGySJoRcgSvt6ywIwf2q43rG18Z8fwEpuukdM= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -156,6 +156,7 @@ h1:B/ZKq0d90aqLf0EvQfND4cd8ZRHcmxfzKF2N1lpSeIs= 20251209022744.sql h1:y5/PAiZH/fYCpDJpkQdNRJwWICHH2iNIwM1V+S1P6KA= 20251209025908.sql h1:p3kZA8kyEj+mQZSrdY3k2K1NojQzFJh/MlZJ0Oy6t/k= 20251209030538.sql h1:zltV6/Fu2zJW0/lVBl7MdnWuJcqNTUIRcqYYZ8Fi1wo= -20251209064304.sql h1:Mj6Zh+2b/4AkM1HjnJGjAs788kVN0UaL34jeaKQIjT0= -20251209070128.sql h1:ip4wNCIF/UFQlNo6KpFG87/XA08aG3/Rf5zpxz3xioY= -20251209084929.sql h1:Z5higP1Ecq5UPWhrWZ5UCrxddMNqiJi8PbCNvGBE48A= +20251209051742.sql h1:BBNSmWfkamWrcKdxWjPiBS9yJ8yyQQUQIj3kip53nuE= +20251209064304.sql h1:Xs73yQbuJvuQ0OnW1FAZpeytmUl/bGTlJFrwGOsTF4w= +20251209070128.sql h1:fPGE6xOV6uCiVOqnvwn2L/GsBbgp2wxgmZOhF3bSGGM= +20251209084929.sql h1:u4LPMvkGAH4RfGC2IlBTIm7T7paMHoBSvTQ0w5Br7d0= diff --git a/cmd/simgos-sync-api/main.go b/cmd/simgos-sync-api/main.go index ddb3897d..fd201356 100644 --- a/cmd/simgos-sync-api/main.go +++ b/cmd/simgos-sync-api/main.go @@ -1,10 +1,10 @@ package main import ( - a "github.com/karincake/apem" - h "simrs-vx/internal/interface/simgos-sync-handler" + a "github.com/karincake/apem" + d "github.com/karincake/apem/db-gorm-pg" l "github.com/karincake/apem/logger-zerolog" diff --git a/internal/domain/simgos-entities/m_perawat/entity.go b/internal/domain/simgos-entities/m-perawat/entity.go similarity index 100% rename from internal/domain/simgos-entities/m_perawat/entity.go rename to internal/domain/simgos-entities/m-perawat/entity.go diff --git a/internal/interface/simgos-sync-handler/seeder/nurse/handler.go b/internal/interface/simgos-sync-handler/seeder/nurse/handler.go new file mode 100644 index 00000000..93d58045 --- /dev/null +++ b/internal/interface/simgos-sync-handler/seeder/nurse/handler.go @@ -0,0 +1,18 @@ +package nurse + +import ( + "net/http" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/nurse" + + rw "github.com/karincake/risoles" +) + +type myBase struct{} + +var O myBase + +func (obj myBase) Seeder(w http.ResponseWriter, r *http.Request) { + + err := nurse.SeedNurse() + rw.DataResponse(w, nil, err) +} diff --git a/internal/interface/simgos-sync-handler/simgos-sync-handler.go b/internal/interface/simgos-sync-handler/simgos-sync-handler.go index f4837d70..e7a6c597 100644 --- a/internal/interface/simgos-sync-handler/simgos-sync-handler.go +++ b/internal/interface/simgos-sync-handler/simgos-sync-handler.go @@ -30,7 +30,8 @@ import ( "simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist" "simrs-vx/internal/interface/simgos-sync-handler/new/unit" - ds "simrs-vx/internal/interface/simgos-sync-handler/seeder/doctor" + sd "simrs-vx/internal/interface/simgos-sync-handler/seeder/doctor" + sn "simrs-vx/internal/interface/simgos-sync-handler/seeder/nurse" oldpatient "simrs-vx/internal/interface/simgos-sync-handler/old/patient" @@ -81,7 +82,8 @@ func SetRoutes() http.Handler { /******************** SvcToNew ******************/ prefixseeder := "/new-seeder" hk.GroupRoutes(prefixseeder+"/v1", r, hk.MapHandlerFunc{ - "POST /doctor": ds.O.Seeder, + "POST /doctor": sd.O.Seeder, + "POST /nurse": sn.O.Seeder, }) /******************** SvcToNew ******************/ diff --git a/internal/use-case/simgos-sync-use-case/new/nurse/case.go b/internal/use-case/simgos-sync-use-case/new/nurse/case.go new file mode 100644 index 00000000..de34b9b9 --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/new/nurse/case.go @@ -0,0 +1,194 @@ +package nurse + +import ( + pl "simrs-vx/pkg/logger" + + d "github.com/karincake/dodol" + "gorm.io/gorm" + + db "simrs-vx/pkg/dualtrx-helper" + + elog "simrs-vx/internal/domain/sync-entities/log" +) + +const source = "patient" + +//func Create(input e.CreateDto) (*d.Data, error) { +// var ( +// sgData *esimgos.MUnit +// syncLink *esync.DivisionLink +// err error +// ) +// +// event := pl.Event{ +// Feature: "Create", +// Source: source, +// } +// +// // Start log +// pl.SetLogInfo(&event, input, "started", "create") +// +// err = db.WithDualTx(func(tx *db.Dualtx) error { +// // STEP 1: Insert to simgos +// sgData, err = CreateSimgosData(input, &event, tx.Simgos) +// if err != nil { +// return err +// } +// +// // STEP 2: Insert to Link +// syncLink, err = CreateLinkData(*input.Id, sgData.KodeUnit, &event, tx.Sync) +// if err != nil { +// return err +// } +// +// return nil +// }) +// +// if err != nil { +// if syncLink != nil { +// go func() { _ = DeleteLinkData(syncLink, &event) }() +// } +// return nil, err +// } +// +// pl.SetLogInfo(&event, nil, "complete") +// +// return &d.Data{ +// Meta: d.II{ +// "source": source, +// "structure": "single-data", +// "status": "created", +// }, +// }, nil +//} + +func CreateSimxLog(input elog.SimxLogDto) (*d.Data, error) { + event := pl.Event{ + Feature: "Create", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "create") + + tx := db.NewTx() + err := tx.Sync.Transaction(func(tx *gorm.DB) error { + // Insert to Log + if err := CreateLogData(input, &event, tx); err != nil { + return err + } + + return nil + }) + + if err != nil { + return nil, err + } + + pl.SetLogInfo(&event, nil, "complete") + + return &d.Data{ + Meta: d.II{ + "source": source, + "structure": "single-data", + "status": "created", + }, + }, nil +} + +//func Update(input e.UpdateDto) (*d.Data, error) { +// event := pl.Event{ +// Feature: "Update", +// Source: source, +// } +// +// // Start log +// pl.SetLogInfo(&event, input, "started", "update") +// +// // STEP 1: Get Link +// syncLink, err := ReadDetailLinkData(*input.Id, &event) +// if err != nil { +// return nil, err +// } +// +// tx := db.NewTx() +// err = tx.Simgos.Transaction(func(tx *gorm.DB) error { +// // Step 2: Update Simgos +// if err = UpdateSimgosData(input, syncLink, &event, tx); err != nil { +// return err +// } +// +// return nil +// }) +// +// pl.SetLogInfo(&event, nil, "complete") +// +// return &d.Data{ +// Meta: d.IS{ +// "source": source, +// "structure": "single-data", +// "status": "updated", +// }, +// }, nil +//} + +//func Delete(input e.DeleteDto) (*d.Data, error) { +// var isLinkDeleted bool +// +// event := pl.Event{ +// Feature: "Delete", +// Source: source, +// } +// +// // Start log +// pl.SetLogInfo(&event, input, "started", "delete") +// +// // STEP 1: Get Link +// syncLink, err := ReadDetailLinkData(*input.Id, &event) +// if err != nil { +// return nil, err +// } +// +// // STEP 2: Get Simgos +// sgData, err := ReadDetailSimgosData(uint16(syncLink.Simgos_Id), &event) +// if err != nil { +// return nil, err +// } +// +// err = db.WithDualTx(func(tx *db.Dualtx) error { +// // STEP 3: Delete Simgos +// err = HardDeleteSimgosData(sgData, &event, tx.Simgos) +// if err != nil { +// return err +// } +// +// // STEP 4: Delete Link +// err = DeleteLinkData(syncLink, &event, tx.Sync) +// if err != nil { +// return err +// } +// +// isLinkDeleted = true +// return nil +// }) +// +// if err != nil { +// if isLinkDeleted { +// go func() { +// _, _ = CreateLinkData(uint(*input.Id), sgData.KodeUnit, &event) +// }() +// } +// return nil, err +// } +// +// pl.SetLogInfo(&event, nil, "complete") +// +// return &d.Data{ +// Meta: d.IS{ +// "source": source, +// "structure": "single-data", +// "status": "deleted", +// }, +// }, nil +// +//} diff --git a/internal/use-case/simgos-sync-use-case/new/nurse/helper.go b/internal/use-case/simgos-sync-use-case/new/nurse/helper.go new file mode 100644 index 00000000..73dfe1ac --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/new/nurse/helper.go @@ -0,0 +1,54 @@ +/* +DESCRIPTION: +Any functions that are used internally by the use-case +*/ +package nurse + +import ( + "encoding/json" + erc "simrs-vx/internal/domain/references/common" + + esyncLog "simrs-vx/internal/domain/sync-entities/log" + esync "simrs-vx/internal/domain/sync-entities/nurse" +) + +//func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T) (data esimgos.MDokter) { +// var inputSrc *e.CreateDto +// if inputT, ok := any(input).(*e.CreateDto); ok { +// inputSrc = inputT +// } else { +// inputTemp := any(input).(*e.UpdateDto) +// inputSrc = &inputTemp.CreateDto +// } +// +// data.NamaUnit = inputSrc.Name +// return +//} + +func setDataSimxLog(input *esyncLog.SimxLogDto) (data esync.NurseSimxLog) { + // encode to JSON + jsonData, _ := json.MarshalIndent(input.Payload, "", " ") + jsonString := string(jsonData) + + var status erc.ProcessStatusCode + if input.IsSuccess { + status = erc.PSCSuccess + } else { + status = erc.PSCFailed + if input.ErrMessage != nil { + data.ErrMessage = input.ErrMessage + } + } + + data.Value = &jsonString + data.Date = &now + data.Status = status + + return +} + +func setDataSimxLink(simxId, simgosId uint) (data esync.NurseLink) { + data.Simx_Id = simxId + data.Simgos_Id = simgosId + return +} diff --git a/internal/use-case/simgos-sync-use-case/new/nurse/lib.go b/internal/use-case/simgos-sync-use-case/new/nurse/lib.go new file mode 100644 index 00000000..e92b5b66 --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/new/nurse/lib.go @@ -0,0 +1,186 @@ +package nurse + +import ( + plh "simrs-vx/pkg/lib-helper" + pl "simrs-vx/pkg/logger" + pu "simrs-vx/pkg/use-case-helper" + "time" + + dg "github.com/karincake/apem/db-gorm-pg" + "gorm.io/gorm" + + esynclog "simrs-vx/internal/domain/sync-entities/log" + esync "simrs-vx/internal/domain/sync-entities/nurse" +) + +var now = time.Now() + +//func CreateSimgosData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*esimgos.MDokter, error) { +// pl.SetLogInfo(event, nil, "started", "DBCreate") +// +// data := setDataSimgos(&input) +// +// var tx *gorm.DB +// if len(dbx) > 0 { +// tx = dbx[0] +// } else { +// tx = dg.IS["simrs"] +// } +// +// if err := tx.Create(&data).Error; err != nil { +// return nil, plh.HandleCreateError(input, event, err) +// } +// +// pl.SetLogInfo(event, nil, "complete") +// return &data, nil +//} + +//func ReadDetailSimgosData(simgosId uint16, event *pl.Event) (*esimgos.MUnit, error) { +// pl.SetLogInfo(event, simgosId, "started", "DBReadDetail") +// data := esimgos.MUnit{} +// +// var tx = dg.IS["simrs"] +// +// if err := tx. +// Where("\"kode_unit\" = ?", simgosId). +// First(&data).Error; err != nil { +// if processedErr := pu.HandleReadError(err, event, source, simgosId, data); processedErr != nil { +// return nil, processedErr +// } +// } +// +// pl.SetLogInfo(event, nil, "complete") +// return &data, nil +//} + +//func UpdateSimgosData(input e.UpdateDto, dataSimgos *esync.DivisionLink, event *pl.Event, dbx ...*gorm.DB) error { +// pl.SetLogInfo(event, input, "started", "DBUpdate") +// +// data := setDataSimgos(&input) +// data.KodeUnit = dataSimgos.Simgos_Id +// +// var tx *gorm.DB +// if len(dbx) > 0 { +// tx = dbx[0] +// } else { +// tx = dg.IS["simrs"] +// } +// +// 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 HardDeleteSimgosData(data *esimgos.MUnit, 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.IS["simrs"] +// } +// +// 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 +//} + +func CreateLinkData(simxId, simgosId uint, event *pl.Event, dbx ...*gorm.DB) (*esync.NurseLink, error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + data := setDataSimxLink(simxId, simgosId) + + 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(data, event, err) + } + + pl.SetLogInfo(event, nil, "complete") + return &data, nil +} + +func ReadDetailLinkData(simxId uint16, event *pl.Event) (*esync.NurseLink, error) { + pl.SetLogInfo(event, simxId, "started", "DBReadDetail") + data := esync.NurseLink{} + + var tx = dg.I + + if err := tx. + Where("\"Simx_Id\" = ?", simxId). + First(&data).Error; err != nil { + if processedErr := pu.HandleReadError(err, event, source, simxId, data); processedErr != nil { + return nil, processedErr + } + } + + pl.SetLogInfo(event, nil, "complete") + return &data, nil +} + +func DeleteLinkData(data *esync.NurseLink, 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 +} + +func CreateLogData(input esynclog.SimxLogDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, nil, "started", "DBCreate") + data := setDataSimxLog(&input) + + 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 +} diff --git a/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go index e993b27b..e63b1503 100644 --- a/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go +++ b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go @@ -1,11 +1,13 @@ package doctor import ( - "bytes" "encoding/json" - "io" + "fmt" + + "log" "net/http" - cfg "simrs-vx/internal/infra/sync-cfg" + + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" pl "simrs-vx/pkg/logger" "strconv" @@ -13,27 +15,22 @@ import ( erg "simrs-vx/internal/domain/references/organization" - ed "simrs-vx/internal/domain/simgos-entities/m-dokter" - el "simrs-vx/internal/domain/simgos-entities/m-login" - ep "simrs-vx/internal/domain/simgos-entities/m-pegawai" - + eed "simrs-vx/internal/domain/main-entities/doctor" epr "simrs-vx/internal/domain/main-entities/person" es "simrs-vx/internal/domain/main-entities/user" ud "simrs-vx/internal/use-case/simgos-sync-use-case/new/doctor" ) -type User struct { - Doctor ed.MDokter `gorm:"embedded"` - Employee ep.MPegawai `gorm:"embedded"` - Login el.MLogin `gorm:"embedded"` -} - -var path = "user" - func SeedDoctor() error { + + log.Println("=== START SeedDoctor ===") + tx := db.NewTx() - var users []User + + var users []seeder.User + + log.Println("Querying SIMRS doctors...") err := tx.Simgos.Table("m_dokter"). Select(` @@ -43,94 +40,101 @@ func SeedDoctor() error { `). Joins(`LEFT JOIN m_login l ON l.kddokter = m_dokter.kddokter`). Joins(`LEFT JOIN m_pegawai p ON p.no_peg = m_dokter.kddokter`). - Where(`m_dokter.aktif = ?`, 1). + Where(`p.nik != '' AND p.nik != '0' AND l.nip != ''`). Order(`m_dokter.kddokter DESC`). Limit(10). Scan(&users).Error if err != nil { + log.Println("Error Querying SIMRS:", err) return err } + log.Printf("Found %d doctors to seed\n", len(users)) + // mapping - doctorsimx := []es.CreateDto{} for i, d := range users { + log.Printf("[%d/%d] Processing doctor KdDokter=%d ...", i+1, len(users), d.Doctor.Kddokter) + kddokter := strconv.Itoa(int(d.Doctor.Kddokter)) - doctorsimx = append(doctorsimx, es.CreateDto{ + doctorsimx := es.CreateDto{ Name: d.Login.NIP, Password: "1234", ContractPosition_Code: erg.CSCEmp, Code: &kddokter, Person: &epr.UpdateDto{ CreateDto: epr.CreateDto{ - Name: d.Employee.NamaPeg, - BirthPlace: &d.Employee.TempatLahir, + Name: d.Employee.NamaPeg, + BirthPlace: &d.Employee.TempatLahir, + ResidentIdentityNumber: &d.Employee.NIK, }, }, Employee: &es.EmployeUpdateDto{ Position_Code: erg.EPCDoc, }, - }) + } - // create request body - jsonUser, err := json.Marshal(doctorsimx[i]) + log.Printf("[%d] Creating User for NIP=%s ...", i+1, d.Login.NIP) + + // create user + user, err := seeder.CreateUser(doctorsimx) if err != nil { + log.Println("Error createUser:", err) return err } - reqBody := bytes.NewBuffer(jsonUser) - // send data to main-api - resp, err := send(http.MethodPost, path, reqBody, "von") + log.Printf("[%d] User created: ID=%d", i+1, user.Id) + + log.Printf("[%d] Fetching doctor with code=%s ...", i+1, kddokter) + // get doctor + dataDoctor, err := getDoctors(kddokter) if err != nil { + log.Println("Error getDoctors:", err) return err } - type MetaData struct { - Source string `json:"source"` - Status string `json:"status"` - Structure string `json:"structure"` - } + doc := *dataDoctor + ddoc := doc[0] - type MainApiResp struct { - Meta MetaData `json:"meta"` - Data es.User `json:"data"` - } - - // getting response - var data MainApiResp - err = json.Unmarshal(resp, &data) - if err != nil { + log.Printf("[%d] Linking doctor %d to %d ...", i+1, ddoc.Id, d.Doctor.Kddokter) + if _, err := ud.CreateLinkData(ddoc.Id, d.Doctor.Kddokter, &pl.Event{}); err != nil { return err } - if _, err := ud.CreateLinkData(data.Data.Id, d.Doctor.Kddokter, &pl.Event{}); err != nil { - return err - } + log.Printf("[%d] Link created successfully.", i+1) } + log.Println("=== FINISH SeedDoctor ===") + return nil } -func send(method string, endpoint string, body *bytes.Buffer, username string) ([]byte, error) { - var url string = cfg.O.NewHost + "/v1" + endpoint - var reader io.Reader = nil - if body != nil { - reader = body - } - req, err := http.NewRequest(method, url, reader) +func getDoctors(code string) (*[]eed.Doctor, error) { + path := fmt.Sprintf("doctor?code=%s", code) + + resp, err := seeder.Send(http.MethodGet, path, nil, "von") if err != nil { return nil, err } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("X-Sync-Source", cfg.O.OldSource) - req.Header.Set("X-Sync-SecretKey", cfg.O.NewSecretKey) - req.Header.Set("X-Sync-UserName", username) - resp, err := http.DefaultClient.Do(req) + + type MetaData struct { + Source string `json:"source"` + Status string `json:"status"` + Structure string `json:"structure"` + } + + type MainApiResp struct { + Meta MetaData `json:"meta"` + Data []eed.Doctor `json:"data"` + } + + // getting response + var data MainApiResp + err = json.Unmarshal(resp, &data) if err != nil { return nil, err } - defer resp.Body.Close() - respBody, _ := io.ReadAll(resp.Body) - return respBody, nil + + return &data.Data, nil } diff --git a/internal/use-case/simgos-sync-use-case/seeder/helper.go b/internal/use-case/simgos-sync-use-case/seeder/helper.go new file mode 100644 index 00000000..15d242bd --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/seeder/helper.go @@ -0,0 +1,86 @@ +package seeder + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "net/http" + es "simrs-vx/internal/domain/main-entities/user" + ed "simrs-vx/internal/domain/simgos-entities/m-dokter" + el "simrs-vx/internal/domain/simgos-entities/m-login" + ep "simrs-vx/internal/domain/simgos-entities/m-pegawai" + epr "simrs-vx/internal/domain/simgos-entities/m-perawat" + cfg "simrs-vx/internal/infra/sync-cfg" +) + +type User struct { + Login el.MLogin `gorm:"embedded"` + Nurse epr.MPerawat `gorm:"embedded"` + Doctor ed.MDokter `gorm:"embedded"` + Employee ep.MPegawai `gorm:"embedded"` +} + +func Send(method string, endpoint string, body *bytes.Buffer, username string) ([]byte, error) { + var url string = cfg.O.NewHost + "v1/" + endpoint + var reader io.Reader = nil + if body != nil { + reader = body + } + req, err := http.NewRequest(method, url, reader) + if err != nil { + return nil, err + } + req.Header.Set("Content-Type", "application/json") + req.Header.Set("X-Sync-Source", cfg.O.OldSource) + req.Header.Set("X-Sync-SecretKey", cfg.O.NewSecretKey) + req.Header.Set("X-Sync-UserName", username) + resp, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("http status code %d", resp.StatusCode) + } + respBody, _ := io.ReadAll(resp.Body) + return respBody, nil +} + +func CreateUser(user es.CreateDto) (*es.User, error) { + var path = "user" + + // create request body + jsonUser, err := json.Marshal(user) + if err != nil { + return nil, err + } + + reqBody := bytes.NewBuffer(jsonUser) + // send data to main-api + resp, err := Send(http.MethodPost, path, reqBody, "von") + if err != nil { + return nil, err + } + + type MetaData struct { + Source string `json:"source"` + Status string `json:"status"` + Structure string `json:"structure"` + } + + type MainApiResp struct { + Meta MetaData `json:"meta"` + Data es.User `json:"data"` + } + + // getting response + var data MainApiResp + err = json.Unmarshal(resp, &data) + if err != nil { + return nil, err + } + + return &data.Data, nil +} diff --git a/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go new file mode 100644 index 00000000..16f07b36 --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go @@ -0,0 +1,164 @@ +package nurse + +import ( + "encoding/json" + "fmt" + "log" + "math/rand" + "net/http" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" + pl "simrs-vx/pkg/logger" + "strconv" + "time" + + db "simrs-vx/pkg/dualtrx-helper" + + erg "simrs-vx/internal/domain/references/organization" + + en "simrs-vx/internal/domain/main-entities/nurse" + epr "simrs-vx/internal/domain/main-entities/person" + es "simrs-vx/internal/domain/main-entities/user" + + un "simrs-vx/internal/use-case/simgos-sync-use-case/new/nurse" +) + +func SeedNurse() error { + + log.Println("=== START SeedNurse ===") + + tx := db.NewTx() + + var users []seeder.User + + log.Println("Querying SIMRS nurses...") + + err := tx.Simgos.Table("m_perawat"). + Select("m_perawat.*, l.*"). + Joins("LEFT JOIN m_login l ON l.kdperawat = m_perawat.idperawat"). + Where("l.roles = ?", 4). + Order("m_perawat.idperawat DESC"). + Limit(10). + Scan(&users).Error + + if err != nil { + log.Println("Error Querying SIMRS:", err) + return err + } + + log.Printf("Found %d nurses to seed\n", len(users)) + + // mapping + for i, d := range users { + log.Printf("[%d/%d] Processing nurse KdPerawat=%d ...", i+1, len(users), d.Nurse.NIP) + + kdprawat := strconv.Itoa(int(*d.Nurse.Idperawat)) + nik := GenerateDummyNIK("F") + nursesimx := es.CreateDto{ + Name: d.Login.NIP, + Password: "1234", + ContractPosition_Code: erg.CSCEmp, + Code: &kdprawat, + Person: &epr.UpdateDto{ + CreateDto: epr.CreateDto{ + Name: d.Employee.NamaPeg, + BirthPlace: &d.Employee.TempatLahir, + ResidentIdentityNumber: &nik, + }, + }, + Employee: &es.EmployeUpdateDto{ + Position_Code: erg.EPCNur, + }, + } + + log.Printf("[%d] Creating User for NIP=%s ...", i+1, d.Login.NIP) + + // create user + user, err := seeder.CreateUser(nursesimx) + if err != nil { + log.Println("Error createUser:", err) + return err + } + + log.Printf("[%d] User created: ID=%d", i+1, user.Id) + + log.Printf("[%d] Fetching nurse with code=%s ...", i+1, kdprawat) + // get nurse + dataNurse, err := getNurse(kdprawat) + if err != nil { + log.Println("Error getnurses:", err) + return err + } + + data := *dataNurse + ddata := data[0] + + log.Printf("[%d] Linking nurse %d to %d ...", i+1, ddata.Id, d.Nurse.Idperawat) + if _, err := un.CreateLinkData(ddata.Id, *d.Nurse.Idperawat, &pl.Event{}); err != nil { + return err + } + + log.Printf("[%d] Link created successfully.", i+1) + } + + log.Println("=== FINISH Seednurse ===") + + return nil + +} + +func getNurse(code string) (*[]en.Nurse, error) { + path := fmt.Sprintf("nurse?code=%s", code) + + resp, err := seeder.Send(http.MethodGet, path, nil, "von") + if err != nil { + return nil, err + } + + type MetaData struct { + Source string `json:"source"` + Status string `json:"status"` + Structure string `json:"structure"` + } + + type MainApiResp struct { + Meta MetaData `json:"meta"` + Data []en.Nurse `json:"data"` + } + + // getting response + var data MainApiResp + err = json.Unmarshal(resp, &data) + if err != nil { + return nil, err + } + + return &data.Data, nil +} + +func GenerateDummyNIK(gender string) string { + rand.Seed(time.Now().UnixNano()) + + // 1️⃣ Kode wilayah (6 digit) + // Bisa di-random, atau gunakan kode tetap seperti Jakarta: 317301 + region := rand.Intn(999999) // 000000 - 999999 + regionCode := fmt.Sprintf("%06d", region) + + // 2️⃣ Tanggal lahir (DDMMYY) + year := rand.Intn(30) + 70 // antara tahun 1970-1999 (bisa diganti range lain) + month := rand.Intn(12) + 1 + day := rand.Intn(28) + 1 // selalu valid + + if gender == "F" { + day += 40 // aturan NIK perempuan: tanggal lahir + 40 + } + + birth := fmt.Sprintf("%02d%02d%02d", day, month, year) + + // 3️⃣ Nomor urut (4 digit) + sequence := fmt.Sprintf("%04d", rand.Intn(9999)) + + // 4️⃣ Susun NIK akhir + nik := regionCode + birth + sequence + + return nik +} From bd2f073dfc4833559cd8cef3d76ecb1f9ab8bff4 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Wed, 10 Dec 2025 12:32:14 +0700 Subject: [PATCH 28/39] wip --- .../interface/main-handler/main-handler.go | 5 ++ .../vclaim-sep-control-letter/handler.go | 67 +++++++++++++++++++ .../vclaim-sep-control-letter/plugin.go | 3 +- 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 internal/interface/main-handler/vclaim-sep-control-letter/handler.go diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 7bf8cd2d..225a320f 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -138,6 +138,7 @@ import ( reference "simrs-vx/internal/interface/main-handler/reference" referral "simrs-vx/internal/interface/main-handler/referral" vclaimsep "simrs-vx/internal/interface/main-handler/vclaim-sep" + vclaimsepcontrolletter "simrs-vx/internal/interface/main-handler/vclaim-sep-control-letter" vclaimsephist "simrs-vx/internal/interface/main-handler/vclaim-sep-hist" vclaimsepprint "simrs-vx/internal/interface/main-handler/vclaim-sep-print" ) @@ -414,6 +415,10 @@ func SetRoutes() http.Handler { "DELETE /{number}": vclaimsep.O.Delete, }) + hk.GroupRoutes("/v1/vclaim-sep-control-letter", r, hk.MapHandlerFunc{ + "POST /": vclaimsepcontrolletter.O.Create, + }) + hk.GroupRoutes("/v1/vclaim-sep-hist", r, hk.MapHandlerFunc{ "GET /": vclaimsephist.O.GetList, }) diff --git a/internal/interface/main-handler/vclaim-sep-control-letter/handler.go b/internal/interface/main-handler/vclaim-sep-control-letter/handler.go new file mode 100644 index 00000000..d26cc633 --- /dev/null +++ b/internal/interface/main-handler/vclaim-sep-control-letter/handler.go @@ -0,0 +1,67 @@ +package vclaimsepcontrolletter + +import ( + "net/http" + + rw "github.com/karincake/risoles" + + e "simrs-vx/internal/domain/bpjs-entities/vclaim-sep-control-letter" + u "simrs-vx/internal/use-case/bpjs-use-case/vclaim-sep-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) { +// number := rw.ValidateString(w, "number", r.PathValue("number")) +// if number <= "" { +// return +// } +// dto := e.ReadDetailDto{} +// dto.Number = &number +// res, err := u.ReadDetail(dto) +// rw.DataResponse(w, res, err) +// } + +// func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { +// number := rw.ValidateString(w, "number", r.PathValue("number")) +// if number != "" { +// return +// } + +// dto := e.UpdateDto{} +// if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { +// return +// } +// dto.Number = &number +// 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/bpjs-plugin/vclaim-sep-control-letter/plugin.go b/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/plugin.go index b8460713..3ad81f74 100644 --- a/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/plugin.go +++ b/internal/use-case/bpjs-plugin/vclaim-sep-control-letter/plugin.go @@ -50,7 +50,8 @@ func CreateSepControlLetter(input *e.CreateDto, data *e.VclaimSepControlLetter, } tmp := string(pdfNeeds) input.Value = &tmp - + input.Number = &vresp.Response.NoSuratKontrol + input.VclaimSep_Number = &vresp.Response.Sep.NoSep return nil } From 5143b71efdefacdd83f68a46fad7b8ddf1176554 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Wed, 10 Dec 2025 12:35:04 +0700 Subject: [PATCH 29/39] feat (vclaim-sep): use number on delete --- internal/interface/main-handler/vclaim-sep/handler.go | 6 +++--- internal/use-case/bpjs-use-case/vclaim-sep/case.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/interface/main-handler/vclaim-sep/handler.go b/internal/interface/main-handler/vclaim-sep/handler.go index 1529e2d8..2a3fe788 100644 --- a/internal/interface/main-handler/vclaim-sep/handler.go +++ b/internal/interface/main-handler/vclaim-sep/handler.go @@ -56,12 +56,12 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { // } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + number := rw.ValidateString(w, "number", r.PathValue("number")) + if number == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Number = &number res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/bpjs-use-case/vclaim-sep/case.go b/internal/use-case/bpjs-use-case/vclaim-sep/case.go index 1d0e4aab..0f0d5203 100644 --- a/internal/use-case/bpjs-use-case/vclaim-sep/case.go +++ b/internal/use-case/bpjs-use-case/vclaim-sep/case.go @@ -246,7 +246,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{Number: input.Number} var data *e.VclaimSep var err error From 56e2db2387c5360160b0ea529427078273395e8a Mon Sep 17 00:00:00 2001 From: vanilia Date: Wed, 10 Dec 2025 21:48:26 +0700 Subject: [PATCH 30/39] on going seeder --- .../seeder/doctor/seeder.go | 13 +++++- .../simgos-sync-use-case/seeder/helper.go | 11 ----- .../seeder/nurse/seeder.go | 44 ++++++++++++------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go index e63b1503..63626d16 100644 --- a/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go +++ b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go @@ -3,7 +3,6 @@ package doctor import ( "encoding/json" "fmt" - "log" "net/http" @@ -19,16 +18,26 @@ import ( epr "simrs-vx/internal/domain/main-entities/person" es "simrs-vx/internal/domain/main-entities/user" + ed "simrs-vx/internal/domain/simgos-entities/m-dokter" + el "simrs-vx/internal/domain/simgos-entities/m-login" + ee "simrs-vx/internal/domain/simgos-entities/m-pegawai" + ud "simrs-vx/internal/use-case/simgos-sync-use-case/new/doctor" ) +type user struct { + Login el.MLogin `gorm:"embedded"` + Doctor ed.MDokter `gorm:"embedded"` + Employee ee.MPegawai `gorm:"embedded"` +} + func SeedDoctor() error { log.Println("=== START SeedDoctor ===") tx := db.NewTx() - var users []seeder.User + var users []user log.Println("Querying SIMRS doctors...") diff --git a/internal/use-case/simgos-sync-use-case/seeder/helper.go b/internal/use-case/simgos-sync-use-case/seeder/helper.go index 15d242bd..b9b7336f 100644 --- a/internal/use-case/simgos-sync-use-case/seeder/helper.go +++ b/internal/use-case/simgos-sync-use-case/seeder/helper.go @@ -7,20 +7,9 @@ import ( "io" "net/http" es "simrs-vx/internal/domain/main-entities/user" - ed "simrs-vx/internal/domain/simgos-entities/m-dokter" - el "simrs-vx/internal/domain/simgos-entities/m-login" - ep "simrs-vx/internal/domain/simgos-entities/m-pegawai" - epr "simrs-vx/internal/domain/simgos-entities/m-perawat" cfg "simrs-vx/internal/infra/sync-cfg" ) -type User struct { - Login el.MLogin `gorm:"embedded"` - Nurse epr.MPerawat `gorm:"embedded"` - Doctor ed.MDokter `gorm:"embedded"` - Employee ep.MPegawai `gorm:"embedded"` -} - func Send(method string, endpoint string, body *bytes.Buffer, username string) ([]byte, error) { var url string = cfg.O.NewHost + "v1/" + endpoint var reader io.Reader = nil diff --git a/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go index 16f07b36..8f1732ff 100644 --- a/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go +++ b/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go @@ -6,6 +6,7 @@ import ( "log" "math/rand" "net/http" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" pl "simrs-vx/pkg/logger" "strconv" @@ -15,25 +16,33 @@ import ( erg "simrs-vx/internal/domain/references/organization" - en "simrs-vx/internal/domain/main-entities/nurse" + enr "simrs-vx/internal/domain/main-entities/nurse" epr "simrs-vx/internal/domain/main-entities/person" es "simrs-vx/internal/domain/main-entities/user" + el "simrs-vx/internal/domain/simgos-entities/m-login" + en "simrs-vx/internal/domain/simgos-entities/m-perawat" + un "simrs-vx/internal/use-case/simgos-sync-use-case/new/nurse" ) +type user struct { + el.MLogin + en.MPerawat +} + func SeedNurse() error { log.Println("=== START SeedNurse ===") tx := db.NewTx() - var users []seeder.User + var users []user log.Println("Querying SIMRS nurses...") err := tx.Simgos.Table("m_perawat"). - Select("m_perawat.*, l.*"). + Select("m_perawat.idperawat, m_perawat.nama, l.*"). Joins("LEFT JOIN m_login l ON l.kdperawat = m_perawat.idperawat"). Where("l.roles = ?", 4). Order("m_perawat.idperawat DESC"). @@ -49,19 +58,18 @@ func SeedNurse() error { // mapping for i, d := range users { - log.Printf("[%d/%d] Processing nurse KdPerawat=%d ...", i+1, len(users), d.Nurse.NIP) + log.Printf("[%d/%d] Processing nurse KdPerawat=%d ...", i+1, len(users), d.Idperawat) - kdprawat := strconv.Itoa(int(*d.Nurse.Idperawat)) + kdprawat := strconv.Itoa(int(*d.Idperawat)) nik := GenerateDummyNIK("F") nursesimx := es.CreateDto{ - Name: d.Login.NIP, + Name: d.MLogin.NIP, Password: "1234", ContractPosition_Code: erg.CSCEmp, Code: &kdprawat, Person: &epr.UpdateDto{ CreateDto: epr.CreateDto{ - Name: d.Employee.NamaPeg, - BirthPlace: &d.Employee.TempatLahir, + Name: d.NamaPegawai, ResidentIdentityNumber: &nik, }, }, @@ -70,16 +78,20 @@ func SeedNurse() error { }, } - log.Printf("[%d] Creating User for NIP=%s ...", i+1, d.Login.NIP) + log.Printf("[%d] Creating User for NIP=%v ...", i+1, d.Idperawat) + + if i == 0 { + continue + } // create user - user, err := seeder.CreateUser(nursesimx) + userData, err := seeder.CreateUser(nursesimx) if err != nil { log.Println("Error createUser:", err) return err } - log.Printf("[%d] User created: ID=%d", i+1, user.Id) + log.Printf("[%d] User created: ID=%d", i+1, userData.Id) log.Printf("[%d] Fetching nurse with code=%s ...", i+1, kdprawat) // get nurse @@ -92,8 +104,8 @@ func SeedNurse() error { data := *dataNurse ddata := data[0] - log.Printf("[%d] Linking nurse %d to %d ...", i+1, ddata.Id, d.Nurse.Idperawat) - if _, err := un.CreateLinkData(ddata.Id, *d.Nurse.Idperawat, &pl.Event{}); err != nil { + log.Printf("[%d] Linking nurse %d to %s ...", i+1, ddata.Id, kdprawat) + if _, err := un.CreateLinkData(ddata.Id, *d.Idperawat, &pl.Event{}); err != nil { return err } @@ -106,7 +118,7 @@ func SeedNurse() error { } -func getNurse(code string) (*[]en.Nurse, error) { +func getNurse(code string) (*[]enr.Nurse, error) { path := fmt.Sprintf("nurse?code=%s", code) resp, err := seeder.Send(http.MethodGet, path, nil, "von") @@ -121,8 +133,8 @@ func getNurse(code string) (*[]en.Nurse, error) { } type MainApiResp struct { - Meta MetaData `json:"meta"` - Data []en.Nurse `json:"data"` + Meta MetaData `json:"meta"` + Data []enr.Nurse `json:"data"` } // getting response From 2ce91179b93a43c6631fa0f20243459c51635003 Mon Sep 17 00:00:00 2001 From: vanilia Date: Wed, 10 Dec 2025 21:52:18 +0700 Subject: [PATCH 31/39] update name in user --- cmd/main-migration/migrations/20251210145148.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 10 ++++++---- internal/domain/main-entities/user/entity.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 cmd/main-migration/migrations/20251210145148.sql diff --git a/cmd/main-migration/migrations/20251210145148.sql b/cmd/main-migration/migrations/20251210145148.sql new file mode 100644 index 00000000..6a37b2af --- /dev/null +++ b/cmd/main-migration/migrations/20251210145148.sql @@ -0,0 +1,2 @@ +-- Modify "User" table +ALTER TABLE "public"."User" ALTER COLUMN "Name" TYPE character varying(50); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 9c137d56..ca21de20 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:B/ZKq0d90aqLf0EvQfND4cd8ZRHcmxfzKF2N1lpSeIs= +h1:nDEuOqs0hKLyxdzKDcaNhEkrmnmbm6o/jgoGigw47bo= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -156,6 +156,8 @@ h1:B/ZKq0d90aqLf0EvQfND4cd8ZRHcmxfzKF2N1lpSeIs= 20251209022744.sql h1:y5/PAiZH/fYCpDJpkQdNRJwWICHH2iNIwM1V+S1P6KA= 20251209025908.sql h1:p3kZA8kyEj+mQZSrdY3k2K1NojQzFJh/MlZJ0Oy6t/k= 20251209030538.sql h1:zltV6/Fu2zJW0/lVBl7MdnWuJcqNTUIRcqYYZ8Fi1wo= -20251209064304.sql h1:Mj6Zh+2b/4AkM1HjnJGjAs788kVN0UaL34jeaKQIjT0= -20251209070128.sql h1:ip4wNCIF/UFQlNo6KpFG87/XA08aG3/Rf5zpxz3xioY= -20251209084929.sql h1:Z5higP1Ecq5UPWhrWZ5UCrxddMNqiJi8PbCNvGBE48A= +20251209051742.sql h1:BBNSmWfkamWrcKdxWjPiBS9yJ8yyQQUQIj3kip53nuE= +20251209064304.sql h1:Xs73yQbuJvuQ0OnW1FAZpeytmUl/bGTlJFrwGOsTF4w= +20251209070128.sql h1:fPGE6xOV6uCiVOqnvwn2L/GsBbgp2wxgmZOhF3bSGGM= +20251209084929.sql h1:u4LPMvkGAH4RfGC2IlBTIm7T7paMHoBSvTQ0w5Br7d0= +20251210145148.sql h1:EWbK5f1QKyhaVsKZfJFunmQuw22Msl0Ox3KQ/uag2bw= diff --git a/internal/domain/main-entities/user/entity.go b/internal/domain/main-entities/user/entity.go index f51dbf14..712a70e1 100644 --- a/internal/domain/main-entities/user/entity.go +++ b/internal/domain/main-entities/user/entity.go @@ -10,7 +10,7 @@ import ( type User struct { ecore.Main // adjust this according to the needs - Name string `json:"name" gorm:"unique;not null;size:25"` + Name string `json:"name" gorm:"unique;not null;size:50"` Password string `json:"password" gorm:"not null;size:255"` Status_Code erc.UserStatusCode `json:"status_code" gorm:"not null;size:10"` ContractPosition_Code erg.ContractPositionCode `json:"contractPosition_code" gorm:"not null;size:20"` From e6cc34ee94e46dc534a31d1fab109cbd91584ab5 Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 11 Dec 2025 01:35:39 +0700 Subject: [PATCH 32/39] seeder finish --- .../seeder/doctor/handler.go | 18 ---- .../simgos-sync-handler/seeder/handler.go | 23 +++++ .../seeder/nurse/handler.go | 18 ---- .../simgos-sync-handler.go | 10 +- internal/use-case/main-use-case/user/case.go | 7 +- .../seeder/doctor/seeder.go | 66 +++++++------ .../simgos-sync-use-case/seeder/helper.go | 35 +++++++ .../seeder/nurse/seeder.go | 71 +++++--------- .../seeder/regular/seeder.go | 57 +++++++++++ .../seeder/seeder/seeder.go | 94 +++++++++++++++++++ 10 files changed, 272 insertions(+), 127 deletions(-) delete mode 100644 internal/interface/simgos-sync-handler/seeder/doctor/handler.go create mode 100644 internal/interface/simgos-sync-handler/seeder/handler.go delete mode 100644 internal/interface/simgos-sync-handler/seeder/nurse/handler.go create mode 100644 internal/use-case/simgos-sync-use-case/seeder/regular/seeder.go create mode 100644 internal/use-case/simgos-sync-use-case/seeder/seeder/seeder.go diff --git a/internal/interface/simgos-sync-handler/seeder/doctor/handler.go b/internal/interface/simgos-sync-handler/seeder/doctor/handler.go deleted file mode 100644 index 38c11cc4..00000000 --- a/internal/interface/simgos-sync-handler/seeder/doctor/handler.go +++ /dev/null @@ -1,18 +0,0 @@ -package doctor - -import ( - "net/http" - "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/doctor" - - rw "github.com/karincake/risoles" -) - -type myBase struct{} - -var O myBase - -func (obj myBase) Seeder(w http.ResponseWriter, r *http.Request) { - - err := doctor.SeedDoctor() - rw.DataResponse(w, nil, err) -} diff --git a/internal/interface/simgos-sync-handler/seeder/handler.go b/internal/interface/simgos-sync-handler/seeder/handler.go new file mode 100644 index 00000000..0d0f70c6 --- /dev/null +++ b/internal/interface/simgos-sync-handler/seeder/handler.go @@ -0,0 +1,23 @@ +package seeder + +import ( + "net/http" + seeder "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" + main "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/seeder" + + rw "github.com/karincake/risoles" +) + +type myBase struct{} + +var O myBase + +func (obj myBase) Seeder(w http.ResponseWriter, r *http.Request) { + dto := seeder.Dto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + + res, err := main.SeedToSimx(dto) + rw.DataResponse(w, res, err) +} diff --git a/internal/interface/simgos-sync-handler/seeder/nurse/handler.go b/internal/interface/simgos-sync-handler/seeder/nurse/handler.go deleted file mode 100644 index 93d58045..00000000 --- a/internal/interface/simgos-sync-handler/seeder/nurse/handler.go +++ /dev/null @@ -1,18 +0,0 @@ -package nurse - -import ( - "net/http" - "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/nurse" - - rw "github.com/karincake/risoles" -) - -type myBase struct{} - -var O myBase - -func (obj myBase) Seeder(w http.ResponseWriter, r *http.Request) { - - err := nurse.SeedNurse() - rw.DataResponse(w, nil, err) -} diff --git a/internal/interface/simgos-sync-handler/simgos-sync-handler.go b/internal/interface/simgos-sync-handler/simgos-sync-handler.go index e7a6c597..c8a08b7f 100644 --- a/internal/interface/simgos-sync-handler/simgos-sync-handler.go +++ b/internal/interface/simgos-sync-handler/simgos-sync-handler.go @@ -30,8 +30,7 @@ import ( "simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist" "simrs-vx/internal/interface/simgos-sync-handler/new/unit" - sd "simrs-vx/internal/interface/simgos-sync-handler/seeder/doctor" - sn "simrs-vx/internal/interface/simgos-sync-handler/seeder/nurse" + sd "simrs-vx/internal/interface/simgos-sync-handler/seeder" oldpatient "simrs-vx/internal/interface/simgos-sync-handler/old/patient" @@ -79,11 +78,10 @@ func SetRoutes() http.Handler { }) hc.SyncCrud(r, prefixnew+"/v1/soapi", soapi.O) - /******************** SvcToNew ******************/ - prefixseeder := "/new-seeder" + /******************** Seeder ******************/ + prefixseeder := "/seeder" hk.GroupRoutes(prefixseeder+"/v1", r, hk.MapHandlerFunc{ - "POST /doctor": sd.O.Seeder, - "POST /nurse": sn.O.Seeder, + "POST /": sd.O.Seeder, }) /******************** SvcToNew ******************/ diff --git a/internal/use-case/main-use-case/user/case.go b/internal/use-case/main-use-case/user/case.go index 1ea8c6ea..154695fb 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -169,9 +169,14 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } case ero.EPCReg, ero.EPCScr: + var instalationCode string + if input.Installation_Code != nil { + instalationCode = *input.Installation_Code + } + createSub := er.CreateDto{ Employee_Id: employeeData.Id, - Installation_Code: *input.Installation_Code, + Installation_Code: instalationCode, } if _, err := ur.CreateData(createSub, &event, tx); err != nil { return err diff --git a/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go index 63626d16..e575c26b 100644 --- a/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go +++ b/internal/use-case/simgos-sync-use-case/seeder/doctor/seeder.go @@ -6,7 +6,6 @@ import ( "log" "net/http" - "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" pl "simrs-vx/pkg/logger" "strconv" @@ -18,44 +17,40 @@ import ( epr "simrs-vx/internal/domain/main-entities/person" es "simrs-vx/internal/domain/main-entities/user" - ed "simrs-vx/internal/domain/simgos-entities/m-dokter" - el "simrs-vx/internal/domain/simgos-entities/m-login" - ee "simrs-vx/internal/domain/simgos-entities/m-pegawai" - ud "simrs-vx/internal/use-case/simgos-sync-use-case/new/doctor" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" ) type user struct { - Login el.MLogin `gorm:"embedded"` - Doctor ed.MDokter `gorm:"embedded"` - Employee ee.MPegawai `gorm:"embedded"` + Kddokter uint `gorm:"column:kddokter"` + Kdpoly uint `gorm:"column:kdpoly"` + NIP string `gorm:"column:nip"` + NamaPegawai string `gorm:"column:nama_pegawai"` } -func SeedDoctor() error { +func SeedDoctor(kddoc []uint, event *pl.Event, tx *db.Dualtx) error { log.Println("=== START SeedDoctor ===") - tx := db.NewTx() - var users []user - log.Println("Querying SIMRS doctors...") + log.Println("Querying SIMGOS doctors...") - err := tx.Simgos.Table("m_dokter"). + err := tx.Simgos. + Table("m_dokter"). Select(` - m_dokter.*, - l.*, - p.* - `). - Joins(`LEFT JOIN m_login l ON l.kddokter = m_dokter.kddokter`). - Joins(`LEFT JOIN m_pegawai p ON p.no_peg = m_dokter.kddokter`). - Where(`p.nik != '' AND p.nik != '0' AND l.nip != ''`). - Order(`m_dokter.kddokter DESC`). - Limit(10). + DISTINCT ON (l.nip) + m_dokter.kddokter as kddokter, + m_dokter.kdpoly as kdpoly, + l.nip as nip, + l.nama_pegawai as nama_pegawai + `). + Joins(`LEFT JOIN m_login l ON l.kddokter = m_dokter.kddokter`). + Where(`m_dokter.kddokter IN (?)`, kddoc). + Order(`l.nip`). Scan(&users).Error if err != nil { - log.Println("Error Querying SIMRS:", err) return err } @@ -63,19 +58,21 @@ func SeedDoctor() error { // mapping for i, d := range users { - log.Printf("[%d/%d] Processing doctor KdDokter=%d ...", i+1, len(users), d.Doctor.Kddokter) + log.Printf("[%d/%d] Processing doctor KdDokter=%d ...", i+1, len(users), d.Kddokter) + + kddokter := strconv.Itoa(int(d.Kddokter)) + //kdpoly := strconv.Itoa(int(d.MDokter.Kdpoly)) + nik := seeder.GenerateDummyNIK("F") - kddokter := strconv.Itoa(int(d.Doctor.Kddokter)) doctorsimx := es.CreateDto{ - Name: d.Login.NIP, + Name: d.NIP, Password: "1234", ContractPosition_Code: erg.CSCEmp, Code: &kddokter, Person: &epr.UpdateDto{ CreateDto: epr.CreateDto{ - Name: d.Employee.NamaPeg, - BirthPlace: &d.Employee.TempatLahir, - ResidentIdentityNumber: &d.Employee.NIK, + Name: d.NamaPegawai, + ResidentIdentityNumber: &nik, }, }, Employee: &es.EmployeUpdateDto{ @@ -83,18 +80,19 @@ func SeedDoctor() error { }, } - log.Printf("[%d] Creating User for NIP=%s ...", i+1, d.Login.NIP) + log.Printf("[%d] Creating User for NIP=%s ...", i+1, d.NIP) // create user - user, err := seeder.CreateUser(doctorsimx) + userData, err := seeder.CreateUser(doctorsimx) if err != nil { log.Println("Error createUser:", err) return err } - log.Printf("[%d] User created: ID=%d", i+1, user.Id) + log.Printf("[%d] User created: ID=%d", i+1, userData.Id) log.Printf("[%d] Fetching doctor with code=%s ...", i+1, kddokter) + // get doctor dataDoctor, err := getDoctors(kddokter) if err != nil { @@ -105,8 +103,8 @@ func SeedDoctor() error { doc := *dataDoctor ddoc := doc[0] - log.Printf("[%d] Linking doctor %d to %d ...", i+1, ddoc.Id, d.Doctor.Kddokter) - if _, err := ud.CreateLinkData(ddoc.Id, d.Doctor.Kddokter, &pl.Event{}); err != nil { + log.Printf("[%d] Linking doctor %d to %s ...", i+1, ddoc.Id, kddokter) + if _, err = ud.CreateLinkData(ddoc.Id, d.Kddokter, event); err != nil { return err } diff --git a/internal/use-case/simgos-sync-use-case/seeder/helper.go b/internal/use-case/simgos-sync-use-case/seeder/helper.go index b9b7336f..74006fe2 100644 --- a/internal/use-case/simgos-sync-use-case/seeder/helper.go +++ b/internal/use-case/simgos-sync-use-case/seeder/helper.go @@ -5,11 +5,18 @@ import ( "encoding/json" "fmt" "io" + "math/rand" "net/http" es "simrs-vx/internal/domain/main-entities/user" cfg "simrs-vx/internal/infra/sync-cfg" + "time" ) +type Dto struct { + LoginNip []string `json:"loginNip"` + Instalasi_Code string `json:"instalasi_code"` +} + func Send(method string, endpoint string, body *bytes.Buffer, username string) ([]byte, error) { var url string = cfg.O.NewHost + "v1/" + endpoint var reader io.Reader = nil @@ -73,3 +80,31 @@ func CreateUser(user es.CreateDto) (*es.User, error) { return &data.Data, nil } + +func GenerateDummyNIK(gender string) string { + rand.Seed(time.Now().UnixNano()) + + // 1️⃣ Kode wilayah (6 digit) + // Bisa di-random, atau gunakan kode tetap seperti Jakarta: 317301 + region := rand.Intn(999999) // 000000 - 999999 + regionCode := fmt.Sprintf("%06d", region) + + // 2️⃣ Tanggal lahir (DDMMYY) + year := rand.Intn(30) + 70 // antara tahun 1970-1999 (bisa diganti range lain) + month := rand.Intn(12) + 1 + day := rand.Intn(28) + 1 // selalu valid + + if gender == "F" { + day += 40 // aturan NIK perempuan: tanggal lahir + 40 + } + + birth := fmt.Sprintf("%02d%02d%02d", day, month, year) + + // 3️⃣ Nomor urut (4 digit) + sequence := fmt.Sprintf("%04d", rand.Intn(9999)) + + // 4️⃣ Susun NIK akhir + nik := regionCode + birth + sequence + + return nik +} diff --git a/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go index 8f1732ff..5ea60fb2 100644 --- a/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go +++ b/internal/use-case/simgos-sync-use-case/seeder/nurse/seeder.go @@ -4,15 +4,12 @@ import ( "encoding/json" "fmt" "log" - "math/rand" "net/http" "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" + db "simrs-vx/pkg/dualtrx-helper" pl "simrs-vx/pkg/logger" "strconv" - "time" - - db "simrs-vx/pkg/dualtrx-helper" erg "simrs-vx/internal/domain/references/organization" @@ -31,26 +28,30 @@ type user struct { en.MPerawat } -func SeedNurse() error { +func SeedNurse(kdnur []uint, event *pl.Event, tx *db.Dualtx) error { log.Println("=== START SeedNurse ===") - tx := db.NewTx() - var users []user - log.Println("Querying SIMRS nurses...") + log.Println("Querying SIMGOS nurses...") - err := tx.Simgos.Table("m_perawat"). - Select("m_perawat.idperawat, m_perawat.nama, l.*"). + err := tx.Simgos. + Table("m_perawat"). + Select(` + DISTINCT ON (l.nip) + m_perawat.idperawat, + m_perawat.nama, + l.nip, + l.nama_pegawai + `). Joins("LEFT JOIN m_login l ON l.kdperawat = m_perawat.idperawat"). - Where("l.roles = ?", 4). - Order("m_perawat.idperawat DESC"). - Limit(10). + Where(`m_perawat.idperawat IN (?)`, kdnur). + Order(`l.nip`). Scan(&users).Error if err != nil { - log.Println("Error Querying SIMRS:", err) + log.Println("Error Querying SIMGOS:", err) return err } @@ -61,7 +62,8 @@ func SeedNurse() error { log.Printf("[%d/%d] Processing nurse KdPerawat=%d ...", i+1, len(users), d.Idperawat) kdprawat := strconv.Itoa(int(*d.Idperawat)) - nik := GenerateDummyNIK("F") + nik := seeder.GenerateDummyNIK("F") + nursesimx := es.CreateDto{ Name: d.MLogin.NIP, Password: "1234", @@ -78,11 +80,7 @@ func SeedNurse() error { }, } - log.Printf("[%d] Creating User for NIP=%v ...", i+1, d.Idperawat) - - if i == 0 { - continue - } + log.Printf("[%d] Creating User for NIP=%v ...", i+1, d.MLogin.NIP) // create user userData, err := seeder.CreateUser(nursesimx) @@ -94,10 +92,11 @@ func SeedNurse() error { log.Printf("[%d] User created: ID=%d", i+1, userData.Id) log.Printf("[%d] Fetching nurse with code=%s ...", i+1, kdprawat) + // get nurse dataNurse, err := getNurse(kdprawat) if err != nil { - log.Println("Error getnurses:", err) + log.Println("Error get nurses:", err) return err } @@ -105,7 +104,7 @@ func SeedNurse() error { ddata := data[0] log.Printf("[%d] Linking nurse %d to %s ...", i+1, ddata.Id, kdprawat) - if _, err := un.CreateLinkData(ddata.Id, *d.Idperawat, &pl.Event{}); err != nil { + if _, err := un.CreateLinkData(ddata.Id, *d.Idperawat, event); err != nil { return err } @@ -146,31 +145,3 @@ func getNurse(code string) (*[]enr.Nurse, error) { return &data.Data, nil } - -func GenerateDummyNIK(gender string) string { - rand.Seed(time.Now().UnixNano()) - - // 1️⃣ Kode wilayah (6 digit) - // Bisa di-random, atau gunakan kode tetap seperti Jakarta: 317301 - region := rand.Intn(999999) // 000000 - 999999 - regionCode := fmt.Sprintf("%06d", region) - - // 2️⃣ Tanggal lahir (DDMMYY) - year := rand.Intn(30) + 70 // antara tahun 1970-1999 (bisa diganti range lain) - month := rand.Intn(12) + 1 - day := rand.Intn(28) + 1 // selalu valid - - if gender == "F" { - day += 40 // aturan NIK perempuan: tanggal lahir + 40 - } - - birth := fmt.Sprintf("%02d%02d%02d", day, month, year) - - // 3️⃣ Nomor urut (4 digit) - sequence := fmt.Sprintf("%04d", rand.Intn(9999)) - - // 4️⃣ Susun NIK akhir - nik := regionCode + birth + sequence - - return nik -} diff --git a/internal/use-case/simgos-sync-use-case/seeder/regular/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/regular/seeder.go new file mode 100644 index 00000000..1ef0c292 --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/seeder/regular/seeder.go @@ -0,0 +1,57 @@ +package regular + +import ( + "log" + erg "simrs-vx/internal/domain/references/organization" + + epr "simrs-vx/internal/domain/main-entities/person" + es "simrs-vx/internal/domain/main-entities/user" + + el "simrs-vx/internal/domain/simgos-entities/m-login" + + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" +) + +func SeedRegular(regLogin []el.MLogin, instalasiCode string) error { + + log.Println("=== START SeedRegular ===") + + // mapping + for i, d := range regLogin { + log.Printf("[%d/%d] Processing Regular NIP=%s ...", i+1, len(regLogin), d.NIP) + + nik := seeder.GenerateDummyNIK("F") + + regularsimx := es.CreateDto{ + Name: d.NIP, + Password: "1234", + ContractPosition_Code: erg.CSCEmp, + Installation_Code: &instalasiCode, + Person: &epr.UpdateDto{ + CreateDto: epr.CreateDto{ + Name: d.NamaPegawai, + ResidentIdentityNumber: &nik, + }, + }, + Employee: &es.EmployeUpdateDto{ + Position_Code: erg.EPCReg, + }, + } + + log.Printf("[%d] Creating User for NIP=%s ...", i+1, d.NIP) + + // create user + userData, err := seeder.CreateUser(regularsimx) + if err != nil { + log.Println("Error createUser:", err) + return err + } + + log.Printf("[%d] User created: ID=%d", i+1, userData.Id) + } + + log.Println("=== FINISH SeedRegular ===") + + return nil + +} diff --git a/internal/use-case/simgos-sync-use-case/seeder/seeder/seeder.go b/internal/use-case/simgos-sync-use-case/seeder/seeder/seeder.go new file mode 100644 index 00000000..49f59b99 --- /dev/null +++ b/internal/use-case/simgos-sync-use-case/seeder/seeder/seeder.go @@ -0,0 +1,94 @@ +package seeder + +import ( + "log" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/doctor" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/nurse" + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder/regular" + + db "simrs-vx/pkg/dualtrx-helper" + pl "simrs-vx/pkg/logger" + + d "github.com/karincake/dodol" + + el "simrs-vx/internal/domain/simgos-entities/m-login" + + "simrs-vx/internal/use-case/simgos-sync-use-case/seeder" +) + +const source = "seeder" + +func SeedToSimx(input seeder.Dto) (*d.Data, error) { + event := pl.Event{ + Feature: "Seeder", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "create") + + var ( + tx = db.NewTx() + mlogin, regLogin []el.MLogin + kddokter, kdperawat []uint + ) + + // Get M_login + err := tx.Simgos.Model(&el.MLogin{}). + Select(`DISTINCT ON (nip) m_login.*`). + Where(`"nip" IN (?)`, input.LoginNip). + Find(&mlogin).Error + if err != nil { + log.Println("Error Querying Mlogin:", err) + return nil, err + } + + // SET data + if len(mlogin) > 0 { + for _, l := range mlogin { + if l.KdDokter != 0 { + kddokter = append(kddokter, l.KdDokter) + continue + } + + if l.KdPerawat != 0 { + kdperawat = append(kdperawat, l.KdPerawat) + continue + } + + regLogin = append(regLogin, l) + } + } + + // Seed based on role + if len(kddokter) > 0 { + err = doctor.SeedDoctor(kddokter, &event, tx) + if err != nil { + return nil, err + } + } + + if len(kdperawat) > 0 { + err = nurse.SeedNurse(kdperawat, &event, tx) + if err != nil { + return nil, err + } + } + + if len(regLogin) > 0 { + err = regular.SeedRegular(regLogin, input.Instalasi_Code) + if err != nil { + return nil, err + } + } + + pl.SetLogInfo(&event, nil, "complete") + + return &d.Data{ + Meta: d.II{ + "source": source, + "structure": "single-data", + "status": "created", + }, + }, nil +} From 67383eefdf7d36cf44d994f540c12a8902a0a9a6 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 11 Dec 2025 15:30:49 +0700 Subject: [PATCH 33/39] bacot tlas atlas --- cmd/main-migration/migrations/atlas.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index ca21de20..25211a51 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:nDEuOqs0hKLyxdzKDcaNhEkrmnmbm6o/jgoGigw47bo= +h1:HeGpsrE/VDqya82E/FdZsVTRliIgCVvytMqVWlRiLl8= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -160,4 +160,4 @@ h1:nDEuOqs0hKLyxdzKDcaNhEkrmnmbm6o/jgoGigw47bo= 20251209064304.sql h1:Xs73yQbuJvuQ0OnW1FAZpeytmUl/bGTlJFrwGOsTF4w= 20251209070128.sql h1:fPGE6xOV6uCiVOqnvwn2L/GsBbgp2wxgmZOhF3bSGGM= 20251209084929.sql h1:u4LPMvkGAH4RfGC2IlBTIm7T7paMHoBSvTQ0w5Br7d0= -20251210145148.sql h1:EWbK5f1QKyhaVsKZfJFunmQuw22Msl0Ox3KQ/uag2bw= +20251210145148.sql h1:rejGrnTpaygxPv06v0vxMytF4rk1OJBXaw3ttSmidgc= From 355f773fece8609d070f9715cf885c48b2cdf61e Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 11 Dec 2025 15:40:07 +0700 Subject: [PATCH 34/39] feat/dockerize: added assets --- Dockerfile-main-api | 1 + Dockerfile-simgos-sync-api | 1 + 2 files changed, 2 insertions(+) diff --git a/Dockerfile-main-api b/Dockerfile-main-api index 0c75acfa..ea038869 100644 --- a/Dockerfile-main-api +++ b/Dockerfile-main-api @@ -7,6 +7,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o ./cmd/main-api/main-api ./cmd/main-api/ FROM alpine:latest WORKDIR /app +COPY --from=builder /src/assets . COPY --from=builder /src/cmd/main-api/main-api . COPY --from=builder /src/cmd/main-api/config.yml . EXPOSE 8000 diff --git a/Dockerfile-simgos-sync-api b/Dockerfile-simgos-sync-api index 35660a2f..efb675db 100644 --- a/Dockerfile-simgos-sync-api +++ b/Dockerfile-simgos-sync-api @@ -7,6 +7,7 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o ./cmd/simgos-sync-api/simgos-sync-api . FROM alpine:latest WORKDIR /app +COPY --from=builder /src/assets . COPY --from=builder /src/cmd/simgos-sync-api/simgos-sync-api . COPY --from=builder /src/cmd/simgos-sync-api/config.yml . EXPOSE 8000 From 741b5069ec6ca836e4a0a4fffca757f474b6e18c Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 11 Dec 2025 15:29:01 +0700 Subject: [PATCH 35/39] feat (encounter): create-with-patient wip --- .../domain/main-entities/encounter/dto.go | 5 + .../main-handler/encounter/handler.go | 26 ++++ .../interface/main-handler/main-handler.go | 1 + .../use-case/main-use-case/encounter/case.go | 143 ++++++++++++++++++ .../encounter/middleware-runner.go | 19 +++ .../main-use-case/encounter/tycovar.go | 7 + .../use-case/main-use-case/patient/case.go | 27 ++-- 7 files changed, 218 insertions(+), 10 deletions(-) diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 324501e4..9265978b 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -297,3 +297,8 @@ func ToResponseList(data []Encounter) []ResponseDto { } return resp } + +type CreateWithPatientDto struct { + Encounter CreateDto `json:"encounter"` + Patient ep.CreateDto `json:"patient"` +} diff --git a/internal/interface/main-handler/encounter/handler.go b/internal/interface/main-handler/encounter/handler.go index 7ac31393..c6a02ba9 100644 --- a/internal/interface/main-handler/encounter/handler.go +++ b/internal/interface/main-handler/encounter/handler.go @@ -312,3 +312,29 @@ func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) { res, err := u.CancelSwitchUnit(dto) rw.DataResponse(w, res, err) } + +func (obj myBase) CreateWithPatient(w http.ResponseWriter, r *http.Request) { + authInfo, err := pa.GetAuthInfo(r) + if err != nil { + rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil) + } + + dto := e.CreateWithPatientDto{} + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + + // validate SubClass + if err := verifyClassCode(dto.Encounter); err != nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: err.Error(), + }) + return + } + + dto.Encounter.AuthInfo = *authInfo + dto.Patient.AuthInfo = *authInfo + res, err := u.CreateWithPatient(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 f6f6bfce..c47ae37d 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -197,6 +197,7 @@ func SetRoutes() http.Handler { "PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit, "PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit, "PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchUnit, + "POST /create-with-patient": encounter.O.CreateWithPatient, }) hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{ "GET /": mcuorder.O.GetList, diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 62a7c992..3b966ef9 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -22,12 +22,14 @@ import ( edc "simrs-vx/internal/domain/main-entities/death-cause" e "simrs-vx/internal/domain/main-entities/encounter" eir "simrs-vx/internal/domain/main-entities/internal-reference" + ep "simrs-vx/internal/domain/main-entities/patient" es "simrs-vx/internal/domain/main-entities/soapi" esync "simrs-vx/internal/domain/sync-entities/log" uv "simrs-vx/internal/use-case/bpjs-use-case/vclaim-reference" udc "simrs-vx/internal/use-case/main-use-case/death-cause" uir "simrs-vx/internal/use-case/main-use-case/internal-reference" + up "simrs-vx/internal/use-case/main-use-case/patient" us "simrs-vx/internal/use-case/main-use-case/soapi" ) @@ -1075,3 +1077,144 @@ func validateAuth(a auth.AuthInfo, roleAllowed []string, action string, event *p return nil } + +func CreateWithPatient(input e.CreateWithPatientDto) (*d.Data, error) { + var ( + data e.Encounter + recentSoapiDataforCopy []es.CreateDto + err error + ) + + event := pl.Event{ + Feature: "Create", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "create") + + roleAllowed := []string{string(erg.EPCReg)} + err = validateAuth(input.Encounter.AuthInfo, roleAllowed, "create-encounter", &event) + if err != nil { + return nil, err + } + + // validate rehab by bpjs + if input.Encounter.RefTypeCode == ere.RTCBpjs && + input.Encounter.Class_Code == ere.ECAmbulatory && + ere.AmbulatoryClassCode(*input.Encounter.SubClass_Code) == ere.ACCRehab { + // get latest rehab data + recentRehabData, err := getLatestRehabData(input.Encounter, &event) + if err != nil { + return nil, err + } + + // If recentRehabData is nil, then visitMode_Code = "adm" + if recentRehabData != nil { + // If recentRehabData is not nil, determine the visitMode_Code: + // If the mode is "series", verify whether the visit count still remains + // and whether the series has not expired. + // If visitMode is "series", then get encounterAdm + input.Encounter.VisitMode_Code, input.Encounter.RecentEncounterAdm, err = determineVisitMode(recentRehabData, input.Encounter, &event) + if err != nil { + return nil, err + } + } else { + input.Encounter.VisitMode_Code = ere.VMCAdm + } + + // When visitMode_Code is "series", load the associated SOAPI record to copy its values. + if input.Encounter.VisitMode_Code == ere.VMCSeries { + // get data soapi + recentSoapiDataforCopy, err = getSoapiEncounterAdm(*input.Encounter.RecentEncounterAdm, &event) + if err != nil { + return nil, err + } + } + } + + // check if patient is new in the hospital + input.Encounter.NewStatus, err = identifyPatientStatus(input.Encounter) + if err != nil { + return nil, err + } + input.Encounter.Adm_Employee_Id = input.Encounter.AuthInfo.Employee_Id + + mwRunner := newMiddlewareRunner(&event, input.Encounter.Sync) + + err = dg.I.Transaction(func(tx *gorm.DB) error { + // create patient + var patientId uint + patientData, err := up.Create(input.Patient, tx) + if err != nil { + return err + } + + if patientData != nil { + patientId = patientData.Data.(*ep.Patient).Id + } + + // create encounter + input.Encounter.Patient_Id = &patientId + if resData, err := CreateData(input.Encounter, &event, tx); err != nil { + return err + } else { + data = *resData + input.Encounter.Id = data.Id + } + + // insert ambulatory/emergency/inpatient + err = insertdataClassCode(input.Encounter, recentSoapiDataforCopy, &event, tx) + if err != nil { + return err + } + + // insert vclaimReference + if vr := input.Encounter.VclaimReference; vr != nil { + t, _ := time.Parse("2006-01-02", vr.TglRujukan) + _, err = uv.CreateData(ev.CreateDto{ + Encounter_Id: &data.Id, + Date: &t, + SrcCode: input.Encounter.Ref_Number, + SrcName: input.Encounter.RefSource_Name, + Number: &vr.NoSep}, &event, tx) + if err != nil { + return err + } + } + + dataEncounter, err := ReadDetailData(e.ReadDetailDto{ + Id: data.Id, + Includes: "Adm_Employee.User,Adm_Employee.Person," + + "Patient.Person.Relatives," + + "Patient.Person.VclaimMember,VclaimReference," + + "Patient.Person.Contacts,Patient.Person.Addresses"}, + &event, tx) + if err != nil { + return err + } + + mwRunner.setMwType(pu.MWTPre) + // Run pre-middleware + if err := mwRunner.RunCreateWithPatientMiddleware(createWithPatientPreMw, dataEncounter); err != nil { + return err + } + + return nil + }) + + if err = runLogMiddleware(err, input, mwRunner); err != nil { + return nil, err + } + + pl.SetLogInfo(&event, nil, "complete") + + return &d.Data{ + Meta: d.II{ + "source": source, + "structure": "single-data", + "status": "created", + }, + Data: data.ToResponse(), + }, nil +} diff --git a/internal/use-case/main-use-case/encounter/middleware-runner.go b/internal/use-case/main-use-case/encounter/middleware-runner.go index da62fdb6..3ee19355 100644 --- a/internal/use-case/main-use-case/encounter/middleware-runner.go +++ b/internal/use-case/main-use-case/encounter/middleware-runner.go @@ -259,3 +259,22 @@ func (me *middlewareRunner) RunCancelSwitchUnitMiddleware(middleware cancelSwitc func (me *middlewareRunner) setMwType(mwType pu.MWType) { me.MwType = mwType } + +func (me *middlewareRunner) RunCreateWithPatientMiddleware(middlewares []createWithPatientMw, input *e.Encounter) error { + if !me.SyncOn { + return nil + } + + for _, middleware := range middlewares { + logData := pu.GetLogData(input, nil) + + pl.SetLogInfo(me.Event, logData, "started", middleware.Name) + + if err := middleware.Func(input); err != nil { + return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err) + } + + pl.SetLogInfo(me.Event, nil, "complete") + } + return nil +} diff --git a/internal/use-case/main-use-case/encounter/tycovar.go b/internal/use-case/main-use-case/encounter/tycovar.go index 2b268378..376baed8 100644 --- a/internal/use-case/main-use-case/encounter/tycovar.go +++ b/internal/use-case/main-use-case/encounter/tycovar.go @@ -74,6 +74,11 @@ type cancelSwitchUnitMw struct { Func func(input *e.ApproveCancelUnitDto) error } +type createWithPatientMw struct { + Name string + Func func(input *e.Encounter) error +} + type UpdateMw = updateMw type DeleteMw = deleteMw @@ -94,3 +99,5 @@ var updatestatusEncounter []updateStatusMw var requestSwitchEncounter requestSwitchUnitMw var approveSwitchEncounter approveSwitchUnitMw var cancelSwitchEncounter cancelSwitchUnitMw +var createWithPatientPreMw []createWithPatientMw +var createWithPatientPostMw []createWithPatientMw diff --git a/internal/use-case/main-use-case/patient/case.go b/internal/use-case/main-use-case/patient/case.go index 5180137b..ec518fe4 100644 --- a/internal/use-case/main-use-case/patient/case.go +++ b/internal/use-case/main-use-case/patient/case.go @@ -27,7 +27,7 @@ import ( const source = "patient" -func Create(input e.CreateDto) (*d.Data, error) { +func Create(input e.CreateDto, dbx ...*gorm.DB) (*d.Data, error) { data := e.Patient{} event := pl.Event{ @@ -35,6 +35,13 @@ func Create(input e.CreateDto) (*d.Data, error) { Source: source, } + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + // Start log pl.SetLogInfo(&event, input, "started", "create") mwRunner := newMiddlewareRunner(&event, input.Sync) @@ -51,7 +58,7 @@ func Create(input e.CreateDto) (*d.Data, error) { input.RegisteredBy_User_Name = &input.AuthInfo.User_Name - err := dg.I.Transaction(func(tx *gorm.DB) error { + err := tx.Transaction(func(tx1 *gorm.DB) error { mwRunner.setMwType(pu.MWTPre) // Run pre-middleware if err := mwRunner.RunCreateMiddleware(createPreMw, &input, &data); err != nil { @@ -65,14 +72,14 @@ func Create(input e.CreateDto) (*d.Data, error) { } input.Number = nomr - if person_id, err := upe.CreateOrUpdatePerson(input.Person, &event, tx); err != nil { + if person_id, err := upe.CreateOrUpdatePerson(input.Person, &event, tx1); err != nil { return err } else { input.Person_Id = person_id } if input.Person.VclaimMember_CardNumber != nil && input.Person.ResidentIdentityNumber != nil { - if err := uvm.CreateOrUpdateData(evm.CreateDto{CardNumber: input.Person.VclaimMember_CardNumber, Person_Id: input.Person_Id}, &event, tx); err != nil { + if err := uvm.CreateOrUpdateData(evm.CreateDto{CardNumber: input.Person.VclaimMember_CardNumber, Person_Id: input.Person_Id}, &event, tx1); err != nil { return err } } @@ -80,38 +87,38 @@ func Create(input e.CreateDto) (*d.Data, error) { for idx := range input.PersonAddresses { input.PersonAddresses[idx].Person_Id = *input.Person_Id } - if err := upa.CreateOrUpdateBatch(input.PersonAddresses, &event, tx); err != nil { + if err := upa.CreateOrUpdateBatch(input.PersonAddresses, &event, tx1); err != nil { return err } for idx := range input.PersonContacts { input.PersonContacts[idx].Person_Id = *input.Person_Id } - if err := upc.CreateOrUpdateBatch(input.PersonContacts, &event, tx); err != nil { + if err := upc.CreateOrUpdateBatch(input.PersonContacts, &event, tx1); err != nil { return err } for idx := range input.PersonRelatives { input.PersonRelatives[idx].Person_Id = *input.Person_Id } - if err := upr.CreateOrUpdateBatch(input.PersonRelatives, &event, tx); err != nil { + if err := upr.CreateOrUpdateBatch(input.PersonRelatives, &event, tx1); err != nil { return err } for idx := range input.PersonInsurances { input.PersonInsurances[idx].Person_Id = *input.Person_Id } - if err := upi.CreateOrUpdateBatch(input.PersonInsurances, &event, tx); err != nil { + if err := upi.CreateOrUpdateBatch(input.PersonInsurances, &event, tx1); err != nil { return err } - if resData, err := CreateData(input, &event, tx); err != nil { + if resData, err := CreateData(input, &event, tx1); err != nil { return err } else { data = *resData } - dataPatient, err := ReadDetailData(e.ReadDetailDto{Id: uint16(data.Id)}, &event, tx) + dataPatient, err := ReadDetailData(e.ReadDetailDto{Id: uint16(data.Id)}, &event, tx1) if err != nil { return err } From 079294a66e278e14c06c723bbf1f160ce531ce29 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 11 Dec 2025 15:51:55 +0700 Subject: [PATCH 36/39] feat (encounter): create-with-patient done, tested with positif case only --- internal/use-case/main-use-case/encounter/case.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 3b966ef9..b4001156 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -1151,7 +1151,7 @@ func CreateWithPatient(input e.CreateWithPatientDto) (*d.Data, error) { } if patientData != nil { - patientId = patientData.Data.(*ep.Patient).Id + patientId = patientData.Data.(ep.ResponseDto).Id } // create encounter From 8dd427d3f7fb1b76757756ba0d91daca34a9ff31 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 11 Dec 2025 16:43:14 +0700 Subject: [PATCH 37/39] dev: chore, moved Dockerfile* to example --- .gitignore | 2 ++ Dockerfile-main-api => Dockerfile-main-api-example | 2 +- Dockerfile-simgos-sync-api => Dockerfile-sync-api-example | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) rename Dockerfile-main-api => Dockerfile-main-api-example (96%) rename Dockerfile-simgos-sync-api => Dockerfile-sync-api-example (97%) diff --git a/.gitignore b/.gitignore index 7800ac94..4c10eb38 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,8 @@ go.work.sum # env file .env config.yml +Dockerfile-main-api +Dockerfile-sync-api **/atlas.hcl !**/atlas.hcl.example diff --git a/Dockerfile-main-api b/Dockerfile-main-api-example similarity index 96% rename from Dockerfile-main-api rename to Dockerfile-main-api-example index ea038869..cb8839b9 100644 --- a/Dockerfile-main-api +++ b/Dockerfile-main-api-example @@ -10,5 +10,5 @@ WORKDIR /app COPY --from=builder /src/assets . COPY --from=builder /src/cmd/main-api/main-api . COPY --from=builder /src/cmd/main-api/config.yml . -EXPOSE 8000 +EXPOSE 8010 CMD ["./main-api"] diff --git a/Dockerfile-simgos-sync-api b/Dockerfile-sync-api-example similarity index 97% rename from Dockerfile-simgos-sync-api rename to Dockerfile-sync-api-example index efb675db..5b32d522 100644 --- a/Dockerfile-simgos-sync-api +++ b/Dockerfile-sync-api-example @@ -10,5 +10,5 @@ WORKDIR /app COPY --from=builder /src/assets . COPY --from=builder /src/cmd/simgos-sync-api/simgos-sync-api . COPY --from=builder /src/cmd/simgos-sync-api/config.yml . -EXPOSE 8000 +EXPOSE 8011 CMD ["./simgos-sync-api"] From ed19aa7d599aaf7c22c2d12c206412c60493ad5f Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Thu, 11 Dec 2025 17:51:08 +0700 Subject: [PATCH 38/39] refactor/unit-dropping: done --- .../migrations/20251211101547.sql | 36 +++ cmd/main-migration/migrations/atlas.sum | 3 +- internal/domain/main-entities/chemo/dto.go | 19 +- internal/domain/main-entities/chemo/entity.go | 6 +- .../domain/main-entities/consultation/dto.go | 54 ++-- .../main-entities/consultation/entity.go | 16 +- .../main-entities/control-letter/dto.go | 5 - .../main-entities/control-letter/entity.go | 3 - internal/domain/main-entities/doctor/dto.go | 5 - .../domain/main-entities/doctor/entity.go | 3 - .../domain/main-entities/encounter/dto.go | 12 +- .../domain/main-entities/encounter/entity.go | 3 - .../main-entities/internal-reference/dto.go | 48 +-- .../internal-reference/entity.go | 26 +- internal/domain/main-entities/nurse/dto.go | 54 ++-- internal/domain/main-entities/nurse/entity.go | 20 +- .../main-entities/practice-schedule/dto.go | 40 +-- .../main-entities/practice-schedule/entity.go | 18 +- .../procedure-room/base/entity.go | 1 - .../main-entities/procedure-room/dto.go | 7 - .../main-entities/procedure-room/entity.go | 2 - .../domain/main-entities/specialist/dto.go | 20 +- .../domain/main-entities/specialist/entity.go | 16 +- .../unit-position/base/entity.go | 20 -- .../domain/main-entities/unit-position/dto.go | 85 ----- .../main-entities/unit-position/entity.go | 11 - internal/domain/main-entities/unit/dto.go | 82 ----- internal/domain/main-entities/unit/entity.go | 18 -- .../main-handler/encounter/handler.go | 20 +- .../encounter/request-validation.go | 4 +- .../interface/main-handler/main-handler.go | 10 +- .../main-handler/unit-position/handler.go | 71 ---- .../interface/main-handler/unit/handler.go | 73 ----- internal/interface/migration/main-entities.go | 4 - .../new/encounter/handler.go | 16 +- .../simgos-sync-handler/new/unit/handler.go | 67 ---- .../simgos-sync-handler.go | 8 +- .../main-use-case/authentication/helper.go | 40 +-- .../use-case/main-use-case/chemo/helper.go | 2 +- .../main-use-case/consultation/case.go | 4 +- .../main-use-case/consultation/helper.go | 2 +- .../main-use-case/control-letter/helper.go | 1 - .../use-case/main-use-case/doctor/helper.go | 1 - .../use-case/main-use-case/encounter/case.go | 32 +- .../main-use-case/encounter/helper.go | 24 +- .../use-case/main-use-case/encounter/lib.go | 8 +- .../encounter/middleware-runner.go | 6 +- .../main-use-case/encounter/middleware.go | 6 +- .../main-use-case/encounter/tycovar.go | 16 +- .../use-case/main-use-case/infra/helper.go | 1 - .../internal-reference/helper.go | 16 +- .../main-use-case/internal-reference/lib.go | 2 +- .../use-case/main-use-case/nurse/helper.go | 2 +- .../main-use-case/practice-schedule/helper.go | 2 +- .../main-use-case/procedure-room/helper.go | 1 - .../main-use-case/specialist/helper.go | 2 +- .../main-use-case/unit-position/case.go | 302 ------------------ .../main-use-case/unit-position/helper.go | 25 -- .../main-use-case/unit-position/lib.go | 156 --------- .../unit-position/middleware-runner.go | 103 ------ .../main-use-case/unit-position/middleware.go | 9 - .../main-use-case/unit-position/tycovar.go | 44 --- internal/use-case/main-use-case/unit/case.go | 280 ---------------- .../use-case/main-use-case/unit/helper.go | 23 -- internal/use-case/main-use-case/unit/lib.go | 149 --------- .../main-use-case/unit/middleware-runner.go | 148 --------- .../use-case/main-use-case/unit/middleware.go | 20 -- .../use-case/main-use-case/unit/tycovar.go | 61 ---- internal/use-case/main-use-case/user/case.go | 21 +- .../new/encounter/plugin.go | 6 +- .../simgos-sync-plugin/new/unit/plugin.go | 37 --- .../use-case/simgos-sync-plugin/old/.keep | 0 .../new/encounter/case.go | 18 +- .../new/encounter/helper.go | 4 +- .../new/internal-reference/helper.go | 6 +- .../new/internal-reference/lib.go | 2 +- .../simgos-sync-use-case/new/unit/case.go | 198 ------------ .../simgos-sync-use-case/new/unit/helper.go | 62 ---- .../simgos-sync-use-case/new/unit/lib.go | 188 ----------- .../new/unit/middleware-runner.go | 104 ------ .../new/unit/middleware.go | 9 - .../simgos-sync-use-case/new/unit/tycovar.go | 44 --- 82 files changed, 329 insertions(+), 2764 deletions(-) create mode 100644 cmd/main-migration/migrations/20251211101547.sql delete mode 100644 internal/domain/main-entities/unit-position/base/entity.go delete mode 100644 internal/domain/main-entities/unit-position/dto.go delete mode 100644 internal/domain/main-entities/unit-position/entity.go delete mode 100644 internal/domain/main-entities/unit/dto.go delete mode 100644 internal/domain/main-entities/unit/entity.go delete mode 100644 internal/interface/main-handler/unit-position/handler.go delete mode 100644 internal/interface/main-handler/unit/handler.go delete mode 100644 internal/interface/simgos-sync-handler/new/unit/handler.go delete mode 100644 internal/use-case/main-use-case/unit-position/case.go delete mode 100644 internal/use-case/main-use-case/unit-position/helper.go delete mode 100644 internal/use-case/main-use-case/unit-position/lib.go delete mode 100644 internal/use-case/main-use-case/unit-position/middleware-runner.go delete mode 100644 internal/use-case/main-use-case/unit-position/middleware.go delete mode 100644 internal/use-case/main-use-case/unit-position/tycovar.go delete mode 100644 internal/use-case/main-use-case/unit/case.go delete mode 100644 internal/use-case/main-use-case/unit/helper.go delete mode 100644 internal/use-case/main-use-case/unit/lib.go delete mode 100644 internal/use-case/main-use-case/unit/middleware-runner.go delete mode 100644 internal/use-case/main-use-case/unit/middleware.go delete mode 100644 internal/use-case/main-use-case/unit/tycovar.go delete mode 100644 internal/use-case/simgos-sync-plugin/new/unit/plugin.go create mode 100644 internal/use-case/simgos-sync-plugin/old/.keep delete mode 100644 internal/use-case/simgos-sync-use-case/new/unit/case.go delete mode 100644 internal/use-case/simgos-sync-use-case/new/unit/helper.go delete mode 100644 internal/use-case/simgos-sync-use-case/new/unit/lib.go delete mode 100644 internal/use-case/simgos-sync-use-case/new/unit/middleware-runner.go delete mode 100644 internal/use-case/simgos-sync-use-case/new/unit/middleware.go delete mode 100644 internal/use-case/simgos-sync-use-case/new/unit/tycovar.go diff --git a/cmd/main-migration/migrations/20251211101547.sql b/cmd/main-migration/migrations/20251211101547.sql new file mode 100644 index 00000000..c24aab8d --- /dev/null +++ b/cmd/main-migration/migrations/20251211101547.sql @@ -0,0 +1,36 @@ +-- Modify "Specialist" table +ALTER TABLE "public"."Specialist" DROP COLUMN "Unit_Code"; +-- Rename a column from "SrcUnit_Code" to "Specialist_Code" +ALTER TABLE "public"."Chemo" RENAME COLUMN "SrcUnit_Code" TO "Specialist_Code"; +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" DROP CONSTRAINT "fk_Chemo_SrcUnit", ADD CONSTRAINT "fk_Chemo_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Doctor" table +ALTER TABLE "public"."Doctor" DROP COLUMN "Unit_Code"; +-- Rename a column from "DstUnit_Code" to "Specialist_Code" +ALTER TABLE "public"."Consultation" RENAME COLUMN "DstUnit_Code" TO "Specialist_Code"; +-- Rename a column from "DstDoctor_Code" to "Doctor_Code" +ALTER TABLE "public"."Consultation" RENAME COLUMN "DstDoctor_Code" TO "Doctor_Code"; +-- Modify "Consultation" table +ALTER TABLE "public"."Consultation" DROP CONSTRAINT "fk_Consultation_DstDoctor", DROP CONSTRAINT "fk_Consultation_DstUnit", ADD CONSTRAINT "fk_Consultation_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Consultation_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Rename a column from "Unit_Code" to "Specialist_Code" +ALTER TABLE "public"."InternalReference" RENAME COLUMN "Unit_Code" TO "Specialist_Code"; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" DROP CONSTRAINT "fk_InternalReference_Unit", ADD CONSTRAINT "fk_InternalReference_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Rename a column from "Unit_Code" to "Specialist_Code" +ALTER TABLE "public"."Nurse" RENAME COLUMN "Unit_Code" TO "Specialist_Code"; +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" DROP CONSTRAINT "fk_Nurse_Unit", ADD CONSTRAINT "fk_Nurse_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Rename a column from "Unit_Code" to "Specialist_Code" +ALTER TABLE "public"."PracticeSchedule" RENAME COLUMN "Unit_Code" TO "Specialist_Code"; +-- Modify "PracticeSchedule" table +ALTER TABLE "public"."PracticeSchedule" DROP CONSTRAINT "fk_PracticeSchedule_Unit", ADD CONSTRAINT "fk_PracticeSchedule_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ControlLetter" table +ALTER TABLE "public"."ControlLetter" DROP COLUMN "Unit_Code"; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" DROP COLUMN "Unit_Code"; +-- Modify "ProcedureRoom" table +ALTER TABLE "public"."ProcedureRoom" DROP COLUMN "Unit_Code"; +-- Drop "UnitPosition" table +DROP TABLE "public"."UnitPosition"; +-- Drop "Unit" table +DROP TABLE "public"."Unit"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 25211a51..40d1acc3 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:HeGpsrE/VDqya82E/FdZsVTRliIgCVvytMqVWlRiLl8= +h1:B4Ghh1AyZG5WD/79iuFWUIRiik0xl2zgtiWRWJ/prTU= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -161,3 +161,4 @@ h1:HeGpsrE/VDqya82E/FdZsVTRliIgCVvytMqVWlRiLl8= 20251209070128.sql h1:fPGE6xOV6uCiVOqnvwn2L/GsBbgp2wxgmZOhF3bSGGM= 20251209084929.sql h1:u4LPMvkGAH4RfGC2IlBTIm7T7paMHoBSvTQ0w5Br7d0= 20251210145148.sql h1:rejGrnTpaygxPv06v0vxMytF4rk1OJBXaw3ttSmidgc= +20251211101547.sql h1:rRb5Azkx3yvOYIGIXiuAYU26gviETwWarfAaiQY+FLk= diff --git a/internal/domain/main-entities/chemo/dto.go b/internal/domain/main-entities/chemo/dto.go index 461203d2..fa3bd8a5 100644 --- a/internal/domain/main-entities/chemo/dto.go +++ b/internal/domain/main-entities/chemo/dto.go @@ -2,7 +2,7 @@ package chemo import ( ed "simrs-vx/internal/domain/main-entities/doctor" - // std + es "simrs-vx/internal/domain/main-entities/specialist" "time" // internal - lib @@ -14,14 +14,13 @@ import ( // internal - domain - main-entities ecore "simrs-vx/internal/domain/base-entities/core" ee "simrs-vx/internal/domain/main-entities/encounter" - eun "simrs-vx/internal/domain/main-entities/unit" eus "simrs-vx/internal/domain/main-entities/user" ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Status_Code erc.DataVerifiedCode `json:"status_code"` - SrcUnit_Code *string `json:"srcUnit_code"` + Encounter_Id *uint `json:"encounter_id"` + Status_Code erc.DataVerifiedCode `json:"status_code"` + Specialist_Code *string `json:"specialist_code"` } type ReadListDto struct { @@ -34,7 +33,7 @@ type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` Status_Code *erc.DataVerifiedCode `json:"status-code"` VerifiedBy_User_Id *uint `json:"verifiedBy-user-id"` - SrcUnit_Code *string `json:"srcUnit-code"` + Specialist_Code *string `json:"specialist-code"` } type ReadDetailDto struct { @@ -75,8 +74,8 @@ type ResponseDto struct { VerifiedAt *time.Time `json:"verifiedAt"` VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty"` - SrcUnit_Code *string `json:"srcUnit_code"` - SrcUnit *eun.Unit `json:"srcUnit,omitempty"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` NextChemoDate *time.Time `json:"nextChemoDate"` @@ -90,8 +89,8 @@ func (d Chemo) ToResponse() ResponseDto { VerifiedAt: d.VerifiedAt, VerifiedBy_User_Id: d.VerifiedBy_User_Id, VerifiedBy: d.VerifiedBy, - SrcUnit_Code: d.SrcUnit_Code, - SrcUnit: d.SrcUnit, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, NextChemoDate: d.NextChemoDate, diff --git a/internal/domain/main-entities/chemo/entity.go b/internal/domain/main-entities/chemo/entity.go index cc828835..b9aa58fd 100644 --- a/internal/domain/main-entities/chemo/entity.go +++ b/internal/domain/main-entities/chemo/entity.go @@ -9,7 +9,7 @@ import ( ed "simrs-vx/internal/domain/main-entities/doctor" ee "simrs-vx/internal/domain/main-entities/encounter" - eun "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" eus "simrs-vx/internal/domain/main-entities/user" ) @@ -21,8 +21,8 @@ type Chemo struct { VerifiedAt *time.Time `json:"verifiedAt"` VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty" gorm:"foreignKey:VerifiedBy_User_Id;references:Id"` - SrcUnit_Code *string `json:"src_unit_code"` // klinik asal - SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Code;references:Code"` + Specialist_Code *string `json:"specialist_code"` // klinik asal + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Bed *string `json:"bed" gorm:"size:1024"` Needs *string `json:"needs" gorm:"size:2048"` Doctor_Code *string `json:"doctor_code"` diff --git a/internal/domain/main-entities/consultation/dto.go b/internal/domain/main-entities/consultation/dto.go index 1b83df77..6f4740c8 100644 --- a/internal/domain/main-entities/consultation/dto.go +++ b/internal/domain/main-entities/consultation/dto.go @@ -13,14 +13,14 @@ import ( // internal - domain - main-entities ed "simrs-vx/internal/domain/main-entities/doctor" ee "simrs-vx/internal/domain/main-entities/encounter" - eu "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Date *time.Time `json:"date"` - Problem *string `json:"problem" validate:"maxLength=10240"` - DstUnit_Code *string `json:"dstUnit_code"` + Encounter_Id *uint `json:"encounter_id"` + Date *time.Time `json:"date"` + Problem *string `json:"problem" validate:"maxLength=10240"` + Specialist_Code *string `json:"dstSpecialist_code"` } type ReadListDto struct { @@ -30,9 +30,9 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - DstUnit_Code *string `json:"dstUnit-code"` - DstDoctor_Code *string `json:"dstDoctor-code"` + Encounter_Id *uint `json:"encounter-id"` + Specialist_Code *string `json:"dstSpecialist-code"` + Doctor_Code *string `json:"doctor-code"` } type ReadDetailDto struct { @@ -63,29 +63,29 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Date *time.Time `json:"date"` - Problem *string `json:"problem"` - Solution *string `json:"solution"` - DstUnit_Code *string `json:"dstUnit_code"` - DstUnit *eu.Unit `json:"dstUnit,omitempty"` - DstDoctor_Code *string `json:"dstDoctor_code"` - DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"` - RepliedAt *time.Time `json:"repliedAt"` + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Date *time.Time `json:"date"` + Problem *string `json:"problem"` + Solution *string `json:"solution"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + RepliedAt *time.Time `json:"repliedAt"` } func (d Consultation) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Encounter: d.Encounter, - Date: d.Date, - Problem: d.Problem, - Solution: d.Solution, - DstUnit_Code: d.DstUnit_Code, - DstUnit: d.DstUnit, - DstDoctor_Code: d.DstDoctor_Code, - DstDoctor: d.DstDoctor, + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Date: d.Date, + Problem: d.Problem, + Solution: d.Solution, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Doctor_Code: d.Doctor_Code, + Doctor: d.Doctor, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/consultation/entity.go b/internal/domain/main-entities/consultation/entity.go index b8be3596..95ba2512 100644 --- a/internal/domain/main-entities/consultation/entity.go +++ b/internal/domain/main-entities/consultation/entity.go @@ -6,7 +6,7 @@ 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" - eu "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" ) type Consultation struct { @@ -15,11 +15,11 @@ type Consultation struct { Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` Date *time.Time `json:"date"` - Problem *string `json:"case" gorm:"size:10240"` - Solution *string `json:"solution" gorm:"size:10240"` - DstUnit_Code *string `json:"dstUnit_code"` - DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Code;references:Code"` - DstDoctor_Code *string `json:"dstDoctor_code"` - DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Code;references:Code"` - RepliedAt *time.Time `json:"repliedAt"` + Problem *string `json:"case" gorm:"size:10240"` + Solution *string `json:"solution" gorm:"size:10240"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Code;references:Code"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Code;references:Code"` + RepliedAt *time.Time `json:"repliedAt"` } diff --git a/internal/domain/main-entities/control-letter/dto.go b/internal/domain/main-entities/control-letter/dto.go index 87b82366..18f8020f 100644 --- a/internal/domain/main-entities/control-letter/dto.go +++ b/internal/domain/main-entities/control-letter/dto.go @@ -15,7 +15,6 @@ import ( ee "simrs-vx/internal/domain/main-entities/encounter" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" - eu "simrs-vx/internal/domain/main-entities/unit" ) type CreateDto struct { @@ -66,8 +65,6 @@ type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,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"` @@ -81,8 +78,6 @@ func (d ControlLetter) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, Encounter: d.Encounter, - Unit_Code: d.Unit_Code, - Unit: d.Unit, Specialist_Code: d.Specialist_Code, Specialist: d.Specialist, Subspecialist_Code: d.Subspecialist_Code, diff --git a/internal/domain/main-entities/control-letter/entity.go b/internal/domain/main-entities/control-letter/entity.go index 2b8019b4..e13f5940 100644 --- a/internal/domain/main-entities/control-letter/entity.go +++ b/internal/domain/main-entities/control-letter/entity.go @@ -8,15 +8,12 @@ import ( ee "simrs-vx/internal/domain/main-entities/encounter" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" - eu "simrs-vx/internal/domain/main-entities/unit" ) type ControlLetter struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Code;references:Code"` Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code"` diff --git a/internal/domain/main-entities/doctor/dto.go b/internal/domain/main-entities/doctor/dto.go index c7eb0f6b..9bcbc932 100644 --- a/internal/domain/main-entities/doctor/dto.go +++ b/internal/domain/main-entities/doctor/dto.go @@ -5,7 +5,6 @@ import ( ee "simrs-vx/internal/domain/main-entities/employee" 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" ) @@ -69,8 +68,6 @@ type ResponseDto struct { 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"` @@ -84,8 +81,6 @@ func (d Doctor) ToResponse() ResponseDto { 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, diff --git a/internal/domain/main-entities/doctor/entity.go b/internal/domain/main-entities/doctor/entity.go index 506271a2..f5797924 100644 --- a/internal/domain/main-entities/doctor/entity.go +++ b/internal/domain/main-entities/doctor/entity.go @@ -5,7 +5,6 @@ import ( ee "simrs-vx/internal/domain/main-entities/employee" 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" ) @@ -17,8 +16,6 @@ type Doctor struct { 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_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 9265978b..5dcf76db 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -30,7 +30,6 @@ import ( 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" ) type CreateDto struct { @@ -39,7 +38,6 @@ type CreateDto struct { Class_Code ere.EncounterClassCode `json:"class_code" validate:"maxLength=10"` SubClass_Code *string `json:"subClass_code" validate:"maxLength=10"` // for sub Infra_Code *string `json:"infra_code"` // for inpatient - Unit_Code *string `json:"unit_code"` Specialist_Code *string `json:"specialist_code"` Subspecialist_Code *string `json:"subspecialist_code"` VisitDate time.Time `json:"visitDate"` @@ -96,7 +94,7 @@ type ReadListDto struct { EndDate *string `json:"end-date"` PaymentMethod_Code *string `json:"paymentMethod-code"` Status_Code *string `json:"status-code"` - Unit_Code *string `json:"unit-code"` + Specialist_Code *string `json:"specialist-code"` pa.AuthInfo } @@ -170,7 +168,7 @@ type CheckinDto struct { pa.AuthInfo } -type SwitchUnitDto struct { +type SwitchSpecialistDto struct { Id uint `json:"id"` PolySwitchCode *ere.PolySwitchCode `json:"polySwitchCode"` InternalReferences *[]eir.CreateDto `json:"internalReferences" validate:"required"` @@ -180,7 +178,7 @@ type SwitchUnitDto struct { pa.AuthInfo } -type ApproveCancelUnitDto struct { +type ApproveCancelSpecialistDto struct { Id uint `json:"id"` InternalReferences_Id uint `json:"internalReferences_id" validate:"required"` Dst_Doctor_Code *string `json:"dst_doctor_code"` @@ -194,12 +192,10 @@ type ResponseDto struct { Patient *ep.Patient `json:"patient,omitempty"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code"` - Unit_Code *string `json:"unit_code"` Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty"` Subspecialist_Code *string `json:"subspecialist_code"` Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` - Unit *eu.Unit `json:"unit,omitempty"` VisitDate time.Time `json:"visitDate"` PaymentMethod_Code ere.AllPaymentMethodCode `json:"paymentMethod_code"` InsuranceCompany_Code *string `json:"insuranceCompany_code"` @@ -244,8 +240,6 @@ func (d Encounter) ToResponse() ResponseDto { Patient: d.Patient, RegisteredAt: d.RegisteredAt, Class_Code: d.Class_Code, - Unit_Code: d.Unit_Code, - Unit: d.Unit, Specialist_Code: d.Specialist_Code, Specialist: d.Specialist, Subspecialist_Code: d.Subspecialist_Code, diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index 0b1da159..6bdcfa0c 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -25,7 +25,6 @@ import ( 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" ) type Encounter struct { @@ -34,8 +33,6 @@ type Encounter struct { Patient *ep.Patient `json:"patient,omitempty" gorm:"foreignKey:Patient_Id;references:Id"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code" gorm:"not null;size:10"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code"` diff --git a/internal/domain/main-entities/internal-reference/dto.go b/internal/domain/main-entities/internal-reference/dto.go index d3771c4d..c2ceec18 100644 --- a/internal/domain/main-entities/internal-reference/dto.go +++ b/internal/domain/main-entities/internal-reference/dto.go @@ -5,17 +5,17 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" - eu "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" ) type CreateDto struct { - Encounter_Id *uint `json:"-"` - Unit_Code *string `json:"unit_code"` - Doctor_Code *string `json:"doctor_code"` - Nurse_Code *string `json:"nurse_code"` - Status_Code erc.DataApprovalCode `json:"status_code"` - SrcDoctor_Code *string `json:"srcDoctor_code"` - SrcNurse_Code *string `json:"srcNurse_code"` + Encounter_Id *uint `json:"-"` + Specialist_Code *string `json:"specialist_code"` + Doctor_Code *string `json:"doctor_code"` + Nurse_Code *string `json:"nurse_code"` + Status_Code erc.DataApprovalCode `json:"status_code"` + SrcDoctor_Code *string `json:"srcDoctor_code"` + SrcNurse_Code *string `json:"srcNurse_code"` } type ReadListDto struct { @@ -25,10 +25,10 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Unit_Code *uint `json:"unit-code"` - Doctor_Code *uint `json:"doctor-code"` - Status_Code erc.DataApprovalCode `json:"status-code"` + Encounter_Id *uint `json:"encounter-id"` + Specialist_Code *uint `json:"specialist-code"` + Doctor_Code *uint `json:"doctor-code"` + Status_Code erc.DataApprovalCode `json:"status-code"` } type ReadDetailDto struct { @@ -53,22 +53,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty"` - Doctor_Code *string `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` - Status_Code *erc.DataApprovalCode `json:"status_code"` + Encounter_Id *uint `json:"encounter_id"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Doctor_Code *string `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + Status_Code *erc.DataApprovalCode `json:"status_code"` } func (d InternalReference) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Unit_Code: d.Unit_Code, - Unit: d.Unit, - Doctor_Code: d.Doctor_Code, - Doctor: d.Doctor, - Status_Code: d.Status_Code, + Encounter_Id: d.Encounter_Id, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Doctor_Code: d.Doctor_Code, + Doctor: d.Doctor, + Status_Code: d.Status_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/internal-reference/entity.go b/internal/domain/main-entities/internal-reference/entity.go index 90859710..15bbe5cb 100644 --- a/internal/domain/main-entities/internal-reference/entity.go +++ b/internal/domain/main-entities/internal-reference/entity.go @@ -6,21 +6,21 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" en "simrs-vx/internal/domain/main-entities/nurse" - eu "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" ) type InternalReference struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` - Doctor_Code *string `json:"doctor_code"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` - Status_Code *erc.DataApprovalCode `json:"status_code"` - SrcDoctor_Code *string `json:"srcDoctor_code"` - SrcDoctor *ed.Doctor `json:"srcDoctor,omitempty" gorm:"foreignKey:SrcDoctor_Code;references:Code"` - SrcNurse_Code *string `json:"srcNurse_code"` - SrcNurse *en.Nurse `json:"srcNurse,omitempty" gorm:"foreignKey:SrcNurse_Code;references:Code"` - Nurse_Code *string `json:"nurse_code"` - Nurse *en.Nurse `json:"nurse,omitempty" gorm:"foreignKey:Nurse_Code;references:Code"` + Encounter_Id *uint `json:"encounter_id"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` + Status_Code *erc.DataApprovalCode `json:"status_code"` + SrcDoctor_Code *string `json:"srcDoctor_code"` + SrcDoctor *ed.Doctor `json:"srcDoctor,omitempty" gorm:"foreignKey:SrcDoctor_Code;references:Code"` + SrcNurse_Code *string `json:"srcNurse_code"` + SrcNurse *en.Nurse `json:"srcNurse,omitempty" gorm:"foreignKey:SrcNurse_Code;references:Code"` + Nurse_Code *string `json:"nurse_code"` + Nurse *en.Nurse `json:"nurse,omitempty" gorm:"foreignKey:Nurse_Code;references:Code"` } diff --git a/internal/domain/main-entities/nurse/dto.go b/internal/domain/main-entities/nurse/dto.go index b0cd6104..4ebd3800 100644 --- a/internal/domain/main-entities/nurse/dto.go +++ b/internal/domain/main-entities/nurse/dto.go @@ -4,15 +4,15 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" ee "simrs-vx/internal/domain/main-entities/employee" ei "simrs-vx/internal/domain/main-entities/infra" - eu "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" ) 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_Code *string `json:"unit_code"` - Infra_Code *string `json:"infra_code"` + Code *string `json:"code" validate:"maxLength=20"` + Employee_Id *uint `json:"employee_id"` + IHS_Number *string `json:"ihs_number" validate:"maxLength=20"` + Specialist_Code *string `json:"specialist_code"` + Infra_Code *string `json:"infra_code"` } type ReadListDto struct { @@ -22,11 +22,11 @@ type ReadListDto struct { } type FilterDto struct { - Code *string `json:"code"` - Employee_Id *uint `json:"employee-id"` - IHS_Number *string `json:"ihs-number"` - Unit_Code *string `json:"unit-code"` - Infra_Code *string `json:"infra-code"` + Code *string `json:"code"` + Employee_Id *uint `json:"employee-id"` + IHS_Number *string `json:"ihs-number"` + Specialist_Code *string `json:"specialist-code"` + Infra_Code *string `json:"infra-code"` } type ReadDetailDto struct { Id *uint16 `json:"id"` @@ -53,26 +53,26 @@ 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"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty"` - Infra_Code *string `json:"infra_code"` - Infra *ei.Infra `json:"infra,omitempty"` + Code *string `json:"code"` + Employee_Id *uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty"` + IHS_Number *string `json:"ihs_number"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Infra_Code *string `json:"infra_code"` + Infra *ei.Infra `json:"infra,omitempty"` } func (d Nurse) ToResponse() ResponseDto { resp := ResponseDto{ - Code: d.Code, - Employee_Id: d.Employee_Id, - Employee: d.Employee, - IHS_Number: d.IHS_Number, - Unit_Code: d.Unit_Code, - Unit: d.Unit, - Infra_Code: d.Infra_Code, - Infra: d.Infra, + Code: d.Code, + Employee_Id: d.Employee_Id, + Employee: d.Employee, + IHS_Number: d.IHS_Number, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Infra_Code: d.Infra_Code, + Infra: d.Infra, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/nurse/entity.go b/internal/domain/main-entities/nurse/entity.go index cb1df0a8..adb14c10 100644 --- a/internal/domain/main-entities/nurse/entity.go +++ b/internal/domain/main-entities/nurse/entity.go @@ -4,17 +4,17 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" ee "simrs-vx/internal/domain/main-entities/employee" ei "simrs-vx/internal/domain/main-entities/infra" - eu "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" ) type Nurse 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"` - Unit_Code *string `json:"unit_code" gorm:"size:10"` - 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_Code;references:Code"` + 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"` + Specialist_Code *string `json:"specialist_code" gorm:"size:10"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` + Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"` } diff --git a/internal/domain/main-entities/practice-schedule/dto.go b/internal/domain/main-entities/practice-schedule/dto.go index 832bc29d..35e7ff35 100644 --- a/internal/domain/main-entities/practice-schedule/dto.go +++ b/internal/domain/main-entities/practice-schedule/dto.go @@ -6,11 +6,11 @@ import ( ) type CreateDto struct { - Doctor_Code *string `json:"doctor_code"` - Unit_Code *string `json:"unit_code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime" validate:"maxLength=5"` - EndTime *string `json:"endTime" validate:"maxLength=5"` + Doctor_Code *string `json:"doctor_code"` + Specialist_Code *string `json:"specialist_code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime" validate:"maxLength=5"` + EndTime *string `json:"endTime" validate:"maxLength=5"` } type ReadListDto struct { @@ -20,11 +20,11 @@ type ReadListDto struct { } type FilterDto struct { - Doctor_Code *string `json:"doctor-code"` - Unit_Code *string `json:"unit-code"` - Day_Code *erc.DayCode `json:"day-code"` - StartTime *string `json:"startTime"` - EndTime *string `json:"endTime"` + Doctor_Code *string `json:"doctor-code"` + Specialist_Code *string `json:"specialist-code"` + Day_Code *erc.DayCode `json:"day-code"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` } type ReadDetailDto struct { @@ -48,20 +48,20 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Doctor_Code *string `json:"doctor_code"` - Unit_Code *string `json:"unit_code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime"` - EndTime *string `json:"endTime"` + Doctor_Code *string `json:"doctor_code"` + Specialist_Code *string `json:"specialist_code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` } func (d PracticeSchedule) ToResponse() ResponseDto { resp := ResponseDto{ - Doctor_Code: d.Doctor_Code, - Unit_Code: d.Unit_Code, - Day_Code: d.Day_Code, - StartTime: d.StartTime, - EndTime: d.EndTime, + Doctor_Code: d.Doctor_Code, + Specialist_Code: d.Specialist_Code, + Day_Code: d.Day_Code, + StartTime: d.StartTime, + EndTime: d.EndTime, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/practice-schedule/entity.go b/internal/domain/main-entities/practice-schedule/entity.go index 84ea3296..3f466a3b 100644 --- a/internal/domain/main-entities/practice-schedule/entity.go +++ b/internal/domain/main-entities/practice-schedule/entity.go @@ -3,17 +3,17 @@ package practiceschedule import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" - eu "simrs-vx/internal/domain/main-entities/unit" + es "simrs-vx/internal/domain/main-entities/specialist" erc "simrs-vx/internal/domain/references/common" ) type PracticeSchedule struct { - ecore.Main // adjust this according to the needs - Doctor_Code *string `json:"doctor_code"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime" gorm:"size:5"` - EndTime *string `json:"endTime" gorm:"size:5"` + ecore.Main // adjust this according to the needs + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime" gorm:"size:5"` + EndTime *string `json:"endTime" gorm:"size:5"` } diff --git a/internal/domain/main-entities/procedure-room/base/entity.go b/internal/domain/main-entities/procedure-room/base/entity.go index 981dd4f2..ec42de2c 100644 --- a/internal/domain/main-entities/procedure-room/base/entity.go +++ b/internal/domain/main-entities/procedure-room/base/entity.go @@ -10,7 +10,6 @@ type ProcedureRoom struct { Code string `json:"code" gorm:"unique;size:20"` // copied from infra code Infra_Code *string `json:"infra_code" gorm:"size:20;unique"` Type_Code *ero.ProdcedureRoomTypeCode `json:"type_code" gorm:"size:10"` - Unit_Code *string `json:"unit_code" gorm:"size:20"` Specialist_Code *string `json:"specialist_code" gorm:"size:20"` Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:20"` } diff --git a/internal/domain/main-entities/procedure-room/dto.go b/internal/domain/main-entities/procedure-room/dto.go index b3812db2..28779c73 100644 --- a/internal/domain/main-entities/procedure-room/dto.go +++ b/internal/domain/main-entities/procedure-room/dto.go @@ -5,14 +5,12 @@ import ( ei "simrs-vx/internal/domain/main-entities/infra" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" - eu "simrs-vx/internal/domain/main-entities/unit" ) type CreateDto struct { Code *string `json:"code"` Infra_Code *string `json:"infra_code"` Type_Code string `json:"type_code"` - Unit_Code *string `json:"unit_code"` Specialist_Code *string `json:"specialist_code"` Subspecialist_Code *string `json:"subspecialist_code"` } @@ -26,7 +24,6 @@ type ReadListDto struct { type FilterDto struct { Infra_Code *string `json:"infra-code"` Type_Code string `json:"type-code"` - Unit_Code *string `json:"unit-code"` Specialist_Code *string `json:"specialist-code"` Subspecialist_Code *string `json:"subspecialist-code"` } @@ -56,8 +53,6 @@ type ResponseDto struct { Type_Code *string `json:"type_code"` 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"` @@ -70,8 +65,6 @@ func (d ProcedureRoom) ToResponse() ResponseDto { Infra_Code: d.Infra_Code, Infra: d.Infra, Type_Code: (*string)(d.Type_Code), - Unit_Code: d.Unit_Code, - Unit: d.Unit, Specialist_Code: d.Specialist_Code, Specialist: d.Specialist, Subspecialist_Code: d.Subspecialist_Code, diff --git a/internal/domain/main-entities/procedure-room/entity.go b/internal/domain/main-entities/procedure-room/entity.go index 9be3ac69..76186011 100644 --- a/internal/domain/main-entities/procedure-room/entity.go +++ b/internal/domain/main-entities/procedure-room/entity.go @@ -5,13 +5,11 @@ import ( ebase "simrs-vx/internal/domain/main-entities/procedure-room/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" ) type ProcedureRoom struct { ebase.ProcedureRoom Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` } diff --git a/internal/domain/main-entities/specialist/dto.go b/internal/domain/main-entities/specialist/dto.go index 2d656556..78f7ae31 100644 --- a/internal/domain/main-entities/specialist/dto.go +++ b/internal/domain/main-entities/specialist/dto.go @@ -4,14 +4,13 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" espb "simrs-vx/internal/domain/main-entities/specialist-position/base" essb "simrs-vx/internal/domain/main-entities/subspecialist/base" - eu "simrs-vx/internal/domain/main-entities/unit" ) type CreateDto struct { - Id *uint `json:"id"` - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Unit_Code *string `json:"unit_code"` + Id *uint `json:"id"` + Installation_Code string `json:"installation_code"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` } type ReadListDto struct { @@ -22,10 +21,9 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` - Unit_Code *string `json:"unit-code"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code string `json:"code"` + Name string `json:"name"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { @@ -54,8 +52,6 @@ type ResponseDto struct { ecore.SmallMain Code string `json:"code"` Name string `json:"name"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty"` SpecialistPositions []espb.Basic `json:"specialistPositions,omitempty"` Subspecialists []essb.Basic `json:"subspecialists,omitempty"` } @@ -64,8 +60,6 @@ func (d Specialist) ToResponse() ResponseDto { resp := ResponseDto{ Code: d.Code, Name: d.Name, - Unit: d.Unit, - 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 0b5b7a5d..0326f614 100644 --- a/internal/domain/main-entities/specialist/entity.go +++ b/internal/domain/main-entities/specialist/entity.go @@ -2,17 +2,17 @@ package specialist import ( ecore "simrs-vx/internal/domain/base-entities/core" + ei "simrs-vx/internal/domain/main-entities/installation" eub "simrs-vx/internal/domain/main-entities/specialist-position/base" essb "simrs-vx/internal/domain/main-entities/subspecialist/base" - eu "simrs-vx/internal/domain/main-entities/unit" ) type Specialist struct { - ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:20"` - Name string `json:"name" gorm:"size:50"` - Unit_Code *string `json:"unit_code" gorm:"size:20"` - 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"` + ecore.SmallMain // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:20"` + Name string `json:"name" gorm:"size:50"` + Installation_Code string `json:"installation_code" gorm:"size:20"` + Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_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/unit-position/base/entity.go b/internal/domain/main-entities/unit-position/base/entity.go deleted file mode 100644 index eb046dfc..00000000 --- a/internal/domain/main-entities/unit-position/base/entity.go +++ /dev/null @@ -1,20 +0,0 @@ -package base - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" - ee "simrs-vx/internal/domain/main-entities/employee" -) - -type Basic struct { - ecore.SmallMain // adjust this according to the needs - 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"` - Employee_Id *uint `json:"employee_id"` - Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` -} - -func (Basic) TableName() string { - return "UnitPosition" -} diff --git a/internal/domain/main-entities/unit-position/dto.go b/internal/domain/main-entities/unit-position/dto.go deleted file mode 100644 index 856cec77..00000000 --- a/internal/domain/main-entities/unit-position/dto.go +++ /dev/null @@ -1,85 +0,0 @@ -package unit_position - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" - ee "simrs-vx/internal/domain/main-entities/employee" - eu "simrs-vx/internal/domain/main-entities/unit" -) - -type CreateDto struct { - 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"` - Employee_Id *uint `json:"employee_id"` -} - -type ReadListDto struct { - FilterDto - Includes string `json:"includes"` - Sort string `json:"sort"` - Pagination ecore.Pagination -} - -type FilterDto struct { - Unit_Code *string `json:"unit-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"` - Code *string `json:"code"` -} - -type UpdateDto struct { - Id *uint16 `json:"id"` - CreateDto -} - -type DeleteDto struct { - Id *uint16 `json:"id"` - Code *string `json:"code"` -} - -type MetaDto struct { - PageNumber int `json:"page_number"` - PageSize int `json:"page_size"` - Count int `json:"count"` -} - -type ResponseDto struct { - ecore.SmallMain - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,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 UnitPosition) ToResponse() ResponseDto { - resp := ResponseDto{ - Unit_Code: d.Unit_Code, - Unit: d.Unit, - Code: d.Code, - Name: d.Name, - HeadStatus: d.HeadStatus, - Employee_Id: d.Employee_Id, - Employee: d.Employee, - } - resp.SmallMain = d.SmallMain - return resp -} - -func ToResponseList(data []UnitPosition) []ResponseDto { - resp := make([]ResponseDto, len(data)) - for i, u := range data { - resp[i] = u.ToResponse() - } - return resp -} diff --git a/internal/domain/main-entities/unit-position/entity.go b/internal/domain/main-entities/unit-position/entity.go deleted file mode 100644 index a7598049..00000000 --- a/internal/domain/main-entities/unit-position/entity.go +++ /dev/null @@ -1,11 +0,0 @@ -package unit_position - -import ( - eu "simrs-vx/internal/domain/main-entities/unit" - eub "simrs-vx/internal/domain/main-entities/unit-position/base" -) - -type UnitPosition struct { - eub.Basic - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` -} diff --git a/internal/domain/main-entities/unit/dto.go b/internal/domain/main-entities/unit/dto.go deleted file mode 100644 index 76151cb7..00000000 --- a/internal/domain/main-entities/unit/dto.go +++ /dev/null @@ -1,82 +0,0 @@ -package unit - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" - ei "simrs-vx/internal/domain/main-entities/installation" - eipb "simrs-vx/internal/domain/main-entities/unit-position/base" -) - -type CreateDto struct { - Id *uint `json:"id"` - Installation_Code *string `json:"installation_code"` - 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 { - 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_Code *string `json:"installation_code"` - Code *string `json:"code"` - Includes string `json:"includes"` -} - -type UpdateDto struct { - Id *uint16 `json:"id"` - CreateDto -} - -type DeleteDto struct { - Id *uint16 `json:"id"` - Code *string `json:"code"` -} - -type MetaDto struct { - PageNumber int `json:"page_number"` - PageSize int `json:"page_size"` - Count int `json:"count"` -} - -type ResponseDto struct { - ecore.SmallMain - 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_Code: d.Installation_Code, - Code: d.Code, - Name: d.Name, - UnitPositions: d.UnitPositions, - } - resp.SmallMain = d.SmallMain - if d.Installation != nil { - resp.Installation = d.Installation - } - return resp -} - -func ToResponseList(data []Unit) []ResponseDto { - resp := make([]ResponseDto, len(data)) - for i, u := range data { - resp[i] = u.ToResponse() - } - return resp -} diff --git a/internal/domain/main-entities/unit/entity.go b/internal/domain/main-entities/unit/entity.go deleted file mode 100644 index e8110db3..00000000 --- a/internal/domain/main-entities/unit/entity.go +++ /dev/null @@ -1,18 +0,0 @@ -package unit - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" - ei "simrs-vx/internal/domain/main-entities/installation" - eub "simrs-vx/internal/domain/main-entities/unit-position/base" - ero "simrs-vx/internal/domain/references/organization" -) - -type Unit struct { - ecore.SmallMain // adjust this according to the needs - Installation_Code *string `json:"installation_code" gorm:"size:20"` - Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Code;references:Code"` - Code string `json:"code" gorm:"unique;size:20"` - Name string `json:"name" gorm:"size:50"` - Type_Code *ero.UnitTypeCode `json:"type_code"` - UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` -} diff --git a/internal/interface/main-handler/encounter/handler.go b/internal/interface/main-handler/encounter/handler.go index c6a02ba9..8b8babc9 100644 --- a/internal/interface/main-handler/encounter/handler.go +++ b/internal/interface/main-handler/encounter/handler.go @@ -240,8 +240,8 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) { rw.DataResponse(w, res, err) } -func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) { - dto := e.SwitchUnitDto{} +func (obj myBase) RequestSwitchSpecialist(w http.ResponseWriter, r *http.Request) { + dto := e.SwitchSpecialistDto{} id := rw.ValidateInt(w, "id", r.PathValue("id")) if id <= 0 { return @@ -252,7 +252,7 @@ func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) { } // validate request body - if valid := validateRequestSwitchUnit(w, dto); !valid { + if valid := validateRequestSwitchSpecialist(w, dto); !valid { return } @@ -263,12 +263,12 @@ func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) { dto.AuthInfo = *authInfo dto.Id = uint(id) - res, err := u.RequestSwitchUnit(dto) + res, err := u.RequestSwitchSpecialist(dto) rw.DataResponse(w, res, err) } -func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) { - dto := e.ApproveCancelUnitDto{} +func (obj myBase) ApproveSwitchSpecialist(w http.ResponseWriter, r *http.Request) { + dto := e.ApproveCancelSpecialistDto{} id := rw.ValidateInt(w, "id", r.PathValue("id")) if id <= 0 { return @@ -286,12 +286,12 @@ func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) { dto.AuthInfo = *authInfo dto.Id = uint(id) - res, err := u.ApproveSwitchUnit(dto) + res, err := u.ApproveSwitchSpecialist(dto) rw.DataResponse(w, res, err) } -func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) { - dto := e.ApproveCancelUnitDto{} +func (obj myBase) CancelSwitchSpecialist(w http.ResponseWriter, r *http.Request) { + dto := e.ApproveCancelSpecialistDto{} id := rw.ValidateInt(w, "id", r.PathValue("id")) if id <= 0 { return @@ -309,7 +309,7 @@ func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) { dto.AuthInfo = *authInfo dto.Id = uint(id) - res, err := u.CancelSwitchUnit(dto) + res, err := u.CancelSwitchSpecialist(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 67d8a63c..7d22893e 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -58,7 +58,7 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) return true } -func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid bool) { +func validateRequestSwitchSpecialist(w http.ResponseWriter, i e.SwitchSpecialistDto) (valid bool) { // validate poly-switch-code if i.PolySwitchCode == nil { rw.DataResponse(w, nil, d.FieldError{ @@ -84,7 +84,7 @@ func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid } for _, v := range *i.InternalReferences { - if v.Unit_Code == nil { + if v.Specialist_Code == nil { rw.DataResponse(w, nil, d.FieldError{ Code: dataValidationFail, Message: "internalReferences.unit_code required", diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index c47ae37d..fced567e 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -115,8 +115,6 @@ import ( 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" vehicle "simrs-vx/internal/interface/main-handler/vehicle" vehiclehist "simrs-vx/internal/interface/main-handler/vehicle-hist" @@ -194,9 +192,9 @@ func SetRoutes() http.Handler { "PATCH /{id}/cancel": encounter.O.Cancel, "PATCH /{id}/reject": encounter.O.Reject, "PATCH /{id}/skip": encounter.O.Skip, - "PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit, - "PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit, - "PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchUnit, + "PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchSpecialist, + "PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchSpecialist, + "PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchSpecialist, "POST /create-with-patient": encounter.O.CreateWithPatient, }) hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{ @@ -369,9 +367,7 @@ func SetRoutes() http.Handler { hc.RegCrudByCode(r, "/v1/division", division.O) hc.RegCrudByCode(r, "/v1/division-position", divisionposition.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) diff --git a/internal/interface/main-handler/unit-position/handler.go b/internal/interface/main-handler/unit-position/handler.go deleted file mode 100644 index 7780e80d..00000000 --- a/internal/interface/main-handler/unit-position/handler.go +++ /dev/null @@ -1,71 +0,0 @@ -package unit_position - -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/unit-position" - u "simrs-vx/internal/use-case/main-use-case/unit-position" -) - -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) { - code := rw.ValidateString(w, "code", r.PathValue("code")) - if code == "" { - return - } - dto := e.ReadDetailDto{} - dto.Code = &code - res, err := u.ReadDetail(dto) - rw.DataResponse(w, res, err) -} - -func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - code := rw.ValidateString(w, "code", r.PathValue("code")) - if code == "" { - return - } - - dto := e.UpdateDto{} - if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { - return - } - dto.Code = code - res, err := u.Update(dto) - rw.DataResponse(w, res, err) -} - -func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - code := rw.ValidateString(w, "code", r.PathValue("code")) - if code == "" { - return - } - - dto := e.DeleteDto{} - 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 deleted file mode 100644 index f31667a2..00000000 --- a/internal/interface/main-handler/unit/handler.go +++ /dev/null @@ -1,73 +0,0 @@ -package unit - -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/unit" - u "simrs-vx/internal/use-case/main-use-case/unit" -) - -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) { - code := rw.ValidateString(w, "code", r.PathValue("code")) - if code == "" { - return - } - dto := e.ReadDetailDto{} - - sf.UrlQueryParam(&dto, *r.URL) - dto.Code = &code - res, err := u.ReadDetail(dto) - rw.DataResponse(w, res, err) -} - -func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - code := rw.ValidateString(w, "code", r.PathValue("code")) - if code == "" { - return - } - - dto := e.UpdateDto{} - if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { - return - } - dto.Code = code - res, err := u.Update(dto) - rw.DataResponse(w, res, err) -} - -func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - code := rw.ValidateString(w, "code", r.PathValue("code")) - if code == "" { - return - } - - dto := e.DeleteDto{} - dto.Code = &code - res, err := u.Delete(dto) - rw.DataResponse(w, res, err) -} diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index af3b35d3..a89e74f2 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -109,8 +109,6 @@ import ( subspecialist "simrs-vx/internal/domain/main-entities/subspecialist" subspecialistposition "simrs-vx/internal/domain/main-entities/subspecialist-position" therapyprotocol "simrs-vx/internal/domain/main-entities/therapy-protocol" - unit "simrs-vx/internal/domain/main-entities/unit" - unitposition "simrs-vx/internal/domain/main-entities/unit-position" uom "simrs-vx/internal/domain/main-entities/uom" user "simrs-vx/internal/domain/main-entities/user" userfes "simrs-vx/internal/domain/main-entities/user-fes" @@ -135,7 +133,6 @@ func getMainEntities() []any { &division.Division{}, &divisionposition.DivisionPosition{}, &installation.Installation{}, - &unit.Unit{}, &village.Village{}, &district.District{}, ®ency.Regency{}, @@ -237,7 +234,6 @@ func getMainEntities() []any { &generalconsent.GeneralConsent{}, &deathcause.DeathCause{}, &installationposition.InstallationPosition{}, - &unitposition.UnitPosition{}, &specialistposition.SpecialistPosition{}, &subspecialistposition.SubspecialistPosition{}, &responsibledoctorhist.ResponsibleDoctorHist{}, diff --git a/internal/interface/simgos-sync-handler/new/encounter/handler.go b/internal/interface/simgos-sync-handler/new/encounter/handler.go index aef2f7d2..c37ba66d 100644 --- a/internal/interface/simgos-sync-handler/new/encounter/handler.go +++ b/internal/interface/simgos-sync-handler/new/encounter/handler.go @@ -87,32 +87,32 @@ func (obj myBase) UpdateStatus(w http.ResponseWriter, r *http.Request) { rw.DataResponse(w, res, err) } -func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) { +func (obj myBase) RequestSwitchSpecialist(w http.ResponseWriter, r *http.Request) { dto := e.Encounter{} if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - res, err := u.RequestSwitchUnit(dto) + res, err := u.RequestSwitchSpecialist(dto) rw.DataResponse(w, res, err) } -func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) { - dto := e.ApproveCancelUnitDto{} +func (obj myBase) ApproveSwitchSpecialist(w http.ResponseWriter, r *http.Request) { + dto := e.ApproveCancelSpecialistDto{} if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - res, err := u.ApproveSwitchUnit(dto) + res, err := u.ApproveSwitchSpecialist(dto) rw.DataResponse(w, res, err) } -func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) { - dto := e.ApproveCancelUnitDto{} +func (obj myBase) CancelSwitchSpecialist(w http.ResponseWriter, r *http.Request) { + dto := e.ApproveCancelSpecialistDto{} if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - res, err := u.CancelSwitchUnit(dto) + res, err := u.CancelSwitchSpecialist(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/simgos-sync-handler/new/unit/handler.go b/internal/interface/simgos-sync-handler/new/unit/handler.go deleted file mode 100644 index 95808728..00000000 --- a/internal/interface/simgos-sync-handler/new/unit/handler.go +++ /dev/null @@ -1,67 +0,0 @@ -package unit - -import ( - "net/http" - - rw "github.com/karincake/risoles" - // ua "github.com/karincake/tumpeng/auth/svc" - - e "simrs-vx/internal/domain/main-entities/unit" - esync "simrs-vx/internal/domain/sync-entities/log" - - u "simrs-vx/internal/use-case/simgos-sync-use-case/new/unit" -) - -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) CreateLog(w http.ResponseWriter, r *http.Request) { - dto := esync.SimxLogDto{} - if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { - return - } - res, err := u.CreateSimxLog(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 - } - - val := uint16(id) - dto.Id = &val - - 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{} - val := uint16(id) - dto.Id = &val - - res, err := u.Delete(dto) - rw.DataResponse(w, res, err) -} diff --git a/internal/interface/simgos-sync-handler/simgos-sync-handler.go b/internal/interface/simgos-sync-handler/simgos-sync-handler.go index c8a08b7f..761c6b74 100644 --- a/internal/interface/simgos-sync-handler/simgos-sync-handler.go +++ b/internal/interface/simgos-sync-handler/simgos-sync-handler.go @@ -28,7 +28,6 @@ import ( "simrs-vx/internal/interface/simgos-sync-handler/new/soapi" "simrs-vx/internal/interface/simgos-sync-handler/new/specialist" "simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist" - "simrs-vx/internal/interface/simgos-sync-handler/new/unit" sd "simrs-vx/internal/interface/simgos-sync-handler/seeder" @@ -53,7 +52,6 @@ func SetRoutes() http.Handler { /******************** SvcToOld ******************/ prefixnew := "/new-to-old" hc.SyncCrud(r, prefixnew+"/v1/installation", installation.O) - hc.SyncCrud(r, prefixnew+"/v1/unit", unit.O) hc.SyncCrud(r, prefixnew+"/v1/division", division.O) hc.SyncCrud(r, prefixnew+"/v1/specialist", specialist.O) hc.SyncCrud(r, prefixnew+"/v1/subspecialist", subspecialist.O) @@ -72,9 +70,9 @@ func SetRoutes() http.Handler { "PATCH /{id}/checkin": encounter.O.Checkin, "PATCH /{id}/checkout": encounter.O.Checkout, "PATCH /{id}/update-status": encounter.O.UpdateStatus, - "PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit, - "PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit, - "PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchUnit, + "PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchSpecialist, + "PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchSpecialist, + "PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchSpecialist, }) hc.SyncCrud(r, prefixnew+"/v1/soapi", soapi.O) diff --git a/internal/use-case/main-use-case/authentication/helper.go b/internal/use-case/main-use-case/authentication/helper.go index 3a8154b6..94739363 100644 --- a/internal/use-case/main-use-case/authentication/helper.go +++ b/internal/use-case/main-use-case/authentication/helper.go @@ -29,14 +29,12 @@ import ( er "simrs-vx/internal/domain/main-entities/registrator" esp "simrs-vx/internal/domain/main-entities/specialist-position" essp "simrs-vx/internal/domain/main-entities/subspecialist-position" - eup "simrs-vx/internal/domain/main-entities/unit-position" eu "simrs-vx/internal/domain/main-entities/user" udp "simrs-vx/internal/use-case/main-use-case/division-position" uip "simrs-vx/internal/use-case/main-use-case/installation-position" 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" ) // just return the error code @@ -85,7 +83,7 @@ func getDivisionPosition(employee_id uint, event *pl.Event) ([]string, error) { func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string - // get data unit_position based on employee_id + // get data specialist_position based on employee_id data, _, err := uip.ReadListData(eip.ReadListDto{ FilterDto: eip.FilterDto{Employee_Id: &employeeId}, Includes: "installation"}, event) @@ -102,28 +100,10 @@ func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) return result, nil } -func getUnitPosition(employeeId uint, event *pl.Event) ([]string, error) { - var result []string - - // get data unit_position based on employee_id - data, _, err := uup.ReadListData(eup.ReadListDto{FilterDto: eup.FilterDto{Employee_Id: &employeeId}}, event) - if err != nil { - return nil, err - } - - if len(data) > 0 { - for _, dp := range data { - result = append(result, "unit|"+*dp.Unit_Code+"|"+dp.Code) - } - } - - return result, nil -} - func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string - // get data unit_position based on employee_id + // get data specialist_position based on employee_id data, _, err := usp.ReadListData(esp.ReadListDto{FilterDto: esp.FilterDto{Employee_Id: &employeeId}}, event) if err != nil { return nil, err @@ -141,7 +121,7 @@ func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) { func getSubspecialistPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string - // get data unit_position based on employee_id + // get data specialist_position based on employee_id data, _, err := ussp.ReadListData(essp.ReadListDto{ FilterDto: essp.FilterDto{Employee_Id: &employeeId}, Includes: "subspecialist"}, event) @@ -230,9 +210,9 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out outputData["doctor_code"] = doctor.Code // specialist - if doctor.Unit_Code != nil { - atClaims["unit_code"] = doctor.Unit_Code - outputData["unit_code"] = doctor.Unit_Code + if doctor.Specialist_Code != nil { + atClaims["specialist_code"] = doctor.Specialist_Code + outputData["specialist_code"] = doctor.Specialist_Code } if doctor.Specialist_Code != nil { atClaims["specialist_code"] = doctor.Specialist_Code @@ -292,12 +272,6 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out return errorGetPosition } - // unit position - unitPositions, err := getUnitPosition(employee.Id, &event) - if err != nil { - return errorGetPosition - } - // specialist position specialistPositions, err := getSpecialistPosition(employee.Id, &event) if err != nil { @@ -312,7 +286,7 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out roles = append(roles, divisionPositions...) roles = append(roles, installationPositions...) - roles = append(roles, unitPositions...) + roles = append(roles, specialistPositions...) roles = append(roles, specialistPositions...) roles = append(roles, subspecialistPositions...) // atClaims["division_positions"] = divsionPositions diff --git a/internal/use-case/main-use-case/chemo/helper.go b/internal/use-case/main-use-case/chemo/helper.go index 51a09a3a..c241bce3 100644 --- a/internal/use-case/main-use-case/chemo/helper.go +++ b/internal/use-case/main-use-case/chemo/helper.go @@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Chemo) { data.Encounter_Id = inputSrc.Encounter_Id data.Status_Code = inputSrc.Status_Code - data.SrcUnit_Code = inputSrc.SrcUnit_Code + data.Specialist_Code = inputSrc.Specialist_Code } diff --git a/internal/use-case/main-use-case/consultation/case.go b/internal/use-case/main-use-case/consultation/case.go index 25306169..1691e4a9 100644 --- a/internal/use-case/main-use-case/consultation/case.go +++ b/internal/use-case/main-use-case/consultation/case.go @@ -312,7 +312,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - if data.DstDoctor_Code != nil && data.DstDoctor_Code != input.AuthInfo.Doctor_Code { + if data.Doctor_Code != nil && data.Doctor_Code != input.AuthInfo.Doctor_Code { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-handled-mismatch", @@ -322,7 +322,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - data.DstDoctor_Code = input.AuthInfo.Doctor_Code + data.Doctor_Code = input.AuthInfo.Doctor_Code data.Solution = input.Solution data.RepliedAt = pu.GetTimeNow() err = tx.Save(&data).Error diff --git a/internal/use-case/main-use-case/consultation/helper.go b/internal/use-case/main-use-case/consultation/helper.go index 3a518c77..6a4e2a3e 100644 --- a/internal/use-case/main-use-case/consultation/helper.go +++ b/internal/use-case/main-use-case/consultation/helper.go @@ -20,5 +20,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Consultation) { data.Encounter_Id = inputSrc.Encounter_Id data.Date = inputSrc.Date data.Problem = inputSrc.Problem - data.DstUnit_Code = inputSrc.DstUnit_Code + data.Specialist_Code = inputSrc.Specialist_Code } 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 8ae71d3c..899fb437 100644 --- a/internal/use-case/main-use-case/control-letter/helper.go +++ b/internal/use-case/main-use-case/control-letter/helper.go @@ -18,7 +18,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ControlLetter) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Unit_Code = inputSrc.Unit_Code data.Specialist_Code = inputSrc.Specialist_Code data.Subspecialist_Code = inputSrc.Subspecialist_Code data.Doctor_Code = inputSrc.Doctor_Code diff --git a/internal/use-case/main-use-case/doctor/helper.go b/internal/use-case/main-use-case/doctor/helper.go index 9ddc2027..9571f62d 100644 --- a/internal/use-case/main-use-case/doctor/helper.go +++ b/internal/use-case/main-use-case/doctor/helper.go @@ -21,7 +21,6 @@ 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_Code = inputSrc.Unit_Code data.Specialist_Code = inputSrc.Specialist_Code data.Subspecialist_Code = inputSrc.Subspecialist_Code } diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index b4001156..dd131944 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -704,13 +704,13 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { }, nil } -func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { +func RequestSwitchSpecialist(input e.SwitchSpecialistDto) (*d.Data, error) { rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Responsible_Nurse.Employee.User,Responsible_Doctor.Employee"} var data *e.Encounter var err error event := pl.Event{ - Feature: "RequestSwitchUnit", + Feature: "RequestSwitchSpecialist", Source: source, } @@ -720,8 +720,8 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { unitCodes := make(map[string]struct{}) doctorCodes := make(map[string]struct{}) for _, ref := range *input.InternalReferences { - if ref.Unit_Code != nil { - unitCodes[*ref.Unit_Code] = struct{}{} + if ref.Specialist_Code != nil { + unitCodes[*ref.Specialist_Code] = struct{}{} } if ref.Doctor_Code != nil { doctorCodes[*ref.Doctor_Code] = struct{}{} @@ -729,7 +729,7 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { } // validate unit - if err = validateUnitCodes(unitCodes, &event); err != nil { + if err = validateSpecialistCodes(unitCodes, &event); err != nil { return nil, err } @@ -796,7 +796,7 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { mwRunner.setMwType(pu.MWTPre) // Run pre-middleware - if err := mwRunner.RunRequestSwitchUnitMiddleware(requestSwitchEncounter, dataEncounter); err != nil { + if err := mwRunner.RunRequestSwitchSpecialistMiddleware(requestSwitchEncounter, dataEncounter); err != nil { return err } return nil @@ -812,13 +812,13 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { Meta: d.IS{ "source": source, "structure": "single-data", - "status": "requestSwitchUnit", + "status": "requestSwitchSpecialist", }, Data: data.ToResponse(), }, nil } -func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { +func ApproveSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) { rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Responsible_Doctor.Employee"} var ( data *e.Encounter @@ -826,12 +826,12 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { ) event := pl.Event{ - Feature: "ApproveSwitchUnit", + Feature: "ApproveSwitchSpecialist", Source: source, } // Start log - pl.SetLogInfo(&event, input, "started", "approveSwitchUnit") + pl.SetLogInfo(&event, input, "started", "approveSwitchSpecialist") roleAllowed := []string{string(erg.EPCNur)} err = validateAuth(input.AuthInfo, roleAllowed, "request-switch-poly", &event) @@ -904,13 +904,13 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { } // update encounter - if err = updateEncounterApproveSwitchUnit(input, &event, tx); err != nil { + if err = updateEncounterApproveSwitchSpecialist(input, &event, tx); err != nil { return err } mwRunner.setMwType(pu.MWTPre) // Run pre-middleware - if err := mwRunner.RunApproveSwitchUnitMiddleware(approveSwitchEncounter, &input); err != nil { + if err := mwRunner.RunApproveSwitchSpecialistMiddleware(approveSwitchEncounter, &input); err != nil { return err } return nil @@ -933,7 +933,7 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { } -func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { +func CancelSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) { rdDto := e.ReadDetailDto{Id: input.Id} var ( data *e.Encounter @@ -941,12 +941,12 @@ func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { ) event := pl.Event{ - Feature: "CancelSwitchUnit", + Feature: "CancelSwitchSpecialist", Source: source, } // Start log - pl.SetLogInfo(&event, input, "started", "cancelSwitchUnit") + pl.SetLogInfo(&event, input, "started", "cancelSwitchSpecialist") roleAllowed := []string{string(erg.EPCNur)} err = validateAuth(input.AuthInfo, roleAllowed, "request-switch-poly", &event) @@ -1000,7 +1000,7 @@ func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { mwRunner.setMwType(pu.MWTPre) // Run pre-middleware - if err := mwRunner.RunCancelSwitchUnitMiddleware(cancelSwitchEncounter, &input); err != nil { + if err := mwRunner.RunCancelSwitchSpecialistMiddleware(cancelSwitchEncounter, &input); err != nil { return err } return nil diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index f606eb7c..e3dfb00c 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -44,7 +44,7 @@ import ( 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" - eu "simrs-vx/internal/domain/main-entities/unit" + esp "simrs-vx/internal/domain/main-entities/specialist" // udo "simrs-vx/internal/use-case/main-use-case/device-order" uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist" @@ -69,7 +69,7 @@ func setDataCreate(input *e.CreateDto, data *e.Encounter) { data.Patient_Id = input.Patient_Id data.RegisteredAt = input.RegisteredAt data.Class_Code = input.Class_Code - data.Unit_Code = input.Unit_Code + data.Specialist_Code = input.Specialist_Code data.Specialist_Code = input.Specialist_Code data.Subspecialist_Code = input.Subspecialist_Code data.VisitDate = input.VisitDate @@ -88,7 +88,7 @@ func setDataCreate(input *e.CreateDto, data *e.Encounter) { } func setDataUpdate(src e.UpdateDto, dst *e.Encounter) { - dst.Unit_Code = src.Unit_Code + dst.Specialist_Code = src.Specialist_Code dst.Specialist_Code = src.Specialist_Code dst.Subspecialist_Code = src.Subspecialist_Code dst.VisitDate = src.VisitDate @@ -104,7 +104,7 @@ func setDataUpdate(src e.UpdateDto, dst *e.Encounter) { func setDataUpdateFromSource(input *e.UpdateDto, data *e.Encounter) { data.Patient_Id = input.Patient_Id data.RegisteredAt = input.RegisteredAt - data.Unit_Code = input.Unit_Code + data.Specialist_Code = input.Specialist_Code data.Specialist_Code = input.Specialist_Code data.Subspecialist_Code = input.Subspecialist_Code data.VisitDate = input.VisitDate @@ -853,9 +853,9 @@ func insertDataSubClassAmbulatory(input e.CreateDto, soapiData []es.CreateDto, e switch { case subCode == ere.ACCChemo: chemoCreate := ec.CreateDto{ - Encounter_Id: &input.Id, - Status_Code: erc.DVCNew, - SrcUnit_Code: input.Unit_Code, + Encounter_Id: &input.Id, + Status_Code: erc.DVCNew, + Specialist_Code: input.Specialist_Code, } // create data chemo @@ -977,9 +977,9 @@ func setDBError(event *pl.Event, err error, ctx any) error { return pl.SetLogError(event, ctx) } -func getUnits(unitIds []string, event *pl.Event) ([]eu.Unit, error) { - pl.SetLogInfo(event, nil, "started", "getUnits") - var units []eu.Unit +func getSpecialists(unitIds []string, event *pl.Event) ([]esp.Specialist, error) { + pl.SetLogInfo(event, nil, "started", "getSpecialists") + var units []esp.Specialist err := dg.I.Where("\"Code\" IN ?", unitIds).Find(&units).Error if err != nil { event.Status = "failed" @@ -1009,14 +1009,14 @@ func getDoctors(doctorIds []string, event *pl.Event) ([]ed.Doctor, error) { return doctors, nil } -func validateUnitCodes(unitCodes map[string]struct{}, event *pl.Event) error { +func validateSpecialistCodes(unitCodes map[string]struct{}, event *pl.Event) error { if len(unitCodes) > 0 { var codes []string for code := range unitCodes { codes = append(codes, code) } - units, err := getUnits(codes, event) + units, err := getSpecialists(codes, event) if err != nil { return fmt.Errorf("failed to fetch units: %w", err) } diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 33f68af5..d102030a 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -83,8 +83,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.En tx = tx.Where("\"Encounter\".\"Status_Code\" = ?", *input.Status_Code) } - if input.Unit_Code != nil { - tx = tx.Where("\"Encounter\".\"Unit_Code\" = ?", *input.Unit_Code) + if input.Specialist_Code != nil { + tx = tx.Where("\"Encounter\".\"Specialist_Code\" = ?", *input.Specialist_Code) } if input.PaymentMethod_Code != nil { @@ -268,7 +268,7 @@ func UpdateStatusData(input e.UpdateStatusDto, event *pl.Event, dbx ...*gorm.DB) return nil } -func UpdateDischargeMethod(input e.SwitchUnitDto, event *pl.Event, dbx ...*gorm.DB) error { +func UpdateDischargeMethod(input e.SwitchSpecialistDto, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, input, "started", "DBUpdateDischargeMethod") dischargeCode := setDischargeMethodCode(*input.PolySwitchCode) @@ -382,7 +382,7 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo return recentEncounterAdm, valid, nil } -func updateEncounterApproveSwitchUnit(input e.ApproveCancelUnitDto, event *pl.Event, dbx ...*gorm.DB) (err error) { +func updateEncounterApproveSwitchSpecialist(input e.ApproveCancelSpecialistDto, event *pl.Event, dbx ...*gorm.DB) (err error) { pl.SetLogInfo(event, nil, "started", "DBCreate") var tx *gorm.DB diff --git a/internal/use-case/main-use-case/encounter/middleware-runner.go b/internal/use-case/main-use-case/encounter/middleware-runner.go index 3ee19355..fff1a804 100644 --- a/internal/use-case/main-use-case/encounter/middleware-runner.go +++ b/internal/use-case/main-use-case/encounter/middleware-runner.go @@ -202,7 +202,7 @@ func (me *middlewareRunner) RunUpdateStatusMiddleware(middlewares []updateStatus return nil } -func (me *middlewareRunner) RunRequestSwitchUnitMiddleware(middleware requestSwitchUnitMw, input *e.Encounter) error { +func (me *middlewareRunner) RunRequestSwitchSpecialistMiddleware(middleware requestSwitchSpecialistMw, input *e.Encounter) error { if !me.SyncOn { return nil } @@ -220,7 +220,7 @@ func (me *middlewareRunner) RunRequestSwitchUnitMiddleware(middleware requestSwi return nil } -func (me *middlewareRunner) RunApproveSwitchUnitMiddleware(middleware approveSwitchUnitMw, input *e.ApproveCancelUnitDto) error { +func (me *middlewareRunner) RunApproveSwitchSpecialistMiddleware(middleware approveSwitchSpecialistMw, input *e.ApproveCancelSpecialistDto) error { if !me.SyncOn { return nil } @@ -238,7 +238,7 @@ func (me *middlewareRunner) RunApproveSwitchUnitMiddleware(middleware approveSwi return nil } -func (me *middlewareRunner) RunCancelSwitchUnitMiddleware(middleware cancelSwitchUnitMw, input *e.ApproveCancelUnitDto) error { +func (me *middlewareRunner) RunCancelSwitchSpecialistMiddleware(middleware cancelSwitchSpecialistMw, input *e.ApproveCancelSpecialistDto) error { if !me.SyncOn { return nil } diff --git a/internal/use-case/main-use-case/encounter/middleware.go b/internal/use-case/main-use-case/encounter/middleware.go index 306e4bca..0db86dec 100644 --- a/internal/use-case/main-use-case/encounter/middleware.go +++ b/internal/use-case/main-use-case/encounter/middleware.go @@ -23,7 +23,7 @@ func init() { updatestatusEncounter = append(updatestatusEncounter, updateStatusMw{Name: "sync-update-status-encounter", Func: plugin.UpdateStatus}) - requestSwitchEncounter = requestSwitchUnitMw{Name: "sync-request-switch-unit-encounter", Func: plugin.RequestSwitchUnit} - approveSwitchEncounter = approveSwitchUnitMw{Name: "sync-approve-switch-unit-encounter", Func: plugin.ApproveSwitchUnit} - cancelSwitchEncounter = cancelSwitchUnitMw{Name: "sync-cancel-switch-unit-encounter", Func: plugin.CancelSwitchUnit} + requestSwitchEncounter = requestSwitchSpecialistMw{Name: "sync-request-switch-unit-encounter", Func: plugin.RequestSwitchSpecialist} + approveSwitchEncounter = approveSwitchSpecialistMw{Name: "sync-approve-switch-unit-encounter", Func: plugin.ApproveSwitchSpecialist} + cancelSwitchEncounter = cancelSwitchSpecialistMw{Name: "sync-cancel-switch-unit-encounter", Func: plugin.CancelSwitchSpecialist} } diff --git a/internal/use-case/main-use-case/encounter/tycovar.go b/internal/use-case/main-use-case/encounter/tycovar.go index 376baed8..fbafc4dd 100644 --- a/internal/use-case/main-use-case/encounter/tycovar.go +++ b/internal/use-case/main-use-case/encounter/tycovar.go @@ -59,19 +59,19 @@ type updateStatusMw struct { Func func(input *e.Encounter) error } -type requestSwitchUnitMw struct { +type requestSwitchSpecialistMw struct { Name string Func func(input *e.Encounter) error } -type approveSwitchUnitMw struct { +type approveSwitchSpecialistMw struct { Name string - Func func(input *e.ApproveCancelUnitDto) error + Func func(input *e.ApproveCancelSpecialistDto) error } -type cancelSwitchUnitMw struct { +type cancelSwitchSpecialistMw struct { Name string - Func func(input *e.ApproveCancelUnitDto) error + Func func(input *e.ApproveCancelSpecialistDto) error } type createWithPatientMw struct { @@ -96,8 +96,8 @@ var deletePostMw []readDetailMw var checkinEncounterMw checkinMw var checkoutEncounter checkoutMw var updatestatusEncounter []updateStatusMw -var requestSwitchEncounter requestSwitchUnitMw -var approveSwitchEncounter approveSwitchUnitMw -var cancelSwitchEncounter cancelSwitchUnitMw +var requestSwitchEncounter requestSwitchSpecialistMw +var approveSwitchEncounter approveSwitchSpecialistMw +var cancelSwitchEncounter cancelSwitchSpecialistMw var createWithPatientPreMw []createWithPatientMw var createWithPatientPostMw []createWithPatientMw diff --git a/internal/use-case/main-use-case/infra/helper.go b/internal/use-case/main-use-case/infra/helper.go index 27c5442c..82048ebf 100644 --- a/internal/use-case/main-use-case/infra/helper.go +++ b/internal/use-case/main-use-case/infra/helper.go @@ -57,7 +57,6 @@ func createProcedureRoom(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error roomCreate := er.CreateDto{ Code: input.Infra_Code, Infra_Code: input.Infra_Code, - Unit_Code: input.Unit_Code, Specialist_Code: input.Specialist_Code, Subspecialist_Code: input.Subspecialist_Code, } diff --git a/internal/use-case/main-use-case/internal-reference/helper.go b/internal/use-case/main-use-case/internal-reference/helper.go index 26b8903f..7ffdf9e4 100644 --- a/internal/use-case/main-use-case/internal-reference/helper.go +++ b/internal/use-case/main-use-case/internal-reference/helper.go @@ -12,7 +12,7 @@ import ( func setDataCreate(input *ir.CreateDto, data *ir.InternalReference) { data.Encounter_Id = input.Encounter_Id - data.Unit_Code = input.Unit_Code + data.Specialist_Code = input.Specialist_Code data.Doctor_Code = input.Doctor_Code data.SrcDoctor_Code = input.SrcDoctor_Code @@ -28,18 +28,18 @@ func setDataUpdate(input *ir.UpdateDto, data *ir.InternalReference) { data.Status_Code = &input.Status_Code } -func setBulkData(input *e.SwitchUnitDto) []ir.InternalReference { +func setBulkData(input *e.SwitchSpecialistDto) []ir.InternalReference { var data []ir.InternalReference for _, v := range *input.InternalReferences { statusCode := erc.DACNew data = append(data, ir.InternalReference{ - Encounter_Id: &input.Id, - Unit_Code: v.Unit_Code, - Doctor_Code: v.Doctor_Code, - Status_Code: &statusCode, - SrcDoctor_Code: input.Src_Doctor_Code, - SrcNurse_Code: input.Src_Nurse_Code, + Encounter_Id: &input.Id, + Specialist_Code: v.Specialist_Code, + Doctor_Code: v.Doctor_Code, + Status_Code: &statusCode, + SrcDoctor_Code: input.Src_Doctor_Code, + SrcNurse_Code: input.Src_Nurse_Code, }) } diff --git a/internal/use-case/main-use-case/internal-reference/lib.go b/internal/use-case/main-use-case/internal-reference/lib.go index 0aa54b4b..eb3ca18f 100644 --- a/internal/use-case/main-use-case/internal-reference/lib.go +++ b/internal/use-case/main-use-case/internal-reference/lib.go @@ -144,7 +144,7 @@ func DeleteData(data *eir.InternalReference, event *pl.Event, dbx ...*gorm.DB) e return nil } -func CreateBulkData(input *e.SwitchUnitDto, event *pl.Event, dbx ...*gorm.DB) error { +func CreateBulkData(input *e.SwitchSpecialistDto, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, nil, "started", "DBCreate") data := setBulkData(input) diff --git a/internal/use-case/main-use-case/nurse/helper.go b/internal/use-case/main-use-case/nurse/helper.go index 49078088..cfdf7eb4 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_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Specialist_Code data.Infra_Code = inputSrc.Infra_Code } diff --git a/internal/use-case/main-use-case/practice-schedule/helper.go b/internal/use-case/main-use-case/practice-schedule/helper.go index ba61b691..1fbe4b5d 100644 --- a/internal/use-case/main-use-case/practice-schedule/helper.go +++ b/internal/use-case/main-use-case/practice-schedule/helper.go @@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PracticeSchedule) { } data.Doctor_Code = inputSrc.Doctor_Code - data.Unit_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Specialist_Code data.Day_Code = inputSrc.Day_Code data.StartTime = inputSrc.StartTime data.EndTime = inputSrc.EndTime diff --git a/internal/use-case/main-use-case/procedure-room/helper.go b/internal/use-case/main-use-case/procedure-room/helper.go index 0101efef..fa16d16b 100644 --- a/internal/use-case/main-use-case/procedure-room/helper.go +++ b/internal/use-case/main-use-case/procedure-room/helper.go @@ -19,7 +19,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ProcedureRoom) { data.Code = *inputSrc.Infra_Code data.Infra_Code = inputSrc.Infra_Code - data.Unit_Code = inputSrc.Unit_Code data.Specialist_Code = inputSrc.Specialist_Code data.Subspecialist_Code = inputSrc.Subspecialist_Code } diff --git a/internal/use-case/main-use-case/specialist/helper.go b/internal/use-case/main-use-case/specialist/helper.go index 5c59b1cf..8a71d2cb 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_Code = inputSrc.Unit_Code + data.Installation_Code = inputSrc.Installation_Code } diff --git a/internal/use-case/main-use-case/unit-position/case.go b/internal/use-case/main-use-case/unit-position/case.go deleted file mode 100644 index c472e90c..00000000 --- a/internal/use-case/main-use-case/unit-position/case.go +++ /dev/null @@ -1,302 +0,0 @@ -package unit_position - -import ( - ee "simrs-vx/internal/domain/main-entities/employee" - eu "simrs-vx/internal/domain/main-entities/unit" - e "simrs-vx/internal/domain/main-entities/unit-position" - "strconv" - - ue "simrs-vx/internal/use-case/main-use-case/employee" - uu "simrs-vx/internal/use-case/main-use-case/unit" - - 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 = "unit-position" - -func Create(input e.CreateDto) (*d.Data, error) { - data := e.UnitPosition{} - - 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 err := validateForeignKey(input); 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.UnitPosition - var dataList []e.UnitPosition - 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.UnitPosition - 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{Code: &input.Code} - var data *e.UnitPosition - 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 := validateForeignKey(input.CreateDto); 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{Code: input.Code} - var data *e.UnitPosition - 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 installation_id - if _, err := uu.ReadDetail(eu.ReadDetailDto{Code: input.Unit_Code}); err != nil { - return err - } - - // validate employee_Id - if _, err := ue.ReadDetail(ee.ReadDetailDto{Id: uint16(*input.Employee_Id)}); err != nil { - return err - } - return nil -} diff --git a/internal/use-case/main-use-case/unit-position/helper.go b/internal/use-case/main-use-case/unit-position/helper.go deleted file mode 100644 index 827dfcc3..00000000 --- a/internal/use-case/main-use-case/unit-position/helper.go +++ /dev/null @@ -1,25 +0,0 @@ -/* -DESCRIPTION: -Any functions that are used internally by the use-case -*/ -package unit_position - -import ( - e "simrs-vx/internal/domain/main-entities/unit-position" -) - -func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.UnitPosition) { - var inputSrc *e.CreateDto - if inputT, ok := any(input).(*e.CreateDto); ok { - inputSrc = inputT - } else { - inputTemp := any(input).(*e.UpdateDto) - inputSrc = &inputTemp.CreateDto - } - - data.Unit_Code = inputSrc.Unit_Code - data.Code = inputSrc.Code - data.Name = inputSrc.Name - data.HeadStatus = inputSrc.HeadStatus - data.Employee_Id = inputSrc.Employee_Id -} diff --git a/internal/use-case/main-use-case/unit-position/lib.go b/internal/use-case/main-use-case/unit-position/lib.go deleted file mode 100644 index 104357e5..00000000 --- a/internal/use-case/main-use-case/unit-position/lib.go +++ /dev/null @@ -1,156 +0,0 @@ -package unit_position - -import ( - "errors" - e "simrs-vx/internal/domain/main-entities/unit-position" - - 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.UnitPosition, error) { - pl.SetLogInfo(event, nil, "started", "DBCreate") - - data := e.UnitPosition{} - 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.UnitPosition, *e.MetaDto, error) { - pl.SetLogInfo(event, input, "started", "DBReadList") - data := []e.UnitPosition{} - 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.UnitPosition{}). - Scopes(gh.Preload(input.Includes)). - Scopes(gh.Filter(input.FilterDto)). - Count(&count). - Scopes(gh.Paginate(input, &pagination)). - Scopes(gh.Sort(input.Sort)) - - 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.UnitPosition, error) { - pl.SetLogInfo(event, input, "started", "DBReadDetail") - data := e.UnitPosition{} - - var tx, getData *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - switch { - case input.Id != nil: - 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", - } - - 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 - } - } - - pl.SetLogInfo(event, nil, "complete") - return &data, nil -} - -func UpdateData(input e.UpdateDto, data *e.UnitPosition, 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.UnitPosition, 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/unit-position/middleware-runner.go b/internal/use-case/main-use-case/unit-position/middleware-runner.go deleted file mode 100644 index 73092025..00000000 --- a/internal/use-case/main-use-case/unit-position/middleware-runner.go +++ /dev/null @@ -1,103 +0,0 @@ -package unit_position - -import ( - e "simrs-vx/internal/domain/main-entities/unit-position" - 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.UnitPosition) 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.UnitPosition) 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.UnitPosition) 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.UnitPosition) 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.UnitPosition) 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/unit-position/middleware.go b/internal/use-case/main-use-case/unit-position/middleware.go deleted file mode 100644 index 44c1e396..00000000 --- a/internal/use-case/main-use-case/unit-position/middleware.go +++ /dev/null @@ -1,9 +0,0 @@ -package unit_position - -// 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/unit-position/tycovar.go b/internal/use-case/main-use-case/unit-position/tycovar.go deleted file mode 100644 index 451d6445..00000000 --- a/internal/use-case/main-use-case/unit-position/tycovar.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -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 unit_position - -import ( - "gorm.io/gorm" - - e "simrs-vx/internal/domain/main-entities/unit-position" -) - -type createMw struct { - Name string - Func func(input *e.CreateDto, data *e.UnitPosition, tx *gorm.DB) error -} - -type readListMw struct { - Name string - Func func(input *e.ReadListDto, data *e.UnitPosition, tx *gorm.DB) error -} - -type readDetailMw struct { - Name string - Func func(input *e.ReadDetailDto, data *e.UnitPosition, 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/unit/case.go b/internal/use-case/main-use-case/unit/case.go deleted file mode 100644 index c73c2c1d..00000000 --- a/internal/use-case/main-use-case/unit/case.go +++ /dev/null @@ -1,280 +0,0 @@ -package unit - -import ( - "errors" - e "simrs-vx/internal/domain/main-entities/unit" - erc "simrs-vx/internal/domain/references/common" - esync "simrs-vx/internal/domain/sync-entities/log" - "strconv" - - dg "github.com/karincake/apem/db-gorm-pg" - d "github.com/karincake/dodol" - - pl "simrs-vx/pkg/logger" - pu "simrs-vx/pkg/use-case-helper" - - "gorm.io/gorm" -) - -const source = "unit" - -func Create(input e.CreateDto) (*d.Data, error) { - data := e.Unit{} - - event := pl.Event{ - Feature: "Create", - Source: source, - } - - // Start log - pl.SetLogInfo(&event, input, "started", "create") - - // validate unit_code - _, err := strconv.Atoi(input.Code) - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "invalid_code_format", - Detail: "unit_code must be a valid integer", - Raw: errors.New("invalid unit_code format"), - } - return nil, pl.SetLogError(&event, input) - } - - mwRunner := newMiddlewareRunner(&event) - - err = dg.I.Transaction(func(tx *gorm.DB) error { - if resData, err := CreateData(input, &event, tx); err != nil { - return err - } else { - data = *resData - id := uint(data.Id) - input.Id = &id - } - - mwRunner.setMwType(pu.MWTPre) - // Run pre-middleware - if err := mwRunner.RunCreateMiddleware(createPreMw, &input); err != nil { - return err - } - - return nil - }) - - if err = runLogMiddleware(err, input, mwRunner); err != nil { - return nil, err - } - - pl.SetLogInfo(&event, nil, "complete") - - 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 dataList []e.Unit - 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 { - if dataList, metaList, err = ReadListData(input, &event, tx); 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.Unit - 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 { - if data, err = ReadDetailData(input, &event, tx); 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{Code: &input.Code} - var data *e.Unit - var err error - - event := pl.Event{ - Feature: "Update", - Source: source, - } - - // Start log - pl.SetLogInfo(&event, input, "started", "update") - mwRunner := newMiddlewareRunner(&event) - - 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 - } - - input.Id = &data.Id - if err := UpdateData(input, data, &event, tx); err != nil { - return err - } - - mwRunner.setMwType(pu.MWTPre) - // Run pre-middleware - if err := mwRunner.RunUpdateMiddleware(updatePreMw, &input); err != nil { - return err - } - - return nil - }) - - if err = runLogMiddleware(err, input, mwRunner); err != nil { - return nil, err - } - - pl.SetLogInfo(&event, nil, "complete") - - 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{Code: input.Code} - var data *e.Unit - var err error - - event := pl.Event{ - Feature: "Delete", - Source: source, - } - - // Start log - pl.SetLogInfo(&event, input, "started", "delete") - mwRunner := newMiddlewareRunner(&event) - - 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 - } - - input.Id = &data.Id - if err := DeleteData(data, &event, tx); err != nil { - return err - } - - mwRunner.setMwType(pu.MWTPre) - // Run pre-middleware - if err := mwRunner.RunDeleteMiddleware(deletePreMw, &input); err != nil { - return err - } - - return nil - }) - - if err = runLogMiddleware(err, input, mwRunner); err != nil { - return nil, err - } - - pl.SetLogInfo(&event, nil, "complete") - - return &d.Data{ - Meta: d.IS{ - "source": source, - "structure": "single-data", - "status": "deleted", - }, - Data: data.ToResponse(), - }, nil - -} - -func runLogMiddleware(err error, input any, mwRunner *middlewareRunner) error { - var errMsg string - inputLog := esync.SimxLogDto{ - Payload: input, - Method: erc.CCCreate, - } - - if err != nil { - // Run log-middleware - errMsg = err.Error() - inputLog.ErrMessage = &errMsg - inputLog.IsSuccess = false - - // create log failed - if errMiddleware := mwRunner.RunCreateLogMiddleware(createSimxLogMw, &inputLog); errMiddleware != nil { - return errMiddleware - } - return err - } - - // create log success - inputLog.IsSuccess = true - if err = mwRunner.RunCreateLogMiddleware(createSimxLogMw, &inputLog); err != nil { - return err - } - - return nil -} diff --git a/internal/use-case/main-use-case/unit/helper.go b/internal/use-case/main-use-case/unit/helper.go deleted file mode 100644 index 8ee7f7e6..00000000 --- a/internal/use-case/main-use-case/unit/helper.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -DESCRIPTION: -Any functions that are used internally by the use-case -*/ -package unit - -import ( - e "simrs-vx/internal/domain/main-entities/unit" -) - -func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Unit) { - var inputSrc *e.CreateDto - if inputT, ok := any(input).(*e.CreateDto); ok { - inputSrc = inputT - } else { - inputTemp := any(input).(*e.UpdateDto) - inputSrc = &inputTemp.CreateDto - } - - 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 deleted file mode 100644 index 3ec4a10c..00000000 --- a/internal/use-case/main-use-case/unit/lib.go +++ /dev/null @@ -1,149 +0,0 @@ -package unit - -import ( - e "simrs-vx/internal/domain/main-entities/unit" - - 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.Unit, error) { - pl.SetLogInfo(event, nil, "started", "DBCreate") - - data := e.Unit{} - 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.Unit, *e.MetaDto, error) { - pl.SetLogInfo(event, input, "started", "DBReadList") - data := []e.Unit{} - 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.Unit{}). - Scopes(gh.Preload(input.Includes)). - Scopes(gh.Filter(input.FilterDto)). - Count(&count). - Scopes(gh.Paginate(input, &pagination)). - Scopes(gh.Sort(input.Sort)) - - 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.Unit, error) { - pl.SetLogInfo(event, input, "started", "DBReadDetail") - data := e.Unit{} - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - 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).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.Unit, 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.Unit, 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/unit/middleware-runner.go b/internal/use-case/main-use-case/unit/middleware-runner.go deleted file mode 100644 index a02bb9cf..00000000 --- a/internal/use-case/main-use-case/unit/middleware-runner.go +++ /dev/null @@ -1,148 +0,0 @@ -package unit - -import ( - pl "simrs-vx/pkg/logger" - pu "simrs-vx/pkg/use-case-helper" - - "gorm.io/gorm" - - sync "simrs-vx/internal/infra/sync-consumer-cfg" - - e "simrs-vx/internal/domain/main-entities/unit" - esync "simrs-vx/internal/domain/sync-entities/log" -) - -type middlewareRunner struct { - Event *pl.Event - Tx *gorm.DB - MwType pu.MWType - SyncOn bool -} - -// NewMiddlewareExecutor creates a new middleware executor -func newMiddlewareRunner(event *pl.Event) *middlewareRunner { - return &middlewareRunner{ - Event: event, - SyncOn: sync.O.Enable, - } -} - -// ExecuteCreateMiddleware executes create middleware -func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto) error { - if !me.SyncOn { - return nil - } - - for _, middleware := range middlewares { - logData := pu.GetLogData(input, nil) - - pl.SetLogInfo(me.Event, logData, "started", middleware.Name) - - if err := middleware.Func(input); err != nil { - return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err) - } - - pl.SetLogInfo(me.Event, nil, "complete") - } - return nil -} - -// ExecuteCreateMiddleware executes create middleware -func (me *middlewareRunner) RunCreateLogMiddleware(middlewares []createLogMw, input *esync.SimxLogDto) error { - if !me.SyncOn { - return nil - } - - for _, middleware := range middlewares { - logData := pu.GetLogData(input, nil) - - pl.SetLogInfo(me.Event, logData, "started", middleware.Name) - - if err := middleware.Func(input); 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.Unit) error { - if !me.SyncOn { - return nil - } - - 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.Unit) error { - if !me.SyncOn { - return nil - } - - 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 []updateMw, input *e.UpdateDto) error { - if !me.SyncOn { - return nil - } - - for _, middleware := range middlewares { - logData := pu.GetLogData(input, nil) - - pl.SetLogInfo(me.Event, logData, "started", middleware.Name) - - if err := middleware.Func(input); 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 []deleteMw, input *e.DeleteDto) error { - if !me.SyncOn { - return nil - } - - for _, middleware := range middlewares { - logData := pu.GetLogData(input, nil) - - pl.SetLogInfo(me.Event, logData, "started", middleware.Name) - - if err := middleware.Func(input); 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/unit/middleware.go b/internal/use-case/main-use-case/unit/middleware.go deleted file mode 100644 index 03ef2c19..00000000 --- a/internal/use-case/main-use-case/unit/middleware.go +++ /dev/null @@ -1,20 +0,0 @@ -package unit - -import ( - plugin "simrs-vx/internal/use-case/simgos-sync-plugin/new/unit" -) - -// example of middleware -func init() { - createPreMw = append(createPreMw, - createMw{Name: "sync-create-unit", Func: plugin.Create}) - - createSimxLogMw = append(createSimxLogMw, - createLogMw{Name: "create-sync-log", Func: plugin.CreateLog}) - - updatePreMw = append(updatePreMw, - updateMw{Name: "sync-update-unit", Func: plugin.Update}) - - deletePreMw = append(deletePreMw, - deleteMw{Name: "sync-delete-unit", Func: plugin.Delete}) -} diff --git a/internal/use-case/main-use-case/unit/tycovar.go b/internal/use-case/main-use-case/unit/tycovar.go deleted file mode 100644 index bf717333..00000000 --- a/internal/use-case/main-use-case/unit/tycovar.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -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 unit - -import ( - "gorm.io/gorm" - - e "simrs-vx/internal/domain/main-entities/unit" - elog "simrs-vx/internal/domain/sync-entities/log" -) - -type createMw struct { - Name string - Func func(input *e.CreateDto) error -} - -type createLogMw struct { - Name string - Func func(input *elog.SimxLogDto) error -} - -type updateMw struct { - Name string - Func func(input *e.UpdateDto) error -} - -type deleteMw struct { - Name string - Func func(input *e.DeleteDto) error -} - -type readListMw struct { - Name string - Func func(input *e.ReadListDto, data *e.Unit, tx *gorm.DB) error -} - -type readDetailMw struct { - Name string - Func func(input *e.ReadDetailDto, data *e.Unit, tx *gorm.DB) error -} - -type UpdateMw = updateMw -type DeleteMw = deleteMw - -var createPreMw []createMw // preprocess middleware -var createPostMw []createMw // postprocess middleware -var createSimxLogMw []createLogMw -var readListPreMw []readListMw // .. -var readListPostMw []readListMw // .. -var readDetailPreMw []readDetailMw -var readDetailPostMw []readDetailMw -var updatePreMw []updateMw -var updatePostMw []readDetailMw -var deletePreMw []deleteMw -var deletePostMw []readDetailMw diff --git a/internal/use-case/main-use-case/user/case.go b/internal/use-case/main-use-case/user/case.go index 154695fb..e50aa156 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -114,7 +114,6 @@ func Create(input e.CreateDto) (*d.Data, error) { 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, } @@ -123,11 +122,11 @@ func Create(input e.CreateDto) (*d.Data, error) { } case ero.EPCNur: createNurse := en.CreateDto{ - Code: input.Code, - Employee_Id: &employeeData.Id, - IHS_Number: input.IHS_Number, - Unit_Code: input.Unit_Code, - Infra_Code: input.Infra_Code, + Code: input.Code, + Employee_Id: &employeeData.Id, + IHS_Number: input.IHS_Number, + Specialist_Code: input.Specialist_Code, + Infra_Code: input.Infra_Code, } if _, err := un.CreateData(createNurse, &event, tx); err != nil { return err @@ -436,11 +435,11 @@ func Update(input e.UpdateDto) (*d.Data, error) { return err } createNur := en.CreateDto{ - Code: input.Code, - Employee_Id: &employeeData.Id, - IHS_Number: input.IHS_Number, - Unit_Code: input.Unit_Code, - Infra_Code: input.Infra_Code, + Code: input.Code, + Employee_Id: &employeeData.Id, + IHS_Number: input.IHS_Number, + Specialist_Code: input.Specialist_Code, + Infra_Code: input.Infra_Code, } if readNurData != nil { if err := un.UpdateData(en.UpdateDto{CreateDto: createNur}, readNurData, &event, tx); err != nil { diff --git a/internal/use-case/simgos-sync-plugin/new/encounter/plugin.go b/internal/use-case/simgos-sync-plugin/new/encounter/plugin.go index 2f5e2515..69e79b77 100644 --- a/internal/use-case/simgos-sync-plugin/new/encounter/plugin.go +++ b/internal/use-case/simgos-sync-plugin/new/encounter/plugin.go @@ -49,19 +49,19 @@ func UpdateStatus(input *e.Encounter) error { return helper.DoJsonRequest(input, "PATCH", endpoint) } -func RequestSwitchUnit(input *e.Encounter) error { +func RequestSwitchSpecialist(input *e.Encounter) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v/req-switch-unit", prefixEndpoint, input.Id) return helper.DoJsonRequest(input, "PATCH", endpoint) } -func ApproveSwitchUnit(input *e.ApproveCancelUnitDto) error { +func ApproveSwitchSpecialist(input *e.ApproveCancelSpecialistDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v/approve-switch-unit", prefixEndpoint, input.Id) return helper.DoJsonRequest(input, "PATCH", endpoint) } -func CancelSwitchUnit(input *e.ApproveCancelUnitDto) error { +func CancelSwitchSpecialist(input *e.ApproveCancelSpecialistDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v/cancel-switch-unit", prefixEndpoint, input.Id) return helper.DoJsonRequest(input, "PATCH", endpoint) diff --git a/internal/use-case/simgos-sync-plugin/new/unit/plugin.go b/internal/use-case/simgos-sync-plugin/new/unit/plugin.go deleted file mode 100644 index f646f450..00000000 --- a/internal/use-case/simgos-sync-plugin/new/unit/plugin.go +++ /dev/null @@ -1,37 +0,0 @@ -package unit - -import ( - "fmt" - helper "simrs-vx/internal/use-case/simgos-sync-plugin/new" - - sync "simrs-vx/internal/infra/sync-consumer-cfg" - - e "simrs-vx/internal/domain/main-entities/unit" - elog "simrs-vx/internal/domain/sync-entities/log" -) - -func Create(input *e.CreateDto) error { - return helper.DoJsonRequest(input, "POST", getPrefixEndpoint()) -} - -func CreateLog(input *elog.SimxLogDto) error { - prefixEndpoint := getPrefixEndpoint() - endpoint := prefixEndpoint + "/log" - return helper.DoJsonRequest(input, "POST", endpoint) -} - -func Update(input *e.UpdateDto) error { - prefixEndpoint := getPrefixEndpoint() - endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - return helper.DoJsonRequest(input, "PATCH", endpoint) -} - -func Delete(input *e.DeleteDto) error { - prefixEndpoint := getPrefixEndpoint() - endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - return helper.DoJsonRequest(input, "DELETE", endpoint) -} - -func getPrefixEndpoint() string { - return fmt.Sprintf("%s%s/v1/unit", sync.O.TargetHost, sync.O.Prefix) -} diff --git a/internal/use-case/simgos-sync-plugin/old/.keep b/internal/use-case/simgos-sync-plugin/old/.keep new file mode 100644 index 00000000..e69de29b diff --git a/internal/use-case/simgos-sync-use-case/new/encounter/case.go b/internal/use-case/simgos-sync-use-case/new/encounter/case.go index 05c77915..db1cb654 100644 --- a/internal/use-case/simgos-sync-use-case/new/encounter/case.go +++ b/internal/use-case/simgos-sync-use-case/new/encounter/case.go @@ -368,18 +368,18 @@ func UpdateStatus(input e.Encounter) (*d.Data, error) { }, nil } -func RequestSwitchUnit(input e.Encounter) (*d.Data, error) { +func RequestSwitchSpecialist(input e.Encounter) (*d.Data, error) { var ( syncLinkInternal *[]syncir.InternalReferenceLink ) event := pl.Event{ - Feature: "RequestSwitchUnit", + Feature: "RequestSwitchSpecialist", Source: source, } // Start log - pl.SetLogInfo(&event, input, "started", "request-switch-unit") + pl.SetLogInfo(&event, input, "started", "request-switch-specialist") // STEP 1: Get Link syncLink, err := ReadDetailLinkData(input.Id, &event) @@ -431,14 +431,14 @@ func RequestSwitchUnit(input e.Encounter) (*d.Data, error) { }, nil } -func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { +func ApproveSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) { event := pl.Event{ - Feature: "ApproveSwitchUnit", + Feature: "ApproveSwitchSpecialist", Source: source, } // Start log - pl.SetLogInfo(&event, input, "started", "approve-switch-unit") + pl.SetLogInfo(&event, input, "started", "approve-switch-specialist") // STEP 1: Get InternalReference Link syncLink, err := utph.ReadDetailLinkData(input.InternalReferences_Id, &event) @@ -478,14 +478,14 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { }, nil } -func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) { +func CancelSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) { event := pl.Event{ - Feature: "CancelSwitchUnit", + Feature: "CancelSwitchSpecialist", Source: source, } // Start log - pl.SetLogInfo(&event, input, "started", "cancel-switch-unit") + pl.SetLogInfo(&event, input, "started", "cancel-switch-specialist") // STEP 1: Get InternalReference Link syncLink, err := utph.ReadDetailLinkData(input.InternalReferences_Id, &event) diff --git a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go index 97656afe..f88ba59f 100644 --- a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go @@ -77,8 +77,8 @@ func setDataTPendaftaran(input *e.Encounter, data *etp.TPendaftaran) { data.Tglreg = input.RegisteredAt // set kdpoly - if p := input.Unit_Code; p != nil { - kdpoly, _ := strconv.Atoi(*input.Unit_Code) + if p := input.Specialist_Code; p != nil { + kdpoly, _ := strconv.Atoi(*input.Specialist_Code) data.Kdpoly = uint(kdpoly) } diff --git a/internal/use-case/simgos-sync-use-case/new/internal-reference/helper.go b/internal/use-case/simgos-sync-use-case/new/internal-reference/helper.go index 9cb55785..6ac98549 100644 --- a/internal/use-case/simgos-sync-use-case/new/internal-reference/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/internal-reference/helper.go @@ -24,7 +24,7 @@ func setCreateDataSimgos(input e.Encounter, data *etp.TPendaftaran) (hist []etph for i, ref := range *enc { hist = append(hist, etph.TPemeriksaanHist{ Idxdaftar: &data.Idxdaftar, - Kdpoly: stringtouint(*ref.Unit_Code), + Kdpoly: stringtouint(*ref.Specialist_Code), DokterPengonsul: stringtouint(*ref.SrcDoctor_Code), DokterPenerima: stringtouint(*ref.Doctor_Code), }) @@ -46,7 +46,7 @@ func setCreateDataSimgos(input e.Encounter, data *etp.TPendaftaran) (hist []etph return } -func setUpdateApproveDataSimgos(input e.ApproveCancelUnitDto, data *etph.TPemeriksaanHist) { +func setUpdateApproveDataSimgos(input e.ApproveCancelSpecialistDto, data *etph.TPemeriksaanHist) { data.DokterPenerima = stringtouint(*input.Dst_Doctor_Code) data.StartKonsul = &now data.UserPenerima = &input.User_Name @@ -54,7 +54,7 @@ func setUpdateApproveDataSimgos(input e.ApproveCancelUnitDto, data *etph.TPemeri return } -func setUpdateCancelDataSimgos(input e.ApproveCancelUnitDto, data *etph.TPemeriksaanHist) { +func setUpdateCancelDataSimgos(input e.ApproveCancelSpecialistDto, data *etph.TPemeriksaanHist) { data.UserBatal = &input.User_Name data.TglBatal = &now diff --git a/internal/use-case/simgos-sync-use-case/new/internal-reference/lib.go b/internal/use-case/simgos-sync-use-case/new/internal-reference/lib.go index 2263f230..b3c526c5 100644 --- a/internal/use-case/simgos-sync-use-case/new/internal-reference/lib.go +++ b/internal/use-case/simgos-sync-use-case/new/internal-reference/lib.go @@ -61,7 +61,7 @@ func ReadDetailSimgosData(simgosId uint, event *pl.Event) (*etph.TPemeriksaanHis return &data, nil } -func UpdateSimgosData(input e.ApproveCancelUnitDto, data *etph.TPemeriksaanHist, method string, event *pl.Event, dbx ...*gorm.DB) error { +func UpdateSimgosData(input e.ApproveCancelSpecialistDto, data *etph.TPemeriksaanHist, method string, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, input, "started", "DBUpdate") switch method { diff --git a/internal/use-case/simgos-sync-use-case/new/unit/case.go b/internal/use-case/simgos-sync-use-case/new/unit/case.go deleted file mode 100644 index 3450a4cb..00000000 --- a/internal/use-case/simgos-sync-use-case/new/unit/case.go +++ /dev/null @@ -1,198 +0,0 @@ -package unit - -import ( - pl "simrs-vx/pkg/logger" - - d "github.com/karincake/dodol" - "gorm.io/gorm" - - db "simrs-vx/pkg/dualtrx-helper" - - e "simrs-vx/internal/domain/main-entities/unit" - esimgos "simrs-vx/internal/domain/simgos-entities/m-poly" - elog "simrs-vx/internal/domain/sync-entities/log" - esync "simrs-vx/internal/domain/sync-entities/unit" -) - -const source = "unit" - -func Create(input e.CreateDto) (*d.Data, error) { - var ( - sgData *esimgos.MPoly - syncLink *esync.UnitLink - err error - ) - - event := pl.Event{ - Feature: "Create", - Source: source, - } - - // Start log - pl.SetLogInfo(&event, input, "started", "create") - - err = db.WithDualTx(func(tx *db.Dualtx) error { - // STEP 1: Insert to simgos - sgData, err = CreateSimgosData(input, &event, tx.Simgos) - if err != nil { - return err - } - - // STEP 2: Insert to Link - syncLink, err = CreateLinkData(*input.Id, sgData.Kode, &event, tx.Sync) - if err != nil { - return err - } - - return nil - }) - - if err != nil { - if syncLink != nil { - go func() { _ = DeleteLinkData(syncLink, &event) }() - } - return nil, err - } - - pl.SetLogInfo(&event, nil, "complete") - - return &d.Data{ - Meta: d.II{ - "source": source, - "structure": "single-data", - "status": "created", - }, - }, nil -} - -func CreateSimxLog(input elog.SimxLogDto) (*d.Data, error) { - event := pl.Event{ - Feature: "Create", - Source: source, - } - - // Start log - pl.SetLogInfo(&event, input, "started", "create") - - tx := db.NewTx() - err := tx.Sync.Transaction(func(tx *gorm.DB) error { - // Insert to Log - if err := CreateLogData(input, &event, tx); err != nil { - return err - } - - return nil - }) - - if err != nil { - return nil, err - } - - pl.SetLogInfo(&event, nil, "complete") - - return &d.Data{ - Meta: d.II{ - "source": source, - "structure": "single-data", - "status": "created", - }, - }, nil -} - -func Update(input e.UpdateDto) (*d.Data, error) { - event := pl.Event{ - Feature: "Update", - Source: source, - } - - // Start log - pl.SetLogInfo(&event, input, "started", "update") - - // STEP 1: Get Installation Link - syncLink, err := ReadDetailLinkData(*input.Id, &event) - if err != nil { - return nil, err - } - - tx := db.NewTx() - err = tx.Simgos.Transaction(func(tx *gorm.DB) error { - // Step 2: Update Simgos - err = UpdateSimgosData(input, syncLink, &event, tx) - if err != nil { - return err - } - - return nil - }) - - pl.SetLogInfo(&event, nil, "complete") - - return &d.Data{ - Meta: d.IS{ - "source": source, - "structure": "single-data", - "status": "updated", - }, - }, nil -} - -func Delete(input e.DeleteDto) (*d.Data, error) { - var isLinkDeleted bool - - event := pl.Event{ - Feature: "Delete", - Source: source, - } - - // Start log - pl.SetLogInfo(&event, input, "started", "delete") - - // STEP 1: Get Installation Link - syncLink, err := ReadDetailLinkData(*input.Id, &event) - if err != nil { - return nil, err - } - - // STEP 2: Get Simgos - sgData, err := ReadDetailSimgosData(uint16(syncLink.Simgos_Id), &event) - if err != nil { - return nil, err - } - - err = db.WithDualTx(func(tx *db.Dualtx) error { - // STEP 3: Delete M_Poly Simgos - err = HardDeleteSimgosData(sgData, &event, tx.Simgos) - if err != nil { - return err - } - - // STEP 4: Delete Installation Link - err = DeleteLinkData(syncLink, &event, tx.Sync) - if err != nil { - return err - } - - isLinkDeleted = true - return nil - }) - - if err != nil { - if isLinkDeleted { - go func() { - _, _ = CreateLinkData(uint(*input.Id), sgData.Kode, &event) - }() - } - return nil, err - } - - pl.SetLogInfo(&event, nil, "complete") - - return &d.Data{ - Meta: d.IS{ - "source": source, - "structure": "single-data", - "status": "deleted", - }, - }, nil - -} diff --git a/internal/use-case/simgos-sync-use-case/new/unit/helper.go b/internal/use-case/simgos-sync-use-case/new/unit/helper.go deleted file mode 100644 index d7dfb1f6..00000000 --- a/internal/use-case/simgos-sync-use-case/new/unit/helper.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -DESCRIPTION: -Any functions that are used internally by the use-case -*/ -package unit - -import ( - "encoding/json" - erc "simrs-vx/internal/domain/references/common" - "strconv" - - e "simrs-vx/internal/domain/main-entities/unit" - - esimgos "simrs-vx/internal/domain/simgos-entities/m-poly" - esyncLog "simrs-vx/internal/domain/sync-entities/log" - esync "simrs-vx/internal/domain/sync-entities/unit" -) - -func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T) (data esimgos.MPoly) { - var inputSrc *e.CreateDto - if inputT, ok := any(input).(*e.CreateDto); ok { - inputSrc = inputT - } else { - inputTemp := any(input).(*e.UpdateDto) - inputSrc = &inputTemp.CreateDto - } - - data.Nama = inputSrc.Name - data.Jenispoly = 0 - - kodePoly, _ := strconv.Atoi(inputSrc.Code) - data.Kode = uint(kodePoly) - return -} - -func setDataSimxLog(input *esyncLog.SimxLogDto) (data esync.UnitSimxLog) { - // encode to JSON - jsonData, _ := json.MarshalIndent(input.Payload, "", " ") - jsonString := string(jsonData) - - var status erc.ProcessStatusCode - if input.IsSuccess { - status = erc.PSCSuccess - } else { - status = erc.PSCFailed - if input.ErrMessage != nil { - data.ErrMessage = input.ErrMessage - } - } - - data.Value = &jsonString - data.Date = &now - data.Status = status - - return -} - -func setDataSimxLink(simxId, simgosId uint) (data esync.UnitLink) { - data.Simx_Id = simxId - data.Simgos_Id = simgosId - return -} diff --git a/internal/use-case/simgos-sync-use-case/new/unit/lib.go b/internal/use-case/simgos-sync-use-case/new/unit/lib.go deleted file mode 100644 index 8712ab03..00000000 --- a/internal/use-case/simgos-sync-use-case/new/unit/lib.go +++ /dev/null @@ -1,188 +0,0 @@ -package unit - -import ( - plh "simrs-vx/pkg/lib-helper" - pl "simrs-vx/pkg/logger" - pu "simrs-vx/pkg/use-case-helper" - "time" - - dg "github.com/karincake/apem/db-gorm-pg" - "gorm.io/gorm" - - e "simrs-vx/internal/domain/main-entities/unit" - esimgos "simrs-vx/internal/domain/simgos-entities/m-poly" - esynclog "simrs-vx/internal/domain/sync-entities/log" - esync "simrs-vx/internal/domain/sync-entities/unit" -) - -var now = time.Now() - -func CreateSimgosData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*esimgos.MPoly, error) { - pl.SetLogInfo(event, nil, "started", "DBCreate") - - data := setDataSimgos(&input) - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.IS["simrs"] - } - - if err := tx.Create(&data).Error; err != nil { - return nil, plh.HandleCreateError(input, event, err) - } - - pl.SetLogInfo(event, nil, "complete") - return &data, nil -} - -func ReadDetailSimgosData(simgosId uint16, event *pl.Event) (*esimgos.MPoly, error) { - pl.SetLogInfo(event, simgosId, "started", "DBReadDetail") - data := esimgos.MPoly{} - - var tx = dg.IS["simrs"] - - if err := tx. - Where("\"kode\" = ?", simgosId). - First(&data).Error; err != nil { - if processedErr := pu.HandleReadError(err, event, source, simgosId, data); processedErr != nil { - return nil, processedErr - } - } - - pl.SetLogInfo(event, nil, "complete") - return &data, nil -} - -func UpdateSimgosData(input e.UpdateDto, dataSimgos *esync.UnitLink, event *pl.Event, dbx ...*gorm.DB) error { - pl.SetLogInfo(event, input, "started", "DBUpdate") - - data := setDataSimgos(&input) - data.Kode = dataSimgos.Simgos_Id - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.IS["simrs"] - } - - 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 HardDeleteSimgosData(data *esimgos.MPoly, 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.IS["simrs"] - } - - 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 -} - -func CreateLinkData(simxId, simgosId uint, event *pl.Event, dbx ...*gorm.DB) (*esync.UnitLink, error) { - pl.SetLogInfo(event, nil, "started", "DBCreate") - data := setDataSimxLink(simxId, simgosId) - - 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(data, event, err) - } - - pl.SetLogInfo(event, nil, "complete") - return &data, nil -} - -func ReadDetailLinkData(simxId uint16, event *pl.Event) (*esync.UnitLink, error) { - pl.SetLogInfo(event, simxId, "started", "DBReadDetail") - data := esync.UnitLink{} - - var tx = dg.I - - if err := tx. - Where("\"Simx_Id\" = ?", simxId). - First(&data).Error; err != nil { - if processedErr := pu.HandleReadError(err, event, source, simxId, data); processedErr != nil { - return nil, processedErr - } - } - - pl.SetLogInfo(event, nil, "complete") - return &data, nil -} - -func DeleteLinkData(data *esync.UnitLink, 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 -} - -func CreateLogData(input esynclog.SimxLogDto, event *pl.Event, dbx ...*gorm.DB) error { - pl.SetLogInfo(event, nil, "started", "DBCreate") - data := setDataSimxLog(&input) - - 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 -} diff --git a/internal/use-case/simgos-sync-use-case/new/unit/middleware-runner.go b/internal/use-case/simgos-sync-use-case/new/unit/middleware-runner.go deleted file mode 100644 index 64426eb9..00000000 --- a/internal/use-case/simgos-sync-use-case/new/unit/middleware-runner.go +++ /dev/null @@ -1,104 +0,0 @@ -package unit - -import ( - pl "simrs-vx/pkg/logger" - pu "simrs-vx/pkg/use-case-helper" - - "gorm.io/gorm" - - e "simrs-vx/internal/domain/main-entities/unit" -) - -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.Unit) 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.Unit) 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.Unit) 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.Unit) 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.Unit) 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/simgos-sync-use-case/new/unit/middleware.go b/internal/use-case/simgos-sync-use-case/new/unit/middleware.go deleted file mode 100644 index bac48f4d..00000000 --- a/internal/use-case/simgos-sync-use-case/new/unit/middleware.go +++ /dev/null @@ -1,9 +0,0 @@ -package unit - -// 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/simgos-sync-use-case/new/unit/tycovar.go b/internal/use-case/simgos-sync-use-case/new/unit/tycovar.go deleted file mode 100644 index e1a7c69f..00000000 --- a/internal/use-case/simgos-sync-use-case/new/unit/tycovar.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -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 unit - -import ( - "gorm.io/gorm" - - e "simrs-vx/internal/domain/main-entities/unit" -) - -type createMw struct { - Name string - Func func(input *e.CreateDto, data *e.Unit, tx *gorm.DB) error -} - -type readListMw struct { - Name string - Func func(input *e.ReadListDto, data *e.Unit, tx *gorm.DB) error -} - -type readDetailMw struct { - Name string - Func func(input *e.ReadDetailDto, data *e.Unit, 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 3e266f1d0cd195b87550b8bd99bc5a4a771c6882 Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 11 Dec 2025 18:40:48 +0700 Subject: [PATCH 39/39] adjust subspecialist entity --- cmd/main-migration/migrations/20251211113942.sql | 4 ++++ cmd/main-migration/migrations/atlas.sum | 5 +++-- cmd/simgos-sync-migration/migrations/atlas.sum | 4 ++-- internal/domain/main-entities/subspecialist/base/entity.go | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 cmd/main-migration/migrations/20251211113942.sql diff --git a/cmd/main-migration/migrations/20251211113942.sql b/cmd/main-migration/migrations/20251211113942.sql new file mode 100644 index 00000000..b357f487 --- /dev/null +++ b/cmd/main-migration/migrations/20251211113942.sql @@ -0,0 +1,4 @@ +-- Modify "Subspecialist" table +ALTER TABLE "public"."Subspecialist" ALTER COLUMN "Name" TYPE character varying(100); +-- Modify "Specialist" table +ALTER TABLE "public"."Specialist" ADD COLUMN "Installation_Code" character varying(20) NULL, ADD CONSTRAINT "fk_Specialist_Installation" FOREIGN KEY ("Installation_Code") REFERENCES "public"."Installation" ("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 40d1acc3..3ff7d286 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:B4Ghh1AyZG5WD/79iuFWUIRiik0xl2zgtiWRWJ/prTU= +h1:IfSOZ5RxGCWboRtqCJrYxCJa1HYSrlROJLXcElq1P3I= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -161,4 +161,5 @@ h1:B4Ghh1AyZG5WD/79iuFWUIRiik0xl2zgtiWRWJ/prTU= 20251209070128.sql h1:fPGE6xOV6uCiVOqnvwn2L/GsBbgp2wxgmZOhF3bSGGM= 20251209084929.sql h1:u4LPMvkGAH4RfGC2IlBTIm7T7paMHoBSvTQ0w5Br7d0= 20251210145148.sql h1:rejGrnTpaygxPv06v0vxMytF4rk1OJBXaw3ttSmidgc= -20251211101547.sql h1:rRb5Azkx3yvOYIGIXiuAYU26gviETwWarfAaiQY+FLk= +20251211101547.sql h1:+jT5yRCEsSRExzoawrqymS/I7lVfwUQQSgSzbxCxgRk= +20251211113942.sql h1:F8go8XaJf4GFa4RuoMlo4U/NtbDtbDkVYHZOJz7GYhM= diff --git a/cmd/simgos-sync-migration/migrations/atlas.sum b/cmd/simgos-sync-migration/migrations/atlas.sum index c06e3535..a6ba5a4a 100644 --- a/cmd/simgos-sync-migration/migrations/atlas.sum +++ b/cmd/simgos-sync-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:D3uD6s7yxMG7Roi9DCeYuLeRazZmQnd3rHMmUWf6YMM= +h1:V6uRNFb6js/aPft2hebJMA8tI0YJc4BuZ7Rlp56FV00= 20251113035508.sql h1:rjDlu6yDdy5xv6nrCOr7NialrLSLT23pzduYNq29Hf0= 20251114071129.sql h1:Z0GQ5bJo3C+tplaWzxT8n3J9HLkEaVsRVp5nn7bmYow= 20251117041601.sql h1:l/RPG5mObqCSBjO4mzG+wTq2ieSycvlfOSz4czpUdWY= @@ -6,4 +6,4 @@ h1:D3uD6s7yxMG7Roi9DCeYuLeRazZmQnd3rHMmUWf6YMM= 20251118082915.sql h1:hP6FmUVFuADIN2cDg2Z1l7Wx7PQRb+IYQDvKD7J8VAM= 20251126115527.sql h1:Bvg+Y7k+h5s+/UaezUyJb7J7uzEJS7U5Z/RoCixcUtI= 20251201093443.sql h1:dyiD1WzU9D6RjGhF0AtGfGLEsG6yocuk3HbcZWt9ZRQ= -20251209083238.sql h1:83pG5dPfMh8v0QognjeacK6s3fGxQ0nkijxtKL5y3Dc= +20251209083238.sql h1:GmnvITp+vr3sYlWmPxWVxMnjSIRI0QKmv9i202kRgp4= diff --git a/internal/domain/main-entities/subspecialist/base/entity.go b/internal/domain/main-entities/subspecialist/base/entity.go index 9fe77039..14804da4 100644 --- a/internal/domain/main-entities/subspecialist/base/entity.go +++ b/internal/domain/main-entities/subspecialist/base/entity.go @@ -7,7 +7,7 @@ import ( type Basic struct { ecore.SmallMain // adjust this according to the needs Code string `json:"code" gorm:"unique;size:20"` - Name string `json:"name" gorm:"size:50"` + Name string `json:"name" gorm:"size:100"` Specialist_Code *string `json:"specialist_code" gorm:"size:20"` }