his_config_api_controller.go 61KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  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. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/astaxie/beego/config"
  11. "golang.org/x/sync/errgroup"
  12. "reflect"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type HisConfigApiController struct {
  18. BaseAuthAPIController
  19. }
  20. const (
  21. AddTypeDrug = 1 //药品
  22. AddTypeProject = 2 //项目
  23. )
  24. func HisConfigApiRegistRouters() {
  25. beego.Router("/api/his/patient/list", &HisConfigApiController{}, "get:GetAllHisPatientsList")
  26. beego.Router("/api/his/patient/getpatientlisttwenty", &HisConfigApiController{}, "get:GetPatientListTwenty")
  27. beego.Router("/api/his/prescriptiontemplate/list", &HisConfigApiController{}, "get:GetPrescriptionTemplateList")
  28. beego.Router("/api/his/prescriptiontemplate/info", &HisConfigApiController{}, "get:GetPrescriptionTemplateInfo")
  29. beego.Router("/api/his/prescriptiontemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionTemplate") //批量添加
  30. beego.Router("/api/his/prescriptiontemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionTemplate")
  31. beego.Router("/api/his/prescriptioninfotemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoTemplate")
  32. beego.Router("/api/his/advicetemplate/delete", &HisConfigApiController{}, "post:DeleteAdviceTemplate")
  33. beego.Router("/api/his/projecttemplate/delete", &HisConfigApiController{}, "post:DeleteProjectTemplate")
  34. //beego.Router("/api/his/responsibilitydoctor/get", &HisConfigApiController{}, "get:GetResponsibilityDoctor")
  35. beego.Router("/api/his/getmodetemplatename", &HisConfigApiController{}, "get:GetModeTemplateName")
  36. beego.Router("/api/his/getprescriptiontemplatedetail", &HisConfigApiController{}, "get:GetPrescriptionTemplateDetail")
  37. beego.Router("/api/his/prescriptionmodetemplate/create", &HisConfigApiController{}, "post:CreatePrescriptionModeTemplate")
  38. beego.Router("/api/his/prescriptionmodetemplate/info", &HisConfigApiController{}, "get:GetPrescriptionModeTemplateInfo")
  39. beego.Router("/api/his/prescriptionmodetemplate/delete", &HisConfigApiController{}, "post:DeleteModePrescriptionTemplate")
  40. beego.Router("/api/his/projectmodetemplate/delete", &HisConfigApiController{}, "post:DeleteModeProjectTemplate")
  41. beego.Router("/api/his/advicempdetemplate/delete", &HisConfigApiController{}, "post:DeleteModeAdviceTemplate")
  42. beego.Router("/api/his/prescriptioninfomodetemplate/delete", &HisConfigApiController{}, "post:DeletePrescriptionInfoModeTemplate")
  43. beego.Router("/api/his/getdialysismodename", &HisConfigApiController{}, "get:GetDialysisModeName") //根据透析模式获取患者姓名
  44. beego.Router("/api/his/getdrugsname", &HisConfigApiController{}, "get:GetDrugsName") //根据类型获取药品名称
  45. beego.Router("/api/his/getmodeconfigs", &HisConfigApiController{}, "get:GetModeConfigs")
  46. beego.Router("/api/his/getdrugsinformation", &HisConfigApiController{}, "get:GetDrugsInformation") //根据id获取药品耗材项目基本信息
  47. beego.Router("/api/his/replacepeoplename", &HisConfigApiController{}, "get:ReplacePeopleName") //替换——获取患者名字
  48. beego.Router("/api/his/replaceconfig", &HisConfigApiController{}, "get:ReplaceConfig")
  49. beego.Router("/api/his/replacesavedrug", &HisConfigApiController{}, "post:ReplaceSaveDrug") //替换——药品保存
  50. beego.Router("/api/his/replacesaveproject", &HisConfigApiController{}, "post:ReplaceSaveProject") //替换——项目保存
  51. beego.Router("/api/his/deletedrugsbatch", &HisConfigApiController{}, "get:DeleteDrugsBatch") //批量删除——药品
  52. beego.Router("/api/his/batchdeleteitems", &HisConfigApiController{}, "get:BatchDeleteItems") //批量删除——项目
  53. beego.Router("/api/his/addstemplate", &HisConfigApiController{}, "post:AddsTemplate") //批量添加
  54. beego.Router("/api/his/ptemplateinformation", &HisConfigApiController{}, "get:PTemplateInformation") //根据患者id、透析模式获取处方模板信息
  55. beego.Router("/api/his/deleteone", &HisConfigApiController{}, "get:DeleteOne") //删除单条处方模板
  56. beego.Router("/api/his/exportmdtrtcerttype", &HisConfigApiController{}, "get:ExportMdtrtCertType") //删除单条处方模板
  57. }
  58. func (c *HisConfigApiController) ExportMdtrtCertType() {
  59. start_time := c.GetString("start_time")
  60. end_time := c.GetString("end_time")
  61. start_time = start_time + " 00:00:00"
  62. end_time = end_time + " 23:00:00"
  63. os, _ := service.GetHisMdtrtCertType(start_time, end_time, c.GetAdminUserInfo().CurrentOrgId)
  64. c.ServeSuccessJSON(map[string]interface{}{
  65. "list": os,
  66. })
  67. }
  68. func (c *HisConfigApiController) GetAllHisPatientsList() {
  69. patients, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  70. c.ServeSuccessJSON(map[string]interface{}{
  71. "list": patients,
  72. })
  73. }
  74. func (c *HisConfigApiController) GetPatientListTwenty() {
  75. patients, _, _ := service.GetAllPatientListTwenty(c.GetAdminUserInfo().CurrentOrgId)
  76. c.ServeSuccessJSON(map[string]interface{}{
  77. "list": patients,
  78. })
  79. }
  80. func (c *HisConfigApiController) GetPrescriptionTemplateList() {
  81. patient_id, _ := c.GetInt64("patient_id", 0)
  82. page, _ := c.GetInt64("page", 0)
  83. limit, _ := c.GetInt64("limit", 0)
  84. if page <= 0 {
  85. page = 1
  86. }
  87. if limit <= 0 {
  88. limit = 10
  89. }
  90. if patient_id <= 0 {
  91. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  92. return
  93. }
  94. templates, total, _ := service.GetHisPrescriptionTemplatesList(patient_id, c.GetAdminUserInfo().CurrentOrgId, page, limit)
  95. c.ServeSuccessJSON(map[string]interface{}{
  96. "list": templates,
  97. "total": total,
  98. })
  99. }
  100. func (c *HisConfigApiController) GetPrescriptionTemplateInfo() {
  101. id, _ := c.GetInt64("id", 0)
  102. template, _ := service.GetHisPrescriptionTemplateByID(id)
  103. prescriptions, _ := service.GetHisPrescriptionTemplate(template.ID, c.GetAdminUserInfo().CurrentOrgId)
  104. c.ServeSuccessJSON(map[string]interface{}{
  105. "template": template,
  106. "prescriptions": prescriptions,
  107. })
  108. }
  109. func (c *HisConfigApiController) CreatePrescriptionTemplate() {
  110. id, _ := c.GetInt64("id")
  111. name := c.GetString("name")
  112. mode_id, _ := c.GetInt64("mode_id", 0)
  113. types, _ := c.GetInt64("type", 0)
  114. patient_id, _ := c.GetInt64("patient_id", 0)
  115. types = 1
  116. adminInfo := c.GetAdminUserInfo()
  117. if id == 0 {
  118. mode_template, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, adminInfo.CurrentOrgId)
  119. if mode_template.ID > 0 {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  121. return
  122. }
  123. }
  124. if id > 0 {
  125. mode_template, _ := service.GetHisPrescriptionTemplateByModeIdTwo(mode_id, patient_id, adminInfo.CurrentOrgId, id)
  126. if mode_template.ID > 0 {
  127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  128. return
  129. }
  130. }
  131. src_template, _ := service.GetHisPrescriptionTemplateByID(id)
  132. if src_template.ID == 0 {
  133. template := models.HisPrescriptionTemplate{
  134. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  135. PatientId: patient_id,
  136. Type: types,
  137. Status: 1,
  138. Ctime: time.Now().Unix(),
  139. Mtime: time.Now().Unix(),
  140. Name: name,
  141. Mode: mode_id,
  142. }
  143. src_template = template
  144. service.CreateHisPrescriptionTemplate(&src_template)
  145. } else {
  146. src_template.Name = name
  147. src_template.Mode = mode_id
  148. service.SaveHisPrescriptionTemplate(&src_template)
  149. }
  150. dataBody := make(map[string]interface{}, 0)
  151. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  152. if err != nil {
  153. utils.ErrorLog(err.Error())
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  155. return
  156. }
  157. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  158. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  159. if len(prescriptions) > 0 {
  160. for _, item := range prescriptions {
  161. items := item.(map[string]interface{})
  162. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  163. utils.ErrorLog("id")
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  165. return
  166. }
  167. id := int64(items["id"].(float64))
  168. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  169. utils.ErrorLog("type")
  170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  171. return
  172. }
  173. types := int64(items["type"].(float64))
  174. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  175. utils.ErrorLog("med_type")
  176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  177. return
  178. }
  179. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  180. ctime := time.Now().Unix()
  181. prescription := &models.HisPrescriptionInfoTemplate{
  182. ID: id,
  183. PatientId: patient_id,
  184. UserOrgId: adminInfo.CurrentOrgId,
  185. Ctime: ctime,
  186. Mtime: ctime,
  187. Type: types,
  188. Modifier: adminInfo.AdminUser.Id,
  189. Creator: adminInfo.AdminUser.Id,
  190. Status: 1,
  191. PTemplateId: src_template.ID,
  192. MedType: med_type,
  193. }
  194. service.CreateHisPrescriptionInfoTemplate(prescription)
  195. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  196. advices := items["advices"].([]interface{})
  197. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  198. groupNo := int64(0)
  199. ctime := time.Now().Unix()
  200. mtime := ctime
  201. if len(advices) > 0 {
  202. for _, advice := range advices {
  203. var s models.HisPrescriptionAdviceTemplate
  204. s.PrescriptionId = prescription.ID
  205. s.AdviceType = 2
  206. s.StopState = 2
  207. s.ExecutionState = 2
  208. s.Status = 1
  209. s.UserOrgId = adminInfo.CurrentOrgId
  210. s.Groupno = groupNo
  211. s.CreatedTime = ctime
  212. s.UpdatedTime = mtime
  213. s.PatientId = patient_id
  214. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  215. if errcode > 0 {
  216. c.ServeFailJSONWithSGJErrorCode(errcode)
  217. return
  218. }
  219. service.CreateHisPrescriptionAdviceTemplate(&s)
  220. }
  221. }
  222. }
  223. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  224. projects := items["project"].([]interface{})
  225. if len(projects) > 0 {
  226. for _, project := range projects {
  227. var p models.HisPrescriptionProjectTemplate
  228. p.PrescriptionId = prescription.ID
  229. p.Ctime = time.Now().Unix()
  230. p.Mtime = time.Now().Unix()
  231. p.PatientId = patient_id
  232. p.UserOrgId = adminInfo.CurrentOrgId
  233. p.Status = 1
  234. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  235. if errcode > 0 {
  236. c.ServeFailJSONWithSGJErrorCode(errcode)
  237. return
  238. }
  239. service.CreateHisPrescriptionProjectTemplate(&p)
  240. }
  241. }
  242. }
  243. }
  244. c.ServeSuccessJSON(map[string]interface{}{
  245. "msg": "创建成功",
  246. })
  247. }
  248. }
  249. }
  250. func (c *HisConfigApiController) DeletePrescriptionTemplate() {
  251. id, _ := c.GetInt64("id")
  252. err := service.DelelteHisPrescriptionTemplate(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) DeletePrescriptionInfoTemplate() {
  264. prescription_id, _ := c.GetInt64("id")
  265. err := service.DelelteHisPrescriptionInfoTemplate(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  266. if err == nil {
  267. c.ServeSuccessJSON(map[string]interface{}{
  268. "msg": "删除成功",
  269. })
  270. return
  271. } else {
  272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  273. return
  274. }
  275. }
  276. func (c *HisConfigApiController) DeleteAdviceTemplate() {
  277. id, _ := c.GetInt64("id")
  278. err := service.DelelteHisPrescriptionAdviceTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  279. if err == nil {
  280. c.ServeSuccessJSON(map[string]interface{}{
  281. "msg": "删除成功",
  282. })
  283. return
  284. } else {
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  286. return
  287. }
  288. }
  289. func (c *HisConfigApiController) DeleteProjectTemplate() {
  290. id, _ := c.GetInt64("id")
  291. err := service.DelelteHisPrescriptionProjectTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  292. if err == nil {
  293. c.ServeSuccessJSON(map[string]interface{}{
  294. "msg": "删除成功",
  295. })
  296. return
  297. } else {
  298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  299. return
  300. }
  301. }
  302. func (c *HisConfigApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  303. if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
  304. advice_id := int64(json["advice_id"].(float64))
  305. advice.ID = advice_id
  306. }
  307. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  308. utils.ErrorLog("drug_name")
  309. return enums.ErrorCodeParamWrong
  310. }
  311. adviceName, _ := json["drug_name"].(string)
  312. if len(adviceName) == 0 {
  313. utils.ErrorLog("len(advice_name) == 0")
  314. return enums.ErrorCodeParamWrong
  315. }
  316. advice.AdviceName = adviceName
  317. adviceDesc, _ := json["advice_desc"].(string)
  318. advice.AdviceDesc = adviceDesc
  319. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  320. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  321. advice.DrugSpec = drugSpec
  322. }
  323. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  324. remark, _ := json["remark"].(string)
  325. advice.Remark = remark
  326. }
  327. if json["id"] == nil {
  328. advice.DrugId = 0
  329. } else {
  330. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  331. drug_id := int64(json["id"].(float64))
  332. advice.DrugId = drug_id
  333. }
  334. }
  335. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  336. drugSpecUnit, _ := json["min_unit"].(string)
  337. advice.DrugSpecUnit = drugSpecUnit
  338. }
  339. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  340. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  341. advice.SingleDose = singleDose
  342. }
  343. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  344. singleDoseUnit, _ := json["single_dose_unit"].(string)
  345. advice.SingleDoseUnit = singleDoseUnit
  346. }
  347. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  348. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  349. advice.PrescribingNumber = prescribingNumber
  350. }
  351. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  352. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  353. advice.PrescribingNumberUnit = prescribingNumberUnit
  354. }
  355. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  356. deliveryWay, _ := json["delivery_way"].(string)
  357. advice.DeliveryWay = deliveryWay
  358. }
  359. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  360. executionFrequency, _ := json["execution_frequency"].(string)
  361. advice.ExecutionFrequency = executionFrequency
  362. }
  363. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  364. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  365. advice.Price = price
  366. }
  367. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  368. med_list_codg, _ := json["medical_insurance_number"].(string)
  369. advice.MedListCodg = med_list_codg
  370. }
  371. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  372. day := int64(json["day"].(float64))
  373. advice.Day = day
  374. }
  375. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  376. groupno := int64(json["groupno"].(float64))
  377. advice.Groupno = groupno
  378. }
  379. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  380. frequency_type := int64(json["frequency_type"].(float64))
  381. advice.FrequencyType = frequency_type
  382. }
  383. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  384. day_count := int64(json["day_count"].(float64))
  385. advice.DayCount = day_count
  386. }
  387. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  388. week_day, _ := json["week_day"].(string)
  389. advice.WeekDay = week_day
  390. }
  391. return 0
  392. }
  393. func (c *HisConfigApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  394. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  395. id := int64(json["id"].(float64))
  396. project.ID = id
  397. }
  398. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  399. frequency_type := int64(json["frequency_type"].(float64))
  400. project.FrequencyType = frequency_type
  401. }
  402. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  403. day_count := int64(json["day_count"].(float64))
  404. project.DayCount = day_count
  405. }
  406. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  407. week_day, _ := json["week_day"].(string)
  408. project.WeekDay = week_day
  409. }
  410. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  411. types := int64(json["type"].(float64))
  412. project.Type = types
  413. }
  414. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  415. project_id := int64(json["project_id"].(float64))
  416. project.ProjectId = project_id
  417. }
  418. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  419. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  420. project.Price = price
  421. }
  422. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  423. total, _ := json["total"].(string)
  424. //totals, _ := strconv.ParseInt(total, 10, 64)
  425. project.Count = total
  426. }
  427. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  428. medical_code, _ := json["medical_code"].(string)
  429. project.MedListCodg = medical_code
  430. }
  431. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  432. single_dose, _ := json["single_dose"].(string)
  433. project.SingleDose = single_dose
  434. }
  435. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  436. delivery_way, _ := json["delivery_way"].(string)
  437. project.DeliveryWay = delivery_way
  438. }
  439. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  440. execution_frequency, _ := json["execution_frequency"].(string)
  441. project.ExecutionFrequency = execution_frequency
  442. }
  443. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  444. remark, _ := json["remark"].(string)
  445. project.Remark = remark
  446. }
  447. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  448. day, _ := json["number_days"].(string)
  449. project.Day = day
  450. }
  451. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  452. unit, _ := json["unit"].(string)
  453. project.Unit = unit
  454. }
  455. return 0
  456. }
  457. func (this *HisConfigApiController) GetModeTemplateName() {
  458. mode_id, _ := this.GetInt64("mode_id")
  459. orgId := this.GetAdminUserInfo().CurrentOrgId
  460. modeTeplate, err := service.GetModeTemplateName(mode_id, orgId)
  461. if err == nil {
  462. this.ServeSuccessJSON(map[string]interface{}{
  463. "modeTeplate": modeTeplate,
  464. })
  465. return
  466. } else {
  467. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  468. return
  469. }
  470. }
  471. func (this *HisConfigApiController) GetPrescriptionTemplateDetail() {
  472. mode_id, _ := this.GetInt64("mode_id")
  473. orgId := this.GetAdminUserInfo().CurrentOrgId
  474. template, _ := service.GetModeTemplateNameDetail(mode_id, orgId)
  475. prescriptions, err := service.GetHisPrescriptionModeTemplate(template.ID, orgId)
  476. if err == nil {
  477. this.ServeSuccessJSON(map[string]interface{}{
  478. "template": template,
  479. "prescriptions": prescriptions,
  480. })
  481. return
  482. } else {
  483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  484. return
  485. }
  486. }
  487. func (c *HisConfigApiController) CreatePrescriptionModeTemplate() {
  488. id, _ := c.GetInt64("id")
  489. name := c.GetString("name")
  490. mode_id, _ := c.GetInt64("mode_id", 0)
  491. types, _ := c.GetInt64("type", 0)
  492. patient_id, _ := c.GetInt64("patient_id", 0)
  493. types = 1
  494. adminInfo := c.GetAdminUserInfo()
  495. if id == 0 {
  496. mode_template, _ := service.GetHisModePrescriptionTemplateByModeId(mode_id, patient_id, adminInfo.CurrentOrgId)
  497. if mode_template.ID > 0 {
  498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  499. return
  500. }
  501. }
  502. if id > 0 {
  503. mode_template, _ := service.GetHisModePrescriptionTemplateByModeIdTwo(mode_id, patient_id, adminInfo.CurrentOrgId, id)
  504. if mode_template.ID > 0 {
  505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorModeTemplateCodeParamWrong)
  506. return
  507. }
  508. }
  509. src_template, _ := service.GetHisModePrescriptionTemplateByID(id)
  510. if src_template.ID == 0 {
  511. template := models.HisPrescriptionModeTemplate{
  512. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  513. PatientId: patient_id,
  514. Type: types,
  515. Status: 1,
  516. Ctime: time.Now().Unix(),
  517. Mtime: time.Now().Unix(),
  518. Name: name,
  519. Mode: mode_id,
  520. }
  521. src_template = template
  522. service.CreateHisModePrescriptionTemplate(&src_template)
  523. } else {
  524. src_template.Name = name
  525. src_template.Mode = mode_id
  526. service.SaveHisModePrescriptionTemplate(&src_template)
  527. }
  528. dataBody := make(map[string]interface{}, 0)
  529. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  530. if err != nil {
  531. utils.ErrorLog(err.Error())
  532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  533. return
  534. }
  535. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  536. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  537. if len(prescriptions) > 0 {
  538. for _, item := range prescriptions {
  539. items := item.(map[string]interface{})
  540. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  541. utils.ErrorLog("id")
  542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  543. return
  544. }
  545. id := int64(items["id"].(float64))
  546. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  547. utils.ErrorLog("type")
  548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  549. return
  550. }
  551. types := int64(items["type"].(float64))
  552. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  553. utils.ErrorLog("med_type")
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  558. ctime := time.Now().Unix()
  559. prescription := &models.HisPrescriptionInfoModeTemplate{
  560. ID: id,
  561. PatientId: patient_id,
  562. UserOrgId: adminInfo.CurrentOrgId,
  563. Ctime: ctime,
  564. Mtime: ctime,
  565. Type: types,
  566. Modifier: adminInfo.AdminUser.Id,
  567. Creator: adminInfo.AdminUser.Id,
  568. Status: 1,
  569. PTemplateId: src_template.ID,
  570. MedType: med_type,
  571. }
  572. service.CreateHisModePrescriptionInfoTemplate(prescription)
  573. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  574. advices := items["advices"].([]interface{})
  575. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  576. groupNo := int64(0)
  577. ctime := time.Now().Unix()
  578. mtime := ctime
  579. if len(advices) > 0 {
  580. for _, advice := range advices {
  581. var s models.HisPrescriptionAdviceModeTemplate
  582. s.PrescriptionId = prescription.ID
  583. s.AdviceType = 2
  584. s.StopState = 2
  585. s.ExecutionState = 2
  586. s.Status = 1
  587. s.UserOrgId = adminInfo.CurrentOrgId
  588. s.Groupno = groupNo
  589. s.CreatedTime = ctime
  590. s.UpdatedTime = mtime
  591. s.PatientId = patient_id
  592. errcode := c.setAdviceModeTemplateWithJSON(&s, advice.(map[string]interface{}))
  593. if errcode > 0 {
  594. c.ServeFailJSONWithSGJErrorCode(errcode)
  595. return
  596. }
  597. service.CreateHisModePrescriptionAdviceTemplate(&s)
  598. }
  599. }
  600. }
  601. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  602. projects := items["project"].([]interface{})
  603. if len(projects) > 0 {
  604. for _, project := range projects {
  605. var p models.HisPrescriptionProjectModeTemplate
  606. p.PrescriptionId = prescription.ID
  607. p.Ctime = time.Now().Unix()
  608. p.Mtime = time.Now().Unix()
  609. p.PatientId = patient_id
  610. p.UserOrgId = adminInfo.CurrentOrgId
  611. p.Status = 1
  612. errcode := c.setProjectModeTemplateWithJSON(&p, project.(map[string]interface{}))
  613. if errcode > 0 {
  614. c.ServeFailJSONWithSGJErrorCode(errcode)
  615. return
  616. }
  617. service.CreateHisModePrescriptionProjectTemplate(&p)
  618. }
  619. }
  620. }
  621. }
  622. c.ServeSuccessJSON(map[string]interface{}{
  623. "msg": "创建成功",
  624. })
  625. }
  626. }
  627. }
  628. func (c *HisConfigApiController) GetPrescriptionModeTemplateInfo() {
  629. id, _ := c.GetInt64("id", 0)
  630. template, _ := service.GetHisModePrescriptionTemplateByID(id)
  631. prescriptions, _ := service.GetHisPrescriptionModeTemplate(template.ID, c.GetAdminUserInfo().CurrentOrgId)
  632. c.ServeSuccessJSON(map[string]interface{}{
  633. "template": template,
  634. "prescriptions": prescriptions,
  635. })
  636. }
  637. func (c *HisConfigApiController) setAdviceModeTemplateWithJSON(advice *models.HisPrescriptionAdviceModeTemplate, json map[string]interface{}) int {
  638. if json["advice_id"] != nil || reflect.TypeOf(json["advice_id"]).String() == "float64" {
  639. advice_id := int64(json["advice_id"].(float64))
  640. advice.ID = advice_id
  641. }
  642. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  643. utils.ErrorLog("drug_name")
  644. return enums.ErrorCodeParamWrong
  645. }
  646. adviceName, _ := json["drug_name"].(string)
  647. if len(adviceName) == 0 {
  648. utils.ErrorLog("len(advice_name) == 0")
  649. return enums.ErrorCodeParamWrong
  650. }
  651. advice.AdviceName = adviceName
  652. adviceDesc, _ := json["advice_desc"].(string)
  653. advice.AdviceDesc = adviceDesc
  654. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  655. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  656. advice.DrugSpec = drugSpec
  657. }
  658. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  659. remark, _ := json["remark"].(string)
  660. advice.Remark = remark
  661. }
  662. if json["id"] == nil {
  663. advice.DrugId = 0
  664. } else {
  665. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  666. drug_id := int64(json["id"].(float64))
  667. advice.DrugId = drug_id
  668. }
  669. }
  670. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  671. drugSpecUnit, _ := json["min_unit"].(string)
  672. advice.DrugSpecUnit = drugSpecUnit
  673. }
  674. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  675. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  676. advice.SingleDose = singleDose
  677. }
  678. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  679. singleDoseUnit, _ := json["single_dose_unit"].(string)
  680. advice.SingleDoseUnit = singleDoseUnit
  681. }
  682. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  683. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  684. advice.PrescribingNumber = prescribingNumber
  685. }
  686. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  687. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  688. advice.PrescribingNumberUnit = prescribingNumberUnit
  689. }
  690. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  691. deliveryWay, _ := json["delivery_way"].(string)
  692. advice.DeliveryWay = deliveryWay
  693. }
  694. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  695. executionFrequency, _ := json["execution_frequency"].(string)
  696. advice.ExecutionFrequency = executionFrequency
  697. }
  698. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  699. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  700. advice.Price = price
  701. }
  702. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  703. med_list_codg, _ := json["medical_insurance_number"].(string)
  704. advice.MedListCodg = med_list_codg
  705. }
  706. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  707. day := int64(json["day"].(float64))
  708. advice.Day = day
  709. }
  710. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  711. groupno := int64(json["groupno"].(float64))
  712. advice.Groupno = groupno
  713. }
  714. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  715. frequency_type := int64(json["frequency_type"].(float64))
  716. advice.FrequencyType = frequency_type
  717. }
  718. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  719. day_count := int64(json["day_count"].(float64))
  720. advice.DayCount = day_count
  721. }
  722. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  723. week_day, _ := json["week_day"].(string)
  724. advice.WeekDay = week_day
  725. }
  726. return 0
  727. }
  728. func (c *HisConfigApiController) setProjectModeTemplateWithJSON(project *models.HisPrescriptionProjectModeTemplate, json map[string]interface{}) int {
  729. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  730. id := int64(json["id"].(float64))
  731. project.ID = id
  732. }
  733. if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  734. frequency_type := int64(json["frequency_type"].(float64))
  735. project.FrequencyType = frequency_type
  736. }
  737. if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  738. day_count := int64(json["day_count"].(float64))
  739. project.DayCount = day_count
  740. }
  741. if json["week_day"] != nil || reflect.TypeOf(json["week_day"]).String() == "string" {
  742. week_day, _ := json["week_day"].(string)
  743. project.WeekDay = week_day
  744. }
  745. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  746. types := int64(json["type"].(float64))
  747. project.Type = types
  748. }
  749. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  750. project_id := int64(json["project_id"].(float64))
  751. project.ProjectId = project_id
  752. }
  753. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  754. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  755. project.Price = price
  756. }
  757. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  758. total, _ := json["total"].(string)
  759. //totals, _ := strconv.ParseInt(total, 10, 64)
  760. project.Count = total
  761. }
  762. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  763. medical_code, _ := json["medical_code"].(string)
  764. project.MedListCodg = medical_code
  765. }
  766. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  767. single_dose, _ := json["single_dose"].(string)
  768. project.SingleDose = single_dose
  769. }
  770. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  771. delivery_way, _ := json["delivery_way"].(string)
  772. project.DeliveryWay = delivery_way
  773. }
  774. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  775. execution_frequency, _ := json["execution_frequency"].(string)
  776. project.ExecutionFrequency = execution_frequency
  777. }
  778. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  779. remark, _ := json["remark"].(string)
  780. project.Remark = remark
  781. }
  782. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  783. day, _ := json["number_days"].(string)
  784. project.Day = day
  785. }
  786. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  787. unit, _ := json["unit"].(string)
  788. project.Unit = unit
  789. }
  790. return 0
  791. }
  792. func (c *HisConfigApiController) DeleteModePrescriptionTemplate() {
  793. id, _ := c.GetInt64("id")
  794. err := service.DelelteHisModePrescriptionTemplate(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. }
  805. func (c *HisConfigApiController) DeleteModeProjectTemplate() {
  806. id, _ := c.GetInt64("id")
  807. err := service.DelelteHisModePrescriptionProjectTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  808. if err == nil {
  809. c.ServeSuccessJSON(map[string]interface{}{
  810. "msg": "删除成功",
  811. })
  812. return
  813. } else {
  814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  815. return
  816. }
  817. }
  818. func (c *HisConfigApiController) DeleteModeAdviceTemplate() {
  819. id, _ := c.GetInt64("id")
  820. err := service.DelelteHisModePrescriptionAdviceTemplate(id, c.GetAdminUserInfo().CurrentOrgId)
  821. if err == nil {
  822. c.ServeSuccessJSON(map[string]interface{}{
  823. "msg": "删除成功",
  824. })
  825. return
  826. } else {
  827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  828. return
  829. }
  830. }
  831. func (c *HisConfigApiController) DeletePrescriptionInfoModeTemplate() {
  832. prescription_id, _ := c.GetInt64("id")
  833. err := service.DelelteHisPrescriptionInfoModeTemplate(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  834. if err == nil {
  835. c.ServeSuccessJSON(map[string]interface{}{
  836. "msg": "删除成功",
  837. })
  838. return
  839. } else {
  840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  841. return
  842. }
  843. }
  844. func (c *HisConfigApiController) GetDialysisModeName() {
  845. var err error
  846. defer func() {
  847. if rec := recover(); rec != nil {
  848. err = fmt.Errorf("程序异常:%v", rec)
  849. }
  850. if err != nil {
  851. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  852. }
  853. }()
  854. orgid := c.GetAdminUserInfo().CurrentOrgId
  855. mode, _ := c.GetInt64("mode")
  856. var list []*models.DialysisPatient
  857. list, err = service.GetDialysisModePatient(orgid, mode)
  858. if err != nil {
  859. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  860. return
  861. }
  862. c.ServeSuccessJSON(map[string]interface{}{
  863. "list": list,
  864. })
  865. return
  866. }
  867. func (c *HisConfigApiController) GetDrugsName() {
  868. var err error
  869. defer func() {
  870. if rec := recover(); rec != nil {
  871. err = fmt.Errorf("程序异常:%v", rec)
  872. }
  873. if err != nil {
  874. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  875. }
  876. }()
  877. orgid := c.GetAdminUserInfo().CurrentOrgId
  878. addtype, _ := c.GetInt("addtype")
  879. //special,_ := c.GetInt("special")
  880. //tmpBool := false
  881. //if special == IsSpecialDiseases{
  882. // tmpBool = true
  883. //}
  884. tmp := make(map[string]interface{}, 0)
  885. if addtype == AddTypeDrug {
  886. var list []*models.ReplacementDrugs
  887. list, err = service.ReplacementDrugs(orgid, true)
  888. if err != nil {
  889. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  890. return
  891. }
  892. var list2 []*models.ReplacementDrugs
  893. list2, err = service.ReplacementDrugs(orgid, false)
  894. if err != nil {
  895. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  896. return
  897. }
  898. tmp["list"] = list
  899. tmp["list2"] = list2
  900. } else if addtype == AddTypeProject {
  901. var list3 []*models.DropDownList
  902. list3, err = service.ProjectConsumables2(orgid, true)
  903. if err != nil {
  904. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  905. return
  906. }
  907. var list4 []*models.DropDownList
  908. list4, err = service.ProjectConsumables2(orgid, false)
  909. if err != nil {
  910. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  911. return
  912. }
  913. tmp["list"] = list3
  914. tmp["list2"] = list4
  915. } else {
  916. err = fmt.Errorf("类型解析错误")
  917. if err != nil {
  918. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  919. return
  920. }
  921. }
  922. c.ServeSuccessJSON(tmp)
  923. return
  924. }
  925. // 配置项
  926. func (c *HisConfigApiController) GetModeConfigs() {
  927. var err error
  928. defer func() {
  929. if rec := recover(); rec != nil {
  930. err = fmt.Errorf("程序异常:%v", rec)
  931. }
  932. if err != nil {
  933. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  934. }
  935. }()
  936. orgid := c.GetAdminUserInfo().CurrentOrgId
  937. var drugways []*models.DrugwayDic
  938. var efs []*models.ExecutionFrequencyDic
  939. var dataconfig []*models.DictDataconfig
  940. drugways, _, err = service.GetDrugWayDics(orgid)
  941. if err != nil {
  942. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  943. return
  944. }
  945. efs, _, err = service.GetExecutionFrequencyDics(orgid)
  946. if err != nil {
  947. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  948. return
  949. }
  950. dataconfig, err = service.GetDataConfig(orgid)
  951. c.ServeSuccessJSON(map[string]interface{}{
  952. "drugways": drugways,
  953. "efs": efs,
  954. "dataconfig": dataconfig, //组
  955. })
  956. return
  957. }
  958. func (c *HisConfigApiController) GetDrugsInformation() {
  959. var err error
  960. defer func() {
  961. if rec := recover(); rec != nil {
  962. err = fmt.Errorf("程序异常:%v", rec)
  963. }
  964. if err != nil {
  965. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  966. }
  967. }()
  968. orgid := c.GetAdminUserInfo().CurrentOrgId
  969. id := c.GetString("id", "")
  970. if len(id) == 0 {
  971. err = fmt.Errorf("参数错误")
  972. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  973. return
  974. }
  975. var list interface{}
  976. list, err = service.QueryFourTables(id, orgid)
  977. if err != nil {
  978. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  979. return
  980. }
  981. c.ServeSuccessJSON(map[string]interface{}{
  982. "list": list,
  983. })
  984. return
  985. }
  986. func (c *HisConfigApiController) ReplacePeopleName() {
  987. var g errgroup.Group
  988. var err error
  989. defer func() {
  990. if rec := recover(); rec != nil {
  991. err = fmt.Errorf("程序异常:%v", rec)
  992. }
  993. if err != nil {
  994. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  995. }
  996. }()
  997. orgid := c.GetAdminUserInfo().CurrentOrgId
  998. mode, _ := c.GetInt64("mode") //透析模式
  999. id := c.GetString("id", "") //药品/项目/耗材id
  1000. if id == "" {
  1001. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数错误")
  1002. return
  1003. }
  1004. var list []*models.DialysisPatient
  1005. finlist := make([]*models.DialysisPatient, 0) //筛选后的列表
  1006. list, err = service.GetDialysisModePatient(orgid, mode)
  1007. fmt.Println("list-----------------", list)
  1008. if err != nil {
  1009. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1010. return
  1011. }
  1012. for _, v := range list {
  1013. v := v
  1014. g.Go(func() error {
  1015. //判断该患者是否有使用该药品/项目/耗材
  1016. tmpid := id[:1]
  1017. bo := false
  1018. if tmpid == "p" {
  1019. pid := id[1:]
  1020. tmpisid, _ := strconv.ParseInt(pid, 10, 64)
  1021. tp := service.FindPatientXiang(orgid, v.ID, tmpisid, mode)
  1022. if tp {
  1023. bo = true
  1024. }
  1025. } else if tmpid == "i" {
  1026. pid := id[1:]
  1027. tmpisid, _ := strconv.ParseInt(pid, 10, 64)
  1028. tp := service.FindPatientXiang2(orgid, v.ID, tmpisid, mode)
  1029. if tp {
  1030. bo = true
  1031. }
  1032. } else {
  1033. pid := id
  1034. tmpisid, _ := strconv.ParseInt(pid, 10, 64)
  1035. tp := service.FindPatientDrug(orgid, v.ID, tmpisid, mode)
  1036. if tp {
  1037. bo = true
  1038. }
  1039. }
  1040. if bo {
  1041. finlist = append(finlist, v)
  1042. }
  1043. return nil
  1044. })
  1045. }
  1046. if err = g.Wait(); err != nil {
  1047. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1048. return
  1049. }
  1050. c.ServeSuccessJSON(map[string]interface{}{
  1051. "list": finlist,
  1052. })
  1053. return
  1054. }
  1055. func (c *HisConfigApiController) ReplaceConfig() {
  1056. var err error
  1057. defer func() {
  1058. if rec := recover(); rec != nil {
  1059. err = fmt.Errorf("程序异常:%v", rec)
  1060. }
  1061. if err != nil {
  1062. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1063. }
  1064. }()
  1065. orgid := c.GetAdminUserInfo().CurrentOrgId
  1066. tmp := make(map[string]interface{}, 0)
  1067. var list []*models.ReplacementDrugs
  1068. var list2 []*models.DropDownList
  1069. list, err = service.ReplacementDrugsT(orgid)
  1070. if err != nil {
  1071. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1072. return
  1073. }
  1074. tmp["list"] = list
  1075. list2, err = service.ProjectConsumables2T(orgid)
  1076. if err != nil {
  1077. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1078. return
  1079. }
  1080. tmp["list2"] = list2
  1081. c.ServeSuccessJSON(tmp)
  1082. return
  1083. }
  1084. // 批量替换——药品
  1085. func (c *HisConfigApiController) ReplaceSaveDrug() {
  1086. var g errgroup.Group
  1087. var err error
  1088. tx := service.XTWriteDB().Begin()
  1089. defer func() {
  1090. if rec := recover(); rec != nil {
  1091. err = fmt.Errorf("程序异常:%v", rec)
  1092. }
  1093. if err != nil {
  1094. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1095. tx.Rollback()
  1096. } else {
  1097. tx.Commit()
  1098. }
  1099. }()
  1100. mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
  1101. types, _ := c.GetInt64("type", 1) //1.药品 2.项目
  1102. patient_id := c.GetString("patient_id") //患者
  1103. replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
  1104. orgid := c.GetAdminUserInfo().CurrentOrgId
  1105. dataBody := make(map[string]interface{}, 0)
  1106. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1107. if err != nil {
  1108. utils.ErrorLog(err.Error())
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. t_ids := ""
  1113. if patient_id[len(patient_id)-1] == 44 {
  1114. t_ids = patient_id[:len(patient_id)-1]
  1115. } else {
  1116. t_ids = patient_id
  1117. }
  1118. tmp_id := strings.Split(t_ids, ",")
  1119. ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
  1120. drugid, _ := strconv.ParseInt(replaced, 10, 64)
  1121. for _, v := range tmp_id {
  1122. v := v
  1123. g.Go(func() error {
  1124. pp, _ := strconv.ParseInt(v, 10, 64) //患者id
  1125. var err error
  1126. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1127. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1128. if len(prescriptions) > 0 {
  1129. for _, item := range prescriptions {
  1130. items := item.(map[string]interface{})
  1131. var s models.HisPrescriptionAdviceTemplate
  1132. var tmpdrugid int64
  1133. if items["drug_name"] != nil && reflect.TypeOf(items["drug_name"]).String() == "string" {
  1134. tmpdrugid, _ = strconv.ParseInt(items["drug_name"].(string), 10, 64)
  1135. }
  1136. if items["drug_name"] != nil && reflect.TypeOf(items["drug_name"]).String() == "float64" {
  1137. tmpdrugid = int64(items["drug_name"].(float64))
  1138. }
  1139. s.AdviceName = service.FindDrugsName(tmpdrugid) //药品名称
  1140. if items["id"] == nil {
  1141. err = fmt.Errorf("缺少参数")
  1142. return err
  1143. } else {
  1144. if items["id"] != nil && reflect.TypeOf(items["id"]).String() == "string" {
  1145. tmp_drugid := items["id"].(string)
  1146. drug_id, _ := strconv.ParseInt(tmp_drugid, 10, 64)
  1147. s.DrugId = drug_id //药品id
  1148. }
  1149. if items["id"] != nil && reflect.TypeOf(items["id"]).String() == "float64" {
  1150. drug_id := int64(items["id"].(float64))
  1151. s.DrugId = drug_id
  1152. }
  1153. }
  1154. if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
  1155. remark, _ := items["remark"].(string)
  1156. s.Remark = remark //备注
  1157. }
  1158. if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
  1159. singleDose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  1160. s.SingleDose = singleDose
  1161. }
  1162. if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "float64" {
  1163. singleDose := items["single_dose"].(float64)
  1164. s.SingleDose = singleDose
  1165. }
  1166. if items["single_dose_unit"] != nil && reflect.TypeOf(items["single_dose_unit"]).String() == "string" {
  1167. singleDoseUnit, _ := items["single_dose_unit"].(string)
  1168. s.SingleDoseUnit = singleDoseUnit
  1169. }
  1170. if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
  1171. prescribingNumber, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  1172. s.PrescribingNumber = prescribingNumber
  1173. }
  1174. if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "float64" {
  1175. prescribingNumber := items["prescribing_number"].(float64)
  1176. s.PrescribingNumber = prescribingNumber
  1177. }
  1178. if items["prescribing_number_unit"] != nil && reflect.TypeOf(items["prescribing_number_unit"]).String() == "string" {
  1179. prescribingNumberUnit, _ := items["prescribing_number_unit"].(string)
  1180. s.PrescribingNumberUnit = prescribingNumberUnit
  1181. }
  1182. if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
  1183. deliveryWay, _ := items["delivery_way"].(string)
  1184. s.DeliveryWay = deliveryWay
  1185. }
  1186. if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
  1187. executionFrequency, _ := items["execution_frequency"].(string)
  1188. s.ExecutionFrequency = executionFrequency
  1189. }
  1190. if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "string" {
  1191. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1192. s.Price = price
  1193. }
  1194. if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "float64" {
  1195. price := items["price"].(float64)
  1196. s.Price = price
  1197. }
  1198. if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "string" {
  1199. day, _ := strconv.ParseInt(items["day"].(string), 10, 64)
  1200. s.Day = day
  1201. }
  1202. if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "float64" {
  1203. day := int64(items["day"].(float64))
  1204. s.Day = day
  1205. }
  1206. s.FrequencyType = 1
  1207. err = service.ReplaceDrugPrescriptionTemplate(orgid, pp, drugid, ids, s, tx)
  1208. if err != nil {
  1209. return err
  1210. }
  1211. }
  1212. return nil
  1213. }
  1214. }
  1215. return err
  1216. })
  1217. }
  1218. if errs := g.Wait(); errs != nil {
  1219. err = errs
  1220. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
  1221. return
  1222. }
  1223. c.ServeSuccessJSON(map[string]interface{}{
  1224. "list": "替换成功",
  1225. })
  1226. return
  1227. }
  1228. // 批量替换项目
  1229. func (c *HisConfigApiController) ReplaceSaveProject() {
  1230. var g errgroup.Group
  1231. var err error
  1232. tx := service.XTWriteDB().Begin()
  1233. defer func() {
  1234. if rec := recover(); rec != nil {
  1235. err = fmt.Errorf("程序异常:%v", rec)
  1236. }
  1237. if err != nil {
  1238. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1239. tx.Rollback()
  1240. } else {
  1241. tx.Commit()
  1242. }
  1243. }()
  1244. mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
  1245. types, _ := c.GetInt64("type", 2) //1.药品 2.项目
  1246. patient_id := c.GetString("patient_id") //患者
  1247. replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
  1248. orgid := c.GetAdminUserInfo().CurrentOrgId
  1249. dataBody := make(map[string]interface{}, 0)
  1250. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1251. if err != nil {
  1252. utils.ErrorLog(err.Error())
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. t_ids := ""
  1257. if patient_id[len(patient_id)-1] == 44 {
  1258. t_ids = patient_id[:len(patient_id)-1]
  1259. } else {
  1260. t_ids = patient_id
  1261. }
  1262. tmp_id := strings.Split(t_ids, ",")
  1263. ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
  1264. drugid, _ := strconv.ParseInt(replaced[1:], 10, 64)
  1265. for _, v := range tmp_id {
  1266. v := v
  1267. g.Go(func() error {
  1268. pp, _ := strconv.ParseInt(v, 10, 64) //患者id
  1269. var err error
  1270. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1271. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1272. if len(prescriptions) > 0 {
  1273. for _, item := range prescriptions {
  1274. items := item.(map[string]interface{})
  1275. var s models.HisPrescriptionProjectTemplate
  1276. if items["id"] != nil {
  1277. id := items["id"].(string)
  1278. if id != "" {
  1279. tmpPid := id[1:]
  1280. project_id, _ := strconv.ParseInt(tmpPid, 10, 64)
  1281. if id[0] == 112 {
  1282. s.Type = 2
  1283. }
  1284. if id[0] == 105 {
  1285. s.Type = 3
  1286. }
  1287. s.ProjectId = project_id
  1288. } else {
  1289. s.ProjectId = int64(0)
  1290. }
  1291. }
  1292. if items["frequency_type"] != nil && reflect.TypeOf(items["frequency_type"]).String() == "string" {
  1293. tmp_drugid := items["frequency_type"].(string)
  1294. frequency_type, _ := strconv.ParseInt(tmp_drugid, 10, 64)
  1295. s.FrequencyType = frequency_type
  1296. }
  1297. if items["frequency_type"] != nil && reflect.TypeOf(items["frequency_type"]).String() == "float64" {
  1298. frequency_type := int64(items["frequency_type"].(float64))
  1299. s.FrequencyType = frequency_type
  1300. }
  1301. if items["day_count"] != nil && reflect.TypeOf(items["day_count"]).String() == "string" {
  1302. tmp_drugid := items["day_count"].(string)
  1303. day_count, _ := strconv.ParseInt(tmp_drugid, 10, 64)
  1304. s.DayCount = day_count
  1305. }
  1306. if items["day_count"] != nil && reflect.TypeOf(items["day_count"]).String() == "float64" {
  1307. day_count := int64(items["day_count"].(float64))
  1308. s.DayCount = day_count
  1309. }
  1310. if items["week_day"] != nil && reflect.TypeOf(items["week_day"]).String() == "string" {
  1311. week_day, _ := items["week_day"].(string)
  1312. s.WeekDay = week_day
  1313. }
  1314. if items["week_day"] != nil && reflect.TypeOf(items["week_day"]).String() == "float64" {
  1315. week_day := config.ToString(items["week_day"].(float64))
  1316. s.WeekDay = week_day
  1317. }
  1318. if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "string" {
  1319. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  1320. s.Price = price
  1321. }
  1322. if items["price"] != nil && reflect.TypeOf(items["price"]).String() == "float64" {
  1323. price := items["price"].(float64)
  1324. s.Price = price
  1325. }
  1326. if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
  1327. total, _ := items["prescribing_number"].(string)
  1328. //totals, _ := strconv.ParseInt(total, 10, 64)
  1329. s.Count = total
  1330. }
  1331. if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "float64" {
  1332. total := config.ToString(items["prescribing_number"].(float64))
  1333. //totals, _ := strconv.ParseInt(total, 10, 64)
  1334. s.Count = total
  1335. }
  1336. if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
  1337. single_dose, _ := items["single_dose"].(string)
  1338. s.SingleDose = single_dose
  1339. }
  1340. if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "float64" {
  1341. single_dose := config.ToString(items["single_dose"].(float64))
  1342. s.SingleDose = single_dose
  1343. }
  1344. if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
  1345. delivery_way, _ := items["delivery_way"].(string)
  1346. s.DeliveryWay = delivery_way
  1347. }
  1348. if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
  1349. execution_frequency, _ := items["execution_frequency"].(string)
  1350. s.ExecutionFrequency = execution_frequency
  1351. }
  1352. if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
  1353. remark, _ := items["remark"].(string)
  1354. s.Remark = remark
  1355. }
  1356. if items["day"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
  1357. day, _ := items["number_days"].(string)
  1358. s.Day = day
  1359. }
  1360. if items["day"] != nil && reflect.TypeOf(items["remark"]).String() == "float64" {
  1361. day := config.ToString(items["number_days"].(float64))
  1362. s.Day = day
  1363. }
  1364. if items["unit"] != nil && reflect.TypeOf(items["unit"]).String() == "string" {
  1365. unit, _ := items["unit"].(string)
  1366. s.Unit = unit
  1367. }
  1368. err = service.ReplaceProjectPrescriptionTemplate(orgid, pp, drugid, ids, s, tx)
  1369. if err != nil {
  1370. return err
  1371. }
  1372. }
  1373. return nil
  1374. }
  1375. }
  1376. return err
  1377. })
  1378. }
  1379. if errs := g.Wait(); errs != nil {
  1380. err = errs
  1381. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
  1382. return
  1383. }
  1384. c.ServeSuccessJSON(map[string]interface{}{
  1385. "list": "替换成功",
  1386. })
  1387. return
  1388. }
  1389. // 批量删除项目
  1390. func (c *HisConfigApiController) BatchDeleteItems() {
  1391. var g errgroup.Group
  1392. var err error
  1393. tx := service.XTWriteDB().Begin()
  1394. defer func() {
  1395. if rec := recover(); rec != nil {
  1396. err = fmt.Errorf("程序异常:%v", rec)
  1397. }
  1398. if err != nil {
  1399. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1400. tx.Rollback()
  1401. } else {
  1402. tx.Commit()
  1403. }
  1404. }()
  1405. mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
  1406. types, _ := c.GetInt64("type", 2) //1.药品 2.项目
  1407. patient_id := c.GetString("patient_id") //患者
  1408. replaced := c.GetString("replaced", "") //被删除的药品、项目、耗材id
  1409. orgid := c.GetAdminUserInfo().CurrentOrgId
  1410. t_ids := ""
  1411. if patient_id[len(patient_id)-1] == 44 {
  1412. t_ids = patient_id[:len(patient_id)-1]
  1413. } else {
  1414. t_ids = patient_id
  1415. }
  1416. tmp_id := strings.Split(t_ids, ",")
  1417. ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
  1418. drugid, _ := strconv.ParseInt(replaced[1:], 10, 64)
  1419. for _, v := range tmp_id {
  1420. v := v
  1421. g.Go(func() error {
  1422. pp, _ := strconv.ParseInt(v, 10, 64) //患者id
  1423. var err error
  1424. err = service.DeleteProjectTemplate(orgid, pp, drugid, ids, tx)
  1425. return err
  1426. })
  1427. }
  1428. if errs := g.Wait(); errs != nil {
  1429. err = errs
  1430. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
  1431. return
  1432. }
  1433. c.ServeSuccessJSON(map[string]interface{}{
  1434. "list": "删除成功",
  1435. })
  1436. return
  1437. }
  1438. // 批量删除药品
  1439. func (c *HisConfigApiController) DeleteDrugsBatch() {
  1440. var g errgroup.Group
  1441. var err error
  1442. tx := service.XTWriteDB().Begin()
  1443. defer func() {
  1444. if rec := recover(); rec != nil {
  1445. err = fmt.Errorf("程序异常:%v", rec)
  1446. }
  1447. if err != nil {
  1448. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1449. tx.Rollback()
  1450. } else {
  1451. tx.Commit()
  1452. }
  1453. }()
  1454. mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
  1455. types, _ := c.GetInt64("type", 1) //1.药品 2.项目
  1456. patient_id := c.GetString("patient_id") //患者
  1457. replaced := c.GetString("replaced", "") //被替换的药品、项目、耗材id
  1458. orgid := c.GetAdminUserInfo().CurrentOrgId
  1459. t_ids := ""
  1460. if patient_id[len(patient_id)-1] == 44 {
  1461. t_ids = patient_id[:len(patient_id)-1]
  1462. } else {
  1463. t_ids = patient_id
  1464. }
  1465. tmp_id := strings.Split(t_ids, ",")
  1466. ids := service.GetHisInfoTempalteId(mode_id, orgid, types) //获取所有药品模板id
  1467. drugid, _ := strconv.ParseInt(replaced, 10, 64)
  1468. for _, v := range tmp_id {
  1469. v := v
  1470. g.Go(func() error {
  1471. pp, _ := strconv.ParseInt(v, 10, 64) //患者id
  1472. var err error
  1473. err = service.DeletePrescriptionTemplate(orgid, pp, drugid, ids, tx)
  1474. return err
  1475. })
  1476. }
  1477. if errs := g.Wait(); errs != nil {
  1478. err = errs
  1479. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
  1480. return
  1481. }
  1482. c.ServeSuccessJSON(map[string]interface{}{
  1483. "list": "删除成功",
  1484. })
  1485. return
  1486. }
  1487. // 批量添加
  1488. func (c *HisConfigApiController) AddsTemplate() {
  1489. var g errgroup.Group
  1490. var err error
  1491. defer func() {
  1492. if rec := recover(); rec != nil {
  1493. err = fmt.Errorf("程序异常:%v", rec)
  1494. }
  1495. if err != nil {
  1496. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1497. }
  1498. }()
  1499. //id, _ := c.GetInt64("id")
  1500. name := c.GetString("name", "")
  1501. mode_id, _ := c.GetInt64("mode_id", 0)
  1502. types, _ := c.GetInt64("type", 1) //没啥用
  1503. patient_id := c.GetString("patient_id")
  1504. //patient_id, _ := c.GetInt64("patient_id", 0)
  1505. if name == "" {
  1506. name = service.DialysisModeName(mode_id)
  1507. }
  1508. adminInfo := c.GetAdminUserInfo()
  1509. dataBody := make(map[string]interface{}, 0)
  1510. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1511. if err != nil {
  1512. utils.ErrorLog(err.Error())
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1514. return
  1515. }
  1516. t_ids := ""
  1517. if patient_id[len(patient_id)-1] == 44 {
  1518. t_ids = patient_id[:len(patient_id)-1]
  1519. } else {
  1520. t_ids = patient_id
  1521. }
  1522. tmp_id := strings.Split(t_ids, ",")
  1523. for _, v := range tmp_id {
  1524. v := v
  1525. g.Go(func() error {
  1526. var err error
  1527. pa, _ := strconv.ParseInt(v, 10, 64)
  1528. tmp_bool_id := service.IsDialysisMode(adminInfo.CurrentOrgId, pa, mode_id)
  1529. var src_template models.HisPrescriptionTemplate
  1530. if !tmp_bool_id {
  1531. template := models.HisPrescriptionTemplate{
  1532. UserOrgId: adminInfo.CurrentOrgId,
  1533. PatientId: pa,
  1534. Type: types,
  1535. Status: 1,
  1536. Ctime: time.Now().Unix(),
  1537. Mtime: time.Now().Unix(),
  1538. Name: name,
  1539. Mode: mode_id,
  1540. }
  1541. src_template = template
  1542. service.CreateHisPrescriptionTemplate(&src_template)
  1543. } else {
  1544. //查询出该模板的id
  1545. src_template, err = service.IdOfTheTemplate(adminInfo.CurrentOrgId, pa, mode_id)
  1546. if err != nil {
  1547. return err
  1548. }
  1549. src_template.Name = name
  1550. src_template.Mode = mode_id
  1551. service.SaveHisPrescriptionTemplate(&src_template)
  1552. }
  1553. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1554. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1555. if len(prescriptions) > 0 {
  1556. for _, item := range prescriptions {
  1557. items := item.(map[string]interface{})
  1558. id := int64(0)
  1559. //fmt.Println("111111111111111111111")
  1560. //if items["type"] == nil {
  1561. // utils.ErrorLog("type")
  1562. // //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1563. // fmt.Println("222222222222222")
  1564. // err = fmt.Errorf("参数错误")
  1565. // return err
  1566. //}
  1567. //fmt.Println("33333333333")
  1568. //type1 := types
  1569. med_type := ""
  1570. var tmps float64
  1571. if items["patient_value"] != nil && reflect.TypeOf(items["patient_value"]).String() == "float64" {
  1572. tmps = items["patient_value"].(float64)
  1573. }
  1574. if items["patient_value"] != nil && reflect.TypeOf(items["patient_value"]).String() == "string" {
  1575. tmps, _ = strconv.ParseFloat(items["patient_value"].(string), 64)
  1576. }
  1577. if tmps == 1 {
  1578. med_type = "11"
  1579. } else if tmps == 2 {
  1580. med_type = "14"
  1581. } else {
  1582. err = fmt.Errorf("医疗类型参数错误")
  1583. }
  1584. ctime := time.Now().Unix()
  1585. prescription := &models.HisPrescriptionInfoTemplate{
  1586. ID: id,
  1587. PatientId: pa,
  1588. UserOrgId: adminInfo.CurrentOrgId,
  1589. Ctime: ctime,
  1590. Mtime: ctime,
  1591. Type: types,
  1592. Modifier: adminInfo.AdminUser.Id,
  1593. Creator: adminInfo.AdminUser.Id,
  1594. Status: 1,
  1595. PTemplateId: src_template.ID,
  1596. MedType: med_type,
  1597. }
  1598. service.CreateHisPrescriptionInfoTemplate(prescription)
  1599. if items["tableDatas"] != nil && reflect.TypeOf(items["tableDatas"]).String() == "[]interface {}" {
  1600. advices := items["tableDatas"].([]interface{})
  1601. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1602. groupNo := int64(0)
  1603. ctime := time.Now().Unix()
  1604. mtime := ctime
  1605. if len(advices) > 0 {
  1606. for k, advice := range advices {
  1607. var s models.HisPrescriptionAdviceTemplate
  1608. s.PrescriptionId = prescription.ID
  1609. s.AdviceType = 2
  1610. s.StopState = 2
  1611. s.ExecutionState = 2
  1612. s.Status = 1
  1613. s.UserOrgId = adminInfo.CurrentOrgId
  1614. s.Groupno = groupNo
  1615. s.CreatedTime = ctime
  1616. s.UpdatedTime = mtime
  1617. s.PatientId = pa
  1618. errcode := service.FensetAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  1619. if errcode > 0 {
  1620. //c.ServeFailJSONWithSGJErrorCode(errcode)
  1621. err = fmt.Errorf("参数错误")
  1622. return err
  1623. }
  1624. if s.FrequencyType == 0 {
  1625. s.FrequencyType = 1
  1626. }
  1627. s.Groupno = int64(k + 1) //序号
  1628. if s.DrugId != 0 {
  1629. service.CreateHisPrescriptionAdviceTemplate(&s)
  1630. }
  1631. }
  1632. }
  1633. }
  1634. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1635. projects := items["project"].([]interface{})
  1636. if len(projects) > 0 {
  1637. for _, project := range projects {
  1638. var p models.HisPrescriptionProjectTemplate
  1639. p.PrescriptionId = prescription.ID
  1640. p.Ctime = time.Now().Unix()
  1641. p.Mtime = time.Now().Unix()
  1642. p.PatientId = pa
  1643. p.UserOrgId = adminInfo.CurrentOrgId
  1644. p.Status = 1
  1645. errcode := service.FensetProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  1646. if errcode > 0 {
  1647. //c.ServeFailJSONWithSGJErrorCode(errcode)
  1648. err = fmt.Errorf("参数错误")
  1649. return err
  1650. }
  1651. if p.FrequencyType == 0 {
  1652. p.FrequencyType = 1
  1653. }
  1654. if p.ProjectId != 0 {
  1655. service.CreateHisPrescriptionProjectTemplate(&p)
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. return nil
  1662. }
  1663. }
  1664. return err
  1665. })
  1666. }
  1667. if errs := g.Wait(); errs != nil {
  1668. err = errs
  1669. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
  1670. return
  1671. }
  1672. c.ServeSuccessJSON(map[string]interface{}{
  1673. "list": "创建成功",
  1674. })
  1675. return
  1676. }
  1677. // 根据透析模式和患者id获取该患者的处方内容
  1678. func (c *HisConfigApiController) PTemplateInformation() {
  1679. var err error
  1680. defer func() {
  1681. if rec := recover(); rec != nil {
  1682. err = fmt.Errorf("程序异常:%v", rec)
  1683. }
  1684. if err != nil {
  1685. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1686. }
  1687. }()
  1688. orgid := c.GetAdminUserInfo().CurrentOrgId
  1689. mode_id, _ := c.GetInt64("mode_id", 0) //透析模式
  1690. patient_id, _ := c.GetInt64("patient_id") //患者
  1691. list, err := service.PTemplateInformation(orgid, mode_id, patient_id)
  1692. if err != nil {
  1693. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1694. return
  1695. }
  1696. c.ServeSuccessJSON(map[string]interface{}{
  1697. "list": list,
  1698. })
  1699. return
  1700. }
  1701. // 删除单条记录
  1702. func (c *HisConfigApiController) DeleteOne() {
  1703. var err error
  1704. defer func() {
  1705. if rec := recover(); rec != nil {
  1706. err = fmt.Errorf("程序异常:%v", rec)
  1707. }
  1708. if err != nil {
  1709. service.SaveErrs(c.GetAdminUserInfo().CurrentOrgId, c.Ctx.Input, err)
  1710. }
  1711. }()
  1712. orgid := c.GetAdminUserInfo().CurrentOrgId
  1713. types, _ := c.GetInt64("type") //透析模式
  1714. id, _ := c.GetInt64("id") //患者
  1715. err = service.DeleteOne(types, id)
  1716. if err != nil {
  1717. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1718. return
  1719. }
  1720. err = service.Scavenger(orgid)
  1721. if err != nil {
  1722. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
  1723. return
  1724. }
  1725. c.ServeSuccessJSON(map[string]interface{}{
  1726. "list": "成功",
  1727. })
  1728. return
  1729. }