new_dialysis_api_controller.go 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. package new_mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type NewDialysisApiController struct {
  15. NewMobileBaseAPIAuthController
  16. }
  17. func (this *NewDialysisApiController) GetIllnesslist() {
  18. illnesslist, err := service.GetIllnessListTwo()
  19. if err != nil {
  20. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  21. return
  22. }
  23. this.ServeSuccessJSON(map[string]interface{}{
  24. "illnesslist": illnesslist,
  25. })
  26. }
  27. func (this *NewDialysisApiController) GetPatient() {
  28. adminInfo := this.GetMobileAdminUserInfo()
  29. orgid := adminInfo.Org.Id
  30. page, _ := this.GetInt64("page")
  31. limit, _ := this.GetInt64("limit")
  32. patient, total, err := service.GetBloodDialysisPatient(orgid, page, limit)
  33. if err != nil {
  34. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  35. return
  36. }
  37. this.ServeSuccessJSON(map[string]interface{}{
  38. "patient": patient,
  39. "total": total,
  40. })
  41. }
  42. func (this *NewDialysisApiController) GetAllPatient() {
  43. fmt.Print("--------------------触发了没有")
  44. adminInfo := this.GetMobileAdminUserInfo()
  45. orgid := adminInfo.Org.Id
  46. page, _ := this.GetInt64("page")
  47. fmt.Print("page", page)
  48. limit, _ := this.GetInt64("limit")
  49. fmt.Print("limit", limit)
  50. patient, err := service.GetAllPatient(orgid)
  51. fmt.Print("err--------------------", err)
  52. if err != nil {
  53. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  54. return
  55. }
  56. this.ServeSuccessJSON(map[string]interface{}{
  57. "patient": patient,
  58. })
  59. }
  60. func (this *NewDialysisApiController) GetGeneratedialysisno() {
  61. adminInfo := this.GetMobileAdminUserInfo()
  62. orgid := adminInfo.Org.Id
  63. dialysisNo := service.ChechLastDialysisNoTwo(orgid)
  64. //fmt.Print("机构ID",adminUserInfo.CurrentOrgId)
  65. if dialysisNo == 0 {
  66. dialysisNo = 1
  67. } else {
  68. dialysisNo++
  69. }
  70. no := strconv.FormatInt(dialysisNo, 10)
  71. rep := 3 - len(no)
  72. if rep > 0 {
  73. no = strings.Repeat("0", rep) + no
  74. }
  75. this.ServeSuccessJSON(map[string]interface{}{
  76. "no": no,
  77. })
  78. return
  79. }
  80. func (this *NewDialysisApiController) SavePatient() {
  81. adminInfo := this.GetMobileAdminUserInfo()
  82. orgid := adminInfo.Org.Id
  83. dataBody := make(map[string]interface{}, 0)
  84. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  85. fmt.Print("err", err)
  86. name := dataBody["name"].(string)
  87. fmt.Println("姓名", name)
  88. sex := int64(dataBody["sex"].(float64))
  89. fmt.Print("性别", sex)
  90. idCard := dataBody["idCard"].(string)
  91. fmt.Print("身份证", idCard)
  92. birthday := dataBody["birthday"].(string)
  93. births := strings.Split(birthday, "-")
  94. fmt.Print("生日", birthday)
  95. birYear, _ := strconv.Atoi(births[0])
  96. age := time.Now().Year() - birYear
  97. ages := int64(age)
  98. fmt.Println("age是多少", ages)
  99. timeLayout := "2006-01-02 15:04:05"
  100. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  101. birth := theTime.Unix()
  102. fmt.Print(birth)
  103. phone := dataBody["phone"].(string)
  104. fmt.Print("电话号码", phone)
  105. patientType := dataBody["result"].([]interface{})
  106. fmt.Print("患者标签", patientType)
  107. dialysis := dataBody["dialysis"].(string)
  108. fmt.Print("透析号", dialysis)
  109. patientsoure := int64(dataBody["patientsoure"].(float64))
  110. fmt.Print("患者来源", patientsoure)
  111. lapseto := int64(dataBody["lapseto"].(float64))
  112. fmt.Print("留置状态", lapseto)
  113. contagions := dataBody["resultTwo"].([]interface{})
  114. fmt.Print("传染病", contagions)
  115. adminssionNumber := dataBody["admissionNumber"].(string)
  116. fmt.Print("住院号", adminssionNumber)
  117. fistdate := dataBody["fistDate"].(string)
  118. fmt.Print("首次透析日期", fistdate)
  119. times, err := utils.ParseTimeStringToTime(timeLayout, fistdate+"00:00:00")
  120. fisttime := times.Unix()
  121. fmt.Print(fisttime)
  122. diagonse := dataBody["diagnose"].(string)
  123. fmt.Print("诊断", diagonse)
  124. avatar := dataBody["avatar"].(string)
  125. fmt.Print("头像", avatar)
  126. //慢性病
  127. requipmentId := dataBody["requipmentId"].(string)
  128. fmt.Print("设备ID", requipmentId)
  129. slowContagions := dataBody["resultThree"].([]interface{})
  130. fmt.Print("慢性传染病", slowContagions)
  131. slowDisease := int64(dataBody["slowDisease"].(float64))
  132. fmt.Print("slowDisease", slowDisease)
  133. bloodPatient := int64(dataBody["bloodPatient"].(float64))
  134. fmt.Print("血透病人", bloodPatient)
  135. slowpatient := int64(dataBody["slowPatient"].(float64))
  136. fmt.Print("慢病病人", slowpatient)
  137. memberpatient := int64(dataBody["memberPatient"].(float64))
  138. fmt.Print("会员病人", memberpatient)
  139. //会员
  140. memberFistDate := dataBody["memberFistDate"].(string)
  141. fmt.Print("首次透析日期", memberFistDate)
  142. membertimes, err := utils.ParseTimeStringToTime(timeLayout, memberFistDate+"00:00:00")
  143. memtime := membertimes.Unix()
  144. fmt.Print(memtime)
  145. patient_type := int64(dataBody["patientType"].(float64))
  146. fmt.Print("病种", patient_type)
  147. treatmentmethod := int64(dataBody["treatmentMethod"].(float64))
  148. fmt.Print("治疗方式", treatmentmethod)
  149. _, errcode := service.GetPatientData(phone, orgid)
  150. if errcode == gorm.ErrRecordNotFound {
  151. patients := models.Patients{
  152. Name: name,
  153. Gender: sex,
  154. Birthday: birth,
  155. Age: ages,
  156. Phone: phone,
  157. Lapseto: lapseto,
  158. AdmissionNumber: adminssionNumber,
  159. FirstDialysisDate: fisttime,
  160. Diagnose: diagonse,
  161. Source: patientsoure,
  162. DialysisNo: dialysis,
  163. UserOrgId: orgid,
  164. Status: 1,
  165. CreatedTime: time.Now().Unix(),
  166. Avatar: avatar,
  167. }
  168. err := service.CreateOldPatient(&patients)
  169. fmt.Print("报错-------------", err)
  170. patient, err := service.GetLastOldPatient(7957)
  171. fmt.Print("病人ID", patient.ID)
  172. patientsNew := models.XtPatientsNew{
  173. Name: name,
  174. Gender: sex,
  175. Birthday: birth,
  176. Age: ages,
  177. Phone: phone,
  178. Lapseto: lapseto,
  179. AdmissionNumber: adminssionNumber,
  180. FirstDialysisDate: fisttime,
  181. Diagnose: diagonse,
  182. Source: patientsoure,
  183. DialysisNo: dialysis,
  184. UserOrgId: orgid,
  185. Status: 1,
  186. CreatedTime: time.Now().Unix(),
  187. Avatar: avatar,
  188. MemberPatients: memberpatient,
  189. BloodPatients: bloodPatient,
  190. SlowPatients: slowpatient,
  191. BloodId: patient.ID,
  192. }
  193. err = service.CreateNewPatient(&patientsNew)
  194. fmt.Print("报错", err)
  195. if err != nil {
  196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  197. return
  198. }
  199. this.ServeSuccessJSON(map[string]interface{}{
  200. "patient": patientsNew,
  201. })
  202. } else if errcode == nil {
  203. fmt.Print("病人已存在")
  204. return
  205. } else {
  206. }
  207. }
  208. func (this *NewDialysisApiController) GetPatientDetail() {
  209. id, _ := this.GetInt64("id")
  210. //获取病人详情信息
  211. detail, err := service.GetPatientDetailTwo(id)
  212. //获取血透医嘱管理
  213. if err != nil {
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  215. return
  216. }
  217. this.ServeSuccessJSON(map[string]interface{}{
  218. "patientDetail": detail,
  219. })
  220. }
  221. func (this *NewDialysisApiController) GetDoctorAdvices() {
  222. timeLayout := "2006-01-02"
  223. loc, _ := time.LoadLocation("Local")
  224. adminInfo := this.GetMobileAdminUserInfo()
  225. orgid := adminInfo.Org.Id
  226. id, _ := this.GetInt64("id")
  227. fmt.Print("id", id)
  228. //跟据新表id获取老表id
  229. newPatientInfo, _ := service.GetPatientDetailTwo(id)
  230. //获取病人ID
  231. doctor_type, _ := this.GetInt64("type")
  232. fmt.Print("医嘱内型", doctor_type)
  233. start := this.GetString("startime")
  234. fmt.Print("start", start)
  235. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  236. startime := startTimes.Unix()
  237. fmt.Print("开始时间", startime)
  238. end := this.GetString("endtime")
  239. fmt.Print("end", end)
  240. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
  241. endtime := endTimes.Unix()
  242. fmt.Print("结束时间", endtime)
  243. limit, _ := this.GetInt64("limit")
  244. page, _ := this.GetInt64("page")
  245. advice, total, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
  246. if err != nil {
  247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  248. return
  249. }
  250. this.ServeSuccessJSON(map[string]interface{}{
  251. "advice": advice,
  252. "total": total,
  253. })
  254. }
  255. func (this *NewDialysisApiController) GetDryWeight() {
  256. timeLayout := "2006-01-02"
  257. loc, _ := time.LoadLocation("Local")
  258. id, _ := this.GetInt64("id")
  259. fmt.Print("id", id)
  260. patient, _ := service.GetPatientDetailTwo(id)
  261. start := this.GetString("startime")
  262. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  263. startime := startTimes.Unix()
  264. fmt.Print("startime", startime)
  265. end := this.GetString("endtime")
  266. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
  267. endtime := endTimes.Unix()
  268. fmt.Print("endtime", endtime)
  269. limit, _ := this.GetInt64("limit")
  270. fmt.Print("limit", limit)
  271. page, _ := this.GetInt64("page")
  272. fmt.Print("page", page)
  273. adminInfo := this.GetMobileAdminUserInfo()
  274. orgid := adminInfo.Org.Id
  275. dryweight, total, err := service.GetDryWeight(patient.BloodId, startime, endtime, limit, page, orgid)
  276. if err != nil {
  277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  278. return
  279. }
  280. this.ServeSuccessJSON(map[string]interface{}{
  281. "dryweight": dryweight,
  282. "total": total,
  283. })
  284. }
  285. func (this *NewDialysisApiController) ToSearch() {
  286. adminUser := this.GetMobileAdminUserInfo()
  287. orgId := adminUser.Org.Id
  288. name := this.GetString("name")
  289. search, err := service.ToSearch(orgId, name)
  290. if err != nil {
  291. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  292. return
  293. }
  294. this.ServeSuccessJSON(map[string]interface{}{
  295. "search": search,
  296. })
  297. }