patient_api_controller.go 91KB

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