his_config_api_controller.go 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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. beego.Router("/api/his/getmodetemplatename", &HisConfigApiController{}, "get:GetModeTemplateName")
  27. beego.Router("/api/his/getprescriptiontemplatedetail", &HisConfigApiController{}, "get:GetPrescriptionTemplateDetail")
  28. beego.Router("/api/his/prescriptionmodetemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionModeTemplate")
  29. beego.Router("/api/his/prescriptionmodetemplate/info", &HisConfigApiController{}, "get:GetPrescriptionModeTemplateInfo")
  30. beego.Router("/api/his/prescriptionmodetemplate/delete", &HisConfigApiController{}, "post:DeleteModePrescriptionTemplate")
  31. beego.Router("/api/his/projectmodetemplate/delete", &HisConfigApiController{}, "post:DeleteModeProjectTemplate")
  32. beego.Router("/api/his/advicempdetemplate/delete", &HisConfigApiController{}, "post:DeleteModeAdviceTemplate")
  33. beego.Router("/api/his/prescriptioninfomodetemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoModeTemplate")
  34. }
  35. func (c *HisConfigApiController) GetAllHisPatientsList() {
  36. patients, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  37. c.ServeSuccessJSON(map[string]interface{}{
  38. "list": patients,
  39. })
  40. }
  41. func (c *HisConfigApiController) GetPrescriptionTemplateList() {
  42. patient_id, _ := c.GetInt64("patient_id", 0)
  43. page, _ := c.GetInt64("page", 0)
  44. limit, _ := c.GetInt64("limit", 0)
  45. if page <= 0 {
  46. page = 1
  47. }
  48. if limit <= 0 {
  49. limit = 10
  50. }
  51. if patient_id <= 0 {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  53. return
  54. }
  55. templates, total, _ := service.GetHisPrescriptionTemplatesList(patient_id, c.GetAdminUserInfo().CurrentOrgId, page, limit)
  56. c.ServeSuccessJSON(map[string]interface{}{
  57. "list": templates,
  58. "total": total,
  59. })
  60. }
  61. func (c *HisConfigApiController) GetPrescriptionTemplateInfo() {
  62. id, _ := c.GetInt64("id", 0)
  63. template, _ := service.GetHisPrescriptionTemplateByID(id)
  64. prescriptions, _ := service.GetHisPrescriptionTemplate(template.ID, c.GetAdminUserInfo().CurrentOrgId)
  65. c.ServeSuccessJSON(map[string]interface{}{
  66. "template": template,
  67. "prescriptions": prescriptions,
  68. })
  69. }
  70. func (c *HisConfigApiController) CreatePrescriptionTemplate() {
  71. id, _ := c.GetInt64("id")
  72. name := c.GetString("name")
  73. mode_id, _ := c.GetInt64("mode_id", 0)
  74. types, _ := c.GetInt64("type", 0)
  75. patient_id, _ := c.GetInt64("patient_id", 0)
  76. types = 1
  77. adminInfo := c.GetAdminUserInfo()
  78. if id == 0 {
  79. mode_template, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, adminInfo.CurrentOrgId)
  80. if mode_template.ID > 0 {
  81. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  82. return
  83. }
  84. }
  85. if id > 0 {
  86. mode_template, _ := service.GetHisPrescriptionTemplateByModeIdTwo(mode_id, patient_id, adminInfo.CurrentOrgId, id)
  87. if mode_template.ID > 0 {
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  89. return
  90. }
  91. }
  92. src_template, _ := service.GetHisPrescriptionTemplateByID(id)
  93. if src_template.ID == 0 {
  94. template := models.HisPrescriptionTemplate{
  95. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  96. PatientId: patient_id,
  97. Type: types,
  98. Status: 1,
  99. Ctime: time.Now().Unix(),
  100. Mtime: time.Now().Unix(),
  101. Name: name,
  102. Mode: mode_id,
  103. }
  104. src_template = template
  105. service.CreateHisPrescriptionTemplate(&src_template)
  106. } else {
  107. src_template.Name = name
  108. src_template.Mode = mode_id
  109. service.SaveHisPrescriptionTemplate(&src_template)
  110. }
  111. dataBody := make(map[string]interface{}, 0)
  112. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  113. if err != nil {
  114. utils.ErrorLog(err.Error())
  115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  116. return
  117. }
  118. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  119. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  120. if len(prescriptions) > 0 {
  121. for _, item := range prescriptions {
  122. items := item.(map[string]interface{})
  123. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  124. utils.ErrorLog("id")
  125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  126. return
  127. }
  128. id := int64(items["id"].(float64))
  129. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  130. utils.ErrorLog("type")
  131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  132. return
  133. }
  134. types := int64(items["type"].(float64))
  135. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  136. utils.ErrorLog("med_type")
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  141. ctime := time.Now().Unix()
  142. prescription := &models.HisPrescriptionInfoTemplate{
  143. ID: id,
  144. PatientId: patient_id,
  145. UserOrgId: adminInfo.CurrentOrgId,
  146. Ctime: ctime,
  147. Mtime: ctime,
  148. Type: types,
  149. Modifier: adminInfo.AdminUser.Id,
  150. Creator: adminInfo.AdminUser.Id,
  151. Status: 1,
  152. PTemplateId: src_template.ID,
  153. MedType: med_type,
  154. }
  155. service.CreateHisPrescriptionInfoTemplate(prescription)
  156. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  157. advices := items["advices"].([]interface{})
  158. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  159. groupNo := int64(0)
  160. ctime := time.Now().Unix()
  161. mtime := ctime
  162. if len(advices) > 0 {
  163. for _, advice := range advices {
  164. var s models.HisPrescriptionAdviceTemplate
  165. s.PrescriptionId = prescription.ID
  166. s.AdviceType = 2
  167. s.StopState = 2
  168. s.ExecutionState = 2
  169. s.Status = 1
  170. s.UserOrgId = adminInfo.CurrentOrgId
  171. s.Groupno = groupNo
  172. s.CreatedTime = ctime
  173. s.UpdatedTime = mtime
  174. s.PatientId = patient_id
  175. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  176. if errcode > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(errcode)
  178. return
  179. }
  180. service.CreateHisPrescriptionAdviceTemplate(&s)
  181. }
  182. }
  183. }
  184. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  185. projects := items["project"].([]interface{})
  186. if len(projects) > 0 {
  187. for _, project := range projects {
  188. var p models.HisPrescriptionProjectTemplate
  189. p.PrescriptionId = prescription.ID
  190. p.Ctime = time.Now().Unix()
  191. p.Mtime = time.Now().Unix()
  192. p.PatientId = patient_id
  193. p.UserOrgId = adminInfo.CurrentOrgId
  194. p.Status = 1
  195. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  196. if errcode > 0 {
  197. c.ServeFailJSONWithSGJErrorCode(errcode)
  198. return
  199. }
  200. service.CreateHisPrescriptionProjectTemplate(&p)
  201. }
  202. }
  203. }
  204. }
  205. c.ServeSuccessJSON(map[string]interface{}{
  206. "msg": "创建成功",
  207. })
  208. }
  209. }
  210. }
  211. func (c *HisConfigApiController) DeletePrescriptionTemplate() {
  212. id, _ := c.GetInt64("id")
  213. err := service.DelelteHisPrescriptionTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  214. if err == nil {
  215. c.ServeSuccessJSON(map[string]interface{}{
  216. "msg": "删除成功",
  217. })
  218. return
  219. } else {
  220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  221. return
  222. }
  223. }
  224. func (c *HisConfigApiController) DeletePrescriptionInfoTemplate() {
  225. prescription_id, _ := c.GetInt64("id")
  226. err := service.DelelteHisPrescriptionInfoTemplate(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  227. if err == nil {
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "msg": "删除成功",
  230. })
  231. return
  232. } else {
  233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  234. return
  235. }
  236. }
  237. func (c *HisConfigApiController) DeleteAdviceTemplate() {
  238. id, _ := c.GetInt64("id")
  239. err := service.DelelteHisPrescriptionAdviceTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  240. if err == nil {
  241. c.ServeSuccessJSON(map[string]interface{}{
  242. "msg": "删除成功",
  243. })
  244. return
  245. } else {
  246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  247. return
  248. }
  249. }
  250. func (c *HisConfigApiController) DeleteProjectTemplate() {
  251. id, _ := c.GetInt64("id")
  252. err := service.DelelteHisPrescriptionProjectTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  253. if err == nil {
  254. c.ServeSuccessJSON(map[string]interface{}{
  255. "msg": "删除成功",
  256. })
  257. return
  258. } else {
  259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  260. return
  261. }
  262. }
  263. func (c *HisConfigApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  264. if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
  265. advice_id := int64(json["advice_id"].(float64))
  266. advice.ID = advice_id
  267. }
  268. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  269. utils.ErrorLog("drug_name")
  270. return enums.ErrorCodeParamWrong
  271. }
  272. adviceName, _ := json["drug_name"].(string)
  273. if len(adviceName) == 0 {
  274. utils.ErrorLog("len(advice_name) == 0")
  275. return enums.ErrorCodeParamWrong
  276. }
  277. advice.AdviceName = adviceName
  278. adviceDesc, _ := json["advice_desc"].(string)
  279. advice.AdviceDesc = adviceDesc
  280. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  281. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  282. advice.DrugSpec = drugSpec
  283. }
  284. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  285. remark, _ := json["remark"].(string)
  286. advice.Remark = remark
  287. }
  288. if json["id"] == nil {
  289. advice.DrugId = 0
  290. } else {
  291. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  292. drug_id := int64(json["id"].(float64))
  293. advice.DrugId = drug_id
  294. }
  295. }
  296. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  297. drugSpecUnit, _ := json["min_unit"].(string)
  298. advice.DrugSpecUnit = drugSpecUnit
  299. }
  300. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  301. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  302. advice.SingleDose = singleDose
  303. }
  304. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  305. singleDoseUnit, _ := json["single_dose_unit"].(string)
  306. advice.SingleDoseUnit = singleDoseUnit
  307. }
  308. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  309. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  310. advice.PrescribingNumber = prescribingNumber
  311. }
  312. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  313. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  314. advice.PrescribingNumberUnit = prescribingNumberUnit
  315. }
  316. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  317. deliveryWay, _ := json["delivery_way"].(string)
  318. advice.DeliveryWay = deliveryWay
  319. }
  320. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  321. executionFrequency, _ := json["execution_frequency"].(string)
  322. advice.ExecutionFrequency = executionFrequency
  323. }
  324. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  325. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  326. advice.Price = price
  327. }
  328. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  329. med_list_codg, _ := json["medical_insurance_number"].(string)
  330. advice.MedListCodg = med_list_codg
  331. }
  332. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  333. day := int64(json["day"].(float64))
  334. advice.Day = day
  335. }
  336. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  337. groupno := int64(json["groupno"].(float64))
  338. advice.Groupno = groupno
  339. }
  340. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  341. frequency_type := int64(json["frequency_type"].(float64))
  342. advice.FrequencyType = frequency_type
  343. }
  344. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  345. day_count := int64(json["day_count"].(float64))
  346. advice.DayCount = day_count
  347. }
  348. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  349. week_day, _ := json["week_day"].(string)
  350. advice.WeekDay = week_day
  351. }
  352. return 0
  353. }
  354. func (c *HisConfigApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  355. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  356. id := int64(json["id"].(float64))
  357. project.ID = id
  358. }
  359. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  360. frequency_type := int64(json["frequency_type"].(float64))
  361. project.FrequencyType = frequency_type
  362. }
  363. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  364. day_count := int64(json["day_count"].(float64))
  365. project.DayCount = day_count
  366. }
  367. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  368. week_day, _ := json["week_day"].(string)
  369. project.WeekDay = week_day
  370. }
  371. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  372. types := int64(json["type"].(float64))
  373. project.Type = types
  374. }
  375. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  376. project_id := int64(json["project_id"].(float64))
  377. project.ProjectId = project_id
  378. }
  379. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  380. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  381. project.Price = price
  382. }
  383. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  384. total, _ := json["total"].(string)
  385. //totals, _ := strconv.ParseInt(total, 10, 64)
  386. project.Count = total
  387. }
  388. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  389. medical_code, _ := json["medical_code"].(string)
  390. project.MedListCodg = medical_code
  391. }
  392. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  393. single_dose, _ := json["single_dose"].(string)
  394. project.SingleDose = single_dose
  395. }
  396. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  397. delivery_way, _ := json["delivery_way"].(string)
  398. project.DeliveryWay = delivery_way
  399. }
  400. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  401. execution_frequency, _ := json["execution_frequency"].(string)
  402. project.ExecutionFrequency = execution_frequency
  403. }
  404. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  405. remark, _ := json["remark"].(string)
  406. project.Remark = remark
  407. }
  408. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  409. day, _ := json["number_days"].(string)
  410. project.Day = day
  411. }
  412. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  413. unit, _ := json["unit"].(string)
  414. project.Unit = unit
  415. }
  416. return 0
  417. }
  418. func (this *HisConfigApiController) GetModeTemplateName() {
  419. mode_id, _ := this.GetInt64("mode_id")
  420. orgId := this.GetAdminUserInfo().CurrentOrgId
  421. modeTeplate, err := service.GetModeTemplateName(mode_id, orgId)
  422. if err == nil {
  423. this.ServeSuccessJSON(map[string]interface{}{
  424. "modeTeplate": modeTeplate,
  425. })
  426. return
  427. } else {
  428. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  429. return
  430. }
  431. }
  432. func (this *HisConfigApiController) GetPrescriptionTemplateDetail() {
  433. mode_id, _ := this.GetInt64("mode_id")
  434. orgId := this.GetAdminUserInfo().CurrentOrgId
  435. template, _ := service.GetModeTemplateNameDetail(mode_id, orgId)
  436. prescriptions, err := service.GetHisPrescriptionModeTemplate(template.ID, orgId)
  437. if err == nil {
  438. this.ServeSuccessJSON(map[string]interface{}{
  439. "template": template,
  440. "prescriptions": prescriptions,
  441. })
  442. return
  443. } else {
  444. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  445. return
  446. }
  447. }
  448. func (c *HisConfigApiController) CreatePrescriptionModeTemplate() {
  449. id, _ := c.GetInt64("id")
  450. name := c.GetString("name")
  451. mode_id, _ := c.GetInt64("mode_id", 0)
  452. types, _ := c.GetInt64("type", 0)
  453. patient_id, _ := c.GetInt64("patient_id", 0)
  454. types = 1
  455. adminInfo := c.GetAdminUserInfo()
  456. if id == 0 {
  457. mode_template, _ := service.GetHisModePrescriptionTemplateByModeId(mode_id, patient_id, adminInfo.CurrentOrgId)
  458. if mode_template.ID > 0 {
  459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  460. return
  461. }
  462. }
  463. if id > 0 {
  464. mode_template, _ := service.GetHisModePrescriptionTemplateByModeIdTwo(mode_id, patient_id, adminInfo.CurrentOrgId, id)
  465. if mode_template.ID > 0 {
  466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  467. return
  468. }
  469. }
  470. src_template, _ := service.GetHisModePrescriptionTemplateByID(id)
  471. if src_template.ID == 0 {
  472. template := models.HisPrescriptionModeTemplate{
  473. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  474. PatientId: patient_id,
  475. Type: types,
  476. Status: 1,
  477. Ctime: time.Now().Unix(),
  478. Mtime: time.Now().Unix(),
  479. Name: name,
  480. Mode: mode_id,
  481. }
  482. src_template = template
  483. service.CreateHisModePrescriptionTemplate(&src_template)
  484. } else {
  485. src_template.Name = name
  486. src_template.Mode = mode_id
  487. service.SaveHisModePrescriptionTemplate(&src_template)
  488. }
  489. dataBody := make(map[string]interface{}, 0)
  490. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  491. if err != nil {
  492. utils.ErrorLog(err.Error())
  493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  494. return
  495. }
  496. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  497. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  498. if len(prescriptions) > 0 {
  499. for _, item := range prescriptions {
  500. items := item.(map[string]interface{})
  501. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  502. utils.ErrorLog("id")
  503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  504. return
  505. }
  506. id := int64(items["id"].(float64))
  507. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  508. utils.ErrorLog("type")
  509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  510. return
  511. }
  512. types := int64(items["type"].(float64))
  513. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  514. utils.ErrorLog("med_type")
  515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  516. return
  517. }
  518. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  519. ctime := time.Now().Unix()
  520. prescription := &models.HisPrescriptionInfoModeTemplate{
  521. ID: id,
  522. PatientId: patient_id,
  523. UserOrgId: adminInfo.CurrentOrgId,
  524. Ctime: ctime,
  525. Mtime: ctime,
  526. Type: types,
  527. Modifier: adminInfo.AdminUser.Id,
  528. Creator: adminInfo.AdminUser.Id,
  529. Status: 1,
  530. PTemplateId: src_template.ID,
  531. MedType: med_type,
  532. }
  533. service.CreateHisModePrescriptionInfoTemplate(prescription)
  534. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  535. advices := items["advices"].([]interface{})
  536. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  537. groupNo := int64(0)
  538. ctime := time.Now().Unix()
  539. mtime := ctime
  540. if len(advices) > 0 {
  541. for _, advice := range advices {
  542. var s models.HisPrescriptionAdviceModeTemplate
  543. s.PrescriptionId = prescription.ID
  544. s.AdviceType = 2
  545. s.StopState = 2
  546. s.ExecutionState = 2
  547. s.Status = 1
  548. s.UserOrgId = adminInfo.CurrentOrgId
  549. s.Groupno = groupNo
  550. s.CreatedTime = ctime
  551. s.UpdatedTime = mtime
  552. s.PatientId = patient_id
  553. errcode := c.setAdviceModeTemplateWithJSON(&s, advice.(map[string]interface{}))
  554. if errcode > 0 {
  555. c.ServeFailJSONWithSGJErrorCode(errcode)
  556. return
  557. }
  558. service.CreateHisModePrescriptionAdviceTemplate(&s)
  559. }
  560. }
  561. }
  562. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  563. projects := items["project"].([]interface{})
  564. if len(projects) > 0 {
  565. for _, project := range projects {
  566. var p models.HisPrescriptionProjectModeTemplate
  567. p.PrescriptionId = prescription.ID
  568. p.Ctime = time.Now().Unix()
  569. p.Mtime = time.Now().Unix()
  570. p.PatientId = patient_id
  571. p.UserOrgId = adminInfo.CurrentOrgId
  572. p.Status = 1
  573. errcode := c.setProjectModeTemplateWithJSON(&p, project.(map[string]interface{}))
  574. if errcode > 0 {
  575. c.ServeFailJSONWithSGJErrorCode(errcode)
  576. return
  577. }
  578. service.CreateHisModePrescriptionProjectTemplate(&p)
  579. }
  580. }
  581. }
  582. }
  583. c.ServeSuccessJSON(map[string]interface{}{
  584. "msg": "创建成功",
  585. })
  586. }
  587. }
  588. }
  589. func (c *HisConfigApiController) GetPrescriptionModeTemplateInfo() {
  590. id, _ := c.GetInt64("id", 0)
  591. template, _ := service.GetHisModePrescriptionTemplateByID(id)
  592. prescriptions, _ := service.GetHisPrescriptionModeTemplate(template.ID, c.GetAdminUserInfo().CurrentOrgId)
  593. c.ServeSuccessJSON(map[string]interface{}{
  594. "template": template,
  595. "prescriptions": prescriptions,
  596. })
  597. }
  598. func (c *HisConfigApiController) setAdviceModeTemplateWithJSON(advice *models.HisPrescriptionAdviceModeTemplate, json map[string]interface{}) int {
  599. if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
  600. advice_id := int64(json["advice_id"].(float64))
  601. advice.ID = advice_id
  602. }
  603. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  604. utils.ErrorLog("drug_name")
  605. return enums.ErrorCodeParamWrong
  606. }
  607. adviceName, _ := json["drug_name"].(string)
  608. if len(adviceName) == 0 {
  609. utils.ErrorLog("len(advice_name) == 0")
  610. return enums.ErrorCodeParamWrong
  611. }
  612. advice.AdviceName = adviceName
  613. adviceDesc, _ := json["advice_desc"].(string)
  614. advice.AdviceDesc = adviceDesc
  615. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  616. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  617. advice.DrugSpec = drugSpec
  618. }
  619. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  620. remark, _ := json["remark"].(string)
  621. advice.Remark = remark
  622. }
  623. if json["id"] == nil {
  624. advice.DrugId = 0
  625. } else {
  626. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  627. drug_id := int64(json["id"].(float64))
  628. advice.DrugId = drug_id
  629. }
  630. }
  631. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  632. drugSpecUnit, _ := json["min_unit"].(string)
  633. advice.DrugSpecUnit = drugSpecUnit
  634. }
  635. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  636. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  637. advice.SingleDose = singleDose
  638. }
  639. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  640. singleDoseUnit, _ := json["single_dose_unit"].(string)
  641. advice.SingleDoseUnit = singleDoseUnit
  642. }
  643. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  644. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  645. advice.PrescribingNumber = prescribingNumber
  646. }
  647. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  648. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  649. advice.PrescribingNumberUnit = prescribingNumberUnit
  650. }
  651. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  652. deliveryWay, _ := json["delivery_way"].(string)
  653. advice.DeliveryWay = deliveryWay
  654. }
  655. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  656. executionFrequency, _ := json["execution_frequency"].(string)
  657. advice.ExecutionFrequency = executionFrequency
  658. }
  659. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  660. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  661. advice.Price = price
  662. }
  663. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  664. med_list_codg, _ := json["medical_insurance_number"].(string)
  665. advice.MedListCodg = med_list_codg
  666. }
  667. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  668. day := int64(json["day"].(float64))
  669. advice.Day = day
  670. }
  671. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  672. groupno := int64(json["groupno"].(float64))
  673. advice.Groupno = groupno
  674. }
  675. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  676. frequency_type := int64(json["frequency_type"].(float64))
  677. advice.FrequencyType = frequency_type
  678. }
  679. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  680. day_count := int64(json["day_count"].(float64))
  681. advice.DayCount = day_count
  682. }
  683. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  684. week_day, _ := json["week_day"].(string)
  685. advice.WeekDay = week_day
  686. }
  687. return 0
  688. }
  689. func (c *HisConfigApiController) setProjectModeTemplateWithJSON(project *models.HisPrescriptionProjectModeTemplate, json map[string]interface{}) int {
  690. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  691. id := int64(json["id"].(float64))
  692. project.ID = id
  693. }
  694. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  695. frequency_type := int64(json["frequency_type"].(float64))
  696. project.FrequencyType = frequency_type
  697. }
  698. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  699. day_count := int64(json["day_count"].(float64))
  700. project.DayCount = day_count
  701. }
  702. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  703. week_day, _ := json["week_day"].(string)
  704. project.WeekDay = week_day
  705. }
  706. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  707. types := int64(json["type"].(float64))
  708. project.Type = types
  709. }
  710. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  711. project_id := int64(json["project_id"].(float64))
  712. project.ProjectId = project_id
  713. }
  714. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  715. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  716. project.Price = price
  717. }
  718. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  719. total, _ := json["total"].(string)
  720. //totals, _ := strconv.ParseInt(total, 10, 64)
  721. project.Count = total
  722. }
  723. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  724. medical_code, _ := json["medical_code"].(string)
  725. project.MedListCodg = medical_code
  726. }
  727. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  728. single_dose, _ := json["single_dose"].(string)
  729. project.SingleDose = single_dose
  730. }
  731. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  732. delivery_way, _ := json["delivery_way"].(string)
  733. project.DeliveryWay = delivery_way
  734. }
  735. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  736. execution_frequency, _ := json["execution_frequency"].(string)
  737. project.ExecutionFrequency = execution_frequency
  738. }
  739. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  740. remark, _ := json["remark"].(string)
  741. project.Remark = remark
  742. }
  743. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  744. day, _ := json["number_days"].(string)
  745. project.Day = day
  746. }
  747. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  748. unit, _ := json["unit"].(string)
  749. project.Unit = unit
  750. }
  751. return 0
  752. }
  753. func (c *HisConfigApiController) DeleteModePrescriptionTemplate() {
  754. id, _ := c.GetInt64("id")
  755. err := service.DelelteHisModePrescriptionTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  756. if err == nil {
  757. c.ServeSuccessJSON(map[string]interface{}{
  758. "msg": "删除成功",
  759. })
  760. return
  761. } else {
  762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  763. return
  764. }
  765. }
  766. func (c *HisConfigApiController) DeleteModeProjectTemplate() {
  767. id, _ := c.GetInt64("id")
  768. err := service.DelelteHisModePrescriptionProjectTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  769. if err == nil {
  770. c.ServeSuccessJSON(map[string]interface{}{
  771. "msg": "删除成功",
  772. })
  773. return
  774. } else {
  775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  776. return
  777. }
  778. }
  779. func (c *HisConfigApiController) DeleteModeAdviceTemplate() {
  780. id, _ := c.GetInt64("id")
  781. err := service.DelelteHisModePrescriptionAdviceTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  782. if err == nil {
  783. c.ServeSuccessJSON(map[string]interface{}{
  784. "msg": "删除成功",
  785. })
  786. return
  787. } else {
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  789. return
  790. }
  791. }
  792. func (c *HisConfigApiController) DeletePrescriptionInfoModeTemplate() {
  793. prescription_id, _ := c.GetInt64("id")
  794. err := service.DelelteHisPrescriptionInfoModeTemplate(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  795. if err == nil {
  796. c.ServeSuccessJSON(map[string]interface{}{
  797. "msg": "删除成功",
  798. })
  799. return
  800. } else {
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  802. return
  803. }
  804. }