his_config_api_controller.go 60KB

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