dialysis_api_controller.go 227KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145
  1. package controllers
  2. import (
  3. "XT_New/models"
  4. "XT_New/service"
  5. "XT_New/utils"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/jinzhu/gorm"
  9. "math"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  41. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  42. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  43. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  44. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  45. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  46. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  47. }
  48. func (c *DialysisApiController) PostPrescription() {
  49. patient, _ := c.GetInt64("patient", 0)
  50. recordDateStr := c.GetString("record_date")
  51. if patient <= 0 {
  52. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  53. return
  54. }
  55. adminUserInfo := c.GetAdminUserInfo()
  56. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  57. if patientInfo.ID == 0 {
  58. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  59. return
  60. }
  61. if len(recordDateStr) == 0 {
  62. recordDateStr = time.Now().Format("2006-01-02")
  63. }
  64. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  65. if parseDateErr != nil {
  66. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  67. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  68. return
  69. }
  70. mode_id, _ := c.GetInt64("mode_id", 0)
  71. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  72. dialyzer, _ := c.GetInt64("dialyzer", 0)
  73. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  74. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  75. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  76. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  77. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  78. replacement_way, _ := c.GetInt64("replacement_way", 0)
  79. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  80. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  81. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  82. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  83. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  84. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  85. kalium, _ := c.GetFloat("kalium", 0)
  86. sodium, _ := c.GetFloat("sodium", 0)
  87. replacement_total, _ := c.GetFloat("replacement_total", 0)
  88. calcium, _ := c.GetFloat("calcium", 0)
  89. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  90. glucose, _ := c.GetFloat("glucose", 0)
  91. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  92. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  93. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  94. conductivity, _ := c.GetFloat("conductivity", 0)
  95. remark := c.GetString("remark")
  96. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  97. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  98. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  99. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  100. body_fluid, _ := c.GetInt64("body_fluid", 0)
  101. special_medicine, _ := c.GetInt64("special_medicine", 0)
  102. special_medicine_other := c.GetString("special_medicine_other")
  103. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  104. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  105. blood_access, _ := c.GetInt64("blood_access", 0)
  106. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  107. body_fluid_other := c.GetString("body_fluid_other")
  108. target_ktv, _ := c.GetFloat("target_ktv", 0)
  109. niprocart, _ := c.GetInt64("niprocart", 0)
  110. jms, _ := c.GetInt64("jms", 0)
  111. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  112. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  113. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  114. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  115. filtryzer, _ := c.GetInt64("filtryzer", 0)
  116. dialyzers, _ := c.GetInt64("dialyzers", 0)
  117. injector, _ := c.GetInt64("injector", 0)
  118. bloodlines, _ := c.GetInt64("bloodlines", 0)
  119. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  120. safe_package, _ := c.GetInt64("package", 0)
  121. a_liquid, _ := c.GetInt64("a_liquid", 0)
  122. preImpules, _ := c.GetFloat("pre_impulse", 0)
  123. fmt.Println("========================================================", preImpules)
  124. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  125. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  126. // var prescription_doctor int64
  127. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  128. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  129. //if template.TemplateId == 2 || template.TemplateId == 6 {
  130. // if appRole.UserType == 3 {
  131. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  132. // if getPermissionErr != nil {
  133. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  134. // return
  135. // } else if headNursePermission == nil {
  136. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  137. // return
  138. // }
  139. // }
  140. //}
  141. prescription := models.DialysisPrescription{
  142. UserOrgId: adminUserInfo.CurrentOrgId,
  143. PatientId: patient,
  144. RecordDate: recordDate.Unix(),
  145. ModeId: mode_id,
  146. DialysisDuration: dialysis_duration,
  147. Dialyzer: dialyzer,
  148. ReplacementTotal: replacement_total,
  149. PerfusionApparatus: perfusion_apparatus,
  150. BloodFlowVolume: blood_flow_volume,
  151. DewaterAmount: dewater_amount,
  152. DisplaceLiqui: displace_liqui,
  153. ReplacementWay: replacement_way,
  154. Anticoagulant: anticoagulant,
  155. AnticoagulantShouji: anticoagulant_shouji,
  156. AnticoagulantWeichi: anticoagulant_weichi,
  157. AnticoagulantZongliang: anticoagulant_zongliang,
  158. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  159. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  160. Kalium: kalium,
  161. Sodium: sodium,
  162. Calcium: calcium,
  163. Bicarbonate: bicarbonate,
  164. Glucose: glucose,
  165. // DryWeight: dry_weight,
  166. DialysateFlow: dialysate_flow,
  167. DialysateTemperature: dialysate_temperature,
  168. Conductivity: conductivity,
  169. Remark: remark,
  170. Status: 1,
  171. CreatedTime: time.Now().Unix(),
  172. UpdatedTime: time.Now().Unix(),
  173. DialysisDurationMinute: dialysisDurationMinute,
  174. DialysisDurationHour: dialysisDurationHour,
  175. TargetUltrafiltration: targetUltrafiltration,
  176. DialysateFormulation: dialysateFormulation,
  177. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  178. BodyFluid: body_fluid,
  179. SpecialMedicine: special_medicine,
  180. SpecialMedicineOther: special_medicine_other,
  181. DisplaceLiquiPart: displace_liqui_part,
  182. DisplaceLiquiValue: displace_liqui_value,
  183. BloodAccess: blood_access,
  184. Ultrafiltration: ultrafiltration,
  185. BodyFluidOther: body_fluid_other,
  186. TargetKtv: target_ktv,
  187. Niprocart: niprocart,
  188. Jms: jms,
  189. FistulaNeedleSet: fistula_needle_set,
  190. FistulaNeedleSet16: fistula_needle_set_16,
  191. Hemoperfusion: hemoperfusion,
  192. DialyserSterilised: dialyser_sterilised,
  193. Filtryzer: filtryzer,
  194. Dialyzers: dialyzers,
  195. Injector: injector,
  196. Bloodlines: bloodlines,
  197. TubingHemodialysis: tubing_hemodialysis,
  198. Package: safe_package,
  199. ALiquid: a_liquid,
  200. PreImpulse: preImpules,
  201. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  202. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  203. }
  204. if appRole.UserType == 2 || appRole.UserType == 1 {
  205. prescription.PrescriptionDoctor = appRole.AdminUserId
  206. }
  207. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  208. if dialysisPrescription.ID == 0 { //新增
  209. if mode_id > 0 {
  210. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  211. }
  212. prescription.Creater = adminUserInfo.AdminUser.Id
  213. err := service.AddSigleRecord(&prescription)
  214. if err == nil {
  215. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  216. if updateErr != nil {
  217. utils.ErrorLog("%v", updateErr)
  218. }
  219. c.ServeSuccessJSON(map[string]interface{}{
  220. "prescription": &prescription,
  221. })
  222. } else {
  223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  224. }
  225. } else { //修改
  226. if mode_id > 0 {
  227. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  228. }
  229. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  230. //if template.TemplateId == 1 {
  231. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  232. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  233. // if getPermissionErr != nil {
  234. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  235. // return
  236. // } else if headNursePermission == nil {
  237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  238. // return
  239. // }
  240. // }
  241. //}
  242. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  243. if record.IsOpen == 1 {
  244. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  245. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  246. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  247. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  248. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  249. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  250. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  251. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  252. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  253. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  254. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  255. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  256. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  257. err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  258. if err == nil {
  259. if order.ID > 0 {
  260. if dialysisPrescription.Niprocart != niprocart {
  261. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  262. //1.用上机透析日期查出当天的订单
  263. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  264. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  265. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  266. //判断前端更改后的商品id的出库记录在数据库中是否存在
  267. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  268. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  269. warehouseOutInfo := &models.WarehouseOutInfo{
  270. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  271. WarehouseOutId: out.ID,
  272. Count: 1,
  273. Status: 1,
  274. Ctime: time.Now().Unix(),
  275. Remark: "",
  276. OrgId: adminUserInfo.CurrentOrgId,
  277. Type: 1,
  278. Manufacturer: 0,
  279. Dealer: 0,
  280. IsSys: 1,
  281. SysRecordTime: order.StartTime,
  282. }
  283. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
  284. warehouseOutInfo.Price = stockInInfo.Price
  285. warehouseOutInfo.GoodId = niprocart
  286. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  287. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  288. if err == nil {
  289. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  290. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  291. if err == gorm.ErrRecordNotFound {
  292. details := &models.AutomaticReduceDetail{
  293. WarehouseOutId: warehouseOutInfo.ID,
  294. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  295. PatientId: patient,
  296. Ctime: time.Now().Unix(),
  297. Mtime: time.Now().Unix(),
  298. Status: 1,
  299. RecordTime: order.StartTime,
  300. OrgId: adminUserInfo.CurrentOrgId,
  301. GoodId: niprocart,
  302. GoodTypeId: niprocart_good_type_id,
  303. }
  304. service.AddSigleAutoReduceRecordInfo(details)
  305. } else if err == nil {
  306. if user.ID > 0 {
  307. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
  308. }
  309. }
  310. }
  311. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  312. if newOut.ID > 0 {
  313. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  314. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  315. if err == gorm.ErrRecordNotFound {
  316. details := &models.AutomaticReduceDetail{
  317. WarehouseOutId: newOut.ID,
  318. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  319. PatientId: patient,
  320. Ctime: time.Now().Unix(),
  321. Mtime: time.Now().Unix(),
  322. Status: 1,
  323. RecordTime: order.StartTime,
  324. OrgId: adminUserInfo.CurrentOrgId,
  325. GoodId: niprocart,
  326. GoodTypeId: niprocart_good_type_id,
  327. }
  328. service.AddSigleAutoReduceRecordInfo(details)
  329. } else if err == nil {
  330. if user.ID > 0 {
  331. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
  332. }
  333. }
  334. }
  335. }
  336. }
  337. if dialysisPrescription.Jms != jms {
  338. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  339. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  340. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  341. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  342. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  343. //判断前端更改后的商品id的出库记录在数据库中是否存在
  344. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  345. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  346. warehouseOutInfo := &models.WarehouseOutInfo{
  347. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  348. WarehouseOutId: out.ID,
  349. Count: 1,
  350. Status: 1,
  351. Ctime: time.Now().Unix(),
  352. Remark: "",
  353. OrgId: adminUserInfo.CurrentOrgId,
  354. Type: 1,
  355. Manufacturer: 0,
  356. Dealer: 0,
  357. IsSys: 1,
  358. SysRecordTime: order.StartTime,
  359. }
  360. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
  361. warehouseOutInfo.Price = stockInInfo.Price
  362. warehouseOutInfo.GoodId = jms
  363. warehouseOutInfo.GoodTypeId = jms_good_type_id
  364. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  365. if err == nil {
  366. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  367. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  368. if err == gorm.ErrRecordNotFound {
  369. details := &models.AutomaticReduceDetail{
  370. WarehouseOutId: warehouseOutInfo.ID,
  371. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  372. PatientId: patient,
  373. Ctime: time.Now().Unix(),
  374. Mtime: time.Now().Unix(),
  375. Status: 1,
  376. RecordTime: order.StartTime,
  377. OrgId: adminUserInfo.CurrentOrgId,
  378. GoodId: jms,
  379. GoodTypeId: jms_good_type_id,
  380. }
  381. service.AddSigleAutoReduceRecordInfo(details)
  382. } else if err == nil {
  383. if user.ID > 0 {
  384. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
  385. }
  386. }
  387. }
  388. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  389. if newOut.ID > 0 {
  390. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  391. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  392. if err == gorm.ErrRecordNotFound {
  393. details := &models.AutomaticReduceDetail{
  394. WarehouseOutId: newOut.ID,
  395. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  396. PatientId: patient,
  397. Ctime: time.Now().Unix(),
  398. Mtime: time.Now().Unix(),
  399. Status: 1,
  400. RecordTime: order.StartTime,
  401. OrgId: adminUserInfo.CurrentOrgId,
  402. GoodId: jms,
  403. GoodTypeId: jms_good_type_id,
  404. }
  405. service.AddSigleAutoReduceRecordInfo(details)
  406. } else if err == nil {
  407. if user.ID > 0 {
  408. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
  409. }
  410. }
  411. }
  412. }
  413. }
  414. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  415. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  416. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  417. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  418. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  419. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  420. //判断前端更改后的商品id的出库记录在数据库中是否存在
  421. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  422. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  423. warehouseOutInfo := &models.WarehouseOutInfo{
  424. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  425. WarehouseOutId: out.ID,
  426. Count: 1,
  427. Status: 1,
  428. Ctime: time.Now().Unix(),
  429. Remark: "",
  430. OrgId: adminUserInfo.CurrentOrgId,
  431. Type: 1,
  432. Manufacturer: 0,
  433. Dealer: 0,
  434. IsSys: 1,
  435. SysRecordTime: order.StartTime,
  436. }
  437. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
  438. warehouseOutInfo.Price = stockInInfo.Price
  439. warehouseOutInfo.GoodId = fistula_needle_set
  440. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  441. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  442. if err == nil {
  443. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  444. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  445. if err == gorm.ErrRecordNotFound {
  446. details := &models.AutomaticReduceDetail{
  447. WarehouseOutId: warehouseOutInfo.ID,
  448. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  449. PatientId: patient,
  450. Ctime: time.Now().Unix(),
  451. Mtime: time.Now().Unix(),
  452. Status: 1,
  453. RecordTime: order.StartTime,
  454. OrgId: adminUserInfo.CurrentOrgId,
  455. GoodId: fistula_needle_set,
  456. GoodTypeId: fistula_needle_set_good_type_id,
  457. }
  458. service.AddSigleAutoReduceRecordInfo(details)
  459. } else if err == nil {
  460. if user.ID > 0 {
  461. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  462. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
  463. }
  464. }
  465. }
  466. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  467. if newOut.ID > 0 {
  468. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  469. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  470. if err == gorm.ErrRecordNotFound {
  471. details := &models.AutomaticReduceDetail{
  472. WarehouseOutId: newOut.ID,
  473. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  474. PatientId: patient,
  475. Ctime: time.Now().Unix(),
  476. Mtime: time.Now().Unix(),
  477. Status: 1,
  478. RecordTime: order.StartTime,
  479. OrgId: adminUserInfo.CurrentOrgId,
  480. GoodId: fistula_needle_set,
  481. GoodTypeId: fistula_needle_set_good_type_id,
  482. }
  483. service.AddSigleAutoReduceRecordInfo(details)
  484. } else if err == nil {
  485. if user.ID > 0 {
  486. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  487. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
  488. }
  489. }
  490. }
  491. }
  492. }
  493. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  494. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  495. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  496. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  497. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  498. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  499. //判断前端更改后的商品id的出库记录在数据库中是否存在
  500. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  501. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  502. warehouseOutInfo := &models.WarehouseOutInfo{
  503. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  504. WarehouseOutId: out.ID,
  505. Count: 1,
  506. Status: 1,
  507. Ctime: time.Now().Unix(),
  508. Remark: "",
  509. OrgId: adminUserInfo.CurrentOrgId,
  510. Type: 1,
  511. Manufacturer: 0,
  512. Dealer: 0,
  513. IsSys: 1,
  514. SysRecordTime: order.StartTime,
  515. }
  516. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
  517. warehouseOutInfo.Price = stockInInfo.Price
  518. warehouseOutInfo.GoodId = fistula_needle_set_16
  519. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  520. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  521. if err == nil {
  522. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  523. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  524. if err == gorm.ErrRecordNotFound {
  525. details := &models.AutomaticReduceDetail{
  526. WarehouseOutId: warehouseOutInfo.ID,
  527. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  528. PatientId: patient,
  529. Ctime: time.Now().Unix(),
  530. Mtime: time.Now().Unix(),
  531. Status: 1,
  532. RecordTime: order.StartTime,
  533. OrgId: adminUserInfo.CurrentOrgId,
  534. GoodId: fistula_needle_set_16,
  535. GoodTypeId: fistula_needle_set_16_good_type_id,
  536. }
  537. service.AddSigleAutoReduceRecordInfo(details)
  538. } else if err == nil {
  539. if user.ID > 0 {
  540. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
  541. }
  542. }
  543. }
  544. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  545. if newOut.ID > 0 {
  546. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  547. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  548. if err == gorm.ErrRecordNotFound {
  549. details := &models.AutomaticReduceDetail{
  550. WarehouseOutId: newOut.ID,
  551. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  552. PatientId: patient,
  553. Ctime: time.Now().Unix(),
  554. Mtime: time.Now().Unix(),
  555. Status: 1,
  556. RecordTime: order.StartTime,
  557. OrgId: adminUserInfo.CurrentOrgId,
  558. GoodId: fistula_needle_set_16,
  559. GoodTypeId: fistula_needle_set_16_good_type_id,
  560. }
  561. service.AddSigleAutoReduceRecordInfo(details)
  562. } else if err == nil {
  563. if user.ID > 0 {
  564. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
  565. }
  566. }
  567. }
  568. }
  569. }
  570. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  571. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  572. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  573. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  574. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  575. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  576. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  577. //判断前端更改后的商品id的出库记录在数据库中是否存在
  578. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  579. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  580. warehouseOutInfo := &models.WarehouseOutInfo{
  581. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  582. WarehouseOutId: out.ID,
  583. Count: 1,
  584. Status: 1,
  585. Ctime: time.Now().Unix(),
  586. Remark: "",
  587. OrgId: adminUserInfo.CurrentOrgId,
  588. Type: 1,
  589. Manufacturer: 0,
  590. Dealer: 0,
  591. IsSys: 1,
  592. SysRecordTime: order.StartTime,
  593. }
  594. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
  595. warehouseOutInfo.Price = stockInInfo.Price
  596. warehouseOutInfo.GoodId = hemoperfusion
  597. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  598. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  599. if err == nil {
  600. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  601. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  602. if err == gorm.ErrRecordNotFound {
  603. details := &models.AutomaticReduceDetail{
  604. WarehouseOutId: warehouseOutInfo.ID,
  605. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  606. PatientId: patient,
  607. Ctime: time.Now().Unix(),
  608. Mtime: time.Now().Unix(),
  609. Status: 1,
  610. RecordTime: order.StartTime,
  611. OrgId: adminUserInfo.CurrentOrgId,
  612. GoodId: hemoperfusion,
  613. GoodTypeId: hemoperfusion_good_type_id,
  614. }
  615. service.AddSigleAutoReduceRecordInfo(details)
  616. } else if err == nil {
  617. if user.ID > 0 {
  618. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
  619. }
  620. }
  621. }
  622. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  623. if newOut.ID > 0 {
  624. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  625. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  626. if err == gorm.ErrRecordNotFound {
  627. details := &models.AutomaticReduceDetail{
  628. WarehouseOutId: newOut.ID,
  629. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  630. PatientId: patient,
  631. Ctime: time.Now().Unix(),
  632. Mtime: time.Now().Unix(),
  633. Status: 1,
  634. RecordTime: order.StartTime,
  635. OrgId: adminUserInfo.CurrentOrgId,
  636. GoodId: hemoperfusion,
  637. GoodTypeId: hemoperfusion_good_type_id,
  638. }
  639. service.AddSigleAutoReduceRecordInfo(details)
  640. } else if err == nil {
  641. if user.ID > 0 {
  642. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
  643. }
  644. }
  645. }
  646. }
  647. }
  648. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  649. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
  650. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  651. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  652. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  653. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  654. //判断前端更改后的商品id的出库记录在数据库中是否存在
  655. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  656. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  657. warehouseOutInfo := &models.WarehouseOutInfo{
  658. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  659. WarehouseOutId: out.WarehouseOutId,
  660. Count: 1,
  661. Status: 1,
  662. Ctime: time.Now().Unix(),
  663. Remark: "",
  664. OrgId: adminUserInfo.CurrentOrgId,
  665. Type: 1,
  666. Manufacturer: 0,
  667. Dealer: 0,
  668. IsSys: 1,
  669. SysRecordTime: order.StartTime,
  670. }
  671. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
  672. warehouseOutInfo.Price = stockInInfo.Price
  673. warehouseOutInfo.GoodId = dialyser_sterilised
  674. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  675. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  676. if err == nil {
  677. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  678. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  679. if err == gorm.ErrRecordNotFound {
  680. details := &models.AutomaticReduceDetail{
  681. WarehouseOutId: warehouseOutInfo.ID,
  682. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  683. PatientId: patient,
  684. Ctime: time.Now().Unix(),
  685. Mtime: time.Now().Unix(),
  686. Status: 1,
  687. RecordTime: order.StartTime,
  688. OrgId: adminUserInfo.CurrentOrgId,
  689. GoodId: dialyser_sterilised,
  690. GoodTypeId: dialyser_sterilised_good_type_id,
  691. }
  692. service.AddSigleAutoReduceRecordInfo(details)
  693. } else if err == nil {
  694. if user.ID > 0 {
  695. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  696. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
  697. }
  698. }
  699. }
  700. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  701. if newOut.ID > 0 {
  702. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  703. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  704. if err == gorm.ErrRecordNotFound {
  705. details := &models.AutomaticReduceDetail{
  706. WarehouseOutId: newOut.ID,
  707. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  708. PatientId: patient,
  709. Ctime: time.Now().Unix(),
  710. Mtime: time.Now().Unix(),
  711. Status: 1,
  712. RecordTime: order.StartTime,
  713. OrgId: adminUserInfo.CurrentOrgId,
  714. GoodId: dialyser_sterilised,
  715. GoodTypeId: dialyser_sterilised_good_type_id,
  716. }
  717. service.AddSigleAutoReduceRecordInfo(details)
  718. } else if err == nil {
  719. if user.ID > 0 {
  720. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
  721. }
  722. }
  723. }
  724. }
  725. }
  726. if dialysisPrescription.Filtryzer != filtryzer {
  727. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  728. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  729. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  730. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  731. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  732. //判断前端更改后的商品id的出库记录在数据库中是否存在
  733. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  734. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  735. warehouseOutInfo := &models.WarehouseOutInfo{
  736. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  737. WarehouseOutId: out.ID,
  738. Count: 1,
  739. Status: 1,
  740. Ctime: time.Now().Unix(),
  741. Remark: "",
  742. OrgId: adminUserInfo.CurrentOrgId,
  743. Type: 1,
  744. Manufacturer: 0,
  745. Dealer: 0,
  746. IsSys: 1,
  747. SysRecordTime: order.StartTime,
  748. }
  749. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
  750. warehouseOutInfo.Price = stockInInfo.Price
  751. warehouseOutInfo.GoodId = filtryzer
  752. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  753. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  754. if err == nil {
  755. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  756. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  757. if err == gorm.ErrRecordNotFound {
  758. details := &models.AutomaticReduceDetail{
  759. WarehouseOutId: warehouseOutInfo.ID,
  760. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  761. PatientId: patient,
  762. Ctime: time.Now().Unix(),
  763. Mtime: time.Now().Unix(),
  764. Status: 1,
  765. RecordTime: order.StartTime,
  766. OrgId: adminUserInfo.CurrentOrgId,
  767. GoodId: filtryzer,
  768. GoodTypeId: filtryzer_good_type_id,
  769. }
  770. service.AddSigleAutoReduceRecordInfo(details)
  771. } else if err == nil {
  772. if user.ID > 0 {
  773. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
  774. }
  775. }
  776. }
  777. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  778. if newOut.ID > 0 {
  779. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  780. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  781. if err == gorm.ErrRecordNotFound {
  782. details := &models.AutomaticReduceDetail{
  783. WarehouseOutId: newOut.ID,
  784. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  785. PatientId: patient,
  786. Ctime: time.Now().Unix(),
  787. Mtime: time.Now().Unix(),
  788. Status: 1,
  789. RecordTime: order.StartTime,
  790. OrgId: adminUserInfo.CurrentOrgId,
  791. GoodId: filtryzer,
  792. GoodTypeId: filtryzer_good_type_id,
  793. }
  794. service.AddSigleAutoReduceRecordInfo(details)
  795. } else if err == nil {
  796. if user.ID > 0 {
  797. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
  798. }
  799. }
  800. }
  801. }
  802. }
  803. if dialysisPrescription.Dialyzers != dialyzers {
  804. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  805. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  806. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  807. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  808. //判断前端更改后的商品id的出库记录在数据库中是否存在
  809. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  810. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  811. warehouseOutInfo := &models.WarehouseOutInfo{
  812. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  813. WarehouseOutId: out.ID,
  814. Count: 1,
  815. Status: 1,
  816. Ctime: time.Now().Unix(),
  817. Remark: "",
  818. OrgId: adminUserInfo.CurrentOrgId,
  819. Type: 1,
  820. Manufacturer: 0,
  821. Dealer: 0,
  822. IsSys: 1,
  823. SysRecordTime: order.StartTime,
  824. }
  825. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
  826. warehouseOutInfo.Price = stockInInfo.Price
  827. warehouseOutInfo.GoodId = dialyzers
  828. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  829. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  830. if err == nil {
  831. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  832. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  833. if err == gorm.ErrRecordNotFound {
  834. details := &models.AutomaticReduceDetail{
  835. WarehouseOutId: warehouseOutInfo.ID,
  836. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  837. PatientId: patient,
  838. Ctime: time.Now().Unix(),
  839. Mtime: time.Now().Unix(),
  840. Status: 1,
  841. RecordTime: order.StartTime,
  842. OrgId: adminUserInfo.CurrentOrgId,
  843. GoodId: dialyzers,
  844. GoodTypeId: dialyzers_good_type_id,
  845. }
  846. service.AddSigleAutoReduceRecordInfo(details)
  847. } else if err == nil {
  848. if user.ID > 0 {
  849. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
  850. }
  851. }
  852. }
  853. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  854. if newOut.ID > 0 {
  855. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  856. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  857. if err == gorm.ErrRecordNotFound {
  858. details := &models.AutomaticReduceDetail{
  859. WarehouseOutId: newOut.ID,
  860. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  861. PatientId: patient,
  862. Ctime: time.Now().Unix(),
  863. Mtime: time.Now().Unix(),
  864. Status: 1,
  865. RecordTime: order.StartTime,
  866. OrgId: adminUserInfo.CurrentOrgId,
  867. GoodId: dialyzers,
  868. GoodTypeId: dialyzers_good_type_id,
  869. }
  870. service.AddSigleAutoReduceRecordInfo(details)
  871. } else if err == nil {
  872. if user.ID > 0 {
  873. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
  874. }
  875. }
  876. }
  877. }
  878. }
  879. if dialysisPrescription.Injector != injector {
  880. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  881. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  882. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  883. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  884. //判断前端更改后的商品id的出库记录在数据库中是否存在
  885. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  886. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  887. warehouseOutInfo := &models.WarehouseOutInfo{
  888. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  889. WarehouseOutId: out.ID,
  890. Count: 1,
  891. Status: 1,
  892. Ctime: time.Now().Unix(),
  893. Remark: "",
  894. OrgId: adminUserInfo.CurrentOrgId,
  895. Type: 1,
  896. Manufacturer: 0,
  897. Dealer: 0,
  898. IsSys: 1,
  899. SysRecordTime: order.StartTime,
  900. }
  901. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
  902. warehouseOutInfo.Price = stockInInfo.Price
  903. warehouseOutInfo.GoodId = injector
  904. warehouseOutInfo.GoodTypeId = injector_good_type_id
  905. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  906. if err == nil {
  907. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  908. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  909. if err == gorm.ErrRecordNotFound {
  910. details := &models.AutomaticReduceDetail{
  911. WarehouseOutId: warehouseOutInfo.ID,
  912. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  913. PatientId: patient,
  914. Ctime: time.Now().Unix(),
  915. Mtime: time.Now().Unix(),
  916. Status: 1,
  917. RecordTime: order.StartTime,
  918. OrgId: adminUserInfo.CurrentOrgId,
  919. GoodId: injector,
  920. GoodTypeId: injector_good_type_id,
  921. }
  922. service.AddSigleAutoReduceRecordInfo(details)
  923. } else if err == nil {
  924. if user.ID > 0 {
  925. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
  926. }
  927. }
  928. }
  929. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  930. if newOut.ID > 0 {
  931. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  932. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  933. if err == gorm.ErrRecordNotFound {
  934. details := &models.AutomaticReduceDetail{
  935. WarehouseOutId: newOut.ID,
  936. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  937. PatientId: patient,
  938. Ctime: time.Now().Unix(),
  939. Mtime: time.Now().Unix(),
  940. Status: 1,
  941. RecordTime: order.StartTime,
  942. OrgId: adminUserInfo.CurrentOrgId,
  943. GoodId: injector,
  944. GoodTypeId: injector_good_type_id,
  945. }
  946. service.AddSigleAutoReduceRecordInfo(details)
  947. } else if err == nil {
  948. if user.ID > 0 {
  949. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
  950. }
  951. }
  952. }
  953. }
  954. }
  955. if dialysisPrescription.Bloodlines != bloodlines {
  956. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  957. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  958. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  959. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  960. //判断前端更改后的商品id的出库记录在数据库中是否存在
  961. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  962. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  963. warehouseOutInfo := &models.WarehouseOutInfo{
  964. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  965. WarehouseOutId: out.ID,
  966. Count: 1,
  967. Status: 1,
  968. Ctime: time.Now().Unix(),
  969. Remark: "",
  970. OrgId: adminUserInfo.CurrentOrgId,
  971. Type: 1,
  972. Manufacturer: 0,
  973. Dealer: 0,
  974. IsSys: 1,
  975. SysRecordTime: order.StartTime,
  976. }
  977. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
  978. warehouseOutInfo.Price = stockInInfo.Price
  979. warehouseOutInfo.GoodId = bloodlines
  980. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  981. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  982. if err == nil {
  983. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  984. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  985. if err == gorm.ErrRecordNotFound {
  986. details := &models.AutomaticReduceDetail{
  987. WarehouseOutId: warehouseOutInfo.ID,
  988. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  989. PatientId: patient,
  990. Ctime: time.Now().Unix(),
  991. Mtime: time.Now().Unix(),
  992. Status: 1,
  993. RecordTime: order.StartTime,
  994. OrgId: adminUserInfo.CurrentOrgId,
  995. GoodId: bloodlines,
  996. GoodTypeId: bloodlines_good_type_id,
  997. }
  998. service.AddSigleAutoReduceRecordInfo(details)
  999. } else if err == nil {
  1000. if user.ID > 0 {
  1001. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
  1002. }
  1003. }
  1004. }
  1005. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1006. if newOut.ID > 0 {
  1007. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1008. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1009. if err == gorm.ErrRecordNotFound {
  1010. details := &models.AutomaticReduceDetail{
  1011. WarehouseOutId: newOut.ID,
  1012. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1013. PatientId: patient,
  1014. Ctime: time.Now().Unix(),
  1015. Mtime: time.Now().Unix(),
  1016. Status: 1,
  1017. RecordTime: order.StartTime,
  1018. OrgId: adminUserInfo.CurrentOrgId,
  1019. GoodId: bloodlines,
  1020. GoodTypeId: bloodlines_good_type_id,
  1021. }
  1022. service.AddSigleAutoReduceRecordInfo(details)
  1023. } else if err == nil {
  1024. if user.ID > 0 {
  1025. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
  1026. }
  1027. }
  1028. }
  1029. }
  1030. }
  1031. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1032. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1033. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1034. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1035. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1036. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1037. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1038. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1039. warehouseOutInfo := &models.WarehouseOutInfo{
  1040. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1041. WarehouseOutId: out.ID,
  1042. Count: 1,
  1043. Status: 1,
  1044. Ctime: time.Now().Unix(),
  1045. Remark: "",
  1046. OrgId: adminUserInfo.CurrentOrgId,
  1047. Type: 1,
  1048. Manufacturer: 0,
  1049. Dealer: 0,
  1050. IsSys: 1,
  1051. SysRecordTime: order.StartTime,
  1052. }
  1053. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
  1054. warehouseOutInfo.Price = stockInInfo.Price
  1055. warehouseOutInfo.GoodId = tubing_hemodialysis
  1056. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1057. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1058. if err == nil {
  1059. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1060. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1061. if err == gorm.ErrRecordNotFound {
  1062. details := &models.AutomaticReduceDetail{
  1063. WarehouseOutId: warehouseOutInfo.ID,
  1064. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1065. PatientId: patient,
  1066. Ctime: time.Now().Unix(),
  1067. Mtime: time.Now().Unix(),
  1068. Status: 1,
  1069. RecordTime: order.StartTime,
  1070. OrgId: adminUserInfo.CurrentOrgId,
  1071. GoodId: tubing_hemodialysis,
  1072. GoodTypeId: tubingHemodialysis_good_type_id,
  1073. }
  1074. service.AddSigleAutoReduceRecordInfo(details)
  1075. } else if err == nil {
  1076. if user.ID > 0 {
  1077. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
  1078. }
  1079. }
  1080. }
  1081. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1082. if newOut.ID > 0 {
  1083. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1084. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1085. if err == gorm.ErrRecordNotFound {
  1086. details := &models.AutomaticReduceDetail{
  1087. WarehouseOutId: newOut.ID,
  1088. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1089. PatientId: patient,
  1090. Ctime: time.Now().Unix(),
  1091. Mtime: time.Now().Unix(),
  1092. Status: 1,
  1093. RecordTime: order.StartTime,
  1094. OrgId: adminUserInfo.CurrentOrgId,
  1095. GoodId: tubing_hemodialysis,
  1096. GoodTypeId: tubingHemodialysis_good_type_id,
  1097. }
  1098. service.AddSigleAutoReduceRecordInfo(details)
  1099. } else if err == nil {
  1100. if user.ID > 0 {
  1101. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
  1102. }
  1103. }
  1104. }
  1105. }
  1106. }
  1107. if dialysisPrescription.Package != safe_package {
  1108. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1109. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1110. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1111. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1112. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1113. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1114. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1115. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1116. warehouseOutInfo := &models.WarehouseOutInfo{
  1117. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1118. WarehouseOutId: out.ID,
  1119. Count: 1,
  1120. Status: 1,
  1121. Ctime: time.Now().Unix(),
  1122. Remark: "",
  1123. OrgId: adminUserInfo.CurrentOrgId,
  1124. Type: 1,
  1125. Manufacturer: 0,
  1126. Dealer: 0,
  1127. IsSys: 1,
  1128. SysRecordTime: order.StartTime,
  1129. }
  1130. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
  1131. warehouseOutInfo.Price = stockInInfo.Price
  1132. warehouseOutInfo.GoodId = safe_package
  1133. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1134. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1135. if err == nil {
  1136. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1137. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1138. if err == gorm.ErrRecordNotFound {
  1139. details := &models.AutomaticReduceDetail{
  1140. WarehouseOutId: warehouseOutInfo.ID,
  1141. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1142. PatientId: patient,
  1143. Ctime: time.Now().Unix(),
  1144. Mtime: time.Now().Unix(),
  1145. Status: 1,
  1146. RecordTime: order.StartTime,
  1147. OrgId: adminUserInfo.CurrentOrgId,
  1148. GoodId: safe_package,
  1149. GoodTypeId: safe_package_good_type_id,
  1150. }
  1151. service.AddSigleAutoReduceRecordInfo(details)
  1152. } else if err == nil {
  1153. if user.ID > 0 {
  1154. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
  1155. }
  1156. }
  1157. }
  1158. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1159. if newOut.ID > 0 {
  1160. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1161. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1162. if err == gorm.ErrRecordNotFound {
  1163. details := &models.AutomaticReduceDetail{
  1164. WarehouseOutId: newOut.ID,
  1165. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1166. PatientId: patient,
  1167. Ctime: time.Now().Unix(),
  1168. Mtime: time.Now().Unix(),
  1169. Status: 1,
  1170. RecordTime: order.StartTime,
  1171. OrgId: adminUserInfo.CurrentOrgId,
  1172. GoodId: safe_package,
  1173. GoodTypeId: safe_package_good_type_id,
  1174. }
  1175. service.AddSigleAutoReduceRecordInfo(details)
  1176. } else if err == nil {
  1177. if user.ID > 0 {
  1178. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
  1179. }
  1180. }
  1181. }
  1182. }
  1183. }
  1184. if dialysisPrescription.ALiquid != a_liquid {
  1185. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1186. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1187. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1188. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1189. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1190. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1191. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1192. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1193. warehouseOutInfo := &models.WarehouseOutInfo{
  1194. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1195. WarehouseOutId: out.ID,
  1196. Count: 1,
  1197. Status: 1,
  1198. Ctime: time.Now().Unix(),
  1199. Remark: "",
  1200. OrgId: adminUserInfo.CurrentOrgId,
  1201. Type: 1,
  1202. Manufacturer: 0,
  1203. Dealer: 0,
  1204. IsSys: 1,
  1205. SysRecordTime: order.StartTime,
  1206. }
  1207. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
  1208. warehouseOutInfo.Price = stockInInfo.Price
  1209. warehouseOutInfo.GoodId = a_liquid
  1210. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1211. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1212. if err == nil {
  1213. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1214. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1215. if err == gorm.ErrRecordNotFound {
  1216. details := &models.AutomaticReduceDetail{
  1217. WarehouseOutId: warehouseOutInfo.ID,
  1218. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1219. PatientId: patient,
  1220. Ctime: time.Now().Unix(),
  1221. Mtime: time.Now().Unix(),
  1222. Status: 1,
  1223. RecordTime: order.StartTime,
  1224. OrgId: adminUserInfo.CurrentOrgId,
  1225. GoodId: a_liquid,
  1226. GoodTypeId: aliquid_good_type_id,
  1227. }
  1228. service.AddSigleAutoReduceRecordInfo(details)
  1229. } else if err == nil {
  1230. if user.ID > 0 {
  1231. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
  1232. }
  1233. }
  1234. }
  1235. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1236. if newOut.ID > 0 {
  1237. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1238. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1239. if err == gorm.ErrRecordNotFound {
  1240. details := &models.AutomaticReduceDetail{
  1241. WarehouseOutId: newOut.ID,
  1242. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1243. PatientId: patient,
  1244. Ctime: time.Now().Unix(),
  1245. Mtime: time.Now().Unix(),
  1246. Status: 1,
  1247. RecordTime: order.StartTime,
  1248. OrgId: adminUserInfo.CurrentOrgId,
  1249. GoodId: a_liquid,
  1250. GoodTypeId: aliquid_good_type_id,
  1251. }
  1252. service.AddSigleAutoReduceRecordInfo(details)
  1253. } else if err == nil {
  1254. if user.ID > 0 {
  1255. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
  1256. }
  1257. }
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. }
  1264. if appRole.UserType == 2 || appRole.UserType == 1 {
  1265. prescription_doctor := adminUserInfo.AdminUser.Id
  1266. prescription.PrescriptionDoctor = prescription_doctor
  1267. }
  1268. if dialysisPrescription.Creater == 0 { //体重称
  1269. prescription.Creater = adminUserInfo.AdminUser.Id
  1270. } else {
  1271. prescription.Creater = dialysisPrescription.Creater
  1272. }
  1273. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1274. prescription.UpdatedTime = time.Now().Unix()
  1275. prescription.Modifier = adminUserInfo.AdminUser.Id
  1276. prescription.ID = dialysisPrescription.ID
  1277. updateErr := service.UpDateDialysisPrescription(&prescription)
  1278. if updateErr == nil {
  1279. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  1280. if updateErr != nil {
  1281. utils.ErrorLog("%v", updateErr)
  1282. }
  1283. c.ServeSuccessJSON(map[string]interface{}{
  1284. "prescription": &prescription,
  1285. })
  1286. } else {
  1287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1288. }
  1289. }
  1290. }
  1291. func (c *DialysisApiController) PostSoulution() {
  1292. patient, _ := c.GetInt64("patient", 0)
  1293. recordDateStr := c.GetString("record_date")
  1294. if patient <= 0 {
  1295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1296. return
  1297. }
  1298. adminUserInfo := c.GetAdminUserInfo()
  1299. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1300. if patientInfo.ID == 0 {
  1301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1302. return
  1303. }
  1304. if len(recordDateStr) == 0 {
  1305. recordDateStr = time.Now().Format("2006-01-02")
  1306. }
  1307. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1308. if parseDateErr != nil {
  1309. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1311. return
  1312. }
  1313. mode_id, _ := c.GetInt64("mode_id", 0)
  1314. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1315. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1316. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1317. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1318. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1319. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1320. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1321. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1322. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1323. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1324. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1325. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1326. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1327. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1328. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1329. kalium, _ := c.GetFloat("kalium", 0)
  1330. sodium, _ := c.GetFloat("sodium", 0)
  1331. calcium, _ := c.GetFloat("calcium", 0)
  1332. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1333. glucose, _ := c.GetFloat("glucose", 0)
  1334. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1335. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1336. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1337. conductivity, _ := c.GetFloat("conductivity", 0)
  1338. remark := c.GetString("remark")
  1339. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1340. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1341. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1342. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1343. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1344. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1345. special_medicine_other := c.GetString("special_medicine_other")
  1346. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1347. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1348. blood_access, _ := c.GetInt64("blood_access", 0)
  1349. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1350. body_fluid_other := c.GetString("body_fluid_other")
  1351. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1352. niprocart, _ := c.GetInt64("niprocart", 0)
  1353. jms, _ := c.GetInt64("jms", 0)
  1354. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1355. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1356. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1357. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1358. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1359. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1360. injector, _ := c.GetInt64("injector", 0)
  1361. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1362. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1363. safe_package, _ := c.GetInt64("package", 0)
  1364. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1365. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1366. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1367. var prescription_doctor int64
  1368. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1369. if appRole.UserType == 2 || appRole.UserType == 1 {
  1370. prescription_doctor = appRole.AdminUserId
  1371. } else {
  1372. prescription_doctor = 0
  1373. }
  1374. if mode_id > 0 {
  1375. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1376. }
  1377. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1378. //
  1379. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1380. // if appRole.UserType == 3 {
  1381. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1382. // if getPermissionErr != nil {
  1383. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1384. // return
  1385. // } else if headNursePermission == nil {
  1386. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1387. // return
  1388. // }
  1389. // }
  1390. //}
  1391. prescription := models.DialysisPrescription{
  1392. UserOrgId: adminUserInfo.CurrentOrgId,
  1393. PatientId: patient,
  1394. RecordDate: recordDate.Unix(),
  1395. ModeId: mode_id,
  1396. DialysisDuration: dialysis_duration,
  1397. Dialyzer: dialyzer,
  1398. PerfusionApparatus: perfusion_apparatus,
  1399. BloodFlowVolume: blood_flow_volume,
  1400. DewaterAmount: dewater_amount,
  1401. DisplaceLiqui: displace_liqui,
  1402. ReplacementWay: replacement_way,
  1403. Anticoagulant: anticoagulant,
  1404. AnticoagulantShouji: anticoagulant_shouji,
  1405. AnticoagulantWeichi: anticoagulant_weichi,
  1406. AnticoagulantZongliang: anticoagulant_zongliang,
  1407. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1408. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1409. Kalium: kalium,
  1410. Sodium: sodium,
  1411. Calcium: calcium,
  1412. Bicarbonate: bicarbonate,
  1413. Glucose: glucose,
  1414. // DryWeight: dry_weight,
  1415. DialysateFlow: dialysate_flow,
  1416. DialysateTemperature: dialysate_temperature,
  1417. Conductivity: conductivity,
  1418. Remark: remark,
  1419. PrescriptionDoctor: prescription_doctor,
  1420. Status: 1,
  1421. CreatedTime: time.Now().Unix(),
  1422. UpdatedTime: time.Now().Unix(),
  1423. DialysisDurationMinute: dialysisDurationMinute,
  1424. DialysisDurationHour: dialysisDurationHour,
  1425. TargetUltrafiltration: targetUltrafiltration,
  1426. DialysateFormulation: dialysateFormulation,
  1427. ReplacementTotal: replacement_total,
  1428. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1429. BodyFluid: body_fluid,
  1430. SpecialMedicine: special_medicine,
  1431. SpecialMedicineOther: special_medicine_other,
  1432. DisplaceLiquiPart: displace_liqui_part,
  1433. DisplaceLiquiValue: displace_liqui_value,
  1434. BloodAccess: blood_access,
  1435. Ultrafiltration: ultrafiltration,
  1436. BodyFluidOther: body_fluid_other,
  1437. TargetKtv: target_ktv,
  1438. Niprocart: niprocart,
  1439. Jms: jms,
  1440. FistulaNeedleSet: fistula_needle_set,
  1441. FistulaNeedleSet16: fistula_needle_set_16,
  1442. Hemoperfusion: hemoperfusion,
  1443. DialyserSterilised: dialyser_sterilised,
  1444. Filtryzer: filtryzer,
  1445. Dialyzers: dialyzers,
  1446. Injector: injector,
  1447. Bloodlines: bloodlines,
  1448. TubingHemodialysis: tubing_hemodialysis,
  1449. Package: safe_package,
  1450. ALiquid: a_liquid,
  1451. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1452. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1453. }
  1454. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1455. if dialysisPrescription.ID == 0 { //新增
  1456. prescription.Creater = adminUserInfo.AdminUser.Id
  1457. } else { //修改
  1458. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1459. //if template.TemplateId == 1 {
  1460. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1461. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1462. // if getPermissionErr != nil {
  1463. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1464. // return
  1465. // } else if headNursePermission == nil {
  1466. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1467. // return
  1468. // }
  1469. // }
  1470. //}
  1471. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1472. if record.IsOpen == 1 {
  1473. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  1474. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  1475. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  1476. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  1477. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  1478. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  1479. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  1480. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  1481. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  1482. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  1483. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  1484. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  1485. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1486. err, order := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1487. if err == nil {
  1488. if order.ID > 0 {
  1489. if dialysisPrescription.Niprocart != niprocart {
  1490. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1491. //1.用上机透析日期查出当天的订单
  1492. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1493. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1494. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1495. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1496. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1497. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1498. warehouseOutInfo := &models.WarehouseOutInfo{
  1499. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1500. WarehouseOutId: out.ID,
  1501. Count: 1,
  1502. Status: 1,
  1503. Ctime: time.Now().Unix(),
  1504. Remark: "",
  1505. OrgId: adminUserInfo.CurrentOrgId,
  1506. Type: 1,
  1507. Manufacturer: 0,
  1508. Dealer: 0,
  1509. IsSys: 1,
  1510. SysRecordTime: order.StartTime,
  1511. }
  1512. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.CurrentOrgId)
  1513. warehouseOutInfo.Price = stockInInfo.Price
  1514. warehouseOutInfo.GoodId = niprocart
  1515. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1516. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1517. if err == nil {
  1518. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1519. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1520. if err == gorm.ErrRecordNotFound {
  1521. details := &models.AutomaticReduceDetail{
  1522. WarehouseOutId: warehouseOutInfo.ID,
  1523. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1524. PatientId: patient,
  1525. Ctime: time.Now().Unix(),
  1526. Mtime: time.Now().Unix(),
  1527. Status: 1,
  1528. RecordTime: order.StartTime,
  1529. OrgId: adminUserInfo.CurrentOrgId,
  1530. GoodId: niprocart,
  1531. GoodTypeId: niprocart_good_type_id,
  1532. }
  1533. service.AddSigleAutoReduceRecordInfo(details)
  1534. } else if err == nil {
  1535. if user.ID > 0 {
  1536. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, warehouseOutInfo)
  1537. }
  1538. }
  1539. }
  1540. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1541. if newOut.ID > 0 {
  1542. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1543. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1544. if err == gorm.ErrRecordNotFound {
  1545. details := &models.AutomaticReduceDetail{
  1546. WarehouseOutId: newOut.ID,
  1547. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1548. PatientId: patient,
  1549. Ctime: time.Now().Unix(),
  1550. Mtime: time.Now().Unix(),
  1551. Status: 1,
  1552. RecordTime: order.StartTime,
  1553. OrgId: adminUserInfo.CurrentOrgId,
  1554. GoodId: niprocart,
  1555. GoodTypeId: niprocart_good_type_id,
  1556. }
  1557. service.AddSigleAutoReduceRecordInfo(details)
  1558. } else if err == nil {
  1559. if user.ID > 0 {
  1560. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.CurrentOrgId, patient, niprocart, &newOut)
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. if dialysisPrescription.Jms != jms {
  1567. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1568. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1569. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1570. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1571. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1572. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1573. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1574. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1575. warehouseOutInfo := &models.WarehouseOutInfo{
  1576. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1577. WarehouseOutId: out.ID,
  1578. Count: 1,
  1579. Status: 1,
  1580. Ctime: time.Now().Unix(),
  1581. Remark: "",
  1582. OrgId: adminUserInfo.CurrentOrgId,
  1583. Type: 1,
  1584. Manufacturer: 0,
  1585. Dealer: 0,
  1586. IsSys: 1,
  1587. SysRecordTime: order.StartTime,
  1588. }
  1589. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.CurrentOrgId)
  1590. warehouseOutInfo.Price = stockInInfo.Price
  1591. warehouseOutInfo.GoodId = jms
  1592. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1593. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1594. if err == nil {
  1595. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1596. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1597. if err == gorm.ErrRecordNotFound {
  1598. details := &models.AutomaticReduceDetail{
  1599. WarehouseOutId: warehouseOutInfo.ID,
  1600. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1601. PatientId: patient,
  1602. Ctime: time.Now().Unix(),
  1603. Mtime: time.Now().Unix(),
  1604. Status: 1,
  1605. RecordTime: order.StartTime,
  1606. OrgId: adminUserInfo.CurrentOrgId,
  1607. GoodId: jms,
  1608. GoodTypeId: jms_good_type_id,
  1609. }
  1610. service.AddSigleAutoReduceRecordInfo(details)
  1611. } else if err == nil {
  1612. if user.ID > 0 {
  1613. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, warehouseOutInfo)
  1614. }
  1615. }
  1616. }
  1617. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1618. if newOut.ID > 0 {
  1619. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1620. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1621. if err == gorm.ErrRecordNotFound {
  1622. details := &models.AutomaticReduceDetail{
  1623. WarehouseOutId: newOut.ID,
  1624. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1625. PatientId: patient,
  1626. Ctime: time.Now().Unix(),
  1627. Mtime: time.Now().Unix(),
  1628. Status: 1,
  1629. RecordTime: order.StartTime,
  1630. OrgId: adminUserInfo.CurrentOrgId,
  1631. GoodId: jms,
  1632. GoodTypeId: jms_good_type_id,
  1633. }
  1634. service.AddSigleAutoReduceRecordInfo(details)
  1635. } else if err == nil {
  1636. if user.ID > 0 {
  1637. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.CurrentOrgId, patient, jms, &newOut)
  1638. }
  1639. }
  1640. }
  1641. }
  1642. }
  1643. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1644. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1645. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1646. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1647. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1648. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1649. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1650. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1651. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1652. warehouseOutInfo := &models.WarehouseOutInfo{
  1653. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1654. WarehouseOutId: out.ID,
  1655. Count: 1,
  1656. Status: 1,
  1657. Ctime: time.Now().Unix(),
  1658. Remark: "",
  1659. OrgId: adminUserInfo.CurrentOrgId,
  1660. Type: 1,
  1661. Manufacturer: 0,
  1662. Dealer: 0,
  1663. IsSys: 1,
  1664. SysRecordTime: order.StartTime,
  1665. }
  1666. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.CurrentOrgId)
  1667. warehouseOutInfo.Price = stockInInfo.Price
  1668. warehouseOutInfo.GoodId = fistula_needle_set
  1669. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1670. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1671. if err == nil {
  1672. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1673. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1674. if err == gorm.ErrRecordNotFound {
  1675. details := &models.AutomaticReduceDetail{
  1676. WarehouseOutId: warehouseOutInfo.ID,
  1677. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1678. PatientId: patient,
  1679. Ctime: time.Now().Unix(),
  1680. Mtime: time.Now().Unix(),
  1681. Status: 1,
  1682. RecordTime: order.StartTime,
  1683. OrgId: adminUserInfo.CurrentOrgId,
  1684. GoodId: fistula_needle_set,
  1685. GoodTypeId: fistula_needle_set_good_type_id,
  1686. }
  1687. service.AddSigleAutoReduceRecordInfo(details)
  1688. } else if err == nil {
  1689. if user.ID > 0 {
  1690. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1691. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, warehouseOutInfo)
  1692. }
  1693. }
  1694. }
  1695. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1696. if newOut.ID > 0 {
  1697. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1698. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1699. if err == gorm.ErrRecordNotFound {
  1700. details := &models.AutomaticReduceDetail{
  1701. WarehouseOutId: newOut.ID,
  1702. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1703. PatientId: patient,
  1704. Ctime: time.Now().Unix(),
  1705. Mtime: time.Now().Unix(),
  1706. Status: 1,
  1707. RecordTime: order.StartTime,
  1708. OrgId: adminUserInfo.CurrentOrgId,
  1709. GoodId: fistula_needle_set,
  1710. GoodTypeId: fistula_needle_set_good_type_id,
  1711. }
  1712. service.AddSigleAutoReduceRecordInfo(details)
  1713. } else if err == nil {
  1714. if user.ID > 0 {
  1715. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1716. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set, &newOut)
  1717. }
  1718. }
  1719. }
  1720. }
  1721. }
  1722. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1723. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1724. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1725. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1726. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1727. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1728. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1729. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1730. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1731. warehouseOutInfo := &models.WarehouseOutInfo{
  1732. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1733. WarehouseOutId: out.ID,
  1734. Count: 1,
  1735. Status: 1,
  1736. Ctime: time.Now().Unix(),
  1737. Remark: "",
  1738. OrgId: adminUserInfo.CurrentOrgId,
  1739. Type: 1,
  1740. Manufacturer: 0,
  1741. Dealer: 0,
  1742. IsSys: 1,
  1743. SysRecordTime: order.StartTime,
  1744. }
  1745. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.CurrentOrgId)
  1746. warehouseOutInfo.Price = stockInInfo.Price
  1747. warehouseOutInfo.GoodId = fistula_needle_set_16
  1748. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1749. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1750. if err == nil {
  1751. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1752. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1753. if err == gorm.ErrRecordNotFound {
  1754. details := &models.AutomaticReduceDetail{
  1755. WarehouseOutId: warehouseOutInfo.ID,
  1756. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1757. PatientId: patient,
  1758. Ctime: time.Now().Unix(),
  1759. Mtime: time.Now().Unix(),
  1760. Status: 1,
  1761. RecordTime: order.StartTime,
  1762. OrgId: adminUserInfo.CurrentOrgId,
  1763. GoodId: fistula_needle_set_16,
  1764. GoodTypeId: fistula_needle_set_16_good_type_id,
  1765. }
  1766. service.AddSigleAutoReduceRecordInfo(details)
  1767. } else if err == nil {
  1768. if user.ID > 0 {
  1769. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, warehouseOutInfo)
  1770. }
  1771. }
  1772. }
  1773. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1774. if newOut.ID > 0 {
  1775. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1776. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1777. if err == gorm.ErrRecordNotFound {
  1778. details := &models.AutomaticReduceDetail{
  1779. WarehouseOutId: newOut.ID,
  1780. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1781. PatientId: patient,
  1782. Ctime: time.Now().Unix(),
  1783. Mtime: time.Now().Unix(),
  1784. Status: 1,
  1785. RecordTime: order.StartTime,
  1786. OrgId: adminUserInfo.CurrentOrgId,
  1787. GoodId: fistula_needle_set_16,
  1788. GoodTypeId: fistula_needle_set_16_good_type_id,
  1789. }
  1790. service.AddSigleAutoReduceRecordInfo(details)
  1791. } else if err == nil {
  1792. if user.ID > 0 {
  1793. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.CurrentOrgId, patient, fistula_needle_set_16, &newOut)
  1794. }
  1795. }
  1796. }
  1797. }
  1798. }
  1799. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1800. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1801. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1802. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1803. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1804. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1805. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1806. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1807. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1808. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1809. warehouseOutInfo := &models.WarehouseOutInfo{
  1810. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1811. WarehouseOutId: out.ID,
  1812. Count: 1,
  1813. Status: 1,
  1814. Ctime: time.Now().Unix(),
  1815. Remark: "",
  1816. OrgId: adminUserInfo.CurrentOrgId,
  1817. Type: 1,
  1818. Manufacturer: 0,
  1819. Dealer: 0,
  1820. IsSys: 1,
  1821. SysRecordTime: order.StartTime,
  1822. }
  1823. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.CurrentOrgId)
  1824. warehouseOutInfo.Price = stockInInfo.Price
  1825. warehouseOutInfo.GoodId = hemoperfusion
  1826. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1827. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1828. if err == nil {
  1829. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1830. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1831. if err == gorm.ErrRecordNotFound {
  1832. details := &models.AutomaticReduceDetail{
  1833. WarehouseOutId: warehouseOutInfo.ID,
  1834. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1835. PatientId: patient,
  1836. Ctime: time.Now().Unix(),
  1837. Mtime: time.Now().Unix(),
  1838. Status: 1,
  1839. RecordTime: order.StartTime,
  1840. OrgId: adminUserInfo.CurrentOrgId,
  1841. GoodId: hemoperfusion,
  1842. GoodTypeId: hemoperfusion_good_type_id,
  1843. }
  1844. service.AddSigleAutoReduceRecordInfo(details)
  1845. } else if err == nil {
  1846. if user.ID > 0 {
  1847. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, warehouseOutInfo)
  1848. }
  1849. }
  1850. }
  1851. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1852. if newOut.ID > 0 {
  1853. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1854. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1855. if err == gorm.ErrRecordNotFound {
  1856. details := &models.AutomaticReduceDetail{
  1857. WarehouseOutId: newOut.ID,
  1858. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1859. PatientId: patient,
  1860. Ctime: time.Now().Unix(),
  1861. Mtime: time.Now().Unix(),
  1862. Status: 1,
  1863. RecordTime: order.StartTime,
  1864. OrgId: adminUserInfo.CurrentOrgId,
  1865. GoodId: hemoperfusion,
  1866. GoodTypeId: hemoperfusion_good_type_id,
  1867. }
  1868. service.AddSigleAutoReduceRecordInfo(details)
  1869. } else if err == nil {
  1870. if user.ID > 0 {
  1871. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.CurrentOrgId, patient, hemoperfusion, &newOut)
  1872. }
  1873. }
  1874. }
  1875. }
  1876. }
  1877. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1878. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.CurrentOrgId)
  1879. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1880. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1881. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1882. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1883. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1884. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1885. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1886. warehouseOutInfo := &models.WarehouseOutInfo{
  1887. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1888. WarehouseOutId: out.WarehouseOutId,
  1889. Count: 1,
  1890. Status: 1,
  1891. Ctime: time.Now().Unix(),
  1892. Remark: "",
  1893. OrgId: adminUserInfo.CurrentOrgId,
  1894. Type: 1,
  1895. Manufacturer: 0,
  1896. Dealer: 0,
  1897. IsSys: 1,
  1898. SysRecordTime: order.StartTime,
  1899. }
  1900. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.CurrentOrgId)
  1901. warehouseOutInfo.Price = stockInInfo.Price
  1902. warehouseOutInfo.GoodId = dialyser_sterilised
  1903. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1904. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1905. if err == nil {
  1906. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1907. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1908. if err == gorm.ErrRecordNotFound {
  1909. details := &models.AutomaticReduceDetail{
  1910. WarehouseOutId: warehouseOutInfo.ID,
  1911. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1912. PatientId: patient,
  1913. Ctime: time.Now().Unix(),
  1914. Mtime: time.Now().Unix(),
  1915. Status: 1,
  1916. RecordTime: order.StartTime,
  1917. OrgId: adminUserInfo.CurrentOrgId,
  1918. GoodId: dialyser_sterilised,
  1919. GoodTypeId: dialyser_sterilised_good_type_id,
  1920. }
  1921. service.AddSigleAutoReduceRecordInfo(details)
  1922. } else if err == nil {
  1923. if user.ID > 0 {
  1924. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1925. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, warehouseOutInfo)
  1926. }
  1927. }
  1928. }
  1929. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1930. if newOut.ID > 0 {
  1931. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  1932. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1933. if err == gorm.ErrRecordNotFound {
  1934. details := &models.AutomaticReduceDetail{
  1935. WarehouseOutId: newOut.ID,
  1936. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1937. PatientId: patient,
  1938. Ctime: time.Now().Unix(),
  1939. Mtime: time.Now().Unix(),
  1940. Status: 1,
  1941. RecordTime: order.StartTime,
  1942. OrgId: adminUserInfo.CurrentOrgId,
  1943. GoodId: dialyser_sterilised,
  1944. GoodTypeId: dialyser_sterilised_good_type_id,
  1945. }
  1946. service.AddSigleAutoReduceRecordInfo(details)
  1947. } else if err == nil {
  1948. if user.ID > 0 {
  1949. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyser_sterilised, &newOut)
  1950. }
  1951. }
  1952. }
  1953. }
  1954. }
  1955. if dialysisPrescription.Filtryzer != filtryzer {
  1956. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1957. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  1958. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1959. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1960. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1961. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1962. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  1963. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1964. warehouseOutInfo := &models.WarehouseOutInfo{
  1965. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1966. WarehouseOutId: out.ID,
  1967. Count: 1,
  1968. Status: 1,
  1969. Ctime: time.Now().Unix(),
  1970. Remark: "",
  1971. OrgId: adminUserInfo.CurrentOrgId,
  1972. Type: 1,
  1973. Manufacturer: 0,
  1974. Dealer: 0,
  1975. IsSys: 1,
  1976. SysRecordTime: order.StartTime,
  1977. }
  1978. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.CurrentOrgId)
  1979. warehouseOutInfo.Price = stockInInfo.Price
  1980. warehouseOutInfo.GoodId = filtryzer
  1981. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1982. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1983. if err == nil {
  1984. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1985. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  1986. if err == gorm.ErrRecordNotFound {
  1987. details := &models.AutomaticReduceDetail{
  1988. WarehouseOutId: warehouseOutInfo.ID,
  1989. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1990. PatientId: patient,
  1991. Ctime: time.Now().Unix(),
  1992. Mtime: time.Now().Unix(),
  1993. Status: 1,
  1994. RecordTime: order.StartTime,
  1995. OrgId: adminUserInfo.CurrentOrgId,
  1996. GoodId: filtryzer,
  1997. GoodTypeId: filtryzer_good_type_id,
  1998. }
  1999. service.AddSigleAutoReduceRecordInfo(details)
  2000. } else if err == nil {
  2001. if user.ID > 0 {
  2002. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, warehouseOutInfo)
  2003. }
  2004. }
  2005. }
  2006. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2007. if newOut.ID > 0 {
  2008. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2009. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2010. if err == gorm.ErrRecordNotFound {
  2011. details := &models.AutomaticReduceDetail{
  2012. WarehouseOutId: newOut.ID,
  2013. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2014. PatientId: patient,
  2015. Ctime: time.Now().Unix(),
  2016. Mtime: time.Now().Unix(),
  2017. Status: 1,
  2018. RecordTime: order.StartTime,
  2019. OrgId: adminUserInfo.CurrentOrgId,
  2020. GoodId: filtryzer,
  2021. GoodTypeId: filtryzer_good_type_id,
  2022. }
  2023. service.AddSigleAutoReduceRecordInfo(details)
  2024. } else if err == nil {
  2025. if user.ID > 0 {
  2026. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.CurrentOrgId, patient, filtryzer, &newOut)
  2027. }
  2028. }
  2029. }
  2030. }
  2031. }
  2032. if dialysisPrescription.Dialyzers != dialyzers {
  2033. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2034. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2035. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2036. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2037. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2038. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2039. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2040. warehouseOutInfo := &models.WarehouseOutInfo{
  2041. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2042. WarehouseOutId: out.ID,
  2043. Count: 1,
  2044. Status: 1,
  2045. Ctime: time.Now().Unix(),
  2046. Remark: "",
  2047. OrgId: adminUserInfo.CurrentOrgId,
  2048. Type: 1,
  2049. Manufacturer: 0,
  2050. Dealer: 0,
  2051. IsSys: 1,
  2052. SysRecordTime: order.StartTime,
  2053. }
  2054. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.CurrentOrgId)
  2055. warehouseOutInfo.Price = stockInInfo.Price
  2056. warehouseOutInfo.GoodId = dialyzers
  2057. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  2058. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2059. if err == nil {
  2060. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2061. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2062. if err == gorm.ErrRecordNotFound {
  2063. details := &models.AutomaticReduceDetail{
  2064. WarehouseOutId: warehouseOutInfo.ID,
  2065. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2066. PatientId: patient,
  2067. Ctime: time.Now().Unix(),
  2068. Mtime: time.Now().Unix(),
  2069. Status: 1,
  2070. RecordTime: order.StartTime,
  2071. OrgId: adminUserInfo.CurrentOrgId,
  2072. GoodId: dialyzers,
  2073. GoodTypeId: dialyzers_good_type_id,
  2074. }
  2075. service.AddSigleAutoReduceRecordInfo(details)
  2076. } else if err == nil {
  2077. if user.ID > 0 {
  2078. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, warehouseOutInfo)
  2079. }
  2080. }
  2081. }
  2082. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2083. if newOut.ID > 0 {
  2084. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2085. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2086. if err == gorm.ErrRecordNotFound {
  2087. details := &models.AutomaticReduceDetail{
  2088. WarehouseOutId: newOut.ID,
  2089. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2090. PatientId: patient,
  2091. Ctime: time.Now().Unix(),
  2092. Mtime: time.Now().Unix(),
  2093. Status: 1,
  2094. RecordTime: order.StartTime,
  2095. OrgId: adminUserInfo.CurrentOrgId,
  2096. GoodId: dialyzers,
  2097. GoodTypeId: dialyzers_good_type_id,
  2098. }
  2099. service.AddSigleAutoReduceRecordInfo(details)
  2100. } else if err == nil {
  2101. if user.ID > 0 {
  2102. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.CurrentOrgId, patient, dialyzers, &newOut)
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. if dialysisPrescription.Injector != injector {
  2109. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2110. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2111. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2112. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2113. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2114. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2115. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2116. warehouseOutInfo := &models.WarehouseOutInfo{
  2117. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2118. WarehouseOutId: out.ID,
  2119. Count: 1,
  2120. Status: 1,
  2121. Ctime: time.Now().Unix(),
  2122. Remark: "",
  2123. OrgId: adminUserInfo.CurrentOrgId,
  2124. Type: 1,
  2125. Manufacturer: 0,
  2126. Dealer: 0,
  2127. IsSys: 1,
  2128. SysRecordTime: order.StartTime,
  2129. }
  2130. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.CurrentOrgId)
  2131. warehouseOutInfo.Price = stockInInfo.Price
  2132. warehouseOutInfo.GoodId = injector
  2133. warehouseOutInfo.GoodTypeId = injector_good_type_id
  2134. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2135. if err == nil {
  2136. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2137. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2138. if err == gorm.ErrRecordNotFound {
  2139. details := &models.AutomaticReduceDetail{
  2140. WarehouseOutId: warehouseOutInfo.ID,
  2141. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2142. PatientId: patient,
  2143. Ctime: time.Now().Unix(),
  2144. Mtime: time.Now().Unix(),
  2145. Status: 1,
  2146. RecordTime: order.StartTime,
  2147. OrgId: adminUserInfo.CurrentOrgId,
  2148. GoodId: injector,
  2149. GoodTypeId: injector_good_type_id,
  2150. }
  2151. service.AddSigleAutoReduceRecordInfo(details)
  2152. } else if err == nil {
  2153. if user.ID > 0 {
  2154. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, warehouseOutInfo)
  2155. }
  2156. }
  2157. }
  2158. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2159. if newOut.ID > 0 {
  2160. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2161. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2162. if err == gorm.ErrRecordNotFound {
  2163. details := &models.AutomaticReduceDetail{
  2164. WarehouseOutId: newOut.ID,
  2165. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2166. PatientId: patient,
  2167. Ctime: time.Now().Unix(),
  2168. Mtime: time.Now().Unix(),
  2169. Status: 1,
  2170. RecordTime: order.StartTime,
  2171. OrgId: adminUserInfo.CurrentOrgId,
  2172. GoodId: injector,
  2173. GoodTypeId: injector_good_type_id,
  2174. }
  2175. service.AddSigleAutoReduceRecordInfo(details)
  2176. } else if err == nil {
  2177. if user.ID > 0 {
  2178. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.CurrentOrgId, patient, injector, &newOut)
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. if dialysisPrescription.Bloodlines != bloodlines {
  2185. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2186. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2187. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2188. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2189. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2190. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2191. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2192. warehouseOutInfo := &models.WarehouseOutInfo{
  2193. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2194. WarehouseOutId: out.ID,
  2195. Count: 1,
  2196. Status: 1,
  2197. Ctime: time.Now().Unix(),
  2198. Remark: "",
  2199. OrgId: adminUserInfo.CurrentOrgId,
  2200. Type: 1,
  2201. Manufacturer: 0,
  2202. Dealer: 0,
  2203. IsSys: 1,
  2204. SysRecordTime: order.StartTime,
  2205. }
  2206. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.CurrentOrgId)
  2207. warehouseOutInfo.Price = stockInInfo.Price
  2208. warehouseOutInfo.GoodId = bloodlines
  2209. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  2210. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2211. if err == nil {
  2212. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2213. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2214. if err == gorm.ErrRecordNotFound {
  2215. details := &models.AutomaticReduceDetail{
  2216. WarehouseOutId: warehouseOutInfo.ID,
  2217. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2218. PatientId: patient,
  2219. Ctime: time.Now().Unix(),
  2220. Mtime: time.Now().Unix(),
  2221. Status: 1,
  2222. RecordTime: order.StartTime,
  2223. OrgId: adminUserInfo.CurrentOrgId,
  2224. GoodId: bloodlines,
  2225. GoodTypeId: bloodlines_good_type_id,
  2226. }
  2227. service.AddSigleAutoReduceRecordInfo(details)
  2228. } else if err == nil {
  2229. if user.ID > 0 {
  2230. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, warehouseOutInfo)
  2231. }
  2232. }
  2233. }
  2234. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2235. if newOut.ID > 0 {
  2236. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2237. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2238. if err == gorm.ErrRecordNotFound {
  2239. details := &models.AutomaticReduceDetail{
  2240. WarehouseOutId: newOut.ID,
  2241. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2242. PatientId: patient,
  2243. Ctime: time.Now().Unix(),
  2244. Mtime: time.Now().Unix(),
  2245. Status: 1,
  2246. RecordTime: order.StartTime,
  2247. OrgId: adminUserInfo.CurrentOrgId,
  2248. GoodId: bloodlines,
  2249. GoodTypeId: bloodlines_good_type_id,
  2250. }
  2251. service.AddSigleAutoReduceRecordInfo(details)
  2252. } else if err == nil {
  2253. if user.ID > 0 {
  2254. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.CurrentOrgId, patient, bloodlines, &newOut)
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  2261. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2262. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2263. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2264. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2265. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2266. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2267. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2268. warehouseOutInfo := &models.WarehouseOutInfo{
  2269. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2270. WarehouseOutId: out.ID,
  2271. Count: 1,
  2272. Status: 1,
  2273. Ctime: time.Now().Unix(),
  2274. Remark: "",
  2275. OrgId: adminUserInfo.CurrentOrgId,
  2276. Type: 1,
  2277. Manufacturer: 0,
  2278. Dealer: 0,
  2279. IsSys: 1,
  2280. SysRecordTime: order.StartTime,
  2281. }
  2282. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.CurrentOrgId)
  2283. warehouseOutInfo.Price = stockInInfo.Price
  2284. warehouseOutInfo.GoodId = tubing_hemodialysis
  2285. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  2286. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2287. if err == nil {
  2288. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2289. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2290. if err == gorm.ErrRecordNotFound {
  2291. details := &models.AutomaticReduceDetail{
  2292. WarehouseOutId: warehouseOutInfo.ID,
  2293. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2294. PatientId: patient,
  2295. Ctime: time.Now().Unix(),
  2296. Mtime: time.Now().Unix(),
  2297. Status: 1,
  2298. RecordTime: order.StartTime,
  2299. OrgId: adminUserInfo.CurrentOrgId,
  2300. GoodId: tubing_hemodialysis,
  2301. GoodTypeId: tubingHemodialysis_good_type_id,
  2302. }
  2303. service.AddSigleAutoReduceRecordInfo(details)
  2304. } else if err == nil {
  2305. if user.ID > 0 {
  2306. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, warehouseOutInfo)
  2307. }
  2308. }
  2309. }
  2310. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2311. if newOut.ID > 0 {
  2312. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2313. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2314. if err == gorm.ErrRecordNotFound {
  2315. details := &models.AutomaticReduceDetail{
  2316. WarehouseOutId: newOut.ID,
  2317. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2318. PatientId: patient,
  2319. Ctime: time.Now().Unix(),
  2320. Mtime: time.Now().Unix(),
  2321. Status: 1,
  2322. RecordTime: order.StartTime,
  2323. OrgId: adminUserInfo.CurrentOrgId,
  2324. GoodId: tubing_hemodialysis,
  2325. GoodTypeId: tubingHemodialysis_good_type_id,
  2326. }
  2327. service.AddSigleAutoReduceRecordInfo(details)
  2328. } else if err == nil {
  2329. if user.ID > 0 {
  2330. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.CurrentOrgId, patient, tubing_hemodialysis, &newOut)
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. if dialysisPrescription.Package != safe_package {
  2337. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2338. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2339. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2340. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2341. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2342. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2343. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2344. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2345. warehouseOutInfo := &models.WarehouseOutInfo{
  2346. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2347. WarehouseOutId: out.ID,
  2348. Count: 1,
  2349. Status: 1,
  2350. Ctime: time.Now().Unix(),
  2351. Remark: "",
  2352. OrgId: adminUserInfo.CurrentOrgId,
  2353. Type: 1,
  2354. Manufacturer: 0,
  2355. Dealer: 0,
  2356. IsSys: 1,
  2357. SysRecordTime: order.StartTime,
  2358. }
  2359. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.CurrentOrgId)
  2360. warehouseOutInfo.Price = stockInInfo.Price
  2361. warehouseOutInfo.GoodId = safe_package
  2362. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  2363. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2364. if err == nil {
  2365. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2366. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2367. if err == gorm.ErrRecordNotFound {
  2368. details := &models.AutomaticReduceDetail{
  2369. WarehouseOutId: warehouseOutInfo.ID,
  2370. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2371. PatientId: patient,
  2372. Ctime: time.Now().Unix(),
  2373. Mtime: time.Now().Unix(),
  2374. Status: 1,
  2375. RecordTime: order.StartTime,
  2376. OrgId: adminUserInfo.CurrentOrgId,
  2377. GoodId: safe_package,
  2378. GoodTypeId: safe_package_good_type_id,
  2379. }
  2380. service.AddSigleAutoReduceRecordInfo(details)
  2381. } else if err == nil {
  2382. if user.ID > 0 {
  2383. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, warehouseOutInfo)
  2384. }
  2385. }
  2386. }
  2387. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2388. if newOut.ID > 0 {
  2389. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2390. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2391. if err == gorm.ErrRecordNotFound {
  2392. details := &models.AutomaticReduceDetail{
  2393. WarehouseOutId: newOut.ID,
  2394. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2395. PatientId: patient,
  2396. Ctime: time.Now().Unix(),
  2397. Mtime: time.Now().Unix(),
  2398. Status: 1,
  2399. RecordTime: order.StartTime,
  2400. OrgId: adminUserInfo.CurrentOrgId,
  2401. GoodId: safe_package,
  2402. GoodTypeId: safe_package_good_type_id,
  2403. }
  2404. service.AddSigleAutoReduceRecordInfo(details)
  2405. } else if err == nil {
  2406. if user.ID > 0 {
  2407. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.CurrentOrgId, patient, safe_package, &newOut)
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. if dialysisPrescription.ALiquid != a_liquid {
  2414. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2415. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.CurrentOrgId)
  2416. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  2417. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2418. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  2419. //判断前端更改后的商品id的出库记录在数据库中是否存在
  2420. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.CurrentOrgId)
  2421. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  2422. warehouseOutInfo := &models.WarehouseOutInfo{
  2423. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  2424. WarehouseOutId: out.ID,
  2425. Count: 1,
  2426. Status: 1,
  2427. Ctime: time.Now().Unix(),
  2428. Remark: "",
  2429. OrgId: adminUserInfo.CurrentOrgId,
  2430. Type: 1,
  2431. Manufacturer: 0,
  2432. Dealer: 0,
  2433. IsSys: 1,
  2434. SysRecordTime: order.StartTime,
  2435. }
  2436. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.CurrentOrgId)
  2437. warehouseOutInfo.Price = stockInInfo.Price
  2438. warehouseOutInfo.GoodId = a_liquid
  2439. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  2440. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2441. if err == nil {
  2442. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  2443. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2444. if err == gorm.ErrRecordNotFound {
  2445. details := &models.AutomaticReduceDetail{
  2446. WarehouseOutId: warehouseOutInfo.ID,
  2447. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2448. PatientId: patient,
  2449. Ctime: time.Now().Unix(),
  2450. Mtime: time.Now().Unix(),
  2451. Status: 1,
  2452. RecordTime: order.StartTime,
  2453. OrgId: adminUserInfo.CurrentOrgId,
  2454. GoodId: a_liquid,
  2455. GoodTypeId: aliquid_good_type_id,
  2456. }
  2457. service.AddSigleAutoReduceRecordInfo(details)
  2458. } else if err == nil {
  2459. if user.ID > 0 {
  2460. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, warehouseOutInfo)
  2461. }
  2462. }
  2463. }
  2464. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2465. if newOut.ID > 0 {
  2466. service.UpdateStockOutInfoCount(adminUserInfo.CurrentOrgId, newOut.ID)
  2467. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, patient, adminUserInfo.CurrentOrgId, out.WarehouseOutOrderNumber)
  2468. if err == gorm.ErrRecordNotFound {
  2469. details := &models.AutomaticReduceDetail{
  2470. WarehouseOutId: newOut.ID,
  2471. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2472. PatientId: patient,
  2473. Ctime: time.Now().Unix(),
  2474. Mtime: time.Now().Unix(),
  2475. Status: 1,
  2476. RecordTime: order.StartTime,
  2477. OrgId: adminUserInfo.CurrentOrgId,
  2478. GoodId: a_liquid,
  2479. GoodTypeId: aliquid_good_type_id,
  2480. }
  2481. service.AddSigleAutoReduceRecordInfo(details)
  2482. } else if err == nil {
  2483. if user.ID > 0 {
  2484. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.CurrentOrgId, patient, a_liquid, &newOut)
  2485. }
  2486. }
  2487. }
  2488. }
  2489. }
  2490. }
  2491. }
  2492. }
  2493. prescription.Creater = adminUserInfo.AdminUser.Id
  2494. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2495. prescription.UpdatedTime = time.Now().Unix()
  2496. prescription.Modifier = adminUserInfo.AdminUser.Id
  2497. prescription.ID = dialysisPrescription.ID
  2498. }
  2499. solution := models.DialysisSolution{
  2500. RegistrarsId: adminUserInfo.AdminUser.Id,
  2501. UserOrgId: adminUserInfo.CurrentOrgId,
  2502. Doctor: prescription_doctor,
  2503. PatientId: patient,
  2504. ModeId: mode_id,
  2505. DialysisDuration: dialysis_duration,
  2506. PerfusionApparatus: perfusion_apparatus,
  2507. BloodFlowVolume: blood_flow_volume,
  2508. Dewater: dewater_amount,
  2509. DisplaceLiqui: displace_liqui,
  2510. ReplacementWay: replacement_way,
  2511. Anticoagulant: anticoagulant,
  2512. AnticoagulantShouji: anticoagulant_shouji,
  2513. AnticoagulantWeichi: anticoagulant_weichi,
  2514. AnticoagulantZongliang: anticoagulant_zongliang,
  2515. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  2516. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  2517. Kalium: kalium,
  2518. Sodium: sodium,
  2519. Calcium: calcium,
  2520. Bicarbonate: bicarbonate,
  2521. Glucose: glucose,
  2522. // DryWeight: dry_weight,
  2523. DialysateFlow: dialysate_flow,
  2524. DialysateTemperature: dialysate_temperature,
  2525. Conductivity: conductivity,
  2526. Remark: remark,
  2527. Status: 1,
  2528. CreatedTime: time.Now().Unix(),
  2529. UpdatedTime: time.Now().Unix(),
  2530. DialysisDurationMinute: dialysisDurationMinute,
  2531. DialysisDurationHour: dialysisDurationHour,
  2532. TargetUltrafiltration: targetUltrafiltration,
  2533. DialysateFormulation: dialysateFormulation,
  2534. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  2535. BodyFluid: body_fluid,
  2536. SpecialMedicine: special_medicine,
  2537. SpecialMedicineOther: special_medicine_other,
  2538. DisplaceLiquiPart: displace_liqui_part,
  2539. DisplaceLiquiValue: displace_liqui_value,
  2540. BloodAccess: blood_access,
  2541. Ultrafiltration: ultrafiltration,
  2542. BodyFluidOther: body_fluid_other,
  2543. ReplacementTotal: replacement_total,
  2544. TargetKtv: target_ktv,
  2545. }
  2546. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  2547. if err == nil {
  2548. c.ServeSuccessJSON(map[string]interface{}{
  2549. "solution": &solution,
  2550. "prescription": &prescription,
  2551. })
  2552. } else {
  2553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2554. }
  2555. }
  2556. func (c *DialysisApiController) PostDouleCheck() {
  2557. id, _ := c.GetInt64("patient", 0)
  2558. recordDateStr := c.GetString("record_date")
  2559. checkTimeStr := c.GetString("check_time")
  2560. firstCheckTimeStr := c.GetString("first_check_time")
  2561. creater, _ := c.GetInt64("creater", 0)
  2562. modifier, _ := c.GetInt64("modifier", 0)
  2563. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  2564. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  2565. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  2566. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  2567. dialysis_item_desc := c.GetString("dialysis_item_desc")
  2568. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  2569. vascular_access_desc := c.GetString("vascular_access_desc")
  2570. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  2571. collator, _ := c.GetInt64("collator", 0)
  2572. if id <= 0 {
  2573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2574. return
  2575. }
  2576. adminUserInfo := c.GetAdminUserInfo()
  2577. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  2578. if patient.ID == 0 {
  2579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2580. return
  2581. }
  2582. if len(recordDateStr) == 0 {
  2583. recordDateStr = time.Now().Format("2006-01-02")
  2584. }
  2585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2586. if parseDateErr != nil {
  2587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2589. return
  2590. }
  2591. if len(checkTimeStr) == 0 {
  2592. checkTimeStr = time.Now().Format("2006-01-02 15:04")
  2593. }
  2594. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  2595. if len(firstCheckTimeStr) == 0 {
  2596. firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  2597. }
  2598. firstCheckTimeDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  2599. doubleCheck := models.DoubleCheck{
  2600. UserOrgId: adminUserInfo.CurrentOrgId,
  2601. PatientId: id,
  2602. DialysisItemCheck: dialysis_item_check,
  2603. DialysisParameterCheck: dialysis_parameter_check,
  2604. VascularAccessVerification: vascular_access_verification,
  2605. PipelineConnectionCheck: pipeline_connection_check,
  2606. DialysisItemDesc: dialysis_item_desc,
  2607. DialysisParameterDesc: dialysis_parameter_desc,
  2608. VascularAccessDesc: vascular_access_desc,
  2609. PipelineConnectionDesc: pipeline_connection_desc,
  2610. Collator: collator,
  2611. Status: 1,
  2612. CreatedTime: time.Now().Unix(),
  2613. UpdatedTime: time.Now().Unix(),
  2614. CheckDate: recordDate.Unix(),
  2615. }
  2616. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2617. if check.ID == 0 { //新增
  2618. doubleCheck.FirstCheckTime = firstCheckTimeDate.Unix()
  2619. doubleCheck.CheckTime = checkDate.Unix()
  2620. doubleCheck.Creater = creater
  2621. doubleCheck.Modifier = modifier
  2622. err := service.AddSigleDoubleCheck(&doubleCheck)
  2623. if err == nil {
  2624. c.ServeSuccessJSON(map[string]interface{}{
  2625. "doubleCheck": doubleCheck,
  2626. })
  2627. } else {
  2628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2629. }
  2630. } else { //修改
  2631. doubleCheck.FirstCheckTime = firstCheckTimeDate.Unix()
  2632. doubleCheck.CheckTime = checkDate.Unix()
  2633. doubleCheck.Creater = creater
  2634. doubleCheck.Modifier = modifier
  2635. doubleCheck.CreatedTime = check.CreatedTime
  2636. doubleCheck.UpdatedTime = time.Now().Unix()
  2637. doubleCheck.ID = check.ID
  2638. err := service.UpdateDoubleCheck(&doubleCheck)
  2639. if err == nil {
  2640. c.ServeSuccessJSON(map[string]interface{}{
  2641. "doubleCheck": doubleCheck,
  2642. })
  2643. } else {
  2644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2645. }
  2646. }
  2647. }
  2648. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  2649. id, _ := c.GetInt64("patient", 0)
  2650. recordDateStr := c.GetString("record_date")
  2651. way, _ := c.GetInt64("way", 0)
  2652. consciousness, _ := c.GetInt64("consciousness", 0)
  2653. appetite, _ := c.GetInt64("appetite", 0)
  2654. condition, _ := c.GetInt64("condition", 0)
  2655. posture, _ := c.GetInt64("posture")
  2656. score := c.GetString("score")
  2657. sick_condition, _ := c.GetInt64("sick_condition", 0)
  2658. danger_level, _ := c.GetInt64("danger_level", 0)
  2659. intake, _ := c.GetInt64("intake", 0)
  2660. nutrition, _ := c.GetInt64("nutrition", 0)
  2661. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  2662. psychological_assessment_other := c.GetString("psychological_assessment_other")
  2663. sick_condition_other := c.GetString("sick_condition_other")
  2664. //precaution, _ := c.GetInt64("precaution", 0)
  2665. precaution := c.GetString("precaution")
  2666. precaution_other := c.GetString("precaution_other")
  2667. psychological_other := c.GetString("psychological_other")
  2668. admission_number := c.GetString("admission_number")
  2669. if id <= 0 {
  2670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2671. return
  2672. }
  2673. adminUserInfo := c.GetAdminUserInfo()
  2674. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  2675. if patient.ID == 0 {
  2676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2677. return
  2678. }
  2679. if len(recordDateStr) == 0 {
  2680. recordDateStr = time.Now().Format("2006-01-02")
  2681. }
  2682. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2683. if parseDateErr != nil {
  2684. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2686. return
  2687. }
  2688. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2689. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  2690. UserOrgId: adminUserInfo.CurrentOrgId,
  2691. PatientId: id,
  2692. RecordDate: recordDate.Unix(),
  2693. Way: way,
  2694. Consciousness: consciousness,
  2695. Appetite: appetite,
  2696. Condition: condition,
  2697. SickCondition: sick_condition,
  2698. DangerLevel: danger_level,
  2699. Intake: intake,
  2700. Nutrition: nutrition,
  2701. PsychologicalAssessment: psychological_assessment,
  2702. PsychologicalAssessmentOther: psychological_assessment_other,
  2703. SickConditionOther: sick_condition_other,
  2704. Posture: posture,
  2705. CreatedTime: time.Now().Unix(),
  2706. UpdateTime: time.Now().Unix(),
  2707. Status: 1,
  2708. Score: score,
  2709. Precaution: precaution,
  2710. PrecautionOther: precaution_other,
  2711. PsychologicalOther: psychological_other,
  2712. AdmissionNumber: admission_number,
  2713. }
  2714. if receiveTreatment.ID == 0 { //新增
  2715. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  2716. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  2717. if err == nil {
  2718. c.ServeSuccessJSON(map[string]interface{}{
  2719. "receiveTreatmentAsses": receiveTreatmentAsses,
  2720. })
  2721. } else {
  2722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2723. }
  2724. } else { //修改
  2725. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  2726. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2727. // if getPermissionErr != nil {
  2728. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2729. // return
  2730. // } else if headNursePermission == nil {
  2731. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2732. // return
  2733. // }
  2734. //}
  2735. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  2736. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  2737. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  2738. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  2739. receiveTreatmentAsses.ID = receiveTreatment.ID
  2740. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  2741. if err == nil {
  2742. c.ServeSuccessJSON(map[string]interface{}{
  2743. "receiveTreatmentAsses": receiveTreatmentAsses,
  2744. })
  2745. } else {
  2746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2747. }
  2748. }
  2749. }
  2750. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  2751. patient, _ := c.GetInt64("patient", 0)
  2752. recordDateStr := c.GetString("record_date")
  2753. fmt.Println(recordDateStr)
  2754. if patient <= 0 {
  2755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2756. return
  2757. }
  2758. adminUserInfo := c.GetAdminUserInfo()
  2759. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2760. if patientInfo.ID == 0 {
  2761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2762. return
  2763. }
  2764. if len(recordDateStr) == 0 {
  2765. recordDateStr = time.Now().Format("2006-01-02")
  2766. }
  2767. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2768. if parseDateErr != nil {
  2769. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2771. return
  2772. }
  2773. // data := make(map[string]interface{}, 0)
  2774. var data models.AssessmentAfterDislysis
  2775. var err error
  2776. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  2777. fmt.Println(err)
  2778. if err != nil {
  2779. c.ErrorLog("数据解析错误:%v", err)
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2781. return
  2782. }
  2783. fmt.Println("丰管业配置", data.SealingFluidDispose)
  2784. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2785. assessment.DialysisOrderId = data.DialysisOrderId
  2786. assessment.Evaluator = adminUserInfo.AdminUser.Id
  2787. assessment.Status = 1
  2788. assessment.WeightAfter = data.WeightAfter
  2789. assessment.WeightLoss = data.WeightLoss
  2790. assessment.Temperature = data.Temperature
  2791. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  2792. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  2793. assessment.PulseFrequency = data.PulseFrequency
  2794. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  2795. assessment.ActualDisplacement = data.ActualDisplacement
  2796. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  2797. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  2798. assessment.Cruor = data.Cruor
  2799. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  2800. assessment.DialysisIntakes = data.DialysisIntakes
  2801. assessment.InternalFistula = data.InternalFistula
  2802. assessment.BloodAccessPartId = data.BloodAccessPartId
  2803. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  2804. assessment.Catheter = data.Catheter
  2805. assessment.Complication = data.Complication
  2806. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  2807. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  2808. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  2809. assessment.PatientGose = data.PatientGose
  2810. assessment.InpatientDepartment = data.InpatientDepartment
  2811. assessment.ObservationContent = data.ObservationContent
  2812. assessment.ObservationContentOther = data.ObservationContentOther
  2813. assessment.Remark = data.Remark
  2814. assessment.BreathingRate = data.BreathingRate
  2815. assessment.DialysisProcess = data.DialysisProcess
  2816. assessment.InAdvanceMinute = data.InAdvanceMinute
  2817. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  2818. assessment.InAdvanceReason = data.InAdvanceReason
  2819. assessment.HemostasisOpera = data.HemostasisOpera
  2820. assessment.HemostasisMinute = data.HemostasisMinute
  2821. assessment.TremorNoise = data.TremorNoise
  2822. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  2823. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  2824. assessment.ArterialTube = data.ArterialTube
  2825. assessment.IntravenousTube = data.IntravenousTube
  2826. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  2827. assessment.Dialyzer = data.Dialyzer
  2828. assessment.IsEat = data.IsEat
  2829. assessment.CvcA = data.CvcA
  2830. assessment.CvcV = data.CvcV
  2831. assessment.Channel = data.Channel
  2832. assessment.ReturnBlood = data.ReturnBlood
  2833. assessment.RehydrationVolume = data.RehydrationVolume
  2834. assessment.DialysisDuring = data.DialysisDuring
  2835. assessment.StrokeVolume = data.StrokeVolume
  2836. assessment.BloodFlow = data.BloodFlow
  2837. assessment.SealingFluidDispose = data.SealingFluidDispose
  2838. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  2839. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  2840. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  2841. assessment.SettingPressure = data.SettingPressure
  2842. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  2843. assessment.DiastolicPressure = data.DiastolicPressure
  2844. assessment.AdditionalWeight = data.AdditionalWeight
  2845. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2846. if assessment.ID > 0 {
  2847. if appRole.UserType == 2 || appRole.UserType == 1 {
  2848. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2849. assessment.AssessmentTime = time.Now().Unix()
  2850. } else {
  2851. if assessment.Creater == 0 {
  2852. assessment.Modifier = adminUserInfo.AdminUser.Id
  2853. assessment.Creater = adminUserInfo.AdminUser.Id
  2854. } else {
  2855. assessment.Modifier = adminUserInfo.AdminUser.Id
  2856. }
  2857. }
  2858. assessment.UpdatedTime = time.Now().Unix()
  2859. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  2860. } else {
  2861. if appRole.UserType == 2 || appRole.UserType == 1 {
  2862. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2863. assessment.AssessmentTime = time.Now().Unix()
  2864. } else {
  2865. assessment.Creater = adminUserInfo.AdminUser.Id
  2866. }
  2867. assessment.CreatedTime = time.Now().Unix()
  2868. assessment.UpdatedTime = time.Now().Unix()
  2869. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  2870. assessment.PatientId = patient
  2871. assessment.AssessmentDate = recordDate.Unix()
  2872. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  2873. }
  2874. if err != nil {
  2875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2876. return
  2877. }
  2878. c.ServeSuccessJSON(map[string]interface{}{
  2879. "AssessmentAfterDislysis": &assessment,
  2880. })
  2881. }
  2882. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  2883. patient, _ := c.GetInt64("patient", 0)
  2884. recordDateStr := c.GetString("record_date")
  2885. if patient <= 0 {
  2886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2887. return
  2888. }
  2889. adminUserInfo := c.GetAdminUserInfo()
  2890. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2891. if patientInfo.ID == 0 {
  2892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2893. return
  2894. }
  2895. if len(recordDateStr) == 0 {
  2896. recordDateStr = time.Now().Format("2006-01-02")
  2897. }
  2898. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2899. if parseDateErr != nil {
  2900. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2902. return
  2903. }
  2904. weight_before, _ := c.GetFloat("weight_before", 0)
  2905. dry_weight, _ := c.GetFloat("dry_weight", 0)
  2906. additional_weight, _ := c.GetFloat("additional_weight", 0)
  2907. temperature, _ := c.GetFloat("temperature", 0)
  2908. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2909. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2910. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2911. last_post_dialysis := c.GetString("last_post_dialysis")
  2912. dialysis_interphase := c.GetString("dialysis_interphase")
  2913. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  2914. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  2915. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  2916. bloodAccessPartId := c.GetString("blood_access_part_id")
  2917. internalFistula := c.GetString("internal_fistula")
  2918. internal_fistula_skin := c.GetString("internal_fistula_skin")
  2919. catheter := c.GetString("catheter")
  2920. catheter_bend, _ := c.GetInt("catheter_bend")
  2921. complication := c.GetString("complication")
  2922. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2923. hemorrhage := c.GetString("hemorrhage")
  2924. hemorrhage_other := c.GetString("hemorrhage_other")
  2925. remark := c.GetString("remark")
  2926. puncture_method := c.GetString("puncture_method")
  2927. dialysis_count, _ := c.GetInt64("dialysis_count", 0)
  2928. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2929. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2930. ductus_arantii := c.GetString("ductus_arantii")
  2931. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2932. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2933. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2934. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  2935. puncture_way := c.GetString("puncture_way")
  2936. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2937. internal_fistula_other := c.GetString("internal_fistula_other")
  2938. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2939. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  2940. is_infect, _ := c.GetInt64("is_infect", 0)
  2941. exposed, _ := c.GetFloat("exposed", 0)
  2942. //skin, _ := c.GetInt64("skin", 0)
  2943. skin := c.GetString("skin")
  2944. skin_other := c.GetString("skin_other")
  2945. infect_other := c.GetString("infect_other")
  2946. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2947. machine_type := c.GetString("machine_type")
  2948. puncture_needle := c.GetString("puncture_needle")
  2949. humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  2950. phinholing := c.GetString("pinholing")
  2951. catheter_suture := c.GetString("catheter_suture")
  2952. catheter_suture_other := c.GetString("catheter_suture_other")
  2953. edema := c.GetString("edema")
  2954. urine_volume, _ := c.GetFloat("urine_volume", 0)
  2955. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2956. DialysisCount: dialysis_count,
  2957. EmergencyTreatment: emergency_treatment,
  2958. EmergencyTreatmentOther: emergency_treatment_other,
  2959. DuctusArantii: ductus_arantii,
  2960. VenousCatheterization: venous_catheterization,
  2961. VenousCatheterizationPart: venous_catheterization_part,
  2962. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2963. PunctureWay: puncture_way,
  2964. BloodAccessInternalFistula: blood_access_internal_fistula,
  2965. BloodAccessNoise: blood_access_noise,
  2966. InternalFistulaOther: internal_fistula_other,
  2967. Evaluator: adminUserInfo.AdminUser.Id,
  2968. UserOrgId: adminUserInfo.CurrentOrgId,
  2969. PatientId: patient,
  2970. AssessmentDate: recordDate.Unix(),
  2971. Temperature: temperature,
  2972. PulseFrequency: pulse_frequency,
  2973. SystolicBloodPressure: systolic_blood_pressure,
  2974. DiastolicBloodPressure: diastolic_blood_pressure,
  2975. WeightBefore: weight_before,
  2976. DryWeight: dry_weight,
  2977. AdditionalWeight: additional_weight,
  2978. DialysisInterphase: dialysis_interphase,
  2979. LastPostDialysis: last_post_dialysis,
  2980. SymptomBeforeDialysis: symptom_before_dialysis,
  2981. InternalFistula: internalFistula,
  2982. InternalFistulaSkin: internal_fistula_skin,
  2983. Catheter: catheter,
  2984. CatheterBend: catheter_bend,
  2985. Complication: complication,
  2986. CreatedTime: time.Now().Unix(),
  2987. Status: 1,
  2988. Remark: remark,
  2989. IsHemorrhage: is_hemorrhage,
  2990. Hemorrhage: hemorrhage,
  2991. HemorrhageOther: hemorrhage_other,
  2992. BloodAccessPartId: bloodAccessPartId,
  2993. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2994. PunctureMethod: puncture_method,
  2995. BreathingRate: breathing_rate,
  2996. IsInfect: is_infect,
  2997. Exposed: exposed,
  2998. Skin: skin,
  2999. SkinOther: skin_other,
  3000. InfectOther: infect_other,
  3001. DuctusArantiiOther: ductus_arantii_other,
  3002. MachineType: machine_type,
  3003. PunctureNeedle: puncture_needle,
  3004. HumorExcessiveSymptom: humor_excessive_symptom,
  3005. Phinholing: phinholing,
  3006. CatheterSuture: catheter_suture,
  3007. CatheterSutureOther: catheter_suture_other,
  3008. Edema: edema,
  3009. UrineVolume: urine_volume,
  3010. }
  3011. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  3012. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  3013. if evaluation.ID == 0 { //新增
  3014. if appRole.UserType == 2 || appRole.UserType == 1 {
  3015. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3016. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  3017. } else {
  3018. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  3019. }
  3020. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  3021. if err == nil {
  3022. c.ServeSuccessJSON(map[string]interface{}{
  3023. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  3024. })
  3025. } else {
  3026. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3028. }
  3029. } else { //修改
  3030. //if appRole.UserType == 3 {
  3031. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  3032. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3033. // if getPermissionErr != nil {
  3034. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3035. // return
  3036. // } else if headNursePermission == nil {
  3037. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3038. // return
  3039. // }
  3040. // }
  3041. //}
  3042. if appRole.UserType == 2 || appRole.UserType == 1 {
  3043. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  3044. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  3045. } else {
  3046. if evaluation.Creater == 0 {
  3047. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  3048. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  3049. } else {
  3050. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  3051. }
  3052. }
  3053. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  3054. assessmentBeforeDislysis.ID = evaluation.ID
  3055. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  3056. //
  3057. //新增逻辑
  3058. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3059. var dewater_amount float64
  3060. dewater_amount = 0
  3061. if evaluation.DryWeight > 0 {
  3062. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  3063. if templateInfo.TemplateId == 17 && templateInfo.TemplateId == 22 && templateInfo.TemplateId == 21 {
  3064. dewater_amount = dewater_amount * 1000
  3065. }
  3066. if dewater_amount <= 0 {
  3067. dewater_amount = 0
  3068. }
  3069. } else {
  3070. dewater_amount = 0
  3071. }
  3072. // 计算透析处方的相关超滤量
  3073. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3074. var lastDialysisPrescribe *models.DialysisPrescription
  3075. var dialysisSolution *models.DialysisSolution
  3076. var dialysisPrescribe *models.DialysisPrescription
  3077. var mode_id int64
  3078. if schedual != nil {
  3079. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  3080. if dialysisPrescribe == nil {
  3081. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3082. }
  3083. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  3084. // 获取透析模版
  3085. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  3086. mode_id = schedual.ModeId
  3087. } else {
  3088. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  3089. // 获取透析模版
  3090. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3091. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  3092. if dialysisPrescribe == nil && dialysisSolution != nil {
  3093. mode_id = dialysisSolution.ModeId
  3094. }
  3095. if dialysisPrescribe == nil && dialysisSolution == nil {
  3096. mode_id = 0
  3097. }
  3098. }
  3099. // 插入透析处方
  3100. if dialysisPrescribe == nil && dialysisSolution != nil {
  3101. var newprescribe models.DialysisPrescription
  3102. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  3103. newprescribe.PatientId = dialysisSolution.PatientId
  3104. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  3105. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  3106. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  3107. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  3108. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  3109. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  3110. newprescribe.ModeId = dialysisSolution.ModeId
  3111. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  3112. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  3113. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  3114. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  3115. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  3116. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  3117. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  3118. newprescribe.Glucose = dialysisSolution.Glucose
  3119. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  3120. newprescribe.Kalium = dialysisSolution.Kalium
  3121. newprescribe.Sodium = dialysisSolution.Sodium
  3122. newprescribe.Calcium = dialysisSolution.Calcium
  3123. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  3124. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  3125. newprescribe.Conductivity = dialysisSolution.Conductivity
  3126. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  3127. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  3128. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  3129. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  3130. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  3131. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  3132. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  3133. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  3134. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  3135. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  3136. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  3137. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  3138. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  3139. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  3140. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  3141. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  3142. newprescribe.CreatedTime = time.Now().Unix()
  3143. newprescribe.UpdatedTime = time.Now().Unix()
  3144. newprescribe.RecordDate = recordDate.Unix()
  3145. newprescribe.DewaterAmount = dewater_amount
  3146. newprescribe.TargetUltrafiltration = dewater_amount
  3147. newprescribe.Status = 1
  3148. err := service.AddSigleRecord(&newprescribe)
  3149. if err != nil {
  3150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3151. }
  3152. }
  3153. if dialysisPrescribe == nil && dialysisSolution == nil {
  3154. if lastDialysisPrescribe != nil {
  3155. var newprescribe models.DialysisPrescription
  3156. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  3157. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  3158. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3159. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3160. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3161. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3162. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3163. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3164. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3165. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3166. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3167. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3168. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3169. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3170. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3171. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3172. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3173. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3174. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3175. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3176. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3177. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3178. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3179. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3180. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3181. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3182. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3183. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3184. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3185. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3186. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3187. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3188. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3189. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3190. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3191. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3192. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3193. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3194. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3195. newprescribe.CreatedTime = time.Now().Unix()
  3196. newprescribe.UpdatedTime = time.Now().Unix()
  3197. newprescribe.RecordDate = recordDate.Unix()
  3198. newprescribe.DewaterAmount = dewater_amount
  3199. newprescribe.TargetUltrafiltration = dewater_amount
  3200. newprescribe.Status = 1
  3201. err := service.AddSigleRecord(&newprescribe)
  3202. if err != nil {
  3203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3204. }
  3205. } else {
  3206. var newprescribe models.DialysisPrescription
  3207. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  3208. newprescribe.PatientId = patient
  3209. newprescribe.ModeId = mode_id
  3210. newprescribe.CreatedTime = time.Now().Unix()
  3211. newprescribe.UpdatedTime = time.Now().Unix()
  3212. newprescribe.RecordDate = recordDate.Unix()
  3213. newprescribe.DewaterAmount = dewater_amount
  3214. newprescribe.TargetUltrafiltration = dewater_amount
  3215. newprescribe.Status = 1
  3216. err := service.AddSigleRecord(&newprescribe)
  3217. if err != nil {
  3218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3219. }
  3220. }
  3221. }
  3222. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  3223. if err == nil {
  3224. c.ServeSuccessJSON(map[string]interface{}{
  3225. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  3226. })
  3227. } else {
  3228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3229. }
  3230. }
  3231. }
  3232. func (c *DialysisApiController) PostTreatmentSummary() {
  3233. patient, _ := c.GetInt64("patient", 0)
  3234. recordDateStr := c.GetString("record_date")
  3235. if patient <= 0 {
  3236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3237. return
  3238. }
  3239. adminUserInfo := c.GetAdminUserInfo()
  3240. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3241. if patientInfo.ID == 0 {
  3242. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3243. return
  3244. }
  3245. if len(recordDateStr) == 0 {
  3246. recordDateStr = time.Now().Format("2006-01-02")
  3247. }
  3248. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3249. if parseDateErr != nil {
  3250. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3252. return
  3253. }
  3254. mission := c.GetString("mission")
  3255. dialysis_summary := c.GetString("dialysis_summary")
  3256. nursingRecord := c.GetString("nursing_record")
  3257. specialRecord := c.GetString("special_record")
  3258. sj_nurse := adminUserInfo.AdminUser.Id
  3259. zl_nurse := adminUserInfo.AdminUser.Id
  3260. hd_nurse := adminUserInfo.AdminUser.Id
  3261. xj_nurse := adminUserInfo.AdminUser.Id
  3262. zl_doctor := adminUserInfo.AdminUser.Id
  3263. treatmentSummary := models.TreatmentSummary{
  3264. UserOrgId: adminUserInfo.CurrentOrgId,
  3265. PatientId: patient,
  3266. AssessmentDate: recordDate.Unix(),
  3267. Mission: mission,
  3268. DialysisSummary: dialysis_summary,
  3269. SjNurse: sj_nurse,
  3270. ZlNurse: zl_nurse,
  3271. HdNurse: hd_nurse,
  3272. XjNurse: xj_nurse,
  3273. ZlDoctor: zl_doctor,
  3274. Status: 1,
  3275. CreatedTime: time.Now().Unix(),
  3276. NursingRecord: nursingRecord,
  3277. SpecialRecord: specialRecord,
  3278. }
  3279. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  3280. if tempTreatmentSummary.ID == 0 { //新增
  3281. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  3282. err := service.AddSigleSummaryRecord(&treatmentSummary)
  3283. if err == nil {
  3284. c.ServeSuccessJSON(map[string]interface{}{
  3285. "summary": treatmentSummary,
  3286. })
  3287. } else {
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3289. }
  3290. } else { //修改
  3291. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  3292. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3293. // if getPermissionErr != nil {
  3294. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3295. // return
  3296. // } else if headNursePermission == nil {
  3297. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3298. // return
  3299. // }
  3300. //}
  3301. treatmentSummary.Creater = tempTreatmentSummary.Creater
  3302. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  3303. treatmentSummary.UpdatedTime = time.Now().Unix()
  3304. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  3305. treatmentSummary.ID = tempTreatmentSummary.ID
  3306. err := service.UpdateSummeRecord(&treatmentSummary)
  3307. if err == nil {
  3308. c.ServeSuccessJSON(map[string]interface{}{
  3309. "summary": treatmentSummary,
  3310. })
  3311. } else {
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3313. }
  3314. }
  3315. }
  3316. func (c *DialysisApiController) GetDeviceList() {
  3317. adminUserInfo := c.GetAdminUserInfo()
  3318. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  3319. c.ServeSuccessJSON(map[string]interface{}{
  3320. "device": device,
  3321. })
  3322. }
  3323. func (c *DialysisApiController) GetAllDeviceZone() {
  3324. adminUserInfo := c.GetAdminUserInfo()
  3325. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  3326. if err == nil {
  3327. c.ServeSuccessJSON(map[string]interface{}{
  3328. "zone": zone,
  3329. })
  3330. }
  3331. }
  3332. func (c *DialysisApiController) GetDialysisWatch() {
  3333. page, _ := c.GetInt64("page", 1)
  3334. limit, _ := c.GetInt64("limit", 10)
  3335. schedulType, _ := c.GetInt64("schedul_type", 0)
  3336. startTime, _ := c.GetInt64("schedul_time", 0)
  3337. partitionType, _ := c.GetInt64("partition_type", 0)
  3338. keywords := c.GetString("keywords")
  3339. adminUserInfo := c.GetAdminUserInfo()
  3340. if len(keywords) > 0 {
  3341. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3342. if err == nil {
  3343. c.ServeSuccessJSON(map[string]interface{}{
  3344. "schedule": dialysisSchedule,
  3345. "total": total,
  3346. })
  3347. } else {
  3348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3349. }
  3350. } else {
  3351. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3352. if err == nil {
  3353. c.ServeSuccessJSON(map[string]interface{}{
  3354. "schedule": dialysisSchedule,
  3355. "total": total,
  3356. })
  3357. } else {
  3358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3359. }
  3360. }
  3361. }
  3362. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3363. patientId, _ := c.GetInt64("id", 0)
  3364. record_date, _ := c.GetInt64("record_date", 0)
  3365. adminUserInfo := c.GetAdminUserInfo()
  3366. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3367. var dialysisStatus int64
  3368. if dialysisOrder == nil { //没有透析记录
  3369. dialysisStatus = 0 //未透析
  3370. } else {
  3371. dialysisStatus = dialysisOrder.Stage
  3372. }
  3373. //用户基本信息
  3374. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3375. //接诊评估
  3376. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3377. //透前评估
  3378. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3379. //临时医嘱
  3380. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3381. //双人核对
  3382. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3383. //透析监测
  3384. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3385. //透后评估
  3386. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3387. //透析小结
  3388. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3389. //透析处方
  3390. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3391. if dialysisPrescription.ID == 0 {
  3392. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3393. c.ServeSuccessJSON(map[string]interface{}{
  3394. "patientInfo": schedualPatientInfo,
  3395. "dialysisPrescription": solution,
  3396. "receiverTreatmentAccess": receiverTreatmentAccess,
  3397. "predialysisEvaluation": PredialysisEvaluation,
  3398. "doctorAdvice": DoctorAdvice,
  3399. "doubleCheck": DoubleCheck,
  3400. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3401. "treatmentSummary": TreatmentSummary,
  3402. "monitorRecord": Record,
  3403. "dialysisStatus": dialysisStatus,
  3404. "dialysisOrder": dialysisOrder,
  3405. "isSolution": 1,
  3406. })
  3407. } else {
  3408. c.ServeSuccessJSON(map[string]interface{}{
  3409. "patientInfo": schedualPatientInfo,
  3410. "dialysisPrescription": dialysisPrescription,
  3411. "receiverTreatmentAccess": receiverTreatmentAccess,
  3412. "predialysisEvaluation": PredialysisEvaluation,
  3413. "doctorAdvice": DoctorAdvice,
  3414. "doubleCheck": DoubleCheck,
  3415. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3416. "treatmentSummary": TreatmentSummary,
  3417. "monitorRecord": Record,
  3418. "dialysisStatus": dialysisStatus,
  3419. "dialysisOrder": dialysisOrder,
  3420. "isSolution": 2,
  3421. })
  3422. }
  3423. }
  3424. func (c *DialysisApiController) CreateDoctorAdvice() {
  3425. patient, _ := c.GetInt64("id", 0)
  3426. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3427. record_date, _ := c.GetInt64("record_date", 0)
  3428. if patient <= 0 {
  3429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3430. return
  3431. }
  3432. adminUserInfo := c.GetAdminUserInfo()
  3433. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3434. if patientInfo.ID == 0 {
  3435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3436. return
  3437. }
  3438. var advice models.DoctorAdvice
  3439. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3440. if code > 0 {
  3441. c.ServeFailJSONWithSGJErrorCode(code)
  3442. return
  3443. }
  3444. if advice.ParentId > 0 {
  3445. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3446. if old.ID == 0 || old.PatientId != patient {
  3447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3448. return
  3449. }
  3450. if old.StopState == 1 || old.ExecutionState == 1 {
  3451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3452. return
  3453. }
  3454. if old.ParentId > 0 {
  3455. advice.ParentId = old.ParentId
  3456. }
  3457. advice.StartTime = old.StartTime
  3458. advice.AdviceDoctor = old.AdviceDoctor
  3459. advice.DeliveryWay = old.DeliveryWay
  3460. advice.ExecutionFrequency = old.ExecutionFrequency
  3461. }
  3462. advice.RecordDate = record_date
  3463. advice.DialysisOrderId = dialysis_id
  3464. advice.Status = 1
  3465. advice.CreatedTime = time.Now().Unix()
  3466. advice.UpdatedTime = time.Now().Unix()
  3467. advice.StopState = 2
  3468. advice.ExecutionState = 2
  3469. advice.AdviceType = 2
  3470. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3471. advice.PatientId = patient
  3472. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3473. err := service.CreateDoctorAdvice(&advice)
  3474. if err != nil {
  3475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3476. return
  3477. }
  3478. for _, subAdvice := range subAdivice {
  3479. subAdvice.ParentId = advice.ID
  3480. subAdvice.PatientId = patient
  3481. subAdvice.RecordDate = record_date
  3482. subAdvice.CreatedTime = time.Now().Unix()
  3483. subAdvice.UpdatedTime = time.Now().Unix()
  3484. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3485. }
  3486. service.CreateSubDoctorAdvice(subAdivice)
  3487. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3488. c.ServeSuccessJSON(map[string]interface{}{
  3489. "msg": "ok",
  3490. "advice": advice,
  3491. "subAdvice": subAdivices,
  3492. })
  3493. return
  3494. }
  3495. func (c *DialysisApiController) EditDoctorAdvice() {
  3496. patient, _ := c.GetInt64("patient", 0)
  3497. id, _ := c.GetInt64("id", 0)
  3498. parent_id, _ := c.GetInt64("parent_id", 0)
  3499. execution_time := c.GetString("execution_time")
  3500. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3501. // checker, _ := c.GetInt64("checker", 0)
  3502. if id <= 0 || patient <= 0 {
  3503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3504. return
  3505. }
  3506. adminUserInfo := c.GetAdminUserInfo()
  3507. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3508. if advice.ID == 0 || advice.PatientId != patient {
  3509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3510. return
  3511. }
  3512. if len(execution_time) <= 0 {
  3513. utils.ErrorLog("execution_time")
  3514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3515. return
  3516. }
  3517. execution_staff := adminUserInfo.AdminUser.Id
  3518. checker := adminUserInfo.AdminUser.Id
  3519. timeLayout2 := "2006-01-02 15:04"
  3520. loc, _ := time.LoadLocation("Local")
  3521. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3522. if errs != nil {
  3523. utils.ErrorLog(errs.Error())
  3524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3525. return
  3526. }
  3527. advices := models.DoctorAdvice{
  3528. ExecutionStaff: execution_staff,
  3529. ExecutionTime: theTime.Unix(),
  3530. Checker: checker,
  3531. UpdatedTime: time.Now().Unix(),
  3532. }
  3533. var err error
  3534. if parent_id > 0 {
  3535. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3536. } else {
  3537. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3538. }
  3539. if err != nil {
  3540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3541. return
  3542. }
  3543. c.ServeSuccessJSON(map[string]interface{}{
  3544. "msg": "ok",
  3545. "advice": advice,
  3546. })
  3547. return
  3548. }
  3549. func (c *DialysisApiController) GetDoctorAdvice() {
  3550. patient, _ := c.GetInt64("patient_id", 0)
  3551. parent_id, _ := c.GetInt64("parent_id", 0)
  3552. adviceId, _ := c.GetInt64("id", 0)
  3553. if patient <= 0 {
  3554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3555. return
  3556. }
  3557. dminUserInfo := c.GetAdminUserInfo()
  3558. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3559. if patientInfo.ID == 0 {
  3560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3561. return
  3562. }
  3563. var subAdvice []*models.DoctorAdvice
  3564. var advice models.DoctorAdvice
  3565. if parent_id > 0 {
  3566. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3567. if advice.ID == 0 || advice.PatientId != patient {
  3568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3569. return
  3570. }
  3571. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3572. } else {
  3573. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3574. if advice.ID == 0 || advice.PatientId != patient {
  3575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3576. return
  3577. }
  3578. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3579. }
  3580. c.ServeSuccessJSON(map[string]interface{}{
  3581. "msg": "ok",
  3582. "advice": advice,
  3583. "subAdvice": subAdvice,
  3584. })
  3585. }
  3586. func (this *DialysisApiController) DelMonitor() {
  3587. recordID, _ := this.GetInt64("record_id")
  3588. patientID, _ := this.GetInt64("patient_id")
  3589. if recordID <= 0 || patientID <= 0 {
  3590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3591. return
  3592. }
  3593. adminInfo := this.GetAdminUserInfo()
  3594. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3595. if getPatientErr != nil {
  3596. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3597. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3598. return
  3599. } else if patient == nil {
  3600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3601. return
  3602. }
  3603. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3604. if getMonitorErr != nil {
  3605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3606. return
  3607. }
  3608. //if monitor != nil {
  3609. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3610. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3611. // if getPermissionErr != nil {
  3612. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3613. // return
  3614. // } else if headNursePermission == nil {
  3615. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3616. // return
  3617. // }
  3618. // }
  3619. //}
  3620. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3621. if err != nil {
  3622. this.ErrorLog("删除透析监测记录失败:%v", err)
  3623. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3624. return
  3625. }
  3626. this.ServeSuccessJSON(map[string]interface{}{
  3627. "record_id": monitor.ID,
  3628. })
  3629. }
  3630. func (c *DialysisApiController) CreateMonitor() {
  3631. patient, _ := c.GetInt64("id", 0)
  3632. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3633. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3634. operate_time, _ := c.GetInt64("operate_time", 0)
  3635. // monitoring_time := c.GetString("monitoring_time")
  3636. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3637. breathing_rated, _ := c.GetFloat("breathing_rated", 0)
  3638. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3639. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3640. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3641. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3642. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3643. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3644. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3645. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3646. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3647. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3648. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3649. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3650. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3651. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3652. temperature, _ := c.GetFloat("temperature", 0)
  3653. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3654. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3655. conductivity, _ := c.GetFloat("conductivity", 0)
  3656. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3657. heparin, _ := c.GetFloat("heparin", 0)
  3658. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3659. ktv, _ := c.GetFloat("ktv", 0)
  3660. symptom := c.GetString("symptom")
  3661. dispose := c.GetString("dispose")
  3662. result := c.GetString("results")
  3663. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3664. monitoring_date = monitoring_date / 1000
  3665. // operate_time = operate_time / 1000
  3666. if patient <= 0 {
  3667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3668. return
  3669. }
  3670. adminUserInfo := c.GetAdminUserInfo()
  3671. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3672. if patientInfo.ID == 0 {
  3673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3674. return
  3675. }
  3676. monitorRecord := models.MonitoringRecord{
  3677. PatientId: patient,
  3678. MonitoringDate: monitoring_date,
  3679. DialysisOrderId: dialysis_order_id,
  3680. OperateTime: operate_time,
  3681. // MonitoringTime: monitoring_time,
  3682. PulseFrequency: pulse_frequency,
  3683. BreathingRate: breathing_rated,
  3684. SystolicBloodPressure: systolic_blood_pressure,
  3685. DiastolicBloodPressure: diastolic_blood_pressure,
  3686. BloodPressureType: blood_pressure_type,
  3687. BloodFlowVolume: blood_flow_volume,
  3688. VenousPressure: venous_pressure,
  3689. VenousPressureType: venous_pressure_type,
  3690. TransmembranePressure: transmembrane_pressure,
  3691. TransmembranePressureType: transmembrane_pressure_type,
  3692. UltrafiltrationRate: ultrafiltration_rate,
  3693. UltrafiltrationVolume: ultrafiltration_volume,
  3694. SodiumConcentration: sodium_concentration,
  3695. ArterialPressure: arterial_pressure,
  3696. ArterialPressureType: arterial_pressure_type,
  3697. DialysateTemperature: dialysate_temperature,
  3698. Temperature: temperature,
  3699. ReplacementRate: replacement_rate,
  3700. DisplacementQuantity: displacement_quantity,
  3701. Ktv: ktv,
  3702. Symptom: symptom,
  3703. Dispose: dispose,
  3704. Result: result,
  3705. MonitoringNurse: monitoring_nurse,
  3706. Status: 1,
  3707. CreatedTime: time.Now().Unix(),
  3708. UpdatedTime: time.Now().Unix(),
  3709. UserOrgId: adminUserInfo.CurrentOrgId,
  3710. Conductivity: conductivity,
  3711. DisplacementFlowQuantity: displacement_flow_quantity,
  3712. Heparin: heparin,
  3713. DialysateFlow: dialysate_flow,
  3714. }
  3715. err := service.CreateMonitor(&monitorRecord)
  3716. if err != nil {
  3717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3718. return
  3719. }
  3720. c.ServeSuccessJSON(map[string]interface{}{
  3721. "msg": "ok",
  3722. "monitor": monitorRecord,
  3723. })
  3724. return
  3725. }
  3726. // 已弃用
  3727. // func (c *DialysisApiController) CreateRecordData() {
  3728. // patient, _ := c.GetInt64("id", 0)
  3729. // status, _ := c.GetInt64("status", 0)
  3730. // now := time.Now()
  3731. // year, month, day := now.Date()
  3732. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3733. // todayTimeStamp := today_time.Unix()
  3734. // if patient <= 0 {
  3735. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3736. // return
  3737. // }
  3738. // adminUserInfo := c.GetAdminUserInfo()
  3739. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3740. // if patientInfo.ID == 0 {
  3741. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3742. // return
  3743. // }
  3744. // record := &models.DialysisOrder{
  3745. // DialysisDate: todayTimeStamp,
  3746. // UserOrgId: adminUserInfo.CurrentOrgId,
  3747. // PatientId: patient,
  3748. // Stage: status,
  3749. // Status: 1,
  3750. // CreatedTime: time.Now().Unix(),
  3751. // UpdatedTime: time.Now().Unix(),
  3752. // }
  3753. // if status == 1 {
  3754. // //创建透析记录
  3755. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3756. // if err == nil {
  3757. // c.ServeSuccessJSON(map[string]interface{}{
  3758. // "dialysisOrder": record,
  3759. // })
  3760. // } else {
  3761. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3762. // }
  3763. // } else {
  3764. // record_id, _ := c.GetInt64("record_id", 0)
  3765. // //修改透析记录状态
  3766. // errs := service.ModifyDialysisRecord(record_id)
  3767. // //结束时候透析次数加1
  3768. // service.UpdateSolutionByPatientId(patient)
  3769. // if errs == nil {
  3770. // c.ServeSuccessJSON(map[string]interface{}{
  3771. // "dialysisOrder": record,
  3772. // })
  3773. // } else {
  3774. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3775. // }
  3776. // }
  3777. // }
  3778. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3779. dataBody := make(map[string]interface{}, 0)
  3780. err := json.Unmarshal(data, &dataBody)
  3781. if err != nil {
  3782. utils.ErrorLog(err.Error())
  3783. code = enums.ErrorCodeParamWrong
  3784. return
  3785. }
  3786. timeLayout := "2006-01-02 "
  3787. timeLayout2 := "2006-01-02 15:04"
  3788. loc, _ := time.LoadLocation("Local")
  3789. if action == "create" {
  3790. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3791. utils.ErrorLog("advice_type")
  3792. code = enums.ErrorCodeParamWrong
  3793. return
  3794. }
  3795. adviceType := int64(dataBody["advice_type"].(float64))
  3796. if adviceType != 1 && adviceType != 2 {
  3797. utils.ErrorLog("advice_type != 1&&2")
  3798. code = enums.ErrorCodeParamWrong
  3799. return
  3800. }
  3801. advice.AdviceType = adviceType
  3802. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3803. utils.ErrorLog("advice_date")
  3804. code = enums.ErrorCodeParamWrong
  3805. return
  3806. }
  3807. adviceDate, _ := dataBody["advice_date"].(string)
  3808. if len(adviceDate) == 0 {
  3809. utils.ErrorLog("len(adviceDate) == 0")
  3810. code = enums.ErrorCodeParamWrong
  3811. return
  3812. }
  3813. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3814. if err != nil {
  3815. utils.ErrorLog(err.Error())
  3816. code = enums.ErrorCodeParamWrong
  3817. return
  3818. }
  3819. advice.AdviceDate = theTime.Unix()
  3820. }
  3821. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3822. utils.ErrorLog("start_time")
  3823. code = enums.ErrorCodeParamWrong
  3824. return
  3825. }
  3826. startDate, _ := dataBody["start_time"].(string)
  3827. if len(startDate) == 0 {
  3828. utils.ErrorLog("len(startDate) == 0")
  3829. code = enums.ErrorCodeParamWrong
  3830. return
  3831. }
  3832. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3833. if err != nil {
  3834. utils.ErrorLog(err.Error())
  3835. code = enums.ErrorCodeParamWrong
  3836. return
  3837. }
  3838. advice.StartTime = theTime.Unix()
  3839. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3840. utils.ErrorLog("advice_name")
  3841. code = enums.ErrorCodeParamWrong
  3842. return
  3843. }
  3844. adviceName, _ := dataBody["advice_name"].(string)
  3845. if len(adviceName) == 0 {
  3846. utils.ErrorLog("len(advice_name) == 0")
  3847. code = enums.ErrorCodeParamWrong
  3848. return
  3849. }
  3850. advice.AdviceName = adviceName
  3851. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3852. utils.ErrorLog("delivery_way")
  3853. code = enums.ErrorCodeParamWrong
  3854. return
  3855. }
  3856. deliveryWay, _ := dataBody["delivery_way"].(string)
  3857. if len(deliveryWay) == 0 {
  3858. utils.ErrorLog("len(deliveryWay) == 0")
  3859. code = enums.ErrorCodeParamWrong
  3860. return
  3861. }
  3862. advice.DeliveryWay = deliveryWay
  3863. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3864. utils.ErrorLog("execution_frequency")
  3865. code = enums.ErrorCodeParamWrong
  3866. return
  3867. }
  3868. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3869. if len(execution_frequency) == 0 {
  3870. utils.ErrorLog("len(execution_frequency) == 0")
  3871. code = enums.ErrorCodeParamWrong
  3872. return
  3873. }
  3874. advice.ExecutionFrequency = execution_frequency
  3875. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3876. adviceDsc, _ := dataBody["advice_desc"].(string)
  3877. advice.AdviceDesc = adviceDsc
  3878. }
  3879. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3880. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3881. advice.DrugSpecUnit = drugSpecUnit
  3882. }
  3883. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3884. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3885. advice.SingleDose = singleDose
  3886. }
  3887. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3888. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3889. advice.SingleDoseUnit = singleDoseUnit
  3890. }
  3891. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3892. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3893. advice.PrescribingNumber = prescribingNumber
  3894. }
  3895. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3896. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3897. advice.PrescribingNumberUnit = prescribingNumberUnit
  3898. }
  3899. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3900. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3901. if len(thisContagions) > 0 {
  3902. for _, item := range thisContagions {
  3903. items := item.(map[string]interface{})
  3904. advice_name, _ := items["advice_name"].(string)
  3905. advice_desc, _ := items["advice_desc"].(string)
  3906. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3907. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3908. single_dose_unit, _ := items["single_dose_unit"].(string)
  3909. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3910. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3911. advice := &models.DoctorAdvice{
  3912. AdviceName: advice_name,
  3913. AdviceDesc: advice_desc,
  3914. SingleDose: single_dose,
  3915. SingleDoseUnit: single_dose_unit,
  3916. DrugSpecUnit: drug_spec_unit,
  3917. PrescribingNumber: prescribing_number,
  3918. PrescribingNumberUnit: prescribing_number_unit,
  3919. }
  3920. subAdvice = append(subAdvice, advice)
  3921. }
  3922. }
  3923. }
  3924. return
  3925. }
  3926. func (c *DialysisApiController) GetDialysisOrder() {
  3927. xtno := c.GetString("xtno")
  3928. xtdate := c.GetString("xtdate")
  3929. timeLayout := "2006-01-02"
  3930. loc, _ := time.LoadLocation("Local")
  3931. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3932. if err != nil {
  3933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3934. return
  3935. }
  3936. xttime := theTime.Unix()
  3937. operatorIDs := make([]int64, 0)
  3938. adminUserInfo := c.GetAdminUserInfo()
  3939. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3940. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  3941. //透析单
  3942. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3943. if dialysisOrder != nil {
  3944. if dialysisOrder.FinishNurse > 0 {
  3945. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3946. }
  3947. if dialysisOrder.StartNurse > 0 {
  3948. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3949. }
  3950. }
  3951. //透前评估
  3952. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3953. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3954. //透后评估
  3955. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3956. if AssessmentAfterDislysis.Modifier > 0 {
  3957. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3958. }
  3959. //上次透前评估
  3960. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3961. //透析处方
  3962. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3963. if dialysisPrescription.PrescriptionDoctor > 0 {
  3964. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3965. }
  3966. //获取病人的透析模式
  3967. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3968. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3969. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3970. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3971. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3972. //获取透析处方
  3973. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3974. //获取临时医嘱
  3975. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3976. //获取医嘱内容
  3977. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3978. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3979. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3980. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3981. //获取上次的透后体重
  3982. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3983. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3984. //获取透析次数
  3985. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3986. if len(DoctorAdvice) > 0 {
  3987. for _, item := range DoctorAdvice {
  3988. if item.AdviceDoctor > 0 {
  3989. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3990. }
  3991. if item.ExecutionStaff > 0 {
  3992. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3993. }
  3994. if item.Checker > 0 {
  3995. operatorIDs = append(operatorIDs, item.Checker)
  3996. }
  3997. }
  3998. }
  3999. //透析监测
  4000. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4001. //透析检测
  4002. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4003. //透析小结
  4004. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4005. //接诊评估
  4006. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4007. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4008. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4009. patientInfo.TotalDialysis = dialysis_count
  4010. //相关操作对应的操作人
  4011. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  4012. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  4013. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  4014. //获取当前日期月份的第一天
  4015. firstmonth := service.GetFirstDateOfMonth(theTime)
  4016. firstMonthDate := firstmonth.Unix()
  4017. //获取当前月份的病人透析次数
  4018. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  4019. c.ServeSuccessJSON(map[string]interface{}{
  4020. "xtdate": xtdate,
  4021. "users": adminUser,
  4022. "patientInfo": patientInfo,
  4023. "PredialysisEvaluation": PredialysisEvaluation,
  4024. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4025. "dialysisPrescription": dialysisPrescription,
  4026. "advices": DoctorAdvice,
  4027. "monitors": Record,
  4028. "summary": TreatmentSummary,
  4029. "receiverTreatmentAccess": receiverTreatmentAccess,
  4030. "dialysisOrder": dialysisOrder,
  4031. "operators": operators,
  4032. "org_template_info": templateInfo,
  4033. "check": check,
  4034. "schedule": schedule,
  4035. "dialysisway": dialysisway,
  4036. "order": order,
  4037. "doctorAdvice": doctorAdvice,
  4038. "doctor": doctor,
  4039. "nurse": nurse,
  4040. "doctorAdevieInfo": doctorAdevieInfo,
  4041. "total": total,
  4042. "startNuse": startNuse,
  4043. "DoctorName": DoctorName,
  4044. "assessmentAfterDislysis": assessmentAfterDislysis,
  4045. "predialysName": predialysName,
  4046. "FinishNuse": FinishNuse,
  4047. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4048. "dialysiscount": dialysiscount,
  4049. })
  4050. }
  4051. //
  4052. func (c *DialysisApiController) GetLongAdvice() {
  4053. patient_id, _ := c.GetInt64("patient_id")
  4054. adminUserInfo := c.GetAdminUserInfo()
  4055. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4056. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4057. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4058. c.ServeSuccessJSON(map[string]interface{}{
  4059. "status": "1",
  4060. })
  4061. return
  4062. } else { //开启推送提醒
  4063. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4064. var advice_three []*models.DoctorAdvice
  4065. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4066. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id)
  4067. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id)
  4068. for _, advice := range advices {
  4069. if advice.FrequencyType == 3 {
  4070. t := time.Now()
  4071. week := int(t.Weekday())
  4072. switch week {
  4073. case 1:
  4074. if strings.Index(advice.WeekDay, "周一") == -1 {
  4075. advice_three = append(advice_three, advice)
  4076. }
  4077. break
  4078. case 2:
  4079. if strings.Index(advice.WeekDay, "周二") == -1 {
  4080. advice_three = append(advice_three, advice)
  4081. }
  4082. break
  4083. case 3:
  4084. if strings.Index(advice.WeekDay, "周三") == -1 {
  4085. advice_three = append(advice_three, advice)
  4086. }
  4087. break
  4088. case 4:
  4089. if strings.Index(advice.WeekDay, "周四") == -1 {
  4090. advice_three = append(advice_three, advice)
  4091. }
  4092. break
  4093. case 5:
  4094. if strings.Index(advice.WeekDay, "周五") == -1 {
  4095. advice_three = append(advice_three, advice)
  4096. }
  4097. break
  4098. case 6:
  4099. if strings.Index(advice.WeekDay, "周六") == -1 {
  4100. advice_three = append(advice_three, advice)
  4101. }
  4102. break
  4103. case 0:
  4104. if strings.Index(advice.WeekDay, "周日") == -1 {
  4105. advice_three = append(advice_three, advice)
  4106. }
  4107. break
  4108. }
  4109. }
  4110. }
  4111. for _, advice := range advices_two {
  4112. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4113. now := p.Unix()
  4114. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4115. dayStr2 := "-" + dayStr
  4116. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4117. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4118. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4119. for _, ad := range advices {
  4120. advice_three = append(advice_three, ad)
  4121. }
  4122. }
  4123. if err == nil {
  4124. c.ServeSuccessJSON(map[string]interface{}{
  4125. "status": "2",
  4126. "advices": advices,
  4127. "advices_two": RemoveRepeatedElement(advice_three),
  4128. "is_open_remind": config.IsOpenRemind,
  4129. })
  4130. }
  4131. }
  4132. }
  4133. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4134. newArr = make([]*models.DoctorAdvice, 0)
  4135. for i := 0; i < len(arr); i++ {
  4136. repeat := false
  4137. for j := i + 1; j < len(arr); j++ {
  4138. if arr[i].ID == arr[j].ID {
  4139. repeat = true
  4140. break
  4141. }
  4142. }
  4143. if !repeat {
  4144. newArr = append(newArr, arr[i])
  4145. }
  4146. }
  4147. return
  4148. }
  4149. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4150. patient, _ := c.GetInt64("id", 0)
  4151. groupNo, _ := c.GetInt64("groupno", 0)
  4152. if patient <= 0 {
  4153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4154. return
  4155. }
  4156. adminUserInfo := c.GetAdminUserInfo()
  4157. dataBody := make(map[string]interface{}, 0)
  4158. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4159. if err != nil {
  4160. utils.ErrorLog(err.Error())
  4161. return
  4162. }
  4163. utils.ErrorLog("%v", dataBody)
  4164. timeLayout := "2006-01-02 15:04"
  4165. loc, _ := time.LoadLocation("Local")
  4166. timeLayout2 := "2006-01-02"
  4167. loc2, _ := time.LoadLocation("Local")
  4168. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4169. utils.ErrorLog("advice_type")
  4170. return
  4171. }
  4172. adviceType := int64(2)
  4173. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4174. utils.ErrorLog("advice_date")
  4175. return
  4176. }
  4177. adviceDate, _ := dataBody["advice_date"].(string)
  4178. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4179. AdviceDate := theTime.Unix()
  4180. RecordDate := theTime.Unix()
  4181. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4182. utils.ErrorLog("start_time")
  4183. return
  4184. }
  4185. startTime, _ := dataBody["start_time"].(string)
  4186. if len(startTime) == 0 {
  4187. utils.ErrorLog("len(start_time) == 0")
  4188. return
  4189. }
  4190. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4191. if err != nil {
  4192. utils.ErrorLog(err.Error())
  4193. return
  4194. }
  4195. StartTime := theTime.Unix()
  4196. Remark := ""
  4197. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4198. remark, _ := dataBody["remark"].(string)
  4199. Remark = remark
  4200. }
  4201. var advices []*models.GroupAdvice
  4202. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4203. utils.ErrorLog("advices")
  4204. return
  4205. }
  4206. adviceNames := dataBody["advices"].([]interface{})
  4207. for _, adviceNameMap := range adviceNames {
  4208. adviceNameM := adviceNameMap.(map[string]interface{})
  4209. var advice models.GroupAdvice
  4210. advice.Remark = Remark
  4211. advice.AdviceType = adviceType
  4212. advice.StartTime = StartTime
  4213. advice.AdviceDate = AdviceDate
  4214. advice.RecordDate = RecordDate
  4215. advice.Status = 1
  4216. advice.CreatedTime = time.Now().Unix()
  4217. advice.UpdatedTime = time.Now().Unix()
  4218. advice.StopState = 2
  4219. advice.ExecutionState = 2
  4220. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4221. advice.PatientId = patient
  4222. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4223. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4224. utils.ErrorLog("advice_name")
  4225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4226. return
  4227. }
  4228. adviceName, _ := adviceNameM["advice_name"].(string)
  4229. if len(adviceName) == 0 {
  4230. utils.ErrorLog("len(advice_name) == 0")
  4231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4232. return
  4233. }
  4234. advice.AdviceName = adviceName
  4235. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4236. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4237. advice.DrugSpec = drugSpec
  4238. }
  4239. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4240. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4241. advice.AdviceDesc = adviceDesc
  4242. }
  4243. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4244. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4245. advice.DrugSpecUnit = drugSpecUnit
  4246. }
  4247. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4248. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4249. // advice.SingleDose = singleDose
  4250. //}
  4251. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4252. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4253. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4254. }
  4255. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4256. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4257. advice.SingleDoseUnit = singleDoseUnit
  4258. }
  4259. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4260. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4261. // advice.PrescribingNumber = prescribingNumber
  4262. //}
  4263. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4264. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4265. }
  4266. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4267. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4268. advice.PrescribingNumberUnit = prescribingNumberUnit
  4269. }
  4270. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4271. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4272. advice.DeliveryWay = deliveryWay
  4273. }
  4274. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4275. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4276. advice.ExecutionFrequency = executionFrequency
  4277. }
  4278. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4279. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4280. advice.FrequencyType = frequency_type
  4281. }
  4282. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4283. day_count := int64(adviceNameM["day_count"].(float64))
  4284. advice.DayCount = day_count
  4285. }
  4286. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4287. week_day, _ := adviceNameM["week_day"].(string)
  4288. advice.WeekDay = week_day
  4289. }
  4290. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4291. template_id, _ := adviceNameM["template_id"].(string)
  4292. advice.TemplateId = template_id
  4293. }
  4294. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4295. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4296. advice.ExecutionFrequency = executionFrequency
  4297. }
  4298. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4299. children := adviceNameM["child"].([]interface{})
  4300. if len(children) > 0 {
  4301. for _, childrenMap := range children {
  4302. childMap := childrenMap.(map[string]interface{})
  4303. var child models.GroupAdvice
  4304. child.Remark = Remark
  4305. child.AdviceType = adviceType
  4306. child.StartTime = StartTime
  4307. child.AdviceDate = AdviceDate
  4308. child.RecordDate = RecordDate
  4309. child.Status = 1
  4310. child.CreatedTime = time.Now().Unix()
  4311. child.UpdatedTime = time.Now().Unix()
  4312. child.StopState = 2
  4313. child.ExecutionState = 2
  4314. child.UserOrgId = adminUserInfo.CurrentOrgId
  4315. child.PatientId = patient
  4316. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4317. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4318. utils.ErrorLog("child advice_name")
  4319. return
  4320. }
  4321. childAdviceName, _ := childMap["advice_name"].(string)
  4322. if len(childAdviceName) == 0 {
  4323. utils.ErrorLog("len(child advice_name) == 0")
  4324. return
  4325. }
  4326. child.AdviceName = childAdviceName
  4327. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4328. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4329. child.AdviceDesc = childAdviceDesc
  4330. }
  4331. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4332. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4333. child.DrugSpec = childDrugSpec
  4334. }
  4335. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4336. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4337. child.DrugSpecUnit = childDrugSpecUnit
  4338. }
  4339. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4340. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4341. child.SingleDose = childSingleDose
  4342. }
  4343. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4344. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4345. child.SingleDoseUnit = childSingleDoseUnit
  4346. }
  4347. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4348. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4349. child.PrescribingNumber = childPrescribingNumber
  4350. }
  4351. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4352. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4353. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4354. }
  4355. child.DeliveryWay = advice.DeliveryWay
  4356. child.ExecutionFrequency = advice.ExecutionFrequency
  4357. advice.Children = append(advice.Children, &child)
  4358. }
  4359. }
  4360. }
  4361. advices = append(advices, &advice)
  4362. }
  4363. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4364. if err != nil {
  4365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4366. return
  4367. }
  4368. c.ServeSuccessJSON(map[string]interface{}{
  4369. "msg": "ok",
  4370. "advices": list,
  4371. })
  4372. return
  4373. }
  4374. func (c *DialysisApiController) GetSolution() {
  4375. patient_id, _ := c.GetInt64("patient_id")
  4376. mode_id, _ := c.GetInt64("mode_id")
  4377. adminUserInfo := c.GetAdminUserInfo()
  4378. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4379. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4380. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.CurrentOrgId, mode_id)
  4381. if err != nil {
  4382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4383. return
  4384. }
  4385. c.ServeSuccessJSON(map[string]interface{}{
  4386. "solution": solution,
  4387. "prescription": prescription,
  4388. "system_prescription": system_prescription,
  4389. })
  4390. }
  4391. func (c *DialysisApiController) GetSchedule() {
  4392. schedual_type, _ := c.GetInt64("schedual_type")
  4393. adminUserInfo := c.GetAdminUserInfo()
  4394. timeLayout := "2006-01-02 15:04:05"
  4395. date := time.Now().Format("2006-01-02") + " 00:00:00"
  4396. loc, _ := time.LoadLocation("Local")
  4397. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4398. scheduleTime := theStartTime.Unix()
  4399. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4400. c.ServeSuccessJSON(map[string]interface{}{
  4401. "number": deviceNumber,
  4402. })
  4403. }
  4404. func (this *DialysisApiController) GetTodayMonitor() {
  4405. thisTime := time.Now()
  4406. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4407. timeLayout := "2006-01-02 15:04:05"
  4408. loc, _ := time.LoadLocation("Local")
  4409. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4410. theAssessmentDateTime := theStartTime.Unix()
  4411. patientID, _ := this.GetInt64("patient_id")
  4412. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4413. adminInfo := this.GetAdminUserInfo()
  4414. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4415. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4416. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4417. var ultrafiltration_rate float64
  4418. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4419. if prescription.ID > 0 {
  4420. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4421. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4422. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4423. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4424. record.UltrafiltrationRate = ultrafiltration_rate
  4425. }
  4426. if template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.CurrentOrgId == 9538
  4427. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4428. record.UltrafiltrationRate = ultrafiltration_rate
  4429. }
  4430. // 只针对方济医院
  4431. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4432. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4433. ultrafiltration_rate = value
  4434. record.UltrafiltrationRate = ultrafiltration_rate
  4435. }
  4436. }
  4437. }
  4438. // record.UltrafiltrationRate = ultrafiltration_rate
  4439. record.UltrafiltrationVolume = 0
  4440. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4441. if ultrafiltration_rate > 0 {
  4442. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4443. record.UltrafiltrationVolume = value
  4444. }
  4445. }
  4446. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 {
  4447. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  4448. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4449. record.UltrafiltrationVolume = ultrafiltration_volume
  4450. }
  4451. }
  4452. this.ServeSuccessJSON(map[string]interface{}{
  4453. "monitor": record,
  4454. })
  4455. }
  4456. func (c *DialysisApiController) UploadDryWeight() {
  4457. patient_id, _ := c.GetInt64("id")
  4458. dry_weight, _ := c.GetFloat("dry_weight")
  4459. doctor_id, _ := c.GetInt64("doctor_id")
  4460. remark := c.GetString("remark")
  4461. adminUserInfo := c.GetAdminUserInfo()
  4462. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4463. fmt.Println(err)
  4464. if err == gorm.ErrRecordNotFound {
  4465. dryWeight := &models.SgjPatientDryweight{
  4466. PatientId: patient_id,
  4467. DryWeight: dry_weight,
  4468. Remakes: remark,
  4469. Ctime: time.Now().Unix(),
  4470. Mtime: time.Now().Unix(),
  4471. Creator: doctor_id,
  4472. Status: 1,
  4473. UserOrgId: adminUserInfo.CurrentOrgId,
  4474. AdjustedValue: "/",
  4475. UserId: adminUserInfo.AdminUser.Id,
  4476. }
  4477. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4478. if createErr == nil {
  4479. c.ServeSuccessJSON(map[string]interface{}{
  4480. "msg": "提交成功",
  4481. "weight": dryWeight,
  4482. })
  4483. }
  4484. } else {
  4485. dryWeight := &models.SgjPatientDryweight{
  4486. PatientId: patient_id,
  4487. DryWeight: dry_weight,
  4488. Remakes: remark,
  4489. Ctime: time.Now().Unix(),
  4490. Mtime: time.Now().Unix(),
  4491. Creator: doctor_id,
  4492. Status: 1,
  4493. UserOrgId: adminUserInfo.CurrentOrgId,
  4494. AdjustedValue: "/",
  4495. UserId: adminUserInfo.AdminUser.Id,
  4496. }
  4497. var value float64
  4498. value = dry_weight - weightAdjust.DryWeight
  4499. fmt.Println(value)
  4500. if value < 0 {
  4501. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4502. } else if value == 0 {
  4503. dryWeight.AdjustedValue = "/"
  4504. } else if value > 0 {
  4505. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4506. }
  4507. fmt.Println(value)
  4508. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4509. if createErr == nil {
  4510. c.ServeSuccessJSON(map[string]interface{}{
  4511. "msg": "提交成功",
  4512. "weight": dryWeight,
  4513. })
  4514. }
  4515. }
  4516. }
  4517. func (this *DialysisApiController) GetFuncPurview() {
  4518. adminUserInfo := this.GetAdminUserInfo()
  4519. user_id := adminUserInfo.AdminUser.Id
  4520. app_id := adminUserInfo.CurrentAppId
  4521. org_id := adminUserInfo.CurrentOrgId
  4522. create_url := this.GetString("create_url")
  4523. modify_url := this.GetString("modify_url")
  4524. modify_other_url := this.GetString("modify_other_url")
  4525. del_url := this.GetString("del_url")
  4526. del_other_url := this.GetString("del_other_url")
  4527. exce_url := this.GetString("exce_url")
  4528. check_url := this.GetString("check_url")
  4529. modify_exce_url := this.GetString("modify_exce_url")
  4530. module, _ := this.GetInt64("module", 0)
  4531. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4532. var is_has_create bool
  4533. var is_has_modify bool
  4534. var is_has_modify_other bool
  4535. var is_has_del bool
  4536. var is_has_del_other bool
  4537. var is_has_exce bool
  4538. var is_has_check bool
  4539. var is_has_modify_exce bool
  4540. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4541. if adminUserInfo.AdminUser.Id != org.Creator {
  4542. if app_role != nil {
  4543. if len(app_role.RoleIds) > 0 {
  4544. roles := strings.Split(app_role.RoleIds, ",")
  4545. var userRolePurviews string
  4546. for _, item := range roles {
  4547. role_id, _ := strconv.ParseInt(item, 10, 64)
  4548. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4549. if len(userRolePurviews) == 0 {
  4550. userRolePurviews = purviews
  4551. } else {
  4552. userRolePurviews = userRolePurviews + "," + purviews
  4553. }
  4554. }
  4555. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4556. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4557. for _, item := range funcPurviews {
  4558. //for _, url := range strings.Split(item.Urlfor,","){
  4559. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4560. is_has_create = true
  4561. }
  4562. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4563. is_has_modify = true
  4564. }
  4565. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4566. is_has_modify_other = true
  4567. }
  4568. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4569. is_has_del = true
  4570. }
  4571. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4572. is_has_del_other = true
  4573. }
  4574. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4575. is_has_exce = true
  4576. }
  4577. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4578. is_has_check = true
  4579. }
  4580. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4581. is_has_modify_exce = true
  4582. }
  4583. }
  4584. } else {
  4585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4586. return
  4587. }
  4588. this.ServeSuccessJSON(map[string]interface{}{
  4589. "is_has_create": is_has_create,
  4590. "is_has_modify": is_has_modify,
  4591. "is_has_modify_other": is_has_modify_other,
  4592. "is_has_del": is_has_del,
  4593. "is_has_del_other": is_has_del_other,
  4594. "is_has_exce": is_has_exce,
  4595. "is_has_check": is_has_check,
  4596. "is_has_modify_exce": is_has_modify_exce,
  4597. "module": module,
  4598. })
  4599. } else {
  4600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4601. return
  4602. }
  4603. } else {
  4604. this.ServeSuccessJSON(map[string]interface{}{
  4605. "is_has_create": true,
  4606. "is_has_modify": true,
  4607. "is_has_modify_other": true,
  4608. "is_has_del": true,
  4609. "is_has_del_other": true,
  4610. "is_has_exce": true,
  4611. "is_has_check": true,
  4612. "is_has_modify_exce": true,
  4613. "module": true,
  4614. })
  4615. }
  4616. }
  4617. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4618. change_type, _ := this.GetInt64("type", 0)
  4619. record_date := this.GetString("record_time")
  4620. patient_id, _ := this.GetInt64("patient_id", 0)
  4621. timeLayout := "2006-01-02"
  4622. loc, _ := time.LoadLocation("Local")
  4623. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4624. record_time := theAdviceRecordTime.Unix()
  4625. adminUserInfo := this.GetAdminUserInfo()
  4626. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4627. if err == nil {
  4628. if len(advices) == 0 {
  4629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4630. return
  4631. } else {
  4632. this.ServeSuccessJSON(map[string]interface{}{
  4633. "advices": advices,
  4634. "schedule": sch,
  4635. })
  4636. return
  4637. }
  4638. } else {
  4639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4640. return
  4641. }
  4642. }