1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package patient_service
-
- import (
- "Kya_New/models"
- "Kya_New/service"
- "fmt"
- "strconv"
- "strings"
- )
-
- func GetCreatorId(phone string) (models.SgjUserAdmin, error) {
- admin := models.SgjUserAdmin{}
- err := service.UserReadDB().Where("mobile = ? AND status = ?", phone, 1).Find(&admin).Error
- return admin, err
- }
-
- func GetOrgId(id int64) (models.SgjUserOrg, error) {
- org := models.SgjUserOrg{}
- err := service.UserReadDB().Where("creator = ? AND status = ?", id, 1).Find(&org).Error
- return org, err
- }
- func GetneratedDialysisNo(orgID int64) (dialysisNo int64) {
- fmt.Println("orgid", orgID)
- var patient models.Patients
- err := service.XTReadDB().Model(&models.Patients{}).Where("status = 1 AND user_org_id = ?", orgID).Order("dialysis_no desc").First(&patient).Error
- fmt.Println("自动生成透析号错误", err)
- if err != nil {
- return
- }
-
- if patient.ID == 0 {
- return
- }
- dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
- return
- }
-
- func AddPatients(patients *models.Patients) error {
-
- err := service.XTWriteDB().Create(&patients).Error
- return err
- }
-
- func GetPatientsLastData(orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := service.XTReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Find(&patients).Error
- return patients, err
- }
-
- func AddContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64) (err error) {
- utx := service.XTWriteDB().Begin()
- //btx := service.UserWriteDB().Begin()
- if len(contagions) > 0 {
- thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, contagion := range contagions {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, patienid)
- insertData = append(insertData, contagion)
- insertData = append(insertData, 1)
- insertData = append(insertData, createdtime)
- insertData = append(insertData, updatedtime)
- }
- thisSQL += strings.Join(insertParams, ",")
- err = utx.Exec(thisSQL, insertData...).Error
- fmt.Println("这个错误err", err)
- }
- return
- }
-
- func GetCourseManagementData(patientid int64, orgid int64, startime int64, endtime int64) (patientCourse []*models.PatientCourseOfDiseases, err error) {
- db := service.XTReadDB().Table("xt_patient_course_of_disease as x").Where("x.status = 1")
- err = db.Group("x.id").Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Where("x.patient_id = ? and x.org_id = ? and x.record_time >=? and x.record_time <=?", patientid, orgid, startime, endtime).Scan(&patientCourse).Error
- return patientCourse, err
-
- }
-
- func GetCheckPatientData(patientid int64, orgid int64, stattime int64, endtime int64) (inspection []*models.Inspection, err error) {
-
- err = service.XTReadDB().Group("inspect_date").Where("patient_id = ? and org_id = ? and inspect_date >=? and inspect_date <= ? and status = 1", patientid, orgid, stattime, endtime).Find(&inspection).Error
- return inspection, err
- }
-
- func GetCheckData(time int64, patientid int64, orgid int64) (inspection []*models.Inspection, err error) {
-
- err = service.XTReadDB().Group("project_name").Where("patient_id = ? and org_id = ? and inspect_date = ?", patientid, orgid, time).Order("id asc").Find(&inspection).Error
- return inspection, err
- }
- func GetPatientInfectious(patientid int64) (infectious []*models.PatientsInfectiousDiseases, err error) {
-
- err = service.XTReadDB().Model(&models.PatientsInfectiousDiseases{}).Where("patient_id = ?", patientid).Find(&infectious).Error
- return infectious, err
- }
|