diff --git a/cmd/migration/migrations/20250828092003.sql b/cmd/migration/migrations/20250829081952.sql similarity index 95% rename from cmd/migration/migrations/20250828092003.sql rename to cmd/migration/migrations/20250829081952.sql index 175129a6..c74cb017 100644 --- a/cmd/migration/migrations/20250828092003.sql +++ b/cmd/migration/migrations/20250829081952.sql @@ -10,53 +10,6 @@ CREATE TABLE "public"."DiagnoseSrc" ( PRIMARY KEY ("Id"), CONSTRAINT "uni_DiagnoseSrc_Code" UNIQUE ("Code") ); --- Create "PharmacyCompany" table -CREATE TABLE "public"."PharmacyCompany" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(100) NULL, - "Regency_Code" character varying(4) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_PharmacyCompany_Code" UNIQUE ("Code") -); --- Create "McuSrc" table -CREATE TABLE "public"."McuSrc" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "CheckupCategory_Code" character varying(20) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_McuSrc_Code" UNIQUE ("Code") -); --- Create "ItemGroup" table -CREATE TABLE "public"."ItemGroup" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(50) NULL, - "Name" character varying(100) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_ItemGroup_Code" UNIQUE ("Code") -); --- Create "McuSrcCategory" table -CREATE TABLE "public"."McuSrcCategory" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(20) NULL, - "Name" character varying(50) NULL, - "Scope_Code" character varying(10) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_McuSrcCategory_Code" UNIQUE ("Code") -); -- Create "Counter" table CREATE TABLE "public"."Counter" ( "Id" serial NOT NULL, @@ -72,6 +25,53 @@ CREATE TABLE "public"."Counter" ( PRIMARY KEY ("Id"), CONSTRAINT "uni_Counter_Code" UNIQUE ("Code") ); +-- Create "McuSrcCategory" table +CREATE TABLE "public"."McuSrcCategory" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "Scope_Code" character varying(10) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_McuSrcCategory_Code" UNIQUE ("Code") +); +-- Create "McuSrc" table +CREATE TABLE "public"."McuSrc" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(50) NULL, + "CheckupCategory_Code" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_McuSrc_Code" UNIQUE ("Code") +); +-- Create "Uom" table +CREATE TABLE "public"."Uom" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Uom_Code" UNIQUE ("Code") +); +-- Create "PharmacyCompany" table +CREATE TABLE "public"."PharmacyCompany" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(20) NULL, + "Name" character varying(100) NULL, + "Regency_Code" character varying(4) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_PharmacyCompany_Code" UNIQUE ("Code") +); -- Create "User" table CREATE TABLE "public"."User" ( "Id" bigserial NOT NULL, @@ -87,17 +87,6 @@ CREATE TABLE "public"."User" ( "LastAllowdLogin" timestamptz NULL, PRIMARY KEY ("Id") ); --- Create "Uom" table -CREATE TABLE "public"."Uom" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Uom_Code" UNIQUE ("Code") -); -- Create "Item" table CREATE TABLE "public"."Item" ( "Id" bigserial NOT NULL, @@ -112,9 +101,23 @@ CREATE TABLE "public"."Item" ( "Stock" bigint NULL, PRIMARY KEY ("Id"), CONSTRAINT "uni_Item_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Item_ItemGroup" FOREIGN KEY ("ItemGroup_Code") REFERENCES "public"."ItemGroup" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Item_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION ); +-- Create "Infra" table +CREATE TABLE "public"."Infra" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "InfraGroup_Code" character varying(10) NULL, + "Parent_Id" smallint NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Infra_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); -- Create "Device" table CREATE TABLE "public"."Device" ( "Id" bigserial NOT NULL, @@ -124,9 +127,11 @@ CREATE TABLE "public"."Device" ( "Code" character varying(10) NULL, "Name" character varying(50) NULL, "Uom_Code" character varying(10) NULL, + "Infra_Id" integer NULL, "Item_Id" bigint NULL, PRIMARY KEY ("Id"), CONSTRAINT "uni_Device_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Device_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Device_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Device_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION ); @@ -251,34 +256,6 @@ CREATE TABLE "public"."DoctorFee" ( CONSTRAINT "fk_DoctorFee_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_DoctorFee_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); --- Create "InfraGroup" table -CREATE TABLE "public"."InfraGroup" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "Level" smallint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_InfraGroup_Code" UNIQUE ("Code") -); --- Create "Infra" table -CREATE TABLE "public"."Infra" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "InfraGroup_Code" character varying(10) NULL, - "Parent_Id" smallint NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Infra_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Infra_InfraGroup" FOREIGN KEY ("InfraGroup_Code") REFERENCES "public"."InfraGroup" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, - CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); -- Create "InsuranceCompany" table CREATE TABLE "public"."InsuranceCompany" ( "Id" serial NOT NULL, @@ -316,10 +293,12 @@ CREATE TABLE "public"."Material" ( "Code" character varying(10) NULL, "Name" character varying(50) NULL, "Uom_Code" character varying(10) NULL, + "Infra_Id" integer NULL, "Stock" bigint NULL, "Item_Id" bigint NULL, PRIMARY KEY ("Id"), CONSTRAINT "uni_Material_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Material_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Material_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Material_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION ); diff --git a/cmd/migration/migrations/20250901073356.sql b/cmd/migration/migrations/20250901073356.sql new file mode 100644 index 00000000..4ffe005f --- /dev/null +++ b/cmd/migration/migrations/20250901073356.sql @@ -0,0 +1,6 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ALTER COLUMN "Parent_Id" TYPE integer; +-- Modify "User" table +ALTER TABLE "public"."User" ADD CONSTRAINT "uni_User_Name" UNIQUE ("Name"); +-- Modify "Employee" table +ALTER TABLE "public"."Employee" ADD CONSTRAINT "fk_Employee_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Employee_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/migration/migrations/20250901080035.sql b/cmd/migration/migrations/20250901080035.sql new file mode 100644 index 00000000..8b41cd0d --- /dev/null +++ b/cmd/migration/migrations/20250901080035.sql @@ -0,0 +1,2 @@ +-- Modify "McuSrc" table +ALTER TABLE "public"."McuSrc" ADD CONSTRAINT "fk_McuSrc_CheckupCategory" FOREIGN KEY ("CheckupCategory_Code") REFERENCES "public"."McuSrcCategory" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/migration/migrations/20250901105703.sql b/cmd/migration/migrations/20250901105703.sql new file mode 100644 index 00000000..e9c47a1a --- /dev/null +++ b/cmd/migration/migrations/20250901105703.sql @@ -0,0 +1,2 @@ +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD COLUMN "FrontTitle" character varying(50) NULL, ADD COLUMN "EndTitle" character varying(50) NULL; diff --git a/cmd/migration/migrations/atlas.sum b/cmd/migration/migrations/atlas.sum index d3527869..b4d8d0f9 100644 --- a/cmd/migration/migrations/atlas.sum +++ b/cmd/migration/migrations/atlas.sum @@ -1,2 +1,5 @@ -h1:MMNuESyEk0KZHA2z+7AukfG/ATboITROipz2wK3YNPg= -20250828092003.sql h1:Rr221/6KN53t0eoEHK5+sPeMaVsnKjN4322WLulN8AQ= +h1:vQwjJ2jG5TRFv8oZyhxcynOFS+H0vyKY/XWsXJyhpuo= +20250829081952.sql h1:YMsYq3uPsx70EjWSGfYnVRR5GV0q1fRGIszYZAWzXNo= +20250901073356.sql h1:jjd5TLs+Pyi0u3SrOM+aNTbHxSJboXgcOz/L4bkYx+c= +20250901080035.sql h1:LWa3X0NWjalVcxNbk5HaHj1Oqu60/AQabi0jBmCeQBI= +20250901105703.sql h1:45mFfTFkLv+1oQXfqNxtCBGXTyzWuqq759I3u1SVxRo= diff --git a/internal/domain/main-entities/device/dto.go b/internal/domain/main-entities/device/dto.go index 0a9aba7a..921aae1b 100644 --- a/internal/domain/main-entities/device/dto.go +++ b/internal/domain/main-entities/device/dto.go @@ -2,22 +2,31 @@ package device import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Item_Id *uint `json:"item_id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Item_Id *uint `json:"item_id"` } type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Item_Id *uint `json:"item_id"` + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Item_Id *uint `json:"item_id"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -25,11 +34,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { @@ -49,12 +55,14 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Uom *eu.Uom `json:"uom,omitempty"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Uom *eu.Uom `json:"uom,omitempty"` + Infra_Id *uint16 `json:"infra_id"` + Infra *ein.Infra `json:"infra,omitempty"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty"` } func (d Device) ToResponse() ResponseDto { @@ -63,6 +71,8 @@ func (d Device) ToResponse() ResponseDto { Name: d.Name, Uom_Code: d.Uom_Code, Uom: d.Uom, + Infra_Id: d.Infra_Id, + Infra: d.Infra, Item_Id: d.Item_Id, Item: d.Item, } diff --git a/internal/domain/main-entities/device/entity.go b/internal/domain/main-entities/device/entity.go index bf75c746..c9f8fdd7 100644 --- a/internal/domain/main-entities/device/entity.go +++ b/internal/domain/main-entities/device/entity.go @@ -2,16 +2,19 @@ package device import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type Device struct { - ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - Uom_Code string `json:"uom_code" gorm:"size:10"` - Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + ecore.Main // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + 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"` + Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` + 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/diagnose-src/dto.go b/internal/domain/main-entities/diagnose-src/dto.go index 9e8736a1..3cfe0152 100644 --- a/internal/domain/main-entities/diagnose-src/dto.go +++ b/internal/domain/main-entities/diagnose-src/dto.go @@ -21,10 +21,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - IndName string `json:"indName"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/district/dto.go b/internal/domain/main-entities/district/dto.go index 850d4649..57f41892 100644 --- a/internal/domain/main-entities/district/dto.go +++ b/internal/domain/main-entities/district/dto.go @@ -19,10 +19,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint32 `json:"id"` - Regency_Code string `json:"regency_code"` - Code string `json:"code"` - Name string `json:"name"` + Id uint32 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/division-position/dto.go b/internal/domain/main-entities/division-position/dto.go index 8dd18d0b..4bf75308 100644 --- a/internal/domain/main-entities/division-position/dto.go +++ b/internal/domain/main-entities/division-position/dto.go @@ -12,6 +12,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Division_Id *uint16 `json:"division_id"` Code string `json:"code"` Name string `json:"name"` @@ -22,10 +28,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Division_Id *uint16 `json:"division_id"` - Code string `json:"code"` - Name string `json:"name"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/division/dto.go b/internal/domain/main-entities/division/dto.go index d9d7b606..890bd606 100644 --- a/internal/domain/main-entities/division/dto.go +++ b/internal/domain/main-entities/division/dto.go @@ -21,10 +21,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Parent_Id *int16 `json:"parent_id"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/doctor-fee/dto.go b/internal/domain/main-entities/doctor-fee/dto.go index 4d35d903..ae6c8d77 100644 --- a/internal/domain/main-entities/doctor-fee/dto.go +++ b/internal/domain/main-entities/doctor-fee/dto.go @@ -4,19 +4,25 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" ei "simrs-vx/internal/domain/main-entities/item" - erc "simrs-vx/internal/domain/references/clinical" + ero "simrs-vx/internal/domain/references/organization" ) type CreateDto struct { Doctor_Id *uint `json:"doctor_id"` - FeeType_Code *erc.DoctorFeeTypeCode `json:"feeType_code"` + FeeType_Code *ero.DoctorFeeTypeCode `json:"feeType_code"` Price *float64 `json:"price"` Item_Id *uint `json:"item_id"` } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Doctor_Id *uint `json:"doctor_id"` - FeeType_Code *erc.DoctorFeeTypeCode `json:"feeType_code"` + FeeType_Code *ero.DoctorFeeTypeCode `json:"feeType_code"` Price *float64 `json:"price"` Item_Id *uint `json:"item_id"` @@ -26,11 +32,9 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Doctor_Id *uint `json:"doctor_id"` - FeeType_Code *erc.DoctorFeeTypeCode `json:"feeType_code"` - Price *float64 `json:"price"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Doctor_Id *uint `json:"doctor_id"` + Item_Id *uint `json:"item_id"` } type UpdateDto struct { @@ -52,7 +56,7 @@ type ResponseDto struct { ecore.Main Doctor_Id *uint `json:"doctor_id"` Doctor *ed.Doctor `json:"doctor,omitempty"` - FeeType_Code *erc.DoctorFeeTypeCode `json:"feeType_code"` + FeeType_Code *ero.DoctorFeeTypeCode `json:"feeType_code"` Price *float64 `json:"price"` Item_Id *uint `json:"item_id"` Item *ei.Item `json:"item,omitempty"` diff --git a/internal/domain/main-entities/doctor-fee/entity.go b/internal/domain/main-entities/doctor-fee/entity.go index af15173b..211e4148 100644 --- a/internal/domain/main-entities/doctor-fee/entity.go +++ b/internal/domain/main-entities/doctor-fee/entity.go @@ -4,14 +4,14 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" ei "simrs-vx/internal/domain/main-entities/item" - erc "simrs-vx/internal/domain/references/clinical" + ero "simrs-vx/internal/domain/references/organization" ) type DoctorFee struct { ecore.Main // adjust this according to the needs Doctor_Id *uint `json:"doctor_id"` Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` - FeeType_Code *erc.DoctorFeeTypeCode `json:"feeType_code" gorm:"size:11"` + FeeType_Code *ero.DoctorFeeTypeCode `json:"feeType_code" gorm:"size:11"` Price *float64 `json:"price"` 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/doctor/dto.go b/internal/domain/main-entities/doctor/dto.go index f251fe59..7f506a40 100644 --- a/internal/domain/main-entities/doctor/dto.go +++ b/internal/domain/main-entities/doctor/dto.go @@ -14,6 +14,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` SIP_Number *string `json:"sip_number"` @@ -29,7 +35,6 @@ type ReadDetailDto struct { Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` SIP_Number *string `json:"sip_number"` - Unit_Id *uint `json:"unit_id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/employee copy/entity.go b/internal/domain/main-entities/employee copy/entity.go deleted file mode 100644 index 55b829fa..00000000 --- a/internal/domain/main-entities/employee copy/entity.go +++ /dev/null @@ -1,19 +0,0 @@ -package employee - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" - ed "simrs-vx/internal/domain/main-entities/division" - erc "simrs-vx/internal/domain/references/common" - ero "simrs-vx/internal/domain/references/organization" -) - -type Employee struct { - ecore.Main // adjust this according to the needs - User_Id *uint `json:"user_id"` - Person_Id *uint `json:"person_id"` - Position_Code ero.EmployeePosisitionCode `json:"position_code" gorm:"not null;size:20"` - Division_Code *string `json:"division_code"` - Division *ed.Division `json:"division,omitempty" gorm:"foreignKey:Division_Code;references:Code"` - Number *string `json:"number" gorm:"size:20"` - Status_Code erc.StatusCode `json:"status_code" gorm:"not null;size:10"` -} diff --git a/internal/domain/main-entities/employee/dto.go b/internal/domain/main-entities/employee/dto.go index ff650793..66de6b25 100644 --- a/internal/domain/main-entities/employee/dto.go +++ b/internal/domain/main-entities/employee/dto.go @@ -3,26 +3,39 @@ package employee import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/division" + ep "simrs-vx/internal/domain/main-entities/person" + eu "simrs-vx/internal/domain/main-entities/user" erc "simrs-vx/internal/domain/references/common" ero "simrs-vx/internal/domain/references/organization" ) type CreateDto struct { User_Id *uint `json:"user_id"` + User *eu.CreateDto `json:"user"` Person_Id *uint `json:"person_id"` + Person *ep.CreateDto `json:"person"` Position_Code ero.EmployeePosisitionCode `json:"position_code"` Division_Code *string `json:"division_code"` Number *string `json:"number"` - Status_Code erc.StatusCode `json:"status_code"` + Status_Code erc.ActiveStatusCode `json:"status_code"` + IHS_Number *string `json:"ihs_number"` + SIP_Number *string `json:"sip_number"` + Unit_Id *uint `json:"unit_id"` } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { User_Id *uint `json:"user_id"` Person_Id *uint `json:"person_id"` Position_Code ero.EmployeePosisitionCode `json:"position_code"` Division_Code *string `json:"division_code"` Number *string `json:"number"` - Status_Code erc.StatusCode `json:"status_code"` + Status_Code erc.ActiveStatusCode `json:"status_code"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -30,13 +43,10 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - User_Id *uint `json:"user_id"` - Person_Id *uint `json:"person_id"` - Position_Code ero.EmployeePosisitionCode `json:"position_code"` - Division_Code *string `json:"division_code"` - Number *string `json:"number"` - Status_Code erc.StatusCode `json:"status_code"` + Id uint16 `json:"id"` + User_Id *uint `json:"user_id"` + Person_Id *uint `json:"person_id"` + Number *string `json:"number"` } type UpdateDto struct { @@ -57,17 +67,20 @@ type MetaDto struct { type ResponseDto struct { ecore.Main User_Id *uint `json:"user_id"` + User *eu.User `json:"user,omitempty"` Person_Id *uint `json:"person_id"` + Person *ep.Person `json:"person,omitempty"` Position_Code ero.EmployeePosisitionCode `json:"position_code"` Division_Code *string `json:"division_code"` Division *ed.Division `json:"division,omitempty"` Number *string `json:"number"` - Status_Code erc.StatusCode `json:"status_code"` + Status_Code erc.ActiveStatusCode `json:"status_code"` } func (d Employee) ToResponse() ResponseDto { resp := ResponseDto{ User_Id: d.User_Id, + User: d.User, Person_Id: d.Person_Id, Position_Code: d.Position_Code, Division_Code: d.Division_Code, @@ -86,3 +99,9 @@ func ToResponseList(data []Employee) []ResponseDto { } return resp } + +func (c CreateDto) Sanitize() CreateDto { + sanitized := c + sanitized.User.Password = "[REDACTED]" + return sanitized +} diff --git a/internal/domain/main-entities/employee/entity.go b/internal/domain/main-entities/employee/entity.go index 55b829fa..24687262 100644 --- a/internal/domain/main-entities/employee/entity.go +++ b/internal/domain/main-entities/employee/entity.go @@ -3,6 +3,8 @@ package employee import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/division" + ep "simrs-vx/internal/domain/main-entities/person" + eu "simrs-vx/internal/domain/main-entities/user" erc "simrs-vx/internal/domain/references/common" ero "simrs-vx/internal/domain/references/organization" ) @@ -10,10 +12,12 @@ import ( type Employee struct { ecore.Main // adjust this according to the needs User_Id *uint `json:"user_id"` + User *eu.User `json:"user,omitempty" gorm:"foreignKey:User_Id;references:Id"` Person_Id *uint `json:"person_id"` + Person *ep.Person `json:"person,omitempty" gorm:"foreignKey:Person_Id;references:Id"` Position_Code ero.EmployeePosisitionCode `json:"position_code" gorm:"not null;size:20"` Division_Code *string `json:"division_code"` Division *ed.Division `json:"division,omitempty" gorm:"foreignKey:Division_Code;references:Code"` Number *string `json:"number" gorm:"size:20"` - Status_Code erc.StatusCode `json:"status_code" gorm:"not null;size:10"` + Status_Code erc.ActiveStatusCode `json:"status_code" gorm:"not null;size:10"` } diff --git a/internal/domain/main-entities/ethnic/dto.go b/internal/domain/main-entities/ethnic/dto.go index 64e5ca85..f434e4ae 100644 --- a/internal/domain/main-entities/ethnic/dto.go +++ b/internal/domain/main-entities/ethnic/dto.go @@ -19,9 +19,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/infra-group/dto.go b/internal/domain/main-entities/infra-group/dto.go deleted file mode 100644 index e33e92b1..00000000 --- a/internal/domain/main-entities/infra-group/dto.go +++ /dev/null @@ -1,68 +0,0 @@ -package infragroup - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" -) - -type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - Level uint8 `json:"level"` -} - -type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - Level uint8 `json:"level"` - - Page int `json:"page"` - PageSize int `json:"page_size"` - NoPagination int `json:"no_pagination"` -} - -type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Level uint8 `json:"level"` -} - -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 - Code string `json:"code"` - Name string `json:"name"` - Level uint8 `json:"level"` -} - -func (d InfraGroup) ToResponse() ResponseDto { - resp := ResponseDto{ - Code: d.Code, - Name: d.Name, - Level: d.Level, - } - resp.Main = d.Main - return resp -} - -func ToResponseList(data []InfraGroup) []ResponseDto { - resp := make([]ResponseDto, len(data)) - for i, u := range data { - resp[i] = u.ToResponse() - } - return resp -} diff --git a/internal/domain/main-entities/infra-group/entity.go b/internal/domain/main-entities/infra-group/entity.go deleted file mode 100644 index 812c27f1..00000000 --- a/internal/domain/main-entities/infra-group/entity.go +++ /dev/null @@ -1,12 +0,0 @@ -package infragroup - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" -) - -type InfraGroup struct { - ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - Level uint8 `json:"level"` -} diff --git a/internal/domain/main-entities/infra/dto.go b/internal/domain/main-entities/infra/dto.go index 801883d1..49a47073 100644 --- a/internal/domain/main-entities/infra/dto.go +++ b/internal/domain/main-entities/infra/dto.go @@ -2,24 +2,31 @@ package infra import ( ecore "simrs-vx/internal/domain/base-entities/core" - eig "simrs-vx/internal/domain/main-entities/infra-group" ei "simrs-vx/internal/domain/main-entities/item" + + ero "simrs-vx/internal/domain/references/organization" ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - InfraGroup_Code *string `json:"infraGroup_code"` - Parent_Id *int16 `json:"parent_id"` - Item_Id *uint `json:"item_id"` + Code string `json:"code"` + Name string `json:"name"` + InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code"` + Parent_Id *uint16 `json:"parent_id"` + Item_Id *uint `json:"item_id"` } type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - InfraGroup_Code *string `json:"infraGroup_code"` - Parent_Id *int16 `json:"parent_id"` - Item_Id *uint `json:"item_id"` + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { + Code string `json:"code"` + Name string `json:"name"` + InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code"` + Parent_Id *uint16 `json:"parent_id"` + Item_Id *uint `json:"item_id"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -27,12 +34,9 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - InfraGroup_Code *string `json:"infraGroup_code"` - Parent_Id *int16 `json:"parent_id"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Code *string `json:"code"` + Item_Id *uint `json:"item_id"` } type UpdateDto struct { @@ -52,13 +56,12 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Code string `json:"code"` - Name string `json:"name"` - InfraGroup_Code *string `json:"infraGroup_code"` - InfraGroup *eig.InfraGroup `json:"infraGroup,omitempty"` - Parent_Id *int16 `json:"parent_id"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code"` + Parent_Id *uint16 `json:"parent_id"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty"` } func (d Infra) ToResponse() ResponseDto { @@ -66,7 +69,6 @@ func (d Infra) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, InfraGroup_Code: d.InfraGroup_Code, - InfraGroup: d.InfraGroup, Parent_Id: d.Parent_Id, Item_Id: d.Item_Id, Item: d.Item, diff --git a/internal/domain/main-entities/infra/entity.go b/internal/domain/main-entities/infra/entity.go index 7cb2001e..a7d2e6d4 100644 --- a/internal/domain/main-entities/infra/entity.go +++ b/internal/domain/main-entities/infra/entity.go @@ -2,17 +2,17 @@ package infra import ( ecore "simrs-vx/internal/domain/base-entities/core" - eig "simrs-vx/internal/domain/main-entities/infra-group" ei "simrs-vx/internal/domain/main-entities/item" + + ero "simrs-vx/internal/domain/references/organization" ) type Infra struct { - ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - InfraGroup_Code *string `json:"infraGroup_code" gorm:"size:10"` - InfraGroup *eig.InfraGroup `json:"infraGroup,omitempty" gorm:"foreignKey:InfraGroup_Code;references:Code"` - Parent_Id *int16 `json:"parent_id"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + ecore.SmallMain // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" gorm:"size:10"` + Parent_Id *uint16 `json:"parent_id"` + 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/installation/dto.go b/internal/domain/main-entities/installation/dto.go index 66ce57ff..76b4084b 100644 --- a/internal/domain/main-entities/installation/dto.go +++ b/internal/domain/main-entities/installation/dto.go @@ -6,15 +6,15 @@ import ( ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - EncounterClass_Code ere.EncounterClass `json:"encounterClass_code"` + Code string `json:"code"` + Name string `json:"name"` + EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code"` } type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - EncounterClass_Code ere.EncounterClass `json:"encounterClass_code"` + Code string `json:"code"` + Name string `json:"name"` + EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -22,10 +22,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - EncounterClass_Code ere.EncounterClass `json:"encounterClass_code"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { @@ -45,9 +43,9 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Code string `json:"code"` - Name string `json:"name"` - EncounterClass_Code ere.EncounterClass `json:"encounterClass_code"` + Code string `json:"code"` + Name string `json:"name"` + EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code"` } func (d Installation) ToResponse() ResponseDto { diff --git a/internal/domain/main-entities/installation/entity.go b/internal/domain/main-entities/installation/entity.go index 203b231c..0cd5b7dd 100644 --- a/internal/domain/main-entities/installation/entity.go +++ b/internal/domain/main-entities/installation/entity.go @@ -6,8 +6,8 @@ import ( ) type Installation struct { - ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - EncounterClass_Code ere.EncounterClass `json:"encounterClass_code" gorm:"size:10"` + ecore.SmallMain // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code" gorm:"size:10"` } diff --git a/internal/domain/main-entities/insurance-company/dto.go b/internal/domain/main-entities/insurance-company/dto.go index 2cc36195..44728319 100644 --- a/internal/domain/main-entities/insurance-company/dto.go +++ b/internal/domain/main-entities/insurance-company/dto.go @@ -14,6 +14,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Code string `json:"code"` Name string `json:"name"` Regency_Code *string `json:"regency_code"` @@ -26,12 +32,9 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Regency_Code *string `json:"regency_code"` - Address string `json:"address"` - PhoneNumber string `json:"phoneNumber"` + Id uint16 `json:"id"` + Code *string `json:"code"` + PhoneNumber *string `json:"phoneNumber"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/item-group/dto.go b/internal/domain/main-entities/item-group/dto.go deleted file mode 100644 index 99681811..00000000 --- a/internal/domain/main-entities/item-group/dto.go +++ /dev/null @@ -1,63 +0,0 @@ -package itemgroup - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" -) - -type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` -} - -type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - - Page int `json:"page"` - PageSize int `json:"page_size"` - NoPagination int `json:"no_pagination"` -} - -type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` -} - -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 - Code string `json:"code"` - Name string `json:"name"` -} - -func (d ItemGroup) ToResponse() ResponseDto { - resp := ResponseDto{ - Code: d.Code, - Name: d.Name, - } - resp.Main = d.Main - return resp -} - -func ToResponseList(data []ItemGroup) []ResponseDto { - resp := make([]ResponseDto, len(data)) - for i, u := range data { - resp[i] = u.ToResponse() - } - return resp -} diff --git a/internal/domain/main-entities/item-group/entity.go b/internal/domain/main-entities/item-group/entity.go deleted file mode 100644 index 24ee3331..00000000 --- a/internal/domain/main-entities/item-group/entity.go +++ /dev/null @@ -1,11 +0,0 @@ -package itemgroup - -import ( - ecore "simrs-vx/internal/domain/base-entities/core" -) - -type ItemGroup struct { - ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:50"` - Name string `json:"name" gorm:"size:100"` -} diff --git a/internal/domain/main-entities/item-price/dto.go b/internal/domain/main-entities/item-price/dto.go index 730284e0..e9aa2e9b 100644 --- a/internal/domain/main-entities/item-price/dto.go +++ b/internal/domain/main-entities/item-price/dto.go @@ -13,6 +13,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Item_Id *uint `json:"item_id"` Price float64 `json:"price"` InsuranceCompany_Code *string `json:"insuranceCompany_code"` @@ -21,12 +27,9 @@ type ReadListDto struct { PageSize int `json:"page_size"` NoPagination int `json:"no_pagination"` } - type ReadDetailDto struct { - Id uint16 `json:"id"` - Item_Id *uint `json:"item_id"` - Price float64 `json:"price"` - InsuranceCompany_Code *string `json:"insuranceCompany_code"` + Id uint16 `json:"id"` + Item_Id *uint `json:"item_id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/item/dto.go b/internal/domain/main-entities/item/dto.go index c157b541..301b759e 100644 --- a/internal/domain/main-entities/item/dto.go +++ b/internal/domain/main-entities/item/dto.go @@ -2,26 +2,32 @@ package item import ( ecore "simrs-vx/internal/domain/base-entities/core" - eig "simrs-vx/internal/domain/main-entities/item-group" eu "simrs-vx/internal/domain/main-entities/uom" + ero "simrs-vx/internal/domain/references/organization" ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - ItemGroup_Code *string `json:"itemGroup_code"` - Uom_Code *string `json:"uom_code"` - Infra_Id *uint16 `json:"infra_id"` - Stock *int `json:"stock"` + Code string `json:"code"` + Name string `json:"name"` + ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code"` + Uom_Code *string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` } type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - ItemGroup_Code *string `json:"itemGroup_code"` - Uom_Code *string `json:"uom_code"` - Infra_Id *uint16 `json:"infra_id"` - Stock *int `json:"stock"` + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { + Code string `json:"code"` + Name string `json:"name"` + ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code"` + Uom_Code *string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -29,13 +35,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - ItemGroup_Code *string `json:"itemGroup_code"` - Uom_Code *string `json:"uom_code"` - Infra_Id *int16 `json:"infra_id"` - Stock *int `json:"stock"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { @@ -55,14 +56,13 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - ItemGroup_Code *string `json:"itemGroup_code"` - ItemGroup *eig.ItemGroup `json:"itemGroup,omitempty"` - Uom_Code *string `json:"uom_code"` - Uom *eu.Uom `json:"uom,omitempty"` - Infra_Id *uint16 `json:"infra_id"` - Stock *int `json:"stock"` + Code string `json:"code"` + Name string `json:"name"` + ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code"` + Uom_Code *string `json:"uom_code"` + Uom *eu.Uom `json:"uom,omitempty"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` } func (d Item) ToResponse() ResponseDto { @@ -70,7 +70,6 @@ func (d Item) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, ItemGroup_Code: d.ItemGroup_Code, - ItemGroup: d.ItemGroup, Uom_Code: d.Uom_Code, Uom: d.Uom, Infra_Id: d.Infra_Id, diff --git a/internal/domain/main-entities/item/entity.go b/internal/domain/main-entities/item/entity.go index c6cb0b8f..9ac471ad 100644 --- a/internal/domain/main-entities/item/entity.go +++ b/internal/domain/main-entities/item/entity.go @@ -2,18 +2,18 @@ package item import ( ecore "simrs-vx/internal/domain/base-entities/core" - eig "simrs-vx/internal/domain/main-entities/item-group" eu "simrs-vx/internal/domain/main-entities/uom" + + ero "simrs-vx/internal/domain/references/organization" ) 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 *string `json:"itemGroup_code" gorm:"size:10"` - ItemGroup *eig.ItemGroup `json:"itemGroup,omitempty" gorm:"foreignKey:ItemGroup_Code;references:Code"` - 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"` - Stock *int `json:"stock"` + 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"` + 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"` + Stock *int `json:"stock"` } diff --git a/internal/domain/main-entities/material/dto.go b/internal/domain/main-entities/material/dto.go index ec565e59..27b0422b 100644 --- a/internal/domain/main-entities/material/dto.go +++ b/internal/domain/main-entities/material/dto.go @@ -2,24 +2,33 @@ package material import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` } type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -27,12 +36,9 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Code *string `json:"code"` + Item_Id *uint `json:"item_id"` } type UpdateDto struct { @@ -52,13 +58,15 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Uom *eu.Uom `json:"uom,omitempty"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Uom *eu.Uom `json:"uom,omitempty"` + Infra_Id *uint16 `json:"infra_id"` + Infra *ein.Infra `json:"infra,omitempty"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty"` } func (d Material) ToResponse() ResponseDto { @@ -67,6 +75,8 @@ func (d Material) ToResponse() ResponseDto { Name: d.Name, Uom_Code: d.Uom_Code, Uom: d.Uom, + Infra_Id: d.Infra_Id, + Infra: d.Infra, Stock: d.Stock, Item_Id: d.Item_Id, Item: d.Item, diff --git a/internal/domain/main-entities/material/entity.go b/internal/domain/main-entities/material/entity.go index c14aac78..cdfd8bfd 100644 --- a/internal/domain/main-entities/material/entity.go +++ b/internal/domain/main-entities/material/entity.go @@ -2,17 +2,20 @@ package material import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type Material struct { - ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - Uom_Code string `json:"uom_code" gorm:"size:10"` - Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + ecore.Main // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + 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"` + Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` + Stock *int `json:"stock"` + 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/mcu-src-category/dto.go b/internal/domain/main-entities/mcu-src-category/dto.go index f78eb6a9..7058722f 100644 --- a/internal/domain/main-entities/mcu-src-category/dto.go +++ b/internal/domain/main-entities/mcu-src-category/dto.go @@ -2,19 +2,19 @@ package division import ( ecore "simrs-vx/internal/domain/base-entities/core" - erc "simrs-vx/internal/domain/references/clinical" + ere "simrs-vx/internal/domain/references/encounter" ) type CreateDto struct { Code string `json:"code"` Name string `json:"name"` - Scope_Code *erc.CheckupScopeCode `json:"scope_code"` + Scope_Code *ere.CheckupScopeCode `json:"scope_code"` } type ReadListDto struct { Code string `json:"code"` Name string `json:"name"` - Scope_Code *erc.CheckupScopeCode `json:"scope_code"` + Scope_Code *ere.CheckupScopeCode `json:"scope_code"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -22,10 +22,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Scope_Code *erc.CheckupScopeCode `json:"scope_code"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { @@ -47,7 +45,7 @@ type ResponseDto struct { ecore.SmallMain Code string `json:"code"` Name string `json:"name"` - Scope_Code *erc.CheckupScopeCode `json:"scope_code"` + Scope_Code *ere.CheckupScopeCode `json:"scope_code"` } func (d McuSrcCategory) ToResponse() ResponseDto { diff --git a/internal/domain/main-entities/mcu-src-category/entity.go b/internal/domain/main-entities/mcu-src-category/entity.go index 61921168..21c266e3 100644 --- a/internal/domain/main-entities/mcu-src-category/entity.go +++ b/internal/domain/main-entities/mcu-src-category/entity.go @@ -2,12 +2,12 @@ package division import ( ecore "simrs-vx/internal/domain/base-entities/core" - erc "simrs-vx/internal/domain/references/clinical" + ere "simrs-vx/internal/domain/references/encounter" ) type McuSrcCategory struct { ecore.SmallMain // adjust this according to the needs Code string `json:"code" gorm:"unique;size:20"` Name string `json:"name" gorm:"size:50"` - Scope_Code *erc.CheckupScopeCode `json:"scope_code" gorm:"size:10"` + Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"size:10"` } diff --git a/internal/domain/main-entities/mcu-src/dto.go b/internal/domain/main-entities/mcu-src/dto.go index f0c06a51..66205ab2 100644 --- a/internal/domain/main-entities/mcu-src/dto.go +++ b/internal/domain/main-entities/mcu-src/dto.go @@ -11,6 +11,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Code string `json:"code"` Name string `json:"name"` CheckupCategory_Code *string `json:"checkupCategory_code"` @@ -21,10 +27,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - CheckupCategory_Code *string `json:"checkupCategory_code"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/mcu-src/entity.go b/internal/domain/main-entities/mcu-src/entity.go index bec60ac0..cdd8356f 100644 --- a/internal/domain/main-entities/mcu-src/entity.go +++ b/internal/domain/main-entities/mcu-src/entity.go @@ -2,11 +2,13 @@ package mcusrc import ( ecore "simrs-vx/internal/domain/base-entities/core" + emsc "simrs-vx/internal/domain/main-entities/mcu-src-category" ) type McuSrc struct { - ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:20"` - Name string `json:"name" gorm:"size:50"` - CheckupCategory_Code *string `json:"checkupCategory_code" gorm:"size:20"` + ecore.SmallMain // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:20"` + Name string `json:"name" gorm:"size:50"` + CheckupCategory_Code *string `json:"checkupCategory_code" gorm:"size:20"` + CheckupCategory *emsc.McuSrcCategory `json:"checkupCategory,omitempty" gorm:"foreignKey:CheckupCategory_Code;references:Code"` } diff --git a/internal/domain/main-entities/medical-action-src-item/dto.go b/internal/domain/main-entities/medical-action-src-item/dto.go index 79ba260c..75836c14 100644 --- a/internal/domain/main-entities/medical-action-src-item/dto.go +++ b/internal/domain/main-entities/medical-action-src-item/dto.go @@ -14,6 +14,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` ProcedureSrc_Id *uint `json:"procedureSrc_id"` Item_Id *uint `json:"item_id"` @@ -24,10 +30,7 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` - ProcedureSrc_Id *uint `json:"procedureSrc_id"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/medical-action-src/dto.go b/internal/domain/main-entities/medical-action-src/dto.go index 85fdf003..664848df 100644 --- a/internal/domain/main-entities/medical-action-src/dto.go +++ b/internal/domain/main-entities/medical-action-src/dto.go @@ -12,6 +12,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Code string `json:"code"` Name string `json:"name"` Item_Id *uint `json:"item_id"` @@ -22,10 +28,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Code string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/medicine-group/dto.go b/internal/domain/main-entities/medicine-group/dto.go index 3ae439a3..c4dfde6c 100644 --- a/internal/domain/main-entities/medicine-group/dto.go +++ b/internal/domain/main-entities/medicine-group/dto.go @@ -19,9 +19,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/medicine-method/dto.go b/internal/domain/main-entities/medicine-method/dto.go index 074f8caa..763a7c65 100644 --- a/internal/domain/main-entities/medicine-method/dto.go +++ b/internal/domain/main-entities/medicine-method/dto.go @@ -19,9 +19,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/medicine-mix-item/dto.go b/internal/domain/main-entities/medicine-mix-item/dto.go index fcc1865e..dbcbce21 100644 --- a/internal/domain/main-entities/medicine-mix-item/dto.go +++ b/internal/domain/main-entities/medicine-mix-item/dto.go @@ -13,6 +13,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { MedicineMix_Id *uint `json:"medicineMix_id"` Medicine_Id *uint `json:"medicine_id"` Dose *uint8 `json:"dose"` @@ -23,10 +29,7 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - MedicineMix_Id *uint `json:"medicineMix_id"` - Medicine_Id *uint `json:"medicine_id"` - Dose *uint8 `json:"dose"` + Id uint16 `json:"id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/medicine-mix/dto.go b/internal/domain/main-entities/medicine-mix/dto.go index 1d21a635..39314051 100644 --- a/internal/domain/main-entities/medicine-mix/dto.go +++ b/internal/domain/main-entities/medicine-mix/dto.go @@ -17,8 +17,7 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Name string `json:"name"` + Id uint16 `json:"id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/medicine/dto.go b/internal/domain/main-entities/medicine/dto.go index a0ed5d1b..bd01f213 100644 --- a/internal/domain/main-entities/medicine/dto.go +++ b/internal/domain/main-entities/medicine/dto.go @@ -10,19 +10,24 @@ import ( ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - MedicineGroup_Code *string `json:"medicineGroup_code"` - MedicineMethod_Code *string `json:"medicineMethod_code"` - Uom_Code *string `json:"uom_code"` - Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra_id"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` - InsuranceCompany_Code *string `json:"insuranceCompany_code"` + Code string `json:"code"` + Name string `json:"name"` + MedicineGroup_Code *string `json:"medicineGroup_code"` + MedicineMethod_Code *string `json:"medicineMethod_code"` + Uom_Code *string `json:"uom_code"` + Dose uint8 `json:"dose"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Code string `json:"code"` Name string `json:"name"` MedicineGroup_Code *string `json:"medicineGroup_code"` @@ -39,16 +44,9 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - MedicineGroup_Code *string `json:"medicineGroup_code"` - MedicineMethod_Code *string `json:"medicineMethod_code"` - Uom_Code *string `json:"uom_code"` - Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra_id"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Code *string `json:"code"` + Item_Id *uint `json:"item_id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/nurse/dto.go b/internal/domain/main-entities/nurse/dto.go index 3feaa041..f108c1cb 100644 --- a/internal/domain/main-entities/nurse/dto.go +++ b/internal/domain/main-entities/nurse/dto.go @@ -11,6 +11,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` @@ -18,7 +24,6 @@ type ReadListDto struct { PageSize int `json:"page_size"` NoPagination int `json:"no_pagination"` } - type ReadDetailDto struct { Id uint16 `json:"id"` Employee_Id *uint `json:"employee_id"` diff --git a/internal/domain/main-entities/nutritionist/dto.go b/internal/domain/main-entities/nutritionist/dto.go index c5bc7003..f69e252e 100644 --- a/internal/domain/main-entities/nutritionist/dto.go +++ b/internal/domain/main-entities/nutritionist/dto.go @@ -11,6 +11,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` diff --git a/internal/domain/main-entities/person-address/dto.go b/internal/domain/main-entities/person-address/dto.go index 73ae88ce..f88799f1 100644 --- a/internal/domain/main-entities/person-address/dto.go +++ b/internal/domain/main-entities/person-address/dto.go @@ -19,12 +19,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint `json:"id"` - Person_Id uint `json:"person_id"` - Address string `json:"address"` - Rt string `json:"rt"` - Rw string `json:"rw"` - Village_Code string `json:"village_code"` + Id uint `json:"id"` + Person_Id uint `json:"person_id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/person-contact/dto.go b/internal/domain/main-entities/person-contact/dto.go index e6865191..036db7e7 100644 --- a/internal/domain/main-entities/person-contact/dto.go +++ b/internal/domain/main-entities/person-contact/dto.go @@ -18,10 +18,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint `json:"id"` - Person_Id uint `json:"person_id"` - Type_Code erp.ContactTypeCode `json:"type_code"` - Value string `json:"value"` + Id uint `json:"id"` + Person_Id uint `json:"person_id"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/person/dto.go b/internal/domain/main-entities/person/dto.go index 296e23b6..02de4b7e 100644 --- a/internal/domain/main-entities/person/dto.go +++ b/internal/domain/main-entities/person/dto.go @@ -11,6 +11,8 @@ import ( type CreateDto 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"` Gender_Code *erp.GenderCode `json:"gender_code"` @@ -23,14 +25,15 @@ type CreateDto struct { } type ReadListDto struct { - Page int `json:"page"` - PageSize int `json:"page_size"` - NoPagination int `json:"no_pagination"` + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` } -type ReadDetailDto struct { - Id uint `json:"id"` +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"` Gender_Code *erp.GenderCode `json:"gender_code"` @@ -40,6 +43,16 @@ type ReadDetailDto struct { Ocupation_Code *erp.OcupationCode `json:"occupation_code"` Ocupation_Name *string `json:"occupation_name"` Ethnic_Code *string `json:"ethnic_code"` + + Page int `json:"page"` + PageSize int `json:"page_size"` + NoPagination int `json:"no_pagination"` +} + +type ReadDetailDto struct { + Id uint `json:"id"` + Name *string `json:"name"` + ResidentIdentityNumber *string `json:"residentIdentityNumber"` } type UpdateDto struct { @@ -60,6 +73,8 @@ type MetaDto struct { type ResponseDto struct { ecore.Main Name string `json:"name"` + FrontTitle *string `json:"frontTitle"` + EndTitle *string `json:"endTitle"` BirthDate *time.Time `json:"birthDate,omitempty"` BirthRegency_Code *string `json:"birthRegency_code"` Gender_Code *erp.GenderCode `json:"gender_code"` @@ -77,6 +92,8 @@ type ResponseDto struct { func (d *Person) ToResponse() ResponseDto { resp := ResponseDto{ Name: d.Name, + FrontTitle: d.FrontTitle, + EndTitle: d.EndTitle, BirthDate: d.BirthDate, BirthRegency_Code: d.BirthRegency_Code, Gender_Code: d.Gender_Code, diff --git a/internal/domain/main-entities/person/entity.go b/internal/domain/main-entities/person/entity.go index 0acdbc91..09f04c7e 100644 --- a/internal/domain/main-entities/person/entity.go +++ b/internal/domain/main-entities/person/entity.go @@ -13,6 +13,8 @@ import ( type Person struct { ecore.Main // adjust this according to the needs Name string `json:"name" gorm:"not null;size:150"` + FrontTitle *string `json:"frontTitle" gorm:"size:50"` + EndTitle *string `json:"endTitle" gorm:"size:50"` BirthDate *time.Time `json:"birthDate,omitempty"` BirthRegency_Code *string `json:"birthRegency_code" gorm:"size:4"` Gender_Code *erp.GenderCode `json:"gender_code" gorm:"size:10"` diff --git a/internal/domain/main-entities/pharmacist/dto.go b/internal/domain/main-entities/pharmacist/dto.go index 07bcd1f7..7d32082d 100644 --- a/internal/domain/main-entities/pharmacist/dto.go +++ b/internal/domain/main-entities/pharmacist/dto.go @@ -11,6 +11,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` diff --git a/internal/domain/main-entities/pharmacy-company/dto.go b/internal/domain/main-entities/pharmacy-company/dto.go index d8f4dd27..eb7ce5e1 100644 --- a/internal/domain/main-entities/pharmacy-company/dto.go +++ b/internal/domain/main-entities/pharmacy-company/dto.go @@ -21,10 +21,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Regency_Code string `json:"regency_code"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/practice-schedule/dto.go b/internal/domain/main-entities/practice-schedule/dto.go index 2f6cda94..3896868f 100644 --- a/internal/domain/main-entities/practice-schedule/dto.go +++ b/internal/domain/main-entities/practice-schedule/dto.go @@ -2,21 +2,27 @@ package practiceschedule import ( ecore "simrs-vx/internal/domain/base-entities/core" - erx "simrs-vx/internal/domain/references/xtime" + erc "simrs-vx/internal/domain/references/common" ) type CreateDto struct { Doctor_Id *uint `json:"doctor_id"` Unit_Code *string `json:"unit_code"` - Day_Code *erx.DayCode `json:"day_code"` + Day_Code *erc.DayCode `json:"day_code"` StartTime *string `json:"startTime"` EndTime *string `json:"endTime"` } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Doctor_Id *uint `json:"doctor_id"` Unit_Code *string `json:"unit_code"` - Day_Code *erx.DayCode `json:"day_code"` + Day_Code *erc.DayCode `json:"day_code"` StartTime *string `json:"startTime"` EndTime *string `json:"endTime"` @@ -26,12 +32,7 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Doctor_Id *uint `json:"doctor_id"` - Unit_Code *string `json:"unit_code"` - Day_Code *erx.DayCode `json:"day_code"` - StartTime *string `json:"startTime"` - EndTime *string `json:"endTime"` + Id uint16 `json:"id"` } type UpdateDto struct { @@ -53,7 +54,7 @@ type ResponseDto struct { ecore.Main Doctor_Id *uint `json:"doctor_id"` Unit_Code *string `json:"unit_code"` - Day_Code *erx.DayCode `json:"day_code"` + Day_Code *erc.DayCode `json:"day_code"` StartTime *string `json:"startTime"` EndTime *string `json:"endTime"` } diff --git a/internal/domain/main-entities/practice-schedule/entity.go b/internal/domain/main-entities/practice-schedule/entity.go index 5bd1c006..524867c8 100644 --- a/internal/domain/main-entities/practice-schedule/entity.go +++ b/internal/domain/main-entities/practice-schedule/entity.go @@ -4,7 +4,7 @@ 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" - erx "simrs-vx/internal/domain/references/xtime" + erc "simrs-vx/internal/domain/references/common" ) type PracticeSchedule struct { @@ -13,7 +13,7 @@ type PracticeSchedule struct { Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` - Day_Code *erx.DayCode `json:"day_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-src/dto.go b/internal/domain/main-entities/procedure-src/dto.go index c0ba8c30..a69a5244 100644 --- a/internal/domain/main-entities/procedure-src/dto.go +++ b/internal/domain/main-entities/procedure-src/dto.go @@ -21,10 +21,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - IndName string `json:"indName"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/province/dto.go b/internal/domain/main-entities/province/dto.go index bc1461e0..5bd519a8 100644 --- a/internal/domain/main-entities/province/dto.go +++ b/internal/domain/main-entities/province/dto.go @@ -15,9 +15,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id int16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` + Id int16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/regency/dto.go b/internal/domain/main-entities/regency/dto.go index 6cb850de..7fb7546b 100644 --- a/internal/domain/main-entities/regency/dto.go +++ b/internal/domain/main-entities/regency/dto.go @@ -19,10 +19,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Province_Code string `json:"province_code"` - Code string `json:"code"` - Name string `json:"name"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/unit/dto.go b/internal/domain/main-entities/unit/dto.go index 448d16ec..8d4c0b44 100644 --- a/internal/domain/main-entities/unit/dto.go +++ b/internal/domain/main-entities/unit/dto.go @@ -12,6 +12,12 @@ type CreateDto struct { } type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { Installation_Id *uint16 `json:"installation_id"` Code string `json:"code"` Name string `json:"name"` @@ -22,10 +28,9 @@ type ReadListDto struct { } type ReadDetailDto struct { - Installation_Id *uint16 `json:"installation_id"` Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` + Installation_Id *uint16 `json:"installation_id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/uom/dto.go b/internal/domain/main-entities/uom/dto.go index 08055c12..597510a1 100644 --- a/internal/domain/main-entities/uom/dto.go +++ b/internal/domain/main-entities/uom/dto.go @@ -19,9 +19,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` + Id uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/main-entities/user/dto.go b/internal/domain/main-entities/user/dto.go index 98c3a2d1..102429b7 100644 --- a/internal/domain/main-entities/user/dto.go +++ b/internal/domain/main-entities/user/dto.go @@ -7,14 +7,14 @@ import ( ) type CreateDto struct { - Name string `json:"name"` - Password string `json:"password"` - Status_Code erc.StatusCode `json:"status_code"` + Name string `json:"name"` + Password string `json:"password"` + Status_Code erc.UserStatusCode `json:"status_code"` } type ReadListDto struct { - Name string `json:"name"` - Status_Code erc.StatusCode `json:"status_code"` + Name string `json:"name"` + Status_Code erc.UserStatusCode `json:"status_code"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -22,8 +22,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint `json:"id"` - Name string `json:"name"` + Id uint `json:"id"` + Name *string `json:"name"` } type UpdateDto struct { @@ -49,11 +49,11 @@ type LoginDto struct { type ResponseDto struct { ecore.Main - Name string `json:"name"` - Status_Code erc.StatusCode `json:"status_code"` - FailedLoginCount uint8 `json:"failedLoginCount"` - LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"` - LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"` + Name string `json:"name"` + Status_Code erc.UserStatusCode `json:"status_code"` + FailedLoginCount uint8 `json:"failedLoginCount"` + LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"` + LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"` } func (d *User) ToResponse() ResponseDto { diff --git a/internal/domain/main-entities/user/entity.go b/internal/domain/main-entities/user/entity.go index f69e03ca..3ad46b9d 100644 --- a/internal/domain/main-entities/user/entity.go +++ b/internal/domain/main-entities/user/entity.go @@ -7,12 +7,12 @@ import ( ) type User struct { - ecore.Main // adjust this according to the needs - Name string `json:"name" gorm:"not null;size:25"` - Password string `json:"password" gorm:"not null;size:255"` - Status_Code erc.StatusCode `json:"status_code" gorm:"not null;size:10"` - FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"` - LoginAttemptCount int `json:"-"` - LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"` - LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"` + ecore.Main // adjust this according to the needs + Name string `json:"name" gorm:"unique;not null;size:25"` + Password string `json:"password" gorm:"not null;size:255"` + Status_Code erc.UserStatusCode `json:"status_code" gorm:"not null;size:10"` + FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"` + LoginAttemptCount int `json:"-"` + LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"` + LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"` } diff --git a/internal/domain/main-entities/village/dto.go b/internal/domain/main-entities/village/dto.go index bdd1a323..968784ee 100644 --- a/internal/domain/main-entities/village/dto.go +++ b/internal/domain/main-entities/village/dto.go @@ -17,10 +17,8 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint32 `json:"id"` - District_Code string `json:"district_code"` - Code string `json:"code"` - Name string `json:"name"` + Id uint32 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index f1be0605..3998811b 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -1,18 +1,38 @@ package clinical type ( - CheckupScopeCode string - DoctorFeeTypeCode string + SubjectCode string + ObjectCode string + AssessmentCode string + InstructionCode string ) const ( - CSCLab CheckupScopeCode = "lab" // Laboratorium - CSCMLab CheckupScopeCode = "mic-lab" // Microbacterial Laboratorium - CSCPLab CheckupScopeCode = "pa-lab" // Patology Anatomy Laboratorium - CSCRad CheckupScopeCode = "radiology" // Radiology + SCPrimaryComplaint SubjectCode = "pri-compl" // Keluhan Utama + SCSecComplaint SubjectCode = "sec-compl" // Secondary Complaint + SCCurrentDiseaseHistory SubjectCode = "cur-disea-hist" // Current Disease History + SCPastDiseaseHistory SubjectCode = "pas-disea-hist" // Past Disease History + SCFamilyDiseaseHistory SubjectCode = "fam-disea-hist" // Family Disease History + SCAllergyHistory SubjectCode = "alg-hist" // Allergic History + SCAllergyReaction SubjectCode = "alg-react" // Allergic Reaction + SCMedicationHistory SubjectCode = "med-hist" // Medication History - DFTCOut DoctorFeeTypeCode = "outpatient" // Rawat Jalan - DFTCInp DoctorFeeTypeCode = "inpatient" // Rawat Inap - DFTCEme DoctorFeeTypeCode = "emergency" // Darurat - DFTCReh DoctorFeeTypeCode = "medic-rehab" // Rehab Medik + OCConsciousnessLevel ObjectCode = "consc-level" // Tingkat Kesadaran + OCConsciousnessLevelDet ObjectCode = "consc-level-det" // Detail Tingkat Kesadaran + OCSystolicBloodPressure ObjectCode = "syst-bp" // Tekanan Darah Systolic + OCDiastolicBloodPressure ObjectCode = "diast-bp" // Tekanan Darah Diastolic + OCHeartRate ObjectCode = "hear-rt" // Detak Jantung + OCTemperature ObjectCode = "temp" // Suhu + OCSpO2 ObjectCode = "spo2" // SpO2 + OCWeight ObjectCode = "weight" // Berat Badan + OCHeight ObjectCode = "height" // Tinggi Badan + + ACEarlyDiag AssessmentCode = "early-diag" // Diagnosis Awal + ACLateDiag AssessmentCode = "late-diag" // Diagnosis Akhir + ACSecDiag AssessmentCode = "sec-diag" // Diagnosis Sekunder + + ICDetail InstructionCode = "detail" // Detail instruksi + ICMedAct InstructionCode = "med-act" // Tindakan medis + ICMedication InstructionCode = "medication" // Obat + ICMaterial InstructionCode = "material" // BMHP ) diff --git a/internal/domain/references/common/common.go b/internal/domain/references/common/common.go index 7f6fed2b..d60ee8a3 100644 --- a/internal/domain/references/common/common.go +++ b/internal/domain/references/common/common.go @@ -1,12 +1,17 @@ package common type ( - YaTidakCode byte - SudahBelumCode byte - AktifSimpelCode byte - AktifAdvanceCode byte - TersediaCode byte - StatusCode string + YaTidakCode byte + SudahBelumCode byte + AktifSimpelCode byte + AktifAdvanceCode byte + TersediaCode byte + DayCode byte + ActiveStatusCode string + DataStatusCode string + UserStatusCode string + TimeUnitCode string + PaymentMethodCode string ) const ( @@ -35,9 +40,61 @@ const ( ) const ( - SCNew StatusCode = "new" - SCActive StatusCode = "active" - SCInactive StatusCode = "inactive" - SCBlocked StatusCode = "blocked" - SCSuspended StatusCode = "suspended" + DCMinggu DayCode = iota + DCSenin + DCSelasa + DCRabu + DCKamis + DCJumat + DCSabtu ) + +const ( + SCActive ActiveStatusCode = "active" // Aktif + SCInactive ActiveStatusCode = "inactive" // Tidak aktif + + DSCNew DataStatusCode = "new" // Baru + DSCReview DataStatusCode = "review" // Review + DSCProcess DataStatusCode = "process" // Proses + DSCDone DataStatusCode = "done" // Selesai + DSCCancel DataStatusCode = "cancel" // Dibatalkan + DSCRejected DataStatusCode = "rejected" // Ditolak + DSCSkipped DataStatusCode = "skipped" // Dilewati + + USCNew UserStatusCode = "new" // Baru + USCActive UserStatusCode = "active" // Aktif + USCInactive UserStatusCode = "inactive" // Tidak aktif + USCBlocked UserStatusCode = "blocked" // Diblokir + USCSuspended UserStatusCode = "suspended" // Dibekukan + + TUCSec TimeUnitCode = "sec" // Detik + TUCMin TimeUnitCode = "min" // Menit + TUCHour TimeUnitCode = "hour" // Jam + TUCDay TimeUnitCode = "day" // Hari + TUCWeek TimeUnitCode = "week" // Minggu + TUCMonth TimeUnitCode = "month" // Bulan + TUCYear TimeUnitCode = "year" // Tahun + + PMCCash PaymentMethodCode = "cash" // Tunai + PMCDebit PaymentMethodCode = "debit" // Debet + PMCCredit PaymentMethodCode = "credit" // Kredit + PMCInsurance PaymentMethodCode = "insurance" // Asuransi + PMCMembership PaymentMethodCode = "membership" // Member + +) + +func GetDayCodes() map[DayCode]string { + return map[DayCode]string{ + DCMinggu: "Minggu", + DCSenin: "Senin", + DCSelasa: "Selasa", + DCRabu: "Rabu", + DCKamis: "Kamis", + DCJumat: "Jumat", + DCSabtu: "Sabtu", + } +} + +func (obj DayCode) String() string { + return GetDayCodes()[obj] +} diff --git a/internal/domain/references/digital-signature/digital-signature.go b/internal/domain/references/digital-signature/digital-signature.go deleted file mode 100644 index 4c8f2fe9..00000000 --- a/internal/domain/references/digital-signature/digital-signature.go +++ /dev/null @@ -1,26 +0,0 @@ -package digitalsignature - -type ( - RMEType string - SignType string -) - -const ( - // modules - RMETypePrescription RMEType = "prescription" - RMETypeExamination RMEType = "examination" - RMETypeRadiology RMEType = "radiology" - RMETypeSick RMEType = "sick" - RMETypeReferral RMEType = "referral" - RMETypeEndOfLife RMEType = "endoflife" - RMETypeChangeDpjp RMEType = "changedpjp" - - // employee - SignTypeEmployee SignType = "employee" - - // doctor - SignTypeDoctor SignType = "doctor" - - // patient - SignTypePatient SignType = "patient" -) diff --git a/internal/domain/references/encounter/encounter.go b/internal/domain/references/encounter/encounter.go index 941b0cae..00b01236 100644 --- a/internal/domain/references/encounter/encounter.go +++ b/internal/domain/references/encounter/encounter.go @@ -1,32 +1,63 @@ package encounter type ( - EncounterStatus string - EncounterClass string - EmergencyClass string - InpatientClass string + EncounterClassCode string + QueueStatusCode string + DischargeMethodCode string + TransportationCode string + PersonConditionCode string + EmergencyClassCode string + OutpatientClassCode string + CheckupScopeCode string ) const ( - EncounterStatusNew EncounterStatus = "new" - EncounterStatusNurse EncounterStatus = "nurse assessment" - EncounterStatusDoctor EncounterStatus = "doctor assessment" - EncounterStatusDone EncounterStatus = "done" - EncounterStatusCancel EncounterStatus = "canceled" -) -const ( - IGD EmergencyClass = "igd" - Ponek EmergencyClass = "ponek" -) -const ( - ECAmbulatory EncounterClass = "ambulatory" - ECOutpatient EncounterClass = "outpatient" - ECInpatient EncounterClass = "inpatient" - ECEmergency EncounterClass = "emergency" - ECRadiology EncounterClass = "radiology" + ECOutpatient EncounterClassCode = "outpatient" + ECAmbulatory EncounterClassCode = "ambulatory" + ECEmergency EncounterClassCode = "emergency" + ECInpatient EncounterClassCode = "inpatient" + ECDraft EncounterClassCode = "draft" + ECDone EncounterClassCode = "done" + ECCancel EncounterClassCode = "cancel" + ECSkip EncounterClassCode = "skip" + + QSCWait QueueStatusCode = "wait" // Tunggu + QSCProc QueueStatusCode = "proc" // Proses + QSCDone QueueStatusCode = "done" // Selesai + QSCCancel QueueStatusCode = "cancel" // Dibatalkan + QSCSkip QueueStatusCode = "skip" // Dilewati + + DMCHome DischargeMethodCode = "home" // Rumah + DMCHomeReq DischargeMethodCode = "home-request" // Rumah (Dibutuhkan) + + TCAmbulance TransportationCode = "ambulance" + TCCar TransportationCode = "car" + TCMotorCycle TransportationCode = "motor-cycle" + TCOther TransportationCode = "other" + + PCCRes PersonConditionCode = "res" // Resutiasi + PCCEmg PersonConditionCode = "emg" // Darurat + PCCUrg PersonConditionCode = "urg" // Mendesak + PCCLurg PersonConditionCode = "lurg" // Kurang mendesak + PCCNurg PersonConditionCode = "nurg" // + PCCDoa PersonConditionCode = "doa" // Meninggal saat tiba + + ECCEmg EmergencyClassCode = "emg" // Darurat/Emergency biasa + ECCEon EmergencyClassCode = "eon" // Ponek/Emergency obstetri neonatal + + OCCOp OutpatientClassCode = "op" // Rawat Jalan + OCCIcu OutpatientClassCode = "icu" // ICU + OCCHcu OutpatientClassCode = "hcu" // HCU + OCCVk OutpatientClassCode = "vk" // Verlos kamer + + CSCLab CheckupScopeCode = "lab" // Laboratorium + CSCMLab CheckupScopeCode = "mic-lab" // Microbacterial Laboratorium + CSCPLab CheckupScopeCode = "pa-lab" // Patology Anatomy Laboratorium + CSCRad CheckupScopeCode = "radiology" // Radiology + ) -func (ec EncounterClass) Code() string { +func (ec EncounterClassCode) Code() string { switch ec { case ECAmbulatory, ECOutpatient: return "AMB" @@ -38,8 +69,3 @@ func (ec EncounterClass) Code() string { return "UNKNOWN" } } - -const ( - ICU InpatientClass = "ICU" - NonICU InpatientClass = "non ICU" -) diff --git a/internal/domain/references/finance/finance.go b/internal/domain/references/finance/finance.go deleted file mode 100644 index bbf405e7..00000000 --- a/internal/domain/references/finance/finance.go +++ /dev/null @@ -1,67 +0,0 @@ -package finance - -type ( - PaymentMethodCode string - TaxCode string - PaymentStatusCode string - ServiceType string -) - -const ( - PMCCash PaymentMethodCode = "cash" - PMCBPJS PaymentMethodCode = "bpjs" - PMCInsurance PaymentMethodCode = "insurance" - PMCMembership PaymentMethodCode = "membership" - PMCDebit PaymentMethodCode = "debit" - PMCCredit PaymentMethodCode = "credit" - PMCOther PaymentMethodCode = "other" -) - -const ( - TCCountry TaxCode = "country" -) - -const ( - PaymentStatusNew PaymentStatusCode = "new" - PaymentStatusUnpaid PaymentStatusCode = "unpaid" - PaymentStatusPaid PaymentStatusCode = "paid" - PaymentStatusCancel PaymentStatusCode = "cancel" - PaymentStatusFailed PaymentStatusCode = "failed" -) - -func GetTaxeCodes() map[TaxCode]float32 { - return map[TaxCode]float32{ - TCCountry: 0.11, - } -} - -var NonInsurancePaymentMethods = map[PaymentMethodCode]bool{ - PMCCash: true, - PMCDebit: true, - PMCCredit: true, -} - -func (p PaymentMethodCode) IsInsurance() bool { - switch p { - case PMCCash, PMCDebit, PMCCredit, PMCBPJS: - return true - default: - return false - } -} - -const ( - STInpatient = "Rawat Inap" - STAmbulatory = "Rawat Jalan" - STEmergency = "IGD" - STPonek = "PONEK" - STLab = "Laboratorium" - STRadiology = "Radiologi" -) - -const ( - AdminEmergencyFee = "Biaya Administrasi IGD" - DoctorEmergencyFee = "Biaya Dokter IGD" - AdminPediatricInternalFee = "Biaya Administrasi Poli Anak/Penyakit Dalam" - AdminGeneralPolyFee = "Biaya Administrasi Poli" -) diff --git a/internal/domain/references/organization/organization.go b/internal/domain/references/organization/organization.go index bad128d6..5c86ba51 100644 --- a/internal/domain/references/organization/organization.go +++ b/internal/domain/references/organization/organization.go @@ -2,15 +2,45 @@ package organization type ( EmployeePosisitionCode string + ItemGroupCode string + InfraGroupCode string + UnitTypeCode string + DoctorFeeTypeCode string ) const ( - EPCDoc EmployeePosisitionCode = "doctor" - EPCNur EmployeePosisitionCode = "nurse" - EPCNut EmployeePosisitionCode = "nutritionist" - EPCLab EmployeePosisitionCode = "laborant" - EPCPha EmployeePosisitionCode = "pharmacy" - EPCPay EmployeePosisitionCode = "payment" - EPCPav EmployeePosisitionCode = "payment-verificator" - EPCMan EmployeePosisitionCode = "management" + EPCDoc EmployeePosisitionCode = "doctor" // Dokter + EPCNur EmployeePosisitionCode = "nurse" // Perawat + EPCNut EmployeePosisitionCode = "nutritionist" // Ahli gizi + EPCLab EmployeePosisitionCode = "laborant" // Laboran + EPCPha EmployeePosisitionCode = "pharmacy" // Farmasi + EPCPay EmployeePosisitionCode = "payment" // Pembayaran + EPCPav EmployeePosisitionCode = "payment-verificator" // Konfirmasi pembayaran + EPCMan EmployeePosisitionCode = "management" // Manajemen + + ITGCInfra ItemGroupCode = "infra" + ITGCMedicine ItemGroupCode = "medicine" + ITGCDevice ItemGroupCode = "device" + ITGCMaterial ItemGroupCode = "material" + ITGCEmpFee ItemGroupCode = "employee-fee" + ITGCDocFee ItemGroupCode = "doctor-fee" + + IFGCBuilding InfraGroupCode = "building" + IFGCFloor InfraGroupCode = "floor" + IFGCRoom InfraGroupCode = "room" + IFGCChamber InfraGroupCode = "chamber" + IFGCBed InfraGroupCode = "bed" + IFGCWarehouse InfraGroupCode = "warehouse" + + UTCReg UnitTypeCode = "reg" // Registrasi + UTCExa UnitTypeCode = "exa" // Pemeriksaan + UTCPay UnitTypeCode = "pay" // Pembayaran + UTCPha UnitTypeCode = "pha" // Farmasi + UTCLab UnitTypeCode = "lab" // Laboratorium + UTCRad UnitTypeCode = "rad" // Radiologi + + DFTCOut DoctorFeeTypeCode = "outpatient" // Rawat Jalan + DFTCInp DoctorFeeTypeCode = "inpatient" // Rawat Inap + DFTCEme DoctorFeeTypeCode = "emergency" // Darurat + DFTCReh DoctorFeeTypeCode = "medic-rehab" // Rehab Medik ) diff --git a/internal/domain/references/patient/patient.go b/internal/domain/references/patient/patient.go deleted file mode 100644 index 4332eca0..00000000 --- a/internal/domain/references/patient/patient.go +++ /dev/null @@ -1,85 +0,0 @@ -package patient - -type ( - ConsciousLevelCode string - StatusCode string - PaymentMethodCode string - EndAssessmentCode string - VisitTypeJknCode uint8 -) - -const ( - CLCAlert ConsciousLevelCode = "alert" - CLCVoice ConsciousLevelCode = "voice" - CLCPain ConsciousLevelCode = "pain" - CLCUnresponsive ConsciousLevelCode = "unresponsive" - CLCAnxious ConsciousLevelCode = "anxious" - CLCAcuteConfusional ConsciousLevelCode = "acute-confuncional" - - PMCCash PaymentMethodCode = "cash" - PMCDebit PaymentMethodCode = "debit" - PMCCredit PaymentMethodCode = "credit" - PMCBpjs PaymentMethodCode = "bpjs" - PMCMembership PaymentMethodCode = "membership" - PMCInsurance PaymentMethodCode = "insurance" - - SCDraft StatusCode = "draft" - SCActive StatusCode = "active" - SCInactive StatusCode = "inactive" - SCBlocked StatusCode = "blocked" - SCDead StatusCode = "dead" - - EACHomeRecom EndAssessmentCode = "home recommendation" - EACHomeReq EndAssessmentCode = "home request" - EACOtherPoly EndAssessmentCode = "others poly" - EACRefInt EndAssessmentCode = "referral internal" - EACRefExt EndAssessmentCode = "referral external" - EACDecease EndAssessmentCode = "decease" - - VTJCReference VisitTypeJknCode = 1 - VTJCInternalReference VisitTypeJknCode = 2 - VTJCControl VisitTypeJknCode = 3 - VTJCExternalReference VisitTypeJknCode = 4 -) - -func GetStatusCodes() map[StatusCode]string { - return map[StatusCode]string{ - SCDraft: "Draft", - SCActive: "Aktif", - SCInactive: "Tidak Aktif", - SCBlocked: "Diblokir", - SCDead: "Meninggal", - } -} - -func GetConsciousLevelCodes() map[ConsciousLevelCode]string { - return map[ConsciousLevelCode]string{ - CLCAlert: "Sadar Baik / Alert", - CLCVoice: "Berespon dengan kata-kata / Voice", - CLCPain: "Hanya beresponse jika dirangsang nyeri / pain", - CLCUnresponsive: "Pasien tidak sadar / unresponsive", - CLCAnxious: "Gelisah atau bingung", - CLCAcuteConfusional: "Acute Confusional States", - } -} - -func GetPaymentMethodCodes() map[PaymentMethodCode]string { - return map[PaymentMethodCode]string{ - PMCCash: "cash", - PMCDebit: "debit", - PMCCredit: "credit", - PMCBpjs: "bpjs", - PMCMembership: "membership", - PMCInsurance: "insurance"} -} - -func GetEndAssessments() map[EndAssessmentCode]string { - return map[EndAssessmentCode]string{ - EACHomeRecom: "home-recommendation", - EACHomeReq: "home-request", - EACOtherPoly: "other-poly", - EACRefInt: "referral-internal", - EACRefExt: "referral-external", - EACDecease: "decease", - } -} diff --git a/internal/domain/references/person/person.go b/internal/domain/references/person/person.go index eef0a7a2..74afbb8d 100644 --- a/internal/domain/references/person/person.go +++ b/internal/domain/references/person/person.go @@ -48,18 +48,18 @@ const ( ) const ( - ECTidakSekolah EducationCode = "TS" - ECTK EducationCode = "TK" - ECSD EducationCode = "SD" - ECSLTP EducationCode = "SMP" - ECSLTA EducationCode = "SMA" - ECD1 EducationCode = "D1" - ECD2 EducationCode = "D2" - ECD3 EducationCode = "D3" - ECD4 EducationCode = "D4" - ECS1 EducationCode = "S1" - ECS2 EducationCode = "S2" - ECS3 EducationCode = "S3" + ECTS EducationCode = "TS" + ECTK EducationCode = "TK" + ECSD EducationCode = "SD" + ECSLTP EducationCode = "SMP" + ECSLTA EducationCode = "SMA" + ECD1 EducationCode = "D1" + ECD2 EducationCode = "D2" + ECD3 EducationCode = "D3" + ECD4 EducationCode = "D4" + ECS1 EducationCode = "S1" + ECS2 EducationCode = "S2" + ECS3 EducationCode = "S3" ) const ( @@ -160,22 +160,22 @@ func GetReligionCodes() map[ReligionCode]string { func GetEducationCodes() map[EducationCode]string { return map[EducationCode]string{ - ECTidakSekolah: "Tidak Sekolah", - ECTK: "TK", - ECSD: "SD", - ECSLTP: "SMP sederajat", - ECSLTA: "SMP sederajat", - ECD1: "D1 sederajat", - ECD2: "D2 sederajat", - ECD3: "D3 sederajat", - ECD4: "D4 sederajat", - ECS1: "S1", - ECS2: "S3", - ECS3: "S3", + ECTS: "Tidak Sekolah", + ECTK: "TK", + ECSD: "SD", + ECSLTP: "SMP sederajat", + ECSLTA: "SMP sederajat", + ECD1: "D1 sederajat", + ECD2: "D2 sederajat", + ECD3: "D3 sederajat", + ECD4: "D4 sederajat", + ECS1: "S1", + ECS2: "S3", + ECS3: "S3", } } -func GetProfessions() map[OcupationCode]string { +func GetOcupationCodes() map[OcupationCode]string { return map[OcupationCode]string{ OCTidakBekerja: "Tidak Bekerja", OCPns: "PNS", @@ -259,7 +259,7 @@ func (obj EducationCode) String() string { } func (obj OcupationCode) String() string { - return GetProfessions()[obj] + return GetOcupationCodes()[obj] } func (obj AgeGroupCode) String() string { diff --git a/internal/domain/references/queue/queue.go b/internal/domain/references/queue/queue.go deleted file mode 100644 index b36aa415..00000000 --- a/internal/domain/references/queue/queue.go +++ /dev/null @@ -1,3 +0,0 @@ -package queue - -const QueueName = "SABBI-QUEUE-" diff --git a/internal/domain/references/xtime/xtime.go b/internal/domain/references/xtime/xtime.go deleted file mode 100644 index ae15bd32..00000000 --- a/internal/domain/references/xtime/xtime.go +++ /dev/null @@ -1,31 +0,0 @@ -package xtime - -type ( - DayCode byte -) - -const ( - DCMinggu DayCode = iota - DCSenin - DCSelasa - DCRabu - DCKamis - DCJumat - DCSabtu -) - -func GetDayCodes() map[DayCode]string { - return map[DayCode]string{ - DCMinggu: "Minggu", - DCSenin: "Senin", - DCSelasa: "Selasa", - DCRabu: "Rabu", - DCKamis: "Kamis", - DCJumat: "Jumat", - DCSabtu: "Sabtu", - } -} - -func (obj DayCode) String() string { - return GetDayCodes()[obj] -} diff --git a/internal/interface/main-handler/infra-group/handler.go b/internal/interface/main-handler/infra-group/handler.go deleted file mode 100644 index 9b3c090a..00000000 --- a/internal/interface/main-handler/infra-group/handler.go +++ /dev/null @@ -1,71 +0,0 @@ -package infragroup - -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/infra-group" - u "simrs-vx/internal/use-case/main-use-case/infra-group" -) - -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) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { - return - } - dto := e.ReadDetailDto{} - dto.Id = uint16(id) - res, err := u.ReadDetail(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 - } - dto.Id = uint(id) - 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/interface/main-handler/item-group/handler.go b/internal/interface/main-handler/item-group/handler.go deleted file mode 100644 index 71eb8b60..00000000 --- a/internal/interface/main-handler/item-group/handler.go +++ /dev/null @@ -1,71 +0,0 @@ -package itemgroup - -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/item-group" - u "simrs-vx/internal/use-case/main-use-case/item-group" -) - -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) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { - return - } - dto := e.ReadDetailDto{} - dto.Id = uint16(id) - res, err := u.ReadDetail(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 - } - dto.Id = uint(id) - 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/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 4b5fd1f1..0c47e420 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -44,11 +44,9 @@ import ( doctorfee "simrs-vx/internal/interface/main-handler/doctor-fee" ethnic "simrs-vx/internal/interface/main-handler/ethnic" infra "simrs-vx/internal/interface/main-handler/infra" - infragroup "simrs-vx/internal/interface/main-handler/infra-group" installation "simrs-vx/internal/interface/main-handler/installation" insurancecompany "simrs-vx/internal/interface/main-handler/insurance-company" item "simrs-vx/internal/interface/main-handler/item" - itemgroup "simrs-vx/internal/interface/main-handler/item-group" itemprice "simrs-vx/internal/interface/main-handler/item-price" material "simrs-vx/internal/interface/main-handler/material" mcusrc "simrs-vx/internal/interface/main-handler/mcu-src" @@ -120,8 +118,6 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/pharmacy-company", pharmacycompany.O) hc.RegCrud(r, "/v1/diagnose-src", diagnosesrc.O) hc.RegCrud(r, "/v1/procedure-src", proceduresrc.O) - hc.RegCrud(r, "/v1/infra-group", infragroup.O) - hc.RegCrud(r, "/v1/item-group", itemgroup.O) hc.RegCrud(r, "/v1/uom", uom.O) hc.RegCrud(r, "/v1/item", item.O) hc.RegCrud(r, "/v1/item-price", itemprice.O) diff --git a/internal/interface/migration/migration.go b/internal/interface/migration/migration.go index 6122597c..353120d3 100644 --- a/internal/interface/migration/migration.go +++ b/internal/interface/migration/migration.go @@ -16,11 +16,9 @@ import ( employee "simrs-vx/internal/domain/main-entities/employee" ethnic "simrs-vx/internal/domain/main-entities/ethnic" infra "simrs-vx/internal/domain/main-entities/infra" - infragroup "simrs-vx/internal/domain/main-entities/infra-group" installation "simrs-vx/internal/domain/main-entities/installation" insurancecompany "simrs-vx/internal/domain/main-entities/insurance-company" item "simrs-vx/internal/domain/main-entities/item" - itemgroup "simrs-vx/internal/domain/main-entities/item-group" itemprice "simrs-vx/internal/domain/main-entities/item-price" material "simrs-vx/internal/domain/main-entities/material" mcusrc "simrs-vx/internal/domain/main-entities/mcu-src" @@ -96,9 +94,7 @@ func GetEntities() []any { &pharmacycompany.PharmacyCompany{}, &diagnosesrc.DiagnoseSrc{}, &proceduresrc.ProcedureSrc{}, - &infragroup.InfraGroup{}, &employee.Employee{}, - &itemgroup.ItemGroup{}, &doctor.Doctor{}, &nurse.Nurse{}, &nutritionist.Nutritionist{}, diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 069958c7..70925827 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -65,9 +65,9 @@ func GenToken(input mu.LoginDto) (*d.Data, error) { user.LoginAttemptCount++ dg.I.Save(&user) return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-incorrect", Message: el.GenMessage("auth-login-incorrect")}} - } else if user.Status_Code == erc.SCBlocked { + } else if user.Status_Code == erc.USCBlocked { return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-blocked", Message: el.GenMessage("auth-login-blocked")}} - } else if user.Status_Code == erc.SCNew { + } else if user.Status_Code == erc.USCNew { return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-unverified", Message: el.GenMessage("auth-login-unverified")}} } diff --git a/internal/use-case/main-use-case/device/case.go b/internal/use-case/main-use-case/device/case.go index cb40c1eb..5c5c9b73 100644 --- a/internal/use-case/main-use-case/device/case.go +++ b/internal/use-case/main-use-case/device/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 { @@ -87,6 +90,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/device/helper.go b/internal/use-case/main-use-case/device/helper.go index 137425b1..63d51664 100644 --- a/internal/use-case/main-use-case/device/helper.go +++ b/internal/use-case/main-use-case/device/helper.go @@ -6,6 +6,16 @@ package device import ( e "simrs-vx/internal/domain/main-entities/device" + ei "simrs-vx/internal/domain/main-entities/item" + + ui "simrs-vx/internal/use-case/main-use-case/item" + + ero "simrs-vx/internal/domain/references/organization" + + 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.Device) { @@ -22,3 +32,20 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Device) { data.Uom_Code = inputSrc.Uom_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("dev-", input.Code), + Name: input.Name, + ItemGroup_Code: ero.ITGCDevice, + Uom_Code: &input.Uom_Code, + Infra_Id: input.Infra_Id, + } + item, err := ui.CreateData(itemCreate, event, tx) + if err != nil { + return err + } + + input.Item_Id = &item.Id + return nil +} diff --git a/internal/use-case/main-use-case/device/lib.go b/internal/use-case/main-use-case/device/lib.go index ae369a58..22c233b6 100644 --- a/internal/use-case/main-use-case/device/lib.go +++ b/internal/use-case/main-use-case/device/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.De tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Device{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/division-position/case.go b/internal/use-case/main-use-case/division-position/case.go index bc088fcc..2fbb0c3b 100644 --- a/internal/use-case/main-use-case/division-position/case.go +++ b/internal/use-case/main-use-case/division-position/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/division-position/lib.go b/internal/use-case/main-use-case/division-position/lib.go index a09ec618..c59506c0 100644 --- a/internal/use-case/main-use-case/division-position/lib.go +++ b/internal/use-case/main-use-case/division-position/lib.go @@ -51,10 +51,16 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.DivisionPosition{}). Preload("Division"). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/doctor-fee/case.go b/internal/use-case/main-use-case/doctor-fee/case.go index 449349a1..cce2ae5f 100644 --- a/internal/use-case/main-use-case/doctor-fee/case.go +++ b/internal/use-case/main-use-case/doctor-fee/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/doctor-fee/lib.go b/internal/use-case/main-use-case/doctor-fee/lib.go index f34ab9d7..ef4629f5 100644 --- a/internal/use-case/main-use-case/doctor-fee/lib.go +++ b/internal/use-case/main-use-case/doctor-fee/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Do tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.DoctorFee{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/doctor/case.go b/internal/use-case/main-use-case/doctor/case.go index 72a60279..19088c61 100644 --- a/internal/use-case/main-use-case/doctor/case.go +++ b/internal/use-case/main-use-case/doctor/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/doctor/lib.go b/internal/use-case/main-use-case/doctor/lib.go index b75d9bb1..db5bd8b7 100644 --- a/internal/use-case/main-use-case/doctor/lib.go +++ b/internal/use-case/main-use-case/doctor/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Do tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Doctor{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/employee/case.go b/internal/use-case/main-use-case/employee/case.go index 68476e13..0acc1e60 100644 --- a/internal/use-case/main-use-case/employee/case.go +++ b/internal/use-case/main-use-case/employee/case.go @@ -1,15 +1,25 @@ package employee import ( + ed "simrs-vx/internal/domain/main-entities/doctor" e "simrs-vx/internal/domain/main-entities/employee" + en "simrs-vx/internal/domain/main-entities/nurse" + et "simrs-vx/internal/domain/main-entities/nutritionist" + ep "simrs-vx/internal/domain/main-entities/pharmacist" "strconv" - dg "github.com/karincake/apem/db-gorm-pg" - d "github.com/karincake/dodol" + ud "simrs-vx/internal/use-case/main-use-case/doctor" + un "simrs-vx/internal/use-case/main-use-case/nurse" + ut "simrs-vx/internal/use-case/main-use-case/nutritionist" + up "simrs-vx/internal/use-case/main-use-case/pharmacist" + + ero "simrs-vx/internal/domain/references/organization" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" + dg "github.com/karincake/apem/db-gorm-pg" + d "github.com/karincake/dodol" "gorm.io/gorm" ) @@ -24,7 +34,7 @@ func Create(input e.CreateDto) (*d.Data, error) { } // Start log - pl.SetLogInfo(&event, input, "started", "create") + pl.SetLogInfo(&event, input.Sanitize(), "started", "create") err := dg.I.Transaction(func(tx *gorm.DB) error { mwRunner := newMiddlewareRunner(&event, tx) @@ -34,12 +44,57 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } + if err := createOrUpdatePerson(&input, &event, tx); err != nil { + return err + } + + if err := createUser(&input, &event, tx); err != nil { + return err + } + if resData, err := CreateData(input, &event, tx); err != nil { return err } else { data = *resData } + switch input.Position_Code { + case ero.EPCDoc: + createDoc := ed.CreateDto{ + Employee_Id: &data.Id, + IHS_Number: input.IHS_Number, + SIP_Number: input.SIP_Number, + Unit_Id: input.Unit_Id, + } + if _, err := ud.CreateData(createDoc, &event, tx); err != nil { + return err + } + case ero.EPCNur: + createNurse := en.CreateDto{ + Employee_Id: &data.Id, + IHS_Number: input.IHS_Number, + } + if _, err := un.CreateData(createNurse, &event, tx); err != nil { + return err + } + case ero.EPCNut: + createNutritionist := et.CreateDto{ + Employee_Id: &data.Id, + IHS_Number: input.IHS_Number, + } + if _, err := ut.CreateData(createNutritionist, &event, tx); err != nil { + return err + } + case ero.EPCPha: + createPharmacist := ep.CreateDto{ + Employee_Id: &data.Id, + IHS_Number: input.IHS_Number, + } + if _, err := up.CreateData(createPharmacist, &event, tx); err != nil { + return err + } + } + mwRunner.setMwType(pu.MWTPost) // Run post-middleware if err := mwRunner.RunCreateMiddleware(createPostMw, &input, &data); err != nil { @@ -87,6 +142,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/employee/helper.go b/internal/use-case/main-use-case/employee/helper.go index 1660048f..48d658be 100644 --- a/internal/use-case/main-use-case/employee/helper.go +++ b/internal/use-case/main-use-case/employee/helper.go @@ -5,7 +5,17 @@ Any functions that are used internally by the use-case package employee import ( + "errors" e "simrs-vx/internal/domain/main-entities/employee" + ep "simrs-vx/internal/domain/main-entities/person" + "strconv" + + up "simrs-vx/internal/use-case/main-use-case/person" + uu "simrs-vx/internal/use-case/main-use-case/user" + + pl "simrs-vx/pkg/logger" + + "gorm.io/gorm" ) func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Employee) { @@ -24,3 +34,52 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Employee) { data.Number = inputSrc.Number data.Status_Code = inputSrc.Status_Code } + +func createUser(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { + if input.User == nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-create-fail", + Detail: "user request is required", + Raw: errors.New("user request is required"), + } + return pl.SetLogError(event, input) + } + user, err := uu.CreateData(*input.User, event, tx) + if err != nil { + return err + } + input.User_Id = &user.Id + return nil +} + +func createOrUpdatePerson(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { + if input.Person_Id == nil { + person, err := up.CreateData(*input.Person, event, tx) + if err != nil { + return err + } + input.Person_Id = &person.Id + return nil + } + + person, err := up.ReadDetailData(ep.ReadDetailDto{Id: *input.Person_Id}, event, tx) + if err != nil { + return err + } + + if person == nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-notFound", + Detail: "person with ID " + strconv.Itoa(int(*input.Person_Id)) + " not found", + Raw: errors.New("person with ID " + strconv.Itoa(int(*input.Person_Id)) + " not found"), + } + return pl.SetLogError(event, input) + } + + if err := up.UpdateData(ep.UpdateDto{CreateDto: *input.Person}, person, event, tx); err != nil { + return err + } + return nil +} diff --git a/internal/use-case/main-use-case/employee/lib.go b/internal/use-case/main-use-case/employee/lib.go index 261acb56..18dc9d9a 100644 --- a/internal/use-case/main-use-case/employee/lib.go +++ b/internal/use-case/main-use-case/employee/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Em tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Employee{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/infra-group/case.go b/internal/use-case/main-use-case/infra-group/case.go deleted file mode 100644 index 9366114b..00000000 --- a/internal/use-case/main-use-case/infra-group/case.go +++ /dev/null @@ -1,275 +0,0 @@ -package infragroup - -import ( - e "simrs-vx/internal/domain/main-entities/infra-group" - "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 = "infra-group" - -func Create(input e.CreateDto) (*d.Data, error) { - data := e.InfraGroup{} - - 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.InfraGroup - var dataList []e.InfraGroup - 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), - }, - Data: e.ToResponseList(dataList), - }, nil -} - -func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { - var data *e.InfraGroup - 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: uint16(input.Id)} - var data *e.InfraGroup - 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: uint16(input.Id)} - var data *e.InfraGroup - 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/infra-group/helper.go b/internal/use-case/main-use-case/infra-group/helper.go deleted file mode 100644 index 653c0c36..00000000 --- a/internal/use-case/main-use-case/infra-group/helper.go +++ /dev/null @@ -1,22 +0,0 @@ -/* -DESCRIPTION: -Any functions that are used internally by the use-case -*/ -package infragroup - -import ( - e "simrs-vx/internal/domain/main-entities/infra-group" -) - -func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.InfraGroup) { - var inputSrc *e.CreateDto - if inputT, ok := any(input).(*e.CreateDto); ok { - inputSrc = inputT - } else { - inputTemp := any(input).(*e.UpdateDto) - inputSrc = &inputTemp.CreateDto - } - data.Code = inputSrc.Code - data.Name = inputSrc.Name - data.Level = inputSrc.Level -} diff --git a/internal/use-case/main-use-case/infra-group/lib.go b/internal/use-case/main-use-case/infra-group/lib.go deleted file mode 100644 index ba738d71..00000000 --- a/internal/use-case/main-use-case/infra-group/lib.go +++ /dev/null @@ -1,149 +0,0 @@ -package infragroup - -import ( - e "simrs-vx/internal/domain/main-entities/infra-group" - 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.InfraGroup, error) { - pl.SetLogInfo(event, nil, "started", "DBCreate") - - data := e.InfraGroup{} - 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 { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-create-fail", - Detail: "Database insert failed", - Raw: err, - } - return nil, pl.SetLogError(event, input) - } - - pl.SetLogInfo(event, nil, "complete") - return &data, nil -} - -func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.InfraGroup, *e.MetaDto, error) { - pl.SetLogInfo(event, input, "started", "DBReadList") - data := []e.InfraGroup{} - 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.InfraGroup{}). - Scopes(gh.Filter(input)). - Count(&count). - Scopes(gh.Paginate(input, &pagination)). - Order("\"CreatedAt\" DESC") - - if err := tx.Debug().Find(&data).Error; err != nil { - if err == gorm.ErrRecordNotFound { - return nil, &meta, nil - } - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-get-fail", - Detail: "Database get failed", - Raw: err, - } - return nil, nil, pl.SetLogError(event, input) - - } - 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.InfraGroup, error) { - pl.SetLogInfo(event, input, "started", "DBReadDetail") - data := e.InfraGroup{} - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - if err := tx.First(&data, input.Id).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.InfraGroup, 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.InfraGroup, 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/infra-group/middleware-runner.go b/internal/use-case/main-use-case/infra-group/middleware-runner.go deleted file mode 100644 index 50b8fb7a..00000000 --- a/internal/use-case/main-use-case/infra-group/middleware-runner.go +++ /dev/null @@ -1,103 +0,0 @@ -package infragroup - -import ( - e "simrs-vx/internal/domain/main-entities/infra-group" - 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.InfraGroup) 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.InfraGroup) 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.InfraGroup) 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.InfraGroup) 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.InfraGroup) 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/infra-group/middleware.go b/internal/use-case/main-use-case/infra-group/middleware.go deleted file mode 100644 index b811bbe8..00000000 --- a/internal/use-case/main-use-case/infra-group/middleware.go +++ /dev/null @@ -1,9 +0,0 @@ -package infragroup - -// 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/infra-group/tycovar.go b/internal/use-case/main-use-case/infra-group/tycovar.go deleted file mode 100644 index cd5a9925..00000000 --- a/internal/use-case/main-use-case/infra-group/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 infragroup - -import ( - "gorm.io/gorm" - - e "simrs-vx/internal/domain/main-entities/infra-group" -) - -type createMw struct { - Name string - Func func(input *e.CreateDto, data *e.InfraGroup, tx *gorm.DB) error -} - -type readListMw struct { - Name string - Func func(input *e.ReadListDto, data *e.InfraGroup, tx *gorm.DB) error -} - -type readDetailMw struct { - Name string - Func func(input *e.ReadDetailDto, data *e.InfraGroup, 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/infra/case.go b/internal/use-case/main-use-case/infra/case.go index afa0ec6a..e95e09d3 100644 --- a/internal/use-case/main-use-case/infra/case.go +++ b/internal/use-case/main-use-case/infra/case.go @@ -1,12 +1,15 @@ package infra import ( + "errors" e "simrs-vx/internal/domain/main-entities/infra" "strconv" dg "github.com/karincake/apem/db-gorm-pg" d "github.com/karincake/dodol" + ero "simrs-vx/internal/domain/references/organization" + pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" @@ -34,6 +37,21 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } + if input.InfraGroup_Code == ero.IFGCRoom { + if input.Parent_Id == nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-create-fail", + Detail: "parent_id is required", + Raw: errors.New("parent_id is required"), + } + return pl.SetLogError(&event, input) + + } + if err := createItem(&input, &event, tx); err != nil { + return err + } + } if resData, err := CreateData(input, &event, tx); err != nil { return err } else { @@ -87,6 +105,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/infra/helper.go b/internal/use-case/main-use-case/infra/helper.go index 93730033..00057eee 100644 --- a/internal/use-case/main-use-case/infra/helper.go +++ b/internal/use-case/main-use-case/infra/helper.go @@ -6,6 +6,13 @@ package infra import ( e "simrs-vx/internal/domain/main-entities/infra" + ei "simrs-vx/internal/domain/main-entities/item" + 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.Infra) { @@ -23,3 +30,19 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Infra) { data.Parent_Id = inputSrc.Parent_Id data.Item_Id = inputSrc.Item_Id } + +func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { + itemCreate := ei.CreateDto{ + Code: pu.AddPrefix("inf-", input.Code), + Name: input.Name, + ItemGroup_Code: ero.ITGCInfra, + Infra_Id: input.Parent_Id, + } + item, err := ui.CreateData(itemCreate, event, tx) + if err != nil { + return err + } + + input.Item_Id = &item.Id + return nil +} diff --git a/internal/use-case/main-use-case/infra/lib.go b/internal/use-case/main-use-case/infra/lib.go index 23c745db..d4ec76d0 100644 --- a/internal/use-case/main-use-case/infra/lib.go +++ b/internal/use-case/main-use-case/infra/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Infra{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/insurance-company/case.go b/internal/use-case/main-use-case/insurance-company/case.go index fafec031..a981339d 100644 --- a/internal/use-case/main-use-case/insurance-company/case.go +++ b/internal/use-case/main-use-case/insurance-company/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/insurance-company/lib.go b/internal/use-case/main-use-case/insurance-company/lib.go index 06438edb..15073715 100644 --- a/internal/use-case/main-use-case/insurance-company/lib.go +++ b/internal/use-case/main-use-case/insurance-company/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.InsuranceCompany{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/item-group/case.go b/internal/use-case/main-use-case/item-group/case.go deleted file mode 100644 index 91cd05c7..00000000 --- a/internal/use-case/main-use-case/item-group/case.go +++ /dev/null @@ -1,275 +0,0 @@ -package itemgroup - -import ( - e "simrs-vx/internal/domain/main-entities/item-group" - "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 = "item-group" - -func Create(input e.CreateDto) (*d.Data, error) { - data := e.ItemGroup{} - - 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.ItemGroup - var dataList []e.ItemGroup - 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), - }, - Data: e.ToResponseList(dataList), - }, nil -} - -func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { - var data *e.ItemGroup - 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: uint16(input.Id)} - var data *e.ItemGroup - 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: uint16(input.Id)} - var data *e.ItemGroup - 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/item-group/helper.go b/internal/use-case/main-use-case/item-group/helper.go deleted file mode 100644 index 98af4a89..00000000 --- a/internal/use-case/main-use-case/item-group/helper.go +++ /dev/null @@ -1,22 +0,0 @@ -/* -DESCRIPTION: -Any functions that are used internally by the use-case -*/ -package itemgroup - -import ( - e "simrs-vx/internal/domain/main-entities/item-group" -) - -func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ItemGroup) { - var inputSrc *e.CreateDto - if inputT, ok := any(input).(*e.CreateDto); ok { - inputSrc = inputT - } else { - inputTemp := any(input).(*e.UpdateDto) - inputSrc = &inputTemp.CreateDto - } - - data.Code = inputSrc.Code - data.Name = inputSrc.Name -} diff --git a/internal/use-case/main-use-case/item-group/lib.go b/internal/use-case/main-use-case/item-group/lib.go deleted file mode 100644 index 9e86970a..00000000 --- a/internal/use-case/main-use-case/item-group/lib.go +++ /dev/null @@ -1,149 +0,0 @@ -package itemgroup - -import ( - e "simrs-vx/internal/domain/main-entities/item-group" - 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.ItemGroup, error) { - pl.SetLogInfo(event, nil, "started", "DBCreate") - - data := e.ItemGroup{} - 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 { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-create-fail", - Detail: "Database insert failed", - Raw: err, - } - return nil, pl.SetLogError(event, input) - } - - pl.SetLogInfo(event, nil, "complete") - return &data, nil -} - -func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.ItemGroup, *e.MetaDto, error) { - pl.SetLogInfo(event, input, "started", "DBReadList") - data := []e.ItemGroup{} - 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.ItemGroup{}). - Scopes(gh.Filter(input)). - Count(&count). - Scopes(gh.Paginate(input, &pagination)). - Order("\"CreatedAt\" DESC") - - if err := tx.Debug().Find(&data).Error; err != nil { - if err == gorm.ErrRecordNotFound { - return nil, &meta, nil - } - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-get-fail", - Detail: "Database get failed", - Raw: err, - } - return nil, nil, pl.SetLogError(event, input) - - } - 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.ItemGroup, error) { - pl.SetLogInfo(event, input, "started", "DBReadDetail") - data := e.ItemGroup{} - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - if err := tx.First(&data, input.Id).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.ItemGroup, 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.ItemGroup, 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/item-group/middleware-runner.go b/internal/use-case/main-use-case/item-group/middleware-runner.go deleted file mode 100644 index 0fa678be..00000000 --- a/internal/use-case/main-use-case/item-group/middleware-runner.go +++ /dev/null @@ -1,103 +0,0 @@ -package itemgroup - -import ( - e "simrs-vx/internal/domain/main-entities/item-group" - 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.ItemGroup) 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.ItemGroup) 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.ItemGroup) 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.ItemGroup) 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.ItemGroup) 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/item-group/middleware.go b/internal/use-case/main-use-case/item-group/middleware.go deleted file mode 100644 index ab8a3227..00000000 --- a/internal/use-case/main-use-case/item-group/middleware.go +++ /dev/null @@ -1,9 +0,0 @@ -package itemgroup - -// 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/item-group/tycovar.go b/internal/use-case/main-use-case/item-group/tycovar.go deleted file mode 100644 index 17ad5bc0..00000000 --- a/internal/use-case/main-use-case/item-group/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 itemgroup - -import ( - "gorm.io/gorm" - - e "simrs-vx/internal/domain/main-entities/item-group" -) - -type createMw struct { - Name string - Func func(input *e.CreateDto, data *e.ItemGroup, tx *gorm.DB) error -} - -type readListMw struct { - Name string - Func func(input *e.ReadListDto, data *e.ItemGroup, tx *gorm.DB) error -} - -type readDetailMw struct { - Name string - Func func(input *e.ReadDetailDto, data *e.ItemGroup, 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/item-price/case.go b/internal/use-case/main-use-case/item-price/case.go index 6566f6e8..a40f9142 100644 --- a/internal/use-case/main-use-case/item-price/case.go +++ b/internal/use-case/main-use-case/item-price/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/item-price/lib.go b/internal/use-case/main-use-case/item-price/lib.go index 924752f0..8d61f2f8 100644 --- a/internal/use-case/main-use-case/item-price/lib.go +++ b/internal/use-case/main-use-case/item-price/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.It tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.ItemPrice{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/item/case.go b/internal/use-case/main-use-case/item/case.go index 77ca4d89..67027fa8 100644 --- a/internal/use-case/main-use-case/item/case.go +++ b/internal/use-case/main-use-case/item/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/item/lib.go b/internal/use-case/main-use-case/item/lib.go index a65f2da9..b62e1c3a 100644 --- a/internal/use-case/main-use-case/item/lib.go +++ b/internal/use-case/main-use-case/item/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.It tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Item{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/material/case.go b/internal/use-case/main-use-case/material/case.go index f855f044..87b8be9c 100644 --- a/internal/use-case/main-use-case/material/case.go +++ b/internal/use-case/main-use-case/material/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 { @@ -87,6 +90,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/material/helper.go b/internal/use-case/main-use-case/material/helper.go index 11b4900c..ce0d8a2e 100644 --- a/internal/use-case/main-use-case/material/helper.go +++ b/internal/use-case/main-use-case/material/helper.go @@ -5,7 +5,16 @@ Any functions that are used internally by the use-case package material import ( + ei "simrs-vx/internal/domain/main-entities/item" e "simrs-vx/internal/domain/main-entities/material" + + ui "simrs-vx/internal/use-case/main-use-case/item" + + ero "simrs-vx/internal/domain/references/organization" + 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.Material) { @@ -23,3 +32,21 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Material) { data.Stock = inputSrc.Stock data.Item_Id = inputSrc.Item_Id } + +func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { + itemCreate := ei.CreateDto{ + Code: pu.AddPrefix("mat-", input.Code), + Name: input.Name, + ItemGroup_Code: ero.ITGCMaterial, + Uom_Code: &input.Uom_Code, + Infra_Id: input.Infra_Id, + Stock: input.Stock, + } + item, err := ui.CreateData(itemCreate, event, tx) + if err != nil { + return err + } + + input.Item_Id = &item.Id + return nil +} diff --git a/internal/use-case/main-use-case/material/lib.go b/internal/use-case/main-use-case/material/lib.go index ab114241..f1a3f40b 100644 --- a/internal/use-case/main-use-case/material/lib.go +++ b/internal/use-case/main-use-case/material/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Ma tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Material{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/mcu-src/case.go b/internal/use-case/main-use-case/mcu-src/case.go index 3dc69a7c..ae7a1860 100644 --- a/internal/use-case/main-use-case/mcu-src/case.go +++ b/internal/use-case/main-use-case/mcu-src/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/mcu-src/lib.go b/internal/use-case/main-use-case/mcu-src/lib.go index 023d334e..e7e76041 100644 --- a/internal/use-case/main-use-case/mcu-src/lib.go +++ b/internal/use-case/main-use-case/mcu-src/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Mc tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.McuSrc{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/medical-action-src-item/case.go b/internal/use-case/main-use-case/medical-action-src-item/case.go index e811714d..2efdca2c 100644 --- a/internal/use-case/main-use-case/medical-action-src-item/case.go +++ b/internal/use-case/main-use-case/medical-action-src-item/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/medical-action-src-item/lib.go b/internal/use-case/main-use-case/medical-action-src-item/lib.go index f294c118..02d81f6c 100644 --- a/internal/use-case/main-use-case/medical-action-src-item/lib.go +++ b/internal/use-case/main-use-case/medical-action-src-item/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.MedicalActionSrcItem{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") 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 0b22aa7e..1c0fe565 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 @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/medical-action-src/lib.go b/internal/use-case/main-use-case/medical-action-src/lib.go index b0cdbdc0..5bef2fca 100644 --- a/internal/use-case/main-use-case/medical-action-src/lib.go +++ b/internal/use-case/main-use-case/medical-action-src/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.MedicalActionSrc{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/medicine-mix-item/case.go b/internal/use-case/main-use-case/medicine-mix-item/case.go index 1b6dfc6e..42145947 100644 --- a/internal/use-case/main-use-case/medicine-mix-item/case.go +++ b/internal/use-case/main-use-case/medicine-mix-item/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/medicine-mix-item/lib.go b/internal/use-case/main-use-case/medicine-mix-item/lib.go index 739c6a7a..3bea8e9c 100644 --- a/internal/use-case/main-use-case/medicine-mix-item/lib.go +++ b/internal/use-case/main-use-case/medicine-mix-item/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.MedicineMixItem{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/medicine/case.go b/internal/use-case/main-use-case/medicine/case.go index 3775751e..aa970478 100644 --- a/internal/use-case/main-use-case/medicine/case.go +++ b/internal/use-case/main-use-case/medicine/case.go @@ -34,7 +34,7 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } - if err := createItemWithDefaultPrice(&input, &event, tx); err != nil { + if err := createItem(&input, &event, tx); err != nil { return err } if resData, err := CreateData(input, &event, tx); err != nil { @@ -90,6 +90,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/medicine/helper.go b/internal/use-case/main-use-case/medicine/helper.go index 1414b966..388be819 100644 --- a/internal/use-case/main-use-case/medicine/helper.go +++ b/internal/use-case/main-use-case/medicine/helper.go @@ -6,11 +6,11 @@ package medicine import ( ei "simrs-vx/internal/domain/main-entities/item" - eip "simrs-vx/internal/domain/main-entities/item-price" e "simrs-vx/internal/domain/main-entities/medicine" ui "simrs-vx/internal/use-case/main-use-case/item" - uip "simrs-vx/internal/use-case/main-use-case/item-price" + + ero "simrs-vx/internal/domain/references/organization" pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" @@ -39,11 +39,10 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Medicine) { } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { - igcMed := "Medicine" itemCreate := ei.CreateDto{ Code: pu.AddPrefix("med-", input.Code), Name: input.Name, - ItemGroup_Code: &igcMed, + ItemGroup_Code: ero.ITGCMedicine, Uom_Code: input.Uom_Code, Infra_Id: input.Infra_Id, Stock: input.Stock, @@ -56,25 +55,3 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { input.Item_Id = &item.Id return nil } - -func createItemPrice(input *e.CreateDto, event *pl.Event, tx *gorm.DB, item_id *uint) error { - itemPriceCreate := eip.CreateDto{ - Item_Id: item_id, - Price: 0, - InsuranceCompany_Code: input.InsuranceCompany_Code, - } - _, err := uip.CreateData(itemPriceCreate, event, tx) - return err -} - -func createItemWithDefaultPrice(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { - if err := createItem(input, event, tx); err != nil { - return err - } - - if err := createItemPrice(input, event, tx, input.Item_Id); err != nil { - return err - } - - return nil -} diff --git a/internal/use-case/main-use-case/medicine/lib.go b/internal/use-case/main-use-case/medicine/lib.go index a66e7cd0..c7295e10 100644 --- a/internal/use-case/main-use-case/medicine/lib.go +++ b/internal/use-case/main-use-case/medicine/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Me tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Medicine{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/nurse/case.go b/internal/use-case/main-use-case/nurse/case.go index 9bb32296..509be4dd 100644 --- a/internal/use-case/main-use-case/nurse/case.go +++ b/internal/use-case/main-use-case/nurse/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/nurse/lib.go b/internal/use-case/main-use-case/nurse/lib.go index 263888e7..c0ffdbb8 100644 --- a/internal/use-case/main-use-case/nurse/lib.go +++ b/internal/use-case/main-use-case/nurse/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Nu tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Nurse{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/nutritionist/case.go b/internal/use-case/main-use-case/nutritionist/case.go index b7cad178..f584f005 100644 --- a/internal/use-case/main-use-case/nutritionist/case.go +++ b/internal/use-case/main-use-case/nutritionist/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/nutritionist/lib.go b/internal/use-case/main-use-case/nutritionist/lib.go index 263c4231..abe77aa4 100644 --- a/internal/use-case/main-use-case/nutritionist/lib.go +++ b/internal/use-case/main-use-case/nutritionist/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Nu tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Nutritionist{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/person/case.go b/internal/use-case/main-use-case/person/case.go index a372c34a..e0395bd9 100644 --- a/internal/use-case/main-use-case/person/case.go +++ b/internal/use-case/main-use-case/person/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/person/helper.go b/internal/use-case/main-use-case/person/helper.go index 32b4ff42..f4408ab2 100644 --- a/internal/use-case/main-use-case/person/helper.go +++ b/internal/use-case/main-use-case/person/helper.go @@ -18,6 +18,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Person) { } data.Name = inputSrc.Name + data.FrontTitle = inputSrc.FrontTitle + data.EndTitle = inputSrc.EndTitle data.BirthDate = inputSrc.BirthDate data.BirthRegency_Code = inputSrc.BirthRegency_Code data.Gender_Code = inputSrc.Gender_Code diff --git a/internal/use-case/main-use-case/person/lib.go b/internal/use-case/main-use-case/person/lib.go index 430e8b69..e704bfbb 100644 --- a/internal/use-case/main-use-case/person/lib.go +++ b/internal/use-case/main-use-case/person/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Pe tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Person{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/pharmacist/case.go b/internal/use-case/main-use-case/pharmacist/case.go index a2e7aecc..cdc8503f 100644 --- a/internal/use-case/main-use-case/pharmacist/case.go +++ b/internal/use-case/main-use-case/pharmacist/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/pharmacist/lib.go b/internal/use-case/main-use-case/pharmacist/lib.go index 18d41f26..cc22a87f 100644 --- a/internal/use-case/main-use-case/pharmacist/lib.go +++ b/internal/use-case/main-use-case/pharmacist/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Ph tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Pharmacist{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/practice-schedule/case.go b/internal/use-case/main-use-case/practice-schedule/case.go index 82ef0c8b..223d97ec 100644 --- a/internal/use-case/main-use-case/practice-schedule/case.go +++ b/internal/use-case/main-use-case/practice-schedule/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/practice-schedule/lib.go b/internal/use-case/main-use-case/practice-schedule/lib.go index a926e984..1d5e34ac 100644 --- a/internal/use-case/main-use-case/practice-schedule/lib.go +++ b/internal/use-case/main-use-case/practice-schedule/lib.go @@ -51,9 +51,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Pr tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.PracticeSchedule{}). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/unit/case.go b/internal/use-case/main-use-case/unit/case.go index 0ab8cdcb..beb91f7b 100644 --- a/internal/use-case/main-use-case/unit/case.go +++ b/internal/use-case/main-use-case/unit/case.go @@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) { return err } + if len(input.Includes) > 0 { + input.Preloads = pu.GetPreloads(input.Includes) + } if dataList, metaList, err = ReadListData(input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/unit/lib.go b/internal/use-case/main-use-case/unit/lib.go index d7aebcaf..f43530dc 100644 --- a/internal/use-case/main-use-case/unit/lib.go +++ b/internal/use-case/main-use-case/unit/lib.go @@ -51,10 +51,16 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Un tx = dg.I } + if len(input.Preloads) > 0 { + for _, preload := range input.Preloads { + tx = tx.Preload(preload) + } + } + tx = tx. Model(&e.Unit{}). Preload("Installation"). - Scopes(gh.Filter(input)). + Scopes(gh.Filter(input.FilterDto)). Count(&count). Scopes(gh.Paginate(input, &pagination)). Order("\"CreatedAt\" DESC") diff --git a/internal/use-case/main-use-case/user/case.go b/internal/use-case/main-use-case/user/case.go index fd252bac..c4f55985 100644 --- a/internal/use-case/main-use-case/user/case.go +++ b/internal/use-case/main-use-case/user/case.go @@ -297,7 +297,7 @@ func Block(input e.ReadDetailDto) (*d.Data, error) { if data != nil { pl.SetLogInfo(&event, rdDto, "started", "DBUpdate") - data.Status_Code = erc.SCBlocked + data.Status_Code = erc.USCBlocked if err := tx.Save(&data).Error; err != nil { return err } @@ -343,7 +343,7 @@ func Active(input e.ReadDetailDto) (*d.Data, error) { if data != nil { pl.SetLogInfo(&event, rdDto, "started", "DBUpdate") - data.Status_Code = erc.SCActive + data.Status_Code = erc.USCActive if err := tx.Save(&data).Error; err != nil { return err } diff --git a/pkg/use-case-helper/use-case-helper.go b/pkg/use-case-helper/use-case-helper.go index fadfa373..beb369c1 100644 --- a/pkg/use-case-helper/use-case-helper.go +++ b/pkg/use-case-helper/use-case-helper.go @@ -80,3 +80,24 @@ func HandleMiddlewareError(event *pl.Event, mwType, mwName string, logData inter func AddPrefix(prefix string, str string) string { return prefix + str } + +func GetPreloads(input string) []string { + result := []string{} + parts := strings.Split(input, ",") + for _, p := range parts { + result = append(result, kebabToPascal(p)) + } + return result +} + +func kebabToPascal(input string) string { + parts := strings.Split(input, "-") + for i, p := range parts { + if len(p) > 0 { + r := []rune(p) + r[0] = []rune(strings.ToUpper(string(r[0])))[0] + parts[i] = string(r) + } + } + return strings.Join(parts, "") +}