dialysis_api_controller.go 219KB

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