patient_api_controller.go 166KB

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