|
@@ -15,6 +15,7 @@ import (
|
|
|
"FollowUp_Notice/models/Tag"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/beego/beego/v2/adapter/orm"
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
"github.com/robfig/cron/v3"
|
|
|
"github.com/signintech/gopdf"
|
|
@@ -62,7 +63,7 @@ func (c *PatientController) Patient_List() {
|
|
|
// 通知状态 1待通知 2已通知
|
|
|
T_notice, _ := c.GetInt("T_notice")
|
|
|
// 复诊状态 1正常 2超时
|
|
|
- T_follow_up, _ := c.GetInt("T_follow_up")
|
|
|
+ //T_follow_up, _ := c.GetInt("T_follow_up")
|
|
|
// 年龄排序 1-升序 2降序
|
|
|
T_age_sort, _ := c.GetInt("T_age_sort")
|
|
|
// 下次复诊时间 1-升序 2降序
|
|
@@ -70,7 +71,7 @@ func (c *PatientController) Patient_List() {
|
|
|
Tag.Read_Tag_All_Map()
|
|
|
Illness.Read_Illness_All_Map()
|
|
|
Surgical.Read_Surgical_All_Map()
|
|
|
- R_List, R_cnt := Patient.Read_Patient_List(c.User.Id, T_number, T_name, T_tag, T_illness, T_surgical, T_notice, T_follow_up, T_age_sort, T_next_time_sort, page, page_z)
|
|
|
+ R_List, R_cnt := Patient.Read_Patient_List(c.User.Id, T_number, T_name, T_tag, T_illness, T_surgical, T_notice, T_age_sort, T_next_time_sort, page, page_z)
|
|
|
|
|
|
var r_jsons lib.R_JSONS
|
|
|
r_jsons.Num = R_cnt
|
|
@@ -97,7 +98,6 @@ func (c *PatientController) Patient_Add() {
|
|
|
T_notice_message, _ := c.GetInt("T_notice_message")
|
|
|
T_notice_interval := c.GetString("T_notice_interval")
|
|
|
T_record := c.GetString("T_record")
|
|
|
-
|
|
|
var_ := Patient.Patient{
|
|
|
T_uid: c.User.Id,
|
|
|
T_number: T_number,
|
|
@@ -110,40 +110,46 @@ func (c *PatientController) Patient_Add() {
|
|
|
T_notice_phone: T_notice_phone,
|
|
|
T_notice_message: T_notice_message,
|
|
|
T_notice_interval: T_notice_interval,
|
|
|
- T_record: T_record,
|
|
|
- T_State: 1,
|
|
|
- }
|
|
|
- T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
|
|
|
- var T_time string // 复诊时间
|
|
|
- var T_interval int // 复诊间隔
|
|
|
- if len(T_record_list) > 0 {
|
|
|
- temp := T_record_list[len(T_record_list)-1]
|
|
|
- T_time = strings.Split(temp, ",")[0]
|
|
|
- T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
|
|
|
- t, _ := lib.DateStrToTime(T_time)
|
|
|
- nextTime := t.AddDate(0, 0, T_interval)
|
|
|
- // 复诊状态 1正常 2超时 3结束
|
|
|
- var_.T_follow_up = 1
|
|
|
- if nextTime.Before(time.Now()) {
|
|
|
- var_.T_follow_up = 2
|
|
|
- }
|
|
|
- if T_interval == 0 {
|
|
|
- var_.T_follow_up = 3
|
|
|
- }
|
|
|
- var_.T_next_time = nextTime.Format("2006-01-02")
|
|
|
- var_.T_notice = 1
|
|
|
+ //T_record: T_record,
|
|
|
+ T_State: 1,
|
|
|
}
|
|
|
-
|
|
|
- _, err := Patient.Add_Patient(var_)
|
|
|
+ id, err := Patient.Add_Patient(var_)
|
|
|
if err != nil {
|
|
|
c.Data["json"] = lib.JSONS{Code: 209, Msg: "添加失败!"}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
|
|
|
+ if len(T_record_list) > 0 && len(T_record) > 0 {
|
|
|
+ for _, record := range T_record_list {
|
|
|
+ recordId := lib.To_int(strings.Split(record, ",")[0])
|
|
|
+ date := strings.Split(record, ",")[1]
|
|
|
+ illnessNoticeId := lib.To_int(strings.Split(record, ",")[2])
|
|
|
+ if recordId > 0 {
|
|
|
+ PatientRevisitRecord_Edit(c.User, recordId, illnessNoticeId, date)
|
|
|
+ } else {
|
|
|
+ PatientRevisitRecord_Add(c.User, int(id), illnessNoticeId, date)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新患者通知信息
|
|
|
+ psr, err := Patient.Read_Next_PatientRevisitRecord(int(id))
|
|
|
+ if err == nil {
|
|
|
+ var_.Id = int(id)
|
|
|
+ var_.T_next_time = psr.T_date
|
|
|
+ var_.T_notice = psr.T_notice
|
|
|
+ if err = Patient.Update_Patient(var_, "T_next_time", "T_notice"); err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 208, Msg: "添加失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
System.Add_UserLogs_T(c.User.T_uuid, "患者", "新增", var_)
|
|
|
|
|
|
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
|
|
|
c.ServeJSON()
|
|
|
return
|
|
|
|
|
@@ -216,34 +222,28 @@ func (c *PatientController) Patient_Edit() {
|
|
|
patient.T_notice_interval = T_notice_interval
|
|
|
cols = append(cols, "T_notice_interval")
|
|
|
}
|
|
|
- if len(T_record) > 0 {
|
|
|
- patient.T_record = T_record
|
|
|
- cols = append(cols, "T_record")
|
|
|
- }
|
|
|
T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
|
|
|
- var T_time string // 复诊时间
|
|
|
- var T_interval int // 复诊间隔
|
|
|
- if len(T_record_list) > 0 {
|
|
|
- temp := T_record_list[len(T_record_list)-1]
|
|
|
- T_time = strings.Split(temp, ",")[0]
|
|
|
- T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
|
|
|
- t, _ := lib.DateStrToTime(T_time)
|
|
|
- nextTime := t.AddDate(0, 0, T_interval)
|
|
|
- nextTimeStr := nextTime.Format("2006-01-02")
|
|
|
- if nextTimeStr != patient.T_next_time {
|
|
|
- patient.T_follow_up = 1
|
|
|
- if nextTime.Before(time.Now()) {
|
|
|
- patient.T_follow_up = 2
|
|
|
+ if len(T_record_list) > 0 && len(T_record) > 0 {
|
|
|
+ for _, record := range T_record_list {
|
|
|
+ recordId := lib.To_int(strings.Split(record, ",")[0])
|
|
|
+ date := strings.Split(record, ",")[1]
|
|
|
+ illnessNoticeId := lib.To_int(strings.Split(record, ",")[2])
|
|
|
+ if recordId > 0 {
|
|
|
+ PatientRevisitRecord_Edit(c.User, recordId, illnessNoticeId, date)
|
|
|
+ } else {
|
|
|
+ PatientRevisitRecord_Add(c.User, patient.Id, illnessNoticeId, date)
|
|
|
}
|
|
|
- if T_interval == 0 {
|
|
|
- patient.T_follow_up = 3
|
|
|
- }
|
|
|
- patient.T_next_time = nextTimeStr
|
|
|
- patient.T_notice = 1
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ // 更新患者通知信息
|
|
|
+ psr, err := Patient.Read_Next_PatientRevisitRecord(patient.Id)
|
|
|
+ if err == nil {
|
|
|
+ patient.T_next_time = psr.T_date
|
|
|
+ patient.T_notice = psr.T_notice
|
|
|
+ cols = append(cols, "T_next_time")
|
|
|
+ cols = append(cols, "T_notice")
|
|
|
}
|
|
|
- cols = append(cols, "T_next_time", "T_notice", "T_follow_up")
|
|
|
|
|
|
if err = Patient.Update_Patient(patient, cols...); err != nil {
|
|
|
c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
|
|
@@ -292,6 +292,213 @@ func (c *PatientController) Patient_Del() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// 复诊记录
|
|
|
+func (c *PatientController) PatientRevisitRecord_List() {
|
|
|
+
|
|
|
+ // 分页参数 初始化
|
|
|
+ page, _ := c.GetInt("page")
|
|
|
+ if page < 1 {
|
|
|
+ page = 1
|
|
|
+ }
|
|
|
+ page_z, _ := c.GetInt("page_z")
|
|
|
+ if page_z < 1 {
|
|
|
+ page_z = conf.Page_size
|
|
|
+ }
|
|
|
+ T_pid, _ := c.GetInt("T_pid")
|
|
|
+ Illness.Read_IllnessNotice_All_Map()
|
|
|
+ R_List, R_cnt := Patient.Read_PatientRevisitRecord_List(T_pid, page, page_z)
|
|
|
+
|
|
|
+ var r_jsons lib.R_JSONS
|
|
|
+ r_jsons.Num = R_cnt
|
|
|
+ r_jsons.Data = R_List
|
|
|
+ r_jsons.Page = page
|
|
|
+ r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+func PatientRevisitRecord_Add(user Account.User, T_pid, T_illnessNotice int, T_date string) (err error) {
|
|
|
+
|
|
|
+ //date, _ := lib.DateStrToTime(T_date)
|
|
|
+ //nowDate := lib.NowDate()
|
|
|
+ // 超过12点,最早只能通知后天的复诊(提前一天)
|
|
|
+ //if time.Now().Hour() >= 12 {
|
|
|
+ // if nowDate.After(date.AddDate(0, 0, -2)) {
|
|
|
+ // c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("复诊时间必须大于%s!", nowDate.AddDate(0, 0, 1).Format("2006年01月02日"))}
|
|
|
+ // c.ServeJSON()
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //} else {
|
|
|
+ // // 未超过12点,最早只能通知明天的复诊(提前一天)
|
|
|
+ // if nowDate.After(date.AddDate(0, 0, -1)) {
|
|
|
+ // c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("复诊时间必须大于%s!", nowDate.Format("2006年01月02日"))}
|
|
|
+ // c.ServeJSON()
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ var_ := Patient.PatientRevisitRecord{
|
|
|
+ T_date: T_date,
|
|
|
+ T_pid: T_pid,
|
|
|
+ T_illness_notice: T_illnessNotice,
|
|
|
+ T_notice: 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ //prr, err := Patient.Read_PatientRevisitRecord_ByT_date(T_pid, T_date)
|
|
|
+ //if prr.Id > 0 {
|
|
|
+ // return errors.New("日期重复")
|
|
|
+ //}
|
|
|
+ _, err = Patient.Add_PatientRevisitRecord(var_)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ System.Add_UserLogs_T(user.T_uuid, "复诊记录", "添加", var_)
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+func PatientRevisitRecord_Edit(user Account.User, T_id, T_illnessNotice int, T_date string) (err error) {
|
|
|
+
|
|
|
+ PatientRevisitRecord_r, err := Patient.Read_PatientRevisitRecord_ById(T_id)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ //prr, err := Patient.Read_PatientRevisitRecord_ByT_date(PatientRevisitRecord_r.T_pid, T_date)
|
|
|
+ //if prr.Id > 0 && prr.Id != PatientRevisitRecord_r.Id {
|
|
|
+ // err = errors.New("日期重复")
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ if PatientRevisitRecord_r.T_illness_notice == T_illnessNotice && PatientRevisitRecord_r.T_date == T_date {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ // 已通知,禁止修改
|
|
|
+ if PatientRevisitRecord_r.T_notice == 2 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if T_illnessNotice > 0 {
|
|
|
+ PatientRevisitRecord_r.T_illness_notice = T_illnessNotice
|
|
|
+ }
|
|
|
+ if len(T_date) > 0 {
|
|
|
+ PatientRevisitRecord_r.T_date = T_date
|
|
|
+ }
|
|
|
+
|
|
|
+ if err = Patient.Update_PatientRevisitRecord(PatientRevisitRecord_r, "T_illness_notice", "T_date"); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //patient, err := Patient.Read_Patient_ById(PatientRevisitRecord_r.T_pid)
|
|
|
+ //if err != nil {
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //psr, err := Patient.Read_Next_PatientRevisitRecord(PatientRevisitRecord_r.T_pid)
|
|
|
+ //if err == nil {
|
|
|
+ // patient.T_next_time = psr.T_date
|
|
|
+ // patient.T_notice = psr.T_notice
|
|
|
+ // if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ System.Add_UserLogs_T(user.T_uuid, "复诊记录", "修改", PatientRevisitRecord_r)
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (c *PatientController) PatientRevisitRecord_Del() {
|
|
|
+
|
|
|
+ T_id, _ := c.GetInt("T_id")
|
|
|
+ if T_id == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ PatientRevisitRecord_r, err := Patient.Read_PatientRevisitRecord_ById(T_id)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 已通知,禁止删除
|
|
|
+ if PatientRevisitRecord_r.T_notice == 2 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "已通知,禁止删除!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if err = Patient.Delete_PatientRevisitRecord(PatientRevisitRecord_r); err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ patient, err := Patient.Read_Patient_ById(PatientRevisitRecord_r.T_pid)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "查询患者信息失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count, err := Patient.Read_PatientRevisitRecord_Count_ByT_pid(patient.Id)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 203, Msg: "查询患者信息失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通知记录为0时,将患者信息复诊时间和通知状态置为空
|
|
|
+ if count == 0 {
|
|
|
+ patient.T_next_time = ""
|
|
|
+ patient.T_notice = 0
|
|
|
+ if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ psr, err := Patient.Read_Next_PatientRevisitRecord(PatientRevisitRecord_r.T_pid)
|
|
|
+ if err == nil {
|
|
|
+ patient.T_next_time = psr.T_date
|
|
|
+ patient.T_notice = psr.T_notice
|
|
|
+ if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if err == orm.ErrNoRows {
|
|
|
+ psr, err = Patient.Read_Last_PatientRevisitRecord(PatientRevisitRecord_r.T_pid)
|
|
|
+ if err == nil {
|
|
|
+ patient.T_next_time = psr.T_date
|
|
|
+ patient.T_notice = psr.T_notice
|
|
|
+ // 已复诊 - 结束
|
|
|
+ // 未复诊 - 超时
|
|
|
+ // patient.T_follow_up 复诊状态 1正常 2超时 3结束
|
|
|
+ //if psr.T_follow_up == 1 {
|
|
|
+ // patient.T_follow_up = 3
|
|
|
+ //} else {
|
|
|
+ // patient.T_follow_up = 2
|
|
|
+ //}
|
|
|
+ if err = Patient.Update_Patient(patient, "T_next_time", "T_notice"); err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 208, Msg: "修改失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ System.Add_UserLogs(c.User.T_uuid, "复诊记录", "删除", strconv.Itoa(T_id))
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// 发送患者满意度调查
|
|
|
func (c *PatientController) Patient_Send_Satisfaction() {
|
|
|
T_pid := c.GetString("T_pid")
|
|
@@ -346,6 +553,12 @@ func (c *PatientController) VoiceCall_Status() {
|
|
|
// {"eventType":"callout","statusInfo":{"sessionId":"1201_14852_4294967295_20230529072219@callenabler245.huaweicaas.com","timestamp":"2023-05-29 07:22:19","caller":"+8651668971369","called":"+8618086869080"}}
|
|
|
logs.Println("VoiceCall RequestBody-", string(c.Ctx.Input.RequestBody))
|
|
|
|
|
|
+ //callout:呼出事件
|
|
|
+ //alerting:振铃事件
|
|
|
+ //answer:应答事件
|
|
|
+ //collectInfo:放音收号结果事件
|
|
|
+ //disconnect:挂机事件
|
|
|
+
|
|
|
type RequestBody struct {
|
|
|
EventType string `json:"eventType"`
|
|
|
StatusInfo struct {
|
|
@@ -373,13 +586,23 @@ func (c *PatientController) VoiceCall_Status() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ // 应答时间 向redis存入用户接听时间
|
|
|
+ if body.EventType == "answer" {
|
|
|
+ Patient.Redis_PatientSend_Set(body.StatusInfo.SessionId, body.StatusInfo.Timestamp)
|
|
|
+ }
|
|
|
+
|
|
|
if body.EventType == "disconnect" {
|
|
|
- if body.StatusInfo.StateCode == 0 {
|
|
|
+ sTime, _ := Patient.Redis_PatientSend_Get(body.StatusInfo.SessionId)
|
|
|
+ s_time, _ := lib.TimeStrToTime(sTime)
|
|
|
+ e_time, _ := lib.TimeStrToTime(body.StatusInfo.Timestamp)
|
|
|
+ // 华为语音通知8008放音收号失败,也视为通话成功
|
|
|
+ if body.StatusInfo.StateCode == 0 || body.StatusInfo.StateCode == 8008 {
|
|
|
r.T_State = 1
|
|
|
}
|
|
|
r.T_code = strconv.Itoa(body.StatusInfo.StateCode)
|
|
|
r.T_remark = body.StatusInfo.StateDesc
|
|
|
- err = Patient.Update_PatientSend(r, "T_State", "T_remark", "T_code")
|
|
|
+ r.T_fee = e_time.Sub(s_time).Seconds()
|
|
|
+ err = Patient.Update_PatientSend(r, "T_State", "T_remark", "T_code", "T_fee")
|
|
|
if err != nil {
|
|
|
c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改发送状态失败!"}
|
|
|
c.ServeJSON()
|
|
@@ -500,8 +723,8 @@ func (c *PatientController) Patient_Import() {
|
|
|
message = 1
|
|
|
}
|
|
|
// 下次复诊间隔天数
|
|
|
- T_next_interval := c.GetString("T_next_interval")
|
|
|
- T_record := time.Now().Format("2006-01-02") + "," + T_next_interval + "|"
|
|
|
+ //T_next_interval := c.GetString("T_next_interval")
|
|
|
+ //T_record := time.Now().Format("2006-01-02") + "," + T_next_interval + "|"
|
|
|
var_ := Patient.Patient{
|
|
|
T_uid: c.User.Id,
|
|
|
T_number: T_number,
|
|
@@ -514,29 +737,29 @@ func (c *PatientController) Patient_Import() {
|
|
|
T_notice_phone: phone,
|
|
|
T_notice_message: message,
|
|
|
T_notice_interval: "1,3",
|
|
|
- T_record: T_record,
|
|
|
- T_State: 1,
|
|
|
- }
|
|
|
- T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
|
|
|
- var T_time string // 复诊时间
|
|
|
- var T_interval int // 复诊间隔
|
|
|
- if len(T_record_list) > 0 {
|
|
|
- temp := T_record_list[len(T_record_list)-1]
|
|
|
- T_time = strings.Split(temp, ",")[0]
|
|
|
- T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
|
|
|
- t, _ := lib.DateStrToTime(T_time)
|
|
|
- nextTime := t.AddDate(0, 0, T_interval)
|
|
|
- // 复诊状态 1正常 2超时 3结束
|
|
|
- var_.T_follow_up = 1
|
|
|
- if nextTime.Before(time.Now()) {
|
|
|
- var_.T_follow_up = 2
|
|
|
- }
|
|
|
- if T_interval == 0 {
|
|
|
- var_.T_follow_up = 3
|
|
|
- }
|
|
|
- var_.T_next_time = nextTime.Format("2006-01-02")
|
|
|
- var_.T_notice = 1
|
|
|
+ //T_record: T_record,
|
|
|
+ T_State: 1,
|
|
|
}
|
|
|
+ //T_record_list := strings.Split(strings.Trim(T_record, "|"), "|")
|
|
|
+ //var T_time string // 复诊时间
|
|
|
+ //var T_interval int // 复诊间隔
|
|
|
+ //if len(T_record_list) > 0 {
|
|
|
+ // temp := T_record_list[len(T_record_list)-1]
|
|
|
+ // T_time = strings.Split(temp, ",")[0]
|
|
|
+ // T_interval, _ = strconv.Atoi(strings.Split(temp, ",")[1])
|
|
|
+ // t, _ := lib.DateStrToTime(T_time)
|
|
|
+ // nextTime := t.AddDate(0, 0, T_interval)
|
|
|
+ // // 复诊状态 1正常 2超时 3结束
|
|
|
+ // var_.T_follow_up = 1
|
|
|
+ // if nextTime.Before(time.Now()) {
|
|
|
+ // var_.T_follow_up = 2
|
|
|
+ // }
|
|
|
+ // if T_interval == 0 {
|
|
|
+ // var_.T_follow_up = 3
|
|
|
+ // }
|
|
|
+ // var_.T_next_time = nextTime.Format("2006-01-02")
|
|
|
+ // var_.T_notice = 1
|
|
|
+ //}
|
|
|
|
|
|
_, err = Patient.Add_Patient(var_)
|
|
|
if err != nil {
|
|
@@ -809,8 +1032,9 @@ func Cron_Patient() {
|
|
|
c := cron.New(cron.WithSeconds())
|
|
|
//给对象增加定时任务
|
|
|
//c.AddFunc("0 */1 * * * ?", Cron_Patient_ChangeFollowUp)
|
|
|
- c.AddFunc("@daily", Cron_Patient_ChangeFollowUp) // 修改复诊状态
|
|
|
+ c.AddFunc("@daily", Cron_Patient_ChangeNextTime) // 修改下次复诊时间
|
|
|
c.AddFunc("0 0 12 * * *", Cron_Patient_Notice) // 消息通知
|
|
|
+ //c.AddFunc("0 */1 * * * ?", Cron_Patient_Notice) // 消息通知
|
|
|
|
|
|
//启动定时任务
|
|
|
c.Start()
|
|
@@ -821,36 +1045,57 @@ func Cron_Patient() {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// 修改患者复诊状态 每晚0点统计
|
|
|
-// 已通知并且下次复诊时间超过当期时间 已过期
|
|
|
-func Cron_Patient_ChangeFollowUp() {
|
|
|
+// 修改患者下次复诊时间
|
|
|
+// 复诊记录有超过今日的,替换为今日后最近一条
|
|
|
+// 复诊记录无超过今日的,替换为今日前最近一条
|
|
|
+func Cron_Patient_ChangeNextTime() {
|
|
|
|
|
|
T_date := time.Now().Format("2006-01-02")
|
|
|
- logs.Info("开始处理" + T_date + "患者通知状态")
|
|
|
+ logs.Info("开始处理" + T_date + "下次通知时间")
|
|
|
// T_notice 通知状态 1待通知 2已通知
|
|
|
// T_follow_up 复诊状态 1正常 2超时
|
|
|
- list, _ := Patient.Read_Patient_List(0, "", "", 0, 0, 0, 2, 1, 0, 0, 0, 9999)
|
|
|
- for _, v := range list {
|
|
|
- nextTime, _ := lib.DateStrToTime(v.T_next_time)
|
|
|
- if nextTime.Before(time.Now()) {
|
|
|
- var_ := Patient.Patient{Id: v.Id, T_follow_up: 2}
|
|
|
- if err := Patient.Update_Patient(var_, "T_follow_up"); err != nil {
|
|
|
- System.Add_SysLogs_T("复诊状态", "修改失败", var_)
|
|
|
+ list, _ := Patient.Read_Patient_List_Lt_NextTime(0, T_date)
|
|
|
+ for _, patient := range list {
|
|
|
+
|
|
|
+ psr, err := Patient.Read_Next_PatientRevisitRecord(patient.Id)
|
|
|
+ if err == nil {
|
|
|
+ p := Patient.Patient{
|
|
|
+ Id: patient.Id,
|
|
|
+ T_next_time: psr.T_date,
|
|
|
+ T_notice: psr.T_notice,
|
|
|
+ }
|
|
|
+
|
|
|
+ if err = Patient.Update_Patient(p, "T_next_time", "T_notice"); err != nil {
|
|
|
+ System.Add_SysLogs_T("复诊状态", "修改失败", p)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if err == orm.ErrNoRows {
|
|
|
+ psr, err = Patient.Read_Last_PatientRevisitRecord(patient.Id)
|
|
|
+ if err == nil {
|
|
|
+ p := Patient.Patient{
|
|
|
+ Id: patient.Id,
|
|
|
+ T_next_time: psr.T_date,
|
|
|
+ T_notice: psr.T_notice,
|
|
|
+ }
|
|
|
+ if psr.T_date == patient.T_next_time {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if err = Patient.Update_Patient(p, "T_next_time", "T_notice"); err != nil {
|
|
|
+ System.Add_SysLogs_T("复诊状态", "修改失败", p)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 给患者发送消息提醒 每天8点
|
|
|
-// 发送成功将通知状态修改未已通知H
|
|
|
+// 给患者发送消息提醒 每天12点
|
|
|
+// 发送成功将通知状态修改为已通知
|
|
|
func Cron_Patient_Notice() {
|
|
|
|
|
|
T_date := time.Now().Format("2006-01-02")
|
|
|
logs.Info("开始发送" + T_date + "患者通知")
|
|
|
// T_notice 通知状态 1待通知 2已通知
|
|
|
- // T_follow_up 复诊状态 1正常 2超时 3结束
|
|
|
- now := time.Now()
|
|
|
- nowDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
|
|
+ nowDate := lib.NowDate()
|
|
|
userList, _ := Account.Read_User_List("", 0, 9999)
|
|
|
for _, user := range userList {
|
|
|
// T_arrears_notice 欠费通知 1继续通知 2终止通知
|
|
@@ -859,25 +1104,25 @@ func Cron_Patient_Notice() {
|
|
|
if (user.T_money <= 0 && user.T_arrears_notice == 2) || user.T_State == 2 {
|
|
|
continue
|
|
|
}
|
|
|
- patientList, _ := Patient.Read_Patient_List(user.Id, "", "", 0, 0, 0, 0, 1, 0, 0, 0, 9999)
|
|
|
+ patientList := Patient.Read_Patient_List_For_Notice(user.Id, T_date)
|
|
|
for _, v := range patientList {
|
|
|
- nextTime, _ := lib.DateStrToTime(v.T_next_time)
|
|
|
+ nextTime, _ := lib.DateStrToTime(v.T_date)
|
|
|
var success bool
|
|
|
// 提前1天
|
|
|
if strings.Contains(v.T_notice_interval, "1") && nextTime.AddDate(0, 0, -1) == nowDate {
|
|
|
- success = Send_Notice(nextTime, user, v)
|
|
|
+ success = Send_Notice(nextTime, user, v, "提前一天")
|
|
|
}
|
|
|
// 提前2天
|
|
|
if strings.Contains(v.T_notice_interval, "2") && nextTime.AddDate(0, 0, -2) == nowDate {
|
|
|
- success = Send_Notice(nextTime, user, v)
|
|
|
+ success = Send_Notice(nextTime, user, v, "提前两天")
|
|
|
}
|
|
|
// 提前3天
|
|
|
if strings.Contains(v.T_notice_interval, "3") && nextTime.AddDate(0, 0, -3) == nowDate {
|
|
|
- success = Send_Notice(nextTime, user, v)
|
|
|
+ success = Send_Notice(nextTime, user, v, "提前三天")
|
|
|
}
|
|
|
// 提前7天
|
|
|
if strings.Contains(v.T_notice_interval, "7") && nextTime.AddDate(0, 0, -7) == nowDate {
|
|
|
- success = Send_Notice(nextTime, user, v)
|
|
|
+ success = Send_Notice(nextTime, user, v, "提前七天")
|
|
|
}
|
|
|
if success == true {
|
|
|
// 通知状态 1待通知 2已通知
|
|
@@ -892,11 +1137,29 @@ func Cron_Patient_Notice() {
|
|
|
}
|
|
|
|
|
|
// 发送通知(短信、电话)
|
|
|
-func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patient_R) (Success bool) {
|
|
|
+func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patient_R2, days string) (Success bool) {
|
|
|
|
|
|
+ // 查询复诊记录id
|
|
|
+ revisit_record_r, err := Patient.Read_PatientRevisitRecord_ById(patient.T_patient_revisit_record_id)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 查询疾病通知
|
|
|
+ IllnessNotice_r, err := Illness.Read_IllnessNotice_ById(revisit_record_r.T_illness_notice)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ // 短信模板审核通过才能发送通知信息
|
|
|
+ if IllnessNotice_r.T_template_status != "2" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ T_content := strings.Replace(IllnessNotice_r.T_content, "{患者名称}", patient.T_name, -1)
|
|
|
+ T_content = strings.Replace(T_content, "{复诊时间}", nextTime.Format("2006年01月02日"), -1)
|
|
|
+ T_remark := ""
|
|
|
//发送短信通知
|
|
|
if patient.T_notice_message == 1 {
|
|
|
- res, err := submail.SmsXSend(user.T_template_id, patient.T_phone, patient.T_name, nextTime.Format("2006年01月02日"))
|
|
|
+
|
|
|
+ res, err := submail.SmsXSend(IllnessNotice_r.T_template_id, patient.T_phone, patient.T_name, nextTime.Format("2006年01月02日"))
|
|
|
if err != nil {
|
|
|
System.Add_SysLogs_T("复诊通知", "短信通知失败", patient)
|
|
|
}
|
|
@@ -912,16 +1175,22 @@ func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patien
|
|
|
T_code: res.Code,
|
|
|
T_State: 1,
|
|
|
}
|
|
|
+ msg := ""
|
|
|
if res.Status == "error" {
|
|
|
smsSend.T_State = 0
|
|
|
+ msg = "通知失败"
|
|
|
}
|
|
|
if res.Status == "success" {
|
|
|
Success = true
|
|
|
+ msg = "通知成功"
|
|
|
}
|
|
|
_, err = Patient.Add_PatientSend(smsSend)
|
|
|
if err != nil {
|
|
|
System.Add_SysLogs_T("复诊通知", "添加发送记录失败", patient)
|
|
|
}
|
|
|
+
|
|
|
+ // 1201_134,2022-07-24,提前三天,电话,通知成功|1201_135,2022-07-24,提前三天,短信,通知成功
|
|
|
+ T_remark += fmt.Sprintf("%s,%s,%s,短信,%s|", res.Send_id, time.Now().Format("2006-01-02"), days, msg)
|
|
|
}
|
|
|
|
|
|
if patient.T_notice_phone == 1 {
|
|
@@ -953,12 +1222,13 @@ func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patien
|
|
|
//}
|
|
|
|
|
|
// ----------- 塞班语音通知
|
|
|
- res, err := submail.VoiceXSend(patient.T_phone, user.T_user, patient.T_name, nextTime.Format("2006年01月02日"))
|
|
|
+ //res, err := submail.VoiceXSend(patient.T_phone, user.T_user, patient.T_name, nextTime.Format("2006年01月02日"))
|
|
|
+ res, err := submail.VoiceSend(patient.T_phone, user.T_user+"提醒您:"+T_content)
|
|
|
if err != nil {
|
|
|
System.Add_SysLogs_T("复诊通知", "电话通知失败", patient)
|
|
|
}
|
|
|
|
|
|
- // 保存短信发送记录
|
|
|
+ // 保存语音发送记录
|
|
|
send := Patient.PatientSend{
|
|
|
T_uid: user.Id,
|
|
|
T_pid: patient.Id,
|
|
@@ -975,18 +1245,28 @@ func Send_Notice(nextTime time.Time, user Account.User_R, patient Patient.Patien
|
|
|
if err != nil {
|
|
|
System.Add_SysLogs_T("复诊通知", "添加语音发送记录失败", send)
|
|
|
}
|
|
|
+ msg := ""
|
|
|
if res.Status == "error" {
|
|
|
send.T_State = 0
|
|
|
+ msg = "通知失败"
|
|
|
}
|
|
|
if res.Status == "success" {
|
|
|
Success = true
|
|
|
+ msg = "通知成功"
|
|
|
}
|
|
|
_, err = Patient.Add_PatientSend(send)
|
|
|
if err != nil {
|
|
|
System.Add_SysLogs_T("复诊通知", "添加语音发送记录失败", send)
|
|
|
}
|
|
|
+ // 1201_134,2022-07-24,提前三天,电话,通知成功|1201_135,2022-07-24,提前三天,短信,通知成功
|
|
|
+ T_remark += fmt.Sprintf("%s,%s,%s,电话,%s|", res.Send_id, time.Now().Format("2006-01-02"), days, msg)
|
|
|
+ }
|
|
|
|
|
|
+ if Success == true {
|
|
|
+ revisit_record_r.T_notice = 2
|
|
|
}
|
|
|
+ revisit_record_r.T_remark += T_remark
|
|
|
+ Patient.Update_PatientRevisitRecord(revisit_record_r, "T_notice", "T_remark")
|
|
|
|
|
|
return Success
|
|
|
}
|