new_dialysis_api_controller.go 70KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374
  1. package new_mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "crypto/md5"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. type NewDialysisApiController struct {
  17. NewMobileBaseAPIAuthController
  18. }
  19. func (this *NewDialysisApiController) GetIllnesslist() {
  20. illnesslist, err := service.GetIllnessListTwo()
  21. if err != nil {
  22. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  23. return
  24. }
  25. this.ServeSuccessJSON(map[string]interface{}{
  26. "illnesslist": illnesslist,
  27. })
  28. }
  29. func (this *NewDialysisApiController) GetPatient() {
  30. adminInfo := this.GetMobileAdminUserInfo()
  31. orgid := adminInfo.Org.Id
  32. page, _ := this.GetInt64("page")
  33. limit, _ := this.GetInt64("limit")
  34. patient, total, err := service.GetBloodDialysisPatient(orgid, page, limit)
  35. if err != nil {
  36. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  37. return
  38. }
  39. this.ServeSuccessJSON(map[string]interface{}{
  40. "patient": patient,
  41. "total": total,
  42. })
  43. }
  44. func (this *NewDialysisApiController) GetAllPatient() {
  45. adminInfo := this.GetMobileAdminUserInfo()
  46. orgid := adminInfo.Org.Id
  47. page, _ := this.GetInt64("page")
  48. fmt.Print("page", page)
  49. limit, _ := this.GetInt64("limit")
  50. fmt.Print("limit", limit)
  51. patient, err := service.GetAllPatient(orgid)
  52. if err != nil {
  53. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  54. return
  55. }
  56. this.ServeSuccessJSON(map[string]interface{}{
  57. "patient": patient,
  58. })
  59. }
  60. func (this *NewDialysisApiController) GetGeneratedialysisno() {
  61. adminInfo := this.GetMobileAdminUserInfo()
  62. orgid := adminInfo.Org.Id
  63. dialysisNo := service.ChechLastDialysisNoTwo(orgid)
  64. //fmt.Print("机构ID",adminUserInfo.CurrentOrgId)
  65. if dialysisNo == 0 {
  66. dialysisNo = 1
  67. } else {
  68. dialysisNo++
  69. }
  70. no := strconv.FormatInt(dialysisNo, 10)
  71. rep := 3 - len(no)
  72. if rep > 0 {
  73. no = strings.Repeat("0", rep) + no
  74. }
  75. this.ServeSuccessJSON(map[string]interface{}{
  76. "no": no,
  77. })
  78. return
  79. }
  80. func (this *NewDialysisApiController) GetBloodPatientInfo() {
  81. adminInfo := this.GetMobileAdminUserInfo()
  82. orgId := adminInfo.Org.Id
  83. fmt.Print("机构ID", orgId)
  84. phone := this.GetString("phone")
  85. _, errcode := service.GetBloodPatientInfo(orgId, phone)
  86. fmt.Print("errcode", errcode)
  87. if errcode == gorm.ErrRecordNotFound {
  88. returnData := make(map[string]interface{}, 0)
  89. returnData["msg"] = "ok"
  90. this.ServeSuccessJSON(returnData)
  91. return
  92. } else if errcode == nil {
  93. return
  94. } else {
  95. }
  96. }
  97. func (this *NewDialysisApiController) GetSlowPatientInfo() {
  98. adminInfo := this.GetMobileAdminUserInfo()
  99. orgId := adminInfo.Org.Id
  100. fmt.Print("机构ID", orgId)
  101. phone := this.GetString("phone")
  102. fmt.Print("phone", phone)
  103. _, errcode := service.GetSlowPatientInfo(orgId, phone)
  104. fmt.Print("errcode", errcode)
  105. if errcode == gorm.ErrRecordNotFound {
  106. returnData := make(map[string]interface{}, 0)
  107. returnData["msg"] = "ok"
  108. this.ServeSuccessJSON(returnData)
  109. return
  110. } else if errcode == nil {
  111. return
  112. } else {
  113. }
  114. }
  115. func (this *NewDialysisApiController) GetMemberpatientInfo() {
  116. adminInfo := this.GetMobileAdminUserInfo()
  117. orgId := adminInfo.Org.Id
  118. fmt.Print("机构ID", orgId)
  119. phone := this.GetString("phone")
  120. fmt.Print("phone", phone)
  121. _, errcode := service.GetMemberPatientInfo(orgId, phone)
  122. fmt.Print("errcode", errcode)
  123. if errcode == gorm.ErrRecordNotFound {
  124. returnData := make(map[string]interface{}, 0)
  125. returnData["msg"] = "ok"
  126. this.ServeSuccessJSON(returnData)
  127. return
  128. } else if errcode == nil {
  129. return
  130. } else {
  131. }
  132. }
  133. func (this *NewDialysisApiController) SavePatient() {
  134. adminInfo := this.GetMobileAdminUserInfo()
  135. orgid := adminInfo.Org.Id
  136. dataBody := make(map[string]interface{}, 0)
  137. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  138. fmt.Print("err", err)
  139. name := dataBody["name"].(string)
  140. fmt.Println("姓名", name)
  141. sex := int64(dataBody["sex"].(float64))
  142. fmt.Print("性别", sex)
  143. idCard := dataBody["idCard"].(string)
  144. fmt.Print("身份证", idCard)
  145. birthday := dataBody["birthday"].(string)
  146. births := strings.Split(birthday, "-")
  147. fmt.Print("生日", birthday)
  148. birYear, _ := strconv.Atoi(births[0])
  149. age := time.Now().Year() - birYear
  150. ages := int64(age)
  151. fmt.Println("age是多少", ages)
  152. timeLayout := "2006-01-02 15:04:05"
  153. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  154. birth := theTime.Unix()
  155. fmt.Print(birth)
  156. phone := dataBody["phone"].(string)
  157. fmt.Print("电话号码", phone)
  158. patientType := dataBody["result"].([]interface{})
  159. fmt.Print("患者标签", patientType)
  160. dialysis := dataBody["dialysis"].(string)
  161. fmt.Print("透析号", dialysis)
  162. patientsoure := int64(dataBody["patientsoure"].(float64))
  163. fmt.Print("患者来源", patientsoure)
  164. lapseto := int64(dataBody["lapseto"].(float64))
  165. fmt.Print("留置状态", lapseto)
  166. contagions := dataBody["resultTwo"].([]interface{})
  167. fmt.Print("传染病", contagions)
  168. ids := make([]int64, 0)
  169. for _, contagion := range contagions {
  170. id, _ := strconv.ParseInt(contagion.(string), 10, 64)
  171. ids = append(ids, id)
  172. }
  173. fmt.Print("传染病2", contagions)
  174. is_infectious := int64(dataBody["is_infectious"].(float64))
  175. fmt.Print("传染病", is_infectious)
  176. adminssionNumber := dataBody["admissionNumber"].(string)
  177. fmt.Print("住院号", adminssionNumber)
  178. fistdate := dataBody["fistDate"].(string)
  179. fmt.Print("首次透析日期", fistdate)
  180. timeLayouts := "2006-01-02"
  181. loc, _ := time.LoadLocation("Local")
  182. times, err := time.ParseInLocation(timeLayouts+" 15:04:05", fistdate+" 00:00:00", loc)
  183. //times, err := utils.ParseTimeStringToTime(timeLayout, fistdate+"00:00:00")
  184. fisttime := times.Unix()
  185. fmt.Print(fisttime)
  186. diagonse := dataBody["diagnose"].(string)
  187. fmt.Print("诊断", diagonse)
  188. avatar := dataBody["avatar"].(string)
  189. fmt.Print("头像", avatar)
  190. //慢性病
  191. requipmentId := dataBody["requipmentId"].(string)
  192. fmt.Print("设备ID", requipmentId)
  193. slowContagions := dataBody["resultThree"].([]interface{})
  194. fmt.Print("慢性传染病", slowContagions)
  195. idss := make([]int64, 0)
  196. for _, contagion := range slowContagions {
  197. id, _ := strconv.ParseInt(contagion.(string), 10, 64)
  198. idss = append(ids, id)
  199. }
  200. slowDiseases := dataBody["resultFour"].([]interface{})
  201. idsss := make([]int64, 0)
  202. for _, contagion := range slowDiseases {
  203. id, _ := strconv.ParseInt(contagion.(string), 10, 64)
  204. idsss = append(ids, id)
  205. }
  206. fmt.Print("慢性病", slowDiseases)
  207. bloodPatient := int64(dataBody["bloodPatient"].(float64))
  208. fmt.Print("血透病人", bloodPatient)
  209. slowpatient := int64(dataBody["slowPatient"].(float64))
  210. fmt.Print("慢病病人", slowpatient)
  211. memberpatient := int64(dataBody["memberPatient"].(float64))
  212. fmt.Print("会员病人", memberpatient)
  213. //会员
  214. memberFistDate := dataBody["memberFistDate"].(string)
  215. fmt.Print("首次透析日期", memberFistDate)
  216. //membertimes, err := utils.ParseTimeStringToTime(timeLayout, memberFistDate+"00:00:00")
  217. membertimes, _ := time.ParseInLocation(timeLayouts+" 15:04:05", memberFistDate+" 00:00:00", loc)
  218. memtime := membertimes.Unix()
  219. fmt.Print("会员透析日期", memtime)
  220. patient_type := int64(dataBody["patientType"].(float64))
  221. fmt.Print("病种", patient_type)
  222. treatmentmethod := int64(dataBody["treatmentMethod"].(float64))
  223. fmt.Print("治疗方式", treatmentmethod)
  224. //查询身份证号码是否存在
  225. thisPatientOne, _ := service.FindPatientByIdCardNoFive(orgid, idCard)
  226. if thisPatientOne.ID > 0 {
  227. returnData := make(map[string]interface{}, 0)
  228. returnData["msg"] = "身份证号码已存在"
  229. this.ServeSuccessJSON(returnData)
  230. return
  231. }
  232. //查询手机号码是否存在
  233. thisPatient, err := service.FindPatientByMobileFive(phone, orgid)
  234. if thisPatient.ID > 0 {
  235. returnData := make(map[string]interface{}, 0)
  236. returnData["msg"] = "手机号码已存在"
  237. this.ServeSuccessJSON(returnData)
  238. return
  239. }
  240. //如果是血透病人
  241. if bloodPatient == 1 {
  242. //查询透析号是否存在
  243. thisPatientTwo, _ := service.FindPatientByDialysisNoFive(orgid, dialysis)
  244. if thisPatientTwo.ID > 0 {
  245. returnData := make(map[string]interface{}, 0)
  246. returnData["msg"] = "透析号已存在"
  247. this.ServeSuccessJSON(returnData)
  248. return
  249. }
  250. patients := models.Patients{
  251. Name: name,
  252. Gender: sex,
  253. Birthday: birth,
  254. Age: ages,
  255. Phone: phone,
  256. Lapseto: lapseto,
  257. AdmissionNumber: adminssionNumber,
  258. FirstDialysisDate: fisttime,
  259. Diagnose: diagonse,
  260. Source: patientsoure,
  261. DialysisNo: dialysis,
  262. UserOrgId: orgid,
  263. Status: 1,
  264. CreatedTime: time.Now().Unix(),
  265. Avatar: avatar,
  266. IdCardNo: idCard,
  267. IsInfectious: is_infectious,
  268. }
  269. err = service.CreateOldPatient(&patients)
  270. fmt.Print("报错", err)
  271. patient, err := service.GetLastOldPatient(orgid)
  272. fmt.Print("病人ID", patient.ID)
  273. err = service.AddContagions(patient.ID, patient.CreatedTime, patient.UpdatedTime, ids)
  274. fmt.Println("添加传染病失败", err)
  275. patientsNew := models.XtPatientsNew{
  276. Name: name,
  277. Gender: sex,
  278. Birthday: birth,
  279. Age: ages,
  280. Phone: phone,
  281. Lapseto: lapseto,
  282. AdmissionNumber: adminssionNumber,
  283. FirstDialysisDate: fisttime,
  284. Diagnose: diagonse,
  285. Source: patientsoure,
  286. DialysisNo: dialysis,
  287. UserOrgId: orgid,
  288. Status: 1,
  289. CreatedTime: time.Now().Unix(),
  290. Avatar: avatar,
  291. MemberPatients: memberpatient,
  292. BloodPatients: bloodPatient,
  293. SlowPatients: slowpatient,
  294. BloodId: patient.ID,
  295. IsInfectious: is_infectious,
  296. IdCardNo: idCard,
  297. }
  298. err = service.CreateNewPatient(&patientsNew)
  299. fmt.Print("报错", err)
  300. if err != nil {
  301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  302. return
  303. }
  304. this.ServeSuccessJSON(map[string]interface{}{
  305. "patient": patientsNew,
  306. })
  307. }
  308. fmt.Print("slowpatient", slowpatient)
  309. //如果是慢病病人
  310. if slowpatient == 1 {
  311. _, errcodetwo := service.GetSlowPatientData(phone, orgid)
  312. fmt.Print("查询慢慢是吧", errcodetwo)
  313. if errcodetwo == gorm.ErrRecordNotFound {
  314. patients := models.CdmPatients{
  315. Name: name,
  316. Gender: sex,
  317. Birthday: birth,
  318. Phone: phone,
  319. Diagnose: diagonse,
  320. Source: patientsoure,
  321. UserOrgId: orgid,
  322. Status: 1,
  323. CreatedTime: time.Now().Unix(),
  324. Avatar: avatar,
  325. IdCardNo: idCard,
  326. }
  327. errcodetwo := service.CreateCdmPatient(&patients)
  328. fmt.Print("报错", errcodetwo)
  329. slowPatient, errcodetwo := service.GetOldCdmPatient(orgid)
  330. errcodetwo = service.AddSlowContagions(slowPatient.ID, slowPatient.CreatedTime, slowPatient.UpdatedTime, idss, orgid)
  331. fmt.Print("添加慢病传染病失败", errcodetwo)
  332. errcodethree := service.AddSlowDiseases(slowPatient.ID, slowPatient.CreatedTime, slowPatient.UpdatedTime, idsss, orgid)
  333. fmt.Print("添加慢性病失败", errcodethree)
  334. _, errcodefour := service.GetLastNewSlowPatient(phone, orgid)
  335. if errcodefour == gorm.ErrRecordNotFound {
  336. patientsNew := models.XtPatientsNew{
  337. Name: name,
  338. Gender: sex,
  339. Birthday: birth,
  340. Age: ages,
  341. Phone: phone,
  342. Lapseto: lapseto,
  343. AdmissionNumber: adminssionNumber,
  344. FirstDialysisDate: fisttime,
  345. Diagnose: diagonse,
  346. Source: patientsoure,
  347. DialysisNo: dialysis,
  348. UserOrgId: orgid,
  349. Status: 1,
  350. CreatedTime: time.Now().Unix(),
  351. Avatar: avatar,
  352. MemberPatients: memberpatient,
  353. BloodPatients: bloodPatient,
  354. SlowPatients: slowpatient,
  355. SlowId: slowPatient.ID,
  356. IsInfectious: is_infectious,
  357. IdCardNo: idCard,
  358. EquitmentId: requipmentId,
  359. }
  360. err = service.CreateNewPatient(&patientsNew)
  361. if err != nil {
  362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  363. return
  364. }
  365. this.ServeSuccessJSON(map[string]interface{}{
  366. "patient": patientsNew,
  367. })
  368. } else if errcodetwo == nil {
  369. fmt.Print("病人已存在")
  370. if memberpatient == 1 {
  371. fmt.Print("进来没有", memberpatient)
  372. _, errmembercode := service.GetMemberPatientInfo(orgid, phone)
  373. if errmembercode == gorm.ErrRecordNotFound {
  374. customer := models.SgjUserCustomer{
  375. Name: name,
  376. UserOrgId: orgid,
  377. Mobile: phone,
  378. Gender: sex,
  379. Birthday: birth,
  380. IllDate: memtime,
  381. Status: 1,
  382. CreatedTime: time.Now().Unix(),
  383. Avatar: avatar,
  384. IllnessId: patient_type,
  385. TreatType: treatmentmethod,
  386. }
  387. errmembercode := service.CreateMemberPatient(&customer)
  388. fmt.Print("创建会员病人失败", errmembercode)
  389. _, errmembercodetwo := service.GetMemberNewPatient(phone, orgid)
  390. fmt.Print("错误", errmembercodetwo)
  391. //获取机构的最后一条数据
  392. memberPatient, errmembercode := service.GetLastMemberPatient(orgid)
  393. if errmembercodetwo == gorm.ErrRecordNotFound {
  394. patientsNew := models.XtPatientsNew{
  395. Name: name,
  396. Gender: sex,
  397. Birthday: birth,
  398. Age: ages,
  399. Phone: phone,
  400. Lapseto: lapseto,
  401. AdmissionNumber: adminssionNumber,
  402. FirstDialysisDate: fisttime,
  403. Diagnose: diagonse,
  404. Source: patientsoure,
  405. DialysisNo: dialysis,
  406. UserOrgId: orgid,
  407. Status: 1,
  408. CreatedTime: time.Now().Unix(),
  409. Avatar: avatar,
  410. MemberPatients: memberpatient,
  411. BloodPatients: bloodPatient,
  412. SlowPatients: slowpatient,
  413. MemberId: memberPatient.ID,
  414. IsInfectious: is_infectious,
  415. IdCardNo: idCard,
  416. MemberFistdate: memtime,
  417. MemberPatienttype: patient_type,
  418. MemberTreatement: treatmentmethod,
  419. }
  420. err = service.CreateNewPatient(&patientsNew)
  421. fmt.Print("报错", err)
  422. if err != nil {
  423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  424. return
  425. }
  426. this.ServeSuccessJSON(map[string]interface{}{
  427. "patient": patientsNew,
  428. })
  429. } else if errmembercode == nil {
  430. fmt.Print("病人已存在")
  431. return
  432. } else {
  433. }
  434. } else if errmembercode == nil {
  435. fmt.Print("病人已存在")
  436. return
  437. } else {
  438. }
  439. }
  440. return
  441. } else {
  442. }
  443. } else if errcodetwo == nil {
  444. fmt.Print("病人已存在")
  445. return
  446. } else {
  447. }
  448. }
  449. if memberpatient == 1 {
  450. fmt.Print("进来没有", memberpatient)
  451. _, errmembercode := service.GetMemberPatientInfo(orgid, phone)
  452. if errmembercode == gorm.ErrRecordNotFound {
  453. customer := models.SgjUserCustomer{
  454. Name: name,
  455. UserOrgId: orgid,
  456. Mobile: phone,
  457. Gender: sex,
  458. Birthday: birth,
  459. IllDate: memtime,
  460. Status: 1,
  461. CreatedTime: time.Now().Unix(),
  462. Avatar: avatar,
  463. IllnessId: patient_type,
  464. TreatType: treatmentmethod,
  465. }
  466. errmembercode := service.CreateMemberPatient(&customer)
  467. fmt.Print("创建会员病人失败", errmembercode)
  468. _, errmembercodetwo := service.GetMemberNewPatient(phone, orgid)
  469. fmt.Print("错误", errmembercodetwo)
  470. //获取机构的最后一条数据
  471. memberPatient, errmembercode := service.GetLastMemberPatient(orgid)
  472. if errmembercodetwo == gorm.ErrRecordNotFound {
  473. patientsNew := models.XtPatientsNew{
  474. Name: name,
  475. Gender: sex,
  476. Birthday: birth,
  477. Age: ages,
  478. Phone: phone,
  479. Lapseto: lapseto,
  480. AdmissionNumber: adminssionNumber,
  481. FirstDialysisDate: fisttime,
  482. Diagnose: diagonse,
  483. Source: patientsoure,
  484. DialysisNo: dialysis,
  485. UserOrgId: orgid,
  486. Status: 1,
  487. CreatedTime: time.Now().Unix(),
  488. Avatar: avatar,
  489. MemberPatients: memberpatient,
  490. BloodPatients: bloodPatient,
  491. SlowPatients: slowpatient,
  492. MemberId: memberPatient.ID,
  493. IsInfectious: is_infectious,
  494. IdCardNo: idCard,
  495. MemberFistdate: memtime,
  496. MemberPatienttype: patient_type,
  497. MemberTreatement: treatmentmethod,
  498. }
  499. err = service.CreateNewPatient(&patientsNew)
  500. fmt.Print("报错", err)
  501. if err != nil {
  502. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  503. return
  504. }
  505. this.ServeSuccessJSON(map[string]interface{}{
  506. "patient": patientsNew,
  507. })
  508. } else if errmembercode == nil {
  509. fmt.Print("病人已存在")
  510. return
  511. } else {
  512. }
  513. } else if errmembercode == nil {
  514. fmt.Print("病人已存在")
  515. return
  516. } else {
  517. }
  518. }
  519. }
  520. func (this *NewDialysisApiController) GetPatientDetail() {
  521. id, _ := this.GetInt64("id")
  522. //获取病人详情信息
  523. detail, err := service.GetPatientDetailTwo(id)
  524. //获取传染病详情
  525. diseases := service.GetPatientDiseasesTwo(detail.BloodId)
  526. //获取慢病传染病
  527. slowDiseases, err := service.GetSlowPatientDiseases(detail.SlowId)
  528. //获取慢病慢性病
  529. cronicDiseases, err := service.GetCronicDiseases(detail.SlowId)
  530. //获取血透医嘱管理
  531. if err != nil {
  532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  533. return
  534. }
  535. this.ServeSuccessJSON(map[string]interface{}{
  536. "patientDetail": detail,
  537. "diseases": diseases,
  538. "slowDiseases": slowDiseases,
  539. "cronicDiseases": cronicDiseases,
  540. })
  541. }
  542. func (this *NewDialysisApiController) GetDoctorAdvices() {
  543. timeLayout := "2006-01-02"
  544. loc, _ := time.LoadLocation("Local")
  545. adminInfo := this.GetMobileAdminUserInfo()
  546. orgid := adminInfo.Org.Id
  547. id, _ := this.GetInt64("id")
  548. appid := adminInfo.App.Id
  549. fmt.Print("id", id)
  550. //跟据新表id获取老表id
  551. newPatientInfo, _ := service.GetPatientDetailTwo(id)
  552. //获取病人ID
  553. doctor_type, _ := this.GetInt64("type")
  554. fmt.Print("医嘱内型", doctor_type)
  555. start := this.GetString("startime")
  556. fmt.Print("start", start)
  557. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  558. startime := startTimes.Unix()
  559. fmt.Print("开始时间", startime)
  560. end := this.GetString("endtime")
  561. fmt.Print("end", end)
  562. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
  563. endtime := endTimes.Unix()
  564. fmt.Print("结束时间", endtime)
  565. limit, _ := this.GetInt64("limit")
  566. page, _ := this.GetInt64("page")
  567. fmt.Println("病人ID", newPatientInfo.BloodId)
  568. advice, _, err := service.GetNewDoctorAdvice(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
  569. one, total, err := service.GetNewDoctorAdviceOne(newPatientInfo.BloodId, doctor_type, startime, endtime, limit, page, orgid)
  570. fmt.Println("err------------------------", err)
  571. if err != nil {
  572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  573. return
  574. }
  575. doctor, err := service.GetAllDoctorTwo(orgid, appid)
  576. this.ServeSuccessJSON(map[string]interface{}{
  577. "advice": advice,
  578. "total": total,
  579. "doctor": doctor,
  580. "one": one,
  581. })
  582. }
  583. func (this *NewDialysisApiController) GetDryWeight() {
  584. timeLayout := "2006-01-02"
  585. loc, _ := time.LoadLocation("Local")
  586. id, _ := this.GetInt64("id")
  587. fmt.Print("id", id)
  588. patient, _ := service.GetPatientDetailTwo(id)
  589. start := this.GetString("startime")
  590. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  591. startime := startTimes.Unix()
  592. fmt.Print("startime", startime)
  593. end := this.GetString("endtime")
  594. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
  595. endtime := endTimes.Unix()
  596. fmt.Print("endtime", endtime)
  597. limit, _ := this.GetInt64("limit")
  598. fmt.Print("limit", limit)
  599. page, _ := this.GetInt64("page")
  600. fmt.Print("page", page)
  601. adminInfo := this.GetMobileAdminUserInfo()
  602. orgid := adminInfo.Org.Id
  603. dryweight, total, err := service.GetDryWeight(patient.BloodId, startime, endtime, limit, page, orgid)
  604. if err != nil {
  605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  606. return
  607. }
  608. this.ServeSuccessJSON(map[string]interface{}{
  609. "dryweight": dryweight,
  610. "total": total,
  611. })
  612. }
  613. func (this *NewDialysisApiController) ToSearch() {
  614. adminUser := this.GetMobileAdminUserInfo()
  615. orgId := adminUser.Org.Id
  616. name := this.GetString("name")
  617. search, err := service.ToSearch(orgId, name)
  618. if err != nil {
  619. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  620. return
  621. }
  622. this.ServeSuccessJSON(map[string]interface{}{
  623. "search": search,
  624. })
  625. }
  626. func (this *NewDialysisApiController) GetCourseManagement() {
  627. timeLayout := "2006-01-02"
  628. loc, _ := time.LoadLocation("Local")
  629. id, _ := this.GetInt64("id")
  630. fmt.Print("id", id)
  631. patient, _ := service.GetPatientDetailTwo(id)
  632. start := this.GetString("startime")
  633. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  634. startime := startTimes.Unix()
  635. fmt.Print("startime", startime)
  636. end := this.GetString("endtime")
  637. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
  638. endtime := endTimes.Unix()
  639. fmt.Print("endtime", endtime)
  640. limit, _ := this.GetInt64("limit")
  641. fmt.Print("limit", limit)
  642. page, _ := this.GetInt64("page")
  643. fmt.Print("page", page)
  644. adminInfo := this.GetMobileAdminUserInfo()
  645. orgid := adminInfo.Org.Id
  646. management, total, err := service.GetCourseManagement(patient.BloodId, startime, endtime, limit, page, orgid)
  647. if err != nil {
  648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  649. return
  650. }
  651. this.ServeSuccessJSON(map[string]interface{}{
  652. "coursemanagement": management,
  653. "total": total,
  654. })
  655. }
  656. func (this *NewDialysisApiController) DeleteCourseManagement() {
  657. id, _ := this.GetInt64("id")
  658. err := service.DeleteCouseManagement(id)
  659. fmt.Println("错误是什么", err)
  660. returnData := make(map[string]interface{}, 0)
  661. returnData["msg"] = "ok"
  662. this.ServeSuccessJSON(returnData)
  663. return
  664. }
  665. func (this *NewDialysisApiController) GetCouseManagentDetail() {
  666. id, _ := this.GetInt64("id")
  667. detail, err := service.GetCouseManagentDetail(id)
  668. if err != nil {
  669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  670. return
  671. }
  672. this.ServeSuccessJSON(map[string]interface{}{
  673. "couseDetail": detail,
  674. })
  675. }
  676. func (this *NewDialysisApiController) GetAllBloodDialysisPatient() {
  677. page, _ := this.GetInt64("page")
  678. fmt.Print("page", page)
  679. limit, _ := this.GetInt64("limit")
  680. fmt.Print("limit", limit)
  681. lapseto, _ := this.GetInt64("patientstatus")
  682. source, _ := this.GetInt64("source")
  683. adminUserInfo := this.GetMobileAdminUserInfo()
  684. orgid := adminUserInfo.Org.Id
  685. patient, total, err := service.GetAllBloodDialysisPatient(orgid, page, limit, lapseto, source)
  686. if err != nil {
  687. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  688. return
  689. }
  690. this.ServeSuccessJSON(map[string]interface{}{
  691. "bloodpatient": patient,
  692. "total": total,
  693. })
  694. }
  695. func (this *NewDialysisApiController) GetAllSlowPatent() {
  696. page, _ := this.GetInt64("page")
  697. fmt.Print("page", page)
  698. limit, _ := this.GetInt64("limit")
  699. fmt.Print("limit", limit)
  700. adminUserInfo := this.GetMobileAdminUserInfo()
  701. orgid := adminUserInfo.Org.Id
  702. patient, total, err := service.GetAllSlowPatient(orgid, page, limit)
  703. fmt.Print("err", err)
  704. if err != nil {
  705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  706. return
  707. }
  708. this.ServeSuccessJSON(map[string]interface{}{
  709. "slowpatient": patient,
  710. "total": total,
  711. })
  712. }
  713. func (this *NewDialysisApiController) GetAllMemberPatient() {
  714. page, _ := this.GetInt64("page")
  715. fmt.Print("page", page)
  716. limit, _ := this.GetInt64("limit")
  717. fmt.Print("limit", limit)
  718. adminUserInfo := this.GetMobileAdminUserInfo()
  719. orgid := adminUserInfo.Org.Id
  720. patient, total, err := service.GetAllMemberPatient(orgid, page, limit)
  721. if err != nil {
  722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  723. return
  724. }
  725. this.ServeSuccessJSON(map[string]interface{}{
  726. "memberpatient": patient,
  727. "total": total,
  728. })
  729. }
  730. func (this *NewDialysisApiController) DeleteDryWeight() {
  731. id, _ := this.GetInt64("id")
  732. err := service.DeleteDryWeight(id)
  733. fmt.Println("错误是什么", err)
  734. returnData := make(map[string]interface{}, 0)
  735. returnData["msg"] = "ok"
  736. this.ServeSuccessJSON(returnData)
  737. return
  738. }
  739. func (this *NewDialysisApiController) GetDryWeightDetail() {
  740. id, _ := this.GetInt64("id")
  741. fmt.Print("id", id)
  742. drydetail, err := service.GetDryWeightDetail(id)
  743. if err != nil {
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  745. return
  746. }
  747. this.ServeSuccessJSON(map[string]interface{}{
  748. "drydetail": drydetail,
  749. })
  750. }
  751. func (this *NewDialysisApiController) GetlongDialysisrecord() {
  752. timeLayout := "2006-01-02"
  753. loc, _ := time.LoadLocation("Local")
  754. id, _ := this.GetInt64("id")
  755. fmt.Print("id", id)
  756. patient, _ := service.GetPatientDetailTwo(id)
  757. start := this.GetString("startime")
  758. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  759. startime := startTimes.Unix()
  760. fmt.Print("startime", startime)
  761. end := this.GetString("endtime")
  762. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
  763. endtime := endTimes.Unix()
  764. fmt.Print("endtime", endtime)
  765. limit, _ := this.GetInt64("limit")
  766. fmt.Print("limit", limit)
  767. page, _ := this.GetInt64("page")
  768. fmt.Print("page", page)
  769. adminInfo := this.GetMobileAdminUserInfo()
  770. orgid := adminInfo.Org.Id
  771. dialysisrecord, total, err := service.GetlongDialysisrecord(patient.BloodId, startime, endtime, limit, page, orgid)
  772. if err != nil {
  773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  774. return
  775. }
  776. this.ServeSuccessJSON(map[string]interface{}{
  777. "dialysisrecord": dialysisrecord,
  778. "total": total,
  779. })
  780. }
  781. func (this *NewDialysisApiController) GetRescuerecord() {
  782. timeLayout := "2006-01-02"
  783. loc, _ := time.LoadLocation("Local")
  784. id, _ := this.GetInt64("id")
  785. fmt.Print("id", id)
  786. patient, _ := service.GetPatientDetailTwo(id)
  787. start := this.GetString("startime")
  788. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  789. startime := startTimes.Unix()
  790. fmt.Print("startime", startime)
  791. end := this.GetString("endtime")
  792. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 23:59:59", loc)
  793. endtime := endTimes.Unix()
  794. fmt.Print("endtime", endtime)
  795. limit, _ := this.GetInt64("limit")
  796. fmt.Print("limit", limit)
  797. page, _ := this.GetInt64("page")
  798. fmt.Print("page", page)
  799. adminInfo := this.GetMobileAdminUserInfo()
  800. orgid := adminInfo.Org.Id
  801. rescuerecord, total, err := service.GetRescuerecord(patient.BloodId, startime, endtime, limit, page, orgid)
  802. if err != nil {
  803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  804. return
  805. }
  806. this.ServeSuccessJSON(map[string]interface{}{
  807. "rescuerecord": rescuerecord,
  808. "total": total,
  809. })
  810. }
  811. func (this *NewDialysisApiController) GetScheduling() {
  812. timeLayout := "2006-01-02"
  813. loc, _ := time.LoadLocation("Local")
  814. id, _ := this.GetInt64("id")
  815. fmt.Print("id", id)
  816. patient, _ := service.GetPatientDetailTwo(id)
  817. start := this.GetString("startime")
  818. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  819. startime := startTimes.Unix()
  820. fmt.Print("startime", startime)
  821. end := this.GetString("endtime")
  822. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
  823. endtime := endTimes.Unix()
  824. fmt.Print("endtime", endtime)
  825. limit, _ := this.GetInt64("limit")
  826. fmt.Print("limit", limit)
  827. page, _ := this.GetInt64("page")
  828. fmt.Print("page", page)
  829. mode_type, _ := this.GetInt64("mode_types")
  830. fmt.Print("透析模式", mode_type)
  831. adminInfo := this.GetMobileAdminUserInfo()
  832. orgid := adminInfo.Org.Id
  833. scheduling, total, err := service.GetScheduling(patient.BloodId, startime, endtime, limit, page, orgid, mode_type)
  834. if err != nil {
  835. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  836. return
  837. }
  838. this.ServeSuccessJSON(map[string]interface{}{
  839. "scheduling": scheduling,
  840. "total": total,
  841. })
  842. }
  843. func (this *NewDialysisApiController) GetEducation() {
  844. timeLayout := "2006-01-02"
  845. loc, _ := time.LoadLocation("Local")
  846. id, _ := this.GetInt64("id")
  847. fmt.Print("id", id)
  848. patient, _ := service.GetPatientDetailTwo(id)
  849. start := this.GetString("startime")
  850. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  851. startime := startTimes.Unix()
  852. fmt.Print("startime", startime)
  853. end := this.GetString("endtime")
  854. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
  855. endtime := endTimes.Unix()
  856. fmt.Print("endtime", endtime)
  857. limit, _ := this.GetInt64("limit")
  858. fmt.Print("limit", limit)
  859. page, _ := this.GetInt64("page")
  860. fmt.Print("page", page)
  861. adminInfo := this.GetMobileAdminUserInfo()
  862. orgid := adminInfo.Org.Id
  863. education, total, err := service.GetEducation(patient.BloodId, startime, endtime, limit, page, orgid)
  864. if err != nil {
  865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  866. return
  867. }
  868. this.ServeSuccessJSON(map[string]interface{}{
  869. "education": education,
  870. "total": total,
  871. })
  872. }
  873. func (this *NewDialysisApiController) GetSchedulingDetail() {
  874. id, _ := this.GetInt64("id")
  875. detail, err := service.GetSchedulingDetail(id)
  876. patient, err := service.GetSchedulingTwo(id)
  877. fmt.Print("errr", err)
  878. if err != nil {
  879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  880. return
  881. }
  882. this.ServeSuccessJSON(map[string]interface{}{
  883. "schedulingDetail": detail,
  884. "patient": patient,
  885. })
  886. }
  887. func (this *NewDialysisApiController) DeleteScheduling() {
  888. id, _ := this.GetInt64("id")
  889. fmt.Print("id", id)
  890. err := service.DeleteScheduling(id)
  891. fmt.Println("错误是什么", err)
  892. returnData := make(map[string]interface{}, 0)
  893. returnData["msg"] = "ok"
  894. this.ServeSuccessJSON(returnData)
  895. return
  896. }
  897. func (this *NewDialysisApiController) GetEducationDetail() {
  898. id, _ := this.GetInt64("id")
  899. fmt.Print("id", id)
  900. education, err := service.GetEducationDetailOne(id)
  901. if err != nil {
  902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  903. return
  904. }
  905. this.ServeSuccessJSON(map[string]interface{}{
  906. "education": education,
  907. })
  908. }
  909. func (this *NewDialysisApiController) DeleteEducation() {
  910. id, _ := this.GetInt64("id")
  911. fmt.Print("id", id)
  912. err := service.DeleteEducation(id)
  913. fmt.Println("错误是什么", err)
  914. returnData := make(map[string]interface{}, 0)
  915. returnData["msg"] = "ok"
  916. this.ServeSuccessJSON(returnData)
  917. return
  918. }
  919. func (this *NewDialysisApiController) GetRescueRecordDetail() {
  920. id, _ := this.GetInt64("id")
  921. recordDetail, err := service.GetRescueRecordDetail(id)
  922. if err != nil {
  923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  924. return
  925. }
  926. this.ServeSuccessJSON(map[string]interface{}{
  927. "recordDetail": recordDetail,
  928. })
  929. }
  930. func (this *NewDialysisApiController) DeleteRescueRecord() {
  931. id, _ := this.GetInt64("id")
  932. err := service.DeleteRescueRecord(id)
  933. fmt.Println("错误是什么", err)
  934. returnData := make(map[string]interface{}, 0)
  935. returnData["msg"] = "ok"
  936. this.ServeSuccessJSON(returnData)
  937. return
  938. }
  939. func (this *NewDialysisApiController) ToSearchePatient() {
  940. keyword := this.GetString("keyword")
  941. fmt.Print("关键字", keyword)
  942. adminUserinfo := this.GetMobileAdminUserInfo()
  943. orgid := adminUserinfo.Org.Id
  944. fmt.Println(orgid)
  945. patient, err := service.ToSearchePatient(keyword, orgid)
  946. if err != nil {
  947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  948. return
  949. }
  950. this.ServeSuccessJSON(map[string]interface{}{
  951. "patient": patient,
  952. })
  953. }
  954. func (this *NewDialysisApiController) SearchallPatient() {
  955. keyword := this.GetString("keyword")
  956. fmt.Print("关键字", keyword)
  957. adminUser := this.GetMobileAdminUserInfo()
  958. orgid := adminUser.Org.Id
  959. patient, err := service.SearchallPatient(keyword, orgid)
  960. if err != nil {
  961. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  962. return
  963. }
  964. this.ServeSuccessJSON(map[string]interface{}{
  965. "patient": patient,
  966. })
  967. }
  968. func (this *NewDialysisApiController) GetSearchallBlood() {
  969. keyword := this.GetString("keyword")
  970. fmt.Print("关键字", keyword)
  971. adminUser := this.GetMobileAdminUserInfo()
  972. orgid := adminUser.Org.Id
  973. bloodPatient, err := service.GetSearchallBlood(keyword, orgid)
  974. if err != nil {
  975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  976. return
  977. }
  978. this.ServeSuccessJSON(map[string]interface{}{
  979. "bloodPatient": bloodPatient,
  980. })
  981. }
  982. func (this *NewDialysisApiController) GetSlowSearchePatient() {
  983. keyword := this.GetString("keyword")
  984. fmt.Print("关键字", keyword)
  985. adminUser := this.GetMobileAdminUserInfo()
  986. orgid := adminUser.Org.Id
  987. slowPatient, err := service.GetSlowSearchePatient(keyword, orgid)
  988. if err != nil {
  989. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  990. return
  991. }
  992. this.ServeSuccessJSON(map[string]interface{}{
  993. "slowPatient": slowPatient,
  994. })
  995. }
  996. func (this *NewDialysisApiController) GetMemberSearchPatent() {
  997. keyword := this.GetString("keyword")
  998. fmt.Print("关键字", keyword)
  999. adminUser := this.GetMobileAdminUserInfo()
  1000. orgid := adminUser.Org.Id
  1001. memberPatient, err := service.GetMemberSearchPatient(keyword, orgid)
  1002. if err != nil {
  1003. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1004. return
  1005. }
  1006. this.ServeSuccessJSON(map[string]interface{}{
  1007. "memberPatient": memberPatient,
  1008. })
  1009. }
  1010. func (this *NewDialysisApiController) GetLongDialysisDetail() {
  1011. id, err := this.GetInt64("id")
  1012. longDialysisDetail, err := service.GetLongDialysisDetail(id)
  1013. patient, err := service.GetPatientName(longDialysisDetail.PatientId)
  1014. if err != nil {
  1015. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1016. return
  1017. }
  1018. this.ServeSuccessJSON(map[string]interface{}{
  1019. "longDialysisDetail": longDialysisDetail,
  1020. "patient": patient,
  1021. })
  1022. }
  1023. func (this *NewDialysisApiController) DeleteLongDialysis() {
  1024. id, _ := this.GetInt64("id")
  1025. fmt.Print("id", id)
  1026. err := service.DeleteLongDialysis(id)
  1027. fmt.Println("错误是什么", err)
  1028. returnData := make(map[string]interface{}, 0)
  1029. returnData["msg"] = "ok"
  1030. this.ServeSuccessJSON(returnData)
  1031. return
  1032. }
  1033. func (this *NewDialysisApiController) GetDialysisrecord() {
  1034. timeLayout := "2006-01-02"
  1035. loc, _ := time.LoadLocation("Local")
  1036. id, _ := this.GetInt64("id")
  1037. fmt.Print("id", id)
  1038. patient, _ := service.GetPatientDetailTwo(id)
  1039. start := this.GetString("startime")
  1040. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  1041. startime := startTimes.Unix()
  1042. fmt.Print("startime", startime)
  1043. end := this.GetString("endtime")
  1044. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
  1045. endtime := endTimes.Unix()
  1046. fmt.Print("endtime", endtime)
  1047. limit, _ := this.GetInt64("limit")
  1048. fmt.Print("limit", limit)
  1049. page, _ := this.GetInt64("page")
  1050. fmt.Print("page", page)
  1051. adminInfo := this.GetMobileAdminUserInfo()
  1052. orgid := adminInfo.Org.Id
  1053. appid := adminInfo.App.Id
  1054. dislystype, _ := this.GetInt64("dislysType")
  1055. fmt.Print("透析模式", dislystype)
  1056. dialysisrecord, total, err := service.GetDialysisrecord(patient.BloodId, startime, endtime, limit, page, orgid, dislystype)
  1057. doctor, err := service.GetAllDoctorTwo(orgid, appid)
  1058. if err != nil {
  1059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1060. return
  1061. }
  1062. this.ServeSuccessJSON(map[string]interface{}{
  1063. "dialysisrecord": dialysisrecord,
  1064. "total": total,
  1065. "doctor": doctor,
  1066. })
  1067. }
  1068. func (this *NewDialysisApiController) GetDoctorAdviceDetail() {
  1069. adminUser := this.GetMobileAdminUserInfo()
  1070. orgid := adminUser.Org.Id
  1071. appid := adminUser.App.Id
  1072. id, _ := this.GetInt64("id")
  1073. bloodTwo, _ := service.GetPatientDetailTwo(id)
  1074. fmt.Println("id", bloodTwo.BloodId)
  1075. date, _ := this.GetInt64("date")
  1076. doctorAdvicedetail, err := service.GetDoctorAdviceDetail(date, bloodTwo.BloodId, orgid)
  1077. fmt.Println("err-------------------------------", err)
  1078. doctorDetail, err := service.GetAllDoctorTwo(orgid, appid)
  1079. if err != nil {
  1080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1081. return
  1082. }
  1083. this.ServeSuccessJSON(map[string]interface{}{
  1084. "doctorAdvicedetail": doctorAdvicedetail,
  1085. "doctorDetail": doctorDetail,
  1086. })
  1087. }
  1088. func (this *NewDialysisApiController) DeleteManagement() {
  1089. groupno, _ := this.GetInt64("id")
  1090. fmt.Print("id是什么", groupno)
  1091. orgId := this.GetMobileAdminUserInfo().Org.Id
  1092. fmt.Print("机构ID", orgId)
  1093. err := service.DeleteManagement(groupno, orgId)
  1094. fmt.Println("错误是什么", err)
  1095. returnData := make(map[string]interface{}, 0)
  1096. returnData["msg"] = "ok"
  1097. this.ServeSuccessJSON(returnData)
  1098. return
  1099. }
  1100. func (this *NewDialysisApiController) DeleteChild() {
  1101. id, _ := this.GetInt64("id")
  1102. err := service.DeleteChild(id)
  1103. fmt.Println("错误是什么", err)
  1104. returnData := make(map[string]interface{}, 0)
  1105. returnData["msg"] = "ok"
  1106. this.ServeSuccessJSON(returnData)
  1107. return
  1108. }
  1109. func (this *NewDialysisApiController) DeletePatient() {
  1110. id, _ := this.GetInt64("id")
  1111. err := service.DeletePatient(id)
  1112. fmt.Println("错误是什么", err)
  1113. returnData := make(map[string]interface{}, 0)
  1114. returnData["msg"] = "ok"
  1115. this.ServeSuccessJSON(returnData)
  1116. return
  1117. }
  1118. func (this *NewDialysisApiController) UpdatedPatient() {
  1119. adminInfo := this.GetMobileAdminUserInfo()
  1120. orgid := adminInfo.Org.Id
  1121. fmt.Print("机构ID", orgid)
  1122. dataBody := make(map[string]interface{}, 0)
  1123. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1124. fmt.Print("err", err)
  1125. id := int64(dataBody["id"].(float64))
  1126. fmt.Print("id", id)
  1127. name := dataBody["name"].(string)
  1128. fmt.Println("姓名", name)
  1129. sex := int64(dataBody["sex"].(float64))
  1130. fmt.Print("性别", sex)
  1131. idCard := dataBody["idCard"].(string)
  1132. fmt.Print("身份证", idCard)
  1133. birthday := dataBody["birthday"].(string)
  1134. births := strings.Split(birthday, "-")
  1135. fmt.Print("生日", birthday)
  1136. birYear, _ := strconv.Atoi(births[0])
  1137. age := time.Now().Year() - birYear
  1138. ages := int64(age)
  1139. fmt.Println("age是多少", ages)
  1140. timeLayout := "2006-01-02 15:04:05"
  1141. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  1142. birth := theTime.Unix()
  1143. fmt.Print(birth)
  1144. phone := dataBody["phone"].(string)
  1145. fmt.Print("电话号码", phone)
  1146. patientType := dataBody["result"].([]interface{})
  1147. fmt.Print("患者标签", patientType)
  1148. dialysis := dataBody["dialysis"].(string)
  1149. fmt.Print("透析号", dialysis)
  1150. patientsoure := int64(dataBody["patientsoure"].(float64))
  1151. fmt.Print("患者来源", patientsoure)
  1152. lapseto := int64(dataBody["lapseto"].(float64))
  1153. fmt.Print("留置状态", lapseto)
  1154. contagions := dataBody["resultTwo"].([]interface{})
  1155. fmt.Print("传染病", contagions)
  1156. ids := make([]int64, 0)
  1157. for _, contagion := range contagions {
  1158. id, _ := strconv.ParseInt(contagion.(string), 10, 64)
  1159. ids = append(ids, id)
  1160. }
  1161. fmt.Print("传染病2", contagions)
  1162. is_infectious := int64(dataBody["is_infectious"].(float64))
  1163. fmt.Print("传染病", is_infectious)
  1164. adminssionNumber := dataBody["admissionNumber"].(string)
  1165. fmt.Print("住院号", adminssionNumber)
  1166. fistdate := dataBody["fistDate"].(string)
  1167. fmt.Print("首次透析日期", fistdate)
  1168. timeLayouts := "2006-01-02"
  1169. loc, _ := time.LoadLocation("Local")
  1170. times, err := time.ParseInLocation(timeLayouts+" 15:04:05", fistdate+" 00:00:00", loc)
  1171. //times, err := utils.ParseTimeStringToTime(timeLayout, fistdate+"00:00:00")
  1172. fisttime := times.Unix()
  1173. fmt.Print(fisttime)
  1174. diagonse := dataBody["diagnose"].(string)
  1175. fmt.Print("诊断", diagonse)
  1176. avatar := dataBody["avatar"].(string)
  1177. fmt.Print("头像", avatar)
  1178. //慢性病
  1179. requipmentId := dataBody["requipmentId"].(string)
  1180. fmt.Print("设备ID", requipmentId)
  1181. slowContagions := dataBody["resultThree"].([]interface{})
  1182. fmt.Print("慢性传染病", slowContagions)
  1183. idss := make([]int64, 0)
  1184. for _, contagion := range slowContagions {
  1185. id, _ := strconv.ParseInt(contagion.(string), 10, 64)
  1186. idss = append(ids, id)
  1187. }
  1188. fmt.Print(idss)
  1189. slowDiseases := dataBody["resultFour"].([]interface{})
  1190. idsss := make([]int64, 0)
  1191. for _, contagion := range slowDiseases {
  1192. id, _ := strconv.ParseInt(contagion.(string), 10, 64)
  1193. idsss = append(ids, id)
  1194. }
  1195. fmt.Print("idsss", idsss)
  1196. fmt.Print("慢性病", slowDiseases)
  1197. bloodPatient := int64(dataBody["bloodPatient"].(float64))
  1198. fmt.Print("血透病人", bloodPatient)
  1199. slowpatient := int64(dataBody["slowPatient"].(float64))
  1200. fmt.Print("慢病病人", slowpatient)
  1201. memberpatient := int64(dataBody["memberPatient"].(float64))
  1202. fmt.Print("会员病人", memberpatient)
  1203. //会员
  1204. memberFistDate := dataBody["memberFistDate"].(string)
  1205. fmt.Print("首次透析日期", memberFistDate)
  1206. //membertimes, err := utils.ParseTimeStringToTime(timeLayout, memberFistDate+"00:00:00")
  1207. membertimes, _ := time.ParseInLocation(timeLayouts+" 15:04:05", memberFistDate+" 00:00:00", loc)
  1208. memtime := membertimes.Unix()
  1209. fmt.Print("会员透析日期", memtime)
  1210. patient_type := int64(dataBody["patientType"].(float64))
  1211. fmt.Print("病种", patient_type)
  1212. treatmentmethod := int64(dataBody["treatmentMethod"].(float64))
  1213. fmt.Print("治疗方式", treatmentmethod)
  1214. //如果是血透病人
  1215. if bloodPatient == 1 {
  1216. //根据新表ID获取老表病人ID
  1217. patient, _ := service.GetNewPatient(id)
  1218. //判断身份证号是否相同
  1219. thisPatient, _ := service.FindPatientByIdCardNoOne(orgid, idCard, id)
  1220. if thisPatient.ID > 0 && thisPatient.ID != patient.BloodId {
  1221. returnData := make(map[string]interface{}, 0)
  1222. returnData["msg"] = "身份证号码已存在"
  1223. this.ServeSuccessJSON(returnData)
  1224. return
  1225. }
  1226. //查询手机号码是否存在
  1227. thisPatientOne, err := service.FindPatientByMobileOne(phone, orgid, id)
  1228. if thisPatientOne.ID > 0 && thisPatientOne.ID != patient.BloodId {
  1229. returnData := make(map[string]interface{}, 0)
  1230. returnData["msg"] = "手机号码已存在"
  1231. this.ServeSuccessJSON(returnData)
  1232. return
  1233. }
  1234. //查询号透析号是否相同
  1235. thisPatientother, _ := service.FindPatientByDialysisNoOne(orgid, dialysis, id)
  1236. if thisPatientother.ID > 0 && thisPatientother.ID != patient.BloodId {
  1237. fmt.Println("进来没有---------------------------------")
  1238. returnData := make(map[string]interface{}, 0)
  1239. returnData["msg"] = "透析号码已存在"
  1240. this.ServeSuccessJSON(returnData)
  1241. return
  1242. }
  1243. patients := models.Patients{
  1244. Name: name,
  1245. Gender: sex,
  1246. Birthday: birth,
  1247. Age: ages,
  1248. Phone: phone,
  1249. Lapseto: lapseto,
  1250. AdmissionNumber: adminssionNumber,
  1251. FirstDialysisDate: fisttime,
  1252. Diagnose: diagonse,
  1253. Source: patientsoure,
  1254. DialysisNo: dialysis,
  1255. UserOrgId: orgid,
  1256. Status: 1,
  1257. CreatedTime: time.Now().Unix(),
  1258. Avatar: avatar,
  1259. IdCardNo: idCard,
  1260. IsInfectious: is_infectious,
  1261. }
  1262. err = service.UpdatedPatient(patients, patient.BloodId)
  1263. patientsNew := models.XtPatientsNew{
  1264. ID: id,
  1265. Name: name,
  1266. Gender: sex,
  1267. Birthday: birth,
  1268. Age: ages,
  1269. Phone: phone,
  1270. Lapseto: lapseto,
  1271. AdmissionNumber: adminssionNumber,
  1272. FirstDialysisDate: fisttime,
  1273. Diagnose: diagonse,
  1274. Source: patientsoure,
  1275. DialysisNo: dialysis,
  1276. UserOrgId: orgid,
  1277. Status: 1,
  1278. CreatedTime: time.Now().Unix(),
  1279. Avatar: avatar,
  1280. IdCardNo: idCard,
  1281. IsInfectious: is_infectious,
  1282. }
  1283. err = service.UpdateXtPatientNew(patientsNew, id)
  1284. if err != nil {
  1285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1286. return
  1287. }
  1288. this.ServeSuccessJSON(map[string]interface{}{
  1289. "patients": patientsNew,
  1290. })
  1291. //更改传染病
  1292. updateContagions, err := service.UpdateContagions(patient.BloodId)
  1293. fmt.Print("更新传染病失败", err)
  1294. fmt.Print("up", updateContagions)
  1295. err = service.AddContagions(patient.BloodId, patient.CreatedTime, patient.UpdatedTime, ids)
  1296. fmt.Println("添加传染病失败", err)
  1297. }
  1298. if slowpatient == 1 {
  1299. patient, _ := service.GetNewPatient(id)
  1300. patients := models.CdmPatients{
  1301. Name: name,
  1302. Gender: sex,
  1303. Birthday: birth,
  1304. Phone: phone,
  1305. Diagnose: diagonse,
  1306. Source: patientsoure,
  1307. UserOrgId: orgid,
  1308. Status: 1,
  1309. CreatedTime: time.Now().Unix(),
  1310. Avatar: avatar,
  1311. IdCardNo: idCard,
  1312. }
  1313. err := service.UpdateCustomer(patients, patient.SlowId)
  1314. fmt.Print("更新慢病患者失败", err)
  1315. xtPatientsNew := models.XtPatientsNew{
  1316. ID: id,
  1317. Name: name,
  1318. Gender: sex,
  1319. Birthday: birth,
  1320. Age: ages,
  1321. Phone: phone,
  1322. Lapseto: lapseto,
  1323. AdmissionNumber: adminssionNumber,
  1324. FirstDialysisDate: fisttime,
  1325. Diagnose: diagonse,
  1326. Source: patientsoure,
  1327. DialysisNo: dialysis,
  1328. UserOrgId: orgid,
  1329. Status: 1,
  1330. CreatedTime: time.Now().Unix(),
  1331. Avatar: avatar,
  1332. MemberPatients: memberpatient,
  1333. BloodPatients: bloodPatient,
  1334. SlowPatients: slowpatient,
  1335. IsInfectious: is_infectious,
  1336. IdCardNo: idCard,
  1337. EquitmentId: requipmentId,
  1338. }
  1339. err = service.UpdateXtPatientNew(xtPatientsNew, id)
  1340. fmt.Print("更新失败", err)
  1341. if err != nil {
  1342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1343. return
  1344. }
  1345. this.ServeSuccessJSON(map[string]interface{}{
  1346. "patients": xtPatientsNew,
  1347. })
  1348. }
  1349. if memberpatient == 1 {
  1350. patient, _ := service.GetNewPatient(id)
  1351. customer := models.SgjUserCustomer{
  1352. Name: name,
  1353. UserOrgId: orgid,
  1354. Mobile: phone,
  1355. Gender: sex,
  1356. Birthday: birth,
  1357. IllDate: memtime,
  1358. Status: 1,
  1359. CreatedTime: time.Now().Unix(),
  1360. Avatar: avatar,
  1361. IllnessId: patient_type,
  1362. TreatType: treatmentmethod,
  1363. }
  1364. err := service.UpdatedCustomer(customer, patient.MemberId)
  1365. fmt.Print("更新失败", err)
  1366. patientsNew := models.XtPatientsNew{
  1367. ID: id,
  1368. Name: name,
  1369. Gender: sex,
  1370. Birthday: birth,
  1371. Age: ages,
  1372. Phone: phone,
  1373. Lapseto: lapseto,
  1374. AdmissionNumber: adminssionNumber,
  1375. FirstDialysisDate: fisttime,
  1376. Diagnose: diagonse,
  1377. Source: patientsoure,
  1378. DialysisNo: dialysis,
  1379. UserOrgId: orgid,
  1380. Status: 1,
  1381. CreatedTime: time.Now().Unix(),
  1382. Avatar: avatar,
  1383. MemberPatients: memberpatient,
  1384. BloodPatients: bloodPatient,
  1385. SlowPatients: slowpatient,
  1386. IsInfectious: is_infectious,
  1387. IdCardNo: idCard,
  1388. MemberFistdate: memtime,
  1389. MemberPatienttype: patient_type,
  1390. MemberTreatement: treatmentmethod,
  1391. }
  1392. err = service.UpdateXtPatientNewOne(patientsNew, id)
  1393. if err != nil {
  1394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1395. return
  1396. }
  1397. this.ServeSuccessJSON(map[string]interface{}{
  1398. "patients": patientsNew,
  1399. })
  1400. }
  1401. }
  1402. func (this *NewDialysisApiController) GetAllDoctor() {
  1403. orgid := this.GetMobileAdminUserInfo().Org.Id
  1404. id := this.GetMobileAdminUserInfo().App.Id
  1405. doctor, err := service.GetAllDoctorTwo(orgid, id)
  1406. if err != nil {
  1407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1408. return
  1409. }
  1410. this.ServeSuccessJSON(map[string]interface{}{
  1411. "doctor": doctor,
  1412. })
  1413. }
  1414. func (this *NewDialysisApiController) GetAllInspection() {
  1415. //查询该机构是否存在检验检测项目
  1416. orgid := this.GetMobileAdminUserInfo().Org.Id
  1417. fmt.Print("orgid", orgid)
  1418. _, errcode := service.GetInspectionByOrgId(orgid)
  1419. if errcode == gorm.ErrRecordNotFound {
  1420. inspection, err := service.GetAllInspection(0)
  1421. if err != nil {
  1422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1423. return
  1424. }
  1425. this.ServeSuccessJSON(map[string]interface{}{
  1426. "inspection": inspection,
  1427. })
  1428. } else if errcode == nil {
  1429. inspection, err := service.GetAllInspection(orgid)
  1430. if err != nil {
  1431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1432. return
  1433. }
  1434. this.ServeSuccessJSON(map[string]interface{}{
  1435. "inspection": inspection,
  1436. })
  1437. } else {
  1438. }
  1439. }
  1440. func (this *NewDialysisApiController) GetInspection() {
  1441. timeLayout := "2006-01-02"
  1442. loc, _ := time.LoadLocation("Local")
  1443. id, _ := this.GetInt64("id")
  1444. fmt.Print("id", id)
  1445. patient, _ := service.GetPatientDetailTwo(id)
  1446. start := this.GetString("startime")
  1447. startTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", start+" 00:00:00", loc)
  1448. startime := startTimes.Unix()
  1449. fmt.Print("startime", startime)
  1450. end := this.GetString("endtime")
  1451. endTimes, _ := time.ParseInLocation(timeLayout+" 15:04:05", end+" 00:00:00", loc)
  1452. endtime := endTimes.Unix()
  1453. fmt.Print("endtime", endtime)
  1454. limit, _ := this.GetInt64("limit")
  1455. fmt.Print("limit", limit)
  1456. page, _ := this.GetInt64("page")
  1457. fmt.Print("page", page)
  1458. projectid, _ := this.GetInt64("projectid")
  1459. fmt.Print("projectid", projectid)
  1460. adminInfo := this.GetMobileAdminUserInfo()
  1461. orgid := adminInfo.Org.Id
  1462. fmt.Print("patient", patient)
  1463. fmt.Print("orgid", orgid)
  1464. //查询该机构是否存在
  1465. //inspection, _ := service.GetInspectionById(patient.BloodId, startime, endtime, orgid)
  1466. //if len(inspection) == 0 {
  1467. //
  1468. //}
  1469. inspection, total, err := service.GetInspection(patient.BloodId, startime, endtime, limit, page, orgid, projectid)
  1470. if err != nil {
  1471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1472. return
  1473. }
  1474. this.ServeSuccessJSON(map[string]interface{}{
  1475. "inspection": inspection,
  1476. "total": total,
  1477. })
  1478. }
  1479. func (this *NewDialysisApiController) GetMyInformation() {
  1480. id, _ := this.GetInt64("id")
  1481. roleInfo, err := service.GetPosition(id)
  1482. if err != nil {
  1483. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1484. return
  1485. }
  1486. this.ServeSuccessJSON(map[string]interface{}{
  1487. "roleInfo": roleInfo,
  1488. })
  1489. return
  1490. }
  1491. func (this *NewDialysisApiController) GetMyInformationThree() {
  1492. id, _ := this.GetInt64("id")
  1493. roleInfo, err := service.GetPositionOne(id)
  1494. if err != nil {
  1495. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1496. return
  1497. }
  1498. this.ServeSuccessJSON(map[string]interface{}{
  1499. "roleInfo": roleInfo,
  1500. })
  1501. return
  1502. }
  1503. func (this *NewDialysisApiController) GetPatientName() {
  1504. id, _ := this.GetInt64("id")
  1505. patients, _ := service.GetPatientDetailTwo(id)
  1506. fmt.Print("paitents", patients.ID)
  1507. patientName, err := service.GetPatientName(patients.BloodId)
  1508. fmt.Print("err", err)
  1509. if err != nil {
  1510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1511. return
  1512. }
  1513. this.ServeSuccessJSON(map[string]interface{}{
  1514. "patientName": patientName,
  1515. })
  1516. }
  1517. func (this *NewDialysisApiController) GetInspectionDetail() {
  1518. patientid, _ := this.GetInt64("patientid")
  1519. fmt.Print("patientid", patientid)
  1520. patients, _ := service.GetPatientDetailTwo(patientid)
  1521. date, _ := this.GetInt64("date")
  1522. fmt.Print("date", date)
  1523. projectid, _ := this.GetInt64("projectid")
  1524. adminUser := this.GetMobileAdminUserInfo()
  1525. orgid := adminUser.Org.Id
  1526. InspectionDetail, err := service.GetInspectionDetail(patients.BloodId, date, orgid, projectid)
  1527. if err != nil {
  1528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1529. return
  1530. }
  1531. this.ServeSuccessJSON(map[string]interface{}{
  1532. "InspectionDetail": InspectionDetail,
  1533. })
  1534. }
  1535. func (this *NewDialysisApiController) SaveFeed() {
  1536. question, _ := this.GetInt64("question")
  1537. fmt.Print("question", question)
  1538. title := this.GetString("title")
  1539. fmt.Print("title", title)
  1540. content := this.GetString("content")
  1541. fmt.Print("content", content)
  1542. phone := this.GetString("phone")
  1543. fmt.Print("phone", phone)
  1544. times, _ := this.GetInt64("time")
  1545. fmt.Print("time", times)
  1546. adminuserid, _ := this.GetInt64("admin_user_id")
  1547. fmt.Println("admin", adminuserid)
  1548. adminUser := this.GetMobileAdminUserInfo()
  1549. orgid := adminUser.Org.Id
  1550. appid := adminUser.App.Id
  1551. feedback := models.XtPatientFeedback{
  1552. ProblemType: question,
  1553. Title: title,
  1554. Content: content,
  1555. Phone: phone,
  1556. TimeQuantum: times,
  1557. UserOrgId: orgid,
  1558. Ctime: time.Now().Unix(),
  1559. Status: 1,
  1560. AdminUserId: adminuserid,
  1561. AppId: appid,
  1562. }
  1563. err := service.CreateFeedBack(&feedback)
  1564. if err != nil {
  1565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1566. return
  1567. }
  1568. this.ServeSuccessJSON(map[string]interface{}{
  1569. "feedback": feedback,
  1570. })
  1571. }
  1572. func (this *NewDialysisApiController) DeleteInspection() {
  1573. admininfo := this.GetMobileAdminUserInfo()
  1574. orgid := admininfo.Org.Id
  1575. date, _ := this.GetInt64("date")
  1576. fmt.Println("date", date)
  1577. err := service.DeleteInspection(date, orgid)
  1578. fmt.Println("删除失败", err)
  1579. returnData := make(map[string]interface{}, 0)
  1580. returnData["msg"] = "手机号码已存在"
  1581. this.ServeSuccessJSON(returnData)
  1582. return
  1583. }
  1584. func (this *NewDialysisApiController) DeleteChildInspection() {
  1585. admininfo := this.GetMobileAdminUserInfo()
  1586. orgid := admininfo.Org.Id
  1587. name := this.GetString("name")
  1588. fmt.Println("name", name)
  1589. date, _ := this.GetInt64("date")
  1590. fmt.Println("date", date)
  1591. err := service.DeleteChildInspection(name, date, orgid)
  1592. fmt.Println("删除失败", err)
  1593. returnData := make(map[string]interface{}, 0)
  1594. returnData["msg"] = "手机号码已存在"
  1595. this.ServeSuccessJSON(returnData)
  1596. return
  1597. }
  1598. func (this *NewDialysisApiController) SaveMessage() {
  1599. id, _ := this.GetInt64("id")
  1600. fmt.Println("id", id)
  1601. message := this.GetString("message")
  1602. fmt.Println("message", message)
  1603. role := models.SgjUserAdminRole{
  1604. Message: message,
  1605. }
  1606. err := service.SaveMessage(id, &role)
  1607. if err != nil {
  1608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1609. return
  1610. }
  1611. this.ServeSuccessJSON(map[string]interface{}{
  1612. "role": role,
  1613. })
  1614. }
  1615. func (this *NewDialysisApiController) SaveSex() {
  1616. sex, _ := this.GetInt64("sex")
  1617. fmt.Println("sex", sex)
  1618. id, _ := this.GetInt64("id")
  1619. fmt.Println("id", id)
  1620. role := models.SgjUserAdminRole{
  1621. Sex: sex,
  1622. }
  1623. err := service.SaveSex(id, &role)
  1624. if err != nil {
  1625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1626. return
  1627. }
  1628. this.ServeSuccessJSON(map[string]interface{}{
  1629. "role": role,
  1630. })
  1631. }
  1632. func (this *NewDialysisApiController) SaveBirthday() {
  1633. dataBody := make(map[string]interface{}, 0)
  1634. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1635. fmt.Println(err)
  1636. id := dataBody["id"].(string)
  1637. ids, err := strconv.ParseInt(id, 10, 64)
  1638. fmt.Print("id", id)
  1639. birthday := dataBody["birth"].(string)
  1640. timeLayout := "2006-01-02 15:04:05"
  1641. theTime, err := utils.ParseTimeStringToTime(timeLayout, birthday+" 00:00:00")
  1642. birth := theTime.Unix()
  1643. role := models.SgjUserAdminRole{
  1644. Birthday: birth,
  1645. }
  1646. err = service.SaveBirthday(ids, &role)
  1647. if err != nil {
  1648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1649. return
  1650. }
  1651. this.ServeSuccessJSON(map[string]interface{}{
  1652. "role": role,
  1653. })
  1654. }
  1655. func (this *NewDialysisApiController) GetOrgName() {
  1656. id, _ := this.GetInt64("id")
  1657. name, err := service.GetOrgName(id)
  1658. if err != nil {
  1659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1660. return
  1661. }
  1662. this.ServeSuccessJSON(map[string]interface{}{
  1663. "name": name,
  1664. })
  1665. }
  1666. func (this *NewDialysisApiController) GetRoleName() {
  1667. id, _ := this.GetInt64("id")
  1668. fmt.Println("id", id)
  1669. orgid := this.GetMobileAdminUserInfo().Org.Id
  1670. fmt.Println("orgid", orgid)
  1671. appid := this.GetMobileAdminUserInfo().App.Id
  1672. fmt.Println("appid", appid)
  1673. name, err := service.GetRoleName(id, orgid, appid)
  1674. //获取管理员
  1675. admin, err := service.GetAdmin(id)
  1676. positionName, err := service.GetPositionName(id, orgid, appid)
  1677. if err != nil {
  1678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1679. return
  1680. }
  1681. this.ServeSuccessJSON(map[string]interface{}{
  1682. "name": name,
  1683. "positionName": positionName,
  1684. "admin": admin,
  1685. })
  1686. }
  1687. func (this *NewDialysisApiController) SavePartition() {
  1688. adminInfo := this.GetMobileAdminUserInfo()
  1689. name := this.GetString("name")
  1690. fmt.Println("分区名称", name)
  1691. zonetype, _ := this.GetInt64("type")
  1692. fmt.Println("分区型号", zonetype)
  1693. strInt64 := strconv.FormatInt(zonetype, 10)
  1694. typeid, _ := strconv.Atoi(strInt64)
  1695. zone := models.DeviceZone{
  1696. Name: name,
  1697. Type: typeid,
  1698. OrgID: adminInfo.Org.Id,
  1699. Status: 1,
  1700. CreateTime: time.Now().Unix(),
  1701. }
  1702. err := service.CreatedZone(&zone)
  1703. if err != nil {
  1704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1705. return
  1706. }
  1707. this.ServeSuccessJSON(map[string]interface{}{
  1708. "zone": zone,
  1709. })
  1710. }
  1711. func (this *NewDialysisApiController) GetAllZone() {
  1712. adminUser := this.GetMobileAdminUserInfo()
  1713. orgid := adminUser.Org.Id
  1714. page, _ := this.GetInt64("page")
  1715. limit, _ := this.GetInt64("limit")
  1716. zone, total, err := service.GetAllZone(orgid, page, limit)
  1717. if err != nil {
  1718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1719. return
  1720. }
  1721. this.ServeSuccessJSON(map[string]interface{}{
  1722. "zone": zone,
  1723. "total": total,
  1724. })
  1725. }
  1726. func (this *NewDialysisApiController) DeleteZone() {
  1727. id, _ := this.GetInt64("id")
  1728. err := service.DeleteZoneById(id)
  1729. fmt.Println("删除失败", err)
  1730. returnData := make(map[string]interface{}, 0)
  1731. returnData["msg"] = "删除失败"
  1732. this.ServeSuccessJSON(returnData)
  1733. return
  1734. }
  1735. func (this *NewDialysisApiController) SaveGroup() {
  1736. adminUser := this.GetMobileAdminUserInfo()
  1737. orgid := adminUser.Org.Id
  1738. name := this.GetString("name")
  1739. fmt.Println("name", name)
  1740. group := models.DeviceGroup{
  1741. Name: name,
  1742. Status: 1,
  1743. CreateTime: time.Now().Unix(),
  1744. OrgID: orgid,
  1745. }
  1746. err := service.SaveGroup(&group)
  1747. if err != nil {
  1748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1749. return
  1750. }
  1751. this.ServeSuccessJSON(map[string]interface{}{
  1752. "group": group,
  1753. })
  1754. }
  1755. func (this *NewDialysisApiController) GetAllGroup() {
  1756. adminUser := this.GetMobileAdminUserInfo()
  1757. orgid := adminUser.Org.Id
  1758. page, _ := this.GetInt64("page")
  1759. fmt.Println("page", page)
  1760. limit, _ := this.GetInt64("limit")
  1761. fmt.Println("limit", limit)
  1762. group, total, err := service.GetAllGroup(orgid, page, limit)
  1763. if err != nil {
  1764. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1765. return
  1766. }
  1767. this.ServeSuccessJSON(map[string]interface{}{
  1768. "group": group,
  1769. "total": total,
  1770. })
  1771. }
  1772. func (this *NewDialysisApiController) DeleteGroup() {
  1773. id, _ := this.GetInt64("id")
  1774. fmt.Println("id", id)
  1775. err := service.DeleteGroup(id)
  1776. fmt.Println("删除失败", err)
  1777. returnData := make(map[string]interface{}, 0)
  1778. returnData["msg"] = "删除失败"
  1779. this.ServeSuccessJSON(returnData)
  1780. return
  1781. }
  1782. func (this *NewDialysisApiController) GetAllGroupOne() {
  1783. admininfo := this.GetMobileAdminUserInfo()
  1784. orgid := admininfo.Org.Id
  1785. zone, _ := service.GetAllZoneOne(orgid)
  1786. group, err := service.GetAllGroupOne(orgid)
  1787. if err != nil {
  1788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1789. return
  1790. }
  1791. this.ServeSuccessJSON(map[string]interface{}{
  1792. "zone": zone,
  1793. "group": group,
  1794. })
  1795. }
  1796. func (this *NewDialysisApiController) SaveBed() {
  1797. adminuser := this.GetMobileAdminUserInfo()
  1798. orgid := adminuser.Org.Id
  1799. name := this.GetString("name")
  1800. fmt.Println("name", name)
  1801. zone, _ := this.GetInt64("zone")
  1802. fmt.Print("zone", zone)
  1803. group, _ := this.GetInt64("group")
  1804. fmt.Println("group", group)
  1805. number := models.DeviceNumber{
  1806. Number: name,
  1807. ZoneID: zone,
  1808. GroupID: group,
  1809. OrgID: orgid,
  1810. Status: 1,
  1811. CreateTime: time.Now().Unix(),
  1812. }
  1813. err := service.CreateNumber(&number)
  1814. if err != nil {
  1815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1816. return
  1817. }
  1818. this.ServeSuccessJSON(map[string]interface{}{
  1819. "number": number,
  1820. })
  1821. }
  1822. func (this *NewDialysisApiController) GetAllNumber() {
  1823. admininfo := this.GetMobileAdminUserInfo()
  1824. orgid := admininfo.Org.Id
  1825. page, _ := this.GetInt64("page")
  1826. fmt.Print("page", page)
  1827. limit, _ := this.GetInt64("limit")
  1828. fmt.Println("limit", limit)
  1829. number, total, err := service.GetAllNumber(page, limit, orgid)
  1830. zone, _ := service.GetAllZoneOne(orgid)
  1831. group, _ := service.GetAllGroupOne(orgid)
  1832. if err != nil {
  1833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1834. return
  1835. }
  1836. this.ServeSuccessJSON(map[string]interface{}{
  1837. "number": number,
  1838. "total": total,
  1839. "zone": zone,
  1840. "group": group,
  1841. })
  1842. }
  1843. func (this *NewDialysisApiController) DeleteBed() {
  1844. id, _ := this.GetInt64("id")
  1845. fmt.Println("id", id)
  1846. nowDateTime := time.Now()
  1847. nowDate := nowDateTime.Format("2006-01-02")
  1848. nowDate += " 00:00:00"
  1849. timeLayout := "2006-01-02"
  1850. loc, _ := time.LoadLocation("Local")
  1851. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  1852. fmt.Println(theTime.Unix())
  1853. adminInfo := this.GetMobileAdminUserInfo()
  1854. orgid := adminInfo.Org.Id
  1855. _, errcode := service.GetSchedu(id, theTime.Unix(), orgid)
  1856. fmt.Println("errcode", errcode)
  1857. if errcode == gorm.ErrRecordNotFound {
  1858. err := service.DeleteBed(id)
  1859. fmt.Println("删除失败", err)
  1860. returnData := make(map[string]interface{}, 0)
  1861. returnData["msg"] = "删除失败"
  1862. this.ServeSuccessJSON(returnData)
  1863. return
  1864. } else if errcode == nil {
  1865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1866. return
  1867. }
  1868. }
  1869. func (this *NewDialysisApiController) LoginOut() {
  1870. this.DelSession("mobile_admin_user_info")
  1871. this.Ctx.SetCookie("logout_cookie", "1")
  1872. this.Ctx.SetCookie("token_cookie", "")
  1873. id, _ := this.GetInt64("id")
  1874. fmt.Println("id------------------------------------------", id)
  1875. loginLog := models.SgjUserAdminLoginLog{
  1876. AdminUserId: id,
  1877. OrgId: 0,
  1878. AppId: 0,
  1879. Ip: utils.GetIP(this.Ctx.Request),
  1880. OperateType: 2,
  1881. AppType: 0,
  1882. Ctime: time.Now().Unix(),
  1883. }
  1884. err := service.CreateLoginLod(&loginLog)
  1885. fmt.Println("err--------", err)
  1886. returnData := make(map[string]interface{}, 0)
  1887. returnData["msg"] = "删除失败"
  1888. this.ServeSuccessJSON(returnData)
  1889. return
  1890. }
  1891. func (this *NewDialysisApiController) GetMemberPatient() {
  1892. adminUser := this.GetMobileAdminUserInfo()
  1893. orgid := adminUser.Org.Id
  1894. patient, err := service.GetMemberPatient(orgid)
  1895. if err != nil {
  1896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1897. return
  1898. }
  1899. this.ServeSuccessJSON(map[string]interface{}{
  1900. "patient": patient,
  1901. })
  1902. }
  1903. func (this *NewDialysisApiController) GetSlowPatient() {
  1904. adminUser := this.GetMobileAdminUserInfo()
  1905. orgid := adminUser.Org.Id
  1906. patient, err := service.GetSlowPatient(orgid)
  1907. if err != nil {
  1908. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1909. return
  1910. }
  1911. this.ServeSuccessJSON(map[string]interface{}{
  1912. "patient": patient,
  1913. })
  1914. }
  1915. func (this *NewDialysisApiController) GetBloodPatient() {
  1916. adminUser := this.GetMobileAdminUserInfo()
  1917. orgid := adminUser.Org.Id
  1918. patient, err := service.GetBloodPatient(orgid)
  1919. if err != nil {
  1920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1921. return
  1922. }
  1923. this.ServeSuccessJSON(map[string]interface{}{
  1924. "patient": patient,
  1925. })
  1926. }
  1927. func (this *NewDialysisApiController) SaveName() {
  1928. id := this.GetString("id")
  1929. ids, _ := strconv.ParseInt(id, 10, 64)
  1930. fmt.Println("id", ids)
  1931. name := this.GetString("name")
  1932. fmt.Println("name", name)
  1933. admin := models.SgjUserAdmin{
  1934. Name: name,
  1935. }
  1936. err := service.SaveName(ids, &admin)
  1937. if err != nil {
  1938. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1939. return
  1940. }
  1941. this.ServeSuccessJSON(map[string]interface{}{
  1942. "admin": admin,
  1943. })
  1944. }
  1945. func (this *NewDialysisApiController) GetAllOrganization() {
  1946. id, _ := this.GetInt64("id")
  1947. fmt.Println("id", id)
  1948. }
  1949. func (this *NewDialysisApiController) GetMyOrganazition() {
  1950. id, _ := this.GetInt64("id")
  1951. fmt.Println("id", id)
  1952. role, _ := service.GetAdminUserId(id)
  1953. organaziton, err := service.GetMyOrganaziton(role.AdminUserId)
  1954. if err != nil {
  1955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1956. return
  1957. }
  1958. this.ServeSuccessJSON(map[string]interface{}{
  1959. "organaziton": organaziton,
  1960. })
  1961. }
  1962. func (this *NewDialysisApiController) GetOrgInformation() {
  1963. id, _ := this.GetInt64("id")
  1964. information, err := service.GetOrgInformation(id)
  1965. name, err := service.GetShortName(information.OrgType)
  1966. typeName, err := service.GetTypeName(name.Pid)
  1967. //获取省
  1968. province, err := service.GetOrgProvince(information.Province)
  1969. cityes, err := service.GetOrgProvince(information.City)
  1970. district, err := service.GetOrgProvince(information.District)
  1971. fmt.Print("err", err)
  1972. //if err != nil {
  1973. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1974. // return
  1975. //}
  1976. this.ServeSuccessJSON(map[string]interface{}{
  1977. "information": information,
  1978. "name": name,
  1979. "typeName": typeName,
  1980. "province": province,
  1981. "city": cityes,
  1982. "district": district,
  1983. })
  1984. }
  1985. func (this *NewDialysisApiController) GetAllOrgType() {
  1986. orgType, _ := service.GetAllOrgType()
  1987. returnData := make(map[string]interface{}, 0)
  1988. returnData["orgType"] = orgType
  1989. this.ServeSuccessJSON(returnData)
  1990. }
  1991. func (this *NewDialysisApiController) EditOrg() {
  1992. id, _ := this.GetInt64("id")
  1993. fmt.Println("id", id)
  1994. name := this.GetString("org_name")
  1995. fmt.Println("name", name)
  1996. provinceName := this.GetString("provinces_name")
  1997. fmt.Println("provinceName", provinceName)
  1998. cityName := this.GetString("city_name")
  1999. fmt.Println("cityName", cityName)
  2000. districtName := this.GetString("district_name")
  2001. fmt.Println("districtName", districtName)
  2002. address := this.GetString("address")
  2003. fmt.Println("address", address)
  2004. org_type := this.GetString("org_type")
  2005. fmt.Println("org_type", org_type)
  2006. contactName := this.GetString("contact_name")
  2007. fmt.Println("contactName", contactName)
  2008. orgPhone := this.GetString("telephone")
  2009. fmt.Println("orgPhone", orgPhone)
  2010. provinceID := 0
  2011. cityID := 0
  2012. districtID := 0
  2013. province, getProvinceErr := service.GetProvinceWithName(provinceName)
  2014. if getProvinceErr != nil {
  2015. utils.ErrorLog("查询省名失败:%v", getProvinceErr)
  2016. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2017. this.ServeJSON()
  2018. return
  2019. } else if province != nil {
  2020. provinceID = int(province.ID)
  2021. city, getCityErr := service.GetCityWithName(province.ID, cityName)
  2022. if getCityErr != nil {
  2023. utils.ErrorLog("查询城市名失败:%v", getCityErr)
  2024. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2025. this.ServeJSON()
  2026. return
  2027. } else if city != nil {
  2028. cityID = int(city.ID)
  2029. district, getDistrictErr := service.GetDistrictWithName(city.ID, districtName)
  2030. if getDistrictErr != nil {
  2031. utils.ErrorLog("查询区县名失败:%v", getDistrictErr)
  2032. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2033. this.ServeJSON()
  2034. return
  2035. } else if district != nil {
  2036. districtID = int(district.ID)
  2037. }
  2038. }
  2039. }
  2040. orgType := service.GetOrgTypeByName(org_type)
  2041. fmt.Println(provinceID, cityID, districtID)
  2042. org := models.SgjUserOrg{
  2043. OrgName: name,
  2044. OrgShortName: name,
  2045. Province: int64(provinceID),
  2046. City: int64(cityID),
  2047. District: int64(districtID),
  2048. Address: address,
  2049. OrgType: orgType.ID,
  2050. Telephone: orgPhone,
  2051. ContactName: contactName,
  2052. }
  2053. fmt.Println("org", org)
  2054. err := service.UpdateOrg(id, org)
  2055. if err != nil {
  2056. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2057. return
  2058. }
  2059. this.ServeSuccessJSON(map[string]interface{}{
  2060. "org": org,
  2061. })
  2062. }
  2063. func (this *NewDialysisApiController) GetMyInforName() {
  2064. id, _ := this.GetInt64("id")
  2065. //Rolename, err := service.GetMyInfoName(id)
  2066. Username, err := service.GetAdminName(id)
  2067. if err != nil {
  2068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2069. return
  2070. }
  2071. this.ServeSuccessJSON(map[string]interface{}{
  2072. "Username": Username,
  2073. })
  2074. }
  2075. func (this *NewDialysisApiController) GetPartionDetail() {
  2076. id, _ := this.GetInt64("id")
  2077. partionDetail, err := service.GetPartionDetail(id)
  2078. if err != nil {
  2079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2080. return
  2081. }
  2082. this.ServeSuccessJSON(map[string]interface{}{
  2083. "partionDetail": partionDetail,
  2084. })
  2085. }
  2086. func (this *NewDialysisApiController) UpdatePartition() {
  2087. id, _ := this.GetInt64("id")
  2088. name := this.GetString("name")
  2089. zoneType, _ := this.GetInt64("type")
  2090. strInt64 := strconv.FormatInt(zoneType, 10)
  2091. typeid, _ := strconv.Atoi(strInt64)
  2092. zone := models.DeviceZone{
  2093. Name: name,
  2094. Type: typeid,
  2095. }
  2096. err := service.UpdatePartition(id, &zone)
  2097. if err != nil {
  2098. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2099. return
  2100. }
  2101. this.ServeSuccessJSON(map[string]interface{}{
  2102. "zone": zone,
  2103. })
  2104. }
  2105. func (this *NewDialysisApiController) GetGroupDetail() {
  2106. id, _ := this.GetInt64("id")
  2107. groupDetail, err := service.GetGroupDetail(id)
  2108. if err != nil {
  2109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2110. return
  2111. }
  2112. this.ServeSuccessJSON(map[string]interface{}{
  2113. "groupDetail": groupDetail,
  2114. })
  2115. }
  2116. func (this *NewDialysisApiController) UpdateGroup() {
  2117. id, _ := this.GetInt64("id")
  2118. name := this.GetString("name")
  2119. group := models.DeviceGroup{Name: name}
  2120. err := service.UpdateGroup(id, &group)
  2121. if err != nil {
  2122. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2123. return
  2124. }
  2125. this.ServeSuccessJSON(map[string]interface{}{
  2126. "group": group,
  2127. })
  2128. }
  2129. func (this *NewDialysisApiController) GetBedDetail() {
  2130. adminUser := this.GetMobileAdminUserInfo()
  2131. orgid := adminUser.Org.Id
  2132. id, _ := this.GetInt64("id")
  2133. zone, _ := service.GetAllZoneOne(orgid)
  2134. group, err := service.GetAllGroupOne(orgid)
  2135. bedDetail, err := service.GetBedDetail(id)
  2136. if err != nil {
  2137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2138. return
  2139. }
  2140. this.ServeSuccessJSON(map[string]interface{}{
  2141. "zone": zone,
  2142. "group": group,
  2143. "bedDetail": bedDetail,
  2144. })
  2145. }
  2146. func (this *NewDialysisApiController) UpdatedBed() {
  2147. id, _ := this.GetInt64("id")
  2148. name := this.GetString("name")
  2149. fmt.Println("name", name)
  2150. zone, _ := this.GetInt64("zone")
  2151. fmt.Println("zone", zone)
  2152. group, _ := this.GetInt64("group")
  2153. fmt.Println("group", group)
  2154. number := models.DeviceNumber{
  2155. Number: name,
  2156. ZoneID: zone,
  2157. GroupID: group,
  2158. }
  2159. err := service.UpdatedBed(id, &number)
  2160. if err != nil {
  2161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2162. return
  2163. }
  2164. this.ServeSuccessJSON(map[string]interface{}{
  2165. "number": number,
  2166. })
  2167. }
  2168. func (this *NewDialysisApiController) GetMyOrgInformation() {
  2169. creator, _ := this.GetInt64("creator")
  2170. fmt.Println("cretor", creator)
  2171. adminInfo := this.GetMobileAdminUserInfo()
  2172. appId := adminInfo.App.Id
  2173. information, err := service.GetMyOrgInformation(creator, appId)
  2174. if err != nil {
  2175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2176. return
  2177. }
  2178. this.ServeSuccessJSON(map[string]interface{}{
  2179. "information": information,
  2180. })
  2181. }
  2182. func (this *NewDialysisApiController) SaveNameTwo() {
  2183. id, _ := this.GetInt64("id")
  2184. name := this.GetString("name")
  2185. fmt.Println("name------------------", name)
  2186. role := models.SgjUserAdminRole{
  2187. UserName: name,
  2188. }
  2189. err := service.SaveNameTwo(id, &role)
  2190. if err != nil {
  2191. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2192. return
  2193. }
  2194. this.ServeSuccessJSON(map[string]interface{}{
  2195. "role": role,
  2196. })
  2197. }
  2198. func (this *NewDialysisApiController) GetCurrentOrg() {
  2199. nowTime := time.Now().Unix()
  2200. adminInfo := this.GetMobileAdminUserInfo()
  2201. orgId := adminInfo.Org.Id
  2202. fxKey := beego.AppConfig.String("fxtokenkey")
  2203. stringA := fmt.Sprintf("org_id=%d&time=%d", orgId, nowTime)
  2204. data := []byte(stringA)
  2205. has := md5.Sum(data)
  2206. md5str := fmt.Sprintf("%x", has)
  2207. stringB := fmt.Sprintf("string=%s&key=%s", md5str, fxKey)
  2208. data = []byte(stringB)
  2209. has = md5.Sum(data)
  2210. signToken := fmt.Sprintf("%x", has)
  2211. name, err := service.GetOrgName(orgId)
  2212. //var fxlink = signToken + fmt.Sprintf("&fxtoken=%s&fxorgid=%d&timestamp=%d&fxadmin=%d", signToken, orgId, nowTime, name.Creator)
  2213. //fmt.Println(fxlink)
  2214. if err != nil {
  2215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2216. return
  2217. }
  2218. this.ServeSuccessJSON(map[string]interface{}{
  2219. "org": name,
  2220. "nowTime": nowTime,
  2221. "signToken": signToken,
  2222. })
  2223. }