diff --git a/cmd/migration/migrations/20250903073200.sql b/cmd/migration/migrations/20250903073200.sql new file mode 100644 index 00000000..9d6923a7 --- /dev/null +++ b/cmd/migration/migrations/20250903073200.sql @@ -0,0 +1,25 @@ +-- Modify "MedicineGroup" table +ALTER TABLE "public"."MedicineGroup" ALTER COLUMN "Code" TYPE character varying(10), ALTER COLUMN "Name" TYPE character varying(50); +-- Modify "MedicineMethod" table +ALTER TABLE "public"."MedicineMethod" ALTER COLUMN "Code" TYPE character varying(10), ALTER COLUMN "Name" TYPE character varying(50); +-- Create "Encounter" table +CREATE TABLE "public"."Encounter" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Patient_Id" bigint NULL, + "RegisteredAt" timestamptz NULL, + "Class_Code" character varying(10) NOT NULL, + "Unit_Id" bigint NULL, + "VisitDate" timestamptz NULL, + "Assignment_Doctor_Id" bigint NULL, + "Responsible_Doctor_Id" bigint NULL, + "DischardeMethod_Code" character varying(10) NULL, + "RefSource_Name" character varying(100) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Encounter_Assignment_Doctor" FOREIGN KEY ("Assignment_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Patient" FOREIGN KEY ("Patient_Id") REFERENCES "public"."Patient" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Responsible_Doctor" FOREIGN KEY ("Responsible_Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Encounter_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/migration/migrations/atlas.sum b/cmd/migration/migrations/atlas.sum index 8246b576..8b56b6fa 100644 --- a/cmd/migration/migrations/atlas.sum +++ b/cmd/migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:/oxZnT+1LpkBjyeDak9iLLwckizN6WbyuPQlG7bmr+c= +h1:179RYs36FGTJB7o/kUCO3K612TUM4fbHOaI3UBdlmlU= 20250829081952.sql h1:YMsYq3uPsx70EjWSGfYnVRR5GV0q1fRGIszYZAWzXNo= 20250901073356.sql h1:jjd5TLs+Pyi0u3SrOM+aNTbHxSJboXgcOz/L4bkYx+c= 20250901080035.sql h1:LWa3X0NWjalVcxNbk5HaHj1Oqu60/AQabi0jBmCeQBI= @@ -6,4 +6,5 @@ h1:/oxZnT+1LpkBjyeDak9iLLwckizN6WbyuPQlG7bmr+c= 20250902052320.sql h1:+tWdeS4NorPj5WdKHMirBfP4EeS01wyyfdT03DBMmcI= 20250902063217.sql h1:wYFIrAIp1RczNvzlmu8jP8P1J7xEXqgDLKDUNBbkt84= 20250902105300.sql h1:6N2SDYK3a6djaO6u468E/DrDR9kM+uYoJvNlTFon6bY= -20250903041718.sql h1:9s5sfoT+RBGP5NYNafcnHWNb8nLtZ9jhYbyKKPFCK8k= +20250903041718.sql h1:ZiaacurDuBwWaI348Sjo7VZ6rSsj9TLTkudiRv05C/w= +20250903073200.sql h1:Tnxfz/3JjvrwPie2FYuhmfo5xFNeQV1lH+qbBJjpm5g= diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go new file mode 100644 index 00000000..b959fb38 --- /dev/null +++ b/internal/domain/main-entities/encounter/dto.go @@ -0,0 +1,100 @@ +package encounter + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ed "simrs-vx/internal/domain/main-entities/doctor" + ep "simrs-vx/internal/domain/main-entities/patient" + eu "simrs-vx/internal/domain/main-entities/unit" + ere "simrs-vx/internal/domain/references/encounter" + "time" +) + +type CreateDto struct { + Patient_Id *uint `json:"patient_id"` + 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"` + VisitDate time.Time `json:"visitDate"` + Assignment_Doctor_Id *uint `json:"assignment_doctor_id"` + Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` + DischardeMethod_Code ere.DischargeMethodCode `json:"dischardeMethod_code" validate:"maxLength=10"` + RefSource_Name *string `json:"refSource_name" validate:"maxLength=100"` +} + +type ReadListDto struct { + Code string `json:"code"` + Name string `json:"name"` + Parent_Id *int16 `json:"parent_id"` + + Page int `json:"page"` + PageSize int `json:"page_size"` + NoPagination int `json:"no_pagination"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` + Code string `json:"code"` + Name string `json:"name"` + Parent_Id *int16 `json:"parent_id"` +} + +type UpdateDto struct { + Id uint16 `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint16 `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Patient_Id *uint `json:"patient_id"` + Patient *ep.Patient `json:"patient,omitempty"` + RegisteredAt *time.Time `json:"registeredAt"` + Class_Code ere.EncounterClassCode `json:"class_code"` + Unit_Id *uint `json:"unit_id"` + Unit *eu.Unit `json:"unit,omitempty"` + VisitDate time.Time `json:"visitDate"` + Assignment_Doctor_Id *uint `json:"assignment_doctor_id"` + Assignment_Doctor *ed.Doctor `json:"assignment_doctor,omitempty"` + Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` + Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty"` + DischardeMethod_Code ere.DischargeMethodCode `json:"dischardeMethod_code` + RefSource_Name *string `json:"refSource_name"` +} + +func (d Encounter) ToResponse() ResponseDto { + resp := ResponseDto{ + Patient_Id: d.Patient_Id, + Patient: d.Patient, + RegisteredAt: d.RegisteredAt, + Class_Code: d.Class_Code, + Unit_Id: d.Unit_Id, + Unit: d.Unit, + VisitDate: d.VisitDate, + Assignment_Doctor_Id: d.Assignment_Doctor_Id, + Assignment_Doctor: d.Assignment_Doctor, + Responsible_Doctor_Id: d.Responsible_Doctor_Id, + Responsible_Doctor: d.Responsible_Doctor, + DischardeMethod_Code: d.DischardeMethod_Code, + RefSource_Name: d.RefSource_Name, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []Encounter) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go new file mode 100644 index 00000000..258c6354 --- /dev/null +++ b/internal/domain/main-entities/encounter/entity.go @@ -0,0 +1,27 @@ +package encounter + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ed "simrs-vx/internal/domain/main-entities/doctor" + ep "simrs-vx/internal/domain/main-entities/patient" + eu "simrs-vx/internal/domain/main-entities/unit" + ere "simrs-vx/internal/domain/references/encounter" + "time" +) + +type Encounter struct { + ecore.Main // adjust this according to the needs + Patient_Id *uint `json:"patient_id"` + 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"` + VisitDate time.Time `json:"visitDate"` + Assignment_Doctor_Id *uint `json:"assignment_doctor_id"` + Assignment_Doctor *ed.Doctor `json:"assignment_doctor,omitempty" gorm:"foreignKey:Assignment_Doctor_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"` + DischardeMethod_Code ere.DischargeMethodCode `json:"dischardeMethod_code" gorm:"size:10"` + RefSource_Name *string `json:"refSource_name" gorm:"size:100"` +} diff --git a/internal/domain/main-entities/medicine-group/entity.go b/internal/domain/main-entities/medicine-group/entity.go index 612ab3b3..5db60dda 100644 --- a/internal/domain/main-entities/medicine-group/entity.go +++ b/internal/domain/main-entities/medicine-group/entity.go @@ -6,6 +6,6 @@ import ( type MedicineGroup struct { ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:50"` - Name string `json:"name" gorm:"size:100"` + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` } diff --git a/internal/domain/main-entities/medicine-method/entity.go b/internal/domain/main-entities/medicine-method/entity.go index dde7c578..4d8865c6 100644 --- a/internal/domain/main-entities/medicine-method/entity.go +++ b/internal/domain/main-entities/medicine-method/entity.go @@ -6,6 +6,6 @@ import ( type MedicineMethod struct { ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:50"` - Name string `json:"name" gorm:"size:100"` + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` } diff --git a/internal/interface/migration/migration.go b/internal/interface/migration/migration.go index f00338bb..2f6f0d50 100644 --- a/internal/interface/migration/migration.go +++ b/internal/interface/migration/migration.go @@ -14,6 +14,7 @@ import ( doctor "simrs-vx/internal/domain/main-entities/doctor" doctorfee "simrs-vx/internal/domain/main-entities/doctor-fee" employee "simrs-vx/internal/domain/main-entities/employee" + encounter "simrs-vx/internal/domain/main-entities/encounter" ethnic "simrs-vx/internal/domain/main-entities/ethnic" infra "simrs-vx/internal/domain/main-entities/infra" installation "simrs-vx/internal/domain/main-entities/installation" @@ -125,6 +126,7 @@ func GetEntities() []any { &language.Language{}, &personrelative.PersonRelative{}, &patient.Patient{}, + &encounter.Encounter{}, } }