patient_api_controller.go 111KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296
  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. "github.com/jinzhu/gorm"
  10. "math"
  11. "strings"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. patient, _ := c.GetInt64("id", 0)
  147. if patient <= 0 {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  149. return
  150. }
  151. adminUserInfo := c.GetMobileAdminUserInfo()
  152. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  153. if patientInfo.ID == 0 {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  155. return
  156. }
  157. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  158. //if appRole.UserType == 3{
  159. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  160. // return
  161. //}
  162. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  163. //
  164. //if appRole.UserType == 3 {
  165. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  166. // if getPermissionErr != nil {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  168. // return
  169. // } else if headNursePermission == nil {
  170. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  171. // return
  172. // }
  173. //}
  174. var advice models.DoctorAdvice
  175. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  176. if code > 0 {
  177. c.ServeFailJSONWithSGJErrorCode(code)
  178. return
  179. }
  180. if advice.ParentId > 0 {
  181. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  182. if old.ID == 0 || old.PatientId != patient {
  183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  184. return
  185. }
  186. if old.StopState == 1 || old.ExecutionState == 1 {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  188. return
  189. }
  190. if old.ParentId > 0 {
  191. advice.ParentId = old.ParentId
  192. }
  193. advice.StartTime = old.StartTime
  194. advice.AdviceDoctor = old.AdviceDoctor
  195. advice.DeliveryWay = old.DeliveryWay
  196. advice.ExecutionFrequency = old.ExecutionFrequency
  197. advice.GroupNo = old.GroupNo
  198. }
  199. advice.Status = 1
  200. advice.CreatedTime = time.Now().Unix()
  201. advice.UpdatedTime = time.Now().Unix()
  202. advice.StopState = 2
  203. advice.ExecutionState = 2
  204. advice.UserOrgId = adminUserInfo.Org.Id
  205. advice.PatientId = patient
  206. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  207. err := service.CreateDoctorAdvice(&advice)
  208. if err != nil {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  210. return
  211. }
  212. c.ServeSuccessJSON(map[string]interface{}{
  213. "msg": "ok",
  214. "advice": advice,
  215. })
  216. return
  217. }
  218. func (c *PatientApiController) EditDoctorAdvice() {
  219. id, _ := c.GetInt64("id", 0)
  220. if id <= 0 {
  221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  222. return
  223. }
  224. adminUserInfo := c.GetMobileAdminUserInfo()
  225. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  226. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  227. //
  228. //if appRole.UserType == 3 {
  229. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  230. // if getPermissionErr != nil {
  231. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  232. // return
  233. // } else if headNursePermission == nil {
  234. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  235. // return
  236. // }
  237. //}
  238. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  239. if advice.ID == 0 {
  240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  241. return
  242. }
  243. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  244. if code > 0 {
  245. c.ServeFailJSONWithSGJErrorCode(code)
  246. return
  247. }
  248. advice.Status = 1
  249. advice.UpdatedTime = time.Now().Unix()
  250. advice.UserOrgId = adminUserInfo.Org.Id
  251. advice.Modifier = adminUserInfo.AdminUser.Id
  252. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  253. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  254. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  255. var err error
  256. var isChangeGroup bool
  257. if advice.ParentId == 0 {
  258. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  259. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  260. if len(adviceSlice) == 1 {
  261. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  262. if advice.StartTime == sourceAdvice.StartTime {
  263. err = service.UpdateDoctorAdvice(&advice)
  264. isChangeGroup = false
  265. } else {
  266. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  267. isChangeGroup = false
  268. }
  269. } else if len(adviceSlice) > 1 {
  270. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  271. if advice.StartTime == sourceAdvice.StartTime {
  272. err = service.UpdateDoctorAdvice(&advice)
  273. isChangeGroup = false
  274. } else {
  275. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  276. gruopNo = gruopNo + 1
  277. advice.GroupNo = gruopNo
  278. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  279. isChangeGroup = true
  280. }
  281. }
  282. } else {
  283. isChangeGroup = false
  284. err = service.UpdateDoctorAdvice(&advice)
  285. }
  286. if err != nil {
  287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  288. return
  289. }
  290. if !isChangeGroup {
  291. c.ServeSuccessJSON(map[string]interface{}{
  292. "msg": "ok",
  293. "advice": advice,
  294. "isChange": isChangeGroup, //方便前端处理数据
  295. })
  296. } else {
  297. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  298. if err != nil {
  299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  300. return
  301. }
  302. c.ServeSuccessJSON(map[string]interface{}{
  303. "msg": "ok",
  304. "advice": newGroupAdvice,
  305. "isChange": isChangeGroup, //方便前端处理数据
  306. })
  307. }
  308. return
  309. }
  310. func (c *PatientApiController) StopDoctorAdvice() {
  311. id, _ := c.GetInt64("id", 0)
  312. if id <= 0 {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  314. return
  315. }
  316. adminUserInfo := c.GetMobileAdminUserInfo()
  317. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  318. if advice.ID == 0 {
  319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  320. return
  321. }
  322. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  323. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  324. // return
  325. //}
  326. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  327. //
  328. //if appRole.UserType == 3 {
  329. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  330. // if getPermissionErr != nil {
  331. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  332. // return
  333. // } else if headNursePermission == nil {
  334. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  335. // return
  336. // }
  337. //}
  338. if advice.StopState == 1 {
  339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  340. return
  341. }
  342. dataBody := make(map[string]interface{}, 0)
  343. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  344. if err != nil {
  345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  346. return
  347. }
  348. timeLayout := "2006-01-02"
  349. loc, _ := time.LoadLocation("Local")
  350. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  351. utils.ErrorLog("stop_time")
  352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  353. return
  354. }
  355. stopTime, _ := dataBody["stop_time"].(string)
  356. if len(stopTime) == 0 {
  357. utils.ErrorLog("len(stop_time) == 0")
  358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  359. return
  360. }
  361. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  362. if err != nil {
  363. utils.ErrorLog(err.Error())
  364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  365. return
  366. }
  367. advice.StopTime = theTime.Unix()
  368. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  369. utils.ErrorLog("stop_reason")
  370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  371. return
  372. }
  373. stopReason, _ := dataBody["stop_reason"].(string)
  374. if len(stopReason) == 0 {
  375. utils.ErrorLog("len(stop_reason) == 0")
  376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  377. return
  378. }
  379. advice.StopReason = stopReason
  380. advice.Status = 1
  381. advice.UpdatedTime = time.Now().Unix()
  382. advice.StopDoctor = adminUserInfo.AdminUser.Id
  383. advice.StopState = 1
  384. advice.StopTime = time.Now().Unix()
  385. advice.Modifier = adminUserInfo.AdminUser.Id
  386. err = service.StopDoctorAdvice(&advice)
  387. if err != nil {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  389. return
  390. }
  391. c.ServeSuccessJSON(map[string]interface{}{
  392. "msg": "ok",
  393. "advice": advice,
  394. })
  395. return
  396. }
  397. func (c *PatientApiController) DeleteDoctorAdvice() {
  398. id, _ := c.GetInt64("id", 0)
  399. if id <= 0 {
  400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  401. return
  402. }
  403. adminUserInfo := c.GetMobileAdminUserInfo()
  404. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  405. if advice.ID == 0 {
  406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  407. return
  408. }
  409. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  411. // return
  412. //}
  413. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  414. //
  415. //if appRole.UserType == 3 {
  416. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  417. // if getPermissionErr != nil {
  418. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  419. // return
  420. // } else if headNursePermission == nil {
  421. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  422. // return
  423. // }
  424. //}
  425. advice.UpdatedTime = time.Now().Unix()
  426. advice.Status = 0
  427. advice.Modifier = adminUserInfo.AdminUser.Id
  428. err := service.DeleteDoctorAdvice(&advice)
  429. if err != nil {
  430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  431. return
  432. }
  433. c.ServeSuccessJSON(map[string]interface{}{
  434. "msg": "ok",
  435. })
  436. return
  437. }
  438. func (c *PatientApiController) ExecDoctorAdvice() {
  439. execution_time := c.GetString("execution_time")
  440. origin, _ := c.GetInt64("origin", 0)
  441. groupno, _ := c.GetInt64("groupno", -1)
  442. if origin != 2 {
  443. var ids []string
  444. if groupno == 0 {
  445. advice_ids := c.GetString("advice_id")
  446. ids = strings.Split(advice_ids, ",")
  447. }
  448. if groupno < 0 {
  449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  450. return
  451. }
  452. if len(execution_time) <= 0 {
  453. utils.ErrorLog("execution_time")
  454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  455. return
  456. }
  457. timeLayout2 := "2006-01-02 15:04:05"
  458. loc, _ := time.LoadLocation("Local")
  459. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  460. if errs != nil {
  461. utils.ErrorLog(errs.Error())
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  463. return
  464. }
  465. adminUserInfo := c.GetMobileAdminUserInfo()
  466. var advice models.DoctorAdvice
  467. if groupno > 0 {
  468. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  469. for _, item := range advices {
  470. if item.ExecutionState == 2 {
  471. advice = item
  472. }
  473. }
  474. } else {
  475. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  476. for _, item := range advices {
  477. if item.ExecutionState == 2 {
  478. advice = item
  479. }
  480. }
  481. }
  482. if advice.ExecutionState == 1 {
  483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  484. return
  485. }
  486. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  488. return
  489. }
  490. if advice.StartTime > theTime.Unix() {
  491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  492. return
  493. }
  494. execution_staff := adminUserInfo.AdminUser.Id
  495. advices := models.DoctorAdvice{
  496. ExecutionStaff: execution_staff,
  497. ExecutionTime: theTime.Unix(),
  498. UpdatedTime: time.Now().Unix(),
  499. }
  500. var err error
  501. if groupno > 0 {
  502. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  503. } else {
  504. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  505. }
  506. if err != nil {
  507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  508. return
  509. }
  510. advice.ExecutionStaff = execution_staff
  511. advice.ExecutionTime = theTime.Unix()
  512. advice.ExecutionState = 1
  513. advice.Modifier = adminUserInfo.AdminUser.Id
  514. //处理出库相关逻辑
  515. //1.判断是否启用药品管理和自备药出库功能
  516. //药品管理信息
  517. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  518. //自备药信息
  519. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  520. if drugStockConfig.IsOpen == 1 {
  521. if groupno > 0 {
  522. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  523. isHasWay := false //用来判断是否包含来自药品库的医嘱
  524. for _, item := range advices {
  525. if item.Way == 1 {
  526. isHasWay = true
  527. }
  528. }
  529. if isHasWay {
  530. for _, item := range advices {
  531. if item.Way == 1 {
  532. //查询该药品是否有库存
  533. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  534. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  535. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  536. if list.Count == 0 {
  537. c.ServeSuccessJSON(map[string]interface{}{
  538. "msg": "1",
  539. "advice": advice,
  540. "ids": ids,
  541. })
  542. return
  543. }
  544. if count > list.Count {
  545. c.ServeSuccessJSON(map[string]interface{}{
  546. "msg": "2",
  547. "advice": advice,
  548. "ids": ids,
  549. })
  550. return
  551. }
  552. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  553. }
  554. }
  555. }
  556. } else {
  557. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  558. isHasWay := false //用来判断是否包含来自药品库的医嘱
  559. for _, item := range advices {
  560. if item.Way == 1 {
  561. isHasWay = true
  562. }
  563. }
  564. if isHasWay {
  565. for _, item := range advices {
  566. if item.Way == 1 {
  567. //查询该药品是否有库存
  568. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  569. //获取该药品的信息
  570. //medical, _ := service.GetBaseDrugMedical(item.DrugId)
  571. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  572. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  573. if list.Count == 0 {
  574. c.ServeSuccessJSON(map[string]interface{}{
  575. "msg": "1",
  576. "advice": advice,
  577. "ids": ids,
  578. })
  579. return
  580. }
  581. if count > list.Count {
  582. c.ServeSuccessJSON(map[string]interface{}{
  583. "msg": "2",
  584. "advice": advice,
  585. "ids": ids,
  586. })
  587. return
  588. }
  589. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  590. }
  591. }
  592. }
  593. }
  594. }
  595. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  596. if groupno > 0 {
  597. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  598. for _, item := range advices {
  599. if item.ExecutionState == 1 && item.Way == 2 {
  600. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  601. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  602. timeStr := time.Now().Format("2006-01-02")
  603. timeArr := strings.Split(timeStr, "-")
  604. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  605. total = total + 1
  606. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  607. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  608. number = number + total
  609. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  610. //插入自备药出库单
  611. outStock := models.XtSelfOutStock{
  612. DrugName: item.AdviceName,
  613. DrugNameId: item.DrugNameId,
  614. DrugSpec: item.AdviceDesc,
  615. OutstoreNumber: count,
  616. AdminUserId: adminUserInfo.AdminUser.Id,
  617. StorckTime: item.AdviceDate,
  618. UserOrgId: adminUserInfo.Org.Id,
  619. CreatedTime: time.Now().Unix(),
  620. Status: 1,
  621. PatientId: item.PatientId,
  622. ExitMode: 2,
  623. MedicId: item.DrugId,
  624. StockOutNumber: warehousing_out_order,
  625. }
  626. //查询 该患者是否已出库
  627. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  628. if errcode == gorm.ErrRecordNotFound {
  629. service.CreateOutStock(&outStock)
  630. } else if errcode == nil {
  631. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  632. fmt.Println("err", err)
  633. }
  634. }
  635. }
  636. } else {
  637. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  638. for _, item := range advices {
  639. if item.ExecutionState == 1 && item.Way == 2 {
  640. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  641. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  642. timeStr := time.Now().Format("2006-01-02")
  643. timeArr := strings.Split(timeStr, "-")
  644. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  645. total = total + 1
  646. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  647. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  648. number = number + total
  649. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  650. //插入自备药出库单
  651. outStock := models.XtSelfOutStock{
  652. DrugName: item.AdviceName,
  653. DrugNameId: item.DrugNameId,
  654. DrugSpec: item.AdviceDesc,
  655. OutstoreNumber: count,
  656. AdminUserId: adminUserInfo.AdminUser.Id,
  657. StorckTime: item.AdviceDate,
  658. UserOrgId: adminUserInfo.Org.Id,
  659. CreatedTime: time.Now().Unix(),
  660. Status: 1,
  661. PatientId: item.PatientId,
  662. ExitMode: 2,
  663. MedicId: item.DrugId,
  664. StockOutNumber: warehousing_out_order,
  665. }
  666. //查询 该患者是否已出库
  667. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  668. if errcode == gorm.ErrRecordNotFound {
  669. service.CreateOutStock(&outStock)
  670. } else if errcode == nil {
  671. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  672. fmt.Println("err", err)
  673. }
  674. }
  675. }
  676. }
  677. }
  678. c.ServeSuccessJSON(map[string]interface{}{
  679. "msg": "ok",
  680. "advice": advice,
  681. "ids": ids,
  682. })
  683. return
  684. } else if origin == 2 {
  685. if len(execution_time) <= 0 {
  686. utils.ErrorLog("execution_time")
  687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  688. return
  689. }
  690. timeLayout2 := "2006-01-02 15:04:05"
  691. loc, _ := time.LoadLocation("Local")
  692. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  693. if errs != nil {
  694. utils.ErrorLog(errs.Error())
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  696. return
  697. }
  698. adminInfo := c.GetMobileAdminUserInfo()
  699. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  700. advice_id, _ := c.GetInt64("advice_id")
  701. advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
  702. if advices.ExecutionState == 1 {
  703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  704. return
  705. }
  706. if advices.Checker >= 0 && advices.Checker == adminInfo.AdminUser.Id {
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  708. return
  709. }
  710. if advices.StartTime > theTime.Unix() {
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  712. return
  713. }
  714. advices.ExecutionState = 1
  715. advices.ExecutionStaff = adminInfo.AdminUser.Id
  716. advices.ExecutionTime = theTime.Unix()
  717. err := service.SaveHisDoctorAdvice(&advices)
  718. var ids []string
  719. ids = append(ids, strconv.FormatInt(advices.ID, 10))
  720. if err == nil {
  721. //药品管理信息
  722. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  723. if drugStockConfig.IsOpen == 1 {
  724. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
  725. //查询该药品是否有库存
  726. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
  727. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  728. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  729. if list.Count == 0 {
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "msg": "1",
  732. "advice": advice,
  733. "ids": ids,
  734. })
  735. return
  736. }
  737. if count > list.Count {
  738. c.ServeSuccessJSON(map[string]interface{}{
  739. "msg": "2",
  740. "advice": advice,
  741. "ids": ids,
  742. })
  743. return
  744. }
  745. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  746. }
  747. c.ServeSuccessJSON(map[string]interface{}{
  748. "msg": "ok",
  749. "advice": advices,
  750. "ids": ids,
  751. })
  752. } else {
  753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  754. }
  755. }
  756. }
  757. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  758. execution_time := c.GetString("execution_time")
  759. groupno, _ := c.GetInt64("groupno", -1)
  760. var ids []string
  761. if groupno == 0 {
  762. advice_ids := c.GetString("advice_id")
  763. ids = strings.Split(advice_ids, ",")
  764. }
  765. if groupno < 0 {
  766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  767. return
  768. }
  769. if len(execution_time) <= 0 {
  770. utils.ErrorLog("execution_time")
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. timeLayout2 := "2006-01-02 15:04:05"
  775. loc, _ := time.LoadLocation("Local")
  776. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  777. if errs != nil {
  778. utils.ErrorLog(errs.Error())
  779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  780. return
  781. }
  782. adminUserInfo := c.GetMobileAdminUserInfo()
  783. var advice models.DoctorAdvice
  784. if groupno > 0 {
  785. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  786. for _, item := range advices {
  787. if item.ExecutionState == 1 {
  788. advice = item
  789. }
  790. }
  791. } else {
  792. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  793. for _, item := range advices {
  794. if item.ExecutionState == 1 {
  795. advice = item
  796. }
  797. }
  798. }
  799. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  800. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  801. // if getPermissionErr != nil {
  802. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  803. // return
  804. // } else if headNursePermission == nil {
  805. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  806. // return
  807. // }
  808. //}
  809. if advice.StartTime > theTime.Unix() {
  810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  811. return
  812. }
  813. advices := models.DoctorAdvice{
  814. ExecutionTime: theTime.Unix(),
  815. UpdatedTime: time.Now().Unix(),
  816. }
  817. var err error
  818. if groupno > 0 {
  819. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  820. } else {
  821. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  822. }
  823. //判断是否开启his
  824. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  825. //如果开启去修改执行时间
  826. if config.IsOpen == 1 {
  827. advicesinfo := models.HisDoctorAdviceInfo{
  828. ExecutionTime: theTime.Unix(),
  829. UpdatedTime: time.Now().Unix(),
  830. }
  831. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  832. }
  833. if err != nil {
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  835. return
  836. }
  837. advice.ExecutionTime = theTime.Unix()
  838. c.ServeSuccessJSON(map[string]interface{}{
  839. "msg": "ok",
  840. "advice": advice,
  841. "ids": ids,
  842. })
  843. return
  844. }
  845. func (c *PatientApiController) CheckDoctorAdvice() {
  846. origin, _ := c.GetInt64("origin", 0)
  847. if origin != 2 {
  848. groupno, _ := c.GetInt64("groupno", -1)
  849. var ids []string
  850. if groupno == 0 {
  851. advice_ids := c.GetString("advice_id")
  852. if advice_ids == "" {
  853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  854. return
  855. } else {
  856. ids = strings.Split(advice_ids, ",")
  857. if len(ids) <= 0 {
  858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  859. return
  860. }
  861. }
  862. }
  863. if groupno < 0 {
  864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  865. return
  866. }
  867. adminUserInfo := c.GetMobileAdminUserInfo()
  868. var advice models.DoctorAdvice
  869. if groupno > 0 {
  870. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  871. for _, item := range advices {
  872. if item.CheckState == 0 {
  873. advice = item
  874. }
  875. }
  876. if advice.CheckState == 1 {
  877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  878. return
  879. }
  880. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  882. return
  883. }
  884. } else {
  885. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  886. for _, item := range advices {
  887. if item.CheckState == 0 {
  888. advice = item
  889. }
  890. }
  891. if advice.CheckState == 1 {
  892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  893. return
  894. }
  895. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  897. return
  898. }
  899. }
  900. checker := adminUserInfo.AdminUser.Id
  901. theTime := time.Now()
  902. advices := models.DoctorAdvice{
  903. CheckTime: theTime.Unix(),
  904. Checker: checker,
  905. UpdatedTime: time.Now().Unix(),
  906. }
  907. var err error
  908. if groupno > 0 {
  909. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  910. } else {
  911. if len(ids[0]) <= 0 {
  912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  913. return
  914. } else {
  915. //t := time.Now().Format("2006-01-02")/**/
  916. //timeLayout2 := "2006-01-02"
  917. //loc, _ := time.LoadLocation("Local")
  918. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  919. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  920. }
  921. }
  922. if err != nil {
  923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  924. return
  925. }
  926. advice.Checker = checker
  927. advice.CheckTime = theTime.Unix()
  928. advice.CheckState = 1
  929. c.ServeSuccessJSON(map[string]interface{}{
  930. "msg": "ok",
  931. "advice": advice,
  932. })
  933. } else if origin == 2 {
  934. adminInfo := c.GetMobileAdminUserInfo()
  935. advice_id, _ := c.GetInt64("advice_id")
  936. advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
  937. if advices.CheckState == 1 {
  938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  939. return
  940. }
  941. if advices.ExecutionStaff >= 0 && advices.ExecutionStaff == adminInfo.AdminUser.Id {
  942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  943. return
  944. }
  945. advices.Checker = adminInfo.AdminUser.Id
  946. advices.CheckTime = time.Now().Unix()
  947. advices.CheckState = 1
  948. err := service.SaveHisDoctorAdvice(&advices)
  949. if err == nil {
  950. c.ServeSuccessJSON(map[string]interface{}{
  951. "msg": "ok",
  952. "advice": advices,
  953. })
  954. } else {
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  956. return
  957. }
  958. }
  959. return
  960. }
  961. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  962. id, _ := c.GetInt64("patient", 0)
  963. assessmentDate := c.GetString("assessment_date", "")
  964. if id <= 0 || len(assessmentDate) != 10 {
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  966. return
  967. }
  968. timeLayout := "2006-01-02"
  969. loc, _ := time.LoadLocation("Local")
  970. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  971. if err != nil {
  972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  973. return
  974. }
  975. theAssessmentDateTime := theTime.Unix()
  976. adminUserInfo := c.GetMobileAdminUserInfo()
  977. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  978. if patient.ID == 0 {
  979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  980. return
  981. }
  982. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  983. if getPEErr != nil {
  984. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  986. return
  987. }
  988. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  989. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  990. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  991. var evaluation models.PredialysisEvaluation
  992. if theEvaluation != nil {
  993. evaluation = *theEvaluation
  994. }
  995. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  996. if code > 0 {
  997. c.ServeFailJSONWithSGJErrorCode(code)
  998. return
  999. }
  1000. if theEvaluation == nil {
  1001. evaluation.CreatedTime = time.Now().Unix()
  1002. evaluation.Status = 1
  1003. evaluation.AssessmentDate = theAssessmentDateTime
  1004. evaluation.PatientId = id
  1005. evaluation.UserOrgId = adminUserInfo.Org.Id
  1006. if appRole.UserType == 2 || appRole.UserType == 1 {
  1007. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1008. evaluation.AssessmentTime = time.Now().Unix()
  1009. } else {
  1010. evaluation.Creater = adminUserInfo.AdminUser.Id
  1011. }
  1012. } else {
  1013. evaluation.UpdatedTime = time.Now().Unix()
  1014. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1015. if appRole.UserType == 2 || appRole.UserType == 1 {
  1016. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1017. evaluation.AssessmentTime = time.Now().Unix()
  1018. } else {
  1019. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1020. if evaluation.Creater == 0 {
  1021. evaluation.Creater = adminUserInfo.AdminUser.Id
  1022. }
  1023. }
  1024. }
  1025. //新增逻辑
  1026. var dewater_amount float64
  1027. dewater_amount = 0
  1028. if evaluation.DryWeight > 0 {
  1029. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1030. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 {
  1031. dewater_amount = dewater_amount * 1000
  1032. }
  1033. if dewater_amount <= 0 {
  1034. dewater_amount = 0
  1035. }
  1036. } else {
  1037. dewater_amount = 0
  1038. }
  1039. // 计算透析处方的相关超滤量
  1040. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1041. var lastDialysisPrescribe *models.DialysisPrescription
  1042. var dialysisSolution *models.DialysisSolution
  1043. var dialysisPrescribe *models.DialysisPrescription
  1044. var system_dialysisPrescribe *models.SystemPrescription
  1045. var mode_id int64
  1046. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1047. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  1048. if schedual != nil {
  1049. // 获取透析模版
  1050. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  1051. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  1052. mode_id = schedual.ModeId
  1053. } else {
  1054. // 获取透析模版
  1055. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1056. if dialysisPrescribe == nil && dialysisSolution != nil {
  1057. mode_id = dialysisSolution.ModeId
  1058. }
  1059. if dialysisPrescribe == nil && dialysisSolution == nil {
  1060. mode_id = 0
  1061. }
  1062. }
  1063. // 插入透析处方
  1064. if dialysisPrescribe == nil && dialysisSolution != nil {
  1065. var newprescribe models.DialysisPrescription
  1066. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1067. newprescribe.PatientId = dialysisSolution.PatientId
  1068. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1069. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1070. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1071. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1072. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1073. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1074. newprescribe.ModeId = dialysisSolution.ModeId
  1075. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1076. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1077. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1078. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1079. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1080. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1081. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1082. newprescribe.Glucose = dialysisSolution.Glucose
  1083. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1084. newprescribe.Kalium = dialysisSolution.Kalium
  1085. newprescribe.Sodium = dialysisSolution.Sodium
  1086. newprescribe.Calcium = dialysisSolution.Calcium
  1087. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1088. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1089. newprescribe.Conductivity = dialysisSolution.Conductivity
  1090. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1091. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1092. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1093. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1094. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1095. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1096. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1097. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1098. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1099. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1100. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1101. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1102. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1103. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1104. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1105. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1106. newprescribe.CreatedTime = time.Now().Unix()
  1107. newprescribe.UpdatedTime = time.Now().Unix()
  1108. newprescribe.RecordDate = theAssessmentDateTime
  1109. newprescribe.DewaterAmount = dewater_amount
  1110. newprescribe.TargetUltrafiltration = dewater_amount
  1111. newprescribe.Status = 1
  1112. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1113. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1114. err := service.AddSigleRecord(&newprescribe)
  1115. if err != nil {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1117. }
  1118. }
  1119. if dialysisPrescribe == nil && dialysisSolution == nil {
  1120. if lastDialysisPrescribe != nil {
  1121. var newprescribe models.DialysisPrescription
  1122. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1123. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1124. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1125. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1126. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1127. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1128. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1129. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1130. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1131. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1132. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1133. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1134. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1135. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1136. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1137. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1138. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1139. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1140. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1141. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1142. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1143. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1144. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1145. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1146. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1147. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1148. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1149. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1150. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1151. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1152. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1153. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1154. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1155. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1156. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1157. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1158. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1159. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1160. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1161. newprescribe.CreatedTime = time.Now().Unix()
  1162. newprescribe.UpdatedTime = time.Now().Unix()
  1163. newprescribe.RecordDate = theAssessmentDateTime
  1164. newprescribe.DewaterAmount = dewater_amount
  1165. newprescribe.TargetUltrafiltration = dewater_amount
  1166. newprescribe.Status = 1
  1167. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  1168. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  1169. err := service.AddSigleRecord(&newprescribe)
  1170. if err != nil {
  1171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1172. }
  1173. } else if system_dialysisPrescribe != nil {
  1174. var newprescribe models.DialysisPrescription
  1175. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  1176. newprescribe.PatientId = id
  1177. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  1178. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  1179. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  1180. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  1181. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  1182. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  1183. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  1184. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  1185. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  1186. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  1187. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  1188. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  1189. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  1190. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  1191. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  1192. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  1193. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  1194. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  1195. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  1196. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  1197. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  1198. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  1199. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  1200. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  1201. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  1202. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  1203. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  1204. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  1205. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  1206. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  1207. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  1208. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  1209. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  1210. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  1211. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  1212. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  1213. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  1214. newprescribe.CreatedTime = time.Now().Unix()
  1215. newprescribe.UpdatedTime = time.Now().Unix()
  1216. newprescribe.RecordDate = theAssessmentDateTime
  1217. newprescribe.DewaterAmount = dewater_amount
  1218. newprescribe.TargetUltrafiltration = dewater_amount
  1219. newprescribe.Status = 1
  1220. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  1221. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  1222. err := service.AddSigleRecord(&newprescribe)
  1223. if err != nil {
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1225. }
  1226. } else {
  1227. var newprescribe models.DialysisPrescription
  1228. newprescribe.UserOrgId = adminUserInfo.Org.Id
  1229. newprescribe.PatientId = id
  1230. newprescribe.ModeId = mode_id
  1231. newprescribe.CreatedTime = time.Now().Unix()
  1232. newprescribe.UpdatedTime = time.Now().Unix()
  1233. newprescribe.RecordDate = theAssessmentDateTime
  1234. newprescribe.DewaterAmount = dewater_amount
  1235. newprescribe.TargetUltrafiltration = dewater_amount
  1236. newprescribe.Status = 1
  1237. err := service.AddSigleRecord(&newprescribe)
  1238. if err != nil {
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1240. }
  1241. }
  1242. }
  1243. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  1244. // if dialysisPrescribe != nil {
  1245. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  1246. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  1247. // dialysisPrescribe.DewaterAmount = dewater_amount
  1248. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  1249. // dialysisPrescribe.Status = 1
  1250. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  1251. // if updateErr != nil {
  1252. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1253. // }
  1254. // }
  1255. err = service.UpadatePredialysisEvaluation(&evaluation)
  1256. if err != nil {
  1257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1258. return
  1259. }
  1260. c.ServeSuccessJSON(map[string]interface{}{
  1261. "msg": "ok",
  1262. "evaluation": evaluation,
  1263. })
  1264. return
  1265. }
  1266. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1267. dataBody := make(map[string]interface{}, 0)
  1268. err := json.Unmarshal(data, &dataBody)
  1269. utils.InfoLog(string(data))
  1270. if err != nil {
  1271. utils.ErrorLog(err.Error())
  1272. code = enums.ErrorCodeParamWrong
  1273. return
  1274. }
  1275. // if method == "create" {
  1276. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1277. utils.ErrorLog("mode")
  1278. code = enums.ErrorCodeParamWrong
  1279. return
  1280. }
  1281. mode := int64(dataBody["mode"].(float64))
  1282. if mode <= 0 {
  1283. utils.ErrorLog("mode <= 0")
  1284. code = enums.ErrorCodeParamWrong
  1285. return
  1286. }
  1287. solution.ModeId = mode
  1288. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1289. utils.ErrorLog("mode_name")
  1290. code = enums.ErrorCodeParamWrong
  1291. return
  1292. }
  1293. modeName, _ := dataBody["mode_name"].(string)
  1294. if len(modeName) == 0 {
  1295. utils.ErrorLog("len(mode_name) == 0")
  1296. code = enums.ErrorCodeParamWrong
  1297. return
  1298. }
  1299. solution.ModeName = modeName
  1300. solution.Name = modeName
  1301. // }
  1302. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1303. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1304. solution.DialysisDuration = dialysisDuration
  1305. }
  1306. if dataBody["dialysis_duration"] != nil {
  1307. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1308. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1309. solution.DialysisDuration = dialysisDuration
  1310. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1311. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1312. solution.DialysisDuration = dialysisDuration
  1313. }
  1314. }
  1315. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1316. dialyzer := int64(dataBody["dialyzer"].(float64))
  1317. solution.Dialyzer = dialyzer
  1318. }
  1319. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1320. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1321. solution.PerfusionApparatus = perfusionApparatus
  1322. }
  1323. if dataBody["blood_flow_volume"] != nil {
  1324. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1325. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1326. solution.BloodFlowVolume = bloodFlowVolume
  1327. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1328. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1329. solution.BloodFlowVolume = bloodFlowVolume
  1330. }
  1331. }
  1332. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1333. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1334. solution.HemodialysisMachine = hemodialysisMachine
  1335. }
  1336. if dataBody["dewater"] != nil {
  1337. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1338. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1339. solution.Dewater = dewater
  1340. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1341. dewater := dataBody["dewater"].(float64)
  1342. solution.Dewater = dewater
  1343. }
  1344. }
  1345. if dataBody["replacement_total"] != nil {
  1346. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1347. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1348. solution.ReplacementTotal = replacementTotal
  1349. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1350. replacementTotal := dataBody["replacement_total"].(float64)
  1351. solution.ReplacementTotal = replacementTotal
  1352. }
  1353. }
  1354. if dataBody["displace_liqui"] != nil {
  1355. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1356. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1357. solution.DisplaceLiqui = displaceLiqui
  1358. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1359. displaceLiqui := dataBody["displace_liqui"].(float64)
  1360. solution.DisplaceLiqui = displaceLiqui
  1361. }
  1362. }
  1363. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1364. replacementWay := int64(dataBody["replacement_way"].(float64))
  1365. solution.ReplacementWay = replacementWay
  1366. }
  1367. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1368. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1369. solution.Anticoagulant = anticoagulant
  1370. }
  1371. if dataBody["anticoagulant_shouji"] != nil {
  1372. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1373. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1374. solution.AnticoagulantShouji = anticoagulantShouji
  1375. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1376. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1377. solution.AnticoagulantShouji = anticoagulantShouji
  1378. }
  1379. }
  1380. if dataBody["anticoagulant_weichi"] != nil {
  1381. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1382. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1383. solution.AnticoagulantWeichi = anticoagulantWeichi
  1384. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1385. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1386. solution.AnticoagulantWeichi = anticoagulantWeichi
  1387. }
  1388. }
  1389. if dataBody["anticoagulant_zongliang"] != nil {
  1390. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1391. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1392. solution.AnticoagulantZongliang = anticoagulantZongliang
  1393. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1394. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1395. solution.AnticoagulantZongliang = anticoagulantZongliang
  1396. }
  1397. }
  1398. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1399. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1400. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1401. }
  1402. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1403. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1404. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1405. }
  1406. if dataBody["kalium"] != nil {
  1407. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1408. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1409. solution.Kalium = kalium
  1410. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1411. kalium := dataBody["kalium"].(float64)
  1412. solution.Kalium = kalium
  1413. }
  1414. }
  1415. if dataBody["sodium"] != nil {
  1416. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1417. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1418. solution.Sodium = sodium
  1419. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1420. sodium := dataBody["sodium"].(float64)
  1421. solution.Sodium = sodium
  1422. }
  1423. }
  1424. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1425. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1426. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1427. solution.Calcium = calcium
  1428. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1429. calcium := dataBody["calcium"].(float64)
  1430. solution.Calcium = calcium
  1431. }
  1432. }
  1433. if dataBody["bicarbonate"] != nil {
  1434. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1435. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1436. solution.Bicarbonate = bicarbonate
  1437. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1438. bicarbonate := dataBody["bicarbonate"].(float64)
  1439. solution.Bicarbonate = bicarbonate
  1440. }
  1441. }
  1442. if dataBody["glucose"] != nil {
  1443. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1444. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1445. solution.Glucose = glucose
  1446. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1447. glucose := dataBody["glucose"].(float64)
  1448. solution.Glucose = glucose
  1449. }
  1450. }
  1451. // if dataBody["dry_weight"] != nil {
  1452. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1453. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1454. // solution.DryWeight = dryWeight
  1455. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1456. // dryWeight := dataBody["dry_weight"].(float64)
  1457. // solution.DryWeight = dryWeight
  1458. // }
  1459. // }
  1460. if dataBody["dialysate_flow"] != nil {
  1461. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1462. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1463. solution.DialysateFlow = dialysateFlow
  1464. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1465. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1466. solution.DialysateFlow = dialysateFlow
  1467. }
  1468. }
  1469. if dataBody["dialysate_temperature"] != nil {
  1470. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1471. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1472. solution.DialysateTemperature = dialysateTemperature
  1473. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1474. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1475. solution.DialysateTemperature = dialysateTemperature
  1476. }
  1477. }
  1478. if dataBody["conductivity"] != nil {
  1479. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1480. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1481. solution.Conductivity = conductivity
  1482. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1483. conductivity := dataBody["conductivity"].(float64)
  1484. solution.Conductivity = conductivity
  1485. }
  1486. }
  1487. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1488. remark := dataBody["remark"].(string)
  1489. solution.Remark = remark
  1490. }
  1491. if dataBody["dialysis_duration_hour"] != nil {
  1492. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1493. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1494. solution.DialysisDurationHour = dialysisDurationHour
  1495. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1496. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1497. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1498. }
  1499. }
  1500. if dataBody["dialysis_duration_minute"] != nil {
  1501. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1502. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1503. solution.DialysisDurationMinute = dialysisDurationMinute
  1504. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1505. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1506. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1507. }
  1508. }
  1509. if dataBody["target_ultrafiltration"] != nil {
  1510. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1511. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1512. solution.TargetUltrafiltration = targetUltrafiltration
  1513. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1514. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1515. solution.TargetUltrafiltration = targetUltrafiltration
  1516. }
  1517. }
  1518. if dataBody["dialysate_formulation"] != nil {
  1519. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1520. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1521. solution.DialysateFormulation = dialysateFormulation
  1522. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1523. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1524. solution.DialysateFormulation = int64(dialysateFormulation)
  1525. }
  1526. }
  1527. return
  1528. }
  1529. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1530. dataBody := make(map[string]interface{}, 0)
  1531. err := json.Unmarshal(data, &dataBody)
  1532. utils.InfoLog(string(data))
  1533. if err != nil {
  1534. utils.ErrorLog(err.Error())
  1535. code = enums.ErrorCodeParamWrong
  1536. return
  1537. }
  1538. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1539. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1540. evaluation.WeightBefore = weightVefore
  1541. }
  1542. // fmt.Println(dataBody["dry_weight"])
  1543. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1544. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1545. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1546. fmt.Println(additionalWeight)
  1547. evaluation.DryWeight = additionalWeight
  1548. }
  1549. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1550. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1551. fmt.Println(additionalWeight)
  1552. evaluation.AdditionalWeight = additionalWeight
  1553. }
  1554. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1555. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1556. evaluation.Temperature = Temperature
  1557. }
  1558. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1559. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  1560. evaluation.SystolicBloodPressure = systolicBloodPressure
  1561. }
  1562. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  1563. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  1564. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  1565. }
  1566. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  1567. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  1568. evaluation.PulseFrequency = pulseFrequency
  1569. }
  1570. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  1571. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  1572. evaluation.BreathingRate = breathingRate
  1573. }
  1574. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  1575. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  1576. evaluation.LastPostDialysis = lastPostDialysis
  1577. }
  1578. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  1579. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  1580. evaluation.DialysisInterphase = dialysisInterphase
  1581. }
  1582. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  1583. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  1584. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  1585. }
  1586. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  1587. catheter, _ := dataBody["catheter"].(string)
  1588. evaluation.Catheter = catheter
  1589. }
  1590. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  1591. catheter_bend := int(dataBody["catheter_bend"].(float64))
  1592. evaluation.CatheterBend = catheter_bend
  1593. }
  1594. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  1595. Complication, _ := dataBody["complication"].(string)
  1596. evaluation.Complication = Complication
  1597. }
  1598. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1599. remark := dataBody["remark"].(string)
  1600. evaluation.Remark = remark
  1601. }
  1602. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  1603. machine_type := dataBody["machine_type"].(string)
  1604. evaluation.MachineType = machine_type
  1605. }
  1606. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  1607. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  1608. evaluation.BloodAccessPartId = blood_access_part_id
  1609. }
  1610. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  1611. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  1612. // evaluation.BloodAccessPartId = blood_access_part_id
  1613. //}
  1614. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  1615. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  1616. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  1617. }
  1618. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  1619. internal_fistula, _ := dataBody["internal_fistula"].(string)
  1620. evaluation.InternalFistula = internal_fistula
  1621. }
  1622. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  1623. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  1624. evaluation.InternalFistulaSkin = internal_fistula_skin
  1625. }
  1626. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  1627. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  1628. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  1629. evaluation.IsHemorrhage = is_hemorrhage
  1630. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  1631. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  1632. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  1633. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  1634. is_hemorrhage = 0
  1635. }
  1636. evaluation.IsHemorrhage = is_hemorrhage
  1637. if is_hemorrhage == 1 {
  1638. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  1639. hemorrhage, _ := dataBody["hemorrhage"].(string)
  1640. evaluation.Hemorrhage = hemorrhage
  1641. }
  1642. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  1643. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  1644. evaluation.HemorrhageOther = hemorrhage_other
  1645. }
  1646. }
  1647. } else {
  1648. evaluation.IsHemorrhage = 0
  1649. }
  1650. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  1651. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  1652. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  1653. }
  1654. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  1655. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  1656. evaluation.InternalFistulaOther = internal_fistula_other
  1657. }
  1658. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  1659. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  1660. evaluation.BloodAccessNoise = blood_access_noise
  1661. }
  1662. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  1663. //puncture_way := int64(dataBody["puncture_way"].(float64))
  1664. puncture_way := dataBody["puncture_way"].(string)
  1665. evaluation.PunctureWay = puncture_way
  1666. }
  1667. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  1668. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  1669. evaluation.VenousCatheterization = venous_catheterization
  1670. }
  1671. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  1672. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  1673. evaluation.VenousCatheterizationPart = venous_catheterization_part
  1674. }
  1675. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  1676. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  1677. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  1678. }
  1679. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  1680. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  1681. evaluation.DuctusArantii = ductus_arantii
  1682. }
  1683. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  1684. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  1685. evaluation.EmergencyTreatment = emergency_treatment
  1686. }
  1687. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  1688. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  1689. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  1690. }
  1691. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  1692. dialysis_count, _ := dataBody["dialysis_count"].(string)
  1693. count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  1694. evaluation.DialysisCount = count
  1695. }
  1696. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  1697. is_infect, _ := dataBody["is_infect"].(string)
  1698. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  1699. evaluation.IsInfect = infect
  1700. }
  1701. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  1702. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  1703. evaluation.Exposed = exposed
  1704. }
  1705. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  1706. skin, _ := dataBody["skin"].(string)
  1707. //skins, _ := strconv.ParseInt(skin, 10, 64)
  1708. evaluation.Skin = skin
  1709. }
  1710. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  1711. skin_other, _ := dataBody["skin_other"].(string)
  1712. evaluation.SkinOther = skin_other
  1713. }
  1714. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  1715. infect_other, _ := dataBody["infect_other"].(string)
  1716. evaluation.InfectOther = infect_other
  1717. }
  1718. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  1719. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  1720. evaluation.DuctusArantiiOther = ductus_arantii_other
  1721. }
  1722. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  1723. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  1724. evaluation.PunctureNeedle = punctureNeedle
  1725. }
  1726. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "float64" {
  1727. humor_excessive_symptom := int64(dataBody["humor_excessive_symptom"].(float64))
  1728. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  1729. }
  1730. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  1731. pinholing := dataBody["pinholing"].(string)
  1732. evaluation.Phinholing = pinholing
  1733. }
  1734. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  1735. catheter_suture := dataBody["catheter_suture"].(string)
  1736. evaluation.CatheterSuture = catheter_suture
  1737. }
  1738. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  1739. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  1740. evaluation.CatheterSutureOther = catheter_suture_other
  1741. }
  1742. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  1743. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  1744. evaluation.UrineVolume = urine_volume
  1745. }
  1746. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  1747. edema := dataBody["edema"].(string)
  1748. evaluation.Edema = edema
  1749. }
  1750. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  1751. specialTreatment := dataBody["special_treatment"].(string)
  1752. evaluation.SpecialTreatment = specialTreatment
  1753. }
  1754. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  1755. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  1756. evaluation.CatheterMaintenance = catheter_maintenance
  1757. }
  1758. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  1759. thromubusType := int64(dataBody["thromubus_type"].(float64))
  1760. evaluation.ThromubusType = thromubusType
  1761. }
  1762. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  1763. thrombus_av := dataBody["thrombus_av"].(string)
  1764. evaluation.ThrombusAv = thrombus_av
  1765. }
  1766. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  1767. thromubus_a := dataBody["thromubus_a"].(string)
  1768. evaluation.ThromubusA = thromubus_a
  1769. }
  1770. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  1771. thromubus_v := dataBody["thromubus_v"].(string)
  1772. evaluation.ThromubusV = thromubus_v
  1773. }
  1774. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  1775. dehydration := dataBody["dehydration"].(string)
  1776. evaluation.Dehydration = dehydration
  1777. }
  1778. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  1779. period := int64(dataBody["period"].(float64))
  1780. evaluation.Period = period
  1781. }
  1782. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  1783. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  1784. evaluation.EstimatedFoodIntake = estimated_food_intake
  1785. }
  1786. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  1787. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  1788. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  1789. }
  1790. return
  1791. }
  1792. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1793. dataBody := make(map[string]interface{}, 0)
  1794. err := json.Unmarshal(data, &dataBody)
  1795. if err != nil {
  1796. utils.ErrorLog(err.Error())
  1797. code = enums.ErrorCodeParamWrong
  1798. return
  1799. }
  1800. timeLayout := "2006-01-02"
  1801. loc, _ := time.LoadLocation("Local")
  1802. isChild := false
  1803. if action == "create" {
  1804. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1805. utils.ErrorLog("advice_type")
  1806. code = enums.ErrorCodeParamWrong
  1807. return
  1808. }
  1809. adviceType := int64(dataBody["advice_type"].(float64))
  1810. if adviceType != 1 && adviceType != 2 {
  1811. utils.ErrorLog("advice_type != 1&&2")
  1812. code = enums.ErrorCodeParamWrong
  1813. return
  1814. }
  1815. advice.AdviceType = adviceType
  1816. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1817. utils.ErrorLog("advice_date")
  1818. code = enums.ErrorCodeParamWrong
  1819. return
  1820. }
  1821. adviceDate, _ := dataBody["advice_date"].(string)
  1822. if len(adviceDate) == 0 {
  1823. utils.ErrorLog("len(adviceDate) == 0")
  1824. code = enums.ErrorCodeParamWrong
  1825. return
  1826. }
  1827. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1828. if err != nil {
  1829. utils.ErrorLog(err.Error())
  1830. code = enums.ErrorCodeParamWrong
  1831. return
  1832. }
  1833. advice.AdviceDate = theTime.Unix()
  1834. advice.RecordDate = theTime.Unix()
  1835. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  1836. parentId := int64(dataBody["parent_id"].(float64))
  1837. advice.ParentId = parentId
  1838. if parentId > 0 {
  1839. isChild = true
  1840. }
  1841. }
  1842. } else {
  1843. isChild = advice.ParentId > 0
  1844. }
  1845. if !isChild {
  1846. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1847. utils.ErrorLog("start_time")
  1848. code = enums.ErrorCodeParamWrong
  1849. return
  1850. }
  1851. startTime, _ := dataBody["start_time"].(string)
  1852. if len(startTime) == 0 {
  1853. utils.ErrorLog("len(start_time) == 0")
  1854. code = enums.ErrorCodeParamWrong
  1855. return
  1856. }
  1857. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  1858. if err != nil {
  1859. utils.ErrorLog(err.Error())
  1860. code = enums.ErrorCodeParamWrong
  1861. return
  1862. }
  1863. advice.StartTime = theTime.Unix()
  1864. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1865. deliveryWay, _ := dataBody["delivery_way"].(string)
  1866. advice.DeliveryWay = deliveryWay
  1867. }
  1868. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1869. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1870. advice.ExecutionFrequency = executionFrequency
  1871. }
  1872. }
  1873. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  1874. deliveryWay, _ := dataBody["delivery_way"].(string)
  1875. advice.DeliveryWay = deliveryWay
  1876. }
  1877. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  1878. executionFrequency, _ := dataBody["execution_frequency"].(string)
  1879. advice.ExecutionFrequency = executionFrequency
  1880. }
  1881. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  1882. utils.ErrorLog("advice_name")
  1883. code = enums.ErrorCodeParamWrong
  1884. return
  1885. }
  1886. adviceName, _ := dataBody["advice_name"].(string)
  1887. if len(adviceName) == 0 {
  1888. utils.ErrorLog("len(advice_name) == 0")
  1889. code = enums.ErrorCodeParamWrong
  1890. return
  1891. }
  1892. advice.AdviceName = adviceName
  1893. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  1894. adviceDsc, _ := dataBody["advice_desc"].(string)
  1895. advice.AdviceDesc = adviceDsc
  1896. }
  1897. if dataBody["way"] == nil {
  1898. advice.Way = 0
  1899. } else {
  1900. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  1901. way := int64(dataBody["way"].(float64))
  1902. advice.Way = way
  1903. }
  1904. }
  1905. if dataBody["drug_id"] == nil {
  1906. advice.DrugId = 0
  1907. } else {
  1908. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  1909. drug_id := int64(dataBody["drug_id"].(float64))
  1910. advice.DrugId = drug_id
  1911. }
  1912. }
  1913. if dataBody["drug_name_id"] == nil {
  1914. advice.DrugNameId = 0
  1915. } else {
  1916. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  1917. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  1918. advice.DrugNameId = drug_name_id
  1919. fmt.Println("0000000000", advice.DrugNameId)
  1920. }
  1921. }
  1922. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  1923. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  1924. advice.SingleDose = singleDose
  1925. }
  1926. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  1927. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  1928. advice.SingleDoseUnit = singleDoseUnit
  1929. }
  1930. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  1931. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  1932. advice.DrugSpec = drugSpec
  1933. }
  1934. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  1935. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  1936. advice.DrugSpecUnit = drugSpecUnit
  1937. }
  1938. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  1939. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  1940. advice.PrescribingNumber = prescribingNumber
  1941. }
  1942. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  1943. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  1944. advice.PrescribingNumberUnit = prescribingNumberUnit
  1945. }
  1946. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1947. remark, _ := dataBody["remark"].(string)
  1948. advice.Remark = remark
  1949. }
  1950. return
  1951. }
  1952. func (c *PatientApiController) GetPatientEducation() {
  1953. patientID, _ := c.GetInt64("patient_id", 0)
  1954. page, _ := c.GetInt64("page", 0)
  1955. limit, _ := c.GetInt64("limit", 0)
  1956. startTime := c.GetString("start_time", "")
  1957. endTime := c.GetString("end_time", "")
  1958. if page <= 0 {
  1959. page = 1
  1960. }
  1961. if limit <= 0 {
  1962. limit = 10
  1963. }
  1964. if patientID <= 0 {
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. timeLayout := "2006-01-02"
  1969. loc, _ := time.LoadLocation("Local")
  1970. var theStartTIme int64
  1971. if len(startTime) > 0 {
  1972. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  1973. if err != nil {
  1974. theStartTIme = 0
  1975. }
  1976. theStartTIme = theTime.Unix()
  1977. }
  1978. var theEndtTIme int64
  1979. if len(endTime) > 0 {
  1980. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  1981. if err != nil {
  1982. theEndtTIme = 0
  1983. }
  1984. theEndtTIme = theTime.Unix()
  1985. }
  1986. adminUserInfo := c.GetMobileAdminUserInfo()
  1987. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  1988. c.ServeSuccessJSON(map[string]interface{}{
  1989. "total": total,
  1990. "edus": edus,
  1991. })
  1992. return
  1993. }
  1994. func (c *PatientApiController) GetPatientSchedulesList() {
  1995. patientID, _ := c.GetInt64("patient_id", 0)
  1996. page, _ := c.GetInt64("page", 0)
  1997. limit, _ := c.GetInt64("limit", 0)
  1998. if patientID <= 0 {
  1999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2000. return
  2001. }
  2002. adminUserInfo := c.GetMobileAdminUserInfo()
  2003. todayTime := time.Now().Format("2006-01-02")
  2004. timeLayout := "2006-01-02 15:04:05"
  2005. loc, _ := time.LoadLocation("Local")
  2006. var theStartTime int64
  2007. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2008. theStartTime = theTime.Unix()
  2009. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  2010. if len(schedules) > 0 {
  2011. for index, item := range schedules {
  2012. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2013. schedules[index].Week = int64(week)
  2014. }
  2015. }
  2016. c.ServeSuccessJSON(map[string]interface{}{
  2017. "schedules": schedules,
  2018. })
  2019. return
  2020. }
  2021. func (c *PatientApiController) GetRecords() {
  2022. patientID, _ := c.GetInt64("patient_id", 0)
  2023. page, _ := c.GetInt64("page", 0)
  2024. limit, _ := c.GetInt64("limit", 0)
  2025. startTime := c.GetString("start_time", "")
  2026. endTime := c.GetString("end_time", "")
  2027. mode_id, _ := c.GetInt64("mode_id", 0)
  2028. if page <= 0 {
  2029. page = 1
  2030. }
  2031. if limit <= 0 {
  2032. limit = 10
  2033. }
  2034. if patientID <= 0 {
  2035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2036. return
  2037. }
  2038. timeLayout := "2006-01-02"
  2039. loc, _ := time.LoadLocation("Local")
  2040. var theStartTIme int64
  2041. if len(startTime) > 0 {
  2042. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2043. if err != nil {
  2044. theStartTIme = 0
  2045. }
  2046. theStartTIme = theTime.Unix()
  2047. }
  2048. var theEndtTIme int64
  2049. if len(endTime) > 0 {
  2050. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2051. if err != nil {
  2052. theEndtTIme = 0
  2053. }
  2054. theEndtTIme = theTime.Unix()
  2055. }
  2056. adminUserInfo := c.GetMobileAdminUserInfo()
  2057. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2058. c.ServeSuccessJSON(map[string]interface{}{
  2059. "total": total,
  2060. "records": records,
  2061. })
  2062. return
  2063. }
  2064. func (c *PatientApiController) GetPatientMonitor() {
  2065. partition, _ := c.GetInt64("partition")
  2066. monitorDate := c.GetString("date")
  2067. patient_id, _ := c.GetInt64("patient_id")
  2068. timeLayout := "2006-01-02"
  2069. loc, _ := time.LoadLocation("Local")
  2070. var theStartTime int64
  2071. if len(monitorDate) > 0 {
  2072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  2073. if err != nil {
  2074. theStartTime = 0
  2075. }
  2076. theStartTime = theTime.Unix()
  2077. }
  2078. adminInfo := c.GetMobileAdminUserInfo()
  2079. orgID := adminInfo.Org.Id
  2080. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  2081. //获取患者的透析次数
  2082. count, err := service.GetDialysisCount(orgID, partition)
  2083. patients, err := service.GetAllpatient(orgID)
  2084. if err == nil {
  2085. c.ServeSuccessJSON(map[string]interface{}{
  2086. "monitor": monitor,
  2087. "patientCount": count,
  2088. "patients": patients,
  2089. })
  2090. } else {
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2092. }
  2093. }
  2094. // /m/api/monitor/patient [get] 搜索病人的测量记录
  2095. // @param keyword:string 病人姓名或透析号
  2096. // @param page:int
  2097. func (this *PatientApiController) SearchMonitorPatient() {
  2098. keyword := this.GetString("keyword")
  2099. page, _ := this.GetInt("page")
  2100. if page <= 0 {
  2101. page = 1
  2102. }
  2103. if len(keyword) == 0 {
  2104. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2105. return
  2106. }
  2107. adminUserInfo := this.GetMobileAdminUserInfo()
  2108. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  2109. if getMonitorErr != nil {
  2110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2111. return
  2112. } else {
  2113. this.ServeSuccessJSON(map[string]interface{}{
  2114. "monitor": monitors,
  2115. })
  2116. }
  2117. }
  2118. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  2119. id, _ := c.GetInt64("id", 0)
  2120. page, _ := c.GetInt64("page", 0)
  2121. limit, _ := c.GetInt64("limit", 0)
  2122. if id <= 0 {
  2123. c.ServeSuccessJSON(map[string]interface{}{
  2124. "solutions": nil,
  2125. })
  2126. return
  2127. }
  2128. if page <= 0 {
  2129. page = 1
  2130. }
  2131. if limit <= 0 {
  2132. limit = 10
  2133. }
  2134. adminInfo := c.GetMobileAdminUserInfo()
  2135. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  2136. c.ServeSuccessJSON(map[string]interface{}{
  2137. "solutions": solutions,
  2138. "total": total,
  2139. })
  2140. return
  2141. }
  2142. //GetDoctorAdvices 医嘱列表
  2143. func (c *PatientApiController) GetDoctorAdvices() {
  2144. id, _ := c.GetInt64("id", 0)
  2145. adviceType, _ := c.GetInt64("advice_type", 0)
  2146. stopType, _ := c.GetInt64("stop_state", 0)
  2147. startTime := c.GetString("start_time", "")
  2148. endTime := c.GetString("end_time", "")
  2149. keywords := c.GetString("keywords", "")
  2150. need, _ := c.GetInt64("need_doctor", 0)
  2151. adminUserInfo := c.GetMobileAdminUserInfo()
  2152. timeLayout := "2006-01-02"
  2153. loc, _ := time.LoadLocation("Local")
  2154. var theStartTIme int64
  2155. if len(startTime) > 0 {
  2156. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2157. if err != nil {
  2158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2159. return
  2160. }
  2161. theStartTIme = theTime.Unix()
  2162. }
  2163. var theEndtTIme int64
  2164. if len(endTime) > 0 {
  2165. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2166. if err != nil {
  2167. utils.ErrorLog(err.Error())
  2168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2169. return
  2170. }
  2171. theEndtTIme = theTime.Unix()
  2172. }
  2173. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  2174. if need == 1 {
  2175. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2176. c.ServeSuccessJSON(map[string]interface{}{
  2177. "advices": advices,
  2178. "total": total,
  2179. "users": users,
  2180. })
  2181. } else {
  2182. c.ServeSuccessJSON(map[string]interface{}{
  2183. "advices": advices,
  2184. "total": total,
  2185. "users": []string{},
  2186. })
  2187. }
  2188. return
  2189. }
  2190. func (c *PatientApiController) GetPrintDialysisOrder() {
  2191. xtno := c.GetString("xtno")
  2192. xtdate := c.GetString("xtdate")
  2193. timeLayout := "2006-01-02"
  2194. loc, _ := time.LoadLocation("Local")
  2195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2196. if err != nil {
  2197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2198. return
  2199. }
  2200. xttime := theTime.Unix()
  2201. //获取当前日期月份的第一天
  2202. firstmonth := service.GetFirstDateOfMonth(theTime)
  2203. firstMonthDate := firstmonth.Unix()
  2204. operatorIDs := make([]int64, 0)
  2205. adminUserInfo := c.GetMobileAdminUserInfo()
  2206. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2207. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  2208. //透析单
  2209. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2210. if dialysisOrder != nil {
  2211. if dialysisOrder.FinishNurse > 0 {
  2212. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2213. }
  2214. if dialysisOrder.StartNurse > 0 {
  2215. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2216. }
  2217. }
  2218. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2219. //透前评估
  2220. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2221. //透后评估
  2222. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2223. if AssessmentAfterDislysis.Modifier > 0 {
  2224. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2225. }
  2226. //透析处方
  2227. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2228. if dialysisPrescription.PrescriptionDoctor > 0 {
  2229. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2230. }
  2231. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2232. patientInfo.TotalDialysis = dialysis_count
  2233. //临时医嘱
  2234. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2235. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2236. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  2237. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  2238. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2239. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  2240. for _, item := range projects {
  2241. var advice *models.HisDoctorAdviceInfo
  2242. advice.ID = item.ID
  2243. advice.Checker = item.Checker
  2244. advice.CheckTime = item.CheckTime
  2245. advice.CheckState = item.CheckState
  2246. advice.ExecutionState = item.ExecutionState
  2247. advice.ExecutionStaff = item.ExecutionStaff
  2248. advice.PrescribingNumber = float64(item.Count)
  2249. advice.PrescribingNumberUnit = item.Unit
  2250. advice.AdviceDoctor = item.Doctor
  2251. if item.Type == 3 {
  2252. advice.AdviceName = item.GoodInfo.GoodName
  2253. } else if item.Type == 2 {
  2254. advice.AdviceName = item.HisProject.ProjectName
  2255. }
  2256. advice.StartTime = item.StartTime
  2257. hisAdvice = append(hisAdvice, advice)
  2258. }
  2259. }
  2260. if len(DoctorAdvice) > 0 {
  2261. for _, item := range DoctorAdvice {
  2262. if item.AdviceDoctor > 0 {
  2263. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2264. }
  2265. if item.ExecutionStaff > 0 {
  2266. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2267. }
  2268. if item.Checker > 0 {
  2269. operatorIDs = append(operatorIDs, item.Checker)
  2270. }
  2271. }
  2272. }
  2273. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2274. //透析监测
  2275. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2276. //透析小结
  2277. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2278. //接诊评估
  2279. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2280. //相关操作对应的操作人
  2281. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  2282. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  2283. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2284. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2285. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  2286. if config.IsOpen == 1 {
  2287. c.ServeSuccessJSON(map[string]interface{}{
  2288. "users": adminUser,
  2289. "patientInfo": patientInfo,
  2290. "PredialysisEvaluation": PredialysisEvaluation,
  2291. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2292. "dialysisPrescription": dialysisPrescription,
  2293. "advices": hisAdvice,
  2294. "monitors": Record,
  2295. "summary": TreatmentSummary,
  2296. "receiverTreatmentAccess": receiverTreatmentAccess,
  2297. "dialysisOrder": dialysisOrder,
  2298. "operators": operators,
  2299. "org_template_info": templateInfo,
  2300. "check": check,
  2301. "dialysiscount": dialysiscount,
  2302. "last_order": last_order,
  2303. })
  2304. }
  2305. if config.IsOpen == 0 || config.IsOpen == 2 {
  2306. c.ServeSuccessJSON(map[string]interface{}{
  2307. "users": adminUser,
  2308. "patientInfo": patientInfo,
  2309. "PredialysisEvaluation": PredialysisEvaluation,
  2310. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2311. "dialysisPrescription": dialysisPrescription,
  2312. "advices": DoctorAdvice,
  2313. "monitors": Record,
  2314. "summary": TreatmentSummary,
  2315. "receiverTreatmentAccess": receiverTreatmentAccess,
  2316. "dialysisOrder": dialysisOrder,
  2317. "operators": operators,
  2318. "org_template_info": templateInfo,
  2319. "check": check,
  2320. "dialysiscount": dialysiscount,
  2321. "last_order": last_order,
  2322. })
  2323. }
  2324. }
  2325. func (c *PatientApiController) CreateGroupAdvice() {
  2326. is_child, _ := c.GetInt64("is_child", 0)
  2327. if is_child == 1 {
  2328. patient, _ := c.GetInt64("id", 0)
  2329. if patient <= 0 {
  2330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2331. return
  2332. }
  2333. adminUserInfo := c.GetMobileAdminUserInfo()
  2334. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2335. if patientInfo.ID == 0 {
  2336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2337. return
  2338. }
  2339. group_no, _ := c.GetInt64("group_no")
  2340. if group_no <= 0 {
  2341. group_no = 0
  2342. }
  2343. dataBody := make(map[string]interface{}, 0)
  2344. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2345. if err != nil {
  2346. utils.ErrorLog(err.Error())
  2347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2348. return
  2349. }
  2350. timeLayout := "2006-01-02"
  2351. loc, _ := time.LoadLocation("Local")
  2352. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2353. utils.ErrorLog("advice_type")
  2354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2355. return
  2356. }
  2357. adviceType := int64(dataBody["advice_type"].(float64))
  2358. if adviceType != 1 && adviceType != 2 {
  2359. utils.ErrorLog("advice_type != 1&&2")
  2360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2361. return
  2362. }
  2363. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2364. utils.ErrorLog("start_time")
  2365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2366. return
  2367. }
  2368. startTime2, _ := dataBody["start_time"].(string)
  2369. time_arr := strings.Split(startTime2, " ")
  2370. if len(time_arr) > 0 {
  2371. startTime2 = time_arr[0]
  2372. }
  2373. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2374. utils.ErrorLog("advice_date")
  2375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2376. return
  2377. }
  2378. adviceDate := startTime2
  2379. if len(adviceDate) == 0 {
  2380. utils.ErrorLog("len(adviceDate) == 0")
  2381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2382. return
  2383. }
  2384. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2385. if err != nil {
  2386. utils.ErrorLog(err.Error())
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2388. return
  2389. }
  2390. AdviceDate := theTime.Unix()
  2391. RecordDate := theTime.Unix()
  2392. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2393. utils.ErrorLog("start_time")
  2394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2395. return
  2396. }
  2397. startTime, _ := dataBody["start_time"].(string)
  2398. if len(startTime) == 0 {
  2399. utils.ErrorLog("len(start_time) == 0")
  2400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2401. return
  2402. }
  2403. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2404. if err != nil {
  2405. utils.ErrorLog(err.Error())
  2406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2407. return
  2408. }
  2409. StartTime := theTime.Unix()
  2410. Remark := ""
  2411. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2412. remark, _ := dataBody["remark"].(string)
  2413. Remark = remark
  2414. }
  2415. var advices []*models.GroupAdvice
  2416. // utils.TraceLog("%+v", dataBody["adviceNames"])
  2417. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  2418. utils.ErrorLog("adviceNames")
  2419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2420. return
  2421. }
  2422. adviceNames := dataBody["adviceNames"].([]interface{})
  2423. for _, adviceNameMap := range adviceNames {
  2424. adviceNameM := adviceNameMap.(map[string]interface{})
  2425. var advice models.GroupAdvice
  2426. advice.Remark = Remark
  2427. advice.AdviceType = adviceType
  2428. advice.StartTime = StartTime
  2429. advice.AdviceDate = AdviceDate
  2430. advice.RecordDate = RecordDate
  2431. advice.Status = 1
  2432. advice.CreatedTime = time.Now().Unix()
  2433. advice.UpdatedTime = time.Now().Unix()
  2434. advice.StopState = 2
  2435. advice.ExecutionState = 2
  2436. advice.UserOrgId = adminUserInfo.Org.Id
  2437. advice.PatientId = patientInfo.ID
  2438. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2439. //入口
  2440. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2441. if errcode > 0 {
  2442. c.ServeFailJSONWithSGJErrorCode(errcode)
  2443. return
  2444. }
  2445. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2446. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2447. if len(subdrugs) > 0 {
  2448. for _, subdrug := range subdrugs {
  2449. var s models.GroupAdvice
  2450. s.Remark = Remark
  2451. s.AdviceType = adviceType
  2452. s.StartTime = StartTime
  2453. s.AdviceDate = AdviceDate
  2454. s.RecordDate = RecordDate
  2455. s.Status = 1
  2456. s.CreatedTime = time.Now().Unix()
  2457. s.UpdatedTime = time.Now().Unix()
  2458. s.StopState = 2
  2459. s.ExecutionState = 2
  2460. s.UserOrgId = adminUserInfo.Org.Id
  2461. s.PatientId = patientInfo.ID
  2462. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2463. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2464. if errcode > 0 {
  2465. c.ServeFailJSONWithSGJErrorCode(errcode)
  2466. return
  2467. }
  2468. advice.Children = append(advice.Children, &s)
  2469. }
  2470. }
  2471. }
  2472. advices = append(advices, &advice)
  2473. }
  2474. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  2475. if createErr != nil {
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2477. return
  2478. }
  2479. c.ServeSuccessJSON(map[string]interface{}{
  2480. "msg": "ok",
  2481. "advices": newAdvices,
  2482. })
  2483. return
  2484. } else if is_child == 2 {
  2485. patient, _ := c.GetInt64("id", 0)
  2486. if patient <= 0 {
  2487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2488. return
  2489. }
  2490. adminUserInfo := c.GetMobileAdminUserInfo()
  2491. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2492. if patientInfo.ID == 0 {
  2493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2494. return
  2495. }
  2496. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2497. //if appRole.UserType == 3{
  2498. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  2499. // return
  2500. //}
  2501. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2502. //
  2503. //if appRole.UserType == 3 {
  2504. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2505. // if getPermissionErr != nil {
  2506. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2507. // return
  2508. // } else if headNursePermission == nil {
  2509. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2510. // return
  2511. // }
  2512. //}
  2513. var advice models.DoctorAdvice
  2514. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  2515. if code > 0 {
  2516. c.ServeFailJSONWithSGJErrorCode(code)
  2517. return
  2518. }
  2519. if advice.ParentId > 0 {
  2520. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  2521. if old.ID == 0 || old.PatientId != patient {
  2522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2523. return
  2524. }
  2525. if old.StopState == 1 || old.ExecutionState == 1 {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2527. return
  2528. }
  2529. if old.ParentId > 0 {
  2530. advice.ParentId = old.ParentId
  2531. }
  2532. advice.StartTime = old.StartTime
  2533. advice.AdviceDoctor = old.AdviceDoctor
  2534. advice.DeliveryWay = old.DeliveryWay
  2535. advice.ExecutionFrequency = old.ExecutionFrequency
  2536. advice.GroupNo = old.GroupNo
  2537. }
  2538. advice.Status = 1
  2539. advice.CreatedTime = time.Now().Unix()
  2540. advice.UpdatedTime = time.Now().Unix()
  2541. advice.StopState = 2
  2542. advice.ExecutionState = 2
  2543. advice.UserOrgId = adminUserInfo.Org.Id
  2544. advice.PatientId = patient
  2545. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2546. err := service.CreateDoctorAdvice(&advice)
  2547. if err != nil {
  2548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2549. return
  2550. }
  2551. c.ServeSuccessJSON(map[string]interface{}{
  2552. "msg": "ok",
  2553. "advice": advice,
  2554. })
  2555. return
  2556. }
  2557. }
  2558. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  2559. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  2560. utils.ErrorLog("advice_name")
  2561. return enums.ErrorCodeParamWrong
  2562. }
  2563. adviceName, _ := json["advice_name"].(string)
  2564. if len(adviceName) == 0 {
  2565. utils.ErrorLog("len(advice_name) == 0")
  2566. return enums.ErrorCodeParamWrong
  2567. }
  2568. advice.AdviceName = adviceName
  2569. adviceDesc, _ := json["advice_desc"].(string)
  2570. advice.AdviceDesc = adviceDesc
  2571. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2572. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2573. advice.DrugSpec = drugSpec
  2574. }
  2575. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2576. remark, _ := json["remark"].(string)
  2577. advice.Remark = remark
  2578. }
  2579. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  2580. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  2581. // advice.Way = src_type
  2582. //}
  2583. if json["way"] == nil {
  2584. advice.Way = 0
  2585. } else {
  2586. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  2587. way := int64(json["way"].(float64))
  2588. advice.Way = way
  2589. }
  2590. }
  2591. if json["drug_id"] == nil {
  2592. advice.DrugId = 0
  2593. } else {
  2594. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  2595. drug_id := int64(json["drug_id"].(float64))
  2596. advice.DrugId = drug_id
  2597. }
  2598. }
  2599. if json["drug_name_id"] == nil {
  2600. advice.DrugNameId = 0
  2601. } else {
  2602. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  2603. drug_name_id := int64(json["drug_name_id"].(float64))
  2604. advice.DrugNameId = drug_name_id
  2605. }
  2606. }
  2607. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  2608. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  2609. advice.DrugSpecUnit = drugSpecUnit
  2610. }
  2611. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2612. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2613. advice.SingleDose = singleDose
  2614. }
  2615. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2616. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2617. advice.SingleDoseUnit = singleDoseUnit
  2618. }
  2619. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2620. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2621. advice.PrescribingNumber = prescribingNumber
  2622. }
  2623. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2624. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2625. advice.PrescribingNumberUnit = prescribingNumberUnit
  2626. }
  2627. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2628. deliveryWay, _ := json["delivery_way"].(string)
  2629. advice.DeliveryWay = deliveryWay
  2630. }
  2631. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2632. executionFrequency, _ := json["execution_frequency"].(string)
  2633. advice.ExecutionFrequency = executionFrequency
  2634. }
  2635. return 0
  2636. }
  2637. func (c *PatientApiController) DelDoctorAdvice() {
  2638. groupno, _ := c.GetInt64("groupno", -1)
  2639. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  2640. if is_sub == 1 { //是
  2641. advice_id, _ := c.GetInt64("advice_id")
  2642. adminUserInfo := c.GetMobileAdminUserInfo()
  2643. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2644. if advice.ID == 0 {
  2645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2646. return
  2647. }
  2648. advice.Status = 0
  2649. advice.UpdatedTime = time.Now().Unix()
  2650. advice.Modifier = adminUserInfo.AdminUser.Id
  2651. err := service.DeleteDoctorAdvice(&advice)
  2652. if err != nil {
  2653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2654. return
  2655. }
  2656. c.ServeSuccessJSON(map[string]interface{}{
  2657. "msg": "ok",
  2658. })
  2659. return
  2660. } else { //
  2661. var ids []string
  2662. if groupno == 0 {
  2663. advice_id := c.GetString("advice_id")
  2664. ids = strings.Split(advice_id, ",")
  2665. if len(ids) <= 0 {
  2666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2667. return
  2668. }
  2669. }
  2670. if groupno < 0 {
  2671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2672. return
  2673. }
  2674. adminUserInfo := c.GetMobileAdminUserInfo()
  2675. var advice models.DoctorAdvice
  2676. if groupno > 0 {
  2677. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2678. if advice.ID == 0 {
  2679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2680. return
  2681. }
  2682. } else {
  2683. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2684. for _, item := range advices {
  2685. if item.ID == 0 {
  2686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2687. return
  2688. }
  2689. }
  2690. }
  2691. advice.UpdatedTime = time.Now().Unix()
  2692. advice.Status = 0
  2693. advice.GroupNo = groupno
  2694. advice.Modifier = adminUserInfo.AdminUser.Id
  2695. var err error
  2696. if groupno > 0 {
  2697. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  2698. } else {
  2699. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  2700. }
  2701. if err != nil {
  2702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2703. return
  2704. }
  2705. c.ServeSuccessJSON(map[string]interface{}{
  2706. "msg": "ok",
  2707. })
  2708. return
  2709. }
  2710. }
  2711. // /m/api/advice/group/modify_starttime [post]
  2712. // @param group_no:int
  2713. // @param start_time:string yyyy-MM-dd hh:mm:ss
  2714. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  2715. group_no, _ := this.GetInt64("group_no")
  2716. start_time_str := this.GetString("start_time")
  2717. if group_no <= 0 || len(start_time_str) == 0 {
  2718. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2719. return
  2720. }
  2721. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  2722. if parseTimeErr != nil {
  2723. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  2724. return
  2725. }
  2726. adminUserInfo := this.GetMobileAdminUserInfo()
  2727. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  2728. if updateStartTimeErr != nil {
  2729. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  2730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2731. return
  2732. }
  2733. this.ServeSuccessJSON(map[string]interface{}{
  2734. "start_time": startTime.Unix(),
  2735. })
  2736. }
  2737. func (this *PatientApiController) DelSubDoctorAdvice() {
  2738. advice_id, _ := this.GetInt64("advice_id")
  2739. adminUserInfo := this.GetMobileAdminUserInfo()
  2740. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2741. if advice.ID == 0 {
  2742. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2743. return
  2744. }
  2745. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2746. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  2747. // return
  2748. //}
  2749. advice.Status = 0
  2750. advice.UpdatedTime = time.Now().Unix()
  2751. advice.Modifier = adminUserInfo.AdminUser.Id
  2752. err := service.DeleteDoctorAdvice(&advice)
  2753. if err != nil {
  2754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2755. return
  2756. }
  2757. this.ServeSuccessJSON(map[string]interface{}{
  2758. "msg": "ok",
  2759. })
  2760. return
  2761. }
  2762. func (this *PatientApiController) GetAdviceUnReadMessage() {
  2763. //adminUserInfo := this.GetMobileAdminUserInfo()
  2764. //service.FindUnReadDoctorAdviceMessage()
  2765. }
  2766. func (this *PatientApiController) GetPatientsByKeyWord() {
  2767. keyWord := this.GetString("keyword")
  2768. adminUserInfo := this.GetMobileAdminUserInfo()
  2769. today := utils.ZeroHourTimeOfDay(time.Now())
  2770. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  2771. if err != nil {
  2772. utils.ErrorLog(err.Error())
  2773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2774. return
  2775. }
  2776. this.ServeSuccessJSON(map[string]interface{}{
  2777. "patient": patient,
  2778. })
  2779. }
  2780. func (this *PatientApiController) GetSearchPatient() {
  2781. keyWord := this.GetString("keyword")
  2782. adminUserInfo := this.GetMobileAdminUserInfo()
  2783. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  2784. if err != nil {
  2785. utils.ErrorLog(err.Error())
  2786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2787. return
  2788. }
  2789. this.ServeSuccessJSON(map[string]interface{}{
  2790. "patient": patient,
  2791. })
  2792. }
  2793. func (c *PatientApiController) ExecProject() {
  2794. execution_time := c.GetString("execution_time")
  2795. project_id, _ := c.GetInt64("project_id")
  2796. if len(execution_time) <= 0 {
  2797. utils.ErrorLog("execution_time")
  2798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2799. return
  2800. }
  2801. timeLayout2 := "2006-01-02 15:04:05"
  2802. loc, _ := time.LoadLocation("Local")
  2803. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2804. if errs != nil {
  2805. utils.ErrorLog(errs.Error())
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. adminInfo := c.GetMobileAdminUserInfo()
  2810. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  2811. if project.ExecutionState == 1 {
  2812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  2813. return
  2814. }
  2815. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  2816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2817. return
  2818. }
  2819. project.ExecutionState = 1
  2820. project.ExecutionStaff = adminInfo.AdminUser.Id
  2821. project.ExecutionTime = theTime.Unix()
  2822. err := service.SaveHisProject(&project)
  2823. if err == nil {
  2824. c.ServeSuccessJSON(map[string]interface{}{
  2825. "project": project,
  2826. })
  2827. } else {
  2828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2829. return
  2830. }
  2831. }
  2832. func (c *PatientApiController) CheckProject() {
  2833. adminInfo := c.GetMobileAdminUserInfo()
  2834. project_id, _ := c.GetInt64("project_id")
  2835. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  2836. if project.CheckState == 1 {
  2837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  2838. return
  2839. }
  2840. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  2842. return
  2843. }
  2844. project.Checker = adminInfo.AdminUser.Id
  2845. project.CheckTime = time.Now().Unix()
  2846. project.CheckState = 1
  2847. err := service.SaveHisProject(&project)
  2848. if err == nil {
  2849. c.ServeSuccessJSON(map[string]interface{}{
  2850. "msg": "ok",
  2851. "project": project,
  2852. })
  2853. } else {
  2854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2855. return
  2856. }
  2857. }