dialysis_api_controller.go 270KB

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