his_config_api_controller.go 61KB

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