new_dialysis_api_controller.go 78KB

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