his_config_api_controller.go 13KB

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