dialysis_api_controller.go 278KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/astaxie/beego"
  6. "github.com/jinzhu/gorm"
  7. "reflect"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "XT_New/enums"
  12. "XT_New/models"
  13. "XT_New/service"
  14. "XT_New/utils"
  15. "math"
  16. )
  17. // type DialysisTestAPIController struct {
  18. // MobileBaseAPIController
  19. // }
  20. // [get]/m/api/test
  21. // func (this *DialysisTestAPIController) Test() {
  22. // orgID := int64(3907)
  23. // now := time.Now()
  24. // nextWeek := now.AddDate(0, 0, 7)
  25. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  26. // nextTwoWeek := now.AddDate(0, 0, 14)
  27. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  28. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  29. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  30. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  31. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  32. // return
  33. // }
  34. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  35. // if exchangeErr != nil {
  36. // this.ErrorLog("%v", exchangeErr)
  37. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  38. // return
  39. // }
  40. // this.ServeSuccessJSON(map[string]interface{}{
  41. // // "now": now,
  42. // // "next_week": nextWeek,f
  43. // // "next_week_mon": nextWeekMon,
  44. // // "next_week_sun": nextWeekSun,
  45. // // "next_two_week_mon": nextTwoWeekMon,
  46. // // "next_two_week_sun": nextTwoWeekSun,
  47. // "next_week_schs": nextWeekSchs,
  48. // "next_two_week_schs": nextTwoWeekSchs,
  49. // })
  50. // }
  51. type DialysisAPIController struct {
  52. MobileBaseAPIAuthController
  53. }
  54. // /m/api/scheduals [get]
  55. // @param type:int
  56. // @param date:string
  57. func (this *DialysisAPIController) Scheduals() {
  58. schedualType, _ := this.GetInt64("type")
  59. schedualDate := this.GetString("date")
  60. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  61. schedualType = 0
  62. }
  63. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  64. if parseDateErr != nil {
  65. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  66. return
  67. }
  68. adminInfo := this.GetMobileAdminUserInfo()
  69. orgID := adminInfo.Org.Id
  70. redis := service.RedisClient()
  71. defer redis.Close()
  72. // cur_date := time.Now().Format("2006-01-02")
  73. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  74. scheduals_json_str, _ := redis.Get(key).Result()
  75. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  76. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  77. if err != nil {
  78. this.ErrorLog("获取排班信息失败:%v", err)
  79. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  80. } else {
  81. if len(scheduals) > 0 {
  82. //缓存数据
  83. scheduals_json, err := json.Marshal(scheduals)
  84. if err == nil {
  85. redis.Set(key, scheduals_json, time.Second*30)
  86. }
  87. }
  88. this.ServeSuccessJSON(map[string]interface{}{
  89. "scheduals": scheduals,
  90. })
  91. }
  92. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  93. var dat []map[string]interface{}
  94. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  95. } else {
  96. }
  97. this.ServeSuccessJSON(map[string]interface{}{
  98. "scheduals": dat,
  99. "redis": "true",
  100. "date": schedualDate,
  101. })
  102. }
  103. }
  104. // /m/api/waiting_scheduals [get]
  105. // @param date:string
  106. func (this *DialysisAPIController) WaitingScheduals() {
  107. schedualDate := this.GetString("date")
  108. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  109. if parseDateErr != nil && len(schedualDate) != 0 {
  110. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  111. return
  112. }
  113. adminInfo := this.GetMobileAdminUserInfo()
  114. orgID := adminInfo.Org.Id
  115. redis := service.RedisClient()
  116. defer redis.Close()
  117. // cur_date := time.Now().Format("2006-01-02")
  118. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  119. wait_scheduals, _ := redis.Get(key).Result()
  120. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  121. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  122. if err != nil {
  123. this.ErrorLog("获取排班信息失败:%v", err)
  124. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. } else {
  126. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  127. for _, s := range scheduals {
  128. returnScheduals = append(returnScheduals, s)
  129. }
  130. if len(returnScheduals) > 0 {
  131. //缓存数据
  132. wait_scheduals_json, err := json.Marshal(scheduals)
  133. if err == nil {
  134. redis.Set(key, wait_scheduals_json, time.Second*30)
  135. }
  136. }
  137. this.ServeSuccessJSON(map[string]interface{}{
  138. "scheduals": scheduals,
  139. })
  140. }
  141. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  142. var dat []map[string]interface{}
  143. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  144. } else {
  145. }
  146. this.ServeSuccessJSON(map[string]interface{}{
  147. "scheduals": dat,
  148. "redis": "true",
  149. "date": schedualDate,
  150. })
  151. }
  152. }
  153. //else{
  154. // fmt.Println("33333333")
  155. //
  156. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  157. // if err != nil {
  158. // this.ErrorLog("获取排班信息失败:%v", err)
  159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. // } else {
  161. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  162. // for _, s := range scheduals {
  163. //
  164. // returnScheduals = append(returnScheduals, s)
  165. // }
  166. //
  167. // this.ServeSuccessJSON(map[string]interface{}{
  168. // "scheduals": returnScheduals,
  169. // })
  170. // }
  171. //
  172. // }
  173. //if err == nil{
  174. //
  175. //
  176. //
  177. //
  178. //
  179. //}else{
  180. //}
  181. // /m/api/dialysis/record [get]
  182. // @param patient_id:int
  183. // @param date:string (yyyy-MM-dd)
  184. func (this *DialysisAPIController) DialysisRecord() {
  185. patientID, _ := this.GetInt64("patient_id")
  186. recordDateStr := this.GetString("date")
  187. if patientID <= 0 {
  188. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  189. return
  190. }
  191. if len(recordDateStr) == 0 {
  192. recordDateStr = time.Now().Format("2006-01-02")
  193. }
  194. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  195. if parseDateErr != nil {
  196. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := this.GetMobileAdminUserInfo()
  201. patient, getPatientErr := service.MobileGetPatientDetail(adminInfo.Org.Id, patientID)
  202. if getPatientErr != nil {
  203. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  205. return
  206. } else if patient == nil {
  207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  208. return
  209. }
  210. schedual, getSchedualErr := service.MobileGetSchedualDetail(adminInfo.Org.Id, patientID, date.Unix())
  211. // this.TraceLog("==================================%+v", schedual)
  212. if getSchedualErr != nil {
  213. this.ErrorLog("获取患者排班信息失败:%v", getSchedualErr)
  214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  215. return
  216. }
  217. receiverTreatmentAccess, getRTARErr := service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  218. if getRTARErr != nil {
  219. this.ErrorLog("获取接诊评估失败:%v", getRTARErr)
  220. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  221. return
  222. }
  223. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  224. if getPEErr != nil {
  225. this.ErrorLog("获取透前评估失败:%v", getPEErr)
  226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  227. return
  228. }
  229. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  230. if getLPEErr != nil {
  231. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  232. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. return
  234. }
  235. doctorAdvices, getDoctorAdvicesErr := service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  236. if getDoctorAdvicesErr != nil {
  237. this.ErrorLog("获取临时医嘱失败:%v", getDoctorAdvicesErr)
  238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  239. return
  240. }
  241. dialysisOrder, getDialysisOrderErr := service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  242. if getDialysisOrderErr != nil {
  243. this.ErrorLog("获取透析记录失败:%v", getDialysisOrderErr)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. return
  246. }
  247. doubleCheck, getDoubleCheckErr := service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  248. if getDoubleCheckErr != nil {
  249. this.ErrorLog("获取双人核对记录失败:%v", getDoubleCheckErr)
  250. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  251. return
  252. }
  253. monitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  254. if getMonitorRecordsErr != nil {
  255. this.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  257. return
  258. }
  259. var lastMonitorRecord *models.MonitoringRecord
  260. lastMonitorRecord, getLastErr := service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  261. if getLastErr != nil {
  262. this.ErrorLog("获取上一次透析的监测记录失败:%v", getLastErr)
  263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  264. return
  265. }
  266. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  267. if getAADErr != nil {
  268. this.ErrorLog("获取透后评估失败:%v", getAADErr)
  269. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  270. return
  271. }
  272. lastAssessmentAfterDislysis, getLAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  273. if getLAADErr != nil {
  274. this.ErrorLog("获取上一次透后评估失败:%v", getLAADErr)
  275. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  276. return
  277. }
  278. treatmentSummary, getTreatmentSummaryErr := service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  279. if getTreatmentSummaryErr != nil {
  280. this.ErrorLog("获取治疗小结失败:%v", getTreatmentSummaryErr)
  281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  282. return
  283. }
  284. dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  285. //if getDialysisPrescribeErr != nil {
  286. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  287. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  288. // return
  289. //}
  290. dialysisSolution, _ := service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  291. //if getDialysisSolutionErr != nil {
  292. // this.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  293. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  294. // return
  295. //}
  296. lastDialysisPrescribe, _ := service.MobileGetLastDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  297. //fmt.Println("上次透析处方",lastDialysisPrescribe.DialyzerPerfusionApparatus)
  298. //if getDialysisPrescribeErr != nil {
  299. // this.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  300. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  301. // return
  302. //}
  303. //获取系统透析处方模版
  304. systemDialysisPrescribe, _ := service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  305. //if getSystemDialysisPrescribeErr != nil {
  306. // this.ErrorLog("获取系统透析处方失败:%v", getSystemDialysisPrescribeErr)
  307. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  308. // return
  309. //}
  310. //dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminInfo.Org.Id, patientID)
  311. //operators, _ := service.GetAllAdminUserES(adminInfo.Org.Id, adminInfo.App.Id)
  312. if getLPEErr != nil {
  313. this.ErrorLog("获取上一次透前评估失败:%v", getLPEErr)
  314. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  315. return
  316. }
  317. lastDryWeightDislysis, getDryErr := service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  318. if getDryErr != nil {
  319. this.ErrorLog("获取最后一条干体重失败:%v", getDryErr)
  320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  321. return
  322. }
  323. //headNurses, _ := service.GetAllSpecialPermissionAdminUsersWithoutStatus(adminInfo.Org.Id, adminInfo.App.Id, models.SpecialPermissionTypeHeadNurse)
  324. _, gobalConfig := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  325. goodTypes, _ := service.FindAllGoodTypeByType(1) //查出所有库存配置的系统类型
  326. goodInfos, _ := service.FindAllGoodInfo(adminInfo.Org.Id) //查出所有库存配置的系统类型
  327. operators, err := service.GetAllStarfEs(adminInfo.Org.Id)
  328. fmt.Println("报错", err)
  329. returnData := map[string]interface{}{
  330. "patient": patient,
  331. "schedual": schedual,
  332. "prescription": dialysisPrescribe,
  333. "solution": dialysisSolution,
  334. "last_prescription": lastDialysisPrescribe,
  335. "receiver_treatment_access": receiverTreatmentAccess,
  336. "predialysis_evaluation": predialysisEvaluation,
  337. "doctor_advices": doctorAdvices,
  338. "double_check": doubleCheck,
  339. "assessment_after_dislysis": assessmentAfterDislysis,
  340. "treatment_summary": treatmentSummary,
  341. "monitor_records": monitorRecords,
  342. "dialysis_order": dialysisOrder,
  343. "operators": operators,
  344. "last_predialysis_evaluation": lastPredialysisEvaluation,
  345. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  346. "last_monitor_record": lastMonitorRecord,
  347. //"special_premission": headNurses,
  348. "config": gobalConfig,
  349. "types": goodTypes,
  350. "goodInfos": goodInfos,
  351. "dry_weight": lastDryWeightDislysis,
  352. "system_prescription": systemDialysisPrescribe,
  353. }
  354. this.ServeSuccessJSON(returnData)
  355. }
  356. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  357. adminInfo := c.GetMobileAdminUserInfo()
  358. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  359. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  360. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  361. returnData := map[string]interface{}{
  362. "admin_users": adminUsers,
  363. "devices": devices,
  364. "device_numbers": device_numbers,
  365. }
  366. c.ServeSuccessJSON(returnData)
  367. }
  368. func (c *DialysisAPIController) PostAtreatmentInfo() {
  369. id, _ := c.GetInt64("patient", 0)
  370. recordDateStr := c.GetString("record_date")
  371. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  372. summaryContent := c.GetString("summaryContent")
  373. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  374. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  375. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  376. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  377. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  378. nursingRecord := c.GetString("nursing_record")
  379. fmt.Println("护理记录", nursingRecord)
  380. specialRecord := c.GetString("special_record")
  381. fmt.Println("特殊记录", specialRecord)
  382. adminUserInfo := c.GetMobileAdminUserInfo()
  383. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  384. checkStaffId = adminUserInfo.AdminUser.Id
  385. deboardNurseId = adminUserInfo.AdminUser.Id
  386. treatDoctor = adminUserInfo.AdminUser.Id
  387. if id <= 0 {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  389. return
  390. }
  391. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  392. if patient.ID == 0 {
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  394. return
  395. }
  396. if len(recordDateStr) == 0 {
  397. recordDateStr = time.Now().Format("2006-01-02")
  398. }
  399. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  400. if parseDateErr != nil {
  401. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  403. return
  404. }
  405. //now := time.Now()
  406. //year, month, day := now.Date()
  407. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  408. //todayTimeStamp := today_time.Unix()
  409. summary := models.TreatmentSummary{
  410. UserOrgId: adminUserInfo.Org.Id,
  411. PatientId: id,
  412. AssessmentDate: recordDate.Unix(),
  413. Mission: propagandaAndEducationContent,
  414. DialysisSummary: summaryContent,
  415. SjNurse: changeMedicalNurseId,
  416. ZlNurse: treatNurseId,
  417. HdNurse: checkStaffId,
  418. XjNurse: deboardNurseId,
  419. ZlDoctor: treatDoctor,
  420. CreatedTime: time.Now().Unix(),
  421. Status: 1,
  422. NursingRecord: nursingRecord,
  423. SpecialRecord: specialRecord,
  424. }
  425. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  426. if treatmentSummary.ID == 0 { //新增
  427. summary.Creater = adminUserInfo.AdminUser.Id
  428. service.AddSigleSummaryRecord(&summary)
  429. c.ServeSuccessJSON(map[string]interface{}{
  430. "summary": summary,
  431. })
  432. } else { //修改
  433. //if treatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  434. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  435. // if getPermissionErr != nil {
  436. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  437. // return
  438. // } else if headNursePermission == nil {
  439. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  440. // return
  441. // }
  442. //}
  443. summary.Creater = treatmentSummary.Creater
  444. summary.CreatedTime = treatmentSummary.CreatedTime
  445. summary.Modifier = adminUserInfo.AdminUser.Id
  446. summary.ID = treatmentSummary.ID
  447. service.UpdateSummeRecord(&summary)
  448. c.ServeSuccessJSON(map[string]interface{}{
  449. "summary": summary,
  450. })
  451. }
  452. }
  453. func (c *DialysisAPIController) PostDoubleCheck() {
  454. id, _ := c.GetInt64("patient", 0)
  455. recordDateStr := c.GetString("record_date")
  456. checkTimeStr := c.GetString("check_time")
  457. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  458. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  459. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  460. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  461. dialysis_item_desc := c.GetString("dialysis_item_desc")
  462. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  463. vascular_access_desc := c.GetString("vascular_access_desc")
  464. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  465. collator, _ := c.GetInt64("collator", 0)
  466. if id <= 0 {
  467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  468. return
  469. }
  470. adminUserInfo := c.GetMobileAdminUserInfo()
  471. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  472. if patient.ID == 0 {
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  474. return
  475. }
  476. if len(recordDateStr) == 0 {
  477. recordDateStr = time.Now().Format("2006-01-02")
  478. }
  479. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  480. if parseDateErr != nil {
  481. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  483. return
  484. }
  485. if len(checkTimeStr) == 0 {
  486. checkTimeStr = time.Now().Format("2006-01-02 15:04:05")
  487. }
  488. checkDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  489. //now := time.Now()
  490. //year, month, day := now.Date()
  491. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  492. //todayTimeStamp := today_time.Unix()
  493. doubleCheck := models.DoubleCheck{
  494. UserOrgId: adminUserInfo.Org.Id,
  495. PatientId: id,
  496. DialysisItemCheck: dialysis_item_check,
  497. DialysisParameterCheck: dialysis_parameter_check,
  498. VascularAccessVerification: vascular_access_verification,
  499. PipelineConnectionCheck: pipeline_connection_check,
  500. DialysisItemDesc: dialysis_item_desc,
  501. DialysisParameterDesc: dialysis_parameter_desc,
  502. VascularAccessDesc: vascular_access_desc,
  503. PipelineConnectionDesc: pipeline_connection_desc,
  504. Collator: collator,
  505. Status: 1,
  506. CreatedTime: time.Now().Unix(),
  507. UpdatedTime: time.Now().Unix(),
  508. CheckDate: recordDate.Unix(),
  509. }
  510. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  511. if check.ID == 0 { //新增
  512. doubleCheck.FirstCheckTime = checkDate.Unix()
  513. doubleCheck.Creater = adminUserInfo.AdminUser.Id
  514. err := service.AddSigleDoubleCheck(&doubleCheck)
  515. if err == nil {
  516. c.ServeSuccessJSON(map[string]interface{}{
  517. "doubleCheck": &doubleCheck,
  518. })
  519. }
  520. } else { //修改
  521. if check.Modifier != 0 {
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckWrong)
  523. } else {
  524. if adminUserInfo.AdminUser.Id == check.Creater {
  525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoubleCheckUserWrong)
  526. return
  527. }
  528. doubleCheck.FirstCheckTime = check.FirstCheckTime
  529. doubleCheck.CheckTime = checkDate.Unix()
  530. doubleCheck.Creater = check.Creater
  531. doubleCheck.CreatedTime = check.CreatedTime
  532. doubleCheck.Modifier = adminUserInfo.AdminUser.Id
  533. doubleCheck.ID = check.ID
  534. err := service.UpdateDoubleCheck(&doubleCheck)
  535. if err == nil {
  536. c.ServeSuccessJSON(map[string]interface{}{
  537. "doubleCheck": &doubleCheck,
  538. })
  539. }
  540. }
  541. }
  542. }
  543. func (c *DialysisAPIController) PostAcceptsAssessment() {
  544. id, _ := c.GetInt64("patient", 0)
  545. recordDateStr := c.GetString("record_date")
  546. way, _ := c.GetInt64("way", 0)
  547. consciousness, _ := c.GetInt64("consciousness", 0)
  548. appetite, _ := c.GetInt64("appetite", 0)
  549. condition, _ := c.GetInt64("condition", 0)
  550. posture, _ := c.GetInt64("posture")
  551. sick_condition, _ := c.GetInt64("sick_condition", 0)
  552. danger_level, _ := c.GetInt64("danger_level", 0)
  553. intake, _ := c.GetInt64("intake", 0)
  554. nutrition, _ := c.GetInt64("nutrition", 0)
  555. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  556. psychological_assessment_other := c.GetString("psychological_assessment_other")
  557. score := c.GetString("score")
  558. sick_condition_other := c.GetString("sick_condition_other")
  559. //precaution, _ := c.GetInt64("precaution", 0)
  560. precaution := c.GetString("precaution")
  561. precaution_other := c.GetString("precaution_other")
  562. psychological_other := c.GetString("psychological_other")
  563. admission_number := c.GetString("admission_number")
  564. if id <= 0 {
  565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  566. return
  567. }
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  570. if patient.ID == 0 {
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  572. return
  573. }
  574. //now := time.Now()
  575. //year, month, day := now.Date()
  576. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  577. //todayTimeStamp := today_time.Unix()
  578. if len(recordDateStr) == 0 {
  579. recordDateStr = time.Now().Format("2006-01-02")
  580. }
  581. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  582. if parseDateErr != nil {
  583. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  585. return
  586. }
  587. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  588. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  589. UserOrgId: adminUserInfo.Org.Id,
  590. PatientId: id,
  591. RecordDate: recordDate.Unix(),
  592. Way: way,
  593. Consciousness: consciousness,
  594. Appetite: appetite,
  595. Condition: condition,
  596. SickCondition: sick_condition,
  597. DangerLevel: danger_level,
  598. Intake: intake,
  599. Nutrition: nutrition,
  600. PsychologicalAssessment: psychological_assessment,
  601. PsychologicalAssessmentOther: psychological_assessment_other,
  602. SickConditionOther: sick_condition_other,
  603. Posture: posture,
  604. CreatedTime: time.Now().Unix(),
  605. UpdateTime: time.Now().Unix(),
  606. Status: 1,
  607. Score: score,
  608. Precaution: precaution,
  609. PrecautionOther: precaution_other,
  610. PsychologicalOther: psychological_other,
  611. AdmissionNumber: admission_number,
  612. }
  613. if receiveTreatment.ID == 0 { //新增
  614. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  615. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  616. if err == nil {
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "receiveTreatmentAsses": receiveTreatmentAsses,
  619. })
  620. }
  621. } else { //修改
  622. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  623. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  624. // if getPermissionErr != nil {
  625. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  626. // return
  627. // } else if headNursePermission == nil {
  628. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  629. // return
  630. // }
  631. //}
  632. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  633. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  634. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  635. receiveTreatmentAsses.ID = receiveTreatment.ID
  636. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  637. if err == nil {
  638. c.ServeSuccessJSON(map[string]interface{}{
  639. "receiveTreatmentAsses": receiveTreatmentAsses,
  640. })
  641. }
  642. }
  643. }
  644. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  645. id, _ := c.GetInt64("patient", 0)
  646. recordDateStr := c.GetString("record_date")
  647. weightAfter, _ := c.GetFloat("weight_after", 0)
  648. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  649. weightReduce, _ := c.GetFloat("weight_loss", 0)
  650. temperature, _ := c.GetFloat("temperature", 0)
  651. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  652. breathing_rate, _ := c.GetFloat("breathing_rate", 0)
  653. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  654. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  655. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  656. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  657. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  658. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  659. cruor := c.GetString("cruor")
  660. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  661. internalFistula := c.GetString("internal_fistula")
  662. catheter := c.GetString("catheter")
  663. complications := c.GetString("complication")
  664. remark := c.GetString("remark")
  665. dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  666. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  667. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  668. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  669. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  670. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  671. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  672. patientGose, _ := c.GetInt64("patient_gose", 0)
  673. inpatientDepartment := c.GetString("inpatient_department")
  674. observationContent := c.GetString("observation_content")
  675. observationContentOther := c.GetString("observation_content_other")
  676. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  677. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  678. in_advance_reason := c.GetString("in_advance_reason")
  679. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  680. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  681. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  682. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  683. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  684. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  685. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  686. dialyzer, _ := c.GetInt64("dialyzer", 0)
  687. in_advance_reason_other := c.GetString("in_advance_reason_other")
  688. is_eat, _ := c.GetInt64("is_eat", 0)
  689. cvc_a, _ := c.GetFloat("cvc_a", 0)
  690. cvc_v, _ := c.GetFloat("cvc_v", 0)
  691. channels, _ := c.GetInt64("channel", 0)
  692. return_blood, _ := c.GetInt64("return_blood", 0)
  693. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  694. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  695. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  696. blood_flow, _ := c.GetInt64("blood_flow", 0)
  697. sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  698. sealing_fluid_special := c.GetString("sealing_fluid_special")
  699. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  700. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  701. setting_pressure := c.GetString("setting_pressure")
  702. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  703. diastolic_pressure := c.GetString("diastolic_pressure")
  704. if id <= 0 {
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. adminUserInfo := c.GetMobileAdminUserInfo()
  709. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  710. if patient.ID == 0 {
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  712. return
  713. }
  714. if len(recordDateStr) == 0 {
  715. recordDateStr = time.Now().Format("2006-01-02")
  716. }
  717. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  718. if parseDateErr != nil {
  719. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  721. return
  722. }
  723. //now := time.Now()
  724. //year, month, day := now.Date()
  725. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  726. //todayTimeStamp := today_time.Unix()
  727. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  728. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  729. UserOrgId: adminUserInfo.Org.Id,
  730. PatientId: id,
  731. AssessmentDate: recordDate.Unix(),
  732. Temperature: temperature,
  733. PulseFrequency: pulse_frequency,
  734. BreathingRate: breathing_rate,
  735. SystolicBloodPressure: systolic_blood_pressure,
  736. DiastolicBloodPressure: diastolic_blood_pressure,
  737. ActualUltrafiltration: actual_ultrafiltration,
  738. ActualDisplacement: actual_displacement,
  739. ActualTreatmentHour: actualtreatHour,
  740. ActualTreatmentMinute: actualtreatmin,
  741. WeightAfter: weightAfter,
  742. AdditionalWeight: additionalWeight,
  743. WeightLoss: weightReduce,
  744. Cruor: cruor,
  745. SymptomAfterDialysis: symptomsAfterDialysi,
  746. InternalFistula: internalFistula,
  747. Catheter: catheter,
  748. Complication: complications,
  749. DialysisIntakes: dialysateVolume,
  750. CreatedTime: time.Now().Unix(),
  751. Status: 1,
  752. Remark: remark,
  753. BloodAccessPartId: blood_access_part_id,
  754. BloodAccessPartOperaId: blood_access_part_opera_id,
  755. DialysisIntakesUnit: dialysis_intakes_unit,
  756. PuncturePointOozingBlood: puncturePointOozingBlood,
  757. PuncturePointHaematoma: puncturePointHaematoma,
  758. InternalFistulaTremorAc: internalFistulaTremorAc,
  759. PatientGose: patientGose,
  760. InpatientDepartment: inpatientDepartment,
  761. ObservationContent: observationContent,
  762. ObservationContentOther: observationContentOther,
  763. DialysisProcess: dialysis_process,
  764. InAdvanceMinute: in_advance_minute,
  765. InAdvanceReason: in_advance_reason,
  766. HemostasisMinute: hemostasis_minute,
  767. HemostasisOpera: hemostasis_opera,
  768. TremorNoise: tremor_noise,
  769. DisequilibriumSyndrome: disequilibrium_syndrome,
  770. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  771. ArterialTube: arterial_tube,
  772. IntravenousTube: intravenous_tube,
  773. Dialyzer: dialyzer,
  774. InAdvanceReasonOther: in_advance_reason_other,
  775. IsEat: is_eat,
  776. CvcA: cvc_a,
  777. CvcV: cvc_v,
  778. Channel: channels,
  779. ReturnBlood: return_blood,
  780. RehydrationVolume: rehydration_volume,
  781. DialysisDuring: dialysis_during,
  782. StrokeVolume: stroke_volume,
  783. BloodFlow: blood_flow,
  784. SealingFluidDispose: sealing_fluid_dispose,
  785. SealingFluidSpecial: sealing_fluid_special,
  786. DosageOfAnticoagulants: dosage_of_anticoagulants,
  787. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  788. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  789. SettingPressure: setting_pressure,
  790. DiastolicPressure: diastolic_pressure,
  791. }
  792. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  793. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  794. if assessmentAfter.ID == 0 { //新增
  795. if appRole.UserType == 2 || appRole.UserType == 1 {
  796. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  797. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  798. } else {
  799. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  800. }
  801. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  802. if err == nil {
  803. c.ServeSuccessJSON(map[string]interface{}{
  804. "assessmentAfterDislysis": assessmentAfterDislysis,
  805. })
  806. }
  807. } else { //修改
  808. if appRole.UserType == 2 || appRole.UserType == 1 {
  809. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  810. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  811. } else {
  812. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  813. if assessmentAfterDislysis.Creater == 0 {
  814. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  815. }
  816. }
  817. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  818. assessmentAfterDislysis.ID = assessmentAfter.ID
  819. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  820. if err == nil {
  821. c.ServeSuccessJSON(map[string]interface{}{
  822. "assessmentAfterDislysis": assessmentAfterDislysis,
  823. })
  824. }
  825. }
  826. }
  827. func (c *DialysisAPIController) PostDialysisPrescription() {
  828. id, _ := c.GetInt64("patient", 0)
  829. recordDateStr := c.GetString("record_date")
  830. if id <= 0 {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. adminUserInfo := c.GetMobileAdminUserInfo()
  835. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  836. if patient.ID == 0 {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  838. return
  839. }
  840. if len(recordDateStr) == 0 {
  841. recordDateStr = time.Now().Format("2006-01-02")
  842. }
  843. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  844. if parseDateErr != nil {
  845. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  847. return
  848. }
  849. mode_id, _ := c.GetInt64("mode_id", 0)
  850. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  851. dialyzer, _ := c.GetInt64("dialyzer", 0)
  852. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  853. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  854. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  855. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  856. replacement_total, _ := c.GetFloat("replacement_total", 0)
  857. replacement_way, _ := c.GetInt64("replacement_way", 0)
  858. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  859. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  860. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  861. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  862. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  863. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  864. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  865. kalium, _ := c.GetFloat("kalium", 0)
  866. sodium, _ := c.GetFloat("sodium", 0)
  867. calcium, _ := c.GetFloat("calcium", 0)
  868. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  869. glucose, _ := c.GetFloat("glucose", 0)
  870. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  871. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  872. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  873. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  874. conductivity, _ := c.GetFloat("conductivity", 0)
  875. remark := c.GetString("remark")
  876. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  877. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  878. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  879. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  880. body_fluid, _ := c.GetInt64("body_fluid", 0)
  881. special_medicine, _ := c.GetInt64("special_medicine", 0)
  882. special_medicine_other := c.GetString("special_medicine_other")
  883. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  884. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  885. blood_access, _ := c.GetInt64("blood_access", 0)
  886. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  887. body_fluid_other := c.GetString("body_fluid_other")
  888. niprocart, _ := c.GetInt64("niprocart", 0)
  889. jms, _ := c.GetInt64("jms", 0)
  890. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  891. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  892. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  893. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  894. filtryzer, _ := c.GetInt64("filtryzer", 0)
  895. target_ktv, _ := c.GetFloat("target_ktv", 0)
  896. dialyzers, _ := c.GetInt64("dialyzers", 0)
  897. injector, _ := c.GetInt64("injector", 0)
  898. bloodlines, _ := c.GetInt64("bloodlines", 0)
  899. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  900. safe_package, _ := c.GetInt64("package", 0)
  901. a_liquid, _ := c.GetInt64("a_liquid", 0)
  902. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  903. fmt.Println("预冲量====", pre_impulse)
  904. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  905. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  906. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  907. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  908. //
  909. //if template.TemplateId == 2 || template.TemplateId == 6 {
  910. // if appRole.UserType == 3 {
  911. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  912. // if getPermissionErr != nil {
  913. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  914. // return
  915. // } else if headNursePermission == nil {
  916. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  917. // return
  918. // }
  919. // }
  920. //}
  921. //TODO 需要根据角色去判断
  922. prescription := models.DialysisPrescription{
  923. UserOrgId: adminUserInfo.Org.Id,
  924. PatientId: id,
  925. RecordDate: recordDate.Unix(),
  926. ModeId: mode_id,
  927. DialysisDuration: dialysis_duration,
  928. Dialyzer: dialyzer,
  929. PerfusionApparatus: perfusion_apparatus,
  930. BloodFlowVolume: blood_flow_volume,
  931. DewaterAmount: dewater_amount,
  932. DisplaceLiqui: displace_liqui,
  933. ReplacementWay: replacement_way,
  934. Anticoagulant: anticoagulant,
  935. AnticoagulantShouji: anticoagulant_shouji,
  936. AnticoagulantWeichi: anticoagulant_weichi,
  937. AnticoagulantZongliang: anticoagulant_zongliang,
  938. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  939. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  940. Kalium: kalium,
  941. Sodium: sodium,
  942. Calcium: calcium,
  943. Bicarbonate: bicarbonate,
  944. Glucose: glucose,
  945. // DryWeight: dry_weight,
  946. DialysateFlow: dialysate_flow,
  947. DialysateTemperature: dialysate_temperature,
  948. // PrescriptionDoctor: prescription_doctor,
  949. ReplacementTotal: replacement_total,
  950. Conductivity: conductivity,
  951. Remark: remark,
  952. Status: 1,
  953. CreatedTime: time.Now().Unix(),
  954. UpdatedTime: time.Now().Unix(),
  955. DialysisDurationMinute: dialysisDurationMinute,
  956. DialysisDurationHour: dialysisDurationHour,
  957. TargetUltrafiltration: targetUltrafiltration,
  958. DialysateFormulation: dialysateFormulation,
  959. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  960. BodyFluid: body_fluid,
  961. SpecialMedicine: special_medicine,
  962. SpecialMedicineOther: special_medicine_other,
  963. DisplaceLiquiPart: displace_liqui_part,
  964. DisplaceLiquiValue: displace_liqui_value,
  965. BloodAccess: blood_access,
  966. Ultrafiltration: ultrafiltration,
  967. BodyFluidOther: body_fluid_other,
  968. Niprocart: niprocart,
  969. Jms: jms,
  970. FistulaNeedleSet: fistula_needle_set,
  971. FistulaNeedleSet16: fistula_needle_set_16,
  972. Hemoperfusion: hemoperfusion,
  973. DialyserSterilised: dialyser_sterilised,
  974. Filtryzer: filtryzer,
  975. Dialyzers: dialyzers,
  976. Injector: injector,
  977. Bloodlines: bloodlines,
  978. TubingHemodialysis: tubing_hemodialysis,
  979. Package: safe_package,
  980. ALiquid: a_liquid,
  981. TargetKtv: target_ktv,
  982. PreImpulse: pre_impulse,
  983. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  984. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  985. }
  986. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  987. if dialysisPrescription.ID == 0 { //新增
  988. //if mode_id > 0 {
  989. // //service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  990. //}
  991. if appRole.UserType == 2 || appRole.UserType == 1 {
  992. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  993. }
  994. prescription.Creater = adminUserInfo.AdminUser.Id
  995. err := service.AddSigleRecord(&prescription)
  996. if err == nil {
  997. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  998. if updateErr != nil {
  999. utils.ErrorLog("%v", updateErr)
  1000. }
  1001. c.ServeSuccessJSON(map[string]interface{}{
  1002. "prescription": prescription,
  1003. })
  1004. }
  1005. } else { //修改
  1006. //if mode_id > 0 {
  1007. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1008. //}
  1009. //if template.TemplateId == 1 {
  1010. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1011. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1012. // if getPermissionErr != nil {
  1013. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1014. // return
  1015. // } else if headNursePermission == nil {
  1016. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1017. // return
  1018. // }
  1019. // }
  1020. //}
  1021. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  1022. if record.IsOpen == 1 {
  1023. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  1024. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  1025. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  1026. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  1027. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  1028. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  1029. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  1030. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  1031. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  1032. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  1033. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  1034. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  1035. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  1036. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  1037. if err == nil {
  1038. if order.ID > 0 {
  1039. if dialysisPrescription.Niprocart != niprocart {
  1040. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1041. //1.用上机透析日期查出当天的订单
  1042. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1043. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1044. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1045. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1046. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1047. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1048. warehouseOutInfo := &models.WarehouseOutInfo{
  1049. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1050. WarehouseOutId: out.ID,
  1051. Count: 1,
  1052. Status: 1,
  1053. Ctime: time.Now().Unix(),
  1054. Remark: "",
  1055. OrgId: adminUserInfo.Org.Id,
  1056. Type: 1,
  1057. Manufacturer: 0,
  1058. Dealer: 0,
  1059. IsSys: 1,
  1060. SysRecordTime: order.StartTime,
  1061. }
  1062. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  1063. warehouseOutInfo.Price = stockInInfo.Price
  1064. warehouseOutInfo.GoodId = niprocart
  1065. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  1066. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1067. if err == nil {
  1068. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1069. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1070. if err == gorm.ErrRecordNotFound {
  1071. details := &models.AutomaticReduceDetail{
  1072. WarehouseOutId: warehouseOutInfo.ID,
  1073. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1074. PatientId: id,
  1075. Ctime: time.Now().Unix(),
  1076. Mtime: time.Now().Unix(),
  1077. Status: 1,
  1078. RecordTime: order.StartTime,
  1079. OrgId: adminUserInfo.Org.Id,
  1080. GoodId: niprocart,
  1081. GoodTypeId: niprocart_good_type_id,
  1082. }
  1083. service.AddSigleAutoReduceRecordInfo(details)
  1084. } else if err == nil {
  1085. if user.ID > 0 {
  1086. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  1087. }
  1088. }
  1089. }
  1090. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1091. if newOut.ID > 0 {
  1092. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1093. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1094. if err == gorm.ErrRecordNotFound {
  1095. details := &models.AutomaticReduceDetail{
  1096. WarehouseOutId: newOut.ID,
  1097. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1098. PatientId: id,
  1099. Ctime: time.Now().Unix(),
  1100. Mtime: time.Now().Unix(),
  1101. Status: 1,
  1102. RecordTime: order.StartTime,
  1103. OrgId: adminUserInfo.Org.Id,
  1104. GoodId: niprocart,
  1105. GoodTypeId: niprocart_good_type_id,
  1106. }
  1107. service.AddSigleAutoReduceRecordInfo(details)
  1108. } else if err == nil {
  1109. if user.ID > 0 {
  1110. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  1111. }
  1112. }
  1113. }
  1114. }
  1115. }
  1116. if dialysisPrescription.Jms != jms {
  1117. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1118. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1119. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1120. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1121. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  1122. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1123. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1124. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1125. warehouseOutInfo := &models.WarehouseOutInfo{
  1126. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1127. WarehouseOutId: out.ID,
  1128. Count: 1,
  1129. Status: 1,
  1130. Ctime: time.Now().Unix(),
  1131. Remark: "",
  1132. OrgId: adminUserInfo.Org.Id,
  1133. Type: 1,
  1134. Manufacturer: 0,
  1135. Dealer: 0,
  1136. IsSys: 1,
  1137. SysRecordTime: order.StartTime,
  1138. }
  1139. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  1140. warehouseOutInfo.Price = stockInInfo.Price
  1141. warehouseOutInfo.GoodId = jms
  1142. warehouseOutInfo.GoodTypeId = jms_good_type_id
  1143. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1144. if err == nil {
  1145. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1146. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1147. if err == gorm.ErrRecordNotFound {
  1148. details := &models.AutomaticReduceDetail{
  1149. WarehouseOutId: warehouseOutInfo.ID,
  1150. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1151. PatientId: id,
  1152. Ctime: time.Now().Unix(),
  1153. Mtime: time.Now().Unix(),
  1154. Status: 1,
  1155. RecordTime: order.StartTime,
  1156. OrgId: adminUserInfo.Org.Id,
  1157. GoodId: jms,
  1158. GoodTypeId: jms_good_type_id,
  1159. }
  1160. service.AddSigleAutoReduceRecordInfo(details)
  1161. } else if err == nil {
  1162. if user.ID > 0 {
  1163. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1164. }
  1165. }
  1166. }
  1167. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1168. if newOut.ID > 0 {
  1169. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1170. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1171. if err == gorm.ErrRecordNotFound {
  1172. details := &models.AutomaticReduceDetail{
  1173. WarehouseOutId: newOut.ID,
  1174. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1175. PatientId: id,
  1176. Ctime: time.Now().Unix(),
  1177. Mtime: time.Now().Unix(),
  1178. Status: 1,
  1179. RecordTime: order.StartTime,
  1180. OrgId: adminUserInfo.Org.Id,
  1181. GoodId: jms,
  1182. GoodTypeId: jms_good_type_id,
  1183. }
  1184. service.AddSigleAutoReduceRecordInfo(details)
  1185. } else if err == nil {
  1186. if user.ID > 0 {
  1187. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  1188. }
  1189. }
  1190. }
  1191. }
  1192. }
  1193. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  1194. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1195. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1196. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1197. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1198. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  1199. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1200. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1201. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1202. warehouseOutInfo := &models.WarehouseOutInfo{
  1203. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1204. WarehouseOutId: out.ID,
  1205. Count: 1,
  1206. Status: 1,
  1207. Ctime: time.Now().Unix(),
  1208. Remark: "",
  1209. OrgId: adminUserInfo.Org.Id,
  1210. Type: 1,
  1211. Manufacturer: 0,
  1212. Dealer: 0,
  1213. IsSys: 1,
  1214. SysRecordTime: order.StartTime,
  1215. }
  1216. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  1217. warehouseOutInfo.Price = stockInInfo.Price
  1218. warehouseOutInfo.GoodId = fistula_needle_set
  1219. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  1220. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1221. if err == nil {
  1222. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1223. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1224. if err == gorm.ErrRecordNotFound {
  1225. details := &models.AutomaticReduceDetail{
  1226. WarehouseOutId: warehouseOutInfo.ID,
  1227. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1228. PatientId: id,
  1229. Ctime: time.Now().Unix(),
  1230. Mtime: time.Now().Unix(),
  1231. Status: 1,
  1232. RecordTime: order.StartTime,
  1233. OrgId: adminUserInfo.Org.Id,
  1234. GoodId: fistula_needle_set,
  1235. GoodTypeId: fistula_needle_set_good_type_id,
  1236. }
  1237. service.AddSigleAutoReduceRecordInfo(details)
  1238. } else if err == nil {
  1239. if user.ID > 0 {
  1240. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1241. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1242. }
  1243. }
  1244. }
  1245. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1246. if newOut.ID > 0 {
  1247. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1248. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1249. if err == gorm.ErrRecordNotFound {
  1250. details := &models.AutomaticReduceDetail{
  1251. WarehouseOutId: newOut.ID,
  1252. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1253. PatientId: id,
  1254. Ctime: time.Now().Unix(),
  1255. Mtime: time.Now().Unix(),
  1256. Status: 1,
  1257. RecordTime: order.StartTime,
  1258. OrgId: adminUserInfo.Org.Id,
  1259. GoodId: fistula_needle_set,
  1260. GoodTypeId: fistula_needle_set_good_type_id,
  1261. }
  1262. service.AddSigleAutoReduceRecordInfo(details)
  1263. } else if err == nil {
  1264. if user.ID > 0 {
  1265. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1266. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  1267. }
  1268. }
  1269. }
  1270. }
  1271. }
  1272. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  1273. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1274. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1275. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1276. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1277. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1278. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1279. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1280. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1281. warehouseOutInfo := &models.WarehouseOutInfo{
  1282. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1283. WarehouseOutId: out.ID,
  1284. Count: 1,
  1285. Status: 1,
  1286. Ctime: time.Now().Unix(),
  1287. Remark: "",
  1288. OrgId: adminUserInfo.Org.Id,
  1289. Type: 1,
  1290. Manufacturer: 0,
  1291. Dealer: 0,
  1292. IsSys: 1,
  1293. SysRecordTime: order.StartTime,
  1294. }
  1295. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  1296. warehouseOutInfo.Price = stockInInfo.Price
  1297. warehouseOutInfo.GoodId = fistula_needle_set_16
  1298. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  1299. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1300. if err == nil {
  1301. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1302. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1303. if err == gorm.ErrRecordNotFound {
  1304. details := &models.AutomaticReduceDetail{
  1305. WarehouseOutId: warehouseOutInfo.ID,
  1306. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1307. PatientId: id,
  1308. Ctime: time.Now().Unix(),
  1309. Mtime: time.Now().Unix(),
  1310. Status: 1,
  1311. RecordTime: order.StartTime,
  1312. OrgId: adminUserInfo.Org.Id,
  1313. GoodId: fistula_needle_set_16,
  1314. GoodTypeId: fistula_needle_set_16_good_type_id,
  1315. }
  1316. service.AddSigleAutoReduceRecordInfo(details)
  1317. } else if err == nil {
  1318. if user.ID > 0 {
  1319. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  1320. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  1321. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  1322. }
  1323. }
  1324. }
  1325. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1326. if newOut.ID > 0 {
  1327. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1328. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1329. if err == gorm.ErrRecordNotFound {
  1330. details := &models.AutomaticReduceDetail{
  1331. WarehouseOutId: newOut.ID,
  1332. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1333. PatientId: id,
  1334. Ctime: time.Now().Unix(),
  1335. Mtime: time.Now().Unix(),
  1336. Status: 1,
  1337. RecordTime: order.StartTime,
  1338. OrgId: adminUserInfo.Org.Id,
  1339. GoodId: fistula_needle_set_good_type_id,
  1340. GoodTypeId: fistula_needle_set_16_good_type_id,
  1341. }
  1342. service.AddSigleAutoReduceRecordInfo(details)
  1343. } else if err == nil {
  1344. if user.ID > 0 {
  1345. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  1352. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1353. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1354. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1355. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1356. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  1357. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1358. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1359. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1360. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1361. warehouseOutInfo := &models.WarehouseOutInfo{
  1362. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1363. WarehouseOutId: out.ID,
  1364. Count: 1,
  1365. Status: 1,
  1366. Ctime: time.Now().Unix(),
  1367. Remark: "",
  1368. OrgId: adminUserInfo.Org.Id,
  1369. Type: 1,
  1370. Manufacturer: 0,
  1371. Dealer: 0,
  1372. IsSys: 1,
  1373. SysRecordTime: order.StartTime,
  1374. }
  1375. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  1376. warehouseOutInfo.Price = stockInInfo.Price
  1377. warehouseOutInfo.GoodId = hemoperfusion
  1378. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  1379. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1380. if err == nil {
  1381. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1382. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1383. if err == gorm.ErrRecordNotFound {
  1384. details := &models.AutomaticReduceDetail{
  1385. WarehouseOutId: warehouseOutInfo.ID,
  1386. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1387. PatientId: id,
  1388. Ctime: time.Now().Unix(),
  1389. Mtime: time.Now().Unix(),
  1390. Status: 1,
  1391. RecordTime: order.StartTime,
  1392. OrgId: adminUserInfo.Org.Id,
  1393. GoodId: hemoperfusion,
  1394. GoodTypeId: hemoperfusion_good_type_id,
  1395. }
  1396. service.AddSigleAutoReduceRecordInfo(details)
  1397. } else if err == nil {
  1398. if user.ID > 0 {
  1399. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1400. }
  1401. }
  1402. }
  1403. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1404. if newOut.ID > 0 {
  1405. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1406. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1407. if err == gorm.ErrRecordNotFound {
  1408. details := &models.AutomaticReduceDetail{
  1409. WarehouseOutId: newOut.ID,
  1410. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1411. PatientId: id,
  1412. Ctime: time.Now().Unix(),
  1413. Mtime: time.Now().Unix(),
  1414. Status: 1,
  1415. RecordTime: order.StartTime,
  1416. OrgId: adminUserInfo.Org.Id,
  1417. GoodId: hemoperfusion,
  1418. GoodTypeId: hemoperfusion_good_type_id,
  1419. }
  1420. service.AddSigleAutoReduceRecordInfo(details)
  1421. } else if err == nil {
  1422. if user.ID > 0 {
  1423. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  1424. }
  1425. }
  1426. }
  1427. }
  1428. }
  1429. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  1430. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1431. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1432. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1433. //_, out := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id)
  1434. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1435. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1436. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1437. if err == gorm.ErrRecordNotFound { //����存在,则新增出库记录,并更改使用人商品信息
  1438. warehouseOutInfo := &models.WarehouseOutInfo{
  1439. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1440. WarehouseOutId: out.WarehouseOutId,
  1441. Count: 1,
  1442. Status: 1,
  1443. Ctime: time.Now().Unix(),
  1444. Remark: "",
  1445. OrgId: adminUserInfo.Org.Id,
  1446. Type: 1,
  1447. Manufacturer: 0,
  1448. Dealer: 0,
  1449. IsSys: 1,
  1450. SysRecordTime: order.StartTime,
  1451. }
  1452. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  1453. warehouseOutInfo.Price = stockInInfo.Price
  1454. warehouseOutInfo.GoodId = dialyser_sterilised
  1455. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  1456. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1457. if err == nil {
  1458. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1459. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1460. if err == gorm.ErrRecordNotFound {
  1461. details := &models.AutomaticReduceDetail{
  1462. WarehouseOutId: warehouseOutInfo.ID,
  1463. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1464. PatientId: id,
  1465. Ctime: time.Now().Unix(),
  1466. Mtime: time.Now().Unix(),
  1467. Status: 1,
  1468. RecordTime: order.StartTime,
  1469. OrgId: adminUserInfo.Org.Id,
  1470. GoodId: dialyser_sterilised,
  1471. GoodTypeId: dialyser_sterilised_good_type_id,
  1472. }
  1473. service.AddSigleAutoReduceRecordInfo(details)
  1474. } else if err == nil {
  1475. if user.ID > 0 {
  1476. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  1477. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  1478. }
  1479. }
  1480. }
  1481. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1482. if newOut.ID > 0 {
  1483. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1484. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1485. if err == gorm.ErrRecordNotFound {
  1486. details := &models.AutomaticReduceDetail{
  1487. WarehouseOutId: newOut.ID,
  1488. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1489. PatientId: id,
  1490. Ctime: time.Now().Unix(),
  1491. Mtime: time.Now().Unix(),
  1492. Status: 1,
  1493. RecordTime: order.StartTime,
  1494. OrgId: adminUserInfo.Org.Id,
  1495. GoodId: dialyser_sterilised,
  1496. GoodTypeId: dialyser_sterilised_good_type_id,
  1497. }
  1498. service.AddSigleAutoReduceRecordInfo(details)
  1499. } else if err == nil {
  1500. if user.ID > 0 {
  1501. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  1502. }
  1503. }
  1504. }
  1505. }
  1506. }
  1507. if dialysisPrescription.Filtryzer != filtryzer {
  1508. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1509. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1510. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1511. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1512. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  1513. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1514. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1515. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1516. warehouseOutInfo := &models.WarehouseOutInfo{
  1517. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1518. WarehouseOutId: out.ID,
  1519. Count: 1,
  1520. Status: 1,
  1521. Ctime: time.Now().Unix(),
  1522. Remark: "",
  1523. OrgId: adminUserInfo.Org.Id,
  1524. Type: 1,
  1525. Manufacturer: 0,
  1526. Dealer: 0,
  1527. IsSys: 1,
  1528. SysRecordTime: order.StartTime,
  1529. }
  1530. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  1531. warehouseOutInfo.Price = stockInInfo.Price
  1532. warehouseOutInfo.GoodId = filtryzer
  1533. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  1534. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1535. if err == nil {
  1536. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1537. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1538. if err == gorm.ErrRecordNotFound {
  1539. details := &models.AutomaticReduceDetail{
  1540. WarehouseOutId: warehouseOutInfo.ID,
  1541. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1542. PatientId: id,
  1543. Ctime: time.Now().Unix(),
  1544. Mtime: time.Now().Unix(),
  1545. Status: 1,
  1546. RecordTime: order.StartTime,
  1547. OrgId: adminUserInfo.Org.Id,
  1548. GoodId: filtryzer,
  1549. GoodTypeId: filtryzer_good_type_id,
  1550. }
  1551. service.AddSigleAutoReduceRecordInfo(details)
  1552. } else if err == nil {
  1553. if user.ID > 0 {
  1554. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  1555. }
  1556. }
  1557. }
  1558. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1559. if newOut.ID > 0 {
  1560. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1561. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1562. if err == gorm.ErrRecordNotFound {
  1563. details := &models.AutomaticReduceDetail{
  1564. WarehouseOutId: newOut.ID,
  1565. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1566. PatientId: id,
  1567. Ctime: time.Now().Unix(),
  1568. Mtime: time.Now().Unix(),
  1569. Status: 1,
  1570. RecordTime: order.StartTime,
  1571. OrgId: adminUserInfo.Org.Id,
  1572. GoodId: filtryzer,
  1573. GoodTypeId: filtryzer_good_type_id,
  1574. }
  1575. service.AddSigleAutoReduceRecordInfo(details)
  1576. } else if err == nil {
  1577. if user.ID > 0 {
  1578. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  1579. }
  1580. }
  1581. }
  1582. }
  1583. }
  1584. if dialysisPrescription.Dialyzers != dialyzers {
  1585. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1586. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1587. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1588. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1589. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1590. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1591. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1592. warehouseOutInfo := &models.WarehouseOutInfo{
  1593. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1594. WarehouseOutId: out.ID,
  1595. Count: 1,
  1596. Status: 1,
  1597. Ctime: time.Now().Unix(),
  1598. Remark: "",
  1599. OrgId: adminUserInfo.Org.Id,
  1600. Type: 1,
  1601. Manufacturer: 0,
  1602. Dealer: 0,
  1603. IsSys: 1,
  1604. SysRecordTime: order.StartTime,
  1605. }
  1606. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  1607. warehouseOutInfo.Price = stockInInfo.Price
  1608. warehouseOutInfo.GoodId = dialyzers
  1609. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  1610. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1611. if err == nil {
  1612. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1613. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1614. if err == gorm.ErrRecordNotFound {
  1615. details := &models.AutomaticReduceDetail{
  1616. WarehouseOutId: warehouseOutInfo.ID,
  1617. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1618. PatientId: id,
  1619. Ctime: time.Now().Unix(),
  1620. Mtime: time.Now().Unix(),
  1621. Status: 1,
  1622. RecordTime: order.StartTime,
  1623. OrgId: adminUserInfo.Org.Id,
  1624. GoodId: dialyzers,
  1625. GoodTypeId: dialyzers_good_type_id,
  1626. }
  1627. service.AddSigleAutoReduceRecordInfo(details)
  1628. } else if err == nil {
  1629. if user.ID > 0 {
  1630. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  1631. }
  1632. }
  1633. }
  1634. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1635. if newOut.ID > 0 {
  1636. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1637. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1638. if err == gorm.ErrRecordNotFound {
  1639. details := &models.AutomaticReduceDetail{
  1640. WarehouseOutId: newOut.ID,
  1641. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1642. PatientId: id,
  1643. Ctime: time.Now().Unix(),
  1644. Mtime: time.Now().Unix(),
  1645. Status: 1,
  1646. RecordTime: order.StartTime,
  1647. OrgId: adminUserInfo.Org.Id,
  1648. GoodId: dialyzers,
  1649. GoodTypeId: dialyzers_good_type_id,
  1650. }
  1651. service.AddSigleAutoReduceRecordInfo(details)
  1652. } else if err == nil {
  1653. if user.ID > 0 {
  1654. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. if dialysisPrescription.Injector != injector {
  1661. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1662. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1663. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1664. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1665. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1666. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1667. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1668. warehouseOutInfo := &models.WarehouseOutInfo{
  1669. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1670. WarehouseOutId: out.ID,
  1671. Count: 1,
  1672. Status: 1,
  1673. Ctime: time.Now().Unix(),
  1674. Remark: "",
  1675. OrgId: adminUserInfo.Org.Id,
  1676. Type: 1,
  1677. Manufacturer: 0,
  1678. Dealer: 0,
  1679. IsSys: 1,
  1680. SysRecordTime: order.StartTime,
  1681. }
  1682. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  1683. warehouseOutInfo.Price = stockInInfo.Price
  1684. warehouseOutInfo.GoodId = injector
  1685. warehouseOutInfo.GoodTypeId = injector_good_type_id
  1686. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1687. if err == nil {
  1688. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1689. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1690. if err == gorm.ErrRecordNotFound {
  1691. details := &models.AutomaticReduceDetail{
  1692. WarehouseOutId: warehouseOutInfo.ID,
  1693. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1694. PatientId: id,
  1695. Ctime: time.Now().Unix(),
  1696. Mtime: time.Now().Unix(),
  1697. Status: 1,
  1698. RecordTime: order.StartTime,
  1699. OrgId: adminUserInfo.Org.Id,
  1700. GoodId: injector,
  1701. GoodTypeId: injector_good_type_id,
  1702. }
  1703. service.AddSigleAutoReduceRecordInfo(details)
  1704. } else if err == nil {
  1705. if user.ID > 0 {
  1706. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  1707. }
  1708. }
  1709. }
  1710. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1711. if newOut.ID > 0 {
  1712. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1713. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1714. if err == gorm.ErrRecordNotFound {
  1715. details := &models.AutomaticReduceDetail{
  1716. WarehouseOutId: newOut.ID,
  1717. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1718. PatientId: id,
  1719. Ctime: time.Now().Unix(),
  1720. Mtime: time.Now().Unix(),
  1721. Status: 1,
  1722. RecordTime: order.StartTime,
  1723. OrgId: adminUserInfo.Org.Id,
  1724. GoodId: injector,
  1725. GoodTypeId: injector_good_type_id,
  1726. }
  1727. service.AddSigleAutoReduceRecordInfo(details)
  1728. } else if err == nil {
  1729. if user.ID > 0 {
  1730. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. if dialysisPrescription.Bloodlines != bloodlines {
  1737. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1738. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1739. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1740. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1741. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1742. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1743. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1744. warehouseOutInfo := &models.WarehouseOutInfo{
  1745. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1746. WarehouseOutId: out.ID,
  1747. Count: 1,
  1748. Status: 1,
  1749. Ctime: time.Now().Unix(),
  1750. Remark: "",
  1751. OrgId: adminUserInfo.Org.Id,
  1752. Type: 1,
  1753. Manufacturer: 0,
  1754. Dealer: 0,
  1755. IsSys: 1,
  1756. SysRecordTime: order.StartTime,
  1757. }
  1758. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  1759. warehouseOutInfo.Price = stockInInfo.Price
  1760. warehouseOutInfo.GoodId = bloodlines
  1761. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  1762. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1763. if err == nil {
  1764. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1765. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1766. if err == gorm.ErrRecordNotFound {
  1767. details := &models.AutomaticReduceDetail{
  1768. WarehouseOutId: warehouseOutInfo.ID,
  1769. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1770. PatientId: id,
  1771. Ctime: time.Now().Unix(),
  1772. Mtime: time.Now().Unix(),
  1773. Status: 1,
  1774. RecordTime: order.StartTime,
  1775. OrgId: adminUserInfo.Org.Id,
  1776. GoodId: bloodlines,
  1777. GoodTypeId: bloodlines_good_type_id,
  1778. }
  1779. service.AddSigleAutoReduceRecordInfo(details)
  1780. } else if err == nil {
  1781. if user.ID > 0 {
  1782. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  1783. }
  1784. }
  1785. }
  1786. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1787. if newOut.ID > 0 {
  1788. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1789. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1790. if err == gorm.ErrRecordNotFound {
  1791. details := &models.AutomaticReduceDetail{
  1792. WarehouseOutId: newOut.ID,
  1793. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1794. PatientId: id,
  1795. Ctime: time.Now().Unix(),
  1796. Mtime: time.Now().Unix(),
  1797. Status: 1,
  1798. RecordTime: order.StartTime,
  1799. OrgId: adminUserInfo.Org.Id,
  1800. GoodId: bloodlines,
  1801. GoodTypeId: bloodlines_good_type_id,
  1802. }
  1803. service.AddSigleAutoReduceRecordInfo(details)
  1804. } else if err == nil {
  1805. if user.ID > 0 {
  1806. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  1813. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1814. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1815. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1816. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1817. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1818. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1819. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1820. warehouseOutInfo := &models.WarehouseOutInfo{
  1821. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1822. WarehouseOutId: out.ID,
  1823. Count: 1,
  1824. Status: 1,
  1825. Ctime: time.Now().Unix(),
  1826. Remark: "",
  1827. OrgId: adminUserInfo.Org.Id,
  1828. Type: 1,
  1829. Manufacturer: 0,
  1830. Dealer: 0,
  1831. IsSys: 1,
  1832. SysRecordTime: order.StartTime,
  1833. }
  1834. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  1835. warehouseOutInfo.Price = stockInInfo.Price
  1836. warehouseOutInfo.GoodId = tubing_hemodialysis
  1837. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  1838. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1839. if err == nil {
  1840. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1841. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1842. if err == gorm.ErrRecordNotFound {
  1843. details := &models.AutomaticReduceDetail{
  1844. WarehouseOutId: warehouseOutInfo.ID,
  1845. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1846. PatientId: id,
  1847. Ctime: time.Now().Unix(),
  1848. Mtime: time.Now().Unix(),
  1849. Status: 1,
  1850. RecordTime: order.StartTime,
  1851. OrgId: adminUserInfo.Org.Id,
  1852. GoodId: tubing_hemodialysis,
  1853. GoodTypeId: tubingHemodialysis_good_type_id,
  1854. }
  1855. service.AddSigleAutoReduceRecordInfo(details)
  1856. } else if err == nil {
  1857. if user.ID > 0 {
  1858. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  1859. }
  1860. }
  1861. }
  1862. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1863. if newOut.ID > 0 {
  1864. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1865. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1866. if err == gorm.ErrRecordNotFound {
  1867. details := &models.AutomaticReduceDetail{
  1868. WarehouseOutId: newOut.ID,
  1869. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1870. PatientId: id,
  1871. Ctime: time.Now().Unix(),
  1872. Mtime: time.Now().Unix(),
  1873. Status: 1,
  1874. RecordTime: order.StartTime,
  1875. OrgId: adminUserInfo.Org.Id,
  1876. GoodId: tubing_hemodialysis,
  1877. GoodTypeId: tubingHemodialysis_good_type_id,
  1878. }
  1879. service.AddSigleAutoReduceRecordInfo(details)
  1880. } else if err == nil {
  1881. if user.ID > 0 {
  1882. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  1883. }
  1884. }
  1885. }
  1886. }
  1887. }
  1888. if dialysisPrescription.Package != safe_package {
  1889. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1890. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1891. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1892. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1893. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1894. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1895. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1896. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1897. warehouseOutInfo := &models.WarehouseOutInfo{
  1898. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1899. WarehouseOutId: out.ID,
  1900. Count: 1,
  1901. Status: 1,
  1902. Ctime: time.Now().Unix(),
  1903. Remark: "",
  1904. OrgId: adminUserInfo.Org.Id,
  1905. Type: 1,
  1906. Manufacturer: 0,
  1907. Dealer: 0,
  1908. IsSys: 1,
  1909. SysRecordTime: order.StartTime,
  1910. }
  1911. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  1912. warehouseOutInfo.Price = stockInInfo.Price
  1913. warehouseOutInfo.GoodId = safe_package
  1914. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  1915. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1916. if err == nil {
  1917. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1918. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1919. if err == gorm.ErrRecordNotFound {
  1920. details := &models.AutomaticReduceDetail{
  1921. WarehouseOutId: warehouseOutInfo.ID,
  1922. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  1923. PatientId: id,
  1924. Ctime: time.Now().Unix(),
  1925. Mtime: time.Now().Unix(),
  1926. Status: 1,
  1927. RecordTime: order.StartTime,
  1928. OrgId: adminUserInfo.Org.Id,
  1929. GoodId: safe_package,
  1930. GoodTypeId: safe_package_good_type_id,
  1931. }
  1932. service.AddSigleAutoReduceRecordInfo(details)
  1933. } else if err == nil {
  1934. if user.ID > 0 {
  1935. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  1936. }
  1937. }
  1938. }
  1939. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  1940. if newOut.ID > 0 {
  1941. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  1942. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1943. if err == gorm.ErrRecordNotFound {
  1944. details := &models.AutomaticReduceDetail{
  1945. WarehouseOutId: newOut.ID,
  1946. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  1947. PatientId: id,
  1948. Ctime: time.Now().Unix(),
  1949. Mtime: time.Now().Unix(),
  1950. Status: 1,
  1951. RecordTime: order.StartTime,
  1952. OrgId: adminUserInfo.Org.Id,
  1953. GoodId: safe_package,
  1954. GoodTypeId: safe_package_good_type_id,
  1955. }
  1956. service.AddSigleAutoReduceRecordInfo(details)
  1957. } else if err == nil {
  1958. if user.ID > 0 {
  1959. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  1960. }
  1961. }
  1962. }
  1963. }
  1964. }
  1965. if dialysisPrescription.ALiquid != a_liquid {
  1966. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1967. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  1968. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  1969. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1970. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  1971. //判断前端更改后的商品id的出库记录在数据库中是否存在
  1972. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  1973. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  1974. warehouseOutInfo := &models.WarehouseOutInfo{
  1975. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  1976. WarehouseOutId: out.ID,
  1977. Count: 1,
  1978. Status: 1,
  1979. Ctime: time.Now().Unix(),
  1980. Remark: "",
  1981. OrgId: adminUserInfo.Org.Id,
  1982. Type: 1,
  1983. Manufacturer: 0,
  1984. Dealer: 0,
  1985. IsSys: 1,
  1986. SysRecordTime: order.StartTime,
  1987. }
  1988. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  1989. warehouseOutInfo.Price = stockInInfo.Price
  1990. warehouseOutInfo.GoodId = a_liquid
  1991. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  1992. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  1993. if err == nil {
  1994. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  1995. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  1996. if err == gorm.ErrRecordNotFound {
  1997. details := &models.AutomaticReduceDetail{
  1998. WarehouseOutId: warehouseOutInfo.ID,
  1999. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2000. PatientId: id,
  2001. Ctime: time.Now().Unix(),
  2002. Mtime: time.Now().Unix(),
  2003. Status: 1,
  2004. RecordTime: order.StartTime,
  2005. OrgId: adminUserInfo.Org.Id,
  2006. GoodId: a_liquid,
  2007. GoodTypeId: aliquid_good_type_id,
  2008. }
  2009. service.AddSigleAutoReduceRecordInfo(details)
  2010. } else if err == nil {
  2011. if user.ID > 0 {
  2012. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  2013. }
  2014. }
  2015. }
  2016. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  2017. if newOut.ID > 0 {
  2018. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  2019. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  2020. if err == gorm.ErrRecordNotFound {
  2021. details := &models.AutomaticReduceDetail{
  2022. WarehouseOutId: newOut.ID,
  2023. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  2024. PatientId: id,
  2025. Ctime: time.Now().Unix(),
  2026. Mtime: time.Now().Unix(),
  2027. Status: 1,
  2028. RecordTime: order.StartTime,
  2029. OrgId: adminUserInfo.Org.Id,
  2030. GoodId: a_liquid,
  2031. GoodTypeId: aliquid_good_type_id,
  2032. }
  2033. service.AddSigleAutoReduceRecordInfo(details)
  2034. } else if err == nil {
  2035. if user.ID > 0 {
  2036. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  2037. }
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. }
  2045. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2046. prescription.Modifier = adminUserInfo.AdminUser.Id
  2047. if appRole.UserType == 2 || appRole.UserType == 1 {
  2048. prescription_doctor := adminUserInfo.AdminUser.Id
  2049. prescription.PrescriptionDoctor = prescription_doctor
  2050. }
  2051. if dialysisPrescription.Creater == 0 { //体重称
  2052. prescription.Creater = adminUserInfo.AdminUser.Id
  2053. } else {
  2054. prescription.Creater = dialysisPrescription.Creater
  2055. }
  2056. prescription.ID = dialysisPrescription.ID
  2057. err := service.UpDateDialysisPrescription(&prescription)
  2058. if err == nil {
  2059. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2060. if updateErr != nil {
  2061. utils.ErrorLog("%v", updateErr)
  2062. }
  2063. c.ServeSuccessJSON(map[string]interface{}{
  2064. "prescription": prescription,
  2065. })
  2066. }
  2067. }
  2068. }
  2069. func (c *DialysisAPIController) Finish() {
  2070. id, _ := c.GetInt64("patient", 0)
  2071. recordDateStr := c.GetString("record_date")
  2072. nurseID, _ := c.GetInt64("nurse")
  2073. end_time := c.GetString("end_time")
  2074. if id <= 0 || nurseID <= 0 {
  2075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2076. return
  2077. }
  2078. adminUserInfo := c.GetMobileAdminUserInfo()
  2079. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2080. if patient.ID == 0 {
  2081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2082. return
  2083. }
  2084. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2085. if getNurseErr != nil {
  2086. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2088. return
  2089. } else if nurse == nil {
  2090. c.ErrorLog("护士不存在")
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2092. return
  2093. }
  2094. if len(recordDateStr) == 0 {
  2095. recordDateStr = time.Now().Format("2006-01-02")
  2096. }
  2097. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2098. if parseDateErr != nil {
  2099. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2101. return
  2102. }
  2103. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2104. if parseEndDateErr != nil {
  2105. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2107. return
  2108. }
  2109. //now := time.Now()
  2110. //year, month, day := now.Date()
  2111. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2112. //todayTimeStamp := today_time.Unix()
  2113. // 获取当天的第一条透析纪录
  2114. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2115. if getMonitorRecordsErr != nil {
  2116. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2118. return
  2119. }
  2120. // 获取当前的最后一条透析纪录
  2121. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecord(adminUserInfo.Org.Id, id, recordDate.Unix())
  2122. if getMonitorRecordsErr != nil {
  2123. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2125. return
  2126. }
  2127. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2128. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2129. if getAADErr != nil {
  2130. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2132. return
  2133. }
  2134. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, recordDate.Unix())
  2135. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2136. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2137. if assessmentAfterDislysis != nil {
  2138. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2139. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2140. } else {
  2141. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2142. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2143. tempassessmentAfterDislysis.Status = 1
  2144. tempassessmentAfterDislysis.PatientId = id
  2145. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2146. }
  2147. if dialysisOrder.Stage == 1 {
  2148. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2149. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2150. fmt.Println(value)
  2151. a, b := math.Modf(value)
  2152. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2153. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2154. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2155. fmt.Println(hour)
  2156. fmt.Println(minute)
  2157. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2158. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2159. }
  2160. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2161. //var num1 int64
  2162. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2163. //fmt.Println(num1)
  2164. //sub := float64(num1 / 3600)
  2165. //fmt.Println(sub)
  2166. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2167. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2168. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2169. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2170. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2171. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2172. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2173. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2174. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2175. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2176. }
  2177. if lastAssessmentAfterDislysis != nil {
  2178. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2179. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2180. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2181. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2182. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2183. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2184. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2185. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2186. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2187. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2188. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2189. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2190. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2191. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2192. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2193. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2194. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2195. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2196. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2197. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2198. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2199. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2200. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2201. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2202. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2203. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2204. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2205. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2206. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2207. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2208. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2209. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2210. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2211. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2212. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2213. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2214. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2215. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2216. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2217. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2218. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2219. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2220. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2221. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2222. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2223. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2224. }
  2225. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2226. if err != nil {
  2227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2228. return
  2229. }
  2230. if dialysisOrder == nil {
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2232. return
  2233. }
  2234. if dialysisOrder.Stage == 2 {
  2235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2236. return
  2237. }
  2238. if dialysisOrder.Stage == 1 {
  2239. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id)
  2240. //结束时候透析次数加1
  2241. service.UpdateSolutionByPatientId(id)
  2242. dialysisOrder.Stage = 2
  2243. dialysisOrder.FinishNurse = nurseID
  2244. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2245. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2246. dialysisOrder.EndTime = endDate.Unix()
  2247. if err == nil {
  2248. c.ServeSuccessJSON(map[string]interface{}{
  2249. "dialysisOrder": dialysisOrder,
  2250. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2251. })
  2252. } else {
  2253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2254. }
  2255. }
  2256. }
  2257. func (c *DialysisAPIController) GetAllZone() {
  2258. adminUserInfo := c.GetMobileAdminUserInfo()
  2259. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2260. if err == nil {
  2261. c.ServeSuccessJSON(map[string]interface{}{
  2262. "zone": zone,
  2263. })
  2264. }
  2265. }
  2266. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2267. adminUserInfo := c.GetMobileAdminUserInfo()
  2268. page, _ := c.GetInt64("page", 1)
  2269. limit, _ := c.GetInt64("limit", 10)
  2270. schedulType, _ := c.GetInt64("schedul_type", 0)
  2271. startTime, _ := c.GetInt64("schedul_time", 0)
  2272. partitionType, _ := c.GetInt64("partition_type", 0)
  2273. keywords := c.GetString("keywords")
  2274. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2275. if err == nil {
  2276. c.ServeSuccessJSON(map[string]interface{}{
  2277. "schedule": dialysisSchedule,
  2278. })
  2279. }
  2280. return
  2281. }
  2282. // /m/api/dialysis/start [post]
  2283. // @param patient_id:int
  2284. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2285. // @param nurse:int 上机护士
  2286. // @param bed:int 床位号
  2287. func (this *DialysisAPIController) StartDialysis() {
  2288. patientID, _ := this.GetInt64("patient_id")
  2289. recordDateStr := this.GetString("record_date")
  2290. nurseID, _ := this.GetInt64("nurse")
  2291. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2292. blood_drawing, _ := this.GetInt64("blood_drawing")
  2293. schedual_type, _ := this.GetInt64("schedual_type")
  2294. bedID, _ := this.GetInt64("bed")
  2295. start_time := this.GetString("start_time")
  2296. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2297. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2299. return
  2300. }
  2301. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2302. if parseStartDateErr != nil {
  2303. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2305. return
  2306. }
  2307. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2308. if parseErr != nil {
  2309. this.ErrorLog("时间解析失败:%v", parseErr)
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2311. return
  2312. }
  2313. adminUserInfo := this.GetMobileAdminUserInfo()
  2314. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2315. if getPatientErr != nil {
  2316. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2318. return
  2319. } else if patient == nil {
  2320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2321. return
  2322. }
  2323. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2324. if getNurseErr != nil {
  2325. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2327. return
  2328. } else if nurse == nil {
  2329. this.ErrorLog("护士不存在")
  2330. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2331. return
  2332. }
  2333. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2334. if getNurseErr != nil {
  2335. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2336. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2337. return
  2338. } else if nurse == nil {
  2339. this.ErrorLog("护士不存在")
  2340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2341. return
  2342. }
  2343. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2344. if getDeviceNumberErr != nil {
  2345. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2347. return
  2348. } else if deviceNumber == nil {
  2349. this.ErrorLog("床位号不存在")
  2350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2351. return
  2352. }
  2353. _, configs := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2354. if configs.IsOpen == 1 {
  2355. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2356. if prescription.ID == 0 {
  2357. this.ErrorLog("上机失败,还没开处方")
  2358. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  2359. return
  2360. }
  2361. }
  2362. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2363. if getRecordErr != nil {
  2364. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2366. return
  2367. } else if dialysisRecord != nil {
  2368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2369. return
  2370. }
  2371. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2372. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2373. timeLayout := "2006-01-02 15:04:05"
  2374. loc, _ := time.LoadLocation("Local")
  2375. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2376. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2377. schedulestartTime := theStartTime.Unix()
  2378. scheduleendTime := theEndTime.Unix()
  2379. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2380. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2381. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2382. //查询该床位是否有人用了
  2383. order, order_err := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2384. if err == gorm.ErrRecordNotFound { //空床位
  2385. // 修改了床位逻辑
  2386. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2387. if daySchedule.ID > 0 {
  2388. daySchedule.PartitionId = deviceNumber.ZoneID
  2389. daySchedule.BedId = bedID
  2390. daySchedule.ScheduleType = schedual_type
  2391. daySchedule.UpdatedTime = time.Now().Unix()
  2392. err := service.UpdateSchedule(&daySchedule)
  2393. if err != nil {
  2394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2395. return
  2396. }
  2397. }
  2398. } else if err == nil {
  2399. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2400. if order_err == nil {
  2401. if order.ID > 0 { //该机位被其他人占用了
  2402. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2403. return
  2404. } else {
  2405. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2406. if daySchedule.ID > 0 {
  2407. daySchedule.PartitionId = deviceNumber.ZoneID
  2408. daySchedule.BedId = bedID
  2409. daySchedule.ScheduleType = schedual_type
  2410. daySchedule.UpdatedTime = time.Now().Unix()
  2411. err := service.UpdateSchedule(&daySchedule)
  2412. if err != nil {
  2413. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. } else if order_err == gorm.ErrRecordNotFound { //该床位没被占用
  2419. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2420. if daySchedule.ID > 0 {
  2421. daySchedule.PartitionId = deviceNumber.ZoneID
  2422. daySchedule.BedId = bedID
  2423. daySchedule.ScheduleType = schedual_type
  2424. daySchedule.UpdatedTime = time.Now().Unix()
  2425. err := service.UpdateSchedule(&daySchedule)
  2426. if err != nil {
  2427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2428. return
  2429. }
  2430. }
  2431. }
  2432. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2434. return
  2435. }
  2436. } else if err != nil {
  2437. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2438. return
  2439. }
  2440. dialysisRecord = &models.DialysisOrder{
  2441. DialysisDate: recordDate.Unix(),
  2442. UserOrgId: adminUserInfo.Org.Id,
  2443. PatientId: patientID,
  2444. Stage: 1,
  2445. BedID: bedID,
  2446. StartNurse: nurseID,
  2447. Status: 1,
  2448. StartTime: startDate.Unix(),
  2449. CreatedTime: time.Now().Unix(),
  2450. UpdatedTime: time.Now().Unix(),
  2451. PunctureNurse: puncture_nurse,
  2452. Creator: adminUserInfo.AdminUser.Id,
  2453. Modifier: adminUserInfo.AdminUser.Id,
  2454. SchedualType: schedual_type,
  2455. WashpipeNurse: washpipe_nurse,
  2456. }
  2457. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2458. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2459. var tempdispose string
  2460. // 只针对中能建
  2461. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2462. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2463. }
  2464. var ultrafiltration_rate float64
  2465. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2466. if prescription.ID > 0 {
  2467. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2468. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2469. if template.TemplateId == 6 { //adminUserInfo.Org.Id == 9538
  2470. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2471. }
  2472. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2473. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2474. }
  2475. // 只针对方济医院
  2476. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2477. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2478. ultrafiltration_rate = value
  2479. }
  2480. }
  2481. }
  2482. record := models.MonitoringRecord{
  2483. UserOrgId: adminUserInfo.Org.Id,
  2484. PatientId: patientID,
  2485. DialysisOrderId: dialysisRecord.ID,
  2486. MonitoringDate: schedulestartTime,
  2487. OperateTime: startDate.Unix(),
  2488. // MonitoringTime: recordTime,
  2489. MonitoringNurse: nurseID,
  2490. Dispose: tempdispose,
  2491. UltrafiltrationRate: ultrafiltration_rate,
  2492. UltrafiltrationVolume: 0,
  2493. Status: 1,
  2494. CreatedTime: time.Now().Unix(),
  2495. UpdatedTime: time.Now().Unix(),
  2496. }
  2497. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2498. if newdialysisRecord.ID > 0 {
  2499. err := service.CreateMonitor(&record)
  2500. if err != nil {
  2501. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2502. return
  2503. }
  2504. }
  2505. //是否启动自动扣减功能
  2506. _, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  2507. //启动的话
  2508. if config.IsOpen == 1 {
  2509. niprocart, _ := beego.AppConfig.Int64("niprocart")
  2510. jms, _ := beego.AppConfig.Int64("jms")
  2511. fistula_needle_set, _ := beego.AppConfig.Int64("fistula_needle_set")
  2512. fistula_needle_set_16, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  2513. hemoperfusion, _ := beego.AppConfig.Int64("hemoperfusion")
  2514. dialyser_sterilised, _ := beego.AppConfig.Int64("dialyser_sterilised")
  2515. filtryzer, _ := beego.AppConfig.Int64("filtryzer")
  2516. dialyzers, _ := beego.AppConfig.Int64("dialyzers")
  2517. injector, _ := beego.AppConfig.Int64("injector")
  2518. bloodlines, _ := beego.AppConfig.Int64("bloodlines")
  2519. tubingHemodialysis, _ := beego.AppConfig.Int64("tubingHemodialysis")
  2520. safe_package, _ := beego.AppConfig.Int64("package")
  2521. aliquid, _ := beego.AppConfig.Int64("aliquid")
  2522. //库存自动扣减功能
  2523. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2524. if prescription.ID > 0 {
  2525. out, err := service.FindStockOutByIsSys(adminUserInfo.Org.Id, 1, recordDate.Unix())
  2526. if err == gorm.ErrRecordNotFound {
  2527. //没有记录,则创建出库单
  2528. timeStr := time.Now().Format("2006-01-02")
  2529. timeArr := strings.Split(timeStr, "-")
  2530. total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
  2531. total = total + 1
  2532. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2533. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2534. number = number + total
  2535. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2536. creater := adminUserInfo.AdminUser.Id
  2537. warehouseOut := models.WarehouseOut{
  2538. WarehouseOutOrderNumber: warehousing_out_order,
  2539. OperationTime: time.Now().Unix(),
  2540. OrgId: adminUserInfo.Org.Id,
  2541. Creater: creater,
  2542. Ctime: time.Now().Unix(),
  2543. Status: 1,
  2544. WarehouseOutTime: recordDate.Unix(),
  2545. Dealer: 0,
  2546. Manufacturer: 0,
  2547. Type: 1,
  2548. IsSys: 1,
  2549. }
  2550. err := service.AddSigleWarehouseOut(&warehouseOut)
  2551. if err != nil {
  2552. utils.TraceLog("创建出库单失败 err = %v", err)
  2553. } else {
  2554. if prescription.Niprocart > 0 {
  2555. warehouseOutInfo := &models.WarehouseOutInfo{
  2556. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2557. WarehouseOutId: warehouseOut.ID,
  2558. Count: 1,
  2559. Status: 1,
  2560. Ctime: time.Now().Unix(),
  2561. Remark: "",
  2562. OrgId: adminUserInfo.Org.Id,
  2563. Type: 1,
  2564. Manufacturer: 0,
  2565. Dealer: 0,
  2566. IsSys: 1,
  2567. SysRecordTime: startDate.Unix(),
  2568. }
  2569. //查出入库记录中最后一条记录
  2570. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  2571. warehouseOutInfo.Price = stockInInfo.Price
  2572. warehouseOutInfo.GoodId = prescription.Niprocart
  2573. warehouseOutInfo.GoodTypeId = niprocart
  2574. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2575. if err == nil {
  2576. details := &models.AutomaticReduceDetail{
  2577. WarehouseOutId: warehouseOutInfo.ID,
  2578. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2579. PatientId: patientID,
  2580. Ctime: time.Now().Unix(),
  2581. Mtime: time.Now().Unix(),
  2582. Status: 1,
  2583. RecordTime: startDate.Unix(),
  2584. OrgId: adminUserInfo.Org.Id,
  2585. GoodId: prescription.Niprocart,
  2586. GoodTypeId: niprocart,
  2587. }
  2588. service.AddSigleAutoReduceRecordInfo(details)
  2589. }
  2590. }
  2591. if prescription.Jms > 0 {
  2592. warehouseOutInfo := &models.WarehouseOutInfo{
  2593. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2594. WarehouseOutId: warehouseOut.ID,
  2595. Count: 1,
  2596. Status: 1,
  2597. Ctime: time.Now().Unix(),
  2598. Remark: "",
  2599. OrgId: adminUserInfo.Org.Id,
  2600. Type: 1,
  2601. Manufacturer: 0,
  2602. Dealer: 0,
  2603. IsSys: 1,
  2604. SysRecordTime: startDate.Unix(),
  2605. }
  2606. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  2607. warehouseOutInfo.Price = stockInInfo.Price
  2608. warehouseOutInfo.GoodId = prescription.Jms
  2609. warehouseOutInfo.GoodTypeId = jms
  2610. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2611. if err == nil {
  2612. details := &models.AutomaticReduceDetail{
  2613. WarehouseOutId: warehouseOutInfo.ID,
  2614. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2615. PatientId: patientID,
  2616. Ctime: time.Now().Unix(),
  2617. Mtime: time.Now().Unix(),
  2618. Status: 1,
  2619. RecordTime: startDate.Unix(),
  2620. OrgId: adminUserInfo.Org.Id,
  2621. GoodId: prescription.Jms,
  2622. GoodTypeId: jms,
  2623. }
  2624. service.AddSigleAutoReduceRecordInfo(details)
  2625. }
  2626. }
  2627. if prescription.FistulaNeedleSet > 0 {
  2628. warehouseOutInfo := &models.WarehouseOutInfo{
  2629. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2630. WarehouseOutId: warehouseOut.ID,
  2631. Count: 1,
  2632. Status: 1,
  2633. Ctime: time.Now().Unix(),
  2634. Remark: "",
  2635. OrgId: adminUserInfo.Org.Id,
  2636. Type: 1,
  2637. Manufacturer: 0,
  2638. Dealer: 0,
  2639. IsSys: 1,
  2640. SysRecordTime: startDate.Unix(),
  2641. }
  2642. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  2643. warehouseOutInfo.Price = stockInInfo.Price
  2644. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  2645. warehouseOutInfo.GoodTypeId = fistula_needle_set
  2646. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2647. if err == nil {
  2648. details := &models.AutomaticReduceDetail{
  2649. WarehouseOutId: warehouseOutInfo.ID,
  2650. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2651. PatientId: patientID,
  2652. Ctime: time.Now().Unix(),
  2653. Mtime: time.Now().Unix(),
  2654. Status: 1,
  2655. RecordTime: startDate.Unix(),
  2656. OrgId: adminUserInfo.Org.Id,
  2657. GoodId: prescription.FistulaNeedleSet,
  2658. GoodTypeId: fistula_needle_set,
  2659. }
  2660. service.AddSigleAutoReduceRecordInfo(details)
  2661. }
  2662. }
  2663. if prescription.FistulaNeedleSet16 > 0 {
  2664. warehouseOutInfo := &models.WarehouseOutInfo{
  2665. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2666. WarehouseOutId: warehouseOut.ID,
  2667. Count: 1,
  2668. Status: 1,
  2669. Ctime: time.Now().Unix(),
  2670. Remark: "",
  2671. OrgId: adminUserInfo.Org.Id,
  2672. Type: 1,
  2673. Manufacturer: 0,
  2674. Dealer: 0,
  2675. IsSys: 1,
  2676. SysRecordTime: startDate.Unix(),
  2677. }
  2678. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  2679. warehouseOutInfo.Price = stockInInfo.Price
  2680. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  2681. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  2682. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2683. if err == nil {
  2684. details := &models.AutomaticReduceDetail{
  2685. WarehouseOutId: warehouseOutInfo.ID,
  2686. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2687. PatientId: patientID,
  2688. Ctime: time.Now().Unix(),
  2689. Mtime: time.Now().Unix(),
  2690. Status: 1,
  2691. RecordTime: startDate.Unix(),
  2692. OrgId: adminUserInfo.Org.Id,
  2693. GoodId: prescription.FistulaNeedleSet16,
  2694. GoodTypeId: fistula_needle_set_16,
  2695. }
  2696. service.AddSigleAutoReduceRecordInfo(details)
  2697. }
  2698. }
  2699. if prescription.Hemoperfusion > 0 {
  2700. warehouseOutInfo := &models.WarehouseOutInfo{
  2701. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2702. WarehouseOutId: warehouseOut.ID,
  2703. Count: 1,
  2704. Status: 1,
  2705. Ctime: time.Now().Unix(),
  2706. Remark: "",
  2707. OrgId: adminUserInfo.Org.Id,
  2708. Type: 1,
  2709. Manufacturer: 0,
  2710. Dealer: 0,
  2711. IsSys: 1,
  2712. SysRecordTime: startDate.Unix(),
  2713. }
  2714. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  2715. warehouseOutInfo.Price = stockInInfo.Price
  2716. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  2717. warehouseOutInfo.GoodTypeId = hemoperfusion
  2718. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2719. if err == nil {
  2720. details := &models.AutomaticReduceDetail{
  2721. WarehouseOutId: warehouseOutInfo.ID,
  2722. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2723. PatientId: patientID,
  2724. Ctime: time.Now().Unix(),
  2725. Mtime: time.Now().Unix(),
  2726. Status: 1,
  2727. RecordTime: startDate.Unix(),
  2728. OrgId: adminUserInfo.Org.Id,
  2729. GoodId: prescription.Hemoperfusion,
  2730. GoodTypeId: hemoperfusion,
  2731. }
  2732. service.AddSigleAutoReduceRecordInfo(details)
  2733. }
  2734. }
  2735. if prescription.DialyserSterilised > 0 {
  2736. warehouseOutInfo := &models.WarehouseOutInfo{
  2737. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2738. WarehouseOutId: warehouseOut.ID,
  2739. Count: 1,
  2740. Status: 1,
  2741. Ctime: time.Now().Unix(),
  2742. Remark: "",
  2743. OrgId: adminUserInfo.Org.Id,
  2744. Type: 1,
  2745. Manufacturer: 0,
  2746. Dealer: 0,
  2747. IsSys: 1,
  2748. SysRecordTime: startDate.Unix(),
  2749. }
  2750. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  2751. warehouseOutInfo.Price = stockInInfo.Price
  2752. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  2753. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  2754. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2755. if err == nil {
  2756. details := &models.AutomaticReduceDetail{
  2757. WarehouseOutId: warehouseOutInfo.ID,
  2758. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2759. PatientId: patientID,
  2760. Ctime: time.Now().Unix(),
  2761. Mtime: time.Now().Unix(),
  2762. Status: 1,
  2763. RecordTime: startDate.Unix(),
  2764. OrgId: adminUserInfo.Org.Id,
  2765. GoodId: prescription.DialyserSterilised,
  2766. GoodTypeId: dialyser_sterilised,
  2767. }
  2768. service.AddSigleAutoReduceRecordInfo(details)
  2769. }
  2770. }
  2771. if prescription.Filtryzer > 0 {
  2772. warehouseOutInfo := &models.WarehouseOutInfo{
  2773. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2774. WarehouseOutId: warehouseOut.ID,
  2775. Count: 1,
  2776. Status: 1,
  2777. Ctime: time.Now().Unix(),
  2778. Remark: "",
  2779. OrgId: adminUserInfo.Org.Id,
  2780. Type: 1,
  2781. Manufacturer: 0,
  2782. Dealer: 0,
  2783. IsSys: 1,
  2784. SysRecordTime: startDate.Unix(),
  2785. }
  2786. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  2787. warehouseOutInfo.Price = stockInInfo.Price
  2788. warehouseOutInfo.GoodId = prescription.Filtryzer
  2789. warehouseOutInfo.GoodTypeId = filtryzer
  2790. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2791. if err == nil {
  2792. details := &models.AutomaticReduceDetail{
  2793. WarehouseOutId: warehouseOutInfo.ID,
  2794. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2795. PatientId: patientID,
  2796. Ctime: time.Now().Unix(),
  2797. Mtime: time.Now().Unix(),
  2798. Status: 1,
  2799. RecordTime: startDate.Unix(),
  2800. OrgId: adminUserInfo.Org.Id,
  2801. GoodId: prescription.Filtryzer,
  2802. GoodTypeId: filtryzer,
  2803. }
  2804. service.AddSigleAutoReduceRecordInfo(details)
  2805. }
  2806. }
  2807. if prescription.Dialyzers > 0 {
  2808. warehouseOutInfo := &models.WarehouseOutInfo{
  2809. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2810. WarehouseOutId: warehouseOut.ID,
  2811. Count: 1,
  2812. Status: 1,
  2813. Ctime: time.Now().Unix(),
  2814. Remark: "",
  2815. OrgId: adminUserInfo.Org.Id,
  2816. Type: 1,
  2817. Manufacturer: 0,
  2818. Dealer: 0,
  2819. IsSys: 1,
  2820. SysRecordTime: startDate.Unix(),
  2821. }
  2822. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  2823. warehouseOutInfo.Price = stockInInfo.Price
  2824. warehouseOutInfo.GoodId = prescription.Dialyzers
  2825. warehouseOutInfo.GoodTypeId = dialyzers
  2826. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2827. if err == nil {
  2828. details := &models.AutomaticReduceDetail{
  2829. WarehouseOutId: warehouseOutInfo.ID,
  2830. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2831. PatientId: patientID,
  2832. Ctime: time.Now().Unix(),
  2833. Mtime: time.Now().Unix(),
  2834. Status: 1,
  2835. RecordTime: startDate.Unix(),
  2836. OrgId: adminUserInfo.Org.Id,
  2837. GoodId: prescription.Dialyzers,
  2838. GoodTypeId: dialyzers,
  2839. }
  2840. service.AddSigleAutoReduceRecordInfo(details)
  2841. }
  2842. }
  2843. if prescription.Injector > 0 {
  2844. warehouseOutInfo := &models.WarehouseOutInfo{
  2845. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2846. WarehouseOutId: warehouseOut.ID,
  2847. Count: 1,
  2848. Status: 1,
  2849. Ctime: time.Now().Unix(),
  2850. Remark: "",
  2851. OrgId: adminUserInfo.Org.Id,
  2852. Type: 1,
  2853. Manufacturer: 0,
  2854. Dealer: 0,
  2855. IsSys: 1,
  2856. SysRecordTime: startDate.Unix(),
  2857. }
  2858. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  2859. warehouseOutInfo.Price = stockInInfo.Price
  2860. warehouseOutInfo.GoodId = prescription.Injector
  2861. warehouseOutInfo.GoodTypeId = injector
  2862. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2863. if err == nil {
  2864. details := &models.AutomaticReduceDetail{
  2865. WarehouseOutId: warehouseOutInfo.ID,
  2866. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2867. PatientId: patientID,
  2868. Ctime: time.Now().Unix(),
  2869. Mtime: time.Now().Unix(),
  2870. Status: 1,
  2871. RecordTime: startDate.Unix(),
  2872. OrgId: adminUserInfo.Org.Id,
  2873. GoodId: prescription.Injector,
  2874. GoodTypeId: injector,
  2875. }
  2876. service.AddSigleAutoReduceRecordInfo(details)
  2877. }
  2878. }
  2879. if prescription.Bloodlines > 0 {
  2880. warehouseOutInfo := &models.WarehouseOutInfo{
  2881. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2882. WarehouseOutId: warehouseOut.ID,
  2883. Count: 1,
  2884. Status: 1,
  2885. Ctime: time.Now().Unix(),
  2886. Remark: "",
  2887. OrgId: adminUserInfo.Org.Id,
  2888. Type: 1,
  2889. Manufacturer: 0,
  2890. Dealer: 0,
  2891. IsSys: 1,
  2892. SysRecordTime: startDate.Unix(),
  2893. }
  2894. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  2895. warehouseOutInfo.Price = stockInInfo.Price
  2896. warehouseOutInfo.GoodId = prescription.Bloodlines
  2897. warehouseOutInfo.GoodTypeId = bloodlines
  2898. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2899. if err == nil {
  2900. details := &models.AutomaticReduceDetail{
  2901. WarehouseOutId: warehouseOutInfo.ID,
  2902. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2903. PatientId: patientID,
  2904. Ctime: time.Now().Unix(),
  2905. Mtime: time.Now().Unix(),
  2906. Status: 1,
  2907. RecordTime: startDate.Unix(),
  2908. OrgId: adminUserInfo.Org.Id,
  2909. GoodId: prescription.Bloodlines,
  2910. GoodTypeId: bloodlines,
  2911. }
  2912. service.AddSigleAutoReduceRecordInfo(details)
  2913. }
  2914. }
  2915. if prescription.TubingHemodialysis > 0 {
  2916. warehouseOutInfo := &models.WarehouseOutInfo{
  2917. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2918. WarehouseOutId: warehouseOut.ID,
  2919. Count: 1,
  2920. Status: 1,
  2921. Ctime: time.Now().Unix(),
  2922. Remark: "",
  2923. OrgId: adminUserInfo.Org.Id,
  2924. Type: 1,
  2925. Manufacturer: 0,
  2926. Dealer: 0,
  2927. IsSys: 1,
  2928. SysRecordTime: startDate.Unix(),
  2929. }
  2930. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  2931. warehouseOutInfo.Price = stockInInfo.Price
  2932. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  2933. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  2934. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2935. if err == nil {
  2936. details := &models.AutomaticReduceDetail{
  2937. WarehouseOutId: warehouseOutInfo.ID,
  2938. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2939. PatientId: patientID,
  2940. Ctime: time.Now().Unix(),
  2941. Mtime: time.Now().Unix(),
  2942. Status: 1,
  2943. RecordTime: startDate.Unix(),
  2944. OrgId: adminUserInfo.Org.Id,
  2945. GoodId: prescription.TubingHemodialysis,
  2946. GoodTypeId: tubingHemodialysis,
  2947. }
  2948. service.AddSigleAutoReduceRecordInfo(details)
  2949. }
  2950. }
  2951. if prescription.Package > 0 {
  2952. warehouseOutInfo := &models.WarehouseOutInfo{
  2953. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2954. WarehouseOutId: warehouseOut.ID,
  2955. Count: 1,
  2956. Status: 1,
  2957. Ctime: time.Now().Unix(),
  2958. Remark: "",
  2959. OrgId: adminUserInfo.Org.Id,
  2960. Type: 1,
  2961. Manufacturer: 0,
  2962. Dealer: 0,
  2963. IsSys: 1,
  2964. SysRecordTime: startDate.Unix(),
  2965. }
  2966. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  2967. warehouseOutInfo.Price = stockInInfo.Price
  2968. warehouseOutInfo.GoodId = prescription.Package
  2969. warehouseOutInfo.GoodTypeId = safe_package
  2970. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  2971. if err == nil {
  2972. details := &models.AutomaticReduceDetail{
  2973. WarehouseOutId: warehouseOutInfo.ID,
  2974. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  2975. PatientId: patientID,
  2976. Ctime: time.Now().Unix(),
  2977. Mtime: time.Now().Unix(),
  2978. Status: 1,
  2979. RecordTime: startDate.Unix(),
  2980. OrgId: adminUserInfo.Org.Id,
  2981. GoodId: prescription.Package,
  2982. GoodTypeId: safe_package,
  2983. }
  2984. service.AddSigleAutoReduceRecordInfo(details)
  2985. }
  2986. }
  2987. if prescription.ALiquid > 0 {
  2988. warehouseOutInfo := &models.WarehouseOutInfo{
  2989. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  2990. WarehouseOutId: warehouseOut.ID,
  2991. Count: 1,
  2992. Status: 1,
  2993. Ctime: time.Now().Unix(),
  2994. Remark: "",
  2995. OrgId: adminUserInfo.Org.Id,
  2996. Type: 1,
  2997. Manufacturer: 0,
  2998. Dealer: 0,
  2999. IsSys: 1,
  3000. SysRecordTime: startDate.Unix(),
  3001. }
  3002. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  3003. warehouseOutInfo.Price = stockInInfo.Price
  3004. warehouseOutInfo.GoodId = prescription.ALiquid
  3005. warehouseOutInfo.GoodTypeId = aliquid
  3006. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3007. if err == nil {
  3008. details := &models.AutomaticReduceDetail{
  3009. WarehouseOutId: warehouseOutInfo.ID,
  3010. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3011. PatientId: patientID,
  3012. Ctime: time.Now().Unix(),
  3013. Mtime: time.Now().Unix(),
  3014. Status: 1,
  3015. RecordTime: startDate.Unix(),
  3016. OrgId: adminUserInfo.Org.Id,
  3017. GoodId: prescription.ALiquid,
  3018. GoodTypeId: aliquid,
  3019. }
  3020. service.AddSigleAutoReduceRecordInfo(details)
  3021. }
  3022. }
  3023. }
  3024. } else if err == nil {
  3025. if out.ID > 0 {
  3026. if prescription.Niprocart > 0 {
  3027. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, niprocart, prescription.Niprocart, out.ID)
  3028. if err == gorm.ErrRecordNotFound {
  3029. warehouseOutInfo := &models.WarehouseOutInfo{
  3030. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3031. WarehouseOutId: out.ID,
  3032. Status: 1,
  3033. Ctime: time.Now().Unix(),
  3034. Remark: "",
  3035. OrgId: adminUserInfo.Org.Id,
  3036. Type: 1,
  3037. Manufacturer: 0,
  3038. Dealer: 0,
  3039. IsSys: 1,
  3040. SysRecordTime: startDate.Unix(),
  3041. }
  3042. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Niprocart, adminUserInfo.Org.Id)
  3043. warehouseOutInfo.Price = stockInInfo.Price
  3044. warehouseOutInfo.GoodId = prescription.Niprocart
  3045. warehouseOutInfo.GoodTypeId = niprocart
  3046. warehouseOutInfo.Count = 1
  3047. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3048. if err == nil {
  3049. details := &models.AutomaticReduceDetail{
  3050. WarehouseOutId: warehouseOutInfo.ID,
  3051. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3052. PatientId: patientID,
  3053. Ctime: time.Now().Unix(),
  3054. Mtime: time.Now().Unix(),
  3055. Status: 1,
  3056. RecordTime: startDate.Unix(),
  3057. OrgId: adminUserInfo.Org.Id,
  3058. GoodId: prescription.Niprocart,
  3059. GoodTypeId: niprocart,
  3060. }
  3061. service.AddSigleAutoReduceRecordInfo(details)
  3062. }
  3063. } else if err == nil { //记录存在,则将数量加1
  3064. if outInfo.ID > 0 {
  3065. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3066. }
  3067. details := &models.AutomaticReduceDetail{
  3068. WarehouseOutId: outInfo.ID,
  3069. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3070. PatientId: patientID,
  3071. Ctime: time.Now().Unix(),
  3072. Mtime: time.Now().Unix(),
  3073. Status: 1,
  3074. RecordTime: startDate.Unix(),
  3075. OrgId: adminUserInfo.Org.Id,
  3076. GoodId: prescription.Niprocart,
  3077. GoodTypeId: niprocart,
  3078. }
  3079. service.AddSigleAutoReduceRecordInfo(details)
  3080. }
  3081. }
  3082. if prescription.Jms > 0 {
  3083. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, jms, prescription.Jms, out.ID)
  3084. if err == gorm.ErrRecordNotFound {
  3085. warehouseOutInfo := &models.WarehouseOutInfo{
  3086. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3087. WarehouseOutId: out.ID,
  3088. Status: 1,
  3089. Ctime: time.Now().Unix(),
  3090. Remark: "",
  3091. OrgId: adminUserInfo.Org.Id,
  3092. Type: 1,
  3093. Manufacturer: 0,
  3094. Dealer: 0,
  3095. IsSys: 1,
  3096. SysRecordTime: startDate.Unix(),
  3097. }
  3098. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Jms, adminUserInfo.Org.Id)
  3099. warehouseOutInfo.Price = stockInInfo.Price
  3100. warehouseOutInfo.GoodId = prescription.Jms
  3101. warehouseOutInfo.GoodTypeId = jms
  3102. warehouseOutInfo.Count = 1
  3103. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3104. if err == nil {
  3105. details := &models.AutomaticReduceDetail{
  3106. WarehouseOutId: warehouseOutInfo.ID,
  3107. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3108. PatientId: patientID,
  3109. Ctime: time.Now().Unix(),
  3110. Mtime: time.Now().Unix(),
  3111. Status: 1,
  3112. RecordTime: startDate.Unix(),
  3113. OrgId: adminUserInfo.Org.Id,
  3114. GoodId: prescription.Jms,
  3115. GoodTypeId: jms,
  3116. }
  3117. service.AddSigleAutoReduceRecordInfo(details)
  3118. }
  3119. } else if err == nil { //记录存在,则将数量加1
  3120. if outInfo.ID > 0 {
  3121. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3122. }
  3123. details := &models.AutomaticReduceDetail{
  3124. WarehouseOutId: outInfo.ID,
  3125. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3126. PatientId: patientID,
  3127. Ctime: time.Now().Unix(),
  3128. Mtime: time.Now().Unix(),
  3129. Status: 1,
  3130. RecordTime: startDate.Unix(),
  3131. OrgId: adminUserInfo.Org.Id,
  3132. GoodId: prescription.Jms,
  3133. GoodTypeId: jms,
  3134. }
  3135. service.AddSigleAutoReduceRecordInfo(details)
  3136. }
  3137. }
  3138. if prescription.FistulaNeedleSet > 0 {
  3139. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set, prescription.FistulaNeedleSet, out.ID)
  3140. if err == gorm.ErrRecordNotFound {
  3141. warehouseOutInfo := &models.WarehouseOutInfo{
  3142. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3143. WarehouseOutId: out.ID,
  3144. Status: 1,
  3145. Ctime: time.Now().Unix(),
  3146. Remark: "",
  3147. OrgId: adminUserInfo.Org.Id,
  3148. Type: 1,
  3149. Manufacturer: 0,
  3150. Dealer: 0,
  3151. IsSys: 1,
  3152. SysRecordTime: startDate.Unix(),
  3153. }
  3154. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet, adminUserInfo.Org.Id)
  3155. warehouseOutInfo.Price = stockInInfo.Price
  3156. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet
  3157. warehouseOutInfo.GoodTypeId = fistula_needle_set
  3158. warehouseOutInfo.Count = 1
  3159. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3160. if err == nil {
  3161. details := &models.AutomaticReduceDetail{
  3162. WarehouseOutId: warehouseOutInfo.ID,
  3163. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3164. PatientId: patientID,
  3165. Ctime: time.Now().Unix(),
  3166. Mtime: time.Now().Unix(),
  3167. Status: 1,
  3168. RecordTime: startDate.Unix(),
  3169. OrgId: adminUserInfo.Org.Id,
  3170. GoodId: prescription.FistulaNeedleSet,
  3171. GoodTypeId: fistula_needle_set,
  3172. }
  3173. service.AddSigleAutoReduceRecordInfo(details)
  3174. }
  3175. } else if err == nil { //记录存在,则将数量加1
  3176. if outInfo.ID > 0 {
  3177. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3178. }
  3179. details := &models.AutomaticReduceDetail{
  3180. WarehouseOutId: outInfo.ID,
  3181. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3182. PatientId: patientID,
  3183. Ctime: time.Now().Unix(),
  3184. Mtime: time.Now().Unix(),
  3185. Status: 1,
  3186. RecordTime: startDate.Unix(),
  3187. OrgId: adminUserInfo.Org.Id,
  3188. GoodId: prescription.FistulaNeedleSet,
  3189. GoodTypeId: fistula_needle_set,
  3190. }
  3191. service.AddSigleAutoReduceRecordInfo(details)
  3192. }
  3193. }
  3194. if prescription.FistulaNeedleSet16 > 0 {
  3195. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, fistula_needle_set_16, prescription.FistulaNeedleSet16, out.ID)
  3196. if err == gorm.ErrRecordNotFound {
  3197. warehouseOutInfo := &models.WarehouseOutInfo{
  3198. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3199. WarehouseOutId: out.ID,
  3200. Status: 1,
  3201. Ctime: time.Now().Unix(),
  3202. Remark: "",
  3203. OrgId: adminUserInfo.Org.Id,
  3204. Type: 1,
  3205. Manufacturer: 0,
  3206. Dealer: 0,
  3207. IsSys: 1,
  3208. SysRecordTime: startDate.Unix(),
  3209. }
  3210. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.FistulaNeedleSet16, adminUserInfo.Org.Id)
  3211. warehouseOutInfo.Price = stockInInfo.Price
  3212. warehouseOutInfo.GoodId = prescription.FistulaNeedleSet16
  3213. warehouseOutInfo.GoodTypeId = fistula_needle_set_16
  3214. warehouseOutInfo.Count = 1
  3215. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3216. if err == nil {
  3217. details := &models.AutomaticReduceDetail{
  3218. WarehouseOutId: warehouseOutInfo.ID,
  3219. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3220. PatientId: patientID,
  3221. Ctime: time.Now().Unix(),
  3222. Mtime: time.Now().Unix(),
  3223. Status: 1,
  3224. RecordTime: startDate.Unix(),
  3225. OrgId: adminUserInfo.Org.Id,
  3226. GoodId: prescription.FistulaNeedleSet16,
  3227. GoodTypeId: fistula_needle_set_16,
  3228. }
  3229. service.AddSigleAutoReduceRecordInfo(details)
  3230. }
  3231. } else if err == nil { //记录存在,则将数量加1
  3232. if outInfo.ID > 0 {
  3233. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3234. }
  3235. details := &models.AutomaticReduceDetail{
  3236. WarehouseOutId: outInfo.ID,
  3237. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3238. PatientId: patientID,
  3239. Ctime: time.Now().Unix(),
  3240. Mtime: time.Now().Unix(),
  3241. Status: 1,
  3242. RecordTime: startDate.Unix(),
  3243. OrgId: adminUserInfo.Org.Id,
  3244. GoodId: prescription.FistulaNeedleSet16,
  3245. GoodTypeId: fistula_needle_set_16,
  3246. }
  3247. service.AddSigleAutoReduceRecordInfo(details)
  3248. }
  3249. }
  3250. if prescription.Hemoperfusion > 0 {
  3251. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, hemoperfusion, prescription.Hemoperfusion, out.ID)
  3252. if err == gorm.ErrRecordNotFound {
  3253. warehouseOutInfo := &models.WarehouseOutInfo{
  3254. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3255. WarehouseOutId: out.ID,
  3256. Status: 1,
  3257. Ctime: time.Now().Unix(),
  3258. Remark: "",
  3259. OrgId: adminUserInfo.Org.Id,
  3260. Type: 1,
  3261. Manufacturer: 0,
  3262. Dealer: 0,
  3263. IsSys: 1,
  3264. SysRecordTime: startDate.Unix(),
  3265. }
  3266. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Hemoperfusion, adminUserInfo.Org.Id)
  3267. warehouseOutInfo.Price = stockInInfo.Price
  3268. warehouseOutInfo.GoodId = prescription.Hemoperfusion
  3269. warehouseOutInfo.GoodTypeId = hemoperfusion
  3270. warehouseOutInfo.Count = 1
  3271. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3272. if err == nil {
  3273. details := &models.AutomaticReduceDetail{
  3274. WarehouseOutId: warehouseOutInfo.ID,
  3275. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3276. PatientId: patientID,
  3277. Ctime: time.Now().Unix(),
  3278. Mtime: time.Now().Unix(),
  3279. Status: 1,
  3280. RecordTime: startDate.Unix(),
  3281. OrgId: adminUserInfo.Org.Id,
  3282. GoodId: prescription.Hemoperfusion,
  3283. GoodTypeId: hemoperfusion,
  3284. }
  3285. service.AddSigleAutoReduceRecordInfo(details)
  3286. }
  3287. } else if err == nil { //记录存在,则将数量加1
  3288. if outInfo.ID > 0 {
  3289. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3290. }
  3291. details := &models.AutomaticReduceDetail{
  3292. WarehouseOutId: outInfo.ID,
  3293. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3294. PatientId: patientID,
  3295. Ctime: time.Now().Unix(),
  3296. Mtime: time.Now().Unix(),
  3297. Status: 1,
  3298. RecordTime: startDate.Unix(),
  3299. OrgId: adminUserInfo.Org.Id,
  3300. GoodId: prescription.Hemoperfusion,
  3301. GoodTypeId: hemoperfusion,
  3302. }
  3303. service.AddSigleAutoReduceRecordInfo(details)
  3304. }
  3305. }
  3306. if prescription.DialyserSterilised > 0 {
  3307. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyser_sterilised, prescription.DialyserSterilised, out.ID)
  3308. if err == gorm.ErrRecordNotFound {
  3309. warehouseOutInfo := &models.WarehouseOutInfo{
  3310. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3311. WarehouseOutId: out.ID,
  3312. Status: 1,
  3313. Ctime: time.Now().Unix(),
  3314. Remark: "",
  3315. OrgId: adminUserInfo.Org.Id,
  3316. Type: 1,
  3317. Manufacturer: 0,
  3318. Dealer: 0,
  3319. IsSys: 1,
  3320. SysRecordTime: startDate.Unix(),
  3321. }
  3322. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.DialyserSterilised, adminUserInfo.Org.Id)
  3323. warehouseOutInfo.Price = stockInInfo.Price
  3324. warehouseOutInfo.GoodId = prescription.DialyserSterilised
  3325. warehouseOutInfo.GoodTypeId = dialyser_sterilised
  3326. warehouseOutInfo.Count = 1
  3327. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3328. if err == nil {
  3329. details := &models.AutomaticReduceDetail{
  3330. WarehouseOutId: warehouseOutInfo.ID,
  3331. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3332. PatientId: patientID,
  3333. Ctime: time.Now().Unix(),
  3334. Mtime: time.Now().Unix(),
  3335. Status: 1,
  3336. RecordTime: startDate.Unix(),
  3337. OrgId: adminUserInfo.Org.Id,
  3338. GoodId: prescription.DialyserSterilised,
  3339. GoodTypeId: dialyser_sterilised,
  3340. }
  3341. service.AddSigleAutoReduceRecordInfo(details)
  3342. }
  3343. } else if err == nil { //记录存在,则将数量加1
  3344. if outInfo.ID > 0 {
  3345. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3346. }
  3347. details := &models.AutomaticReduceDetail{
  3348. WarehouseOutId: outInfo.ID,
  3349. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3350. PatientId: patientID,
  3351. Ctime: time.Now().Unix(),
  3352. Mtime: time.Now().Unix(),
  3353. Status: 1,
  3354. RecordTime: startDate.Unix(),
  3355. OrgId: adminUserInfo.Org.Id,
  3356. GoodId: prescription.DialyserSterilised,
  3357. GoodTypeId: dialyser_sterilised,
  3358. }
  3359. service.AddSigleAutoReduceRecordInfo(details)
  3360. }
  3361. }
  3362. if prescription.Filtryzer > 0 {
  3363. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, filtryzer, prescription.Filtryzer, out.ID)
  3364. if err == gorm.ErrRecordNotFound {
  3365. warehouseOutInfo := &models.WarehouseOutInfo{
  3366. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3367. WarehouseOutId: out.ID,
  3368. Status: 1,
  3369. Ctime: time.Now().Unix(),
  3370. Remark: "",
  3371. OrgId: adminUserInfo.Org.Id,
  3372. Type: 1,
  3373. Manufacturer: 0,
  3374. Dealer: 0,
  3375. IsSys: 1,
  3376. SysRecordTime: startDate.Unix(),
  3377. }
  3378. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Filtryzer, adminUserInfo.Org.Id)
  3379. warehouseOutInfo.Price = stockInInfo.Price
  3380. warehouseOutInfo.GoodId = prescription.Filtryzer
  3381. warehouseOutInfo.GoodTypeId = filtryzer
  3382. warehouseOutInfo.Count = 1
  3383. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3384. if err == nil {
  3385. details := &models.AutomaticReduceDetail{
  3386. WarehouseOutId: warehouseOutInfo.ID,
  3387. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3388. PatientId: patientID,
  3389. Ctime: time.Now().Unix(),
  3390. Mtime: time.Now().Unix(),
  3391. Status: 1,
  3392. RecordTime: startDate.Unix(),
  3393. OrgId: adminUserInfo.Org.Id,
  3394. GoodId: prescription.Filtryzer,
  3395. GoodTypeId: filtryzer,
  3396. }
  3397. service.AddSigleAutoReduceRecordInfo(details)
  3398. }
  3399. } else if err == nil { //记录存在,则将耗材使用数量加1
  3400. if outInfo.ID > 0 {
  3401. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3402. }
  3403. //插入病人耗材使用记录
  3404. details := &models.AutomaticReduceDetail{
  3405. WarehouseOutId: outInfo.ID,
  3406. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3407. PatientId: patientID,
  3408. Ctime: time.Now().Unix(),
  3409. Mtime: time.Now().Unix(),
  3410. Status: 1,
  3411. RecordTime: startDate.Unix(),
  3412. OrgId: adminUserInfo.Org.Id,
  3413. GoodId: prescription.Filtryzer,
  3414. GoodTypeId: filtryzer,
  3415. }
  3416. service.AddSigleAutoReduceRecordInfo(details)
  3417. }
  3418. }
  3419. if prescription.Dialyzers > 0 {
  3420. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, dialyzers, prescription.Dialyzers, out.ID)
  3421. if err == gorm.ErrRecordNotFound {
  3422. warehouseOutInfo := &models.WarehouseOutInfo{
  3423. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3424. WarehouseOutId: out.ID,
  3425. Status: 1,
  3426. Ctime: time.Now().Unix(),
  3427. Remark: "",
  3428. OrgId: adminUserInfo.Org.Id,
  3429. Type: 1,
  3430. Manufacturer: 0,
  3431. Dealer: 0,
  3432. IsSys: 1,
  3433. SysRecordTime: startDate.Unix(),
  3434. }
  3435. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Dialyzers, adminUserInfo.Org.Id)
  3436. warehouseOutInfo.Price = stockInInfo.Price
  3437. warehouseOutInfo.GoodId = prescription.Dialyzers
  3438. warehouseOutInfo.GoodTypeId = dialyzers
  3439. warehouseOutInfo.Count = 1
  3440. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3441. if err == nil {
  3442. details := &models.AutomaticReduceDetail{
  3443. WarehouseOutId: warehouseOutInfo.ID,
  3444. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3445. PatientId: patientID,
  3446. Ctime: time.Now().Unix(),
  3447. Mtime: time.Now().Unix(),
  3448. Status: 1,
  3449. RecordTime: startDate.Unix(),
  3450. OrgId: adminUserInfo.Org.Id,
  3451. GoodId: prescription.Dialyzers,
  3452. GoodTypeId: dialyzers,
  3453. }
  3454. service.AddSigleAutoReduceRecordInfo(details)
  3455. }
  3456. } else if err == nil { //记录存在,则将耗材使用数量加1
  3457. if outInfo.ID > 0 {
  3458. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3459. }
  3460. //插入病人耗材使用记录
  3461. details := &models.AutomaticReduceDetail{
  3462. WarehouseOutId: outInfo.ID,
  3463. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3464. PatientId: patientID,
  3465. Ctime: time.Now().Unix(),
  3466. Mtime: time.Now().Unix(),
  3467. Status: 1,
  3468. RecordTime: startDate.Unix(),
  3469. OrgId: adminUserInfo.Org.Id,
  3470. GoodId: prescription.Dialyzers,
  3471. GoodTypeId: dialyzers,
  3472. }
  3473. service.AddSigleAutoReduceRecordInfo(details)
  3474. }
  3475. }
  3476. if prescription.Injector > 0 {
  3477. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, injector, prescription.Injector, out.ID)
  3478. if err == gorm.ErrRecordNotFound {
  3479. warehouseOutInfo := &models.WarehouseOutInfo{
  3480. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3481. WarehouseOutId: out.ID,
  3482. Status: 1,
  3483. Ctime: time.Now().Unix(),
  3484. Remark: "",
  3485. OrgId: adminUserInfo.Org.Id,
  3486. Type: 1,
  3487. Manufacturer: 0,
  3488. Dealer: 0,
  3489. IsSys: 1,
  3490. SysRecordTime: startDate.Unix(),
  3491. }
  3492. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Injector, adminUserInfo.Org.Id)
  3493. warehouseOutInfo.Price = stockInInfo.Price
  3494. warehouseOutInfo.GoodId = prescription.Injector
  3495. warehouseOutInfo.GoodTypeId = injector
  3496. warehouseOutInfo.Count = 1
  3497. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3498. if err == nil {
  3499. details := &models.AutomaticReduceDetail{
  3500. WarehouseOutId: warehouseOutInfo.ID,
  3501. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3502. PatientId: patientID,
  3503. Ctime: time.Now().Unix(),
  3504. Mtime: time.Now().Unix(),
  3505. Status: 1,
  3506. RecordTime: startDate.Unix(),
  3507. OrgId: adminUserInfo.Org.Id,
  3508. GoodId: prescription.Injector,
  3509. GoodTypeId: injector,
  3510. }
  3511. service.AddSigleAutoReduceRecordInfo(details)
  3512. }
  3513. } else if err == nil { //记录存在,则将耗材使用数量加1
  3514. if outInfo.ID > 0 {
  3515. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3516. }
  3517. //插入病人耗材使用记录
  3518. details := &models.AutomaticReduceDetail{
  3519. WarehouseOutId: outInfo.ID,
  3520. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3521. PatientId: patientID,
  3522. Ctime: time.Now().Unix(),
  3523. Mtime: time.Now().Unix(),
  3524. Status: 1,
  3525. RecordTime: startDate.Unix(),
  3526. OrgId: adminUserInfo.Org.Id,
  3527. GoodId: prescription.Injector,
  3528. GoodTypeId: injector,
  3529. }
  3530. service.AddSigleAutoReduceRecordInfo(details)
  3531. }
  3532. }
  3533. if prescription.Bloodlines > 0 {
  3534. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, bloodlines, prescription.Bloodlines, out.ID)
  3535. if err == gorm.ErrRecordNotFound {
  3536. warehouseOutInfo := &models.WarehouseOutInfo{
  3537. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3538. WarehouseOutId: out.ID,
  3539. Status: 1,
  3540. Ctime: time.Now().Unix(),
  3541. Remark: "",
  3542. OrgId: adminUserInfo.Org.Id,
  3543. Type: 1,
  3544. Manufacturer: 0,
  3545. Dealer: 0,
  3546. IsSys: 1,
  3547. SysRecordTime: startDate.Unix(),
  3548. }
  3549. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Bloodlines, adminUserInfo.Org.Id)
  3550. warehouseOutInfo.Price = stockInInfo.Price
  3551. warehouseOutInfo.GoodId = prescription.Bloodlines
  3552. warehouseOutInfo.GoodTypeId = bloodlines
  3553. warehouseOutInfo.Count = 1
  3554. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3555. if err == nil {
  3556. details := &models.AutomaticReduceDetail{
  3557. WarehouseOutId: warehouseOutInfo.ID,
  3558. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3559. PatientId: patientID,
  3560. Ctime: time.Now().Unix(),
  3561. Mtime: time.Now().Unix(),
  3562. Status: 1,
  3563. RecordTime: startDate.Unix(),
  3564. OrgId: adminUserInfo.Org.Id,
  3565. GoodId: prescription.Bloodlines,
  3566. GoodTypeId: bloodlines,
  3567. }
  3568. service.AddSigleAutoReduceRecordInfo(details)
  3569. }
  3570. } else if err == nil { //记录存在,则将耗材使用数量加1
  3571. if outInfo.ID > 0 {
  3572. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3573. }
  3574. //插入病人耗材使用记录
  3575. details := &models.AutomaticReduceDetail{
  3576. WarehouseOutId: outInfo.ID,
  3577. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3578. PatientId: patientID,
  3579. Ctime: time.Now().Unix(),
  3580. Mtime: time.Now().Unix(),
  3581. Status: 1,
  3582. RecordTime: startDate.Unix(),
  3583. OrgId: adminUserInfo.Org.Id,
  3584. GoodId: prescription.Bloodlines,
  3585. GoodTypeId: bloodlines,
  3586. }
  3587. service.AddSigleAutoReduceRecordInfo(details)
  3588. }
  3589. }
  3590. if prescription.TubingHemodialysis > 0 {
  3591. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, tubingHemodialysis, prescription.TubingHemodialysis, out.ID)
  3592. if err == gorm.ErrRecordNotFound {
  3593. warehouseOutInfo := &models.WarehouseOutInfo{
  3594. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3595. WarehouseOutId: out.ID,
  3596. Status: 1,
  3597. Ctime: time.Now().Unix(),
  3598. Remark: "",
  3599. OrgId: adminUserInfo.Org.Id,
  3600. Type: 1,
  3601. Manufacturer: 0,
  3602. Dealer: 0,
  3603. IsSys: 1,
  3604. SysRecordTime: startDate.Unix(),
  3605. }
  3606. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.TubingHemodialysis, adminUserInfo.Org.Id)
  3607. warehouseOutInfo.Price = stockInInfo.Price
  3608. warehouseOutInfo.GoodId = prescription.TubingHemodialysis
  3609. warehouseOutInfo.GoodTypeId = tubingHemodialysis
  3610. warehouseOutInfo.Count = 1
  3611. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3612. if err == nil {
  3613. details := &models.AutomaticReduceDetail{
  3614. WarehouseOutId: warehouseOutInfo.ID,
  3615. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3616. PatientId: patientID,
  3617. Ctime: time.Now().Unix(),
  3618. Mtime: time.Now().Unix(),
  3619. Status: 1,
  3620. RecordTime: startDate.Unix(),
  3621. OrgId: adminUserInfo.Org.Id,
  3622. GoodId: prescription.TubingHemodialysis,
  3623. GoodTypeId: tubingHemodialysis,
  3624. }
  3625. service.AddSigleAutoReduceRecordInfo(details)
  3626. }
  3627. } else if err == nil { //记录存在,则将耗材使用数量加1
  3628. if outInfo.ID > 0 {
  3629. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3630. }
  3631. //插入病人耗材使用记录
  3632. details := &models.AutomaticReduceDetail{
  3633. WarehouseOutId: outInfo.ID,
  3634. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3635. PatientId: patientID,
  3636. Ctime: time.Now().Unix(),
  3637. Mtime: time.Now().Unix(),
  3638. Status: 1,
  3639. RecordTime: startDate.Unix(),
  3640. OrgId: adminUserInfo.Org.Id,
  3641. GoodId: prescription.TubingHemodialysis,
  3642. GoodTypeId: tubingHemodialysis,
  3643. }
  3644. service.AddSigleAutoReduceRecordInfo(details)
  3645. }
  3646. }
  3647. if prescription.Package > 0 {
  3648. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, safe_package, prescription.Package, out.ID)
  3649. if err == gorm.ErrRecordNotFound {
  3650. warehouseOutInfo := &models.WarehouseOutInfo{
  3651. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3652. WarehouseOutId: out.ID,
  3653. Status: 1,
  3654. Ctime: time.Now().Unix(),
  3655. Remark: "",
  3656. OrgId: adminUserInfo.Org.Id,
  3657. Type: 1,
  3658. Manufacturer: 0,
  3659. Dealer: 0,
  3660. IsSys: 1,
  3661. SysRecordTime: startDate.Unix(),
  3662. }
  3663. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.Package, adminUserInfo.Org.Id)
  3664. warehouseOutInfo.Price = stockInInfo.Price
  3665. warehouseOutInfo.GoodId = prescription.Package
  3666. warehouseOutInfo.GoodTypeId = safe_package
  3667. warehouseOutInfo.Count = 1
  3668. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3669. if err == nil {
  3670. details := &models.AutomaticReduceDetail{
  3671. WarehouseOutId: warehouseOutInfo.ID,
  3672. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3673. PatientId: patientID,
  3674. Ctime: time.Now().Unix(),
  3675. Mtime: time.Now().Unix(),
  3676. Status: 1,
  3677. RecordTime: startDate.Unix(),
  3678. OrgId: adminUserInfo.Org.Id,
  3679. GoodId: prescription.Package,
  3680. GoodTypeId: safe_package,
  3681. }
  3682. service.AddSigleAutoReduceRecordInfo(details)
  3683. }
  3684. } else if err == nil { //记录存在,则将耗材使用数量加1
  3685. if outInfo.ID > 0 {
  3686. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3687. }
  3688. //插入病人耗材使用记录
  3689. details := &models.AutomaticReduceDetail{
  3690. WarehouseOutId: outInfo.ID,
  3691. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3692. PatientId: patientID,
  3693. Ctime: time.Now().Unix(),
  3694. Mtime: time.Now().Unix(),
  3695. Status: 1,
  3696. RecordTime: startDate.Unix(),
  3697. OrgId: adminUserInfo.Org.Id,
  3698. GoodId: prescription.Package,
  3699. GoodTypeId: safe_package,
  3700. }
  3701. service.AddSigleAutoReduceRecordInfo(details)
  3702. }
  3703. }
  3704. if prescription.ALiquid > 0 {
  3705. outInfo, err := service.FindStockOutInfoByTypeId(adminUserInfo.Org.Id, aliquid, prescription.ALiquid, out.ID)
  3706. if err == gorm.ErrRecordNotFound {
  3707. warehouseOutInfo := &models.WarehouseOutInfo{
  3708. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3709. WarehouseOutId: out.ID,
  3710. Status: 1,
  3711. Ctime: time.Now().Unix(),
  3712. Remark: "",
  3713. OrgId: adminUserInfo.Org.Id,
  3714. Type: 1,
  3715. Manufacturer: 0,
  3716. Dealer: 0,
  3717. IsSys: 1,
  3718. SysRecordTime: startDate.Unix(),
  3719. }
  3720. stockInInfo, _ := service.FindLastStockInInfoRecord(prescription.ALiquid, adminUserInfo.Org.Id)
  3721. warehouseOutInfo.Price = stockInInfo.Price
  3722. warehouseOutInfo.GoodId = prescription.ALiquid
  3723. warehouseOutInfo.GoodTypeId = aliquid
  3724. warehouseOutInfo.Count = 1
  3725. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  3726. if err == nil {
  3727. details := &models.AutomaticReduceDetail{
  3728. WarehouseOutId: warehouseOutInfo.ID,
  3729. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  3730. PatientId: patientID,
  3731. Ctime: time.Now().Unix(),
  3732. Mtime: time.Now().Unix(),
  3733. Status: 1,
  3734. RecordTime: startDate.Unix(),
  3735. OrgId: adminUserInfo.Org.Id,
  3736. GoodId: prescription.ALiquid,
  3737. GoodTypeId: aliquid,
  3738. }
  3739. service.AddSigleAutoReduceRecordInfo(details)
  3740. }
  3741. } else if err == nil { //记录存在,则将耗材使用数量加1
  3742. if outInfo.ID > 0 {
  3743. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, outInfo.ID)
  3744. }
  3745. //插入病人耗材使用记录
  3746. details := &models.AutomaticReduceDetail{
  3747. WarehouseOutId: outInfo.ID,
  3748. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  3749. PatientId: patientID,
  3750. Ctime: time.Now().Unix(),
  3751. Mtime: time.Now().Unix(),
  3752. Status: 1,
  3753. RecordTime: startDate.Unix(),
  3754. OrgId: adminUserInfo.Org.Id,
  3755. GoodId: prescription.ALiquid,
  3756. GoodTypeId: aliquid,
  3757. }
  3758. service.AddSigleAutoReduceRecordInfo(details)
  3759. }
  3760. }
  3761. }
  3762. }
  3763. } else {
  3764. this.ErrorLog("上机失败,还没开处方")
  3765. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionException)
  3766. return
  3767. }
  3768. }
  3769. if createErr != nil {
  3770. this.ErrorLog("上机失败:%v", createErr)
  3771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3772. return
  3773. }
  3774. this.ServeSuccessJSON(map[string]interface{}{
  3775. "dialysis_order": newdialysisRecord,
  3776. "monitor": record,
  3777. })
  3778. }
  3779. func (c *DialysisAPIController) PostSolution() {
  3780. id, _ := c.GetInt64("patient", 0)
  3781. recordDateStr := c.GetString("record_date")
  3782. if id <= 0 {
  3783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3784. return
  3785. }
  3786. adminUserInfo := c.GetMobileAdminUserInfo()
  3787. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3788. if patient.ID == 0 {
  3789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3790. return
  3791. }
  3792. if len(recordDateStr) == 0 {
  3793. recordDateStr = time.Now().Format("2006-01-02")
  3794. }
  3795. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3796. if parseDateErr != nil {
  3797. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3799. return
  3800. }
  3801. mode_id, _ := c.GetInt64("mode_id", 0)
  3802. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3803. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3804. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3805. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3806. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3807. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3808. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3809. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3810. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3811. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3812. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3813. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3814. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3815. kalium, _ := c.GetFloat("kalium", 0)
  3816. sodium, _ := c.GetFloat("sodium", 0)
  3817. calcium, _ := c.GetFloat("calcium", 0)
  3818. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3819. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3820. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3821. glucose, _ := c.GetFloat("glucose", 0)
  3822. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3823. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3824. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3825. conductivity, _ := c.GetFloat("conductivity", 0)
  3826. remark := c.GetString("remark")
  3827. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3828. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3829. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3830. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3831. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3832. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3833. special_medicine_other := c.GetString("special_medicine_other")
  3834. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3835. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3836. blood_access, _ := c.GetInt64("blood_access", 0)
  3837. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3838. body_fluid_other := c.GetString("body_fluid_other")
  3839. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3840. niprocart, _ := c.GetInt64("niprocart", 0)
  3841. jms, _ := c.GetInt64("jms", 0)
  3842. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3843. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3844. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3845. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3846. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3847. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3848. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3849. injector, _ := c.GetInt64("injector", 0)
  3850. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3851. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3852. safe_package, _ := c.GetInt64("package", 0)
  3853. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3854. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3855. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3856. if mode_id > 0 {
  3857. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  3858. }
  3859. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3860. //
  3861. //if appRole.UserType == 2 || appRole.UserType == 1 {
  3862. // prescription_doctor = appRole.AdminUserId
  3863. //} else {
  3864. // prescription_doctor = 0
  3865. //}
  3866. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3867. //
  3868. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3869. // if appRole.UserType == 3 {
  3870. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3871. // if getPermissionErr != nil {
  3872. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3873. // return
  3874. // } else if headNursePermission == nil {
  3875. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3876. // return
  3877. // }
  3878. // }
  3879. //}
  3880. prescription := models.DialysisPrescription{
  3881. UserOrgId: adminUserInfo.Org.Id,
  3882. PatientId: id,
  3883. RecordDate: recordDate.Unix(),
  3884. ModeId: mode_id,
  3885. DialysisDuration: dialysis_duration,
  3886. Dialyzer: dialyzer,
  3887. PerfusionApparatus: perfusion_apparatus,
  3888. BloodFlowVolume: blood_flow_volume,
  3889. DewaterAmount: dewater_amount,
  3890. DisplaceLiqui: displace_liqui,
  3891. ReplacementWay: replacement_way,
  3892. Anticoagulant: anticoagulant,
  3893. AnticoagulantShouji: anticoagulant_shouji,
  3894. AnticoagulantWeichi: anticoagulant_weichi,
  3895. AnticoagulantZongliang: anticoagulant_zongliang,
  3896. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3897. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3898. Kalium: kalium,
  3899. Sodium: sodium,
  3900. Calcium: calcium,
  3901. Bicarbonate: bicarbonate,
  3902. Glucose: glucose,
  3903. // DryWeight: dry_weight,
  3904. DialysateFlow: dialysate_flow,
  3905. DialysateTemperature: dialysate_temperature,
  3906. Conductivity: conductivity,
  3907. Remark: remark,
  3908. PrescriptionDoctor: prescription_doctor,
  3909. Status: 1,
  3910. CreatedTime: time.Now().Unix(),
  3911. UpdatedTime: time.Now().Unix(),
  3912. DialysisDurationMinute: dialysisDurationMinute,
  3913. DialysisDurationHour: dialysisDurationHour,
  3914. TargetUltrafiltration: targetUltrafiltration,
  3915. DialysateFormulation: dialysateFormulation,
  3916. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3917. BodyFluid: body_fluid,
  3918. SpecialMedicine: special_medicine,
  3919. SpecialMedicineOther: special_medicine_other,
  3920. DisplaceLiquiPart: displace_liqui_part,
  3921. DisplaceLiquiValue: displace_liqui_value,
  3922. BloodAccess: blood_access,
  3923. Ultrafiltration: ultrafiltration,
  3924. BodyFluidOther: body_fluid_other,
  3925. ReplacementTotal: replacement_total,
  3926. Niprocart: niprocart,
  3927. Jms: jms,
  3928. FistulaNeedleSet: fistula_needle_set,
  3929. FistulaNeedleSet16: fistula_needle_set_16,
  3930. Hemoperfusion: hemoperfusion,
  3931. DialyserSterilised: dialyser_sterilised,
  3932. Filtryzer: filtryzer,
  3933. TargetKtv: target_ktv,
  3934. Dialyzers: dialyzers,
  3935. Injector: injector,
  3936. Bloodlines: bloodlines,
  3937. TubingHemodialysis: tubing_hemodialysis,
  3938. Package: safe_package,
  3939. ALiquid: a_liquid,
  3940. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3941. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3942. }
  3943. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3944. if dialysisPrescription.ID == 0 { //新增
  3945. prescription.Creater = adminUserInfo.AdminUser.Id
  3946. } else { //修改
  3947. prescription.Creater = adminUserInfo.AdminUser.Id
  3948. //if/**/
  3949. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3950. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3951. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3952. // if getPermissionErr != nil {
  3953. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3954. // return
  3955. // } else if headNursePermission == nil {
  3956. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3957. // return
  3958. // }
  3959. //}
  3960. _, record := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  3961. if record.IsOpen == 1 {
  3962. niprocart_good_type_id, _ := beego.AppConfig.Int64("niprocart")
  3963. jms_good_type_id, _ := beego.AppConfig.Int64("jms")
  3964. fistula_needle_set_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set")
  3965. fistula_needle_set_16_good_type_id, _ := beego.AppConfig.Int64("fistula_needle_set_16")
  3966. hemoperfusion_good_type_id, _ := beego.AppConfig.Int64("hemoperfusion")
  3967. dialyser_sterilised_good_type_id, _ := beego.AppConfig.Int64("dialyser_sterilised")
  3968. filtryzer_good_type_id, _ := beego.AppConfig.Int64("filtryzer")
  3969. dialyzers_good_type_id, _ := beego.AppConfig.Int64("dialyzers")
  3970. injector_good_type_id, _ := beego.AppConfig.Int64("injector")
  3971. bloodlines_good_type_id, _ := beego.AppConfig.Int64("bloodlines")
  3972. tubingHemodialysis_good_type_id, _ := beego.AppConfig.Int64("tubingHemodialysis")
  3973. safe_package_good_type_id, _ := beego.AppConfig.Int64("package")
  3974. aliquid_good_type_id, _ := beego.AppConfig.Int64("aliquid")
  3975. err, order := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  3976. if err == nil {
  3977. if order.ID > 0 {
  3978. if dialysisPrescription.Niprocart != niprocart {
  3979. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  3980. //1.用上机透析日期查出当天的订单
  3981. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  3982. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  3983. service.UpdateOrderCount(niprocart_good_type_id, dialysisPrescription.Niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3984. //判断前端更改后的商品id的出库记录在数据库中是否存在
  3985. err, newOut := service.FindOrderInfoByGoodId(niprocart_good_type_id, niprocart, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  3986. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  3987. warehouseOutInfo := &models.WarehouseOutInfo{
  3988. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  3989. WarehouseOutId: out.ID,
  3990. Count: 1,
  3991. Status: 1,
  3992. Ctime: time.Now().Unix(),
  3993. Remark: "",
  3994. OrgId: adminUserInfo.Org.Id,
  3995. Type: 1,
  3996. Manufacturer: 0,
  3997. Dealer: 0,
  3998. IsSys: 1,
  3999. SysRecordTime: order.StartTime,
  4000. }
  4001. stockInInfo, _ := service.FindLastStockInInfoRecord(niprocart, adminUserInfo.Org.Id)
  4002. warehouseOutInfo.Price = stockInInfo.Price
  4003. warehouseOutInfo.GoodId = niprocart
  4004. warehouseOutInfo.GoodTypeId = niprocart_good_type_id
  4005. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4006. if err == nil {
  4007. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4008. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4009. if err == gorm.ErrRecordNotFound {
  4010. details := &models.AutomaticReduceDetail{
  4011. WarehouseOutId: warehouseOutInfo.ID,
  4012. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4013. PatientId: id,
  4014. Ctime: time.Now().Unix(),
  4015. Mtime: time.Now().Unix(),
  4016. Status: 1,
  4017. RecordTime: order.StartTime,
  4018. OrgId: adminUserInfo.Org.Id,
  4019. GoodId: niprocart,
  4020. GoodTypeId: niprocart_good_type_id,
  4021. }
  4022. service.AddSigleAutoReduceRecordInfo(details)
  4023. } else if err == nil {
  4024. if user.ID > 0 {
  4025. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, warehouseOutInfo)
  4026. }
  4027. }
  4028. }
  4029. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4030. if newOut.ID > 0 {
  4031. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4032. user, err := service.FindGoodUserById(niprocart_good_type_id, dialysisPrescription.Niprocart, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4033. if err == gorm.ErrRecordNotFound {
  4034. details := &models.AutomaticReduceDetail{
  4035. WarehouseOutId: newOut.ID,
  4036. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4037. PatientId: id,
  4038. Ctime: time.Now().Unix(),
  4039. Mtime: time.Now().Unix(),
  4040. Status: 1,
  4041. RecordTime: order.StartTime,
  4042. OrgId: adminUserInfo.Org.Id,
  4043. GoodId: niprocart,
  4044. GoodTypeId: niprocart_good_type_id,
  4045. }
  4046. service.AddSigleAutoReduceRecordInfo(details)
  4047. } else if err == nil {
  4048. if user.ID > 0 {
  4049. service.UpdateOrderInfoDetails(niprocart_good_type_id, dialysisPrescription.Niprocart, order.StartTime, adminUserInfo.Org.Id, id, niprocart, &newOut)
  4050. }
  4051. }
  4052. }
  4053. }
  4054. }
  4055. if dialysisPrescription.Jms != jms {
  4056. //不一致,先将原有的商品出库单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4057. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4058. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4059. service.UpdateOrderCount(jms_good_type_id, dialysisPrescription.Jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4060. //_, out := service.FindOrderInfoByGoodId(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id)
  4061. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4062. err, newOut := service.FindOrderInfoByGoodId(jms_good_type_id, jms, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4063. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4064. warehouseOutInfo := &models.WarehouseOutInfo{
  4065. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4066. WarehouseOutId: out.ID,
  4067. Count: 1,
  4068. Status: 1,
  4069. Ctime: time.Now().Unix(),
  4070. Remark: "",
  4071. OrgId: adminUserInfo.Org.Id,
  4072. Type: 1,
  4073. Manufacturer: 0,
  4074. Dealer: 0,
  4075. IsSys: 1,
  4076. SysRecordTime: order.StartTime,
  4077. }
  4078. stockInInfo, _ := service.FindLastStockInInfoRecord(jms, adminUserInfo.Org.Id)
  4079. warehouseOutInfo.Price = stockInInfo.Price
  4080. warehouseOutInfo.GoodId = jms
  4081. warehouseOutInfo.GoodTypeId = jms_good_type_id
  4082. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4083. if err == nil {
  4084. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4085. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4086. if err == gorm.ErrRecordNotFound {
  4087. details := &models.AutomaticReduceDetail{
  4088. WarehouseOutId: warehouseOutInfo.ID,
  4089. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4090. PatientId: id,
  4091. Ctime: time.Now().Unix(),
  4092. Mtime: time.Now().Unix(),
  4093. Status: 1,
  4094. RecordTime: order.StartTime,
  4095. OrgId: adminUserInfo.Org.Id,
  4096. GoodId: jms,
  4097. GoodTypeId: jms_good_type_id,
  4098. }
  4099. service.AddSigleAutoReduceRecordInfo(details)
  4100. } else if err == nil {
  4101. if user.ID > 0 {
  4102. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4103. }
  4104. }
  4105. }
  4106. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4107. if newOut.ID > 0 {
  4108. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4109. user, err := service.FindGoodUserById(jms_good_type_id, dialysisPrescription.Jms, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4110. if err == gorm.ErrRecordNotFound {
  4111. details := &models.AutomaticReduceDetail{
  4112. WarehouseOutId: newOut.ID,
  4113. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4114. PatientId: id,
  4115. Ctime: time.Now().Unix(),
  4116. Mtime: time.Now().Unix(),
  4117. Status: 1,
  4118. RecordTime: order.StartTime,
  4119. OrgId: adminUserInfo.Org.Id,
  4120. GoodId: jms,
  4121. GoodTypeId: jms_good_type_id,
  4122. }
  4123. service.AddSigleAutoReduceRecordInfo(details)
  4124. } else if err == nil {
  4125. if user.ID > 0 {
  4126. service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, &newOut)
  4127. }
  4128. }
  4129. }
  4130. }
  4131. }
  4132. if dialysisPrescription.FistulaNeedleSet != fistula_needle_set {
  4133. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4134. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4135. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4136. service.UpdateOrderCount(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4137. //_, out := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id)
  4138. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4139. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_good_type_id, fistula_needle_set, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4140. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4141. warehouseOutInfo := &models.WarehouseOutInfo{
  4142. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4143. WarehouseOutId: out.ID,
  4144. Count: 1,
  4145. Status: 1,
  4146. Ctime: time.Now().Unix(),
  4147. Remark: "",
  4148. OrgId: adminUserInfo.Org.Id,
  4149. Type: 1,
  4150. Manufacturer: 0,
  4151. Dealer: 0,
  4152. IsSys: 1,
  4153. SysRecordTime: order.StartTime,
  4154. }
  4155. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set, adminUserInfo.Org.Id)
  4156. warehouseOutInfo.Price = stockInInfo.Price
  4157. warehouseOutInfo.GoodId = fistula_needle_set
  4158. warehouseOutInfo.GoodTypeId = fistula_needle_set_good_type_id
  4159. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4160. if err == nil {
  4161. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4162. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4163. if err == gorm.ErrRecordNotFound {
  4164. details := &models.AutomaticReduceDetail{
  4165. WarehouseOutId: warehouseOutInfo.ID,
  4166. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4167. PatientId: id,
  4168. Ctime: time.Now().Unix(),
  4169. Mtime: time.Now().Unix(),
  4170. Status: 1,
  4171. RecordTime: order.StartTime,
  4172. OrgId: adminUserInfo.Org.Id,
  4173. GoodId: fistula_needle_set,
  4174. GoodTypeId: fistula_needle_set_good_type_id,
  4175. }
  4176. service.AddSigleAutoReduceRecordInfo(details)
  4177. } else if err == nil {
  4178. if user.ID > 0 {
  4179. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4180. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4181. }
  4182. }
  4183. }
  4184. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4185. if newOut.ID > 0 {
  4186. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4187. user, err := service.FindGoodUserById(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4188. if err == gorm.ErrRecordNotFound {
  4189. details := &models.AutomaticReduceDetail{
  4190. WarehouseOutId: newOut.ID,
  4191. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4192. PatientId: id,
  4193. Ctime: time.Now().Unix(),
  4194. Mtime: time.Now().Unix(),
  4195. Status: 1,
  4196. RecordTime: order.StartTime,
  4197. OrgId: adminUserInfo.Org.Id,
  4198. GoodId: fistula_needle_set,
  4199. GoodTypeId: fistula_needle_set_good_type_id,
  4200. }
  4201. service.AddSigleAutoReduceRecordInfo(details)
  4202. } else if err == nil {
  4203. if user.ID > 0 {
  4204. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4205. service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, &newOut)
  4206. }
  4207. }
  4208. }
  4209. }
  4210. }
  4211. if dialysisPrescription.FistulaNeedleSet16 != fistula_needle_set_16 {
  4212. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4213. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4214. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4215. service.UpdateOrderCount(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4216. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4217. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4218. err, newOut := service.FindOrderInfoByGoodId(fistula_needle_set_16_good_type_id, fistula_needle_set_16, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4219. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4220. warehouseOutInfo := &models.WarehouseOutInfo{
  4221. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4222. WarehouseOutId: out.ID,
  4223. Count: 1,
  4224. Status: 1,
  4225. Ctime: time.Now().Unix(),
  4226. Remark: "",
  4227. OrgId: adminUserInfo.Org.Id,
  4228. Type: 1,
  4229. Manufacturer: 0,
  4230. Dealer: 0,
  4231. IsSys: 1,
  4232. SysRecordTime: order.StartTime,
  4233. }
  4234. stockInInfo, _ := service.FindLastStockInInfoRecord(fistula_needle_set_16, adminUserInfo.Org.Id)
  4235. warehouseOutInfo.Price = stockInInfo.Price
  4236. warehouseOutInfo.GoodId = fistula_needle_set_16
  4237. warehouseOutInfo.GoodTypeId = fistula_needle_set_16_good_type_id
  4238. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4239. if err == nil {
  4240. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4241. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4242. if err == gorm.ErrRecordNotFound {
  4243. details := &models.AutomaticReduceDetail{
  4244. WarehouseOutId: warehouseOutInfo.ID,
  4245. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4246. PatientId: id,
  4247. Ctime: time.Now().Unix(),
  4248. Mtime: time.Now().Unix(),
  4249. Status: 1,
  4250. RecordTime: order.StartTime,
  4251. OrgId: adminUserInfo.Org.Id,
  4252. GoodId: fistula_needle_set_16,
  4253. GoodTypeId: fistula_needle_set_16_good_type_id,
  4254. }
  4255. service.AddSigleAutoReduceRecordInfo(details)
  4256. } else if err == nil {
  4257. if user.ID > 0 {
  4258. //service.UpdateOrderInfoDetails(jms_good_type_id, dialysisPrescription.Jms, order.StartTime, adminUserInfo.Org.Id, id, jms, warehouseOutInfo)
  4259. //service.UpdateOrderInfoDetails(fistula_needle_set_good_type_id, dialysisPrescription.FistulaNeedleSet, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set, warehouseOutInfo)
  4260. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, warehouseOutInfo)
  4261. }
  4262. }
  4263. }
  4264. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4265. if newOut.ID > 0 {
  4266. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4267. user, err := service.FindGoodUserById(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4268. if err == gorm.ErrRecordNotFound {
  4269. details := &models.AutomaticReduceDetail{
  4270. WarehouseOutId: newOut.ID,
  4271. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4272. PatientId: id,
  4273. Ctime: time.Now().Unix(),
  4274. Mtime: time.Now().Unix(),
  4275. Status: 1,
  4276. RecordTime: order.StartTime,
  4277. OrgId: adminUserInfo.Org.Id,
  4278. GoodId: fistula_needle_set_good_type_id,
  4279. GoodTypeId: fistula_needle_set_16_good_type_id,
  4280. }
  4281. service.AddSigleAutoReduceRecordInfo(details)
  4282. } else if err == nil {
  4283. if user.ID > 0 {
  4284. service.UpdateOrderInfoDetails(fistula_needle_set_16_good_type_id, dialysisPrescription.FistulaNeedleSet16, order.StartTime, adminUserInfo.Org.Id, id, fistula_needle_set_16, &newOut)
  4285. }
  4286. }
  4287. }
  4288. }
  4289. }
  4290. if dialysisPrescription.Hemoperfusion != hemoperfusion {
  4291. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4292. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4293. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4294. service.UpdateOrderCount(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4295. //_, out := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id)
  4296. //_, out := service.FindOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4297. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4298. err, newOut := service.FindOrderInfoByGoodId(hemoperfusion_good_type_id, hemoperfusion, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4299. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4300. warehouseOutInfo := &models.WarehouseOutInfo{
  4301. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4302. WarehouseOutId: out.ID,
  4303. Count: 1,
  4304. Status: 1,
  4305. Ctime: time.Now().Unix(),
  4306. Remark: "",
  4307. OrgId: adminUserInfo.Org.Id,
  4308. Type: 1,
  4309. Manufacturer: 0,
  4310. Dealer: 0,
  4311. IsSys: 1,
  4312. SysRecordTime: order.StartTime,
  4313. }
  4314. stockInInfo, _ := service.FindLastStockInInfoRecord(hemoperfusion, adminUserInfo.Org.Id)
  4315. warehouseOutInfo.Price = stockInInfo.Price
  4316. warehouseOutInfo.GoodId = hemoperfusion
  4317. warehouseOutInfo.GoodTypeId = hemoperfusion_good_type_id
  4318. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4319. if err == nil {
  4320. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4321. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4322. if err == gorm.ErrRecordNotFound {
  4323. details := &models.AutomaticReduceDetail{
  4324. WarehouseOutId: warehouseOutInfo.ID,
  4325. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4326. PatientId: id,
  4327. Ctime: time.Now().Unix(),
  4328. Mtime: time.Now().Unix(),
  4329. Status: 1,
  4330. RecordTime: order.StartTime,
  4331. OrgId: adminUserInfo.Org.Id,
  4332. GoodId: hemoperfusion,
  4333. GoodTypeId: hemoperfusion_good_type_id,
  4334. }
  4335. service.AddSigleAutoReduceRecordInfo(details)
  4336. } else if err == nil {
  4337. if user.ID > 0 {
  4338. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4339. }
  4340. }
  4341. }
  4342. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4343. if newOut.ID > 0 {
  4344. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4345. user, err := service.FindGoodUserById(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4346. if err == gorm.ErrRecordNotFound {
  4347. details := &models.AutomaticReduceDetail{
  4348. WarehouseOutId: newOut.ID,
  4349. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4350. PatientId: id,
  4351. Ctime: time.Now().Unix(),
  4352. Mtime: time.Now().Unix(),
  4353. Status: 1,
  4354. RecordTime: order.StartTime,
  4355. OrgId: adminUserInfo.Org.Id,
  4356. GoodId: hemoperfusion,
  4357. GoodTypeId: hemoperfusion_good_type_id,
  4358. }
  4359. service.AddSigleAutoReduceRecordInfo(details)
  4360. } else if err == nil {
  4361. if user.ID > 0 {
  4362. service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, &newOut)
  4363. }
  4364. }
  4365. }
  4366. }
  4367. }
  4368. if dialysisPrescription.DialyserSterilised != dialyser_sterilised {
  4369. _, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4370. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4371. service.UpdateOrderCount(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4372. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4373. err, newOut := service.FindOrderInfoByGoodId(dialyser_sterilised_good_type_id, dialyser_sterilised, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4374. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4375. warehouseOutInfo := &models.WarehouseOutInfo{
  4376. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4377. WarehouseOutId: out.WarehouseOutId,
  4378. Count: 1,
  4379. Status: 1,
  4380. Ctime: time.Now().Unix(),
  4381. Remark: "",
  4382. OrgId: adminUserInfo.Org.Id,
  4383. Type: 1,
  4384. Manufacturer: 0,
  4385. Dealer: 0,
  4386. IsSys: 1,
  4387. SysRecordTime: order.StartTime,
  4388. }
  4389. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyser_sterilised, adminUserInfo.Org.Id)
  4390. warehouseOutInfo.Price = stockInInfo.Price
  4391. warehouseOutInfo.GoodId = dialyser_sterilised
  4392. warehouseOutInfo.GoodTypeId = dialyser_sterilised_good_type_id
  4393. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4394. if err == nil {
  4395. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4396. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4397. if err == gorm.ErrRecordNotFound {
  4398. details := &models.AutomaticReduceDetail{
  4399. WarehouseOutId: warehouseOutInfo.ID,
  4400. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4401. PatientId: id,
  4402. Ctime: time.Now().Unix(),
  4403. Mtime: time.Now().Unix(),
  4404. Status: 1,
  4405. RecordTime: order.StartTime,
  4406. OrgId: adminUserInfo.Org.Id,
  4407. GoodId: dialyser_sterilised,
  4408. GoodTypeId: dialyser_sterilised_good_type_id,
  4409. }
  4410. service.AddSigleAutoReduceRecordInfo(details)
  4411. } else if err == nil {
  4412. if user.ID > 0 {
  4413. //service.UpdateOrderInfoDetails(hemoperfusion_good_type_id, dialysisPrescription.Hemoperfusion, order.StartTime, adminUserInfo.Org.Id, id, hemoperfusion, warehouseOutInfo)
  4414. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, warehouseOutInfo)
  4415. }
  4416. }
  4417. }
  4418. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4419. if newOut.ID > 0 {
  4420. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4421. user, err := service.FindGoodUserById(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4422. if err == gorm.ErrRecordNotFound {
  4423. details := &models.AutomaticReduceDetail{
  4424. WarehouseOutId: newOut.ID,
  4425. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4426. PatientId: id,
  4427. Ctime: time.Now().Unix(),
  4428. Mtime: time.Now().Unix(),
  4429. Status: 1,
  4430. RecordTime: order.StartTime,
  4431. OrgId: adminUserInfo.Org.Id,
  4432. GoodId: dialyser_sterilised,
  4433. GoodTypeId: dialyser_sterilised_good_type_id,
  4434. }
  4435. service.AddSigleAutoReduceRecordInfo(details)
  4436. } else if err == nil {
  4437. if user.ID > 0 {
  4438. service.UpdateOrderInfoDetails(dialyser_sterilised_good_type_id, dialysisPrescription.DialyserSterilised, order.StartTime, adminUserInfo.Org.Id, id, dialyser_sterilised, &newOut)
  4439. }
  4440. }
  4441. }
  4442. }
  4443. }
  4444. if dialysisPrescription.Filtryzer != filtryzer {
  4445. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4446. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4447. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4448. service.UpdateOrderCount(filtryzer_good_type_id, dialysisPrescription.Filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4449. //_, out := service.FindOrderInfoByGoodId(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id)
  4450. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4451. err, newOut := service.FindOrderInfoByGoodId(filtryzer_good_type_id, filtryzer, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4452. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4453. warehouseOutInfo := &models.WarehouseOutInfo{
  4454. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4455. WarehouseOutId: out.ID,
  4456. Count: 1,
  4457. Status: 1,
  4458. Ctime: time.Now().Unix(),
  4459. Remark: "",
  4460. OrgId: adminUserInfo.Org.Id,
  4461. Type: 1,
  4462. Manufacturer: 0,
  4463. Dealer: 0,
  4464. IsSys: 1,
  4465. SysRecordTime: order.StartTime,
  4466. }
  4467. stockInInfo, _ := service.FindLastStockInInfoRecord(filtryzer, adminUserInfo.Org.Id)
  4468. warehouseOutInfo.Price = stockInInfo.Price
  4469. warehouseOutInfo.GoodId = filtryzer
  4470. warehouseOutInfo.GoodTypeId = filtryzer_good_type_id
  4471. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4472. if err == nil {
  4473. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4474. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4475. if err == gorm.ErrRecordNotFound {
  4476. details := &models.AutomaticReduceDetail{
  4477. WarehouseOutId: warehouseOutInfo.ID,
  4478. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4479. PatientId: id,
  4480. Ctime: time.Now().Unix(),
  4481. Mtime: time.Now().Unix(),
  4482. Status: 1,
  4483. RecordTime: order.StartTime,
  4484. OrgId: adminUserInfo.Org.Id,
  4485. GoodId: filtryzer,
  4486. GoodTypeId: filtryzer_good_type_id,
  4487. }
  4488. service.AddSigleAutoReduceRecordInfo(details)
  4489. } else if err == nil {
  4490. if user.ID > 0 {
  4491. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, warehouseOutInfo)
  4492. }
  4493. }
  4494. }
  4495. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4496. if newOut.ID > 0 {
  4497. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4498. user, err := service.FindGoodUserById(filtryzer_good_type_id, dialysisPrescription.Filtryzer, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4499. if err == gorm.ErrRecordNotFound {
  4500. details := &models.AutomaticReduceDetail{
  4501. WarehouseOutId: newOut.ID,
  4502. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4503. PatientId: id,
  4504. Ctime: time.Now().Unix(),
  4505. Mtime: time.Now().Unix(),
  4506. Status: 1,
  4507. RecordTime: order.StartTime,
  4508. OrgId: adminUserInfo.Org.Id,
  4509. GoodId: filtryzer,
  4510. GoodTypeId: filtryzer_good_type_id,
  4511. }
  4512. service.AddSigleAutoReduceRecordInfo(details)
  4513. } else if err == nil {
  4514. if user.ID > 0 {
  4515. service.UpdateOrderInfoDetails(filtryzer_good_type_id, dialysisPrescription.Filtryzer, order.StartTime, adminUserInfo.Org.Id, id, filtryzer, &newOut)
  4516. }
  4517. }
  4518. }
  4519. }
  4520. }
  4521. if dialysisPrescription.Dialyzers != dialyzers {
  4522. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4523. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4524. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4525. service.UpdateOrderCount(dialyzers_good_type_id, dialysisPrescription.Dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4526. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4527. err, newOut := service.FindOrderInfoByGoodId(dialyzers_good_type_id, dialyzers, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4528. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4529. warehouseOutInfo := &models.WarehouseOutInfo{
  4530. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4531. WarehouseOutId: out.ID,
  4532. Count: 1,
  4533. Status: 1,
  4534. Ctime: time.Now().Unix(),
  4535. Remark: "",
  4536. OrgId: adminUserInfo.Org.Id,
  4537. Type: 1,
  4538. Manufacturer: 0,
  4539. Dealer: 0,
  4540. IsSys: 1,
  4541. SysRecordTime: order.StartTime,
  4542. }
  4543. stockInInfo, _ := service.FindLastStockInInfoRecord(dialyzers, adminUserInfo.Org.Id)
  4544. warehouseOutInfo.Price = stockInInfo.Price
  4545. warehouseOutInfo.GoodId = dialyzers
  4546. warehouseOutInfo.GoodTypeId = dialyzers_good_type_id
  4547. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4548. if err == nil {
  4549. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4550. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4551. if err == gorm.ErrRecordNotFound {
  4552. details := &models.AutomaticReduceDetail{
  4553. WarehouseOutId: warehouseOutInfo.ID,
  4554. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4555. PatientId: id,
  4556. Ctime: time.Now().Unix(),
  4557. Mtime: time.Now().Unix(),
  4558. Status: 1,
  4559. RecordTime: order.StartTime,
  4560. OrgId: adminUserInfo.Org.Id,
  4561. GoodId: dialyzers,
  4562. GoodTypeId: dialyzers_good_type_id,
  4563. }
  4564. service.AddSigleAutoReduceRecordInfo(details)
  4565. } else if err == nil {
  4566. if user.ID > 0 {
  4567. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, warehouseOutInfo)
  4568. }
  4569. }
  4570. }
  4571. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4572. if newOut.ID > 0 {
  4573. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4574. user, err := service.FindGoodUserById(dialyzers_good_type_id, dialysisPrescription.Dialyzers, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4575. if err == gorm.ErrRecordNotFound {
  4576. details := &models.AutomaticReduceDetail{
  4577. WarehouseOutId: newOut.ID,
  4578. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4579. PatientId: id,
  4580. Ctime: time.Now().Unix(),
  4581. Mtime: time.Now().Unix(),
  4582. Status: 1,
  4583. RecordTime: order.StartTime,
  4584. OrgId: adminUserInfo.Org.Id,
  4585. GoodId: dialyzers,
  4586. GoodTypeId: dialyzers_good_type_id,
  4587. }
  4588. service.AddSigleAutoReduceRecordInfo(details)
  4589. } else if err == nil {
  4590. if user.ID > 0 {
  4591. service.UpdateOrderInfoDetails(dialyzers_good_type_id, dialysisPrescription.Dialyzers, order.StartTime, adminUserInfo.Org.Id, id, dialyzers, &newOut)
  4592. }
  4593. }
  4594. }
  4595. }
  4596. }
  4597. if dialysisPrescription.Injector != injector {
  4598. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4599. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4600. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4601. service.UpdateOrderCount(injector_good_type_id, dialysisPrescription.Injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4602. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4603. err, newOut := service.FindOrderInfoByGoodId(injector_good_type_id, injector, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4604. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4605. warehouseOutInfo := &models.WarehouseOutInfo{
  4606. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4607. WarehouseOutId: out.ID,
  4608. Count: 1,
  4609. Status: 1,
  4610. Ctime: time.Now().Unix(),
  4611. Remark: "",
  4612. OrgId: adminUserInfo.Org.Id,
  4613. Type: 1,
  4614. Manufacturer: 0,
  4615. Dealer: 0,
  4616. IsSys: 1,
  4617. SysRecordTime: order.StartTime,
  4618. }
  4619. stockInInfo, _ := service.FindLastStockInInfoRecord(injector, adminUserInfo.Org.Id)
  4620. warehouseOutInfo.Price = stockInInfo.Price
  4621. warehouseOutInfo.GoodId = injector
  4622. warehouseOutInfo.GoodTypeId = injector_good_type_id
  4623. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4624. if err == nil {
  4625. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4626. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4627. if err == gorm.ErrRecordNotFound {
  4628. details := &models.AutomaticReduceDetail{
  4629. WarehouseOutId: warehouseOutInfo.ID,
  4630. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4631. PatientId: id,
  4632. Ctime: time.Now().Unix(),
  4633. Mtime: time.Now().Unix(),
  4634. Status: 1,
  4635. RecordTime: order.StartTime,
  4636. OrgId: adminUserInfo.Org.Id,
  4637. GoodId: injector,
  4638. GoodTypeId: injector_good_type_id,
  4639. }
  4640. service.AddSigleAutoReduceRecordInfo(details)
  4641. } else if err == nil {
  4642. if user.ID > 0 {
  4643. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, warehouseOutInfo)
  4644. }
  4645. }
  4646. }
  4647. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4648. if newOut.ID > 0 {
  4649. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4650. user, err := service.FindGoodUserById(injector_good_type_id, dialysisPrescription.Injector, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4651. if err == gorm.ErrRecordNotFound {
  4652. details := &models.AutomaticReduceDetail{
  4653. WarehouseOutId: newOut.ID,
  4654. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4655. PatientId: id,
  4656. Ctime: time.Now().Unix(),
  4657. Mtime: time.Now().Unix(),
  4658. Status: 1,
  4659. RecordTime: order.StartTime,
  4660. OrgId: adminUserInfo.Org.Id,
  4661. GoodId: injector,
  4662. GoodTypeId: injector_good_type_id,
  4663. }
  4664. service.AddSigleAutoReduceRecordInfo(details)
  4665. } else if err == nil {
  4666. if user.ID > 0 {
  4667. service.UpdateOrderInfoDetails(injector_good_type_id, dialysisPrescription.Injector, order.StartTime, adminUserInfo.Org.Id, id, injector, &newOut)
  4668. }
  4669. }
  4670. }
  4671. }
  4672. }
  4673. if dialysisPrescription.Bloodlines != bloodlines {
  4674. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4675. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4676. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4677. service.UpdateOrderCount(bloodlines_good_type_id, dialysisPrescription.Bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4678. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4679. err, newOut := service.FindOrderInfoByGoodId(bloodlines_good_type_id, bloodlines, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4680. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4681. warehouseOutInfo := &models.WarehouseOutInfo{
  4682. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4683. WarehouseOutId: out.ID,
  4684. Count: 1,
  4685. Status: 1,
  4686. Ctime: time.Now().Unix(),
  4687. Remark: "",
  4688. OrgId: adminUserInfo.Org.Id,
  4689. Type: 1,
  4690. Manufacturer: 0,
  4691. Dealer: 0,
  4692. IsSys: 1,
  4693. SysRecordTime: order.StartTime,
  4694. }
  4695. stockInInfo, _ := service.FindLastStockInInfoRecord(bloodlines, adminUserInfo.Org.Id)
  4696. warehouseOutInfo.Price = stockInInfo.Price
  4697. warehouseOutInfo.GoodId = bloodlines
  4698. warehouseOutInfo.GoodTypeId = bloodlines_good_type_id
  4699. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4700. if err == nil {
  4701. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4702. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4703. if err == gorm.ErrRecordNotFound {
  4704. details := &models.AutomaticReduceDetail{
  4705. WarehouseOutId: warehouseOutInfo.ID,
  4706. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4707. PatientId: id,
  4708. Ctime: time.Now().Unix(),
  4709. Mtime: time.Now().Unix(),
  4710. Status: 1,
  4711. RecordTime: order.StartTime,
  4712. OrgId: adminUserInfo.Org.Id,
  4713. GoodId: bloodlines,
  4714. GoodTypeId: bloodlines_good_type_id,
  4715. }
  4716. service.AddSigleAutoReduceRecordInfo(details)
  4717. } else if err == nil {
  4718. if user.ID > 0 {
  4719. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, warehouseOutInfo)
  4720. }
  4721. }
  4722. }
  4723. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4724. if newOut.ID > 0 {
  4725. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4726. user, err := service.FindGoodUserById(bloodlines_good_type_id, dialysisPrescription.Bloodlines, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4727. if err == gorm.ErrRecordNotFound {
  4728. details := &models.AutomaticReduceDetail{
  4729. WarehouseOutId: newOut.ID,
  4730. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4731. PatientId: id,
  4732. Ctime: time.Now().Unix(),
  4733. Mtime: time.Now().Unix(),
  4734. Status: 1,
  4735. RecordTime: order.StartTime,
  4736. OrgId: adminUserInfo.Org.Id,
  4737. GoodId: bloodlines,
  4738. GoodTypeId: bloodlines_good_type_id,
  4739. }
  4740. service.AddSigleAutoReduceRecordInfo(details)
  4741. } else if err == nil {
  4742. if user.ID > 0 {
  4743. service.UpdateOrderInfoDetails(bloodlines_good_type_id, dialysisPrescription.Bloodlines, order.StartTime, adminUserInfo.Org.Id, id, bloodlines, &newOut)
  4744. }
  4745. }
  4746. }
  4747. }
  4748. }
  4749. if dialysisPrescription.TubingHemodialysis != tubing_hemodialysis {
  4750. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4751. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4752. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4753. service.UpdateOrderCount(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4754. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4755. err, newOut := service.FindOrderInfoByGoodId(tubingHemodialysis_good_type_id, tubing_hemodialysis, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4756. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4757. warehouseOutInfo := &models.WarehouseOutInfo{
  4758. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4759. WarehouseOutId: out.ID,
  4760. Count: 1,
  4761. Status: 1,
  4762. Ctime: time.Now().Unix(),
  4763. Remark: "",
  4764. OrgId: adminUserInfo.Org.Id,
  4765. Type: 1,
  4766. Manufacturer: 0,
  4767. Dealer: 0,
  4768. IsSys: 1,
  4769. SysRecordTime: order.StartTime,
  4770. }
  4771. stockInInfo, _ := service.FindLastStockInInfoRecord(tubing_hemodialysis, adminUserInfo.Org.Id)
  4772. warehouseOutInfo.Price = stockInInfo.Price
  4773. warehouseOutInfo.GoodId = tubing_hemodialysis
  4774. warehouseOutInfo.GoodTypeId = tubingHemodialysis_good_type_id
  4775. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4776. if err == nil {
  4777. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4778. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4779. if err == gorm.ErrRecordNotFound {
  4780. details := &models.AutomaticReduceDetail{
  4781. WarehouseOutId: warehouseOutInfo.ID,
  4782. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4783. PatientId: id,
  4784. Ctime: time.Now().Unix(),
  4785. Mtime: time.Now().Unix(),
  4786. Status: 1,
  4787. RecordTime: order.StartTime,
  4788. OrgId: adminUserInfo.Org.Id,
  4789. GoodId: tubing_hemodialysis,
  4790. GoodTypeId: tubingHemodialysis_good_type_id,
  4791. }
  4792. service.AddSigleAutoReduceRecordInfo(details)
  4793. } else if err == nil {
  4794. if user.ID > 0 {
  4795. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, warehouseOutInfo)
  4796. }
  4797. }
  4798. }
  4799. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4800. if newOut.ID > 0 {
  4801. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4802. user, err := service.FindGoodUserById(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4803. if err == gorm.ErrRecordNotFound {
  4804. details := &models.AutomaticReduceDetail{
  4805. WarehouseOutId: newOut.ID,
  4806. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4807. PatientId: id,
  4808. Ctime: time.Now().Unix(),
  4809. Mtime: time.Now().Unix(),
  4810. Status: 1,
  4811. RecordTime: order.StartTime,
  4812. OrgId: adminUserInfo.Org.Id,
  4813. GoodId: tubing_hemodialysis,
  4814. GoodTypeId: tubingHemodialysis_good_type_id,
  4815. }
  4816. service.AddSigleAutoReduceRecordInfo(details)
  4817. } else if err == nil {
  4818. if user.ID > 0 {
  4819. service.UpdateOrderInfoDetails(tubingHemodialysis_good_type_id, dialysisPrescription.TubingHemodialysis, order.StartTime, adminUserInfo.Org.Id, id, tubing_hemodialysis, &newOut)
  4820. }
  4821. }
  4822. }
  4823. }
  4824. }
  4825. if dialysisPrescription.Package != safe_package {
  4826. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4827. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4828. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4829. service.UpdateOrderCount(safe_package_good_type_id, dialysisPrescription.Package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4830. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4831. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4832. err, newOut := service.FindOrderInfoByGoodId(safe_package_good_type_id, safe_package, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4833. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4834. warehouseOutInfo := &models.WarehouseOutInfo{
  4835. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4836. WarehouseOutId: out.ID,
  4837. Count: 1,
  4838. Status: 1,
  4839. Ctime: time.Now().Unix(),
  4840. Remark: "",
  4841. OrgId: adminUserInfo.Org.Id,
  4842. Type: 1,
  4843. Manufacturer: 0,
  4844. Dealer: 0,
  4845. IsSys: 1,
  4846. SysRecordTime: order.StartTime,
  4847. }
  4848. stockInInfo, _ := service.FindLastStockInInfoRecord(safe_package, adminUserInfo.Org.Id)
  4849. warehouseOutInfo.Price = stockInInfo.Price
  4850. warehouseOutInfo.GoodId = safe_package
  4851. warehouseOutInfo.GoodTypeId = safe_package_good_type_id
  4852. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4853. if err == nil {
  4854. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4855. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4856. if err == gorm.ErrRecordNotFound {
  4857. details := &models.AutomaticReduceDetail{
  4858. WarehouseOutId: warehouseOutInfo.ID,
  4859. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4860. PatientId: id,
  4861. Ctime: time.Now().Unix(),
  4862. Mtime: time.Now().Unix(),
  4863. Status: 1,
  4864. RecordTime: order.StartTime,
  4865. OrgId: adminUserInfo.Org.Id,
  4866. GoodId: safe_package,
  4867. GoodTypeId: safe_package_good_type_id,
  4868. }
  4869. service.AddSigleAutoReduceRecordInfo(details)
  4870. } else if err == nil {
  4871. if user.ID > 0 {
  4872. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, warehouseOutInfo)
  4873. }
  4874. }
  4875. }
  4876. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4877. if newOut.ID > 0 {
  4878. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4879. user, err := service.FindGoodUserById(safe_package_good_type_id, dialysisPrescription.Package, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4880. if err == gorm.ErrRecordNotFound {
  4881. details := &models.AutomaticReduceDetail{
  4882. WarehouseOutId: newOut.ID,
  4883. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4884. PatientId: id,
  4885. Ctime: time.Now().Unix(),
  4886. Mtime: time.Now().Unix(),
  4887. Status: 1,
  4888. RecordTime: order.StartTime,
  4889. OrgId: adminUserInfo.Org.Id,
  4890. GoodId: safe_package,
  4891. GoodTypeId: safe_package_good_type_id,
  4892. }
  4893. service.AddSigleAutoReduceRecordInfo(details)
  4894. } else if err == nil {
  4895. if user.ID > 0 {
  4896. service.UpdateOrderInfoDetails(safe_package_good_type_id, dialysisPrescription.Package, order.StartTime, adminUserInfo.Org.Id, id, safe_package, &newOut)
  4897. }
  4898. }
  4899. }
  4900. }
  4901. }
  4902. if dialysisPrescription.ALiquid != a_liquid {
  4903. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4904. _, out := service.FindStockOutOrderNumberByTime(order.DialysisDate, adminUserInfo.Org.Id)
  4905. //不一致,先将原有的商品订单数量进行减一的操作,并将原有使用记录进行修改商品信息(根据上机的日期和商品类型id,商品id)
  4906. service.UpdateOrderCount(aliquid_good_type_id, dialysisPrescription.ALiquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4907. //_, out := service.FindOldOrderInfoByGoodId(order.StartTime, adminUserInfo.Org.Id)
  4908. //判断前端更改后的商品id的出库记录在数据库中是否存在
  4909. err, newOut := service.FindOrderInfoByGoodId(aliquid_good_type_id, a_liquid, out.WarehouseOutOrderNumber, adminUserInfo.Org.Id)
  4910. if err == gorm.ErrRecordNotFound { //不存在,则新增出库记录,并更改使用人商品信息
  4911. warehouseOutInfo := &models.WarehouseOutInfo{
  4912. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  4913. WarehouseOutId: out.ID,
  4914. Count: 1,
  4915. Status: 1,
  4916. Ctime: time.Now().Unix(),
  4917. Remark: "",
  4918. OrgId: adminUserInfo.Org.Id,
  4919. Type: 1,
  4920. Manufacturer: 0,
  4921. Dealer: 0,
  4922. IsSys: 1,
  4923. SysRecordTime: order.StartTime,
  4924. }
  4925. stockInInfo, _ := service.FindLastStockInInfoRecord(a_liquid, adminUserInfo.Org.Id)
  4926. warehouseOutInfo.Price = stockInInfo.Price
  4927. warehouseOutInfo.GoodId = a_liquid
  4928. warehouseOutInfo.GoodTypeId = aliquid_good_type_id
  4929. err := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  4930. if err == nil {
  4931. //可能存在商品使用人不存在的情况,需要先判断商品使用人是否存在
  4932. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4933. if err == gorm.ErrRecordNotFound {
  4934. details := &models.AutomaticReduceDetail{
  4935. WarehouseOutId: warehouseOutInfo.ID,
  4936. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  4937. PatientId: id,
  4938. Ctime: time.Now().Unix(),
  4939. Mtime: time.Now().Unix(),
  4940. Status: 1,
  4941. RecordTime: order.StartTime,
  4942. OrgId: adminUserInfo.Org.Id,
  4943. GoodId: a_liquid,
  4944. GoodTypeId: aliquid_good_type_id,
  4945. }
  4946. service.AddSigleAutoReduceRecordInfo(details)
  4947. } else if err == nil {
  4948. if user.ID > 0 {
  4949. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, warehouseOutInfo)
  4950. }
  4951. }
  4952. }
  4953. } else if err == nil { //存在,则出库数量加1,并更改使用人商品信息
  4954. if newOut.ID > 0 {
  4955. service.UpdateStockOutInfoCount(adminUserInfo.Org.Id, newOut.ID)
  4956. user, err := service.FindGoodUserById(aliquid_good_type_id, dialysisPrescription.ALiquid, id, adminUserInfo.Org.Id, out.WarehouseOutOrderNumber)
  4957. if err == gorm.ErrRecordNotFound {
  4958. details := &models.AutomaticReduceDetail{
  4959. WarehouseOutId: newOut.ID,
  4960. WarehouseOutOrderNumber: newOut.WarehouseOutOrderNumber,
  4961. PatientId: id,
  4962. Ctime: time.Now().Unix(),
  4963. Mtime: time.Now().Unix(),
  4964. Status: 1,
  4965. RecordTime: order.StartTime,
  4966. OrgId: adminUserInfo.Org.Id,
  4967. GoodId: a_liquid,
  4968. GoodTypeId: aliquid_good_type_id,
  4969. }
  4970. service.AddSigleAutoReduceRecordInfo(details)
  4971. } else if err == nil {
  4972. if user.ID > 0 {
  4973. service.UpdateOrderInfoDetails(aliquid_good_type_id, dialysisPrescription.ALiquid, order.StartTime, adminUserInfo.Org.Id, id, a_liquid, &newOut)
  4974. }
  4975. }
  4976. }
  4977. }
  4978. }
  4979. }
  4980. }
  4981. }
  4982. //prescription.Creater = dialysisPrescription.Creater
  4983. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4984. prescription.Modifier = adminUserInfo.AdminUser.Id
  4985. prescription.ID = dialysisPrescription.ID
  4986. }
  4987. solution := models.DialysisSolution{
  4988. RegistrarsId: adminUserInfo.AdminUser.Id,
  4989. UserOrgId: adminUserInfo.Org.Id,
  4990. Doctor: prescription_doctor,
  4991. PatientId: id,
  4992. ModeId: mode_id,
  4993. DialysisDuration: dialysis_duration,
  4994. PerfusionApparatus: perfusion_apparatus,
  4995. BloodFlowVolume: blood_flow_volume,
  4996. Dewater: dewater_amount,
  4997. DisplaceLiqui: displace_liqui,
  4998. ReplacementWay: replacement_way,
  4999. Anticoagulant: anticoagulant,
  5000. AnticoagulantShouji: anticoagulant_shouji,
  5001. AnticoagulantWeichi: anticoagulant_weichi,
  5002. AnticoagulantZongliang: anticoagulant_zongliang,
  5003. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  5004. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  5005. Kalium: kalium,
  5006. Sodium: sodium,
  5007. Calcium: calcium,
  5008. Bicarbonate: bicarbonate,
  5009. Glucose: glucose,
  5010. // DryWeight: dry_weight,
  5011. DialysateFlow: dialysate_flow,
  5012. DialysateTemperature: dialysate_temperature,
  5013. Conductivity: conductivity,
  5014. Remark: remark,
  5015. Status: 1,
  5016. CreatedTime: time.Now().Unix(),
  5017. UpdatedTime: time.Now().Unix(),
  5018. DialysisDurationMinute: dialysisDurationMinute,
  5019. DialysisDurationHour: dialysisDurationHour,
  5020. TargetUltrafiltration: targetUltrafiltration,
  5021. DialysateFormulation: dialysateFormulation,
  5022. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  5023. BodyFluid: body_fluid,
  5024. SpecialMedicine: special_medicine,
  5025. SpecialMedicineOther: special_medicine_other,
  5026. DisplaceLiquiPart: displace_liqui_part,
  5027. DisplaceLiquiValue: displace_liqui_value,
  5028. BloodAccess: blood_access,
  5029. Ultrafiltration: ultrafiltration,
  5030. BodyFluidOther: body_fluid_other,
  5031. ReplacementTotal: replacement_total,
  5032. TargetKtv: target_ktv,
  5033. }
  5034. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  5035. c.ServeSuccessJSON(map[string]interface{}{
  5036. "solution": &solution,
  5037. "prescription": &prescription,
  5038. })
  5039. }
  5040. func (c *DialysisAPIController) GetAcceptsAssessment() {
  5041. patient, _ := c.GetInt64("patient", 0)
  5042. adminUserInfo := c.GetMobileAdminUserInfo()
  5043. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  5044. c.ServeSuccessJSON(map[string]interface{}{
  5045. "receiveTreatmentAsses": receiveTreatmentAsses,
  5046. })
  5047. }
  5048. func (this *DialysisAPIController) PostSignInfo() {
  5049. patientID, _ := this.GetInt64("patient_id")
  5050. recordDateStr := this.GetString("date")
  5051. if patientID <= 0 {
  5052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5053. return
  5054. }
  5055. if len(recordDateStr) == 0 {
  5056. recordDateStr = time.Now().Format("2006-01-02")
  5057. }
  5058. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5059. if parseDateErr != nil {
  5060. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  5061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5062. return
  5063. }
  5064. adminInfo := this.GetMobileAdminUserInfo()
  5065. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  5066. if err != nil {
  5067. this.ErrorLog("签名失败:%v", err)
  5068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5069. return
  5070. }
  5071. this.ServeSuccessJSON(map[string]interface{}{
  5072. "doctor_id": adminInfo.AdminUser.Id,
  5073. })
  5074. }
  5075. func (this *DialysisAPIController) GetLastMonitorRecord() {
  5076. patientID, _ := this.GetInt64("patient_id")
  5077. adminInfo := this.GetMobileAdminUserInfo()
  5078. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  5079. this.ServeSuccessJSON(map[string]interface{}{
  5080. "monitor": record,
  5081. })
  5082. }
  5083. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  5084. thisTime := time.Now()
  5085. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  5086. timeLayout := "2006-01-02 15:04:05"
  5087. loc, _ := time.LoadLocation("Local")
  5088. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5089. theAssessmentDateTime := theStartTime.Unix()
  5090. patientID, _ := this.GetInt64("patient_id")
  5091. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  5092. adminInfo := this.GetMobileAdminUserInfo()
  5093. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5094. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  5095. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  5096. var ultrafiltration_rate float64
  5097. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  5098. if prescription.ID > 0 {
  5099. fmt.Println("444444444")
  5100. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  5101. fmt.Println("4444444445555")
  5102. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5103. if template.TemplateId == 6 {
  5104. fmt.Println("12222222")
  5105. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5106. record.UltrafiltrationRate = ultrafiltration_rate
  5107. }
  5108. if template.TemplateId == 20 || template.TemplateId == 22 {
  5109. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5110. record.UltrafiltrationRate = ultrafiltration_rate
  5111. }
  5112. // 只针对方济医院
  5113. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  5114. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  5115. ultrafiltration_rate = value
  5116. record.UltrafiltrationRate = ultrafiltration_rate
  5117. }
  5118. }
  5119. }
  5120. // record.UltrafiltrationRate = ultrafiltration_rate
  5121. record.UltrafiltrationVolume = 0
  5122. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  5123. if ultrafiltration_rate > 0 {
  5124. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5125. record.UltrafiltrationVolume = value
  5126. }
  5127. }
  5128. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 { //adminInfo.Org.Id == 9538
  5129. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  5130. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5131. record.UltrafiltrationVolume = ultrafiltration_volume
  5132. }
  5133. }
  5134. this.ServeSuccessJSON(map[string]interface{}{
  5135. "monitor": record,
  5136. })
  5137. }
  5138. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  5139. record_id, _ := this.GetInt64("id")
  5140. nurseID, _ := this.GetInt64("nurse")
  5141. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  5142. bedID, _ := this.GetInt64("bed")
  5143. start_time := this.GetString("start_time")
  5144. schedual_type, _ := this.GetInt64("schedual_type")
  5145. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  5146. if record_id == 0 {
  5147. this.ErrorLog("id:%v", record_id)
  5148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5149. return
  5150. }
  5151. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5152. if parseStartDateErr != nil {
  5153. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  5154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5155. return
  5156. }
  5157. adminUserInfo := this.GetMobileAdminUserInfo()
  5158. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5159. if getNurseErr != nil {
  5160. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5162. return
  5163. } else if nurse == nil {
  5164. this.ErrorLog("护士不存在")
  5165. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5166. return
  5167. }
  5168. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  5169. if getNurseErr != nil {
  5170. this.ErrorLog("获取护士失败:%v", getNurseErr)
  5171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5172. return
  5173. } else if nurse == nil {
  5174. this.ErrorLog("护士不存在")
  5175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5176. return
  5177. }
  5178. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  5179. if getDeviceNumberErr != nil {
  5180. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  5181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5182. return
  5183. } else if deviceNumber == nil {
  5184. this.ErrorLog("床位号不存在")
  5185. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5186. return
  5187. }
  5188. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  5189. //
  5190. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  5191. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5192. // if getPermissionErr != nil {
  5193. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5194. // return
  5195. // } else if headNursePermission == nil {
  5196. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5197. // return
  5198. // }
  5199. //}
  5200. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  5201. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  5202. timeLayout := "2006-01-02 15:04:05"
  5203. loc, _ := time.LoadLocation("Local")
  5204. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5205. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  5206. schedulestartTime := theStartTime.Unix()
  5207. scheduleendTime := theEndTime.Unix()
  5208. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  5209. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  5210. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5211. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  5212. if err == gorm.ErrRecordNotFound { //空床位
  5213. // 修改了床位逻辑
  5214. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5215. if daySchedule.ID > 0 {
  5216. daySchedule.BedId = bedID
  5217. daySchedule.PartitionId = deviceNumber.ZoneID
  5218. daySchedule.ScheduleType = schedual_type
  5219. daySchedule.UpdatedTime = time.Now().Unix()
  5220. err := service.UpdateSchedule(&daySchedule)
  5221. if err != nil {
  5222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5223. return
  5224. }
  5225. }
  5226. } else if err == nil {
  5227. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  5228. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  5229. if daySchedule.ID > 0 {
  5230. daySchedule.BedId = bedID
  5231. daySchedule.PartitionId = deviceNumber.ZoneID
  5232. daySchedule.ScheduleType = schedual_type
  5233. daySchedule.UpdatedTime = time.Now().Unix()
  5234. err := service.UpdateSchedule(&daySchedule)
  5235. if err != nil {
  5236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5237. return
  5238. }
  5239. }
  5240. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  5241. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  5242. return
  5243. }
  5244. } else if err != nil {
  5245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5246. return
  5247. }
  5248. }
  5249. dialysisRecord := &models.DialysisOrder{
  5250. ID: record_id,
  5251. UserOrgId: adminUserInfo.Org.Id,
  5252. BedID: bedID,
  5253. StartNurse: nurseID,
  5254. StartTime: startDate.Unix(),
  5255. PunctureNurse: puncture_nurse,
  5256. Creator: adminUserInfo.AdminUser.Id,
  5257. Modifier: adminUserInfo.AdminUser.Id,
  5258. WashpipeNurse: washpipe_nurse,
  5259. SchedualType: schedual_type,
  5260. }
  5261. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  5262. if updateErr != nil {
  5263. this.ErrorLog("修改上机失败:%v", updateErr)
  5264. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5265. return
  5266. }
  5267. if updateErr == nil {
  5268. if tempDialysisRecord.Stage == 2 {
  5269. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5270. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5271. fmt.Println(value)
  5272. a, b := math.Modf(value)
  5273. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5274. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5275. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5276. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5277. if updateAssessmentErr != nil {
  5278. utils.ErrorLog("%v", updateAssessmentErr)
  5279. }
  5280. }
  5281. }
  5282. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5283. this.ServeSuccessJSON(map[string]interface{}{
  5284. "dialysis_order": dialysisRecords,
  5285. })
  5286. }
  5287. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5288. record_id, _ := c.GetInt64("id")
  5289. nurseID, _ := c.GetInt64("nurse")
  5290. end_time := c.GetString("end_time")
  5291. if record_id <= 0 || nurseID <= 0 {
  5292. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5293. return
  5294. }
  5295. adminUserInfo := c.GetMobileAdminUserInfo()
  5296. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5297. if getNurseErr != nil {
  5298. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5300. return
  5301. } else if nurse == nil {
  5302. c.ErrorLog("护士不存在")
  5303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5304. return
  5305. }
  5306. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5307. if parseEndDateErr != nil {
  5308. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5310. return
  5311. }
  5312. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5313. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5314. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5315. // if getPermissionErr != nil {
  5316. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5317. // return
  5318. // } else if headNursePermission == nil {
  5319. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5320. // return
  5321. // }
  5322. //}
  5323. dialysisRecord := &models.DialysisOrder{
  5324. ID: record_id,
  5325. UserOrgId: adminUserInfo.Org.Id,
  5326. EndTime: endDate.Unix(),
  5327. FinishNurse: nurseID,
  5328. FinishModifier: adminUserInfo.AdminUser.Id,
  5329. }
  5330. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5331. if updateErr != nil {
  5332. c.ErrorLog("修改下机失败:%v", updateErr)
  5333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5334. return
  5335. }
  5336. if updateErr == nil {
  5337. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5338. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5339. a, b := math.Modf(value)
  5340. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5341. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5342. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5343. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5344. if updateAssessmentErr != nil {
  5345. utils.ErrorLog("%v", updateAssessmentErr)
  5346. }
  5347. }
  5348. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5349. c.ServeSuccessJSON(map[string]interface{}{
  5350. "dialysis_order": dialysisRecords,
  5351. })
  5352. }
  5353. func (c *DialysisAPIController) GetLongAdvice() {
  5354. patient_id, _ := c.GetInt64("id")
  5355. adminUserInfo := c.GetMobileAdminUserInfo()
  5356. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5357. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5358. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5359. c.ServeSuccessJSON(map[string]interface{}{
  5360. "status": "1",
  5361. })
  5362. return
  5363. } else { //开启推送提醒
  5364. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5365. var advice_three []*models.DoctorAdvice
  5366. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  5367. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id)
  5368. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id)
  5369. for _, advice := range advices {
  5370. if advice.FrequencyType == 3 {
  5371. t := time.Now()
  5372. week := int(t.Weekday())
  5373. switch week {
  5374. case 1:
  5375. if strings.Index(advice.WeekDay, "周一") == -1 {
  5376. advice_three = append(advice_three, advice)
  5377. }
  5378. break
  5379. case 2:
  5380. if strings.Index(advice.WeekDay, "周二") == -1 {
  5381. advice_three = append(advice_three, advice)
  5382. }
  5383. break
  5384. case 3:
  5385. if strings.Index(advice.WeekDay, "周三") == -1 {
  5386. advice_three = append(advice_three, advice)
  5387. }
  5388. break
  5389. case 4:
  5390. if strings.Index(advice.WeekDay, "周四") == -1 {
  5391. advice_three = append(advice_three, advice)
  5392. }
  5393. break
  5394. case 5:
  5395. if strings.Index(advice.WeekDay, "周五") == -1 {
  5396. advice_three = append(advice_three, advice)
  5397. }
  5398. break
  5399. case 6:
  5400. if strings.Index(advice.WeekDay, "周六") == -1 {
  5401. advice_three = append(advice_three, advice)
  5402. }
  5403. break
  5404. case 0:
  5405. if strings.Index(advice.WeekDay, "周日") == -1 {
  5406. advice_three = append(advice_three, advice)
  5407. }
  5408. break
  5409. }
  5410. }
  5411. }
  5412. for _, advice := range advices_two {
  5413. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5414. now := p.Unix()
  5415. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5416. dayStr2 := "-" + dayStr
  5417. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5418. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5419. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5420. for _, ad := range advices {
  5421. advice_three = append(advice_three, ad)
  5422. }
  5423. }
  5424. if err == nil {
  5425. c.ServeSuccessJSON(map[string]interface{}{
  5426. "status": "2",
  5427. "advices": advices,
  5428. "advices_two": RemoveRepeatedElement(advice_three),
  5429. "is_open_remind": config.IsOpenRemind,
  5430. })
  5431. }
  5432. }
  5433. }
  5434. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5435. newArr = make([]*models.DoctorAdvice, 0)
  5436. for i := 0; i < len(arr); i++ {
  5437. repeat := false
  5438. for j := i + 1; j < len(arr); j++ {
  5439. if arr[i].ID == arr[j].ID {
  5440. repeat = true
  5441. break
  5442. }
  5443. }
  5444. if !repeat {
  5445. newArr = append(newArr, arr[i])
  5446. }
  5447. }
  5448. return
  5449. }
  5450. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5451. patient, _ := c.GetInt64("id", 0)
  5452. groupNo, _ := c.GetInt64("groupno", 0)
  5453. if patient <= 0 {
  5454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5455. return
  5456. }
  5457. adminUserInfo := c.GetMobileAdminUserInfo()
  5458. dataBody := make(map[string]interface{}, 0)
  5459. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5460. if err != nil {
  5461. utils.ErrorLog(err.Error())
  5462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5463. return
  5464. }
  5465. utils.ErrorLog("%v", dataBody)
  5466. timeLayout := "2006-01-02 15:04"
  5467. loc, _ := time.LoadLocation("Local")
  5468. timeLayout2 := "2006-01-02"
  5469. loc2, _ := time.LoadLocation("Local")
  5470. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5471. utils.ErrorLog("advice_type")
  5472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5473. return
  5474. }
  5475. adviceType := int64(2)
  5476. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5477. utils.ErrorLog("advice_date")
  5478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5479. return
  5480. }
  5481. adviceDate, _ := dataBody["advice_date"].(string)
  5482. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5483. AdviceDate := theTime.Unix()
  5484. RecordDate := theTime.Unix()
  5485. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5486. utils.ErrorLog("start_time")
  5487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5488. return
  5489. }
  5490. startTime, _ := dataBody["start_time"].(string)
  5491. if len(startTime) == 0 {
  5492. utils.ErrorLog("len(start_time) == 0")
  5493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5494. return
  5495. }
  5496. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5497. if err != nil {
  5498. utils.ErrorLog(err.Error())
  5499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5500. return
  5501. }
  5502. StartTime := theTime.Unix()
  5503. Remark := ""
  5504. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5505. remark, _ := dataBody["remark"].(string)
  5506. Remark = remark
  5507. }
  5508. var advices []*models.GroupAdvice
  5509. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5510. utils.ErrorLog("advices")
  5511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5512. return
  5513. }
  5514. adviceNames := dataBody["advices"].([]interface{})
  5515. for _, adviceNameMap := range adviceNames {
  5516. adviceNameM := adviceNameMap.(map[string]interface{})
  5517. var advice models.GroupAdvice
  5518. advice.Remark = Remark
  5519. advice.AdviceType = adviceType
  5520. advice.StartTime = StartTime
  5521. advice.AdviceDate = AdviceDate
  5522. advice.RecordDate = RecordDate
  5523. advice.Status = 1
  5524. advice.CreatedTime = time.Now().Unix()
  5525. advice.UpdatedTime = time.Now().Unix()
  5526. advice.StopState = 2
  5527. advice.ExecutionState = 2
  5528. advice.UserOrgId = adminUserInfo.Org.Id
  5529. advice.PatientId = patient
  5530. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5531. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5532. utils.ErrorLog("advice_name")
  5533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5534. return
  5535. }
  5536. adviceName, _ := adviceNameM["advice_name"].(string)
  5537. if len(adviceName) == 0 {
  5538. utils.ErrorLog("len(advice_name) == 0")
  5539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5540. return
  5541. }
  5542. advice.AdviceName = adviceName
  5543. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5544. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5545. advice.DrugSpec = drugSpec
  5546. }
  5547. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5548. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5549. advice.AdviceDesc = adviceDesc
  5550. }
  5551. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5552. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5553. advice.DrugSpecUnit = drugSpecUnit
  5554. }
  5555. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5556. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5557. // advice.SingleDose = singleDose
  5558. //}
  5559. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5560. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5561. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5562. }
  5563. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5564. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5565. advice.SingleDoseUnit = singleDoseUnit
  5566. }
  5567. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5568. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5569. // advice.PrescribingNumber = prescribingNumber
  5570. //}
  5571. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5572. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5573. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5574. }
  5575. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5576. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5577. advice.PrescribingNumberUnit = prescribingNumberUnit
  5578. }
  5579. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5580. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5581. advice.DeliveryWay = deliveryWay
  5582. }
  5583. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5584. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5585. advice.ExecutionFrequency = executionFrequency
  5586. }
  5587. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5588. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5589. advice.FrequencyType = frequency_type
  5590. }
  5591. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5592. day_count := int64(adviceNameM["day_count"].(float64))
  5593. advice.DayCount = day_count
  5594. }
  5595. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5596. week_day, _ := adviceNameM["week_day"].(string)
  5597. advice.WeekDay = week_day
  5598. }
  5599. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5600. template_id, _ := adviceNameM["template_id"].(string)
  5601. advice.TemplateId = template_id
  5602. }
  5603. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5604. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5605. advice.ExecutionFrequency = executionFrequency
  5606. }
  5607. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5608. children := adviceNameM["child"].([]interface{})
  5609. if len(children) > 0 {
  5610. for _, childrenMap := range children {
  5611. childMap := childrenMap.(map[string]interface{})
  5612. var child models.GroupAdvice
  5613. child.Remark = Remark
  5614. child.AdviceType = adviceType
  5615. child.StartTime = StartTime
  5616. child.AdviceDate = AdviceDate
  5617. child.RecordDate = RecordDate
  5618. child.Status = 1
  5619. child.CreatedTime = time.Now().Unix()
  5620. child.UpdatedTime = time.Now().Unix()
  5621. child.StopState = 2
  5622. child.ExecutionState = 2
  5623. child.UserOrgId = adminUserInfo.Org.Id
  5624. child.PatientId = patient
  5625. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5626. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5627. utils.ErrorLog("child advice_name")
  5628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5629. return
  5630. }
  5631. childAdviceName, _ := childMap["advice_name"].(string)
  5632. if len(childAdviceName) == 0 {
  5633. utils.ErrorLog("len(child advice_name) == 0")
  5634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5635. return
  5636. }
  5637. child.AdviceName = childAdviceName
  5638. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5639. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5640. child.AdviceDesc = childAdviceDesc
  5641. }
  5642. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5643. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5644. child.DrugSpec = childDrugSpec
  5645. }
  5646. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5647. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5648. child.DrugSpecUnit = childDrugSpecUnit
  5649. }
  5650. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5651. child.SingleDose = childMap["single_dose"].(float64)
  5652. }
  5653. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5654. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5655. child.SingleDoseUnit = childSingleDoseUnit
  5656. }
  5657. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5658. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5659. }
  5660. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5661. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5662. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5663. }
  5664. child.DeliveryWay = advice.DeliveryWay
  5665. child.ExecutionFrequency = advice.ExecutionFrequency
  5666. advice.Children = append(advice.Children, &child)
  5667. }
  5668. }
  5669. }
  5670. advices = append(advices, &advice)
  5671. }
  5672. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5673. if err != nil {
  5674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5675. return
  5676. }
  5677. c.ServeSuccessJSON(map[string]interface{}{
  5678. "msg": "ok",
  5679. "advices": list,
  5680. })
  5681. return
  5682. }
  5683. func (c *DialysisAPIController) UploadDryWeight() {
  5684. patient_id, _ := c.GetInt64("id")
  5685. dry_weight, _ := c.GetFloat("dry_weight")
  5686. doctor_id, _ := c.GetInt64("doctor_id")
  5687. remark := c.GetString("remark")
  5688. adminUserInfo := c.GetMobileAdminUserInfo()
  5689. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5690. if err == gorm.ErrRecordNotFound {
  5691. dryWeight := &models.SgjPatientDryweight{
  5692. PatientId: patient_id,
  5693. DryWeight: dry_weight,
  5694. Remakes: remark,
  5695. Ctime: time.Now().Unix(),
  5696. Mtime: time.Now().Unix(),
  5697. Creator: doctor_id,
  5698. Status: 1,
  5699. UserOrgId: adminUserInfo.Org.Id,
  5700. AdjustedValue: "/",
  5701. UserId: adminUserInfo.AdminUser.Id,
  5702. }
  5703. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5704. if createErr == nil {
  5705. c.ServeSuccessJSON(map[string]interface{}{
  5706. "msg": "提交成功",
  5707. "weight": dryWeight,
  5708. })
  5709. }
  5710. } else {
  5711. dryWeight := &models.SgjPatientDryweight{
  5712. PatientId: patient_id,
  5713. DryWeight: dry_weight,
  5714. Remakes: remark,
  5715. Ctime: time.Now().Unix(),
  5716. Mtime: time.Now().Unix(),
  5717. Creator: doctor_id,
  5718. Status: 1,
  5719. UserOrgId: adminUserInfo.Org.Id,
  5720. AdjustedValue: "/",
  5721. UserId: adminUserInfo.AdminUser.Id,
  5722. }
  5723. var value float64
  5724. value = dry_weight - weightAdjust.DryWeight
  5725. if value < 0 {
  5726. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5727. } else if value == 0 {
  5728. dryWeight.AdjustedValue = "/"
  5729. } else if value > 0 {
  5730. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5731. }
  5732. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5733. if createErr == nil {
  5734. c.ServeSuccessJSON(map[string]interface{}{
  5735. "msg": "提交成功",
  5736. "weight": dryWeight,
  5737. })
  5738. }
  5739. }
  5740. }
  5741. func (c *DialysisAPIController) GetSolution() {
  5742. patient_id, _ := c.GetInt64("patient_id")
  5743. mode_id, _ := c.GetInt64("mode_id")
  5744. adminUserInfo := c.GetMobileAdminUserInfo()
  5745. solution, err := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5746. prescription, err := service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient_id, mode_id)
  5747. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, mode_id)
  5748. if err != nil {
  5749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5750. return
  5751. }
  5752. c.ServeSuccessJSON(map[string]interface{}{
  5753. "solution": solution,
  5754. "prescription": prescription,
  5755. "system_prescription": system_prescription,
  5756. })
  5757. }
  5758. func (c *DialysisAPIController) GetSchedule() {
  5759. schedual_type, _ := c.GetInt64("schedual_type")
  5760. adminUserInfo := c.GetMobileAdminUserInfo()
  5761. timeLayout := "2006-01-02 15:04:05"
  5762. date := time.Now().Format("2006-01-02") + " 00:00:00"
  5763. loc, _ := time.LoadLocation("Local")
  5764. theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5765. scheduleTime := theStartTime.Unix()
  5766. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5767. c.ServeSuccessJSON(map[string]interface{}{
  5768. "number": deviceNumber,
  5769. })
  5770. }
  5771. func (c *DialysisAPIController) GetPatientId() {
  5772. id, _ := c.GetInt64("id")
  5773. patientId, _ := service.GetPatientId(id)
  5774. c.ServeSuccessJSON(map[string]interface{}{
  5775. "patient": patientId,
  5776. })
  5777. }
  5778. func (this *DialysisAPIController) GetDialysisSchedule() {
  5779. schedualDate := this.GetString("date")
  5780. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5781. if parseDateErr != nil {
  5782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5783. return
  5784. }
  5785. adminInfo := this.GetMobileAdminUserInfo()
  5786. orgID := adminInfo.Org.Id
  5787. redis := service.RedisClient()
  5788. defer redis.Close()
  5789. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5790. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5791. if len(scheduals) > 0 {
  5792. //缓存数据
  5793. scheduals_json, err := json.Marshal(scheduals)
  5794. if err == nil {
  5795. redis.Set(key, scheduals_json, time.Second*30)
  5796. }
  5797. }
  5798. this.ServeSuccessJSON(map[string]interface{}{
  5799. "scheduals": scheduals,
  5800. })
  5801. }