dialysis_api_controller.go 224KB

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