his_config_api_controller.go 13KB

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