From a8e41f055c746a32100248f22d09b461e44a1f87 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 16 Oct 2025 08:12:54 +0700 Subject: [PATCH] add person-insurance, adjust person --- .../migrations/20251016010845.sql | 2 + .../migrations/20251016011023.sql | 17 ++++++ cmd/main-migration/migrations/atlas.sum | 6 +- .../domain/main-entities/encounter/entity.go | 2 +- .../main-entities/person-insurance/dto.go | 1 + .../main-entities/person-insurance/entity.go | 15 +++++ .../domain/main-entities/person/entity.go | 60 ++++++++++--------- internal/interface/migration/main-entities.go | 2 + 8 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 cmd/main-migration/migrations/20251016010845.sql create mode 100644 cmd/main-migration/migrations/20251016011023.sql create mode 100644 internal/domain/main-entities/person-insurance/dto.go create mode 100644 internal/domain/main-entities/person-insurance/entity.go diff --git a/cmd/main-migration/migrations/20251016010845.sql b/cmd/main-migration/migrations/20251016010845.sql new file mode 100644 index 00000000..edbbb414 --- /dev/null +++ b/cmd/main-migration/migrations/20251016010845.sql @@ -0,0 +1,2 @@ +-- Rename a column from "ClassCode" to "Class_Code" +ALTER TABLE "public"."Chemo" RENAME COLUMN "ClassCode" TO "Class_Code"; diff --git a/cmd/main-migration/migrations/20251016011023.sql b/cmd/main-migration/migrations/20251016011023.sql new file mode 100644 index 00000000..12e51e7d --- /dev/null +++ b/cmd/main-migration/migrations/20251016011023.sql @@ -0,0 +1,17 @@ +-- Create "PersonInsurance" table +CREATE TABLE "public"."PersonInsurance" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Person_Id" bigint NULL, + "InsuranceCompany_Id" bigint NULL, + "Ref_Number" character varying(20) NULL, + "DefaultStatus" boolean NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_PersonInsurance_Ref_Number" UNIQUE ("Ref_Number"), + CONSTRAINT "fk_PersonInsurance_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Id") REFERENCES "public"."InsuranceCompany" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Person_Insurances" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create index "idx_person_insurance" to table: "PersonInsurance" +CREATE UNIQUE INDEX "idx_person_insurance" ON "public"."PersonInsurance" ("Person_Id", "DefaultStatus"); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index e3172704..05c66cea 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:Y15nC3Bp3DWNym7hAvXkF9zFwkHh8nQDpxcNrxQgYhE= +h1:qfP77w9XYWpAFDON1lo+vpqIYCSiPkVEyHXcYFC52Hk= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -43,4 +43,6 @@ h1:Y15nC3Bp3DWNym7hAvXkF9zFwkHh8nQDpxcNrxQgYhE= 20251014060047.sql h1:0jqj49WTtneEIMQDBoo4c095ZGi8sCrA8NnHBrPU6D8= 20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg= 20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14= -20251015045455.sql h1:v120CzYYiFWmW81VmKWsjmjRiBIv5aFnPZXwQaQxqes= +20251015045455.sql h1:MeLWmMhAOAz8b15Dd7IAQnt6JxjSml02XCXK22C0Lpg= +20251016010845.sql h1:MSUh26glEDyZ5BFiteYOm9mUCWw7aG9vv5TxYY+EidU= +20251016011023.sql h1:8oUBzIpzAYTo03yex+wLKacv32YjXmn4MsXtBFiQtzY= diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index c9f81712..3e888356 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -32,10 +32,10 @@ type Encounter struct { VisitDate time.Time `json:"visitDate"` 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"` Member_Number *string `json:"memberNumber" gorm:"unique;size:20"` Ref_Number *string `json:"refNumber" gorm:"unique;size:20"` Trx_Number *string `json:"trxNumber" gorm:"unique;size:20"` - InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Id;references:Id"` Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Id;references:Id"` Adm_Employee_Id *uint `json:"admEmployee_id"` diff --git a/internal/domain/main-entities/person-insurance/dto.go b/internal/domain/main-entities/person-insurance/dto.go new file mode 100644 index 00000000..5a2ee2a1 --- /dev/null +++ b/internal/domain/main-entities/person-insurance/dto.go @@ -0,0 +1 @@ +package personinsurance diff --git a/internal/domain/main-entities/person-insurance/entity.go b/internal/domain/main-entities/person-insurance/entity.go new file mode 100644 index 00000000..64057835 --- /dev/null +++ b/internal/domain/main-entities/person-insurance/entity.go @@ -0,0 +1,15 @@ +package personinsurance + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ei "simrs-vx/internal/domain/main-entities/insurance-company" +) + +type PersonInsurance struct { + ecore.Main + Person_Id *uint `json:"person_id" gorm:"uniqueIndex:idx_person_insurance"` + InsuranceCompany_Id *uint `json:"insurance_id"` + InsuranceCompany *ei.InsuranceCompany `json:"insurance,omitempty" gorm:"foreignKey:InsuranceCompany_Id;references:Id"` + Ref_Number *string `json:"ref_number" gorm:"unique;size:20"` + DefaultStatus *bool `json:"default_status" gorm:"uniqueIndex:idx_person_insurance"` +} diff --git a/internal/domain/main-entities/person/entity.go b/internal/domain/main-entities/person/entity.go index 8639df25..8932ca1b 100644 --- a/internal/domain/main-entities/person/entity.go +++ b/internal/domain/main-entities/person/entity.go @@ -6,6 +6,7 @@ import ( el "simrs-vx/internal/domain/main-entities/language" epa "simrs-vx/internal/domain/main-entities/person-address" epc "simrs-vx/internal/domain/main-entities/person-contact" + epi "simrs-vx/internal/domain/main-entities/person-insurance" epr "simrs-vx/internal/domain/main-entities/person-relative" er "simrs-vx/internal/domain/main-entities/regency" @@ -15,35 +16,36 @@ 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"` - BirthRegency *er.Regency `json:"birthRegency,omitempty" gorm:"foreignKey:BirthRegency_Code;references:Code"` - 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"` - Nationality *string `json:"nationality": 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"` - CommunicationIssueStatus bool `json:"communicationIssueStatus"` - Disability *string `json:"disability" gorm:"size:100"` - 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"` + 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"` + BirthRegency *er.Regency `json:"birthRegency,omitempty" gorm:"foreignKey:BirthRegency_Code;references:Code"` + 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"` + Nationality *string `json:"nationality": gorm:"size:50"` + Ethnic_Code *string `json:"ethnic_code" gorm:"size:20"` + Ethnic *ee.Ethnic `json:"ethnic,omitempty" gorm:"foreignKey:Ethnic_Code;references:Code"` + Language_Code *string `json:"language_code" gorm:"size:10"` + Language *el.Language `json:"language,omitempty" gorm:"foreignKey:Language_Code;references:Code"` + CommunicationIssueStatus bool `json:"communicationIssueStatus"` + Disability *string `json:"disability" gorm:"size:100"` + 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"` + 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"` + Insurances *[]epi.PersonInsurance `json:"insurances" gorm:"foreignKey:Person_Id"` } func (d Person) IsSameResidentIdentityNumber(input *string) bool { diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 034495c3..ea8ec1c0 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -55,6 +55,7 @@ import ( person "simrs-vx/internal/domain/main-entities/person" personaddress "simrs-vx/internal/domain/main-entities/person-address" personcontact "simrs-vx/internal/domain/main-entities/person-contact" + personinsurance "simrs-vx/internal/domain/main-entities/person-insurance" personrelative "simrs-vx/internal/domain/main-entities/person-relative" pharmacist "simrs-vx/internal/domain/main-entities/pharmacist" pharmacycompany "simrs-vx/internal/domain/main-entities/pharmacy-company" @@ -96,6 +97,7 @@ func getMainEntities() []any { &person.Person{}, &personaddress.PersonAddress{}, &personcontact.PersonContact{}, + &personinsurance.PersonInsurance{}, &pharmacycompany.PharmacyCompany{}, &diagnosesrc.DiagnoseSrc{}, &proceduresrc.ProcedureSrc{},