dialysis_api_controller.go 269KB

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