From 3391ee0937c9a8a70c7079957c9778c88075528c Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Sun, 2 Nov 2025 16:18:35 +0700 Subject: [PATCH 1/3] feat/trx-orders: added scope for order filtering --- .../domain/main-entities/mcu-order/dto.go | 73 ++++++++++--------- .../domain/main-entities/mcu-order/entity.go | 24 +++--- .../main-use-case/mcu-order/helper.go | 2 +- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/internal/domain/main-entities/mcu-order/dto.go b/internal/domain/main-entities/mcu-order/dto.go index 9c540d56..3d042c2f 100644 --- a/internal/domain/main-entities/mcu-order/dto.go +++ b/internal/domain/main-entities/mcu-order/dto.go @@ -20,14 +20,14 @@ import ( ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor_id"` - SpecimenPickTime *time.Time `json:"specimenPickTime"` - ExaminationDate *time.Time `json:"examinationDate"` - Number uint8 `json:"number"` - Temperature float64 `json:"temperature"` - McuUrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"mcuUrgencyLevel_code"` + Encounter_Id *uint `json:"encounter_id"` + Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` + Doctor_Id *uint `json:"doctor_id"` + SpecimenPickTime *time.Time `json:"specimenPickTime"` + ExaminationDate *time.Time `json:"examinationDate"` + Number uint8 `json:"number"` + Temperature float64 `json:"temperature"` + UrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"urgencyLevel_code"` pa.AuthInfo } @@ -39,14 +39,15 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Status_Code erc.DataStatusCode `json:"status-code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor-id"` - SpecimenPickTime *time.Time `json:"specimenPickTime"` - ExaminationDate *time.Time `json:"examinationDate"` - Number uint8 `json:"number"` - Temperature float64 `json:"temperature"` - McuUrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"mcuUrgencyLevel-code"` + Encounter_Id *uint `json:"encounter-id"` + Status_Code erc.DataStatusCode `json:"status-code" gorm:"not null;size:10"` + Doctor_Id *uint `json:"doctor-id"` + SpecimenPickTime *time.Time `json:"specimenPickTime"` + ExaminationDate *time.Time `json:"examinationDate"` + Number uint8 `json:"number"` + Temperature float64 `json:"temperature"` + UrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"urgency-level-code"` + Scope_Code ercl.McuUrgencyLevelCode `json:"scope-code"` } type ReadDetailDto struct { Id uint `json:"id"` @@ -74,30 +75,30 @@ type MetaDto struct { } type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` - SpecimenPickTime *time.Time `json:"specimenPickTime"` - ExaminationDate *time.Time `json:"examinationDate"` - Number uint8 `json:"number"` - Temperature float64 `json:"temperature"` - McuUrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"mcuUrgencyLevel_code""` + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + SpecimenPickTime *time.Time `json:"specimenPickTime"` + ExaminationDate *time.Time `json:"examinationDate"` + Number uint8 `json:"number"` + Temperature float64 `json:"temperature"` + UrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"urgencyLevel_code""` } func (d McuOrder) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Encounter: d.Encounter, - Status_Code: d.Status_Code, - Doctor_Id: d.Doctor_Id, - Doctor: d.Doctor, - SpecimenPickTime: d.SpecimenPickTime, - ExaminationDate: d.ExaminationDate, - Number: d.Number, - Temperature: d.Temperature, - McuUrgencyLevel_Code: d.McuUrgencyLevel_Code, + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Status_Code: d.Status_Code, + Doctor_Id: d.Doctor_Id, + Doctor: d.Doctor, + SpecimenPickTime: d.SpecimenPickTime, + ExaminationDate: d.ExaminationDate, + Number: d.Number, + Temperature: d.Temperature, + UrgencyLevel_Code: d.UrgencyLevel_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/mcu-order/entity.go b/internal/domain/main-entities/mcu-order/entity.go index 38053523..d2b81e58 100644 --- a/internal/domain/main-entities/mcu-order/entity.go +++ b/internal/domain/main-entities/mcu-order/entity.go @@ -12,18 +12,18 @@ import ( ) type McuOrder struct { - ecore.Main // adjust this according to the needs - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` - SpecimenPickTime *time.Time `json:"specimenPickTime"` - ExaminationDate *time.Time `json:"examinationDate"` - Number uint8 `json:"number"` - Temperature float64 `json:"temperature"` - McuUrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"mcuUrgencyLevel_code" gorm:"not null;size:15"` - Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"index;size:10"` + ecore.Main // adjust this according to the needs + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + SpecimenPickTime *time.Time `json:"specimenPickTime"` + ExaminationDate *time.Time `json:"examinationDate"` + Number uint8 `json:"number"` + Temperature float64 `json:"temperature"` + UrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"urgencyLevel_code" gorm:"not null;size:15"` + Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"index;size:10"` } func (d McuOrder) IsCompleted() bool { diff --git a/internal/use-case/main-use-case/mcu-order/helper.go b/internal/use-case/main-use-case/mcu-order/helper.go index 8c7115b6..c7d6fc6f 100644 --- a/internal/use-case/main-use-case/mcu-order/helper.go +++ b/internal/use-case/main-use-case/mcu-order/helper.go @@ -26,6 +26,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuOrder) { data.ExaminationDate = inputSrc.ExaminationDate data.Number = inputSrc.Number data.Temperature = inputSrc.Temperature - data.McuUrgencyLevel_Code = inputSrc.McuUrgencyLevel_Code + data.UrgencyLevel_Code = inputSrc.UrgencyLevel_Code data.Doctor_Id = inputSrc.Doctor_Id } From 149253b00f19507e9319568a89efc80548d13529 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Sun, 2 Nov 2025 22:16:02 +0700 Subject: [PATCH 2/3] feat/trx-orders: fixes + renamed a column on table McuOrderItem +migration --- cmd/main-migration/migrations/20251102091932.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 5 +++-- internal/domain/main-entities/mcu-order-item/dto.go | 4 ++-- internal/use-case/main-use-case/mcu-order-item/lib.go | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 cmd/main-migration/migrations/20251102091932.sql diff --git a/cmd/main-migration/migrations/20251102091932.sql b/cmd/main-migration/migrations/20251102091932.sql new file mode 100644 index 00000000..f10eadd3 --- /dev/null +++ b/cmd/main-migration/migrations/20251102091932.sql @@ -0,0 +1,2 @@ +-- Rename a column from "McuUrgencyLevel_Code" to "UrgencyLevel_Code" +ALTER TABLE "public"."McuOrder" RENAME COLUMN "McuUrgencyLevel_Code" TO "UrgencyLevel_Code"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 73107582..5162b628 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:ewCVlZr73Pj7qD/A+J5/yF94CncwZCb6s8VSHl0Hawo= +h1:A+ajQZrPn+BR8s8J5tX9DrfLEzZbstFw0klWQiK5Nao= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -62,4 +62,5 @@ h1:ewCVlZr73Pj7qD/A+J5/yF94CncwZCb6s8VSHl0Hawo= 20251025013609.sql h1:evPJaTD8WxYRMOJZHkSr7ONLx9PYxT+ankzQt9c/sJ0= 20251027075128.sql h1:/iFQBM1sytjqpyQSOx61q33gnorMgxTiFVSuL6bQqsM= 20251027091406.sql h1:eCZGtUkxAzEAqpC9UsGpP8Df9mS0DEOqSl885LgqpvM= -20251102002037.sql h1:FTJ9KdTOhso+wNbDoEtvj3D8XkgT6blu79JucGQoprg= +20251102002037.sql h1:lFJbuoZ2LMQnUNGdcwHVY3Xlfslgzu9t2WByT8yfOZI= +20251102091932.sql h1:QfMos5PVRvCsA427b505VSKxoFERhxx07DcP4WhSd7U= diff --git a/internal/domain/main-entities/mcu-order-item/dto.go b/internal/domain/main-entities/mcu-order-item/dto.go index 64e56a85..75e02184 100644 --- a/internal/domain/main-entities/mcu-order-item/dto.go +++ b/internal/domain/main-entities/mcu-order-item/dto.go @@ -23,8 +23,8 @@ type ReadListDto struct { } type FilterDto struct { - McuOrder_Id *uint `json:"mcuOrder-id"` - McuSrc_Id *uint `json:"mcuSrc-id"` + McuOrder_Id *uint `json:"mcu-order-id"` + McuSrc_Id *uint `json:"mcu-src-id"` Result *string `json:"result"` Status_Code erc.DataStatusCode `json:"status-code"` } diff --git a/internal/use-case/main-use-case/mcu-order-item/lib.go b/internal/use-case/main-use-case/mcu-order-item/lib.go index 13030ce8..4b5bb04f 100644 --- a/internal/use-case/main-use-case/mcu-order-item/lib.go +++ b/internal/use-case/main-use-case/mcu-order-item/lib.go @@ -24,10 +24,10 @@ func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.McuOrde deletedData := e.McuOrderItem{} tx.Unscoped(). - Where("\"McuOrder_Id\" = ? AND \"McuSrc_Id\" = ?", input.McuOrder_Id, input.McuSrc_Id). + Where("\"McuOrder_Id\" = ? AND \"McuSrc_Id\" = ?", *input.McuOrder_Id, input.McuSrc_Id). First(&deletedData) if deletedData.Id != 0 { - if err := tx.Model(e.McuOrderItem{}).Where("Id = ?", deletedData.Id).Update("DeletedAt", nil).Error; err != nil { + if err := tx.Unscoped().Model(e.McuOrderItem{}).Where("\"Id\" = ?", deletedData.Id).Update("\"DeletedAt\"", nil).Error; err != nil { return nil, plh.HandleCreateError(input, event, err) } return &deletedData, nil From 474939278833d00efa47dc227eb76d882aa45dee Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 3 Nov 2025 15:17:11 +0700 Subject: [PATCH 3/3] add control-letter --- .../migrations/20251103081637.sql | 17 +++ cmd/main-migration/migrations/atlas.sum | 5 +- .../main-entities/control-letter/dto.go | 104 ++++++++++++++++++ .../main-entities/control-letter/entity.go | 24 ++++ internal/interface/migration/main-entities.go | 2 + 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 cmd/main-migration/migrations/20251103081637.sql create mode 100644 internal/domain/main-entities/control-letter/dto.go create mode 100644 internal/domain/main-entities/control-letter/entity.go diff --git a/cmd/main-migration/migrations/20251103081637.sql b/cmd/main-migration/migrations/20251103081637.sql new file mode 100644 index 00000000..ca898d90 --- /dev/null +++ b/cmd/main-migration/migrations/20251103081637.sql @@ -0,0 +1,17 @@ +-- Create "ControlLetter" table +CREATE TABLE "public"."ControlLetter" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Unit_Id" bigint NULL, + "Specialist_Id" bigint NULL, + "Subspecialist_Id" bigint NULL, + "Date" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ControlLetter_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ControlLetter_Specialist" FOREIGN KEY ("Specialist_Id") REFERENCES "public"."Specialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ControlLetter_Subspecialist" FOREIGN KEY ("Subspecialist_Id") REFERENCES "public"."Subspecialist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ControlLetter_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 5162b628..b5785611 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:A+ajQZrPn+BR8s8J5tX9DrfLEzZbstFw0klWQiK5Nao= +h1:zJVjtCkiWEF41JV7lzbRtI5mPZGz5bC8FaVruh3fmkY= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -63,4 +63,5 @@ h1:A+ajQZrPn+BR8s8J5tX9DrfLEzZbstFw0klWQiK5Nao= 20251027075128.sql h1:/iFQBM1sytjqpyQSOx61q33gnorMgxTiFVSuL6bQqsM= 20251027091406.sql h1:eCZGtUkxAzEAqpC9UsGpP8Df9mS0DEOqSl885LgqpvM= 20251102002037.sql h1:lFJbuoZ2LMQnUNGdcwHVY3Xlfslgzu9t2WByT8yfOZI= -20251102091932.sql h1:QfMos5PVRvCsA427b505VSKxoFERhxx07DcP4WhSd7U= +20251102091932.sql h1:rmdhb5m+P+fU8jROBZNyeYgZKuQvucsuljXv4ZVzvks= +20251103081637.sql h1:jqpMnygFceOJn0rI30GYWI2CKbOu6RzVqw2/Pji2Ka8= diff --git a/internal/domain/main-entities/control-letter/dto.go b/internal/domain/main-entities/control-letter/dto.go new file mode 100644 index 00000000..270ff7b5 --- /dev/null +++ b/internal/domain/main-entities/control-letter/dto.go @@ -0,0 +1,104 @@ +package controlletter + +import ( + // std + "time" + + // internal - lib + pa "simrs-vx/internal/lib/auth" + + // internal - domain - base-entities + ecore "simrs-vx/internal/domain/base-entities/core" + + // internal - domain - main-entities + + 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 { + Encounter_Id *uint `json:"encounter_id"` + Unit_Id *uint `json:"unit_id"` + Specialist_Id *uint `json:"specialist_id"` + Subspecialist_Id *uint `json:"subspecialist_id"` + Date *time.Time `json:"date"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Encounter_Id *uint `json:"encounter-id"` + Unit_Id *uint `json:"unit-id"` + Specialist_Id *uint `json:"specialist-id"` + Subspecialist_Id *uint `json:"subspecialist-id"` + Date *time.Time `json:"date"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` +} + +type UpdateDto struct { + Id uint `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint `json:"id"` +} + +type ReplyDto struct { + Id uint `json:"id"` + Solution *string `json:"solution"` + + pa.AuthInfo +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` + Unit_Id *uint `json:"unit_id"` + Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` + Specialist_Id *uint `json:"specialist_id"` + Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"` + Subspecialist_Id *uint `json:"subspecialist_id"` + Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Date *time.Time `json:"date"` +} + +func (d ControlLetter) ToResponse() ResponseDto { + resp := ResponseDto{ + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Unit_Id: d.Unit_Id, + Unit: d.Unit, + Specialist_Id: d.Specialist_Id, + Specialist: d.Specialist, + Subspecialist_Id: d.Subspecialist_Id, + Subspecialist: d.Subspecialist, + Date: d.Date, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []ControlLetter) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/control-letter/entity.go b/internal/domain/main-entities/control-letter/entity.go new file mode 100644 index 00000000..9cf74a68 --- /dev/null +++ b/internal/domain/main-entities/control-letter/entity.go @@ -0,0 +1,24 @@ +package controlletter + +import ( + "time" + + ecore "simrs-vx/internal/domain/base-entities/core" + 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_Id *uint `json:"unit_id"` + Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` + Specialist_Id *uint `json:"specialist_id"` + Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"` + Subspecialist_Id *uint `json:"subspecialist_id"` + Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Date *time.Time `json:"date"` +} diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 6507202e..28fd0376 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -8,6 +8,7 @@ import ( appointment "simrs-vx/internal/domain/main-entities/appointment" chemo "simrs-vx/internal/domain/main-entities/chemo" consultation "simrs-vx/internal/domain/main-entities/consultation" + controlletter "simrs-vx/internal/domain/main-entities/control-letter" counter "simrs-vx/internal/domain/main-entities/counter" deathcause "simrs-vx/internal/domain/main-entities/death-cause" device "simrs-vx/internal/domain/main-entities/device" @@ -193,5 +194,6 @@ func getMainEntities() []any { &responsibledoctorhist.ResponsibleDoctorHist{}, &admemployeehist.AdmEmployeeHist{}, &vclaimmember.VclaimMember{}, + &controlletter.ControlLetter{}, } }