diff --git a/cmd/main-migration/migration.go b/cmd/main-migration/migration.go index c0c1283c..dd28a55f 100644 --- a/cmd/main-migration/migration.go +++ b/cmd/main-migration/migration.go @@ -1,9 +1,9 @@ -package main - -import ( - m "simrs-vx/internal/interface/migration" -) - -func main() { - m.Migrate(m.Main) -} +package main + +import ( + m "simrs-vx/internal/interface/migration" +) + +func main() { + m.Migrate(m.Main) +} diff --git a/cmd/main-migration/migrations/20251110012217.sql b/cmd/main-migration/migrations/20251110012217.sql new file mode 100644 index 00000000..dd292709 --- /dev/null +++ b/cmd/main-migration/migrations/20251110012217.sql @@ -0,0 +1,6 @@ +-- Modify "Ambulatory" table +ALTER TABLE "public"."Ambulatory" DROP COLUMN "VisitMode_Code"; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" ADD COLUMN "Status_Code" text NULL; +-- Modify "Rehab" table +ALTER TABLE "public"."Rehab" ADD COLUMN "Parent_Encounter_Id" bigint NULL, ADD COLUMN "ExpiredAt" timestamptz NULL, ADD COLUMN "VisitMode_Code" text NULL, ADD COLUMN "Status_Code" text NULL; diff --git a/cmd/main-migration/migrations/20251110012306.sql b/cmd/main-migration/migrations/20251110012306.sql new file mode 100644 index 00000000..45e5f4e4 --- /dev/null +++ b/cmd/main-migration/migrations/20251110012306.sql @@ -0,0 +1,2 @@ +-- Modify "Rehab" table +ALTER TABLE "public"."Rehab" DROP COLUMN "Doctor_Id"; diff --git a/cmd/main-migration/migrations/20251110052049.sql b/cmd/main-migration/migrations/20251110052049.sql new file mode 100644 index 00000000..4a1d74d7 --- /dev/null +++ b/cmd/main-migration/migrations/20251110052049.sql @@ -0,0 +1,14 @@ +-- Modify "Consultation" table +ALTER TABLE "public"."Consultation" ADD COLUMN "DstUnit_Code" text NULL, ADD COLUMN "DstDoctor_Code" text NULL; +-- Modify "ControlLetter" table +ALTER TABLE "public"."ControlLetter" ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "Specialist_Code" text NULL, ADD COLUMN "Subspecialist_Code" text NULL, ADD COLUMN "Doctor_Code" text NULL; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "Specialist_Code" text NULL, ADD COLUMN "Subspecialist_Code" text NULL, ADD COLUMN "Appointment_Doctor_Code" text NULL, ADD COLUMN "Responsible_Doctor_Code" text NULL; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "Doctor_Code" text NULL; +-- Modify "PracticeSchedule" table +ALTER TABLE "public"."PracticeSchedule" ADD COLUMN "Doctor_Code" text NULL; +-- Modify "ResponsibleDoctorHist" table +ALTER TABLE "public"."ResponsibleDoctorHist" ADD COLUMN "Doctor_Code" text NULL; +-- Modify "TherapyProtocol" table +ALTER TABLE "public"."TherapyProtocol" ADD COLUMN "Doctor_Code" text NULL; diff --git a/cmd/main-migration/migrations/20251110062042.sql b/cmd/main-migration/migrations/20251110062042.sql new file mode 100644 index 00000000..9ec62cf7 --- /dev/null +++ b/cmd/main-migration/migrations/20251110062042.sql @@ -0,0 +1,14 @@ +-- Modify "Consultation" table +ALTER TABLE "public"."Consultation" DROP CONSTRAINT "fk_Consultation_DstDoctor", DROP CONSTRAINT "fk_Consultation_DstUnit", DROP COLUMN "DstUnit_Id", DROP COLUMN "DstDoctor_Id", ALTER COLUMN "DstUnit_Code" TYPE character varying(10), ALTER COLUMN "DstDoctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_Consultation_DstDoctor" FOREIGN KEY ("DstDoctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Consultation_DstUnit" FOREIGN KEY ("DstUnit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ControlLetter" table +ALTER TABLE "public"."ControlLetter" DROP CONSTRAINT "fk_ControlLetter_Doctor", DROP CONSTRAINT "fk_ControlLetter_Specialist", DROP CONSTRAINT "fk_ControlLetter_Subspecialist", DROP CONSTRAINT "fk_ControlLetter_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", DROP COLUMN "Doctor_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "Specialist_Code" TYPE character varying(10), ALTER COLUMN "Subspecialist_Code" TYPE character varying(10), ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_ControlLetter_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" DROP CONSTRAINT "fk_Encounter_Appointment_Doctor", DROP CONSTRAINT "fk_Encounter_Responsible_Doctor", DROP CONSTRAINT "fk_Encounter_Specialist", DROP CONSTRAINT "fk_Encounter_Subspecialist", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", DROP COLUMN "Responsible_Doctor_Id", DROP COLUMN "Appointment_Doctor_Id", ALTER COLUMN "Specialist_Code" TYPE character varying(10), ALTER COLUMN "Subspecialist_Code" TYPE character varying(10), ALTER COLUMN "Appointment_Doctor_Code" TYPE character varying(20), ALTER COLUMN "Responsible_Doctor_Code" TYPE character varying(20), ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "InsuranceCompany_Code" text NULL, ADD CONSTRAINT "fk_Encounter_Appointment_Doctor" FOREIGN KEY ("Appointment_Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Responsible_Doctor" FOREIGN KEY ("Responsible_Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" DROP CONSTRAINT "fk_InternalReference_Doctor", DROP CONSTRAINT "fk_InternalReference_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Doctor_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_InternalReference_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_InternalReference_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "PracticeSchedule" table +ALTER TABLE "public"."PracticeSchedule" DROP CONSTRAINT "fk_PracticeSchedule_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_PracticeSchedule_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ResponsibleDoctorHist" table +ALTER TABLE "public"."ResponsibleDoctorHist" DROP CONSTRAINT "fk_ResponsibleDoctorHist_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_ResponsibleDoctorHist_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "TherapyProtocol" table +ALTER TABLE "public"."TherapyProtocol" DROP CONSTRAINT "fk_TherapyProtocol_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_TherapyProtocol_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251110063202.sql b/cmd/main-migration/migrations/20251110063202.sql new file mode 100644 index 00000000..90c55b4d --- /dev/null +++ b/cmd/main-migration/migrations/20251110063202.sql @@ -0,0 +1,4 @@ +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" ADD COLUMN "SrcUnit_Code" text NULL; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" DROP CONSTRAINT "fk_Encounter_InsuranceCompany", DROP CONSTRAINT "fk_Encounter_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "InsuranceCompany_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "InsuranceCompany_Code" TYPE character varying(20), ADD CONSTRAINT "fk_Encounter_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Code") REFERENCES "public"."InsuranceCompany" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251110063633.sql b/cmd/main-migration/migrations/20251110063633.sql new file mode 100644 index 00000000..de41516f --- /dev/null +++ b/cmd/main-migration/migrations/20251110063633.sql @@ -0,0 +1,2 @@ +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" DROP CONSTRAINT "fk_Chemo_SrcUnit", DROP COLUMN "SrcUnit_Id", ALTER COLUMN "SrcUnit_Code" TYPE character varying(10), ADD CONSTRAINT "fk_Chemo_SrcUnit" FOREIGN KEY ("SrcUnit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251110085551.sql b/cmd/main-migration/migrations/20251110085551.sql new file mode 100644 index 00000000..8cdcbc3b --- /dev/null +++ b/cmd/main-migration/migrations/20251110085551.sql @@ -0,0 +1,8 @@ +-- Modify "DeviceOrder" table +ALTER TABLE "public"."DeviceOrder" ADD COLUMN "Doctor_Code" text NULL; +-- Modify "Inpatient" table +ALTER TABLE "public"."Inpatient" ADD COLUMN "Infra_Code" character varying(10) NULL; +-- Modify "MaterialOrder" table +ALTER TABLE "public"."MaterialOrder" ADD COLUMN "Doctor_Code" text NULL; +-- Modify "McuOrder" table +ALTER TABLE "public"."McuOrder" ADD COLUMN "Doctor_Code" text NULL; diff --git a/cmd/main-migration/migrations/20251110091516.sql b/cmd/main-migration/migrations/20251110091516.sql new file mode 100644 index 00000000..10010abb --- /dev/null +++ b/cmd/main-migration/migrations/20251110091516.sql @@ -0,0 +1,8 @@ +-- Modify "DeviceOrder" table +ALTER TABLE "public"."DeviceOrder" DROP CONSTRAINT "fk_DeviceOrder_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_DeviceOrder_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Inpatient" table +ALTER TABLE "public"."Inpatient" DROP CONSTRAINT "fk_Inpatient_Infra", DROP COLUMN "Infra_Id", ADD CONSTRAINT "fk_Inpatient_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MaterialOrder" table +ALTER TABLE "public"."MaterialOrder" DROP CONSTRAINT "fk_MaterialOrder_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_MaterialOrder_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "McuOrder" table +ALTER TABLE "public"."McuOrder" DROP CONSTRAINT "fk_McuOrder_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_McuOrder_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251110091948.sql b/cmd/main-migration/migrations/20251110091948.sql new file mode 100644 index 00000000..452f56ad --- /dev/null +++ b/cmd/main-migration/migrations/20251110091948.sql @@ -0,0 +1,4 @@ +-- Modify "DeviceOrderItem" table +ALTER TABLE "public"."DeviceOrderItem" ADD COLUMN "Device_Code" text NULL; +-- Modify "MaterialOrderItem" table +ALTER TABLE "public"."MaterialOrderItem" ADD COLUMN "Material_Code" text NULL; diff --git a/cmd/main-migration/migrations/20251110092729.sql b/cmd/main-migration/migrations/20251110092729.sql new file mode 100644 index 00000000..7f4702ab --- /dev/null +++ b/cmd/main-migration/migrations/20251110092729.sql @@ -0,0 +1,4 @@ +-- Modify "DeviceOrderItem" table +ALTER TABLE "public"."DeviceOrderItem" DROP CONSTRAINT "fk_DeviceOrderItem_Device", DROP COLUMN "Device_Id", ALTER COLUMN "Device_Code" TYPE character varying(10), ADD CONSTRAINT "fk_DeviceOrderItem_Device" FOREIGN KEY ("Device_Code") REFERENCES "public"."Device" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MaterialOrderItem" table +ALTER TABLE "public"."MaterialOrderItem" DROP CONSTRAINT "fk_MaterialOrderItem_Material", DROP COLUMN "Material_Id", ALTER COLUMN "Material_Code" TYPE character varying(10), ADD CONSTRAINT "fk_MaterialOrderItem_Material" FOREIGN KEY ("Material_Code") REFERENCES "public"."Material" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251110093522.sql b/cmd/main-migration/migrations/20251110093522.sql new file mode 100644 index 00000000..8ed5f757 --- /dev/null +++ b/cmd/main-migration/migrations/20251110093522.sql @@ -0,0 +1,8 @@ +-- Modify "McuSrc" table +ALTER TABLE "public"."McuSrc" ALTER COLUMN "Code" SET NOT NULL, ADD COLUMN "Item_Code" text NULL; +-- Modify "McuSubSrc" table +ALTER TABLE "public"."McuSubSrc" ADD COLUMN "McuSrc_Code" text NULL; +-- Modify "MedicalActionSrc" table +ALTER TABLE "public"."MedicalActionSrc" ADD COLUMN "Item_Code" text NULL; +-- Modify "MedicalActionSrcItem" table +ALTER TABLE "public"."MedicalActionSrcItem" ADD COLUMN "MedicalActionSrc_Code" text NULL, ADD COLUMN "ProcedureSrc_Code" text NULL, ADD COLUMN "Item_Code" text NULL; diff --git a/cmd/main-migration/migrations/20251110100258.sql b/cmd/main-migration/migrations/20251110100258.sql new file mode 100644 index 00000000..9d902938 --- /dev/null +++ b/cmd/main-migration/migrations/20251110100258.sql @@ -0,0 +1,8 @@ +-- Modify "McuSrc" table +ALTER TABLE "public"."McuSrc" DROP CONSTRAINT "fk_McuSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_McuSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "McuSubSrc" table +ALTER TABLE "public"."McuSubSrc" DROP CONSTRAINT "fk_McuSubSrc_McuSrc", DROP COLUMN "McuSrc_Id", ALTER COLUMN "McuSrc_Code" TYPE character varying(20), ADD COLUMN "Item_Code" text NULL, ADD CONSTRAINT "fk_McuSubSrc_McuSrc" FOREIGN KEY ("McuSrc_Code") REFERENCES "public"."McuSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MedicalActionSrc" table +ALTER TABLE "public"."MedicalActionSrc" DROP CONSTRAINT "fk_MedicalActionSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_MedicalActionSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MedicalActionSrcItem" table +ALTER TABLE "public"."MedicalActionSrcItem" DROP CONSTRAINT "fk_MedicalActionSrcItem_Item", DROP CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc", DROP CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc", DROP COLUMN "MedicalActionSrc_Id", DROP COLUMN "ProcedureSrc_Id", DROP COLUMN "Item_Id", ALTER COLUMN "MedicalActionSrc_Code" TYPE character varying(20), ALTER COLUMN "ProcedureSrc_Code" TYPE character varying(10), ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_MedicalActionSrcItem_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc" FOREIGN KEY ("MedicalActionSrc_Code") REFERENCES "public"."MedicalActionSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc" FOREIGN KEY ("ProcedureSrc_Code") REFERENCES "public"."ProcedureSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251110100545.sql b/cmd/main-migration/migrations/20251110100545.sql new file mode 100644 index 00000000..3fdc6a82 --- /dev/null +++ b/cmd/main-migration/migrations/20251110100545.sql @@ -0,0 +1,2 @@ +-- Modify "McuSubSrc" table +ALTER TABLE "public"."McuSubSrc" DROP CONSTRAINT "fk_McuSubSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_McuSubSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 0da32e52..293ca91a 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:69CxJYTc7MIeFR2nLQwjoba/TUnw7lIzVApYkI34yss= +h1:EhWXa9CRUdCX5FiHAOEgknGsAmS+hlumbeo45IiWbbs= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -95,3 +95,16 @@ h1:69CxJYTc7MIeFR2nLQwjoba/TUnw7lIzVApYkI34yss= 20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= 20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= 20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= +20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= +20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= +20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= +20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= +20251110063202.sql h1:A117DuZmZ6U0jWHA3DISnr+yvBjKIr1ObrUr047YezQ= +20251110063633.sql h1:qTiC0F19JnhUIXF4LGJQ21jEV6kKGyhTr1x2kimFqPQ= +20251110085551.sql h1:HZcJM0RSC6HBaUSjKBE8MgDG8Vn9f3LmwA/OnT9Cp7I= +20251110091516.sql h1:W3AQhQLgirEWuCObbLl+Prdrbq6k6EEY1xcoWsmbog4= +20251110091948.sql h1:3tsITMrZr/T+L4wqUMz8sHS229jCJl4T0Nu3dMccxH8= +20251110092729.sql h1:uU+k88RH/e0Ns4/SmJl03RVYPscBAPuiLfxR6CJqaf0= +20251110093522.sql h1:O7upSj8VNjzvroL4IU59bfxKATOkAVGBArcUbVNq9aM= +20251110100258.sql h1://JSArUMNI3/gAtYDx2VN94C198SFW0ANjgs+p6eCRM= +20251110100545.sql h1:ENPOqeJYRpMI4e8VCKwaQgaql8se6pIidAhG2cjskBg= diff --git a/internal/domain/main-entities/ambulatory/dto.go b/internal/domain/main-entities/ambulatory/dto.go index f580467a..ec34f37f 100644 --- a/internal/domain/main-entities/ambulatory/dto.go +++ b/internal/domain/main-entities/ambulatory/dto.go @@ -6,9 +6,8 @@ import ( ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"` - VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` + Encounter_Id *uint `json:"encounter_id"` + Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"` } type ReadListDto struct { @@ -50,9 +49,8 @@ type ResponseDto struct { func (d Ambulatory) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Class_Code: d.Class_Code, - VisitMode_Code: d.VisitMode_Code, + Encounter_Id: d.Encounter_Id, + Class_Code: d.Class_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/ambulatory/entity.go b/internal/domain/main-entities/ambulatory/entity.go index ecf9915e..06754385 100644 --- a/internal/domain/main-entities/ambulatory/entity.go +++ b/internal/domain/main-entities/ambulatory/entity.go @@ -6,8 +6,7 @@ import ( ) type Ambulatory struct { - ecore.Main // adjust this according to the needs - Encounter_Id *uint `json:"encounter_id"` - Class_Code ere.AmbulatoryClassCode `json:"class_code" gorm:"size:10"` - VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` + ecore.Main // adjust this according to the needs + Encounter_Id *uint `json:"encounter_id"` + Class_Code ere.AmbulatoryClassCode `json:"class_code" gorm:"size:10"` } diff --git a/internal/domain/main-entities/chemo/dto.go b/internal/domain/main-entities/chemo/dto.go index 653b5409..5d8b9501 100644 --- a/internal/domain/main-entities/chemo/dto.go +++ b/internal/domain/main-entities/chemo/dto.go @@ -20,7 +20,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Status_Code erc.DataVerifiedCode `json:"status_code"` - SrcUnit_Id *uint `json:"srcUnit_id"` + SrcUnit_Code *string `json:"srcUnit_code"` } type ReadListDto struct { @@ -33,7 +33,7 @@ type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` Status_Code *erc.DataVerifiedCode `json:"status-code"` VerifiedBy_User_Id *uint `json:"verifiedBy-user-id"` - SrcUnit_Id *uint `json:"srcUnit-id"` + SrcUnit_Code *string `json:"srcUnit-code"` } type ReadDetailDto struct { @@ -72,7 +72,7 @@ type ResponseDto struct { VerifiedAt *time.Time `json:"verifiedAt"` VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty"` - SrcUnit_Id *uint `json:"srcUnit_id"` + SrcUnit_Code *string `json:"srcUnit_code"` SrcUnit *eun.Unit `json:"srcUnit,omitempty"` } @@ -84,7 +84,7 @@ func (d Chemo) ToResponse() ResponseDto { VerifiedAt: d.VerifiedAt, VerifiedBy_User_Id: d.VerifiedBy_User_Id, VerifiedBy: d.VerifiedBy, - SrcUnit_Id: d.SrcUnit_Id, + SrcUnit_Code: d.SrcUnit_Code, SrcUnit: d.SrcUnit, } resp.Main = d.Main diff --git a/internal/domain/main-entities/chemo/entity.go b/internal/domain/main-entities/chemo/entity.go index a56dae76..6f5180aa 100644 --- a/internal/domain/main-entities/chemo/entity.go +++ b/internal/domain/main-entities/chemo/entity.go @@ -19,8 +19,8 @@ type Chemo struct { VerifiedAt *time.Time `json:"verifiedAt"` VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty" gorm:"foreignKey:VerifiedBy_User_Id;references:Id"` - SrcUnit_Id *uint `json:"src_unit_id"` - SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Id;references:Id"` + SrcUnit_Code *string `json:"src_unit_code"` + SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Code;references:Code"` Bed *string `json:"bed" gorm:"size:1024"` Needs *string `json:"needs" gorm:"size:2048"` } diff --git a/internal/domain/main-entities/consultation/dto.go b/internal/domain/main-entities/consultation/dto.go index 33868dd0..1b83df77 100644 --- a/internal/domain/main-entities/consultation/dto.go +++ b/internal/domain/main-entities/consultation/dto.go @@ -20,7 +20,7 @@ type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Date *time.Time `json:"date"` Problem *string `json:"problem" validate:"maxLength=10240"` - DstUnit_Id *uint `json:"dstUnit_id"` + DstUnit_Code *string `json:"dstUnit_code"` } type ReadListDto struct { @@ -30,9 +30,9 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - DstUnit_Id *uint `json:"dstUnit-id"` - DstDoctor_Id *uint `json:"dstDoctor-id"` + Encounter_Id *uint `json:"encounter-id"` + DstUnit_Code *string `json:"dstUnit-code"` + DstDoctor_Code *string `json:"dstDoctor-code"` } type ReadDetailDto struct { @@ -63,29 +63,29 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Date *time.Time `json:"date"` - Problem *string `json:"problem"` - Solution *string `json:"solution"` - DstUnit_Id *uint `json:"dstUnit_id"` - DstUnit *eu.Unit `json:"dstUnit,omitempty"` - DstDoctor_Id *uint `json:"dstDoctor_id"` - DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"` - RepliedAt *time.Time `json:"repliedAt"` + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Date *time.Time `json:"date"` + Problem *string `json:"problem"` + Solution *string `json:"solution"` + DstUnit_Code *string `json:"dstUnit_code"` + DstUnit *eu.Unit `json:"dstUnit,omitempty"` + DstDoctor_Code *string `json:"dstDoctor_code"` + DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"` + RepliedAt *time.Time `json:"repliedAt"` } func (d Consultation) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Encounter: d.Encounter, - Date: d.Date, - Problem: d.Problem, - Solution: d.Solution, - DstUnit_Id: d.DstUnit_Id, - DstUnit: d.DstUnit, - DstDoctor_Id: d.DstDoctor_Id, - DstDoctor: d.DstDoctor, + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Date: d.Date, + Problem: d.Problem, + Solution: d.Solution, + DstUnit_Code: d.DstUnit_Code, + DstUnit: d.DstUnit, + DstDoctor_Code: d.DstDoctor_Code, + DstDoctor: d.DstDoctor, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/consultation/entity.go b/internal/domain/main-entities/consultation/entity.go index 2fda8bd0..b8be3596 100644 --- a/internal/domain/main-entities/consultation/entity.go +++ b/internal/domain/main-entities/consultation/entity.go @@ -15,11 +15,11 @@ type Consultation struct { Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` Date *time.Time `json:"date"` - Problem *string `json:"case" gorm:"size:10240"` - Solution *string `json:"solution" gorm:"size:10240"` - DstUnit_Id *uint `json:"dstUnit_id"` - DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Id;references:Id"` - DstDoctor_Id *uint `json:"dstDoctor_id"` - DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Id;references:Id"` - RepliedAt *time.Time `json:"repliedAt"` + Problem *string `json:"case" gorm:"size:10240"` + Solution *string `json:"solution" gorm:"size:10240"` + DstUnit_Code *string `json:"dstUnit_code"` + DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Code;references:Code"` + DstDoctor_Code *string `json:"dstDoctor_code"` + DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Code;references:Code"` + RepliedAt *time.Time `json:"repliedAt"` } diff --git a/internal/domain/main-entities/control-letter/dto.go b/internal/domain/main-entities/control-letter/dto.go index c2bab776..87b82366 100644 --- a/internal/domain/main-entities/control-letter/dto.go +++ b/internal/domain/main-entities/control-letter/dto.go @@ -5,7 +5,6 @@ import ( "time" // internal - lib - pa "simrs-vx/internal/lib/auth" // internal - domain - base-entities ecore "simrs-vx/internal/domain/base-entities/core" @@ -20,12 +19,12 @@ import ( ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint `json:"unit_id"` - Specialist_Id *uint `json:"specialist_id"` - Subspecialist_Id *uint `json:"subspecialist_id"` - Doctor_Id *uint `json:"doctor_id"` - Date *time.Time `json:"date"` + Encounter_Id *uint `json:"encounter_id"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + Doctor_Code *string `json:"doctor_code"` + Date *time.Time `json:"date"` } type ReadListDto struct { @@ -35,12 +34,12 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Unit_Id *uint `json:"unit-id"` - Specialist_Id *uint `json:"specialist-id"` - Subspecialist_Id *uint `json:"subspecialist-id"` - Doctor_Id *uint `json:"doctor-id"` - Date *time.Time `json:"date"` + Encounter_Id *uint `json:"encounter-id"` + Unit_Code *string `json:"unit-code"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` + Doctor_Code *string `json:"doctor-code"` + Date *time.Time `json:"date"` } type ReadDetailDto struct { @@ -57,13 +56,6 @@ type DeleteDto struct { Id uint `json:"id"` } -type ReplyDto struct { - Id uint `json:"id"` - Solution *string `json:"solution"` - - pa.AuthInfo -} - type MetaDto struct { PageNumber int `json:"page_number"` PageSize int `json:"page_size"` @@ -72,32 +64,32 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Unit_Id *uint `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty"` - Specialist_Id *uint `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist_Id *uint `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` - Date *time.Time `json:"date"` + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + Date *time.Time `json:"date"` } func (d ControlLetter) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Encounter: d.Encounter, - Unit_Id: d.Unit_Id, - Unit: d.Unit, - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, - Subspecialist: d.Subspecialist, - Doctor_Id: d.Doctor_Id, - Doctor: d.Doctor, - Date: d.Date, + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Unit_Code: d.Unit_Code, + Unit: d.Unit, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Subspecialist_Code: d.Subspecialist_Code, + Subspecialist: d.Subspecialist, + Doctor_Code: d.Doctor_Code, + Doctor: d.Doctor, + Date: d.Date, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/control-letter/entity.go b/internal/domain/main-entities/control-letter/entity.go index abaf4a72..2b8019b4 100644 --- a/internal/domain/main-entities/control-letter/entity.go +++ b/internal/domain/main-entities/control-letter/entity.go @@ -12,16 +12,16 @@ import ( ) type ControlLetter struct { - ecore.Main // adjust this according to the needs - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` - Unit_Id *uint `json:"unit_id"` - Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` - Specialist_Id *uint `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"` - Subspecialist_Id *uint `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Id;references:Id"` - Date *time.Time `json:"date"` + ecore.Main // adjust this according to the needs + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Code;references:Code"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Code;references:Code"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Code;references:Code"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Code;references:Code"` + Date *time.Time `json:"date"` } diff --git a/internal/domain/main-entities/device-order-item/dto.go b/internal/domain/main-entities/device-order-item/dto.go index e89d5fad..afa08ed8 100644 --- a/internal/domain/main-entities/device-order-item/dto.go +++ b/internal/domain/main-entities/device-order-item/dto.go @@ -7,9 +7,9 @@ import ( ) type CreateDto struct { - DeviceOrder_Id *uint `json:"deviceOrder_id"` - Device_Id *uint `json:"device_id"` - Count uint8 `json:"count"` + DeviceOrder_Id *uint `json:"deviceOrder_id"` + Device_Code *string `json:"device_code"` + Count uint8 `json:"count"` } type ReadListDto struct { @@ -19,9 +19,9 @@ type ReadListDto struct { } type FilterDto struct { - DeviceOrder_Id *uint `json:"deviceOrder-id"` - Device_Id *uint `json:"device-id"` - Count uint8 `json:"count"` + DeviceOrder_Id *uint `json:"deviceOrder-id"` + Device_Code *string `json:"device-code"` + Count uint8 `json:"count"` } type ReadDetailDto struct { Id uint16 `json:"id"` @@ -46,7 +46,7 @@ type ResponseDto struct { ecore.Main DeviceOrder_Id *uint `json:"deviceOrder_id"` DeviceOrder *edo.DeviceOrder `json:"deviceOrder,omitempty"` - Device_Id *uint `json:"device_id"` + Device_Code *string `json:"device_code"` Device *ed.Device `json:"device,omitempty"` Count uint8 `json:"count"` } @@ -55,7 +55,7 @@ func (d DeviceOrderItem) ToResponse() ResponseDto { resp := ResponseDto{ DeviceOrder_Id: d.DeviceOrder_Id, DeviceOrder: d.DeviceOrder, - Device_Id: d.Device_Id, + Device_Code: d.Device_Code, Device: d.Device, Count: d.Count, } diff --git a/internal/domain/main-entities/device-order-item/entity.go b/internal/domain/main-entities/device-order-item/entity.go index 196415af..27197125 100644 --- a/internal/domain/main-entities/device-order-item/entity.go +++ b/internal/domain/main-entities/device-order-item/entity.go @@ -10,7 +10,7 @@ type DeviceOrderItem struct { ecore.Main // adjust this according to the needs DeviceOrder_Id *uint `json:"deviceOrder_id"` DeviceOrder *edo.DeviceOrder `json:"deviceOrder,omitempty" gorm:"foreignKey:DeviceOrder_Id;references:Id"` - Device_Id *uint `json:"device_id"` - Device *ed.Device `json:"device,omitempty" gorm:"foreignKey:Device_Id;references:Id"` + Device_Code *string `json:"device_code"` + Device *ed.Device `json:"device,omitempty" gorm:"foreignKey:Device_Code;references:Code"` Count uint8 `json:"count"` } diff --git a/internal/domain/main-entities/device-order/dto.go b/internal/domain/main-entities/device-order/dto.go index 3d944941..6371800c 100644 --- a/internal/domain/main-entities/device-order/dto.go +++ b/internal/domain/main-entities/device-order/dto.go @@ -18,7 +18,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Status_Code erc.DataStatusCode `json:"status_code"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` pa.AuthInfo } @@ -32,7 +32,7 @@ type ReadListDto struct { type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` Status_Code erc.DataStatusCode `json:"status-code"` - Doctor_Id *uint `json:"doctor-id"` + Doctor_Code *string `json:"doctor-code"` } type ReadDetailDto struct { Id uint16 `json:"id"` @@ -57,7 +57,7 @@ type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` Status_Code erc.DataStatusCode `json:"status_code"` } @@ -66,7 +66,7 @@ func (d DeviceOrder) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, Encounter: d.Encounter, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, Status_Code: d.Status_Code, } diff --git a/internal/domain/main-entities/device-order/entity.go b/internal/domain/main-entities/device-order/entity.go index 7f693518..7ff4fa34 100644 --- a/internal/domain/main-entities/device-order/entity.go +++ b/internal/domain/main-entities/device-order/entity.go @@ -12,8 +12,8 @@ type DeviceOrder struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` Status_Code erc.DataStatusCode `json:"status_code"` } @@ -21,6 +21,6 @@ func (d DeviceOrder) IsCompleted() bool { return d.Status_Code == erc.DSCDone } -func (d DeviceOrder) IsSameDoctor(doctor_id *uint) bool { - return d.Doctor_Id == doctor_id +func (d DeviceOrder) IsSameDoctor(doctor_code *string) bool { + return d.Doctor_Code == doctor_code } diff --git a/internal/domain/main-entities/doctor/dto.go b/internal/domain/main-entities/doctor/dto.go index 67290551..e3d1f3ee 100644 --- a/internal/domain/main-entities/doctor/dto.go +++ b/internal/domain/main-entities/doctor/dto.go @@ -38,7 +38,7 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` @@ -46,12 +46,13 @@ type ReadDetailDto struct { } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 6782b18c..290a7766 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -1,6 +1,13 @@ package encounter import ( + eam "simrs-vx/internal/domain/main-entities/ambulatory" + edc "simrs-vx/internal/domain/main-entities/death-cause" + eem "simrs-vx/internal/domain/main-entities/emergency" + eip "simrs-vx/internal/domain/main-entities/inpatient" + eir "simrs-vx/internal/domain/main-entities/internal-reference" + er "simrs-vx/internal/domain/main-entities/rehab/base" + // std "time" @@ -19,7 +26,6 @@ import ( ea "simrs-vx/internal/domain/main-entities/appointment" ed "simrs-vx/internal/domain/main-entities/doctor" ee "simrs-vx/internal/domain/main-entities/employee" - eir "simrs-vx/internal/domain/main-entities/internal-reference" ep "simrs-vx/internal/domain/main-entities/patient" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" @@ -27,29 +33,31 @@ import ( ) type CreateDto struct { - Patient_Id *uint `json:"patient_id"` - RegisteredAt *time.Time `json:"registeredAt"` - Class_Code ere.EncounterClassCode `json:"class_code" validate:"maxLength=10"` - SubClass_Code *string `json:"subClass_code" validate:"maxLength=10"` // for sub - Infra_Id *uint16 `json:"infra_id"` // for inpatient - Unit_Id *uint `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - VisitDate time.Time `json:"visitDate"` - PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` - InsuranceCompany_Id *uint `json:"insuranceCompany_id"` - Member_Number *string `json:"member_number" validate:"maxLength=20"` - Ref_Number *string `json:"ref_number" validate:"maxLength=20"` - Trx_Number *string `json:"trx_number" validate:"maxLength=20"` - Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` - Adm_Employee_Id *uint `json:"-"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` - RefSource_Name *string `json:"refSource_name" validate:"maxLength=100"` - Appointment_Id *uint `json:"appointment_id"` - RefTypeCode ere.RefTypeCode `json:"refTypeCode"` - NewStatus bool `json:"newStatus"` - VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` // if subClass_Code is rehab - AllocatedVisitCount *int `json:"allocatedVisitCount"` // if subClass_Code is rehab and VisitMode_Code is "adm" + Patient_Id *uint `json:"patient_id"` + RegisteredAt *time.Time `json:"registeredAt"` + Class_Code ere.EncounterClassCode `json:"class_code" validate:"maxLength=10"` + SubClass_Code *string `json:"subClass_code" validate:"maxLength=10"` // for sub + Infra_Code *string `json:"infra_code"` // for inpatient + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + VisitDate time.Time `json:"visitDate"` + PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` + InsuranceCompany_Code *string `json:"insuranceCompany_code"` + Member_Number *string `json:"member_number" validate:"maxLength=20"` + Ref_Number *string `json:"ref_number" validate:"maxLength=20"` + Trx_Number *string `json:"trx_number" validate:"maxLength=20"` + Appointment_Doctor_Code *string `json:"appointment_doctor_code"` + Adm_Employee_Id *uint `json:"-"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` + RefSource_Name *string `json:"refSource_name" validate:"maxLength=100"` + Appointment_Id *uint `json:"appointment_id"` + RefTypeCode ere.RefTypeCode `json:"refTypeCode"` + NewStatus bool `json:"newStatus"` + + Id uint `json:"-"` + RecentEncounterAdm *Encounter `json:"-"` // if subClass_Code is rehab + VisitMode_Code ere.VisitModeCode `json:"-"` // if subClass_Code is rehab pa.AuthInfo } @@ -67,12 +75,12 @@ type FilterDto struct { Patient *ep.Patient `json:"patient,omitempty"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class-code" validate:"maxLength=10"` - Unit_Id *uint `json:"unit-id"` - Specialist_Id *uint16 `json:"specialist-id"` - Subspecialist_Id *uint16 `json:"subspecialist-id"` + Unit_Code *string `json:"unit-code"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` VisitDate time.Time `json:"visitDate"` - Appoinment_Doctor_Id *uint `json:"appointment-doctor-id"` - Responsible_Doctor_Id *uint `json:"responsible-doctor-id"` + Appoinment_Doctor_Code *string `json:"appointment-doctor-code"` + Responsible_Doctor_Code *string `json:"responsible-doctor-code"` DischargeMethod_Code ere.DischargeMethodCode `json:"dischargeMethod-code" validate:"maxLength=10"` RefSource_Name *string `json:"refSource-name" validate:"maxLength=100"` Appointment_Id *uint `json:"appointment-id"` @@ -114,15 +122,25 @@ type DischargeDto struct { AdmDischargeEducation *string `json:"admDischargeEducation"` DischargeReason *string `json:"dischargeReason"` DeathCause *string `json:"deathCause"` - InternalReferences *[]eir.CreateDto `json:"internalReferences,omitempty"` } type CheckinDto struct { - Id uint `json:"id"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` - Adm_Employee_Id *uint `json:"adm_employee_id"` - StartedAt *time.Time `json:"startedAt"` - FinishedAt *time.Time `json:"finishedAt"` + Id uint `json:"id"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` + Adm_Employee_Id *uint `json:"adm_employee_id"` + StartedAt *time.Time `json:"startedAt"` + FinishedAt *time.Time `json:"finishedAt"` +} + +type SwitchUnitDto struct { + Id uint `json:"id"` + PolySwitchCode *ere.PolySwitchCode `json:"polySwitchCode"` + InternalReferences *[]eir.CreateDto `json:"internalReferences" validate:"required"` +} + +type ApproveUnitDto struct { + Id uint `json:"id"` + InternalReferences_Id uint16 `json:"internalReferences_id" validate:"required"` } type ResponseDto struct { @@ -131,21 +149,21 @@ type ResponseDto struct { Patient *ep.Patient `json:"patient,omitempty"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code"` - Unit_Id *uint `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Subspecialist_Code *string `json:"subspecialist_code"` Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` Unit *eu.Unit `json:"unit,omitempty"` VisitDate time.Time `json:"visitDate"` PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code"` - InsuranceCompany_Id *uint `json:"insuranceCompany_id"` + InsuranceCompany_Code *string `json:"insuranceCompany_code"` Member_Number *string `json:"member_number"` Ref_Number *string `json:"ref_number"` Trx_Number *string `json:"trx_number"` - Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` + Appointment_Doctor_Code *string `json:"appointment_doctor_code"` Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty"` Adm_Employee_Id *uint `json:"adm_employee_id"` Adm_Employee *ee.Employee `json:"adm_employee,omitempty"` @@ -159,6 +177,17 @@ type ResponseDto struct { DischargeReason *string `json:"dischargeReason"` Status_Code erc.DataStatusCode `json:"status_code"` VclaimSep *evs.VclaimSep `json:"vclaimSep,omitempty"` + StartedAt *time.Time `json:"startedAt"` + FinishedAt *time.Time `json:"finishedAt"` + Discharge_Date *time.Time `json:"discharge_date"` + InternalReferences *[]eir.InternalReference `json:"internalReferences,omitempty"` + DeathCause *edc.DeathCause `json:"deathCause,omitempty"` + NewStatus bool `json:"newStatus"` + Ambulatory *eam.Ambulatory `json:"ambulatory,omitempty"` + Emergency *eem.Emergency `json:"emergency,omitempty"` + Inpatient *eip.Inpatient `json:"inpatient,omitempty"` + Rehab *er.Basic `json:"rehab,omitempty"` + RehabChildren *[]er.Basic `json:"rehabChildren,omitempty"` } func (d Encounter) ToResponse() ResponseDto { @@ -167,23 +196,23 @@ func (d Encounter) ToResponse() ResponseDto { Patient: d.Patient, RegisteredAt: d.RegisteredAt, Class_Code: d.Class_Code, - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, - Specialist_Id: d.Specialist_Id, + Specialist_Code: d.Specialist_Code, Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, + Subspecialist_Code: d.Subspecialist_Code, Subspecialist: d.Subspecialist, VisitDate: d.VisitDate, PaymentMethod_Code: d.PaymentMethod_Code, - InsuranceCompany_Id: d.InsuranceCompany_Id, + InsuranceCompany_Code: d.InsuranceCompany_Code, Member_Number: d.Member_Number, Ref_Number: d.Ref_Number, Trx_Number: d.Trx_Number, - Appointment_Doctor_Id: d.Appointment_Doctor_Id, + Appointment_Doctor_Code: d.Appointment_Doctor_Code, Appointment_Doctor: d.Appointment_Doctor, Adm_Employee_Id: d.Adm_Employee_Id, Adm_Employee: d.Adm_Employee, - Responsible_Doctor_Id: d.Responsible_Doctor_Id, + Responsible_Doctor_Code: d.Responsible_Doctor_Code, Responsible_Doctor: d.Responsible_Doctor, Discharge_Method_Code: d.Discharge_Method_Code, RefSource_Name: d.RefSource_Name, @@ -195,6 +224,16 @@ func (d Encounter) ToResponse() ResponseDto { DischargeReason: d.DischargeReason, Status_Code: d.Status_Code, VclaimSep: d.VclaimSep, + StartedAt: d.StartedAt, + FinishedAt: d.FinishedAt, + Discharge_Date: d.Discharge_Date, + InternalReferences: d.InternalReferences, + DeathCause: d.DeathCause, + NewStatus: d.NewStatus, + Emergency: d.Emergency, + Inpatient: d.Inpatient, + Rehab: d.Rehab, + RehabChildren: d.RehabChildren, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index 5e950def..c9e9bb95 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -29,28 +29,28 @@ type Encounter struct { Patient *ep.Patient `json:"patient,omitempty" gorm:"foreignKey:Patient_Id;references:Id"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code" gorm:"not null;size:10"` - Unit_Id *uint `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` VisitDate time.Time `json:"visitDate"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` - InsuranceCompany_Id *uint `json:"insuranceCompany_id"` - InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Id;references:Id"` + InsuranceCompany_Code *string `json:"insuranceCompany_code"` + InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Code;references:Code"` Member_Number *string `json:"memberNumber" gorm:"unique;size:20"` RefType_Code *ere.RefTypeCode `json:"refType_code"` Ref_Number *string `json:"refNumber" gorm:"unique;size:20"` Trx_Number *string `json:"trxNumber" gorm:"unique;size:20"` - Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` - Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Id;references:Id"` + Appointment_Doctor_Code *string `json:"appointment_doctor_code"` + Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Code;references:Code"` Adm_Employee_Id *uint `json:"adm_employee_id"` Adm_Employee *ee.Employee `json:"adm_employee,omitempty" gorm:"foreignKey:Adm_Employee_Id;references:Id"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` - Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Id;references:Id"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` + Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Code;references:Code"` Discharge_Method_Code *ere.DischargeMethodCode `json:"discharge_method_code" gorm:"size:16"` RefSource_Name *string `json:"refSource_name" gorm:"size:100"` Appointment_Id *uint `json:"appointment_id"` @@ -69,6 +69,7 @@ type Encounter struct { Emergency *eem.Emergency `json:"emergency,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Inpatient *eip.Inpatient `json:"inpatient,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Rehab *er.Basic `json:"rehab,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + RehabChildren *[]er.Basic `json:"rehabChildren,omitempty" gorm:"foreignKey:Parent_Encounter_Id;references:Id"` } func (d Encounter) IsDone() bool { diff --git a/internal/domain/main-entities/inpatient/dto.go b/internal/domain/main-entities/inpatient/dto.go index 11a864eb..be817ad0 100644 --- a/internal/domain/main-entities/inpatient/dto.go +++ b/internal/domain/main-entities/inpatient/dto.go @@ -10,7 +10,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Class_Code ere.InpatientClassCode `json:"class_code" validate:"maxLength=10"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` } type ReadListDto struct { @@ -22,7 +22,7 @@ type ReadListDto struct { type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` Class_Code ere.InpatientClassCode `json:"class-code"` - Infra_Id *uint16 `json:"infra-id"` + Infra_Code *string `json:"infra-code"` } type ReadDetailDto struct { @@ -48,7 +48,7 @@ type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` Class_Code ere.InpatientClassCode `json:"class_code"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Infra *ei.Infra `json:"infra,omitempty"` } @@ -56,7 +56,7 @@ func (d Inpatient) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, Class_Code: d.Class_Code, - Infra_Id: d.Infra_Id, + Infra_Code: d.Infra_Code, Infra: d.Infra, } resp.Main = d.Main diff --git a/internal/domain/main-entities/inpatient/entity.go b/internal/domain/main-entities/inpatient/entity.go index f88eb2fb..39cc2dbe 100644 --- a/internal/domain/main-entities/inpatient/entity.go +++ b/internal/domain/main-entities/inpatient/entity.go @@ -10,6 +10,6 @@ type Inpatient struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Class_Code ere.InpatientClassCode `json:"class_code" gorm:"size:10"` - Infra_Id *uint16 `json:"infra_id"` - Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` + Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"` } diff --git a/internal/domain/main-entities/internal-reference/dto.go b/internal/domain/main-entities/internal-reference/dto.go index 360c3193..08eaaac2 100644 --- a/internal/domain/main-entities/internal-reference/dto.go +++ b/internal/domain/main-entities/internal-reference/dto.go @@ -1,15 +1,18 @@ package internal_reference import ( + erc "simrs-vx/internal/domain/references/common" + ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" eu "simrs-vx/internal/domain/main-entities/unit" ) type CreateDto struct { - Encounter_Id *uint `json:"-"` - Unit_Id *uint16 `json:"unit_id"` - Doctor_Id *uint `json:"doctor_Id"` + Encounter_Id *uint `json:"-"` + Unit_Code *string `json:"unit_code"` + Doctor_Code *string `json:"doctor_code"` + Status_Code erc.DataApprovalCode `json:"status_code"` } type ReadListDto struct { @@ -19,9 +22,10 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Unit_Id *uint `json:"unit-id"` - Doctor_Id *uint `json:"doctor-id"` + Encounter_Id *uint `json:"encounter-id"` + Unit_Code *uint `json:"unit-code"` + Doctor_Code *uint `json:"doctor-code"` + Status_Code erc.DataApprovalCode `json:"status-code"` } type ReadDetailDto struct { @@ -46,20 +50,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` + Encounter_Id *uint `json:"encounter_id"` + Unit_Code *string `json:"unit_id"` + Unit *eu.Unit `json:"unit,omitempty"` + Doctor_Code *string `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + Status_Code *erc.DataApprovalCode `json:"status_code"` } func (d InternalReference) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, + Status_Code: d.Status_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/internal-reference/entity.go b/internal/domain/main-entities/internal-reference/entity.go index 85334449..ae6307bb 100644 --- a/internal/domain/main-entities/internal-reference/entity.go +++ b/internal/domain/main-entities/internal-reference/entity.go @@ -1,6 +1,8 @@ package internal_reference import ( + erc "simrs-vx/internal/domain/references/common" + ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" eu "simrs-vx/internal/domain/main-entities/unit" @@ -8,9 +10,10 @@ import ( type InternalReference struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Encounter_Id *uint `json:"encounter_id"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` + Status_Code *erc.DataApprovalCode `json:"status_code"` } diff --git a/internal/domain/main-entities/material-order-item/dto.go b/internal/domain/main-entities/material-order-item/dto.go index b76792bf..c8fd363d 100644 --- a/internal/domain/main-entities/material-order-item/dto.go +++ b/internal/domain/main-entities/material-order-item/dto.go @@ -8,7 +8,7 @@ import ( type CreateDto struct { MaterialOrder_Id *uint `json:"materialOrder_id"` - Material_Id *uint `json:"material_id"` + Material_Code *string `json:"material_code"` Count *uint16 `json:"count"` } @@ -20,7 +20,7 @@ type ReadListDto struct { type FilterDto struct { MaterialOrder_Id *uint `json:"materialOrder-id"` - Material_Id *uint `json:"material-id"` + Material_Code *string `json:"material-code"` Count *uint16 `json:"count"` } type ReadDetailDto struct { @@ -46,7 +46,7 @@ type ResponseDto struct { ecore.Main MaterialOrder_Id *uint `json:"materialOrder_id"` MaterialOrder *emo.MaterialOrder `json:"materialOrder,omitempty"` - Material_Id *uint `json:"material_id"` + Material_Code *string `json:"material_code"` Material *em.Material `json:"material,omitempty"` Count *uint16 `json:"count"` } @@ -55,7 +55,7 @@ func (d MaterialOrderItem) ToResponse() ResponseDto { resp := ResponseDto{ MaterialOrder_Id: d.MaterialOrder_Id, MaterialOrder: d.MaterialOrder, - Material_Id: d.Material_Id, + Material_Code: d.Material_Code, Material: d.Material, Count: d.Count, } diff --git a/internal/domain/main-entities/material-order-item/entity.go b/internal/domain/main-entities/material-order-item/entity.go index 432a36b9..2a85122a 100644 --- a/internal/domain/main-entities/material-order-item/entity.go +++ b/internal/domain/main-entities/material-order-item/entity.go @@ -10,7 +10,7 @@ type MaterialOrderItem struct { ecore.Main // adjust this according to the needs MaterialOrder_Id *uint `json:"materialOrder_id"` MaterialOrder *emo.MaterialOrder `json:"materialOrder,omitempty" gorm:"foreignKey:MaterialOrder_Id;references:Id"` - Material_Id *uint `json:"material_id"` - Material *em.Material `json:"material,omitempty" gorm:"foreignKey:Material_Id;references:Id"` + Material_Code *string `json:"material_code"` + Material *em.Material `json:"material,omitempty" gorm:"foreignKey:Material_Code;references:Code"` Count *uint16 `json:"count"` } diff --git a/internal/domain/main-entities/material-order/dto.go b/internal/domain/main-entities/material-order/dto.go index bd4f5c91..b830119d 100644 --- a/internal/domain/main-entities/material-order/dto.go +++ b/internal/domain/main-entities/material-order/dto.go @@ -18,7 +18,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Status_Code erc.DataStatusCode `json:"status_code"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` pa.AuthInfo } @@ -56,7 +56,7 @@ type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` Status_Code erc.DataStatusCode `json:"status_code"` } @@ -65,7 +65,7 @@ func (d MaterialOrder) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, Encounter: d.Encounter, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, Status_Code: d.Status_Code, } diff --git a/internal/domain/main-entities/material-order/entity.go b/internal/domain/main-entities/material-order/entity.go index 27b5c011..aec23316 100644 --- a/internal/domain/main-entities/material-order/entity.go +++ b/internal/domain/main-entities/material-order/entity.go @@ -12,8 +12,8 @@ type MaterialOrder struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` Status_Code erc.DataStatusCode `json:"status_code"` } @@ -21,6 +21,6 @@ func (d MaterialOrder) IsCompleted() bool { return d.Status_Code == erc.DSCDone } -func (d MaterialOrder) IsSameDoctor(doctor_id *uint) bool { - return d.Doctor_Id == doctor_id +func (d MaterialOrder) IsSameDoctor(doctor_code *string) bool { + return d.Doctor_Code == doctor_code } diff --git a/internal/domain/main-entities/mcu-order/dto.go b/internal/domain/main-entities/mcu-order/dto.go index e63a3e08..594f72d7 100644 --- a/internal/domain/main-entities/mcu-order/dto.go +++ b/internal/domain/main-entities/mcu-order/dto.go @@ -22,7 +22,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` SpecimenPickTime *time.Time `json:"specimenPickTime"` ExaminationDate *time.Time `json:"examinationDate"` Number uint8 `json:"number"` @@ -42,7 +42,7 @@ type ReadListDto struct { type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` Status_Code erc.DataStatusCode `json:"status-code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor-id"` + Doctor_Code *string `json:"doctor-code"` SpecimenPickTime *time.Time `json:"specimenPickTime"` ExaminationDate *time.Time `json:"examinationDate"` Number uint8 `json:"number"` @@ -79,7 +79,7 @@ type ResponseDto struct { Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty"` Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` SpecimenPickTime *time.Time `json:"specimenPickTime"` ExaminationDate *time.Time `json:"examinationDate"` @@ -93,7 +93,7 @@ func (d McuOrder) ToResponse() ResponseDto { Encounter_Id: d.Encounter_Id, Encounter: d.Encounter, Status_Code: d.Status_Code, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, SpecimenPickTime: d.SpecimenPickTime, ExaminationDate: d.ExaminationDate, diff --git a/internal/domain/main-entities/mcu-order/entity.go b/internal/domain/main-entities/mcu-order/entity.go index bf4e2e77..b9e5d0d7 100644 --- a/internal/domain/main-entities/mcu-order/entity.go +++ b/internal/domain/main-entities/mcu-order/entity.go @@ -15,8 +15,8 @@ type McuOrder struct { Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` SpecimenPickTime *time.Time `json:"specimenPickTime"` ExaminationDate *time.Time `json:"examinationDate"` Number uint8 `json:"number"` @@ -29,6 +29,6 @@ func (d McuOrder) IsCompleted() bool { return d.Status_Code == erc.DSCDone } -func (d McuOrder) IsSameDoctor(doctor_id *uint) bool { - return d.Doctor_Id == doctor_id +func (d McuOrder) IsSameDoctor(doctor_code *string) bool { + return d.Doctor_Code == doctor_code } diff --git a/internal/domain/main-entities/mcu-src/dto.go b/internal/domain/main-entities/mcu-src/dto.go index 7ab13428..6db7af65 100644 --- a/internal/domain/main-entities/mcu-src/dto.go +++ b/internal/domain/main-entities/mcu-src/dto.go @@ -6,10 +6,10 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=20"` + Code *string `json:"code" validate:"maxLength=20"` Name string `json:"name" validate:"maxLength=50"` McuSrcCategory_Code *string `json:"mcuSrcCategory_code" validate:"maxLength=20"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -27,17 +27,18 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -51,7 +52,7 @@ type ResponseDto struct { Code string `json:"code"` Name string `json:"name"` McuSrcCategory_Code *string `json:"mcuSrcCategory_code"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *ei.Item `json:"item,omitempty"` } @@ -60,7 +61,7 @@ func (d McuSrc) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, McuSrcCategory_Code: d.McuSrcCategory_Code, - Item_Id: d.Item_Id, + Item_Code: d.Item_Code, Item: d.Item, } resp.Main = d.Main diff --git a/internal/domain/main-entities/mcu-src/entity.go b/internal/domain/main-entities/mcu-src/entity.go index d3f4fca1..91ef8b99 100644 --- a/internal/domain/main-entities/mcu-src/entity.go +++ b/internal/domain/main-entities/mcu-src/entity.go @@ -8,10 +8,10 @@ import ( type McuSrc struct { ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:20"` + Code string `json:"code" gorm:"unique;size:20;not null"` Name string `json:"name" gorm:"size:50"` McuSrcCategory_Code *string `json:"mcuSrcCategory_code" gorm:"size:20"` McuSrcCategory *emsc.McuSrcCategory `json:"mcuSrcCategory,omitempty" gorm:"foreignKey:McuSrcCategory_Code;references:Code"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` } diff --git a/internal/domain/main-entities/mcu-sub-src/dto.go b/internal/domain/main-entities/mcu-sub-src/dto.go index f1b6d3bb..fde77fd2 100644 --- a/internal/domain/main-entities/mcu-sub-src/dto.go +++ b/internal/domain/main-entities/mcu-sub-src/dto.go @@ -7,10 +7,10 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=20"` - Name string `json:"name" validate:"maxLength=50"` - McuSrc_Id *uint `json:"mcuSrc_id"` - Item_Id *uint `json:"item_id"` + Code *string `json:"code" validate:"maxLength=20"` + Name string `json:"name" validate:"maxLength=50"` + McuSrc_Code *string `json:"mcuSrc_code"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -21,24 +21,25 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` + Code *string `json:"code"` + Name *string `json:"name"` CheckupCategory_Code *string `json:"checkupCategory-code"` Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -49,22 +50,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - McuSrc_Id *uint `json:"mcuSrc_id"` - McuSrc *ems.McuSrc `json:"mcuSrc,omitempty"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + McuSrc_Code *string `json:"mcuSrc_code"` + McuSrc *ems.McuSrc `json:"mcuSrc,omitempty"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty"` } func (d McuSubSrc) ToResponse() ResponseDto { resp := ResponseDto{ - Code: d.Code, - Name: d.Name, - McuSrc_Id: d.McuSrc_Id, - McuSrc: d.McuSrc, - Item_Id: d.Item_Id, - Item: d.Item, + Code: d.Code, + Name: d.Name, + McuSrc_Code: d.McuSrc_Code, + McuSrc: d.McuSrc, + Item_Code: d.Item_Code, + Item: d.Item, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/mcu-sub-src/entity.go b/internal/domain/main-entities/mcu-sub-src/entity.go index 02559abb..888ebf90 100644 --- a/internal/domain/main-entities/mcu-sub-src/entity.go +++ b/internal/domain/main-entities/mcu-sub-src/entity.go @@ -7,11 +7,11 @@ import ( ) type McuSubSrc struct { - ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:20"` - Name string `json:"name" gorm:"size:50"` - McuSrc_Id *uint `json:"mcuSrc_id"` - McuSrc *ems.McuSrc `json:"mcuSrc,omitempty" gorm:"foreignKey:McuSrc_Id;references:Id"` - 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:20"` + Name string `json:"name" gorm:"size:50"` + McuSrc_Code *string `json:"mcuSrc_code"` + McuSrc *ems.McuSrc `json:"mcuSrc,omitempty" gorm:"foreignKey:McuSrc_Code;references:Code"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_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 540a6ca5..849e6b18 100644 --- a/internal/domain/main-entities/medical-action-src-item/dto.go +++ b/internal/domain/main-entities/medical-action-src-item/dto.go @@ -8,9 +8,9 @@ import ( ) type CreateDto struct { - MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` - ProcedureSrc_Id *uint `json:"procedureSrc_id"` - Item_Id *uint `json:"item_id"` + MedicalActionSrc_Code *string `json:"medicalActionSrc_code"` + ProcedureSrc_Code *string `json:"procedureSrc_code"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -20,9 +20,9 @@ type ReadListDto struct { } type FilterDto struct { - MedicalActionSrc_Id *uint `json:"medicalActionSrc-id"` - ProcedureSrc_Id *uint `json:"procedureSrc-id"` - Item_Id *uint `json:"item-id"` + MedicalActionSrc_Code *string `json:"medicalActionSrc-code"` + ProcedureSrc_Code *string `json:"procedureSrc-code"` + Item_Code *string `json:"item-code"` } type ReadDetailDto struct { @@ -46,22 +46,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` - MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty"` - ProcedureSrc_Id *uint `json:"procedureSrc_id"` - ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + MedicalActionSrc_Code *string `json:"medicalActionSrc_code"` + MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty"` + ProcedureSrc_Code *string `json:"procedureSrc_code"` + ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty"` } func (d MedicalActionSrcItem) ToResponse() ResponseDto { resp := ResponseDto{ - MedicalActionSrc_Id: d.MedicalActionSrc_Id, - MedicalActionSrc: d.MedicalActionSrc, - ProcedureSrc_Id: d.ProcedureSrc_Id, - ProcedureSrc: d.ProcedureSrc, - Item_Id: d.Item_Id, - Item: d.Item, + MedicalActionSrc_Code: d.MedicalActionSrc_Code, + MedicalActionSrc: d.MedicalActionSrc, + ProcedureSrc_Code: d.ProcedureSrc_Code, + ProcedureSrc: d.ProcedureSrc, + Item_Code: d.Item_Code, + Item: d.Item, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/medical-action-src-item/entity.go b/internal/domain/main-entities/medical-action-src-item/entity.go index 59ecb828..2474c08b 100644 --- a/internal/domain/main-entities/medical-action-src-item/entity.go +++ b/internal/domain/main-entities/medical-action-src-item/entity.go @@ -8,11 +8,11 @@ import ( ) type MedicalActionSrcItem struct { - ecore.Main // adjust this according to the needs - MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` - MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty" gorm:"foreignKey:MedicalActionSrc_Id;references:Id"` - ProcedureSrc_Id *uint `json:"procedureSrc_id"` - ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty" gorm:"foreignKey:ProcedureSrc_Id;references:Id"` - 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 + MedicalActionSrc_Code *string `json:"medicalActionSrc_code"` + MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty" gorm:"foreignKey:MedicalActionSrc_Code;references:Code"` + ProcedureSrc_Code *string `json:"procedureSrc_code"` + ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty" gorm:"foreignKey:ProcedureSrc_Code;references:Code"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` } diff --git a/internal/domain/main-entities/medical-action-src/dto.go b/internal/domain/main-entities/medical-action-src/dto.go index 32e248d8..9316677f 100644 --- a/internal/domain/main-entities/medical-action-src/dto.go +++ b/internal/domain/main-entities/medical-action-src/dto.go @@ -6,10 +6,10 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=20"` - Name string `json:"name" validate:"maxLength=50"` - Type_Code string `json:"type_code" validate:"maxLength=20"` - Item_Id *uint `json:"item_id"` + Code *string `json:"code" validate:"maxLength=20"` + Name string `json:"name" validate:"maxLength=50"` + Type_Code string `json:"type_code" validate:"maxLength=20"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -20,25 +20,26 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` - Type_Code string `json:"type_code"` - Item_Id *uint `json:"item-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code *string `json:"code"` + Name string `json:"name"` + Type_Code string `json:"type_code"` + Item_Code *string `json:"item-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,7 +53,7 @@ type ResponseDto struct { Code string `json:"code"` Name string `json:"name"` Type_Code string `json:"type_code"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *ei.Item `json:"item,omitempty"` } @@ -61,7 +62,7 @@ func (d MedicalActionSrc) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, Type_Code: d.Type_Code, - Item_Id: d.Item_Id, + Item_Code: d.Item_Code, Item: d.Item, } resp.Main = d.Main diff --git a/internal/domain/main-entities/medical-action-src/entity.go b/internal/domain/main-entities/medical-action-src/entity.go index 60f15816..db3672a6 100644 --- a/internal/domain/main-entities/medical-action-src/entity.go +++ b/internal/domain/main-entities/medical-action-src/entity.go @@ -10,6 +10,6 @@ type MedicalActionSrc struct { Code string `json:"code" gorm:"unique;size:20"` Name string `json:"name" gorm:"size:50"` Type_Code string `json:"type_code" gorm:"size:20"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` } diff --git a/internal/domain/main-entities/nurse/dto.go b/internal/domain/main-entities/nurse/dto.go index f48014dd..b0cd6104 100644 --- a/internal/domain/main-entities/nurse/dto.go +++ b/internal/domain/main-entities/nurse/dto.go @@ -29,19 +29,20 @@ type FilterDto struct { Infra_Code *string `json:"infra-code"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { diff --git a/internal/domain/main-entities/practice-schedule/dto.go b/internal/domain/main-entities/practice-schedule/dto.go index 00eea2ad..832bc29d 100644 --- a/internal/domain/main-entities/practice-schedule/dto.go +++ b/internal/domain/main-entities/practice-schedule/dto.go @@ -6,11 +6,11 @@ import ( ) type CreateDto struct { - Doctor_Id *uint `json:"doctor_id"` - Unit_Code *string `json:"unit_code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime" validate:"maxLength=5"` - EndTime *string `json:"endTime" validate:"maxLength=5"` + Doctor_Code *string `json:"doctor_code"` + Unit_Code *string `json:"unit_code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime" validate:"maxLength=5"` + EndTime *string `json:"endTime" validate:"maxLength=5"` } type ReadListDto struct { @@ -20,11 +20,11 @@ type ReadListDto struct { } type FilterDto struct { - Doctor_Id *uint `json:"doctor-id"` - Unit_Code *string `json:"unit-code"` - Day_Code *erc.DayCode `json:"day-code"` - StartTime *string `json:"startTime"` - EndTime *string `json:"endTime"` + Doctor_Code *string `json:"doctor-code"` + Unit_Code *string `json:"unit-code"` + Day_Code *erc.DayCode `json:"day-code"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` } type ReadDetailDto struct { @@ -48,20 +48,20 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Doctor_Id *uint `json:"doctor_id"` - Unit_Code *string `json:"unit_code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime"` - EndTime *string `json:"endTime"` + Doctor_Code *string `json:"doctor_code"` + Unit_Code *string `json:"unit_code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` } func (d PracticeSchedule) ToResponse() ResponseDto { resp := ResponseDto{ - Doctor_Id: d.Doctor_Id, - Unit_Code: d.Unit_Code, - Day_Code: d.Day_Code, - StartTime: d.StartTime, - EndTime: d.EndTime, + Doctor_Code: d.Doctor_Code, + Unit_Code: d.Unit_Code, + Day_Code: d.Day_Code, + StartTime: d.StartTime, + EndTime: d.EndTime, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/practice-schedule/entity.go b/internal/domain/main-entities/practice-schedule/entity.go index 524867c8..84ea3296 100644 --- a/internal/domain/main-entities/practice-schedule/entity.go +++ b/internal/domain/main-entities/practice-schedule/entity.go @@ -8,12 +8,12 @@ import ( ) type PracticeSchedule 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"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime" gorm:"size:5"` - EndTime *string `json:"endTime" gorm:"size:5"` + ecore.Main // adjust this according to the needs + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references: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/rehab/base/entity.go b/internal/domain/main-entities/rehab/base/entity.go index b1713811..d932a991 100644 --- a/internal/domain/main-entities/rehab/base/entity.go +++ b/internal/domain/main-entities/rehab/base/entity.go @@ -1,16 +1,21 @@ package base import ( + erc "simrs-vx/internal/domain/references/common" + ere "simrs-vx/internal/domain/references/encounter" + "time" + ecore "simrs-vx/internal/domain/base-entities/core" - ed "simrs-vx/internal/domain/main-entities/doctor" ) type Basic struct { - ecore.Main // adjust this according to the needs - Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` - AllocatedVisitCount *int `json:"allocatedVisitCount"` + ecore.Main // adjust this according to the needs + Parent_Encounter_Id *uint `json:"parent_encounter_id"` + Encounter_Id *uint `json:"encounter_id"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` + ExpiredAt *time.Time `json:"expiredAt"` + VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` + Status_Code *erc.DataStatusCode `json:"status_code"` } func (Basic) TableName() string { diff --git a/internal/domain/main-entities/rehab/dto.go b/internal/domain/main-entities/rehab/dto.go index 0cec61d8..9dd16c3e 100644 --- a/internal/domain/main-entities/rehab/dto.go +++ b/internal/domain/main-entities/rehab/dto.go @@ -1,14 +1,20 @@ package rehab import ( + erc "simrs-vx/internal/domain/references/common" + ere "simrs-vx/internal/domain/references/encounter" + ecore "simrs-vx/internal/domain/base-entities/core" - ed "simrs-vx/internal/domain/main-entities/doctor" + "time" ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` - AllocatedVisitCount *int `json:"allocatedVisitCount"` + Encounter_Id *uint `json:"encounter_id"` + Parent_Encounter_Id *uint `json:"parent_encounter_id"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` + ExpiredAt *time.Time `json:"expiredAt"` + VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` + Status_Code erc.DataStatusCode `json:"status_code"` } type ReadListDto struct { @@ -18,8 +24,9 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Doctor_Id *uint `json:"doctor-id"` + Encounter_Id *uint `json:"encounter-id"` + Parent_Encounter_Id *uint `json:"parent-encounter-id"` + VisitMode_Code ere.VisitModeCode `json:"visitMode-code"` } type ReadDetailDto struct { @@ -44,18 +51,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` - AllocatedVisitCount *int `json:"allocatedVisitCount"` + Encounter_Id *uint `json:"encounter_id"` + Parent_Encounter_Id *uint `json:"parent_encounter_id"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` + ExpiredAt *time.Time `json:"expiredAt"` + VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` + Status_Code *erc.DataStatusCode `json:"status_code"` } func (d Rehab) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, - Doctor_Id: d.Doctor_Id, - Doctor: d.Doctor, + Parent_Encounter_Id: d.Parent_Encounter_Id, AllocatedVisitCount: d.AllocatedVisitCount, + ExpiredAt: d.ExpiredAt, + VisitMode_Code: d.VisitMode_Code, + Status_Code: d.Status_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/responsible-doctor-hist/dto.go b/internal/domain/main-entities/responsible-doctor-hist/dto.go index 68c8dd21..c96c588c 100644 --- a/internal/domain/main-entities/responsible-doctor-hist/dto.go +++ b/internal/domain/main-entities/responsible-doctor-hist/dto.go @@ -8,7 +8,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` } @@ -22,7 +22,7 @@ type ReadListDto struct { type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` - Doctor_Id *uint `json:"doctor-id"` + Doctor_Code *string `json:"doctor-code"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` } @@ -50,7 +50,7 @@ type MetaDto struct { type ResponseDto struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` @@ -59,7 +59,7 @@ type ResponseDto struct { func (d ResponsibleDoctorHist) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, StartedAt: d.StartedAt, FinishedAt: d.FinishedAt, diff --git a/internal/domain/main-entities/responsible-doctor-hist/entity.go b/internal/domain/main-entities/responsible-doctor-hist/entity.go index c9df2c13..d9b4946c 100644 --- a/internal/domain/main-entities/responsible-doctor-hist/entity.go +++ b/internal/domain/main-entities/responsible-doctor-hist/entity.go @@ -9,8 +9,8 @@ import ( type ResponsibleDoctorHist struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` } diff --git a/internal/domain/main-entities/therapy-protocol/dto.go b/internal/domain/main-entities/therapy-protocol/dto.go index f7a5f2e4..40633b89 100644 --- a/internal/domain/main-entities/therapy-protocol/dto.go +++ b/internal/domain/main-entities/therapy-protocol/dto.go @@ -9,7 +9,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Anamnesis *string `json:"anamnesis" validate:"maxLength=2048"` MedicalDiagnoses *string `json:"medicalDiagnoses"` FunctionDiagnoses *string `json:"functionDiagnoses"` @@ -31,8 +31,8 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Doctor_Id *uint `json:"doctor-id"` + Encounter_Id *uint `json:"encounter-id"` + Doctor_Code *string `json:"doctor-code"` } type ReadDetailDto struct { @@ -59,7 +59,7 @@ type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter,omitempty"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` Anamnesis *string `json:"anamnesis"` MedicalDiagnoses *string `json:"medicalDiagnoses"` @@ -79,7 +79,7 @@ func (d TherapyProtocol) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, Encounter: d.Encounter, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, Anamnesis: d.Anamnesis, MedicalDiagnoses: d.MedicalDiagnoses, diff --git a/internal/domain/main-entities/therapy-protocol/entity.go b/internal/domain/main-entities/therapy-protocol/entity.go index f5ec318a..7caaf0a6 100644 --- a/internal/domain/main-entities/therapy-protocol/entity.go +++ b/internal/domain/main-entities/therapy-protocol/entity.go @@ -13,8 +13,8 @@ type TherapyProtocol struct { Encounter_Id *uint `json:"encounter_id" gorm:"not null"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"` Anamnesis *string `json:"anamnesis" gorm:"size:2048"` MedicalDiagnoses *string `json:"medicalDiagnoses"` diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index c5d949e2..f5190297 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -2,26 +2,26 @@ package clinical type ( - SubjectCode string - ObjectCode string - AssessmentCode string - PlanCode string - InstructionCode string - HeadToToeCode string - McuUrgencyLevelCode string - McuScopeCode string - SoapiTypeCode string - MedicalAction string - VehicleTypeCode string - GeneralEduCode string - SpecialEduCode string - EduAssessmentCode string - AbilityCode string - WillCode string - MedObstacleCode string - LearnMethodCode string - LangClassCode string - TranslatorSrcCode string + SubjectCode string + ObjectCode string + AssessmentCode string + PlanCode string + InstructionCode string + HeadToToeCode string + McuUrgencyLevelCode string + McuScopeCode string + SoapiTypeCode string + MedicalActionTypeCode string + VehicleTypeCode string + GeneralEduCode string + SpecialEduCode string + EduAssessmentCode string + AbilityCode string + WillCode string + MedObstacleCode string + LearnMethodCode string + LangClassCode string + TranslatorSrcCode string ) const ( @@ -124,11 +124,11 @@ const ( STCProgress SoapiTypeCode = "progress" // CPPT STCDevRecord SoapiTypeCode = "dev-record" // Catatan Perkembangan - MAChemo MedicalAction = "chemo" - MAHemo MedicalAction = "hemo" - MAThalasemia MedicalAction = "thalasemia" - MAEchocardio MedicalAction = "echocardio" - MASpirometry MedicalAction = "spirometry" + MATCChemo MedicalActionTypeCode = "chemo" + MATCHemo MedicalActionTypeCode = "hemo" + MATCThalasemia MedicalActionTypeCode = "thalasemia" + MATCEchocardio MedicalActionTypeCode = "echocardio" + MATCSpirometry MedicalActionTypeCode = "spirometry" VTCAmbulance VehicleTypeCode = "ambulance" // Ambulans VTCTransport VehicleTypeCode = "transport" // Transport diff --git a/internal/domain/references/common/common.go b/internal/domain/references/common/common.go index 9e532b14..2941049c 100644 --- a/internal/domain/references/common/common.go +++ b/internal/domain/references/common/common.go @@ -15,6 +15,7 @@ type ( DataAvailabilityCode string DataVerifiedCode string CrudCode string + DataApprovalCode string ) const ( @@ -96,6 +97,10 @@ const ( CCRead CrudCode = "r" // Read CCUpdate CrudCode = "u" // Update CCDelete CrudCode = "d" // Delete + + DACNew DataApprovalCode = "new" + DACApproved DataApprovalCode = "approved" + DACRejected DataApprovalCode = "rejected" ) func GetDayCodes() map[DayCode]string { diff --git a/internal/domain/references/encounter/encounter.go b/internal/domain/references/encounter/encounter.go index 45ee8c89..7e3fb204 100644 --- a/internal/domain/references/encounter/encounter.go +++ b/internal/domain/references/encounter/encounter.go @@ -18,6 +18,7 @@ type ( AllPaymentMethodCode string SEPRefTypeCode string VisitModeCode string + PolySwitchCode string ) const ( @@ -107,6 +108,9 @@ const ( VMCAdm VisitModeCode = "adm" VMCSeries VisitModeCode = "series" + + PSCConsulPoly PolySwitchCode = "consul-poly" // Konsultasi Poliklinik Lain + PSCConsulExecutive PolySwitchCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif ) func (ec EncounterClassCode) Code() string { diff --git a/internal/interface/main-handler/doctor/handler.go b/internal/interface/main-handler/doctor/handler.go index ee1252ad..f62495d6 100644 --- a/internal/interface/main-handler/doctor/handler.go +++ b/internal/interface/main-handler/doctor/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint(id) + dto.Code = &code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/encounter/handler.go b/internal/interface/main-handler/encounter/handler.go index b66abe76..22d1d8cf 100644 --- a/internal/interface/main-handler/encounter/handler.go +++ b/internal/interface/main-handler/encounter/handler.go @@ -3,18 +3,17 @@ package encounter import ( "net/http" + pa "simrs-vx/internal/lib/auth" + + d "github.com/karincake/dodol" rw "github.com/karincake/risoles" sf "github.com/karincake/semprit" // ua "github.com/karincake/tumpeng/auth/svc" + erc "simrs-vx/internal/domain/references/common" e "simrs-vx/internal/domain/main-entities/encounter" u "simrs-vx/internal/use-case/main-use-case/encounter" - - erc "simrs-vx/internal/domain/references/common" - pa "simrs-vx/internal/lib/auth" - - d "github.com/karincake/dodol" ) type myBase struct{} @@ -31,7 +30,13 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - if valid := validateRequestCreate(w, dto); !valid { + + // validate SubClass + if err := verifyClassCode(dto); err != nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: err.Error(), + }) return } @@ -192,3 +197,40 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) { res, err := u.UpdateStatusCode(dto) rw.DataResponse(w, res, err) } + +func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) { + dto := e.SwitchUnitDto{} + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + + // validate request body + if valid := validateRequestSwitchUnit(w, dto); !valid { + return + } + + dto.Id = uint(id) + res, err := u.RequestSwitchUnit(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) { + dto := e.ApproveUnitDto{} + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + + dto.Id = uint(id) + res, err := u.ApproveSwitchUnit(dto) + rw.DataResponse(w, res, err) +} diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index b7d31e71..79cc832c 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -1,10 +1,14 @@ package encounter import ( + "errors" "fmt" "net/http" e "simrs-vx/internal/domain/main-entities/encounter" ere "simrs-vx/internal/domain/references/encounter" + ua "simrs-vx/internal/use-case/main-use-case/ambulatory" + ue "simrs-vx/internal/use-case/main-use-case/emergency" + ui "simrs-vx/internal/use-case/main-use-case/inpatient" d "github.com/karincake/dodol" rw "github.com/karincake/risoles" @@ -12,51 +16,41 @@ import ( const dataValidationFail = "data-validation-fail" +func verifyClassCode(input e.CreateDto) (err error) { + switch input.Class_Code { + case ere.ECAmbulatory: + _, err = ua.CheckClassCode(input.SubClass_Code) + case ere.ECEmergency: + _, err = ue.CheckClassCode(input.SubClass_Code) + case ere.ECInpatient: + _, err = ui.CheckClassCode(input.SubClass_Code) + default: + return errors.New("invalid encounter class code") + } + + if err != nil { + return + } + + return nil +} + func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) { - switch *i.Discharge_Method_Code { - case ere.DMCDeath: - if i.DeathCause == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "deathCause required if discharge_method_code is death", - }) - return - } - case ere.DMCConsulPoly, ere.DMCConsulExecutive: - if i.InternalReferences == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: fmt.Sprintf("internalReferences required if discharge_method_code is %s", *i.Discharge_Method_Code), - }) - return - } - - for _, v := range *i.InternalReferences { - if v.Unit_Id == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "internalReferences.unit_id required", - }) - return - } - - if v.Doctor_Id == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "internalReferences.doctor_id required", - }) - return - } - } + if *i.Discharge_Method_Code == ere.DMCDeath && i.DeathCause == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "deathCause required if discharge_method_code is death", + }) + return } return true } func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) { - if i.Responsible_Doctor_Id == nil { + if i.Responsible_Doctor_Code == nil { rw.DataResponse(w, nil, d.FieldError{ Code: dataValidationFail, - Message: "responsible_doctor_id required", + Message: "responsible_doctor_code required", }) return } @@ -64,18 +58,30 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) return true } -func validateRequestCreate(w http.ResponseWriter, i e.CreateDto) (valid bool) { - switch { - case i.Class_Code == ere.ECAmbulatory: - // field allocatedVisitCount required if ambulatory visitMode_Code is adm - if ere.AmbulatoryClassCode(*i.SubClass_Code) == ere.ACCRehab && *i.VisitMode_Code == ere.VMCAdm { - if *i.AllocatedVisitCount == 0 { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "allocatedVisitCount required", - }) - return - } +func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid bool) { + if i.InternalReferences == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: fmt.Sprintf("internalReferences required"), + }) + return + } + + for _, v := range *i.InternalReferences { + if v.Unit_Code == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "internalReferences.unit_code required", + }) + return + } + + if v.Doctor_Code == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "internalReferences.doctor_code required", + }) + return } } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 117dfdb1..b3a2b65b 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -149,17 +149,19 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/material-order-item", materialorderitem.O) hk.GroupRoutes("/v1/encounter", r, auth.GuardMW, hk.MapHandlerFunc{ - "GET /": encounter.O.GetList, - "GET /{id}": encounter.O.GetDetail, - "POST /": encounter.O.Create, - "PATCH /{id}": encounter.O.Update, - "DELETE /{id}": encounter.O.Delete, - "PATCH /{id}/check-out": encounter.O.CheckOut, - "PATCH /{id}/check-in": encounter.O.CheckIn, - "PATCH /{id}/proccess": encounter.O.Process, - "PATCH /{id}/cancel": encounter.O.Cancel, - "PATCH /{id}/reject": encounter.O.Reject, - "PATCH /{id}/skip": encounter.O.Skip, + "GET /": encounter.O.GetList, + "GET /{id}": encounter.O.GetDetail, + "POST /": encounter.O.Create, + "PATCH /{id}": encounter.O.Update, + "DELETE /{id}": encounter.O.Delete, + "PATCH /{id}/check-out": encounter.O.CheckOut, + "PATCH /{id}/check-in": encounter.O.CheckIn, + "PATCH /{id}/proccess": encounter.O.Process, + "PATCH /{id}/cancel": encounter.O.Cancel, + "PATCH /{id}/reject": encounter.O.Reject, + "PATCH /{id}/skip": encounter.O.Skip, + "PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit, + "PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit, }) hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{ "GET /": mcuorder.O.GetList, @@ -320,17 +322,17 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/medicine-group", medicinegroup.O) hc.RegCrud(r, "/v1/medicine-method", medicinemethod.O) hc.RegCrud(r, "/v1/mcu-src-category", mcusrccategory.O) - hc.RegCrud(r, "/v1/mcu-src", mcusrc.O) + hc.RegCrudByCode(r, "/v1/mcu-src", mcusrc.O) hc.RegCrud(r, "/v1/ethnic", ethnic.O) hc.RegCrud(r, "/v1/insurance-company", insurancecompany.O) hc.RegCrudByCode(r, "/v1/medicine", medicine.O) hc.RegCrudByCode(r, "/v1/device", device.O) hc.RegCrudByCode(r, "/v1/material", material.O) hc.RegCrud(r, "/v1/doctor-fee", doctorfee.O) - hc.RegCrud(r, "/v1/medical-action-src", medicalactionsrc.O) + hc.RegCrudByCode(r, "/v1/medical-action-src", medicalactionsrc.O) hc.RegCrud(r, "/v1/medical-action-src-item", medicalactionsrcitem.O) hc.RegCrud(r, "/v1/language", language.O) - hc.RegCrud(r, "/v1/mcu-sub-src", mcusubsrc.O) + hc.RegCrudByCode(r, "/v1/mcu-sub-src", mcusubsrc.O) hc.RegCrud(r, "/v1/vehicle", vehicle.O) hc.RegCrud(r, "/v1/vehicle-hist", vehiclehist.O) hc.RegCrud(r, "/v1/edu-assessment", eduassesment.O) diff --git a/internal/interface/main-handler/mcu-src/handler.go b/internal/interface/main-handler/mcu-src/handler.go index c607017d..7523ea7e 100644 --- a/internal/interface/main-handler/mcu-src/handler.go +++ b/internal/interface/main-handler/mcu-src/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code 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 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = &code 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 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/mcu-sub-src/handler.go b/internal/interface/main-handler/mcu-sub-src/handler.go index 949be715..ad7868d9 100644 --- a/internal/interface/main-handler/mcu-sub-src/handler.go +++ b/internal/interface/main-handler/mcu-sub-src/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code 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 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = &code 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 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/medical-action-src/handler.go b/internal/interface/main-handler/medical-action-src/handler.go index c8b24706..42d41c92 100644 --- a/internal/interface/main-handler/medical-action-src/handler.go +++ b/internal/interface/main-handler/medical-action-src/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code 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 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint(id) + dto.Code = &code 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 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/nurse/handler.go b/internal/interface/main-handler/nurse/handler.go index 8817ae14..b8252892 100644 --- a/internal/interface/main-handler/nurse/handler.go +++ b/internal/interface/main-handler/nurse/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint(id) + dto.Code = &code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/main-use-case/ambulatory/helper.go b/internal/use-case/main-use-case/ambulatory/helper.go index a8a00e0d..912211c0 100644 --- a/internal/use-case/main-use-case/ambulatory/helper.go +++ b/internal/use-case/main-use-case/ambulatory/helper.go @@ -22,7 +22,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Ambulatory) { data.Encounter_Id = inputSrc.Encounter_Id data.Class_Code = inputSrc.Class_Code - data.VisitMode_Code = inputSrc.VisitMode_Code } func CheckClassCode(input *string) (ere.AmbulatoryClassCode, error) { diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 94a28fef..15f18ef8 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -207,12 +207,12 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err data.User_ContractPosition_code = checkStrClaims(claims, "contractPosition_code") data.Employee_Position_Code = checkStrPtrClaims(claims, "employee_position_code") - data.Doctor_Code = checkStrPtrClaims(claims, "doctor_string") - data.Nurse_Code = checkStrPtrClaims(claims, "nurse_string") - data.Midwife_Code = checkStrPtrClaims(claims, "midwife_string") - data.Nutritionist_Code = checkStrPtrClaims(claims, "nutritionist_string") - data.Laborant_Code = checkStrPtrClaims(claims, "laborant_string") - data.Pharmachist_Code = checkStrPtrClaims(claims, "pharmachist_string") + data.Doctor_Code = checkStrPtrClaims(claims, "doctor_code") + data.Nurse_Code = checkStrPtrClaims(claims, "nurse_code") + data.Midwife_Code = checkStrPtrClaims(claims, "midwife_code") + data.Nutritionist_Code = checkStrPtrClaims(claims, "nutritionist_code") + data.Laborant_Code = checkStrPtrClaims(claims, "laborant_code") + data.Pharmachist_Code = checkStrPtrClaims(claims, "pharmachist_code") data.Intern_Position_Code = checkStrPtrClaims(claims, "intern_position_code") data.Employee_Id = checkUntPtrClaims(claims, "employee_id") return diff --git a/internal/use-case/main-use-case/chemo/helper.go b/internal/use-case/main-use-case/chemo/helper.go index bb60a39b..51a09a3a 100644 --- a/internal/use-case/main-use-case/chemo/helper.go +++ b/internal/use-case/main-use-case/chemo/helper.go @@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Chemo) { data.Encounter_Id = inputSrc.Encounter_Id data.Status_Code = inputSrc.Status_Code - data.SrcUnit_Id = inputSrc.SrcUnit_Id + data.SrcUnit_Code = inputSrc.SrcUnit_Code } diff --git a/internal/use-case/main-use-case/consultation/case.go b/internal/use-case/main-use-case/consultation/case.go index 3cda31d9..25306169 100644 --- a/internal/use-case/main-use-case/consultation/case.go +++ b/internal/use-case/main-use-case/consultation/case.go @@ -7,8 +7,6 @@ import ( e "simrs-vx/internal/domain/main-entities/consultation" ue "simrs-vx/internal/use-case/main-use-case/encounter" - ud "simrs-vx/internal/use-case/main-use-case/doctor" - dg "github.com/karincake/apem/db-gorm-pg" d "github.com/karincake/dodol" @@ -314,12 +312,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx) - if err != nil { - return err - } - - if data.DstDoctor_Id != nil && data.DstDoctor_Id != doctor_id { + if data.DstDoctor_Code != nil && data.DstDoctor_Code != input.AuthInfo.Doctor_Code { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-handled-mismatch", @@ -329,7 +322,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - data.DstDoctor_Id = doctor_id + data.DstDoctor_Code = input.AuthInfo.Doctor_Code data.Solution = input.Solution data.RepliedAt = pu.GetTimeNow() err = tx.Save(&data).Error diff --git a/internal/use-case/main-use-case/consultation/helper.go b/internal/use-case/main-use-case/consultation/helper.go index 519c3c91..3a518c77 100644 --- a/internal/use-case/main-use-case/consultation/helper.go +++ b/internal/use-case/main-use-case/consultation/helper.go @@ -20,5 +20,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Consultation) { data.Encounter_Id = inputSrc.Encounter_Id data.Date = inputSrc.Date data.Problem = inputSrc.Problem - data.DstUnit_Id = inputSrc.DstUnit_Id + data.DstUnit_Code = inputSrc.DstUnit_Code } diff --git a/internal/use-case/main-use-case/control-letter/helper.go b/internal/use-case/main-use-case/control-letter/helper.go index 5cc943c5..8ae71d3c 100644 --- a/internal/use-case/main-use-case/control-letter/helper.go +++ b/internal/use-case/main-use-case/control-letter/helper.go @@ -18,9 +18,9 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ControlLetter) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Unit_Id = inputSrc.Unit_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Unit_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code + data.Doctor_Code = inputSrc.Doctor_Code data.Date = inputSrc.Date } diff --git a/internal/use-case/main-use-case/device-order-item/helper.go b/internal/use-case/main-use-case/device-order-item/helper.go index 5c6a0e68..8c0be91f 100644 --- a/internal/use-case/main-use-case/device-order-item/helper.go +++ b/internal/use-case/main-use-case/device-order-item/helper.go @@ -18,6 +18,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.DeviceOrderItem) { } data.DeviceOrder_Id = inputSrc.DeviceOrder_Id - data.Device_Id = inputSrc.Device_Id + data.Device_Code = inputSrc.Device_Code data.Count = inputSrc.Count } diff --git a/internal/use-case/main-use-case/device-order/case.go b/internal/use-case/main-use-case/device-order/case.go index 89466ead..b48e7670 100644 --- a/internal/use-case/main-use-case/device-order/case.go +++ b/internal/use-case/main-use-case/device-order/case.go @@ -6,7 +6,6 @@ import ( e "simrs-vx/internal/domain/main-entities/device-order" - ud "simrs-vx/internal/use-case/main-use-case/doctor" ue "simrs-vx/internal/use-case/main-use-case/encounter" erc "simrs-vx/internal/domain/references/common" @@ -60,11 +59,7 @@ func Create(input e.CreateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx) - if err != nil { - return err - } - input.Doctor_Id = doctor_id + input.Doctor_Code = input.AuthInfo.Doctor_Code if resData, err := CreateData(input, &event, tx); err != nil { return err @@ -236,11 +231,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx) - if err != nil { - return err - } - if !data.IsSameDoctor(doctor_id) { + if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "auth-forbidden", @@ -250,7 +241,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - input.Doctor_Id = doctor_id + input.Doctor_Code = input.AuthInfo.Doctor_Code if err := UpdateData(input, data, &event, tx); err != nil { return err diff --git a/internal/use-case/main-use-case/device-order/helper.go b/internal/use-case/main-use-case/device-order/helper.go index 3be32a7a..1fa0b4a8 100644 --- a/internal/use-case/main-use-case/device-order/helper.go +++ b/internal/use-case/main-use-case/device-order/helper.go @@ -21,5 +21,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.DeviceOrder) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code } diff --git a/internal/use-case/main-use-case/doctor/case.go b/internal/use-case/main-use-case/doctor/case.go index 74337056..cab7facc 100644 --- a/internal/use-case/main-use-case/doctor/case.go +++ b/internal/use-case/main-use-case/doctor/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Doctor var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Doctor var err error diff --git a/internal/use-case/main-use-case/doctor/lib.go b/internal/use-case/main-use-case/doctor/lib.go index 3355bb3c..12b62176 100644 --- a/internal/use-case/main-use-case/doctor/lib.go +++ b/internal/use-case/main-use-case/doctor/lib.go @@ -84,7 +84,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e if input.Employee_Id != nil { tx = tx.Where("\"Employee_Id\" = ?", *input.Employee_Id) } - if input.Id > 0 { + if input.Id != nil { tx = tx.Where("\"Id\" = ?", input.Id) } if err := tx.First(&data).Error; err != nil { diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index ef70d9c2..3a8c3b82 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -2,7 +2,7 @@ package encounter import ( "errors" - authhelper "simrs-vx/internal/lib/auth" + "fmt" "strconv" "time" @@ -17,28 +17,18 @@ import ( ere "simrs-vx/internal/domain/references/encounter" eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist" - ea "simrs-vx/internal/domain/main-entities/ambulatory" - ec "simrs-vx/internal/domain/main-entities/chemo" edc "simrs-vx/internal/domain/main-entities/death-cause" - ed "simrs-vx/internal/domain/main-entities/doctor" - ee "simrs-vx/internal/domain/main-entities/emergency" eem "simrs-vx/internal/domain/main-entities/employee" e "simrs-vx/internal/domain/main-entities/encounter" - ei "simrs-vx/internal/domain/main-entities/inpatient" - er "simrs-vx/internal/domain/main-entities/rehab" + eir "simrs-vx/internal/domain/main-entities/internal-reference" erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" es "simrs-vx/internal/domain/main-entities/soapi" uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist" - ua "simrs-vx/internal/use-case/main-use-case/ambulatory" - uc "simrs-vx/internal/use-case/main-use-case/chemo" udc "simrs-vx/internal/use-case/main-use-case/death-cause" - ud "simrs-vx/internal/use-case/main-use-case/doctor" - ue "simrs-vx/internal/use-case/main-use-case/emergency" uem "simrs-vx/internal/use-case/main-use-case/employee" - ui "simrs-vx/internal/use-case/main-use-case/inpatient" - ur "simrs-vx/internal/use-case/main-use-case/rehab" - us "simrs-vx/internal/use-case/main-use-case/soapi" + uir "simrs-vx/internal/use-case/main-use-case/internal-reference" + urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist" ) const source = "encounter" @@ -46,8 +36,11 @@ const source = "encounter" var now = time.Now() func Create(input e.CreateDto) (*d.Data, error) { - data := e.Encounter{} - createSoapi := []es.CreateDto{} + var ( + data e.Encounter + recentSoapiDataforCopy []es.CreateDto + err error + ) event := pl.Event{ Feature: "Create", @@ -57,51 +50,36 @@ func Create(input e.CreateDto) (*d.Data, error) { // Start log pl.SetLogInfo(&event, input, "started", "create") - // validate SubClass - var subCode interface{} - subCode, err := verifyClassCode(input) - if err != nil { - return nil, err - } - - // verify whether the allocated visit count has not exceeded the limit - if input.Class_Code == ere.ECAmbulatory && subCode.(ere.AmbulatoryClassCode) == ere.ACCRehab && - *input.VisitMode_Code == ere.VMCSeries { - - dataEncounter, valid, err := verifyAllocatedVisitCount(input, &event) + // validate rehab bpjs + if input.RefTypeCode == ere.RTCBpjs && input.Class_Code == ere.ECAmbulatory && ere.AmbulatoryClassCode(*input.SubClass_Code) == ere.ACCRehab { + // get latest rehab data + recentRehabData, err := getLatestRehabData(input, &event) if err != nil { return nil, err } - if !valid { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "visit-limit-exceeded", - Detail: "Encounter has exceeded the allowed number of visits", - Raw: errors.New("visit count exceeds allowed limit"), + if recentRehabData != nil { + // determine VisitModeCode + input.VisitMode_Code, input.RecentEncounterAdm, err = determineVisitMode(recentRehabData, input, &event) + if err != nil { + return nil, err } - return nil, pl.SetLogError(&event, input) + } else { + input.VisitMode_Code = ere.VMCAdm } - // get data soapi - createSoapi, err = getSoapiEncounterAdm(dataEncounter, &event) - if err != nil { - return nil, err + // if visitMode_Code is series, then get data soapi for copy + if input.VisitMode_Code == ere.VMCSeries { + // get data soapi + recentSoapiDataforCopy, err = getSoapiEncounterAdm(*input.RecentEncounterAdm, &event) + if err != nil { + return nil, err + } } } // check if patient is new in the hospital - dataPatient, err := ReadList(e.ReadListDto{ - FilterDto: e.FilterDto{Patient_Id: input.Patient_Id}, - AuthInfo: authhelper.AuthInfo{User_Id: input.User_Id}}) - if err != nil { - return nil, err - } - if list, ok := dataPatient.Data.([]e.ResponseDto); ok { - if len(list) < 1 { - input.NewStatus = true - } - } + input.NewStatus, err = identifyPatientStatus(input) err = dg.I.Transaction(func(tx *gorm.DB) error { mwRunner := newMiddlewareRunner(&event, tx) @@ -122,74 +100,18 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } else { data = *resData + input.Id = data.Id } - switch input.Class_Code { - case ere.ECAmbulatory: - subCodeAmbulatory := subCode.(ere.AmbulatoryClassCode) - ambCreate := ea.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCodeAmbulatory, - VisitMode_Code: *input.VisitMode_Code, - } - _, err = ua.CreateData(ambCreate, &event, tx) - if err != nil { - return err - } - - if subCodeAmbulatory == ere.ACCChemo { - chemoCreate := ec.CreateDto{ - Encounter_Id: &data.Id, - Status_Code: erc.DVCNew, - SrcUnit_Id: input.Unit_Id, - } - _, err = uc.CreateData(chemoCreate, &event, tx) - if err != nil { - return err - } - } - - if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCAdm { - // create data rehab - if _, err = ur.CreateData(er.CreateDto{ - Encounter_Id: &data.Id, - Doctor_Id: input.Appointment_Doctor_Id, - AllocatedVisitCount: input.AllocatedVisitCount}, &event, tx); err != nil { - return err - } - } else if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCSeries { - // Insert Soapi - if err = us.CreateBulkData(createSoapi, data.Id, &event, tx); err != nil { - return err - } - } - - case ere.ECEmergency: - emerCreate := ee.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCode.(ere.EmergencyClassCode), - } - _, err = ue.CreateData(emerCreate, &event, tx) - if err != nil { - return err - } - case ere.ECInpatient: - inpCreate := ei.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCode.(ere.InpatientClassCode), - Infra_Id: input.Infra_Id, - } - _, err = ui.CreateData(inpCreate, &event, tx) - if err != nil { - return err - } - default: - return errors.New("invalid encounter class code") + // insert ambulatory/emergency/inpatient + err = insertdataClassCode(input, recentSoapiDataforCopy, &event, tx) + if err != nil { + return err } // insert adm_employee_hist if _, err := uaeh.CreateData(eaeh.CreateDto{ - Encounter_Id: &data.Main.Id, + Encounter_Id: &data.Id, Employee_Id: data.Adm_Employee_Id, StartedAt: &now}, &event, tx); err != nil { return err @@ -441,7 +363,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { } func CheckOut(input e.DischargeDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Ambulatory"} + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Ambulatory,Rehab"} var data *e.Encounter var err error @@ -471,10 +393,16 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) { // validate if soapi exist - err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-out") - if err != nil { + if err = getSoapiByTypeCode(data, &event, "check-out"); err != nil { return err } + + if data.Ambulatory.Class_Code == ere.ACCRehab { + // verify and update rehabData if visit count has reached the allowed limit + if err = verifyRehabLimit(data, &event, tx); err != nil { + return err + } + } } else { // chemo TBC if err := checkSoapiByDocExists(data.Id, &event, tx); err != nil { @@ -497,26 +425,20 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { } // update finishedAt in latest responsible_doctor_hist - if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, StartedAt: &now}, &event, tx); err != nil { + if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil { return err } // update finishedAt in latest adm_employee_hist - if err = updateLatestAdmEmployeeHist(e.CheckinDto{Id: input.Id, StartedAt: &now}, &event, tx); err != nil { + if err = updateLatestAdmEmployeeHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil { return err } - switch *input.Discharge_Method_Code { - case ere.DMCDeath: - // insert data death-cause + // insert data death-cause + if *input.Discharge_Method_Code == ere.DMCDeath { if _, err = udc.CreateData(edc.CreateDto{Encounter_Id: &input.Id, Value: input.DeathCause}, &event, tx); err != nil { return err } - case ere.DMCConsulPoly, ere.DMCConsulExecutive: - // bulk insert internal-references - if err = createInternalReferences(input, &event, tx); err != nil { - return err - } } pl.SetLogInfo(&event, nil, "complete") @@ -645,25 +567,25 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { // validate if soapi exist if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) { - err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-in") + err = getSoapiByTypeCode(data, &event, "check-in") if err != nil { return err } } - // Insert responsible_doctor_hist if responsible_doctor_id has changed && update latest history - if data.Responsible_Doctor_Id == nil || *input.Responsible_Doctor_Id != *data.Responsible_Doctor_Id { + // Upsert responsible_doctor_hist if responsible_doctor_id has changed + if data.Responsible_Doctor_Code == nil || *input.Responsible_Doctor_Code != *data.Responsible_Doctor_Code { // upsert responsibleDoctorHist if err = upsertResponsibleDoctorHist(erdh.CreateDto{ Encounter_Id: &data.Id, - Doctor_Id: input.Responsible_Doctor_Id, + Doctor_Code: input.Responsible_Doctor_Code, StartedAt: input.StartedAt, }, &event, tx); err != nil { return err } } - // Insert adm_employee_hist if adm_employee_id has changed && update latest history + // Upsert adm_employee_hist if adm_employee_id has changed if input.Adm_Employee_Id != nil && *input.Adm_Employee_Id != *data.Adm_Employee_Id { // upsert admEmployeeHist if err = upsertAdmEmployeeHist(eaeh.CreateDto{ @@ -680,15 +602,6 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { return err } - if data.Ambulatory.Class_Code == ere.ACCRehab { - if err := updateRehabDoctor(er.UpdateDto{CreateDto: er.CreateDto{ - Encounter_Id: &data.Id, - Doctor_Id: input.Responsible_Doctor_Id, - }}, &event, tx); err != nil { - return err - } - } - pl.SetLogInfo(&event, nil, "complete") return nil @@ -708,43 +621,205 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { }, nil } -func validateForeignKey(input e.CheckinDto) error { - // validate employee_Id - if input.Adm_Employee_Id != nil { - if _, err := uem.ReadDetail(eem.ReadDetailDto{Id: uint16(*input.Adm_Employee_Id)}); err != nil { +func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"} + var data *e.Encounter + var err error + + event := pl.Event{ + Feature: "RequestSwitchUnit", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "checkOut") + + unitCodes := make(map[string]struct{}) + doctorCodes := make(map[string]struct{}) + for _, ref := range *input.InternalReferences { + if ref.Unit_Code != nil { + unitCodes[*ref.Unit_Code] = struct{}{} + } + if ref.Doctor_Code != nil { + doctorCodes[*ref.Doctor_Code] = struct{}{} + } + } + + // validate unit + if err = validateUnitCodes(unitCodes, &event); err != nil { + return nil, err + } + + // validate doctor + if err = validateDoctorCodes(doctorCodes, &event); err != nil { + return nil, err + } + + 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 } - } - // validate doctor_id - if input.Responsible_Doctor_Id != nil { - if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Responsible_Doctor_Id)}); err != nil { + //if data.IsDone() { + // event.Status = "failed" + // event.ErrInfo = pl.ErrorInfo{ + // Code: "data-state-mismatch", + // Detail: "encounter is done", + // Raw: errors.New("encounter is done"), + // } + // return pl.SetLogError(&event, input) + //} + + // verify Soapi exist for current responsible doctor + dataSoapi, err := getSoapiByResponsibleDoctor(*data, &event) + if err != nil { return err } + if len(dataSoapi) < 1 { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "missing-soapi", + Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"), + } + return pl.SetLogError(&event, input) + } + + // bulk internal references + if err := uir.CreateBulkData(*input.InternalReferences, input.Id, &event, tx); err != nil { + return err + } + + pl.SetLogInfo(&event, nil, "complete") + return nil + }) + + if err != nil { + return nil, err } - return nil + return &d.Data{ + Meta: d.IS{ + "source": source, + "structure": "single-data", + "status": "requestSwitchUnit", + }, + Data: data.ToResponse(), + }, nil } -func verifyClassCode(input e.CreateDto) (subCode interface{}, err error) { - switch input.Class_Code { - case ere.ECAmbulatory: - subCode, err = ua.CheckClassCode(input.SubClass_Code) - if err != nil { - return nil, err - } - case ere.ECEmergency: - subCode, err = ue.CheckClassCode(input.SubClass_Code) - if err != nil { - return nil, err - } - case ere.ECInpatient: - subCode, err = ui.CheckClassCode(input.SubClass_Code) - if err != nil { - return nil, err - } - default: - return nil, errors.New("invalid encounter class code") +func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) { + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"} + var data *e.Encounter + var err error + + event := pl.Event{ + Feature: "ApproveSwitchUnit", + Source: source, } - return + + // Start log + pl.SetLogInfo(&event, input, "started", "approveSwitchUnit") + + 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 + } + + // get internal reference + irData, err := uir.ReadDetailData(eir.ReadDetailDto{ + Id: input.InternalReferences_Id, Includes: "Doctor"}, &event, tx) + if err != nil { + return err + } + + if *irData.Status_Code != erc.DACNew { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-state-mismatch", + Detail: "internal references is approve", + Raw: errors.New("internal references is approve"), + } + return pl.SetLogError(&event, input) + } + + //if data.IsDone() { + // event.Status = "failed" + // event.ErrInfo = pl.ErrorInfo{ + // Code: "data-state-mismatch", + // Detail: "encounter is done", + // Raw: errors.New("encounter is done"), + // } + // return pl.SetLogError(&event, input) + //} + + // verify Soapi exist for current responsible doctor + dataSoapi, err := getSoapiByResponsibleDoctor(*data, &event) + if err != nil { + return err + } + if len(dataSoapi) < 1 { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "missing-soapi", + Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"), + } + return pl.SetLogError(&event, input) + } + + // update internal reference + if err = uir.UpdateData(eir.UpdateDto{ + Id: input.InternalReferences_Id, + CreateDto: eir.CreateDto{ + Encounter_Id: &input.Id, + Doctor_Code: irData.Doctor_Code, + Unit_Code: irData.Unit_Code, + Status_Code: erc.DACApproved, + }}, irData, &event, tx); err != nil { + return err + } + + // update encounter + if err = updateEncounterApproveSwitchUnit(*irData, &event, tx); err != nil { + return err + } + + // update latest responsible doctor hist + if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil { + return err + } + + // create responsible doctor based on internal reference data + if _, err = urdh.CreateData(erdh.CreateDto{ + Encounter_Id: &input.Id, + Doctor_Code: irData.Doctor_Code, + StartedAt: &now, + }, &event, tx); err != nil { + return err + } + + // update data response + data.Responsible_Doctor_Code = irData.Doctor_Code + data.Unit = irData.Unit // TODO: check if this is correct + data.Specialist_Code = irData.Doctor.Specialist_Code + data.Subspecialist_Code = irData.Doctor.Subspecialist_Code + + pl.SetLogInfo(&event, nil, "complete") + 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 + } diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 67cef58b..1e86121f 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -10,6 +10,8 @@ import ( "strings" "time" + authhelper "simrs-vx/internal/lib/auth" + dg "github.com/karincake/apem/db-gorm-pg" "gorm.io/gorm" @@ -23,9 +25,13 @@ import ( eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist" ea "simrs-vx/internal/domain/main-entities/ambulatory" + ec "simrs-vx/internal/domain/main-entities/chemo" edo "simrs-vx/internal/domain/main-entities/device-order" ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/emergency" + eem "simrs-vx/internal/domain/main-entities/employee" e "simrs-vx/internal/domain/main-entities/encounter" + ei "simrs-vx/internal/domain/main-entities/inpatient" emo "simrs-vx/internal/domain/main-entities/material-order" emco "simrs-vx/internal/domain/main-entities/mcu-order" em "simrs-vx/internal/domain/main-entities/medication" @@ -36,19 +42,26 @@ import ( epi "simrs-vx/internal/domain/main-entities/prescription-item" er "simrs-vx/internal/domain/main-entities/rehab" erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" + es "simrs-vx/internal/domain/main-entities/soapi" eu "simrs-vx/internal/domain/main-entities/unit" // udo "simrs-vx/internal/use-case/main-use-case/device-order" - es "simrs-vx/internal/domain/main-entities/soapi" uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist" - uir "simrs-vx/internal/use-case/main-use-case/internal-reference" + ua "simrs-vx/internal/use-case/main-use-case/ambulatory" + uc "simrs-vx/internal/use-case/main-use-case/chemo" + ud "simrs-vx/internal/use-case/main-use-case/doctor" + ue "simrs-vx/internal/use-case/main-use-case/emergency" + uem "simrs-vx/internal/use-case/main-use-case/employee" + ui "simrs-vx/internal/use-case/main-use-case/inpatient" um "simrs-vx/internal/use-case/main-use-case/medication" umei "simrs-vx/internal/use-case/main-use-case/medication-item" umi "simrs-vx/internal/use-case/main-use-case/medicine-mix" ummi "simrs-vx/internal/use-case/main-use-case/medicine-mix-item" up "simrs-vx/internal/use-case/main-use-case/prescription" upi "simrs-vx/internal/use-case/main-use-case/prescription-item" + ur "simrs-vx/internal/use-case/main-use-case/rehab" urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist" + us "simrs-vx/internal/use-case/main-use-case/soapi" ) func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { @@ -63,18 +76,18 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { data.Patient_Id = inputSrc.Patient_Id data.RegisteredAt = inputSrc.RegisteredAt data.Class_Code = inputSrc.Class_Code - data.Unit_Id = inputSrc.Unit_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Unit_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code data.VisitDate = inputSrc.VisitDate data.PaymentMethod_Code = inputSrc.PaymentMethod_Code - data.InsuranceCompany_Id = inputSrc.InsuranceCompany_Id + data.InsuranceCompany_Code = inputSrc.InsuranceCompany_Code data.Member_Number = inputSrc.Member_Number data.Ref_Number = inputSrc.Ref_Number data.Trx_Number = inputSrc.Trx_Number - data.Appointment_Doctor_Id = inputSrc.Appointment_Doctor_Id + data.Appointment_Doctor_Code = inputSrc.Appointment_Doctor_Code data.Adm_Employee_Id = inputSrc.Adm_Employee_Id - data.Responsible_Doctor_Id = inputSrc.Responsible_Doctor_Id + data.Responsible_Doctor_Code = inputSrc.Responsible_Doctor_Code data.RefSource_Name = inputSrc.RefSource_Name data.Appointment_Id = inputSrc.Appointment_Id data.Status_Code = erc.DSCProcess @@ -83,11 +96,11 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { } func setDataUpdate(src e.UpdateDto, dst *e.Encounter) { - dst.Appointment_Doctor_Id = src.Appointment_Doctor_Id - dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id - dst.Unit_Id = src.Unit_Id - dst.Specialist_Id = src.Specialist_Id - dst.Subspecialist_Id = src.Subspecialist_Id + dst.Appointment_Doctor_Code = src.Appointment_Doctor_Code + dst.Responsible_Doctor_Code = src.Responsible_Doctor_Code + dst.Unit_Code = src.Unit_Code + dst.Specialist_Code = src.Specialist_Code + dst.Subspecialist_Code = src.Subspecialist_Code dst.VisitDate = src.VisitDate } @@ -104,6 +117,19 @@ func setDataDischarge(src e.DischargeDto, dst *e.Encounter) { dst.FinishedAt = &now } +func setDataUpdateStatus(src e.UpdateStatusDto, dst *e.Encounter) { + dst.Status_Code = src.StatusCode +} + +func setDataCheckIn(src e.CheckinDto, dst *e.Encounter) { + if src.Adm_Employee_Id != nil { + dst.Adm_Employee_Id = src.Adm_Employee_Id + } + + dst.Responsible_Doctor_Code = src.Responsible_Doctor_Code + dst.StartedAt = src.StartedAt +} + func checkSoapiByDocExists(encounter_id uint, event *pl.Event, tx *gorm.DB) error { pl.SetLogInfo(event, nil, "started", "checkSoapiByDocExists") var soapies []es.Soapi @@ -335,113 +361,6 @@ func getMcuOrders(encounter_id uint, event *pl.Event, tx *gorm.DB) error { return nil } -func setDataUpdateStatus(src e.UpdateStatusDto, dst *e.Encounter) { - dst.Status_Code = src.StatusCode -} - -func setDataCheckIn(src e.CheckinDto, dst *e.Encounter) { - if src.Adm_Employee_Id != nil { - dst.Adm_Employee_Id = src.Adm_Employee_Id - } - - dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id - dst.StartedAt = src.StartedAt -} - -func createInternalReferences(input e.DischargeDto, event *pl.Event, tx *gorm.DB) error { - unitIDs := make(map[uint16]struct{}) - doctorIDs := make(map[uint]struct{}) - - for _, ref := range *input.InternalReferences { - if ref.Unit_Id != nil { - unitIDs[*ref.Unit_Id] = struct{}{} - } - if ref.Doctor_Id != nil { - doctorIDs[*ref.Doctor_Id] = struct{}{} - } - } - - // validate unitIds - if len(unitIDs) > 0 { - var ids []uint16 - for id := range unitIDs { - ids = append(ids, id) - } - - units, err := getUnits(ids, event, tx) - if err != nil { - return fmt.Errorf("failed to fetch units: %w", err) - } - if len(units) != len(ids) { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-validation-fail", - Detail: "unit_id not found", - } - return pl.SetLogError(event, nil) - } - } - - // validate doctorIds - if len(doctorIDs) > 0 { - var ids []uint - for id := range doctorIDs { - ids = append(ids, id) - } - - doctors, err := getDoctors(ids, event, tx) - if err != nil { - return fmt.Errorf("failed to fetch doctors: %w", err) - } - if len(doctors) != len(ids) { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-validation-fail", - Detail: "doctor_id not found", - } - return pl.SetLogError(event, nil) - } - } - - if err := uir.CreateBulkData(*input.InternalReferences, input.Id, event, tx); err != nil { - return err - } - - return nil -} - -func getUnits(unitIds []uint16, event *pl.Event, tx *gorm.DB) ([]eu.Unit, error) { - pl.SetLogInfo(event, nil, "started", "getUnits") - var units []eu.Unit - err := tx.Where("\"Id\" IN ?", unitIds).Find(&units).Error - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-get-fail", - Detail: "get units", - Raw: err, - } - return nil, pl.SetLogError(event, nil) - } - return units, nil -} - -func getDoctors(doctorIds []uint, event *pl.Event, tx *gorm.DB) ([]ed.Doctor, error) { - pl.SetLogInfo(event, nil, "started", "getDoctors") - var doctors []ed.Doctor - err := tx.Where("\"Id\" IN ?", doctorIds).Find(&doctors).Error - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-get-fail", - Detail: "get doctors", - Raw: err, - } - return nil, pl.SetLogError(event, nil) - } - return doctors, nil -} - func upsertResponsibleDoctorHist(input erdh.CreateDto, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, nil, "started", "DBCreate") @@ -476,9 +395,9 @@ func upsertResponsibleDoctorHist(input erdh.CreateDto, event *pl.Event, dbx ...* default: // Update if err := tx.Model(&latest).Updates(map[string]interface{}{ - "Doctor_Id": input.Doctor_Id, - "StartedAt": input.StartedAt, - "UpdatedAt": time.Now(), + "Doctor_Code": input.Doctor_Code, + "StartedAt": input.StartedAt, + "UpdatedAt": time.Now(), }).Error; err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -566,7 +485,7 @@ func updateLatestResponsibleDoctorHist(input e.CheckinDto, event *pl.Event, dbx result := tx. Model(&erdh.ResponsibleDoctorHist{}). Where("\"Id\" = (?)", subQuery). - Update("\"FinishedAt\"", input.StartedAt) + Update("\"FinishedAt\"", input.FinishedAt) if result.Error != nil { event.Status = "failed" @@ -607,7 +526,7 @@ func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*go result := tx. Model(&eaeh.AdmEmployeeHist{}). Where("\"Id\" = (?)", subQuery). - Update("\"FinishedAt\"", input.StartedAt) + Update("\"FinishedAt\"", input.FinishedAt) if result.Error != nil { event.Status = "failed" @@ -628,9 +547,7 @@ func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*go return nil } -func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) { - var data []es.Soapi - +func getSoapiByResponsibleDoctor(enc e.Encounter, event *pl.Event) (data []es.Soapi, err error) { pl.SetLogInfo(event, enc, "started", "DBReadList") if enc.Responsible_Doctor == nil { @@ -642,6 +559,7 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea } err = dg.I. + Debug(). Model(&es.Soapi{}). Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). Where("\"Encounter_Id\" = ?", enc.Id). @@ -653,21 +571,22 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea if err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ - Raw: err, + Raw: err, + Code: "read-fail", + Detail: "Database read failed", } - - if errors.Is(err, gorm.ErrRecordNotFound) { - event.ErrInfo.Code = "data-not-found" - event.ErrInfo.Detail = "Data not found" - return nil, pl.SetLogError(event, enc) - } - - event.ErrInfo.Code = "read-fail" - event.ErrInfo.Detail = "Database read failed" return nil, pl.SetLogError(event, enc) } pl.SetLogInfo(event, nil, "complete") + return +} + +func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) { + data, err := getSoapiByResponsibleDoctor(enc, event) + if err != nil { + return nil, err + } for _, s := range data { // set data soapi for copy @@ -690,39 +609,46 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea return } -func getSoapiByTypeCode(encounterId uint, dataAmbulatory ea.Ambulatory, event *pl.Event, mode string) (err error) { - pl.SetLogInfo(event, encounterId, "started", "DBReadList") +func getSoapiByTypeCode(encounter *e.Encounter, event *pl.Event, mode string) (err error) { + pl.SetLogInfo(event, encounter, "started", "DBReadList") var ( dataSoapi []es.Soapi + amb = encounter.Ambulatory + rehab = encounter.Rehab ) // Set Query for get data Soapi tx := dg.I. Model(&es.Soapi{}). Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). - Where("\"Encounter_Id\" = ?", encounterId). + Where("\"Encounter_Id\" = ?", encounter.Id). Where("\"Employee\".\"Position_Code\" = ?", erg.EPCDoc) // Set Case switch { - case dataAmbulatory.Class_Code == ere.ACCReg: + case amb.Class_Code == ere.ACCReg: tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEEarlyMedic) - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCAdm: tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab}) - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCSeries: tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEarlyRehab) } if err = tx.Find(&dataSoapi).Error; err != nil { - return setDBError(event, err, encounterId) + return setDBError(event, err, encounter) } pl.SetLogInfo(event, nil, "complete") - return validateExistedSoapi(dataSoapi, &dataAmbulatory, event, mode) + return validateExistedSoapi(dataSoapi, encounter, event, mode) } -func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, event *pl.Event, mode string) error { +func validateExistedSoapi(dataSoapi []es.Soapi, dataEncounter *e.Encounter, event *pl.Event, mode string) error { + var ( + amb = dataEncounter.Ambulatory + rehab = dataEncounter.Rehab + ) + typeExist := make(map[ercl.SoapiTypeCode]bool) for _, s := range dataSoapi { typeExist[s.TypeCode] = true @@ -731,11 +657,11 @@ func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, e required := []ercl.SoapiTypeCode{} switch { - case dataAmbulatory.Class_Code == ere.ACCReg: + case amb.Class_Code == ere.ACCReg: required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic} - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCAdm: required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab} - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCSeries: required = []ercl.SoapiTypeCode{ercl.STCEarlyRehab} } @@ -762,6 +688,231 @@ func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, e return nil } +func identifyPatientStatus(input e.CreateDto) (isNewPatient bool, err error) { + dataPatient, err := ReadList(e.ReadListDto{ + FilterDto: e.FilterDto{Patient_Id: input.Patient_Id}, + AuthInfo: authhelper.AuthInfo{User_Id: input.User_Id}}) + if err != nil { + return + } + + if list, ok := dataPatient.Data.([]e.ResponseDto); ok { + if len(list) < 1 { + isNewPatient = true + } + } + + return +} + +func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl.Event) (ere.VisitModeCode, *e.Encounter, error) { + var ( + visitModeCode ere.VisitModeCode + recentAdmEncounterData e.Encounter + isQuotaValid bool + err error + ) + + switch *recentRehabData.Status_Code { + case erc.DSCProcess: + visitModeCode = ere.VMCSeries + + // verify whether the allocated visit count has not exceeded the limit + recentAdmEncounterData, isQuotaValid, err = verifyAllocatedVisitCount(input, event) + if err != nil { + return "", nil, err + } + + if !isQuotaValid || recentRehabData.ExpiredAt.Before(*pu.GetTimeNow()) { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "visit-limit-exceeded", + Detail: "Encounter has exceeded the allowed number of visits or expired", + Raw: errors.New("visit count exceeds allowed limit"), + } + return "", nil, pl.SetLogError(event, input) + } + + case erc.DSCDone: + visitModeCode = ere.VMCAdm + + default: + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "invalid-status", + Detail: fmt.Sprintf("Unknown rehab status: %v", *recentRehabData.Status_Code), + Raw: errors.New("unsupported rehab status"), + } + return "", nil, pl.SetLogError(event, input) + } + + return visitModeCode, &recentAdmEncounterData, nil +} + +func insertdataClassCode(input e.CreateDto, soapiData []es.CreateDto, event *pl.Event, tx *gorm.DB) (err error) { + switch input.Class_Code { + case ere.ECAmbulatory: + subCode := ere.AmbulatoryClassCode(*input.SubClass_Code) + ambCreate := ea.CreateDto{ + Encounter_Id: &input.Id, + Class_Code: subCode, + } + + // create data Ambulatory + _, err = ua.CreateData(ambCreate, event, tx) + if err != nil { + return err + } + + // insert chemo/rehab + err = insertDataSubClassAmbulatory(input, soapiData, event, tx) + if err != nil { + return err + } + + case ere.ECEmergency: + subCode := ere.EmergencyClassCode(*input.SubClass_Code) + emerCreate := ee.CreateDto{ + Encounter_Id: &input.Id, + Class_Code: subCode, + } + + // create data emergency + _, err = ue.CreateData(emerCreate, event, tx) + if err != nil { + return err + } + case ere.ECInpatient: + subCode := ere.InpatientClassCode(*input.SubClass_Code) + inpCreate := ei.CreateDto{ + Encounter_Id: &input.Id, + Class_Code: subCode, + Infra_Code: input.Infra_Code, + } + + // create data inpatient + _, err = ui.CreateData(inpCreate, event, tx) + if err != nil { + return err + } + default: + return errors.New("invalid encounter class code") + } + + return +} + +func insertDataSubClassAmbulatory(input e.CreateDto, soapiData []es.CreateDto, event *pl.Event, tx *gorm.DB) (err error) { + subCode := ere.AmbulatoryClassCode(*input.SubClass_Code) + + switch { + case subCode == ere.ACCChemo: + chemoCreate := ec.CreateDto{ + Encounter_Id: &input.Id, + Status_Code: erc.DVCNew, + SrcUnit_Code: input.Unit_Code, + } + + // create data chemo + _, err = uc.CreateData(chemoCreate, event, tx) + if err != nil { + return err + } + + case subCode == ere.ACCRehab: + rehabData := er.CreateDto{ + Encounter_Id: &input.Id, + VisitMode_Code: input.VisitMode_Code, + Status_Code: erc.DSCProcess, + } + + // if visitMode_code is series, then bulk insert soapi + if input.VisitMode_Code == ere.VMCSeries { + rehabData.Parent_Encounter_Id = &input.RecentEncounterAdm.Id + + // Insert Soapi + if err = us.CreateBulkData(soapiData, input.Id, event, tx); err != nil { + return err + } + } + + // create rehab + if _, err = ur.CreateData(rehabData, event, tx); err != nil { + return err + } + } + + return +} + +func verifyRehabLimit(data *e.Encounter, event *pl.Event, tx *gorm.DB) error { + // get data encounter adm + encounterAdmData, _, err := verifyAllocatedVisitCount(e.CreateDto{Patient_Id: data.Patient_Id}, event) + if err != nil { + return err + } + + // Check if the visit count has reached the allowed limit + // Mark latest rehab status as 'done' if exceeded. + if len(*encounterAdmData.RehabChildren) >= *encounterAdmData.Rehab.AllocatedVisitCount { + err = updateRehabStatus(er.UpdateDto{ + Id: uint16(data.Rehab.Id), + CreateDto: er.CreateDto{Status_Code: erc.DSCDone}}, event, tx) + if err != nil { + return err + } + } + + return nil +} + +func updateRehabStatus(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, "started", "DBUpdate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + result := tx. + Model(&er.Rehab{}). + Where("\"Id\" = (?)", input.Id). + Update("\"Status_Code\"", input.Status_Code) + + if result.Error != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-update-fail", + Detail: "Database update failed", + Raw: result.Error, + } + return pl.SetLogError(event, input) + } + + pl.SetLogInfo(event, nil, "complete") + return nil +} + +func validateForeignKey(input e.CheckinDto) error { + // validate employee_Id + if input.Adm_Employee_Id != nil { + if _, err := uem.ReadDetail(eem.ReadDetailDto{Id: uint16(*input.Adm_Employee_Id)}); err != nil { + return err + } + } + + // validate doctor_id + if input.Responsible_Doctor_Code != nil { + if _, err := ud.ReadDetail(ed.ReadDetailDto{Code: input.Responsible_Doctor_Code}); err != nil { + return err + } + } + + return nil +} + func setSoapiError(event *pl.Event, detail string) error { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -781,31 +932,82 @@ func setDBError(event *pl.Event, err error, ctx any) error { return pl.SetLogError(event, ctx) } -func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { - pl.SetLogInfo(event, "started", "DBUpdate") - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - result := tx. - Model(&er.Rehab{}). - Where("\"Encounter_Id\" = (?)", input.Encounter_Id). - Update("\"Doctor_Id\"", input.Doctor_Id) - - if result.Error != nil { +func getUnits(unitIds []string, event *pl.Event) ([]eu.Unit, error) { + pl.SetLogInfo(event, nil, "started", "getUnits") + var units []eu.Unit + err := dg.I.Where("\"Code\" IN ?", unitIds).Find(&units).Error + if err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ - Code: "data-update-fail", - Detail: "Database update failed", - Raw: result.Error, + Code: "data-get-fail", + Detail: "get units", + Raw: err, + } + return nil, pl.SetLogError(event, nil) + } + return units, nil +} + +func getDoctors(doctorIds []string, event *pl.Event) ([]ed.Doctor, error) { + pl.SetLogInfo(event, nil, "started", "getDoctors") + var doctors []ed.Doctor + err := dg.I.Where("\"Id\" Code ?", doctorIds).Find(&doctors).Error + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-get-fail", + Detail: "get doctors", + Raw: err, + } + return nil, pl.SetLogError(event, nil) + } + return doctors, nil +} + +func validateUnitCodes(unitCodes map[string]struct{}, event *pl.Event) error { + if len(unitCodes) > 0 { + var codes []string + for code := range unitCodes { + codes = append(codes, code) + } + + units, err := getUnits(codes, event) + if err != nil { + return fmt.Errorf("failed to fetch units: %w", err) + } + if len(units) != len(codes) { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-validation-fail", + Detail: "unit_id not found", + } + return pl.SetLogError(event, nil) + } + } + + return nil +} + +func validateDoctorCodes(doctorCodes map[string]struct{}, event *pl.Event) error { + if len(doctorCodes) > 0 { + var codes []string + for code := range doctorCodes { + codes = append(codes, code) + } + + doctors, err := getDoctors(codes, event) + if err != nil { + return fmt.Errorf("failed to fetch doctors: %w", err) + } + if len(doctors) != len(codes) { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-validation-fail", + Detail: "doctor_id not found", + } + return pl.SetLogError(event, nil) } - return pl.SetLogError(event, input) } - pl.SetLogInfo(event, nil, "complete") return nil } diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 18a632c3..840fefac 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -3,7 +3,7 @@ package encounter import ( // std "errors" - ere "simrs-vx/internal/domain/references/encounter" + eir "simrs-vx/internal/domain/main-entities/internal-reference" // external dg "github.com/karincake/apem/db-gorm-pg" @@ -15,9 +15,14 @@ import ( pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" + ere "simrs-vx/internal/domain/references/encounter" + e "simrs-vx/internal/domain/main-entities/encounter" + er "simrs-vx/internal/domain/main-entities/rehab" ) +const ErrorReadFailed = "Database read failed" + func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Encounter, error) { pl.SetLogInfo(event, nil, "started", "DBCreate") @@ -251,20 +256,49 @@ func updateCheckInData(input e.CheckinDto, data *e.Encounter, event *pl.Event, d return nil } +func getLatestRehabData(i e.CreateDto, event *pl.Event) (recentRehabData *er.Rehab, err error) { + pl.SetLogInfo(event, nil, "started", "DBGetLatestRehab") + + var ( + tx = dg.I + ) + + err = tx. + Joins("JOIN \"Encounter\" ON \"Encounter\".\"Id\" = \"Rehab\".\"Encounter_Id\""). + Where("\"Encounter\".\"Patient_Id\" = ?", i.Patient_Id). + Order("\"CreatedAt\" DESC"). + First(&recentRehabData).Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, nil + } + + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "read-recentRehab-fail", + Detail: ErrorReadFailed, + Raw: err, + } + return nil, pl.SetLogError(event, i) + } + + return +} + func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, bool, error) { pl.SetLogInfo(event, nil, "started", "DBGetRecentEncounterAdm") var ( - tx = dg.I - recentEncounterAdm e.Encounter - countEncounterSeries int64 + tx = dg.I + recentEncounterAdm e.Encounter + valid = true ) err := tx. - Scopes(gh.Preload("Rehab,Responsible_Doctor")). - Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). - Where("\"Patient_Id\" = ?", i.Patient_Id). - Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCAdm). + Scopes(gh.Preload("RehabChildren,Rehab,Responsible_Doctor")). + Joins("JOIN \"Rehab\" ON \"Rehab\".\"Encounter_Id\" = \"Encounter\".\"Id\""). + Where("\"Encounter\".\"Patient_Id\" = ?", i.Patient_Id). + Where("\"Rehab\".\"VisitMode_Code\" = ?", ere.VMCAdm). Order("\"CreatedAt\" DESC"). First(&recentEncounterAdm).Error if err != nil { @@ -277,22 +311,41 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo return e.Encounter{}, false, pl.SetLogError(event, i) } - err = tx. - Model(&e.Encounter{}). - Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). - Where("\"Patient_Id\" = ?", i.Patient_Id). - Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCSeries). - Where("\"Encounter\".\"CreatedAt\" > ?", recentEncounterAdm.CreatedAt). - Count(&countEncounterSeries).Error - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "read-countEncounter-fail", - Detail: "Database read failed", - Raw: err, - } - return e.Encounter{}, false, pl.SetLogError(event, i) + // validate count rehab children + if recentEncounterAdm.RehabChildren != nil { + valid = len(*recentEncounterAdm.RehabChildren) < *recentEncounterAdm.Rehab.AllocatedVisitCount } - return recentEncounterAdm, countEncounterSeries < int64(*recentEncounterAdm.Rehab.AllocatedVisitCount), nil + return recentEncounterAdm, valid, nil +} + +func updateEncounterApproveSwitchUnit(input eir.InternalReference, event *pl.Event, dbx ...*gorm.DB) (err error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if err := tx.Model(&e.Encounter{}). + Where("\"Id\" = ?", input.Encounter_Id). + Updates(map[string]interface{}{ + "Responsible_Doctor_Code": input.Doctor_Code, + "Unit_Code": input.Unit_Code, + "Specialist_Code": input.Doctor.Specialist_Code, + "Subspecialist_Code": input.Doctor.Subspecialist_Code, + }).Error; err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "update-fail", + Detail: "Failed to update encounter approve switch unit", + Raw: err, + } + return pl.SetLogError(event, input) + } + + pl.SetLogInfo(event, input, "complete") + return nil } diff --git a/internal/use-case/main-use-case/inpatient/helper.go b/internal/use-case/main-use-case/inpatient/helper.go index 45014af1..d59ea4d8 100644 --- a/internal/use-case/main-use-case/inpatient/helper.go +++ b/internal/use-case/main-use-case/inpatient/helper.go @@ -22,6 +22,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Inpatient) { data.Encounter_Id = inputSrc.Encounter_Id data.Class_Code = inputSrc.Class_Code + data.Infra_Code = inputSrc.Infra_Code } func CheckClassCode(input *string) (ere.InpatientClassCode, error) { diff --git a/internal/use-case/main-use-case/internal-reference/helper.go b/internal/use-case/main-use-case/internal-reference/helper.go index dbd92f73..234eb770 100644 --- a/internal/use-case/main-use-case/internal-reference/helper.go +++ b/internal/use-case/main-use-case/internal-reference/helper.go @@ -6,6 +6,7 @@ package internal_reference import ( ir "simrs-vx/internal/domain/main-entities/internal-reference" + erc "simrs-vx/internal/domain/references/common" ) func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReference) { @@ -18,18 +19,21 @@ func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReferenc } data.Encounter_Id = inputSrc.Encounter_Id - data.Unit_Id = inputSrc.Unit_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Unit_Code = inputSrc.Unit_Code + data.Doctor_Code = inputSrc.Doctor_Code + data.Status_Code = &inputSrc.Status_Code } func setBulkData(input []ir.CreateDto, encounterId uint) []ir.InternalReference { var data []ir.InternalReference for _, v := range input { + statusCode := erc.DACNew data = append(data, ir.InternalReference{ Encounter_Id: &encounterId, - Unit_Id: v.Unit_Id, - Doctor_Id: v.Doctor_Id, + Unit_Code: v.Unit_Code, + Doctor_Code: v.Doctor_Code, + Status_Code: &statusCode, }) } diff --git a/internal/use-case/main-use-case/material-order-item/helper.go b/internal/use-case/main-use-case/material-order-item/helper.go index 25e89a21..f66daa0b 100644 --- a/internal/use-case/main-use-case/material-order-item/helper.go +++ b/internal/use-case/main-use-case/material-order-item/helper.go @@ -18,6 +18,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MaterialOrderItem) } data.MaterialOrder_Id = inputSrc.MaterialOrder_Id - data.Material_Id = inputSrc.Material_Id + data.Material_Code = inputSrc.Material_Code data.Count = inputSrc.Count } diff --git a/internal/use-case/main-use-case/material-order/case.go b/internal/use-case/main-use-case/material-order/case.go index 713f64c0..a6d3943c 100644 --- a/internal/use-case/main-use-case/material-order/case.go +++ b/internal/use-case/main-use-case/material-order/case.go @@ -6,7 +6,6 @@ import ( e "simrs-vx/internal/domain/main-entities/material-order" - ud "simrs-vx/internal/use-case/main-use-case/doctor" ue "simrs-vx/internal/use-case/main-use-case/encounter" erc "simrs-vx/internal/domain/references/common" @@ -56,11 +55,7 @@ func Create(input e.CreateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx) - if err != nil { - return err - } - input.Doctor_Id = doctor_id + input.Doctor_Code = input.AuthInfo.Doctor_Code if resData, err := CreateData(input, &event, tx); err != nil { return err @@ -233,12 +228,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx) - if err != nil { - return err - } - - if !data.IsSameDoctor(doctor_id) { + if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "auth-forbidden", @@ -248,7 +238,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - input.Doctor_Id = doctor_id + input.Doctor_Code = input.AuthInfo.Doctor_Code if err := UpdateData(input, data, &event, tx); err != nil { return err diff --git a/internal/use-case/main-use-case/material-order/helper.go b/internal/use-case/main-use-case/material-order/helper.go index fe0862e9..8f037f91 100644 --- a/internal/use-case/main-use-case/material-order/helper.go +++ b/internal/use-case/main-use-case/material-order/helper.go @@ -21,5 +21,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MaterialOrder) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code } diff --git a/internal/use-case/main-use-case/mcu-order/case.go b/internal/use-case/main-use-case/mcu-order/case.go index 19b34cbe..38f13088 100644 --- a/internal/use-case/main-use-case/mcu-order/case.go +++ b/internal/use-case/main-use-case/mcu-order/case.go @@ -6,7 +6,6 @@ import ( e "simrs-vx/internal/domain/main-entities/mcu-order" - ud "simrs-vx/internal/use-case/main-use-case/doctor" ue "simrs-vx/internal/use-case/main-use-case/encounter" erc "simrs-vx/internal/domain/references/common" @@ -56,11 +55,7 @@ func Create(input e.CreateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx) - if err != nil { - return err - } - input.Doctor_Id = doctor_id + input.Doctor_Code = input.AuthInfo.Doctor_Code if resData, err := CreateData(input, &event, tx); err != nil { return err @@ -233,12 +228,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx) - if err != nil { - return err - } - - if !data.IsSameDoctor(doctor_id) { + if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "auth-forbidden", @@ -248,7 +238,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - input.Doctor_Id = doctor_id + input.Doctor_Code = input.AuthInfo.Doctor_Code if err := UpdateData(input, data, &event, tx); err != nil { return err diff --git a/internal/use-case/main-use-case/mcu-order/helper.go b/internal/use-case/main-use-case/mcu-order/helper.go index 7c21f1f6..1c803f68 100644 --- a/internal/use-case/main-use-case/mcu-order/helper.go +++ b/internal/use-case/main-use-case/mcu-order/helper.go @@ -21,12 +21,11 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuOrder) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code data.SpecimenPickTime = inputSrc.SpecimenPickTime data.ExaminationDate = inputSrc.ExaminationDate data.Number = inputSrc.Number data.Temperature = inputSrc.Temperature data.UrgencyLevel_Code = inputSrc.UrgencyLevel_Code - data.Doctor_Id = inputSrc.Doctor_Id data.Scope_Code = inputSrc.Scope_Code } 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 564a582b..31af8e84 100644 --- a/internal/use-case/main-use-case/mcu-src/case.go +++ b/internal/use-case/main-use-case/mcu-src/case.go @@ -170,7 +170,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.McuSrc var err error @@ -226,7 +226,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.McuSrc var err error diff --git a/internal/use-case/main-use-case/mcu-src/helper.go b/internal/use-case/main-use-case/mcu-src/helper.go index 9d808ca8..545def25 100644 --- a/internal/use-case/main-use-case/mcu-src/helper.go +++ b/internal/use-case/main-use-case/mcu-src/helper.go @@ -27,14 +27,14 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuSrc) { inputSrc = &inputTemp.CreateDto } - data.Code = inputSrc.Code + data.Code = *inputSrc.Code data.Name = inputSrc.Name data.McuSrcCategory_Code = inputSrc.McuSrcCategory_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { itemCreate := ei.CreateDto{ - Code: pu.AddPrefix("mcu-", input.Code), + Code: pu.AddPrefix("mcu-", *input.Code), Name: input.Name, ItemGroup_Code: ero.ITGCMCU, // Uom_Code: &input.Uom_Code, @@ -45,6 +45,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } 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 e74d5ce8..d62c9282 100644 --- a/internal/use-case/main-use-case/mcu-src/lib.go +++ b/internal/use-case/main-use-case/mcu-src/lib.go @@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } - if err := tx.First(&data, input.Id).Error; err != nil { + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/mcu-sub-src/case.go b/internal/use-case/main-use-case/mcu-sub-src/case.go index ba533bc4..fbb9f468 100644 --- a/internal/use-case/main-use-case/mcu-sub-src/case.go +++ b/internal/use-case/main-use-case/mcu-sub-src/case.go @@ -170,7 +170,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.McuSubSrc var err error @@ -226,7 +226,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: input.Id} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.McuSubSrc var err error diff --git a/internal/use-case/main-use-case/mcu-sub-src/helper.go b/internal/use-case/main-use-case/mcu-sub-src/helper.go index 95444d5a..962abe46 100644 --- a/internal/use-case/main-use-case/mcu-sub-src/helper.go +++ b/internal/use-case/main-use-case/mcu-sub-src/helper.go @@ -27,15 +27,15 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuSubSrc) { inputSrc = &inputTemp.CreateDto } - data.Code = inputSrc.Code + data.Code = *inputSrc.Code data.Name = inputSrc.Name - data.McuSrc_Id = inputSrc.McuSrc_Id - data.Item_Id = inputSrc.Item_Id + data.McuSrc_Code = inputSrc.McuSrc_Code + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { itemCreate := ei.CreateDto{ - Code: pu.AddPrefix("mcuSub-", input.Code), + Code: pu.AddPrefix("mcuSub-", *input.Code), Name: input.Name, ItemGroup_Code: ero.ITGCMCUSub, // Uom_Code: &input.Uom_Code, @@ -46,6 +46,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/mcu-sub-src/lib.go b/internal/use-case/main-use-case/mcu-sub-src/lib.go index 96684fef..438eb7ac 100644 --- a/internal/use-case/main-use-case/mcu-sub-src/lib.go +++ b/internal/use-case/main-use-case/mcu-sub-src/lib.go @@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } - if err := tx.First(&data, input.Id).Error; err != nil { + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/medical-action-src-item/helper.go b/internal/use-case/main-use-case/medical-action-src-item/helper.go index 385b0f53..09d028a9 100644 --- a/internal/use-case/main-use-case/medical-action-src-item/helper.go +++ b/internal/use-case/main-use-case/medical-action-src-item/helper.go @@ -16,7 +16,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrcIte inputTemp := any(input).(*e.UpdateDto) inputSrc = &inputTemp.CreateDto } - data.MedicalActionSrc_Id = inputSrc.MedicalActionSrc_Id - data.ProcedureSrc_Id = inputSrc.ProcedureSrc_Id - data.Item_Id = inputSrc.Item_Id + data.MedicalActionSrc_Code = inputSrc.MedicalActionSrc_Code + data.ProcedureSrc_Code = inputSrc.ProcedureSrc_Code + data.Item_Code = inputSrc.Item_Code } 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 cd42766c..7ca58dde 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 @@ -169,7 +169,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.MedicalActionSrc var err error @@ -225,7 +225,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.MedicalActionSrc var err error diff --git a/internal/use-case/main-use-case/medical-action-src/helper.go b/internal/use-case/main-use-case/medical-action-src/helper.go index c955274d..910b6f8a 100644 --- a/internal/use-case/main-use-case/medical-action-src/helper.go +++ b/internal/use-case/main-use-case/medical-action-src/helper.go @@ -27,15 +27,15 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrc) { inputSrc = &inputTemp.CreateDto } - data.Code = inputSrc.Code + data.Code = *inputSrc.Code data.Name = inputSrc.Name data.Type_Code = inputSrc.Type_Code - data.Item_Id = inputSrc.Item_Id + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { itemCreate := ei.CreateDto{ - Code: pu.AddPrefix("medAct-", input.Code), + Code: pu.AddPrefix("medAct-", *input.Code), Name: input.Name, ItemGroup_Code: ero.ITGCMedAct, } @@ -44,6 +44,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } 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 31492861..dd29a6b3 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 @@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } - if err := tx.First(&data, input.Id).Error; err != nil { + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/nurse/case.go b/internal/use-case/main-use-case/nurse/case.go index 6201e15b..e7d0ce0c 100644 --- a/internal/use-case/main-use-case/nurse/case.go +++ b/internal/use-case/main-use-case/nurse/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Nurse var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Nurse var err error diff --git a/internal/use-case/main-use-case/nurse/lib.go b/internal/use-case/main-use-case/nurse/lib.go index a59cc692..e0ce8ba6 100644 --- a/internal/use-case/main-use-case/nurse/lib.go +++ b/internal/use-case/main-use-case/nurse/lib.go @@ -84,7 +84,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e if input.Employee_Id != nil { tx = tx.Where("\"Employee_Id\" = ?", *input.Employee_Id) } - if input.Id > 0 { + if input.Id != nil { tx = tx.Where("\"Id\" = ?", input.Id) } if err := tx.First(&data).Error; err != nil { diff --git a/internal/use-case/main-use-case/practice-schedule/helper.go b/internal/use-case/main-use-case/practice-schedule/helper.go index 5c9f7815..ba61b691 100644 --- a/internal/use-case/main-use-case/practice-schedule/helper.go +++ b/internal/use-case/main-use-case/practice-schedule/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PracticeSchedule) { inputSrc = &inputTemp.CreateDto } - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code data.Unit_Code = inputSrc.Unit_Code data.Day_Code = inputSrc.Day_Code data.StartTime = inputSrc.StartTime diff --git a/internal/use-case/main-use-case/rehab/helper.go b/internal/use-case/main-use-case/rehab/helper.go index 5c06ca0a..c5da08ad 100644 --- a/internal/use-case/main-use-case/rehab/helper.go +++ b/internal/use-case/main-use-case/rehab/helper.go @@ -18,6 +18,9 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Rehab) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Parent_Encounter_Id = inputSrc.Parent_Encounter_Id data.AllocatedVisitCount = inputSrc.AllocatedVisitCount + data.ExpiredAt = inputSrc.ExpiredAt + data.VisitMode_Code = &inputSrc.VisitMode_Code + data.Status_Code = &inputSrc.Status_Code } diff --git a/internal/use-case/main-use-case/responsible-doctor-hist/helper.go b/internal/use-case/main-use-case/responsible-doctor-hist/helper.go index 6efd1097..33ee9da4 100644 --- a/internal/use-case/main-use-case/responsible-doctor-hist/helper.go +++ b/internal/use-case/main-use-case/responsible-doctor-hist/helper.go @@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ResponsibleDoctorHi } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code data.StartedAt = inputSrc.StartedAt data.FinishedAt = inputSrc.FinishedAt } diff --git a/internal/use-case/main-use-case/therapy-protocol/case.go b/internal/use-case/main-use-case/therapy-protocol/case.go index 93cf05a4..bc65325f 100644 --- a/internal/use-case/main-use-case/therapy-protocol/case.go +++ b/internal/use-case/main-use-case/therapy-protocol/case.go @@ -299,9 +299,9 @@ func validateForeignKey(input e.CreateDto) error { } } - // validate doctor_id - if input.Doctor_Id != nil { - if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Doctor_Id)}); err != nil { + // validate doctor_code + if input.Doctor_Code != nil { + if _, err := ud.ReadDetail(ed.ReadDetailDto{Code: input.Doctor_Code}); err != nil { return err } } diff --git a/internal/use-case/main-use-case/therapy-protocol/helper.go b/internal/use-case/main-use-case/therapy-protocol/helper.go index 12e48747..021c89ed 100644 --- a/internal/use-case/main-use-case/therapy-protocol/helper.go +++ b/internal/use-case/main-use-case/therapy-protocol/helper.go @@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.TherapyProtocol) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code data.Anamnesis = inputSrc.Anamnesis data.MedicalDiagnoses = inputSrc.MedicalDiagnoses data.FunctionDiagnoses = inputSrc.FunctionDiagnoses