From 200c3e9c83ec88c9ec16d50f41cbad5f8bb5b4b6 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Fri, 3 Oct 2025 10:21:18 +0700 Subject: [PATCH] add doctor id into device-order, material-order, add fk parent and childrens for infra --- cmd/main-migration/migrations/20251003032030.sql | 6 ++++++ cmd/main-migration/migrations/atlas.sum | 3 ++- internal/domain/main-entities/device-order/entity.go | 3 +++ internal/domain/main-entities/division/entity.go | 4 ++-- internal/domain/main-entities/infra/entity.go | 2 ++ internal/domain/main-entities/material-order/entity.go | 3 +++ 6 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 cmd/main-migration/migrations/20251003032030.sql diff --git a/cmd/main-migration/migrations/20251003032030.sql b/cmd/main-migration/migrations/20251003032030.sql new file mode 100644 index 00000000..2bdf73ba --- /dev/null +++ b/cmd/main-migration/migrations/20251003032030.sql @@ -0,0 +1,6 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ADD CONSTRAINT "fk_Infra_Childrens" FOREIGN KEY ("Parent_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "DeviceOrder" table +ALTER TABLE "public"."DeviceOrder" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_DeviceOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MaterialOrder" table +ALTER TABLE "public"."MaterialOrder" ADD COLUMN "Doctor_Id" bigint NULL, ADD CONSTRAINT "fk_MaterialOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index dedb750a..571f69da 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:jZ9sh96fN1qtT2OItPgP+Anzvi92I1twBDGmU2RWlVU= +h1:EkXfc/qeBa+6Fog89GGHEbrpjWfLwy/t6MQdrP9tImE= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -22,3 +22,4 @@ h1:jZ9sh96fN1qtT2OItPgP+Anzvi92I1twBDGmU2RWlVU= 20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= 20250930140351.sql h1:9AAEG1AnOAH+o0+oHL5G7I8vqlWOhwRlCGyyCpT/y1Q= 20251002085604.sql h1:3xZ68eYp4urXRnvotNH1XvG2mYOSDV/j3zHEZ/txg5E= +20251003032030.sql h1:hdN6UINPM9Pz9ME6uP3pr6PNCqqz4y7h2qY1UlVjw60= diff --git a/internal/domain/main-entities/device-order/entity.go b/internal/domain/main-entities/device-order/entity.go index 79af88c2..cfb39216 100644 --- a/internal/domain/main-entities/device-order/entity.go +++ b/internal/domain/main-entities/device-order/entity.go @@ -2,6 +2,7 @@ package deviceorder 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" erc "simrs-vx/internal/domain/references/common" @@ -11,5 +12,7 @@ type DeviceOrder struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` Status_Code erc.DataStatusCode `json:"status_code"` } diff --git a/internal/domain/main-entities/division/entity.go b/internal/domain/main-entities/division/entity.go index 2aa6c8dd..470fab0d 100644 --- a/internal/domain/main-entities/division/entity.go +++ b/internal/domain/main-entities/division/entity.go @@ -9,6 +9,6 @@ type Division struct { Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` Parent_Id *uint16 `json:"parent_id"` - Parent *Division `gorm:"foreignKey:Parent_Id;references:Id"` - Childrens []Division `gorm:"foreignKey:Parent_Id"` // may need references to self + Parent *Division `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"` + Childrens []Division `json:"childrens" gorm:"foreignKey:Parent_Id"` // may need references to self } diff --git a/internal/domain/main-entities/infra/entity.go b/internal/domain/main-entities/infra/entity.go index a7d2e6d4..cf069376 100644 --- a/internal/domain/main-entities/infra/entity.go +++ b/internal/domain/main-entities/infra/entity.go @@ -13,6 +13,8 @@ type Infra struct { Name string `json:"name" gorm:"size:50"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" gorm:"size:10"` Parent_Id *uint16 `json:"parent_id"` + Parent *Infra `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"` + Childrens []Infra `json:"childrens" gorm:"foreignKey:Parent_Id"` // may need references to self Item_Id *uint `json:"item_id"` Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/material-order/entity.go b/internal/domain/main-entities/material-order/entity.go index e306d372..73cd9851 100644 --- a/internal/domain/main-entities/material-order/entity.go +++ b/internal/domain/main-entities/material-order/entity.go @@ -2,6 +2,7 @@ package materialorder 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" erc "simrs-vx/internal/domain/references/common" @@ -11,5 +12,7 @@ type MaterialOrder struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` Status_Code erc.DataStatusCode `json:"status_code"` }