dialysis_api_controller.go 269KB

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