patient_api_controller.go 92KB

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