his_config_api_controller.go 61KB

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