dialysis_api_controller.go 270KB

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