coordinate_controller.go 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package coordinate
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "math/rand"
  12. "os"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type CoordinateController struct {
  18. controllers.BaseAuthAPIController
  19. }
  20. type ResultReg struct {
  21. ResultCode string `json:"resultCode"`
  22. ResultDesc string `json:"resultDesc"`
  23. InfoSeq string `json:"infoSeq"`
  24. }
  25. func CoordinateRegistRouters() {
  26. beego.Router("/coordinate/check", &CoordinateController{}, "get:SavePatientMessageInfo")
  27. beego.Router("/coordinate/register", &CoordinateController{}, "get:Register")
  28. beego.Router("/coordinate/getWaitPayDetail", &CoordinateController{}, "get:GetWaitPayDetail")
  29. beego.Router("/coordinate/opKeepAccounts", &CoordinateController{}, "get:OpKeepAccounts")
  30. beego.Router("/coordinate/opCancelKeepAccounts", &CoordinateController{}, "get:OpCancelKeepAccounts")
  31. }
  32. func (c *CoordinateController) SavePatientMessageInfo() {
  33. //result, request_log := service.SavePatientMessageInfo()
  34. }
  35. func (c *CoordinateController) Register() {
  36. patient_id, _ := c.GetInt64("patient_id")
  37. diagnosis_time := c.GetString("diagnosis_time")
  38. record_date := c.GetString("record_date")
  39. admin_user_id, _ := c.GetInt64("admin_user_id")
  40. patient, _ := service.GetPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  41. timeLayout := "2006-01-02"
  42. loc, _ := time.LoadLocation("Local")
  43. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  44. if err != nil {
  45. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  46. return
  47. }
  48. recordDateTime := theTime.Unix()
  49. patientPrescription, _ := service.FindPatientPrescriptionInfo(c.GetAdminUserInfo().CurrentOrgId, patient.ID, recordDateTime)
  50. if patientPrescription.ID == 0 {
  51. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(c.GetAdminUserInfo().CurrentOrgId, patient.ID, recordDateTime)
  52. }
  53. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  54. doctor_info, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, patientPrescription.DoctorId)
  55. admin_user_info, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  56. reg := models.Reg{
  57. DeptId: department.Number,
  58. PatientId: patient.ZbPatientId,
  59. PatientName: patient.Name,
  60. DoctorId: doctor_info.DoctorNumber,
  61. RegDate: strings.Split(diagnosis_time, " ")[0],
  62. RegFee: "0",
  63. TreatFee: "0",
  64. OperatorId: admin_user_info.UserName,
  65. }
  66. result, request_log := service.SaveReg(reg)
  67. fmt.Println(result)
  68. fmt.Println(request_log)
  69. saveLog(result, request_log, "reg", "挂号")
  70. var res ResultReg
  71. if err := json.Unmarshal([]byte(result), &res); err != nil {
  72. utils.ErrorLog("解析失败:%v", err)
  73. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  74. return
  75. }
  76. timestamp := time.Now().Unix()
  77. tempTime := time.Unix(timestamp, 0)
  78. timeFormat := tempTime.Format("20060102150405")
  79. chrgBchno := rand.Intn(100000) + 10000
  80. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  81. his := models.VMHisPatient{
  82. Name: patient.Name,
  83. Gender: patient.Gender,
  84. Birthday: patient.Birthday,
  85. MedicalTreatmentType: 0,
  86. IdType: 1,
  87. IdCardNo: patient.IdCardNo,
  88. BalanceAccountsType: 1,
  89. SocialType: 0,
  90. MedicalInsuranceNumber: "",
  91. RegisterType: 0,
  92. RegisterCost: 0,
  93. TreatmentCost: 0,
  94. Status: 1,
  95. Ctime: time.Now().Unix(),
  96. Mtime: time.Now().Unix(),
  97. PsnNo: patient.ZbPatientId,
  98. PsnCertType: "",
  99. Certno: patient.IdCardNo,
  100. PsnName: patient.Name,
  101. Gend: "",
  102. Naty: "",
  103. Brdy: "",
  104. Age: 0,
  105. Iinfo: "",
  106. Idetinfo: "",
  107. PatientId: patient.ID,
  108. RecordDate: theTime.Unix(),
  109. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  110. AdminUserId: admin_user_id,
  111. IsReturn: 1,
  112. IdCardType: 1,
  113. Doctor: patientPrescription.DoctorId,
  114. Departments: patientPrescription.Departments,
  115. IptOtpNo: ipt_otp_no,
  116. Number: res.InfoSeq,
  117. PhoneNumber: patient.Phone,
  118. }
  119. service.UpdateHisPatientStatus(&his)
  120. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "his_info": his,
  123. })
  124. }
  125. func (c *CoordinateController) GetWaitPayDetail() {
  126. result, request_log := service.GetWaitPayDetail()
  127. fmt.Println(result)
  128. fmt.Println(request_log)
  129. }
  130. func (c *CoordinateController) OpKeepAccounts() {
  131. //patient_id, _ := c.GetInt64("patient_id")
  132. //diagnosis_time := c.GetString("diagnosis_time")
  133. //record_date := c.GetString("record_date")
  134. //admin_user_id, _ := c.GetInt64("admin_user_id")
  135. //
  136. //result, request_log := service.OpKeepAccounts()
  137. //fmt.Println(result)
  138. //fmt.Println(request_log)
  139. }
  140. func (c *CoordinateController) OpCancelKeepAccounts() {
  141. result, request_log := service.OpCancelKeepAccounts()
  142. fmt.Println(result)
  143. fmt.Println(request_log)
  144. }
  145. func saveLog(result string, request string, infno string, desc string) {
  146. org_id, _ := beego.AppConfig.Int64("org_id")
  147. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  148. dir := miConfig.OrgName + "日志"
  149. utils.Mkdir(dir)
  150. month := time.Unix(1557042972, 0).Format("1")
  151. year := time.Now().Format("2006")
  152. month = time.Now().Format("01")
  153. day := time.Now().Format("02")
  154. hour := time.Now().Format("15")
  155. min := time.Now().Format("04")
  156. sec := time.Now().Format("05")
  157. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  158. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  159. file_name := file + ".txt"
  160. file_path := miConfig.OrgName + "日志" + "/" + file_name
  161. exist, _ := utils.PathExists(file_path)
  162. if exist { //存在
  163. fmt.Println("存在")
  164. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  165. if err != nil {
  166. fmt.Println("read fail")
  167. }
  168. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  169. n, _ := f.Seek(0, 2)
  170. _, err = f.WriteAt([]byte(content), n)
  171. } else { //不存在
  172. fmt.Println("文件不存在,创建文件")
  173. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  174. defer f.Close()
  175. if err != nil {
  176. } else {
  177. _, err = f.Write([]byte("记录日志"))
  178. }
  179. }
  180. }
  181. type Charset string
  182. const (
  183. UTF8 = Charset("UTF-8")
  184. GB18030 = Charset("GB18030")
  185. )