65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
/*
|
|
DESCRIPTION:
|
|
Any functions that are used internally by the use-case
|
|
*/
|
|
package encounter
|
|
|
|
import (
|
|
"errors"
|
|
e "simrs-vx/internal/domain/main-entities/encounter"
|
|
es "simrs-vx/internal/domain/main-entities/soapi"
|
|
|
|
ero "simrs-vx/internal/domain/references/organization"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) {
|
|
var inputSrc *e.CreateDto
|
|
if inputT, ok := any(input).(*e.CreateDto); ok {
|
|
inputSrc = inputT
|
|
} else {
|
|
inputTemp := any(input).(*e.UpdateDto)
|
|
inputSrc = &inputTemp.CreateDto
|
|
}
|
|
|
|
data.Patient_Id = inputSrc.Patient_Id
|
|
data.Class_Code = inputSrc.Class_Code
|
|
data.Unit_Id = inputSrc.Unit_Id
|
|
data.Specialist_Id = inputSrc.Specialist_Id
|
|
data.Subspecialist_Id = inputSrc.Subspecialist_Id
|
|
data.VisitDate = inputSrc.VisitDate
|
|
data.Appointment_Doctor_Id = inputSrc.Appointment_Doctor_Id
|
|
data.Responsible_Doctor_Id = inputSrc.Responsible_Doctor_Id
|
|
data.RefSource_Name = inputSrc.RefSource_Name
|
|
data.Appointment_Id = inputSrc.Appointment_Id
|
|
}
|
|
|
|
func setDataDischarge(src e.DischargeDto, dst *e.Encounter) {
|
|
dst.DischargeMethod_Code = src.DischargeMethod_Code
|
|
dst.EarlyEducation = src.EarlyEducation
|
|
dst.MedicalDischargeEducation = src.MedicalDischargeEducation
|
|
dst.AdmDischargeEducation = src.AdmDischargeEducation
|
|
dst.DischargeReason = src.DischargeReason
|
|
}
|
|
|
|
func checkSoapiByDocExists(encounter_id uint, tx *gorm.DB) error {
|
|
soapi := es.Soapi{}
|
|
err := tx.
|
|
Preload("Employee").
|
|
Preload("Employee.User").
|
|
Where("\"Encounter_Id\" = ?", encounter_id).First(&soapi).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if soapi.Employee == nil || soapi.Employee.User == nil {
|
|
return errors.New("employee not found")
|
|
}
|
|
if soapi.Employee.User.Position_Code != ero.UPCDoc {
|
|
return errors.New("employee is not a doctor")
|
|
}
|
|
|
|
return nil
|
|
}
|