his_config_api_controller.go 61KB

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