his_config_api_controller.go 15KB

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