dialysis_api_controller.go 269KB

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