refactor
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
-- Modify "Doctor" table
|
||||||
|
ALTER TABLE "public"."Doctor" ADD CONSTRAINT "uni_Doctor_IHS_Number" UNIQUE ("IHS_Number"), ADD CONSTRAINT "uni_Doctor_SIP_Number" UNIQUE ("SIP_Number");
|
||||||
|
-- Modify "Laborant" table
|
||||||
|
ALTER TABLE "public"."Laborant" ADD CONSTRAINT "uni_Laborant_IHS_Number" UNIQUE ("IHS_Number");
|
||||||
|
-- Modify "Nurse" table
|
||||||
|
ALTER TABLE "public"."Nurse" ADD CONSTRAINT "uni_Nurse_IHS_Number" UNIQUE ("IHS_Number");
|
||||||
|
-- Modify "Nutritionist" table
|
||||||
|
ALTER TABLE "public"."Nutritionist" ADD CONSTRAINT "uni_Nutritionist_IHS_Number" UNIQUE ("IHS_Number");
|
||||||
|
-- Modify "Pharmacist" table
|
||||||
|
ALTER TABLE "public"."Pharmacist" ADD CONSTRAINT "uni_Pharmacist_IHS_Number" UNIQUE ("IHS_Number");
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
h1:5CRUsZFEhBmTlYz30l5g/ilZWIUjrfTf7K0qa5ffXQg=
|
h1:G2T3Gv3jMXqZDaBw/lSU8IhowMI3z//r+ZtHxndsLc4=
|
||||||
20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY=
|
20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY=
|
||||||
|
20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg=
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ type Doctor struct {
|
|||||||
ecore.Main // adjust this according to the needs
|
ecore.Main // adjust this according to the needs
|
||||||
Employee_Id *uint `json:"employee_id"`
|
Employee_Id *uint `json:"employee_id"`
|
||||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||||
IHS_Number *string `json:"ihs_number" gorm:"size:20"`
|
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||||
SIP_Number *string `json:"sip_number" gorm:"size:20"`
|
SIP_Number *string `json:"sip_number" gorm:"unique;size:20"`
|
||||||
Unit_Id *uint16 `json:"unit_id"`
|
Unit_Id *uint16 `json:"unit_id"`
|
||||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"`
|
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"`
|
||||||
Specialist_Id *uint16 `json:"specialist_id"`
|
Specialist_Id *uint16 `json:"specialist_id"`
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ type Laborant struct {
|
|||||||
ecore.Main // adjust this according to the needs
|
ecore.Main // adjust this according to the needs
|
||||||
Employee_Id *uint `json:"employee_id"`
|
Employee_Id *uint `json:"employee_id"`
|
||||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||||
IHS_Number *string `json:"ihs_number" gorm:"size:20"`
|
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ type Nurse struct {
|
|||||||
ecore.Main // adjust this according to the needs
|
ecore.Main // adjust this according to the needs
|
||||||
Employee_Id *uint `json:"employee_id"`
|
Employee_Id *uint `json:"employee_id"`
|
||||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||||
IHS_Number *string `json:"ihs_number" gorm:"size:20"`
|
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||||
Unit_Id *uint16 `json:"unit_id"`
|
Unit_Id *uint16 `json:"unit_id"`
|
||||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"`
|
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"`
|
||||||
Infra_Id *uint16 `json:"infra_id"`
|
Infra_Id *uint16 `json:"infra_id"`
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ type Nutritionist struct {
|
|||||||
ecore.Main // adjust this according to the needs
|
ecore.Main // adjust this according to the needs
|
||||||
Employee_Id *uint `json:"employee_id"`
|
Employee_Id *uint `json:"employee_id"`
|
||||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||||
IHS_Number *string `json:"ihs_number" gorm:"size:20"`
|
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ type Pharmacist struct {
|
|||||||
ecore.Main // adjust this according to the needs
|
ecore.Main // adjust this according to the needs
|
||||||
Employee_Id *uint `json:"employee_id"`
|
Employee_Id *uint `json:"employee_id"`
|
||||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||||
IHS_Number *string `json:"ihs_number" gorm:"size:20"`
|
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,20 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
|
|||||||
tx = tx.Preload("Person.Contacts")
|
tx = tx.Preload("Person.Contacts")
|
||||||
tx = tx.Preload("Person.Relatives")
|
tx = tx.Preload("Person.Relatives")
|
||||||
|
|
||||||
if err := tx.First(&data, input.Id).Error; err != nil {
|
if input.User_Id != nil {
|
||||||
|
tx = tx.Where("\"User_Id\" = ?", *input.User_Id)
|
||||||
|
}
|
||||||
|
if input.Person_Id != nil {
|
||||||
|
tx = tx.Where("\"Person_Id\" = ?", *input.Person_Id)
|
||||||
|
}
|
||||||
|
if input.Number != nil {
|
||||||
|
tx = tx.Where("\"Number\" = ?", *input.Number)
|
||||||
|
}
|
||||||
|
if input.Id != 0 {
|
||||||
|
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 {
|
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||||
return nil, processedErr
|
return nil, processedErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
|
|||||||
tx = dg.I
|
tx = dg.I
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tx.First(&data, input.Id).Error; err != nil {
|
if input.User_Id != nil {
|
||||||
|
tx = tx.Where("\"User_Id\" = ?", *input.User_Id)
|
||||||
|
}
|
||||||
|
if input.Id > 0 {
|
||||||
|
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 {
|
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||||
return nil, processedErr
|
return nil, processedErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -341,7 +341,12 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
createInt := esi.CreateDto{}
|
createInt := esi.CreateDto{
|
||||||
|
User_Id: &data.Id,
|
||||||
|
Person_Id: input.Person_Id,
|
||||||
|
Specialist_Id: input.Specialist_Id,
|
||||||
|
Subspecialist_Id: input.Subspecialist_Id,
|
||||||
|
}
|
||||||
if readIntData != nil {
|
if readIntData != nil {
|
||||||
if err := usi.UpdateData(esi.UpdateDto{CreateDto: createInt}, readIntData, &event, tx); err != nil {
|
if err := usi.UpdateData(esi.UpdateDto{CreateDto: createInt}, readIntData, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -368,7 +373,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
|
|
||||||
switch input.Position_Code {
|
switch input.Position_Code {
|
||||||
case ero.UPCDoc:
|
case ero.UPCDoc:
|
||||||
readDoc := ed.ReadDetailDto{Employee_Id: &data.Id}
|
readDoc := ed.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||||
readDocData, err := ud.ReadDetailData(readDoc, &event, tx)
|
readDocData, err := ud.ReadDetailData(readDoc, &event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -390,7 +395,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCNur:
|
case ero.UPCNur:
|
||||||
readNur := en.ReadDetailDto{Employee_Id: &data.Id}
|
readNur := en.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||||
readNurData, err := un.ReadDetailData(readNur, &event, tx)
|
readNurData, err := un.ReadDetailData(readNur, &event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -410,7 +415,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCNut:
|
case ero.UPCNut:
|
||||||
readNut := et.ReadDetailDto{Employee_Id: &data.Id}
|
readNut := et.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||||
readNutData, err := ut.ReadDetailData(readNut, &event, tx)
|
readNutData, err := ut.ReadDetailData(readNut, &event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -430,7 +435,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCPha:
|
case ero.UPCPha:
|
||||||
readPha := ep.ReadDetailDto{Employee_Id: &data.Id}
|
readPha := ep.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||||
readPhaData, err := up.ReadDetailData(readPha, &event, tx)
|
readPhaData, err := up.ReadDetailData(readPha, &event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -450,7 +455,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCLab:
|
case ero.UPCLab:
|
||||||
readLab := el.ReadDetailDto{Employee_Id: &data.Id}
|
readLab := el.ReadDetailDto{Employee_Id: &employeeData.Id}
|
||||||
readLabData, err := ul.ReadDetailData(readLab, &event, tx)
|
readLabData, err := ul.ReadDetailData(readLab, &event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Any functions that are used internally by the use-case
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||||
esi "simrs-vx/internal/domain/main-entities/specialist-intern"
|
esi "simrs-vx/internal/domain/main-entities/specialist-intern"
|
||||||
e "simrs-vx/internal/domain/main-entities/user"
|
e "simrs-vx/internal/domain/main-entities/user"
|
||||||
@@ -56,18 +57,20 @@ func setDataEmployeeUpdate(src e.EmployeUpdateDto) ee.UpdateDto {
|
|||||||
func getPersonIdByUserId(userId uint, positionCode ero.UserPosisitionCode, event *pl.Event, tx *gorm.DB) (*uint, error) {
|
func getPersonIdByUserId(userId uint, positionCode ero.UserPosisitionCode, event *pl.Event, tx *gorm.DB) (*uint, error) {
|
||||||
pl.SetLogInfo(event, nil, "started", "DBGetPersonIdByUserId")
|
pl.SetLogInfo(event, nil, "started", "DBGetPersonIdByUserId")
|
||||||
if positionCode == ero.UPCInt {
|
if positionCode == ero.UPCInt {
|
||||||
person, err := usi.ReadDetailData(esi.ReadDetailDto{User_Id: &userId}, event, tx)
|
specInt, err := usi.ReadDetailData(esi.ReadDetailDto{User_Id: &userId}, event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if specInt.Person_Id == nil {
|
||||||
return &person.Id, nil
|
return nil, errors.New("person id not found")
|
||||||
|
}
|
||||||
|
return specInt.Person_Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
person, err := ue.ReadDetailData(ee.ReadDetailDto{User_Id: &userId}, event, tx)
|
emp, err := ue.ReadDetailData(ee.ReadDetailDto{User_Id: &userId}, event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &person.Id, nil
|
return emp.Person_Id, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user