Merge branch 'migration' of github.com:dikstub-rssa/simrs-be into fix/anything-moko
This commit is contained in:
@@ -18,9 +18,14 @@ import (
|
||||
pl "simrs-vx/pkg/logger"
|
||||
p "simrs-vx/pkg/password"
|
||||
|
||||
eap "simrs-vx/internal/domain/main-entities/auth-partner"
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
"simrs-vx/internal/domain/main-entities/intern"
|
||||
em "simrs-vx/internal/domain/main-entities/midwife"
|
||||
en "simrs-vx/internal/domain/main-entities/nurse"
|
||||
eu "simrs-vx/internal/domain/main-entities/user"
|
||||
euf "simrs-vx/internal/domain/main-entities/user-fes"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
)
|
||||
|
||||
@@ -80,12 +85,152 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
|
||||
// Data and output population
|
||||
atClaims := jwt.MapClaims{}
|
||||
outputData := d.II{}
|
||||
if err := populateRoles(user, input, atClaims, outputData, event); err != nil {
|
||||
return nil, err
|
||||
atClaims["user_id"] = user.Id
|
||||
atClaims["user_name"] = user.Name
|
||||
atClaims["user_contractPosition_code"] = user.ContractPosition_Code
|
||||
atClaims["uuid"] = aUuid
|
||||
atClaims["exp"] = atExpires
|
||||
|
||||
// Create output
|
||||
outputData := d.II{
|
||||
"user_id": strconv.Itoa(int(user.Id)),
|
||||
"user_name": user.Name,
|
||||
"user_contractPosition_code": user.ContractPosition_Code,
|
||||
}
|
||||
|
||||
// extra
|
||||
role := []string{}
|
||||
switch user.ContractPosition_Code {
|
||||
case erg.CSCEmp:
|
||||
// employee
|
||||
employee := ee.Employee{}
|
||||
dg.I.Where("\"User_Id\" = ?", user.Id).First(&employee)
|
||||
if employee.Id == 0 {
|
||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noEmployee", Message: pl.GenMessage("auth-noEmployee")}}
|
||||
}
|
||||
atClaims["employee_id"] = employee.Id
|
||||
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
|
||||
//}
|
||||
|
||||
// employee position
|
||||
if employee.Id > 0 && employee.Position_Code != nil {
|
||||
atClaims["employee_position_code"] = *employee.Position_Code
|
||||
switch *employee.Position_Code {
|
||||
case erg.EPCDoc:
|
||||
doctor := ed.Doctor{}
|
||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&doctor)
|
||||
if doctor.Id == 0 {
|
||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: pl.GenMessage("auth-noDoctor")}}
|
||||
}
|
||||
atClaims["doctor_code"] = doctor.Code
|
||||
outputData["doctor_code"] = doctor.Code
|
||||
|
||||
// specialist
|
||||
if doctor.Specialist_Code != nil {
|
||||
atClaims["specialist_code"] = doctor.Specialist_Code
|
||||
outputData["specialist_code"] = doctor.Specialist_Code
|
||||
}
|
||||
if doctor.Subspecialist_Code != nil {
|
||||
atClaims["subspecialist_code"] = doctor.Subspecialist_Code
|
||||
outputData["subspecialist_code"] = doctor.Subspecialist_Code
|
||||
}
|
||||
case erg.EPCNur:
|
||||
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: pl.GenMessage("auth-noNurse")}}
|
||||
}
|
||||
atClaims["nurse_code"] = empData.Code
|
||||
outputData["nurse_code"] = empData.Code
|
||||
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-noMidwife", Message: pl.GenMessage("auth-noMidwife")}}
|
||||
}
|
||||
atClaims["midwife_code"] = empData.Code
|
||||
outputData["midwife_code"] = empData.Code
|
||||
case erg.EPCPha:
|
||||
empData := ep.Pharmacist{}
|
||||
dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData)
|
||||
if empData.Id == 0 {
|
||||
return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noPharmacist", Message: pl.GenMessage("auth-noPharmacist")}}
|
||||
}
|
||||
atClaims["pharmacist_code"] = empData.Code
|
||||
outputData["pharmacist_code"] = empData.Code
|
||||
}
|
||||
|
||||
errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: pl.GenMessage("auth-getData-failed")}}
|
||||
|
||||
// division position
|
||||
divisionPositions, err := getDivisionPosition(employee.Id, &event)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// installation position
|
||||
installationPositions, err := getInstallationPosition(employee.Id, &event)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// unit position
|
||||
unitPositions, err := getUnitPosition(employee.Id, &event)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// specialist position
|
||||
specialistPositions, err := getSpecialistPosition(employee.Id, &event)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
// subspecialist position
|
||||
subspecialistPositions, err := getSubspecialistPosition(employee.Id, &event)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
role = append(role, divisionPositions...)
|
||||
role = append(role, installationPositions...)
|
||||
role = append(role, unitPositions...)
|
||||
role = append(role, specialistPositions...)
|
||||
role = append(role, subspecialistPositions...)
|
||||
// atClaims["division_positions"] = divsionPositions
|
||||
// outputData["division_positions"] = divsionPositions
|
||||
}
|
||||
case erg.CSCInt:
|
||||
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
|
||||
|
||||
// Generate jwt
|
||||
at := jwt.NewWithClaims(jwt.SigningMethodHS256, atClaims)
|
||||
ats, err := at.SignedString([]byte(atSecretKey))
|
||||
if err != nil {
|
||||
return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: pl.GenMessage("token-sign-err")}}
|
||||
}
|
||||
outputData["accessToken"] = ats
|
||||
|
||||
// Save to redis
|
||||
now := time.Now()
|
||||
atx := time.Unix(atExpires, 0) //converting Unix to UTC(to Time object)
|
||||
err = ms.I.Set(aUuid, strconv.Itoa(int(user.Id)), atx.Sub(now)).Err()
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf(l.I.Msg("redis-store-fail"), err.Error()))
|
||||
}
|
||||
|
||||
// Only manual login
|
||||
tn := time.Now()
|
||||
user.LoginAttemptCount = 0
|
||||
user.LastSuccessLogin = &tn
|
||||
|
||||
@@ -233,7 +233,7 @@ func createMedicineMixAndItem(input emi.MedicineMix, event *pl.Event, tx *gorm.D
|
||||
for _, medicineMixItem := range input.MixItems {
|
||||
medicineMixItemCreate := emmi.CreateDto{
|
||||
MedicineMix_Id: &medicineMix.Id,
|
||||
Medicine_Id: medicineMixItem.Medicine_Id,
|
||||
Medicine_Code: medicineMixItem.Medicine_Code,
|
||||
Dose: medicineMixItem.Dose,
|
||||
}
|
||||
_, err := ummi.CreateData(medicineMixItemCreate, event, tx)
|
||||
@@ -251,7 +251,7 @@ func createMedicationItem(medication_id uint, input epi.PrescriptionItem, event
|
||||
medicationItemCreate := emei.CreateDto{
|
||||
Medication_Id: &medication_id,
|
||||
IsMix: input.IsMix,
|
||||
Medicine_Id: input.Medicine_Id,
|
||||
Medicine_Code: input.Medicine_Code,
|
||||
MedicineMix_Id: input.MedicineMix_Id,
|
||||
Usage: input.Usage,
|
||||
Interval: input.Interval,
|
||||
|
||||
@@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuOrderItem) {
|
||||
}
|
||||
|
||||
data.McuOrder_Id = inputSrc.McuOrder_Id
|
||||
data.McuSrc_Id = inputSrc.McuSrc_Id
|
||||
data.McuSrc_Code = inputSrc.McuSrc_Code
|
||||
data.Result = inputSrc.Result
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
data.ExaminationDate = inputSrc.ExaminationDate
|
||||
|
||||
@@ -24,7 +24,7 @@ func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.McuOrde
|
||||
|
||||
deletedData := e.McuOrderItem{}
|
||||
tx.Unscoped().
|
||||
Where("\"McuOrder_Id\" = ? AND \"McuSrc_Id\" = ?", *input.McuOrder_Id, input.McuSrc_Id).
|
||||
Where("\"McuOrder_Id\" = ? AND \"McuSrc_Code\" = ?", *input.McuOrder_Id, input.McuSrc_Code).
|
||||
First(&deletedData)
|
||||
if deletedData.Id != 0 {
|
||||
if err := tx.Unscoped().Model(e.McuOrderItem{}).Where("\"Id\" = ?", deletedData.Id).Update("\"DeletedAt\"", nil).Error; err != nil {
|
||||
|
||||
@@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuOrderSubItem) {
|
||||
inputSrc = &inputTemp.CreateDto
|
||||
}
|
||||
|
||||
data.McuSubSrc_Id = inputSrc.McuSubSrc_Id
|
||||
data.McuSubSrc_Code = inputSrc.McuSubSrc_Code
|
||||
data.McuOrderItem_Id = inputSrc.McuOrderItem_Id
|
||||
data.Result = inputSrc.Result
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/medication-item-dist"
|
||||
|
||||
un "simrs-vx/internal/use-case/main-use-case/nurse"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
@@ -303,11 +301,6 @@ func Consume(input e.ConsumeDto) (*d.Data, error) {
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
nurse_id, err := un.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -319,7 +312,18 @@ func Consume(input e.ConsumeDto) (*d.Data, error) {
|
||||
}
|
||||
|
||||
data.Remain -= input.Usage
|
||||
data.Nurse_Id = nurse_id
|
||||
|
||||
if input.AuthInfo.Nurse_Code == nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "auth-noNurse",
|
||||
Detail: "user position is not allowed, only nurse can do action consume medication",
|
||||
Raw: errors.New("authentication failed"),
|
||||
}
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
data.Nurse_Code = input.AuthInfo.Nurse_Code
|
||||
|
||||
if err := tx.Save(&data).Error; err != nil {
|
||||
event.Status = "failed"
|
||||
|
||||
@@ -20,5 +20,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicationItemDist)
|
||||
data.MedicationItem_Id = inputSrc.MedicationItem_Id
|
||||
data.DateTime = inputSrc.DateTime
|
||||
data.Remain = inputSrc.Remain
|
||||
data.Nurse_Id = inputSrc.Nurse_Id
|
||||
data.Nurse_Code = inputSrc.Nurse_Code
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicationItem) {
|
||||
|
||||
data.Medication_Id = inputSrc.Medication_Id
|
||||
data.IsMix = inputSrc.IsMix
|
||||
data.Medicine_Id = inputSrc.Medicine_Id
|
||||
data.Medicine_Code = inputSrc.Medicine_Code
|
||||
data.MedicineMix_Id = inputSrc.MedicineMix_Id
|
||||
data.Frequency = inputSrc.Frequency
|
||||
data.Dose = inputSrc.Dose
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
up "simrs-vx/internal/use-case/main-use-case/pharmacist"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
@@ -313,13 +311,18 @@ func Complete(input e.ReadDetailDto) (*d.Data, error) {
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
pharmacist_id, err := up.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
if input.AuthInfo.Pharmachist_Code == nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "auth-noPharmacist",
|
||||
Detail: "user position is not allowed, only pharmacist can do actioncomplete medication",
|
||||
Raw: errors.New("authentication failed"),
|
||||
}
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
data.Status_Code = erc.DSCDone
|
||||
data.Pharmacist_Id = pharmacist_id
|
||||
data.Pharmacist_Code = input.AuthInfo.Pharmachist_Code
|
||||
if err := tx.Save(&data).Error; err != nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
|
||||
@@ -30,7 +30,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Medication) {
|
||||
|
||||
data.Encounter_Id = inputSrc.Encounter_Id
|
||||
data.IssuedAt = inputSrc.IssuedAt
|
||||
data.Pharmacist_Id = inputSrc.Pharmacist_Id
|
||||
data.Pharmacist_Code = inputSrc.Pharmacist_Code
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicineMixItem) {
|
||||
}
|
||||
|
||||
data.MedicineMix_Id = inputSrc.MedicineMix_Id
|
||||
data.Medicine_Id = inputSrc.Medicine_Id
|
||||
data.Medicine_Code = inputSrc.Medicine_Code
|
||||
data.Dose = inputSrc.Dose
|
||||
data.Note = inputSrc.Note
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PrescriptionItem) {
|
||||
|
||||
data.Prescription_Id = inputSrc.Prescription_Id
|
||||
data.IsMix = inputSrc.IsMix
|
||||
data.Medicine_Id = inputSrc.Medicine_Id
|
||||
data.Medicine_Code = inputSrc.Medicine_Code
|
||||
data.MedicineMix_Id = inputSrc.MedicineMix_Id
|
||||
data.Frequency = inputSrc.Frequency
|
||||
data.Dose = inputSrc.Dose
|
||||
|
||||
@@ -99,7 +99,7 @@ func createMedicineMixAndItem(input emi.MedicineMix, event *pl.Event, tx *gorm.D
|
||||
for _, medicineMixItem := range input.MixItems {
|
||||
medicineMixItemCreate := emmi.CreateDto{
|
||||
MedicineMix_Id: &medicineMix.Id,
|
||||
Medicine_Id: medicineMixItem.Medicine_Id,
|
||||
Medicine_Code: medicineMixItem.Medicine_Code,
|
||||
Dose: medicineMixItem.Dose,
|
||||
}
|
||||
_, err := ummi.CreateData(medicineMixItemCreate, event, tx)
|
||||
@@ -117,7 +117,7 @@ func createMedicationItem(medication_id uint, input epi.PrescriptionItem, event
|
||||
medicationItemCreate := emei.CreateDto{
|
||||
Medication_Id: &medication_id,
|
||||
IsMix: input.IsMix,
|
||||
Medicine_Id: input.Medicine_Id,
|
||||
Medicine_Code: input.Medicine_Code,
|
||||
MedicineMix_Id: input.MedicineMix_Id,
|
||||
Frequency: input.Frequency,
|
||||
Dose: input.Dose,
|
||||
|
||||
Reference in New Issue
Block a user