dialysis_api_controller.go 222KB

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