fix conflict
This commit is contained in:
@@ -13,12 +13,13 @@ import (
|
||||
"simrs-vx/internal/domain/main-entities/intern"
|
||||
eu "simrs-vx/internal/domain/main-entities/user"
|
||||
|
||||
pa "simrs-vx/pkg/auth-helper"
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
el "simrs-vx/pkg/logger"
|
||||
p "simrs-vx/pkg/password"
|
||||
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
em "simrs-vx/internal/domain/main-entities/midwife"
|
||||
en "simrs-vx/internal/domain/main-entities/nurse"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
erg "simrs-vx/internal/domain/references/organization"
|
||||
@@ -120,10 +121,10 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
outputData["employee_id"] = employee.Id
|
||||
role = append(role, "emp-"+string(*employee.Position_Code))
|
||||
|
||||
if employee.Division_Code != nil {
|
||||
atClaims["employee_division_code"] = employee.Division_Code
|
||||
outputData["employee_division_code"] = employee.Division_Code
|
||||
}
|
||||
//if employee.Division_Code != nil {
|
||||
// atClaims["employee_division_code"] = employee.Division_Code
|
||||
// outputData["employee_division_code"] = employee.Division_Code
|
||||
//}
|
||||
|
||||
// employee position
|
||||
if employee.Id > 0 && employee.Position_Code != nil {
|
||||
@@ -147,19 +148,27 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
outputData["subspecialist_id"] = doctor.Subspecialist_Id
|
||||
}
|
||||
case erg.EPCNur:
|
||||
nurse := en.Nurse{}
|
||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&nurse)
|
||||
if nurse.Id == 0 {
|
||||
empData := en.Nurse{}
|
||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData)
|
||||
if empData.Id == 0 {
|
||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: el.GenMessage("auth-noNurse")}}
|
||||
}
|
||||
atClaims["nurse_id"] = nurse.Id
|
||||
outputData["nurse_id"] = nurse.Id
|
||||
atClaims["nurse_id"] = empData.Id
|
||||
outputData["nurse_id"] = empData.Id
|
||||
case erg.EPCMwi:
|
||||
empData := em.Midwife{}
|
||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData)
|
||||
if empData.Id == 0 {
|
||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: el.GenMessage("auth-noNurse")}}
|
||||
}
|
||||
atClaims["nurse_id"] = empData.Id
|
||||
outputData["nurse_id"] = empData.Id
|
||||
}
|
||||
|
||||
errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}}
|
||||
|
||||
// division position
|
||||
divsionPositions, err := getDivisionPosition(employee.Id)
|
||||
divisionPositions, err := getDivisionPosition(employee.Id)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
@@ -188,7 +197,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
role = append(role, divsionPositions...)
|
||||
role = append(role, divisionPositions...)
|
||||
role = append(role, installationPositions...)
|
||||
role = append(role, unitPositions...)
|
||||
role = append(role, specialistPositions...)
|
||||
@@ -200,6 +209,8 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
intern := intern.Intern{}
|
||||
dg.I.Where("\"User_Id\" = ?", user.Id).First(&intern)
|
||||
role = append(role, "int-"+string(*intern.Position_Code))
|
||||
case erg.CSCSys:
|
||||
role = append(role, "system")
|
||||
}
|
||||
atClaims["roles"] = role
|
||||
outputData["roles"] = role
|
||||
@@ -287,43 +298,22 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
|
||||
if accessUuidRedis.String() == "" {
|
||||
return nil, d.FieldError{Code: "token-unidentified", Message: el.GenMessage("token-unidentified")}
|
||||
}
|
||||
user_name := fmt.Sprintf("%v", claims["user_name"])
|
||||
// user_email := ""
|
||||
// if v, exist := claims["user_email"]; exist && v != nil {
|
||||
// user_email = v.(string)
|
||||
// }
|
||||
// ref_id := 0
|
||||
// if v, exist := claims["user_ref_id"]; exist && v != nil {
|
||||
// tmp := v.(float64)
|
||||
// ref_id = int(tmp)
|
||||
// }
|
||||
// position_code := ""
|
||||
// if v, exist := claims["user_position_code"]; exist && v != nil {
|
||||
// position_code = v.(string)
|
||||
// }
|
||||
// data = &AuthInfo{
|
||||
// Uuid: accessUuid,
|
||||
// User_Id: int(user_id),
|
||||
// User_Name: user_name,
|
||||
// User_Email: user_email,
|
||||
// User_Ref_Id: ref_id,
|
||||
// User_Position_Code: position_code,
|
||||
contractPosition_code := ""
|
||||
if v, exist := claims["contractPosition_code"]; exist && v != nil {
|
||||
contractPosition_code = v.(string)
|
||||
}
|
||||
employee_position_code := ""
|
||||
if v, exist := claims["employee_position_code"]; exist && v != nil {
|
||||
employee_position_code = v.(string)
|
||||
}
|
||||
|
||||
data = &pa.AuthInfo{
|
||||
Uuid: accessUuid,
|
||||
User_Id: uint(user_id),
|
||||
User_Name: user_name,
|
||||
User_ContractPosition_code: contractPosition_code,
|
||||
Employee_Position_Code: &employee_position_code,
|
||||
Uuid: accessUuid,
|
||||
User_Id: uint(user_id),
|
||||
User_Name: fmt.Sprintf("%v", claims["user_name"]),
|
||||
}
|
||||
|
||||
data.User_ContractPosition_code = checkStrClaims(claims, "contractPosition_code")
|
||||
data.Employee_Position_Code = checkStrPtrClaims(claims, "employee_position_code")
|
||||
data.Doctor_Id = checkIntPtrClaims(claims, "doctor_id")
|
||||
data.Nurse_Id = checkIntPtrClaims(claims, "nurse_id")
|
||||
data.Midwife_Id = checkIntPtrClaims(claims, "midwife_id")
|
||||
data.Nutritionist_Id = checkIntPtrClaims(claims, "nutritionist_id")
|
||||
data.Laborant_Id = checkIntPtrClaims(claims, "laborant_id")
|
||||
data.Pharmachist_Id = checkIntPtrClaims(claims, "pharmachist_id")
|
||||
data.Intern_Position_Code = checkStrPtrClaims(claims, "intern_position_code")
|
||||
return
|
||||
}
|
||||
return nil, d.FieldError{Code: "token", Message: "token-invalid"}
|
||||
@@ -332,3 +322,33 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
|
||||
func GetConfig() {
|
||||
a.ParseCfg(&authCfg)
|
||||
}
|
||||
|
||||
func checkStrClaims(claim map[string]interface{}, key string) string {
|
||||
if v, exist := claim[key]; exist && v != nil {
|
||||
return v.(string)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func checkStrPtrClaims(claim map[string]interface{}, key string) *string {
|
||||
if v, exist := claim[key]; exist && v != nil {
|
||||
val := v.(string)
|
||||
return &val
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkIntClaims(claim map[string]interface{}, key string) int {
|
||||
if v, exist := claim[key]; exist && v != nil {
|
||||
return v.(int)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func checkIntPtrClaims(claim map[string]interface{}, key string) *int {
|
||||
if v, exist := claim[key]; exist && v != nil {
|
||||
val := int(v.(float64))
|
||||
return &val
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,10 +28,6 @@ func getAndCheck(input, condition any) (eCode string) {
|
||||
return ""
|
||||
}
|
||||
|
||||
func getDocName(id uint) string {
|
||||
return "authentication"
|
||||
}
|
||||
|
||||
func getDivisionPosition(employee_id uint) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
|
||||
@@ -91,7 +91,9 @@ 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 err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Employee) {
|
||||
|
||||
data.User_Id = inputSrc.User_Id
|
||||
data.Person_Id = inputSrc.Person_Id
|
||||
data.Division_Code = inputSrc.Division_Code
|
||||
data.Number = inputSrc.Number
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
data.Position_Code = inputSrc.Position_Code
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package encounter
|
||||
|
||||
import (
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
// std
|
||||
"errors"
|
||||
|
||||
// external
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
gh "github.com/karincake/getuk"
|
||||
"gorm.io/gorm"
|
||||
|
||||
// pkg
|
||||
plh "simrs-vx/pkg/lib-helper"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
gh "github.com/karincake/getuk"
|
||||
"gorm.io/gorm"
|
||||
// internal
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
)
|
||||
|
||||
func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Encounter, error) {
|
||||
@@ -34,6 +40,10 @@ func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Encount
|
||||
}
|
||||
|
||||
func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Encounter, *e.MetaDto, error) {
|
||||
if input.AuthInfo.User_Id == 0 {
|
||||
return nil, nil, plh.HandleListError(input, event, errors.New("user_id is required"))
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, input, "started", "DBReadList")
|
||||
data := []e.Encounter{}
|
||||
pagination := gh.Pagination{}
|
||||
@@ -46,10 +56,13 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.En
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
tx = tx.Model(&e.Encounter{})
|
||||
|
||||
tx = tx.
|
||||
Model(&e.Encounter{}).
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
if input.AuthInfo.Doctor_Id != nil {
|
||||
tx.Where("\"Responsible_Doctor_Id\" = ?", *input.AuthInfo.Doctor_Id)
|
||||
}
|
||||
|
||||
tx.Scopes(gh.Preload(input.Includes)).
|
||||
Scopes(gh.Filter(input.FilterDto)).
|
||||
Count(&count).
|
||||
Scopes(gh.Paginate(input, &pagination)).
|
||||
|
||||
@@ -81,7 +81,9 @@ 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 err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
|
||||
@@ -352,18 +352,18 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
|
||||
|
||||
}
|
||||
|
||||
func Search(input e.SearchDto) (*d.Data, error) {
|
||||
func SearchByResidentIdentityNumber(input e.SearchDto) (*d.Data, error) {
|
||||
var data *e.Patient
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Search",
|
||||
Feature: "Search By Resident Identity Number",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "search")
|
||||
if data, err = SearchData(input, &event); err != nil {
|
||||
if data, err = SearchDataByRIN(input, &event); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -377,6 +377,46 @@ func Search(input e.SearchDto) (*d.Data, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Search(input e.SearchDto) (*d.Data, error) {
|
||||
var dataList []e.Patient
|
||||
var metaList *e.MetaDto
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Search",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "readList")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
if dataList, metaList, err = SearchData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "list-data",
|
||||
"status": "fetched",
|
||||
"page_number": strconv.Itoa(metaList.PageNumber),
|
||||
"page_size": strconv.Itoa(metaList.PageSize),
|
||||
"record_totalCount": strconv.Itoa(metaList.Count),
|
||||
"record_currentCount": strconv.Itoa(len(dataList)),
|
||||
},
|
||||
Data: e.ToResponseList(dataList),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Upload(input e.UploadDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
|
||||
var data *e.Patient
|
||||
|
||||
@@ -154,11 +154,11 @@ func DeleteData(data *e.Patient, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SearchData(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) (*e.Patient, error) {
|
||||
// Search By Resident Identity Number
|
||||
func SearchDataByRIN(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) (*e.Patient, error) {
|
||||
pl.SetLogInfo(event, input, "started", "DBSearch")
|
||||
|
||||
var patient e.Patient
|
||||
var err error
|
||||
var data e.Patient
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
@@ -174,27 +174,60 @@ func SearchData(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) (*e.Patient
|
||||
Preload("Person.Relatives").
|
||||
Preload("Person.Insurances")
|
||||
|
||||
switch input.Mode {
|
||||
case e.SMIdent:
|
||||
// Search by patient number OR person's resident identity number (exact match) OR person's name (partial match)
|
||||
err = tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
|
||||
Where("\"Patient\".\"Number\" = ? OR \"Person\".\"ResidentIdentityNumber\" = ? OR \"Person\".\"Name\" ILIKE ?",
|
||||
input.Search, input.Search, "%"+input.Search+"%").
|
||||
First(&patient).Error
|
||||
case e.SMNik:
|
||||
// Search by patient person's resident identity number (exact match)
|
||||
err = tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
|
||||
Where("\"Person\".\"ResidentIdentityNumber\" = ?",
|
||||
input.Search).
|
||||
First(&patient).Error
|
||||
}
|
||||
// Search by patient person's resident identity number (exact match)
|
||||
err := tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
|
||||
Where("\"Person\".\"ResidentIdentityNumber\" = ?",
|
||||
input.Search).
|
||||
First(&data).Error
|
||||
|
||||
if err != nil {
|
||||
if processedErr := pu.HandleSearchError(err, event, source, input.Search, patient); processedErr != nil {
|
||||
if processedErr := pu.HandleSearchError(err, event, source, input.Search, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &patient, nil
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func SearchData(input e.SearchDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Patient, *e.MetaDto, error) {
|
||||
pl.SetLogInfo(event, input, "started", "DBSearch")
|
||||
|
||||
var data []e.Patient
|
||||
pagination := gh.Pagination{}
|
||||
count := int64(0)
|
||||
meta := e.MetaDto{}
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
// Preload associations for complete data
|
||||
tx = tx.Preload(clause.Associations)
|
||||
tx = tx.Preload("Person.Addresses").
|
||||
Preload("Person.Contacts").
|
||||
Preload("Person.Relatives").
|
||||
Preload("Person.Insurances")
|
||||
|
||||
// Search by patient number OR person's resident identity number (exact match) OR person's name (partial match)
|
||||
tx = tx.Joins("JOIN \"Person\" ON \"Patient\".\"Person_Id\" = \"Person\".\"Id\"").
|
||||
Where("\"Patient\".\"Number\" ILIKE ? OR \"Person\".\"ResidentIdentityNumber\" ILIKE ? OR \"Person\".\"Name\" ILIKE ?",
|
||||
"%"+input.Search+"%", "%"+input.Search+"%", "%"+input.Search+"%")
|
||||
err := tx.Scopes(gh.Paginate(input, &pagination)).Find(&data).Error
|
||||
|
||||
if err != nil {
|
||||
if processedErr := pu.HandleSearchError(err, event, source, input.Search, data); processedErr != nil {
|
||||
return nil, nil, processedErr
|
||||
}
|
||||
}
|
||||
|
||||
meta.Count = int(count)
|
||||
meta.PageNumber = pagination.PageNumber
|
||||
meta.PageSize = pagination.PageSize
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return data, &meta, nil
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ 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 err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ 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 err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ 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 err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ func setDataEmployeeUpdate(src e.EmployeUpdateDto) ee.UpdateDto {
|
||||
CreateDto: ee.CreateDto{
|
||||
User_Id: src.User_Id,
|
||||
Person_Id: src.Person_Id,
|
||||
Division_Code: src.Division_Code,
|
||||
Number: src.Number,
|
||||
Status_Code: src.Status_Code,
|
||||
Position_Code: &src.Position_Code,
|
||||
|
||||
Reference in New Issue
Block a user