123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package manage_service
-
- import (
- "Kya_New/models"
- "Kya_New/service"
- "fmt"
- "github.com/jinzhu/gorm"
- "strings"
- "time"
- )
-
- func GetPatientInfoByIdCard(idcard string, orgid int64) (*models.Patients, error) {
- var patients models.Patients
- var err error
- err = service.XTReadDB().Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ? AND status = ?", idcard, orgid, 1).Find(&patients).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patients, nil
- }
-
- func GetPatientInfoByPhone(phone string, orgid int64) (*models.Patients, error) {
- var patients models.Patients
- var err error
- err = service.XTReadDB().Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ? AND status = ?", phone, orgid, 1).Find(&patients).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &patients, nil
- }
-
- func AddPatients(patients *models.Patients) error {
-
- err := service.XTWriteDB().Create(&patients).Error
- return err
- }
-
- func GetLastData(orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := service.XTReadDB().Where("user_org_id = ? AND status = ?", orgid, 1).Last(&patients).Error
- return patients, err
- }
-
- func GetPatientLastData(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()
- 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)
- }
- utx.Commit()
- return
- }
-
- func AddPatientType(orgid int64, patientid int64, patientType []int64) (err error) {
- utx := service.XTWriteDB()
- if len(patientType) > 0 {
- thisSQL := "INSERT INTO xt_patients_type(user_org_id,patient_id,created_time,status,text) VALUES"
- insertParams := make([]string, 0)
- insertData := make([]interface{}, 0)
- for _, patientype := range patientType {
- insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
- insertData = append(insertData, orgid)
- insertData = append(insertData, patientid)
- insertData = append(insertData, time.Now().Unix())
- insertData = append(insertData, 1)
- insertData = append(insertData, patientype)
- }
- thisSQL += strings.Join(insertParams, ",")
- err = utx.Exec(thisSQL, insertData...).Error
- fmt.Println("这个错误err", err)
- }
- utx.Commit()
- return
- }
-
- func DeleteCouseManage(patientid int64, orgid int64) error {
-
- err := service.XTWriteDB().Model(models.PatientCourseOfDisease{}).Where("id = ? AND org_id = ?", patientid, orgid).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetRecordServe(patientid int64, orgid int64, startime int64, endtime int64) (record []*models.PatientRescueRecords, err error) {
- db := service.XTReadDB().Table("xt_patient_rescue_record 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.status,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(&record).Error
- return record, err
- }
-
- func GetLongDialysisData(patientid int64, orgid int64, startime int64, endtime int64) (dialysis []*models.DialysisPrescription, err error) {
-
- err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND record_date >= ? AND record_date <=?", patientid, orgid, startime, endtime).Find(&dialysis).Error
- return dialysis, err
- }
-
- func GetDialysReCord(patientid int64, orgid int64, startime int64, endtime int64) (dialysisOrder []*models.DialysisOrder, err error) {
-
- err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND dialysis_date >=? AND dialysis_date <= ?", patientid, orgid, startime, endtime).Find(&dialysisOrder).Error
- return dialysisOrder, err
- }
-
- func GetMissionInforMation(patientid int64, orgid int64, startime int64, endtime int64) (treatment []*models.TreatmentSummary, err error) {
- err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date >=? AND assessment_date <= ?", patientid, orgid, startime, endtime).Find(&treatment).Error
- return treatment, err
- }
-
- func ToSeacherCourseManagement(patientid int64, orgid int64, content string) (patient []*models.PatientCourseOfDiseases, err error) {
- likekey := "%" + content + "%"
- 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.title like ?", patientid, orgid, likekey).Scan(&patient).Error
- return patient, err
- }
-
- func ToDeleteSaveRecord(id int64) error {
- err := service.XTWriteDB().Model(models.PatientRescueRecord{}).Where("id = ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func ToSeacherRecord(patientid int64, orgid int64, content string) (record []*models.PatientRescueRecords, err error) {
- likekey := "%" + content + "%"
- db := service.XTReadDB().Table("xt_patient_rescue_record 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,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.content like ?", patientid, orgid, likekey).Scan(&record).Error
- return record, err
- }
-
- func DeletMissionInformation(id int64) error {
-
- err := service.XTWriteDB().Model(models.TreatmentSummary{}).Where("id = ?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func ToSeacherMissionInformation(patientid int64, orgid int64, seachval string) (treat []*models.TreatmentSummary, err error) {
-
- db := service.XTReadDB().Table("xt_treatment_summary as x")
- //if len(keywords) > 0 {
- // likeKey := "%" + keywords + "%"
- // db = db.Where("p.name LIKE ?", likeKey)
- //}
- if len(seachval) > 0 {
- likeKe := seachval + "%"
- db = db.Where("x.patient_id = ? AND x.user_org_id = ? AND x.mission LIKE ?", patientid, orgid, likeKe)
- }
-
- err = db.Find(&treat).Error
-
- return treat, err
- }
-
- func GetPatientSchedules(patientid int64, orgid int64, startime int64, endtime int64) (schedules []*models.PatientSchedule, err error) {
- err = service.XTReadDB().Table("xt_schedule as s").
- Preload("DeviceZone", "org_id = ? and status =1", orgid).
- Preload("DeviceNumber", "org_id = ? and status =1", orgid).
- Where("s.patient_id = ? and s.user_org_id = ? and s.schedule_date >= ? and s.schedule_date <= ? and status = 1", patientid, orgid, startime, endtime).
- Find(&schedules).Error
- return
- }
-
- func ToSeacherSheduleinformation(patientid int64, orgid int64, seachval string) (schedules []*models.PatientSchedule, err error) {
- db := service.XTReadDB().Table("xt_schedule as s")
- err = db.Preload("DeviceZone", "org_id = ? and status =1", orgid).
- Preload("DeviceNumber", "org_id = ? and status =1", orgid).
- Where("s.patient_id = ? and s.user_org_id = ? and s.bed_id = ?", patientid, orgid, seachval).Find(&schedules).Error
- return schedules, err
- }
-
- func DeleteScheduleinformationById(id int64) error {
- err := service.XTWriteDB().Model(models.Schedule{}).Where("id = ? ", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetPaitentType(patientid int64, orgid int64) (patientType []*models.PatientsType, err error) {
-
- err = service.XTReadDB().Where("patient_id = ? AND user_org_id = ?", patientid, orgid).Find(&patientType).Error
- return patientType, err
- }
|