his_config_api_controller.go 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. "time"
  12. )
  13. type HisConfigApiController struct {
  14. BaseAuthAPIController
  15. }
  16. func HisConfigApiRegistRouters() {
  17. beego.Router("/api/his/patient/list", &HisConfigApiController{}, "get:GetAllHisPatientsList")
  18. beego.Router("/api/his/prescriptiontemplate/list", &HisConfigApiController{}, "get:GetPrescriptionTemplateList")
  19. beego.Router("/api/his/prescriptiontemplate/info", &HisConfigApiController{}, "get:GetPrescriptionTemplateInfo")
  20. beego.Router("/api/his/prescriptiontemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionTemplate")
  21. beego.Router("/api/his/prescriptiontemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionTemplate")
  22. beego.Router("/api/his/prescriptioninfotemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoTemplate")
  23. beego.Router("/api/his/advicetemplate/delete", &HisConfigApiController{}, "post:DeleteAdviceTemplate")
  24. beego.Router("/api/his/projecttemplate/delete", &HisConfigApiController{}, "post:DeleteProjectTemplate")
  25. //beego.Router("/api/his/responsibilitydoctor/get", &HisConfigApiController{}, "get:GetResponsibilityDoctor")
  26. }
  27. func (c *HisConfigApiController) GetAllHisPatientsList() {
  28. patients, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  29. c.ServeSuccessJSON(map[string]interface{}{
  30. "list": patients,
  31. })
  32. }
  33. func (c *HisConfigApiController) GetPrescriptionTemplateList() {
  34. patient_id, _ := c.GetInt64("patient_id", 0)
  35. page, _ := c.GetInt64("page", 0)
  36. limit, _ := c.GetInt64("limit", 0)
  37. if page <= 0 {
  38. page = 1
  39. }
  40. if limit <= 0 {
  41. limit = 10
  42. }
  43. if patient_id <= 0 {
  44. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  45. return
  46. }
  47. templates, total, _ := service.GetHisPrescriptionTemplatesList(patient_id, c.GetAdminUserInfo().CurrentOrgId, page, limit)
  48. c.ServeSuccessJSON(map[string]interface{}{
  49. "list": templates,
  50. "total": total,
  51. })
  52. }
  53. func (c *HisConfigApiController) GetPrescriptionTemplateInfo() {
  54. id, _ := c.GetInt64("id", 0)
  55. template, _ := service.GetHisPrescriptionTemplateByID(id)
  56. prescriptions, _ := service.GetHisPrescriptionTemplate(template.ID, c.GetAdminUserInfo().CurrentOrgId)
  57. c.ServeSuccessJSON(map[string]interface{}{
  58. "template": template,
  59. "prescriptions": prescriptions,
  60. })
  61. }
  62. func (c *HisConfigApiController) CreatePrescriptionTemplate() {
  63. id, _ := c.GetInt64("id")
  64. name := c.GetString("name")
  65. mode_id, _ := c.GetInt64("mode_id", 0)
  66. types, _ := c.GetInt64("type", 0)
  67. patient_id, _ := c.GetInt64("patient_id", 0)
  68. types = 1
  69. adminInfo := c.GetAdminUserInfo()
  70. if id == 0 {
  71. mode_template, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id)
  72. if mode_template.ID > 0 {
  73. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  74. return
  75. }
  76. }
  77. src_template, _ := service.GetHisPrescriptionTemplateByID(id)
  78. if src_template.ID == 0 {
  79. template := models.HisPrescriptionTemplate{
  80. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  81. PatientId: patient_id,
  82. Type: types,
  83. Status: 1,
  84. Ctime: time.Now().Unix(),
  85. Mtime: time.Now().Unix(),
  86. Name: name,
  87. Mode: mode_id,
  88. }
  89. src_template = template
  90. service.CreateHisPrescriptionTemplate(&src_template)
  91. } else {
  92. src_template.Name = name
  93. src_template.Mode = mode_id
  94. service.SaveHisPrescriptionTemplate(&src_template)
  95. }
  96. dataBody := make(map[string]interface{}, 0)
  97. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  98. if err != nil {
  99. utils.ErrorLog(err.Error())
  100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  101. return
  102. }
  103. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  104. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  105. if len(prescriptions) > 0 {
  106. for _, item := range prescriptions {
  107. items := item.(map[string]interface{})
  108. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  109. utils.ErrorLog("id")
  110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. id := int64(items["id"].(float64))
  114. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  115. utils.ErrorLog("type")
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. types := int64(items["type"].(float64))
  120. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  121. utils.ErrorLog("med_type")
  122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  123. return
  124. }
  125. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  126. ctime := time.Now().Unix()
  127. prescription := &models.HisPrescriptionInfoTemplate{
  128. ID: id,
  129. PatientId: patient_id,
  130. UserOrgId: adminInfo.CurrentOrgId,
  131. Ctime: ctime,
  132. Mtime: ctime,
  133. Type: types,
  134. Modifier: adminInfo.AdminUser.Id,
  135. Creator: adminInfo.AdminUser.Id,
  136. Status: 1,
  137. PTemplateId: src_template.ID,
  138. MedType: med_type,
  139. }
  140. service.CreateHisPrescriptionInfoTemplate(prescription)
  141. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  142. advices := items["advices"].([]interface{})
  143. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  144. groupNo := int64(0)
  145. ctime := time.Now().Unix()
  146. mtime := ctime
  147. if len(advices) > 0 {
  148. for _, advice := range advices {
  149. var s models.HisPrescriptionAdviceTemplate
  150. s.PrescriptionId = prescription.ID
  151. s.AdviceType = 2
  152. s.StopState = 2
  153. s.ExecutionState = 2
  154. s.Status = 1
  155. s.UserOrgId = adminInfo.CurrentOrgId
  156. s.Groupno = groupNo
  157. s.CreatedTime = ctime
  158. s.UpdatedTime = mtime
  159. s.PatientId = patient_id
  160. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  161. if errcode > 0 {
  162. c.ServeFailJSONWithSGJErrorCode(errcode)
  163. return
  164. }
  165. service.CreateHisPrescriptionAdviceTemplate(&s)
  166. }
  167. }
  168. }
  169. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  170. projects := items["project"].([]interface{})
  171. if len(projects) > 0 {
  172. for _, project := range projects {
  173. var p models.HisPrescriptionProjectTemplate
  174. p.PrescriptionId = prescription.ID
  175. p.Ctime = time.Now().Unix()
  176. p.Mtime = time.Now().Unix()
  177. p.PatientId = patient_id
  178. p.UserOrgId = adminInfo.CurrentOrgId
  179. p.Status = 1
  180. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  181. if errcode > 0 {
  182. c.ServeFailJSONWithSGJErrorCode(errcode)
  183. return
  184. }
  185. service.CreateHisPrescriptionProjectTemplate(&p)
  186. }
  187. }
  188. }
  189. }
  190. c.ServeSuccessJSON(map[string]interface{}{
  191. "msg": "创建成功",
  192. })
  193. }
  194. }
  195. }
  196. func (c *HisConfigApiController) DeletePrescriptionTemplate() {
  197. id, _ := c.GetInt64("id")
  198. err := service.DelelteHisPrescriptionTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  199. if err == nil {
  200. c.ServeSuccessJSON(map[string]interface{}{
  201. "msg": "删除成功",
  202. })
  203. return
  204. } else {
  205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  206. return
  207. }
  208. }
  209. func (c *HisConfigApiController) DeletePrescriptionInfoTemplate() {
  210. prescription_id, _ := c.GetInt64("id")
  211. err := service.DelelteHisPrescriptionInfoTemplate(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  212. if err == nil {
  213. c.ServeSuccessJSON(map[string]interface{}{
  214. "msg": "删除成功",
  215. })
  216. return
  217. } else {
  218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  219. return
  220. }
  221. }
  222. func (c *HisConfigApiController) DeleteAdviceTemplate() {
  223. id, _ := c.GetInt64("id")
  224. err := service.DelelteHisPrescriptionAdviceTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  225. if err == nil {
  226. c.ServeSuccessJSON(map[string]interface{}{
  227. "msg": "删除成功",
  228. })
  229. return
  230. } else {
  231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  232. return
  233. }
  234. }
  235. func (c *HisConfigApiController) DeleteProjectTemplate() {
  236. id, _ := c.GetInt64("id")
  237. err := service.DelelteHisPrescriptionProjectTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "删除成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisConfigApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  249. if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
  250. advice_id := int64(json["advice_id"].(float64))
  251. advice.ID = advice_id
  252. }
  253. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  254. utils.ErrorLog("drug_name")
  255. return enums.ErrorCodeParamWrong
  256. }
  257. adviceName, _ := json["drug_name"].(string)
  258. if len(adviceName) == 0 {
  259. utils.ErrorLog("len(advice_name) == 0")
  260. return enums.ErrorCodeParamWrong
  261. }
  262. advice.AdviceName = adviceName
  263. adviceDesc, _ := json["advice_desc"].(string)
  264. advice.AdviceDesc = adviceDesc
  265. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  266. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  267. advice.DrugSpec = drugSpec
  268. }
  269. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  270. remark, _ := json["remark"].(string)
  271. advice.Remark = remark
  272. }
  273. if json["id"] == nil {
  274. advice.DrugId = 0
  275. } else {
  276. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  277. drug_id := int64(json["id"].(float64))
  278. advice.DrugId = drug_id
  279. }
  280. }
  281. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  282. drugSpecUnit, _ := json["min_unit"].(string)
  283. advice.DrugSpecUnit = drugSpecUnit
  284. }
  285. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  286. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  287. advice.SingleDose = singleDose
  288. }
  289. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  290. singleDoseUnit, _ := json["single_dose_unit"].(string)
  291. advice.SingleDoseUnit = singleDoseUnit
  292. }
  293. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  294. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  295. advice.PrescribingNumber = prescribingNumber
  296. }
  297. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  298. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  299. advice.PrescribingNumberUnit = prescribingNumberUnit
  300. }
  301. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  302. deliveryWay, _ := json["delivery_way"].(string)
  303. advice.DeliveryWay = deliveryWay
  304. }
  305. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  306. executionFrequency, _ := json["execution_frequency"].(string)
  307. advice.ExecutionFrequency = executionFrequency
  308. }
  309. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  310. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  311. advice.Price = price
  312. }
  313. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  314. med_list_codg, _ := json["medical_insurance_number"].(string)
  315. advice.MedListCodg = med_list_codg
  316. }
  317. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  318. day := int64(json["day"].(float64))
  319. advice.Day = day
  320. }
  321. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  322. groupno := int64(json["groupno"].(float64))
  323. advice.Groupno = groupno
  324. }
  325. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  326. frequency_type := int64(json["frequency_type"].(float64))
  327. advice.FrequencyType = frequency_type
  328. }
  329. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  330. day_count := int64(json["day_count"].(float64))
  331. advice.DayCount = day_count
  332. }
  333. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  334. week_day, _ := json["week_day"].(string)
  335. advice.WeekDay = week_day
  336. }
  337. return 0
  338. }
  339. func (c *HisConfigApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  340. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  341. id := int64(json["id"].(float64))
  342. project.ID = id
  343. }
  344. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  345. frequency_type := int64(json["frequency_type"].(float64))
  346. project.FrequencyType = frequency_type
  347. }
  348. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  349. day_count := int64(json["day_count"].(float64))
  350. project.DayCount = day_count
  351. }
  352. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  353. week_day, _ := json["week_day"].(string)
  354. project.WeekDay = week_day
  355. }
  356. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  357. types := int64(json["type"].(float64))
  358. project.Type = types
  359. }
  360. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  361. project_id := int64(json["project_id"].(float64))
  362. project.ProjectId = project_id
  363. }
  364. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  365. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  366. project.Price = price
  367. }
  368. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  369. total, _ := json["total"].(string)
  370. //totals, _ := strconv.ParseInt(total, 10, 64)
  371. project.Count = total
  372. }
  373. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  374. medical_code, _ := json["medical_code"].(string)
  375. project.MedListCodg = medical_code
  376. }
  377. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  378. single_dose, _ := json["single_dose"].(string)
  379. project.SingleDose = single_dose
  380. }
  381. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  382. delivery_way, _ := json["delivery_way"].(string)
  383. project.DeliveryWay = delivery_way
  384. }
  385. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  386. execution_frequency, _ := json["execution_frequency"].(string)
  387. project.ExecutionFrequency = execution_frequency
  388. }
  389. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  390. remark, _ := json["remark"].(string)
  391. project.Remark = remark
  392. }
  393. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  394. day, _ := json["number_days"].(string)
  395. project.Day = day
  396. }
  397. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  398. unit, _ := json["unit"].(string)
  399. project.Unit = unit
  400. }
  401. return 0
  402. }