data_api_controller.go 58KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "time"
  8. "XT_New/enums"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "XT_New/utils"
  12. "github.com/astaxie/beego"
  13. )
  14. type DataApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func DataApiRegistRouters() {
  18. beego.Router("/api/getconfiglist", &DataApiController{}, "get,post:GetConfigList")
  19. beego.Router("/api/createconfig", &DataApiController{}, "Post:CreateConfig")
  20. beego.Router("/api/createchildconfig", &DataApiController{}, "Post:CreateChildConfig")
  21. beego.Router("/api/updatechildconfig", &DataApiController{}, "Post:UpdateChildConfig")
  22. beego.Router("/api/deletechildconfig", &DataApiController{}, "Post:DeleteChildConfig")
  23. beego.Router("/api/updatetemplate", &DataApiController{}, "Post:UpdateTemplate")
  24. beego.Router("/api/getadviceconfigs", &DataApiController{}, "Get:GetAdviceConfigs")
  25. beego.Router("/api/getalladviceconfig", &DataApiController{}, "Get:GetAllAdviceConfigs")
  26. beego.Router("/api/drugdic/create", &DataApiController{}, "Post:CreateDrugDic")
  27. beego.Router("/api/drugdic/update", &DataApiController{}, "Put:UpdateDrugDic")
  28. beego.Router("/api/drugdic/delete", &DataApiController{}, "Delete:DeleteDrugDic")
  29. beego.Router("/api/drugway/create", &DataApiController{}, "Post:CreateDrugWay")
  30. beego.Router("/api/drugway/update", &DataApiController{}, "Put:UpdateDrugWay")
  31. beego.Router("/api/drugway/delete", &DataApiController{}, "Delete:DeleteDrugWay")
  32. beego.Router("/api/executionfrequency/create", &DataApiController{}, "Post:CreateExecutionFrequency")
  33. beego.Router("/api/executionfrequency/update", &DataApiController{}, "Put:UpdateExecutionFrequency")
  34. beego.Router("/api/executionfrequency/delete", &DataApiController{}, "Delete:DeleteExecutionFrequency")
  35. beego.Router("/api/advicetemplate/create", &DataApiController{}, "Post:CreateAdviceTemplate")
  36. beego.Router("/api/subadvice/create", &DataApiController{}, "Post:CreateSubAdviceTemplate")
  37. beego.Router("/api/advicetemplate/update", &DataApiController{}, "Put:UpdateAdviceTemplate")
  38. beego.Router("/api/advicetemplate/delete", &DataApiController{}, "Delete:DeleteAdviceTemplate")
  39. beego.Router("/api/advicetemplate/add", &DataApiController{}, "Post:CreateSingleAdviceTemplate")
  40. beego.Router("/api/adviceparenttemplate/delete", &DataApiController{}, "Delete:DeleteParentAdviceTemplate")
  41. beego.Router("/api/template/modify", &DataApiController{}, "Post:ModifyTemplateName")
  42. beego.Router("/api/filed/show", &DataApiController{}, "Post:ModifyFiledIsShow")
  43. beego.Router("/article/hanleupdatetwo", &DataApiController{}, "Get:GetHandleData")
  44. beego.Router("/article/updatedatatwo", &DataApiController{}, "Post:UpdateDataTwo")
  45. beego.Router("/api/hisadvicetemplate/create", &DataApiController{}, "Post:CreateHisAdviceTemplate")
  46. beego.Router("/api/hisadvicetemplate/update", &DataApiController{}, "Put:UpdateHisAdviceTemplate")
  47. beego.Router("/api/hisadvicetemplate/delete", &DataApiController{}, "Delete:DeleteHisAdviceTemplate")
  48. beego.Router("/api/hisadvicetemplate/add", &DataApiController{}, "Post:CreateSingleHisAdviceTemplate")
  49. beego.Router("/api/hisadviceparenttemplate/delete", &DataApiController{}, "Delete:DeleteHisParentAdviceTemplate")
  50. beego.Router("/api/histemplate/modify", &DataApiController{}, "Post:ModifyHisTemplateName")
  51. beego.Router("/api/getallhisadvicetemplate", &DataApiController{}, "Get:GetAllHisAdviceTemplate")
  52. }
  53. // GetPatientsList 取配置信息列表
  54. func (c *DataApiController) GetConfigList() {
  55. adminUserInfo := c.GetAdminUserInfo()
  56. configList, _ := service.GetConfigList(adminUserInfo.CurrentOrgId)
  57. c.ServeSuccessJSON(map[string]interface{}{
  58. "configlist": configList,
  59. })
  60. return
  61. }
  62. // CreateConfig 创建配置信息
  63. func (c *DataApiController) CreateConfig() {
  64. adminUserInfo := c.GetAdminUserInfo()
  65. var dataconfig models.Dataconfig
  66. var resultConfig models.ConfigViewModel
  67. code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
  68. if code > 0 {
  69. c.ServeFailJSONWithSGJErrorCode(code)
  70. return
  71. }
  72. // 验证关键字段的值是否重复
  73. thisConfig, _ := service.FindConfigByTitle(dataconfig.Module, dataconfig.FieldName, adminUserInfo.CurrentOrgId)
  74. fmt.Println("99999", thisConfig)
  75. if thisConfig.ID > 0 {
  76. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  77. return
  78. }
  79. fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, adminUserInfo.CurrentOrgId)
  80. dataconfig.Value = fieldValue + 1
  81. dataBody := make(map[string]interface{}, 0)
  82. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  83. if err != nil {
  84. utils.ErrorLog(err.Error())
  85. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  86. return
  87. }
  88. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  89. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  90. dataconfig.Status = 1
  91. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  92. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  93. dataconfig.Remark = string(dataBody["remark"].(string))
  94. if dataBody["order"] != nil {
  95. dataconfig.Order = int64(dataBody["order"].(float64))
  96. } else {
  97. dataconfig.Order = 0
  98. }
  99. err = service.CreateConfig(&dataconfig)
  100. if err != nil {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  102. return
  103. } else {
  104. resultConfig.ID = dataconfig.ID
  105. resultConfig.Module = dataconfig.Module
  106. resultConfig.Name = dataconfig.Name
  107. resultConfig.OrgId = dataconfig.OrgId
  108. resultConfig.ParentId = dataconfig.ParentId
  109. resultConfig.FieldName = dataconfig.FieldName
  110. resultConfig.CreateUserId = dataconfig.CreateUserId
  111. resultConfig.Title = dataconfig.Title
  112. resultConfig.Content = dataconfig.Content
  113. }
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "dataconfig": resultConfig,
  116. "msg": "ok",
  117. })
  118. return
  119. }
  120. func (c *DataApiController) UpdateTemplate() {
  121. adminUserInfo := c.GetAdminUserInfo()
  122. var dataconfig models.Dataconfig
  123. code := configFormData(&dataconfig, c.Ctx.Input.RequestBody)
  124. if code > 0 {
  125. c.ServeFailJSONWithSGJErrorCode(code)
  126. return
  127. }
  128. dataBody := make(map[string]interface{}, 0)
  129. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  130. if err != nil {
  131. utils.ErrorLog(err.Error())
  132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  133. return
  134. }
  135. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  136. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  137. dataconfig.Status = 1
  138. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  139. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  140. dataconfig.Remark = string(dataBody["remark"].(string))
  141. if dataBody["order"] != nil {
  142. dataconfig.Order = int64(dataBody["order"].(float64))
  143. } else {
  144. dataconfig.Order = 0
  145. }
  146. // 验证关键字段的值是否重复
  147. // cur_id := int64(dataBody["id"].(float64))
  148. // thisConfig,_:=service.FindConfigByTitleForUpdate(dataconfig.Module, dataconfig.Title,dataconfig.OrgId,cur_id)
  149. // if thisConfig.ID >0 {
  150. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  151. // return
  152. // }
  153. configOrgId := int64(dataBody["org_id"].(float64))
  154. if configOrgId == 0 {
  155. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  156. err := service.CreateConfig(&dataconfig)
  157. if err != nil {
  158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  159. return
  160. }
  161. } else {
  162. dataconfig.ID = int64(dataBody["id"].(float64))
  163. err = service.UpdateTemplate(&dataconfig)
  164. if err != nil {
  165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  166. return
  167. }
  168. }
  169. c.ServeSuccessJSON(map[string]interface{}{
  170. "dataconfig": dataconfig,
  171. "msg": "ok",
  172. })
  173. return
  174. }
  175. func (c *DataApiController) UpdateChildConfig() {
  176. adminUserInfo := c.GetAdminUserInfo()
  177. var dataconfig models.Dataconfig
  178. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  179. if code > 0 {
  180. c.ServeFailJSONWithSGJErrorCode(code)
  181. return
  182. }
  183. dataBody := make(map[string]interface{}, 0)
  184. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  185. if err != nil {
  186. utils.ErrorLog(err.Error())
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  191. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  192. dataconfig.Status = 1
  193. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  194. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  195. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  196. dataconfig.Remark = string(dataBody["remark"].(string))
  197. dataconfig.Order = int64(dataBody["orders"].(float64))
  198. dataconfig.FieldType = int64(dataBody["field_type"].(float64))
  199. //if dataBody["orders"] != nil {
  200. // dataconfig.Order = int64(dataBody["orders"].(float64))
  201. // fmt.Println("dataconfig",dataconfig.Order)
  202. //} else {
  203. // dataconfig.Order = 0
  204. //}
  205. configOrgId := int64(dataBody["org_id"].(float64))
  206. // 验证关键字段的值是否重复
  207. // configId := int64(dataBody["id"].(float64))
  208. // thisConfig,_:=service.FindConfigByNameForUpdate(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId,configId)
  209. // if thisConfig.ID >0 {
  210. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  211. // return
  212. // }
  213. if configOrgId == 0 {
  214. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  215. err := service.CreateConfig(&dataconfig)
  216. if err != nil {
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  218. return
  219. }
  220. } else {
  221. dataconfig.ID = int64(dataBody["id"].(float64))
  222. err = service.UpdateChildConfig(&dataconfig)
  223. if err != nil {
  224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  225. return
  226. }
  227. }
  228. c.ServeSuccessJSON(map[string]interface{}{
  229. "dataconfig": dataconfig,
  230. "msg": "ok",
  231. })
  232. return
  233. }
  234. func (c *DataApiController) DeleteChildConfig() {
  235. adminUserInfo := c.GetAdminUserInfo()
  236. var dataconfig models.Dataconfig
  237. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  238. if code > 0 {
  239. c.ServeFailJSONWithSGJErrorCode(code)
  240. return
  241. }
  242. dataBody := make(map[string]interface{}, 0)
  243. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  244. if err != nil {
  245. utils.ErrorLog(err.Error())
  246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  247. return
  248. }
  249. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  250. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  251. dataconfig.Status = 0
  252. dataconfig.Value = int(int64(dataBody["value"].(float64)))
  253. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  254. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  255. dataconfig.Remark = string(dataBody["remark"].(string))
  256. if dataBody["order"] != nil {
  257. dataconfig.Order = int64(dataBody["order"].(float64))
  258. } else {
  259. dataconfig.Order = 0
  260. }
  261. configOrgId := int64(dataBody["org_id"].(float64))
  262. if configOrgId == 0 {
  263. dataconfig.DeleteIdSystem = int64(dataBody["id"].(float64))
  264. err := service.CreateConfig(&dataconfig)
  265. if err != nil {
  266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  267. return
  268. }
  269. } else {
  270. dataconfig.ID = int64(dataBody["id"].(float64))
  271. err := service.DeleteChildConfig(&dataconfig)
  272. if err != nil {
  273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  274. return
  275. }
  276. }
  277. c.ServeSuccessJSON(map[string]interface{}{
  278. "dataconfig": dataconfig,
  279. "msg": "ok",
  280. })
  281. return
  282. }
  283. // CreateChildConfig 创建子配置信息
  284. func (c *DataApiController) CreateChildConfig() {
  285. adminUserInfo := c.GetAdminUserInfo()
  286. var dataconfig models.Dataconfig
  287. code := configChildFormData(&dataconfig, c.Ctx.Input.RequestBody)
  288. if code > 0 {
  289. c.ServeFailJSONWithSGJErrorCode(code)
  290. return
  291. }
  292. dataBody := make(map[string]interface{}, 0)
  293. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  294. if err != nil {
  295. utils.ErrorLog(err.Error())
  296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  297. return
  298. }
  299. dataconfig.OrgId = adminUserInfo.CurrentOrgId
  300. dataconfig.CreateUserId = adminUserInfo.AdminUser.Id
  301. dataconfig.Status = 1
  302. dataconfig.CreatedTime = time.Now().Format("2006-01-02 15:04:05")
  303. dataconfig.UpdatedTime = time.Now().Format("2006-01-02 15:04:05")
  304. dataconfig.Remark = string(dataBody["remark"].(string))
  305. if dataBody["order"] != nil {
  306. dataconfig.Order = int64(dataBody["order"].(float64))
  307. } else {
  308. dataconfig.Order = 0
  309. }
  310. if dataBody["field_type"] != nil {
  311. dataconfig.FieldType = int64(dataBody["field_type"].(float64))
  312. } else {
  313. dataconfig.FieldType = 0
  314. }
  315. // 验证关键字段的值是否重复
  316. // thisConfig,_:=service.FindConfigByName(dataconfig.Module, dataconfig.Name,dataconfig.ParentId,dataconfig.OrgId)
  317. // if thisConfig.ID >0 {
  318. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeFieldExist)
  319. // return
  320. // }
  321. fieldValue := service.GetChildValue(dataconfig.Module, dataconfig.ParentId, dataconfig.OrgId)
  322. dataconfig.Value = fieldValue + 1
  323. err = service.CreateConfig(&dataconfig)
  324. if err != nil {
  325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
  326. return
  327. }
  328. c.ServeSuccessJSON(map[string]interface{}{
  329. "dataconfig": dataconfig,
  330. "msg": "ok",
  331. })
  332. return
  333. }
  334. func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  335. configBody := make(map[string]interface{}, 0)
  336. err := json.Unmarshal(data, &configBody)
  337. utils.InfoLog(string(data))
  338. if err != nil {
  339. utils.ErrorLog(err.Error())
  340. code = enums.ErrorCodeParamWrong
  341. return
  342. }
  343. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  344. utils.ErrorLog("module")
  345. code = enums.ErrorCodeParamWrong
  346. return
  347. }
  348. module, _ := configBody["module"].(string)
  349. if len(module) == 0 {
  350. utils.ErrorLog("len(module) == 0")
  351. code = enums.ErrorCodeParamWrong
  352. return
  353. }
  354. dataconfig.Module = module
  355. if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" || module == "admitting_diagnosis" || module == "discharge_diagnosis" || module == "diagnosis_admission" || module == "treatment" || module == "illness_discharge" || module == "discharge_advice" || module == "dialysis_remark" || module == "catheter_operation" || module == "main_content" || module == "patient_case" || module == "tentative_diagnosis" || module == "diagnostic_basis" || module == "differential_diagnosis" || module == "treatment_plan" || module == "sick_history" || module == "befor_symptoms" {
  356. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  357. utils.ErrorLog("title")
  358. code = enums.ErrorCodeParamWrong
  359. return
  360. }
  361. title, _ := configBody["title"].(string)
  362. if len(title) == 0 {
  363. utils.ErrorLog("len(title) == 0")
  364. code = enums.ErrorCodeParamWrong
  365. return
  366. }
  367. dataconfig.Title = title
  368. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  369. utils.ErrorLog("content")
  370. code = enums.ErrorCodeParamWrong
  371. return
  372. }
  373. content, _ := configBody["content"].(string)
  374. if len(content) == 0 {
  375. utils.ErrorLog("len(content) == 0")
  376. code = enums.ErrorCodeParamWrong
  377. return
  378. }
  379. dataconfig.Content = content
  380. } else {
  381. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  382. utils.ErrorLog("name")
  383. code = enums.ErrorCodeParamWrong
  384. return
  385. }
  386. name, _ := configBody["name"].(string)
  387. if len(name) == 0 {
  388. utils.ErrorLog("len(name) == 0")
  389. code = enums.ErrorCodeParamWrong
  390. return
  391. }
  392. dataconfig.Name = name
  393. if configBody["field_name"] == nil || reflect.TypeOf(configBody["field_name"]).String() != "string" {
  394. utils.ErrorLog("field_name")
  395. code = enums.ErrorCodeParamWrong
  396. return
  397. }
  398. field_name, _ := configBody["field_name"].(string)
  399. if len(field_name) == 0 {
  400. utils.ErrorLog("len(field_name) == 0")
  401. code = enums.ErrorCodeParamWrong
  402. return
  403. }
  404. dataconfig.FieldName = field_name
  405. }
  406. return
  407. }
  408. func configChildFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
  409. configBody := make(map[string]interface{}, 0)
  410. err := json.Unmarshal(data, &configBody)
  411. utils.InfoLog(string(data))
  412. if err != nil {
  413. utils.ErrorLog(err.Error())
  414. code = enums.ErrorCodeParamWrong
  415. return
  416. }
  417. if configBody["module"] == nil || reflect.TypeOf(configBody["module"]).String() != "string" {
  418. utils.ErrorLog("module")
  419. code = enums.ErrorCodeParamWrong
  420. return
  421. }
  422. module, _ := configBody["module"].(string)
  423. if len(module) == 0 {
  424. utils.ErrorLog("len(module) == 0")
  425. code = enums.ErrorCodeParamWrong
  426. return
  427. }
  428. dataconfig.Module = module
  429. if module == "education" || module == "summary" {
  430. if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
  431. utils.ErrorLog("title")
  432. code = enums.ErrorCodeParamWrong
  433. return
  434. }
  435. title, _ := configBody["title"].(string)
  436. if len(title) == 0 {
  437. utils.ErrorLog("len(title) == 0")
  438. code = enums.ErrorCodeParamWrong
  439. return
  440. }
  441. dataconfig.Title = title
  442. if configBody["content"] == nil || reflect.TypeOf(configBody["content"]).String() != "string" {
  443. utils.ErrorLog("content")
  444. code = enums.ErrorCodeParamWrong
  445. return
  446. }
  447. content, _ := configBody["content"].(string)
  448. if len(content) == 0 {
  449. utils.ErrorLog("len(content) == 0")
  450. code = enums.ErrorCodeParamWrong
  451. return
  452. }
  453. dataconfig.Content = content
  454. } else {
  455. if configBody["parent_id"] == nil || reflect.TypeOf(configBody["parent_id"]).String() != "float64" {
  456. utils.ErrorLog("module")
  457. code = enums.ErrorCodeParamWrong
  458. return
  459. }
  460. parent_id := int64(configBody["parent_id"].(float64))
  461. //if parent_id <= 0 {
  462. // utils.ErrorLog("parent_id <= 0")
  463. // code = enums.ErrorCodeParamWrong
  464. // return
  465. //}
  466. dataconfig.ParentId = parent_id
  467. if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
  468. utils.ErrorLog("name")
  469. code = enums.ErrorCodeParamWrong
  470. return
  471. }
  472. name, _ := configBody["name"].(string)
  473. //if len(name) == 0 {
  474. // utils.ErrorLog("len(name) == 0")
  475. // code = enums.ErrorCodeParamWrong
  476. // return
  477. //}
  478. dataconfig.Name = name
  479. }
  480. return
  481. }
  482. func (c *DataApiController) GetAdviceConfigs() {
  483. advice_type, _ := c.GetInt64("type", 0)
  484. adminUserInfo := c.GetAdminUserInfo()
  485. var drugs []models.DrugDic
  486. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  487. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  488. adviceTemplates, _ := service.FindAllAdviceTemplate(adminUserInfo.CurrentOrgId, advice_type)
  489. c.ServeSuccessJSON(map[string]interface{}{
  490. "drugs": drugs,
  491. "drugways": drugways,
  492. "efs": efs,
  493. "advice_templates": adviceTemplates,
  494. })
  495. }
  496. func (c *DataApiController) CreateDrugDic() {
  497. adminUserInfo := c.GetAdminUserInfo()
  498. var drugdic models.DrugDic
  499. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdic)
  500. if err != nil {
  501. utils.ErrorLog("%v", err)
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  503. return
  504. }
  505. if drugdic.Name == "" {
  506. utils.ErrorLog("医嘱名称不能为空")
  507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  508. return
  509. }
  510. timeNow := time.Now().Unix()
  511. drugdic.Code = ""
  512. drugdic.Status = 1
  513. drugdic.CreatedTime = timeNow
  514. drugdic.UpdatedTime = timeNow
  515. drugdic.OrgId = adminUserInfo.CurrentOrgId
  516. drugdic.Creator = adminUserInfo.AdminUser.Id
  517. err = service.CreateDrugDic(&drugdic)
  518. if err != nil {
  519. utils.ErrorLog("%v", err)
  520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  521. return
  522. }
  523. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  524. redis := service.RedisClient()
  525. defer redis.Close()
  526. redis.Set(drugways_keys, "", time.Second*60*60*18)
  527. c.ServeSuccessJSON(map[string]interface{}{
  528. "drugdic": drugdic,
  529. })
  530. return
  531. }
  532. func (c *DataApiController) UpdateDrugDic() {
  533. adminUserInfo := c.GetAdminUserInfo()
  534. id, _ := c.GetInt64("id", 0)
  535. if id <= 0 {
  536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  537. return
  538. }
  539. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  540. if drugdic == nil {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  542. return
  543. }
  544. var drugdicdata models.DrugDic
  545. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugdicdata)
  546. if err != nil {
  547. utils.ErrorLog("%v", err)
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  549. return
  550. }
  551. if drugdicdata.Name == "" {
  552. utils.ErrorLog("医嘱名称不能为空")
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  554. return
  555. }
  556. timeNow := time.Now().Unix()
  557. drugdic.UpdatedTime = timeNow
  558. drugdic.Name = drugdicdata.Name
  559. drugdic.Spec = drugdicdata.Spec
  560. drugdic.SpecUnit = drugdicdata.SpecUnit
  561. drugdic.Form = drugdicdata.Form
  562. drugdic.FormUnit = drugdicdata.FormUnit
  563. err = service.UpdateDrugDic(drugdic)
  564. if err != nil {
  565. utils.ErrorLog("%v", err)
  566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  567. return
  568. }
  569. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  570. redis := service.RedisClient()
  571. defer redis.Close()
  572. redis.Set(drugways_keys, "", time.Second*60*60*18)
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "drugdic": drugdic,
  575. })
  576. return
  577. }
  578. func (c *DataApiController) DeleteDrugDic() {
  579. adminUserInfo := c.GetAdminUserInfo()
  580. id, _ := c.GetInt64("id", 0)
  581. if id <= 0 {
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  583. return
  584. }
  585. drugdic, _ := service.FindDrugDic(adminUserInfo.CurrentOrgId, id)
  586. if drugdic == nil {
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  588. return
  589. }
  590. timeNow := time.Now().Unix()
  591. drugdic.UpdatedTime = timeNow
  592. drugdic.Status = 2
  593. err := service.UpdateDrugDic(drugdic)
  594. if err != nil {
  595. utils.ErrorLog("%v", err)
  596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  597. return
  598. }
  599. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  600. redis := service.RedisClient()
  601. defer redis.Close()
  602. redis.Set(drugways_keys, "", time.Second*60*60*18)
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "msg": "ok",
  605. })
  606. return
  607. }
  608. func (c *DataApiController) CreateDrugWay() {
  609. adminUserInfo := c.GetAdminUserInfo()
  610. var drugway models.DrugwayDic
  611. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugway)
  612. if err != nil {
  613. utils.ErrorLog("%v", err)
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  615. return
  616. }
  617. if drugway.Name == "" {
  618. utils.ErrorLog("给药途径不能为空")
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  620. return
  621. }
  622. timeNow := time.Now().Unix()
  623. drugway.Code = drugway.Code
  624. drugway.Status = 1
  625. drugway.CreatedTime = timeNow
  626. drugway.UpdatedTime = timeNow
  627. drugway.OrgId = adminUserInfo.CurrentOrgId
  628. drugway.Creator = adminUserInfo.AdminUser.Id
  629. drugway.Bby01 = drugway.Bby01
  630. err = service.CreateDrugWay(&drugway)
  631. if err != nil {
  632. utils.ErrorLog("%v", err)
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  634. return
  635. }
  636. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  637. redis := service.RedisClient()
  638. defer redis.Close()
  639. redis.Set(drugways_keys, "", time.Second*60*60*18)
  640. c.ServeSuccessJSON(map[string]interface{}{
  641. "drugway": drugway,
  642. })
  643. return
  644. }
  645. func (c *DataApiController) UpdateDrugWay() {
  646. adminUserInfo := c.GetAdminUserInfo()
  647. id, _ := c.GetInt64("id", 0)
  648. if id <= 0 {
  649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  650. return
  651. }
  652. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  653. if drugway == nil {
  654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  655. return
  656. }
  657. var drugwaydata models.DrugwayDic
  658. err := json.Unmarshal(c.Ctx.Input.RequestBody, &drugwaydata)
  659. if err != nil {
  660. utils.ErrorLog("%v", err)
  661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  662. return
  663. }
  664. if drugwaydata.Name == "" {
  665. utils.ErrorLog("给药途径不能为空")
  666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  667. return
  668. }
  669. timeNow := time.Now().Unix()
  670. drugway.UpdatedTime = timeNow
  671. drugway.Code = drugwaydata.Code
  672. drugway.Name = drugwaydata.Name
  673. drugway.Bby01 = drugwaydata.Bby01
  674. err = service.UpdateDrugWay(drugway)
  675. if err != nil {
  676. utils.ErrorLog("%v", err)
  677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  678. return
  679. }
  680. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  681. redis := service.RedisClient()
  682. defer redis.Close()
  683. redis.Set(drugways_keys, "", time.Second*60*60*18)
  684. c.ServeSuccessJSON(map[string]interface{}{
  685. "drugway": drugway,
  686. })
  687. return
  688. }
  689. func (c *DataApiController) DeleteDrugWay() {
  690. adminUserInfo := c.GetAdminUserInfo()
  691. id, _ := c.GetInt64("id", 0)
  692. if id <= 0 {
  693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  694. return
  695. }
  696. drugway, _ := service.FindDrugWay(adminUserInfo.CurrentOrgId, id)
  697. if drugway == nil {
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  699. return
  700. }
  701. timeNow := time.Now().Unix()
  702. drugway.UpdatedTime = timeNow
  703. drugway.Status = 2
  704. err := service.UpdateDrugWay(drugway)
  705. if err != nil {
  706. utils.ErrorLog("%v", err)
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  708. return
  709. }
  710. drugways_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_drugways"
  711. redis := service.RedisClient()
  712. defer redis.Close()
  713. redis.Set(drugways_keys, "", time.Second*60*60*18)
  714. c.ServeSuccessJSON(map[string]interface{}{
  715. "msg": "ok",
  716. })
  717. return
  718. }
  719. func (c *DataApiController) CreateExecutionFrequency() {
  720. adminUserInfo := c.GetAdminUserInfo()
  721. var ef models.ExecutionFrequencyDic
  722. err := json.Unmarshal(c.Ctx.Input.RequestBody, &ef)
  723. if err != nil {
  724. utils.ErrorLog("%v", err)
  725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  726. return
  727. }
  728. if ef.Name == "" {
  729. utils.ErrorLog("执行频率不能为空")
  730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  731. return
  732. }
  733. timeNow := time.Now().Unix()
  734. ef.Status = 1
  735. ef.CreatedTime = timeNow
  736. ef.UpdatedTime = timeNow
  737. ef.OrgId = adminUserInfo.CurrentOrgId
  738. ef.Creator = adminUserInfo.AdminUser.Id
  739. err = service.CreateExecutionFrequency(&ef)
  740. if err != nil {
  741. utils.ErrorLog("%v", err)
  742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  743. return
  744. }
  745. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  746. redis := service.RedisClient()
  747. defer redis.Close()
  748. redis.Set(efs_keys, "", time.Second*60*60*18)
  749. c.ServeSuccessJSON(map[string]interface{}{
  750. "ef": ef,
  751. })
  752. return
  753. }
  754. func (c *DataApiController) UpdateExecutionFrequency() {
  755. adminUserInfo := c.GetAdminUserInfo()
  756. id, _ := c.GetInt64("id", 0)
  757. if id <= 0 {
  758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  759. return
  760. }
  761. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  762. if ef == nil {
  763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  764. return
  765. }
  766. var efdata models.ExecutionFrequencyDic
  767. err := json.Unmarshal(c.Ctx.Input.RequestBody, &efdata)
  768. if err != nil {
  769. utils.ErrorLog("%v", err)
  770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  771. return
  772. }
  773. if efdata.Name == "" {
  774. utils.ErrorLog("执行频率不能为空")
  775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  776. return
  777. }
  778. timeNow := time.Now().Unix()
  779. ef.UpdatedTime = timeNow
  780. ef.Name = efdata.Name
  781. ef.Code = efdata.Code
  782. ef.Count = efdata.Count
  783. err = service.UpdateExecutionFrequency(ef)
  784. if err != nil {
  785. utils.ErrorLog("%v", err)
  786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  787. return
  788. }
  789. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  790. redis := service.RedisClient()
  791. defer redis.Close()
  792. redis.Set(efs_keys, "", time.Second*60*60*18)
  793. c.ServeSuccessJSON(map[string]interface{}{
  794. "ef": ef,
  795. })
  796. return
  797. }
  798. func (c *DataApiController) DeleteExecutionFrequency() {
  799. adminUserInfo := c.GetAdminUserInfo()
  800. id, _ := c.GetInt64("id", 0)
  801. if id <= 0 {
  802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  803. return
  804. }
  805. ef, _ := service.FindExecutionFrequency(adminUserInfo.CurrentOrgId, id)
  806. if ef == nil {
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  808. return
  809. }
  810. timeNow := time.Now().Unix()
  811. ef.UpdatedTime = timeNow
  812. ef.Status = 2
  813. err := service.UpdateExecutionFrequency(ef)
  814. if err != nil {
  815. utils.ErrorLog("%v", err)
  816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  817. return
  818. }
  819. efs_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_efs"
  820. redis := service.RedisClient()
  821. defer redis.Close()
  822. redis.Set(efs_keys, "", time.Second*60*60*18)
  823. c.ServeSuccessJSON(map[string]interface{}{
  824. "msg": "ok",
  825. })
  826. return
  827. }
  828. func (c *DataApiController) CreateAdviceTemplate() {
  829. templateName := c.GetString("template_name")
  830. advice_type, _ := c.GetInt64("advice_type")
  831. sort, _ := c.GetInt64("sort")
  832. if templateName == "" {
  833. utils.ErrorLog("模版名称不能为空")
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  835. return
  836. }
  837. if advice_type < 0 {
  838. utils.ErrorLog("医嘱模版类型不能为空")
  839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  840. return
  841. }
  842. adminUserInfo := c.GetAdminUserInfo()
  843. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  844. if appRole.UserType == 3 {
  845. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  846. if getPermissionErr != nil {
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  848. return
  849. } else if headNursePermission == nil {
  850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  851. return
  852. }
  853. }
  854. template := &models.DoctorAdviceParentTemplate{
  855. Name: templateName,
  856. OrgId: adminUserInfo.CurrentOrgId,
  857. Status: 1,
  858. CreatedTime: time.Now().Unix(),
  859. UpdatedTime: time.Now().Unix(),
  860. AdviceType: advice_type,
  861. Sort: sort,
  862. }
  863. createErr := service.CreateTemplate(template)
  864. if createErr != nil {
  865. utils.ErrorLog("%v", createErr)
  866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. return
  868. }
  869. dataBody := make(map[string]interface{}, 0)
  870. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  871. if err != nil {
  872. utils.ErrorLog(err.Error())
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  874. return
  875. }
  876. var subTemplate []*models.DoctorAdviceTemplate
  877. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  878. subTemp, _ := dataBody["data"].([]interface{})
  879. if len(subTemp) > 0 {
  880. for _, item := range subTemp {
  881. items := item.(map[string]interface{})
  882. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  883. utils.ErrorLog("advice_name")
  884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  885. return
  886. }
  887. advice_name, _ := items["advice_name"].(string)
  888. advice_desc, _ := items["advice_desc"].(string)
  889. single_dose_unit, _ := items["single_dose_unit"].(string)
  890. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  891. delivery_way, _ := items["delivery_way"].(string)
  892. execution_frequency, _ := items["execution_frequency"].(string)
  893. drug_spec, _ := items["drug_spec"].(string)
  894. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  895. single_dose := items["single_dose"].(float64)
  896. prescribing_number := items["prescribing_number"].(float64)
  897. day_count, _ := strconv.ParseInt(items["day_count"].(string), 10, 64)
  898. weekdays := items["weekdays"].(string)
  899. frequency_type := int64(items["frequency_type"].(float64))
  900. drug_id := int64(items["drug_id"].(float64))
  901. way := int64(items["way"].(float64))
  902. remark := items["remark"].(string)
  903. fmt.Println("remark--------------------------", remark)
  904. subTemps := &models.DoctorAdviceTemplate{
  905. AdviceName: advice_name,
  906. Status: 1,
  907. CreatedTime: time.Now().Unix(),
  908. UpdatedTime: time.Now().Unix(),
  909. OrgId: adminUserInfo.CurrentOrgId,
  910. AdviceDesc: advice_desc,
  911. AdviceType: advice_type,
  912. SingleDoseUnit: single_dose_unit,
  913. PrescribingNumber: prescribing_number,
  914. PrescribingNumberUnit: prescribing_number_unit,
  915. DeliveryWay: delivery_way,
  916. ExecutionFrequency: execution_frequency,
  917. TemplateId: template.ID,
  918. DrugSpec: drug_spec,
  919. DrugSpecUnit: drug_spec_unit,
  920. SingleDose: single_dose,
  921. AdviceDoctor: adminUserInfo.AdminUser.Id,
  922. DayCount: day_count,
  923. WeekDays: weekdays,
  924. FrequencyType: frequency_type,
  925. Way: way,
  926. DrugId: drug_id,
  927. DrugNameId: 0,
  928. Remark: remark,
  929. }
  930. subTemplate = append(subTemplate, subTemps)
  931. }
  932. }
  933. }
  934. //errs := service.CreateBatchRecord(subTemplate)
  935. errs := service.CreateSubTemplate(subTemplate)
  936. if errs != nil {
  937. utils.ErrorLog(errs.Error())
  938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  939. return
  940. }
  941. templates, _ := service.FindDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  942. c.ServeSuccessJSON(map[string]interface{}{
  943. "template": templates,
  944. })
  945. return
  946. }
  947. func (c *DataApiController) UpdateAdviceTemplate() {
  948. adminUserInfo := c.GetAdminUserInfo()
  949. id, _ := c.GetInt64("id", 0)
  950. if id <= 0 {
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  952. return
  953. }
  954. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  955. if template == nil {
  956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  957. return
  958. }
  959. //TODO 根据路由来做权限
  960. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  961. //if appRole.UserType == 3 {
  962. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  963. // if getPermissionErr != nil {
  964. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  965. // return
  966. // } else if headNursePermission == nil {
  967. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  968. // return
  969. // }
  970. //}
  971. var templatedata models.DoctorAdviceTemplate
  972. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  973. if err != nil {
  974. utils.ErrorLog("%v", err)
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  976. return
  977. }
  978. if templatedata.AdviceName == "" {
  979. utils.ErrorLog("不能为空")
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. timeNow := time.Now().Unix()
  984. template.UpdatedTime = timeNow
  985. template.AdviceName = templatedata.AdviceName
  986. template.AdviceDesc = templatedata.AdviceDesc
  987. template.SingleDose = templatedata.SingleDose
  988. template.SingleDoseUnit = templatedata.SingleDoseUnit
  989. template.PrescribingNumber = templatedata.PrescribingNumber
  990. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  991. template.DrugSpec = templatedata.DrugSpec
  992. template.DrugSpecUnit = templatedata.DrugSpecUnit
  993. template.DeliveryWay = templatedata.DeliveryWay
  994. template.ExecutionFrequency = templatedata.ExecutionFrequency
  995. template.FrequencyType = templatedata.FrequencyType
  996. template.DayCount = templatedata.DayCount
  997. template.WeekDays = templatedata.WeekDays
  998. template.DrugId = template.DrugId
  999. template.Way = template.Way
  1000. template.Remark = templatedata.Remark
  1001. err = service.UpdateAdviceTemplate(template)
  1002. if err != nil {
  1003. utils.ErrorLog("%v", err)
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1005. return
  1006. }
  1007. c.ServeSuccessJSON(map[string]interface{}{
  1008. "template": template,
  1009. })
  1010. return
  1011. }
  1012. func (c *DataApiController) DeleteAdviceTemplate() {
  1013. adminUserInfo := c.GetAdminUserInfo()
  1014. parent_id, _ := c.GetInt64("parent_id", 0)
  1015. id, _ := c.GetInt64("id", 0)
  1016. if id <= 0 {
  1017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1018. return
  1019. }
  1020. template, _ := service.FindAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1021. if template == nil {
  1022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1023. return
  1024. }
  1025. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1026. //if appRole.UserType == 3 {
  1027. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1028. // if getPermissionErr != nil {
  1029. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1030. // return
  1031. // } else if headNursePermission == nil {
  1032. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1033. // return
  1034. // }
  1035. //}
  1036. timeNow := time.Now().Unix()
  1037. template.ID = id
  1038. template.UpdatedTime = timeNow
  1039. template.ParentId = parent_id
  1040. template.Status = 2
  1041. if parent_id > 0 { //删除子医嘱
  1042. err := service.UpdateAdviceTemplate(template)
  1043. if err != nil {
  1044. utils.ErrorLog("%v", err)
  1045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1046. return
  1047. }
  1048. } else { //删除该医嘱下的所有子医嘱
  1049. err := service.UpdateAdviceAndSubAdviceTemplate(template)
  1050. if err != nil {
  1051. utils.ErrorLog("%v", err)
  1052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1053. return
  1054. }
  1055. }
  1056. c.ServeSuccessJSON(map[string]interface{}{
  1057. "msg": "ok",
  1058. })
  1059. return
  1060. }
  1061. func (c *DataApiController) CreateSingleAdviceTemplate() {
  1062. drug_spec := c.GetString("drug_spec")
  1063. drug_spec_unit := c.GetString("drug_spec_unit")
  1064. advice_name := c.GetString("advice_name")
  1065. advice_desc := c.GetString("advice_desc")
  1066. single_dose, _ := c.GetFloat("single_dose", 0)
  1067. single_dose_unit := c.GetString("single_dose_unit")
  1068. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1069. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1070. delivery_way := c.GetString("delivery_way")
  1071. execution_frequency := c.GetString("execution_frequency")
  1072. template_id, _ := c.GetInt64("template_id", -1)
  1073. advice_type, _ := c.GetInt64("advice_type", -1)
  1074. frequency_type, _ := c.GetInt64("frequency_type", -1)
  1075. week_days := c.GetString("week_days")
  1076. day_count, _ := c.GetInt64("day_count", -1)
  1077. drug_id, _ := c.GetInt64("drug_id")
  1078. way, _ := c.GetInt64("way")
  1079. adminUserInfo := c.GetAdminUserInfo()
  1080. template := models.DoctorAdviceTemplate{
  1081. OrgId: adminUserInfo.CurrentOrgId,
  1082. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1083. AdviceType: advice_type,
  1084. FrequencyType: frequency_type,
  1085. WeekDays: week_days,
  1086. DayCount: day_count,
  1087. Status: 1,
  1088. CreatedTime: time.Now().Unix(),
  1089. UpdatedTime: time.Now().Unix(),
  1090. DrugSpec: drug_spec,
  1091. DrugSpecUnit: drug_spec_unit,
  1092. AdviceName: advice_name,
  1093. AdviceDesc: advice_desc,
  1094. SingleDose: single_dose,
  1095. SingleDoseUnit: service.TypeConversion02(single_dose_unit),
  1096. PrescribingNumber: prescribing_number,
  1097. PrescribingNumberUnit: prescribing_number_unit,
  1098. DeliveryWay: delivery_way,
  1099. ExecutionFrequency: execution_frequency,
  1100. TemplateId: template_id,
  1101. Way: way,
  1102. DrugId: drug_id,
  1103. }
  1104. if template.AdviceName == "" {
  1105. utils.ErrorLog("医嘱名字不能为空")
  1106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1107. return
  1108. }
  1109. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1110. if appRole.UserType == 3 {
  1111. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1112. if getPermissionErr != nil {
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1114. return
  1115. } else if headNursePermission == nil {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1117. return
  1118. }
  1119. }
  1120. err := service.CreateAdviceTemplate(&template)
  1121. if err != nil {
  1122. utils.ErrorLog("%v", err)
  1123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1124. return
  1125. }
  1126. c.ServeSuccessJSON(map[string]interface{}{
  1127. "template": template,
  1128. })
  1129. return
  1130. }
  1131. func (c *DataApiController) DeleteParentAdviceTemplate() {
  1132. template_id, _ := c.GetInt64("template_id", 0)
  1133. adminUserInfo := c.GetAdminUserInfo()
  1134. _, err := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1135. if err != nil {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1137. return
  1138. }
  1139. err1 := service.DeleteParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1140. if err1 != nil {
  1141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1142. return
  1143. }
  1144. c.ServeSuccessJSON(map[string]interface{}{
  1145. "msg": "删除成功",
  1146. })
  1147. }
  1148. func (c *DataApiController) CreateSubAdviceTemplate() {
  1149. drug_spec := c.GetString("drug_spec")
  1150. drug_spec_unit := c.GetString("drug_spec_unit")
  1151. advice_name := c.GetString("advice_name")
  1152. advice_desc := c.GetString("advice_desc")
  1153. single_dose, _ := c.GetFloat("single_dose", 0)
  1154. single_dose_unit := c.GetString("single_dose_unit")
  1155. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1156. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1157. delivery_way := c.GetString("delivery_way")
  1158. execution_frequency := c.GetString("execution_frequency")
  1159. template_id, _ := c.GetInt64("template_id", 0)
  1160. parent_id, _ := c.GetInt64("parent_id", 0)
  1161. drug_id, _ := c.GetInt64("drug_id")
  1162. way, _ := c.GetInt64("way")
  1163. remark := c.GetString("remark")
  1164. adminUserInfo := c.GetAdminUserInfo()
  1165. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1166. if appRole.UserType == 3 {
  1167. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1168. if getPermissionErr != nil {
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1170. return
  1171. } else if headNursePermission == nil {
  1172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1173. return
  1174. }
  1175. }
  1176. template := models.DoctorAdviceTemplate{
  1177. OrgId: adminUserInfo.CurrentOrgId,
  1178. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1179. Status: 1,
  1180. CreatedTime: time.Now().Unix(),
  1181. UpdatedTime: time.Now().Unix(),
  1182. DrugSpec: drug_spec,
  1183. DrugSpecUnit: drug_spec_unit,
  1184. AdviceName: advice_name,
  1185. AdviceDesc: advice_desc,
  1186. SingleDose: single_dose,
  1187. SingleDoseUnit: single_dose_unit,
  1188. PrescribingNumber: prescribing_number,
  1189. PrescribingNumberUnit: prescribing_number_unit,
  1190. DeliveryWay: delivery_way,
  1191. ExecutionFrequency: execution_frequency,
  1192. TemplateId: template_id,
  1193. ParentId: parent_id,
  1194. DrugId: drug_id,
  1195. Way: way,
  1196. Remark: remark,
  1197. }
  1198. if template.AdviceName == "" {
  1199. utils.ErrorLog("医嘱名字不能为空")
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1201. return
  1202. }
  1203. err := service.CreateAdviceTemplate(&template)
  1204. if err != nil {
  1205. utils.ErrorLog("%v", err)
  1206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1207. return
  1208. }
  1209. c.ServeSuccessJSON(map[string]interface{}{
  1210. "template": template,
  1211. })
  1212. return
  1213. }
  1214. func (this *DataApiController) ModifyTemplateName() {
  1215. template_name := this.GetString("template_name")
  1216. template_id, _ := this.GetInt64("template_id", 0)
  1217. sort, _ := this.GetInt64("sort")
  1218. if len(template_name) <= 0 {
  1219. utils.ErrorLog("模版名字不能为空")
  1220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1221. return
  1222. }
  1223. if template_id == 0 {
  1224. utils.ErrorLog("模版不存在")
  1225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1226. return
  1227. }
  1228. adminUserInfo := this.GetAdminUserInfo()
  1229. template, _ := service.FindParentTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1230. var err error
  1231. if template.Name == template_name {
  1232. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1233. if err != nil {
  1234. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1235. return
  1236. }
  1237. } else {
  1238. //total := service.FindTemplateRecordByName(adminUserInfo.CurrentOrgId, template_name);
  1239. //if total > 0 {
  1240. // utils.ErrorLog("模版名称已经存在")
  1241. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameWrong)
  1242. // return
  1243. //}
  1244. err = service.ModifyTemplateNameOne(template_id, template_name, sort)
  1245. if err != nil {
  1246. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1247. return
  1248. }
  1249. }
  1250. this.ServeSuccessJSON(map[string]interface{}{
  1251. "template_name": template_name,
  1252. "template_id": template_id,
  1253. })
  1254. }
  1255. func (this *DataApiController) ModifyFiledIsShow() {
  1256. id, _ := this.GetInt64("id", 0)
  1257. is_show, _ := this.GetInt("is_show", 0)
  1258. is_write, _ := this.GetInt("is_write", 0)
  1259. adminUserInfo := this.GetAdminUserInfo()
  1260. err := service.ShowFiledConfig(adminUserInfo.CurrentOrgId, is_show, is_write, id)
  1261. if err != nil {
  1262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1263. return
  1264. } else {
  1265. this.ServeSuccessJSON(map[string]interface{}{
  1266. "id": id,
  1267. "is_show": is_show,
  1268. "is_write": is_write,
  1269. })
  1270. }
  1271. }
  1272. func (c *DataApiController) GetAllAdviceConfigs() {
  1273. adminUserInfo := c.GetAdminUserInfo()
  1274. var drugs []models.DrugDic
  1275. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1276. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1277. adviceTemplates, _ := service.FindOtherAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1278. dics, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1279. c.ServeSuccessJSON(map[string]interface{}{
  1280. "drugs": drugs,
  1281. "drugways": drugways,
  1282. "efs": efs,
  1283. "advice_templates": adviceTemplates,
  1284. "dics": dics,
  1285. })
  1286. }
  1287. func (c *DataApiController) GetHandleData() {
  1288. id, _ := c.GetInt64("id")
  1289. config, err := service.GetHandleData(id)
  1290. if err != nil {
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1292. return
  1293. }
  1294. c.ServeSuccessJSON(map[string]interface{}{
  1295. "config": config,
  1296. })
  1297. }
  1298. func (c *DataApiController) UpdateDataTwo() {
  1299. id, _ := c.GetInt64("id")
  1300. //fmt.Print("id",id)
  1301. dataBody := make(map[string]interface{}, 0)
  1302. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1303. //fmt.Print("err",err)
  1304. //fmt.Print("id",id)
  1305. name := dataBody["name"].(string)
  1306. // fmt.Print("name",name)
  1307. order := int64(dataBody["order"].(float64))
  1308. // fmt.Print("order",order)
  1309. remake := dataBody["remark"].(string)
  1310. // fmt.Print("remake",remake)
  1311. configModel := models.ConfigViewModel{
  1312. Name: name,
  1313. Order: order,
  1314. Remark: remake,
  1315. }
  1316. err = service.UpdateDataTwo(id, configModel)
  1317. if err != nil {
  1318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1319. return
  1320. }
  1321. c.ServeSuccessJSON(map[string]interface{}{
  1322. "configModel": configModel,
  1323. })
  1324. }
  1325. func (c *DataApiController) CreateHisAdviceTemplate() {
  1326. templateName := c.GetString("template_name")
  1327. advice_type, _ := c.GetInt64("advice_type")
  1328. if templateName == "" {
  1329. utils.ErrorLog("模版名称不能为空")
  1330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1331. return
  1332. }
  1333. if advice_type < 0 {
  1334. utils.ErrorLog("医嘱模版类型不能为空")
  1335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceTypeWrong)
  1336. return
  1337. }
  1338. adminUserInfo := c.GetAdminUserInfo()
  1339. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1340. if appRole.UserType == 3 {
  1341. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1342. if getPermissionErr != nil {
  1343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1344. return
  1345. } else if headNursePermission == nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1347. return
  1348. }
  1349. }
  1350. template := &models.HisDoctorAdviceParentTemplate{
  1351. Name: templateName,
  1352. OrgId: adminUserInfo.CurrentOrgId,
  1353. Status: 1,
  1354. CreatedTime: time.Now().Unix(),
  1355. UpdatedTime: time.Now().Unix(),
  1356. AdviceType: advice_type,
  1357. }
  1358. createErr := service.CreateHisDoctorAdviceTemplate(template)
  1359. if createErr != nil {
  1360. utils.ErrorLog("%v", createErr)
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. dataBody := make(map[string]interface{}, 0)
  1365. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1366. if err != nil {
  1367. utils.ErrorLog(err.Error())
  1368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1369. return
  1370. }
  1371. var subTemplate []*models.HisDoctorAdviceTemplate
  1372. if dataBody["data"] != nil && reflect.TypeOf(dataBody["data"]).String() == "[]interface {}" {
  1373. subTemp, _ := dataBody["data"].([]interface{})
  1374. if len(subTemp) > 0 {
  1375. for _, item := range subTemp {
  1376. items := item.(map[string]interface{})
  1377. if items["advice_name"] == nil || reflect.TypeOf(items["advice_name"]).String() != "string" {
  1378. utils.ErrorLog("advice_name")
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1380. return
  1381. }
  1382. advice_name, _ := items["advice_name"].(string)
  1383. advice_desc, _ := items["advice_desc"].(string)
  1384. single_dose_unit, _ := items["single_dose_unit"].(string)
  1385. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  1386. delivery_way, _ := items["delivery_way"].(string)
  1387. execution_frequency, _ := items["execution_frequency"].(string)
  1388. drug_spec, _ := items["drug_spec"].(string)
  1389. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  1390. single_dose := items["single_dose"].(float64)
  1391. prescribing_number := items["prescribing_number"].(float64)
  1392. drug_id := int64(items["drug_id"].(float64))
  1393. subTemps := &models.HisDoctorAdviceTemplate{
  1394. AdviceName: advice_name,
  1395. Status: 1,
  1396. CreatedTime: time.Now().Unix(),
  1397. UpdatedTime: time.Now().Unix(),
  1398. OrgId: adminUserInfo.CurrentOrgId,
  1399. AdviceDesc: advice_desc,
  1400. AdviceType: advice_type,
  1401. SingleDoseUnit: single_dose_unit,
  1402. PrescribingNumber: prescribing_number,
  1403. PrescribingNumberUnit: prescribing_number_unit,
  1404. DeliveryWay: delivery_way,
  1405. ExecutionFrequency: execution_frequency,
  1406. TemplateId: template.ID,
  1407. DrugSpec: drug_spec,
  1408. DrugSpecUnit: drug_spec_unit,
  1409. SingleDose: single_dose,
  1410. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1411. DrugId: drug_id,
  1412. }
  1413. subTemplate = append(subTemplate, subTemps)
  1414. }
  1415. }
  1416. }
  1417. //errs := service.CreateBatchRecord(subTemplate)
  1418. errs := service.CreateHisSubDoctorAdviceTemplate(subTemplate)
  1419. if errs != nil {
  1420. utils.ErrorLog(errs.Error())
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1422. return
  1423. }
  1424. templates, _ := service.FindHisDoctorAdviceTemplateById(template.ID, adminUserInfo.CurrentOrgId)
  1425. c.ServeSuccessJSON(map[string]interface{}{
  1426. "template": templates,
  1427. })
  1428. return
  1429. }
  1430. func (c *DataApiController) UpdateHisAdviceTemplate() {
  1431. adminUserInfo := c.GetAdminUserInfo()
  1432. id, _ := c.GetInt64("id", 0)
  1433. if id <= 0 {
  1434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1435. return
  1436. }
  1437. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1438. if template == nil {
  1439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1440. return
  1441. }
  1442. var templatedata models.HisDoctorAdviceTemplate
  1443. err := json.Unmarshal(c.Ctx.Input.RequestBody, &templatedata)
  1444. if err != nil {
  1445. utils.ErrorLog("%v", err)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. if templatedata.AdviceName == "" {
  1450. utils.ErrorLog("不能为空")
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1452. return
  1453. }
  1454. timeNow := time.Now().Unix()
  1455. template.UpdatedTime = timeNow
  1456. template.AdviceName = templatedata.AdviceName
  1457. template.AdviceDesc = templatedata.AdviceDesc
  1458. template.SingleDose = templatedata.SingleDose
  1459. template.SingleDoseUnit = templatedata.SingleDoseUnit
  1460. template.PrescribingNumber = templatedata.PrescribingNumber
  1461. template.PrescribingNumberUnit = templatedata.PrescribingNumberUnit
  1462. template.DrugSpec = templatedata.DrugSpec
  1463. template.DrugSpecUnit = templatedata.DrugSpecUnit
  1464. template.DeliveryWay = templatedata.DeliveryWay
  1465. template.ExecutionFrequency = templatedata.ExecutionFrequency
  1466. template.DrugId = template.DrugId
  1467. err = service.UpdateHisAdviceTemplate(template)
  1468. if err != nil {
  1469. utils.ErrorLog("%v", err)
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1471. return
  1472. }
  1473. c.ServeSuccessJSON(map[string]interface{}{
  1474. "template": template,
  1475. })
  1476. return
  1477. }
  1478. func (c *DataApiController) DeleteHisAdviceTemplate() {
  1479. adminUserInfo := c.GetAdminUserInfo()
  1480. parent_id, _ := c.GetInt64("parent_id", 0)
  1481. id, _ := c.GetInt64("id", 0)
  1482. if id <= 0 {
  1483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1484. return
  1485. }
  1486. template, _ := service.FindHisAdviceTemplate(adminUserInfo.CurrentOrgId, id)
  1487. if template == nil {
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  1489. return
  1490. }
  1491. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1492. //if appRole.UserType == 3 {
  1493. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1494. // if getPermissionErr != nil {
  1495. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1496. // return
  1497. // } else if headNursePermission == nil {
  1498. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1499. // return
  1500. // }
  1501. //}
  1502. timeNow := time.Now().Unix()
  1503. template.ID = id
  1504. template.UpdatedTime = timeNow
  1505. template.ParentId = parent_id
  1506. template.Status = 2
  1507. if parent_id > 0 { //删除子医嘱
  1508. err := service.UpdateHisAdviceTemplate(template)
  1509. if err != nil {
  1510. utils.ErrorLog("%v", err)
  1511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1512. return
  1513. }
  1514. } else { //删除该医嘱下的所有子医嘱
  1515. err := service.UpdateHisAdviceAndSubAdviceTemplate(template)
  1516. if err != nil {
  1517. utils.ErrorLog("%v", err)
  1518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1519. return
  1520. }
  1521. }
  1522. c.ServeSuccessJSON(map[string]interface{}{
  1523. "msg": "ok",
  1524. })
  1525. return
  1526. }
  1527. func (c *DataApiController) CreateSingleHisAdviceTemplate() {
  1528. drug_spec := c.GetString("drug_spec")
  1529. drug_spec_unit := c.GetString("drug_spec_unit")
  1530. advice_name := c.GetString("advice_name")
  1531. advice_desc := c.GetString("advice_desc")
  1532. single_dose, _ := c.GetFloat("single_dose", 0)
  1533. single_dose_unit := c.GetString("single_dose_unit")
  1534. prescribing_number, _ := c.GetFloat("prescribing_number", 0)
  1535. prescribing_number_unit := c.GetString("prescribing_number_unit")
  1536. delivery_way := c.GetString("delivery_way")
  1537. execution_frequency := c.GetString("execution_frequency")
  1538. template_id, _ := c.GetInt64("template_id", -1)
  1539. drug_id, _ := c.GetInt64("drug_id")
  1540. adminUserInfo := c.GetAdminUserInfo()
  1541. template := models.HisDoctorAdviceTemplate{
  1542. OrgId: adminUserInfo.CurrentOrgId,
  1543. AdviceDoctor: adminUserInfo.AdminUser.Id,
  1544. Status: 1,
  1545. CreatedTime: time.Now().Unix(),
  1546. UpdatedTime: time.Now().Unix(),
  1547. DrugSpec: drug_spec,
  1548. DrugSpecUnit: drug_spec_unit,
  1549. AdviceName: advice_name,
  1550. AdviceDesc: advice_desc,
  1551. SingleDose: single_dose,
  1552. SingleDoseUnit: single_dose_unit,
  1553. PrescribingNumber: prescribing_number,
  1554. PrescribingNumberUnit: prescribing_number_unit,
  1555. DeliveryWay: delivery_way,
  1556. ExecutionFrequency: execution_frequency,
  1557. TemplateId: template_id,
  1558. DrugId: drug_id,
  1559. }
  1560. if template.AdviceName == "" {
  1561. utils.ErrorLog("医嘱名字不能为空")
  1562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamAdviceEmptyWrong)
  1563. return
  1564. }
  1565. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1566. if appRole.UserType == 3 {
  1567. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1568. if getPermissionErr != nil {
  1569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1570. return
  1571. } else if headNursePermission == nil {
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1573. return
  1574. }
  1575. }
  1576. err := service.CreateHisAdviceTemplate(&template)
  1577. if err != nil {
  1578. utils.ErrorLog("%v", err)
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  1580. return
  1581. }
  1582. c.ServeSuccessJSON(map[string]interface{}{
  1583. "template": template,
  1584. })
  1585. return
  1586. }
  1587. func (c *DataApiController) DeleteHisParentAdviceTemplate() {
  1588. template_id, _ := c.GetInt64("template_id", 0)
  1589. adminUserInfo := c.GetAdminUserInfo()
  1590. _, err := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1591. if err != nil {
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. err1 := service.DeleteHisParentDoctorAdviceByTemplateId(template_id, adminUserInfo.CurrentOrgId)
  1596. if err1 != nil {
  1597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  1598. return
  1599. }
  1600. c.ServeSuccessJSON(map[string]interface{}{
  1601. "msg": "删除成功",
  1602. })
  1603. }
  1604. func (this *DataApiController) ModifyHisTemplateName() {
  1605. template_name := this.GetString("template_name")
  1606. template_id, _ := this.GetInt64("template_id", 0)
  1607. if len(template_name) <= 0 {
  1608. utils.ErrorLog("模版名字不能为空")
  1609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamEmptyWrong)
  1610. return
  1611. }
  1612. if template_id == 0 {
  1613. utils.ErrorLog("模版不存在")
  1614. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamTemplateNOEXISTWrong)
  1615. return
  1616. }
  1617. adminUserInfo := this.GetAdminUserInfo()
  1618. template, _ := service.FindParentHisTemplateRecordById(adminUserInfo.CurrentOrgId, template_id)
  1619. var err error
  1620. if template.Name == template_name {
  1621. err = service.ModifyTemplateName(template_id, template_name)
  1622. if err != nil {
  1623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1624. return
  1625. }
  1626. } else {
  1627. err = service.ModifyHisTemplateName(template_id, template_name)
  1628. if err != nil {
  1629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1630. return
  1631. }
  1632. }
  1633. this.ServeSuccessJSON(map[string]interface{}{
  1634. "template_name": template_name,
  1635. "template_id": template_id,
  1636. })
  1637. }
  1638. func (this *DataApiController) GetAllHisAdviceTemplate() {
  1639. adminUserInfo := this.GetAdminUserInfo()
  1640. drugs, _ := service.GetAllDrugLibs(adminUserInfo.CurrentOrgId)
  1641. drugways, _, _ := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  1642. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  1643. adviceTemplates, _ := service.FindHisAllAdviceTemplate(adminUserInfo.CurrentOrgId)
  1644. this.ServeSuccessJSON(map[string]interface{}{
  1645. "drugways": drugways,
  1646. "efs": efs,
  1647. "advice_templates": adviceTemplates,
  1648. "drugs": drugs,
  1649. })
  1650. }