dialysis_api_controller.go 269KB

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