From 29f0ff688762fb768533fd92d189d9f67bc2477e Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 15 Sep 2025 19:36:26 +0700 Subject: [PATCH] add migration for several order tables --- .../migrations/20250915123412.sql | 146 ++++++++++++++++++ cmd/main-migration/migrations/atlas.sum | 3 +- .../main-entities/medication-item/dto.go | 68 ++++---- .../main-entities/medication-item/entity.go | 24 +-- .../main-entities/prescription-item/dto.go | 65 ++++---- .../main-entities/prescription-item/entity.go | 24 +-- 6 files changed, 244 insertions(+), 86 deletions(-) create mode 100644 cmd/main-migration/migrations/20250915123412.sql diff --git a/cmd/main-migration/migrations/20250915123412.sql b/cmd/main-migration/migrations/20250915123412.sql new file mode 100644 index 00000000..5bb948f0 --- /dev/null +++ b/cmd/main-migration/migrations/20250915123412.sql @@ -0,0 +1,146 @@ +-- Create "DeviceOrder" table +CREATE TABLE "public"."DeviceOrder" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_DeviceOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "DeviceOrderItem" table +CREATE TABLE "public"."DeviceOrderItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "DeviceOrder_Id" bigint NULL, + "Device_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_DeviceOrderItem_Device" FOREIGN KEY ("Device_Id") REFERENCES "public"."Device" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_DeviceOrderItem_DeviceOrder" FOREIGN KEY ("DeviceOrder_Id") REFERENCES "public"."DeviceOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MaterialOrder" table +CREATE TABLE "public"."MaterialOrder" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MaterialOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MaterialOrderItem" table +CREATE TABLE "public"."MaterialOrderItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "MaterialOrder_Id" bigint NULL, + "Material_Id" bigint NULL, + "Count" integer NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MaterialOrderItem_Material" FOREIGN KEY ("Material_Id") REFERENCES "public"."Material" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MaterialOrderItem_MaterialOrder" FOREIGN KEY ("MaterialOrder_Id") REFERENCES "public"."MaterialOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "McuOrder" table +CREATE TABLE "public"."McuOrder" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Status_Code" character varying(10) NOT NULL, + "Doctor_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_McuOrder_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_McuOrder_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "McuOrderItem" table +CREATE TABLE "public"."McuOrderItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "McuOrder_Id" bigint NULL, + "McuSrc_Id" bigint NULL, + "Result" text NULL, + "Status_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_McuOrderItem_McuOrder" FOREIGN KEY ("McuOrder_Id") REFERENCES "public"."McuOrder" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_McuOrderItem_McuSrc" FOREIGN KEY ("McuSrc_Id") REFERENCES "public"."McuSrc" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Medication" table +CREATE TABLE "public"."Medication" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "IssuedAt" timestamptz NULL, + "Pharmacist_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Medication_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Medication_Pharmacist" FOREIGN KEY ("Pharmacist_Id") REFERENCES "public"."Pharmacist" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MedicationItem" table +CREATE TABLE "public"."MedicationItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Medication_Id" bigint NULL, + "IsMix" boolean NULL, + "Medicine_Id" bigint NULL, + "MedicineMix_Id" bigint NULL, + "Usage" smallint NULL, + "Interval" smallint NULL, + "IntervalUnit_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MedicationItem_Medication" FOREIGN KEY ("Medication_Id") REFERENCES "public"."Medication" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MedicationItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_MedicationItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "MedicationItemDist" table +CREATE TABLE "public"."MedicationItemDist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "MedicationItem_Id" bigint NULL, + "DateTime" timestamptz NULL, + "Remain" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_MedicationItemDist_MedicationItem" FOREIGN KEY ("MedicationItem_Id") REFERENCES "public"."MedicationItem" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "Prescription" table +CREATE TABLE "public"."Prescription" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Doctor_Id" bigint NULL, + "IssuedAt" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Prescription_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Prescription_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "PrescriptionItem" table +CREATE TABLE "public"."PrescriptionItem" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Prescription_Id" bigint NULL, + "IsMix" boolean NULL, + "Medicine_Id" bigint NULL, + "MedicineMix_Id" bigint NULL, + "Usage" smallint NULL, + "Interval" smallint NULL, + "IntervalUnit_Code" text NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_PrescriptionItem_Medicine" FOREIGN KEY ("Medicine_Id") REFERENCES "public"."Medicine" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_PrescriptionItem_MedicineMix" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_PrescriptionItem_Prescription" FOREIGN KEY ("Prescription_Id") REFERENCES "public"."Prescription" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 3482f994..7bc09afb 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:BLtMDgAdnqZbCj3HUbiTlyYtA87C4LcP/uquCbM6GSE= +h1:vKW524Os6+DLuWTIk2ogb2LnlRoaYqgz1GLvvmc2KYA= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -6,3 +6,4 @@ h1:BLtMDgAdnqZbCj3HUbiTlyYtA87C4LcP/uquCbM6GSE= 20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= 20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= 20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= +20250915123412.sql h1:CndzsEFauRnieT/Qv/kqZ5Gr49g6f127Tq/fskHAPwg= diff --git a/internal/domain/main-entities/medication-item/dto.go b/internal/domain/main-entities/medication-item/dto.go index 2b4e0ed1..59ae7688 100644 --- a/internal/domain/main-entities/medication-item/dto.go +++ b/internal/domain/main-entities/medication-item/dto.go @@ -5,16 +5,17 @@ import ( eme "simrs-vx/internal/domain/main-entities/medication" em "simrs-vx/internal/domain/main-entities/medicine" emm "simrs-vx/internal/domain/main-entities/medicine-mix" + erc "simrs-vx/internal/domain/references/common" ) type CreateDto struct { - Medication_Id *uint `json:"medication_id"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - MedicineMix_Id *uint `json:"medicineMix_id"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` - // IntervalUnit_Code + Medication_Id *uint `json:"medication_id"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + MedicineMix_Id *uint `json:"medicineMix_id"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` } type ReadListDto struct { @@ -24,13 +25,13 @@ type ReadListDto struct { } type FilterDto struct { - Medication_Id *uint `json:"medication_id"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - MedicineMix_Id *uint `json:"medicineMix_id"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` - // IntervalUnit_Code + Medication_Id *uint `json:"medication_id"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + MedicineMix_Id *uint `json:"medicineMix_id"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -57,29 +58,30 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Medication_Id *uint `json:"medication_id"` - Medication *eme.Medication `json:"medication,omitempty"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - Medicine *em.Medicine `json:"medicine,omitempty"` - MedicineMix_Id *uint `json:"medicineMix_id"` - MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` - // IntervalUnit_Code + Medication_Id *uint `json:"medication_id"` + Medication *eme.Medication `json:"medication,omitempty"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + Medicine *em.Medicine `json:"medicine,omitempty"` + MedicineMix_Id *uint `json:"medicineMix_id"` + MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` } func (d MedicationItem) ToResponse() ResponseDto { resp := ResponseDto{ - Medication_Id: d.Medication_Id, - Medication: d.Medication, - IsMix: d.IsMix, - Medicine_Id: d.Medicine_Id, - Medicine: d.Medicine, - MedicineMix_Id: d.MedicineMix_Id, - MedicineMix: d.MedicineMix, - Usage: d.Usage, - Interval: d.Interval, + Medication_Id: d.Medication_Id, + Medication: d.Medication, + IsMix: d.IsMix, + Medicine_Id: d.Medicine_Id, + Medicine: d.Medicine, + MedicineMix_Id: d.MedicineMix_Id, + MedicineMix: d.MedicineMix, + Usage: d.Usage, + Interval: d.Interval, + IntervalUnit_Code: d.IntervalUnit_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/medication-item/entity.go b/internal/domain/main-entities/medication-item/entity.go index 160b7dec..ef7f20ea 100644 --- a/internal/domain/main-entities/medication-item/entity.go +++ b/internal/domain/main-entities/medication-item/entity.go @@ -5,18 +5,20 @@ import ( eme "simrs-vx/internal/domain/main-entities/medication" em "simrs-vx/internal/domain/main-entities/medicine" emm "simrs-vx/internal/domain/main-entities/medicine-mix" + + erc "simrs-vx/internal/domain/references/common" ) type MedicationItem struct { - ecore.Main // adjust this according to the needs - Medication_Id *uint `json:"medication_id"` - Medication *eme.Medication `json:"medication,omitempty" gorm:"foreignKey:Medication_Id;references:Id"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"` - MedicineMix_Id *uint `json:"medicineMix_id"` - MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty" gorm:"foreignKey:MedicineMix_Id;references:Id"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` - // IntervalUnit_Code + ecore.Main // adjust this according to the needs + Medication_Id *uint `json:"medication_id"` + Medication *eme.Medication `json:"medication,omitempty" gorm:"foreignKey:Medication_Id;references:Id"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"` + MedicineMix_Id *uint `json:"medicineMix_id"` + MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty" gorm:"foreignKey:MedicineMix_Id;references:Id"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` } diff --git a/internal/domain/main-entities/prescription-item/dto.go b/internal/domain/main-entities/prescription-item/dto.go index 9d28a511..a87daaae 100644 --- a/internal/domain/main-entities/prescription-item/dto.go +++ b/internal/domain/main-entities/prescription-item/dto.go @@ -5,15 +5,17 @@ import ( em "simrs-vx/internal/domain/main-entities/medicine" emm "simrs-vx/internal/domain/main-entities/medicine-mix" ep "simrs-vx/internal/domain/main-entities/prescription" + erc "simrs-vx/internal/domain/references/common" ) type CreateDto struct { - Prescription_Id *uint `json:"prescription_id"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - MedicineMix_Id *uint `json:"medicineMix_id"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` + Prescription_Id *uint `json:"prescription_id"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + MedicineMix_Id *uint `json:"medicineMix_id"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` } type ReadListDto struct { @@ -23,12 +25,13 @@ type ReadListDto struct { } type FilterDto struct { - Prescription_Id *uint `json:"prescription_id"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - MedicineMix_Id *uint `json:"medicineMix_id"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` + Prescription_Id *uint `json:"prescription_id"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + MedicineMix_Id *uint `json:"medicineMix_id"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -55,28 +58,30 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Prescription_Id *uint `json:"prescription_id"` - Prescription *ep.Prescription `json:"prescription,omitempty"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - Medicine *em.Medicine `json:"medicine,omitempty"` - MedicineMix_Id *uint `json:"medicineMix_id"` - MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` + Prescription_Id *uint `json:"prescription_id"` + Prescription *ep.Prescription `json:"prescription,omitempty"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + Medicine *em.Medicine `json:"medicine,omitempty"` + MedicineMix_Id *uint `json:"medicineMix_id"` + MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` } func (d PrescriptionItem) ToResponse() ResponseDto { resp := ResponseDto{ - Prescription_Id: d.Prescription_Id, - Prescription: d.Prescription, - IsMix: d.IsMix, - Medicine_Id: d.Medicine_Id, - Medicine: d.Medicine, - MedicineMix_Id: d.MedicineMix_Id, - MedicineMix: d.MedicineMix, - Usage: d.Usage, - Interval: d.Interval, + Prescription_Id: d.Prescription_Id, + Prescription: d.Prescription, + IsMix: d.IsMix, + Medicine_Id: d.Medicine_Id, + Medicine: d.Medicine, + MedicineMix_Id: d.MedicineMix_Id, + MedicineMix: d.MedicineMix, + Usage: d.Usage, + Interval: d.Interval, + IntervalUnit_Code: d.IntervalUnit_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/prescription-item/entity.go b/internal/domain/main-entities/prescription-item/entity.go index 3898e170..3c662c5c 100644 --- a/internal/domain/main-entities/prescription-item/entity.go +++ b/internal/domain/main-entities/prescription-item/entity.go @@ -5,18 +5,20 @@ import ( em "simrs-vx/internal/domain/main-entities/medicine" emm "simrs-vx/internal/domain/main-entities/medicine-mix" ep "simrs-vx/internal/domain/main-entities/prescription" + + erc "simrs-vx/internal/domain/references/common" ) type PrescriptionItem struct { - ecore.Main // adjust this according to the needs - Prescription_Id *uint `json:"prescription_id"` - Prescription *ep.Prescription `json:"prescription,omitempty" gorm:"foreignKey:Prescription_Id;references:Id"` - IsMix bool `json:"isMix"` - Medicine_Id *uint `json:"medicine_id"` - Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"` - MedicineMix_Id *uint `json:"medicineMix_id"` - MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty" gorm:"foreignKey:MedicineMix_Id;references:Id"` - Usage uint8 `json:"usage"` - Interval uint8 `json:"interval"` - // IntervalUnit_Code + ecore.Main // adjust this according to the needs + Prescription_Id *uint `json:"prescription_id"` + Prescription *ep.Prescription `json:"prescription,omitempty" gorm:"foreignKey:Prescription_Id;references:Id"` + IsMix bool `json:"isMix"` + Medicine_Id *uint `json:"medicine_id"` + Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"` + MedicineMix_Id *uint `json:"medicineMix_id"` + MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty" gorm:"foreignKey:MedicineMix_Id;references:Id"` + Usage uint8 `json:"usage"` + Interval uint8 `json:"interval"` + IntervalUnit_Code erc.TimeUnitCode `json:"intervalUnit_code"` }