patient_api_controller.go 89KB

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