patient_api_controller.go 88KB

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