patient_api_controller.go 157KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401
  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. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  271. if advice.StartTime == sourceAdvice.StartTime {
  272. err = service.UpdateDoctorAdvice(&advice)
  273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  274. defer redis.Close()
  275. redis.Set(key, "", time.Second)
  276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  277. redis.Set(keyOne, "", time.Second)
  278. isChangeGroup = false
  279. } else {
  280. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  281. isChangeGroup = false
  282. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  283. defer redis.Close()
  284. redis.Set(key, "", time.Second)
  285. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  286. redis.Set(keyOne, "", time.Second)
  287. }
  288. } else if len(adviceSlice) > 1 {
  289. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  290. if advice.StartTime == sourceAdvice.StartTime {
  291. err = service.UpdateDoctorAdvice(&advice)
  292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  293. defer redis.Close()
  294. redis.Set(key, "", time.Second)
  295. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  296. redis.Set(keyOne, "", time.Second)
  297. isChangeGroup = false
  298. } else {
  299. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  300. gruopNo = gruopNo + 1
  301. advice.GroupNo = gruopNo
  302. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  303. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  304. defer redis.Close()
  305. redis.Set(key, "", time.Second)
  306. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  307. redis.Set(keyOne, "", time.Second)
  308. isChangeGroup = true
  309. }
  310. }
  311. } else {
  312. isChangeGroup = false
  313. err = service.UpdateDoctorAdvice(&advice)
  314. redis := service.RedisClient()
  315. defer redis.Close()
  316. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  317. redis.Set(key, "", time.Second)
  318. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  319. redis.Set(keyOne, "", time.Second)
  320. }
  321. if err != nil {
  322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  323. return
  324. }
  325. if !isChangeGroup {
  326. c.ServeSuccessJSON(map[string]interface{}{
  327. "msg": "ok",
  328. "advice": advice,
  329. "isChange": isChangeGroup, //方便前端处理数据
  330. })
  331. } else {
  332. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  333. if err != nil {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  335. return
  336. }
  337. c.ServeSuccessJSON(map[string]interface{}{
  338. "msg": "ok",
  339. "advice": newGroupAdvice,
  340. "isChange": isChangeGroup, //方便前端处理数据
  341. })
  342. }
  343. return
  344. }
  345. func (c *PatientApiController) StopDoctorAdvice() {
  346. id, _ := c.GetInt64("id", 0)
  347. if id <= 0 {
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  349. return
  350. }
  351. adminUserInfo := c.GetMobileAdminUserInfo()
  352. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  353. if advice.ID == 0 {
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  355. return
  356. }
  357. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  358. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  359. // return
  360. //}
  361. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  362. //
  363. //if appRole.UserType == 3 {
  364. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  365. // if getPermissionErr != nil {
  366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. // return
  368. // } else if headNursePermission == nil {
  369. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  370. // return
  371. // }
  372. //}
  373. if advice.StopState == 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  375. return
  376. }
  377. dataBody := make(map[string]interface{}, 0)
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  379. if err != nil {
  380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  381. return
  382. }
  383. timeLayout := "2006-01-02"
  384. loc, _ := time.LoadLocation("Local")
  385. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  386. utils.ErrorLog("stop_time")
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. stopTime, _ := dataBody["stop_time"].(string)
  391. if len(stopTime) == 0 {
  392. utils.ErrorLog("len(stop_time) == 0")
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  397. if err != nil {
  398. utils.ErrorLog(err.Error())
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. advice.StopTime = theTime.Unix()
  403. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  404. utils.ErrorLog("stop_reason")
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. stopReason, _ := dataBody["stop_reason"].(string)
  409. if len(stopReason) == 0 {
  410. utils.ErrorLog("len(stop_reason) == 0")
  411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  412. return
  413. }
  414. advice.StopReason = stopReason
  415. advice.Status = 1
  416. advice.UpdatedTime = time.Now().Unix()
  417. advice.StopDoctor = adminUserInfo.AdminUser.Id
  418. advice.StopState = 1
  419. advice.StopTime = time.Now().Unix()
  420. advice.Modifier = adminUserInfo.AdminUser.Id
  421. err = service.StopDoctorAdvice(&advice)
  422. if err != nil {
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  424. return
  425. }
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "msg": "ok",
  428. "advice": advice,
  429. })
  430. return
  431. }
  432. func (c *PatientApiController) DeleteDoctorAdvice() {
  433. id, _ := c.GetInt64("id", 0)
  434. if id <= 0 {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. adminUserInfo := c.GetMobileAdminUserInfo()
  439. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  440. if advice.ID == 0 {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  442. return
  443. }
  444. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  446. // return
  447. //}
  448. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  449. //
  450. //if appRole.UserType == 3 {
  451. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  452. // if getPermissionErr != nil {
  453. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  454. // return
  455. // } else if headNursePermission == nil {
  456. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  457. // return
  458. // }
  459. //}
  460. advice.UpdatedTime = time.Now().Unix()
  461. advice.Status = 0
  462. advice.Modifier = adminUserInfo.AdminUser.Id
  463. err := service.DeleteDoctorAdvice(&advice)
  464. if err != nil {
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  466. return
  467. }
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "msg": "ok",
  470. })
  471. return
  472. }
  473. func (c *PatientApiController) ExecDoctorAdvice() {
  474. execution_time := c.GetString("execution_time")
  475. origin, _ := c.GetInt64("origin", 0)
  476. groupno, _ := c.GetInt64("groupno", -1)
  477. if origin != 2 {
  478. adminUserInfo := c.GetMobileAdminUserInfo()
  479. execution_staff := adminUserInfo.AdminUser.Id
  480. var ids []string
  481. advice_ids := c.GetString("advice_id")
  482. if groupno == 0 {
  483. ids = strings.Split(advice_ids, ",")
  484. }
  485. if groupno < 0 {
  486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  487. return
  488. }
  489. if len(execution_time) <= 0 {
  490. utils.ErrorLog("execution_time")
  491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  492. return
  493. }
  494. timeLayout2 := "2006-01-02 15:04:05"
  495. loc, _ := time.LoadLocation("Local")
  496. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  497. if errs != nil {
  498. utils.ErrorLog(errs.Error())
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  500. return
  501. }
  502. var advice models.DoctorAdvice
  503. if groupno > 0 {
  504. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  505. for _, item := range advices {
  506. if item.ExecutionState == 2 {
  507. advice = item
  508. }
  509. }
  510. } else {
  511. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  512. for _, item := range advices {
  513. if item.ExecutionState == 2 {
  514. advice = item
  515. }
  516. }
  517. }
  518. if advice.ExecutionState == 1 {
  519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  520. return
  521. }
  522. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  524. return
  525. }
  526. if advice.StartTime > theTime.Unix() {
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  528. return
  529. }
  530. advices := models.DoctorAdvice{
  531. ExecutionStaff: execution_staff,
  532. ExecutionTime: theTime.Unix(),
  533. UpdatedTime: time.Now().Unix(),
  534. }
  535. var err error
  536. if groupno > 0 {
  537. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  539. redis := service.RedisClient()
  540. //清空key 值
  541. redis.Set(key, "", time.Second)
  542. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  543. redis.Set(keyTwo, "", time.Second)
  544. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  545. redis.Set(keyThree, "", time.Second)
  546. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  547. theTime := toTime.Format("2006-01-02")
  548. fmt.Println("theTIME", theTime)
  549. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  550. redis.Set(keyFour, "", time.Second)
  551. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  552. redis.Set(keyFive, "", time.Second)
  553. defer redis.Close()
  554. } else {
  555. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  556. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  557. redis := service.RedisClient()
  558. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  559. redis.Set(keyTwo, "", time.Second)
  560. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  561. redis.Set(keyThree, "", time.Second)
  562. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  563. theTime := toTime.Format("2006-01-02")
  564. fmt.Println("theTIME", theTime)
  565. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  566. redis.Set(keyFour, "", time.Second)
  567. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  568. redis.Set(keySix, "", time.Second)
  569. defer redis.Close()
  570. //清空key 值
  571. redis.Set(key, "", time.Second)
  572. }
  573. if err != nil {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  575. return
  576. }
  577. advice.ExecutionStaff = execution_staff
  578. advice.ExecutionTime = theTime.Unix()
  579. advice.ExecutionState = 1
  580. advice.Modifier = adminUserInfo.AdminUser.Id
  581. //处理出库相关逻辑
  582. //1.判断是否启用药品管理和自备药出库功能
  583. //药品管理信息
  584. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  585. //自备药信息
  586. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  587. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  588. fmt.Println("drugStockConfig.IsOpen32232323232", drugStockConfig.IsOpen)
  589. if drugStockConfig.IsOpen == 1 {
  590. if groupno > 0 {
  591. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  592. isHasWay := false //用来判断是否包含来自药品库的医嘱
  593. for _, item := range advices {
  594. if item.Way == 1 {
  595. isHasWay = true
  596. }
  597. }
  598. if isHasWay {
  599. var total int64
  600. var prescribing_number_total int64
  601. fmt.Println("advicesssssssssssssssss", len(advices))
  602. for _, item := range advices {
  603. if item.Way == 1 {
  604. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  605. //查询该药品的剩余库存
  606. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  607. //查询改药品信息
  608. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  609. //判断单位是否相等
  610. if medical.MaxUnit == item.PrescribingNumberUnit {
  611. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  612. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  613. //转化为最小单位
  614. total = list.Count * medical.MinNumber
  615. prescribing_number_total = count * medical.MinNumber
  616. }
  617. if medical.MinUnit == item.PrescribingNumberUnit {
  618. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  619. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  620. total = list.Count*medical.MinNumber + list.StockMinNumber
  621. prescribing_number_total = count
  622. }
  623. if medical.IsUse == 1 {
  624. c.ServeSuccessJSON(map[string]interface{}{
  625. "msg": "1",
  626. "advice": advice,
  627. "ids": ids,
  628. })
  629. return
  630. }
  631. if medical.IsUse != 1 {
  632. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  633. c.ServeSuccessJSON(map[string]interface{}{
  634. "msg": "3",
  635. "advice": advice,
  636. "ids": ids,
  637. })
  638. return
  639. }
  640. if prescribing_number_total > total {
  641. c.ServeSuccessJSON(map[string]interface{}{
  642. "msg": "2",
  643. "advice": advice,
  644. "ids": ids,
  645. })
  646. return
  647. }
  648. }
  649. if prescribing_number_total <= total {
  650. //查询是否出库按钮开启
  651. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  652. if adviceSetting.IsAdviceOpen == 1 {
  653. //查询是否出库按钮开启
  654. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  655. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  656. if prescriptionConfig.IsOpen == 1 {
  657. if medical.IsUse == 2 {
  658. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  659. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  660. }
  661. if pharmacyConfig.IsOpen != 1 {
  662. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  663. }
  664. //更新字典里面的库存
  665. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  666. var sum_count int64
  667. for _, its := range stockInfo {
  668. if its.MaxUnit == medical.MaxUnit {
  669. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  670. }
  671. sum_count += its.StockMaxNumber + its.StockMinNumber
  672. }
  673. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  674. //剩余库存
  675. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  676. }
  677. }
  678. } else {
  679. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  680. if medical.IsUse == 2 {
  681. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  682. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  683. }
  684. if pharmacyConfig.IsOpen != 1 {
  685. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  686. }
  687. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  688. var sum_count int64
  689. for _, its := range stockInfo {
  690. if its.MaxUnit == medical.MaxUnit {
  691. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  692. }
  693. sum_count += its.StockMaxNumber + its.StockMinNumber
  694. }
  695. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  696. //剩余库存
  697. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  698. }
  699. }
  700. }
  701. }
  702. }
  703. }
  704. } else {
  705. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  706. isHasWay := false //用来判断是否包含来自药品库的医嘱
  707. for _, item := range advices {
  708. if item.Way == 1 {
  709. isHasWay = true
  710. }
  711. }
  712. if isHasWay {
  713. var total int64
  714. var prescribing_number_total int64
  715. for _, item := range advices {
  716. if item.Way == 1 {
  717. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  718. //查询该药品的剩余库存
  719. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  720. //查询改药品信息
  721. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  722. //判断单位是否相等
  723. if medical.MaxUnit == item.PrescribingNumberUnit {
  724. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  725. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  726. //转化为最小单位
  727. total = list.Count*medical.MinNumber + list.StockMinNumber
  728. prescribing_number_total = count * medical.MinNumber
  729. }
  730. if medical.MinUnit == item.PrescribingNumberUnit {
  731. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  732. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  733. total = list.Count*medical.MinNumber + list.StockMinNumber
  734. prescribing_number_total = count
  735. }
  736. if medical.IsUse == 1 {
  737. c.ServeSuccessJSON(map[string]interface{}{
  738. "msg": "1",
  739. "advice": advice,
  740. "ids": ids,
  741. })
  742. return
  743. }
  744. if medical.IsUse != 1 {
  745. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  746. c.ServeSuccessJSON(map[string]interface{}{
  747. "msg": "3",
  748. "advice": advice,
  749. "ids": ids,
  750. })
  751. return
  752. }
  753. if prescribing_number_total > total {
  754. c.ServeSuccessJSON(map[string]interface{}{
  755. "msg": "2",
  756. "advice": advice,
  757. "ids": ids,
  758. })
  759. return
  760. }
  761. }
  762. if prescribing_number_total <= total {
  763. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  764. if medical.IsUse == 2 {
  765. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  766. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  767. }
  768. if pharmacyConfig.IsOpen != 1 {
  769. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  770. }
  771. //更新字典里面的库存
  772. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  773. var sum_count int64
  774. for _, its := range stockInfo {
  775. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  776. if its.MaxUnit == baseDrug.MaxUnit {
  777. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  778. }
  779. sum_count += its.StockMaxNumber + its.StockMinNumber
  780. }
  781. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  782. //剩余库存
  783. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  784. }
  785. if medical.IsUse == 1 {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "msg": "1",
  788. "advice": advice,
  789. "ids": ids,
  790. })
  791. return
  792. }
  793. }
  794. }
  795. }
  796. }
  797. }
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "msg": "1",
  800. "advice": advice,
  801. "ids": ids,
  802. })
  803. return
  804. }
  805. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  806. if groupno > 0 {
  807. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  808. for _, item := range advices {
  809. if item.ExecutionState == 1 && item.Way == 2 {
  810. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  811. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  812. timeStr := time.Now().Format("2006-01-02")
  813. timeArr := strings.Split(timeStr, "-")
  814. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  815. total = total + 1
  816. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  817. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  818. number = number + total
  819. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  820. //插入自备药出库单
  821. outStock := models.XtSelfOutStock{
  822. DrugName: item.AdviceName,
  823. DrugNameId: item.DrugNameId,
  824. DrugSpec: item.AdviceDesc,
  825. OutstoreNumber: count,
  826. AdminUserId: adminUserInfo.AdminUser.Id,
  827. StorckTime: item.AdviceDate,
  828. UserOrgId: adminUserInfo.Org.Id,
  829. CreatedTime: time.Now().Unix(),
  830. Status: 1,
  831. PatientId: item.PatientId,
  832. ExitMode: 2,
  833. MedicId: item.DrugId,
  834. StockOutNumber: warehousing_out_order,
  835. }
  836. //查询 该患者是否已出库
  837. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  838. if errcode == gorm.ErrRecordNotFound {
  839. service.CreateOutStock(&outStock)
  840. } else if errcode == nil {
  841. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  842. fmt.Println("err", err)
  843. }
  844. }
  845. }
  846. } else {
  847. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  848. for _, item := range advices {
  849. if item.ExecutionState == 1 && item.Way == 2 {
  850. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  851. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  852. timeStr := time.Now().Format("2006-01-02")
  853. timeArr := strings.Split(timeStr, "-")
  854. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  855. total = total + 1
  856. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  857. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  858. number = number + total
  859. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  860. //插入自备药出库单
  861. outStock := models.XtSelfOutStock{
  862. DrugName: item.AdviceName,
  863. DrugNameId: item.DrugNameId,
  864. DrugSpec: item.AdviceDesc,
  865. OutstoreNumber: count,
  866. AdminUserId: adminUserInfo.AdminUser.Id,
  867. StorckTime: item.AdviceDate,
  868. UserOrgId: adminUserInfo.Org.Id,
  869. CreatedTime: time.Now().Unix(),
  870. Status: 1,
  871. PatientId: item.PatientId,
  872. ExitMode: 2,
  873. MedicId: item.DrugId,
  874. StockOutNumber: warehousing_out_order,
  875. }
  876. //查询 该患者是否已出库
  877. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  878. if errcode == gorm.ErrRecordNotFound {
  879. service.CreateOutStock(&outStock)
  880. } else if errcode == nil {
  881. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  882. fmt.Println("err", err)
  883. }
  884. }
  885. }
  886. c.ServeSuccessJSON(map[string]interface{}{
  887. "msg": "1",
  888. "advice": advice,
  889. "ids": ids,
  890. })
  891. return
  892. }
  893. }
  894. c.ServeSuccessJSON(map[string]interface{}{
  895. "msg": "1",
  896. "advice": advice,
  897. "ids": ids,
  898. })
  899. return
  900. } else if origin == 2 {
  901. adminInfo := c.GetMobileAdminUserInfo()
  902. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  903. var ids []string
  904. advice_ids := c.GetString("advice_id")
  905. ids = strings.Split(advice_ids, ",")
  906. if len(execution_time) <= 0 {
  907. utils.ErrorLog("execution_time")
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. return
  910. }
  911. timeLayout2 := "2006-01-02 15:04:05"
  912. loc, _ := time.LoadLocation("Local")
  913. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  914. if errs != nil {
  915. utils.ErrorLog(errs.Error())
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  917. return
  918. }
  919. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  920. var err error
  921. for _, item := range advices {
  922. if item.ExecutionState == 1 {
  923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  924. return
  925. }
  926. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  928. return
  929. }
  930. if item.StartTime > theTime.Unix() {
  931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  932. return
  933. }
  934. item.ExecutionState = 1
  935. item.ExecutionStaff = adminInfo.AdminUser.Id
  936. item.ExecutionTime = theTime.Unix()
  937. err = service.SaveHisDoctorAdvice(item)
  938. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  939. redis := service.RedisClient()
  940. //清空key 值
  941. redis.Set(key, "", time.Second)
  942. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  943. redis.Set(keyTwo, "", time.Second)
  944. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  945. redis.Set(keyThree, "", time.Second)
  946. recordDate := theTime.Format("2006-01-02")
  947. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  948. redis.Set(keyFour, "", time.Second)
  949. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  950. redis.Set(keyFive, "", time.Second)
  951. defer redis.Close()
  952. }
  953. if err == nil {
  954. //药品管理信息
  955. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  956. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  957. if drugStockConfig.IsOpen == 1 {
  958. for _, item := range advices {
  959. //查询改药品信息
  960. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  961. //查询这个患者这个患者这个药已经出库的所有数量
  962. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  963. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  964. var total_count int64
  965. var drug_count int64
  966. for _, it := range advicelist {
  967. if it.PrescribingNumberUnit == medical.MaxUnit {
  968. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  969. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  970. total_count += prenumber * medical.MinNumber
  971. }
  972. if it.PrescribingNumberUnit == medical.MinUnit {
  973. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  974. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  975. total_count += prenumber
  976. }
  977. }
  978. for _, its := range drugoutlist {
  979. if its.CountUnit == medical.MaxUnit {
  980. drug_count += its.Count * medical.MinNumber
  981. }
  982. if its.CountUnit == medical.MinUnit {
  983. drug_count += its.Count
  984. }
  985. }
  986. if total_count == drug_count {
  987. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "msg": "1",
  990. "advice": advice,
  991. "ids": ids,
  992. })
  993. return
  994. }
  995. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  996. var total int64
  997. var prescribing_number_total int64
  998. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  999. if config.IsOpen != 1 {
  1000. //查询该药品是否有库存
  1001. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1002. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1003. //判断单位是否相等
  1004. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1005. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1006. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1007. //转化为最小单位
  1008. total = list.Count*medical.MinNumber + list.StockMinNumber
  1009. prescribing_number_total = count * medical.MinNumber
  1010. }
  1011. //fmt.Println("医嘱开的数量", total)
  1012. if medical.MinUnit == advice.PrescribingNumberUnit {
  1013. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1014. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1015. total = list.Count*medical.MinNumber + list.StockMinNumber
  1016. prescribing_number_total = count
  1017. }
  1018. if medical.IsUse == 1 {
  1019. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1020. c.ServeSuccessJSON(map[string]interface{}{
  1021. "msg": "1",
  1022. "advice": advice,
  1023. "ids": ids,
  1024. })
  1025. return
  1026. }
  1027. }
  1028. if medical.IsUse != 1 {
  1029. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1030. c.ServeSuccessJSON(map[string]interface{}{
  1031. "msg": "3",
  1032. "advice": advice,
  1033. "ids": ids,
  1034. })
  1035. return
  1036. }
  1037. if prescribing_number_total > total {
  1038. c.ServeSuccessJSON(map[string]interface{}{
  1039. "msg": "2",
  1040. "advice": advice,
  1041. "ids": ids,
  1042. })
  1043. return
  1044. }
  1045. }
  1046. if prescribing_number_total <= total {
  1047. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1048. //判断药品是否零用
  1049. if medical.IsUse == 2 {
  1050. if config.IsOpen != 1 {
  1051. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1052. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1053. }
  1054. if pharmacyConfig.IsOpen != 1 {
  1055. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1056. }
  1057. //更新字典里面的库存
  1058. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1059. var sum_count int64
  1060. for _, its := range stockInfo {
  1061. if its.MaxUnit == medical.MaxUnit {
  1062. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1063. }
  1064. sum_count += its.StockMaxNumber + its.StockMinNumber
  1065. }
  1066. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1067. //剩余库存
  1068. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1069. }
  1070. }
  1071. }
  1072. }
  1073. //
  1074. //if config.IsOpen == 1 && item.UserOrgId == 10088 {
  1075. //
  1076. // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1077. // //更新字典里面的库存
  1078. // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1079. // var sum_count int64
  1080. // for _, its := range stockInfo {
  1081. // if its.MaxUnit == medical.MaxUnit {
  1082. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1083. // }
  1084. // sum_count += its.StockMaxNumber + its.StockMinNumber
  1085. // }
  1086. // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1087. // //剩余库存
  1088. // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1089. //}
  1090. }
  1091. }
  1092. for _, item := range advices {
  1093. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1094. c.ServeSuccessJSON(map[string]interface{}{
  1095. "msg": "1",
  1096. "advice": advice,
  1097. "ids": ids,
  1098. })
  1099. }
  1100. } else {
  1101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1102. }
  1103. }
  1104. }
  1105. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1106. execution_time := c.GetString("execution_time")
  1107. fmt.Println("execution_time", execution_time)
  1108. groupno, _ := c.GetInt64("groupno", -1)
  1109. //patient_id, _ := c.GetInt64("patient_id")
  1110. advice_date, _ := c.GetInt64("advice_date")
  1111. var ids []string
  1112. if groupno == 0 {
  1113. advice_ids := c.GetString("advice_id")
  1114. ids = strings.Split(advice_ids, ",")
  1115. }
  1116. if groupno < 0 {
  1117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1118. return
  1119. }
  1120. if len(execution_time) <= 0 {
  1121. utils.ErrorLog("execution_time")
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1123. return
  1124. }
  1125. timeLayout2 := "2006-01-02 15:04:05"
  1126. loc, _ := time.LoadLocation("Local")
  1127. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1128. if errs != nil {
  1129. utils.ErrorLog(errs.Error())
  1130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1131. return
  1132. }
  1133. adminUserInfo := c.GetMobileAdminUserInfo()
  1134. var advice models.DoctorAdvice
  1135. if groupno > 0 {
  1136. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1137. for _, item := range advices {
  1138. if item.ExecutionState == 1 {
  1139. advice = item
  1140. }
  1141. }
  1142. } else {
  1143. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1144. for _, item := range advices {
  1145. if item.ExecutionState == 1 {
  1146. advice = item
  1147. }
  1148. }
  1149. }
  1150. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1151. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1152. // if getPermissionErr != nil {
  1153. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1154. // return
  1155. // } else if headNursePermission == nil {
  1156. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1157. // return
  1158. // }
  1159. //}
  1160. if advice.StartTime > theTime.Unix() {
  1161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1162. return
  1163. }
  1164. advices := models.DoctorAdvice{
  1165. ExecutionTime: theTime.Unix(),
  1166. UpdatedTime: time.Now().Unix(),
  1167. }
  1168. var err error
  1169. if groupno > 0 {
  1170. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1171. redis := service.RedisClient()
  1172. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1173. redis.Set(key, "", time.Second)
  1174. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1175. redis.Set(keyOne, "", time.Second)
  1176. defer redis.Close()
  1177. } else {
  1178. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1179. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1180. redis := service.RedisClient()
  1181. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1182. redis.Set(key, "", time.Second)
  1183. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1184. redis.Set(keyOne, "", time.Second)
  1185. defer redis.Close()
  1186. }
  1187. //判断是否开启his
  1188. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1189. //如果开启去修改执行时间
  1190. if config.IsOpen == 1 {
  1191. advicesinfo := models.HisDoctorAdviceInfo{
  1192. ExecutionTime: theTime.Unix(),
  1193. UpdatedTime: time.Now().Unix(),
  1194. }
  1195. var advicehis models.HisDoctorAdviceInfo
  1196. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1197. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1198. for _, item := range his_advices {
  1199. if item.ExecutionState == 1 {
  1200. advicehis = item
  1201. }
  1202. }
  1203. redis := service.RedisClient()
  1204. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1205. redis.Set(keyThree, "", time.Second)
  1206. recordDate := theTime.Format("2006-01-02")
  1207. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1208. redis.Set(keyFour, "", time.Second)
  1209. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1210. redis.Set(keyFive, "", time.Second)
  1211. defer redis.Close()
  1212. project := models.HisPrescriptionProject{
  1213. ExecutionTime: theTime.Unix(),
  1214. Mtime: time.Now().Unix(),
  1215. }
  1216. service.ModifyHisPrescriptionProject(&project, ids)
  1217. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1218. redis.Set(keyEnd, "", time.Second)
  1219. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1220. redis.Set(keyFours, "", time.Second)
  1221. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1222. redis.Set(keyFives, "", time.Second)
  1223. defer redis.Close()
  1224. }
  1225. if err != nil {
  1226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1227. return
  1228. }
  1229. advice.ExecutionTime = theTime.Unix()
  1230. c.ServeSuccessJSON(map[string]interface{}{
  1231. "msg": "ok",
  1232. "advice": advice,
  1233. "ids": ids,
  1234. })
  1235. return
  1236. }
  1237. func (c *PatientApiController) CheckDoctorAdvice() {
  1238. origin, _ := c.GetInt64("origin", 0)
  1239. if origin != 2 {
  1240. groupno, _ := c.GetInt64("groupno", -1)
  1241. var ids []string
  1242. if groupno == 0 {
  1243. advice_ids := c.GetString("advice_id")
  1244. if advice_ids == "" {
  1245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1246. return
  1247. } else {
  1248. ids = strings.Split(advice_ids, ",")
  1249. if len(ids) <= 0 {
  1250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1251. return
  1252. }
  1253. }
  1254. }
  1255. if groupno < 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1257. return
  1258. }
  1259. adminUserInfo := c.GetMobileAdminUserInfo()
  1260. var advice models.DoctorAdvice
  1261. if groupno > 0 {
  1262. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1263. for _, item := range advices {
  1264. if item.CheckState == 0 {
  1265. advice = item
  1266. }
  1267. }
  1268. if advice.CheckState == 1 {
  1269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1270. return
  1271. }
  1272. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1274. return
  1275. }
  1276. } else {
  1277. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1278. for _, item := range advices {
  1279. if item.CheckState == 0 {
  1280. advice = item
  1281. }
  1282. }
  1283. if advice.CheckState == 1 {
  1284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1285. return
  1286. }
  1287. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1289. return
  1290. }
  1291. }
  1292. checker := adminUserInfo.AdminUser.Id
  1293. theTime := time.Now()
  1294. advices := models.DoctorAdvice{
  1295. CheckTime: theTime.Unix(),
  1296. Checker: checker,
  1297. UpdatedTime: time.Now().Unix(),
  1298. }
  1299. var err error
  1300. if groupno > 0 {
  1301. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1302. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1303. redis := service.RedisClient()
  1304. //清空key 值
  1305. redis.Set(key, "", time.Second)
  1306. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1307. redis.Set(keyTwo, "", time.Second)
  1308. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1309. redis.Set(keyThree, "", time.Second)
  1310. recordDate := theTime.Format("2006-01-02")
  1311. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1312. redis.Set(keyFour, "", time.Second)
  1313. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1314. redis.Set(keyFive, "", time.Second)
  1315. defer redis.Close()
  1316. } else {
  1317. if len(ids[0]) <= 0 {
  1318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1319. return
  1320. } else {
  1321. //t := time.Now().Format("2006-01-02")/**/
  1322. //timeLayout2 := "2006-01-02"
  1323. //loc, _ := time.LoadLocation("Local")
  1324. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1325. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1326. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1327. redis := service.RedisClient()
  1328. //清空key 值
  1329. redis.Set(key, "", time.Second)
  1330. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1331. redis.Set(keyTwo, "", time.Second)
  1332. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1333. redis.Set(keyThree, "", time.Second)
  1334. recordDate := theTime.Format("2006-01-02")
  1335. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1336. redis.Set(keyFour, "", time.Second)
  1337. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1338. redis.Set(keyFive, "", time.Second)
  1339. defer redis.Close()
  1340. }
  1341. }
  1342. if err != nil {
  1343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1344. return
  1345. }
  1346. advice.Checker = checker
  1347. advice.CheckTime = theTime.Unix()
  1348. advice.CheckState = 1
  1349. c.ServeSuccessJSON(map[string]interface{}{
  1350. "msg": "ok",
  1351. "advice": advice,
  1352. })
  1353. } else if origin == 2 {
  1354. adminInfo := c.GetMobileAdminUserInfo()
  1355. var ids []string
  1356. advice_ids := c.GetString("advice_id")
  1357. ids = strings.Split(advice_ids, ",")
  1358. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1359. var err error
  1360. for _, item := range advices {
  1361. if item.CheckState == 1 {
  1362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1363. return
  1364. }
  1365. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1367. return
  1368. }
  1369. item.Checker = adminInfo.AdminUser.Id
  1370. item.CheckTime = time.Now().Unix()
  1371. item.CheckState = 1
  1372. err = service.SaveHisDoctorAdvice(item)
  1373. redis := service.RedisClient()
  1374. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1375. //清空key 值
  1376. redis.Set(key, "", time.Second)
  1377. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1378. redis.Set(keyTwo, "", time.Second)
  1379. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1380. redis.Set(keyThree, "", time.Second)
  1381. theTime := time.Now()
  1382. recordDate := theTime.Format("2006-01-02")
  1383. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1384. redis.Set(keyFour, "", time.Second)
  1385. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1386. redis.Set(keyFive, "", time.Second)
  1387. defer redis.Close()
  1388. }
  1389. if err == nil {
  1390. c.ServeSuccessJSON(map[string]interface{}{
  1391. "msg": "ok",
  1392. "advice": advices,
  1393. })
  1394. } else {
  1395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1396. return
  1397. }
  1398. }
  1399. return
  1400. }
  1401. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1402. id, _ := c.GetInt64("patient", 0)
  1403. assessmentDate := c.GetString("assessment_date", "")
  1404. if id <= 0 || len(assessmentDate) != 10 {
  1405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1406. return
  1407. }
  1408. timeLayout := "2006-01-02"
  1409. loc, _ := time.LoadLocation("Local")
  1410. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1411. if err != nil {
  1412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1413. return
  1414. }
  1415. theAssessmentDateTime := theTime.Unix()
  1416. adminUserInfo := c.GetMobileAdminUserInfo()
  1417. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1418. if patient.ID == 0 {
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1420. return
  1421. }
  1422. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1423. if getPEErr != nil {
  1424. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1426. return
  1427. }
  1428. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1429. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1430. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1431. var evaluation models.PredialysisEvaluation
  1432. if theEvaluation != nil {
  1433. evaluation = *theEvaluation
  1434. }
  1435. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1436. if code > 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(code)
  1438. return
  1439. }
  1440. if theEvaluation == nil {
  1441. evaluation.CreatedTime = time.Now().Unix()
  1442. evaluation.Status = 1
  1443. evaluation.AssessmentDate = theAssessmentDateTime
  1444. evaluation.PatientId = id
  1445. evaluation.UserOrgId = adminUserInfo.Org.Id
  1446. if appRole.UserType == 2 || appRole.UserType == 1 {
  1447. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1448. evaluation.AssessmentTime = time.Now().Unix()
  1449. } else {
  1450. evaluation.Creater = adminUserInfo.AdminUser.Id
  1451. }
  1452. } else {
  1453. evaluation.UpdatedTime = time.Now().Unix()
  1454. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1455. if appRole.UserType == 2 || appRole.UserType == 1 {
  1456. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1457. evaluation.AssessmentTime = time.Now().Unix()
  1458. } else {
  1459. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1460. if evaluation.Creater == 0 {
  1461. evaluation.Creater = adminUserInfo.AdminUser.Id
  1462. }
  1463. }
  1464. }
  1465. //新增逻辑
  1466. var dewater_amount float64
  1467. dewater_amount = 0
  1468. if evaluation.DryWeight > 0 {
  1469. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1470. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 3877 {
  1471. dewater_amount = dewater_amount * 1000
  1472. }
  1473. if dewater_amount <= 0 {
  1474. dewater_amount = 0
  1475. }
  1476. } else {
  1477. dewater_amount = 0
  1478. }
  1479. // 计算透析处方的相关超滤量
  1480. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1481. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  1482. var lastDialysisPrescribe *models.DialysisPrescription
  1483. var dialysisSolution *models.DialysisSolution
  1484. var dialysisPrescribe *models.DialysisPrescription
  1485. var system_dialysisPrescribe *models.SystemPrescription
  1486. var mode_id int64
  1487. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1488. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1489. if schedual != nil {
  1490. // 获取透析模版
  1491. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1492. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1493. mode_id = schedual.ModeId
  1494. } else {
  1495. // 获取透析模版
  1496. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1497. if dialysisPrescribe == nil && dialysisSolution != nil {
  1498. mode_id = dialysisSolution.ModeId
  1499. }
  1500. if dialysisPrescribe == nil && dialysisSolution == nil {
  1501. mode_id = 0
  1502. }
  1503. }
  1504. // 插入透析处方
  1505. if dialysisPrescribe == nil && dialysisSolution != nil {
  1506. var newprescribe models.DialysisPrescription
  1507. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1508. newprescribe.PatientId = dialysisSolution.PatientId
  1509. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1510. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1511. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1512. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1513. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1514. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1515. newprescribe.ModeId = dialysisSolution.ModeId
  1516. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1517. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1518. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1519. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1520. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1521. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1522. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1523. newprescribe.Glucose = dialysisSolution.Glucose
  1524. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1525. newprescribe.Kalium = dialysisSolution.Kalium
  1526. newprescribe.Sodium = dialysisSolution.Sodium
  1527. newprescribe.Calcium = dialysisSolution.Calcium
  1528. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1529. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1530. newprescribe.Conductivity = dialysisSolution.Conductivity
  1531. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1532. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1533. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1534. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1535. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1536. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1537. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1538. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1539. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1540. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1541. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1542. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1543. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1544. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1545. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1546. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1547. newprescribe.CreatedTime = time.Now().Unix()
  1548. newprescribe.UpdatedTime = time.Now().Unix()
  1549. newprescribe.RecordDate = theAssessmentDateTime
  1550. newprescribe.DewaterAmount = dewater_amount
  1551. newprescribe.TargetUltrafiltration = dewater_amount
  1552. newprescribe.Status = 1
  1553. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1554. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1555. newprescribe.Remark = lastDialysisPrescription.Remark
  1556. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1557. newprescribe.ID = dialysisPrescription.ID
  1558. if dialysisPrescription.ID == 0 {
  1559. if adminUserInfo.Org.Id == 10340 {
  1560. newprescribe.Sodium = 138
  1561. newprescribe.Bicarbonate = 31.1
  1562. newprescribe.DialysateFlow = 500
  1563. }
  1564. err := service.AddSigleRecord(&newprescribe)
  1565. //获取key,清空redis
  1566. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1567. redis := service.RedisClient()
  1568. //清空key 值
  1569. redis.Set(key, "", time.Second)
  1570. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1571. //清空key 值
  1572. redis.Set(keyOne, "", time.Second)
  1573. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1574. //清空key 值
  1575. redis.Set(keyTwo, "", time.Second)
  1576. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1577. redis.Set(keySix, "", time.Second)
  1578. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1579. redis.Set(keySeven, "", time.Second)
  1580. if err != nil {
  1581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1582. }
  1583. } else {
  1584. if adminUserInfo.Org.Id == 10340 {
  1585. newprescribe.Sodium = 138
  1586. newprescribe.Bicarbonate = 31.1
  1587. newprescribe.DialysateFlow = 500
  1588. }
  1589. err := service.UpDateDialysisPrescription(&newprescribe)
  1590. //获取key,清空redis
  1591. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1592. redis := service.RedisClient()
  1593. //清空key 值
  1594. redis.Set(key, "", time.Second)
  1595. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1596. //清空key 值
  1597. redis.Set(keyOne, "", time.Second)
  1598. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1599. //清空key 值
  1600. redis.Set(keyTwo, "", time.Second)
  1601. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1602. redis.Set(keySix, "", time.Second)
  1603. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1604. redis.Set(keySeven, "", time.Second)
  1605. if err != nil {
  1606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1607. }
  1608. }
  1609. }
  1610. if dialysisPrescribe == nil && dialysisSolution == nil {
  1611. if lastDialysisPrescribe != nil {
  1612. var newprescribe models.DialysisPrescription
  1613. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1614. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1615. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1616. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1617. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1618. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1619. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1620. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1621. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1622. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1623. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1624. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1625. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1626. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1627. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1628. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1629. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1630. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1631. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1632. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1633. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1634. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1635. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1636. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1637. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1638. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1639. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1640. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1641. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1642. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1643. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1644. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1645. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1646. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1647. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1648. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1649. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1650. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1651. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1652. newprescribe.CreatedTime = time.Now().Unix()
  1653. newprescribe.UpdatedTime = time.Now().Unix()
  1654. newprescribe.RecordDate = theAssessmentDateTime
  1655. newprescribe.DewaterAmount = dewater_amount
  1656. newprescribe.TargetUltrafiltration = dewater_amount
  1657. newprescribe.Status = 1
  1658. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  1659. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  1660. newprescribe.Remark = lastDialysisPrescription.Remark
  1661. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1662. newprescribe.ID = dialysisPrescription.ID
  1663. if dialysisPrescription.ID == 0 {
  1664. if adminUserInfo.Org.Id == 10340 {
  1665. newprescribe.Sodium = 138
  1666. newprescribe.Bicarbonate = 31.1
  1667. newprescribe.DialysateFlow = 500
  1668. }
  1669. err := service.AddSigleRecord(&newprescribe)
  1670. //获取key,清空redis
  1671. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1672. redis := service.RedisClient()
  1673. //清空key 值
  1674. redis.Set(key, "", time.Second)
  1675. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1676. //清空key 值
  1677. redis.Set(keyOne, "", time.Second)
  1678. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1679. //清空key 值
  1680. redis.Set(keyTwo, "", time.Second)
  1681. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1682. redis.Set(keySix, "", time.Second)
  1683. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1684. redis.Set(keySeven, "", time.Second)
  1685. if err != nil {
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1687. }
  1688. } else {
  1689. err := service.UpDateDialysisPrescription(&newprescribe)
  1690. //获取key,清空redis
  1691. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1692. redis := service.RedisClient()
  1693. //清空key 值
  1694. redis.Set(key, "", time.Second)
  1695. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1696. //清空key 值
  1697. redis.Set(keyOne, "", time.Second)
  1698. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1699. //清空key 值
  1700. redis.Set(keyTwo, "", time.Second)
  1701. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1702. redis.Set(keySix, "", time.Second)
  1703. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1704. redis.Set(keySeven, "", time.Second)
  1705. if err != nil {
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1707. }
  1708. }
  1709. if err != nil {
  1710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1711. }
  1712. } else if system_dialysisPrescribe != nil {
  1713. var newprescribe models.DialysisPrescription
  1714. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  1715. newprescribe.PatientId = id
  1716. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  1717. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  1718. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  1719. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  1720. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  1721. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  1722. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  1723. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  1724. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  1725. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  1726. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  1727. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  1728. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  1729. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  1730. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  1731. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  1732. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  1733. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  1734. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  1735. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  1736. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  1737. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  1738. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  1739. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  1740. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  1741. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  1742. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  1743. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  1744. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  1745. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  1746. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  1747. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  1748. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  1749. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  1750. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  1751. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  1752. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  1753. newprescribe.CreatedTime = time.Now().Unix()
  1754. newprescribe.UpdatedTime = time.Now().Unix()
  1755. newprescribe.RecordDate = theAssessmentDateTime
  1756. newprescribe.DewaterAmount = dewater_amount
  1757. newprescribe.TargetUltrafiltration = dewater_amount
  1758. newprescribe.Status = 1
  1759. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  1760. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  1761. newprescribe.Remark = lastDialysisPrescription.Remark
  1762. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1763. newprescribe.ID = dialysisPrescription.ID
  1764. if dialysisPrescription.ID == 0 {
  1765. if adminUserInfo.Org.Id == 10340 {
  1766. newprescribe.Sodium = 138
  1767. newprescribe.Bicarbonate = 31.1
  1768. newprescribe.DialysateFlow = 500
  1769. }
  1770. err := service.AddSigleRecord(&newprescribe)
  1771. //获取key,清空redis
  1772. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1773. redis := service.RedisClient()
  1774. //清空key 值
  1775. redis.Set(key, "", time.Second)
  1776. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1777. //清空key 值
  1778. redis.Set(keyOne, "", time.Second)
  1779. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1780. //清空key 值
  1781. redis.Set(keyTwo, "", time.Second)
  1782. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1783. redis.Set(keySix, "", time.Second)
  1784. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1785. redis.Set(keySeven, "", time.Second)
  1786. if err != nil {
  1787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1788. }
  1789. } else {
  1790. if adminUserInfo.Org.Id == 10340 {
  1791. newprescribe.Sodium = 138
  1792. newprescribe.Bicarbonate = 31.1
  1793. newprescribe.DialysateFlow = 500
  1794. }
  1795. err := service.UpDateDialysisPrescription(&newprescribe)
  1796. //获取key,清空redis
  1797. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1798. redis := service.RedisClient()
  1799. //清空key 值
  1800. redis.Set(key, "", time.Second)
  1801. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1802. //清空key 值
  1803. redis.Set(keyOne, "", time.Second)
  1804. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1805. //清空key 值
  1806. redis.Set(keyTwo, "", time.Second)
  1807. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1808. redis.Set(keySix, "", time.Second)
  1809. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1810. redis.Set(keySeven, "", time.Second)
  1811. if err != nil {
  1812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1813. }
  1814. }
  1815. if err != nil {
  1816. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1817. }
  1818. } else {
  1819. var newprescribe models.DialysisPrescription
  1820. newprescribe.UserOrgId = adminUserInfo.Org.Id
  1821. newprescribe.PatientId = id
  1822. newprescribe.ModeId = mode_id
  1823. newprescribe.CreatedTime = time.Now().Unix()
  1824. newprescribe.UpdatedTime = time.Now().Unix()
  1825. newprescribe.RecordDate = theAssessmentDateTime
  1826. newprescribe.DewaterAmount = dewater_amount
  1827. newprescribe.TargetUltrafiltration = dewater_amount
  1828. newprescribe.Status = 1
  1829. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1830. newprescribe.ID = dialysisPrescription.ID
  1831. if dialysisPrescription.ID == 0 {
  1832. if adminUserInfo.Org.Id == 10340 {
  1833. newprescribe.Sodium = 138
  1834. newprescribe.Bicarbonate = 31.1
  1835. newprescribe.DialysateFlow = 500
  1836. }
  1837. err := service.AddSigleRecord(&newprescribe)
  1838. //获取key,清空redis
  1839. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1840. redis := service.RedisClient()
  1841. //清空key 值
  1842. redis.Set(key, "", time.Second)
  1843. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1844. //清空key 值
  1845. redis.Set(keyOne, "", time.Second)
  1846. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1847. //清空key 值
  1848. redis.Set(keyTwo, "", time.Second)
  1849. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1850. redis.Set(keySix, "", time.Second)
  1851. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1852. redis.Set(keySeven, "", time.Second)
  1853. if err != nil {
  1854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1855. }
  1856. } else {
  1857. if adminUserInfo.Org.Id == 10340 {
  1858. newprescribe.Sodium = 138
  1859. newprescribe.Bicarbonate = 31.1
  1860. newprescribe.DialysateFlow = 500
  1861. }
  1862. err := service.UpDateDialysisPrescription(&newprescribe)
  1863. //获取key,清空redis
  1864. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1865. redis := service.RedisClient()
  1866. //清空key 值
  1867. redis.Set(key, "", time.Second)
  1868. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1869. //清空key 值
  1870. redis.Set(keyOne, "", time.Second)
  1871. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1872. //清空key 值
  1873. redis.Set(keyTwo, "", time.Second)
  1874. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1875. redis.Set(keySix, "", time.Second)
  1876. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1877. redis.Set(keySeven, "", time.Second)
  1878. if err != nil {
  1879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1880. }
  1881. }
  1882. if err != nil {
  1883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1884. }
  1885. }
  1886. }
  1887. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  1888. // if dialysisPrescribe != nil {
  1889. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  1890. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  1891. // dialysisPrescribe.DewaterAmount = dewater_amount
  1892. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  1893. // dialysisPrescribe.Status = 1
  1894. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  1895. // if updateErr != nil {
  1896. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1897. // }
  1898. // }
  1899. err = service.UpadatePredialysisEvaluation(&evaluation)
  1900. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  1901. redis := service.RedisClient()
  1902. defer redis.Close()
  1903. //清空key 值
  1904. redis.Set(key, "", time.Second)
  1905. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  1906. redis.Set(keyOne, "", time.Second)
  1907. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1908. redis.Set(keyTwo, "", time.Second)
  1909. if err != nil {
  1910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1911. return
  1912. }
  1913. c.ServeSuccessJSON(map[string]interface{}{
  1914. "msg": "ok",
  1915. "evaluation": evaluation,
  1916. })
  1917. return
  1918. }
  1919. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1920. dataBody := make(map[string]interface{}, 0)
  1921. err := json.Unmarshal(data, &dataBody)
  1922. utils.InfoLog(string(data))
  1923. if err != nil {
  1924. utils.ErrorLog(err.Error())
  1925. code = enums.ErrorCodeParamWrong
  1926. return
  1927. }
  1928. // if method == "create" {
  1929. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1930. utils.ErrorLog("mode")
  1931. code = enums.ErrorCodeParamWrong
  1932. return
  1933. }
  1934. mode := int64(dataBody["mode"].(float64))
  1935. if mode <= 0 {
  1936. utils.ErrorLog("mode <= 0")
  1937. code = enums.ErrorCodeParamWrong
  1938. return
  1939. }
  1940. solution.ModeId = mode
  1941. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1942. utils.ErrorLog("mode_name")
  1943. code = enums.ErrorCodeParamWrong
  1944. return
  1945. }
  1946. modeName, _ := dataBody["mode_name"].(string)
  1947. if len(modeName) == 0 {
  1948. utils.ErrorLog("len(mode_name) == 0")
  1949. code = enums.ErrorCodeParamWrong
  1950. return
  1951. }
  1952. solution.ModeName = modeName
  1953. solution.Name = modeName
  1954. // }
  1955. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1956. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1957. solution.DialysisDuration = dialysisDuration
  1958. }
  1959. if dataBody["dialysis_duration"] != nil {
  1960. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1961. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1962. solution.DialysisDuration = dialysisDuration
  1963. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1964. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1965. solution.DialysisDuration = dialysisDuration
  1966. }
  1967. }
  1968. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1969. dialyzer := int64(dataBody["dialyzer"].(float64))
  1970. solution.Dialyzer = dialyzer
  1971. }
  1972. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1973. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1974. solution.PerfusionApparatus = perfusionApparatus
  1975. }
  1976. if dataBody["blood_flow_volume"] != nil {
  1977. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1978. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1979. solution.BloodFlowVolume = bloodFlowVolume
  1980. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1981. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1982. solution.BloodFlowVolume = bloodFlowVolume
  1983. }
  1984. }
  1985. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1986. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1987. solution.HemodialysisMachine = hemodialysisMachine
  1988. }
  1989. if dataBody["dewater"] != nil {
  1990. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1991. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1992. solution.Dewater = dewater
  1993. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1994. dewater := dataBody["dewater"].(float64)
  1995. solution.Dewater = dewater
  1996. }
  1997. }
  1998. if dataBody["replacement_total"] != nil {
  1999. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2000. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2001. solution.ReplacementTotal = replacementTotal
  2002. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  2003. replacementTotal := dataBody["replacement_total"].(float64)
  2004. solution.ReplacementTotal = replacementTotal
  2005. }
  2006. }
  2007. if dataBody["displace_liqui"] != nil {
  2008. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2009. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2010. solution.DisplaceLiqui = displaceLiqui
  2011. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  2012. displaceLiqui := dataBody["displace_liqui"].(float64)
  2013. solution.DisplaceLiqui = displaceLiqui
  2014. }
  2015. }
  2016. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2017. replacementWay := int64(dataBody["replacement_way"].(float64))
  2018. solution.ReplacementWay = replacementWay
  2019. }
  2020. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2021. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2022. solution.Anticoagulant = anticoagulant
  2023. }
  2024. if dataBody["anticoagulant_shouji"] != nil {
  2025. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2026. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2027. solution.AnticoagulantShouji = anticoagulantShouji
  2028. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  2029. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  2030. solution.AnticoagulantShouji = anticoagulantShouji
  2031. }
  2032. }
  2033. if dataBody["anticoagulant_weichi"] != nil {
  2034. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2035. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2036. solution.AnticoagulantWeichi = anticoagulantWeichi
  2037. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  2038. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  2039. solution.AnticoagulantWeichi = anticoagulantWeichi
  2040. }
  2041. }
  2042. if dataBody["anticoagulant_zongliang"] != nil {
  2043. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2044. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2045. solution.AnticoagulantZongliang = anticoagulantZongliang
  2046. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  2047. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  2048. solution.AnticoagulantZongliang = anticoagulantZongliang
  2049. }
  2050. }
  2051. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2052. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2053. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2054. }
  2055. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2056. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2057. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2058. }
  2059. if dataBody["kalium"] != nil {
  2060. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2061. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2062. solution.Kalium = kalium
  2063. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  2064. kalium := dataBody["kalium"].(float64)
  2065. solution.Kalium = kalium
  2066. }
  2067. }
  2068. if dataBody["sodium"] != nil {
  2069. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2070. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2071. solution.Sodium = sodium
  2072. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  2073. sodium := dataBody["sodium"].(float64)
  2074. solution.Sodium = sodium
  2075. }
  2076. }
  2077. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2078. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2079. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2080. solution.Calcium = calcium
  2081. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  2082. calcium := dataBody["calcium"].(float64)
  2083. solution.Calcium = calcium
  2084. }
  2085. }
  2086. if dataBody["bicarbonate"] != nil {
  2087. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2088. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2089. solution.Bicarbonate = bicarbonate
  2090. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  2091. bicarbonate := dataBody["bicarbonate"].(float64)
  2092. solution.Bicarbonate = bicarbonate
  2093. }
  2094. }
  2095. if dataBody["glucose"] != nil {
  2096. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2097. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2098. solution.Glucose = glucose
  2099. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  2100. glucose := dataBody["glucose"].(float64)
  2101. solution.Glucose = glucose
  2102. }
  2103. }
  2104. // if dataBody["dry_weight"] != nil {
  2105. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2106. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2107. // solution.DryWeight = dryWeight
  2108. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  2109. // dryWeight := dataBody["dry_weight"].(float64)
  2110. // solution.DryWeight = dryWeight
  2111. // }
  2112. // }
  2113. if dataBody["dialysate_flow"] != nil {
  2114. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2115. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2116. solution.DialysateFlow = dialysateFlow
  2117. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  2118. dialysateFlow := dataBody["dialysate_flow"].(float64)
  2119. solution.DialysateFlow = dialysateFlow
  2120. }
  2121. }
  2122. if dataBody["dialysate_temperature"] != nil {
  2123. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2124. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2125. solution.DialysateTemperature = dialysateTemperature
  2126. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  2127. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  2128. solution.DialysateTemperature = dialysateTemperature
  2129. }
  2130. }
  2131. if dataBody["conductivity"] != nil {
  2132. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2133. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2134. solution.Conductivity = conductivity
  2135. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  2136. conductivity := dataBody["conductivity"].(float64)
  2137. solution.Conductivity = conductivity
  2138. }
  2139. }
  2140. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2141. remark := dataBody["remark"].(string)
  2142. solution.Remark = remark
  2143. }
  2144. if dataBody["dialysis_duration_hour"] != nil {
  2145. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2146. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  2147. solution.DialysisDurationHour = dialysisDurationHour
  2148. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  2149. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  2150. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2151. }
  2152. }
  2153. if dataBody["dialysis_duration_minute"] != nil {
  2154. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2155. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  2156. solution.DialysisDurationMinute = dialysisDurationMinute
  2157. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  2158. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  2159. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2160. }
  2161. }
  2162. if dataBody["target_ultrafiltration"] != nil {
  2163. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2164. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2165. solution.TargetUltrafiltration = targetUltrafiltration
  2166. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  2167. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  2168. solution.TargetUltrafiltration = targetUltrafiltration
  2169. }
  2170. }
  2171. if dataBody["dialysate_formulation"] != nil {
  2172. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  2173. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  2174. solution.DialysateFormulation = dialysateFormulation
  2175. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2176. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  2177. solution.DialysateFormulation = int64(dialysateFormulation)
  2178. }
  2179. }
  2180. return
  2181. }
  2182. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  2183. dataBody := make(map[string]interface{}, 0)
  2184. err := json.Unmarshal(data, &dataBody)
  2185. utils.InfoLog(string(data))
  2186. if err != nil {
  2187. utils.ErrorLog(err.Error())
  2188. code = enums.ErrorCodeParamWrong
  2189. return
  2190. }
  2191. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  2192. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  2193. evaluation.WeightBefore = weightVefore
  2194. }
  2195. // fmt.Println(dataBody["dry_weight"])
  2196. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  2197. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2198. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2199. fmt.Println(additionalWeight)
  2200. evaluation.DryWeight = additionalWeight
  2201. }
  2202. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  2203. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  2204. fmt.Println(additionalWeight)
  2205. evaluation.AdditionalWeight = additionalWeight
  2206. }
  2207. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  2208. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  2209. evaluation.Temperature = Temperature
  2210. }
  2211. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  2212. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  2213. evaluation.SystolicBloodPressure = systolicBloodPressure
  2214. }
  2215. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2216. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2217. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2218. }
  2219. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2220. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2221. evaluation.PulseFrequency = pulseFrequency
  2222. }
  2223. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2224. breathingRate := dataBody["breathing_rate"].(string)
  2225. evaluation.BreathingRate = breathingRate
  2226. }
  2227. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2228. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2229. evaluation.LastPostDialysis = lastPostDialysis
  2230. }
  2231. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2232. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2233. evaluation.DialysisInterphase = dialysisInterphase
  2234. }
  2235. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2236. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2237. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2238. }
  2239. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2240. catheter, _ := dataBody["catheter"].(string)
  2241. evaluation.Catheter = catheter
  2242. }
  2243. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2244. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2245. evaluation.CatheterBend = catheter_bend
  2246. }
  2247. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2248. Complication, _ := dataBody["complication"].(string)
  2249. evaluation.Complication = Complication
  2250. }
  2251. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2252. remark := dataBody["remark"].(string)
  2253. evaluation.Remark = remark
  2254. }
  2255. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2256. machine_type := dataBody["machine_type"].(string)
  2257. evaluation.MachineType = machine_type
  2258. }
  2259. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2260. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2261. evaluation.BloodAccessPartId = blood_access_part_id
  2262. }
  2263. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2264. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2265. // evaluation.BloodAccessPartId = blood_access_part_id
  2266. //}
  2267. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2268. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2269. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2270. }
  2271. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2272. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2273. evaluation.InternalFistula = internal_fistula
  2274. }
  2275. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2276. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2277. evaluation.InternalFistulaSkin = internal_fistula_skin
  2278. }
  2279. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2280. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2281. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2282. evaluation.IsHemorrhage = is_hemorrhage
  2283. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2284. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2285. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2286. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2287. is_hemorrhage = 0
  2288. }
  2289. evaluation.IsHemorrhage = is_hemorrhage
  2290. if is_hemorrhage == 1 {
  2291. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2292. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2293. evaluation.Hemorrhage = hemorrhage
  2294. }
  2295. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2296. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2297. evaluation.HemorrhageOther = hemorrhage_other
  2298. }
  2299. }
  2300. } else {
  2301. evaluation.IsHemorrhage = 0
  2302. }
  2303. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2304. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2305. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2306. }
  2307. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2308. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2309. evaluation.InternalFistulaOther = internal_fistula_other
  2310. }
  2311. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2312. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2313. evaluation.BloodAccessNoise = blood_access_noise
  2314. }
  2315. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2316. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2317. puncture_way := dataBody["puncture_way"].(string)
  2318. evaluation.PunctureWay = puncture_way
  2319. }
  2320. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2321. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2322. evaluation.VenousCatheterization = venous_catheterization
  2323. }
  2324. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2325. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2326. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2327. }
  2328. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2329. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2330. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2331. }
  2332. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2333. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2334. evaluation.DuctusArantii = ductus_arantii
  2335. }
  2336. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2337. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2338. evaluation.EmergencyTreatment = emergency_treatment
  2339. }
  2340. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2341. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2342. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2343. }
  2344. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2345. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2346. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2347. evaluation.DialysisCount = dialysis_count
  2348. }
  2349. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2350. is_infect, _ := dataBody["is_infect"].(string)
  2351. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2352. evaluation.IsInfect = infect
  2353. }
  2354. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2355. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2356. evaluation.Exposed = exposed
  2357. }
  2358. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2359. skin, _ := dataBody["skin"].(string)
  2360. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2361. evaluation.Skin = skin
  2362. }
  2363. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2364. skin_other, _ := dataBody["skin_other"].(string)
  2365. evaluation.SkinOther = skin_other
  2366. }
  2367. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2368. infect_other, _ := dataBody["infect_other"].(string)
  2369. evaluation.InfectOther = infect_other
  2370. }
  2371. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2372. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2373. evaluation.DuctusArantiiOther = ductus_arantii_other
  2374. }
  2375. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2376. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2377. evaluation.PunctureNeedle = punctureNeedle
  2378. }
  2379. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2380. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2381. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2382. }
  2383. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2384. pinholing := dataBody["pinholing"].(string)
  2385. evaluation.Phinholing = pinholing
  2386. }
  2387. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2388. catheter_suture := dataBody["catheter_suture"].(string)
  2389. evaluation.CatheterSuture = catheter_suture
  2390. }
  2391. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2392. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2393. evaluation.CatheterSutureOther = catheter_suture_other
  2394. }
  2395. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2396. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2397. evaluation.UrineVolume = urine_volume
  2398. }
  2399. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2400. edema := dataBody["edema"].(string)
  2401. evaluation.Edema = edema
  2402. }
  2403. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2404. specialTreatment := dataBody["special_treatment"].(string)
  2405. evaluation.SpecialTreatment = specialTreatment
  2406. }
  2407. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2408. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2409. evaluation.CatheterMaintenance = catheter_maintenance
  2410. }
  2411. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2412. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2413. evaluation.ThromubusType = thromubusType
  2414. }
  2415. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2416. thrombus_av := dataBody["thrombus_av"].(string)
  2417. evaluation.ThrombusAv = thrombus_av
  2418. }
  2419. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2420. thromubus_a := dataBody["thromubus_a"].(string)
  2421. evaluation.ThromubusA = thromubus_a
  2422. }
  2423. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2424. thromubus_v := dataBody["thromubus_v"].(string)
  2425. evaluation.ThromubusV = thromubus_v
  2426. }
  2427. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2428. dehydration := dataBody["dehydration"].(string)
  2429. evaluation.Dehydration = dehydration
  2430. }
  2431. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2432. period := int64(dataBody["period"].(float64))
  2433. evaluation.Period = period
  2434. }
  2435. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2436. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2437. evaluation.EstimatedFoodIntake = estimated_food_intake
  2438. }
  2439. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2440. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2441. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2442. }
  2443. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2444. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2445. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2446. }
  2447. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  2448. urea_befor := dataBody["urea_befor"].(string)
  2449. evaluation.UreaBefor = urea_befor
  2450. }
  2451. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  2452. suction := dataBody["suction"].(string)
  2453. evaluation.Suction = suction
  2454. }
  2455. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  2456. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  2457. evaluation.WeightBeforRemake = weight_befor_remake
  2458. }
  2459. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  2460. height := dataBody["height"].(string)
  2461. evaluation.Height = height
  2462. }
  2463. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  2464. age := dataBody["age"].(string)
  2465. evaluation.Age = age
  2466. }
  2467. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  2468. his_department := dataBody["his_department"].(string)
  2469. evaluation.HisDepartment = his_department
  2470. }
  2471. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  2472. his_bed := dataBody["his_bed"].(string)
  2473. evaluation.HisBed = his_bed
  2474. }
  2475. return
  2476. }
  2477. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2478. dataBody := make(map[string]interface{}, 0)
  2479. err := json.Unmarshal(data, &dataBody)
  2480. if err != nil {
  2481. utils.ErrorLog(err.Error())
  2482. code = enums.ErrorCodeParamWrong
  2483. return
  2484. }
  2485. timeLayout := "2006-01-02"
  2486. loc, _ := time.LoadLocation("Local")
  2487. isChild := false
  2488. if action == "create" {
  2489. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2490. utils.ErrorLog("advice_type")
  2491. code = enums.ErrorCodeParamWrong
  2492. return
  2493. }
  2494. adviceType := int64(dataBody["advice_type"].(float64))
  2495. if adviceType != 1 && adviceType != 2 {
  2496. utils.ErrorLog("advice_type != 1&&2")
  2497. code = enums.ErrorCodeParamWrong
  2498. return
  2499. }
  2500. advice.AdviceType = adviceType
  2501. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2502. utils.ErrorLog("advice_date")
  2503. code = enums.ErrorCodeParamWrong
  2504. return
  2505. }
  2506. adviceDate, _ := dataBody["advice_date"].(string)
  2507. if len(adviceDate) == 0 {
  2508. utils.ErrorLog("len(adviceDate) == 0")
  2509. code = enums.ErrorCodeParamWrong
  2510. return
  2511. }
  2512. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2513. if err != nil {
  2514. utils.ErrorLog(err.Error())
  2515. code = enums.ErrorCodeParamWrong
  2516. return
  2517. }
  2518. advice.AdviceDate = theTime.Unix()
  2519. advice.RecordDate = theTime.Unix()
  2520. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2521. parentId := int64(dataBody["parent_id"].(float64))
  2522. advice.ParentId = parentId
  2523. if parentId > 0 {
  2524. isChild = true
  2525. }
  2526. }
  2527. } else {
  2528. isChild = advice.ParentId > 0
  2529. }
  2530. if !isChild {
  2531. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2532. utils.ErrorLog("start_time")
  2533. code = enums.ErrorCodeParamWrong
  2534. return
  2535. }
  2536. startTime, _ := dataBody["start_time"].(string)
  2537. if len(startTime) == 0 {
  2538. utils.ErrorLog("len(start_time) == 0")
  2539. code = enums.ErrorCodeParamWrong
  2540. return
  2541. }
  2542. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2543. if err != nil {
  2544. utils.ErrorLog(err.Error())
  2545. code = enums.ErrorCodeParamWrong
  2546. return
  2547. }
  2548. advice.StartTime = theTime.Unix()
  2549. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2550. deliveryWay, _ := dataBody["delivery_way"].(string)
  2551. advice.DeliveryWay = deliveryWay
  2552. }
  2553. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2554. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2555. advice.ExecutionFrequency = executionFrequency
  2556. }
  2557. }
  2558. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2559. deliveryWay, _ := dataBody["delivery_way"].(string)
  2560. advice.DeliveryWay = deliveryWay
  2561. }
  2562. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2563. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2564. advice.ExecutionFrequency = executionFrequency
  2565. }
  2566. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2567. utils.ErrorLog("advice_name")
  2568. code = enums.ErrorCodeParamWrong
  2569. return
  2570. }
  2571. adviceName, _ := dataBody["advice_name"].(string)
  2572. if len(adviceName) == 0 {
  2573. utils.ErrorLog("len(advice_name) == 0")
  2574. code = enums.ErrorCodeParamWrong
  2575. return
  2576. }
  2577. advice.AdviceName = adviceName
  2578. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2579. adviceDsc, _ := dataBody["advice_desc"].(string)
  2580. advice.AdviceDesc = adviceDsc
  2581. }
  2582. if dataBody["way"] == nil {
  2583. advice.Way = 0
  2584. } else {
  2585. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2586. way := int64(dataBody["way"].(float64))
  2587. advice.Way = way
  2588. }
  2589. }
  2590. if dataBody["drug_id"] == nil {
  2591. advice.DrugId = 0
  2592. } else {
  2593. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2594. drug_id := int64(dataBody["drug_id"].(float64))
  2595. advice.DrugId = drug_id
  2596. }
  2597. }
  2598. if dataBody["drug_name_id"] == nil {
  2599. advice.DrugNameId = 0
  2600. } else {
  2601. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2602. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  2603. advice.DrugNameId = drug_name_id
  2604. }
  2605. }
  2606. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2607. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2608. advice.SingleDose = singleDose
  2609. }
  2610. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2611. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2612. advice.SingleDoseUnit = singleDoseUnit
  2613. }
  2614. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2615. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2616. advice.DrugSpec = drugSpec
  2617. }
  2618. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2619. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2620. advice.DrugSpecUnit = drugSpecUnit
  2621. }
  2622. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2623. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2624. advice.PrescribingNumber = prescribingNumber
  2625. }
  2626. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2627. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2628. advice.PrescribingNumberUnit = prescribingNumberUnit
  2629. }
  2630. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2631. remark, _ := dataBody["remark"].(string)
  2632. advice.Remark = remark
  2633. }
  2634. return
  2635. }
  2636. func (c *PatientApiController) GetPatientEducation() {
  2637. patientID, _ := c.GetInt64("patient_id", 0)
  2638. page, _ := c.GetInt64("page", 0)
  2639. limit, _ := c.GetInt64("limit", 0)
  2640. startTime := c.GetString("start_time", "")
  2641. endTime := c.GetString("end_time", "")
  2642. if page <= 0 {
  2643. page = 1
  2644. }
  2645. if limit <= 0 {
  2646. limit = 10
  2647. }
  2648. if patientID <= 0 {
  2649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2650. return
  2651. }
  2652. timeLayout := "2006-01-02"
  2653. loc, _ := time.LoadLocation("Local")
  2654. var theStartTIme int64
  2655. if len(startTime) > 0 {
  2656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2657. if err != nil {
  2658. theStartTIme = 0
  2659. }
  2660. theStartTIme = theTime.Unix()
  2661. }
  2662. var theEndtTIme int64
  2663. if len(endTime) > 0 {
  2664. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2665. if err != nil {
  2666. theEndtTIme = 0
  2667. }
  2668. theEndtTIme = theTime.Unix()
  2669. }
  2670. adminUserInfo := c.GetMobileAdminUserInfo()
  2671. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  2672. c.ServeSuccessJSON(map[string]interface{}{
  2673. "total": total,
  2674. "edus": edus,
  2675. })
  2676. return
  2677. }
  2678. func (c *PatientApiController) GetPatientSchedulesList() {
  2679. patientID, _ := c.GetInt64("patient_id", 0)
  2680. page, _ := c.GetInt64("page", 0)
  2681. limit, _ := c.GetInt64("limit", 0)
  2682. if patientID <= 0 {
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2684. return
  2685. }
  2686. adminUserInfo := c.GetMobileAdminUserInfo()
  2687. todayTime := time.Now().Format("2006-01-02")
  2688. timeLayout := "2006-01-02 15:04:05"
  2689. loc, _ := time.LoadLocation("Local")
  2690. var theStartTime int64
  2691. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2692. theStartTime = theTime.Unix()
  2693. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  2694. if len(schedules) > 0 {
  2695. for index, item := range schedules {
  2696. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2697. schedules[index].Week = int64(week)
  2698. }
  2699. }
  2700. c.ServeSuccessJSON(map[string]interface{}{
  2701. "schedules": schedules,
  2702. })
  2703. return
  2704. }
  2705. func (c *PatientApiController) GetRecords() {
  2706. patientID, _ := c.GetInt64("patient_id", 0)
  2707. page, _ := c.GetInt64("page", 0)
  2708. limit, _ := c.GetInt64("limit", 0)
  2709. startTime := c.GetString("start_time", "")
  2710. endTime := c.GetString("end_time", "")
  2711. mode_id, _ := c.GetInt64("mode_id", 0)
  2712. if page <= 0 {
  2713. page = 1
  2714. }
  2715. if limit <= 0 {
  2716. limit = 10
  2717. }
  2718. if patientID <= 0 {
  2719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2720. return
  2721. }
  2722. timeLayout := "2006-01-02"
  2723. loc, _ := time.LoadLocation("Local")
  2724. var theStartTIme int64
  2725. if len(startTime) > 0 {
  2726. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2727. if err != nil {
  2728. theStartTIme = 0
  2729. }
  2730. theStartTIme = theTime.Unix()
  2731. }
  2732. var theEndtTIme int64
  2733. if len(endTime) > 0 {
  2734. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2735. if err != nil {
  2736. theEndtTIme = 0
  2737. }
  2738. theEndtTIme = theTime.Unix()
  2739. }
  2740. adminUserInfo := c.GetMobileAdminUserInfo()
  2741. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2742. c.ServeSuccessJSON(map[string]interface{}{
  2743. "total": total,
  2744. "records": records,
  2745. })
  2746. return
  2747. }
  2748. func (c *PatientApiController) GetPatientMonitor() {
  2749. partition, _ := c.GetInt64("partition")
  2750. monitorDate := c.GetString("date")
  2751. patient_id, _ := c.GetInt64("patient_id")
  2752. timeLayout := "2006-01-02"
  2753. loc, _ := time.LoadLocation("Local")
  2754. var theStartTime int64
  2755. if len(monitorDate) > 0 {
  2756. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  2757. if err != nil {
  2758. theStartTime = 0
  2759. }
  2760. theStartTime = theTime.Unix()
  2761. }
  2762. adminInfo := c.GetMobileAdminUserInfo()
  2763. orgID := adminInfo.Org.Id
  2764. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  2765. if err != nil {
  2766. c.ErrorLog("获取排班信息失败:%v", err)
  2767. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2768. } else {
  2769. if len(monitor) > 0 {
  2770. //获取所有床位
  2771. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  2772. //获取所有分区
  2773. zoneList, _ := service.GetAllZoneByList(orgID)
  2774. //获取透析处方
  2775. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  2776. //获取透前评估
  2777. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  2778. //获取上机
  2779. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  2780. //获取透后
  2781. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  2782. //获取透后监测
  2783. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  2784. //获取所有的患者
  2785. patients, _ := service.GetAllPatientListByListOne(orgID)
  2786. //获取所有透析模式
  2787. treatments, _ := service.GetAllTreatModeByList(orgID)
  2788. for key, item := range monitor {
  2789. // 获取床位信息
  2790. for _, it := range numberList {
  2791. if item.BedId == it.ID {
  2792. monitor[key].DeviceNumber = it
  2793. break
  2794. }
  2795. }
  2796. //获取分区信息
  2797. for _, it := range zoneList {
  2798. if item.PartitionId == it.ID {
  2799. monitor[key].DeviceZone = it
  2800. }
  2801. }
  2802. for _, prescription := range prescriptions {
  2803. if item.PatientId == prescription.PatientId {
  2804. monitor[key].Prescription = prescription
  2805. break
  2806. }
  2807. }
  2808. // 透前评估
  2809. for _, assessmentBefore := range assessmentBefores {
  2810. if item.PatientId == assessmentBefore.PatientId {
  2811. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  2812. break
  2813. }
  2814. }
  2815. // 透析上下机
  2816. for _, dialysisOrder := range dialysisOrders {
  2817. if item.PatientId == dialysisOrder.PatientId {
  2818. monitor[key].DialysisOrder = dialysisOrder
  2819. break
  2820. }
  2821. }
  2822. // 治疗小节
  2823. for _, afterDislysis := range AssessmentAfterDislysis {
  2824. if item.PatientId == afterDislysis.PatientId {
  2825. monitor[key].AssessmentAfterDislysis = afterDislysis
  2826. break
  2827. }
  2828. }
  2829. for _, it := range monitorlist {
  2830. if item.PatientId == it.PatientId {
  2831. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  2832. }
  2833. }
  2834. for _, patient := range patients {
  2835. if item.PatientId == patient.ID {
  2836. monitor[key].MonitorPatients = patient
  2837. break
  2838. }
  2839. }
  2840. for _, treatment := range treatments {
  2841. if item.ModeId == treatment.ID {
  2842. monitor[key].TreatmentMode = treatment
  2843. break
  2844. }
  2845. }
  2846. }
  2847. }
  2848. }
  2849. //获取患者的透析次数
  2850. count, err := service.GetDialysisCount(orgID, partition)
  2851. patients, err := service.GetAllpatientThirty(orgID)
  2852. if err == nil {
  2853. c.ServeSuccessJSON(map[string]interface{}{
  2854. "monitor": monitor,
  2855. "patientCount": count,
  2856. "patients": patients,
  2857. })
  2858. } else {
  2859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2860. }
  2861. }
  2862. // /m/api/monitor/patient [get] 搜索病人的测量记录
  2863. // @param keyword:string 病人姓名或透析号
  2864. // @param page:int
  2865. func (this *PatientApiController) SearchMonitorPatient() {
  2866. keyword := this.GetString("keyword")
  2867. page, _ := this.GetInt("page")
  2868. if page <= 0 {
  2869. page = 1
  2870. }
  2871. if len(keyword) == 0 {
  2872. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2873. return
  2874. }
  2875. adminUserInfo := this.GetMobileAdminUserInfo()
  2876. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  2877. if getMonitorErr != nil {
  2878. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2879. return
  2880. } else {
  2881. this.ServeSuccessJSON(map[string]interface{}{
  2882. "monitor": monitors,
  2883. })
  2884. }
  2885. }
  2886. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  2887. id, _ := c.GetInt64("id", 0)
  2888. page, _ := c.GetInt64("page", 0)
  2889. limit, _ := c.GetInt64("limit", 0)
  2890. if id <= 0 {
  2891. c.ServeSuccessJSON(map[string]interface{}{
  2892. "solutions": nil,
  2893. })
  2894. return
  2895. }
  2896. if page <= 0 {
  2897. page = 1
  2898. }
  2899. if limit <= 0 {
  2900. limit = 10
  2901. }
  2902. adminInfo := c.GetMobileAdminUserInfo()
  2903. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  2904. c.ServeSuccessJSON(map[string]interface{}{
  2905. "solutions": solutions,
  2906. "total": total,
  2907. })
  2908. return
  2909. }
  2910. // GetDoctorAdvices 医嘱列表
  2911. func (c *PatientApiController) GetDoctorAdvices() {
  2912. id, _ := c.GetInt64("id", 0)
  2913. adviceType, _ := c.GetInt64("advice_type", 0)
  2914. stopType, _ := c.GetInt64("stop_state", 0)
  2915. startTime := c.GetString("start_time", "")
  2916. endTime := c.GetString("end_time", "")
  2917. keywords := c.GetString("keywords", "")
  2918. need, _ := c.GetInt64("need_doctor", 0)
  2919. adminUserInfo := c.GetMobileAdminUserInfo()
  2920. timeLayout := "2006-01-02"
  2921. loc, _ := time.LoadLocation("Local")
  2922. var theStartTIme int64
  2923. if len(startTime) > 0 {
  2924. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2925. if err != nil {
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2927. return
  2928. }
  2929. theStartTIme = theTime.Unix()
  2930. }
  2931. var theEndtTIme int64
  2932. if len(endTime) > 0 {
  2933. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2934. if err != nil {
  2935. utils.ErrorLog(err.Error())
  2936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2937. return
  2938. }
  2939. theEndtTIme = theTime.Unix()
  2940. }
  2941. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  2942. if need == 1 {
  2943. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2944. c.ServeSuccessJSON(map[string]interface{}{
  2945. "advices": advices,
  2946. "total": total,
  2947. "users": users,
  2948. })
  2949. } else {
  2950. c.ServeSuccessJSON(map[string]interface{}{
  2951. "advices": advices,
  2952. "total": total,
  2953. "users": []string{},
  2954. })
  2955. }
  2956. return
  2957. }
  2958. func (c *PatientApiController) GetPrintDialysisOrder() {
  2959. xtno := c.GetString("xtno")
  2960. xtdate := c.GetString("xtdate")
  2961. timeLayout := "2006-01-02"
  2962. loc, _ := time.LoadLocation("Local")
  2963. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2964. if err != nil {
  2965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2966. return
  2967. }
  2968. xttime := theTime.Unix()
  2969. //获取当前日期月份的第一天
  2970. firstmonth := service.GetFirstDateOfMonth(theTime)
  2971. firstMonthDate := firstmonth.Unix()
  2972. operatorIDs := make([]int64, 0)
  2973. adminUserInfo := c.GetMobileAdminUserInfo()
  2974. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2975. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  2976. //透析单
  2977. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2978. if dialysisOrder != nil {
  2979. if dialysisOrder.FinishNurse > 0 {
  2980. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2981. }
  2982. if dialysisOrder.StartNurse > 0 {
  2983. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2984. }
  2985. }
  2986. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2987. //透前评估
  2988. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2989. //透后评估
  2990. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2991. if AssessmentAfterDislysis.Modifier > 0 {
  2992. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2993. }
  2994. //透析处方
  2995. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2996. if dialysisPrescription.PrescriptionDoctor > 0 {
  2997. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2998. }
  2999. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3000. patientInfo.TotalDialysis = dialysis_count
  3001. //临时医嘱
  3002. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3003. fmt.Println("DoctorAdvice3223323323232323223323323223332232332wode", DoctorAdvice)
  3004. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3005. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  3006. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  3007. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3008. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3009. for _, item := range projects {
  3010. cnt, _ := strconv.ParseFloat(item.Count, 64)
  3011. var advice models.HisDoctorAdviceInfo
  3012. advice.ID = item.ID
  3013. advice.Checker = item.Checker
  3014. advice.CheckTime = item.CheckTime
  3015. advice.CheckState = item.CheckState
  3016. advice.ExecutionState = item.ExecutionState
  3017. advice.ExecutionStaff = item.ExecutionStaff
  3018. //advice.PrescribingNumber = float64(item.Count)
  3019. advice.PrescribingNumber = cnt
  3020. advice.PrescribingNumberUnit = item.Unit
  3021. advice.AdviceDoctor = item.Doctor
  3022. if item.Type == 3 {
  3023. advice.AdviceName = item.GoodInfo.GoodName
  3024. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  3025. } else if item.Type == 2 {
  3026. advice.AdviceName = item.HisProject.ProjectName
  3027. }
  3028. advice.StartTime = item.StartTime
  3029. hisAdvice = append(hisAdvice, &advice)
  3030. }
  3031. }
  3032. if len(DoctorAdvice) > 0 {
  3033. for _, item := range DoctorAdvice {
  3034. if item.AdviceDoctor > 0 {
  3035. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3036. }
  3037. if item.ExecutionStaff > 0 {
  3038. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3039. }
  3040. if item.Checker > 0 {
  3041. operatorIDs = append(operatorIDs, item.Checker)
  3042. }
  3043. }
  3044. }
  3045. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3046. //透析监测
  3047. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3048. //透析小结
  3049. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3050. //接诊评估
  3051. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3052. //相关操作对应的操作人
  3053. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  3054. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  3055. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3056. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3057. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  3058. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3059. if config.IsOpen == 1 {
  3060. c.ServeSuccessJSON(map[string]interface{}{
  3061. "users": adminUser,
  3062. "patientInfo": patientInfo,
  3063. "PredialysisEvaluation": PredialysisEvaluation,
  3064. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3065. "dialysisPrescription": dialysisPrescription,
  3066. "advices": hisAdvice,
  3067. "monitors": Record,
  3068. "summary": TreatmentSummary,
  3069. "receiverTreatmentAccess": receiverTreatmentAccess,
  3070. "dialysisOrder": dialysisOrder,
  3071. "operators": operators,
  3072. "org_template_info": templateInfo,
  3073. "check": check,
  3074. "dialysiscount": dialysiscount,
  3075. "last_order": last_order,
  3076. "projects": projects,
  3077. "project_config": project_config,
  3078. "lastWeight": lastWeight,
  3079. })
  3080. }
  3081. if config.IsOpen == 0 || config.IsOpen == 2 {
  3082. c.ServeSuccessJSON(map[string]interface{}{
  3083. "users": adminUser,
  3084. "patientInfo": patientInfo,
  3085. "PredialysisEvaluation": PredialysisEvaluation,
  3086. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3087. "dialysisPrescription": dialysisPrescription,
  3088. "advices": DoctorAdvice,
  3089. "monitors": Record,
  3090. "summary": TreatmentSummary,
  3091. "receiverTreatmentAccess": receiverTreatmentAccess,
  3092. "dialysisOrder": dialysisOrder,
  3093. "operators": operators,
  3094. "org_template_info": templateInfo,
  3095. "check": check,
  3096. "dialysiscount": dialysiscount,
  3097. "last_order": last_order,
  3098. "projects": projects,
  3099. "project_config": project_config,
  3100. "lastWeight": lastWeight,
  3101. })
  3102. }
  3103. }
  3104. func (c *PatientApiController) CreateGroupAdvice() {
  3105. is_child, _ := c.GetInt64("is_child", 0)
  3106. if is_child == 1 {
  3107. patient, _ := c.GetInt64("id", 0)
  3108. if patient <= 0 {
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3110. return
  3111. }
  3112. adminUserInfo := c.GetMobileAdminUserInfo()
  3113. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3114. if patientInfo.ID == 0 {
  3115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3116. return
  3117. }
  3118. group_no, _ := c.GetInt64("group_no")
  3119. if group_no <= 0 {
  3120. group_no = 0
  3121. }
  3122. dataBody := make(map[string]interface{}, 0)
  3123. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3124. if err != nil {
  3125. utils.ErrorLog(err.Error())
  3126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3127. return
  3128. }
  3129. timeLayout := "2006-01-02"
  3130. loc, _ := time.LoadLocation("Local")
  3131. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3132. utils.ErrorLog("advice_type")
  3133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3134. return
  3135. }
  3136. adviceType := int64(dataBody["advice_type"].(float64))
  3137. if adviceType != 1 && adviceType != 2 {
  3138. utils.ErrorLog("advice_type != 1&&2")
  3139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3140. return
  3141. }
  3142. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3143. utils.ErrorLog("start_time")
  3144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3145. return
  3146. }
  3147. startTime2, _ := dataBody["start_time"].(string)
  3148. time_arr := strings.Split(startTime2, " ")
  3149. if len(time_arr) > 0 {
  3150. startTime2 = time_arr[0]
  3151. }
  3152. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3153. utils.ErrorLog("advice_date")
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3155. return
  3156. }
  3157. advice_date, _ := dataBody["advice_date"].(string)
  3158. var advicedateunix int64
  3159. if len(advice_date) > 0 {
  3160. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  3161. if err != nil {
  3162. fmt.Println(err)
  3163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3164. return
  3165. }
  3166. advicedateunix = theTime.Unix()
  3167. }
  3168. adviceDate := startTime2
  3169. if len(adviceDate) == 0 {
  3170. utils.ErrorLog("len(adviceDate) == 0")
  3171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3172. return
  3173. }
  3174. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3175. if err != nil {
  3176. utils.ErrorLog(err.Error())
  3177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3178. return
  3179. }
  3180. AdviceDate := advicedateunix
  3181. RecordDate := advicedateunix
  3182. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3183. utils.ErrorLog("start_time")
  3184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3185. return
  3186. }
  3187. startTime, _ := dataBody["start_time"].(string)
  3188. if len(startTime) == 0 {
  3189. utils.ErrorLog("len(start_time) == 0")
  3190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3191. return
  3192. }
  3193. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3194. theTimeOne, _ := time.ParseInLocation("2006-01-02 15:04:05", startTime2+" 00:00:00", loc)
  3195. if err != nil {
  3196. utils.ErrorLog(err.Error())
  3197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3198. return
  3199. }
  3200. StartTime := theTime.Unix()
  3201. Remark := ""
  3202. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3203. remark, _ := dataBody["remark"].(string)
  3204. Remark = remark
  3205. }
  3206. var advices []*models.GroupAdvice
  3207. // utils.TraceLog("%+v", dataBody["adviceNames"])
  3208. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  3209. utils.ErrorLog("adviceNames")
  3210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3211. return
  3212. }
  3213. adviceNames := dataBody["adviceNames"].([]interface{})
  3214. for _, adviceNameMap := range adviceNames {
  3215. adviceNameM := adviceNameMap.(map[string]interface{})
  3216. var advice models.GroupAdvice
  3217. advice.Remark = Remark
  3218. advice.AdviceType = adviceType
  3219. advice.StartTime = StartTime
  3220. if adminUserInfo.Org.Id == 10340 {
  3221. advice.AdviceDate = AdviceDate
  3222. advice.RecordDate = RecordDate
  3223. }
  3224. if adminUserInfo.Org.Id != 10340 {
  3225. advice.AdviceDate = theTimeOne.Unix()
  3226. advice.RecordDate = theTimeOne.Unix()
  3227. }
  3228. advice.Status = 1
  3229. advice.CreatedTime = time.Now().Unix()
  3230. advice.UpdatedTime = time.Now().Unix()
  3231. advice.StopState = 2
  3232. advice.ExecutionState = 2
  3233. advice.UserOrgId = adminUserInfo.Org.Id
  3234. advice.PatientId = patientInfo.ID
  3235. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3236. advice.IsSettle = 2
  3237. //入口
  3238. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  3239. if errcode > 0 {
  3240. c.ServeFailJSONWithSGJErrorCode(errcode)
  3241. return
  3242. }
  3243. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  3244. subdrugs := adviceNameM["subdrugs"].([]interface{})
  3245. if len(subdrugs) > 0 {
  3246. for _, subdrug := range subdrugs {
  3247. var s models.GroupAdvice
  3248. s.Remark = Remark
  3249. s.AdviceType = adviceType
  3250. s.StartTime = StartTime
  3251. s.AdviceDate = AdviceDate
  3252. s.RecordDate = RecordDate
  3253. s.Status = 1
  3254. s.CreatedTime = time.Now().Unix()
  3255. s.UpdatedTime = time.Now().Unix()
  3256. s.StopState = 2
  3257. s.ExecutionState = 2
  3258. s.UserOrgId = adminUserInfo.Org.Id
  3259. s.PatientId = patientInfo.ID
  3260. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  3261. s.IsSettle = 2
  3262. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  3263. if errcode > 0 {
  3264. c.ServeFailJSONWithSGJErrorCode(errcode)
  3265. return
  3266. }
  3267. advice.Children = append(advice.Children, &s)
  3268. }
  3269. }
  3270. }
  3271. //长沙南雅
  3272. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3273. //查询该患者今日有没有双人核对
  3274. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  3275. if check.ID > 0 {
  3276. advice.Checker = check.Modifier
  3277. advice.CheckState = 1
  3278. advice.CheckTime = time.Now().Unix()
  3279. }
  3280. }
  3281. advices = append(advices, &advice)
  3282. }
  3283. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3284. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3285. redis := service.RedisClient()
  3286. //清空key 值
  3287. redis.Set(key, "", time.Second)
  3288. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3289. redis.Set(keyOne, "", time.Second)
  3290. defer redis.Close()
  3291. if createErr != nil {
  3292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3293. return
  3294. }
  3295. c.ServeSuccessJSON(map[string]interface{}{
  3296. "msg": "ok",
  3297. "advices": newAdvices,
  3298. })
  3299. return
  3300. } else if is_child == 2 {
  3301. patient, _ := c.GetInt64("id", 0)
  3302. if patient <= 0 {
  3303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3304. return
  3305. }
  3306. adminUserInfo := c.GetMobileAdminUserInfo()
  3307. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3308. if patientInfo.ID == 0 {
  3309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3310. return
  3311. }
  3312. var advice models.DoctorAdvice
  3313. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3314. if code > 0 {
  3315. c.ServeFailJSONWithSGJErrorCode(code)
  3316. return
  3317. }
  3318. if advice.ParentId > 0 {
  3319. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3320. if old.ID == 0 || old.PatientId != patient {
  3321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3322. return
  3323. }
  3324. if old.StopState == 1 || old.ExecutionState == 1 {
  3325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3326. return
  3327. }
  3328. if old.ParentId > 0 {
  3329. advice.ParentId = old.ParentId
  3330. }
  3331. advice.StartTime = old.StartTime
  3332. advice.AdviceDoctor = old.AdviceDoctor
  3333. advice.DeliveryWay = old.DeliveryWay
  3334. advice.ExecutionFrequency = old.ExecutionFrequency
  3335. advice.GroupNo = old.GroupNo
  3336. }
  3337. advice.Status = 1
  3338. advice.CreatedTime = time.Now().Unix()
  3339. advice.UpdatedTime = time.Now().Unix()
  3340. advice.StopState = 2
  3341. advice.ExecutionState = 2
  3342. advice.UserOrgId = adminUserInfo.Org.Id
  3343. advice.PatientId = patient
  3344. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3345. advice.IsSettle = 2
  3346. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3347. if advice.PrescribingNumber == 0 {
  3348. advice.PrescribingNumber = 1
  3349. }
  3350. //查询该患者今日有没有双人核对
  3351. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  3352. if check.ID > 0 {
  3353. advice.Checker = check.Modifier
  3354. advice.CheckState = 1
  3355. advice.CheckTime = time.Now().Unix()
  3356. }
  3357. }
  3358. err := service.CreateDoctorAdvice(&advice)
  3359. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3360. redis := service.RedisClient()
  3361. //清空key 值
  3362. redis.Set(key, "", time.Second)
  3363. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3364. redis.Set(keyOne, "", time.Second)
  3365. defer redis.Close()
  3366. if err != nil {
  3367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3368. return
  3369. }
  3370. c.ServeSuccessJSON(map[string]interface{}{
  3371. "msg": "ok",
  3372. "advice": advice,
  3373. })
  3374. return
  3375. }
  3376. }
  3377. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3378. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3379. utils.ErrorLog("advice_name")
  3380. return enums.ErrorCodeParamWrong
  3381. }
  3382. adviceName, _ := json["advice_name"].(string)
  3383. if len(adviceName) == 0 {
  3384. utils.ErrorLog("len(advice_name) == 0")
  3385. return enums.ErrorCodeParamWrong
  3386. }
  3387. advice.AdviceName = adviceName
  3388. adviceDesc, _ := json["advice_desc"].(string)
  3389. advice.AdviceDesc = adviceDesc
  3390. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3391. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3392. advice.DrugSpec = drugSpec
  3393. }
  3394. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3395. remark, _ := json["remark"].(string)
  3396. advice.Remark = remark
  3397. }
  3398. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3399. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3400. // advice.Way = src_type
  3401. //}
  3402. if json["way"] == nil {
  3403. advice.Way = 0
  3404. } else {
  3405. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3406. way := int64(json["way"].(float64))
  3407. advice.Way = way
  3408. }
  3409. }
  3410. if json["drug_id"] == nil {
  3411. advice.DrugId = 0
  3412. } else {
  3413. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3414. drug_id := int64(json["drug_id"].(float64))
  3415. advice.DrugId = drug_id
  3416. }
  3417. }
  3418. if json["drug_name_id"] == nil {
  3419. advice.DrugNameId = 0
  3420. } else {
  3421. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3422. drug_name_id := int64(json["drug_name_id"].(float64))
  3423. advice.DrugNameId = drug_name_id
  3424. }
  3425. }
  3426. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3427. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3428. advice.DrugSpecUnit = drugSpecUnit
  3429. }
  3430. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3431. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3432. advice.SingleDose = singleDose
  3433. }
  3434. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3435. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3436. advice.SingleDoseUnit = singleDoseUnit
  3437. }
  3438. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3439. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3440. advice.PrescribingNumber = prescribingNumber
  3441. }
  3442. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3443. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3444. advice.PrescribingNumberUnit = prescribingNumberUnit
  3445. }
  3446. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3447. deliveryWay, _ := json["delivery_way"].(string)
  3448. advice.DeliveryWay = deliveryWay
  3449. }
  3450. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3451. executionFrequency, _ := json["execution_frequency"].(string)
  3452. advice.ExecutionFrequency = executionFrequency
  3453. }
  3454. return 0
  3455. }
  3456. func (c *PatientApiController) DelDoctorAdvice() {
  3457. groupno, _ := c.GetInt64("groupno", -1)
  3458. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3459. patient_id, _ := c.GetInt64("patient_id")
  3460. doc_advice_date, _ := c.GetInt64("advice_date")
  3461. redis := service.RedisClient()
  3462. if is_sub == 1 { //是
  3463. advice_id, _ := c.GetInt64("advice_id")
  3464. adminUserInfo := c.GetMobileAdminUserInfo()
  3465. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3466. if advice.ID == 0 {
  3467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3468. return
  3469. }
  3470. advice.Status = 0
  3471. advice.UpdatedTime = time.Now().Unix()
  3472. advice.Modifier = adminUserInfo.AdminUser.Id
  3473. err := service.DeleteDoctorAdvice(&advice)
  3474. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3475. redis.Set(key, "", time.Second)
  3476. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3477. redis.Set(keyTwo, "", time.Second)
  3478. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3479. redis.Set(keyThree, "", time.Second)
  3480. redis.Close()
  3481. if err != nil {
  3482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3483. return
  3484. }
  3485. c.ServeSuccessJSON(map[string]interface{}{
  3486. "msg": "ok",
  3487. })
  3488. return
  3489. } else { //
  3490. var ids []string
  3491. if groupno == 0 {
  3492. advice_id := c.GetString("advice_id")
  3493. ids = strings.Split(advice_id, ",")
  3494. if len(ids) <= 0 {
  3495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3496. return
  3497. }
  3498. }
  3499. if groupno < 0 {
  3500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3501. return
  3502. }
  3503. adminUserInfo := c.GetMobileAdminUserInfo()
  3504. var advice models.DoctorAdvice
  3505. if groupno > 0 {
  3506. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  3507. if advice.ID == 0 {
  3508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3509. return
  3510. }
  3511. } else {
  3512. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  3513. for _, item := range advices {
  3514. if item.ID == 0 {
  3515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3516. return
  3517. }
  3518. }
  3519. }
  3520. advice.UpdatedTime = time.Now().Unix()
  3521. advice.Status = 0
  3522. advice.GroupNo = groupno
  3523. advice.Modifier = adminUserInfo.AdminUser.Id
  3524. var err error
  3525. if groupno > 0 {
  3526. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  3527. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3528. redis.Set(key, "", time.Second)
  3529. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3530. redis.Set(keyTwo, "", time.Second)
  3531. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3532. redis.Set(keyThree, "", time.Second)
  3533. } else {
  3534. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  3535. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3536. redis.Set(key, "", time.Second)
  3537. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3538. redis.Set(keyTwo, "", time.Second)
  3539. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3540. redis.Set(keyThree, "", time.Second)
  3541. redis.Close()
  3542. }
  3543. if err != nil {
  3544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3545. return
  3546. }
  3547. c.ServeSuccessJSON(map[string]interface{}{
  3548. "msg": "ok",
  3549. })
  3550. return
  3551. }
  3552. }
  3553. // /m/api/advice/group/modify_starttime [post]
  3554. // @param group_no:int
  3555. // @param start_time:string yyyy-MM-dd hh:mm:ss
  3556. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  3557. group_no, _ := this.GetInt64("group_no")
  3558. start_time_str := this.GetString("start_time")
  3559. if group_no <= 0 || len(start_time_str) == 0 {
  3560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3561. return
  3562. }
  3563. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  3564. if parseTimeErr != nil {
  3565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  3566. return
  3567. }
  3568. adminUserInfo := this.GetMobileAdminUserInfo()
  3569. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  3570. if updateStartTimeErr != nil {
  3571. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  3572. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3573. return
  3574. }
  3575. this.ServeSuccessJSON(map[string]interface{}{
  3576. "start_time": startTime.Unix(),
  3577. })
  3578. }
  3579. func (this *PatientApiController) DelSubDoctorAdvice() {
  3580. advice_id, _ := this.GetInt64("advice_id")
  3581. adminUserInfo := this.GetMobileAdminUserInfo()
  3582. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3583. if advice.ID == 0 {
  3584. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3585. return
  3586. }
  3587. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3588. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  3589. // return
  3590. //}
  3591. advice.Status = 0
  3592. advice.UpdatedTime = time.Now().Unix()
  3593. advice.Modifier = adminUserInfo.AdminUser.Id
  3594. err := service.DeleteDoctorAdvice(&advice)
  3595. if err != nil {
  3596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3597. return
  3598. }
  3599. this.ServeSuccessJSON(map[string]interface{}{
  3600. "msg": "ok",
  3601. })
  3602. return
  3603. }
  3604. func (this *PatientApiController) GetAdviceUnReadMessage() {
  3605. //adminUserInfo := this.GetMobileAdminUserInfo()
  3606. //service.FindUnReadDoctorAdviceMessage()
  3607. }
  3608. func (this *PatientApiController) GetPatientsByKeyWord() {
  3609. keyWord := this.GetString("keyword")
  3610. adminUserInfo := this.GetMobileAdminUserInfo()
  3611. today := utils.ZeroHourTimeOfDay(time.Now())
  3612. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  3613. if err != nil {
  3614. utils.ErrorLog(err.Error())
  3615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3616. return
  3617. }
  3618. this.ServeSuccessJSON(map[string]interface{}{
  3619. "patient": patient,
  3620. })
  3621. }
  3622. func (this *PatientApiController) GetSearchPatient() {
  3623. keyWord := this.GetString("keyword")
  3624. adminUserInfo := this.GetMobileAdminUserInfo()
  3625. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  3626. if err != nil {
  3627. utils.ErrorLog(err.Error())
  3628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3629. return
  3630. }
  3631. this.ServeSuccessJSON(map[string]interface{}{
  3632. "patient": patient,
  3633. })
  3634. }
  3635. func (c *PatientApiController) ExecProject() {
  3636. execution_time := c.GetString("execution_time")
  3637. project_id, _ := c.GetInt64("project_id")
  3638. team_id, _ := c.GetInt64("team_id")
  3639. is_check_team, _ := c.GetInt64("is_check_team")
  3640. if len(execution_time) <= 0 {
  3641. utils.ErrorLog("execution_time")
  3642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3643. return
  3644. }
  3645. timeLayout2 := "2006-01-02 15:04:05"
  3646. loc, _ := time.LoadLocation("Local")
  3647. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3648. if errs != nil {
  3649. utils.ErrorLog(errs.Error())
  3650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3651. return
  3652. }
  3653. adminInfo := c.GetMobileAdminUserInfo()
  3654. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3655. if project.Type == 3 {
  3656. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  3657. if good.IsUser != 1 {
  3658. //查询开关是否开启
  3659. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  3660. //开关已经开启
  3661. if stockSetting.IsType == 1 {
  3662. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  3663. scheduleDateStart := theTime.Format("2006-01-02")
  3664. timeLayout3 := "2006-01-02"
  3665. loc, _ := time.LoadLocation("Local")
  3666. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  3667. //查询该耗材是否已经出库
  3668. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  3669. if auto.ID == 0 {
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  3671. return
  3672. }
  3673. }
  3674. }
  3675. if good.IsUser == 1 && good.IsWarehouse == 1 {
  3676. //查询开关是否开启
  3677. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  3678. //开关已经开启
  3679. if stockSetting.IsType == 1 {
  3680. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  3681. scheduleDateStart := theTime.Format("2006-01-02")
  3682. timeLayout3 := "2006-01-02"
  3683. loc, _ := time.LoadLocation("Local")
  3684. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  3685. //查询该耗材是否已经出库
  3686. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  3687. if auto.ID == 0 {
  3688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  3689. return
  3690. }
  3691. }
  3692. }
  3693. }
  3694. if project.ExecutionState == 1 {
  3695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  3696. return
  3697. }
  3698. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  3699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3700. return
  3701. }
  3702. project.ExecutionState = 1
  3703. project.ExecutionStaff = adminInfo.AdminUser.Id
  3704. project.ExecutionTime = theTime.Unix()
  3705. if team_id == 0 {
  3706. err := service.SaveHisProject(&project)
  3707. if err == nil {
  3708. c.ServeSuccessJSON(map[string]interface{}{
  3709. "project": project,
  3710. })
  3711. } else {
  3712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3713. return
  3714. }
  3715. } else {
  3716. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3717. err := service.SaveHisProject(&project)
  3718. if err == nil {
  3719. c.ServeSuccessJSON(map[string]interface{}{
  3720. "project": project,
  3721. })
  3722. } else {
  3723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3724. return
  3725. }
  3726. } else {
  3727. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3728. var ids []int64
  3729. for _, items := range ps {
  3730. ids = append(ids, items.ID)
  3731. }
  3732. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  3733. if err == nil {
  3734. c.ServeSuccessJSON(map[string]interface{}{
  3735. "project": project,
  3736. })
  3737. } else {
  3738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3739. return
  3740. }
  3741. }
  3742. }
  3743. }
  3744. func (c *PatientApiController) CheckProject() {
  3745. adminInfo := c.GetMobileAdminUserInfo()
  3746. project_id, _ := c.GetInt64("project_id")
  3747. team_id, _ := c.GetInt64("team_id")
  3748. is_check_team, _ := c.GetInt64("is_check_team")
  3749. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3750. if project.CheckState == 1 {
  3751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3752. return
  3753. }
  3754. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  3755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3756. return
  3757. }
  3758. project.Checker = adminInfo.AdminUser.Id
  3759. project.CheckTime = time.Now().Unix()
  3760. project.CheckState = 1
  3761. if team_id == 0 {
  3762. err := service.SaveHisProject(&project)
  3763. if err == nil {
  3764. c.ServeSuccessJSON(map[string]interface{}{
  3765. "msg": "ok",
  3766. "project": project,
  3767. })
  3768. } else {
  3769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3770. return
  3771. }
  3772. } else {
  3773. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3774. err := service.SaveHisProject(&project)
  3775. if err == nil {
  3776. c.ServeSuccessJSON(map[string]interface{}{
  3777. "msg": "ok",
  3778. "project": project,
  3779. })
  3780. } else {
  3781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3782. return
  3783. }
  3784. } else {
  3785. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3786. var ids []int64
  3787. for _, items := range ps {
  3788. ids = append(ids, items.ID)
  3789. }
  3790. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  3791. if err == nil {
  3792. c.ServeSuccessJSON(map[string]interface{}{
  3793. "project": project,
  3794. })
  3795. } else {
  3796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3797. return
  3798. }
  3799. }
  3800. }
  3801. }