diff --git a/cmd/main-migration/migrations/20251017082207.sql b/cmd/main-migration/migrations/20251017082207.sql new file mode 100644 index 00000000..732c8d71 --- /dev/null +++ b/cmd/main-migration/migrations/20251017082207.sql @@ -0,0 +1,2 @@ +-- Modify "Item" table +ALTER TABLE "public"."Item" ALTER COLUMN "ItemGroup_Code" TYPE character varying(15); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 1f920b2d..77732bde 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:sU0SrZhFKtCYoF46RbBCtQHOoDtvLJtLcIfBvmeawkg= +h1:/NZRnBd4SNPxw+Sv7Fhn/VBxN0wRNU4OldkTUn6GtbI= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -47,4 +47,5 @@ h1:sU0SrZhFKtCYoF46RbBCtQHOoDtvLJtLcIfBvmeawkg= 20251016010845.sql h1:4BncQdDOasRZJkzVJrSJJA7091A9VPNVx/faUCUPhBM= 20251016011023.sql h1:9JB9eFZKURK5RoCVDKR6glSvdJ8NTXrN7K/4q51zkz4= 20251016062912.sql h1:ACNn0fe+EMqUt3hoY+Dr3uqAV/QICBa1+mIW7fUc9Fk= -20251017060617.sql h1:KzIbA9fYORIK9aGWMMf0te5/8oThYFCCCSQVktGO0K0= +20251017060617.sql h1:4T3t9ifWrEQTPMSM0XJ98pF7Qdt+UfgtMui17bhrnWI= +20251017082207.sql h1:M3k5WPGt8gxv/4kB71di+78L/FyXrxhgGtXxGedwEps= diff --git a/internal/domain/main-entities/item/entity.go b/internal/domain/main-entities/item/entity.go index 9ac471ad..e0ff4e21 100644 --- a/internal/domain/main-entities/item/entity.go +++ b/internal/domain/main-entities/item/entity.go @@ -11,7 +11,7 @@ type Item struct { ecore.Main // adjust this according to the needs Code string `json:"code" gorm:"unique;size:50"` Name string `json:"name" gorm:"size:100"` - ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code" gorm:"size:10"` + ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code" gorm:"size:15"` Uom_Code *string `json:"uom_code" gorm:"size:10"` Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` Infra_Id *uint16 `json:"infra_id"` diff --git a/internal/domain/main-entities/medical-action-src/dto.go b/internal/domain/main-entities/medical-action-src/dto.go index a4796a75..32e248d8 100644 --- a/internal/domain/main-entities/medical-action-src/dto.go +++ b/internal/domain/main-entities/medical-action-src/dto.go @@ -8,7 +8,7 @@ import ( type CreateDto struct { Code string `json:"code" validate:"maxLength=20"` Name string `json:"name" validate:"maxLength=50"` - Type_Code string `json:"type_code" validate:"maxLength:20"` + Type_Code string `json:"type_code" validate:"maxLength=20"` Item_Id *uint `json:"item_id"` } diff --git a/internal/domain/references/organization/organization.go b/internal/domain/references/organization/organization.go index bf11fbd6..04c4fa2a 100644 --- a/internal/domain/references/organization/organization.go +++ b/internal/domain/references/organization/organization.go @@ -30,6 +30,7 @@ const ( ITGCMCUSub ItemGroupCode = "mcuSub" ITGCEmpFee ItemGroupCode = "employee-fee" ITGCDocFee ItemGroupCode = "doctor-fee" + ITGCMedAct ItemGroupCode = "medical-action" IFGCBuilding InfraGroupCode = "building" // Bangunan IFGCFloor InfraGroupCode = "floor" // Lantai diff --git a/internal/use-case/main-use-case/medical-action-src/case.go b/internal/use-case/main-use-case/medical-action-src/case.go index d3fb840b..cd42766c 100644 --- a/internal/use-case/main-use-case/medical-action-src/case.go +++ b/internal/use-case/main-use-case/medical-action-src/case.go @@ -34,6 +34,9 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } + if err := createItem(&input, &event, tx); err != nil { + return err + } if resData, err := CreateData(input, &event, tx); err != nil { return err } else { diff --git a/internal/use-case/main-use-case/medical-action-src/helper.go b/internal/use-case/main-use-case/medical-action-src/helper.go index 3e54a3eb..c955274d 100644 --- a/internal/use-case/main-use-case/medical-action-src/helper.go +++ b/internal/use-case/main-use-case/medical-action-src/helper.go @@ -5,7 +5,17 @@ Any functions that are used internally by the use-case package medicalactionsrc import ( + ei "simrs-vx/internal/domain/main-entities/item" e "simrs-vx/internal/domain/main-entities/medical-action-src" + + ero "simrs-vx/internal/domain/references/organization" + + ui "simrs-vx/internal/use-case/main-use-case/item" + + pl "simrs-vx/pkg/logger" + pu "simrs-vx/pkg/use-case-helper" + + "gorm.io/gorm" ) func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrc) { @@ -22,3 +32,18 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrc) { data.Type_Code = inputSrc.Type_Code data.Item_Id = inputSrc.Item_Id } + +func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { + itemCreate := ei.CreateDto{ + Code: pu.AddPrefix("medAct-", input.Code), + Name: input.Name, + ItemGroup_Code: ero.ITGCMedAct, + } + item, err := ui.CreateData(itemCreate, event, tx) + if err != nil { + return err + } + + input.Item_Id = &item.Id + return nil +}