From d851989df2d972d06a01557e775665b45bd029f7 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Tue, 23 Sep 2025 09:51:55 +0700 Subject: [PATCH 1/2] add consultation --- .../migrations/20250923025134.sql | 17 ++++ cmd/main-migration/migrations/atlas.sum | 3 +- .../domain/main-entities/consultation/dto.go | 87 +++++++++++++++++++ .../main-entities/consultation/entity.go | 23 +++++ internal/interface/migration/main-entities.go | 2 + 5 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 cmd/main-migration/migrations/20250923025134.sql create mode 100644 internal/domain/main-entities/consultation/dto.go create mode 100644 internal/domain/main-entities/consultation/entity.go diff --git a/cmd/main-migration/migrations/20250923025134.sql b/cmd/main-migration/migrations/20250923025134.sql new file mode 100644 index 00000000..57a04744 --- /dev/null +++ b/cmd/main-migration/migrations/20250923025134.sql @@ -0,0 +1,17 @@ +-- Create "Consultation" table +CREATE TABLE "public"."Consultation" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Case" character varying(2048) NULL, + "Solution" character varying(2048) NULL, + "Unit_Id" bigint NULL, + "Doctor_Id" bigint NULL, + "RepliedAt" timestamptz NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Consultation_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Consultation_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Consultation_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 59829316..e61e9880 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:ZD6tpr1oc81DWrZLIE3ZVmvnBpU7r6Nlet5N489jJVk= +h1:0Hvo3AS2yMsS60eDIKnU5B2qvjDhNWHSDHcMxKKYJTk= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -15,3 +15,4 @@ h1:ZD6tpr1oc81DWrZLIE3ZVmvnBpU7r6Nlet5N489jJVk= 20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= 20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= 20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= +20250923025134.sql h1:q1bndJguAqjnTjXr6Jpnsrj4d8zMseR2tf02h0h6ArE= diff --git a/internal/domain/main-entities/consultation/dto.go b/internal/domain/main-entities/consultation/dto.go new file mode 100644 index 00000000..7cac88dd --- /dev/null +++ b/internal/domain/main-entities/consultation/dto.go @@ -0,0 +1,87 @@ +package consultation + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/encounter" + eu "simrs-vx/internal/domain/main-entities/unit" + "time" +) + +type CreateDto struct { + Encounter_Id *uint `json:"encounter_id"` + Case *string `json:"case" validate:"maxLength=2048"` + Unit_Id *uint `json:"unit_id"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Preloads []string `json:"-"` +} + +type FilterDto struct { + Encounter_Id *uint `json:"encounter_id"` + Unit_Id *uint `json:"unit_id"` + Doctor_Id *uint `json:"doctor_id"` + + Page int `json:"page"` + PageSize int `json:"page_size"` + NoPagination int `json:"no_pagination"` +} + +type ReadDetailDto struct { + Id uint16 `json:"id"` +} + +type UpdateDto struct { + Id uint `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Case *string `json:"case"` + Solution *string `json:"solution"` + Unit_Id *uint `json:"unit_id"` + Unit *eu.Unit `json:"unit,omitempty"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + RepliedAt *time.Time `json:"repliedAt"` +} + +func (d Consultation) ToResponse() ResponseDto { + resp := ResponseDto{ + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Case: d.Case, + Solution: d.Solution, + Unit_Id: d.Unit_Id, + Unit: d.Unit, + Doctor_Id: d.Doctor_Id, + Doctor: d.Doctor, + RepliedAt: d.RepliedAt, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []Consultation) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/consultation/entity.go b/internal/domain/main-entities/consultation/entity.go new file mode 100644 index 00000000..68ad37f2 --- /dev/null +++ b/internal/domain/main-entities/consultation/entity.go @@ -0,0 +1,23 @@ +package consultation + +import ( + "time" + + ecore "simrs-vx/internal/domain/base-entities/core" + ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/encounter" + eu "simrs-vx/internal/domain/main-entities/unit" +) + +type Consultation 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"` + Case *string `json:"case" gorm:"size:2048"` + Solution *string `json:"solution" gorm:"size:2048"` + Unit_Id *uint `json:"unit_id"` + Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Id;references:Id"` + RepliedAt *time.Time `json:"repliedAt"` +} diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 6bfde570..6e582af2 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -4,6 +4,7 @@ import ( adime "simrs-vx/internal/domain/main-entities/adime" ambulatory "simrs-vx/internal/domain/main-entities/ambulatory" appointment "simrs-vx/internal/domain/main-entities/appointment" + consultation "simrs-vx/internal/domain/main-entities/consultation" counter "simrs-vx/internal/domain/main-entities/counter" device "simrs-vx/internal/domain/main-entities/device" deviceorder "simrs-vx/internal/domain/main-entities/device-order" @@ -143,5 +144,6 @@ func getMainEntities() []any { &mcuorderitem.McuOrderItem{}, &mcusubsrc.McuSubSrc{}, &mcuordersubitem.McuOrderSubItem{}, + &consultation.Consultation{}, } } From d68a9bb7b7ab074e319e642503e4841bb0433db8 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Wed, 24 Sep 2025 12:13:57 +0700 Subject: [PATCH 2/2] add several columns for file url person --- .../migrations/20250924051317.sql | 2 + cmd/main-migration/migrations/atlas.sum | 5 +- internal/domain/main-entities/person/dto.go | 84 ++++++++++--------- .../domain/main-entities/person/entity.go | 46 +++++----- 4 files changed, 76 insertions(+), 61 deletions(-) create mode 100644 cmd/main-migration/migrations/20250924051317.sql diff --git a/cmd/main-migration/migrations/20250924051317.sql b/cmd/main-migration/migrations/20250924051317.sql new file mode 100644 index 00000000..f0f58947 --- /dev/null +++ b/cmd/main-migration/migrations/20250924051317.sql @@ -0,0 +1,2 @@ +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD COLUMN "ResidentIdentityFileUrl" character varying(1024) NULL, ADD COLUMN "PassportFileUrl" character varying(1024) NULL, ADD COLUMN "DrivingLicenseFileUrl" character varying(1024) NULL, ADD COLUMN "FamilyIdentityFileUrl" character varying(1024) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index e61e9880..b33a1e5c 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:0Hvo3AS2yMsS60eDIKnU5B2qvjDhNWHSDHcMxKKYJTk= +h1:n2YbCQPYchOWsVSLUNPCl29Xx3RMTi7vdulwPRHXL4E= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -15,4 +15,5 @@ h1:0Hvo3AS2yMsS60eDIKnU5B2qvjDhNWHSDHcMxKKYJTk= 20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= 20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= 20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= -20250923025134.sql h1:q1bndJguAqjnTjXr6Jpnsrj4d8zMseR2tf02h0h6ArE= +20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= +20250924051317.sql h1:vbbuylW434V23raIl6Y6Ima6aZVItLrdIpk+xehVsJc= diff --git a/internal/domain/main-entities/person/dto.go b/internal/domain/main-entities/person/dto.go index bab22944..fd38822b 100644 --- a/internal/domain/main-entities/person/dto.go +++ b/internal/domain/main-entities/person/dto.go @@ -81,48 +81,56 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Name string `json:"name"` - FrontTitle *string `json:"frontTitle"` - EndTitle *string `json:"endTitle"` - BirthDate *time.Time `json:"birthDate,omitempty"` - BirthRegency_Code *string `json:"birthRegency_code"` - Gender_Code *erp.GenderCode `json:"gender_code"` - ResidentIdentityNumber *string `json:"residentIdentityNumber"` - PassportNumber *string `json:"passportNumber"` - DrivingLicenseNumber *string `json:"drivingLicenseNumber"` - Religion_Code *erp.ReligionCode `json:"religion_code"` - Education_Code *erp.EducationCode `json:"education_code"` - Ocupation_Code *erp.OcupationCode `json:"occupation_code"` - Ocupation_Name *string `json:"occupation_name"` - Ethnic_Code *string `json:"ethnic_code"` - Ethnic *ee.Ethnic `json:"ethnic,omitempty"` - Addresses *[]epa.PersonAddress `json:"addresses,omitempty"` - Contacts *[]epc.PersonContact `json:"contacts,omitempty"` - Relatives *[]epr.PersonRelative `json:"relatives,omitempty"` - Language_Code *string `json:"language_code"` + Name string `json:"name"` + FrontTitle *string `json:"frontTitle"` + EndTitle *string `json:"endTitle"` + BirthDate *time.Time `json:"birthDate,omitempty"` + BirthRegency_Code *string `json:"birthRegency_code"` + Gender_Code *erp.GenderCode `json:"gender_code"` + ResidentIdentityNumber *string `json:"residentIdentityNumber"` + PassportNumber *string `json:"passportNumber"` + DrivingLicenseNumber *string `json:"drivingLicenseNumber"` + Religion_Code *erp.ReligionCode `json:"religion_code"` + Education_Code *erp.EducationCode `json:"education_code"` + Ocupation_Code *erp.OcupationCode `json:"occupation_code"` + Ocupation_Name *string `json:"occupation_name"` + Ethnic_Code *string `json:"ethnic_code"` + Ethnic *ee.Ethnic `json:"ethnic,omitempty"` + Addresses *[]epa.PersonAddress `json:"addresses,omitempty"` + Contacts *[]epc.PersonContact `json:"contacts,omitempty"` + Relatives *[]epr.PersonRelative `json:"relatives,omitempty"` + Language_Code *string `json:"language_code"` + ResidentIdentityFileUrl *string `json:"residentIdentityFileUrl"` + PassportFileUrl *string `json:"passportFileUrl"` + DrivingLicenseFileUrl *string `json:"drivingLicenseFileUrl"` + FamilyIdentityFileUrl *string `json:"familyIdentityFileUrl"` } func (d *Person) ToResponse() ResponseDto { resp := ResponseDto{ - Name: d.Name, - FrontTitle: d.FrontTitle, - EndTitle: d.EndTitle, - BirthDate: d.BirthDate, - BirthRegency_Code: d.BirthRegency_Code, - Gender_Code: d.Gender_Code, - ResidentIdentityNumber: d.ResidentIdentityNumber, - PassportNumber: d.PassportNumber, - DrivingLicenseNumber: d.DrivingLicenseNumber, - Religion_Code: d.Religion_Code, - Education_Code: d.Education_Code, - Ocupation_Code: d.Ocupation_Code, - Ocupation_Name: d.Ocupation_Name, - Ethnic_Code: d.Ethnic_Code, - Ethnic: d.Ethnic, - Addresses: d.Addresses, - Contacts: d.Contacts, - Relatives: d.Relatives, - Language_Code: d.Language_Code, + Name: d.Name, + FrontTitle: d.FrontTitle, + EndTitle: d.EndTitle, + BirthDate: d.BirthDate, + BirthRegency_Code: d.BirthRegency_Code, + Gender_Code: d.Gender_Code, + ResidentIdentityNumber: d.ResidentIdentityNumber, + PassportNumber: d.PassportNumber, + DrivingLicenseNumber: d.DrivingLicenseNumber, + Religion_Code: d.Religion_Code, + Education_Code: d.Education_Code, + Ocupation_Code: d.Ocupation_Code, + Ocupation_Name: d.Ocupation_Name, + Ethnic_Code: d.Ethnic_Code, + Ethnic: d.Ethnic, + Addresses: d.Addresses, + Contacts: d.Contacts, + Relatives: d.Relatives, + Language_Code: d.Language_Code, + ResidentIdentityFileUrl: d.ResidentIdentityFileUrl, + PassportFileUrl: d.PassportFileUrl, + DrivingLicenseFileUrl: d.DrivingLicenseFileUrl, + FamilyIdentityFileUrl: d.FamilyIdentityFileUrl, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/person/entity.go b/internal/domain/main-entities/person/entity.go index eb3bab27..37e2086c 100644 --- a/internal/domain/main-entities/person/entity.go +++ b/internal/domain/main-entities/person/entity.go @@ -13,27 +13,31 @@ import ( ) type Person struct { - ecore.Main // adjust this according to the needs - Name string `json:"name" gorm:"not null;size:150"` - FrontTitle *string `json:"frontTitle" gorm:"size:50"` - EndTitle *string `json:"endTitle" gorm:"size:50"` - BirthDate *time.Time `json:"birthDate,omitempty"` - BirthRegency_Code *string `json:"birthRegency_code" gorm:"size:4"` - Gender_Code *erp.GenderCode `json:"gender_code" gorm:"size:10"` - ResidentIdentityNumber *string `json:"residentIdentityNumber" gorm:"unique;size:16"` - PassportNumber *string `json:"passportNumber" gorm:"unique;size:20"` - DrivingLicenseNumber *string `json:"drivingLicenseNumber" gorm:"unique;size:20"` - Religion_Code *erp.ReligionCode `json:"religion_code" gorm:"size:10"` - Education_Code *erp.EducationCode `json:"education_code" gorm:"size:10"` - Ocupation_Code *erp.OcupationCode `json:"occupation_code" gorm:"size:15"` - Ocupation_Name *string `json:"occupation_name" gorm:"size:50"` - Ethnic_Code *string `json:"ethnic_code" gorm:"size:20"` - Ethnic *ee.Ethnic `json:"ethnic,omitempty" gorm:"foreignKey:Ethnic_Code;references:Code"` - Addresses *[]epa.PersonAddress `json:"addresses" gorm:"foreignKey:Person_Id"` - Contacts *[]epc.PersonContact `json:"contacts" gorm:"foreignKey:Person_Id"` - Relatives *[]epr.PersonRelative `json:"relatives" gorm:"foreignKey:Person_Id"` - Language_Code *string `json:"language_code" gorm:"size:10"` - Language *el.Language `json:"language,omitempty" gorm:"foreignKey:Language_Code;references:Code"` + ecore.Main // adjust this according to the needs + Name string `json:"name" gorm:"not null;size:150"` + FrontTitle *string `json:"frontTitle" gorm:"size:50"` + EndTitle *string `json:"endTitle" gorm:"size:50"` + BirthDate *time.Time `json:"birthDate,omitempty"` + BirthRegency_Code *string `json:"birthRegency_code" gorm:"size:4"` + Gender_Code *erp.GenderCode `json:"gender_code" gorm:"size:10"` + ResidentIdentityNumber *string `json:"residentIdentityNumber" gorm:"unique;size:16"` + PassportNumber *string `json:"passportNumber" gorm:"unique;size:20"` + DrivingLicenseNumber *string `json:"drivingLicenseNumber" gorm:"unique;size:20"` + Religion_Code *erp.ReligionCode `json:"religion_code" gorm:"size:10"` + Education_Code *erp.EducationCode `json:"education_code" gorm:"size:10"` + Ocupation_Code *erp.OcupationCode `json:"occupation_code" gorm:"size:15"` + Ocupation_Name *string `json:"occupation_name" gorm:"size:50"` + Ethnic_Code *string `json:"ethnic_code" gorm:"size:20"` + Ethnic *ee.Ethnic `json:"ethnic,omitempty" gorm:"foreignKey:Ethnic_Code;references:Code"` + Addresses *[]epa.PersonAddress `json:"addresses" gorm:"foreignKey:Person_Id"` + Contacts *[]epc.PersonContact `json:"contacts" gorm:"foreignKey:Person_Id"` + Relatives *[]epr.PersonRelative `json:"relatives" gorm:"foreignKey:Person_Id"` + Language_Code *string `json:"language_code" gorm:"size:10"` + Language *el.Language `json:"language,omitempty" gorm:"foreignKey:Language_Code;references:Code"` + ResidentIdentityFileUrl *string `json:"residentIdentityFileUrl" gorm:"size:1024"` + PassportFileUrl *string `json:"passportFileUrl" gorm:"size:1024"` + DrivingLicenseFileUrl *string `json:"drivingLicenseFileUrl" gorm:"size:1024"` + FamilyIdentityFileUrl *string `json:"familyIdentityFileUrl" gorm:"size:1024"` } func (d Person) IsSameResidentIdentityNumber(input *string) bool {