his_api_controller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "github.com/astaxie/beego"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type HisApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func HisManagerApiRegistRouters() {
  18. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  19. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  20. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  21. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  22. beego.Router("/api/hisdoctoradvice/create", &HisApiController{}, "post:CreateHisDoctorAdvice")
  23. //beego.Router("/api/hisproject/create", &HisApiController{}, "post:CreateHisProject")
  24. //beego.Router("/api/hisorder/create", &HisApiController{}, "post:CreateHisOrder")
  25. //beego.Router("/api/hisadditional/create", &HisApiController{}, "post:CreateHisAdditionalCharge")
  26. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  27. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  28. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "post:CreateHisPatientCaseHistory")
  29. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "post:CreateCaseHistoryTemplate")
  30. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  31. beego.Router("/api/doctorworkstation/printcasehistory/get", &HisApiController{}, "get:GetPrintHisPatientCaseHistory")
  32. }
  33. func (c *HisApiController) GetHisPatientList() {
  34. types, _ := c.GetInt64("type", 0)
  35. record_date := c.GetString("record_date")
  36. timeLayout := "2006-01-02"
  37. loc, _ := time.LoadLocation("Local")
  38. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  39. if err != nil {
  40. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  41. return
  42. }
  43. recordDateTime := theTime.Unix()
  44. adminInfo := c.GetAdminUserInfo()
  45. patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  46. if types == 0 {
  47. c.ServeSuccessJSON(map[string]interface{}{
  48. "list": patients,
  49. })
  50. } else if types == 1 { //未就诊
  51. var patientsOne []*service.Schedule
  52. for _, item := range patients {
  53. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  54. patientsOne = append(patientsOne, item)
  55. }
  56. }
  57. c.ServeSuccessJSON(map[string]interface{}{
  58. "list": patientsOne,
  59. })
  60. } else if types == 2 { //已就诊
  61. var patientsTwo []*service.Schedule
  62. for _, item := range patients {
  63. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  64. patientsTwo = append(patientsTwo, item)
  65. }
  66. }
  67. c.ServeSuccessJSON(map[string]interface{}{
  68. "list": patientsTwo,
  69. })
  70. }
  71. }
  72. func (c *HisApiController) GetHisPatientInfo() {
  73. patient_id, _ := c.GetInt64("patient_id")
  74. record_date := c.GetString("record_date")
  75. timeLayout := "2006-01-02"
  76. loc, _ := time.LoadLocation("Local")
  77. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  78. if err != nil {
  79. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  80. return
  81. }
  82. recordDateTime := theTime.Unix()
  83. admin := c.GetAdminUserInfo()
  84. his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  85. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  86. prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  87. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  88. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  89. c.ServeSuccessJSON(map[string]interface{}{
  90. "his_info": his_patient_info,
  91. "xt_info": xt_patient_info,
  92. "prescription": prescriptions,
  93. "case_history": case_history,
  94. })
  95. return
  96. }
  97. func (c *HisApiController) GetHisPrescriptionConfig() {
  98. adminInfo := c.GetAdminUserInfo()
  99. //获取医嘱模版
  100. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  101. //获取所有基础药
  102. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  103. //获取所有项目
  104. projects, _ := service.GetAllProjectList(adminInfo.CurrentOrgId)
  105. //获取所有项目组套
  106. c.ServeSuccessJSON(map[string]interface{}{
  107. "drugs": drugs,
  108. "advices_template": advices,
  109. "projects": projects,
  110. })
  111. }
  112. func (c *HisApiController) CreateHisPrescription() {
  113. record_date := c.GetString("record_date")
  114. patient_id, _ := c.GetInt64("patient_id")
  115. his_patient_id, _ := c.GetInt64("his_patient_id")
  116. types, _ := c.GetInt64("type")
  117. doctor := c.GetAdminUserInfo().AdminUser.Id
  118. timeLayout := "2006-01-02"
  119. loc, _ := time.LoadLocation("Local")
  120. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  121. if err != nil {
  122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  123. return
  124. }
  125. recordDateTime := theTime.Unix()
  126. prescription := &models.HisPrescription{
  127. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  128. RecordDate: recordDateTime,
  129. PatientId: patient_id,
  130. HisPatientId: his_patient_id,
  131. Status: 1,
  132. Ctime: time.Now().Unix(),
  133. Mtime: time.Now().Unix(),
  134. Type: types,
  135. Doctor: doctor,
  136. Creator: doctor,
  137. Modifier: doctor,
  138. }
  139. err = service.SaveHisPrescription(prescription)
  140. if err == nil {
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "msg": "保存成功",
  143. })
  144. return
  145. } else {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  147. return
  148. }
  149. }
  150. func (c *HisApiController) CreateHisDoctorAdvice() {
  151. patient_id, _ := c.GetInt64("patient_id")
  152. his_patient_id, _ := c.GetInt64("his_patient_id")
  153. prescription_id, _ := c.GetInt64("prescription_id")
  154. //patient, _ := c.GetInt64("id", 0)
  155. //if patient <= 0 {
  156. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  157. // return
  158. //}
  159. adminUserInfo := c.GetAdminUserInfo()
  160. //patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  161. //if patientInfo.ID == 0 {
  162. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  163. // return
  164. //}
  165. group_no, _ := c.GetInt64("group_no")
  166. if group_no <= 0 {
  167. group_no = 0
  168. }
  169. dataBody := make(map[string]interface{}, 0)
  170. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  171. if err != nil {
  172. utils.ErrorLog(err.Error())
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. return
  175. }
  176. timeLayout := "2006-01-02"
  177. loc, _ := time.LoadLocation("Local")
  178. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  179. utils.ErrorLog("advice_type")
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  181. return
  182. }
  183. adviceType := int64(dataBody["advice_type"].(float64))
  184. if adviceType != 1 && adviceType != 2 {
  185. utils.ErrorLog("advice_type != 1&&2")
  186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  187. return
  188. }
  189. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  190. utils.ErrorLog("start_time")
  191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  192. return
  193. }
  194. startTime2, _ := dataBody["start_time"].(string)
  195. time_arr := strings.Split(startTime2, " ")
  196. if len(time_arr) > 0 {
  197. startTime2 = time_arr[0]
  198. }
  199. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  200. utils.ErrorLog("advice_date")
  201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  202. return
  203. }
  204. adviceDate := startTime2
  205. if len(adviceDate) == 0 {
  206. utils.ErrorLog("len(adviceDate) == 0")
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  208. return
  209. }
  210. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  211. if err != nil {
  212. utils.ErrorLog(err.Error())
  213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  214. return
  215. }
  216. AdviceDate := theTime.Unix()
  217. RecordDate := theTime.Unix()
  218. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  219. utils.ErrorLog("start_time")
  220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  221. return
  222. }
  223. startTime, _ := dataBody["start_time"].(string)
  224. if len(startTime) == 0 {
  225. utils.ErrorLog("len(start_time) == 0")
  226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  227. return
  228. }
  229. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  230. if err != nil {
  231. utils.ErrorLog(err.Error())
  232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  233. return
  234. }
  235. StartTime := theTime.Unix()
  236. Remark := ""
  237. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  238. remark, _ := dataBody["remark"].(string)
  239. Remark = remark
  240. }
  241. var advices []*models.HisGroupAdvice
  242. // utils.TraceLog("%+v", dataBody["adviceNames"])
  243. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  244. utils.ErrorLog("adviceNames")
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. return
  247. }
  248. adviceNames := dataBody["adviceNames"].([]interface{})
  249. for _, adviceNameMap := range adviceNames {
  250. adviceNameM := adviceNameMap.(map[string]interface{})
  251. var advice models.HisGroupAdvice
  252. advice.Remark = Remark
  253. advice.AdviceType = adviceType
  254. advice.StartTime = StartTime
  255. advice.AdviceDate = AdviceDate
  256. advice.RecordDate = RecordDate
  257. advice.Status = 1
  258. advice.CreatedTime = time.Now().Unix()
  259. advice.UpdatedTime = time.Now().Unix()
  260. advice.StopState = 2
  261. advice.ExecutionState = 2
  262. advice.UserOrgId = adminUserInfo.CurrentOrgId
  263. advice.PatientId = patient_id
  264. advice.HisPatientId = his_patient_id
  265. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  266. advice.PrescriptionId = prescription_id
  267. //入口
  268. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  269. if errcode > 0 {
  270. c.ServeFailJSONWithSGJErrorCode(errcode)
  271. return
  272. }
  273. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  274. subdrugs := adviceNameM["subdrugs"].([]interface{})
  275. if len(subdrugs) > 0 {
  276. for _, subdrug := range subdrugs {
  277. var s models.HisGroupAdvice
  278. s.Remark = Remark
  279. s.AdviceType = adviceType
  280. s.StartTime = StartTime
  281. s.AdviceDate = AdviceDate
  282. s.RecordDate = RecordDate
  283. s.Status = 1
  284. s.CreatedTime = time.Now().Unix()
  285. s.UpdatedTime = time.Now().Unix()
  286. s.StopState = 2
  287. s.ExecutionState = 2
  288. s.HisPatientId = his_patient_id
  289. s.UserOrgId = adminUserInfo.CurrentOrgId
  290. s.PatientId = patient_id
  291. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  292. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  293. if errcode > 0 {
  294. c.ServeFailJSONWithSGJErrorCode(errcode)
  295. return
  296. }
  297. advice.Children = append(advice.Children, &s)
  298. }
  299. }
  300. }
  301. advices = append(advices, &advice)
  302. }
  303. newAdvices, createErr := service.CreateHisGroupAdvice(adminUserInfo.CurrentOrgId, advices, group_no)
  304. if createErr != nil {
  305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  306. return
  307. }
  308. c.ServeSuccessJSON(map[string]interface{}{
  309. "msg": "ok",
  310. "advices": newAdvices,
  311. })
  312. return
  313. }
  314. func (c *HisApiController) CreateHisAdditionalCharge() {
  315. his_patient_id, _ := c.GetInt64("his_patient_id")
  316. patient_id, _ := c.GetInt64("patient_id")
  317. record_date := c.GetString("record_date")
  318. timeLayout := "2006-01-02"
  319. loc, _ := time.LoadLocation("Local")
  320. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  321. if err != nil {
  322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  323. return
  324. }
  325. adminInfo := c.GetAdminUserInfo()
  326. recordDateTime := theTime.Unix()
  327. dataBody := make(map[string]interface{}, 0)
  328. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  329. if err != nil {
  330. utils.ErrorLog(err.Error())
  331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  332. return
  333. }
  334. var additions []*models.HisAdditionalCharge
  335. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  336. additions, _ := dataBody["addition"].([]interface{})
  337. if len(additions) > 0 {
  338. for _, item := range additions {
  339. items := item.(map[string]interface{})
  340. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  341. utils.ErrorLog("item_id")
  342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  343. return
  344. }
  345. item_id := int64(items["item_id"].(float64))
  346. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  347. utils.ErrorLog("item_name")
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  349. return
  350. }
  351. item_name := items["item_name"].(string)
  352. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  353. utils.ErrorLog("price")
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  355. return
  356. }
  357. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  358. ctime := time.Now().Unix()
  359. additional := &models.HisAdditionalCharge{
  360. PatientId: patient_id,
  361. HisPatientId: his_patient_id,
  362. UserOrgId: adminInfo.CurrentOrgId,
  363. RecordDate: recordDateTime,
  364. CreatedTime: ctime,
  365. UpdatedTime: ctime,
  366. Modifier: adminInfo.AdminUser.Id,
  367. Creator: adminInfo.AdminUser.Id,
  368. Price: price,
  369. ItemName: item_name,
  370. ItemId: item_id,
  371. Status: 1,
  372. }
  373. additions = append(additions, additional)
  374. }
  375. }
  376. }
  377. for _, item := range additions {
  378. service.CreateAddtionalCharge(item)
  379. }
  380. c.ServeSuccessJSON(map[string]interface{}{
  381. "msg": "创建成功",
  382. })
  383. }
  384. func (c *HisApiController) CreateHisPatientCaseHistory() {
  385. diagnostic := c.GetString("diagnostic")
  386. temperature, _ := c.GetFloat("temperature")
  387. blood_sugar, _ := c.GetFloat("blood_sugar")
  388. pulse, _ := c.GetFloat("pulse")
  389. sbp, _ := c.GetFloat("sbp")
  390. dbp, _ := c.GetFloat("dbp")
  391. blood_fat, _ := c.GetFloat("blood_fat")
  392. height, _ := c.GetFloat("height")
  393. sick_type, _ := c.GetInt64("sick_type")
  394. symptom := c.GetString("symptom")
  395. sick_date := c.GetString("sick_date")
  396. is_infect, _ := c.GetInt64("is_infect")
  397. chief_conplaint := c.GetString("chief_conplaint")
  398. history_of_present_illness := c.GetString("history_of_present_illness")
  399. past_history := c.GetString("past_history")
  400. personal_history := c.GetString("personal_history")
  401. family_history := c.GetString("family_history")
  402. record_date := c.GetString("record_date")
  403. patient_id, _ := c.GetInt64("patient_id")
  404. timeLayout := "2006-01-02"
  405. loc, _ := time.LoadLocation("Local")
  406. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  407. if err != nil {
  408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  409. return
  410. }
  411. recordDateTime := theTime.Unix()
  412. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  413. if err != nil {
  414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  415. return
  416. }
  417. sickTimes := sickTime.Unix()
  418. ctime := time.Now().Unix()
  419. caseHistory := models.HisPatientCaseHistory{
  420. HisPatientId: patient_id,
  421. Temperature: temperature,
  422. BloodSugar: blood_sugar,
  423. Pulse: pulse,
  424. Sbp: sbp,
  425. Dbp: dbp,
  426. Height: height,
  427. BloodFat: blood_fat,
  428. SickType: sick_type,
  429. Symptom: symptom,
  430. SickDate: sickTimes,
  431. IsInfect: is_infect,
  432. HistoryOfPresentIllness: history_of_present_illness,
  433. PastHistory: past_history,
  434. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  435. ChiefConplaint: chief_conplaint,
  436. PersonalHistory: personal_history,
  437. FamilyHistory: family_history,
  438. Diagnostic: diagnostic,
  439. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  440. Status: 1,
  441. Ctime: ctime,
  442. Mtime: ctime,
  443. RecordDate: recordDateTime,
  444. }
  445. err = service.SaveHisPatientCaseHistory(caseHistory)
  446. if err != nil {
  447. c.ServeSuccessJSON(map[string]interface{}{
  448. "msg": "保存成功",
  449. })
  450. }
  451. }
  452. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  453. patient_id, _ := c.GetInt64("patient_id", 0)
  454. adminUser := c.GetAdminUserInfo()
  455. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  456. c.ServeSuccessJSON(map[string]interface{}{
  457. "list": caseHistorys,
  458. })
  459. }
  460. func (c *HisApiController) GetHisPatientCaseHistory() {
  461. record_date, _ := c.GetInt64("record_date", 0)
  462. patient_id, _ := c.GetInt64("patient_id", 0)
  463. admin := c.GetAdminUserInfo()
  464. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  465. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  466. c.ServeSuccessJSON(map[string]interface{}{
  467. "info": info,
  468. "case_history": case_history,
  469. })
  470. }
  471. func (c *HisApiController) CreateCaseHistoryTemplate() {
  472. template_name := c.GetString("template_name")
  473. template_remark := c.GetString("template_remark")
  474. doctor := c.GetAdminUserInfo().AdminUser.Id
  475. diagnostic := c.GetString("diagnostic")
  476. chief_conplaint := c.GetString("chief_conplaint")
  477. history_of_present_illness := c.GetString("history_of_present_illness")
  478. past_history := c.GetString("past_history")
  479. personal_history := c.GetString("personal_history")
  480. family_history := c.GetString("family_history")
  481. record_date := c.GetString("record_date")
  482. timeLayout := "2006-01-02"
  483. loc, _ := time.LoadLocation("Local")
  484. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  485. if err != nil {
  486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  487. return
  488. }
  489. recordDateTime := theTime.Unix()
  490. ctime := time.Now().Unix()
  491. template := models.HisCaseHistoryTemplate{
  492. HistoryOfPresentIllness: history_of_present_illness,
  493. PastHistory: past_history,
  494. ChiefConplaint: chief_conplaint,
  495. PersonalHistory: personal_history,
  496. FamilyHistory: family_history,
  497. Diagnostic: diagnostic,
  498. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  499. Status: 1,
  500. Ctime: ctime,
  501. Mtime: ctime,
  502. RecordDate: recordDateTime,
  503. TemplateName: template_name,
  504. TemplateRemark: template_remark,
  505. Creator: doctor,
  506. Modifier: doctor,
  507. }
  508. err = service.SaveHisPatientCaseHistoryTemplate(template)
  509. if err == nil {
  510. c.ServeSuccessJSON(map[string]interface{}{
  511. "msg": "保存成功",
  512. })
  513. } else {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  515. return
  516. }
  517. }
  518. func (c *HisApiController) GetCaseHistoryTemplate() {
  519. admin := c.GetAdminUserInfo()
  520. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId)
  521. c.ServeSuccessJSON(map[string]interface{}{
  522. "template": template,
  523. })
  524. }
  525. func (c *HisApiController) GetPrintHisPatientCaseHistory() {
  526. }
  527. func (c *HisApiController) setAdviceWithJSON(advice *models.HisGroupAdvice, json map[string]interface{}) int {
  528. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  529. utils.ErrorLog("advice_name")
  530. return enums.ErrorCodeParamWrong
  531. }
  532. adviceName, _ := json["advice_name"].(string)
  533. if len(adviceName) == 0 {
  534. utils.ErrorLog("len(advice_name) == 0")
  535. return enums.ErrorCodeParamWrong
  536. }
  537. advice.AdviceName = adviceName
  538. adviceDesc, _ := json["advice_desc"].(string)
  539. advice.AdviceDesc = adviceDesc
  540. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  541. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  542. advice.DrugSpec = drugSpec
  543. }
  544. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  545. remark, _ := json["remark"].(string)
  546. advice.Remark = remark
  547. }
  548. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  549. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  550. // advice.Way = src_type
  551. //}
  552. if json["way"] == nil {
  553. advice.Way = 0
  554. } else {
  555. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  556. way := int64(json["way"].(float64))
  557. advice.Way = way
  558. }
  559. }
  560. if json["drug_id"] == nil {
  561. advice.DrugId = 0
  562. } else {
  563. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  564. drug_id := int64(json["drug_id"].(float64))
  565. advice.DrugId = drug_id
  566. }
  567. }
  568. if json["drug_name_id"] == nil {
  569. advice.DrugNameId = 0
  570. } else {
  571. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  572. drug_name_id := int64(json["drug_name_id"].(float64))
  573. advice.DrugNameId = drug_name_id
  574. }
  575. }
  576. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  577. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  578. advice.DrugSpecUnit = drugSpecUnit
  579. }
  580. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  581. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  582. advice.SingleDose = singleDose
  583. }
  584. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  585. singleDoseUnit, _ := json["single_dose_unit"].(string)
  586. advice.SingleDoseUnit = singleDoseUnit
  587. }
  588. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  589. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  590. advice.PrescribingNumber = prescribingNumber
  591. }
  592. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  593. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  594. advice.PrescribingNumberUnit = prescribingNumberUnit
  595. }
  596. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  597. deliveryWay, _ := json["delivery_way"].(string)
  598. advice.DeliveryWay = deliveryWay
  599. }
  600. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  601. executionFrequency, _ := json["execution_frequency"].(string)
  602. advice.ExecutionFrequency = executionFrequency
  603. }
  604. return 0
  605. }