patient_api_controller.go 91KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681
  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. advice.Modifier = adminUserInfo.AdminUser.Id
  525. c.ServeSuccessJSON(map[string]interface{}{
  526. "msg": "ok",
  527. "advice": advice,
  528. "ids": ids,
  529. })
  530. return
  531. }
  532. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  533. execution_time := c.GetString("execution_time")
  534. groupno, _ := c.GetInt64("groupno", -1)
  535. var ids []string
  536. if groupno == 0 {
  537. advice_ids := c.GetString("advice_id")
  538. ids = strings.Split(advice_ids, ",")
  539. }
  540. if groupno < 0 {
  541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  542. return
  543. }
  544. if len(execution_time) <= 0 {
  545. utils.ErrorLog("execution_time")
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  547. return
  548. }
  549. timeLayout2 := "2006-01-02 15:04:05"
  550. loc, _ := time.LoadLocation("Local")
  551. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  552. if errs != nil {
  553. utils.ErrorLog(errs.Error())
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  555. return
  556. }
  557. adminUserInfo := c.GetMobileAdminUserInfo()
  558. var advice models.DoctorAdvice
  559. if groupno > 0 {
  560. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  561. for _, item := range advices {
  562. if item.ExecutionState == 1 {
  563. advice = item
  564. }
  565. }
  566. } else {
  567. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  568. for _, item := range advices {
  569. if item.ExecutionState == 1 {
  570. advice = item
  571. }
  572. }
  573. }
  574. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  575. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  576. // if getPermissionErr != nil {
  577. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  578. // return
  579. // } else if headNursePermission == nil {
  580. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  581. // return
  582. // }
  583. //}
  584. if advice.StartTime > theTime.Unix() {
  585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  586. return
  587. }
  588. advices := models.DoctorAdvice{
  589. ExecutionTime: theTime.Unix(),
  590. UpdatedTime: time.Now().Unix(),
  591. }
  592. var err error
  593. if groupno > 0 {
  594. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  595. } else {
  596. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  597. }
  598. if err != nil {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  600. return
  601. }
  602. advice.ExecutionTime = theTime.Unix()
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "msg": "ok",
  605. "advice": advice,
  606. "ids": ids,
  607. })
  608. return
  609. }
  610. func (c *PatientApiController) CheckDoctorAdvice() {
  611. groupno, _ := c.GetInt64("groupno", -1)
  612. var ids []string
  613. if groupno == 0 {
  614. advice_ids := c.GetString("advice_id")
  615. if advice_ids == "" {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  617. return
  618. } else {
  619. ids = strings.Split(advice_ids, ",")
  620. if len(ids) <= 0 {
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  622. return
  623. }
  624. }
  625. }
  626. if groupno < 0 {
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  628. return
  629. }
  630. adminUserInfo := c.GetMobileAdminUserInfo()
  631. var advice models.DoctorAdvice
  632. if groupno > 0 {
  633. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  634. for _, item := range advices {
  635. if item.CheckState == 0 {
  636. advice = item
  637. }
  638. }
  639. if advice.CheckState == 1 {
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  641. return
  642. }
  643. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  645. return
  646. }
  647. } else {
  648. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  649. for _, item := range advices {
  650. if item.CheckState == 0 {
  651. advice = item
  652. }
  653. }
  654. if advice.CheckState == 1 {
  655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  656. return
  657. }
  658. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  660. return
  661. }
  662. }
  663. checker := adminUserInfo.AdminUser.Id
  664. theTime := time.Now()
  665. advices := models.DoctorAdvice{
  666. CheckTime: theTime.Unix(),
  667. Checker: checker,
  668. UpdatedTime: time.Now().Unix(),
  669. }
  670. var err error
  671. if groupno > 0 {
  672. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  673. } else {
  674. if len(ids[0]) <= 0 {
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  676. return
  677. } else {
  678. t := time.Now().Format("2006-01-02")
  679. timeLayout2 := "2006-01-02"
  680. loc, _ := time.LoadLocation("Local")
  681. theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  682. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, theTime.Unix())
  683. }
  684. }
  685. if err != nil {
  686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  687. return
  688. }
  689. advice.Checker = checker
  690. advice.CheckTime = theTime.Unix()
  691. advice.CheckState = 1
  692. c.ServeSuccessJSON(map[string]interface{}{
  693. "msg": "ok",
  694. "advice": advice,
  695. })
  696. return
  697. }
  698. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  699. id, _ := c.GetInt64("patient", 0)
  700. assessmentDate := c.GetString("assessment_date", "")
  701. if id <= 0 || len(assessmentDate) != 10 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  703. return
  704. }
  705. timeLayout := "2006-01-02"
  706. loc, _ := time.LoadLocation("Local")
  707. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  708. if err != nil {
  709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  710. return
  711. }
  712. theAssessmentDateTime := theTime.Unix()
  713. adminUserInfo := c.GetMobileAdminUserInfo()
  714. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  715. if patient.ID == 0 {
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  717. return
  718. }
  719. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  720. if getPEErr != nil {
  721. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  723. return
  724. }
  725. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  726. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  727. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  728. var evaluation models.PredialysisEvaluation
  729. if theEvaluation != nil {
  730. evaluation = *theEvaluation
  731. }
  732. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  733. if code > 0 {
  734. c.ServeFailJSONWithSGJErrorCode(code)
  735. return
  736. }
  737. if theEvaluation == nil {
  738. evaluation.CreatedTime = time.Now().Unix()
  739. evaluation.Status = 1
  740. evaluation.AssessmentDate = theAssessmentDateTime
  741. evaluation.PatientId = id
  742. evaluation.UserOrgId = adminUserInfo.Org.Id
  743. if appRole.UserType == 2 || appRole.UserType == 1 {
  744. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  745. evaluation.AssessmentTime = time.Now().Unix()
  746. } else {
  747. evaluation.Creater = adminUserInfo.AdminUser.Id
  748. }
  749. } else {
  750. evaluation.UpdatedTime = time.Now().Unix()
  751. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  752. if appRole.UserType == 2 || appRole.UserType == 1 {
  753. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  754. evaluation.AssessmentTime = time.Now().Unix()
  755. } else {
  756. evaluation.Modifier = adminUserInfo.AdminUser.Id
  757. if evaluation.Creater == 0 {
  758. evaluation.Creater = adminUserInfo.AdminUser.Id
  759. }
  760. }
  761. }
  762. //新增逻辑
  763. var dewater_amount float64
  764. dewater_amount = 0
  765. if evaluation.DryWeight > 0 {
  766. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  767. if template.TemplateId == 17 {
  768. dewater_amount = dewater_amount * 1000
  769. }
  770. if dewater_amount <= 0 {
  771. dewater_amount = 0
  772. }
  773. } else {
  774. dewater_amount = 0
  775. }
  776. // 计算透析处方的相关超滤量
  777. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  778. var lastDialysisPrescribe *models.DialysisPrescription
  779. var dialysisSolution *models.DialysisSolution
  780. var dialysisPrescribe *models.DialysisPrescription
  781. var system_dialysisPrescribe *models.SystemPrescription
  782. var mode_id int64
  783. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  784. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  785. if schedual != nil {
  786. // 获取透析模版
  787. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  788. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  789. mode_id = schedual.ModeId
  790. } else {
  791. // 获取透析模版
  792. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  793. if dialysisPrescribe == nil && dialysisSolution != nil {
  794. mode_id = dialysisSolution.ModeId
  795. }
  796. if dialysisPrescribe == nil && dialysisSolution == nil {
  797. mode_id = 0
  798. }
  799. }
  800. // 插入透析处方
  801. if dialysisPrescribe == nil && dialysisSolution != nil {
  802. var newprescribe models.DialysisPrescription
  803. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  804. newprescribe.PatientId = dialysisSolution.PatientId
  805. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  806. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  807. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  808. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  809. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  810. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  811. newprescribe.ModeId = dialysisSolution.ModeId
  812. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  813. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  814. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  815. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  816. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  817. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  818. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  819. newprescribe.Glucose = dialysisSolution.Glucose
  820. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  821. newprescribe.Kalium = dialysisSolution.Kalium
  822. newprescribe.Sodium = dialysisSolution.Sodium
  823. newprescribe.Calcium = dialysisSolution.Calcium
  824. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  825. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  826. newprescribe.Conductivity = dialysisSolution.Conductivity
  827. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  828. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  829. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  830. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  831. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  832. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  833. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  834. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  835. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  836. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  837. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  838. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  839. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  840. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  841. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  842. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  843. newprescribe.CreatedTime = time.Now().Unix()
  844. newprescribe.UpdatedTime = time.Now().Unix()
  845. newprescribe.RecordDate = theAssessmentDateTime
  846. newprescribe.DewaterAmount = dewater_amount
  847. newprescribe.TargetUltrafiltration = dewater_amount
  848. newprescribe.Status = 1
  849. err := service.AddSigleRecord(&newprescribe)
  850. if err != nil {
  851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  852. }
  853. }
  854. if dialysisPrescribe == nil && dialysisSolution == nil {
  855. if lastDialysisPrescribe != nil {
  856. var newprescribe models.DialysisPrescription
  857. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  858. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  859. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  860. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  861. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  862. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  863. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  864. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  865. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  866. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  867. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  868. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  869. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  870. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  871. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  872. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  873. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  874. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  875. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  876. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  877. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  878. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  879. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  880. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  881. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  882. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  883. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  884. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  885. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  886. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  887. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  888. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  889. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  890. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  891. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  892. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  893. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  894. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  895. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  896. newprescribe.CreatedTime = time.Now().Unix()
  897. newprescribe.UpdatedTime = time.Now().Unix()
  898. newprescribe.RecordDate = theAssessmentDateTime
  899. newprescribe.DewaterAmount = dewater_amount
  900. newprescribe.TargetUltrafiltration = dewater_amount
  901. newprescribe.Status = 1
  902. err := service.AddSigleRecord(&newprescribe)
  903. if err != nil {
  904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  905. }
  906. } else if system_dialysisPrescribe != nil {
  907. var newprescribe models.DialysisPrescription
  908. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  909. newprescribe.PatientId = id
  910. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  911. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  912. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  913. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  914. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  915. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  916. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  917. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  918. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  919. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  920. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  921. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  922. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  923. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  924. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  925. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  926. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  927. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  928. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  929. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  930. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  931. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  932. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  933. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  934. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  935. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  936. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  937. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  938. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  939. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  940. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  941. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  942. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  943. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  944. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  945. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  946. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  947. newprescribe.CreatedTime = time.Now().Unix()
  948. newprescribe.UpdatedTime = time.Now().Unix()
  949. newprescribe.RecordDate = theAssessmentDateTime
  950. newprescribe.DewaterAmount = dewater_amount
  951. newprescribe.TargetUltrafiltration = dewater_amount
  952. newprescribe.Status = 1
  953. err := service.AddSigleRecord(&newprescribe)
  954. if err != nil {
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  956. }
  957. } else {
  958. var newprescribe models.DialysisPrescription
  959. newprescribe.UserOrgId = adminUserInfo.Org.Id
  960. newprescribe.PatientId = id
  961. newprescribe.ModeId = mode_id
  962. newprescribe.CreatedTime = time.Now().Unix()
  963. newprescribe.UpdatedTime = time.Now().Unix()
  964. newprescribe.RecordDate = theAssessmentDateTime
  965. newprescribe.DewaterAmount = dewater_amount
  966. newprescribe.TargetUltrafiltration = dewater_amount
  967. newprescribe.Status = 1
  968. err := service.AddSigleRecord(&newprescribe)
  969. if err != nil {
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  971. }
  972. }
  973. }
  974. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  975. // if dialysisPrescribe != nil {
  976. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  977. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  978. // dialysisPrescribe.DewaterAmount = dewater_amount
  979. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  980. // dialysisPrescribe.Status = 1
  981. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  982. // if updateErr != nil {
  983. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  984. // }
  985. // }
  986. err = service.UpadatePredialysisEvaluation(&evaluation)
  987. if err != nil {
  988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  989. return
  990. }
  991. c.ServeSuccessJSON(map[string]interface{}{
  992. "msg": "ok",
  993. "evaluation": evaluation,
  994. })
  995. return
  996. }
  997. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  998. dataBody := make(map[string]interface{}, 0)
  999. err := json.Unmarshal(data, &dataBody)
  1000. utils.InfoLog(string(data))
  1001. if err != nil {
  1002. utils.ErrorLog(err.Error())
  1003. code = enums.ErrorCodeParamWrong
  1004. return
  1005. }
  1006. // if method == "create" {
  1007. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1008. utils.ErrorLog("mode")
  1009. code = enums.ErrorCodeParamWrong
  1010. return
  1011. }
  1012. mode := int64(dataBody["mode"].(float64))
  1013. if mode <= 0 {
  1014. utils.ErrorLog("mode <= 0")
  1015. code = enums.ErrorCodeParamWrong
  1016. return
  1017. }
  1018. solution.ModeId = mode
  1019. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1020. utils.ErrorLog("mode_name")
  1021. code = enums.ErrorCodeParamWrong
  1022. return
  1023. }
  1024. modeName, _ := dataBody["mode_name"].(string)
  1025. if len(modeName) == 0 {
  1026. utils.ErrorLog("len(mode_name) == 0")
  1027. code = enums.ErrorCodeParamWrong
  1028. return
  1029. }
  1030. solution.ModeName = modeName
  1031. solution.Name = modeName
  1032. // }
  1033. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1034. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1035. solution.DialysisDuration = dialysisDuration
  1036. }
  1037. if dataBody["dialysis_duration"] != nil {
  1038. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1039. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1040. solution.DialysisDuration = dialysisDuration
  1041. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1042. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1043. solution.DialysisDuration = dialysisDuration
  1044. }
  1045. }
  1046. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1047. dialyzer := int64(dataBody["dialyzer"].(float64))
  1048. solution.Dialyzer = dialyzer
  1049. }
  1050. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1051. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1052. solution.PerfusionApparatus = perfusionApparatus
  1053. }
  1054. if dataBody["blood_flow_volume"] != nil {
  1055. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1056. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1057. solution.BloodFlowVolume = bloodFlowVolume
  1058. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1059. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1060. solution.BloodFlowVolume = bloodFlowVolume
  1061. }
  1062. }
  1063. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1064. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1065. solution.HemodialysisMachine = hemodialysisMachine
  1066. }
  1067. if dataBody["dewater"] != nil {
  1068. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1069. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1070. solution.Dewater = dewater
  1071. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1072. dewater := dataBody["dewater"].(float64)
  1073. solution.Dewater = dewater
  1074. }
  1075. }
  1076. if dataBody["replacement_total"] != nil {
  1077. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1078. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1079. solution.ReplacementTotal = replacementTotal
  1080. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1081. replacementTotal := dataBody["replacement_total"].(float64)
  1082. solution.ReplacementTotal = replacementTotal
  1083. }
  1084. }
  1085. if dataBody["displace_liqui"] != nil {
  1086. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1087. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1088. solution.DisplaceLiqui = displaceLiqui
  1089. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1090. displaceLiqui := dataBody["displace_liqui"].(float64)
  1091. solution.DisplaceLiqui = displaceLiqui
  1092. }
  1093. }
  1094. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1095. replacementWay := int64(dataBody["replacement_way"].(float64))
  1096. solution.ReplacementWay = replacementWay
  1097. }
  1098. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1099. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1100. solution.Anticoagulant = anticoagulant
  1101. }
  1102. if dataBody["anticoagulant_shouji"] != nil {
  1103. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1104. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1105. solution.AnticoagulantShouji = anticoagulantShouji
  1106. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1107. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1108. solution.AnticoagulantShouji = anticoagulantShouji
  1109. }
  1110. }
  1111. if dataBody["anticoagulant_weichi"] != nil {
  1112. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1113. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1114. solution.AnticoagulantWeichi = anticoagulantWeichi
  1115. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1116. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1117. solution.AnticoagulantWeichi = anticoagulantWeichi
  1118. }
  1119. }
  1120. if dataBody["anticoagulant_zongliang"] != nil {
  1121. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1122. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1123. solution.AnticoagulantZongliang = anticoagulantZongliang
  1124. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1125. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1126. solution.AnticoagulantZongliang = anticoagulantZongliang
  1127. }
  1128. }
  1129. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1130. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1131. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1132. }
  1133. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1134. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1135. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1136. }
  1137. if dataBody["kalium"] != nil {
  1138. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1139. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1140. solution.Kalium = kalium
  1141. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1142. kalium := dataBody["kalium"].(float64)
  1143. solution.Kalium = kalium
  1144. }
  1145. }
  1146. if dataBody["sodium"] != nil {
  1147. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1148. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1149. solution.Sodium = sodium
  1150. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1151. sodium := dataBody["sodium"].(float64)
  1152. solution.Sodium = sodium
  1153. }
  1154. }
  1155. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1156. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1157. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1158. solution.Calcium = calcium
  1159. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1160. calcium := dataBody["calcium"].(float64)
  1161. solution.Calcium = calcium
  1162. }
  1163. }
  1164. if dataBody["bicarbonate"] != nil {
  1165. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1166. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1167. solution.Bicarbonate = bicarbonate
  1168. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1169. bicarbonate := dataBody["bicarbonate"].(float64)
  1170. solution.Bicarbonate = bicarbonate
  1171. }
  1172. }
  1173. if dataBody["glucose"] != nil {
  1174. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1175. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1176. solution.Glucose = glucose
  1177. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1178. glucose := dataBody["glucose"].(float64)
  1179. solution.Glucose = glucose
  1180. }
  1181. }
  1182. // if dataBody["dry_weight"] != nil {
  1183. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1184. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1185. // solution.DryWeight = dryWeight
  1186. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1187. // dryWeight := dataBody["dry_weight"].(float64)
  1188. // solution.DryWeight = dryWeight
  1189. // }
  1190. // }
  1191. if dataBody["dialysate_flow"] != nil {
  1192. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1193. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1194. solution.DialysateFlow = dialysateFlow
  1195. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1196. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1197. solution.DialysateFlow = dialysateFlow
  1198. }
  1199. }
  1200. if dataBody["dialysate_temperature"] != nil {
  1201. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1202. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1203. solution.DialysateTemperature = dialysateTemperature
  1204. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1205. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1206. solution.DialysateTemperature = dialysateTemperature
  1207. }
  1208. }
  1209. if dataBody["conductivity"] != nil {
  1210. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1211. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1212. solution.Conductivity = conductivity
  1213. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1214. conductivity := dataBody["conductivity"].(float64)
  1215. solution.Conductivity = conductivity
  1216. }
  1217. }
  1218. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1219. remark := dataBody["remark"].(string)
  1220. solution.Remark = remark
  1221. }
  1222. if dataBody["dialysis_duration_hour"] != nil {
  1223. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1224. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1225. solution.DialysisDurationHour = dialysisDurationHour
  1226. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1227. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1228. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1229. }
  1230. }
  1231. if dataBody["dialysis_duration_minute"] != nil {
  1232. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1233. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1234. solution.DialysisDurationMinute = dialysisDurationMinute
  1235. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1236. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1237. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1238. }
  1239. }
  1240. if dataBody["target_ultrafiltration"] != nil {
  1241. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1242. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1243. solution.TargetUltrafiltration = targetUltrafiltration
  1244. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1245. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1246. solution.TargetUltrafiltration = targetUltrafiltration
  1247. }
  1248. }
  1249. if dataBody["dialysate_formulation"] != nil {
  1250. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1251. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1252. solution.DialysateFormulation = dialysateFormulation
  1253. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1254. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1255. solution.DialysateFormulation = int64(dialysateFormulation)
  1256. }
  1257. }
  1258. return
  1259. }
  1260. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1261. dataBody := make(map[string]interface{}, 0)
  1262. err := json.Unmarshal(data, &dataBody)
  1263. utils.InfoLog(string(data))
  1264. if err != nil {
  1265. utils.ErrorLog(err.Error())
  1266. code = enums.ErrorCodeParamWrong
  1267. return
  1268. }
  1269. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1270. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1271. evaluation.WeightBefore = weightVefore
  1272. }
  1273. // fmt.Println(dataBody["dry_weight"])
  1274. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1275. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1276. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1277. fmt.Println(additionalWeight)
  1278. evaluation.DryWeight = additionalWeight
  1279. }
  1280. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1281. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1282. fmt.Println(additionalWeight)
  1283. evaluation.AdditionalWeight = additionalWeight
  1284. }
  1285. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1286. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1287. evaluation.Temperature = Temperature
  1288. }
  1289. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1290. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  1291. evaluation.SystolicBloodPressure = systolicBloodPressure
  1292. }
  1293. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  1294. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  1295. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  1296. }
  1297. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  1298. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  1299. evaluation.PulseFrequency = pulseFrequency
  1300. }
  1301. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  1302. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  1303. evaluation.BreathingRate = breathingRate
  1304. }
  1305. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  1306. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  1307. evaluation.LastPostDialysis = lastPostDialysis
  1308. }
  1309. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  1310. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  1311. evaluation.DialysisInterphase = dialysisInterphase
  1312. }
  1313. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  1314. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  1315. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  1316. }
  1317. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  1318. catheter, _ := dataBody["catheter"].(string)
  1319. evaluation.Catheter = catheter
  1320. }
  1321. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  1322. catheter_bend := int(dataBody["catheter_bend"].(float64))
  1323. evaluation.CatheterBend = catheter_bend
  1324. }
  1325. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  1326. Complication, _ := dataBody["complication"].(string)
  1327. evaluation.Complication = Complication
  1328. }
  1329. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1330. remark := dataBody["remark"].(string)
  1331. evaluation.Remark = remark
  1332. }
  1333. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  1334. machine_type := dataBody["machine_type"].(string)
  1335. evaluation.MachineType = machine_type
  1336. }
  1337. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  1338. blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  1339. evaluation.BloodAccessPartId = blood_access_part_id
  1340. }
  1341. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  1342. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  1343. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  1344. }
  1345. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  1346. internal_fistula, _ := dataBody["internal_fistula"].(string)
  1347. evaluation.InternalFistula = internal_fistula
  1348. }
  1349. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  1350. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  1351. evaluation.InternalFistulaSkin = internal_fistula_skin
  1352. }
  1353. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  1354. is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  1355. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  1356. is_hemorrhage = 0
  1357. }
  1358. evaluation.IsHemorrhage = is_hemorrhage
  1359. if is_hemorrhage == 1 {
  1360. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  1361. hemorrhage, _ := dataBody["hemorrhage"].(string)
  1362. evaluation.Hemorrhage = hemorrhage
  1363. }
  1364. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  1365. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  1366. evaluation.HemorrhageOther = hemorrhage_other
  1367. }
  1368. }
  1369. } else {
  1370. evaluation.IsHemorrhage = 0
  1371. }
  1372. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  1373. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  1374. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  1375. }
  1376. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  1377. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  1378. evaluation.InternalFistulaOther = internal_fistula_other
  1379. }
  1380. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  1381. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  1382. evaluation.BloodAccessNoise = blood_access_noise
  1383. }
  1384. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "float64" {
  1385. puncture_way := int64(dataBody["puncture_way"].(float64))
  1386. evaluation.PunctureWay = puncture_way
  1387. }
  1388. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  1389. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  1390. evaluation.VenousCatheterization = venous_catheterization
  1391. }
  1392. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  1393. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  1394. evaluation.VenousCatheterizationPart = venous_catheterization_part
  1395. }
  1396. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  1397. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  1398. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  1399. }
  1400. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  1401. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  1402. evaluation.DuctusArantii = ductus_arantii
  1403. }
  1404. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  1405. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  1406. evaluation.EmergencyTreatment = emergency_treatment
  1407. }
  1408. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  1409. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  1410. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  1411. }
  1412. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  1413. dialysis_count, _ := dataBody["dialysis_count"].(string)
  1414. count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  1415. evaluation.DialysisCount = count
  1416. }
  1417. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  1418. is_infect, _ := dataBody["is_infect"].(string)
  1419. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  1420. evaluation.IsInfect = infect
  1421. }
  1422. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  1423. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  1424. evaluation.Exposed = exposed
  1425. }
  1426. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  1427. skin, _ := dataBody["skin"].(string)
  1428. skins, _ := strconv.ParseInt(skin, 10, 64)
  1429. evaluation.Skin = skins
  1430. }
  1431. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  1432. skin_other, _ := dataBody["skin_other"].(string)
  1433. evaluation.SkinOther = skin_other
  1434. }
  1435. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  1436. infect_other, _ := dataBody["infect_other"].(string)
  1437. evaluation.InfectOther = infect_other
  1438. }
  1439. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  1440. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  1441. evaluation.DuctusArantiiOther = ductus_arantii_other
  1442. }
  1443. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  1444. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  1445. evaluation.PunctureNeedle = punctureNeedle
  1446. }
  1447. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "float64" {
  1448. humor_excessive_symptom := int64(dataBody["humor_excessive_symptom"].(float64))
  1449. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  1450. }
  1451. return
  1452. }
  1453. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1454. dataBody := make(map[string]interface{}, 0)
  1455. err := json.Unmarshal(data, &dataBody)
  1456. if err != nil {
  1457. utils.ErrorLog(err.Error())
  1458. code = enums.ErrorCodeParamWrong
  1459. return
  1460. }
  1461. timeLayout := "2006-01-02"
  1462. loc, _ := time.LoadLocation("Local")
  1463. isChild := false
  1464. if action == "create" {
  1465. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1466. utils.ErrorLog("advice_type")
  1467. code = enums.ErrorCodeParamWrong
  1468. return
  1469. }
  1470. adviceType := int64(dataBody["advice_type"].(float64))
  1471. if adviceType != 1 && adviceType != 2 {
  1472. utils.ErrorLog("advice_type != 1&&2")
  1473. code = enums.ErrorCodeParamWrong
  1474. return
  1475. }
  1476. advice.AdviceType = adviceType
  1477. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1478. utils.ErrorLog("advice_date")
  1479. code = enums.ErrorCodeParamWrong
  1480. return
  1481. }
  1482. adviceDate, _ := dataBody["advice_date"].(string)
  1483. if len(adviceDate) == 0 {
  1484. utils.ErrorLog("len(adviceDate) == 0")
  1485. code = enums.ErrorCodeParamWrong
  1486. return
  1487. }
  1488. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1489. if err != nil {
  1490. utils.ErrorLog(err.Error())
  1491. code = enums.ErrorCodeParamWrong
  1492. return
  1493. }
  1494. advice.AdviceDate = theTime.Unix()
  1495. advice.RecordDate = theTime.Unix()
  1496. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  1497. parentId := int64(dataBody["parent_id"].(float64))
  1498. advice.ParentId = parentId
  1499. if parentId > 0 {
  1500. isChild = true
  1501. }
  1502. }
  1503. } else {
  1504. isChild = advice.ParentId > 0
  1505. }
  1506. if !isChild {
  1507. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1508. utils.ErrorLog("start_time")
  1509. code = enums.ErrorCodeParamWrong
  1510. return
  1511. }
  1512. startTime, _ := dataBody["start_time"].(string)
  1513. fmt.Println(startTime)
  1514. if len(startTime) == 0 {
  1515. utils.ErrorLog("len(start_time) == 0")
  1516. code = enums.ErrorCodeParamWrong
  1517. return
  1518. }
  1519. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1520. if err != nil {
  1521. utils.ErrorLog(err.Error())
  1522. code = enums.ErrorCodeParamWrong
  1523. return
  1524. }
  1525. advice.StartTime = theTime.Unix()
  1526. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1527. deliveryWay, _ := dataBody["delivery_way"].(string)
  1528. advice.DeliveryWay = deliveryWay
  1529. }
  1530. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1531. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1532. advice.ExecutionFrequency = executionFrequency
  1533. }
  1534. }
  1535. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1536. deliveryWay, _ := dataBody["delivery_way"].(string)
  1537. advice.DeliveryWay = deliveryWay
  1538. }
  1539. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1540. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1541. advice.ExecutionFrequency = executionFrequency
  1542. }
  1543. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1544. utils.ErrorLog("advice_name")
  1545. code = enums.ErrorCodeParamWrong
  1546. return
  1547. }
  1548. adviceName, _ := dataBody["advice_name"].(string)
  1549. if len(adviceName) == 0 {
  1550. utils.ErrorLog("len(advice_name) == 0")
  1551. code = enums.ErrorCodeParamWrong
  1552. return
  1553. }
  1554. advice.AdviceName = adviceName
  1555. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  1556. adviceDsc, _ := dataBody["advice_desc"].(string)
  1557. advice.AdviceDesc = adviceDsc
  1558. }
  1559. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  1560. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  1561. advice.SingleDose = singleDose
  1562. }
  1563. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  1564. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  1565. advice.SingleDoseUnit = singleDoseUnit
  1566. }
  1567. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  1568. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  1569. advice.DrugSpec = drugSpec
  1570. }
  1571. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  1572. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  1573. advice.DrugSpecUnit = drugSpecUnit
  1574. }
  1575. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  1576. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  1577. advice.PrescribingNumber = prescribingNumber
  1578. }
  1579. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  1580. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  1581. advice.PrescribingNumberUnit = prescribingNumberUnit
  1582. }
  1583. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1584. remark, _ := dataBody["remark"].(string)
  1585. advice.Remark = remark
  1586. }
  1587. return
  1588. }
  1589. func (c *PatientApiController) GetPatientEducation() {
  1590. patientID, _ := c.GetInt64("patient_id", 0)
  1591. page, _ := c.GetInt64("page", 0)
  1592. limit, _ := c.GetInt64("limit", 0)
  1593. startTime := c.GetString("start_time", "")
  1594. endTime := c.GetString("end_time", "")
  1595. if page <= 0 {
  1596. page = 1
  1597. }
  1598. if limit <= 0 {
  1599. limit = 10
  1600. }
  1601. if patientID <= 0 {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. timeLayout := "2006-01-02"
  1606. loc, _ := time.LoadLocation("Local")
  1607. var theStartTIme int64
  1608. if len(startTime) > 0 {
  1609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1610. if err != nil {
  1611. theStartTIme = 0
  1612. }
  1613. theStartTIme = theTime.Unix()
  1614. }
  1615. var theEndtTIme int64
  1616. if len(endTime) > 0 {
  1617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1618. if err != nil {
  1619. theEndtTIme = 0
  1620. }
  1621. theEndtTIme = theTime.Unix()
  1622. }
  1623. adminUserInfo := c.GetMobileAdminUserInfo()
  1624. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  1625. c.ServeSuccessJSON(map[string]interface{}{
  1626. "total": total,
  1627. "edus": edus,
  1628. })
  1629. return
  1630. }
  1631. func (c *PatientApiController) GetPatientSchedulesList() {
  1632. patientID, _ := c.GetInt64("patient_id", 0)
  1633. page, _ := c.GetInt64("page", 0)
  1634. limit, _ := c.GetInt64("limit", 0)
  1635. if patientID <= 0 {
  1636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1637. return
  1638. }
  1639. adminUserInfo := c.GetMobileAdminUserInfo()
  1640. todayTime := time.Now().Format("2006-01-02")
  1641. timeLayout := "2006-01-02 15:04:05"
  1642. loc, _ := time.LoadLocation("Local")
  1643. var theStartTime int64
  1644. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  1645. theStartTime = theTime.Unix()
  1646. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  1647. if len(schedules) > 0 {
  1648. for index, item := range schedules {
  1649. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  1650. schedules[index].Week = int64(week)
  1651. }
  1652. }
  1653. c.ServeSuccessJSON(map[string]interface{}{
  1654. "schedules": schedules,
  1655. })
  1656. return
  1657. }
  1658. func (c *PatientApiController) GetRecords() {
  1659. patientID, _ := c.GetInt64("patient_id", 0)
  1660. page, _ := c.GetInt64("page", 0)
  1661. limit, _ := c.GetInt64("limit", 0)
  1662. startTime := c.GetString("start_time", "")
  1663. endTime := c.GetString("end_time", "")
  1664. mode_id, _ := c.GetInt64("mode_id", 0)
  1665. if page <= 0 {
  1666. page = 1
  1667. }
  1668. if limit <= 0 {
  1669. limit = 10
  1670. }
  1671. if patientID <= 0 {
  1672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1673. return
  1674. }
  1675. timeLayout := "2006-01-02"
  1676. loc, _ := time.LoadLocation("Local")
  1677. var theStartTIme int64
  1678. if len(startTime) > 0 {
  1679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1680. if err != nil {
  1681. theStartTIme = 0
  1682. }
  1683. theStartTIme = theTime.Unix()
  1684. }
  1685. var theEndtTIme int64
  1686. if len(endTime) > 0 {
  1687. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1688. if err != nil {
  1689. theEndtTIme = 0
  1690. }
  1691. theEndtTIme = theTime.Unix()
  1692. }
  1693. adminUserInfo := c.GetMobileAdminUserInfo()
  1694. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  1695. c.ServeSuccessJSON(map[string]interface{}{
  1696. "total": total,
  1697. "records": records,
  1698. })
  1699. return
  1700. }
  1701. func (c *PatientApiController) GetPatientMonitor() {
  1702. partition, _ := c.GetInt64("partition")
  1703. monitorDate := c.GetString("date")
  1704. timeLayout := "2006-01-02"
  1705. loc, _ := time.LoadLocation("Local")
  1706. var theStartTime int64
  1707. if len(monitorDate) > 0 {
  1708. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  1709. if err != nil {
  1710. theStartTime = 0
  1711. }
  1712. theStartTime = theTime.Unix()
  1713. }
  1714. adminInfo := c.GetMobileAdminUserInfo()
  1715. orgID := adminInfo.Org.Id
  1716. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition)
  1717. if err == nil {
  1718. c.ServeSuccessJSON(map[string]interface{}{
  1719. "monitor": monitor,
  1720. })
  1721. } else {
  1722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1723. }
  1724. }
  1725. // /m/api/monitor/patient [get] 搜索病人的测量记录
  1726. // @param keyword:string 病人姓名或透析号
  1727. // @param page:int
  1728. func (this *PatientApiController) SearchMonitorPatient() {
  1729. keyword := this.GetString("keyword")
  1730. page, _ := this.GetInt("page")
  1731. if page <= 0 {
  1732. page = 1
  1733. }
  1734. if len(keyword) == 0 {
  1735. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1736. return
  1737. }
  1738. adminUserInfo := this.GetMobileAdminUserInfo()
  1739. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  1740. if getMonitorErr != nil {
  1741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1742. return
  1743. } else {
  1744. this.ServeSuccessJSON(map[string]interface{}{
  1745. "monitor": monitors,
  1746. })
  1747. }
  1748. }
  1749. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  1750. id, _ := c.GetInt64("id", 0)
  1751. page, _ := c.GetInt64("page", 0)
  1752. limit, _ := c.GetInt64("limit", 0)
  1753. if id <= 0 {
  1754. c.ServeSuccessJSON(map[string]interface{}{
  1755. "solutions": nil,
  1756. })
  1757. return
  1758. }
  1759. if page <= 0 {
  1760. page = 1
  1761. }
  1762. if limit <= 0 {
  1763. limit = 10
  1764. }
  1765. adminInfo := c.GetMobileAdminUserInfo()
  1766. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  1767. c.ServeSuccessJSON(map[string]interface{}{
  1768. "solutions": solutions,
  1769. "total": total,
  1770. })
  1771. return
  1772. }
  1773. //GetDoctorAdvices 医嘱列表
  1774. func (c *PatientApiController) GetDoctorAdvices() {
  1775. id, _ := c.GetInt64("id", 0)
  1776. adviceType, _ := c.GetInt64("advice_type", 0)
  1777. stopType, _ := c.GetInt64("stop_state", 0)
  1778. startTime := c.GetString("start_time", "")
  1779. endTime := c.GetString("end_time", "")
  1780. keywords := c.GetString("keywords", "")
  1781. need, _ := c.GetInt64("need_doctor", 0)
  1782. adminUserInfo := c.GetMobileAdminUserInfo()
  1783. timeLayout := "2006-01-02"
  1784. loc, _ := time.LoadLocation("Local")
  1785. var theStartTIme int64
  1786. if len(startTime) > 0 {
  1787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1788. if err != nil {
  1789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1790. return
  1791. }
  1792. theStartTIme = theTime.Unix()
  1793. }
  1794. var theEndtTIme int64
  1795. if len(endTime) > 0 {
  1796. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1797. if err != nil {
  1798. utils.ErrorLog(err.Error())
  1799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1800. return
  1801. }
  1802. theEndtTIme = theTime.Unix()
  1803. }
  1804. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  1805. if need == 1 {
  1806. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1807. c.ServeSuccessJSON(map[string]interface{}{
  1808. "advices": advices,
  1809. "total": total,
  1810. "users": users,
  1811. })
  1812. } else {
  1813. c.ServeSuccessJSON(map[string]interface{}{
  1814. "advices": advices,
  1815. "total": total,
  1816. "users": []string{},
  1817. })
  1818. }
  1819. return
  1820. }
  1821. func (c *PatientApiController) GetPrintDialysisOrder() {
  1822. xtno := c.GetString("xtno")
  1823. xtdate := c.GetString("xtdate")
  1824. timeLayout := "2006-01-02"
  1825. loc, _ := time.LoadLocation("Local")
  1826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  1827. if err != nil {
  1828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1829. return
  1830. }
  1831. xttime := theTime.Unix()
  1832. operatorIDs := make([]int64, 0)
  1833. adminUserInfo := c.GetMobileAdminUserInfo()
  1834. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  1835. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  1836. //透析单
  1837. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1838. if dialysisOrder != nil {
  1839. if dialysisOrder.FinishNurse > 0 {
  1840. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  1841. }
  1842. if dialysisOrder.StartNurse > 0 {
  1843. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  1844. }
  1845. }
  1846. //透前评估
  1847. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1848. //透后评估
  1849. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1850. if AssessmentAfterDislysis.Modifier > 0 {
  1851. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  1852. }
  1853. //透析处方
  1854. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1855. if dialysisPrescription.PrescriptionDoctor > 0 {
  1856. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  1857. }
  1858. //临时医嘱
  1859. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1860. if len(DoctorAdvice) > 0 {
  1861. for _, item := range DoctorAdvice {
  1862. if item.AdviceDoctor > 0 {
  1863. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  1864. }
  1865. if item.ExecutionStaff > 0 {
  1866. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  1867. }
  1868. if item.Checker > 0 {
  1869. operatorIDs = append(operatorIDs, item.Checker)
  1870. }
  1871. }
  1872. }
  1873. //透析监测
  1874. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1875. //透析小结
  1876. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1877. //接诊评估
  1878. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1879. //相关操作对应的操作人
  1880. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  1881. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  1882. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1883. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  1884. c.ServeSuccessJSON(map[string]interface{}{
  1885. "users": adminUser,
  1886. "patientInfo": patientInfo,
  1887. "PredialysisEvaluation": PredialysisEvaluation,
  1888. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  1889. "dialysisPrescription": dialysisPrescription,
  1890. "advices": DoctorAdvice,
  1891. "monitors": Record,
  1892. "summary": TreatmentSummary,
  1893. "receiverTreatmentAccess": receiverTreatmentAccess,
  1894. "dialysisOrder": dialysisOrder,
  1895. "operators": operators,
  1896. "org_template_info": templateInfo,
  1897. "check": check,
  1898. })
  1899. }
  1900. func (c *PatientApiController) CreateGroupAdvice() {
  1901. is_child, _ := c.GetInt64("is_child", 0)
  1902. if is_child == 1 {
  1903. patient, _ := c.GetInt64("id", 0)
  1904. if patient <= 0 {
  1905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1906. return
  1907. }
  1908. adminUserInfo := c.GetMobileAdminUserInfo()
  1909. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  1910. if patientInfo.ID == 0 {
  1911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1912. return
  1913. }
  1914. group_no, _ := c.GetInt64("group_no")
  1915. if group_no <= 0 {
  1916. group_no = 0
  1917. }
  1918. dataBody := make(map[string]interface{}, 0)
  1919. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1920. if err != nil {
  1921. utils.ErrorLog(err.Error())
  1922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1923. return
  1924. }
  1925. timeLayout := "2006-01-02"
  1926. loc, _ := time.LoadLocation("Local")
  1927. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1928. utils.ErrorLog("advice_type")
  1929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1930. return
  1931. }
  1932. adviceType := int64(dataBody["advice_type"].(float64))
  1933. if adviceType != 1 && adviceType != 2 {
  1934. utils.ErrorLog("advice_type != 1&&2")
  1935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1936. return
  1937. }
  1938. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1939. utils.ErrorLog("start_time")
  1940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1941. return
  1942. }
  1943. startTime2, _ := dataBody["start_time"].(string)
  1944. time_arr := strings.Split(startTime2, " ")
  1945. if len(time_arr) > 0 {
  1946. startTime2 = time_arr[0]
  1947. }
  1948. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1949. utils.ErrorLog("advice_date")
  1950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1951. return
  1952. }
  1953. adviceDate := startTime2
  1954. if len(adviceDate) == 0 {
  1955. utils.ErrorLog("len(adviceDate) == 0")
  1956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1957. return
  1958. }
  1959. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1960. if err != nil {
  1961. utils.ErrorLog(err.Error())
  1962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1963. return
  1964. }
  1965. AdviceDate := theTime.Unix()
  1966. RecordDate := theTime.Unix()
  1967. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1968. utils.ErrorLog("start_time")
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. startTime, _ := dataBody["start_time"].(string)
  1973. if len(startTime) == 0 {
  1974. utils.ErrorLog("len(start_time) == 0")
  1975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1976. return
  1977. }
  1978. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1979. if err != nil {
  1980. utils.ErrorLog(err.Error())
  1981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1982. return
  1983. }
  1984. StartTime := theTime.Unix()
  1985. Remark := ""
  1986. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1987. remark, _ := dataBody["remark"].(string)
  1988. Remark = remark
  1989. }
  1990. var advices []*models.GroupAdvice
  1991. // utils.TraceLog("%+v", dataBody["adviceNames"])
  1992. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1993. utils.ErrorLog("adviceNames")
  1994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1995. return
  1996. }
  1997. adviceNames := dataBody["adviceNames"].([]interface{})
  1998. for _, adviceNameMap := range adviceNames {
  1999. adviceNameM := adviceNameMap.(map[string]interface{})
  2000. var advice models.GroupAdvice
  2001. advice.Remark = Remark
  2002. advice.AdviceType = adviceType
  2003. advice.StartTime = StartTime
  2004. advice.AdviceDate = AdviceDate
  2005. advice.RecordDate = RecordDate
  2006. advice.Status = 1
  2007. advice.CreatedTime = time.Now().Unix()
  2008. advice.UpdatedTime = time.Now().Unix()
  2009. advice.StopState = 2
  2010. advice.ExecutionState = 2
  2011. advice.UserOrgId = adminUserInfo.Org.Id
  2012. advice.PatientId = patientInfo.ID
  2013. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2014. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2015. if errcode > 0 {
  2016. c.ServeFailJSONWithSGJErrorCode(errcode)
  2017. return
  2018. }
  2019. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2020. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2021. if len(subdrugs) > 0 {
  2022. for _, subdrug := range subdrugs {
  2023. var s models.GroupAdvice
  2024. s.Remark = Remark
  2025. s.AdviceType = adviceType
  2026. s.StartTime = StartTime
  2027. s.AdviceDate = AdviceDate
  2028. s.RecordDate = RecordDate
  2029. s.Status = 1
  2030. s.CreatedTime = time.Now().Unix()
  2031. s.UpdatedTime = time.Now().Unix()
  2032. s.StopState = 2
  2033. s.ExecutionState = 2
  2034. s.UserOrgId = adminUserInfo.Org.Id
  2035. s.PatientId = patientInfo.ID
  2036. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2037. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2038. if errcode > 0 {
  2039. c.ServeFailJSONWithSGJErrorCode(errcode)
  2040. return
  2041. }
  2042. advice.Children = append(advice.Children, &s)
  2043. }
  2044. }
  2045. }
  2046. advices = append(advices, &advice)
  2047. }
  2048. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  2049. if createErr != nil {
  2050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2051. return
  2052. }
  2053. c.ServeSuccessJSON(map[string]interface{}{
  2054. "msg": "ok",
  2055. "advices": newAdvices,
  2056. })
  2057. return
  2058. } else if is_child == 2 {
  2059. patient, _ := c.GetInt64("id", 0)
  2060. if patient <= 0 {
  2061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2062. return
  2063. }
  2064. adminUserInfo := c.GetMobileAdminUserInfo()
  2065. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2066. if patientInfo.ID == 0 {
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2068. return
  2069. }
  2070. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2071. //if appRole.UserType == 3{
  2072. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  2073. // return
  2074. //}
  2075. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2076. //
  2077. //if appRole.UserType == 3 {
  2078. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2079. // if getPermissionErr != nil {
  2080. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2081. // return
  2082. // } else if headNursePermission == nil {
  2083. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2084. // return
  2085. // }
  2086. //}
  2087. var advice models.DoctorAdvice
  2088. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  2089. if code > 0 {
  2090. c.ServeFailJSONWithSGJErrorCode(code)
  2091. return
  2092. }
  2093. if advice.ParentId > 0 {
  2094. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  2095. if old.ID == 0 || old.PatientId != patient {
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2097. return
  2098. }
  2099. if old.StopState == 1 || old.ExecutionState == 1 {
  2100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2101. return
  2102. }
  2103. if old.ParentId > 0 {
  2104. advice.ParentId = old.ParentId
  2105. }
  2106. advice.StartTime = old.StartTime
  2107. advice.AdviceDoctor = old.AdviceDoctor
  2108. advice.DeliveryWay = old.DeliveryWay
  2109. advice.ExecutionFrequency = old.ExecutionFrequency
  2110. advice.GroupNo = old.GroupNo
  2111. }
  2112. advice.Status = 1
  2113. advice.CreatedTime = time.Now().Unix()
  2114. advice.UpdatedTime = time.Now().Unix()
  2115. advice.StopState = 2
  2116. advice.ExecutionState = 2
  2117. advice.UserOrgId = adminUserInfo.Org.Id
  2118. advice.PatientId = patient
  2119. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2120. err := service.CreateDoctorAdvice(&advice)
  2121. if err != nil {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2123. return
  2124. }
  2125. c.ServeSuccessJSON(map[string]interface{}{
  2126. "msg": "ok",
  2127. "advice": advice,
  2128. })
  2129. return
  2130. }
  2131. }
  2132. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  2133. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  2134. utils.ErrorLog("advice_name")
  2135. return enums.ErrorCodeParamWrong
  2136. }
  2137. adviceName, _ := json["advice_name"].(string)
  2138. if len(adviceName) == 0 {
  2139. utils.ErrorLog("len(advice_name) == 0")
  2140. return enums.ErrorCodeParamWrong
  2141. }
  2142. advice.AdviceName = adviceName
  2143. adviceDesc, _ := json["advice_desc"].(string)
  2144. advice.AdviceDesc = adviceDesc
  2145. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2146. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2147. advice.DrugSpec = drugSpec
  2148. }
  2149. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2150. remark, _ := json["remark"].(string)
  2151. advice.Remark = remark
  2152. }
  2153. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  2154. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  2155. advice.DrugSpecUnit = drugSpecUnit
  2156. }
  2157. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2158. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2159. advice.SingleDose = singleDose
  2160. }
  2161. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2162. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2163. advice.SingleDoseUnit = singleDoseUnit
  2164. }
  2165. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2166. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2167. advice.PrescribingNumber = prescribingNumber
  2168. }
  2169. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2170. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2171. advice.PrescribingNumberUnit = prescribingNumberUnit
  2172. }
  2173. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2174. deliveryWay, _ := json["delivery_way"].(string)
  2175. advice.DeliveryWay = deliveryWay
  2176. }
  2177. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2178. executionFrequency, _ := json["execution_frequency"].(string)
  2179. advice.ExecutionFrequency = executionFrequency
  2180. }
  2181. return 0
  2182. }
  2183. func (c *PatientApiController) DelDoctorAdvice() {
  2184. groupno, _ := c.GetInt64("groupno", -1)
  2185. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  2186. if is_sub == 1 { //是
  2187. advice_id, _ := c.GetInt64("advice_id")
  2188. adminUserInfo := c.GetMobileAdminUserInfo()
  2189. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2190. if advice.ID == 0 {
  2191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2192. return
  2193. }
  2194. advice.Status = 0
  2195. advice.UpdatedTime = time.Now().Unix()
  2196. advice.Modifier = adminUserInfo.AdminUser.Id
  2197. err := service.DeleteDoctorAdvice(&advice)
  2198. if err != nil {
  2199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2200. return
  2201. }
  2202. c.ServeSuccessJSON(map[string]interface{}{
  2203. "msg": "ok",
  2204. })
  2205. return
  2206. } else { //
  2207. var ids []string
  2208. if groupno == 0 {
  2209. advice_id := c.GetString("advice_id")
  2210. ids = strings.Split(advice_id, ",")
  2211. if len(ids) <= 0 {
  2212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2213. return
  2214. }
  2215. }
  2216. if groupno < 0 {
  2217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2218. return
  2219. }
  2220. adminUserInfo := c.GetMobileAdminUserInfo()
  2221. var advice models.DoctorAdvice
  2222. if groupno > 0 {
  2223. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2224. if advice.ID == 0 {
  2225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2226. return
  2227. }
  2228. } else {
  2229. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2230. for _, item := range advices {
  2231. if item.ID == 0 {
  2232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2233. return
  2234. }
  2235. }
  2236. }
  2237. advice.UpdatedTime = time.Now().Unix()
  2238. advice.Status = 0
  2239. advice.GroupNo = groupno
  2240. advice.Modifier = adminUserInfo.AdminUser.Id
  2241. var err error
  2242. if groupno > 0 {
  2243. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  2244. } else {
  2245. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  2246. }
  2247. if err != nil {
  2248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2249. return
  2250. }
  2251. c.ServeSuccessJSON(map[string]interface{}{
  2252. "msg": "ok",
  2253. })
  2254. return
  2255. }
  2256. }
  2257. // /m/api/advice/group/modify_starttime [post]
  2258. // @param group_no:int
  2259. // @param start_time:string yyyy-MM-dd hh:mm:ss
  2260. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  2261. group_no, _ := this.GetInt64("group_no")
  2262. start_time_str := this.GetString("start_time")
  2263. if group_no <= 0 || len(start_time_str) == 0 {
  2264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2265. return
  2266. }
  2267. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  2268. if parseTimeErr != nil {
  2269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  2270. return
  2271. }
  2272. adminUserInfo := this.GetMobileAdminUserInfo()
  2273. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  2274. if updateStartTimeErr != nil {
  2275. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  2276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2277. return
  2278. }
  2279. this.ServeSuccessJSON(map[string]interface{}{
  2280. "start_time": startTime.Unix(),
  2281. })
  2282. }
  2283. func (this *PatientApiController) DelSubDoctorAdvice() {
  2284. advice_id, _ := this.GetInt64("advice_id")
  2285. adminUserInfo := this.GetMobileAdminUserInfo()
  2286. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2287. if advice.ID == 0 {
  2288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2289. return
  2290. }
  2291. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2292. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  2293. // return
  2294. //}
  2295. advice.Status = 0
  2296. advice.UpdatedTime = time.Now().Unix()
  2297. advice.Modifier = adminUserInfo.AdminUser.Id
  2298. err := service.DeleteDoctorAdvice(&advice)
  2299. if err != nil {
  2300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2301. return
  2302. }
  2303. this.ServeSuccessJSON(map[string]interface{}{
  2304. "msg": "ok",
  2305. })
  2306. return
  2307. }
  2308. func (this *PatientApiController) GetAdviceUnReadMessage() {
  2309. //adminUserInfo := this.GetMobileAdminUserInfo()
  2310. //service.FindUnReadDoctorAdviceMessage()
  2311. }
  2312. func (this *PatientApiController) GetPatientsByKeyWord() {
  2313. keyWord := this.GetString("keyword")
  2314. adminUserInfo := this.GetMobileAdminUserInfo()
  2315. today := utils.ZeroHourTimeOfDay(time.Now())
  2316. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  2317. if err != nil {
  2318. utils.ErrorLog(err.Error())
  2319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2320. return
  2321. }
  2322. this.ServeSuccessJSON(map[string]interface{}{
  2323. "patient": patient,
  2324. })
  2325. }