dialysis_api_controller.go 268KB

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