patient_api_controller.go 88KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "strings"
  10. // "fmt"
  11. "reflect"
  12. "strconv"
  13. "time"
  14. )
  15. type PatientApiController struct {
  16. MobileBaseAPIAuthController
  17. }
  18. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  19. id, _ := c.GetInt64("patient", 0)
  20. if id <= 0 {
  21. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  22. return
  23. }
  24. adminUserInfo := c.GetMobileAdminUserInfo()
  25. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  26. if patient.ID == 0 {
  27. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  28. return
  29. }
  30. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  31. if err != nil {
  32. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  33. return
  34. }
  35. if Registrars != nil {
  36. patient.Registrars = Registrars.Name
  37. }
  38. c.ServeSuccessJSON(map[string]interface{}{
  39. "patient": patient,
  40. })
  41. return
  42. }
  43. func (c *PatientApiController) CreateDialysisSolution() {
  44. id, _ := c.GetInt64("patient", 0)
  45. if id <= 0 {
  46. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  47. return
  48. }
  49. adminUserInfo := c.GetMobileAdminUserInfo()
  50. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  51. if patient.ID == 0 {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  53. return
  54. }
  55. //根据路由来做权限
  56. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  57. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  58. //if template.TemplateId == 2 || template.TemplateId == 6 {
  59. // if appRole.UserType == 3 {
  60. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  61. // if getPermissionErr != nil {
  62. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  63. // return
  64. // } else if headNursePermission == nil {
  65. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  66. // return
  67. // }
  68. // }
  69. //}
  70. var solution models.DialysisSolution
  71. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  72. if code > 0 {
  73. c.ServeFailJSONWithSGJErrorCode(code)
  74. return
  75. }
  76. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  77. solution.Doctor = adminUserInfo.AdminUser.Id
  78. solution.Status = 1
  79. solution.PatientId = id
  80. solution.CreatedTime = time.Now().Unix()
  81. solution.UserOrgId = adminUserInfo.Org.Id
  82. solution.UpdatedTime = time.Now().Unix()
  83. solution.SubName = ""
  84. solution.ParentId = 0
  85. err := service.CreatePatientDialysisSolution(&solution)
  86. if err != nil {
  87. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  88. return
  89. }
  90. c.ServeSuccessJSON(map[string]interface{}{
  91. "msg": "ok",
  92. "solution": solution,
  93. })
  94. return
  95. }
  96. func (c *PatientApiController) EditDialysisSolution() {
  97. id, _ := c.GetInt64("id", 0)
  98. if id <= 0 {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. adminUserInfo := c.GetMobileAdminUserInfo()
  103. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  104. if solution.ID == 0 {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  106. return
  107. }
  108. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  109. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  110. // if getPermissionErr != nil {
  111. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  112. // return
  113. // } else if headNursePermission == nil {
  114. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  115. // return
  116. // }
  117. //}
  118. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  119. if code > 0 {
  120. c.ServeFailJSONWithSGJErrorCode(code)
  121. return
  122. }
  123. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  124. solution.Doctor = adminUserInfo.AdminUser.Id
  125. solution.Status = 1
  126. // solution.PatientId = id
  127. // solution.CreatedTime = time.Now().Unix()
  128. // solution.UserOrgId = adminUserInfo.Org.Id
  129. solution.UpdatedTime = time.Now().Unix()
  130. // solution.SubName = ""
  131. // solution.ParentId = 0
  132. err := service.UpdatePatientDialysisSolution(&solution)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  135. return
  136. }
  137. c.ServeSuccessJSON(map[string]interface{}{
  138. "msg": "ok",
  139. "solution": solution,
  140. })
  141. return
  142. }
  143. func (c *PatientApiController) CreateDoctorAdvice() {
  144. patient, _ := c.GetInt64("id", 0)
  145. if patient <= 0 {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  147. return
  148. }
  149. adminUserInfo := c.GetMobileAdminUserInfo()
  150. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  151. if patientInfo.ID == 0 {
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  153. return
  154. }
  155. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  156. //if appRole.UserType == 3{
  157. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  158. // return
  159. //}
  160. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  161. //
  162. //if appRole.UserType == 3 {
  163. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  164. // if getPermissionErr != nil {
  165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  166. // return
  167. // } else if headNursePermission == nil {
  168. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  169. // return
  170. // }
  171. //}
  172. var advice models.DoctorAdvice
  173. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  174. if code > 0 {
  175. c.ServeFailJSONWithSGJErrorCode(code)
  176. return
  177. }
  178. if advice.ParentId > 0 {
  179. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  180. if old.ID == 0 || old.PatientId != patient {
  181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  182. return
  183. }
  184. if old.StopState == 1 || old.ExecutionState == 1 {
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  186. return
  187. }
  188. if old.ParentId > 0 {
  189. advice.ParentId = old.ParentId
  190. }
  191. advice.StartTime = old.StartTime
  192. advice.AdviceDoctor = old.AdviceDoctor
  193. advice.DeliveryWay = old.DeliveryWay
  194. advice.ExecutionFrequency = old.ExecutionFrequency
  195. advice.GroupNo = old.GroupNo
  196. }
  197. advice.Status = 1
  198. advice.CreatedTime = time.Now().Unix()
  199. advice.UpdatedTime = time.Now().Unix()
  200. advice.StopState = 2
  201. advice.ExecutionState = 2
  202. advice.UserOrgId = adminUserInfo.Org.Id
  203. advice.PatientId = patient
  204. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  205. err := service.CreateDoctorAdvice(&advice)
  206. if err != nil {
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  208. return
  209. }
  210. c.ServeSuccessJSON(map[string]interface{}{
  211. "msg": "ok",
  212. "advice": advice,
  213. })
  214. return
  215. }
  216. func (c *PatientApiController) EditDoctorAdvice() {
  217. id, _ := c.GetInt64("id", 0)
  218. if id <= 0 {
  219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  220. return
  221. }
  222. adminUserInfo := c.GetMobileAdminUserInfo()
  223. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  224. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  225. //
  226. //if appRole.UserType == 3 {
  227. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  228. // if getPermissionErr != nil {
  229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  230. // return
  231. // } else if headNursePermission == nil {
  232. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  233. // return
  234. // }
  235. //}
  236. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  237. if advice.ID == 0 {
  238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  239. return
  240. }
  241. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  242. if code > 0 {
  243. c.ServeFailJSONWithSGJErrorCode(code)
  244. return
  245. }
  246. advice.Status = 1
  247. advice.UpdatedTime = time.Now().Unix()
  248. advice.UserOrgId = adminUserInfo.Org.Id
  249. advice.Modifier = adminUserInfo.AdminUser.Id
  250. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  251. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  252. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  253. var err error
  254. var isChangeGroup bool
  255. if advice.ParentId == 0 {
  256. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  257. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  258. if len(adviceSlice) == 1 {
  259. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  260. if advice.StartTime == sourceAdvice.StartTime {
  261. err = service.UpdateDoctorAdvice(&advice)
  262. isChangeGroup = false
  263. } else {
  264. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  265. isChangeGroup = false
  266. }
  267. } else if len(adviceSlice) > 1 {
  268. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  269. if advice.StartTime == sourceAdvice.StartTime {
  270. err = service.UpdateDoctorAdvice(&advice)
  271. isChangeGroup = false
  272. } else {
  273. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  274. gruopNo = gruopNo + 1
  275. advice.GroupNo = gruopNo
  276. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  277. isChangeGroup = true
  278. }
  279. }
  280. } else {
  281. isChangeGroup = false
  282. err = service.UpdateDoctorAdvice(&advice)
  283. }
  284. if err != nil {
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  286. return
  287. }
  288. if !isChangeGroup {
  289. c.ServeSuccessJSON(map[string]interface{}{
  290. "msg": "ok",
  291. "advice": advice,
  292. "isChange": isChangeGroup, //方便前端处理数据
  293. })
  294. } else {
  295. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  296. if err != nil {
  297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  298. return
  299. }
  300. c.ServeSuccessJSON(map[string]interface{}{
  301. "msg": "ok",
  302. "advice": newGroupAdvice,
  303. "isChange": isChangeGroup, //方便前端处理数据
  304. })
  305. }
  306. return
  307. }
  308. func (c *PatientApiController) StopDoctorAdvice() {
  309. id, _ := c.GetInt64("id", 0)
  310. if id <= 0 {
  311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  312. return
  313. }
  314. adminUserInfo := c.GetMobileAdminUserInfo()
  315. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  316. if advice.ID == 0 {
  317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  318. return
  319. }
  320. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  321. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  322. // return
  323. //}
  324. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  325. //
  326. //if appRole.UserType == 3 {
  327. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  328. // if getPermissionErr != nil {
  329. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  330. // return
  331. // } else if headNursePermission == nil {
  332. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  333. // return
  334. // }
  335. //}
  336. if advice.StopState == 1 {
  337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  338. return
  339. }
  340. dataBody := make(map[string]interface{}, 0)
  341. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  342. if err != nil {
  343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  344. return
  345. }
  346. timeLayout := "2006-01-02"
  347. loc, _ := time.LoadLocation("Local")
  348. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  349. utils.ErrorLog("stop_time")
  350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  351. return
  352. }
  353. stopTime, _ := dataBody["stop_time"].(string)
  354. if len(stopTime) == 0 {
  355. utils.ErrorLog("len(stop_time) == 0")
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  357. return
  358. }
  359. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  360. if err != nil {
  361. utils.ErrorLog(err.Error())
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  363. return
  364. }
  365. advice.StopTime = theTime.Unix()
  366. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  367. utils.ErrorLog("stop_reason")
  368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  369. return
  370. }
  371. stopReason, _ := dataBody["stop_reason"].(string)
  372. if len(stopReason) == 0 {
  373. utils.ErrorLog("len(stop_reason) == 0")
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  375. return
  376. }
  377. advice.StopReason = stopReason
  378. advice.Status = 1
  379. advice.UpdatedTime = time.Now().Unix()
  380. advice.StopDoctor = adminUserInfo.AdminUser.Id
  381. advice.StopState = 1
  382. advice.StopTime = time.Now().Unix()
  383. advice.Modifier = adminUserInfo.AdminUser.Id
  384. err = service.StopDoctorAdvice(&advice)
  385. if err != nil {
  386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  387. return
  388. }
  389. c.ServeSuccessJSON(map[string]interface{}{
  390. "msg": "ok",
  391. "advice": advice,
  392. })
  393. return
  394. }
  395. func (c *PatientApiController) DeleteDoctorAdvice() {
  396. id, _ := c.GetInt64("id", 0)
  397. if id <= 0 {
  398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  399. return
  400. }
  401. adminUserInfo := c.GetMobileAdminUserInfo()
  402. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  403. if advice.ID == 0 {
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  405. return
  406. }
  407. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  408. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  409. // return
  410. //}
  411. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  412. //
  413. //if appRole.UserType == 3 {
  414. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  415. // if getPermissionErr != nil {
  416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  417. // return
  418. // } else if headNursePermission == nil {
  419. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  420. // return
  421. // }
  422. //}
  423. advice.UpdatedTime = time.Now().Unix()
  424. advice.Status = 0
  425. advice.Modifier = adminUserInfo.AdminUser.Id
  426. err := service.DeleteDoctorAdvice(&advice)
  427. if err != nil {
  428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  429. return
  430. }
  431. c.ServeSuccessJSON(map[string]interface{}{
  432. "msg": "ok",
  433. })
  434. return
  435. }
  436. func (c *PatientApiController) ExecDoctorAdvice() {
  437. execution_time := c.GetString("execution_time")
  438. groupno, _ := c.GetInt64("groupno", -1)
  439. var ids []string
  440. if groupno == 0 {
  441. advice_ids := c.GetString("advice_id")
  442. ids = strings.Split(advice_ids, ",")
  443. }
  444. if groupno < 0 {
  445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  446. return
  447. }
  448. if len(execution_time) <= 0 {
  449. utils.ErrorLog("execution_time")
  450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  451. return
  452. }
  453. timeLayout2 := "2006-01-02 15:04:05"
  454. loc, _ := time.LoadLocation("Local")
  455. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  456. if errs != nil {
  457. utils.ErrorLog(errs.Error())
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. adminUserInfo := c.GetMobileAdminUserInfo()
  462. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  463. //
  464. //if appRole.UserType == 2 || appRole.UserType == 1 {
  465. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  466. // if getPermissionErr != nil {
  467. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  468. // return
  469. // } else if headNursePermission == nil {
  470. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  471. // return
  472. // }
  473. //}
  474. var advice models.DoctorAdvice
  475. if groupno > 0 {
  476. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  477. for _, item := range advices {
  478. if item.ExecutionState == 2 {
  479. advice = item
  480. }
  481. }
  482. } else {
  483. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  484. for _, item := range advices {
  485. if item.ExecutionState == 2 {
  486. advice = item
  487. }
  488. }
  489. }
  490. if advice.ExecutionState == 1 {
  491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  492. return
  493. }
  494. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  496. return
  497. }
  498. fmt.Println(theTime)
  499. fmt.Println(theTime.Unix())
  500. fmt.Println(advice.StartTime)
  501. if advice.StartTime > theTime.Unix() {
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  503. return
  504. }
  505. execution_staff := adminUserInfo.AdminUser.Id
  506. advices := models.DoctorAdvice{
  507. ExecutionStaff: execution_staff,
  508. ExecutionTime: theTime.Unix(),
  509. UpdatedTime: time.Now().Unix(),
  510. }
  511. var err error
  512. if groupno > 0 {
  513. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  514. } else {
  515. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  516. }
  517. if err != nil {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  519. return
  520. }
  521. advice.ExecutionStaff = execution_staff
  522. advice.ExecutionTime = theTime.Unix()
  523. advice.ExecutionState = 1
  524. c.ServeSuccessJSON(map[string]interface{}{
  525. "msg": "ok",
  526. "advice": advice,
  527. "ids": ids,
  528. })
  529. return
  530. }
  531. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  532. execution_time := c.GetString("execution_time")
  533. groupno, _ := c.GetInt64("groupno", -1)
  534. var ids []string
  535. if groupno == 0 {
  536. advice_ids := c.GetString("advice_id")
  537. ids = strings.Split(advice_ids, ",")
  538. }
  539. if groupno < 0 {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. if len(execution_time) <= 0 {
  544. utils.ErrorLog("execution_time")
  545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  546. return
  547. }
  548. timeLayout2 := "2006-01-02 15:04:05"
  549. loc, _ := time.LoadLocation("Local")
  550. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  551. if errs != nil {
  552. utils.ErrorLog(errs.Error())
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  554. return
  555. }
  556. adminUserInfo := c.GetMobileAdminUserInfo()
  557. var advice models.DoctorAdvice
  558. if groupno > 0 {
  559. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  560. for _, item := range advices {
  561. if item.ExecutionState == 1 {
  562. advice = item
  563. }
  564. }
  565. } else {
  566. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  567. for _, item := range advices {
  568. if item.ExecutionState == 1 {
  569. advice = item
  570. }
  571. }
  572. }
  573. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  574. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  575. // if getPermissionErr != nil {
  576. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  577. // return
  578. // } else if headNursePermission == nil {
  579. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  580. // return
  581. // }
  582. //}
  583. if advice.StartTime > theTime.Unix() {
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  585. return
  586. }
  587. advices := models.DoctorAdvice{
  588. ExecutionTime: theTime.Unix(),
  589. UpdatedTime: time.Now().Unix(),
  590. }
  591. var err error
  592. if groupno > 0 {
  593. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  594. } else {
  595. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  596. }
  597. if err != nil {
  598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  599. return
  600. }
  601. advice.ExecutionTime = theTime.Unix()
  602. c.ServeSuccessJSON(map[string]interface{}{
  603. "msg": "ok",
  604. "advice": advice,
  605. "ids": ids,
  606. })
  607. return
  608. }
  609. func (c *PatientApiController) CheckDoctorAdvice() {
  610. groupno, _ := c.GetInt64("groupno", -1)
  611. var ids []string
  612. if groupno == 0 {
  613. advice_ids := c.GetString("advice_id")
  614. ids = strings.Split(advice_ids, ",")
  615. if len(ids) <= 0 {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. }
  619. }
  620. if groupno < 0 {
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  622. return
  623. }
  624. adminUserInfo := c.GetMobileAdminUserInfo()
  625. //
  626. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  627. //if appRole.UserType != 3 {
  628. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  629. // if getPermissionErr != nil {
  630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  631. // return
  632. // } else if headNursePermission == nil {
  633. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  634. // return
  635. // }
  636. //}
  637. var advice models.DoctorAdvice
  638. if groupno > 0 {
  639. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  640. for _, item := range advices {
  641. if item.CheckState == 0 {
  642. advice = item
  643. }
  644. }
  645. if advice.CheckState == 1 {
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  647. return
  648. }
  649. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  651. return
  652. }
  653. } else {
  654. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  655. for _, item := range advices {
  656. if item.CheckState == 0 {
  657. advice = item
  658. }
  659. }
  660. if advice.CheckState == 1 {
  661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  662. return
  663. }
  664. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  666. return
  667. }
  668. }
  669. checker := adminUserInfo.AdminUser.Id
  670. theTime := time.Now()
  671. advices := models.DoctorAdvice{
  672. CheckTime: theTime.Unix(),
  673. Checker: checker,
  674. UpdatedTime: time.Now().Unix(),
  675. }
  676. fmt.Println()
  677. var err error
  678. if groupno > 0 {
  679. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  680. } else {
  681. err = service.BatchCheckOldDoctorAdvice(&advices, ids)
  682. }
  683. if err != nil {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  685. return
  686. }
  687. advice.Checker = checker
  688. advice.CheckTime = theTime.Unix()
  689. advice.CheckState = 1
  690. c.ServeSuccessJSON(map[string]interface{}{
  691. "msg": "ok",
  692. "advice": advice,
  693. })
  694. return
  695. }
  696. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  697. id, _ := c.GetInt64("patient", 0)
  698. assessmentDate := c.GetString("assessment_date", "")
  699. if id <= 0 || len(assessmentDate) != 10 {
  700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  701. return
  702. }
  703. timeLayout := "2006-01-02"
  704. loc, _ := time.LoadLocation("Local")
  705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  706. if err != nil {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. theAssessmentDateTime := theTime.Unix()
  711. adminUserInfo := c.GetMobileAdminUserInfo()
  712. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  713. if patient.ID == 0 {
  714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  715. return
  716. }
  717. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  718. if getPEErr != nil {
  719. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  721. return
  722. }
  723. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  724. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  725. var evaluation models.PredialysisEvaluation
  726. if theEvaluation != nil {
  727. evaluation = *theEvaluation
  728. }
  729. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  730. if code > 0 {
  731. c.ServeFailJSONWithSGJErrorCode(code)
  732. return
  733. }
  734. if theEvaluation == nil {
  735. evaluation.CreatedTime = time.Now().Unix()
  736. evaluation.Status = 1
  737. evaluation.AssessmentDate = theAssessmentDateTime
  738. evaluation.PatientId = id
  739. evaluation.UserOrgId = adminUserInfo.Org.Id
  740. if appRole.UserType == 2 || appRole.UserType == 1 {
  741. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  742. evaluation.AssessmentTime = time.Now().Unix()
  743. } else {
  744. evaluation.Creater = adminUserInfo.AdminUser.Id
  745. }
  746. } else {
  747. evaluation.UpdatedTime = time.Now().Unix()
  748. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  749. if appRole.UserType == 2 || appRole.UserType == 1 {
  750. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  751. evaluation.AssessmentTime = time.Now().Unix()
  752. } else {
  753. evaluation.Modifier = adminUserInfo.AdminUser.Id
  754. if evaluation.Creater == 0 {
  755. evaluation.Creater = adminUserInfo.AdminUser.Id
  756. }
  757. }
  758. }
  759. //新增逻辑
  760. var dewater_amount float64
  761. dewater_amount = 0
  762. if evaluation.DryWeight > 0 {
  763. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  764. if dewater_amount <= 0 {
  765. dewater_amount = 0
  766. }
  767. } else {
  768. dewater_amount = 0
  769. }
  770. // 计算透析处方的相关超滤量
  771. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  772. var lastDialysisPrescribe *models.DialysisPrescription
  773. var dialysisSolution *models.DialysisSolution
  774. var dialysisPrescribe *models.DialysisPrescription
  775. var system_dialysisPrescribe *models.SystemPrescription
  776. var mode_id int64
  777. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  778. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  779. if schedual != nil {
  780. // 获取透析模版
  781. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  782. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  783. mode_id = schedual.ModeId
  784. } else {
  785. // 获取透析模版
  786. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  787. if dialysisPrescribe == nil && dialysisSolution != nil {
  788. mode_id = dialysisSolution.ModeId
  789. }
  790. if dialysisPrescribe == nil && dialysisSolution == nil {
  791. mode_id = 0
  792. }
  793. }
  794. // 插入透析处方
  795. if dialysisPrescribe == nil && dialysisSolution != nil {
  796. var newprescribe models.DialysisPrescription
  797. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  798. newprescribe.PatientId = dialysisSolution.PatientId
  799. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  800. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  801. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  802. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  803. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  804. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  805. newprescribe.ModeId = dialysisSolution.ModeId
  806. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  807. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  808. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  809. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  810. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  811. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  812. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  813. newprescribe.Glucose = dialysisSolution.Glucose
  814. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  815. newprescribe.Kalium = dialysisSolution.Kalium
  816. newprescribe.Sodium = dialysisSolution.Sodium
  817. newprescribe.Calcium = dialysisSolution.Calcium
  818. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  819. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  820. newprescribe.Conductivity = dialysisSolution.Conductivity
  821. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  822. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  823. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  824. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  825. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  826. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  827. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  828. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  829. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  830. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  831. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  832. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  833. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  834. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  835. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  836. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  837. newprescribe.CreatedTime = time.Now().Unix()
  838. newprescribe.UpdatedTime = time.Now().Unix()
  839. newprescribe.RecordDate = theAssessmentDateTime
  840. newprescribe.DewaterAmount = dewater_amount
  841. newprescribe.TargetUltrafiltration = dewater_amount
  842. newprescribe.Status = 1
  843. err := service.AddSigleRecord(&newprescribe)
  844. if err != nil {
  845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  846. }
  847. }
  848. if dialysisPrescribe == nil && dialysisSolution == nil {
  849. if lastDialysisPrescribe != nil {
  850. var newprescribe models.DialysisPrescription
  851. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  852. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  853. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  854. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  855. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  856. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  857. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  858. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  859. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  860. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  861. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  862. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  863. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  864. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  865. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  866. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  867. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  868. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  869. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  870. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  871. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  872. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  873. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  874. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  875. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  876. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  877. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  878. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  879. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  880. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  881. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  882. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  883. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  884. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  885. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  886. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  887. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  888. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  889. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  890. newprescribe.CreatedTime = time.Now().Unix()
  891. newprescribe.UpdatedTime = time.Now().Unix()
  892. newprescribe.RecordDate = theAssessmentDateTime
  893. newprescribe.DewaterAmount = dewater_amount
  894. newprescribe.TargetUltrafiltration = dewater_amount
  895. newprescribe.Status = 1
  896. err := service.AddSigleRecord(&newprescribe)
  897. if err != nil {
  898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  899. }
  900. } else if system_dialysisPrescribe != nil {
  901. var newprescribe models.DialysisPrescription
  902. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  903. newprescribe.PatientId = id
  904. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  905. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  906. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  907. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  908. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  909. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  910. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  911. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  912. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  913. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  914. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  915. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  916. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  917. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  918. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  919. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  920. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  921. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  922. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  923. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  924. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  925. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  926. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  927. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  928. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  929. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  930. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  931. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  932. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  933. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  934. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  935. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  936. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  937. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  938. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  939. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  940. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  941. newprescribe.CreatedTime = time.Now().Unix()
  942. newprescribe.UpdatedTime = time.Now().Unix()
  943. newprescribe.RecordDate = theAssessmentDateTime
  944. newprescribe.DewaterAmount = dewater_amount
  945. newprescribe.TargetUltrafiltration = dewater_amount
  946. newprescribe.Status = 1
  947. err := service.AddSigleRecord(&newprescribe)
  948. if err != nil {
  949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  950. }
  951. } else {
  952. var newprescribe models.DialysisPrescription
  953. newprescribe.UserOrgId = adminUserInfo.Org.Id
  954. newprescribe.PatientId = id
  955. newprescribe.ModeId = mode_id
  956. newprescribe.CreatedTime = time.Now().Unix()
  957. newprescribe.UpdatedTime = time.Now().Unix()
  958. newprescribe.RecordDate = theAssessmentDateTime
  959. newprescribe.DewaterAmount = dewater_amount
  960. newprescribe.TargetUltrafiltration = dewater_amount
  961. newprescribe.Status = 1
  962. err := service.AddSigleRecord(&newprescribe)
  963. if err != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  965. }
  966. }
  967. }
  968. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  969. // if dialysisPrescribe != nil {
  970. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  971. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  972. // dialysisPrescribe.DewaterAmount = dewater_amount
  973. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  974. // dialysisPrescribe.Status = 1
  975. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  976. // if updateErr != nil {
  977. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  978. // }
  979. // }
  980. err = service.UpadatePredialysisEvaluation(&evaluation)
  981. if err != nil {
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  983. return
  984. }
  985. c.ServeSuccessJSON(map[string]interface{}{
  986. "msg": "ok",
  987. "evaluation": evaluation,
  988. })
  989. return
  990. }
  991. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  992. dataBody := make(map[string]interface{}, 0)
  993. err := json.Unmarshal(data, &dataBody)
  994. utils.InfoLog(string(data))
  995. if err != nil {
  996. utils.ErrorLog(err.Error())
  997. code = enums.ErrorCodeParamWrong
  998. return
  999. }
  1000. // if method == "create" {
  1001. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1002. utils.ErrorLog("mode")
  1003. code = enums.ErrorCodeParamWrong
  1004. return
  1005. }
  1006. mode := int64(dataBody["mode"].(float64))
  1007. if mode <= 0 {
  1008. utils.ErrorLog("mode <= 0")
  1009. code = enums.ErrorCodeParamWrong
  1010. return
  1011. }
  1012. solution.ModeId = mode
  1013. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1014. utils.ErrorLog("mode_name")
  1015. code = enums.ErrorCodeParamWrong
  1016. return
  1017. }
  1018. modeName, _ := dataBody["mode_name"].(string)
  1019. if len(modeName) == 0 {
  1020. utils.ErrorLog("len(mode_name) == 0")
  1021. code = enums.ErrorCodeParamWrong
  1022. return
  1023. }
  1024. solution.ModeName = modeName
  1025. solution.Name = modeName
  1026. // }
  1027. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1028. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1029. solution.DialysisDuration = dialysisDuration
  1030. }
  1031. if dataBody["dialysis_duration"] != nil {
  1032. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1033. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1034. solution.DialysisDuration = dialysisDuration
  1035. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1036. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1037. solution.DialysisDuration = dialysisDuration
  1038. }
  1039. }
  1040. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1041. dialyzer := int64(dataBody["dialyzer"].(float64))
  1042. solution.Dialyzer = dialyzer
  1043. }
  1044. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1045. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1046. solution.PerfusionApparatus = perfusionApparatus
  1047. }
  1048. if dataBody["blood_flow_volume"] != nil {
  1049. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1050. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1051. solution.BloodFlowVolume = bloodFlowVolume
  1052. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1053. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1054. solution.BloodFlowVolume = bloodFlowVolume
  1055. }
  1056. }
  1057. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1058. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1059. solution.HemodialysisMachine = hemodialysisMachine
  1060. }
  1061. if dataBody["dewater"] != nil {
  1062. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1063. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1064. solution.Dewater = dewater
  1065. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1066. dewater := dataBody["dewater"].(float64)
  1067. solution.Dewater = dewater
  1068. }
  1069. }
  1070. if dataBody["replacement_total"] != nil {
  1071. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1072. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1073. solution.ReplacementTotal = replacementTotal
  1074. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1075. replacementTotal := dataBody["replacement_total"].(float64)
  1076. solution.ReplacementTotal = replacementTotal
  1077. }
  1078. }
  1079. if dataBody["displace_liqui"] != nil {
  1080. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1081. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1082. solution.DisplaceLiqui = displaceLiqui
  1083. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1084. displaceLiqui := dataBody["displace_liqui"].(float64)
  1085. solution.DisplaceLiqui = displaceLiqui
  1086. }
  1087. }
  1088. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1089. replacementWay := int64(dataBody["replacement_way"].(float64))
  1090. solution.ReplacementWay = replacementWay
  1091. }
  1092. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1093. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1094. solution.Anticoagulant = anticoagulant
  1095. }
  1096. if dataBody["anticoagulant_shouji"] != nil {
  1097. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1098. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1099. solution.AnticoagulantShouji = anticoagulantShouji
  1100. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1101. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1102. solution.AnticoagulantShouji = anticoagulantShouji
  1103. }
  1104. }
  1105. if dataBody["anticoagulant_weichi"] != nil {
  1106. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1107. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1108. solution.AnticoagulantWeichi = anticoagulantWeichi
  1109. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1110. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1111. solution.AnticoagulantWeichi = anticoagulantWeichi
  1112. }
  1113. }
  1114. if dataBody["anticoagulant_zongliang"] != nil {
  1115. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1116. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1117. solution.AnticoagulantZongliang = anticoagulantZongliang
  1118. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1119. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1120. solution.AnticoagulantZongliang = anticoagulantZongliang
  1121. }
  1122. }
  1123. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1124. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1125. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1126. }
  1127. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1128. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1129. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1130. }
  1131. if dataBody["kalium"] != nil {
  1132. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1133. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1134. solution.Kalium = kalium
  1135. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1136. kalium := dataBody["kalium"].(float64)
  1137. solution.Kalium = kalium
  1138. }
  1139. }
  1140. if dataBody["sodium"] != nil {
  1141. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1142. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1143. solution.Sodium = sodium
  1144. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1145. sodium := dataBody["sodium"].(float64)
  1146. solution.Sodium = sodium
  1147. }
  1148. }
  1149. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1150. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1151. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1152. solution.Calcium = calcium
  1153. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1154. calcium := dataBody["calcium"].(float64)
  1155. solution.Calcium = calcium
  1156. }
  1157. }
  1158. if dataBody["bicarbonate"] != nil {
  1159. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1160. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1161. solution.Bicarbonate = bicarbonate
  1162. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1163. bicarbonate := dataBody["bicarbonate"].(float64)
  1164. solution.Bicarbonate = bicarbonate
  1165. }
  1166. }
  1167. if dataBody["glucose"] != nil {
  1168. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1169. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1170. solution.Glucose = glucose
  1171. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1172. glucose := dataBody["glucose"].(float64)
  1173. solution.Glucose = glucose
  1174. }
  1175. }
  1176. // if dataBody["dry_weight"] != nil {
  1177. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1178. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1179. // solution.DryWeight = dryWeight
  1180. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1181. // dryWeight := dataBody["dry_weight"].(float64)
  1182. // solution.DryWeight = dryWeight
  1183. // }
  1184. // }
  1185. if dataBody["dialysate_flow"] != nil {
  1186. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1187. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1188. solution.DialysateFlow = dialysateFlow
  1189. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1190. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1191. solution.DialysateFlow = dialysateFlow
  1192. }
  1193. }
  1194. if dataBody["dialysate_temperature"] != nil {
  1195. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1196. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1197. solution.DialysateTemperature = dialysateTemperature
  1198. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1199. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1200. solution.DialysateTemperature = dialysateTemperature
  1201. }
  1202. }
  1203. if dataBody["conductivity"] != nil {
  1204. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1205. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1206. solution.Conductivity = conductivity
  1207. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1208. conductivity := dataBody["conductivity"].(float64)
  1209. solution.Conductivity = conductivity
  1210. }
  1211. }
  1212. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1213. remark := dataBody["remark"].(string)
  1214. solution.Remark = remark
  1215. }
  1216. if dataBody["dialysis_duration_hour"] != nil {
  1217. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1218. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1219. solution.DialysisDurationHour = dialysisDurationHour
  1220. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1221. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1222. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1223. }
  1224. }
  1225. if dataBody["dialysis_duration_minute"] != nil {
  1226. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1227. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1228. solution.DialysisDurationMinute = dialysisDurationMinute
  1229. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1230. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1231. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1232. }
  1233. }
  1234. if dataBody["target_ultrafiltration"] != nil {
  1235. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1236. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1237. solution.TargetUltrafiltration = targetUltrafiltration
  1238. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1239. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1240. solution.TargetUltrafiltration = targetUltrafiltration
  1241. }
  1242. }
  1243. if dataBody["dialysate_formulation"] != nil {
  1244. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1245. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1246. solution.DialysateFormulation = dialysateFormulation
  1247. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1248. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1249. solution.DialysateFormulation = int64(dialysateFormulation)
  1250. }
  1251. }
  1252. return
  1253. }
  1254. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1255. dataBody := make(map[string]interface{}, 0)
  1256. err := json.Unmarshal(data, &dataBody)
  1257. utils.InfoLog(string(data))
  1258. if err != nil {
  1259. utils.ErrorLog(err.Error())
  1260. code = enums.ErrorCodeParamWrong
  1261. return
  1262. }
  1263. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1264. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1265. evaluation.WeightBefore = weightVefore
  1266. }
  1267. // fmt.Println(dataBody["dry_weight"])
  1268. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1269. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1270. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1271. fmt.Println(additionalWeight)
  1272. evaluation.DryWeight = additionalWeight
  1273. }
  1274. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1275. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1276. fmt.Println(additionalWeight)
  1277. evaluation.AdditionalWeight = additionalWeight
  1278. }
  1279. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1280. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1281. evaluation.Temperature = Temperature
  1282. }
  1283. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1284. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  1285. evaluation.SystolicBloodPressure = systolicBloodPressure
  1286. }
  1287. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  1288. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  1289. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  1290. }
  1291. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  1292. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  1293. evaluation.PulseFrequency = pulseFrequency
  1294. }
  1295. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  1296. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  1297. evaluation.BreathingRate = breathingRate
  1298. }
  1299. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  1300. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  1301. evaluation.LastPostDialysis = lastPostDialysis
  1302. }
  1303. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  1304. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  1305. evaluation.DialysisInterphase = dialysisInterphase
  1306. }
  1307. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  1308. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  1309. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  1310. }
  1311. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  1312. catheter, _ := dataBody["catheter"].(string)
  1313. evaluation.Catheter = catheter
  1314. }
  1315. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  1316. catheter_bend := int(dataBody["catheter_bend"].(float64))
  1317. evaluation.CatheterBend = catheter_bend
  1318. }
  1319. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  1320. Complication, _ := dataBody["complication"].(string)
  1321. evaluation.Complication = Complication
  1322. }
  1323. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1324. remark := dataBody["remark"].(string)
  1325. evaluation.Remark = remark
  1326. }
  1327. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  1328. machine_type := dataBody["machine_type"].(string)
  1329. evaluation.MachineType = machine_type
  1330. }
  1331. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  1332. blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  1333. evaluation.BloodAccessPartId = blood_access_part_id
  1334. }
  1335. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  1336. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  1337. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  1338. }
  1339. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  1340. internal_fistula, _ := dataBody["internal_fistula"].(string)
  1341. evaluation.InternalFistula = internal_fistula
  1342. }
  1343. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  1344. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  1345. evaluation.InternalFistulaSkin = internal_fistula_skin
  1346. }
  1347. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  1348. is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  1349. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  1350. is_hemorrhage = 0
  1351. }
  1352. evaluation.IsHemorrhage = is_hemorrhage
  1353. if is_hemorrhage == 1 {
  1354. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  1355. hemorrhage, _ := dataBody["hemorrhage"].(string)
  1356. evaluation.Hemorrhage = hemorrhage
  1357. }
  1358. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  1359. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  1360. evaluation.HemorrhageOther = hemorrhage_other
  1361. }
  1362. }
  1363. } else {
  1364. evaluation.IsHemorrhage = 0
  1365. }
  1366. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  1367. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  1368. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  1369. }
  1370. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  1371. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  1372. evaluation.InternalFistulaOther = internal_fistula_other
  1373. }
  1374. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  1375. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  1376. evaluation.BloodAccessNoise = blood_access_noise
  1377. }
  1378. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "float64" {
  1379. puncture_way := int64(dataBody["puncture_way"].(float64))
  1380. evaluation.PunctureWay = puncture_way
  1381. }
  1382. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  1383. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  1384. evaluation.VenousCatheterization = venous_catheterization
  1385. }
  1386. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  1387. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  1388. evaluation.VenousCatheterizationPart = venous_catheterization_part
  1389. }
  1390. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  1391. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  1392. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  1393. }
  1394. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  1395. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  1396. evaluation.DuctusArantii = ductus_arantii
  1397. }
  1398. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  1399. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  1400. evaluation.EmergencyTreatment = emergency_treatment
  1401. }
  1402. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  1403. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  1404. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  1405. }
  1406. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  1407. dialysis_count, _ := dataBody["dialysis_count"].(string)
  1408. count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  1409. evaluation.DialysisCount = count
  1410. }
  1411. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  1412. is_infect, _ := dataBody["is_infect"].(string)
  1413. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  1414. evaluation.IsInfect = infect
  1415. }
  1416. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  1417. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  1418. evaluation.Exposed = exposed
  1419. }
  1420. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  1421. skin, _ := dataBody["skin"].(string)
  1422. skins, _ := strconv.ParseInt(skin, 10, 64)
  1423. evaluation.Skin = skins
  1424. }
  1425. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  1426. skin_other, _ := dataBody["skin_other"].(string)
  1427. evaluation.SkinOther = skin_other
  1428. }
  1429. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  1430. infect_other, _ := dataBody["infect_other"].(string)
  1431. evaluation.InfectOther = infect_other
  1432. }
  1433. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  1434. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  1435. evaluation.DuctusArantiiOther = ductus_arantii_other
  1436. }
  1437. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  1438. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  1439. evaluation.PunctureNeedle = punctureNeedle
  1440. }
  1441. return
  1442. }
  1443. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1444. dataBody := make(map[string]interface{}, 0)
  1445. err := json.Unmarshal(data, &dataBody)
  1446. if err != nil {
  1447. utils.ErrorLog(err.Error())
  1448. code = enums.ErrorCodeParamWrong
  1449. return
  1450. }
  1451. timeLayout := "2006-01-02"
  1452. loc, _ := time.LoadLocation("Local")
  1453. isChild := false
  1454. if action == "create" {
  1455. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1456. utils.ErrorLog("advice_type")
  1457. code = enums.ErrorCodeParamWrong
  1458. return
  1459. }
  1460. adviceType := int64(dataBody["advice_type"].(float64))
  1461. if adviceType != 1 && adviceType != 2 {
  1462. utils.ErrorLog("advice_type != 1&&2")
  1463. code = enums.ErrorCodeParamWrong
  1464. return
  1465. }
  1466. advice.AdviceType = adviceType
  1467. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1468. utils.ErrorLog("advice_date")
  1469. code = enums.ErrorCodeParamWrong
  1470. return
  1471. }
  1472. adviceDate, _ := dataBody["advice_date"].(string)
  1473. if len(adviceDate) == 0 {
  1474. utils.ErrorLog("len(adviceDate) == 0")
  1475. code = enums.ErrorCodeParamWrong
  1476. return
  1477. }
  1478. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1479. if err != nil {
  1480. utils.ErrorLog(err.Error())
  1481. code = enums.ErrorCodeParamWrong
  1482. return
  1483. }
  1484. advice.AdviceDate = theTime.Unix()
  1485. advice.RecordDate = theTime.Unix()
  1486. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  1487. parentId := int64(dataBody["parent_id"].(float64))
  1488. advice.ParentId = parentId
  1489. if parentId > 0 {
  1490. isChild = true
  1491. }
  1492. }
  1493. } else {
  1494. isChild = advice.ParentId > 0
  1495. }
  1496. if !isChild {
  1497. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1498. utils.ErrorLog("start_time")
  1499. code = enums.ErrorCodeParamWrong
  1500. return
  1501. }
  1502. startTime, _ := dataBody["start_time"].(string)
  1503. fmt.Println(startTime)
  1504. if len(startTime) == 0 {
  1505. utils.ErrorLog("len(start_time) == 0")
  1506. code = enums.ErrorCodeParamWrong
  1507. return
  1508. }
  1509. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1510. if err != nil {
  1511. utils.ErrorLog(err.Error())
  1512. code = enums.ErrorCodeParamWrong
  1513. return
  1514. }
  1515. advice.StartTime = theTime.Unix()
  1516. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1517. deliveryWay, _ := dataBody["delivery_way"].(string)
  1518. advice.DeliveryWay = deliveryWay
  1519. }
  1520. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1521. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1522. advice.ExecutionFrequency = executionFrequency
  1523. }
  1524. }
  1525. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1526. deliveryWay, _ := dataBody["delivery_way"].(string)
  1527. advice.DeliveryWay = deliveryWay
  1528. }
  1529. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1530. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1531. advice.ExecutionFrequency = executionFrequency
  1532. }
  1533. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1534. utils.ErrorLog("advice_name")
  1535. code = enums.ErrorCodeParamWrong
  1536. return
  1537. }
  1538. adviceName, _ := dataBody["advice_name"].(string)
  1539. if len(adviceName) == 0 {
  1540. utils.ErrorLog("len(advice_name) == 0")
  1541. code = enums.ErrorCodeParamWrong
  1542. return
  1543. }
  1544. advice.AdviceName = adviceName
  1545. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  1546. adviceDsc, _ := dataBody["advice_desc"].(string)
  1547. advice.AdviceDesc = adviceDsc
  1548. }
  1549. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  1550. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  1551. advice.SingleDose = singleDose
  1552. }
  1553. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  1554. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  1555. advice.SingleDoseUnit = singleDoseUnit
  1556. }
  1557. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  1558. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  1559. advice.DrugSpec = drugSpec
  1560. }
  1561. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  1562. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  1563. advice.DrugSpecUnit = drugSpecUnit
  1564. }
  1565. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  1566. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  1567. advice.PrescribingNumber = prescribingNumber
  1568. }
  1569. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  1570. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  1571. advice.PrescribingNumberUnit = prescribingNumberUnit
  1572. }
  1573. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1574. remark, _ := dataBody["remark"].(string)
  1575. advice.Remark = remark
  1576. }
  1577. return
  1578. }
  1579. func (c *PatientApiController) GetPatientEducation() {
  1580. patientID, _ := c.GetInt64("patient_id", 0)
  1581. page, _ := c.GetInt64("page", 0)
  1582. limit, _ := c.GetInt64("limit", 0)
  1583. startTime := c.GetString("start_time", "")
  1584. endTime := c.GetString("end_time", "")
  1585. if page <= 0 {
  1586. page = 1
  1587. }
  1588. if limit <= 0 {
  1589. limit = 10
  1590. }
  1591. if patientID <= 0 {
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. timeLayout := "2006-01-02"
  1596. loc, _ := time.LoadLocation("Local")
  1597. var theStartTIme int64
  1598. if len(startTime) > 0 {
  1599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1600. if err != nil {
  1601. theStartTIme = 0
  1602. }
  1603. theStartTIme = theTime.Unix()
  1604. }
  1605. var theEndtTIme int64
  1606. if len(endTime) > 0 {
  1607. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1608. if err != nil {
  1609. theEndtTIme = 0
  1610. }
  1611. theEndtTIme = theTime.Unix()
  1612. }
  1613. adminUserInfo := c.GetMobileAdminUserInfo()
  1614. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  1615. c.ServeSuccessJSON(map[string]interface{}{
  1616. "total": total,
  1617. "edus": edus,
  1618. })
  1619. return
  1620. }
  1621. func (c *PatientApiController) GetPatientSchedulesList() {
  1622. patientID, _ := c.GetInt64("patient_id", 0)
  1623. page, _ := c.GetInt64("page", 0)
  1624. limit, _ := c.GetInt64("limit", 0)
  1625. if patientID <= 0 {
  1626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1627. return
  1628. }
  1629. adminUserInfo := c.GetMobileAdminUserInfo()
  1630. todayTime := time.Now().Format("2006-01-02")
  1631. timeLayout := "2006-01-02 15:04:05"
  1632. loc, _ := time.LoadLocation("Local")
  1633. var theStartTime int64
  1634. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  1635. theStartTime = theTime.Unix()
  1636. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  1637. if len(schedules) > 0 {
  1638. for index, item := range schedules {
  1639. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  1640. schedules[index].Week = int64(week)
  1641. }
  1642. }
  1643. c.ServeSuccessJSON(map[string]interface{}{
  1644. "schedules": schedules,
  1645. })
  1646. return
  1647. }
  1648. func (c *PatientApiController) GetRecords() {
  1649. patientID, _ := c.GetInt64("patient_id", 0)
  1650. page, _ := c.GetInt64("page", 0)
  1651. limit, _ := c.GetInt64("limit", 0)
  1652. startTime := c.GetString("start_time", "")
  1653. endTime := c.GetString("end_time", "")
  1654. mode_id, _ := c.GetInt64("mode_id", 0)
  1655. if page <= 0 {
  1656. page = 1
  1657. }
  1658. if limit <= 0 {
  1659. limit = 10
  1660. }
  1661. if patientID <= 0 {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1663. return
  1664. }
  1665. timeLayout := "2006-01-02"
  1666. loc, _ := time.LoadLocation("Local")
  1667. var theStartTIme int64
  1668. if len(startTime) > 0 {
  1669. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1670. if err != nil {
  1671. theStartTIme = 0
  1672. }
  1673. theStartTIme = theTime.Unix()
  1674. }
  1675. var theEndtTIme int64
  1676. if len(endTime) > 0 {
  1677. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1678. if err != nil {
  1679. theEndtTIme = 0
  1680. }
  1681. theEndtTIme = theTime.Unix()
  1682. }
  1683. adminUserInfo := c.GetMobileAdminUserInfo()
  1684. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  1685. c.ServeSuccessJSON(map[string]interface{}{
  1686. "total": total,
  1687. "records": records,
  1688. })
  1689. return
  1690. }
  1691. func (c *PatientApiController) GetPatientMonitor() {
  1692. partition, _ := c.GetInt64("partition")
  1693. monitorDate := c.GetString("date")
  1694. timeLayout := "2006-01-02"
  1695. loc, _ := time.LoadLocation("Local")
  1696. var theStartTime int64
  1697. if len(monitorDate) > 0 {
  1698. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  1699. if err != nil {
  1700. theStartTime = 0
  1701. }
  1702. theStartTime = theTime.Unix()
  1703. }
  1704. adminInfo := c.GetMobileAdminUserInfo()
  1705. orgID := adminInfo.Org.Id
  1706. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition)
  1707. if err == nil {
  1708. c.ServeSuccessJSON(map[string]interface{}{
  1709. "monitor": monitor,
  1710. })
  1711. } else {
  1712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1713. }
  1714. }
  1715. // /m/api/monitor/patient [get] 搜索病人的测量记录
  1716. // @param keyword:string 病人姓名或透析号
  1717. // @param page:int
  1718. func (this *PatientApiController) SearchMonitorPatient() {
  1719. keyword := this.GetString("keyword")
  1720. page, _ := this.GetInt("page")
  1721. if page <= 0 {
  1722. page = 1
  1723. }
  1724. if len(keyword) == 0 {
  1725. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1726. return
  1727. }
  1728. adminUserInfo := this.GetMobileAdminUserInfo()
  1729. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  1730. if getMonitorErr != nil {
  1731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1732. return
  1733. } else {
  1734. this.ServeSuccessJSON(map[string]interface{}{
  1735. "monitor": monitors,
  1736. })
  1737. }
  1738. }
  1739. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1740. id, _ := c.GetInt64("id", 0)
  1741. page, _ := c.GetInt64("page", 0)
  1742. limit, _ := c.GetInt64("limit", 0)
  1743. if id <= 0 {
  1744. c.ServeSuccessJSON(map[string]interface{}{
  1745. "solutions": nil,
  1746. })
  1747. return
  1748. }
  1749. if page <= 0 {
  1750. page = 1
  1751. }
  1752. if limit <= 0 {
  1753. limit = 10
  1754. }
  1755. adminInfo := c.GetMobileAdminUserInfo()
  1756. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  1757. c.ServeSuccessJSON(map[string]interface{}{
  1758. "solutions": solutions,
  1759. "total": total,
  1760. })
  1761. return
  1762. }
  1763. //GetDoctorAdvices 医嘱列表
  1764. func (c *PatientApiController) GetDoctorAdvices() {
  1765. id, _ := c.GetInt64("id", 0)
  1766. adviceType, _ := c.GetInt64("advice_type", 0)
  1767. stopType, _ := c.GetInt64("stop_state", 0)
  1768. startTime := c.GetString("start_time", "")
  1769. endTime := c.GetString("end_time", "")
  1770. keywords := c.GetString("keywords", "")
  1771. need, _ := c.GetInt64("need_doctor", 0)
  1772. adminUserInfo := c.GetMobileAdminUserInfo()
  1773. timeLayout := "2006-01-02"
  1774. loc, _ := time.LoadLocation("Local")
  1775. var theStartTIme int64
  1776. if len(startTime) > 0 {
  1777. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1778. if err != nil {
  1779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1780. return
  1781. }
  1782. theStartTIme = theTime.Unix()
  1783. }
  1784. var theEndtTIme int64
  1785. if len(endTime) > 0 {
  1786. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1787. if err != nil {
  1788. utils.ErrorLog(err.Error())
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. theEndtTIme = theTime.Unix()
  1793. }
  1794. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  1795. if need == 1 {
  1796. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1797. c.ServeSuccessJSON(map[string]interface{}{
  1798. "advices": advices,
  1799. "total": total,
  1800. "users": users,
  1801. })
  1802. } else {
  1803. c.ServeSuccessJSON(map[string]interface{}{
  1804. "advices": advices,
  1805. "total": total,
  1806. "users": []string{},
  1807. })
  1808. }
  1809. return
  1810. }
  1811. func (c *PatientApiController) GetPrintDialysisOrder() {
  1812. xtno := c.GetString("xtno")
  1813. xtdate := c.GetString("xtdate")
  1814. timeLayout := "2006-01-02"
  1815. loc, _ := time.LoadLocation("Local")
  1816. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  1817. if err != nil {
  1818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1819. return
  1820. }
  1821. xttime := theTime.Unix()
  1822. operatorIDs := make([]int64, 0)
  1823. adminUserInfo := c.GetMobileAdminUserInfo()
  1824. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1825. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  1826. //透析单
  1827. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1828. if dialysisOrder != nil {
  1829. if dialysisOrder.FinishNurse > 0 {
  1830. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  1831. }
  1832. if dialysisOrder.StartNurse > 0 {
  1833. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  1834. }
  1835. }
  1836. //透前评估
  1837. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1838. //透后评估
  1839. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1840. if AssessmentAfterDislysis.Modifier > 0 {
  1841. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  1842. }
  1843. //透析处方
  1844. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1845. if dialysisPrescription.PrescriptionDoctor > 0 {
  1846. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  1847. }
  1848. //临时医嘱
  1849. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1850. if len(DoctorAdvice) > 0 {
  1851. for _, item := range DoctorAdvice {
  1852. if item.AdviceDoctor > 0 {
  1853. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  1854. }
  1855. if item.ExecutionStaff > 0 {
  1856. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  1857. }
  1858. if item.Checker > 0 {
  1859. operatorIDs = append(operatorIDs, item.Checker)
  1860. }
  1861. }
  1862. }
  1863. //透析监测
  1864. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1865. //透析小结
  1866. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1867. //接诊评估
  1868. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1869. //相关操作对应的操作人
  1870. operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  1871. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1872. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1873. c.ServeSuccessJSON(map[string]interface{}{
  1874. "users": adminUser,
  1875. "patientInfo": patientInfo,
  1876. "PredialysisEvaluation": PredialysisEvaluation,
  1877. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  1878. "dialysisPrescription": dialysisPrescription,
  1879. "advices": DoctorAdvice,
  1880. "monitors": Record,
  1881. "summary": TreatmentSummary,
  1882. "receiverTreatmentAccess": receiverTreatmentAccess,
  1883. "dialysisOrder": dialysisOrder,
  1884. "operators": operators,
  1885. "org_template_info": templateInfo,
  1886. "check": check,
  1887. })
  1888. }
  1889. func (c *PatientApiController) CreateGroupAdvice() {
  1890. patient, _ := c.GetInt64("id", 0)
  1891. if patient <= 0 {
  1892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1893. return
  1894. }
  1895. adminUserInfo := c.GetMobileAdminUserInfo()
  1896. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  1897. if patientInfo.ID == 0 {
  1898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1899. return
  1900. }
  1901. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1902. //if appRole.UserType == 3{
  1903. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  1904. // return
  1905. //}
  1906. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1907. //if appRole.UserType == 3 {
  1908. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1909. // if getPermissionErr != nil {
  1910. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1911. // return
  1912. // } else if headNursePermission == nil {
  1913. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1914. // return
  1915. // }
  1916. //}
  1917. //TODO根据路由做权限
  1918. group_no, _ := c.GetInt64("group_no")
  1919. if group_no <= 0 {
  1920. group_no = 0
  1921. }
  1922. dataBody := make(map[string]interface{}, 0)
  1923. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1924. if err != nil {
  1925. utils.ErrorLog(err.Error())
  1926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1927. return
  1928. }
  1929. timeLayout := "2006-01-02"
  1930. loc, _ := time.LoadLocation("Local")
  1931. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1932. utils.ErrorLog("advice_type")
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1934. return
  1935. }
  1936. adviceType := int64(dataBody["advice_type"].(float64))
  1937. if adviceType != 1 && adviceType != 2 {
  1938. utils.ErrorLog("advice_type != 1&&2")
  1939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1940. return
  1941. }
  1942. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1943. utils.ErrorLog("advice_date")
  1944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1945. return
  1946. }
  1947. adviceDate, _ := dataBody["advice_date"].(string)
  1948. if len(adviceDate) == 0 {
  1949. utils.ErrorLog("len(adviceDate) == 0")
  1950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1951. return
  1952. }
  1953. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1954. if err != nil {
  1955. utils.ErrorLog(err.Error())
  1956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1957. return
  1958. }
  1959. AdviceDate := theTime.Unix()
  1960. RecordDate := theTime.Unix()
  1961. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1962. utils.ErrorLog("start_time")
  1963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1964. return
  1965. }
  1966. startTime, _ := dataBody["start_time"].(string)
  1967. if len(startTime) == 0 {
  1968. utils.ErrorLog("len(start_time) == 0")
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1973. if err != nil {
  1974. utils.ErrorLog(err.Error())
  1975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1976. return
  1977. }
  1978. StartTime := theTime.Unix()
  1979. Remark := ""
  1980. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1981. remark, _ := dataBody["remark"].(string)
  1982. Remark = remark
  1983. }
  1984. var advices []*models.GroupAdvice
  1985. // utils.TraceLog("%+v", dataBody["adviceNames"])
  1986. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1987. utils.ErrorLog("adviceNames")
  1988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1989. return
  1990. }
  1991. adviceNames := dataBody["adviceNames"].([]interface{})
  1992. for _, adviceNameMap := range adviceNames {
  1993. adviceNameM := adviceNameMap.(map[string]interface{})
  1994. var advice models.GroupAdvice
  1995. advice.Remark = Remark
  1996. advice.AdviceType = adviceType
  1997. advice.StartTime = StartTime
  1998. advice.AdviceDate = AdviceDate
  1999. advice.RecordDate = RecordDate
  2000. advice.Status = 1
  2001. advice.CreatedTime = time.Now().Unix()
  2002. advice.UpdatedTime = time.Now().Unix()
  2003. advice.StopState = 2
  2004. advice.ExecutionState = 2
  2005. advice.UserOrgId = adminUserInfo.Org.Id
  2006. advice.PatientId = patientInfo.ID
  2007. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2008. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2009. if errcode > 0 {
  2010. c.ServeFailJSONWithSGJErrorCode(errcode)
  2011. return
  2012. }
  2013. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2014. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2015. if len(subdrugs) > 0 {
  2016. for _, subdrug := range subdrugs {
  2017. var s models.GroupAdvice
  2018. s.Remark = Remark
  2019. s.AdviceType = adviceType
  2020. s.StartTime = StartTime
  2021. s.AdviceDate = AdviceDate
  2022. s.RecordDate = RecordDate
  2023. s.Status = 1
  2024. s.CreatedTime = time.Now().Unix()
  2025. s.UpdatedTime = time.Now().Unix()
  2026. s.StopState = 2
  2027. s.ExecutionState = 2
  2028. s.UserOrgId = adminUserInfo.Org.Id
  2029. s.PatientId = patientInfo.ID
  2030. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2031. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2032. if errcode > 0 {
  2033. c.ServeFailJSONWithSGJErrorCode(errcode)
  2034. return
  2035. }
  2036. advice.Children = append(advice.Children, &s)
  2037. }
  2038. }
  2039. }
  2040. advices = append(advices, &advice)
  2041. }
  2042. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  2043. if createErr != nil {
  2044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2045. return
  2046. }
  2047. c.ServeSuccessJSON(map[string]interface{}{
  2048. "msg": "ok",
  2049. "advices": newAdvices,
  2050. })
  2051. return
  2052. }
  2053. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  2054. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  2055. utils.ErrorLog("advice_name")
  2056. return enums.ErrorCodeParamWrong
  2057. }
  2058. adviceName, _ := json["advice_name"].(string)
  2059. if len(adviceName) == 0 {
  2060. utils.ErrorLog("len(advice_name) == 0")
  2061. return enums.ErrorCodeParamWrong
  2062. }
  2063. advice.AdviceName = adviceName
  2064. adviceDesc, _ := json["advice_desc"].(string)
  2065. advice.AdviceDesc = adviceDesc
  2066. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2067. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2068. advice.DrugSpec = drugSpec
  2069. }
  2070. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2071. remark, _ := json["remark"].(string)
  2072. advice.Remark = remark
  2073. }
  2074. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  2075. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  2076. advice.DrugSpecUnit = drugSpecUnit
  2077. }
  2078. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2079. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2080. advice.SingleDose = singleDose
  2081. }
  2082. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2083. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2084. advice.SingleDoseUnit = singleDoseUnit
  2085. }
  2086. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2087. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2088. advice.PrescribingNumber = prescribingNumber
  2089. }
  2090. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2091. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2092. advice.PrescribingNumberUnit = prescribingNumberUnit
  2093. }
  2094. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2095. deliveryWay, _ := json["delivery_way"].(string)
  2096. advice.DeliveryWay = deliveryWay
  2097. }
  2098. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2099. executionFrequency, _ := json["execution_frequency"].(string)
  2100. advice.ExecutionFrequency = executionFrequency
  2101. }
  2102. return 0
  2103. }
  2104. func (c *PatientApiController) DelDoctorAdvice() {
  2105. groupno, _ := c.GetInt64("groupno", -1)
  2106. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  2107. if is_sub == 1 { //是
  2108. advice_id, _ := c.GetInt64("advice_id")
  2109. adminUserInfo := c.GetMobileAdminUserInfo()
  2110. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2111. if advice.ID == 0 {
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2113. return
  2114. }
  2115. //TODO 根据路由来做权限
  2116. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2117. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2118. // return
  2119. //}
  2120. advice.Status = 0
  2121. advice.UpdatedTime = time.Now().Unix()
  2122. advice.Modifier = adminUserInfo.AdminUser.Id
  2123. err := service.DeleteDoctorAdvice(&advice)
  2124. if err != nil {
  2125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2126. return
  2127. }
  2128. c.ServeSuccessJSON(map[string]interface{}{
  2129. "msg": "ok",
  2130. })
  2131. return
  2132. } else { //
  2133. var ids []string
  2134. if groupno == 0 {
  2135. advice_id := c.GetString("advice_id")
  2136. ids = strings.Split(advice_id, ",")
  2137. if len(ids) <= 0 {
  2138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2139. return
  2140. }
  2141. }
  2142. if groupno < 0 {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2144. return
  2145. }
  2146. adminUserInfo := c.GetMobileAdminUserInfo()
  2147. var advice models.DoctorAdvice
  2148. if groupno > 0 {
  2149. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2150. if advice.ID == 0 {
  2151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2152. return
  2153. }
  2154. } else {
  2155. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2156. for _, item := range advices {
  2157. if item.ID == 0 {
  2158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2159. return
  2160. }
  2161. }
  2162. }
  2163. advice.UpdatedTime = time.Now().Unix()
  2164. advice.Status = 0
  2165. advice.GroupNo = groupno
  2166. var err error
  2167. if groupno > 0 {
  2168. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  2169. } else {
  2170. err = service.BatchDeleteDoctorAdvice(ids)
  2171. }
  2172. if err != nil {
  2173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2174. return
  2175. }
  2176. c.ServeSuccessJSON(map[string]interface{}{
  2177. "msg": "ok",
  2178. })
  2179. return
  2180. }
  2181. }
  2182. // /m/api/advice/group/modify_starttime [post]
  2183. // @param group_no:int
  2184. // @param start_time:string yyyy-MM-dd hh:mm:ss
  2185. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  2186. group_no, _ := this.GetInt64("group_no")
  2187. start_time_str := this.GetString("start_time")
  2188. if group_no <= 0 || len(start_time_str) == 0 {
  2189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2190. return
  2191. }
  2192. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  2193. if parseTimeErr != nil {
  2194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  2195. return
  2196. }
  2197. adminUserInfo := this.GetMobileAdminUserInfo()
  2198. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  2199. if updateStartTimeErr != nil {
  2200. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  2201. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2202. return
  2203. }
  2204. this.ServeSuccessJSON(map[string]interface{}{
  2205. "start_time": startTime.Unix(),
  2206. })
  2207. }
  2208. func (this *PatientApiController) DelSubDoctorAdvice() {
  2209. advice_id, _ := this.GetInt64("advice_id")
  2210. adminUserInfo := this.GetMobileAdminUserInfo()
  2211. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2212. if advice.ID == 0 {
  2213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2214. return
  2215. }
  2216. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2217. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  2218. // return
  2219. //}
  2220. advice.Status = 0
  2221. advice.UpdatedTime = time.Now().Unix()
  2222. advice.Modifier = adminUserInfo.AdminUser.Id
  2223. err := service.DeleteDoctorAdvice(&advice)
  2224. if err != nil {
  2225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2226. return
  2227. }
  2228. this.ServeSuccessJSON(map[string]interface{}{
  2229. "msg": "ok",
  2230. })
  2231. return
  2232. }
  2233. func (this *PatientApiController) GetAdviceUnReadMessage() {
  2234. //adminUserInfo := this.GetMobileAdminUserInfo()
  2235. //service.FindUnReadDoctorAdviceMessage()
  2236. }
  2237. func (this *PatientApiController) GetPatientsByKeyWord() {
  2238. keyWord := this.GetString("keyword")
  2239. adminUserInfo := this.GetMobileAdminUserInfo()
  2240. today := utils.ZeroHourTimeOfDay(time.Now())
  2241. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  2242. if err != nil {
  2243. utils.ErrorLog(err.Error())
  2244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2245. return
  2246. }
  2247. this.ServeSuccessJSON(map[string]interface{}{
  2248. "patient": patient,
  2249. })
  2250. }