Merge dev into feat/user
This commit is contained in:
No files matched your search
@@ -1,22 +1,21 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
|
||||||
ep "simrs-vx/internal/domain/main-entities/person"
|
ep "simrs-vx/internal/domain/main-entities/person"
|
||||||
epa "simrs-vx/internal/domain/main-entities/person-address"
|
epa "simrs-vx/internal/domain/main-entities/person-address"
|
||||||
epc "simrs-vx/internal/domain/main-entities/person-contact"
|
epc "simrs-vx/internal/domain/main-entities/person-contact"
|
||||||
|
|
||||||
erc "simrs-vx/internal/domain/references/common"
|
erc "simrs-vx/internal/domain/references/common"
|
||||||
ero "simrs-vx/internal/domain/references/organization"
|
erg "simrs-vx/internal/domain/references/organization"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateDto struct {
|
type CreateDto struct {
|
||||||
Name string `json:"name" validate:"maxLength=25"`
|
Name string `json:"name" validate:"maxLength=25"`
|
||||||
Password string `json:"password" validate:"maxLength=255"`
|
Password string `json:"password" validate:"maxLength=255"`
|
||||||
Status_Code erc.UserStatusCode `json:"status_code" validate:"maxLength=10"`
|
Status_Code erc.UserStatusCode `json:"status_code" validate:"maxLength=10"`
|
||||||
ContractPosition_Code ero.ContractPositionCode `json:"contractPosition_code" validate:"maxLength=20"`
|
|
||||||
Person_Id *uint `json:"-"`
|
Person_Id *uint `json:"-"`
|
||||||
Person *ep.UpdateDto `json:"person"`
|
Person *ep.UpdateDto `json:"person"`
|
||||||
PersonAddresses []epa.UpdateDto `json:"personAddresses"`
|
PersonAddresses []epa.UpdateDto `json:"personAddresses"`
|
||||||
@@ -28,6 +27,7 @@ type CreateDto struct {
|
|||||||
Infra_Id *uint16 `json:"infra_id"`
|
Infra_Id *uint16 `json:"infra_id"`
|
||||||
Specialist_Id *uint16 `json:"specialist_id"`
|
Specialist_Id *uint16 `json:"specialist_id"`
|
||||||
Subspecialist_Id *uint16 `json:"subspecialist_id"`
|
Subspecialist_Id *uint16 `json:"subspecialist_id"`
|
||||||
|
ContractPosition_Code erg.ContractPositionCode `json:"contractPosition_code" gorm:"not null;size:20"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReadListDto struct {
|
type ReadListDto struct {
|
||||||
@@ -89,7 +89,7 @@ type EmployeUpdateDto struct {
|
|||||||
Person_Id *uint `json:"-"`
|
Person_Id *uint `json:"-"`
|
||||||
Division_Code *string `json:"division_code"`
|
Division_Code *string `json:"division_code"`
|
||||||
Number *string `json:"number" validate:"maxLength=20"`
|
Number *string `json:"number" validate:"maxLength=20"`
|
||||||
Position_Code ero.EmployeePosisitionCode `json:"status_code" validate:"maxLength=10"`
|
Position_Code erg.EmployeePosisitionCode `json:"status_code" validate:"maxLength=10"`
|
||||||
Status_Code erc.ActiveStatusCode `json:"status_code" validate:"maxLength=10"`
|
Status_Code erc.ActiveStatusCode `json:"status_code" validate:"maxLength=10"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,16 @@ import (
|
|||||||
|
|
||||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||||
erc "simrs-vx/internal/domain/references/common"
|
erc "simrs-vx/internal/domain/references/common"
|
||||||
ero "simrs-vx/internal/domain/references/organization"
|
erg "simrs-vx/internal/domain/references/organization"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ecore.Main // adjust this according to the needs
|
ecore.Main // adjust this according to the needs
|
||||||
Name string `json:"name" gorm:"unique;not null;size:25"`
|
Name string `json:"name" gorm:"unique;not null;size:25"`
|
||||||
Password string `json:"password" gorm:"not null;size:255"`
|
Password string `json:"password" gorm:"not null;size:255"`
|
||||||
Status_Code erc.UserStatusCode `json:"status_code" gorm:"not null;size:10"`
|
Status_Code erc.UserStatusCode `json:"status_code" gorm:"not null;size:10"`
|
||||||
FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`
|
ContractPosition_Code erg.ContractPositionCode `json:"contractPosition_code" gorm:"not null;size:20"`
|
||||||
// Position_Code ero.EmployeePosisitionCode `json:"position_code" gorm:"not null;size:20"`
|
FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`
|
||||||
ContractPosition_Code ero.ContractPositionCode `json:"contractPosition_Code" gorm:"not null;size:20"`
|
|
||||||
LoginAttemptCount int `json:"-"`
|
LoginAttemptCount int `json:"-"`
|
||||||
LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"`
|
LastSuccessLogin *time.Time `json:"lastSuccessLogin,omitempty"`
|
||||||
LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"`
|
LastAllowdLogin *time.Time `json:"lastAllowdLogin,omitempty"`
|
||||||
|
|||||||
@@ -1,26 +1,33 @@
|
|||||||
package organization
|
package organization
|
||||||
|
|
||||||
type (
|
type (
|
||||||
UserPosisitionCode string
|
ContractPositionCode string
|
||||||
ItemGroupCode string
|
EmployeePosisitionCode string
|
||||||
InfraGroupCode string
|
InternPosisitionCode string
|
||||||
UnitTypeCode string
|
ItemGroupCode string
|
||||||
DoctorFeeTypeCode string
|
InfraGroupCode string
|
||||||
|
UnitTypeCode string
|
||||||
|
DoctorFeeTypeCode string
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UPCReg UserPosisitionCode = "registration" // Admisi/Pendaftaran
|
CSCEmp ContractPositionCode = "employee" // Pegawai
|
||||||
UPCNur UserPosisitionCode = "nurse" // Perawat
|
CSCSpi ContractPositionCode = "intern" // PPDS
|
||||||
UPCDoc UserPosisitionCode = "doctor" // Dokter
|
|
||||||
UPCNut UserPosisitionCode = "nutritionist" // Ahli gizi
|
EPCReg EmployeePosisitionCode = "registration" // Admisi/Pendaftaran
|
||||||
UPCMwi UserPosisitionCode = "mid-wife" // Bidan
|
EPCNur EmployeePosisitionCode = "nurse" // Perawat
|
||||||
UPCLab UserPosisitionCode = "laborant" // Laboran
|
EPCDoc EmployeePosisitionCode = "doctor" // Dokter
|
||||||
UPCPha UserPosisitionCode = "pharmacy" // Farmasi
|
EPCNut EmployeePosisitionCode = "nutritionist" // Ahli gizi
|
||||||
UPCPay UserPosisitionCode = "payment" // Pembayaran
|
EPCMwi EmployeePosisitionCode = "mid-wife" // Bidan
|
||||||
UPCHur UserPosisitionCode = "human-resource" // Sumber Daya Manusia
|
EPCLab EmployeePosisitionCode = "laborant" // Laboran
|
||||||
UPCGea UserPosisitionCode = "general-affair" // Bagian Umum
|
EPCPha EmployeePosisitionCode = "pharmacy" // Farmasi
|
||||||
UPCInt UserPosisitionCode = "specialist-intern" // PPDS
|
EPCPay EmployeePosisitionCode = "payment" // Pembayaran
|
||||||
UPCMan UserPosisitionCode = "management" // Manajemen
|
EPCHur EmployeePosisitionCode = "human-resource" // Sumber Daya Manusia
|
||||||
|
EPCGea EmployeePosisitionCode = "general-affair" // Bagian Umum
|
||||||
|
EPCMan EmployeePosisitionCode = "management" // Manajemen
|
||||||
|
|
||||||
|
IPCSpecialist = "specialist-intern"
|
||||||
|
IPCNurse = "nurse-intern"
|
||||||
|
|
||||||
ITGCInfra ItemGroupCode = "infra"
|
ITGCInfra ItemGroupCode = "infra"
|
||||||
ITGCMedicine ItemGroupCode = "medicine"
|
ITGCMedicine ItemGroupCode = "medicine"
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
eu "simrs-vx/internal/domain/main-entities/user"
|
eu "simrs-vx/internal/domain/main-entities/user"
|
||||||
erc "simrs-vx/internal/domain/references/common"
|
|
||||||
|
|
||||||
pa "simrs-vx/pkg/auth-helper"
|
pa "simrs-vx/pkg/auth-helper"
|
||||||
el "simrs-vx/pkg/logger"
|
el "simrs-vx/pkg/logger"
|
||||||
p "simrs-vx/pkg/password"
|
p "simrs-vx/pkg/password"
|
||||||
|
|
||||||
|
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||||
|
erc "simrs-vx/internal/domain/references/common"
|
||||||
|
|
||||||
a "github.com/karincake/apem"
|
a "github.com/karincake/apem"
|
||||||
dg "github.com/karincake/apem/db-gorm-pg"
|
dg "github.com/karincake/apem/db-gorm-pg"
|
||||||
ms "github.com/karincake/apem/ms-redis"
|
ms "github.com/karincake/apem/ms-redis"
|
||||||
@@ -90,11 +92,26 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
atExpires := time.Now().Add(duration).Unix()
|
atExpires := time.Now().Add(duration).Unix()
|
||||||
atSecretKey := authCfg.AtSecretKey
|
atSecretKey := authCfg.AtSecretKey
|
||||||
|
|
||||||
|
// extra
|
||||||
|
role := []string{}
|
||||||
|
if user.ContractPosition_Code == "employee" {
|
||||||
|
employee := ee.Employee{}
|
||||||
|
dg.I.Where("user_id = ?", user.Id).First(&employee)
|
||||||
|
role = append(role, "emp-"+string(*employee.Position_Code))
|
||||||
|
} else if user.ContractPosition_Code == "intern" {
|
||||||
|
// specialistIntern := esi.SpecialistIntern{}
|
||||||
|
// dg.I.Where("user_id = ?", user.Id).First(&specialistIntern)
|
||||||
|
role = append(role, "spi")
|
||||||
|
}
|
||||||
|
|
||||||
// Creating Access Token
|
// Creating Access Token
|
||||||
atClaims := jwt.MapClaims{}
|
atClaims := jwt.MapClaims{}
|
||||||
atClaims["user_id"] = user.Id
|
atClaims["user_id"] = user.Id
|
||||||
atClaims["user_name"] = user.Name
|
atClaims["user_name"] = user.Name
|
||||||
atClaims["user_position_code"] = user.Position_Code
|
// atClaims["user_email"] = user.Email
|
||||||
|
// atClaims["user_position_code"] = user.Position_Code
|
||||||
|
atClaims["user_employementStatus_code"] = user.ContractPosition_Code
|
||||||
|
// atClaims["user_ref_id"] = user.Ref_Id
|
||||||
atClaims["exp"] = atExpires
|
atClaims["exp"] = atExpires
|
||||||
atClaims["uuid"] = aUuid
|
atClaims["uuid"] = aUuid
|
||||||
atClaims["user_division_positions"] = userDivisionPositions
|
atClaims["user_division_positions"] = userDivisionPositions
|
||||||
@@ -104,6 +121,15 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: el.GenMessage("token-sign-err")}}
|
return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: el.GenMessage("token-sign-err")}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outputData := d.II{
|
||||||
|
"user_id": strconv.Itoa(int(user.Id)),
|
||||||
|
"user_name": user.Name,
|
||||||
|
// "user_email": user.Email,
|
||||||
|
"user_contractPosition_code": user.ContractPosition_Code,
|
||||||
|
// "user_ref_id": user.Ref_Id,
|
||||||
|
"accessToken": ats,
|
||||||
|
}
|
||||||
|
|
||||||
// Save to redis
|
// Save to redis
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
atx := time.Unix(atExpires, 0) //converting Unix to UTC(to Time object)
|
atx := time.Unix(atExpires, 0) //converting Unix to UTC(to Time object)
|
||||||
@@ -125,13 +151,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
|||||||
"structure": "single-data",
|
"structure": "single-data",
|
||||||
"status": "verified",
|
"status": "verified",
|
||||||
},
|
},
|
||||||
Data: d.II{
|
Data: outputData,
|
||||||
"user_id": strconv.Itoa(int(user.Id)),
|
|
||||||
"user_name": user.Name,
|
|
||||||
"user_position_code": user.Position_Code,
|
|
||||||
"accessToken": ats,
|
|
||||||
"user_division_positions": userDivisionPositions,
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,41 +206,41 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
|
|||||||
return nil, d.FieldError{Code: "token-unidentified", Message: el.GenMessage("token-unidentified")}
|
return nil, d.FieldError{Code: "token-unidentified", Message: el.GenMessage("token-unidentified")}
|
||||||
}
|
}
|
||||||
user_name := fmt.Sprintf("%v", claims["user_name"])
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
var userDivisionPositions []pa.DivisionPosition
|
|
||||||
raw := claims["user_division_positions"]
|
|
||||||
if raw == nil {
|
|
||||||
fmt.Println("No user_division_positions found in claims")
|
|
||||||
} else {
|
|
||||||
list, ok := raw.([]interface{})
|
|
||||||
if !ok {
|
|
||||||
fmt.Printf("user_division_positions is not []interface{}, but %T\n", raw)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Found %d division positions\n", len(list))
|
|
||||||
for i, item := range list {
|
|
||||||
if m, ok := item.(map[string]interface{}); ok {
|
|
||||||
fmt.Printf("Item %d: %v\n", i, m)
|
|
||||||
dp := pa.DivisionPosition{
|
|
||||||
Division_Code: fmt.Sprintf("%v", m["division_code"]),
|
|
||||||
DivisionPosition_Code: fmt.Sprintf("%v", m["divisionPosition_code"]),
|
|
||||||
}
|
|
||||||
userDivisionPositions = append(userDivisionPositions, dp)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Item %d not map[string]interface{} but %T\n", i, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
position_code := ""
|
|
||||||
if v, exist := claims["user_position_code"]; exist && v != nil {
|
|
||||||
position_code = v.(string)
|
|
||||||
}
|
|
||||||
data = &pa.AuthInfo{
|
data = &pa.AuthInfo{
|
||||||
Uuid: accessUuid,
|
Uuid: accessUuid,
|
||||||
User_Id: uint(user_id),
|
User_Id: uint(user_id),
|
||||||
User_Name: user_name,
|
User_Name: user_name,
|
||||||
User_Position_Code: position_code,
|
User_ContractPosition_code: contractPosition_code,
|
||||||
User_DivisionPositions: userDivisionPositions,
|
Employee_Position_Code: &employee_position_code,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
"gorm.io/gorm"
|
||||||
es "simrs-vx/internal/domain/main-entities/soapi"
|
|
||||||
|
pl "simrs-vx/pkg/logger"
|
||||||
|
pu "simrs-vx/pkg/use-case-helper"
|
||||||
|
|
||||||
edo "simrs-vx/internal/domain/main-entities/device-order"
|
edo "simrs-vx/internal/domain/main-entities/device-order"
|
||||||
emo "simrs-vx/internal/domain/main-entities/material-order"
|
emo "simrs-vx/internal/domain/main-entities/material-order"
|
||||||
@@ -23,6 +25,7 @@ import (
|
|||||||
epi "simrs-vx/internal/domain/main-entities/prescription-item"
|
epi "simrs-vx/internal/domain/main-entities/prescription-item"
|
||||||
|
|
||||||
// udo "simrs-vx/internal/use-case/main-use-case/device-order"
|
// udo "simrs-vx/internal/use-case/main-use-case/device-order"
|
||||||
|
es "simrs-vx/internal/domain/main-entities/soapi"
|
||||||
um "simrs-vx/internal/use-case/main-use-case/medication"
|
um "simrs-vx/internal/use-case/main-use-case/medication"
|
||||||
umei "simrs-vx/internal/use-case/main-use-case/medication-item"
|
umei "simrs-vx/internal/use-case/main-use-case/medication-item"
|
||||||
umi "simrs-vx/internal/use-case/main-use-case/medicine-mix"
|
umi "simrs-vx/internal/use-case/main-use-case/medicine-mix"
|
||||||
@@ -30,13 +33,9 @@ import (
|
|||||||
up "simrs-vx/internal/use-case/main-use-case/prescription"
|
up "simrs-vx/internal/use-case/main-use-case/prescription"
|
||||||
upi "simrs-vx/internal/use-case/main-use-case/prescription-item"
|
upi "simrs-vx/internal/use-case/main-use-case/prescription-item"
|
||||||
|
|
||||||
pl "simrs-vx/pkg/logger"
|
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||||
pu "simrs-vx/pkg/use-case-helper"
|
|
||||||
|
|
||||||
erc "simrs-vx/internal/domain/references/common"
|
erc "simrs-vx/internal/domain/references/common"
|
||||||
ero "simrs-vx/internal/domain/references/organization"
|
ero "simrs-vx/internal/domain/references/organization"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) {
|
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) {
|
||||||
@@ -114,7 +113,7 @@ func checkSoapiByDocExists(encounter_id uint, event *pl.Event, tx *gorm.DB) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range soapies {
|
for _, s := range soapies {
|
||||||
if s.Employee != nil && s.Employee.User != nil && s.Employee.User.Position_Code == ero.UPCDoc {
|
if s.Employee != nil && s.Employee.User != nil && *s.Employee.Position_Code == ero.EPCDoc {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||||
el "simrs-vx/internal/domain/main-entities/laborant"
|
el "simrs-vx/internal/domain/main-entities/laborant"
|
||||||
em "simrs-vx/internal/domain/main-entities/midwife"
|
|
||||||
en "simrs-vx/internal/domain/main-entities/nurse"
|
en "simrs-vx/internal/domain/main-entities/nurse"
|
||||||
et "simrs-vx/internal/domain/main-entities/nutritionist"
|
et "simrs-vx/internal/domain/main-entities/nutritionist"
|
||||||
ep "simrs-vx/internal/domain/main-entities/pharmacist"
|
ep "simrs-vx/internal/domain/main-entities/pharmacist"
|
||||||
@@ -19,7 +18,6 @@ import (
|
|||||||
ud "simrs-vx/internal/use-case/main-use-case/doctor"
|
ud "simrs-vx/internal/use-case/main-use-case/doctor"
|
||||||
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
||||||
ul "simrs-vx/internal/use-case/main-use-case/laborant"
|
ul "simrs-vx/internal/use-case/main-use-case/laborant"
|
||||||
um "simrs-vx/internal/use-case/main-use-case/midwife"
|
|
||||||
un "simrs-vx/internal/use-case/main-use-case/nurse"
|
un "simrs-vx/internal/use-case/main-use-case/nurse"
|
||||||
ut "simrs-vx/internal/use-case/main-use-case/nutritionist"
|
ut "simrs-vx/internal/use-case/main-use-case/nutritionist"
|
||||||
upe "simrs-vx/internal/use-case/main-use-case/person"
|
upe "simrs-vx/internal/use-case/main-use-case/person"
|
||||||
@@ -85,7 +83,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
data = *resData
|
data = *resData
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.Position_Code == ero.UPCInt {
|
if input.ContractPosition_Code == ero.CSCSpi {
|
||||||
createInt := esi.CreateDto{
|
createInt := esi.CreateDto{
|
||||||
Person_Id: input.Person_Id,
|
Person_Id: input.Person_Id,
|
||||||
Specialist_Id: input.Specialist_Id,
|
Specialist_Id: input.Specialist_Id,
|
||||||
@@ -105,8 +103,8 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch input.Position_Code {
|
switch input.Employee.Position_Code {
|
||||||
case ero.UPCDoc:
|
case ero.EPCDoc:
|
||||||
createDoc := ed.CreateDto{
|
createDoc := ed.CreateDto{
|
||||||
Employee_Id: &employeeData.Id,
|
Employee_Id: &employeeData.Id,
|
||||||
IHS_Number: input.IHS_Number,
|
IHS_Number: input.IHS_Number,
|
||||||
@@ -118,7 +116,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
if _, err := ud.CreateData(createDoc, &event, tx); err != nil {
|
if _, err := ud.CreateData(createDoc, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCNur:
|
case ero.EPCNur:
|
||||||
createNurse := en.CreateDto{
|
createNurse := en.CreateDto{
|
||||||
Employee_Id: &employeeData.Id,
|
Employee_Id: &employeeData.Id,
|
||||||
IHS_Number: input.IHS_Number,
|
IHS_Number: input.IHS_Number,
|
||||||
@@ -128,7 +126,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
if _, err := un.CreateData(createNurse, &event, tx); err != nil {
|
if _, err := un.CreateData(createNurse, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCNut:
|
case ero.EPCNut:
|
||||||
createNutritionist := et.CreateDto{
|
createNutritionist := et.CreateDto{
|
||||||
Employee_Id: &employeeData.Id,
|
Employee_Id: &employeeData.Id,
|
||||||
IHS_Number: input.IHS_Number,
|
IHS_Number: input.IHS_Number,
|
||||||
@@ -136,7 +134,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
if _, err := ut.CreateData(createNutritionist, &event, tx); err != nil {
|
if _, err := ut.CreateData(createNutritionist, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCPha:
|
case ero.EPCPha:
|
||||||
createPharmacist := ep.CreateDto{
|
createPharmacist := ep.CreateDto{
|
||||||
Employee_Id: &employeeData.Id,
|
Employee_Id: &employeeData.Id,
|
||||||
IHS_Number: input.IHS_Number,
|
IHS_Number: input.IHS_Number,
|
||||||
@@ -144,7 +142,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
if _, err := up.CreateData(createPharmacist, &event, tx); err != nil {
|
if _, err := up.CreateData(createPharmacist, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCLab:
|
case ero.EPCLab:
|
||||||
createLaborant := el.CreateDto{
|
createLaborant := el.CreateDto{
|
||||||
Employee_Id: &employeeData.Id,
|
Employee_Id: &employeeData.Id,
|
||||||
IHS_Number: input.IHS_Number,
|
IHS_Number: input.IHS_Number,
|
||||||
@@ -152,16 +150,6 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
if _, err := ul.CreateData(createLaborant, &event, tx); err != nil {
|
if _, err := ul.CreateData(createLaborant, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCMwi:
|
|
||||||
createMidwife := em.CreateDto{
|
|
||||||
Employee_Id: &employeeData.Id,
|
|
||||||
IHS_Number: input.IHS_Number,
|
|
||||||
}
|
|
||||||
if _, err := um.CreateData(em.CreateDto(createMidwife), &event, tx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case ero.UPCReg, ero.UPCHur, ero.UPCGea, ero.UPCMan:
|
|
||||||
// do nothing
|
|
||||||
default:
|
default:
|
||||||
return errors.New("invalid employee position")
|
return errors.New("invalid employee position")
|
||||||
}
|
}
|
||||||
@@ -317,7 +305,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
person_id, err := getPersonIdByUserId(data.Id, input.Position_Code, &event, tx)
|
person_id, err := getPersonIdByUserId(data.Id, input.ContractPosition_Code, &event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
@@ -348,7 +336,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.Position_Code == ero.UPCInt {
|
if input.ContractPosition_Code == ero.CSCSpi {
|
||||||
readInt := esi.ReadDetailDto{User_Id: &data.Id}
|
readInt := esi.ReadDetailDto{User_Id: &data.Id}
|
||||||
readIntData, err := usi.ReadDetailData(readInt, &event, tx)
|
readIntData, err := usi.ReadDetailData(readInt, &event, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -384,8 +372,8 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch input.Position_Code {
|
switch input.Employee.Position_Code {
|
||||||
case ero.UPCDoc:
|
case ero.EPCDoc:
|
||||||
readDoc := ed.ReadDetailDto{Employee_Id: &employeeData.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 {
|
||||||
@@ -407,7 +395,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
if _, err := ud.CreateData(createDoc, &event, tx); err != nil {
|
if _, err := ud.CreateData(createDoc, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCNur:
|
case ero.EPCNur:
|
||||||
readNur := en.ReadDetailDto{Employee_Id: &employeeData.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 {
|
||||||
@@ -427,7 +415,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
if _, err := un.CreateData(createNur, &event, tx); err != nil {
|
if _, err := un.CreateData(createNur, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCNut:
|
case ero.EPCNut:
|
||||||
readNut := et.ReadDetailDto{Employee_Id: &employeeData.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 {
|
||||||
@@ -447,7 +435,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
if _, err := ut.CreateData(createNut, &event, tx); err != nil {
|
if _, err := ut.CreateData(createNut, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCPha:
|
case ero.EPCPha:
|
||||||
readPha := ep.ReadDetailDto{Employee_Id: &employeeData.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 {
|
||||||
@@ -467,7 +455,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
if _, err := up.CreateData(createPha, &event, tx); err != nil {
|
if _, err := up.CreateData(createPha, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCLab:
|
case ero.EPCLab:
|
||||||
readLab := el.ReadDetailDto{Employee_Id: &employeeData.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 {
|
||||||
@@ -487,28 +475,6 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
if _, err := ul.CreateData(createLab, &event, tx); err != nil {
|
if _, err := ul.CreateData(createLab, &event, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case ero.UPCMwi:
|
|
||||||
readMidwife := em.ReadDetailDto{Employee_Id: &employeeData.Id}
|
|
||||||
readMidwifeData, err := um.ReadDetailData(readMidwife, &event, tx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
createMidwife := em.CreateDto{
|
|
||||||
Employee_Id: &employeeData.Id,
|
|
||||||
IHS_Number: input.IHS_Number,
|
|
||||||
}
|
|
||||||
if readMidwifeData != nil {
|
|
||||||
if err := um.UpdateData(em.UpdateDto{CreateDto: createMidwife}, readMidwifeData, &event, tx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := um.CreateData(createMidwife, &event, tx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case ero.UPCReg, ero.UPCHur, ero.UPCGea, ero.UPCMan:
|
|
||||||
// do nothing
|
|
||||||
default:
|
default:
|
||||||
return errors.New("invalid employee position")
|
return errors.New("invalid employee position")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,19 +6,19 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
|
||||||
esi "simrs-vx/internal/domain/main-entities/specialist-intern"
|
|
||||||
e "simrs-vx/internal/domain/main-entities/user"
|
|
||||||
|
|
||||||
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
"gorm.io/gorm"
|
||||||
usi "simrs-vx/internal/use-case/main-use-case/specialist-intern"
|
|
||||||
|
|
||||||
ero "simrs-vx/internal/domain/references/organization"
|
|
||||||
|
|
||||||
pl "simrs-vx/pkg/logger"
|
pl "simrs-vx/pkg/logger"
|
||||||
p "simrs-vx/pkg/password"
|
p "simrs-vx/pkg/password"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
||||||
|
usi "simrs-vx/internal/use-case/main-use-case/specialist-intern"
|
||||||
|
|
||||||
|
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||||
|
esi "simrs-vx/internal/domain/main-entities/specialist-intern"
|
||||||
|
e "simrs-vx/internal/domain/main-entities/user"
|
||||||
|
erg "simrs-vx/internal/domain/references/organization"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setCreate(src e.CreateDto, dst *e.User) error {
|
func setCreate(src e.CreateDto, dst *e.User) error {
|
||||||
@@ -30,15 +30,14 @@ func setCreate(src e.CreateDto, dst *e.User) error {
|
|||||||
dst.Name = src.Name
|
dst.Name = src.Name
|
||||||
dst.Password = pass
|
dst.Password = pass
|
||||||
dst.Status_Code = src.Status_Code
|
dst.Status_Code = src.Status_Code
|
||||||
dst.Position_Code = src.Position_Code
|
dst.ContractPosition_Code = src.ContractPosition_Code
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUpdate(src e.UpdateDto, dst *e.User) {
|
func setUpdate(src e.UpdateDto, dst *e.User) {
|
||||||
dst.Status_Code = src.Status_Code
|
dst.Status_Code = src.Status_Code
|
||||||
dst.Position_Code = src.Position_Code
|
dst.ContractPosition_Code = src.ContractPosition_Code
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDataEmployeeUpdate(src e.EmployeUpdateDto) ee.UpdateDto {
|
func setDataEmployeeUpdate(src e.EmployeUpdateDto) ee.UpdateDto {
|
||||||
@@ -54,9 +53,10 @@ 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 erg.ContractPositionCode, 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 == erg.CSCEmp {
|
||||||
|
} else if positionCode == erg.CSCSpi {
|
||||||
specInt, 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
|
||||||
|
|||||||
+48
-13
@@ -7,11 +7,15 @@ import (
|
|||||||
type AuthKey struct{}
|
type AuthKey struct{}
|
||||||
|
|
||||||
type AuthInfo struct {
|
type AuthInfo struct {
|
||||||
Uuid string
|
Uuid string
|
||||||
User_Id uint
|
User_Id uint
|
||||||
User_Name string
|
User_Name string
|
||||||
User_DivisionPositions []DivisionPosition
|
User_ContractPosition_code string
|
||||||
User_Position_Code string
|
Employee_Position_Code *string
|
||||||
|
Intern_Position_Code *string
|
||||||
|
User_DivisionPositions []DivisionPosition
|
||||||
|
// User_DivisionPositions []DivisionPosition
|
||||||
|
// User_Position_Code string
|
||||||
}
|
}
|
||||||
|
|
||||||
type DivisionPosition struct {
|
type DivisionPosition struct {
|
||||||
@@ -20,33 +24,64 @@ type DivisionPosition struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsDoctor() bool {
|
func (a AuthInfo) IsDoctor() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCDoc)
|
if a.Employee_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Employee_Position_Code == string(ero.EPCDoc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsNurse() bool {
|
func (a AuthInfo) IsNurse() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCNur)
|
if a.Employee_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Employee_Position_Code == string(ero.EPCNur)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsNutritionist() bool {
|
func (a AuthInfo) IsNutritionist() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCNut)
|
if a.Employee_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Employee_Position_Code == string(ero.EPCNut)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsLaborant() bool {
|
func (a AuthInfo) IsLaborant() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCLab)
|
if a.Employee_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Employee_Position_Code == string(ero.EPCLab)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsPharmacist() bool {
|
func (a AuthInfo) IsPharmacist() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCPha)
|
if a.Employee_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Employee_Position_Code == string(ero.EPCPha)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsPayment() bool {
|
func (a AuthInfo) IsPayment() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCPay)
|
if a.Employee_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Employee_Position_Code == string(ero.EPCPay)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsManagement() bool {
|
func (a AuthInfo) IsManagement() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCMan)
|
if a.Employee_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Employee_Position_Code == string(ero.EPCMan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthInfo) IsSpecialistIntern() bool {
|
func (a AuthInfo) IsSpecialistIntern() bool {
|
||||||
return a.User_Position_Code == string(ero.UPCInt)
|
if a.Intern_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Intern_Position_Code == string(ero.IPCSpecialist)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a AuthInfo) IsNurseIntern() bool {
|
||||||
|
if a.Intern_Position_Code == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *a.Intern_Position_Code == string(ero.IPCNurse)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user