his_api_controller.go 597KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. beego.Router("/api/getallgoodinforlist", &HisApiController{}, "Get:GetAllGoodInforList")
  91. beego.Router("/api/savegoodlist", &HisApiController{}, "Post:SaveGoodList")
  92. beego.Router("/api/getgoodlist", &HisApiController{}, "Get:GetGoodList")
  93. beego.Router("/api/getgoodnamedetail", &HisApiController{}, "Get:GetGoodNameDetail")
  94. beego.Router("/api/updategoodlist", &HisApiController{}, "Post:UpdateGoodList")
  95. beego.Router("/api/deletegoodteam", &HisApiController{}, "Get:DeleteGoodTeam")
  96. beego.Router("/api/deletegood", &HisApiController{}, "Get:DeleteGood")
  97. }
  98. func (c *HisApiController) CheckHisPatient() {
  99. record_date := c.GetString("record_date")
  100. patient_id, _ := c.GetInt64("patient_id")
  101. timeLayout := "2006-01-02"
  102. loc, _ := time.LoadLocation("Local")
  103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  104. if err != nil {
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. recordDateTime := theTime.Unix()
  109. adminInfo := c.GetAdminUserInfo()
  110. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  111. if len(patients) > 1 {
  112. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  113. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 1,
  116. "msg": "关联",
  117. "ps": ps,
  118. "his_patient_id": patients[len(patients)-1].ID,
  119. "patient_id": patients[len(patients)-1].PatientId,
  120. })
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. }
  127. } else {
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "status": 0,
  130. "msg": "无需关联",
  131. })
  132. return
  133. }
  134. }
  135. func (c *HisApiController) AssociationHisPrescription() {
  136. record_date := c.GetString("record_date")
  137. his_patient_id, _ := c.GetInt64("his_patient_id")
  138. patient_id, _ := c.GetInt64("patient_id")
  139. p_ids := c.GetString("p_ids")
  140. p_ids_arr := strings.Split(p_ids, ",")
  141. timeLayout := "2006-01-02"
  142. loc, _ := time.LoadLocation("Local")
  143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  144. if err != nil {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. recordDateTime := theTime.Unix()
  149. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  150. if his_patient_id == 0 || his_patient.ID == 0 {
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  152. return
  153. }
  154. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  155. if err == nil {
  156. c.ServeSuccessJSON(map[string]interface{}{
  157. "msg": "关联处方成功",
  158. })
  159. return
  160. } else {
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  162. return
  163. }
  164. }
  165. //func (c *HisApiController) AssociationHisPrescription() {
  166. // record_date, _ := c.GetInt64("record_date")
  167. // his_patient_id, _ := c.GetInt64("his_patient_id")
  168. // patient_id, _ := c.GetInt64("patient_id")
  169. // p_ids := c.GetString("p_ids")
  170. // p_ids_arr := strings.Split(p_ids, ",")
  171. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  172. // if his_patient_id == 0 || his_patient.ID == 0 {
  173. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  174. // return
  175. // }
  176. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  177. // if err == nil {
  178. // c.ServeSuccessJSON(map[string]interface{}{
  179. // "msg": "关联处方成功",
  180. // })
  181. // return
  182. // } else {
  183. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  184. // return
  185. // }
  186. //}
  187. func (c *HisApiController) GetFaPiaoNumber() {
  188. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  189. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  190. fmt.Println(count)
  191. var zero string
  192. number := count + 1
  193. //if number >= 1000 {
  194. // zero = "0000" + strconv.FormatInt(number, 10)
  195. //} else if number >= 10000 {
  196. // zero = "000" + strconv.FormatInt(number, 10)
  197. //} else if number >= 100000 {
  198. // zero = "00" + strconv.FormatInt(number, 10)
  199. //} else if number >= 1000000 {
  200. // zero = "0" + strconv.FormatInt(number, 10)
  201. //} else {
  202. zero = "0" + strconv.FormatInt(number, 10)
  203. //}
  204. c.ServeSuccessJSON(map[string]interface{}{
  205. "fapiao_number": zero,
  206. })
  207. return
  208. }
  209. func (c *HisApiController) ChangeOrderDesc() {
  210. id, _ := c.GetInt64("id")
  211. desc := c.GetString("desc")
  212. change_type := c.GetString("change_type")
  213. order, _ := service.GetHisOrderByID(id)
  214. if order.ID == 0 {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  216. return
  217. }
  218. switch change_type {
  219. case "oth_desc":
  220. order.OthDesc = desc
  221. break
  222. case "cash_pay":
  223. order.CashPay = desc
  224. break
  225. case "jifen_pay":
  226. order.JifenPay = desc
  227. break
  228. case "card_desc":
  229. order.CardDesc = desc
  230. break
  231. case "band_card_pay":
  232. order.BandCardPay = desc
  233. break
  234. case "ali_pay":
  235. order.AliPay = desc
  236. break
  237. case "wechat_pay":
  238. order.WechatPay = desc
  239. break
  240. case "fa_piao_number":
  241. order.FaPiaoNumber = desc
  242. break
  243. case "fa_piao_code":
  244. order.FaPiaoCode = desc
  245. break
  246. }
  247. err := service.SaveHisOrder(&order)
  248. if err == nil {
  249. c.ServeSuccessJSON(map[string]interface{}{
  250. "msg": "修改成功",
  251. })
  252. return
  253. } else {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  255. return
  256. }
  257. }
  258. func (c *HisApiController) GetMonthHisPatient() {
  259. record_date := c.GetString("record_date")
  260. //order_status, _ := c.GetInt64("type")
  261. timeLayout := "2006-01-02"
  262. loc, _ := time.LoadLocation("Local")
  263. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  264. if err != nil {
  265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  266. return
  267. }
  268. recordDateTime := theTime.Unix()
  269. adminInfo := c.GetAdminUserInfo()
  270. var tempPatients []service.NewTempPatients
  271. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  272. // 获取当前时间
  273. now := time.Now()
  274. // 获取本月的第一天
  275. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  276. // 获取下个月的第一天
  277. nextMonth := firstDay.AddDate(0, 1, 0)
  278. // 获取本月的最后一天
  279. lastDay := nextMonth.Add(-time.Nanosecond)
  280. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  281. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  282. var patients []service.NewTempPatients
  283. var patients_two []service.NewTempPatients
  284. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. patients_two = append(patients_two, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. //}
  294. }
  295. } else {
  296. for _, item := range tempPatients {
  297. //过滤掉没挂号的和没开处方的
  298. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  299. patients = append(patients, item)
  300. }
  301. ////过滤掉没挂号的
  302. //if len(item.HisPatient) > 0 {
  303. // patients_two = append(patients_two, item)
  304. //}
  305. }
  306. }
  307. c.ServeSuccessJSON(map[string]interface{}{
  308. "list": patients,
  309. "list_two": patients_two,
  310. "chargePatients": chargePatients,
  311. })
  312. }
  313. func (c *HisApiController) GetBatchSettleAccounts() {
  314. order_ids := c.GetString("order_ids")
  315. admin_user_id, _ := c.GetInt64("admin_user_id")
  316. adminUser := c.GetAdminUserInfo()
  317. orders := strings.Split(order_ids, ",")
  318. var newOrders []models.Orders
  319. for _, item := range orders {
  320. order, _ := service.GetHisOrderByIDTenOne(item)
  321. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  322. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  323. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  324. orderInfos = append(orderInfos, orderInfos_two...)
  325. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  326. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  327. var diagnosis_ids []string
  328. if his.ID > 0 {
  329. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  330. } else {
  331. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  332. }
  333. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  334. var dia_config []*models.HisXtDiagnoseConfig
  335. var name string
  336. for _, item := range diagnosis_ids {
  337. id, _ := strconv.ParseInt(item, 10, 64)
  338. diagnosisConfig, _ := service.FindDiagnoseById(id)
  339. dia_config = append(dia_config, diagnosisConfig)
  340. if len(name) == 0 {
  341. name = diagnosisConfig.ClassName
  342. } else {
  343. name = name + "," + diagnosisConfig.ClassName
  344. }
  345. }
  346. var bedCostTotal float64 = 0 //床位总费
  347. var bedCostSelfTotal float64 = 0 //床位自费
  348. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  349. var bedSelfTotal float64 = 0 //床位部分项目自费
  350. var bedInscpTotal float64 = 0 //床位部分项目自费
  351. var operationCostTotal float64 = 0 //手术费
  352. var operationCostSelfTotal float64 = 0 //手术费
  353. var operationCostPartSelfTotal float64 = 0 //手术费
  354. var operationSelfTotal float64 = 0 //床位部分项目自费
  355. var operationInscpTotal float64 = 0 //床位部分项目自费
  356. var otherCostTotal float64 = 0 //其他费用
  357. var otherCostSelfTotal float64 = 0 //其他费用
  358. var otherCostPartSelfTotal float64 = 0 //其他费用
  359. var otherSelfTotal float64 = 0 //床位部分项目自费
  360. var otherInscpTotal float64 = 0 //床位部分项目自费
  361. var materialCostTotal float64 = 0 //材料费
  362. var materialCostSelfTotal float64 = 0 //材料费
  363. var materialCostPartSelfTotal float64 = 0 //材料费
  364. var materialSelfTotal float64 = 0 //床位部分项目自费
  365. var materialInscpTotal float64 = 0 //床位部分项目自费
  366. var westernMedicineCostTotal float64 = 0 //西药费
  367. var westernMedicineCostSelfTotal float64 = 0 //西药费
  368. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  369. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  370. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  371. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  372. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  373. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  374. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  375. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  376. var checkCostTotal float64 = 0 //检查费
  377. var checkCostSelfTotal float64 = 0 //检查费
  378. var checkCostPartSelfTotal float64 = 0 //检查费
  379. var checkSelfTotal float64 = 0 //床位部分项目自费
  380. var checkInscpTotal float64 = 0 //床位部分项目自费
  381. var laboratoryCostTotal float64 = 0 //化验费
  382. var laboratoryCostSelfTotal float64 = 0 //化验费
  383. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  384. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  385. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  386. var treatCostTotal float64 = 0 //治疗费用
  387. var treatCostSelfTotal float64 = 0 //治疗费用
  388. var treatCostPartSelfTotal float64 = 0 //治疗费用
  389. var treatSelfTotal float64 = 0 //床位部分项目自费
  390. var treatInscpTotal float64 = 0 //床位部分项目自费
  391. decimal.DivisionPrecision = 2
  392. for _, item := range orderInfos {
  393. if item.MedChrgitmType == "01" { //床位费
  394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  395. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  396. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  397. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  398. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  399. }
  400. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  401. if item.MedChrgitmType == "03" { //检查费
  402. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  403. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  404. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  405. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  406. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  407. }
  408. } else {
  409. if item.MedChrgitmType == "03" { //检查费
  410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  413. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  414. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  415. }
  416. }
  417. if item.MedChrgitmType == "04" { //化验费
  418. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  419. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  420. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  421. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  422. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  423. }
  424. if item.MedChrgitmType == "05" { //治疗费
  425. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  426. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  427. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  428. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  429. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  430. }
  431. if item.MedChrgitmType == "06" { //手术费
  432. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  433. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  434. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  435. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  436. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  437. }
  438. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  439. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  440. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  441. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  442. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  443. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  444. }
  445. if item.MedChrgitmType == "09" { //西药费
  446. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if item.MedChrgitmType == "11" { //中成费
  453. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  454. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  455. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  456. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  457. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  458. }
  459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  461. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  462. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  463. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  464. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  465. }
  466. }
  467. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  468. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  469. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  470. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  471. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  472. var doctor_name string
  473. if roles.ID == 0 {
  474. doctor_name = "管理员"
  475. } else {
  476. doctor_name = roles.UserName
  477. }
  478. yiliao_leibie := ""
  479. switch order.MedType {
  480. case "11":
  481. yiliao_leibie = "普通门诊"
  482. break
  483. case "12":
  484. yiliao_leibie = "门诊挂号"
  485. break
  486. case "13":
  487. yiliao_leibie = "急诊"
  488. break
  489. case "14":
  490. yiliao_leibie = "门诊特殊病"
  491. break
  492. case "15":
  493. yiliao_leibie = "门诊统筹"
  494. break
  495. case "16":
  496. yiliao_leibie = "门诊慢性病"
  497. break
  498. case "21":
  499. yiliao_leibie = "普通住院"
  500. break
  501. }
  502. var newOrder models.Orders
  503. newOrder.Diagnosis = name
  504. newOrder.OrderInfos = orderInfos
  505. newOrder.Number = order.MdtrtId
  506. newOrder.Date = order.SettleAccountsDate
  507. newOrder.ChargeAdmin = charge_admin
  508. newOrder.PrintorAdmin = printor_admin
  509. newOrder.Order = order
  510. newOrder.BedCostTotal = bedCostTotal
  511. newOrder.BedCostSelfTotal = bedCostSelfTotal
  512. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  513. newOrder.BedSelfTotal = bedSelfTotal
  514. newOrder.BedInscpTotal = bedInscpTotal
  515. newOrder.OperationCostTotal = operationCostTotal
  516. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  517. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  518. newOrder.OperationSelfTotal = operationSelfTotal
  519. newOrder.OperationInscpTotal = operationInscpTotal
  520. newOrder.OtherCostTotal = otherCostTotal
  521. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  522. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  523. newOrder.OtherSelfTotal = otherSelfTotal
  524. newOrder.OtherInscpTotal = otherInscpTotal
  525. newOrder.MaterialCostTotal = materialCostTotal
  526. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  527. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  528. newOrder.MaterialSelfTotal = materialSelfTotal
  529. newOrder.MaterialInscpTotal = materialInscpTotal
  530. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  531. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  532. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  533. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  534. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  535. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  536. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  537. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  538. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  539. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  540. newOrder.CheckCostTotal = checkCostTotal
  541. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  542. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  543. newOrder.CheckSelfTotal = checkSelfTotal
  544. newOrder.CheckInscpTotal = checkInscpTotal
  545. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  546. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  547. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  548. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  549. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  550. newOrder.TreatCostTotal = treatCostTotal
  551. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  552. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  553. newOrder.TreatSelfTotal = treatSelfTotal
  554. newOrder.TreatInscpTotal = treatInscpTotal
  555. newOrder.DoctorInfo = doctor_info
  556. newOrder.DoctorName = doctor_name
  557. newOrder.HealthCardNo = order.PsnNo
  558. newOrder.YiliaoLeibie = yiliao_leibie
  559. newOrder.Patient = patient
  560. newOrder.OrgName = miConfig.OrgName
  561. newOrder.OrgCode = miConfig.Code
  562. newOrder.OrderNumber = order.Number
  563. newOrder.HisPatient = his
  564. newOrder.DiaConfig = dia_config
  565. newOrders = append(newOrders, newOrder)
  566. }
  567. c.ServeSuccessJSON(map[string]interface{}{
  568. "orders": newOrders,
  569. })
  570. }
  571. func (c *HisApiController) GetTestOrder() {
  572. order_id, _ := c.GetInt64("order_id")
  573. admin_user_id, _ := c.GetInt64("admin_user_id")
  574. adminUser := c.GetAdminUserInfo()
  575. order, _ := service.GetHisOrderByID(order_id)
  576. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  577. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  578. orderInfos = append(orderInfos, orderInfos_two...)
  579. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  580. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  581. var dia_config []*models.HisXtDiagnoseConfig
  582. var name string
  583. var bedCostTotal float64 = 0 //床位总费
  584. var bedCostSelfTotal float64 = 0 //床位自费
  585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  586. var bedSelfTotal float64 = 0 //床位部分项目自费
  587. var bedInscpTotal float64 = 0 //床位部分项目自费
  588. var operationCostTotal float64 = 0 //手术费
  589. var operationCostSelfTotal float64 = 0 //手术费
  590. var operationCostPartSelfTotal float64 = 0 //手术费
  591. var operationSelfTotal float64 = 0 //床位部分项目自费
  592. var operationInscpTotal float64 = 0 //床位部分项目自费
  593. var otherCostTotal float64 = 0 //其他费用
  594. var otherCostSelfTotal float64 = 0 //其他费用
  595. var otherCostPartSelfTotal float64 = 0 //其他费用
  596. var otherSelfTotal float64 = 0 //床位部分项目自费
  597. var otherInscpTotal float64 = 0 //床位部分项目自费
  598. var materialCostTotal float64 = 0 //材料费
  599. var materialCostSelfTotal float64 = 0 //材料费
  600. var materialCostPartSelfTotal float64 = 0 //材料费
  601. var materialSelfTotal float64 = 0 //床位部分项目自费
  602. var materialInscpTotal float64 = 0 //床位部分项目自费
  603. var westernMedicineCostTotal float64 = 0 //西药费
  604. var westernMedicineCostSelfTotal float64 = 0 //西药费
  605. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  606. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  607. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  608. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  609. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  610. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  611. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  612. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  613. var checkCostTotal float64 = 0 //检查费
  614. var checkCostSelfTotal float64 = 0 //检查费
  615. var checkCostPartSelfTotal float64 = 0 //检查费
  616. var checkSelfTotal float64 = 0 //床位部分项目自费
  617. var checkInscpTotal float64 = 0 //床位部分项目自费
  618. var laboratoryCostTotal float64 = 0 //化验费
  619. var laboratoryCostSelfTotal float64 = 0 //化验费
  620. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  621. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  622. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  623. var treatCostTotal float64 = 0 //治疗费用
  624. var treatCostSelfTotal float64 = 0 //治疗费用
  625. var treatCostPartSelfTotal float64 = 0 //治疗费用
  626. var treatSelfTotal float64 = 0 //床位部分项目自费
  627. var treatInscpTotal float64 = 0 //床位部分项目自费
  628. decimal.DivisionPrecision = 2
  629. for _, item := range orderInfos {
  630. if item.MedChrgitmType == "01" { //床位费
  631. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  632. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  633. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  634. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  635. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  636. }
  637. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  638. if item.MedChrgitmType == "03" { //检查费
  639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  640. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  641. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  642. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  643. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  644. }
  645. } else {
  646. if item.MedChrgitmType == "03" { //检查费
  647. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  648. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  649. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  650. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  651. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  652. }
  653. }
  654. if item.MedChrgitmType == "04" { //化验费
  655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  656. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  657. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  658. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  659. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  660. }
  661. if item.MedChrgitmType == "05" { //治疗费
  662. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  663. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  664. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  665. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  666. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  667. }
  668. if item.MedChrgitmType == "06" { //手术费
  669. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  670. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  671. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  672. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  673. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  674. }
  675. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  676. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  677. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  678. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  679. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  680. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  681. }
  682. if item.MedChrgitmType == "09" { //西药费
  683. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  684. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  685. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  686. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  687. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  688. }
  689. if item.MedChrgitmType == "11" { //中成费
  690. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  691. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  692. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  693. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  694. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  695. }
  696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  698. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  699. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  700. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  701. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  702. }
  703. }
  704. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  705. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  706. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  707. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  708. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  709. var doctor_name string
  710. if roles.ID == 0 {
  711. doctor_name = "管理员"
  712. } else {
  713. doctor_name = roles.UserName
  714. }
  715. yiliao_leibie := ""
  716. switch order.MedType {
  717. case "11":
  718. yiliao_leibie = "普通门诊"
  719. break
  720. case "12":
  721. yiliao_leibie = "门诊挂号"
  722. break
  723. case "13":
  724. yiliao_leibie = "急诊"
  725. break
  726. case "14":
  727. yiliao_leibie = "门诊特殊病"
  728. break
  729. case "15":
  730. yiliao_leibie = "门诊统筹"
  731. break
  732. case "16":
  733. yiliao_leibie = "门诊慢性病"
  734. break
  735. case "21":
  736. yiliao_leibie = "普通住院"
  737. break
  738. }
  739. c.ServeSuccessJSON(map[string]interface{}{
  740. "diagnosis": name,
  741. "order_infos": orderInfos,
  742. "number": order.MdtrtId,
  743. "date": order.SettleAccountsDate,
  744. "charge_admin": charge_admin,
  745. "printor_admin": printor_admin,
  746. "info": order,
  747. "order": order,
  748. "bedCostTotal": bedCostTotal,
  749. "bedCostSelfTotal": bedCostSelfTotal,
  750. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  751. "bedSelfTotal": bedSelfTotal,
  752. "bedInscpTotal": bedInscpTotal,
  753. "operationCostTotal": operationCostTotal,
  754. "operationCostSelfTotal": operationCostSelfTotal,
  755. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  756. "operationSelfTotal": operationSelfTotal,
  757. "operationInscpTotal": operationInscpTotal,
  758. "otherCostTotal": otherCostTotal,
  759. "otherCostSelfTotal": otherCostSelfTotal,
  760. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  761. "otherSelfTotal": otherSelfTotal,
  762. "otherInscpTotal": otherInscpTotal,
  763. "materialCostTotal": materialCostTotal,
  764. "materialCostSelfTotal": materialCostSelfTotal,
  765. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  766. "materialSelfTotal": materialSelfTotal,
  767. "materialInscpTotal": materialInscpTotal,
  768. "westernMedicineCostTotal": westernMedicineCostTotal,
  769. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  770. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  771. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  772. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  773. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  774. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  775. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  776. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  777. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  778. "checkCostTotal": checkCostTotal,
  779. "checkCostSelfTotal": checkCostSelfTotal,
  780. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  781. "checkSelfTotal": checkSelfTotal,
  782. "checkInscpTotal": checkInscpTotal,
  783. "laboratoryCostTotal": laboratoryCostTotal,
  784. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  785. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  786. "laboratorySelfTotal": laboratorySelfTotal,
  787. "laboratoryInscpTotal": laboratoryInscpTotal,
  788. "treatCostTotal": treatCostTotal,
  789. "treatCostSelfTotal": treatCostSelfTotal,
  790. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  791. "treatSelfTotal": treatSelfTotal,
  792. "treatInscpTotal": treatInscpTotal,
  793. "doctor_info": doctor_info,
  794. "doctor_name": doctor_name,
  795. "health_card_no": order.PsnNo,
  796. "yiliao_leibie": yiliao_leibie,
  797. "patient": patient,
  798. "org_name": miConfig.OrgName,
  799. "org_code": miConfig.Code,
  800. "order_number": order.Number,
  801. "his_hospital": his_hospital,
  802. "dia_config": dia_config,
  803. })
  804. }
  805. type CustomFundPay struct {
  806. FundPayType string `json:"fund_pay_type"`
  807. FundPayamt float64 `json:"fund_payamt"`
  808. InscpScpAmt float64 `json:"inscp_scp_amt"`
  809. }
  810. func (c *PublicApiController) GetBaiLinExportData() {
  811. data := service.GetBaiLinOrderData()
  812. fmt.Println(len(data))
  813. var new_data []*models.NewCustomHisOrder
  814. for _, item := range data {
  815. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  816. new_data = append(new_data, item)
  817. }
  818. }
  819. fmt.Println(len(new_data))
  820. c.ServeSuccessJSON(map[string]interface{}{
  821. "list": new_data,
  822. })
  823. }
  824. func (c *HisApiController) GetHisUnChargePatientList() {
  825. record_date := c.GetString("record_date")
  826. sch_type, _ := c.GetInt64("sch_type")
  827. timeLayout := "2006-01-02"
  828. loc, _ := time.LoadLocation("Local")
  829. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  830. if err != nil {
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  832. return
  833. }
  834. recordDateTime := theTime.Unix()
  835. adminInfo := c.GetAdminUserInfo()
  836. var tempPatients []*service.NewTempPatients
  837. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  838. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  839. var patients []*service.NewTempPatients
  840. var patients_two []*service.NewTempPatients
  841. for _, item := range tempPatients {
  842. //过滤掉没挂号的和没开处方的
  843. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  844. patients = append(patients, item)
  845. }
  846. //过滤掉没挂号的
  847. if len(item.HisPatient) > 0 {
  848. patients_two = append(patients_two, item)
  849. }
  850. }
  851. c.ServeSuccessJSON(map[string]interface{}{
  852. "list": patients,
  853. "list_two": patients_two,
  854. })
  855. }
  856. func (c *HisApiController) GetPrivateExpensesOrder() {
  857. //id, _ := c.GetInt64("id")
  858. //record_time := c.GetString("record_time")
  859. order_id, _ := c.GetInt64("order_id")
  860. admin_user_id, _ := c.GetInt64("admin_user_id")
  861. //timeLayout := "2006-01-02"
  862. //loc, _ := time.LoadLocation("Local")
  863. //
  864. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  865. //if err != nil {
  866. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  867. // return
  868. //}
  869. //recordDateTime := theTime.Unix()
  870. adminUser := c.GetAdminUserInfo()
  871. order, _ := service.GetHisOrderByID(order_id)
  872. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  873. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  874. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  875. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  876. //var config []*models.HisXtDiagnoseConfig
  877. var name string
  878. if order.PType == 1 {
  879. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. } else {
  890. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  891. for _, item := range diagnosis_ids {
  892. id, _ := strconv.ParseInt(item, 10, 64)
  893. diagnosisConfig, _ := service.FindDiagnoseById(id)
  894. if len(name) == 0 {
  895. name = diagnosisConfig.ClassName
  896. } else {
  897. name = name + "," + diagnosisConfig.ClassName
  898. }
  899. }
  900. }
  901. var bedCostTotal float64 = 0 //床位总费
  902. var bedCostSelfTotal float64 = 0 //床位自费
  903. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  904. var bedSelfTotal float64 = 0 //床位部分项目自费
  905. var bedInscpTotal float64 = 0 //床位部分项目自费
  906. var operationCostTotal float64 = 0 //手术费
  907. var operationCostSelfTotal float64 = 0 //手术费
  908. var operationCostPartSelfTotal float64 = 0 //手术费
  909. var operationSelfTotal float64 = 0 //床位部分项目自费
  910. var operationInscpTotal float64 = 0 //床位部分项目自费
  911. var otherCostTotal float64 = 0 //其他费用
  912. //var otherCostSelfTotal float64 = 0 //其他费用
  913. var otherCostPartSelfTotal float64 = 0 //其他费用
  914. //var otherSelfTotal float64 = 0 //床位部分项目自费
  915. //var otherInscpTotal float64 = 0 //床位部分项目自费
  916. var materialCostTotal float64 = 0 //材料费
  917. var materialCostSelfTotal float64 = 0 //材料费
  918. var materialCostPartSelfTotal float64 = 0 //材料费
  919. var materialSelfTotal float64 = 0 //床位部分项目自费
  920. var materialInscpTotal float64 = 0 //床位部分项目自费
  921. var westernMedicineCostTotal float64 = 0 //西药费
  922. var westernMedicineCostSelfTotal float64 = 0 //西药费
  923. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  924. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  925. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  926. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  927. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  928. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  929. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  930. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  931. var checkCostTotal float64 = 0 //检查费
  932. var checkCostSelfTotal float64 = 0 //检查费
  933. var checkCostPartSelfTotal float64 = 0 //检查费
  934. var checkSelfTotal float64 = 0 //床位部分项目自费
  935. var checkInscpTotal float64 = 0 //床位部分项目自费
  936. var laboratoryCostTotal float64 = 0 //化验费
  937. var laboratoryCostSelfTotal float64 = 0 //化验费
  938. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  939. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  940. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  941. var treatCostTotal float64 = 0 //治疗费用
  942. var treatCostSelfTotal float64 = 0 //治疗费用
  943. var treatCostPartSelfTotal float64 = 0 //治疗费用
  944. var treatSelfTotal float64 = 0 //床位部分项目自费
  945. var treatInscpTotal float64 = 0 //床位部分项目自费
  946. var zhenChaCostTotal float64 = 0 //其他费用
  947. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  948. decimal.DivisionPrecision = 2
  949. for _, item := range orderInfos {
  950. //item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  951. if c.GetAdminUserInfo().CurrentOrgId != 10726 {
  952. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  953. item.MedChrgitmType = "09"
  954. }
  955. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  956. if item.HisPrescriptionProject.Type == 2 {
  957. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  958. fmt.Println("CostClassify")
  959. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  960. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  961. case 0:
  962. item.MedChrgitmType = "0"
  963. break
  964. case 1:
  965. item.MedChrgitmType = "14"
  966. break
  967. case 2:
  968. item.MedChrgitmType = "05"
  969. break
  970. case 3:
  971. item.MedChrgitmType = "03"
  972. break
  973. case 4:
  974. item.MedChrgitmType = "03"
  975. break
  976. case 5:
  977. item.MedChrgitmType = "08"
  978. break
  979. case 6:
  980. item.MedChrgitmType = "14"
  981. break
  982. case 7:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 8:
  986. item.MedChrgitmType = "03"
  987. break
  988. case 9:
  989. item.MedChrgitmType = "14"
  990. break
  991. case 10:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 11:
  995. item.MedChrgitmType = "06"
  996. break
  997. case 12:
  998. item.MedChrgitmType = "12"
  999. break
  1000. case 13:
  1001. item.MedChrgitmType = "01"
  1002. break
  1003. case 14:
  1004. item.MedChrgitmType = "04"
  1005. break
  1006. case 15:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. }
  1010. } else {
  1011. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  1012. case 1:
  1013. item.MedChrgitmType = "14"
  1014. break
  1015. case 2:
  1016. item.MedChrgitmType = "05"
  1017. break
  1018. case 3:
  1019. item.MedChrgitmType = "04"
  1020. break
  1021. case 4:
  1022. item.MedChrgitmType = "14"
  1023. break
  1024. case 5:
  1025. item.MedChrgitmType = "08"
  1026. break
  1027. case 6:
  1028. item.MedChrgitmType = "14"
  1029. break
  1030. case 7:
  1031. item.MedChrgitmType = "14"
  1032. break
  1033. case 8:
  1034. item.MedChrgitmType = "03"
  1035. break
  1036. case 9:
  1037. item.MedChrgitmType = "14"
  1038. break
  1039. default:
  1040. item.MedChrgitmType = "14"
  1041. break
  1042. }
  1043. }
  1044. } else if item.HisPrescriptionProject.Type == 3 {
  1045. item.MedChrgitmType = "08"
  1046. }
  1047. }
  1048. }
  1049. }
  1050. if order.IsMedicineInsurance != 1 {
  1051. order.PsnCashPay = order.MedfeeSumamt
  1052. }
  1053. for _, item := range orderInfos {
  1054. if item.MedChrgitmType == "01" { //床位费
  1055. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1059. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "02" { //诊察费
  1062. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //zhenChaCostSelfTotal = zhenChaCostTotal
  1064. }
  1065. if item.MedChrgitmType == "03" { //检查费
  1066. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1070. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "02" { //检查费
  1073. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1077. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1078. }
  1079. if item.MedChrgitmType == "04" { //化验费
  1080. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1081. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1082. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1083. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1084. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1085. }
  1086. if item.MedChrgitmType == "05" { //治疗费
  1087. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1088. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1089. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1090. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1091. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1092. }
  1093. if item.MedChrgitmType == "06" { //手术费
  1094. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1095. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1096. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1097. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1098. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1099. }
  1100. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1101. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1102. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1103. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1104. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1105. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1106. }
  1107. if item.MedChrgitmType == "09" { //西药费
  1108. fmt.Println("FulamtOwnpayAmt")
  1109. fmt.Println(item.FulamtOwnpayAmt)
  1110. fmt.Println("FulamtOwnpayAmt")
  1111. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1112. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1113. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1114. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1115. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1116. }
  1117. if item.MedChrgitmType == "11" { //中成费
  1118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1119. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1120. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1121. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1122. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  1123. }
  1124. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1125. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1126. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1127. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1128. }
  1129. }
  1130. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1131. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1132. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1133. var dia_config []*models.HisXtDiagnoseConfig
  1134. var diagnosis_ids []string
  1135. if his.ID > 0 {
  1136. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1137. } else {
  1138. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1139. }
  1140. for _, item := range diagnosis_ids {
  1141. id, _ := strconv.ParseInt(item, 10, 64)
  1142. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1143. dia_config = append(dia_config, diagnosisConfig)
  1144. }
  1145. var rf []CustomFundPay
  1146. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1147. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "patient": patient,
  1150. "order_infos": orderInfos,
  1151. "diagnosis": name,
  1152. "bedCostTotal": bedCostTotal,
  1153. "bedCostSelfTotal": bedCostSelfTotal,
  1154. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1155. "bedSelfTotal": bedSelfTotal,
  1156. "bedInscpTotal": bedInscpTotal,
  1157. "operationCostTotal": operationCostTotal,
  1158. "operationCostSelfTotal": operationCostSelfTotal,
  1159. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1160. "operationInscpTotal": operationInscpTotal,
  1161. "operationSelfTotal": operationSelfTotal,
  1162. "otherCostTotal": otherCostTotal,
  1163. //"otherCostSelfTotal": otherCostSelfTotal,
  1164. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1165. "materialCostTotal": materialCostTotal,
  1166. "materialCostSelfTotal": materialCostSelfTotal,
  1167. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1168. "materialSelfTotal": materialSelfTotal,
  1169. "materialInscpTotal": materialInscpTotal,
  1170. "westernMedicineCostTotal": westernMedicineCostTotal,
  1171. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  1172. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1173. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  1174. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  1175. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1176. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  1177. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1178. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  1179. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  1180. "checkCostTotal": checkCostTotal,
  1181. "checkCostSelfTotal": checkCostSelfTotal,
  1182. "checkSelfTotal": checkSelfTotal,
  1183. "checkInscpTotal": checkInscpTotal,
  1184. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1185. "zhenChaCostTotal": zhenChaCostTotal,
  1186. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1187. "laboratoryCostTotal": laboratoryCostTotal,
  1188. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  1189. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1190. "laboratorySelfTotal": laboratorySelfTotal,
  1191. "laboratoryInscpTotal": laboratoryInscpTotal,
  1192. "treatCostTotal": treatCostTotal,
  1193. "treatCostSelfTotal": treatCostSelfTotal,
  1194. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1195. "treatSelfTotal": treatSelfTotal,
  1196. "treatInscpTotal": treatInscpTotal,
  1197. "charge_admin": charge_admin,
  1198. "printor_admin": printor_admin,
  1199. "org_name": org.OrgName,
  1200. "org_code": miConfig.Code,
  1201. "name": patient.Name,
  1202. "number": order.MdtrtId,
  1203. "date": order.SettleAccountsDate,
  1204. "info": order,
  1205. "new_order": order,
  1206. "his_hospital": his_hospital,
  1207. "his": his,
  1208. "funds": rf,
  1209. "dia_config": dia_config,
  1210. })
  1211. }
  1212. func (c *HisApiController) RefudDetail() {
  1213. order_id, _ := c.GetInt64("order_id")
  1214. order, _ := service.GetHisOrderByID(order_id)
  1215. adminUser := c.GetAdminUserInfo()
  1216. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1217. c.ServeSuccessJSON(map[string]interface{}{
  1218. "msg": "撤销成功",
  1219. })
  1220. }
  1221. func (c *HisApiController) Sscard() {
  1222. //r := CardInit()
  1223. //if r == 0 {
  1224. // GetBaseInfo()
  1225. //}
  1226. //c.ServeSuccessJSON(map[string]interface{}{
  1227. // "list": "11",
  1228. //})
  1229. }
  1230. func GetBaseInfo() error {
  1231. //handle := syscall.MustLoadDLL("SSCard.dll")
  1232. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1233. //
  1234. //str := make([]byte, 256)
  1235. //str1 := make([]byte, 256)
  1236. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1237. //if ferr != nil {
  1238. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1239. // return ferr
  1240. //}
  1241. //
  1242. //fmt.Println(string(str))
  1243. //
  1244. //fmt.Println(r)
  1245. return nil
  1246. }
  1247. func CardInit() int {
  1248. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1249. //add := DllTestDef.MustFindProc("Init")
  1250. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1251. //if err != nil {
  1252. // fmt.Println("SSCard的运算结果为:", ret)
  1253. //}
  1254. //result := int(ret)
  1255. return 0
  1256. }
  1257. func IntPtr(n int) uintptr {
  1258. return uintptr(n)
  1259. }
  1260. func StrPtr(s string) uintptr {
  1261. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1262. }
  1263. func (c *HisApiController) GetHisPatientList() {
  1264. record_date := c.GetString("record_date")
  1265. sch_type, _ := c.GetInt64("sch_type")
  1266. patient_type, _ := c.GetInt64("patient_type")
  1267. fmt.Println("patient_type")
  1268. fmt.Println(patient_type)
  1269. timeLayout := "2006-01-02"
  1270. loc, _ := time.LoadLocation("Local")
  1271. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1272. if err != nil {
  1273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1274. return
  1275. }
  1276. recordDateTime := theTime.Unix()
  1277. adminInfo := c.GetAdminUserInfo()
  1278. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type, 0)
  1279. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type, 0)
  1280. if patient_type == 2 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1281. patients_three, _ := service.GetFuTouHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  1282. patients_four, _ := service.GetScheduleHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime)
  1283. fmt.Println(patients_three)
  1284. //获取当前用户的信息
  1285. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1286. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1287. //获取所有科室信息
  1288. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1289. //var aa []service.PatientThree
  1290. noElementsSlice := make([]service.PatientThree, 0)
  1291. c.ServeSuccessJSON(map[string]interface{}{
  1292. "list": patients_three,
  1293. "list_two": patients_four,
  1294. "list_three": noElementsSlice,
  1295. "info": adminUserInfo,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. })
  1299. } else {
  1300. //获取当前用户的信息
  1301. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1302. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1303. //获取所有科室信息
  1304. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1305. //var aa []service.PatientThree
  1306. noElementsSlice := make([]service.PatientThree, 0)
  1307. c.ServeSuccessJSON(map[string]interface{}{
  1308. "list": patients,
  1309. "list_two": patients_two,
  1310. "list_three": noElementsSlice,
  1311. "info": adminUserInfo,
  1312. "doctors": doctors,
  1313. "department": department,
  1314. })
  1315. }
  1316. }
  1317. type CustomTemplate struct {
  1318. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1319. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1320. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1321. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1322. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1323. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1324. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1325. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1326. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1327. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1328. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1329. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1330. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1331. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1332. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1333. }
  1334. func (c *HisApiController) GetHisPatientInfo() {
  1335. patient_id, _ := c.GetInt64("patient_id")
  1336. his_patient_id, _ := c.GetInt64("his_patient_id")
  1337. record_date := c.GetString("record_date")
  1338. number := c.GetString("number")
  1339. //start_time := c.GetString("start_time")
  1340. //end_time := c.GetString("end_time")
  1341. p_type, _ := c.GetInt64("p_type")
  1342. timeLayout := "2006-01-02"
  1343. loc, _ := time.LoadLocation("Local")
  1344. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1345. if err != nil {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. recordDateTime := theTime.Unix()
  1350. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1351. //if err != nil {
  1352. //
  1353. //}
  1354. //startRecordDateTime := startTime.Unix()
  1355. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1356. //if err != nil {
  1357. //
  1358. //}
  1359. //endRecordDateTime := endTime.Unix()
  1360. admin := c.GetAdminUserInfo()
  1361. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1362. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1363. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1364. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1365. pre, _ := service.GetDialysisPrescription(patient_id, admin.CurrentOrgId, recordDateTime)
  1366. var prescriptions []*models.HisPrescription
  1367. var last_prescriptions []*models.HisPrescription
  1368. var sch_prescriptions []CustomTemplate
  1369. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1370. if p_type == 1 { //住院
  1371. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1372. for _, item := range prescriptions {
  1373. for _, subItem := range item.HisDoctorAdviceInfo {
  1374. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1375. if info.RetailPrice > 0 {
  1376. subItem.Drug.MinPrice = info.RetailPrice
  1377. }
  1378. }
  1379. }
  1380. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1381. } else { //门诊
  1382. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1383. for _, item := range prescriptions {
  1384. for _, subItem := range item.HisDoctorAdviceInfo {
  1385. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1386. if info.RetailPrice > 0 {
  1387. subItem.Drug.MinPrice = info.RetailPrice
  1388. }
  1389. }
  1390. }
  1391. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1392. }
  1393. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1394. if sch.ID > 0 {
  1395. var week string
  1396. t := time.Now()
  1397. switch t.Weekday().String() {
  1398. case "Monday":
  1399. week = "周一"
  1400. break
  1401. case "Tuesday":
  1402. week = "周二"
  1403. break
  1404. case "Wednesday":
  1405. week = "周三"
  1406. break
  1407. case "Thursday":
  1408. week = "周四"
  1409. break
  1410. case "Friday":
  1411. week = "周五"
  1412. break
  1413. case "Saturday":
  1414. week = "周六"
  1415. break
  1416. case "Sunday":
  1417. week = "周日"
  1418. break
  1419. }
  1420. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1421. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1422. //根据推送频率组装新的数组
  1423. for _, item := range temp_sch_prescriptions {
  1424. var cus CustomTemplate
  1425. cus.ID = item.ID
  1426. cus.UserOrgId = item.UserOrgId
  1427. cus.PatientId = item.PatientId
  1428. cus.MedType = item.MedType
  1429. cus.RecordDate = item.RecordDate
  1430. cus.Type = item.Type
  1431. cus.PType = item.PType
  1432. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1433. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1434. if subItem.FrequencyType == 1 { //每次必推
  1435. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1436. }
  1437. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1438. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1439. }
  1440. if subItem.FrequencyType == 2 { //按照天数频率
  1441. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1442. now := p.Unix()
  1443. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1444. dayStr2 := "-" + dayStr
  1445. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1446. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1447. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1448. if len(advices) == 0 {
  1449. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1450. }
  1451. }
  1452. }
  1453. }
  1454. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1455. if subItem.Type == 2 {
  1456. if subItem.XtHisProject.MedicalStatus != 1 {
  1457. if subItem.FrequencyType == 1 {
  1458. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1459. }
  1460. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1461. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1462. }
  1463. if subItem.FrequencyType == 2 {
  1464. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1465. now := p.Unix()
  1466. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1467. dayStr2 := "-" + dayStr
  1468. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1469. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1470. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1471. if len(projects) == 0 {
  1472. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1473. }
  1474. }
  1475. }
  1476. } else if subItem.Type == 3 {
  1477. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1478. if subItem.FrequencyType == 1 {
  1479. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1480. }
  1481. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1482. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1483. }
  1484. if subItem.FrequencyType == 2 {
  1485. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1486. now := p.Unix()
  1487. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1488. dayStr2 := "-" + dayStr
  1489. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1490. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1491. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1492. if len(projects) == 0 {
  1493. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1494. }
  1495. }
  1496. }
  1497. }
  1498. }
  1499. sch_prescriptions = append(sch_prescriptions, cus)
  1500. }
  1501. for _, item := range sch_prescriptions {
  1502. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1503. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1504. }
  1505. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1506. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1507. }
  1508. }
  1509. }
  1510. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1511. if config.ID > 0 && config.IsOpen == 1 {
  1512. for _, item := range sch_prescriptions {
  1513. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1514. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1515. if info.RetailPrice > 0 {
  1516. subItem.Drug.MinPrice = info.RetailPrice
  1517. if admin.CurrentOrgId != 10598 {
  1518. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1519. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1520. }
  1521. }
  1522. }
  1523. }
  1524. }
  1525. if config.ID > 0 && config.IsOpen == 1 {
  1526. for _, item := range sch_prescriptions {
  1527. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1528. if subItem.Type == 3 {
  1529. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1530. if info.Price > 0 {
  1531. subItem.GoodInfo.PackingPrice = info.Price
  1532. if admin.CurrentOrgId != 10598 {
  1533. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1534. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1542. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1543. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1544. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1545. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1546. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1547. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1548. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1551. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1552. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1553. prescriptionInfo, _ := service.GetDialysisPresriptionById(admin.CurrentOrgId, patient_id, recordDateTime)
  1554. fmt.Println(prescriptions)
  1555. fmt.Println(sch_prescriptions)
  1556. fmt.Println(last_prescriptions)
  1557. if len(prescriptions) == 0 && c.GetAdminUserInfo().CurrentOrgId == 10721 {
  1558. if len(sch_prescriptions) > 0 {
  1559. var index = 0
  1560. for subindex, item := range sch_prescriptions {
  1561. if item.Type == 2 {
  1562. index = subindex
  1563. }
  1564. }
  1565. fmt.Println(index)
  1566. fmt.Println(len(sch_prescriptions))
  1567. if index >= 0 && index < len(sch_prescriptions) {
  1568. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1569. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1570. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1571. if one.ID > 0 {
  1572. var hpt models.HisPrescriptionProjectTemplate
  1573. hpt.Type = 3
  1574. hpt.ID = 0
  1575. hpt.PatientId = sch_prescriptions[index].PatientId
  1576. hpt.Status = 1
  1577. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1578. hpt.Mtime = time.Now().Unix()
  1579. hpt.Ctime = time.Now().Unix()
  1580. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1581. hpt.Count = "1"
  1582. hpt.Price = one.RetailPrice
  1583. hpt.ProjectId = one.ID
  1584. hpt.FeedetlSn = ""
  1585. hpt.PrescriptionId = sch_prescriptions[index].ID
  1586. hpt.Unit = one.PackingUnit
  1587. hpt.Day = "1"
  1588. hpt.SingleDose = "1"
  1589. hpt.GoodInfo = one
  1590. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1591. }
  1592. if two.ID > 0 {
  1593. var hpt models.HisPrescriptionProjectTemplate
  1594. hpt.Type = 3
  1595. hpt.ID = 0
  1596. hpt.PatientId = sch_prescriptions[index].PatientId
  1597. hpt.Status = 1
  1598. hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1599. hpt.Mtime = time.Now().Unix()
  1600. hpt.Ctime = time.Now().Unix()
  1601. hpt.RecordDate = sch_prescriptions[index].RecordDate
  1602. hpt.Count = "1"
  1603. hpt.Price = two.RetailPrice
  1604. hpt.ProjectId = two.ID
  1605. hpt.FeedetlSn = ""
  1606. hpt.PrescriptionId = sch_prescriptions[index].ID
  1607. hpt.Unit = two.PackingUnit
  1608. hpt.Day = "1"
  1609. hpt.SingleDose = "1"
  1610. hpt.GoodInfo = two
  1611. sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1612. }
  1613. //if three.ID > 0 {
  1614. // var hpt models.HisPrescriptionProjectTemplate
  1615. // hpt.Type = 3
  1616. // hpt.ID = 0
  1617. // hpt.PatientId = sch_prescriptions[index].PatientId
  1618. // hpt.Status = 1
  1619. // hpt.UserOrgId = sch_prescriptions[index].UserOrgId
  1620. // hpt.Mtime = time.Now().Unix()
  1621. // hpt.Ctime = time.Now().Unix()
  1622. // hpt.RecordDate = sch_prescriptions[index].RecordDate
  1623. // hpt.Count = "1"
  1624. // hpt.Price = three.RetailPrice
  1625. // hpt.ProjectId = three.ID
  1626. // hpt.FeedetlSn = ""
  1627. // hpt.PrescriptionId = sch_prescriptions[index].ID
  1628. // hpt.Unit = three.PackingUnit
  1629. // hpt.Day = "1"
  1630. // hpt.SingleDose = "1"
  1631. // hpt.GoodInfo = three
  1632. // sch_prescriptions[index].HisPrescriptionProjectTemplate = append(sch_prescriptions[index].HisPrescriptionProjectTemplate, &hpt)
  1633. //}
  1634. fmt.Println(sch_prescriptions)
  1635. }
  1636. } else {
  1637. if len(last_prescriptions) > 0 {
  1638. var index = 0
  1639. for subindex, item := range last_prescriptions {
  1640. if item.Type == 2 {
  1641. index = subindex
  1642. }
  1643. }
  1644. if index >= 0 && index < len(last_prescriptions) {
  1645. one, _ := service.GetGoodInformationByGoodId(pre.DialysisDialyszersId)
  1646. two, _ := service.GetGoodInformationByGoodId(pre.DialysisIrrigationId)
  1647. //three, _ := service.GetGoodInformationByGoodId(pre.DialysisStrainerId)
  1648. if one.ID > 0 {
  1649. var hpt models.HisPrescriptionProject
  1650. hpt.Type = 3
  1651. hpt.ID = 0
  1652. hpt.PatientId = last_prescriptions[index].PatientId
  1653. hpt.Status = 1
  1654. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1655. hpt.Mtime = time.Now().Unix()
  1656. hpt.Ctime = time.Now().Unix()
  1657. hpt.RecordDate = last_prescriptions[index].RecordDate
  1658. hpt.Count = "1"
  1659. hpt.Price = one.RetailPrice
  1660. hpt.ProjectId = one.ID
  1661. hpt.FeedetlSn = ""
  1662. hpt.PrescriptionId = last_prescriptions[index].ID
  1663. hpt.Unit = one.PackingUnit
  1664. hpt.Day = "1"
  1665. hpt.SingleDose = "1"
  1666. hpt.GoodInfo = one
  1667. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1668. }
  1669. if two.ID > 0 {
  1670. var hpt models.HisPrescriptionProject
  1671. hpt.Type = 3
  1672. hpt.ID = 0
  1673. hpt.PatientId = last_prescriptions[index].PatientId
  1674. hpt.Status = 1
  1675. hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1676. hpt.Mtime = time.Now().Unix()
  1677. hpt.Ctime = time.Now().Unix()
  1678. hpt.RecordDate = last_prescriptions[index].RecordDate
  1679. hpt.Count = "1"
  1680. hpt.Price = two.RetailPrice
  1681. hpt.ProjectId = two.ID
  1682. hpt.FeedetlSn = ""
  1683. hpt.PrescriptionId = last_prescriptions[index].ID
  1684. hpt.Unit = two.PackingUnit
  1685. hpt.Day = "1"
  1686. hpt.SingleDose = "1"
  1687. hpt.GoodInfo = two
  1688. last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1689. }
  1690. //if three.ID > 0 {
  1691. // var hpt models.HisPrescriptionProject
  1692. // hpt.Type = 3
  1693. // hpt.ID = 0
  1694. // hpt.PatientId = last_prescriptions[index].PatientId
  1695. // hpt.Status = 1
  1696. // hpt.UserOrgId = last_prescriptions[index].UserOrgId
  1697. // hpt.Mtime = time.Now().Unix()
  1698. // hpt.Ctime = time.Now().Unix()
  1699. // hpt.RecordDate = last_prescriptions[index].RecordDate
  1700. // hpt.Count = "1"
  1701. // hpt.Price = three.RetailPrice
  1702. // hpt.ProjectId = three.ID
  1703. // hpt.FeedetlSn = ""
  1704. // hpt.PrescriptionId = last_prescriptions[index].ID
  1705. // hpt.Unit = three.PackingUnit
  1706. // hpt.Day = "1"
  1707. // hpt.SingleDose = "1"
  1708. // hpt.GoodInfo = three
  1709. // last_prescriptions[index].HisPrescriptionProject = append(last_prescriptions[index].HisPrescriptionProject, &hpt)
  1710. //}
  1711. }
  1712. }
  1713. }
  1714. }
  1715. c.ServeSuccessJSON(map[string]interface{}{
  1716. "his_info": his_patient_info,
  1717. "xt_info": xt_patient_info,
  1718. "prescription": prescriptions,
  1719. "case_history": case_history,
  1720. "info": patientPrescriptionInfo,
  1721. //"month_prescriptions": monthPrescriptions,
  1722. "order": order,
  1723. "doctors": doctors,
  1724. "department": department,
  1725. "sch_prescriptions": sch_prescriptions,
  1726. "last_prescriptions": last_prescriptions,
  1727. "schedule": sch,
  1728. "count": count,
  1729. "drugStockConfig": drugStockConfig,
  1730. "last_info": lastPatientPrescriptionInfo,
  1731. "befor": beforThrity,
  1732. "LastCaseHistory": LastCaseHistory,
  1733. "prescriptionInfo": prescriptionInfo,
  1734. })
  1735. return
  1736. }
  1737. func (c *HisApiController) GetHisPrescriptionConfig() {
  1738. adminInfo := c.GetAdminUserInfo()
  1739. //获取医嘱模版
  1740. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1741. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1742. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1743. //获取所有基础药
  1744. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1745. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1746. if config.ID > 0 && config.IsOpen == 1 {
  1747. for _, item := range drugs {
  1748. var index = 0
  1749. for _, subItem := range item.OtherDrugWarehouseInfo {
  1750. if index == 0 {
  1751. index = index + 1
  1752. if subItem.RetailPrice > 0 {
  1753. item.MinPrice = subItem.RetailPrice
  1754. }
  1755. }
  1756. }
  1757. }
  1758. }
  1759. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1760. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1761. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1762. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1763. //获取所有科室信息
  1764. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1765. //获取诊断信息
  1766. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1767. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1768. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1769. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1770. //获取是否开启保存耗材出库的开关
  1771. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1772. c.ServeSuccessJSON(map[string]interface{}{
  1773. "drugs": drugs,
  1774. "advices_template": advices,
  1775. "drugways": drugways,
  1776. "efs": efs,
  1777. "doctors": doctors,
  1778. "department": department,
  1779. "sick": sick,
  1780. "additions": additions,
  1781. "diagnose": diagnose,
  1782. "manufacturers": manufacturers,
  1783. "goodOutOpen": goodOutOpen,
  1784. "patientDiagnose": patientDiagnose,
  1785. })
  1786. }
  1787. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1788. //获取所有基础药
  1789. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1790. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1791. if config.ID > 0 && config.IsOpen == 1 {
  1792. for _, item := range drugs {
  1793. var index = 0
  1794. for _, subItem := range item.OtherDrugWarehouseInfo {
  1795. if index == 0 {
  1796. index = index + 1
  1797. if subItem.RetailPrice > 0 {
  1798. item.MinPrice = subItem.RetailPrice
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1805. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1806. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1807. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1808. //获取所有科室信息
  1809. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1810. //获取诊断信息
  1811. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1812. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1813. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1814. //获取是否开启保存耗材出库的开关
  1815. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1816. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1817. c.ServeSuccessJSON(map[string]interface{}{
  1818. "drugs": drugs,
  1819. "advices_template": advices,
  1820. "drugways": drugways,
  1821. "efs": efs,
  1822. "doctors": doctors,
  1823. "department": department,
  1824. "sick": sick,
  1825. "additions": additions,
  1826. "diagnose": diagnose,
  1827. "manufacturers": manufacturers,
  1828. "goodOutOpen": goodOutOpen,
  1829. "patientDiagnose": patientDiagnose,
  1830. })
  1831. }
  1832. }
  1833. func (c *HisApiController) CreateHisPrescription() {
  1834. record_date := c.GetString("record_date")
  1835. patient_id, _ := c.GetInt64("patient_id")
  1836. reg_type, _ := c.GetInt64("reg_type")
  1837. diagnose := c.GetString("diagnose")
  1838. sick_type, _ := c.GetInt64("sick_type")
  1839. sick_history := c.GetString("sick_history")
  1840. doctor_id, _ := c.GetInt64("doctor", 0)
  1841. department, _ := c.GetInt64("department", 0)
  1842. his_patient_id, _ := c.GetInt64("his_patient_id")
  1843. p_type, _ := c.GetInt64("p_type")
  1844. patient_diagnose := c.GetString("patient_diagnose")
  1845. dataBody := make(map[string]interface{}, 0)
  1846. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1847. if err != nil {
  1848. utils.ErrorLog(err.Error())
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1850. return
  1851. }
  1852. //edit, src := GetCompareData(dataBody)
  1853. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1854. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1855. //fmt.Println(drugResult)
  1856. //fmt.Println(goodResult)
  1857. timeLayout := "2006-01-02"
  1858. loc, _ := time.LoadLocation("Local")
  1859. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1860. if err != nil {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. adminInfo := c.GetAdminUserInfo()
  1865. recordDateTime := theTime.Unix()
  1866. //查询默认出库仓库库存
  1867. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1868. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1869. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1870. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1871. if len(lists) == 1 {
  1872. his_patient_id = lists[0].ID
  1873. }
  1874. }
  1875. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1876. //自动出库的开关开启
  1877. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1878. //自动出库
  1879. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1880. //耗材保存处方出库
  1881. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1882. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1883. //已发药和已收费限制逻辑
  1884. isMidicine := false
  1885. isCharge := false
  1886. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1887. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1888. if len(prescriptions) > 0 {
  1889. for _, item := range prescriptions {
  1890. items := item.(map[string]interface{})
  1891. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1892. utils.ErrorLog("id")
  1893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1894. return
  1895. }
  1896. id := int64(items["id"].(float64))
  1897. if id > 0 {
  1898. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1899. if err != nil {
  1900. if new_prescription.OrderStatus == 4 {
  1901. isCharge = true
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. if isMidicine == true {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1910. return
  1911. }
  1912. if isCharge == true {
  1913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1914. return
  1915. }
  1916. // 开始主事务
  1917. db := service.XTWriteDB()
  1918. tx := db.Begin()
  1919. // 在函数结束时处理事务回滚
  1920. defer func() {
  1921. if r := recover(); r != nil {
  1922. tx.Rollback()
  1923. }
  1924. }()
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. //药品发药出库
  1927. if pharmacyConfig.IsOpen == 1 {
  1928. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1929. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1930. if len(prescriptions) > 0 {
  1931. for _, item := range prescriptions {
  1932. items := item.(map[string]interface{})
  1933. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1934. advices := items["advices"].([]interface{})
  1935. if len(advices) > 0 {
  1936. for _, advice := range advices {
  1937. var drug_id int64
  1938. var prescribing_number float64
  1939. var prescribingNumberUnit string
  1940. var adviceId int64
  1941. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1942. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1943. }
  1944. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1945. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1946. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1947. }
  1948. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1949. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1950. }
  1951. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1952. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1953. }
  1954. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1955. if drug.ID == 0 {
  1956. tx.Rollback()
  1957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1958. return
  1959. }
  1960. //查询药品的所有库存
  1961. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1962. var total_count int64
  1963. for _, it := range list {
  1964. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1965. }
  1966. totals := strconv.FormatInt(total_count, 10)
  1967. //查询该药品是否存在开药记录
  1968. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1969. //新增处方盘点库存是否充足
  1970. if advicelist.ID == 0 {
  1971. all_count, _ := strconv.ParseFloat(totals, 64)
  1972. if prescribingNumberUnit == drug.MinUnit {
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. tx.Rollback()
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1978. return
  1979. }
  1980. if prescribing_number > all_count {
  1981. tx.Rollback()
  1982. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1983. return
  1984. }
  1985. }
  1986. }
  1987. }
  1988. if prescribingNumberUnit == drug.MaxUnit {
  1989. num := prescribing_number * float64(drug.MinNumber)
  1990. if drug.IsUse != 1 {
  1991. if drug.IsProject == 0 || drug.IsProject == 2 {
  1992. if all_count == 0 {
  1993. tx.Rollback()
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1995. return
  1996. }
  1997. if num > all_count {
  1998. tx.Rollback()
  1999. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2000. return
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2007. //不使用保存处方出库
  2008. if drugOutConfig.IsOpen != 1 {
  2009. //修改处方
  2010. for _, advice := range advices {
  2011. var drug_id int64
  2012. var prescribing_number float64
  2013. var prescribingNumberUnit string
  2014. var prescribingNumber string
  2015. var adviceId int64
  2016. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2017. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2018. }
  2019. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2020. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2021. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2022. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2023. }
  2024. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2025. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2026. }
  2027. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2028. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2029. }
  2030. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2031. if drug.ID == 0 {
  2032. tx.Rollback()
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2034. return
  2035. }
  2036. //查询药品的所有库存
  2037. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2038. var total_count int64
  2039. for _, it := range list {
  2040. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2041. }
  2042. totals := strconv.FormatInt(total_count, 10)
  2043. //查询该药品是否存在开药记录
  2044. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2045. //新增处方
  2046. if advicelist.ID == 0 {
  2047. all_count, _ := strconv.ParseFloat(totals, 64)
  2048. if prescribingNumberUnit == drug.MinUnit {
  2049. if drug.IsUse != 1 {
  2050. if drug.IsProject == 0 || drug.IsProject == 2 {
  2051. if all_count == 0 {
  2052. tx.Rollback()
  2053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2054. return
  2055. }
  2056. if prescribing_number > all_count {
  2057. tx.Rollback()
  2058. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  2059. return
  2060. }
  2061. }
  2062. }
  2063. } else {
  2064. if prescribingNumberUnit == drug.MaxUnit {
  2065. num := prescribing_number * float64(drug.MinNumber)
  2066. if drug.IsUse != 1 {
  2067. if drug.IsProject == 0 || drug.IsProject == 2 {
  2068. if all_count == 0 {
  2069. tx.Rollback()
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if num > all_count {
  2074. tx.Rollback()
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. //修改处方
  2084. if advicelist.ID > 0 {
  2085. var device_number int64
  2086. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2087. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2088. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2089. device_number = prescribingNumberInt * drug.MinNumber
  2090. }
  2091. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt
  2095. }
  2096. var number_count int64
  2097. if prescribingNumberUnit == drug.MaxUnit {
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2099. number_count = prescribingNumberInt * drug.MinNumber
  2100. }
  2101. if prescribingNumberUnit == drug.MinUnit {
  2102. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2103. number_count = prescribingNumberInt
  2104. }
  2105. //如果修改的数量大于之前修改的数量
  2106. if (number_count - device_number) > 0 {
  2107. //如果修改的差数量 大于库存数量
  2108. if drug.IsUse != 1 {
  2109. if (number_count - device_number) > total_count {
  2110. tx.Rollback()
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2112. return
  2113. }
  2114. }
  2115. }
  2116. }
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. //已发药和已收费限制逻辑
  2127. //执行出库的逻辑
  2128. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  2129. //校验库存总量
  2130. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2131. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2132. if len(prescriptions) > 0 {
  2133. for _, item := range prescriptions {
  2134. items := item.(map[string]interface{})
  2135. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2136. advices := items["advices"].([]interface{})
  2137. if len(advices) > 0 {
  2138. for _, advice := range advices {
  2139. var drug_id int64
  2140. var prescribing_number float64
  2141. var prescribingNumberUnit string
  2142. var adviceId int64
  2143. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2144. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2145. }
  2146. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2147. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2148. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2149. }
  2150. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2151. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2152. }
  2153. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2154. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2155. }
  2156. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2157. if drug.ID == 0 {
  2158. tx.Rollback()
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2160. return
  2161. }
  2162. //查询药品的所有库存
  2163. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2164. var total_count int64
  2165. for _, it := range list {
  2166. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2167. }
  2168. totals := strconv.FormatInt(total_count, 10)
  2169. //查询该药品是否存在开药记录
  2170. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2171. //查询最新批次库存
  2172. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2173. var batch_number_count int64
  2174. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2175. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. all_count, _ := strconv.ParseFloat(totals, 64)
  2179. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2180. if prescribingNumberUnit == drug.MinUnit {
  2181. if drug.IsUse != 1 {
  2182. if drug.IsProject == 0 || drug.IsProject == 2 {
  2183. if all_count == 0 {
  2184. tx.Rollback()
  2185. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2186. return
  2187. }
  2188. if prescribing_number > all_count {
  2189. tx.Rollback()
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2191. return
  2192. }
  2193. }
  2194. if adminInfo.CurrentOrgId == 10215 {
  2195. if prescribing_number > batch_number_all_count {
  2196. tx.Rollback()
  2197. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2198. return
  2199. }
  2200. }
  2201. }
  2202. }
  2203. if prescribingNumberUnit == drug.MaxUnit {
  2204. num := prescribing_number * float64(drug.MinNumber)
  2205. if drug.IsUse != 1 {
  2206. if drug.IsProject == 0 || drug.IsProject == 2 {
  2207. if all_count == 0 {
  2208. tx.Rollback()
  2209. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2210. return
  2211. }
  2212. if num > all_count {
  2213. tx.Rollback()
  2214. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2215. return
  2216. }
  2217. }
  2218. if adminInfo.CurrentOrgId == 10215 {
  2219. if num > batch_number_all_count {
  2220. tx.Rollback()
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. //不是保存处方出库
  2229. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2230. if drugOutConfig.IsOpen != 1 {
  2231. //修改处方
  2232. for _, advice := range advices {
  2233. var drug_id int64
  2234. var prescribing_number float64
  2235. var prescribingNumberUnit string
  2236. var prescribingNumber string
  2237. var adviceId int64
  2238. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2239. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2240. }
  2241. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2242. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2243. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2244. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2247. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2248. }
  2249. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2250. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2251. }
  2252. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2253. if drug.ID == 0 {
  2254. tx.Rollback()
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. //查询药品的所有库存
  2259. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2260. var total_count int64
  2261. for _, it := range list {
  2262. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2263. }
  2264. totals := strconv.FormatInt(total_count, 10)
  2265. //查询该药品是否存在开药记录
  2266. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2267. //新增处方
  2268. if advicelist.ID == 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2274. all_count, _ := strconv.ParseFloat(totals, 64)
  2275. if all_count == 0 {
  2276. tx.Rollback()
  2277. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2278. return
  2279. }
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. //回退库存
  2348. }
  2349. var number_count int64
  2350. if prescribingNumberUnit == drug.MaxUnit {
  2351. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2352. number_count = prescribingNumberInt * drug.MinNumber
  2353. //回退库存
  2354. }
  2355. if prescribingNumberUnit == drug.MinUnit {
  2356. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2357. number_count = prescribingNumberInt
  2358. //回退库存
  2359. }
  2360. //如果修改的数量大于之前修改的数量
  2361. if (number_count - device_number) > 0 {
  2362. //如果修改的差数量 大于库存数量
  2363. if drug.IsUse != 1 {
  2364. if drug.IsProject == 0 || drug.IsProject == 2 {
  2365. if total_count == 0 {
  2366. tx.Rollback()
  2367. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2368. return
  2369. }
  2370. if (number_count - device_number) > total_count {
  2371. tx.Rollback()
  2372. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2373. return
  2374. }
  2375. if (number_count - device_number) > batch_number_count {
  2376. tx.Rollback()
  2377. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2378. return
  2379. }
  2380. }
  2381. if adminInfo.CurrentOrgId == 10215 {
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. //如果修改的数量大于有库存的第一个批次
  2411. if number_count > sum_in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. //药品发药
  2421. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2422. //不使用药品发药的功能
  2423. //if pharmacyConfig.IsOpen != 1 {
  2424. // if device_number != number_count {
  2425. //
  2426. // //查询该药品的出库记录
  2427. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2428. // if len(outListExport) > 0 {
  2429. // //
  2430. // for _, item := range outListExport {
  2431. // //回退库存
  2432. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2433. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2434. // }
  2435. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2436. // var stock_max_number int64
  2437. // var stock_min_number int64
  2438. //
  2439. // if number_count >= drug.MinNumber {
  2440. //
  2441. // stock_max_number = device_number / drug.MinNumber
  2442. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2443. //
  2444. // stock_min_number = device_number % drug.MinNumber
  2445. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2446. //
  2447. // } else {
  2448. //
  2449. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2450. //
  2451. // }
  2452. // }
  2453. //
  2454. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2455. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2456. // }
  2457. // }
  2458. // }
  2459. //
  2460. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2461. // var sum_count int64
  2462. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2463. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2464. // for _, its := range stockInfo {
  2465. // if its.MaxUnit == drug.MaxUnit {
  2466. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2467. // }
  2468. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2469. // }
  2470. // //更新字典里面的库存
  2471. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2472. //
  2473. // //剩余库存
  2474. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2475. //
  2476. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2477. // //减少出库数量
  2478. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2479. //
  2480. // }
  2481. //}
  2482. }
  2483. }
  2484. }
  2485. //保存处方开药
  2486. if drugOutConfig.IsOpen == 1 {
  2487. //修改处方
  2488. for _, advice := range advices {
  2489. var drug_id int64
  2490. var prescribing_number float64
  2491. var prescribingNumberUnit string
  2492. var prescribingNumber string
  2493. var adviceId int64
  2494. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2495. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2496. }
  2497. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2498. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2499. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2500. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2501. }
  2502. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2503. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2504. }
  2505. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2506. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2507. }
  2508. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2509. if drug.ID == 0 {
  2510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. //查询药品的所有库存
  2514. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2515. var total_count int64
  2516. for _, it := range list {
  2517. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2518. }
  2519. totals := strconv.FormatInt(total_count, 10)
  2520. //查询该药品是否存在开药记录
  2521. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2522. //新增处方
  2523. if advicelist.ID == 0 {
  2524. //查询最新批次库存
  2525. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2526. var batch_number_count int64
  2527. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2528. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2529. all_count, _ := strconv.ParseFloat(totals, 64)
  2530. if prescribingNumberUnit == drug.MinUnit {
  2531. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2532. if drug.IsUse != 1 {
  2533. if drug.IsProject == 0 || drug.IsProject == 2 {
  2534. if all_count == 0 {
  2535. tx.Rollback()
  2536. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2537. return
  2538. }
  2539. if prescribing_number > all_count {
  2540. tx.Rollback()
  2541. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2542. return
  2543. }
  2544. }
  2545. if adminInfo.CurrentOrgId == 10215 {
  2546. if prescribing_number > batch_number_all_count {
  2547. tx.Rollback()
  2548. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2549. return
  2550. }
  2551. }
  2552. }
  2553. } else {
  2554. if prescribingNumberUnit == drug.MaxUnit {
  2555. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2556. num := prescribing_number * float64(drug.MinNumber)
  2557. if drug.IsUse != 1 {
  2558. if drug.IsProject == 0 || drug.IsProject == 2 {
  2559. if all_count == 0 {
  2560. tx.Rollback()
  2561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2562. return
  2563. }
  2564. if num > all_count {
  2565. tx.Rollback()
  2566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2567. return
  2568. }
  2569. }
  2570. if adminInfo.CurrentOrgId == 10215 {
  2571. if prescribing_number > batch_number_all_count {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. //修改处方
  2582. if advicelist.ID > 0 {
  2583. //查询最新批次库存
  2584. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2585. var batch_number_count int64
  2586. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2587. var device_number int64
  2588. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2589. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2590. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2591. device_number = prescribingNumberInt * drug.MinNumber
  2592. }
  2593. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2594. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2595. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2596. device_number = prescribingNumberInt
  2597. }
  2598. var number_count int64
  2599. if prescribingNumberUnit == drug.MaxUnit {
  2600. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2601. number_count = prescribingNumberInt * drug.MinNumber
  2602. }
  2603. if prescribingNumberUnit == drug.MinUnit {
  2604. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2605. number_count = prescribingNumberInt
  2606. }
  2607. //如果修改的数量大于之前修改的数量
  2608. if (number_count - device_number) > 0 {
  2609. //如果修改的差数量 大于库存数量
  2610. if drug.IsUse != 1 {
  2611. if drug.IsProject == 0 || drug.IsProject == 2 {
  2612. if total_count == 0 {
  2613. tx.Rollback()
  2614. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2615. return
  2616. }
  2617. if (number_count - device_number) > total_count {
  2618. tx.Rollback()
  2619. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2620. return
  2621. }
  2622. }
  2623. if adminInfo.CurrentOrgId == 10215 {
  2624. if (number_count - device_number) > batch_number_count {
  2625. tx.Rollback()
  2626. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2627. return
  2628. }
  2629. }
  2630. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2631. //查询历史出库数据总批次
  2632. // 查询该药品最后一次出库记录
  2633. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2634. var out_count int64
  2635. var in_count int64
  2636. var stock_max_number int64
  2637. var stock_min_number int64
  2638. for _, it := range outInfo {
  2639. if it.CountUnit == drug.MaxUnit {
  2640. it.Count = it.Count * drug.MinNumber
  2641. }
  2642. out_count += it.Count
  2643. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2644. stock_max_number = warehouseInfoList.StockMaxNumber
  2645. stock_min_number = warehouseInfoList.StockMinNumber
  2646. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2647. }
  2648. if out_count > 0 {
  2649. if (number_count - device_number) > in_count {
  2650. tx.Rollback()
  2651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2652. return
  2653. }
  2654. }
  2655. // 未出库
  2656. if out_count == 0 {
  2657. var sum_in_count int64
  2658. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2659. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2660. if sum_in_count == 0 {
  2661. tx.Rollback()
  2662. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2663. return
  2664. }
  2665. //如果修改的数量大于有库存的第一个批次
  2666. if number_count > sum_in_count {
  2667. tx.Rollback()
  2668. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2669. return
  2670. }
  2671. }
  2672. }
  2673. }
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. }
  2682. }
  2683. }
  2684. }
  2685. //校验耗材库存
  2686. if goodOutConfig.IsOpen == 1 {
  2687. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2688. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2689. if len(prescriptions) > 0 {
  2690. for _, item := range prescriptions {
  2691. items := item.(map[string]interface{})
  2692. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2693. projects := items["project"].([]interface{})
  2694. if len(projects) > 0 {
  2695. for _, project := range projects {
  2696. var project_id int64
  2697. var project_type int64
  2698. var totals float64
  2699. var project_name string
  2700. var parsetotal int64
  2701. var id int64
  2702. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2703. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2704. }
  2705. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2706. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2707. }
  2708. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2709. total, _ := project.(map[string]interface{})["total"].(string)
  2710. totals, _ = strconv.ParseFloat(total, 64)
  2711. }
  2712. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2713. project_name = project.(map[string]interface{})["project_name"].(string)
  2714. }
  2715. if project_type == 3 {
  2716. //查找该耗材的出库记录
  2717. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2718. if len(goodWarehouseInfo) == 0 {
  2719. //查询耗材库存
  2720. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2721. var stock_count int64
  2722. for _, it := range list {
  2723. stock_count += it.StockCount
  2724. }
  2725. stock_counts := strconv.FormatInt(stock_count, 10)
  2726. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2727. if stock_total_count == 0 {
  2728. tx.Rollback()
  2729. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2730. return
  2731. }
  2732. if totals > stock_total_count {
  2733. tx.Rollback()
  2734. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2735. return
  2736. }
  2737. }
  2738. if len(goodWarehouseInfo) > 0 {
  2739. //查询该患者耗材的历史数据
  2740. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2741. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2742. //数量发生改变
  2743. if parsetotal != count {
  2744. //如果现在的数量大于历史数量,就要看库存是否足够
  2745. if parsetotal > count {
  2746. //查询耗材所有库存
  2747. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2748. var stock_count int64
  2749. for _, it := range list {
  2750. stock_count += it.StockCount
  2751. }
  2752. //库存不足
  2753. if stock_count == 0 {
  2754. tx.Rollback()
  2755. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2756. return
  2757. }
  2758. if (parsetotal - count) > stock_count {
  2759. tx.Rollback()
  2760. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2761. return
  2762. }
  2763. }
  2764. }
  2765. }
  2766. }
  2767. }
  2768. }
  2769. }
  2770. }
  2771. }
  2772. }
  2773. }
  2774. //不使用耗材保存处方出库
  2775. if goodOutConfig.IsOpen != 1 {
  2776. if stockConfig.IsOpen == 1 {
  2777. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2778. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. items := item.(map[string]interface{})
  2782. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2783. projects := items["project"].([]interface{})
  2784. if len(projects) > 0 {
  2785. for _, project := range projects {
  2786. var project_id int64
  2787. var project_type int64
  2788. var totals float64
  2789. var project_name string
  2790. var parsetotal int64
  2791. var id int64
  2792. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2793. id = int64(project.(map[string]interface{})["id"].(float64))
  2794. }
  2795. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2796. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2797. }
  2798. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2799. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2800. }
  2801. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2802. total, _ := project.(map[string]interface{})["total"].(string)
  2803. totals, _ = strconv.ParseFloat(total, 64)
  2804. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2805. }
  2806. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2807. project_name = project.(map[string]interface{})["project_name"].(string)
  2808. }
  2809. if project_type == 3 {
  2810. //查找该耗材的出库记录
  2811. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2812. //没有出库记录
  2813. if len(goodWarehouseInfo) == 0 {
  2814. //查询耗材库存
  2815. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2816. var stock_count int64
  2817. for _, it := range list {
  2818. stock_count += it.StockCount
  2819. }
  2820. stock_counts := strconv.FormatInt(stock_count, 10)
  2821. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2822. if stock_total_count == 0 {
  2823. tx.Rollback()
  2824. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2825. return
  2826. }
  2827. if totals > stock_total_count {
  2828. tx.Rollback()
  2829. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2830. return
  2831. }
  2832. //查找今日该患者已经出库的所有耗材
  2833. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2834. for _, item := range goodList {
  2835. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2836. var flush_count int64
  2837. for _, it := range goodListSix {
  2838. flush_count += it.StockCount
  2839. }
  2840. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2841. creater := adminInfo.AdminUser.Id
  2842. if errs != nil {
  2843. goodErrcode := models.XtGoodErrcode{
  2844. UserOrgId: item.OrgId,
  2845. Errcode: "手动出库更新剩余出库失败",
  2846. GoodId: item.GoodId,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Count: 0,
  2851. StockCount: 0,
  2852. Creater: creater,
  2853. BatchNumberId: 0,
  2854. WarehouseOutId: 0,
  2855. }
  2856. service.CreateGoodErrcode(goodErrcode)
  2857. }
  2858. }
  2859. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2860. }
  2861. //有出库记录
  2862. if len(goodWarehouseInfo) > 0 {
  2863. //查询该患者耗材的历史数据
  2864. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2865. fmt.Println("ordProject-----------------------", ordProject.ProjectId)
  2866. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2867. //数量发生改变
  2868. if parsetotal != count {
  2869. //查找今日该患者已经出库的所有耗材
  2870. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2871. for _, item := range goodList {
  2872. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2873. var flush_count int64
  2874. for _, it := range goodListSix {
  2875. flush_count += it.StockCount
  2876. }
  2877. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2878. //减少出库数量
  2879. creater := adminInfo.AdminUser.Id
  2880. if errs != nil {
  2881. goodErrcode := models.XtGoodErrcode{
  2882. UserOrgId: item.OrgId,
  2883. Errcode: "手动出库更新剩余出库失败",
  2884. GoodId: item.GoodId,
  2885. Status: 1,
  2886. Ctime: time.Now().Unix(),
  2887. Mtime: 0,
  2888. Count: 0,
  2889. StockCount: 0,
  2890. Creater: creater,
  2891. BatchNumberId: 0,
  2892. WarehouseOutId: 0,
  2893. }
  2894. service.CreateGoodErrcode(goodErrcode)
  2895. }
  2896. //查询默认仓库
  2897. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2898. var total_count int64
  2899. for _, it := range stockList {
  2900. total_count += it.StockCount
  2901. }
  2902. //基础库插入数据
  2903. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2904. }
  2905. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2906. }
  2907. }
  2908. }
  2909. }
  2910. }
  2911. }
  2912. }
  2913. }
  2914. }
  2915. }
  2916. }
  2917. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2918. var hpInfo models.HisPrescriptionInfo
  2919. if info.ID == 0 {
  2920. var randNum int
  2921. randNum = rand.Intn(10000) + 1000
  2922. timestamp := time.Now().Unix()
  2923. tempTime := time.Unix(timestamp, 0)
  2924. timeFormat := tempTime.Format("20060102150405")
  2925. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2926. hpInfo = models.HisPrescriptionInfo{
  2927. HisPatientId: his_patient_id,
  2928. UserOrgId: adminInfo.CurrentOrgId,
  2929. RecordDate: theTime.Unix(),
  2930. PatientId: patient_id,
  2931. Status: 1,
  2932. Ctime: time.Now().Unix(),
  2933. Mtime: time.Now().Unix(),
  2934. Creator: adminInfo.AdminUser.Id,
  2935. Modifier: adminInfo.AdminUser.Id,
  2936. Diagnosis: diagnose,
  2937. SickHistory: sick_history,
  2938. Departments: department,
  2939. RegisterType: reg_type,
  2940. PrescriptionNumber: p_number,
  2941. PrescriptionStatus: 1,
  2942. Doctor: role.UserName,
  2943. DoctorId: doctor_id,
  2944. SickType: sick_type,
  2945. PType: p_type,
  2946. PatientDiagnosis: patient_diagnose,
  2947. }
  2948. service.SavePatientPrescriptionInfo(hpInfo)
  2949. //创建步骤表
  2950. finish := models.XtDialysisFinish{
  2951. IsFinish: 1,
  2952. UserOrgId: adminInfo.CurrentOrgId,
  2953. Status: 1,
  2954. Ctime: time.Now().Unix(),
  2955. Mtime: 0,
  2956. Module: 4,
  2957. RecordDate: theTime.Unix(),
  2958. Sourse: 1,
  2959. PatientId: patient_id,
  2960. }
  2961. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2962. if dialysisFinish.ID == 0 {
  2963. service.CreateDialysisFinish(finish)
  2964. }
  2965. redis := service.RedisClient()
  2966. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2967. redis.Set(key, "", time.Second)
  2968. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2969. redis.Set(keyOne, "", time.Second)
  2970. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2971. redis.Set(keySeven, "", time.Second)
  2972. defer redis.Close()
  2973. } else {
  2974. hpInfo = models.HisPrescriptionInfo{
  2975. ID: info.ID,
  2976. UserOrgId: adminInfo.CurrentOrgId,
  2977. RecordDate: info.RecordDate,
  2978. PatientId: info.PatientId,
  2979. Status: 1,
  2980. Ctime: info.Ctime,
  2981. Mtime: time.Now().Unix(),
  2982. Creator: info.Creator,
  2983. Modifier: adminInfo.AdminUser.Id,
  2984. Diagnosis: diagnose,
  2985. SickHistory: sick_history,
  2986. Departments: department,
  2987. RegisterType: reg_type,
  2988. PrescriptionNumber: info.PrescriptionNumber,
  2989. Doctor: role.UserName,
  2990. PrescriptionStatus: info.PrescriptionStatus,
  2991. DoctorId: doctor_id,
  2992. SickType: sick_type,
  2993. PType: info.PType,
  2994. HisPatientId: info.HisPatientId,
  2995. PatientDiagnosis: patient_diagnose,
  2996. }
  2997. service.SavePatientPrescriptionInfo(hpInfo)
  2998. //创建步骤表
  2999. finish := models.XtDialysisFinish{
  3000. IsFinish: 1,
  3001. UserOrgId: adminInfo.CurrentOrgId,
  3002. Status: 1,
  3003. Ctime: time.Now().Unix(),
  3004. Mtime: 0,
  3005. Module: 4,
  3006. RecordDate: info.RecordDate,
  3007. Sourse: 1,
  3008. PatientId: info.PatientId,
  3009. }
  3010. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  3011. if dialysisFinish.ID == 0 {
  3012. service.CreateDialysisFinish(finish)
  3013. }
  3014. redis := service.RedisClient()
  3015. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3016. redis.Set(key, "", time.Second)
  3017. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3018. redis.Set(keyOne, "", time.Second)
  3019. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3020. redis.Set(keySeven, "", time.Second)
  3021. defer redis.Close()
  3022. }
  3023. //定义切片
  3024. var adviceList []models.HisDoctorAdviceInfo
  3025. var projectList []models.HisPrescriptionProject
  3026. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10644 || adminInfo.CurrentOrgId == 10635 || adminInfo.CurrentOrgId == 10598 || adminInfo.CurrentOrgId == 10028 || adminInfo.CurrentOrgId == 10721 || adminInfo.CurrentOrgId == 10726 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10571 || adminInfo.CurrentOrgId == 10724 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10731 || adminInfo.CurrentOrgId == 10653 || adminInfo.CurrentOrgId == 10567 {
  3027. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3028. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3029. var tempPrescription *models.HisPrescription
  3030. if len(prescriptions) > 0 {
  3031. for _, item := range prescriptions {
  3032. // 开始外部循环的事务
  3033. tx := db.Begin()
  3034. // 在函数结束时处理事务回滚
  3035. defer func() {
  3036. if r := recover(); r != nil {
  3037. tx.Rollback()
  3038. }
  3039. }()
  3040. items := item.(map[string]interface{})
  3041. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3042. utils.ErrorLog("id")
  3043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3044. return
  3045. }
  3046. id := int64(items["id"].(float64))
  3047. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3048. tempPrescription = &new_prescription
  3049. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3050. utils.ErrorLog("type")
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3052. return
  3053. }
  3054. types := int64(items["type"].(float64))
  3055. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3056. utils.ErrorLog("med_type")
  3057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3058. return
  3059. }
  3060. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3061. if med_type == "0" {
  3062. med_type = "14"
  3063. }
  3064. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  3065. // utils.ErrorLog("diagnoses")
  3066. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. // return
  3068. //}
  3069. //med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3070. diagnoses, _ := items["diagnoses"].(string)
  3071. //if order_status == 0 {
  3072. // order_status = 1
  3073. //}
  3074. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3075. utils.ErrorLog("pre_time")
  3076. }
  3077. preTime, _ := items["pre_time"].(string)
  3078. fmt.Println("preTime", preTime)
  3079. timeLayout := "2006-01-02"
  3080. loc, _ := time.LoadLocation("Local")
  3081. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3082. //result := strings.Split(preTime, " ")
  3083. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  3084. if err != nil {
  3085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3086. return
  3087. }
  3088. pTime := theTime2.Unix()
  3089. ctime := time.Now().Unix()
  3090. if tempPrescription.ID == 0 {
  3091. prescription := &models.HisPrescription{
  3092. ID: 0,
  3093. PatientId: patient_id,
  3094. UserOrgId: adminInfo.CurrentOrgId,
  3095. RecordDate: recordDateTime,
  3096. Ctime: ctime,
  3097. Mtime: ctime,
  3098. Type: types,
  3099. Modifier: adminInfo.AdminUser.Id,
  3100. Creator: adminInfo.AdminUser.Id,
  3101. Status: 1,
  3102. Doctor: role.UserName,
  3103. HisPatientId: his_patient_id,
  3104. OrderStatus: 1,
  3105. BatchNumber: "",
  3106. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3107. PreTime: pTime,
  3108. PType: p_type,
  3109. MedType: med_type,
  3110. Diagnose: diagnoses,
  3111. }
  3112. tempPrescription = prescription
  3113. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3114. redis := service.RedisClient()
  3115. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3116. redis.Set(key, "", time.Second)
  3117. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3118. redis.Set(keyOne, "", time.Second)
  3119. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3120. redis.Set(keySeven, "", time.Second)
  3121. defer redis.Close()
  3122. } else {
  3123. tempPrescription.ID = id
  3124. tempPrescription.Type = types
  3125. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3126. tempPrescription.Mtime = time.Now().Unix()
  3127. tempPrescription.Doctor = role.UserName
  3128. //tempPrescription.OrderStatus = order_status
  3129. tempPrescription.PreTime = pTime
  3130. tempPrescription.MedType = med_type
  3131. tempPrescription.Diagnose = diagnoses
  3132. service.SaveHisPrescriptionOne(tx, tempPrescription)
  3133. redis := service.RedisClient()
  3134. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3135. redis.Set(key, "", time.Second)
  3136. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3137. redis.Set(keyOne, "", time.Second)
  3138. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3139. redis.Set(keySeven, "", time.Second)
  3140. defer redis.Close()
  3141. }
  3142. //service.SaveHisPrescription(prescription)
  3143. //更改患者挂号状态
  3144. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3145. fmt.Println("更改失败", err2)
  3146. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3147. advices := items["advices"].([]interface{})
  3148. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3149. groupNo := int64(0)
  3150. if len(advices) > 0 {
  3151. for _, advice := range advices {
  3152. tx := db.Begin()
  3153. // 在函数结束时处理事务回滚
  3154. defer func() {
  3155. if r := recover(); r != nil {
  3156. tx.Rollback()
  3157. }
  3158. }()
  3159. var s models.HisDoctorAdviceInfo
  3160. s.PrescriptionId = tempPrescription.ID
  3161. s.AdviceType = 2
  3162. s.AdviceDoctor = doctor_id
  3163. s.StopState = 2
  3164. s.ExecutionState = 2
  3165. s.AdviceDate = theTime3.Unix()
  3166. s.Status = 1
  3167. s.UserOrgId = adminInfo.CurrentOrgId
  3168. s.RecordDate = theTime3.Unix()
  3169. s.StartTime = tempPrescription.PreTime
  3170. s.Groupno = groupNo
  3171. s.PatientId = patient_id
  3172. s.HisPatientId = his_patient_id
  3173. s.StartTime = pTime
  3174. s.IsSettle = 2
  3175. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3176. if errcode > 0 {
  3177. c.ServeFailJSONWithSGJErrorCode(errcode)
  3178. return
  3179. }
  3180. s.StartTime = pTime
  3181. var total_count int64 //处方总库存
  3182. //查询改药品信息
  3183. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3184. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3185. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3186. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3187. total_count += prescribingNumberSeven * medical.MinNumber
  3188. }
  3189. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3190. total_count += prescribingNumberSeven
  3191. }
  3192. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3193. total_count += prescribingNumberSeven
  3194. }
  3195. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3196. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3197. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3198. if s.Price != lastWarehouse.RetailPrice {
  3199. s.Price = lastWarehouse.RetailPrice
  3200. }
  3201. if s.Price == 0 {
  3202. if lastWarehouse.ID == 0 {
  3203. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3204. s.Price = lastWarehouseTwo.RetailPrice
  3205. }
  3206. }
  3207. }
  3208. //查询保存处方出库开关是否打开
  3209. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3210. if s.PatientId != 30038 {
  3211. if drugOutConfig.IsOpen == 1 {
  3212. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  3213. // 查询该药品最后一次出库记录
  3214. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  3215. var is_user_total int64
  3216. var no_user_total int64
  3217. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3218. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3219. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3220. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  3221. }
  3222. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3223. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3224. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3225. no_user_total += prescribingNumberSevenTy
  3226. }
  3227. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3228. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3229. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3230. no_user_total += prescribingNumberSevenTy
  3231. }
  3232. if len(druginfo) > 0 {
  3233. for _, it := range druginfo {
  3234. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3235. it.Count = it.Count * drug.MinNumber
  3236. is_user_total += it.Count
  3237. }
  3238. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3239. is_user_total += it.Count
  3240. }
  3241. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3242. is_user_total += it.Count
  3243. }
  3244. }
  3245. }
  3246. //fmt.Println("药品名称----------------------", drug.DrugName)
  3247. //fmt.Println("药品名称----------------------", drug.IsUse)
  3248. //fmt.Println("is_user_total-------------------------", is_user_total)
  3249. //fmt.Println("no_user_total-------------------------", no_user_total)
  3250. //fmt.Println("drug.IsUse---------------", drug.IsUse)
  3251. //fmt.Println("00000000000000000000", s.UserOrgId)
  3252. if is_user_total != no_user_total {
  3253. //出库
  3254. //针对御享天源
  3255. if drug.IsUse == 1 && s.UserOrgId == 10635 {
  3256. creater := adminInfo.AdminUser.Id
  3257. newadviceInfo := &models.HisDoctorAdviceInfo{
  3258. ID: s.ID,
  3259. UserOrgId: s.UserOrgId,
  3260. PatientId: s.PatientId,
  3261. HisPatientId: s.HisPatientId,
  3262. AdviceType: s.AdviceType,
  3263. AdviceDate: s.AdviceDate,
  3264. StartTime: s.StartTime,
  3265. AdviceName: s.AdviceName,
  3266. AdviceDesc: s.AdviceDesc,
  3267. ReminderDate: s.ReminderDate,
  3268. SingleDose: s.SingleDose,
  3269. SingleDoseUnit: s.SingleDoseUnit,
  3270. PrescribingNumber: s.PrescribingNumber,
  3271. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3272. DeliveryWay: s.DeliveryWay,
  3273. ExecutionFrequency: s.ExecutionFrequency,
  3274. AdviceDoctor: s.AdviceDoctor,
  3275. Status: s.Status,
  3276. CreatedTime: s.CreatedTime,
  3277. UpdatedTime: s.UpdatedTime,
  3278. AdviceAffirm: s.AdviceAffirm,
  3279. Remark: s.Remark,
  3280. StopTime: s.StopTime,
  3281. StopReason: s.StopReason,
  3282. StopDoctor: s.StopDoctor,
  3283. StopState: s.StopState,
  3284. ParentId: s.ParentId,
  3285. ExecutionTime: s.ExecutionTime,
  3286. ExecutionStaff: s.ExecutionStaff,
  3287. ExecutionState: s.ExecutionState,
  3288. Checker: s.Checker,
  3289. RecordDate: s.RecordDate,
  3290. DialysisOrderId: s.DialysisOrderId,
  3291. CheckTime: s.CheckTime,
  3292. CheckState: s.CheckState,
  3293. DrugSpec: s.DrugSpec,
  3294. DrugSpecUnit: s.DrugSpecUnit,
  3295. Groupno: s.Groupno,
  3296. RemindType: s.RemindType,
  3297. FrequencyType: s.FrequencyType,
  3298. DayCount: s.DayCount,
  3299. WeekDay: s.WeekDay,
  3300. TemplateId: s.TemplateId,
  3301. Modifier: s.Modifier,
  3302. DrugId: s.DrugId,
  3303. Price: s.Price,
  3304. PrescriptionId: s.PrescriptionId,
  3305. MedListCodg: s.MedListCodg,
  3306. FeedetlSn: s.FeedetlSn,
  3307. Day: s.DayCount,
  3308. ChildDoctorAdvice: nil,
  3309. Drug: models.Drug{},
  3310. Diagnosis: s.Diagnosis,
  3311. Way: s.Way,
  3312. HospApprFlag: s.HospApprFlag,
  3313. LmtUsedFlag: s.LmtUsedFlag,
  3314. HisOrderInfo: models.HisOrderInfo{},
  3315. IsMedicine: s.IsMedicine,
  3316. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3317. Child: nil,
  3318. IsSettle: s.IsSettle,
  3319. IsMobile: s.IsMobile,
  3320. IsSelfDrug: s.IsSelfDrug,
  3321. DrugWayCount: s.DrugWayCount,
  3322. }
  3323. var history_count int64
  3324. var local_count int64
  3325. //查找已经开过的医嘱信息
  3326. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3327. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3328. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3329. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3330. local_count += prescribingNumberSevenTy * drug.MinNumber
  3331. }
  3332. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3333. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3334. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3335. local_count += prescribingNumberSevenTy
  3336. }
  3337. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3338. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3339. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3340. local_count += prescribingNumberSevenTy
  3341. }
  3342. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3343. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3344. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3345. history_count += prescribingNumberSevenTy * drug.MinNumber
  3346. }
  3347. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3348. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3349. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3350. history_count += prescribingNumberSevenTy
  3351. }
  3352. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3353. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3354. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3355. history_count += prescribingNumberSevenTy
  3356. }
  3357. fmt.Println("local_count---------------", local_count)
  3358. fmt.Println("history_count---------------", history_count)
  3359. //如果当前出库数量大于历史出库数量则需要出库
  3360. if local_count > history_count {
  3361. //按最小单位出库
  3362. var cha_count = local_count - history_count
  3363. newadviceInfo.PrescribingNumber = float64(cha_count)
  3364. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3365. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3366. }
  3367. //如果当前出库数量小于历史出库数量则需要退库
  3368. if local_count < history_count {
  3369. var cha_count = history_count - local_count
  3370. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3371. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3372. }
  3373. if local_count == history_count {
  3374. if is_user_total == 0 {
  3375. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3376. }
  3377. }
  3378. }
  3379. if drug.IsUse == 2 {
  3380. creater := adminInfo.AdminUser.Id
  3381. newadviceInfo := &models.HisDoctorAdviceInfo{
  3382. ID: s.ID,
  3383. UserOrgId: s.UserOrgId,
  3384. PatientId: s.PatientId,
  3385. HisPatientId: s.HisPatientId,
  3386. AdviceType: s.AdviceType,
  3387. AdviceDate: s.AdviceDate,
  3388. StartTime: s.StartTime,
  3389. AdviceName: s.AdviceName,
  3390. AdviceDesc: s.AdviceDesc,
  3391. ReminderDate: s.ReminderDate,
  3392. SingleDose: s.SingleDose,
  3393. SingleDoseUnit: s.SingleDoseUnit,
  3394. PrescribingNumber: s.PrescribingNumber,
  3395. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3396. DeliveryWay: s.DeliveryWay,
  3397. ExecutionFrequency: s.ExecutionFrequency,
  3398. AdviceDoctor: s.AdviceDoctor,
  3399. Status: s.Status,
  3400. CreatedTime: s.CreatedTime,
  3401. UpdatedTime: s.UpdatedTime,
  3402. AdviceAffirm: s.AdviceAffirm,
  3403. Remark: s.Remark,
  3404. StopTime: s.StopTime,
  3405. StopReason: s.StopReason,
  3406. StopDoctor: s.StopDoctor,
  3407. StopState: s.StopState,
  3408. ParentId: s.ParentId,
  3409. ExecutionTime: s.ExecutionTime,
  3410. ExecutionStaff: s.ExecutionStaff,
  3411. ExecutionState: s.ExecutionState,
  3412. Checker: s.Checker,
  3413. RecordDate: s.RecordDate,
  3414. DialysisOrderId: s.DialysisOrderId,
  3415. CheckTime: s.CheckTime,
  3416. CheckState: s.CheckState,
  3417. DrugSpec: s.DrugSpec,
  3418. DrugSpecUnit: s.DrugSpecUnit,
  3419. Groupno: s.Groupno,
  3420. RemindType: s.RemindType,
  3421. FrequencyType: s.FrequencyType,
  3422. DayCount: s.DayCount,
  3423. WeekDay: s.WeekDay,
  3424. TemplateId: s.TemplateId,
  3425. Modifier: s.Modifier,
  3426. DrugId: s.DrugId,
  3427. Price: s.Price,
  3428. PrescriptionId: s.PrescriptionId,
  3429. MedListCodg: s.MedListCodg,
  3430. FeedetlSn: s.FeedetlSn,
  3431. Day: s.DayCount,
  3432. ChildDoctorAdvice: nil,
  3433. Drug: models.Drug{},
  3434. Diagnosis: s.Diagnosis,
  3435. Way: s.Way,
  3436. HospApprFlag: s.HospApprFlag,
  3437. LmtUsedFlag: s.LmtUsedFlag,
  3438. HisOrderInfo: models.HisOrderInfo{},
  3439. IsMedicine: s.IsMedicine,
  3440. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3441. Child: nil,
  3442. IsSettle: s.IsSettle,
  3443. IsMobile: s.IsMobile,
  3444. IsSelfDrug: s.IsSelfDrug,
  3445. DrugWayCount: s.DrugWayCount,
  3446. }
  3447. var history_count int64
  3448. var local_count int64
  3449. //查找已经开过的医嘱信息
  3450. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3451. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3452. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3453. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3454. local_count += prescribingNumberSevenTy * drug.MinNumber
  3455. }
  3456. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3457. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3458. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3459. local_count += prescribingNumberSevenTy
  3460. }
  3461. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3462. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3463. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3464. local_count += prescribingNumberSevenTy
  3465. }
  3466. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3467. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3468. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3469. history_count += prescribingNumberSevenTy * drug.MinNumber
  3470. }
  3471. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3472. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3473. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3474. history_count += prescribingNumberSevenTy
  3475. }
  3476. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3477. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3478. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3479. history_count += prescribingNumberSevenTy
  3480. }
  3481. fmt.Println("local_count---------------", local_count)
  3482. fmt.Println("history_count---------------", history_count)
  3483. //如果当前出库数量大于历史出库数量则需要出库
  3484. if local_count > history_count {
  3485. //按最小单位出库
  3486. var cha_count = local_count - history_count
  3487. newadviceInfo.PrescribingNumber = float64(cha_count)
  3488. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3489. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3490. }
  3491. //如果当前出库数量小于历史出库数量则需要退库
  3492. if local_count < history_count {
  3493. var cha_count = history_count - local_count
  3494. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3495. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3496. }
  3497. if local_count == history_count {
  3498. if is_user_total == 0 {
  3499. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3500. }
  3501. }
  3502. }
  3503. //更新字典里面的库存
  3504. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3505. var sum_count int64
  3506. for _, its := range stockInfo {
  3507. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3508. if its.MaxUnit == baseDrug.MaxUnit {
  3509. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3510. }
  3511. sum_count += its.StockMaxNumber + its.StockMinNumber
  3512. }
  3513. //更新基础库存
  3514. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3515. //剩余库存
  3516. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3517. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3518. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3519. //创建医嘱
  3520. service.CreateHisDoctorAdviceOne(&s, tx)
  3521. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3522. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3523. if len(outInfoTwo) > 0 {
  3524. for _, item := range outInfoTwo {
  3525. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3526. }
  3527. }
  3528. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3529. if len(drugAutoDetail) > 0 {
  3530. for _, item := range drugAutoDetail {
  3531. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3532. }
  3533. }
  3534. }
  3535. }
  3536. }
  3537. //记录日志
  3538. byterequest, _ := json.Marshal(s)
  3539. adviceLog := models.XtDoctorAdviceLog{
  3540. UserOrgId: s.UserOrgId,
  3541. PatientId: s.PatientId,
  3542. AdminUserId: adminInfo.AdminUser.Id,
  3543. Module: 1,
  3544. ErrLog: string(byterequest),
  3545. Status: 1,
  3546. Ctime: time.Now().Unix(),
  3547. Mtime: 0,
  3548. Source: "电脑端新建his医嘱",
  3549. RecordDate: s.AdviceDate,
  3550. }
  3551. service.CreateDoctorAdviceLog(adviceLog)
  3552. //存储切片中
  3553. adviceList = append(adviceList, s)
  3554. redis := service.RedisClient()
  3555. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3556. redis.Set(key, "", time.Second)
  3557. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3558. redis.Set(keyOne, "", time.Second)
  3559. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3560. redis.Set(keySeven, "", time.Second)
  3561. var randNum int
  3562. randNum = rand.Intn(10000) + 1000
  3563. timestamp := time.Now().Unix()
  3564. tempTime := time.Unix(timestamp, 0)
  3565. timeFormat := tempTime.Format("20060102150405")
  3566. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3567. if s.UserOrgId != 10206 {
  3568. if s.ID == 0 {
  3569. //查询改药品是否已经停用
  3570. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3571. if base.ID > 0 {
  3572. tx.Rollback()
  3573. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3574. return
  3575. }
  3576. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3577. if drugMedical.SumCount == 0 {
  3578. tx.Rollback()
  3579. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3580. return
  3581. }
  3582. }
  3583. if s.ID > 0 {
  3584. //查询改药品是否已经停用
  3585. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3586. if base.ID > 0 {
  3587. tx.Rollback()
  3588. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3589. return
  3590. }
  3591. }
  3592. }
  3593. //赤峰
  3594. if adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3595. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3596. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3597. if info.RetailPrice > 0 {
  3598. if s.DeliveryWay == "口服" {
  3599. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3600. s.Price = drug.RetailPrice
  3601. }
  3602. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3603. s.Price = info.RetailPrice
  3604. }
  3605. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3606. s.Price = info.RetailPrice
  3607. }
  3608. }
  3609. }
  3610. }
  3611. service.CreateHisDoctorAdviceOne(&s, tx)
  3612. tx.Commit()
  3613. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3614. redis.Set(keySix, "", time.Second)
  3615. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3616. redis.Set(keyFive, "", time.Second)
  3617. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3618. redis.Set(keyEight, "", time.Second)
  3619. defer redis.Close()
  3620. }
  3621. }
  3622. }
  3623. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3624. projects := items["project"].([]interface{})
  3625. if len(projects) > 0 {
  3626. for _, project := range projects {
  3627. tx := db.Begin()
  3628. // 在函数结束时处理事务回滚
  3629. defer func() {
  3630. if r := recover(); r != nil {
  3631. tx.Rollback()
  3632. }
  3633. }()
  3634. var p models.HisPrescriptionProject
  3635. p.PrescriptionId = tempPrescription.ID
  3636. p.PatientId = patient_id
  3637. p.RecordDate = theTime3.Unix()
  3638. p.Doctor = doctor_id
  3639. p.UserOrgId = adminInfo.CurrentOrgId
  3640. p.HisPatientId = his_patient_id
  3641. p.Status = 1
  3642. p.StartTime = pTime
  3643. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3644. if errcode > 0 {
  3645. tx.Rollback()
  3646. c.ServeFailJSONWithSGJErrorCode(errcode)
  3647. return
  3648. }
  3649. if p.ID == 0 {
  3650. p.IsOut = 2
  3651. }
  3652. if p.ID > 0 {
  3653. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3654. p.IsOut = projectDetail.IsOut
  3655. }
  3656. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 10489 {
  3657. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3658. if p.Type == 3 {
  3659. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3660. if p.Price != lastWarehouse.PackingPrice {
  3661. p.Price = lastWarehouse.PackingPrice
  3662. }
  3663. if p.Price == 0 {
  3664. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3665. p.Price = lastWarehouseTwo.PackingPrice
  3666. }
  3667. if p.Unit == "" {
  3668. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3669. p.Unit = goodInfoOne.PackingUnit
  3670. }
  3671. }
  3672. }
  3673. if adminInfo.CurrentOrgId != 10206 {
  3674. if p.Type == 3 {
  3675. if p.ID == 0 {
  3676. //查询该耗材是否停用
  3677. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3678. //表示该耗材已经停用,不能保存
  3679. if goodInfoSeven.ID == 0 {
  3680. tx.Rollback()
  3681. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3682. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3683. return
  3684. }
  3685. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3686. if goodInfoOne.SumCount == 0 {
  3687. tx.Rollback()
  3688. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3689. return
  3690. }
  3691. }
  3692. if p.ID > 0 {
  3693. //查询该耗材是否停用
  3694. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3695. //表示该耗材已经停用,不能保存
  3696. if goodInfoSeven.ID == 0 {
  3697. tx.Rollback()
  3698. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3699. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3700. return
  3701. }
  3702. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3703. if goodInfoOne.SumCount == 0 {
  3704. tx.Rollback()
  3705. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3706. return
  3707. }
  3708. }
  3709. }
  3710. }
  3711. //查询保存耗材出库开关是否打开
  3712. if p.PatientId != 30038 {
  3713. //用机构ID区分
  3714. if adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10164 {
  3715. if goodOutConfig.IsOpen == 1 {
  3716. //耗材出库
  3717. if p.Type == 3 {
  3718. //对比当前数据和历史出库数据
  3719. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3720. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3721. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3722. //如果当前处方数量大于历史数据,则需要出库
  3723. if nowCount > historyCount {
  3724. var cha_count int64
  3725. cha_count = nowCount - historyCount
  3726. timeStr := time.Now().Format("2006-01-02")
  3727. timeArr := strings.Split(timeStr, "-")
  3728. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3729. total = total + 1
  3730. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3731. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3732. number = number + total
  3733. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3734. operation_time := time.Now().Unix()
  3735. creater := c.GetAdminUserInfo().AdminUser.Id
  3736. recordDateStr := time.Now().Format("2006-01-02")
  3737. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3738. nowtime := recordDate.Unix()
  3739. warehouseOut := models.WarehouseOut{
  3740. WarehouseOutOrderNumber: warehousing_out_order,
  3741. OperationTime: operation_time,
  3742. OrgId: adminInfo.CurrentOrgId,
  3743. Creater: creater,
  3744. Ctime: time.Now().Unix(),
  3745. Status: 1,
  3746. WarehouseOutTime: nowtime,
  3747. Type: 1,
  3748. StorehouseId: storeConfig.StorehouseOutInfo,
  3749. IsCheck: 1,
  3750. IsSys: 1,
  3751. }
  3752. //查询是否生成出库单
  3753. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3754. if out.ID == 0 {
  3755. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3756. }
  3757. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3758. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3759. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3760. dialyPrepareOne := models.DialysisBeforePrepare{
  3761. GoodTypeId: goodObj.GoodTypeId,
  3762. GoodId: p.ProjectId,
  3763. PatientId: p.PatientId,
  3764. RecordDate: p.RecordDate,
  3765. UserOrgId: adminInfo.CurrentOrgId,
  3766. Count: cha_count,
  3767. Ctime: time.Now().Unix(),
  3768. Creater: creater,
  3769. Status: 1,
  3770. StorehouseId: houseConfig.StorehouseOutInfo,
  3771. ProjectId: p.ID,
  3772. }
  3773. //出库
  3774. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3775. }
  3776. //如果当前处方数量小于历史数据,怎需要退库
  3777. if nowCount < historyCount {
  3778. var cha_count int64
  3779. cha_count = historyCount - nowCount
  3780. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3781. creater := c.GetAdminUserInfo().AdminUser.Id
  3782. newPrescriptionProject := &models.HisPrescriptionProject{
  3783. ID: p.ID,
  3784. ProjectId: p.ProjectId,
  3785. Price: p.Price,
  3786. UserOrgId: p.UserOrgId,
  3787. Status: 1,
  3788. Ctime: time.Now().Unix(),
  3789. Mtime: time.Now().Unix(),
  3790. PatientId: p.PatientId,
  3791. HisPatientId: p.HisPatientId,
  3792. RecordDate: p.RecordDate,
  3793. PrescriptionId: p.PrescriptionId,
  3794. Count: p.Count,
  3795. FeedetlSn: p.FeedetlSn,
  3796. MedListCodg: p.MedListCodg,
  3797. SingleDose: p.SingleDose,
  3798. DeliveryWay: p.DeliveryWay,
  3799. ExecutionFrequency: p.ExecutionFrequency,
  3800. Day: p.Day,
  3801. HisProject: models.HisProject{},
  3802. GoodInfo: models.GoodInfo{},
  3803. Remark: p.Remark,
  3804. Unit: p.Unit,
  3805. Type: p.Type,
  3806. Doctor: p.Doctor,
  3807. ExecutionTime: p.ExecutionTime,
  3808. ExecutionStaff: p.ExecutionStaff,
  3809. ExecutionState: p.ExecutionState,
  3810. CheckTime: p.CheckTime,
  3811. CheckState: p.CheckState,
  3812. Checker: p.Checker,
  3813. StartTime: p.StartTime,
  3814. TeamId: p.TeamId,
  3815. XtHisProjectTeam: models.XtHisProjectTeam{},
  3816. FrequencyType: p.FrequencyType,
  3817. DayCount: p.DayCount,
  3818. WeekDay: p.WeekDay,
  3819. IsCheckTeam: p.IsCheckTeam,
  3820. HisOrderInfo: models.HisOrderInfo{},
  3821. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3822. IsOut: p.IsOut,
  3823. YbSyncStatus: p.YbSyncStatus,
  3824. }
  3825. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3826. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3827. }
  3828. if nowCount == historyCount {
  3829. if historyCount == 0 {
  3830. recordDateStr := time.Now().Format("2006-01-02")
  3831. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3832. nowtime := recordDate.Unix()
  3833. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3834. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3835. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3836. creater := c.GetAdminUserInfo().AdminUser.Id
  3837. dialyPrepareOne := models.DialysisBeforePrepare{
  3838. GoodTypeId: goodObj.GoodTypeId,
  3839. GoodId: p.ProjectId,
  3840. PatientId: p.PatientId,
  3841. RecordDate: p.RecordDate,
  3842. UserOrgId: adminInfo.CurrentOrgId,
  3843. Count: nowCount,
  3844. Ctime: time.Now().Unix(),
  3845. Creater: creater,
  3846. Status: 1,
  3847. StorehouseId: houseConfig.StorehouseOutInfo,
  3848. ProjectId: p.ID,
  3849. }
  3850. //出库
  3851. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3852. }
  3853. }
  3854. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3855. //查询历史出库数据
  3856. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3857. var out_count_five int64
  3858. for _, item := range flowGood {
  3859. out_count_five += item.Count
  3860. }
  3861. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3862. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3863. if out_count_five != parseIntCount {
  3864. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3865. detail := models.AutomaticReduceDetail{
  3866. WarehouseOutId: 0,
  3867. WarehouseOutOrderNumber: "",
  3868. PatientId: p.PatientId,
  3869. Ctime: time.Now().Unix(),
  3870. Mtime: 0,
  3871. Status: 1,
  3872. RecordTime: p.RecordDate,
  3873. OrgId: p.UserOrgId,
  3874. GoodId: p.ProjectId,
  3875. GoodTypeId: 0,
  3876. Count: parseIntCount,
  3877. Type: 0,
  3878. ProjectId: lastHisProject.ID,
  3879. StorehouseId: 0,
  3880. }
  3881. service.CreateNewAutoDetail(detail, tx)
  3882. }
  3883. // //查询耗材最后一次出库记录
  3884. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3885. // //查询默认出库仓库库存
  3886. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3887. // if len(wareOut) > 0 {
  3888. //
  3889. // for _, it := range wareOut {
  3890. // //回退库存
  3891. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3892. //
  3893. // //删除出库记录
  3894. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3895. //
  3896. // }
  3897. // }
  3898. //
  3899. // timeStr := time.Now().Format("2006-01-02")
  3900. // timeArr := strings.Split(timeStr, "-")
  3901. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3902. //
  3903. // total = total + 1
  3904. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3905. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3906. // number = number + total
  3907. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3908. //
  3909. // operation_time := time.Now().Unix()
  3910. // creater := c.GetAdminUserInfo().AdminUser.Id
  3911. //
  3912. // recordDateStr := time.Now().Format("2006-01-02")
  3913. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3914. // nowtime := recordDate.Unix()
  3915. // warehouseOut := models.WarehouseOut{
  3916. // WarehouseOutOrderNumber: warehousing_out_order,
  3917. // OperationTime: operation_time,
  3918. // OrgId: adminInfo.CurrentOrgId,
  3919. // Creater: creater,
  3920. // Ctime: time.Now().Unix(),
  3921. // Status: 1,
  3922. // WarehouseOutTime: nowtime,
  3923. // Type: 1,
  3924. // StorehouseId: storeConfig.StorehouseOutInfo,
  3925. // IsCheck: 1,
  3926. // IsSys: 1,
  3927. // }
  3928. // //查询是否生成出库单
  3929. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3930. // if out.ID == 0 {
  3931. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3932. // }
  3933. //
  3934. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3935. //
  3936. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3937. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3938. //
  3939. // dialyPrepareOne := models.DialysisBeforePrepare{
  3940. // GoodTypeId: goodObj.GoodTypeId,
  3941. // GoodId: p.ProjectId,
  3942. // PatientId: p.PatientId,
  3943. // RecordDate: p.RecordDate,
  3944. // UserOrgId: adminInfo.CurrentOrgId,
  3945. // Count: parseIntCount,
  3946. // Ctime: time.Now().Unix(),
  3947. // Creater: creater,
  3948. // Status: 1,
  3949. // StorehouseId: houseConfig.StorehouseOutInfo,
  3950. // ProjectId: lastHisProject.ID,
  3951. // }
  3952. // //判断是否是零用耗材(非零用)
  3953. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3954. //
  3955. // //查询历史出库数据
  3956. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3957. // var out_count int64
  3958. // for _, item := range flowGood {
  3959. // out_count += item.Count
  3960. // }
  3961. // //如果历史数和当前数据不想等才进行退库出库
  3962. // if out_count != parseIntCount {
  3963. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3964. //
  3965. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3966. // detail := models.AutomaticReduceDetail{
  3967. // WarehouseOutId: 0,
  3968. // WarehouseOutOrderNumber: "",
  3969. // PatientId: p.PatientId,
  3970. // Ctime: time.Now().Unix(),
  3971. // Mtime: 0,
  3972. // Status: 1,
  3973. // RecordTime: p.RecordDate,
  3974. // OrgId: p.UserOrgId,
  3975. // GoodId: p.ProjectId,
  3976. // GoodTypeId: 0,
  3977. // Count: parseIntCount,
  3978. // Type: 0,
  3979. // ProjectId: lastHisProject.ID,
  3980. // StorehouseId: 0,
  3981. // }
  3982. //
  3983. // service.CreateNewAutoDetail(detail, tx)
  3984. //
  3985. // //查询剩余库存
  3986. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3987. // var sum_count int64
  3988. // for _, item := range goodList {
  3989. // sum_count += item.StockCount
  3990. // }
  3991. //
  3992. // //更新剩余库存
  3993. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3994. //
  3995. // //耗材
  3996. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3997. //
  3998. // }
  3999. // //判断是否是零用耗材(零用但是是出库耗材)
  4000. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4001. //
  4002. // //查询历史出库数据
  4003. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4004. // var out_count int64
  4005. // for _, item := range flowGood {
  4006. // out_count += item.Count
  4007. // }
  4008. // //如果历史数和当前数据不想等才进行退库出库
  4009. // if out_count != parseIntCount {
  4010. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4011. //
  4012. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4013. // detail := models.AutomaticReduceDetail{
  4014. // WarehouseOutId: 0,
  4015. // WarehouseOutOrderNumber: "",
  4016. // PatientId: p.PatientId,
  4017. // Ctime: time.Now().Unix(),
  4018. // Mtime: 0,
  4019. // Status: 1,
  4020. // RecordTime: p.RecordDate,
  4021. // OrgId: p.UserOrgId,
  4022. // GoodId: p.ProjectId,
  4023. // GoodTypeId: 0,
  4024. // Count: parseIntCount,
  4025. // Type: 0,
  4026. // ProjectId: p.ID,
  4027. // StorehouseId: 0,
  4028. // }
  4029. //
  4030. // service.CreateNewAutoDetail(detail, tx)
  4031. //
  4032. // //查询剩余库存
  4033. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4034. // var sum_count int64
  4035. // for _, item := range goodList {
  4036. // sum_count += item.StockCount
  4037. // }
  4038. //
  4039. // //更新剩余库存
  4040. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4041. //
  4042. // //耗材
  4043. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4044. // }
  4045. //
  4046. // }
  4047. //
  4048. // }
  4049. //
  4050. //}
  4051. //记录日志
  4052. byterequest, _ := json.Marshal(p)
  4053. adviceLog := models.XtDoctorAdviceLog{
  4054. UserOrgId: p.UserOrgId,
  4055. PatientId: p.PatientId,
  4056. AdminUserId: adminInfo.AdminUser.Id,
  4057. Module: 1,
  4058. ErrLog: string(byterequest),
  4059. Status: 1,
  4060. Ctime: time.Now().Unix(),
  4061. Mtime: 0,
  4062. Source: "电脑端新建his项目",
  4063. RecordDate: p.RecordDate,
  4064. }
  4065. service.CreateDoctorAdviceLog(adviceLog)
  4066. projectList = append(projectList, p)
  4067. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4068. //新增或者编辑项目,修改对应的标签数据
  4069. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4070. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4071. var label models.HisLabelPrintInfo
  4072. project, _ := service.GetProjectDetail(p.ProjectId)
  4073. if project.CostClassify == 3 { //类别为检验检查
  4074. if p.TeamId > 0 { //检验检查组套
  4075. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4076. if tempLabel.ID == 0 {
  4077. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4078. label.Number = tempPrescription.PrescriptionNumber
  4079. label.ProjectId = project.ID
  4080. label.Status = 1
  4081. label.IsPrint = 2
  4082. label.DoctorId = info.DoctorId
  4083. label.UserOrgId = p.UserOrgId
  4084. label.PatientId = patient_id
  4085. label.RecordDate = recordDateTime
  4086. label.Ctime = time.Now().Unix()
  4087. label.Mtime = time.Now().Unix()
  4088. label.ItemId = p.TeamId
  4089. label.FeedetlSn = p.FeedetlSn
  4090. label.PProjectId = p.ID
  4091. label.ProjectName = team.ProjectTeam
  4092. label.PatientName = patient.Name
  4093. service.CreateNewHisLabelRecord(&label, tx)
  4094. }
  4095. } else { //单条检验检查项目
  4096. label.Number = tempPrescription.PrescriptionNumber
  4097. label.ProjectId = project.ID
  4098. label.Status = 1
  4099. label.DoctorId = info.DoctorId
  4100. label.UserOrgId = p.UserOrgId
  4101. label.PatientId = patient_id
  4102. label.RecordDate = recordDateTime
  4103. label.IsPrint = 2
  4104. label.Ctime = time.Now().Unix()
  4105. label.Mtime = time.Now().Unix()
  4106. label.FeedetlSn = p.FeedetlSn
  4107. label.PProjectId = p.ID
  4108. label.ItemId = p.TeamId
  4109. label.ProjectName = project.ProjectName
  4110. label.PatientName = patient.Name
  4111. service.CreateNewHisLabelRecord(&label, tx)
  4112. }
  4113. }
  4114. }
  4115. }
  4116. }
  4117. }
  4118. }
  4119. if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10164 {
  4120. //耗材出库
  4121. if p.Type == 3 {
  4122. //对比当前数据和历史出库数据
  4123. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  4124. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  4125. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4126. //如果当前处方数量大于历史数据,则需要出库
  4127. if nowCount > historyCount {
  4128. var cha_count int64
  4129. cha_count = nowCount - historyCount
  4130. timeStr := time.Now().Format("2006-01-02")
  4131. timeArr := strings.Split(timeStr, "-")
  4132. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4133. total = total + 1
  4134. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4135. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4136. number = number + total
  4137. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4138. operation_time := time.Now().Unix()
  4139. creater := c.GetAdminUserInfo().AdminUser.Id
  4140. recordDateStr := time.Now().Format("2006-01-02")
  4141. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4142. nowtime := recordDate.Unix()
  4143. warehouseOut := models.WarehouseOut{
  4144. WarehouseOutOrderNumber: warehousing_out_order,
  4145. OperationTime: operation_time,
  4146. OrgId: adminInfo.CurrentOrgId,
  4147. Creater: creater,
  4148. Ctime: time.Now().Unix(),
  4149. Status: 1,
  4150. WarehouseOutTime: nowtime,
  4151. Type: 1,
  4152. StorehouseId: storeConfig.StorehouseOutInfo,
  4153. IsCheck: 1,
  4154. IsSys: 1,
  4155. }
  4156. //查询是否生成出库单
  4157. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4158. if out.ID == 0 {
  4159. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4160. }
  4161. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4162. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4163. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4164. dialyPrepareOne := models.DialysisBeforePrepare{
  4165. GoodTypeId: goodObj.GoodTypeId,
  4166. GoodId: p.ProjectId,
  4167. PatientId: p.PatientId,
  4168. RecordDate: p.RecordDate,
  4169. UserOrgId: adminInfo.CurrentOrgId,
  4170. Count: cha_count,
  4171. Ctime: time.Now().Unix(),
  4172. Creater: creater,
  4173. Status: 1,
  4174. StorehouseId: houseConfig.StorehouseOutInfo,
  4175. ProjectId: p.ID,
  4176. }
  4177. //出库
  4178. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4179. }
  4180. //如果当前处方数量小于历史数据,怎需要退库
  4181. if nowCount < historyCount {
  4182. var cha_count int64
  4183. cha_count = historyCount - nowCount
  4184. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4185. creater := c.GetAdminUserInfo().AdminUser.Id
  4186. newPrescriptionProject := &models.HisPrescriptionProject{
  4187. ID: p.ID,
  4188. ProjectId: p.ProjectId,
  4189. Price: p.Price,
  4190. UserOrgId: p.UserOrgId,
  4191. Status: 1,
  4192. Ctime: time.Now().Unix(),
  4193. Mtime: time.Now().Unix(),
  4194. PatientId: p.PatientId,
  4195. HisPatientId: p.HisPatientId,
  4196. RecordDate: p.RecordDate,
  4197. PrescriptionId: p.PrescriptionId,
  4198. Count: p.Count,
  4199. FeedetlSn: p.FeedetlSn,
  4200. MedListCodg: p.MedListCodg,
  4201. SingleDose: p.SingleDose,
  4202. DeliveryWay: p.DeliveryWay,
  4203. ExecutionFrequency: p.ExecutionFrequency,
  4204. Day: p.Day,
  4205. HisProject: models.HisProject{},
  4206. GoodInfo: models.GoodInfo{},
  4207. Remark: p.Remark,
  4208. Unit: p.Unit,
  4209. Type: p.Type,
  4210. Doctor: p.Doctor,
  4211. ExecutionTime: p.ExecutionTime,
  4212. ExecutionStaff: p.ExecutionStaff,
  4213. ExecutionState: p.ExecutionState,
  4214. CheckTime: p.CheckTime,
  4215. CheckState: p.CheckState,
  4216. Checker: p.Checker,
  4217. StartTime: p.StartTime,
  4218. TeamId: p.TeamId,
  4219. XtHisProjectTeam: models.XtHisProjectTeam{},
  4220. FrequencyType: p.FrequencyType,
  4221. DayCount: p.DayCount,
  4222. WeekDay: p.WeekDay,
  4223. IsCheckTeam: p.IsCheckTeam,
  4224. HisOrderInfo: models.HisOrderInfo{},
  4225. ExecutionFrequencyId: p.ExecutionFrequencyId,
  4226. IsOut: p.IsOut,
  4227. YbSyncStatus: p.YbSyncStatus,
  4228. }
  4229. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4230. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  4231. }
  4232. if nowCount == historyCount {
  4233. if historyCount == 0 {
  4234. recordDateStr := time.Now().Format("2006-01-02")
  4235. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4236. nowtime := recordDate.Unix()
  4237. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4238. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4239. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4240. creater := c.GetAdminUserInfo().AdminUser.Id
  4241. dialyPrepareOne := models.DialysisBeforePrepare{
  4242. GoodTypeId: goodObj.GoodTypeId,
  4243. GoodId: p.ProjectId,
  4244. PatientId: p.PatientId,
  4245. RecordDate: p.RecordDate,
  4246. UserOrgId: adminInfo.CurrentOrgId,
  4247. Count: nowCount,
  4248. Ctime: time.Now().Unix(),
  4249. Creater: creater,
  4250. Status: 1,
  4251. StorehouseId: houseConfig.StorehouseOutInfo,
  4252. ProjectId: p.ID,
  4253. }
  4254. //出库
  4255. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  4256. }
  4257. }
  4258. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  4259. //查询历史出库数据
  4260. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4261. var out_count_five int64
  4262. for _, item := range flowGood {
  4263. out_count_five += item.Count
  4264. }
  4265. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  4266. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  4267. if out_count_five != parseIntCount {
  4268. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4269. detail := models.AutomaticReduceDetail{
  4270. WarehouseOutId: 0,
  4271. WarehouseOutOrderNumber: "",
  4272. PatientId: p.PatientId,
  4273. Ctime: time.Now().Unix(),
  4274. Mtime: 0,
  4275. Status: 1,
  4276. RecordTime: p.RecordDate,
  4277. OrgId: p.UserOrgId,
  4278. GoodId: p.ProjectId,
  4279. GoodTypeId: 0,
  4280. Count: parseIntCount,
  4281. Type: 0,
  4282. ProjectId: lastHisProject.ID,
  4283. StorehouseId: 0,
  4284. }
  4285. service.CreateNewAutoDetail(detail, tx)
  4286. }
  4287. // //查询耗材最后一次出库记录
  4288. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  4289. // //查询默认出库仓库库存
  4290. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4291. // if len(wareOut) > 0 {
  4292. //
  4293. // for _, it := range wareOut {
  4294. // //回退库存
  4295. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4296. //
  4297. // //删除出库记录
  4298. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4299. //
  4300. // }
  4301. // }
  4302. //
  4303. // timeStr := time.Now().Format("2006-01-02")
  4304. // timeArr := strings.Split(timeStr, "-")
  4305. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4306. //
  4307. // total = total + 1
  4308. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4309. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4310. // number = number + total
  4311. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4312. //
  4313. // operation_time := time.Now().Unix()
  4314. // creater := c.GetAdminUserInfo().AdminUser.Id
  4315. //
  4316. // recordDateStr := time.Now().Format("2006-01-02")
  4317. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4318. // nowtime := recordDate.Unix()
  4319. // warehouseOut := models.WarehouseOut{
  4320. // WarehouseOutOrderNumber: warehousing_out_order,
  4321. // OperationTime: operation_time,
  4322. // OrgId: adminInfo.CurrentOrgId,
  4323. // Creater: creater,
  4324. // Ctime: time.Now().Unix(),
  4325. // Status: 1,
  4326. // WarehouseOutTime: nowtime,
  4327. // Type: 1,
  4328. // StorehouseId: storeConfig.StorehouseOutInfo,
  4329. // IsCheck: 1,
  4330. // IsSys: 1,
  4331. // }
  4332. // //查询是否生成出库单
  4333. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4334. // if out.ID == 0 {
  4335. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  4336. // }
  4337. //
  4338. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  4339. //
  4340. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  4341. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4342. //
  4343. // dialyPrepareOne := models.DialysisBeforePrepare{
  4344. // GoodTypeId: goodObj.GoodTypeId,
  4345. // GoodId: p.ProjectId,
  4346. // PatientId: p.PatientId,
  4347. // RecordDate: p.RecordDate,
  4348. // UserOrgId: adminInfo.CurrentOrgId,
  4349. // Count: parseIntCount,
  4350. // Ctime: time.Now().Unix(),
  4351. // Creater: creater,
  4352. // Status: 1,
  4353. // StorehouseId: houseConfig.StorehouseOutInfo,
  4354. // ProjectId: lastHisProject.ID,
  4355. // }
  4356. // //判断是否是零用耗材(非零用)
  4357. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  4358. //
  4359. // //查询历史出库数据
  4360. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4361. // var out_count int64
  4362. // for _, item := range flowGood {
  4363. // out_count += item.Count
  4364. // }
  4365. // //如果历史数和当前数据不想等才进行退库出库
  4366. // if out_count != parseIntCount {
  4367. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4368. //
  4369. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4370. // detail := models.AutomaticReduceDetail{
  4371. // WarehouseOutId: 0,
  4372. // WarehouseOutOrderNumber: "",
  4373. // PatientId: p.PatientId,
  4374. // Ctime: time.Now().Unix(),
  4375. // Mtime: 0,
  4376. // Status: 1,
  4377. // RecordTime: p.RecordDate,
  4378. // OrgId: p.UserOrgId,
  4379. // GoodId: p.ProjectId,
  4380. // GoodTypeId: 0,
  4381. // Count: parseIntCount,
  4382. // Type: 0,
  4383. // ProjectId: lastHisProject.ID,
  4384. // StorehouseId: 0,
  4385. // }
  4386. //
  4387. // service.CreateNewAutoDetail(detail, tx)
  4388. //
  4389. // //查询剩余库存
  4390. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4391. // var sum_count int64
  4392. // for _, item := range goodList {
  4393. // sum_count += item.StockCount
  4394. // }
  4395. //
  4396. // //更新剩余库存
  4397. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4398. //
  4399. // //耗材
  4400. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4401. //
  4402. // }
  4403. // //判断是否是零用耗材(零用但是是出库耗材)
  4404. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  4405. //
  4406. // //查询历史出库数据
  4407. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  4408. // var out_count int64
  4409. // for _, item := range flowGood {
  4410. // out_count += item.Count
  4411. // }
  4412. // //如果历史数和当前数据不想等才进行退库出库
  4413. // if out_count != parseIntCount {
  4414. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  4415. //
  4416. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  4417. // detail := models.AutomaticReduceDetail{
  4418. // WarehouseOutId: 0,
  4419. // WarehouseOutOrderNumber: "",
  4420. // PatientId: p.PatientId,
  4421. // Ctime: time.Now().Unix(),
  4422. // Mtime: 0,
  4423. // Status: 1,
  4424. // RecordTime: p.RecordDate,
  4425. // OrgId: p.UserOrgId,
  4426. // GoodId: p.ProjectId,
  4427. // GoodTypeId: 0,
  4428. // Count: parseIntCount,
  4429. // Type: 0,
  4430. // ProjectId: p.ID,
  4431. // StorehouseId: 0,
  4432. // }
  4433. //
  4434. // service.CreateNewAutoDetail(detail, tx)
  4435. //
  4436. // //查询剩余库存
  4437. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4438. // var sum_count int64
  4439. // for _, item := range goodList {
  4440. // sum_count += item.StockCount
  4441. // }
  4442. //
  4443. // //更新剩余库存
  4444. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4445. //
  4446. // //耗材
  4447. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4448. // }
  4449. //
  4450. // }
  4451. //
  4452. // }
  4453. //
  4454. //}
  4455. //记录日志
  4456. byterequest, _ := json.Marshal(p)
  4457. adviceLog := models.XtDoctorAdviceLog{
  4458. UserOrgId: p.UserOrgId,
  4459. PatientId: p.PatientId,
  4460. AdminUserId: adminInfo.AdminUser.Id,
  4461. Module: 1,
  4462. ErrLog: string(byterequest),
  4463. Status: 1,
  4464. Ctime: time.Now().Unix(),
  4465. Mtime: 0,
  4466. Source: "电脑端新建his项目",
  4467. RecordDate: p.RecordDate,
  4468. }
  4469. service.CreateDoctorAdviceLog(adviceLog)
  4470. projectList = append(projectList, p)
  4471. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4472. //新增或者编辑项目,修改对应的标签数据
  4473. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4474. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4475. var label models.HisLabelPrintInfo
  4476. project, _ := service.GetProjectDetail(p.ProjectId)
  4477. if project.CostClassify == 3 { //类别为检验检查
  4478. if p.TeamId > 0 { //检验检查组套
  4479. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4480. if tempLabel.ID == 0 {
  4481. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4482. label.Number = tempPrescription.PrescriptionNumber
  4483. label.ProjectId = project.ID
  4484. label.Status = 1
  4485. label.IsPrint = 2
  4486. label.DoctorId = info.DoctorId
  4487. label.UserOrgId = p.UserOrgId
  4488. label.PatientId = patient_id
  4489. label.RecordDate = recordDateTime
  4490. label.Ctime = time.Now().Unix()
  4491. label.Mtime = time.Now().Unix()
  4492. label.ItemId = p.TeamId
  4493. label.FeedetlSn = p.FeedetlSn
  4494. label.PProjectId = p.ID
  4495. label.ProjectName = team.ProjectTeam
  4496. label.PatientName = patient.Name
  4497. service.CreateNewHisLabelRecord(&label, tx)
  4498. }
  4499. } else { //单条检验检查项目
  4500. label.Number = tempPrescription.PrescriptionNumber
  4501. label.ProjectId = project.ID
  4502. label.Status = 1
  4503. label.DoctorId = info.DoctorId
  4504. label.UserOrgId = p.UserOrgId
  4505. label.PatientId = patient_id
  4506. label.RecordDate = recordDateTime
  4507. label.IsPrint = 2
  4508. label.Ctime = time.Now().Unix()
  4509. label.Mtime = time.Now().Unix()
  4510. label.FeedetlSn = p.FeedetlSn
  4511. label.PProjectId = p.ID
  4512. label.ItemId = p.TeamId
  4513. label.ProjectName = project.ProjectName
  4514. label.PatientName = patient.Name
  4515. service.CreateNewHisLabelRecord(&label, tx)
  4516. }
  4517. }
  4518. }
  4519. }
  4520. }
  4521. }
  4522. }
  4523. //插入检验数据
  4524. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4525. //新增或者编辑项目,修改对应的标签数据
  4526. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4527. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4528. var label models.HisLabelPrintInfo
  4529. project, _ := service.GetProjectDetail(p.ProjectId)
  4530. if project.CostClassify == 3 { //类别为检验检查
  4531. if p.TeamId > 0 { //检验检查组套
  4532. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4533. if tempLabel.ID == 0 {
  4534. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4535. label.Number = tempPrescription.PrescriptionNumber
  4536. label.ProjectId = project.ID
  4537. label.Status = 1
  4538. label.IsPrint = 2
  4539. label.DoctorId = info.DoctorId
  4540. label.UserOrgId = p.UserOrgId
  4541. label.PatientId = patient_id
  4542. label.RecordDate = recordDateTime
  4543. label.Ctime = time.Now().Unix()
  4544. label.Mtime = time.Now().Unix()
  4545. label.ItemId = p.TeamId
  4546. label.FeedetlSn = p.FeedetlSn
  4547. label.PProjectId = p.ID
  4548. label.ProjectName = team.ProjectTeam
  4549. label.PatientName = patient.Name
  4550. service.CreateHisLabelRecord(&label)
  4551. }
  4552. } else { //单条检验检查项目
  4553. label.Number = tempPrescription.PrescriptionNumber
  4554. label.ProjectId = project.ID
  4555. label.Status = 1
  4556. label.DoctorId = info.DoctorId
  4557. label.UserOrgId = p.UserOrgId
  4558. label.PatientId = patient_id
  4559. label.RecordDate = recordDateTime
  4560. label.IsPrint = 2
  4561. label.Ctime = time.Now().Unix()
  4562. label.Mtime = time.Now().Unix()
  4563. label.FeedetlSn = p.FeedetlSn
  4564. label.PProjectId = p.ID
  4565. label.ItemId = p.TeamId
  4566. label.ProjectName = project.ProjectName
  4567. label.PatientName = patient.Name
  4568. service.CreateHisLabelRecord(&label)
  4569. }
  4570. }
  4571. }
  4572. }
  4573. service.CreateNewHisProjectTwo(&p, tx)
  4574. var randNum int
  4575. randNum = rand.Intn(10000) + 1000
  4576. timestamp := time.Now().Unix()
  4577. tempTime := time.Unix(timestamp, 0)
  4578. timeFormat := tempTime.Format("20060102150405")
  4579. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4580. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  4581. if goodBase.ID > 0 {
  4582. tx.Rollback()
  4583. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  4584. return
  4585. }
  4586. service.CreateNewHisProjectTwo(&p, tx)
  4587. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  4588. //查询剩余库存
  4589. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  4590. var sum_count int64
  4591. for _, item := range goodList {
  4592. sum_count += item.StockCount
  4593. }
  4594. //更新剩余库存
  4595. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  4596. //耗材
  4597. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  4598. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4599. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4600. if len(outInfoTwo) > 0 {
  4601. for _, item := range outInfoTwo {
  4602. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  4603. }
  4604. }
  4605. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  4606. if len(drugAutoDetail) > 0 {
  4607. for _, item := range drugAutoDetail {
  4608. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  4609. }
  4610. }
  4611. tx.Commit()
  4612. }
  4613. }
  4614. }
  4615. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4616. // addition := items["addition"].([]interface{})
  4617. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4618. // ctime := time.Now().Unix()
  4619. // mtime := ctime
  4620. // if len(addition) > 0 {
  4621. // for _, item := range addition {
  4622. // var s models.HisAdditionalCharge
  4623. // s.PrescriptionId = tempPrescription.ID
  4624. // s.Status = 1
  4625. // s.UserOrgId = adminInfo.CurrentOrgId
  4626. // s.RecordDate = recordDateTime
  4627. // s.CreatedTime = ctime
  4628. // s.UpdatedTime = mtime
  4629. // s.PatientId = patient_id
  4630. // s.HisPatientId = his_patient_id
  4631. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4632. // if errcode > 0 {
  4633. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4634. // return
  4635. // }
  4636. // service.CreateAdditionalCharge(&s)
  4637. // var randNum int
  4638. // randNum = rand.Intn(10000) + 1000
  4639. // timestamp := time.Now().Unix()
  4640. // tempTime := time.Unix(timestamp, 0)
  4641. // timeFormat := tempTime.Format("20060102150405")
  4642. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4643. // service.CreateAdditionalCharge(&s)
  4644. //
  4645. // }
  4646. // }
  4647. //}
  4648. }
  4649. }
  4650. }
  4651. tx.Commit()
  4652. if err == nil {
  4653. c.ServeSuccessJSON(map[string]interface{}{
  4654. "msg": "保存成功",
  4655. })
  4656. return
  4657. } else {
  4658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4659. return
  4660. }
  4661. } else {
  4662. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4663. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4664. var tempPrescription *models.HisPrescription
  4665. if len(prescriptions) > 0 {
  4666. for _, item := range prescriptions {
  4667. items := item.(map[string]interface{})
  4668. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4669. utils.ErrorLog("id")
  4670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4671. return
  4672. }
  4673. id := int64(items["id"].(float64))
  4674. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  4675. tempPrescription = &new_prescription
  4676. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4677. utils.ErrorLog("type")
  4678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4679. return
  4680. }
  4681. types := int64(items["type"].(float64))
  4682. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4683. utils.ErrorLog("med_type")
  4684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4685. return
  4686. }
  4687. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4688. if med_type == "0" {
  4689. med_type = "14"
  4690. }
  4691. //if order_status == 0 {
  4692. // order_status = 1
  4693. //}
  4694. //if items["diagnoses"] == nil || reflect.TypeOf(items["diagnoses"]).String() != "string" {
  4695. // utils.ErrorLog("diagnoses")
  4696. //}
  4697. diagnoses, _ := items["diagnoses"].(string)
  4698. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  4699. utils.ErrorLog("pre_time")
  4700. }
  4701. preTime, _ := items["pre_time"].(string)
  4702. timeLayout := "2006-01-02"
  4703. loc, _ := time.LoadLocation("Local")
  4704. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  4705. //result := strings.Split(preTime, " ")
  4706. theTime3, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4707. if err != nil {
  4708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4709. return
  4710. }
  4711. pTime := theTime2.Unix()
  4712. ctime := time.Now().Unix()
  4713. if tempPrescription.ID == 0 {
  4714. prescription := &models.HisPrescription{
  4715. ID: 0,
  4716. PatientId: patient_id,
  4717. UserOrgId: adminInfo.CurrentOrgId,
  4718. RecordDate: recordDateTime,
  4719. Ctime: ctime,
  4720. Mtime: ctime,
  4721. Type: types,
  4722. Modifier: adminInfo.AdminUser.Id,
  4723. Creator: adminInfo.AdminUser.Id,
  4724. Status: 1,
  4725. Doctor: role.UserName,
  4726. HisPatientId: his_patient_id,
  4727. OrderStatus: 1,
  4728. BatchNumber: "",
  4729. PrescriptionNumber: hpInfo.PrescriptionNumber,
  4730. PreTime: pTime,
  4731. PType: p_type,
  4732. MedType: med_type,
  4733. Diagnose: diagnoses,
  4734. }
  4735. tempPrescription = prescription
  4736. service.SaveHisPrescription(tempPrescription)
  4737. redis := service.RedisClient()
  4738. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4739. redis.Set(key, "", time.Second)
  4740. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4741. redis.Set(keyOne, "", time.Second)
  4742. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4743. redis.Set(keySeven, "", time.Second)
  4744. defer redis.Close()
  4745. } else {
  4746. tempPrescription.ID = id
  4747. tempPrescription.Type = types
  4748. tempPrescription.Modifier = adminInfo.AdminUser.Id
  4749. tempPrescription.Mtime = time.Now().Unix()
  4750. tempPrescription.Doctor = role.UserName
  4751. //tempPrescription.OrderStatus = order_status
  4752. tempPrescription.PreTime = pTime
  4753. tempPrescription.MedType = med_type
  4754. tempPrescription.Diagnose = diagnoses
  4755. service.SaveHisPrescription(tempPrescription)
  4756. redis := service.RedisClient()
  4757. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4758. redis.Set(key, "", time.Second)
  4759. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4760. redis.Set(keyOne, "", time.Second)
  4761. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4762. redis.Set(keySeven, "", time.Second)
  4763. defer redis.Close()
  4764. }
  4765. //service.SaveHisPrescription(prescription)
  4766. //更改患者挂号状态
  4767. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4768. fmt.Println("更改失败", err2)
  4769. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4770. advices := items["advices"].([]interface{})
  4771. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4772. groupNo := int64(0)
  4773. if len(advices) > 0 {
  4774. for _, advice := range advices {
  4775. var s models.HisDoctorAdviceInfo
  4776. s.PrescriptionId = tempPrescription.ID
  4777. s.AdviceType = 2
  4778. s.AdviceDoctor = doctor_id
  4779. s.StopState = 2
  4780. s.ExecutionState = 2
  4781. s.AdviceDate = theTime3.Unix()
  4782. s.Status = 1
  4783. s.UserOrgId = adminInfo.CurrentOrgId
  4784. s.RecordDate = theTime3.Unix()
  4785. s.StartTime = tempPrescription.PreTime
  4786. s.Groupno = groupNo
  4787. s.PatientId = patient_id
  4788. s.HisPatientId = his_patient_id
  4789. s.StartTime = pTime
  4790. s.IsSettle = 2
  4791. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  4792. if errcode > 0 {
  4793. c.ServeFailJSONWithSGJErrorCode(errcode)
  4794. return
  4795. }
  4796. s.StartTime = pTime
  4797. var total_count int64 //处方总库存
  4798. //查询改药品信息
  4799. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  4800. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  4801. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4802. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4803. total_count += prescribingNumberSeven * medical.MinNumber
  4804. }
  4805. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4806. total_count += prescribingNumberSeven
  4807. }
  4808. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  4809. total_count += prescribingNumberSeven
  4810. }
  4811. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4812. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4813. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4814. if s.Price != lastWarehouse.RetailPrice {
  4815. s.Price = lastWarehouse.RetailPrice
  4816. }
  4817. if s.Price == 0 {
  4818. if lastWarehouse.ID == 0 {
  4819. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  4820. s.Price = lastWarehouseTwo.RetailPrice
  4821. }
  4822. }
  4823. }
  4824. if adminInfo.CurrentOrgId != 10206 {
  4825. if s.ID == 0 {
  4826. //查询改药品是否已经停用
  4827. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  4828. if base.ID > 0 {
  4829. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  4830. return
  4831. }
  4832. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  4833. if drugMedical.SumCount == 0 {
  4834. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  4835. return
  4836. }
  4837. }
  4838. }
  4839. //赤峰
  4840. if s.UserOrgId == 10265 || s.UserOrgId == 10489 {
  4841. drug, _ := service.GetDrugByGoodId(s.DrugId)
  4842. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  4843. if info.RetailPrice > 0 {
  4844. if s.DeliveryWay == "口服" {
  4845. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4846. s.Price = drug.RetailPrice
  4847. }
  4848. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4849. s.Price = info.RetailPrice
  4850. }
  4851. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4852. s.Price = info.RetailPrice
  4853. }
  4854. }
  4855. }
  4856. }
  4857. service.CreateHisDoctorAdvice(&s)
  4858. //记录日志
  4859. byterequest, _ := json.Marshal(s)
  4860. adviceLog := models.XtDoctorAdviceLog{
  4861. UserOrgId: s.UserOrgId,
  4862. PatientId: s.PatientId,
  4863. AdminUserId: adminInfo.AdminUser.Id,
  4864. Module: 1,
  4865. ErrLog: string(byterequest),
  4866. Status: 1,
  4867. Ctime: time.Now().Unix(),
  4868. Mtime: 0,
  4869. Source: "电脑端新建his医嘱",
  4870. RecordDate: s.AdviceDate,
  4871. }
  4872. service.CreateDoctorAdviceLog(adviceLog)
  4873. //存储切片中
  4874. adviceList = append(adviceList, s)
  4875. redis := service.RedisClient()
  4876. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4877. redis.Set(key, "", time.Second)
  4878. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4879. redis.Set(keyOne, "", time.Second)
  4880. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4881. redis.Set(keySeven, "", time.Second)
  4882. var randNum int
  4883. randNum = rand.Intn(10000) + 1000
  4884. timestamp := time.Now().Unix()
  4885. tempTime := time.Unix(timestamp, 0)
  4886. timeFormat := tempTime.Format("20060102150405")
  4887. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  4888. service.CreateHisDoctorAdvice(&s)
  4889. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4890. redis.Set(keySix, "", time.Second)
  4891. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4892. redis.Set(keyFive, "", time.Second)
  4893. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4894. redis.Set(keyEight, "", time.Second)
  4895. defer redis.Close()
  4896. }
  4897. }
  4898. }
  4899. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4900. projects := items["project"].([]interface{})
  4901. if len(projects) > 0 {
  4902. for _, project := range projects {
  4903. var p models.HisPrescriptionProject
  4904. p.PrescriptionId = tempPrescription.ID
  4905. p.PatientId = patient_id
  4906. p.RecordDate = theTime3.Unix()
  4907. p.Doctor = doctor_id
  4908. p.UserOrgId = adminInfo.CurrentOrgId
  4909. p.HisPatientId = his_patient_id
  4910. p.Status = 1
  4911. p.StartTime = pTime
  4912. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4913. if errcode > 0 {
  4914. c.ServeFailJSONWithSGJErrorCode(errcode)
  4915. return
  4916. }
  4917. if p.ID == 0 {
  4918. p.IsOut = 2
  4919. }
  4920. if p.ID > 0 {
  4921. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4922. p.IsOut = projectDetail.IsOut
  4923. }
  4924. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4925. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4926. if p.Type == 3 {
  4927. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4928. if p.Price != lastWarehouse.PackingPrice {
  4929. p.Price = lastWarehouse.PackingPrice
  4930. }
  4931. if p.Price == 0 {
  4932. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4933. p.Price = lastWarehouseTwo.PackingPrice
  4934. }
  4935. if p.Unit == "" {
  4936. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4937. p.Unit = goodInfoOne.PackingUnit
  4938. }
  4939. }
  4940. }
  4941. if adminInfo.CurrentOrgId != 10206 {
  4942. if p.Type == 3 {
  4943. if p.ID == 0 {
  4944. //查询该耗材是否停用
  4945. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4946. //表示该耗材已经停用,不能保存
  4947. if goodInfoSeven.ID == 0 {
  4948. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4949. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4950. return
  4951. }
  4952. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4953. if goodInfoOne.SumCount == 0 {
  4954. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4955. return
  4956. }
  4957. }
  4958. }
  4959. }
  4960. service.CreateHisProjectTwo(&p)
  4961. //记录日志
  4962. byterequest, _ := json.Marshal(p)
  4963. adviceLog := models.XtDoctorAdviceLog{
  4964. UserOrgId: p.UserOrgId,
  4965. PatientId: p.PatientId,
  4966. AdminUserId: adminInfo.AdminUser.Id,
  4967. Module: 1,
  4968. ErrLog: string(byterequest),
  4969. Status: 1,
  4970. Ctime: time.Now().Unix(),
  4971. Mtime: 0,
  4972. Source: "电脑端新建his项目",
  4973. RecordDate: p.RecordDate,
  4974. }
  4975. service.CreateDoctorAdviceLog(adviceLog)
  4976. projectList = append(projectList, p)
  4977. var randNum int
  4978. randNum = rand.Intn(10000) + 1000
  4979. timestamp := time.Now().Unix()
  4980. tempTime := time.Unix(timestamp, 0)
  4981. timeFormat := tempTime.Format("20060102150405")
  4982. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4983. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4984. //新增或者编辑项目,修改对应的标签数据
  4985. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4986. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4987. var label models.HisLabelPrintInfo
  4988. project, _ := service.GetProjectDetail(p.ProjectId)
  4989. if project.CostClassify == 3 { //类别为检验检查
  4990. if p.TeamId > 0 { //检验检查组套
  4991. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4992. if tempLabel.ID == 0 {
  4993. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4994. label.Number = tempPrescription.PrescriptionNumber
  4995. label.ProjectId = project.ID
  4996. label.Status = 1
  4997. label.IsPrint = 2
  4998. label.DoctorId = info.DoctorId
  4999. label.UserOrgId = p.UserOrgId
  5000. label.PatientId = patient_id
  5001. label.RecordDate = recordDateTime
  5002. label.Ctime = time.Now().Unix()
  5003. label.Mtime = time.Now().Unix()
  5004. label.ItemId = p.TeamId
  5005. label.FeedetlSn = p.FeedetlSn
  5006. label.PProjectId = p.ID
  5007. label.ProjectName = team.ProjectTeam
  5008. label.PatientName = patient.Name
  5009. service.CreateHisLabelRecord(&label)
  5010. }
  5011. } else { //单条检验检查项目
  5012. label.Number = tempPrescription.PrescriptionNumber
  5013. label.ProjectId = project.ID
  5014. label.Status = 1
  5015. label.DoctorId = info.DoctorId
  5016. label.UserOrgId = p.UserOrgId
  5017. label.PatientId = patient_id
  5018. label.RecordDate = recordDateTime
  5019. label.IsPrint = 2
  5020. label.Ctime = time.Now().Unix()
  5021. label.Mtime = time.Now().Unix()
  5022. label.FeedetlSn = p.FeedetlSn
  5023. label.PProjectId = p.ID
  5024. label.ItemId = p.TeamId
  5025. label.ProjectName = project.ProjectName
  5026. label.PatientName = patient.Name
  5027. service.CreateHisLabelRecord(&label)
  5028. }
  5029. }
  5030. }
  5031. }
  5032. service.SaveHisProjectTwo(&p)
  5033. }
  5034. }
  5035. }
  5036. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5037. // addition := items["addition"].([]interface{})
  5038. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5039. // ctime := time.Now().Unix()
  5040. // mtime := ctime
  5041. // if len(addition) > 0 {
  5042. // for _, item := range addition {
  5043. // var s models.HisAdditionalCharge
  5044. // s.PrescriptionId = tempPrescription.ID
  5045. // s.Status = 1
  5046. // s.UserOrgId = adminInfo.CurrentOrgId
  5047. // s.RecordDate = recordDateTime
  5048. // s.CreatedTime = ctime
  5049. // s.UpdatedTime = mtime
  5050. // s.PatientId = patient_id
  5051. // s.HisPatientId = his_patient_id
  5052. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5053. // if errcode > 0 {
  5054. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5055. // return
  5056. // }
  5057. // service.CreateAdditionalCharge(&s)
  5058. // var randNum int
  5059. // randNum = rand.Intn(10000) + 1000
  5060. // timestamp := time.Now().Unix()
  5061. // tempTime := time.Unix(timestamp, 0)
  5062. // timeFormat := tempTime.Format("20060102150405")
  5063. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  5064. // service.CreateAdditionalCharge(&s)
  5065. //
  5066. // }
  5067. // }
  5068. //}
  5069. }
  5070. }
  5071. //查询今日该患者开的药品处方
  5072. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5073. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  5074. //药品出库
  5075. if drugOutConfig.IsOpen == 1 {
  5076. for _, item := range hisdoctorlist {
  5077. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  5078. // 查询该药品最后一次出库记录
  5079. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  5080. if len(druginfo) > 0 {
  5081. //回退库存
  5082. for _, it := range druginfo {
  5083. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  5084. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5085. }
  5086. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  5087. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5088. }
  5089. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  5090. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  5091. }
  5092. }
  5093. }
  5094. //删除记录
  5095. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  5096. //查询最后一次数据
  5097. if drugOutConfig.IsOpen == 1 {
  5098. //出库
  5099. if drug.IsUse == 2 {
  5100. creater := adminInfo.AdminUser.Id
  5101. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  5102. }
  5103. //更新字典里面的库存
  5104. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5105. var sum_count int64
  5106. for _, its := range stockInfo {
  5107. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5108. if its.MaxUnit == baseDrug.MaxUnit {
  5109. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5110. }
  5111. sum_count += its.StockMaxNumber + its.StockMinNumber
  5112. }
  5113. //更新基础库存
  5114. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5115. //剩余库存
  5116. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  5117. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  5118. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  5119. }
  5120. }
  5121. }
  5122. //耗材保存处方出库
  5123. if goodOutConfig.IsOpen == 1 {
  5124. //查询今日耗材出库数量
  5125. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  5126. for _, item := range hisgoodlist {
  5127. //查询历史出库数据
  5128. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5129. var out_count_five int64
  5130. for _, item := range flowGood {
  5131. out_count_five += item.Count
  5132. }
  5133. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  5134. if out_count_five != parseIntCount {
  5135. //查询耗材最后一次出库记录
  5136. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  5137. //查询默认出库仓库库存
  5138. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5139. if len(wareOut) > 0 {
  5140. for _, it := range wareOut {
  5141. //回退库存
  5142. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  5143. //删除出库记录
  5144. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  5145. }
  5146. }
  5147. timeStr := time.Now().Format("2006-01-02")
  5148. timeArr := strings.Split(timeStr, "-")
  5149. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  5150. total = total + 1
  5151. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5152. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5153. number = number + total
  5154. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5155. operation_time := time.Now().Unix()
  5156. creater := c.GetAdminUserInfo().AdminUser.Id
  5157. recordDateStr := time.Now().Format("2006-01-02")
  5158. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5159. nowtime := recordDate.Unix()
  5160. warehouseOut := models.WarehouseOut{
  5161. WarehouseOutOrderNumber: warehousing_out_order,
  5162. OperationTime: operation_time,
  5163. OrgId: adminInfo.CurrentOrgId,
  5164. Creater: creater,
  5165. Ctime: time.Now().Unix(),
  5166. Status: 1,
  5167. WarehouseOutTime: nowtime,
  5168. Type: 1,
  5169. StorehouseId: storeConfig.StorehouseOutInfo,
  5170. IsCheck: 1,
  5171. IsSys: 1,
  5172. }
  5173. //查询是否生成出库单
  5174. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5175. if out.ID == 0 {
  5176. service.AddSigleWarehouseOutOne(&warehouseOut)
  5177. }
  5178. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  5179. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5180. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5181. dialyPrepareOne := models.DialysisBeforePrepare{
  5182. GoodTypeId: goodObj.GoodTypeId,
  5183. GoodId: item.ProjectId,
  5184. PatientId: item.PatientId,
  5185. RecordDate: item.RecordDate,
  5186. UserOrgId: adminInfo.CurrentOrgId,
  5187. Count: parseIntCount,
  5188. Ctime: time.Now().Unix(),
  5189. Creater: creater,
  5190. Status: 1,
  5191. StorehouseId: houseConfig.StorehouseOutInfo,
  5192. ProjectId: item.ID,
  5193. }
  5194. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  5195. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  5196. //查询历史出库数据
  5197. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5198. var out_count int64
  5199. for _, item := range flowGood {
  5200. out_count += item.Count
  5201. }
  5202. //如果历史数和当前数据不想等才进行退库出库
  5203. if out_count != parseIntCount {
  5204. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5205. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5206. detail := models.AutomaticReduceDetail{
  5207. WarehouseOutId: 0,
  5208. WarehouseOutOrderNumber: "",
  5209. PatientId: item.PatientId,
  5210. Ctime: time.Now().Unix(),
  5211. Mtime: 0,
  5212. Status: 1,
  5213. RecordTime: item.RecordDate,
  5214. OrgId: item.UserOrgId,
  5215. GoodId: item.ProjectId,
  5216. GoodTypeId: 0,
  5217. Count: parseIntCount,
  5218. Type: 0,
  5219. ProjectId: item.ID,
  5220. StorehouseId: 0,
  5221. }
  5222. service.CreateAutoDetail(detail)
  5223. //查询剩余库存
  5224. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5225. var sum_count int64
  5226. for _, item := range goodList {
  5227. sum_count += item.StockCount
  5228. }
  5229. //更新剩余库存
  5230. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5231. //耗材
  5232. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5233. }
  5234. }
  5235. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  5236. //查询历史出库数据
  5237. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5238. var out_count int64
  5239. for _, item := range flowGood {
  5240. out_count += item.Count
  5241. }
  5242. //如果历史数和当前数据不想等才进行退库出库
  5243. if out_count != parseIntCount {
  5244. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  5245. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  5246. detail := models.AutomaticReduceDetail{
  5247. WarehouseOutId: 0,
  5248. WarehouseOutOrderNumber: "",
  5249. PatientId: item.PatientId,
  5250. Ctime: time.Now().Unix(),
  5251. Mtime: 0,
  5252. Status: 1,
  5253. RecordTime: item.RecordDate,
  5254. OrgId: item.UserOrgId,
  5255. GoodId: item.ProjectId,
  5256. GoodTypeId: 0,
  5257. Count: parseIntCount,
  5258. Type: 0,
  5259. ProjectId: item.ID,
  5260. StorehouseId: 0,
  5261. }
  5262. service.CreateAutoDetail(detail)
  5263. //查询剩余库存
  5264. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5265. var sum_count int64
  5266. for _, item := range goodList {
  5267. sum_count += item.StockCount
  5268. }
  5269. //更新剩余库存
  5270. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  5271. //耗材
  5272. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  5273. }
  5274. }
  5275. }
  5276. }
  5277. }
  5278. ////同步到自备药
  5279. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  5280. if selfPrescriptionOpen.IsOpen == 1 {
  5281. timeStr := time.Now().Format("2006-01-02")
  5282. timeArr := strings.Split(timeStr, "-")
  5283. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  5284. total = total + 1
  5285. operation_time := time.Now().Unix()
  5286. creater := adminInfo.AdminUser.Id
  5287. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5288. warehousing := models.XtSelfDrugWarehouse{
  5289. WarehousingOrder: warehousing_order,
  5290. OperationTime: operation_time,
  5291. OrgId: adminInfo.CurrentOrgId,
  5292. Creater: creater,
  5293. Ctime: time.Now().Unix(),
  5294. Status: 1,
  5295. WarehousingTime: recordDateTime,
  5296. Type: 0,
  5297. StorehouseId: 0,
  5298. IsCheck: 1,
  5299. PatientId: patient_id,
  5300. IsSys: 1,
  5301. }
  5302. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  5303. if selfDrugWarehouse.ID == 0 {
  5304. service.AddSelfDrugWarehouse(&warehousing, tx)
  5305. }
  5306. if selfDrugWarehouse.ID > 0 {
  5307. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  5308. }
  5309. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  5310. fmt.Println(info)
  5311. for _, item := range hisdoctorlist {
  5312. //查询该病人的该药品是否已经入库
  5313. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  5314. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5315. var in_count int64
  5316. if len(selfdruginfo) > 0 {
  5317. for _, item := range selfdruginfo {
  5318. var in_count_one int64
  5319. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5320. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  5321. }
  5322. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5323. in_count_one = item.WarehousingCount
  5324. }
  5325. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5326. in_count_one = item.WarehousingCount
  5327. }
  5328. in_count += in_count_one
  5329. }
  5330. }
  5331. if selfBasedrug.IsSelfDrug == 1 {
  5332. var total_count int64
  5333. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5334. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5335. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5336. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5337. }
  5338. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5339. total_count += prescribingNumberSeven
  5340. }
  5341. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5342. total_count += prescribingNumberSeven
  5343. }
  5344. //入库
  5345. if total_count > in_count {
  5346. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  5347. WarehousingOrder: warehousing_order,
  5348. WarehousingId: info.ID,
  5349. DrugId: item.DrugId,
  5350. Number: "",
  5351. ProductDate: 0,
  5352. ExpiryDate: 0,
  5353. WarehousingCount: total_count - in_count,
  5354. WarehouseingUnit: selfBasedrug.MinUnit,
  5355. Price: 0,
  5356. TotalPrice: 0,
  5357. Status: 1,
  5358. Ctime: time.Now().Unix(),
  5359. Remark: "",
  5360. OrgId: adminInfo.CurrentOrgId,
  5361. Type: 0,
  5362. Manufacturer: selfBasedrug.Manufacturer,
  5363. Dealer: selfBasedrug.Dealer,
  5364. StockMaxNumber: total_count - in_count,
  5365. RetailTotalPrice: 0,
  5366. BatchNumber: "",
  5367. MaxUnit: selfBasedrug.MinUnit,
  5368. MinUnit: selfBasedrug.MinUnit,
  5369. RetailPrice: 0,
  5370. StorehouseId: 0,
  5371. IsCheck: 1,
  5372. StockMinNumber: 0,
  5373. PatientId: patient_id,
  5374. IsSys: 1,
  5375. RecordDate: item.RecordDate,
  5376. AdviceId: item.ID,
  5377. }
  5378. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  5379. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  5380. Creator := adminInfo.AdminUser.Id
  5381. //查询默认仓库剩余多少库存
  5382. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  5383. var sum_count int64
  5384. for _, it := range list {
  5385. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5386. if it.MaxUnit == baseDrug.MaxUnit {
  5387. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  5388. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  5389. }
  5390. sum_count += it.StockMaxNumber + it.StockMinNumber
  5391. }
  5392. flow := &models.XtSelfDrugFlow{
  5393. WarehousingId: info.ID,
  5394. DrugId: item.DrugId,
  5395. Number: "",
  5396. BatchNumber: "",
  5397. Count: total_count - in_count,
  5398. UserOrgId: adminInfo.CurrentOrgId,
  5399. PatientId: item.PatientId,
  5400. SystemTime: time.Now().Unix(),
  5401. ConsumableType: 1,
  5402. IsSys: 1,
  5403. WarehousingOrder: warehousing_order,
  5404. WarehouseOutId: 0,
  5405. WarehouseOutOrderNumber: "",
  5406. IsEdit: 0,
  5407. CancelStockId: 0,
  5408. CancelOrderNumber: "",
  5409. Manufacturer: selfBasedrug.Manufacturer,
  5410. Dealer: selfBasedrug.Dealer,
  5411. Creator: Creator,
  5412. UpdateCreator: Creator,
  5413. Status: 1,
  5414. Ctime: item.AdviceDate,
  5415. Mtime: 0,
  5416. Price: item.Price,
  5417. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  5418. WarehouseOutDetailId: 0,
  5419. CancelOutDetailId: 0,
  5420. ExpireDate: 0,
  5421. ProductDate: 0,
  5422. MaxUnit: selfBasedrug.MinUnit,
  5423. MinUnit: selfBasedrug.MinUnit,
  5424. StorehouseId: 0,
  5425. OverCount: sum_count,
  5426. OperateTime: time.Now().Unix(),
  5427. AdviceId: item.ID,
  5428. }
  5429. service.CreateSelfDrugFlow(flow, tx)
  5430. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5431. var total_count int64 // 入库总数量
  5432. var over_count int64 //剩余库存
  5433. for _, it := range drugInfolist {
  5434. if it.MaxUnit == selfBasedrug.MaxUnit {
  5435. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  5436. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  5437. }
  5438. }
  5439. for _, it := range drugInfolist {
  5440. total_count += it.WarehousingCount
  5441. over_count += it.StockMaxNumber + it.StockMinNumber
  5442. }
  5443. //查询该仓库是否有默认数据
  5444. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  5445. if selfDrugStock.ID == 0 {
  5446. drugStock := models.XtSelfDrugStockCount{
  5447. UserOrgId: item.UserOrgId,
  5448. PatientId: item.PatientId,
  5449. SumInCount: total_count,
  5450. SumOutCount: 0,
  5451. SumCancelCount: 0,
  5452. DrugId: item.DrugId,
  5453. Ctime: time.Now().Unix(),
  5454. Mtime: 0,
  5455. Status: 1,
  5456. FlushCount: over_count,
  5457. SumActOutCount: 0,
  5458. }
  5459. service.CreateSelfDrugStockSum(drugStock, tx)
  5460. }
  5461. if selfDrugStock.ID > 0 {
  5462. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  5463. }
  5464. }
  5465. //查询这个单据的出库数量
  5466. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  5467. var his_out_count int64
  5468. for _, item := range drugFlowList {
  5469. his_out_count += item.Count
  5470. }
  5471. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  5472. if (total_count + his_out_count) <= in_count {
  5473. // 出库
  5474. if total_count < in_count {
  5475. var cha_count int64
  5476. cha_count = in_count - total_count
  5477. var stock_number int64 = 0
  5478. //查询库存是否充足
  5479. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  5480. // 将该批次的剩余库存数量转换为拆零数量
  5481. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5482. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5483. }
  5484. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5485. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  5486. }
  5487. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5488. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  5489. }
  5490. if stock_number >= cha_count {
  5491. var maxNumber int64 = 0
  5492. var minNumber int64 = 0
  5493. maxNumber = cha_count / selfBasedrug.MinNumber
  5494. minNumber = cha_count % selfBasedrug.MinNumber
  5495. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5496. minNumber = maxNumber
  5497. }
  5498. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5499. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  5500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5501. return
  5502. }
  5503. }
  5504. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5505. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  5506. }
  5507. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5508. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5509. }
  5510. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5511. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  5512. }
  5513. if warehouse.StockMaxNumber < 0 {
  5514. warehouse.StockMaxNumber = 0
  5515. }
  5516. if warehouse.StockMinNumber < 0 {
  5517. warehouse.StockMinNumber = 0
  5518. }
  5519. warehouse.Mtime = time.Now().Unix()
  5520. if warehouse.StockMinNumber < minNumber {
  5521. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5522. if warehouse.MaxUnit != warehouse.MinUnit {
  5523. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  5524. }
  5525. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  5526. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  5527. }
  5528. } else {
  5529. if minNumber > 0 {
  5530. if (warehouse.StockMinNumber - minNumber) >= 0 {
  5531. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  5532. }
  5533. }
  5534. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  5535. if warehouse.StockMinNumber > 0 {
  5536. if warehouse.StockMinNumber-cha_count >= 0 {
  5537. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5538. }
  5539. }
  5540. }
  5541. }
  5542. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  5543. if (warehouse.StockMinNumber - cha_count) >= 0 {
  5544. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  5545. }
  5546. }
  5547. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5548. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  5549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5550. return
  5551. }
  5552. }
  5553. if warehouse.StockMinNumber <= 0 {
  5554. warehouse.StockMinNumber = 0
  5555. }
  5556. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  5557. //查询该药品剩余库存
  5558. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  5559. var over_count int64
  5560. for _, its := range infolist {
  5561. if its.MaxUnit == selfBasedrug.MaxUnit {
  5562. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5563. }
  5564. over_count += its.StockMaxNumber + its.StockMinNumber
  5565. }
  5566. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  5567. drugflow := models.XtSelfDrugFlow{
  5568. WarehouseOutId: 0,
  5569. WarehouseOutOrderNumber: warehousing_order,
  5570. WarehousingOrder: warehousing_order,
  5571. DrugId: item.DrugId,
  5572. Number: warehouse.Number,
  5573. ProductDate: warehouse.ProductDate,
  5574. ExpireDate: warehouse.ExpiryDate,
  5575. Count: cha_count,
  5576. Price: warehouse.RetailPrice,
  5577. Status: 1,
  5578. Ctime: item.AdviceDate,
  5579. Mtime: time.Now().Unix(),
  5580. UserOrgId: item.UserOrgId,
  5581. Manufacturer: warehouse.Manufacturer,
  5582. Dealer: warehouse.Dealer,
  5583. BatchNumber: warehouse.BatchNumber,
  5584. MaxUnit: selfBasedrug.MinUnit,
  5585. ConsumableType: 20,
  5586. IsEdit: 1,
  5587. Creator: 0,
  5588. IsSys: 3,
  5589. WarehouseOutDetailId: drugWareInfo.ID,
  5590. AdviceId: item.ID,
  5591. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  5592. StorehouseId: 0,
  5593. AdminUserId: creater,
  5594. LastPrice: warehouse.Price,
  5595. StockCount: "",
  5596. WarehousingDetailId: 0,
  5597. OverCount: over_count,
  5598. RetailPrice: item.Price, //手动出库出库价格
  5599. WarehousingId: warehouse.ID,
  5600. SystemTime: item.AdviceDate,
  5601. PatientId: item.PatientId,
  5602. Remark: "保存处方入库数据差",
  5603. OperateTime: time.Now().Unix(),
  5604. }
  5605. if warehouse.RetailPrice == 0 {
  5606. drugflow.Price = item.Price
  5607. }
  5608. service.CreateSelfDrugFlowOne(drugflow, tx)
  5609. var out_count int64
  5610. out_count = in_count - total_count
  5611. //
  5612. //fmt.Println("in_count------------------", in_count)
  5613. //fmt.Println("total_count------------------", total_count)
  5614. //添加出库数量
  5615. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  5616. //查询剩余库存
  5617. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  5618. var sum_count int64
  5619. for _, its := range stockInfo {
  5620. if its.MaxUnit == selfBasedrug.MaxUnit {
  5621. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  5622. }
  5623. sum_count += its.StockMaxNumber + its.StockMinNumber
  5624. }
  5625. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  5626. } else {
  5627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  5628. return
  5629. }
  5630. }
  5631. }
  5632. }
  5633. }
  5634. }
  5635. }
  5636. tx.Commit()
  5637. if err == nil {
  5638. c.ServeSuccessJSON(map[string]interface{}{
  5639. "msg": "保存成功",
  5640. })
  5641. return
  5642. } else {
  5643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5644. return
  5645. }
  5646. }
  5647. }
  5648. //func (c *HisApiController) EditHisPrescription() {
  5649. // record_date := c.GetString("record_date")
  5650. // patient_id, _ := c.GetInt64("patient_id")
  5651. // reg_type, _ := c.GetInt64("reg_type")
  5652. // //diagnose, _ := c.GetInt64("diagnose", 0)
  5653. // diagnose := c.GetString("diagnose")
  5654. // sick_type, _ := c.GetInt64("sick_type")
  5655. // sick_history := c.GetString("sick_history")
  5656. // doctor_id, _ := c.GetInt64("doctor", 0)
  5657. // department, _ := c.GetInt64("department", 0)
  5658. // his_patient_id, _ := c.GetInt64("his_patient_id")
  5659. // p_type, _ := c.GetInt64("p_type")
  5660. //
  5661. // dataBody := make(map[string]interface{}, 0)
  5662. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5663. // if err != nil {
  5664. // utils.ErrorLog(err.Error())
  5665. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5666. // return
  5667. // }
  5668. //
  5669. // timeLayout := "2006-01-02"
  5670. // loc, _ := time.LoadLocation("Local")
  5671. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5672. // if err != nil {
  5673. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5674. // return
  5675. // }
  5676. // adminInfo := c.GetAdminUserInfo()
  5677. // recordDateTime := theTime.Unix()
  5678. //
  5679. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  5680. //
  5681. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5682. // var hpInfo models.HisPrescriptionInfo
  5683. // if info.ID == 0 {
  5684. // var randNum int
  5685. // randNum = rand.Intn(10000) + 1000
  5686. // timestamp := time.Now().Unix()
  5687. // tempTime := time.Unix(timestamp, 0)
  5688. // timeFormat := tempTime.Format("20060102150405")
  5689. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5690. //
  5691. // hpInfo = models.HisPrescriptionInfo{
  5692. // UserOrgId: adminInfo.CurrentOrgId,
  5693. // RecordDate: theTime.Unix(),
  5694. // PatientId: patient_id,
  5695. // Status: 1,
  5696. // Ctime: time.Now().Unix(),
  5697. // Mtime: time.Now().Unix(),
  5698. // Creator: adminInfo.AdminUser.Id,
  5699. // Modifier: adminInfo.AdminUser.Id,
  5700. // Diagnosis: diagnose,
  5701. // SickHistory: sick_history,
  5702. // Departments: department,
  5703. // RegisterType: reg_type,
  5704. // PrescriptionNumber: p_number,
  5705. // PrescriptionStatus: 1,
  5706. // Doctor: role.UserName,
  5707. // DoctorId: doctor_id,
  5708. // SickType: sick_type,
  5709. // PType: p_type,
  5710. // }
  5711. // service.SavePatientPrescriptionInfo(hpInfo)
  5712. //
  5713. // } else {
  5714. // hpInfo = models.HisPrescriptionInfo{
  5715. // ID: info.ID,
  5716. // UserOrgId: adminInfo.CurrentOrgId,
  5717. // RecordDate: info.RecordDate,
  5718. // PatientId: info.PatientId,
  5719. // Status: 1,
  5720. // Ctime: info.Ctime,
  5721. // Mtime: time.Now().Unix(),
  5722. // Creator: info.Creator,
  5723. // Modifier: adminInfo.AdminUser.Id,
  5724. // Diagnosis: diagnose,
  5725. // SickHistory: sick_history,
  5726. // Departments: department,
  5727. // RegisterType: reg_type,
  5728. // PrescriptionNumber: info.PrescriptionNumber,
  5729. // Doctor: role.UserName,
  5730. // PrescriptionStatus: info.PrescriptionStatus,
  5731. // DoctorId: doctor_id,
  5732. // SickType: sick_type,
  5733. // PType: info.PType,
  5734. // }
  5735. // service.SavePatientPrescriptionInfo(hpInfo)
  5736. // }
  5737. //
  5738. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5739. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5740. //
  5741. // if len(prescriptions) > 0 {
  5742. // for _, item := range prescriptions {
  5743. // items := item.(map[string]interface{})
  5744. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5745. // utils.ErrorLog("id")
  5746. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5747. // return
  5748. // }
  5749. // id := int64(items["id"].(float64))
  5750. //
  5751. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5752. // utils.ErrorLog("type")
  5753. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5754. // return
  5755. // }
  5756. // types := int64(items["type"].(float64))
  5757. //
  5758. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5759. // utils.ErrorLog("med_type")
  5760. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5761. // return
  5762. // }
  5763. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5764. //
  5765. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  5766. //
  5767. // ctime := time.Now().Unix()
  5768. //
  5769. // prescription := &models.HisPrescription{
  5770. // ID: id,
  5771. // PatientId: patient_id,
  5772. // UserOrgId: adminInfo.CurrentOrgId,
  5773. // RecordDate: recordDateTime,
  5774. // Ctime: ctime,
  5775. // Mtime: ctime,
  5776. // Type: types,
  5777. // Modifier: adminInfo.AdminUser.Id,
  5778. // Creator: adminInfo.AdminUser.Id,
  5779. // Status: 1,
  5780. // Doctor: role.UserName,
  5781. // HisPatientId: his_patient_id,
  5782. // OrderStatus: 1,
  5783. // BatchNumber: "",
  5784. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  5785. // PType: hpInfo.PType,
  5786. // MedType: med_type,
  5787. // }
  5788. //
  5789. // if historyPrescription.ID > 0 {
  5790. // prescription.PreTime = historyPrescription.PreTime
  5791. //
  5792. // }
  5793. //
  5794. // service.SaveHisPrescription(prescription)
  5795. //
  5796. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5797. // advices := items["advices"].([]interface{})
  5798. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5799. // groupNo := int64(0)
  5800. // ctime := time.Now().Unix()
  5801. // mtime := ctime
  5802. // if len(advices) > 0 {
  5803. // for _, advice := range advices {
  5804. // var s models.HisDoctorAdviceInfo
  5805. // s.PrescriptionId = prescription.ID
  5806. // s.AdviceType = 2
  5807. // s.AdviceDoctor = adminInfo.AdminUser.Id
  5808. // s.StopState = 2
  5809. // s.ExecutionState = 2
  5810. // s.AdviceDate = recordDateTime
  5811. // s.Status = 1
  5812. // s.UserOrgId = adminInfo.CurrentOrgId
  5813. // s.RecordDate = recordDateTime
  5814. // s.StartTime = prescription.PreTime
  5815. // s.Groupno = groupNo
  5816. // s.CreatedTime = ctime
  5817. // s.UpdatedTime = mtime
  5818. // s.PatientId = patient_id
  5819. // s.HisPatientId = his_patient_id
  5820. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  5821. // if errcode > 0 {
  5822. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5823. // return
  5824. // }
  5825. //
  5826. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  5827. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  5828. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  5829. // if s.Price == 0 {
  5830. // s.Price = lastWarehouse.RetailPrice
  5831. // }
  5832. // }
  5833. //
  5834. // service.CreateHisDoctorAdvice(&s)
  5835. // //记录日志
  5836. // byterequest, _ := json.Marshal(s)
  5837. // adviceLog := models.XtDoctorAdviceLog{
  5838. // UserOrgId: s.UserOrgId,
  5839. // PatientId: s.PatientId,
  5840. // AdminUserId: adminInfo.AdminUser.Id,
  5841. // Module: 1,
  5842. // ErrLog: string(byterequest),
  5843. // Status: 1,
  5844. // Ctime: time.Now().Unix(),
  5845. // Mtime: 0,
  5846. // Source: "电脑端his医嘱修改",
  5847. // RecordDate: s.AdviceDate,
  5848. // }
  5849. // service.CreateDoctorAdviceLog(adviceLog)
  5850. // redis := service.RedisClient()
  5851. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  5852. // redis.Set(key, "", time.Second)
  5853. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  5854. // fmt.Println("keyOne", keyOne)
  5855. // redis.Set(keyOne, "", time.Second)
  5856. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  5857. // redis.Set(keySeven, "", time.Second)
  5858. // redis.Close()
  5859. //
  5860. // }
  5861. // }
  5862. // }
  5863. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5864. // projects := items["project"].([]interface{})
  5865. // if len(projects) > 0 {
  5866. // for _, project := range projects {
  5867. // var p models.HisPrescriptionProject
  5868. // p.PrescriptionId = prescription.ID
  5869. // p.Ctime = time.Now().Unix()
  5870. // p.Mtime = time.Now().Unix()
  5871. // p.PatientId = patient_id
  5872. // p.RecordDate = recordDateTime
  5873. // p.UserOrgId = adminInfo.CurrentOrgId
  5874. // p.HisPatientId = his_patient_id
  5875. // p.Status = 1
  5876. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  5877. // if errcode > 0 {
  5878. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5879. // return
  5880. // }
  5881. // service.CreateHisProjectTwo(&p)
  5882. //
  5883. // //记录日志
  5884. // byterequest, _ := json.Marshal(p)
  5885. // adviceLog := models.XtDoctorAdviceLog{
  5886. // UserOrgId: p.UserOrgId,
  5887. // PatientId: p.PatientId,
  5888. // AdminUserId: adminInfo.AdminUser.Id,
  5889. // Module: 1,
  5890. // ErrLog: string(byterequest),
  5891. // Status: 1,
  5892. // Ctime: time.Now().Unix(),
  5893. // Mtime: 0,
  5894. // Source: "电脑端his项目修改",
  5895. // RecordDate: p.RecordDate,
  5896. // }
  5897. // service.CreateDoctorAdviceLog(adviceLog)
  5898. // }
  5899. // }
  5900. // }
  5901. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  5902. // addition := items["addition"].([]interface{})
  5903. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5904. // ctime := time.Now().Unix()
  5905. // mtime := ctime
  5906. // if len(addition) > 0 {
  5907. // for _, item := range addition {
  5908. // var s models.HisAdditionalCharge
  5909. // s.PrescriptionId = prescription.ID
  5910. // s.Status = 1
  5911. // s.UserOrgId = adminInfo.CurrentOrgId
  5912. // s.RecordDate = recordDateTime
  5913. // s.CreatedTime = ctime
  5914. // s.UpdatedTime = mtime
  5915. // s.PatientId = patient_id
  5916. // s.HisPatientId = his_patient_id
  5917. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5918. // if errcode > 0 {
  5919. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5920. // return
  5921. // }
  5922. // service.CreateAdditionalCharge(&s)
  5923. // }
  5924. // }
  5925. // }
  5926. //
  5927. // }
  5928. // }
  5929. // }
  5930. // if err == nil {
  5931. // c.ServeSuccessJSON(map[string]interface{}{
  5932. // "msg": "保存成功",
  5933. // })
  5934. // return
  5935. //
  5936. // } else {
  5937. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5938. // return
  5939. // }
  5940. //}
  5941. func (c *HisApiController) DeletePrescription() {
  5942. prescription_id, _ := c.GetInt64("id")
  5943. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5944. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5945. ////同步到自备药
  5946. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5947. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5948. if selfPrescriptionOpen.IsOpen == 1 {
  5949. // 在函数结束时处理事务回滚
  5950. db := service.XTWriteDB()
  5951. tx := db.Begin()
  5952. defer func() {
  5953. if r := recover(); r != nil {
  5954. tx.Rollback()
  5955. } else {
  5956. tx.Commit()
  5957. }
  5958. }()
  5959. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5960. for _, item := range advicesList {
  5961. timeStr := time.Now().Format("2006-01-02")
  5962. timeArr := strings.Split(timeStr, "-")
  5963. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5964. total = total + 1
  5965. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5966. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5967. number = number + total
  5968. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5969. operation_time := time.Now().Unix()
  5970. creater := c.GetAdminUserInfo().AdminUser.Id
  5971. //创建一个出库单
  5972. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5973. WarehouseOutOrderNumber: warehousing_out_order,
  5974. OperationTime: operation_time,
  5975. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5976. Creater: creater,
  5977. Ctime: time.Now().Unix(),
  5978. Status: 1,
  5979. WarehouseOutTime: item.AdviceDate,
  5980. Type: 0,
  5981. PatientId: item.PatientId,
  5982. IsCheck: 1,
  5983. }
  5984. //查询今日是否有出库数据
  5985. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5986. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5987. if lastWarehouseOut.ID == 0 {
  5988. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5989. }
  5990. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5991. var total_count int64
  5992. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5993. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5994. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5995. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5996. }
  5997. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5998. total_count += prescribingNumberSeven
  5999. }
  6000. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6001. total_count += prescribingNumberSeven
  6002. }
  6003. //出库
  6004. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6005. WarehouseOutOrderNumber: warehousing_out_order,
  6006. WarehouseOutId: lastWarehouseOut.ID,
  6007. DrugId: item.DrugId,
  6008. Count: total_count,
  6009. Price: 0,
  6010. TotalPrice: 0,
  6011. Status: 1,
  6012. Ctime: item.AdviceDate,
  6013. Mtime: item.AdviceDate,
  6014. Remark: "",
  6015. OrgId: item.UserOrgId,
  6016. Type: 0,
  6017. Manufacturer: selfBasedrug.Manufacturer,
  6018. Dealer: selfBasedrug.Dealer,
  6019. RetailPrice: 0,
  6020. RetailTotalPrice: 0,
  6021. CountUnit: selfBasedrug.MinUnit,
  6022. ExpiryDate: 0,
  6023. ProductDate: 0,
  6024. Number: "",
  6025. BatchNumber: "",
  6026. IsSys: 1,
  6027. WarehouseInfoId: 0,
  6028. AdminUserId: 0,
  6029. StockCount: "",
  6030. IsCheck: 1,
  6031. SysRecordTime: item.AdviceDate,
  6032. PatientId: item.PatientId,
  6033. ClassType: "",
  6034. AdviceId: item.ID,
  6035. }
  6036. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6037. }
  6038. fmt.Println("长度-------------------------------", warehousingOutInfo)
  6039. for _, it := range warehousingOutInfo {
  6040. //查询今日是否有出库数据
  6041. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  6042. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6043. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6044. //出库逻辑
  6045. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  6046. //查询剩余库存
  6047. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6048. var sum_count int64
  6049. for _, its := range stockInfo {
  6050. if its.MaxUnit == medical.MaxUnit {
  6051. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6052. }
  6053. sum_count += its.StockMaxNumber + its.StockMinNumber
  6054. }
  6055. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6056. }
  6057. }
  6058. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6059. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6060. //耗材保存处方出库
  6061. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6062. //已收费和已发药限制逻辑
  6063. isCharge := false
  6064. isMedicine := false
  6065. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6066. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6067. if new_prescription.IsMedicine == 1 {
  6068. isMedicine = true
  6069. }
  6070. for _, item := range new_prescriptions {
  6071. if item.OrderStatus == 4 {
  6072. isCharge = true
  6073. }
  6074. }
  6075. if p_err != nil {
  6076. if new_prescription.ID > 0 {
  6077. if new_prescription.OrderStatus == 2 {
  6078. isCharge = true
  6079. }
  6080. }
  6081. }
  6082. for _, item := range advices {
  6083. if item.IsMedicine == 1 {
  6084. isMedicine = true
  6085. }
  6086. }
  6087. if isCharge {
  6088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6089. return
  6090. }
  6091. if isMedicine {
  6092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6093. return
  6094. }
  6095. //已收费和已发药限制逻辑
  6096. if len(projects) > 0 {
  6097. for _, item := range projects {
  6098. service.DeletePrintInfo(item.ID) //删除打印信息
  6099. if goodOutConfig.IsOpen != 1 {
  6100. if stockConfig.IsOpen == 1 {
  6101. if item.Type == 3 && item.IsOut == 1 {
  6102. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6103. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6104. good.Total = good.Total + f_count
  6105. service.UpdateGoodInfo(&good)
  6106. operation_time := time.Now().Unix()
  6107. creater := c.GetAdminUserInfo().AdminUser.Id
  6108. //创建退库单
  6109. timeStr := time.Now().Format("2006-01-02")
  6110. timeArr := strings.Split(timeStr, "-")
  6111. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6112. total = total + 1
  6113. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6114. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6115. cancelStock := models.CancelStock{
  6116. OrderNumber: orderNumber,
  6117. OperaTime: operation_time,
  6118. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6119. Creater: creater,
  6120. Ctime: time.Now().Unix(),
  6121. Status: 1,
  6122. ReturnTime: item.RecordDate,
  6123. Type: 1,
  6124. StorehouseId: houseConfig.StorehouseOutInfo,
  6125. IsCheck: 1,
  6126. }
  6127. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6128. if msgerrkonde == gorm.ErrRecordNotFound {
  6129. service.AddSigleCancelStock(&cancelStock)
  6130. }
  6131. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6132. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6133. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6134. //查询该耗材是否出库
  6135. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6136. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6137. deaerler, _ := service.GetDealerById(info.Dealer)
  6138. var total_count int64
  6139. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6140. total_count += count
  6141. if info.ID > 0 {
  6142. if info.Count >= total_count {
  6143. //回退库存
  6144. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6145. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6146. var flush_count int64
  6147. for _, it := range goodList {
  6148. flush_count += it.StockCount
  6149. }
  6150. cancelStockInfo := models.CancelStockInfo{
  6151. GoodId: item.ProjectId,
  6152. CancelStockId: cancel.ID,
  6153. GoodTypeId: good.GoodTypeId,
  6154. Count: prescribingNumber,
  6155. Price: info.Price,
  6156. Total: 0,
  6157. ProductDate: info.ProductDate,
  6158. ExpiryDate: info.ExpiryDate,
  6159. Ctime: time.Now().Unix(),
  6160. Status: 1,
  6161. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6162. OrderNumber: cancel.OrderNumber,
  6163. Type: 0,
  6164. Dealer: deaerler.DealerName,
  6165. Manufacturer: manufacturer.ManufacturerName,
  6166. Number: info.Number,
  6167. RegisterAccount: "",
  6168. Remark: "",
  6169. WarehouseInfoId: info.WarehouseInfotId,
  6170. PatientId: info.PatientId,
  6171. RecordDate: info.SysRecordTime,
  6172. StorehouseId: houseConfig.StorehouseOutInfo,
  6173. IsCheck: 1,
  6174. }
  6175. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6176. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6177. flow := models.VmStockFlow{
  6178. WarehousingId: info.WarehouseInfotId,
  6179. GoodId: item.ProjectId,
  6180. Number: info.Number,
  6181. LicenseNumber: info.LicenseNumber,
  6182. Count: prescribingNumber,
  6183. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6184. PatientId: item.PatientId,
  6185. SystemTime: info.SysRecordTime,
  6186. ConsumableType: 7,
  6187. IsSys: 0,
  6188. WarehousingOrder: "",
  6189. WarehouseOutId: info.WarehouseOutId,
  6190. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6191. IsEdit: 0,
  6192. CancelStockId: cancel.ID,
  6193. CancelOrderNumber: cancel.OrderNumber,
  6194. Manufacturer: manufacturer.ID,
  6195. Dealer: 0,
  6196. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6197. UpdateCreator: 0,
  6198. Status: 1,
  6199. Ctime: time.Now().Unix(),
  6200. Mtime: 0,
  6201. Price: info.Price,
  6202. WarehousingDetailId: info.WarehouseInfotId,
  6203. WarehouseOutDetailId: info.ID,
  6204. CancelOutDetailId: cancelInfo.ID,
  6205. ProductDate: info.ProductDate,
  6206. ExpireDate: info.ExpiryDate,
  6207. StorehouseId: houseConfig.StorehouseOutInfo,
  6208. OverCount: flush_count,
  6209. OperateTime: time.Now().Unix(),
  6210. }
  6211. service.CreateStockFlowOne(flow)
  6212. //退库数量增加
  6213. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6214. //出库数量减少
  6215. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6216. }
  6217. if info.Count < total_count {
  6218. //回退库存
  6219. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  6220. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6221. var flush_count int64
  6222. for _, it := range goodList {
  6223. flush_count += it.StockCount
  6224. }
  6225. cancelStockInfo := models.CancelStockInfo{
  6226. GoodId: item.ProjectId,
  6227. CancelStockId: cancel.ID,
  6228. GoodTypeId: good.GoodTypeId,
  6229. Count: info.Count,
  6230. Price: info.Price,
  6231. Total: 0,
  6232. ProductDate: info.ProductDate,
  6233. ExpiryDate: info.ExpiryDate,
  6234. Ctime: time.Now().Unix(),
  6235. Status: 1,
  6236. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6237. OrderNumber: cancel.OrderNumber,
  6238. Type: 0,
  6239. Dealer: deaerler.DealerName,
  6240. Manufacturer: manufacturer.ManufacturerName,
  6241. Number: info.Number,
  6242. RegisterAccount: "",
  6243. Remark: "",
  6244. WarehouseInfoId: info.WarehouseInfotId,
  6245. PatientId: info.PatientId,
  6246. RecordDate: info.SysRecordTime,
  6247. StorehouseId: houseConfig.StorehouseOutInfo,
  6248. IsCheck: 1,
  6249. }
  6250. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6251. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6252. flow := models.VmStockFlow{
  6253. WarehousingId: info.WarehouseInfotId,
  6254. GoodId: item.ProjectId,
  6255. Number: info.Number,
  6256. LicenseNumber: info.LicenseNumber,
  6257. Count: info.Count,
  6258. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6259. PatientId: item.PatientId,
  6260. SystemTime: info.SysRecordTime,
  6261. ConsumableType: 7,
  6262. IsSys: 0,
  6263. WarehousingOrder: "",
  6264. WarehouseOutId: info.WarehouseOutId,
  6265. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6266. IsEdit: 0,
  6267. CancelStockId: cancel.ID,
  6268. CancelOrderNumber: cancel.OrderNumber,
  6269. Manufacturer: manufacturer.ID,
  6270. Dealer: 0,
  6271. Creator: c.GetAdminUserInfo().CurrentOrgId,
  6272. UpdateCreator: 0,
  6273. Status: 1,
  6274. Ctime: time.Now().Unix(),
  6275. Mtime: 0,
  6276. Price: info.Price,
  6277. WarehousingDetailId: info.WarehouseInfotId,
  6278. WarehouseOutDetailId: info.ID,
  6279. CancelOutDetailId: cancelInfo.ID,
  6280. ProductDate: info.ProductDate,
  6281. ExpireDate: info.ExpiryDate,
  6282. StorehouseId: houseConfig.StorehouseOutInfo,
  6283. OverCount: flush_count,
  6284. OperateTime: time.Now().Unix(),
  6285. }
  6286. service.CreateStockFlowOne(flow)
  6287. //退库数量增加
  6288. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6289. //出库数量减少
  6290. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  6291. }
  6292. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6293. var flush_count int64
  6294. for _, it := range goodList {
  6295. flush_count += it.StockCount
  6296. }
  6297. //查询已出库数量
  6298. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6299. if prescribingNumber < dialysisInfo.Count {
  6300. //改变数量
  6301. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6302. }
  6303. if prescribingNumber >= dialysisInfo.Count {
  6304. //删除出库表
  6305. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6306. }
  6307. //更新库存
  6308. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  6309. //更新基础库库存
  6310. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  6311. }
  6312. }
  6313. }
  6314. }
  6315. //保存耗材出库
  6316. if goodOutConfig.IsOpen == 1 {
  6317. if item.Type == 3 {
  6318. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  6319. f_count, _ := strconv.ParseFloat(item.Count, 64)
  6320. good.Total = good.Total + f_count
  6321. service.UpdateGoodInfo(&good)
  6322. operation_time := time.Now().Unix()
  6323. creater := c.GetAdminUserInfo().AdminUser.Id
  6324. //创建退库单
  6325. timeStr := time.Now().Format("2006-01-02")
  6326. timeArr := strings.Split(timeStr, "-")
  6327. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  6328. total = total + 1
  6329. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6330. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6331. cancelStock := models.CancelStock{
  6332. OrderNumber: orderNumber,
  6333. OperaTime: operation_time,
  6334. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6335. Creater: creater,
  6336. Ctime: time.Now().Unix(),
  6337. Status: 1,
  6338. ReturnTime: item.RecordDate,
  6339. Type: 1,
  6340. StorehouseId: houseConfig.StorehouseOutInfo,
  6341. IsCheck: 1,
  6342. }
  6343. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  6344. if msgerrkonde == gorm.ErrRecordNotFound {
  6345. service.AddSigleCancelStock(&cancelStock)
  6346. }
  6347. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  6348. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6349. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6350. //查询该耗材是否出库
  6351. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  6352. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6353. deaerler, _ := service.GetDealerById(info.Dealer)
  6354. var total_count int64
  6355. count, _ := strconv.ParseInt(item.Count, 10, 64)
  6356. total_count += count
  6357. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6358. var flush_count int64
  6359. for _, it := range goodList {
  6360. flush_count += it.StockCount
  6361. }
  6362. fmt.Println("历史出库数据", info.Count)
  6363. fmt.Println("出库数量", total_count)
  6364. if info.ID > 0 {
  6365. cancelStockInfo := models.CancelStockInfo{
  6366. GoodId: item.ProjectId,
  6367. CancelStockId: cancel.ID,
  6368. GoodTypeId: good.GoodTypeId,
  6369. Count: prescribingNumber,
  6370. Price: info.Price,
  6371. Total: 0,
  6372. ProductDate: info.ProductDate,
  6373. ExpiryDate: info.ExpiryDate,
  6374. Ctime: time.Now().Unix(),
  6375. Status: 1,
  6376. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6377. OrderNumber: cancel.OrderNumber,
  6378. Type: 0,
  6379. Dealer: deaerler.DealerName,
  6380. Manufacturer: manufacturer.ManufacturerName,
  6381. Number: info.Number,
  6382. RegisterAccount: "",
  6383. Remark: "",
  6384. WarehouseInfoId: info.WarehouseInfotId,
  6385. PatientId: info.PatientId,
  6386. RecordDate: info.SysRecordTime,
  6387. StorehouseId: houseConfig.StorehouseOutInfo,
  6388. IsCheck: 1,
  6389. }
  6390. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6391. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  6392. //查询出库数量
  6393. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  6394. //出库数据 大于 退库数量
  6395. if len(list) > 0 {
  6396. for _, it := range list {
  6397. //回退库存
  6398. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6399. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6400. var flush_count_one int64
  6401. for _, it := range goodList {
  6402. flush_count_one += it.StockCount
  6403. }
  6404. //查询该批次是否有退库数据
  6405. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  6406. creater := c.GetAdminUserInfo().AdminUser.Id
  6407. flow := models.VmStockFlow{
  6408. WarehousingId: it.WarehouseInfotId,
  6409. GoodId: it.GoodId,
  6410. Number: it.Number,
  6411. LicenseNumber: it.LicenseNumber,
  6412. Count: it.Count,
  6413. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6414. PatientId: it.PatientId,
  6415. SystemTime: it.SysRecordTime,
  6416. ConsumableType: 7,
  6417. IsSys: 0,
  6418. WarehousingOrder: "",
  6419. WarehouseOutId: it.WarehouseOutId,
  6420. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6421. IsEdit: 0,
  6422. CancelStockId: cancel.ID,
  6423. CancelOrderNumber: cancel.OrderNumber,
  6424. Manufacturer: manufacturer.ID,
  6425. Dealer: 0,
  6426. Creator: creater,
  6427. UpdateCreator: 0,
  6428. Status: 1,
  6429. Ctime: time.Now().Unix(),
  6430. Mtime: 0,
  6431. Price: it.Price,
  6432. WarehousingDetailId: it.WarehouseInfotId,
  6433. WarehouseOutDetailId: it.ID,
  6434. CancelOutDetailId: cancelInfo.ID,
  6435. ProductDate: it.ProductDate,
  6436. ExpireDate: it.ExpiryDate,
  6437. StorehouseId: houseConfig.StorehouseOutInfo,
  6438. OverCount: flush_count_one,
  6439. OperateTime: time.Now().Unix(),
  6440. }
  6441. service.CreateStockFlowOne(flow)
  6442. //if flow.ID > 0 {
  6443. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  6444. //}
  6445. }
  6446. }
  6447. //flow := models.VmStockFlow{
  6448. // WarehousingId: info.WarehouseInfotId,
  6449. // GoodId: item.ProjectId,
  6450. // Number: info.Number,
  6451. // LicenseNumber: info.LicenseNumber,
  6452. // Count: prescribingNumber,
  6453. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6454. // PatientId: item.PatientId,
  6455. // SystemTime: info.SysRecordTime,
  6456. // ConsumableType: 7,
  6457. // IsSys: 0,
  6458. // WarehousingOrder: "",
  6459. // WarehouseOutId: info.WarehouseOutId,
  6460. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6461. // IsEdit: 0,
  6462. // CancelStockId: cancel.ID,
  6463. // CancelOrderNumber: cancel.OrderNumber,
  6464. // Manufacturer: manufacturer.ID,
  6465. // Dealer: 0,
  6466. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  6467. // UpdateCreator: 0,
  6468. // Status: 1,
  6469. // Ctime: time.Now().Unix(),
  6470. // Mtime: 0,
  6471. // Price: info.Price,
  6472. // WarehousingDetailId: info.WarehouseInfotId,
  6473. // WarehouseOutDetailId: info.ID,
  6474. // CancelOutDetailId: cancelInfo.ID,
  6475. // ProductDate: info.ProductDate,
  6476. // ExpireDate: info.ExpiryDate,
  6477. // StorehouseId: houseConfig.StorehouseOutInfo,
  6478. // OverCount: flush_count,
  6479. //}
  6480. //service.CreateStockFlowOne(flow)
  6481. //退库数量增加
  6482. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  6483. //出库数量减少
  6484. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  6485. //查询已出库数量
  6486. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  6487. if prescribingNumber < dialysisInfo.Count {
  6488. //改变数量
  6489. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  6490. }
  6491. if prescribingNumber >= dialysisInfo.Count {
  6492. //删除出库表
  6493. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  6494. }
  6495. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  6496. var flush_count_one int64
  6497. for _, it := range goodList {
  6498. flush_count_one += it.StockCount
  6499. }
  6500. //更新库存
  6501. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  6502. fmt.Println("msgerrkonde23332323", msgerrkonde)
  6503. //更新基础库库存
  6504. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  6505. }
  6506. }
  6507. }
  6508. }
  6509. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6510. fmt.Println(err)
  6511. }
  6512. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  6513. fmt.Println(err)
  6514. if len(advices) > 0 {
  6515. for _, item := range advices {
  6516. redis := service.RedisClient()
  6517. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6518. redis.Set(keyFive, "", time.Second)
  6519. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6520. redis.Set(keyOne, "", time.Second)
  6521. redis.Close()
  6522. }
  6523. }
  6524. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6525. if len(advices) > 0 {
  6526. for _, item := range advices {
  6527. creater := c.GetAdminUserInfo().AdminUser.Id
  6528. service.DrugAutoAddCancelInfo(item, creater)
  6529. }
  6530. }
  6531. } else {
  6532. if drugOutConfig.IsOpen == 1 {
  6533. if len(advices) > 0 {
  6534. for _, item := range advices {
  6535. creater := c.GetAdminUserInfo().AdminUser.Id
  6536. service.DrugAutoAddCancelInfo(item, creater)
  6537. }
  6538. }
  6539. } else {
  6540. if len(advices) > 0 {
  6541. for _, item := range advices {
  6542. creater := c.GetAdminUserInfo().AdminUser.Id
  6543. service.DrugAutoAddCancelInfo(item, creater)
  6544. }
  6545. }
  6546. }
  6547. }
  6548. c.ServeSuccessJSON(map[string]interface{}{
  6549. "msg": "删除成功",
  6550. })
  6551. return
  6552. }
  6553. func (c *HisApiController) DeleteDoctorAdvice() {
  6554. id, _ := c.GetInt64("id")
  6555. advice, _ := service.GetHisDoctorAdvicesById(id)
  6556. ////同步到自备药
  6557. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  6558. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  6559. if selfPrescriptionOpen.IsOpen == 1 {
  6560. db := service.XTWriteDB()
  6561. tx := db.Begin()
  6562. defer func() {
  6563. if r := recover(); r != nil {
  6564. tx.Rollback()
  6565. } else {
  6566. tx.Commit()
  6567. }
  6568. }()
  6569. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  6570. var total_count int64
  6571. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6572. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  6573. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6574. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  6575. }
  6576. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  6577. total_count += prescribingNumberSeven
  6578. }
  6579. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  6580. total_count += prescribingNumberSeven
  6581. }
  6582. timeStr := time.Now().Format("2006-01-02")
  6583. timeArr := strings.Split(timeStr, "-")
  6584. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  6585. total = total + 1
  6586. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6587. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6588. number = number + total
  6589. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  6590. operation_time := time.Now().Unix()
  6591. creater := c.GetAdminUserInfo().AdminUser.Id
  6592. //创建一个出库单
  6593. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  6594. WarehouseOutOrderNumber: warehousing_out_order,
  6595. OperationTime: operation_time,
  6596. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  6597. Creater: creater,
  6598. Ctime: time.Now().Unix(),
  6599. Status: 1,
  6600. WarehouseOutTime: advice.AdviceDate,
  6601. Type: 0,
  6602. PatientId: advice.PatientId,
  6603. IsCheck: 1,
  6604. }
  6605. //查询今日是否有出库数据
  6606. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  6607. if lastWarehouseOut.ID == 0 {
  6608. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  6609. }
  6610. //出库
  6611. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  6612. WarehouseOutId: lastWarehouseOut.ID,
  6613. WarehouseOutOrderNumber: warehousing_out_order,
  6614. DrugId: advice.DrugId,
  6615. Count: total_count,
  6616. Price: 0,
  6617. TotalPrice: 0,
  6618. Status: 1,
  6619. Ctime: advice.AdviceDate,
  6620. Mtime: advice.AdviceDate,
  6621. Remark: "",
  6622. OrgId: advice.UserOrgId,
  6623. Type: 0,
  6624. Manufacturer: selfBasedrug.Manufacturer,
  6625. Dealer: selfBasedrug.Dealer,
  6626. RetailPrice: 0,
  6627. RetailTotalPrice: 0,
  6628. CountUnit: advice.PrescribingNumberUnit,
  6629. ExpiryDate: 0,
  6630. ProductDate: 0,
  6631. Number: "",
  6632. BatchNumber: "",
  6633. IsSys: 0,
  6634. WarehouseInfoId: 0,
  6635. AdminUserId: 0,
  6636. StockCount: "",
  6637. IsCheck: 1,
  6638. SysRecordTime: advice.AdviceDate,
  6639. PatientId: advice.PatientId,
  6640. AdviceId: advice.ID,
  6641. ClassType: "",
  6642. }
  6643. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  6644. for _, it := range warehousingOutInfo {
  6645. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  6646. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  6647. //出库逻辑
  6648. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  6649. //查询剩余库存
  6650. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  6651. var sum_count int64
  6652. for _, its := range stockInfo {
  6653. if its.MaxUnit == medical.MaxUnit {
  6654. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6655. }
  6656. sum_count += its.StockMaxNumber + its.StockMinNumber
  6657. }
  6658. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  6659. }
  6660. }
  6661. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6662. //已收费和已发药的限制逻辑
  6663. isCharge := false
  6664. isMedicine := false
  6665. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6666. //获取今天该患者所有处方,判断是否发药或者收费
  6667. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6668. //for _, item := range new_prescriptions {
  6669. if new_prescription.IsMedicine == 1 {
  6670. isMedicine = true
  6671. }
  6672. //}
  6673. for _, item := range new_prescriptions {
  6674. if item.OrderStatus == 4 {
  6675. isCharge = true
  6676. }
  6677. }
  6678. if isMedicine {
  6679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6680. return
  6681. }
  6682. if isCharge {
  6683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6684. return
  6685. }
  6686. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  6687. for _, item := range advices {
  6688. if item.IsMedicine == 1 {
  6689. isMedicine = true
  6690. }
  6691. }
  6692. if isMedicine {
  6693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  6694. return
  6695. }
  6696. if new_prescription.ID > 0 {
  6697. if new_prescription.OrderStatus == 2 {
  6698. isCharge = true
  6699. }
  6700. }
  6701. if isCharge {
  6702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6703. return
  6704. }
  6705. //已收费和已发药的限制逻辑
  6706. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  6707. redis := service.RedisClient()
  6708. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6709. redis.Set(keyFive, "", time.Second)
  6710. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6711. redis.Set(keyOne, "", time.Second)
  6712. defer redis.Close()
  6713. if err == nil {
  6714. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  6715. //查询是否在处方中出库
  6716. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6717. if openConfig.IsOpen != 1 {
  6718. //判断该医嘱是否执行了
  6719. if advice.ExecutionState == 1 {
  6720. creater := c.GetAdminUserInfo().AdminUser.Id
  6721. service.DrugAutoAddCancelInfo(&advice, creater)
  6722. }
  6723. }
  6724. //开启保存处方扣减功能
  6725. if openConfig.IsOpen == 1 {
  6726. creater := c.GetAdminUserInfo().AdminUser.Id
  6727. service.DrugAutoAddCancelInfo(&advice, creater)
  6728. }
  6729. } else {
  6730. if drugOutConfig.IsOpen == 1 {
  6731. //查询是否在处方中出库
  6732. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  6733. if openConfig.IsOpen != 1 {
  6734. //判断该医嘱是否执行了
  6735. if advice.ExecutionState == 1 {
  6736. creater := c.GetAdminUserInfo().AdminUser.Id
  6737. service.DrugAutoAddCancelInfo(&advice, creater)
  6738. }
  6739. }
  6740. //开启保存处方扣减功能
  6741. if openConfig.IsOpen == 1 {
  6742. creater := c.GetAdminUserInfo().AdminUser.Id
  6743. service.DrugAutoAddCancelInfo(&advice, creater)
  6744. }
  6745. } else {
  6746. //判断该医嘱是否执行了
  6747. if advice.ExecutionState == 1 {
  6748. creater := c.GetAdminUserInfo().AdminUser.Id
  6749. service.DrugAutoAddCancelInfo(&advice, creater)
  6750. }
  6751. }
  6752. }
  6753. c.ServeSuccessJSON(map[string]interface{}{
  6754. "msg": "删除成功",
  6755. })
  6756. return
  6757. } else {
  6758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6759. return
  6760. }
  6761. }
  6762. func (c *HisApiController) DeleteProject() {
  6763. id, _ := c.GetInt64("id")
  6764. adminInfo := c.GetAdminUserInfo()
  6765. project, _ := service.GetHisProjectByID(id)
  6766. // var consumable models.DialysisBeforePrepare
  6767. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  6768. //耗材保存处方出库
  6769. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  6770. isCharge := false
  6771. isMedicine := false
  6772. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  6773. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  6774. for _, item := range new_prescriptions {
  6775. if item.IsMedicine == 1 {
  6776. isMedicine = true
  6777. }
  6778. }
  6779. for _, item := range new_prescriptions {
  6780. if item.OrderStatus == 4 {
  6781. isCharge = true
  6782. }
  6783. }
  6784. if isMedicine {
  6785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  6786. return
  6787. }
  6788. if isCharge {
  6789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  6790. return
  6791. }
  6792. if new_prescription.ID > 0 {
  6793. if new_prescription.OrderStatus == 2 {
  6794. isCharge = true
  6795. }
  6796. }
  6797. if isCharge {
  6798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  6799. return
  6800. }
  6801. service.DeletePrintInfo(id)
  6802. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  6803. label.Status = 0
  6804. service.CreateHisLabelRecordTwo(&label)
  6805. fmt.Println(goodOutConfig.IsOpen)
  6806. if goodOutConfig.IsOpen != 1 {
  6807. if stockConfig.IsOpen == 1 {
  6808. if project.Type == 2 {
  6809. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6810. fmt.Println(err)
  6811. }
  6812. if project.Type == 3 && project.IsOut == 1 {
  6813. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6814. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6815. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6816. operation_time := time.Now().Unix()
  6817. creater := adminInfo.AdminUser.Id
  6818. //创建退库单
  6819. timeStr := time.Now().Format("2006-01-02")
  6820. timeArr := strings.Split(timeStr, "-")
  6821. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6822. total = total + 1
  6823. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6824. cancelStock := models.CancelStock{
  6825. OrderNumber: orderNumber,
  6826. OperaTime: operation_time,
  6827. OrgId: adminInfo.CurrentOrgId,
  6828. Creater: creater,
  6829. Ctime: time.Now().Unix(),
  6830. Status: 1,
  6831. ReturnTime: project.RecordDate,
  6832. Type: 1,
  6833. StorehouseId: houseConfig.StorehouseOutInfo,
  6834. IsCheck: 1,
  6835. }
  6836. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6837. if msgerrkonde == gorm.ErrRecordNotFound {
  6838. service.AddSigleCancelStock(&cancelStock)
  6839. }
  6840. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6841. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6842. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6843. //查询是否有出库
  6844. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6845. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6846. deaerler, _ := service.GetDealerById(info.Dealer)
  6847. if info.ID > 0 {
  6848. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6849. if info.Count >= prescribingNumber {
  6850. cancelStockInfo := models.CancelStockInfo{
  6851. GoodId: project.ProjectId,
  6852. CancelStockId: cancel.ID,
  6853. GoodTypeId: good.GoodTypeId,
  6854. Count: prescribingNumber,
  6855. Price: info.Price,
  6856. Total: 0,
  6857. ProductDate: info.ProductDate,
  6858. ExpiryDate: info.ExpiryDate,
  6859. Ctime: time.Now().Unix(),
  6860. Status: 1,
  6861. OrgId: adminInfo.CurrentOrgId,
  6862. OrderNumber: cancel.OrderNumber,
  6863. Type: 0,
  6864. Dealer: deaerler.DealerName,
  6865. Manufacturer: manufacturer.ManufacturerName,
  6866. Number: info.Number,
  6867. RegisterAccount: "",
  6868. Remark: "",
  6869. WarehouseInfoId: info.WarehouseInfotId,
  6870. PatientId: info.PatientId,
  6871. RecordDate: info.SysRecordTime,
  6872. StorehouseId: houseConfig.StorehouseOutInfo,
  6873. IsCheck: 1,
  6874. }
  6875. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6876. //回退库存
  6877. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  6878. //退库数量增加
  6879. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6880. //出库数量减少
  6881. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6882. }
  6883. if info.Count < prescribingNumber {
  6884. cancelStockInfo := models.CancelStockInfo{
  6885. GoodId: project.ProjectId,
  6886. CancelStockId: cancel.ID,
  6887. GoodTypeId: good.GoodTypeId,
  6888. Count: info.Count,
  6889. Price: info.Price,
  6890. Total: 0,
  6891. ProductDate: info.ProductDate,
  6892. ExpiryDate: info.ExpiryDate,
  6893. Ctime: time.Now().Unix(),
  6894. Status: 1,
  6895. OrgId: adminInfo.CurrentOrgId,
  6896. OrderNumber: cancel.OrderNumber,
  6897. Type: 0,
  6898. Dealer: deaerler.DealerName,
  6899. Manufacturer: manufacturer.ManufacturerName,
  6900. Number: info.Number,
  6901. RegisterAccount: "",
  6902. Remark: "",
  6903. WarehouseInfoId: info.WarehouseInfotId,
  6904. PatientId: info.PatientId,
  6905. RecordDate: info.SysRecordTime,
  6906. StorehouseId: houseConfig.StorehouseOutInfo,
  6907. IsCheck: 1,
  6908. }
  6909. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6910. //回退库存
  6911. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6912. //退库数量增加
  6913. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6914. //出库数量减少
  6915. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6916. }
  6917. //查询剩余库存
  6918. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6919. var over_count int64
  6920. for _, it := range goodList {
  6921. over_count += it.StockCount
  6922. }
  6923. //出库数据 大于 退库数量
  6924. if info.Count >= prescribingNumber {
  6925. flow := models.VmStockFlow{
  6926. WarehousingId: info.WarehouseInfotId,
  6927. GoodId: project.ProjectId,
  6928. Number: info.Number,
  6929. LicenseNumber: info.LicenseNumber,
  6930. Count: prescribingNumber,
  6931. UserOrgId: adminInfo.CurrentOrgId,
  6932. PatientId: project.PatientId,
  6933. SystemTime: info.SysRecordTime,
  6934. ConsumableType: 7,
  6935. IsSys: 0,
  6936. WarehousingOrder: "",
  6937. WarehouseOutId: info.WarehouseOutId,
  6938. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6939. IsEdit: 0,
  6940. CancelStockId: cancel.ID,
  6941. CancelOrderNumber: cancel.OrderNumber,
  6942. Manufacturer: manufacturer.ID,
  6943. Dealer: 0,
  6944. Creator: adminInfo.AdminUser.Id,
  6945. UpdateCreator: 0,
  6946. Status: 1,
  6947. Ctime: time.Now().Unix(),
  6948. Mtime: 0,
  6949. Price: info.Price,
  6950. WarehousingDetailId: info.WarehouseInfotId,
  6951. WarehouseOutDetailId: info.ID,
  6952. CancelOutDetailId: cancelInfo.ID,
  6953. ProductDate: info.ProductDate,
  6954. ExpireDate: info.ExpiryDate,
  6955. StorehouseId: houseConfig.StorehouseOutInfo,
  6956. OverCount: over_count,
  6957. OperateTime: time.Now().Unix(),
  6958. }
  6959. service.CreateStockFlowOne(flow)
  6960. }
  6961. //出库数据小于退库数据
  6962. if info.Count < prescribingNumber {
  6963. flow := models.VmStockFlow{
  6964. WarehousingId: info.WarehouseInfotId,
  6965. GoodId: project.ProjectId,
  6966. Number: info.Number,
  6967. LicenseNumber: info.LicenseNumber,
  6968. Count: info.Count,
  6969. UserOrgId: adminInfo.CurrentOrgId,
  6970. PatientId: project.PatientId,
  6971. SystemTime: info.SysRecordTime,
  6972. ConsumableType: 7,
  6973. IsSys: 0,
  6974. WarehousingOrder: "",
  6975. WarehouseOutId: info.WarehouseOutId,
  6976. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6977. IsEdit: 0,
  6978. CancelStockId: cancel.ID,
  6979. CancelOrderNumber: cancel.OrderNumber,
  6980. Manufacturer: manufacturer.ID,
  6981. Dealer: 0,
  6982. Creator: adminInfo.AdminUser.Id,
  6983. UpdateCreator: 0,
  6984. Status: 1,
  6985. Ctime: time.Now().Unix(),
  6986. Mtime: 0,
  6987. Price: info.Price,
  6988. WarehousingDetailId: info.WarehouseInfotId,
  6989. WarehouseOutDetailId: info.ID,
  6990. CancelOutDetailId: cancelInfo.ID,
  6991. ProductDate: info.ProductDate,
  6992. ExpireDate: info.ExpiryDate,
  6993. StorehouseId: houseConfig.StorehouseOutInfo,
  6994. OverCount: over_count,
  6995. OperateTime: time.Now().Unix(),
  6996. }
  6997. service.CreateStockFlowOne(flow)
  6998. }
  6999. //查询已出库数量
  7000. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7001. if prescribingNumber < dialysisInfo.Count {
  7002. //改变数量
  7003. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7004. }
  7005. if prescribingNumber >= dialysisInfo.Count {
  7006. //删除出库表
  7007. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7008. }
  7009. //更新剩余库存
  7010. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7011. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7012. var total_count_one int64
  7013. for _, it := range stockList {
  7014. total_count_one += it.StockCount
  7015. }
  7016. //基础库插入数据
  7017. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7018. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7019. var flush_count int64
  7020. for _, it := range goodListOne {
  7021. flush_count += it.StockCount
  7022. }
  7023. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7024. if errs != nil {
  7025. goodErrcode := models.XtGoodErrcode{
  7026. UserOrgId: project.UserOrgId,
  7027. Errcode: "手动出库更新剩余出库失败",
  7028. GoodId: project.ProjectId,
  7029. Status: 1,
  7030. Ctime: time.Now().Unix(),
  7031. Mtime: 0,
  7032. Count: 0,
  7033. StockCount: 0,
  7034. Creater: creater,
  7035. BatchNumberId: 0,
  7036. WarehouseOutId: 0,
  7037. }
  7038. service.CreateGoodErrcode(goodErrcode)
  7039. }
  7040. }
  7041. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7042. fmt.Println(err)
  7043. } else {
  7044. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7045. fmt.Println(err)
  7046. }
  7047. } else {
  7048. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7049. fmt.Println(err)
  7050. }
  7051. }
  7052. //保存处方出库
  7053. if goodOutConfig.IsOpen == 1 {
  7054. if project.Type == 3 {
  7055. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  7056. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7057. f_count, _ := strconv.ParseFloat(project.Count, 64)
  7058. operation_time := time.Now().Unix()
  7059. creater := adminInfo.AdminUser.Id
  7060. //创建退库单
  7061. timeStr := time.Now().Format("2006-01-02")
  7062. timeArr := strings.Split(timeStr, "-")
  7063. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  7064. total = total + 1
  7065. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7066. cancelStock := models.CancelStock{
  7067. OrderNumber: orderNumber,
  7068. OperaTime: operation_time,
  7069. OrgId: adminInfo.CurrentOrgId,
  7070. Creater: creater,
  7071. Ctime: time.Now().Unix(),
  7072. Status: 1,
  7073. ReturnTime: project.RecordDate,
  7074. Type: 1,
  7075. StorehouseId: houseConfig.StorehouseOutInfo,
  7076. IsCheck: 1,
  7077. }
  7078. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  7079. if msgerrkonde == gorm.ErrRecordNotFound {
  7080. service.AddSigleCancelStock(&cancelStock)
  7081. }
  7082. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  7083. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  7084. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7085. //获取出库数据
  7086. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  7087. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7088. deaerler, _ := service.GetDealerById(info.Dealer)
  7089. if info.ID > 0 {
  7090. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  7091. if info.Count >= prescribingNumber {
  7092. cancelStockInfo := models.CancelStockInfo{
  7093. GoodId: project.ProjectId,
  7094. CancelStockId: cancel.ID,
  7095. GoodTypeId: good.GoodTypeId,
  7096. Count: prescribingNumber,
  7097. Price: info.Price,
  7098. Total: 0,
  7099. ProductDate: info.ProductDate,
  7100. ExpiryDate: info.ExpiryDate,
  7101. Ctime: time.Now().Unix(),
  7102. Status: 1,
  7103. OrgId: adminInfo.CurrentOrgId,
  7104. OrderNumber: cancel.OrderNumber,
  7105. Type: 0,
  7106. Dealer: deaerler.DealerName,
  7107. Manufacturer: manufacturer.ManufacturerName,
  7108. Number: info.Number,
  7109. RegisterAccount: "",
  7110. Remark: "",
  7111. WarehouseInfoId: info.WarehouseInfotId,
  7112. PatientId: info.PatientId,
  7113. RecordDate: info.SysRecordTime,
  7114. StorehouseId: houseConfig.StorehouseOutInfo,
  7115. IsCheck: 1,
  7116. }
  7117. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7118. //退库数量增加
  7119. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  7120. //出库数量减少
  7121. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  7122. }
  7123. if info.Count < prescribingNumber {
  7124. cancelStockInfo := models.CancelStockInfo{
  7125. GoodId: project.ProjectId,
  7126. CancelStockId: cancel.ID,
  7127. GoodTypeId: good.GoodTypeId,
  7128. Count: prescribingNumber,
  7129. Price: info.Price,
  7130. Total: 0,
  7131. ProductDate: info.ProductDate,
  7132. ExpiryDate: info.ExpiryDate,
  7133. Ctime: time.Now().Unix(),
  7134. Status: 1,
  7135. OrgId: adminInfo.CurrentOrgId,
  7136. OrderNumber: cancel.OrderNumber,
  7137. Type: 0,
  7138. Dealer: deaerler.DealerName,
  7139. Manufacturer: manufacturer.ManufacturerName,
  7140. Number: info.Number,
  7141. RegisterAccount: "",
  7142. Remark: "",
  7143. WarehouseInfoId: info.WarehouseInfotId,
  7144. PatientId: info.PatientId,
  7145. RecordDate: info.SysRecordTime,
  7146. StorehouseId: houseConfig.StorehouseOutInfo,
  7147. IsCheck: 1,
  7148. }
  7149. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7150. //回退库存
  7151. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  7152. }
  7153. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7154. var over_count int64
  7155. for _, it := range goodList {
  7156. over_count += it.StockCount
  7157. }
  7158. //查询出库数量
  7159. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  7160. //出库数据 大于 退库数量
  7161. if len(list) > 0 {
  7162. for _, it := range list {
  7163. //回退库存
  7164. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  7165. //退库数量增加
  7166. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  7167. //出库数量减少
  7168. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  7169. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7170. var over_count_one int64
  7171. for _, it := range goodList {
  7172. over_count_one += it.StockCount
  7173. }
  7174. //查询该批次是否有退库数据
  7175. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  7176. flow := models.VmStockFlow{
  7177. WarehousingId: it.WarehouseInfotId,
  7178. GoodId: it.GoodId,
  7179. Number: it.Number,
  7180. LicenseNumber: it.LicenseNumber,
  7181. Count: it.Count,
  7182. UserOrgId: adminInfo.CurrentOrgId,
  7183. PatientId: it.PatientId,
  7184. SystemTime: it.SysRecordTime,
  7185. ConsumableType: 7,
  7186. IsSys: 0,
  7187. WarehousingOrder: "",
  7188. WarehouseOutId: it.WarehouseOutId,
  7189. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  7190. IsEdit: 0,
  7191. CancelStockId: cancel.ID,
  7192. CancelOrderNumber: cancel.OrderNumber,
  7193. Manufacturer: manufacturer.ID,
  7194. Dealer: 0,
  7195. Creator: adminInfo.AdminUser.Id,
  7196. UpdateCreator: 0,
  7197. Status: 1,
  7198. Ctime: time.Now().Unix(),
  7199. Mtime: 0,
  7200. Price: it.Price,
  7201. WarehousingDetailId: it.WarehouseInfotId,
  7202. WarehouseOutDetailId: it.ID,
  7203. CancelOutDetailId: cancelInfo.ID,
  7204. ProductDate: it.ProductDate,
  7205. ExpireDate: it.ExpiryDate,
  7206. StorehouseId: houseConfig.StorehouseOutInfo,
  7207. OverCount: over_count_one,
  7208. OperateTime: time.Now().Unix(),
  7209. }
  7210. service.CreateStockFlowOne(flow)
  7211. }
  7212. }
  7213. //查询已出库数量
  7214. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  7215. if prescribingNumber < dialysisInfo.Count {
  7216. //改变数量
  7217. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  7218. }
  7219. if prescribingNumber >= dialysisInfo.Count {
  7220. //删除出库表
  7221. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  7222. }
  7223. //更新剩余库存
  7224. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  7225. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  7226. var total_count_one int64
  7227. for _, it := range stockList {
  7228. total_count_one += it.StockCount
  7229. }
  7230. //基础库插入数据
  7231. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  7232. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  7233. var flush_count int64
  7234. for _, it := range goodListOne {
  7235. flush_count += it.StockCount
  7236. }
  7237. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  7238. if errs != nil {
  7239. goodErrcode := models.XtGoodErrcode{
  7240. UserOrgId: project.UserOrgId,
  7241. Errcode: "手动出库更新剩余出库失败",
  7242. GoodId: project.ProjectId,
  7243. Status: 1,
  7244. Ctime: time.Now().Unix(),
  7245. Mtime: 0,
  7246. Count: 0,
  7247. StockCount: 0,
  7248. Creater: creater,
  7249. BatchNumberId: 0,
  7250. WarehouseOutId: 0,
  7251. }
  7252. service.CreateGoodErrcode(goodErrcode)
  7253. }
  7254. }
  7255. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7256. fmt.Println(err)
  7257. } else {
  7258. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  7259. fmt.Println(err)
  7260. }
  7261. }
  7262. c.ServeSuccessJSON(map[string]interface{}{
  7263. "msg": "删除成功",
  7264. })
  7265. return
  7266. }
  7267. func (c *HisApiController) CreateHisAdditionalCharge() {
  7268. his_patient_id, _ := c.GetInt64("his_patient_id")
  7269. patient_id, _ := c.GetInt64("patient_id")
  7270. record_date := c.GetString("record_date")
  7271. timeLayout := "2006-01-02"
  7272. loc, _ := time.LoadLocation("Local")
  7273. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7274. if err != nil {
  7275. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7276. return
  7277. }
  7278. adminInfo := c.GetAdminUserInfo()
  7279. recordDateTime := theTime.Unix()
  7280. dataBody := make(map[string]interface{}, 0)
  7281. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7282. if err != nil {
  7283. utils.ErrorLog(err.Error())
  7284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7285. return
  7286. }
  7287. var additions []*models.HisAdditionalCharge
  7288. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  7289. additions, _ := dataBody["addition"].([]interface{})
  7290. if len(additions) > 0 {
  7291. for _, item := range additions {
  7292. items := item.(map[string]interface{})
  7293. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  7294. utils.ErrorLog("item_id")
  7295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7296. return
  7297. }
  7298. item_id := int64(items["item_id"].(float64))
  7299. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  7300. utils.ErrorLog("item_name")
  7301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7302. return
  7303. }
  7304. item_name := items["item_name"].(string)
  7305. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  7306. utils.ErrorLog("price")
  7307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7308. return
  7309. }
  7310. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  7311. ctime := time.Now().Unix()
  7312. additional := &models.HisAdditionalCharge{
  7313. PatientId: patient_id,
  7314. HisPatientId: his_patient_id,
  7315. UserOrgId: adminInfo.CurrentOrgId,
  7316. RecordDate: recordDateTime,
  7317. CreatedTime: ctime,
  7318. UpdatedTime: ctime,
  7319. Modifier: adminInfo.AdminUser.Id,
  7320. Creator: adminInfo.AdminUser.Id,
  7321. Price: price,
  7322. ItemName: item_name,
  7323. ItemId: item_id,
  7324. Status: 1,
  7325. }
  7326. additions = append(additions, additional)
  7327. }
  7328. }
  7329. }
  7330. for _, item := range additions {
  7331. service.CreateAddtionalCharge(item)
  7332. }
  7333. c.ServeSuccessJSON(map[string]interface{}{
  7334. "msg": "创建成功",
  7335. })
  7336. }
  7337. func (c *HisApiController) CreateHisPatientCaseHistory() {
  7338. blood_fat := c.GetString("blood_fat")
  7339. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  7340. blood_sugar := c.GetString("blood_sugar")
  7341. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  7342. chief_conplaint := c.GetString("chief_conplaint")
  7343. dbp := c.GetString("dbp")
  7344. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  7345. delivery_way, _ := c.GetInt64("delivery_way")
  7346. diagnostic := c.GetString("diagnostic")
  7347. family_history := c.GetString("family_history")
  7348. height := c.GetString("height")
  7349. history_of_present_illness := c.GetString("history_of_present_illness")
  7350. is_infect, _ := c.GetInt64("is_infect")
  7351. past_history := c.GetString("past_history")
  7352. patient_id, _ := c.GetInt64("patient_id")
  7353. his_patient_id, _ := c.GetInt64("his_patient_id")
  7354. personal_history := c.GetString("personal_history")
  7355. pulse := c.GetString("pulse")
  7356. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  7357. sbp := c.GetString("sbp")
  7358. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  7359. heightfloat, _ := strconv.ParseFloat(height, 64)
  7360. sicktype := c.GetString("sick_type")
  7361. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  7362. symptom := c.GetString("symptom")
  7363. sick_date := c.GetString("sick_date")
  7364. temperatures := c.GetString("temperature")
  7365. temperature, _ := strconv.ParseFloat(temperatures, 64)
  7366. record_date := c.GetString("record_date")
  7367. breathing := c.GetString("breathing")
  7368. doctor_advice := c.GetString("doctor_advice")
  7369. remark := c.GetString("remark")
  7370. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  7371. sick, _ := c.GetInt64("sick")
  7372. diagnose, _ := c.GetInt64("diagnose")
  7373. //id, _ := c.GetInt64("id")
  7374. timeLayout := "2006-01-02"
  7375. loc, _ := time.LoadLocation("Local")
  7376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7377. allergic_history := c.GetString("allergic_history")
  7378. if err != nil {
  7379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7380. return
  7381. }
  7382. recordDateTime := theTime.Unix()
  7383. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  7384. if err != nil {
  7385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7386. return
  7387. }
  7388. sickTimes := sickTime.Unix()
  7389. ctime := time.Now().Unix()
  7390. primary_disease := c.GetString("primary_disease")
  7391. confirm_failure_date := c.GetString("confirm_failure_date")
  7392. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  7393. drug_allergy_history := c.GetString("drug_allergy_history")
  7394. physical_examination := c.GetString("physical_examination")
  7395. special_inspection := c.GetString("special_inspection")
  7396. lab_apparatus := c.GetString("lab_apparatus")
  7397. caseHistory := models.HisPatientCaseHistory{
  7398. HisPatientId: his_patient_id,
  7399. PatientId: patient_id,
  7400. Temperature: temperature,
  7401. BloodSugar: bloodsugarfloat,
  7402. Pulse: pulsefloat,
  7403. Sbp: sbpfloat,
  7404. Dbp: dbpfloat,
  7405. Height: heightfloat,
  7406. BloodFat: bloodfatfloat,
  7407. SickType: sick_type,
  7408. Symptom: symptom,
  7409. SickDate: sickTimes,
  7410. IsInfect: is_infect,
  7411. HistoryOfPresentIllness: history_of_present_illness,
  7412. PastHistory: past_history,
  7413. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  7414. ChiefConplaint: chief_conplaint,
  7415. PersonalHistory: personal_history,
  7416. FamilyHistory: family_history,
  7417. Diagnostic: diagnostic,
  7418. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7419. Status: 1,
  7420. Ctime: ctime,
  7421. Mtime: ctime,
  7422. RecordDate: recordDateTime,
  7423. DeliveryWay: delivery_way,
  7424. Breathing: breathingfloat,
  7425. DoctorAdvice: doctor_advice,
  7426. Remark: remark,
  7427. Sick: sick,
  7428. Diagnose: diagnose,
  7429. AllergicHistory: allergic_history,
  7430. PrimaryDisease: primary_disease,
  7431. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  7432. DrugAllergyHistory: drug_allergy_history,
  7433. PhysicalExamination: physical_examination,
  7434. SpecialInspection: special_inspection,
  7435. LabApparatus: lab_apparatus,
  7436. }
  7437. //查询该患者是否有病历
  7438. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  7439. if errcodes == gorm.ErrRecordNotFound {
  7440. err = service.SaveHisPatientCaseHistory(&caseHistory)
  7441. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7442. if err != nil {
  7443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7444. return
  7445. }
  7446. c.ServeSuccessJSON(map[string]interface{}{
  7447. "caseHistory": caseHistory,
  7448. "historyInfo": historyInfo,
  7449. })
  7450. return
  7451. } else if errcodes == nil {
  7452. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  7453. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  7454. if err != nil {
  7455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7456. return
  7457. }
  7458. c.ServeSuccessJSON(map[string]interface{}{
  7459. "caseHistory": caseHistory,
  7460. "historyInfo": historyInfo,
  7461. })
  7462. }
  7463. //查询该患者是否有病历
  7464. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  7465. //if errcode == gorm.ErrRecordNotFound {
  7466. // err = service.SaveHisPatientCaseHistory(caseHistory)
  7467. // if err != nil {
  7468. // c.ServeSuccessJSON(map[string]interface{}{
  7469. // "msg": "保存成功",
  7470. // })
  7471. // }
  7472. //} else if errcode == nil {
  7473. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7474. // return
  7475. //}
  7476. }
  7477. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  7478. patient_id, _ := c.GetInt64("patient_id", 0)
  7479. adminUser := c.GetAdminUserInfo()
  7480. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  7481. c.ServeSuccessJSON(map[string]interface{}{
  7482. "list": caseHistorys,
  7483. })
  7484. }
  7485. func (c *HisApiController) GetHisPatientCaseHistory() {
  7486. record_date, _ := c.GetInt64("record_date", 0)
  7487. patient_id, _ := c.GetInt64("patient_id", 0)
  7488. admin := c.GetAdminUserInfo()
  7489. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  7490. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  7491. c.ServeSuccessJSON(map[string]interface{}{
  7492. "info": info,
  7493. "case_history": case_history,
  7494. })
  7495. }
  7496. func (c *HisApiController) CreateCaseHistoryTemplate() {
  7497. template_name := c.GetString("template_name")
  7498. template_remark := c.GetString("template_remark")
  7499. doctor := c.GetAdminUserInfo().AdminUser.Id
  7500. diagnostic := c.GetString("diagnostic")
  7501. chief_conplaint := c.GetString("chief_conplain")
  7502. history_of_present_illness := c.GetString("history_of_present_illness")
  7503. past_history := c.GetString("past_history")
  7504. personal_history := c.GetString("personal_history")
  7505. family_history := c.GetString("family_history")
  7506. user_name := c.GetString("user_name")
  7507. doctor_advice := c.GetString("doctor_advice")
  7508. remark := c.GetString("remark")
  7509. //record_date := c.GetString("record_date")
  7510. //fmt.Println("record_date--------",record_date)
  7511. //timeLayout := "2006-01-02"
  7512. //loc, _ := time.LoadLocation("Local")
  7513. //
  7514. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7515. //if err != nil {
  7516. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7517. // return
  7518. //}
  7519. //recordDateTime := theTime.Unix()
  7520. ctime := time.Now().Unix()
  7521. template := models.HisCaseHistoryTemplate{
  7522. HistoryOfPresentIllness: history_of_present_illness,
  7523. PastHistory: past_history,
  7524. ChiefConplaint: chief_conplaint,
  7525. PersonalHistory: personal_history,
  7526. FamilyHistory: family_history,
  7527. Diagnostic: diagnostic,
  7528. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7529. Status: 1,
  7530. Ctime: ctime,
  7531. Mtime: ctime,
  7532. RecordDate: time.Now().Unix(),
  7533. TemplateName: template_name,
  7534. TemplateRemark: template_remark,
  7535. Creator: doctor,
  7536. Modifier: doctor,
  7537. UserName: user_name,
  7538. DoctorAdvice: doctor_advice,
  7539. Remark: remark,
  7540. }
  7541. err := service.SaveHisPatientCaseHistoryTemplate(template)
  7542. if err == nil {
  7543. c.ServeSuccessJSON(map[string]interface{}{
  7544. "msg": "保存成功",
  7545. })
  7546. } else {
  7547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7548. return
  7549. }
  7550. }
  7551. func (c *HisApiController) GetCaseHistoryTemplate() {
  7552. timeLayout := "2006-01-02"
  7553. loc, _ := time.LoadLocation("Local")
  7554. keyword := c.GetString("keyword")
  7555. start_time := c.GetString("start_time")
  7556. end_time := c.GetString("end_time")
  7557. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7558. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7559. admin := c.GetAdminUserInfo()
  7560. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  7561. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  7562. c.ServeSuccessJSON(map[string]interface{}{
  7563. "template": template,
  7564. //"history": history,
  7565. })
  7566. }
  7567. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7568. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7569. utils.ErrorLog("drug_name")
  7570. return enums.ErrorCodeParamWrong
  7571. }
  7572. adviceName, _ := json["drug_name"].(string)
  7573. if len(adviceName) == 0 {
  7574. utils.ErrorLog("len(advice_name) == 0")
  7575. return enums.ErrorCodeParamWrong
  7576. }
  7577. advice.AdviceName = adviceName
  7578. adviceDesc, _ := json["advice_desc"].(string)
  7579. advice.AdviceDesc = adviceDesc
  7580. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7581. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7582. advice.DrugSpec = drugSpec
  7583. }
  7584. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7585. remark, _ := json["remark"].(string)
  7586. advice.Remark = remark
  7587. }
  7588. if json["id"] == nil {
  7589. advice.DrugId = 0
  7590. } else {
  7591. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7592. drug_id := int64(json["id"].(float64))
  7593. advice.DrugId = drug_id
  7594. }
  7595. }
  7596. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7597. advice_id := int64(json["advice_id"].(float64))
  7598. advice.ID = advice_id
  7599. if advice.ID > 0 {
  7600. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7601. if err == nil {
  7602. if hisAdvice.ID > 0 {
  7603. advice.ExecutionTime = hisAdvice.ExecutionTime
  7604. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7605. advice.ExecutionState = hisAdvice.ExecutionState
  7606. advice.CheckTime = hisAdvice.CheckTime
  7607. advice.Checker = hisAdvice.Checker
  7608. advice.CheckState = hisAdvice.CheckState
  7609. advice.StartTime = hisAdvice.StartTime
  7610. advice.FeedetlSn = hisAdvice.FeedetlSn
  7611. }
  7612. }
  7613. }
  7614. }
  7615. //
  7616. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7617. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7618. // advice.ExecutionTime = execution_time
  7619. //}
  7620. //
  7621. //
  7622. //
  7623. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7624. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7625. // advice.ExecutionStaff = execution_staff
  7626. //}
  7627. //
  7628. //
  7629. //
  7630. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7631. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7632. // advice.ExecutionState = execution_state
  7633. //}
  7634. //
  7635. //
  7636. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7637. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7638. // advice.CheckTime = check_time
  7639. //}
  7640. //
  7641. //
  7642. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7643. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7644. // advice.CheckState = check_state
  7645. //}
  7646. //
  7647. //
  7648. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7649. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7650. // advice.Checker = checker
  7651. //}
  7652. //
  7653. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7654. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7655. // advice.StartTime = start_time
  7656. //}
  7657. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7658. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7659. advice.IsSelfDrug = is_self_drug
  7660. }
  7661. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7662. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7663. drug_way_count, _ := json["drug_way_count"].(string)
  7664. advice.DrugWayCount = drug_way_count
  7665. }
  7666. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7667. drugSpecUnit, _ := json["min_unit"].(string)
  7668. advice.DrugSpecUnit = drugSpecUnit
  7669. }
  7670. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7671. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7672. advice.SingleDose = singleDose
  7673. }
  7674. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7675. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7676. advice.SingleDoseUnit = singleDoseUnit
  7677. }
  7678. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7679. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7680. advice.PrescribingNumber = prescribingNumber
  7681. }
  7682. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7683. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7684. advice.PrescribingNumberUnit = prescribingNumberUnit
  7685. }
  7686. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7687. deliveryWay, _ := json["delivery_way"].(string)
  7688. advice.DeliveryWay = deliveryWay
  7689. }
  7690. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7691. executionFrequency, _ := json["execution_frequency"].(string)
  7692. advice.ExecutionFrequency = executionFrequency
  7693. }
  7694. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7695. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7696. advice.Price = price
  7697. }
  7698. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7699. med_list_codg, _ := json["medical_insurance_number"].(string)
  7700. advice.MedListCodg = med_list_codg
  7701. }
  7702. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7703. day := int64(json["day"].(float64))
  7704. advice.Day = day
  7705. }
  7706. return 0
  7707. }
  7708. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7709. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7710. id := int64(json["id"].(float64))
  7711. project.ID = id
  7712. historyProject, _ := service.GetHisProjectByID(id)
  7713. project.FeedetlSn = historyProject.FeedetlSn
  7714. }
  7715. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7716. project_id := int64(json["project_id"].(float64))
  7717. project.ProjectId = project_id
  7718. }
  7719. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7720. // price := int64(json["price"].(float64))
  7721. // formatInt_price := strconv.FormatInt(price, 10)
  7722. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7723. // project.Price = float_price
  7724. // }
  7725. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7726. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7727. project.Price = price
  7728. }
  7729. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7730. total, _ := json["total"].(string)
  7731. project.Count = total
  7732. }
  7733. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7734. medical_code, _ := json["medical_code"].(string)
  7735. project.MedListCodg = medical_code
  7736. }
  7737. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7738. single_dose, _ := json["single_dose"].(string)
  7739. project.SingleDose = single_dose
  7740. }
  7741. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7742. delivery_way, _ := json["delivery_way"].(string)
  7743. project.DeliveryWay = delivery_way
  7744. }
  7745. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7746. execution_frequency, _ := json["execution_frequency"].(string)
  7747. project.ExecutionFrequency = execution_frequency
  7748. }
  7749. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7750. remark, _ := json["remark"].(string)
  7751. project.Remark = remark
  7752. }
  7753. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7754. day, _ := json["number_days"].(string)
  7755. project.Day = day
  7756. }
  7757. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7758. unit, _ := json["unit"].(string)
  7759. project.Unit = unit
  7760. }
  7761. return 0
  7762. }
  7763. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7764. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7765. id := int64(json["id"].(float64))
  7766. historyAddtions, _ := service.GetHisAdditionByID(id)
  7767. additionalCharge.ID = id
  7768. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  7769. }
  7770. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7771. item_id := int64(json["item_id"].(float64))
  7772. additionalCharge.ItemId = item_id
  7773. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7774. if config.ID > 0 {
  7775. if len(config.Code) > 0 {
  7776. additionalCharge.MedListCodg = config.Code
  7777. }
  7778. }
  7779. }
  7780. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7781. // price := int64(json["price"].(float64))
  7782. // formatInt_price := strconv.FormatInt(price, 10)
  7783. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7784. // additionalCharge.Price = float_price
  7785. // }
  7786. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7787. // price := int64(json["price"].(float64))
  7788. // formatInt_price := strconv.FormatInt(price, 10)
  7789. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7790. // additionalCharge.Price = float_price
  7791. //}
  7792. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7793. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7794. additionalCharge.Price = price
  7795. }
  7796. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7797. count, _ := json["count"].(string)
  7798. counts, _ := strconv.ParseInt(count, 10, 64)
  7799. additionalCharge.Count = counts
  7800. }
  7801. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7802. item_name, _ := json["item_name"].(string)
  7803. additionalCharge.ItemName = item_name
  7804. }
  7805. return 0
  7806. }
  7807. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7808. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7809. utils.ErrorLog("drug_name")
  7810. return enums.ErrorCodeParamWrong
  7811. }
  7812. adviceName, _ := json["drug_name"].(string)
  7813. if len(adviceName) == 0 {
  7814. utils.ErrorLog("len(advice_name) == 0")
  7815. return enums.ErrorCodeParamWrong
  7816. }
  7817. advice.AdviceName = adviceName
  7818. adviceDesc, _ := json["advice_desc"].(string)
  7819. advice.AdviceDesc = adviceDesc
  7820. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7821. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7822. advice.DrugSpec = drugSpec
  7823. }
  7824. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7825. remark, _ := json["remark"].(string)
  7826. advice.Remark = remark
  7827. }
  7828. if json["id"] == nil {
  7829. advice.DrugId = 0
  7830. } else {
  7831. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7832. drug_id := int64(json["id"].(float64))
  7833. advice.DrugId = drug_id
  7834. }
  7835. }
  7836. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7837. groupno := int64(json["groupno"].(float64))
  7838. advice.Groupno = groupno
  7839. }
  7840. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7841. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7842. advice.IsSelfDrug = is_self_drug
  7843. }
  7844. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7845. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7846. drug_way_count, _ := json["drug_way_count"].(string)
  7847. advice.DrugWayCount = drug_way_count
  7848. }
  7849. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7850. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7851. advice.HospApprFlag = hosp_appr_flag
  7852. }
  7853. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7854. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7855. advice.PrescribingNumber = prescribingNumber
  7856. }
  7857. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7858. // frequency_type := int64(json["frequency_type"].(float64))
  7859. // advice.FrequencyType = frequency_type
  7860. //}
  7861. //
  7862. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7863. // day_count := int64(json["day_count"].(float64))
  7864. // advice.DayCount = day_count
  7865. //}
  7866. //
  7867. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7868. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7869. // week_day, _ := json["week_day"].(string)
  7870. // advice.WeekDay = week_day
  7871. //}
  7872. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7873. drugSpecUnit, _ := json["min_unit"].(string)
  7874. advice.DrugSpecUnit = drugSpecUnit
  7875. }
  7876. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7877. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7878. advice.SingleDose = singleDose
  7879. }
  7880. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7881. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7882. advice.SingleDoseUnit = singleDoseUnit
  7883. }
  7884. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7885. deliveryWay, _ := json["delivery_way"].(string)
  7886. advice.DeliveryWay = deliveryWay
  7887. }
  7888. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7889. executionFrequency, _ := json["execution_frequency"].(string)
  7890. advice.ExecutionFrequency = executionFrequency
  7891. }
  7892. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7893. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7894. advice.Price = price
  7895. }
  7896. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7897. med_list_codg, _ := json["medical_insurance_number"].(string)
  7898. advice.MedListCodg = med_list_codg
  7899. }
  7900. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7901. day := int64(json["day"].(float64))
  7902. advice.Day = day
  7903. }
  7904. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7905. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7906. advice.PrescribingNumberUnit = prescribingNumberUnit
  7907. }
  7908. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7909. advice_id := int64(json["advice_id"].(float64))
  7910. advice.ID = advice_id
  7911. if advice.ID > 0 {
  7912. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7913. if err == nil {
  7914. if hisAdvice.ID > 0 {
  7915. advice.ExecutionTime = hisAdvice.ExecutionTime
  7916. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7917. advice.ExecutionState = hisAdvice.ExecutionState
  7918. advice.CheckTime = hisAdvice.CheckTime
  7919. advice.Checker = hisAdvice.Checker
  7920. advice.CheckState = hisAdvice.CheckState
  7921. advice.StartTime = hisAdvice.StartTime
  7922. advice.HospApprFlag = hisAdvice.HospApprFlag
  7923. advice.IsMedicine = hisAdvice.IsMedicine
  7924. if hisAdvice.UserOrgId == 10028 {
  7925. if hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  7926. advice.ExecutionTime = 0
  7927. advice.ExecutionStaff = 0
  7928. advice.ExecutionState = 2
  7929. advice.CheckTime = 0
  7930. advice.Checker = 0
  7931. advice.CheckState = 2
  7932. }
  7933. } else {
  7934. if hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  7935. advice.ExecutionTime = 0
  7936. advice.ExecutionStaff = 0
  7937. advice.ExecutionState = 2
  7938. advice.CheckTime = 0
  7939. advice.Checker = 0
  7940. advice.CheckState = 2
  7941. advice.UpdatedTime = time.Now().Unix()
  7942. }
  7943. }
  7944. //advice.Groupno = hisAdvice.Groupno
  7945. }
  7946. }
  7947. }
  7948. }
  7949. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7950. //
  7951. //if drugStockConfig.IsOpen == 1 {
  7952. //
  7953. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7954. // if advice.ID == 0 { //医嘱不存在
  7955. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7956. // drug.Total = drug.Total - advice.PrescribingNumber
  7957. // service.UpdateBaseDrugLib(&drug)
  7958. //
  7959. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7960. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7961. // drug.Total = drug.Total - num
  7962. // service.UpdateBaseDrugLib(&drug)
  7963. // }
  7964. //
  7965. // } else if advice.ID > 0 { //医嘱存在
  7966. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7967. // var num float64
  7968. //
  7969. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7970. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7971. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7972. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7973. // drug.Total = drug.Total + num
  7974. // service.UpdateBaseDrugLib(&drug)
  7975. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7976. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7977. // drug.Total = drug.Total - num
  7978. // service.UpdateBaseDrugLib(&drug)
  7979. // }
  7980. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7981. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7982. // if num2 > advice.PrescribingNumber {
  7983. // num = num2 - advice.PrescribingNumber
  7984. // drug.Total = drug.Total + num
  7985. // service.UpdateBaseDrugLib(&drug)
  7986. // } else if num2 < advice.PrescribingNumber {
  7987. // num = advice.PrescribingNumber - num2
  7988. // drug.Total = drug.Total - num
  7989. // service.UpdateBaseDrugLib(&drug)
  7990. // }
  7991. //
  7992. // }
  7993. //
  7994. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7995. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7996. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7997. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7998. // if num1 > num2 {
  7999. // num = num1 - num2
  8000. // drug.Total = drug.Total + num
  8001. // service.UpdateBaseDrugLib(&drug)
  8002. // } else if num1 < num2 {
  8003. // num = num2 - num1
  8004. // drug.Total = drug.Total - num
  8005. // service.UpdateBaseDrugLib(&drug)
  8006. // }
  8007. //
  8008. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8009. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8010. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8011. // if hisAdvice.PrescribingNumber > num2 {
  8012. // num = hisAdvice.PrescribingNumber - num2
  8013. // drug.Total = drug.Total + num
  8014. // service.UpdateBaseDrugLib(&drug)
  8015. // } else if num2 < advice.PrescribingNumber {
  8016. // num = num2 - hisAdvice.PrescribingNumber
  8017. // drug.Total = drug.Total - num
  8018. // service.UpdateBaseDrugLib(&drug)
  8019. // }
  8020. //
  8021. // }
  8022. // }
  8023. // }
  8024. //}
  8025. //
  8026. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8027. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8028. // advice.ExecutionTime = execution_time
  8029. //}
  8030. //
  8031. //
  8032. //
  8033. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8034. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8035. // advice.ExecutionStaff = execution_staff
  8036. //}
  8037. //
  8038. //
  8039. //
  8040. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8041. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8042. // advice.ExecutionState = execution_state
  8043. //}
  8044. //
  8045. //
  8046. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8047. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8048. // advice.CheckTime = check_time
  8049. //}
  8050. //
  8051. //
  8052. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8053. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8054. // advice.CheckState = check_state
  8055. //}
  8056. //
  8057. //
  8058. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8059. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8060. // advice.Checker = checker
  8061. //}
  8062. //
  8063. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8064. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8065. // advice.StartTime = start_time
  8066. //}
  8067. return 0
  8068. }
  8069. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8070. project.ExecutionStaff = 0
  8071. project.ExecutionState = 2
  8072. project.ExecutionTime = 0
  8073. project.Checker = 0
  8074. project.CheckState = 2
  8075. project.CheckTime = 0
  8076. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8077. id := int64(json["id"].(float64))
  8078. project.ID = id
  8079. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8080. project.ExecutionStaff = temp_project.ExecutionStaff
  8081. project.ExecutionState = temp_project.ExecutionState
  8082. project.ExecutionTime = temp_project.ExecutionTime
  8083. project.Checker = temp_project.Checker
  8084. project.CheckState = temp_project.CheckState
  8085. project.CheckTime = temp_project.CheckTime
  8086. project.TeamId = temp_project.TeamId
  8087. }
  8088. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8089. types := int64(json["type"].(float64))
  8090. project.Type = types
  8091. }
  8092. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8093. project_id := int64(json["project_id"].(float64))
  8094. project.ProjectId = project_id
  8095. }
  8096. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8097. team_id := int64(json["team_id"].(float64))
  8098. project.TeamId = team_id
  8099. }
  8100. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8101. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8102. project.Price = price
  8103. }
  8104. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8105. total, _ := json["total"].(string)
  8106. //totals, _ := strconv.ParseInt(total, 10, 64)
  8107. project.Count = total
  8108. }
  8109. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8110. medical_code, _ := json["medical_code"].(string)
  8111. project.MedListCodg = medical_code
  8112. }
  8113. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8114. single_dose, _ := json["single_dose"].(string)
  8115. project.SingleDose = single_dose
  8116. }
  8117. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8118. delivery_way, _ := json["delivery_way"].(string)
  8119. project.DeliveryWay = delivery_way
  8120. }
  8121. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8122. execution_frequency, _ := json["execution_frequency"].(string)
  8123. project.ExecutionFrequency = execution_frequency
  8124. }
  8125. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8126. remark, _ := json["remark"].(string)
  8127. project.Remark = remark
  8128. }
  8129. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8130. day, _ := json["number_days"].(string)
  8131. project.Day = day
  8132. }
  8133. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8134. unit, _ := json["unit"].(string)
  8135. project.Unit = unit
  8136. }
  8137. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8138. // frequency_type := int64(json["frequency_type"].(float64))
  8139. // project.FrequencyType = frequency_type
  8140. //}
  8141. //
  8142. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8143. // day_count := int64(json["day_count"].(float64))
  8144. // project.DayCount = day_count
  8145. //}
  8146. //
  8147. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8148. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8149. // week_day, _ := json["week_day"].(string)
  8150. // project.WeekDay = week_day
  8151. //}
  8152. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8153. //
  8154. //if project.ID == 0 {
  8155. // if stockConfig.IsOpen == 1 {
  8156. // if project.Type == 3 {
  8157. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8158. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8159. // good.Total = good.Total - f_count
  8160. // service.UpdateGoodInfo(&good)
  8161. // }
  8162. // }
  8163. //
  8164. //} else {
  8165. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8166. //
  8167. // if stockConfig.IsOpen == 1 {
  8168. // if project.Type == 3 {
  8169. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8170. // if project.Count < temp_project.Count {
  8171. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8172. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8173. //
  8174. // other_count := f_count_two - f_count_one
  8175. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8176. // good.Total = good.Total + other_count_two
  8177. // service.UpdateGoodInfo(&good)
  8178. // } else if project.Count > temp_project.Count {
  8179. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8180. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8181. //
  8182. // other_count := f_count_one - f_count_two
  8183. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8184. // good.Total = good.Total - other_count_two
  8185. // service.UpdateGoodInfo(&good)
  8186. // }
  8187. //
  8188. // }
  8189. // }
  8190. //
  8191. //}
  8192. return 0
  8193. }
  8194. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  8195. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8196. utils.ErrorLog("drug_name")
  8197. return enums.ErrorCodeParamWrong
  8198. }
  8199. adviceName, _ := json["drug_name"].(string)
  8200. if len(adviceName) == 0 {
  8201. utils.ErrorLog("len(advice_name) == 0")
  8202. return enums.ErrorCodeParamWrong
  8203. }
  8204. advice.AdviceName = adviceName
  8205. adviceDesc, _ := json["advice_desc"].(string)
  8206. advice.AdviceDesc = adviceDesc
  8207. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8208. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8209. advice.DrugSpec = drugSpec
  8210. }
  8211. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8212. remark, _ := json["remark"].(string)
  8213. advice.Remark = remark
  8214. }
  8215. if json["id"] == nil {
  8216. advice.DrugId = 0
  8217. } else {
  8218. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8219. drug_id := int64(json["id"].(float64))
  8220. advice.DrugId = drug_id
  8221. }
  8222. }
  8223. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8224. groupno := int64(json["groupno"].(float64))
  8225. advice.Groupno = groupno
  8226. }
  8227. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  8228. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  8229. advice.IsSelfDrug = is_self_drug
  8230. }
  8231. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  8232. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  8233. drug_way_count, _ := json["drug_way_count"].(string)
  8234. advice.DrugWayCount = drug_way_count
  8235. }
  8236. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  8237. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  8238. advice.HospApprFlag = hosp_appr_flag
  8239. }
  8240. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8241. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8242. advice.PrescribingNumber = prescribingNumber
  8243. }
  8244. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8245. // frequency_type := int64(json["frequency_type"].(float64))
  8246. // advice.FrequencyType = frequency_type
  8247. //}
  8248. //
  8249. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8250. // day_count := int64(json["day_count"].(float64))
  8251. // advice.DayCount = day_count
  8252. //}
  8253. //
  8254. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8255. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8256. // week_day, _ := json["week_day"].(string)
  8257. // advice.WeekDay = week_day
  8258. //}
  8259. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8260. drugSpecUnit, _ := json["min_unit"].(string)
  8261. advice.DrugSpecUnit = drugSpecUnit
  8262. }
  8263. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8264. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8265. advice.SingleDose = singleDose
  8266. }
  8267. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8268. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8269. advice.SingleDoseUnit = singleDoseUnit
  8270. }
  8271. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8272. deliveryWay, _ := json["delivery_way"].(string)
  8273. advice.DeliveryWay = deliveryWay
  8274. }
  8275. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8276. executionFrequency, _ := json["execution_frequency"].(string)
  8277. advice.ExecutionFrequency = executionFrequency
  8278. }
  8279. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8280. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8281. advice.Price = price
  8282. }
  8283. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8284. med_list_codg, _ := json["medical_insurance_number"].(string)
  8285. advice.MedListCodg = med_list_codg
  8286. }
  8287. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8288. day := int64(json["day"].(float64))
  8289. advice.Day = day
  8290. }
  8291. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8292. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8293. advice.PrescribingNumberUnit = prescribingNumberUnit
  8294. }
  8295. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  8296. advice_id := int64(json["advice_id"].(float64))
  8297. advice.ID = advice_id
  8298. if advice.ID > 0 {
  8299. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  8300. if err == nil {
  8301. if hisAdvice.ID > 0 {
  8302. advice.ExecutionTime = hisAdvice.ExecutionTime
  8303. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  8304. advice.ExecutionState = hisAdvice.ExecutionState
  8305. advice.CheckTime = hisAdvice.CheckTime
  8306. advice.Checker = hisAdvice.Checker
  8307. advice.DrugCode = hisAdvice.DrugCode
  8308. advice.CheckState = hisAdvice.CheckState
  8309. advice.StartTime = hisAdvice.StartTime
  8310. advice.HospApprFlag = hisAdvice.HospApprFlag
  8311. advice.IsMedicine = hisAdvice.IsMedicine
  8312. if hisAdvice.UserOrgId == 10028 {
  8313. if hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  8314. advice.ExecutionTime = 0
  8315. advice.ExecutionStaff = 0
  8316. advice.ExecutionState = 2
  8317. advice.CheckTime = 0
  8318. advice.Checker = 0
  8319. advice.CheckState = 2
  8320. }
  8321. } else {
  8322. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  8323. advice.ExecutionTime = 0
  8324. advice.ExecutionStaff = 0
  8325. advice.ExecutionState = 2
  8326. advice.CheckTime = 0
  8327. advice.Checker = 0
  8328. advice.CheckState = 2
  8329. //advice.UpdatedTime = time.Now().Unix()
  8330. advice.CreatedTime = hisAdvice.CreatedTime
  8331. advice.UpdatedTime = time.Now().Unix()
  8332. } else {
  8333. advice.CreatedTime = hisAdvice.CreatedTime
  8334. advice.UpdatedTime = hisAdvice.UpdatedTime
  8335. }
  8336. }
  8337. //advice.Groupno = hisAdvice.Groupno
  8338. } else {
  8339. advice.IsMedicine = 0
  8340. ctime := time.Now().Unix()
  8341. advice.CreatedTime = ctime
  8342. advice.UpdatedTime = ctime
  8343. }
  8344. }
  8345. } else {
  8346. advice.IsMedicine = 0
  8347. ctime := time.Now().Unix()
  8348. advice.CreatedTime = ctime
  8349. advice.UpdatedTime = ctime
  8350. }
  8351. }
  8352. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  8353. //
  8354. //if drugStockConfig.IsOpen == 1 {
  8355. //
  8356. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8357. // if advice.ID == 0 { //医嘱不存在
  8358. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  8359. // drug.Total = drug.Total - advice.PrescribingNumber
  8360. // service.UpdateBaseDrugLib(&drug)
  8361. //
  8362. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  8363. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  8364. // drug.Total = drug.Total - num
  8365. // service.UpdateBaseDrugLib(&drug)
  8366. // }
  8367. //
  8368. // } else if advice.ID > 0 { //医嘱存在
  8369. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  8370. // var num float64
  8371. //
  8372. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  8373. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  8374. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  8375. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  8376. // drug.Total = drug.Total + num
  8377. // service.UpdateBaseDrugLib(&drug)
  8378. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  8379. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  8380. // drug.Total = drug.Total - num
  8381. // service.UpdateBaseDrugLib(&drug)
  8382. // }
  8383. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  8384. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8385. // if num2 > advice.PrescribingNumber {
  8386. // num = num2 - advice.PrescribingNumber
  8387. // drug.Total = drug.Total + num
  8388. // service.UpdateBaseDrugLib(&drug)
  8389. // } else if num2 < advice.PrescribingNumber {
  8390. // num = advice.PrescribingNumber - num2
  8391. // drug.Total = drug.Total - num
  8392. // service.UpdateBaseDrugLib(&drug)
  8393. // }
  8394. //
  8395. // }
  8396. //
  8397. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  8398. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  8399. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  8400. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8401. // if num1 > num2 {
  8402. // num = num1 - num2
  8403. // drug.Total = drug.Total + num
  8404. // service.UpdateBaseDrugLib(&drug)
  8405. // } else if num1 < num2 {
  8406. // num = num2 - num1
  8407. // drug.Total = drug.Total - num
  8408. // service.UpdateBaseDrugLib(&drug)
  8409. // }
  8410. //
  8411. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  8412. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  8413. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  8414. // if hisAdvice.PrescribingNumber > num2 {
  8415. // num = hisAdvice.PrescribingNumber - num2
  8416. // drug.Total = drug.Total + num
  8417. // service.UpdateBaseDrugLib(&drug)
  8418. // } else if num2 < advice.PrescribingNumber {
  8419. // num = num2 - hisAdvice.PrescribingNumber
  8420. // drug.Total = drug.Total - num
  8421. // service.UpdateBaseDrugLib(&drug)
  8422. // }
  8423. //
  8424. // }
  8425. // }
  8426. // }
  8427. //}
  8428. //
  8429. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  8430. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  8431. // advice.ExecutionTime = execution_time
  8432. //}
  8433. //
  8434. //
  8435. //
  8436. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  8437. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  8438. // advice.ExecutionStaff = execution_staff
  8439. //}
  8440. //
  8441. //
  8442. //
  8443. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  8444. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  8445. // advice.ExecutionState = execution_state
  8446. //}
  8447. //
  8448. //
  8449. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  8450. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  8451. // advice.CheckTime = check_time
  8452. //}
  8453. //
  8454. //
  8455. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  8456. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  8457. // advice.CheckState = check_state
  8458. //}
  8459. //
  8460. //
  8461. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  8462. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  8463. // advice.Checker = checker
  8464. //}
  8465. //
  8466. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  8467. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  8468. // advice.StartTime = start_time
  8469. //}
  8470. return 0
  8471. }
  8472. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  8473. project.ExecutionStaff = 0
  8474. project.ExecutionState = 2
  8475. project.ExecutionTime = 0
  8476. project.Checker = 0
  8477. project.CheckState = 2
  8478. project.CheckTime = 0
  8479. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8480. id := int64(json["id"].(float64))
  8481. project.ID = id
  8482. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8483. project.ExecutionStaff = temp_project.ExecutionStaff
  8484. project.ExecutionState = temp_project.ExecutionState
  8485. project.ExecutionTime = temp_project.ExecutionTime
  8486. project.Checker = temp_project.Checker
  8487. project.CheckState = temp_project.CheckState
  8488. project.CheckTime = temp_project.CheckTime
  8489. project.TeamId = temp_project.TeamId
  8490. }
  8491. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8492. types := int64(json["type"].(float64))
  8493. project.Type = types
  8494. }
  8495. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8496. project_id := int64(json["project_id"].(float64))
  8497. project.ProjectId = project_id
  8498. }
  8499. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  8500. team_id := int64(json["team_id"].(float64))
  8501. project.TeamId = team_id
  8502. }
  8503. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8504. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8505. project.Price = price
  8506. }
  8507. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8508. total, _ := json["total"].(string)
  8509. //totals, _ := strconv.ParseInt(total, 10, 64)
  8510. project.Count = total
  8511. }
  8512. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8513. medical_code, _ := json["medical_code"].(string)
  8514. project.MedListCodg = medical_code
  8515. }
  8516. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8517. single_dose, _ := json["single_dose"].(string)
  8518. project.SingleDose = single_dose
  8519. }
  8520. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8521. delivery_way, _ := json["delivery_way"].(string)
  8522. project.DeliveryWay = delivery_way
  8523. }
  8524. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8525. execution_frequency, _ := json["execution_frequency"].(string)
  8526. project.ExecutionFrequency = execution_frequency
  8527. }
  8528. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8529. remark, _ := json["remark"].(string)
  8530. project.Remark = remark
  8531. }
  8532. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8533. day, _ := json["number_days"].(string)
  8534. project.Day = day
  8535. }
  8536. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8537. unit, _ := json["unit"].(string)
  8538. project.Unit = unit
  8539. }
  8540. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  8541. // frequency_type := int64(json["frequency_type"].(float64))
  8542. // project.FrequencyType = frequency_type
  8543. //}
  8544. //
  8545. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  8546. // day_count := int64(json["day_count"].(float64))
  8547. // project.DayCount = day_count
  8548. //}
  8549. //
  8550. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  8551. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  8552. // week_day, _ := json["week_day"].(string)
  8553. // project.WeekDay = week_day
  8554. //}
  8555. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  8556. //
  8557. //if project.ID == 0 {
  8558. // if stockConfig.IsOpen == 1 {
  8559. // if project.Type == 3 {
  8560. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8561. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  8562. // good.Total = good.Total - f_count
  8563. // service.UpdateGoodInfo(&good)
  8564. // }
  8565. // }
  8566. //
  8567. //} else {
  8568. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  8569. //
  8570. // if stockConfig.IsOpen == 1 {
  8571. // if project.Type == 3 {
  8572. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  8573. // if project.Count < temp_project.Count {
  8574. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8575. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8576. //
  8577. // other_count := f_count_two - f_count_one
  8578. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8579. // good.Total = good.Total + other_count_two
  8580. // service.UpdateGoodInfo(&good)
  8581. // } else if project.Count > temp_project.Count {
  8582. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  8583. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  8584. //
  8585. // other_count := f_count_one - f_count_two
  8586. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  8587. // good.Total = good.Total - other_count_two
  8588. // service.UpdateGoodInfo(&good)
  8589. // }
  8590. //
  8591. // }
  8592. // }
  8593. //
  8594. //}
  8595. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8596. id := int64(json["id"].(float64))
  8597. if id > 0 {
  8598. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  8599. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  8600. fmt.Println("666666")
  8601. project.Mtime = time.Now().Unix()
  8602. project.Ctime = temp_project.Ctime
  8603. } else {
  8604. project.Mtime = temp_project.Mtime
  8605. project.Ctime = temp_project.Ctime
  8606. }
  8607. } else {
  8608. ctime := time.Now().Unix()
  8609. project.Mtime = ctime
  8610. project.Ctime = ctime
  8611. }
  8612. }
  8613. return 0
  8614. }
  8615. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  8616. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8617. id := int64(json["id"].(float64))
  8618. additionalCharge.ID = id
  8619. }
  8620. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  8621. item_id := int64(json["item_id"].(float64))
  8622. additionalCharge.ItemId = item_id
  8623. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  8624. if config.ID > 0 {
  8625. if len(config.Code) > 0 {
  8626. additionalCharge.MedListCodg = config.Code
  8627. }
  8628. }
  8629. }
  8630. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8631. // price := int64(json["price"].(float64))
  8632. // formatInt_price := strconv.FormatInt(price, 10)
  8633. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8634. // additionalCharge.Price = float_price
  8635. // }
  8636. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  8637. // price := int64(json["price"].(float64))
  8638. // formatInt_price := strconv.FormatInt(price, 10)
  8639. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  8640. // additionalCharge.Price = float_price
  8641. //}
  8642. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8643. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8644. additionalCharge.Price = price
  8645. }
  8646. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  8647. count, _ := json["count"].(string)
  8648. counts, _ := strconv.ParseInt(count, 10, 64)
  8649. additionalCharge.Count = counts
  8650. }
  8651. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  8652. item_name, _ := json["item_name"].(string)
  8653. additionalCharge.ItemName = item_name
  8654. }
  8655. return 0
  8656. }
  8657. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  8658. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  8659. utils.ErrorLog("drug_name")
  8660. return enums.ErrorCodeParamWrong
  8661. }
  8662. adviceName, _ := json["drug_name"].(string)
  8663. if len(adviceName) == 0 {
  8664. utils.ErrorLog("len(advice_name) == 0")
  8665. return enums.ErrorCodeParamWrong
  8666. }
  8667. advice.AdviceName = adviceName
  8668. adviceDesc, _ := json["advice_desc"].(string)
  8669. advice.AdviceDesc = adviceDesc
  8670. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  8671. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  8672. advice.DrugSpec = drugSpec
  8673. }
  8674. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8675. remark, _ := json["remark"].(string)
  8676. advice.Remark = remark
  8677. }
  8678. if json["id"] == nil {
  8679. advice.DrugId = 0
  8680. } else {
  8681. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  8682. drug_id := int64(json["id"].(float64))
  8683. advice.DrugId = drug_id
  8684. }
  8685. }
  8686. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  8687. groupno := int64(json["groupno"].(float64))
  8688. advice.Groupno = groupno
  8689. }
  8690. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  8691. drugSpecUnit, _ := json["min_unit"].(string)
  8692. advice.DrugSpecUnit = drugSpecUnit
  8693. }
  8694. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8695. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  8696. advice.SingleDose = singleDose
  8697. }
  8698. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  8699. singleDoseUnit, _ := json["single_dose_unit"].(string)
  8700. advice.SingleDoseUnit = singleDoseUnit
  8701. }
  8702. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  8703. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  8704. advice.PrescribingNumber = prescribingNumber
  8705. }
  8706. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  8707. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  8708. advice.PrescribingNumberUnit = prescribingNumberUnit
  8709. }
  8710. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8711. deliveryWay, _ := json["delivery_way"].(string)
  8712. advice.DeliveryWay = deliveryWay
  8713. }
  8714. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8715. executionFrequency, _ := json["execution_frequency"].(string)
  8716. advice.ExecutionFrequency = executionFrequency
  8717. }
  8718. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  8719. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  8720. advice.Price = price
  8721. }
  8722. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  8723. med_list_codg, _ := json["medical_insurance_number"].(string)
  8724. advice.MedListCodg = med_list_codg
  8725. }
  8726. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  8727. day := int64(json["day"].(float64))
  8728. advice.Day = day
  8729. }
  8730. advice.FrequencyType = 1
  8731. return 0
  8732. }
  8733. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  8734. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  8735. types := int64(json["type"].(float64))
  8736. project.Type = types
  8737. }
  8738. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  8739. project_id := int64(json["project_id"].(float64))
  8740. project.ProjectId = project_id
  8741. }
  8742. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  8743. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  8744. project.Price = price
  8745. }
  8746. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  8747. total, _ := json["total"].(string)
  8748. //totals, _ := strconv.ParseInt(total, 10, 64)
  8749. project.Count = total
  8750. }
  8751. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  8752. medical_code, _ := json["medical_code"].(string)
  8753. project.MedListCodg = medical_code
  8754. }
  8755. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  8756. single_dose, _ := json["single_dose"].(string)
  8757. project.SingleDose = single_dose
  8758. }
  8759. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  8760. delivery_way, _ := json["delivery_way"].(string)
  8761. project.DeliveryWay = delivery_way
  8762. }
  8763. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  8764. execution_frequency, _ := json["execution_frequency"].(string)
  8765. project.ExecutionFrequency = execution_frequency
  8766. }
  8767. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  8768. remark, _ := json["remark"].(string)
  8769. project.Remark = remark
  8770. }
  8771. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  8772. day, _ := json["number_days"].(string)
  8773. project.Day = day
  8774. }
  8775. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  8776. unit, _ := json["unit"].(string)
  8777. project.Unit = unit
  8778. }
  8779. project.FrequencyType = 1
  8780. return 0
  8781. }
  8782. func (c *HisApiController) GetHisOrderListTwo() {
  8783. start_time := c.GetString("start_time")
  8784. end_time := c.GetString("end_time")
  8785. timeLayout := "2006-01-02"
  8786. loc, _ := time.LoadLocation("Local")
  8787. var startTime int64
  8788. if len(start_time) > 0 {
  8789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8790. if err != nil {
  8791. //fmt.Println(err)
  8792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8793. return
  8794. }
  8795. startTime = theTime.Unix()
  8796. }
  8797. var endTime int64
  8798. if len(end_time) > 0 {
  8799. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8800. if err != nil {
  8801. utils.ErrorLog(err.Error())
  8802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8803. return
  8804. }
  8805. endTime = theTime.Unix()
  8806. }
  8807. adminUser := c.GetAdminUserInfo()
  8808. org_id := adminUser.CurrentOrgId
  8809. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  8810. if err == nil {
  8811. c.ServeSuccessJSON(map[string]interface{}{
  8812. "order2": order,
  8813. })
  8814. } else {
  8815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8816. return
  8817. }
  8818. }
  8819. func (c *HisApiController) GetHisOrderList() {
  8820. page, _ := c.GetInt64("page", -1)
  8821. limit, _ := c.GetInt64("limit", -1)
  8822. start_time := c.GetString("start_time")
  8823. end_time := c.GetString("end_time")
  8824. types, _ := c.GetInt64("type", 0)
  8825. keywords := c.GetString("keywords")
  8826. p_type, _ := c.GetInt64("p_type", 0)
  8827. sort_type, _ := c.GetInt64("sort_type", 0)
  8828. charge_type, _ := c.GetInt64("charge_type", 0)
  8829. sch_type, _ := c.GetInt64("sch_type", 0)
  8830. zone_type, _ := c.GetInt64("zone_type", 0)
  8831. med_type, _ := c.GetInt64("med_type", 0)
  8832. timeLayout := "2006-01-02"
  8833. loc, _ := time.LoadLocation("Local")
  8834. var startTime int64
  8835. if len(start_time) > 0 {
  8836. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8837. if err != nil {
  8838. //fmt.Println(err)
  8839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8840. return
  8841. }
  8842. startTime = theTime.Unix()
  8843. }
  8844. var endTime int64
  8845. if len(end_time) > 0 {
  8846. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8847. if err != nil {
  8848. utils.ErrorLog(err.Error())
  8849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8850. return
  8851. }
  8852. endTime = theTime.Unix()
  8853. }
  8854. adminUser := c.GetAdminUserInfo()
  8855. org_id := adminUser.CurrentOrgId
  8856. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  8857. for _, item := range order {
  8858. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  8859. item.DoctorName = info.Doctor
  8860. item.DepartmentName = info.XtHisDepartment.Name
  8861. }
  8862. if err == nil {
  8863. c.ServeSuccessJSON(map[string]interface{}{
  8864. "order": order,
  8865. "total": total,
  8866. })
  8867. } else {
  8868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8869. return
  8870. }
  8871. }
  8872. func (c *HisApiController) GetHisOrder() {
  8873. patient_id, _ := c.GetInt64("patient_id", 0)
  8874. number := c.GetString("number")
  8875. adminInfo := c.GetAdminUserInfo()
  8876. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  8877. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  8878. if err == nil {
  8879. c.ServeSuccessJSON(map[string]interface{}{
  8880. "order": order,
  8881. "prescription": prescriptions,
  8882. })
  8883. } else {
  8884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8885. return
  8886. }
  8887. }
  8888. func (c *HisApiController) GetHisPrescriptionList() {
  8889. record_date := c.GetString("record_date")
  8890. keywords := c.GetString("keywords")
  8891. page, _ := c.GetInt64("page")
  8892. limit, _ := c.GetInt64("limit")
  8893. sch_type, _ := c.GetInt64("sch_type")
  8894. timeLayout := "2006-01-02"
  8895. loc, _ := time.LoadLocation("Local")
  8896. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8897. if err != nil {
  8898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8899. return
  8900. }
  8901. recordDateTime := theTime.Unix()
  8902. adminInfo := c.GetAdminUserInfo()
  8903. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  8904. //adminInfo := c.GetAdminUserInfo()
  8905. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  8906. //fmt.Println(prescriptionOrder)
  8907. if err == nil {
  8908. c.ServeSuccessJSON(map[string]interface{}{
  8909. "order": prescriptionOrder,
  8910. "total": total,
  8911. })
  8912. } else {
  8913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8914. return
  8915. }
  8916. }
  8917. func (c *HisApiController) GetHisPrescriptionInfo() {
  8918. id, _ := c.GetInt64("id")
  8919. adminInfo := c.GetAdminUserInfo()
  8920. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8921. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8922. if err == nil {
  8923. c.ServeSuccessJSON(map[string]interface{}{
  8924. "order": prescriptionOrder,
  8925. "prescription": prescription,
  8926. })
  8927. } else {
  8928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8929. return
  8930. }
  8931. }
  8932. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8933. adminUser := c.GetAdminUserInfo()
  8934. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8935. c.ServeSuccessJSON(map[string]interface{}{
  8936. "config": config,
  8937. })
  8938. }
  8939. type ResultTwo struct {
  8940. ErrMsg interface{} `json:"err_msg"`
  8941. InfRefmsgid string `json:"inf_refmsgid"`
  8942. Infcode int64 `json:"infcode"`
  8943. Output struct {
  8944. Baseinfo struct {
  8945. Age float64 `json:"age"`
  8946. Brdy string `json:"brdy"`
  8947. Certno string `json:"certno"`
  8948. Gend string `json:"gend"`
  8949. Naty string `json:"naty"`
  8950. PsnCertType string `json:"psn_cert_type"`
  8951. PsnName string `json:"psn_name"`
  8952. PsnNo string `json:"psn_no"`
  8953. } `json:"baseinfo"`
  8954. Idetinfo []interface{} `json:"idetinfo"`
  8955. Iinfo []struct {
  8956. Balc float64 `json:"balc"`
  8957. CvlservFlag string `json:"cvlserv_flag"`
  8958. EmpName string `json:"emp_name"`
  8959. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8960. Insutype string `json:"insutype"`
  8961. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8962. PausInsuDate interface{} `json:"paus_insu_date"`
  8963. PsnInsuDate string `json:"psn_insu_date"`
  8964. PsnInsuStas string `json:"psn_insu_stas"`
  8965. PsnType string `json:"psn_type"`
  8966. } `json:"insuinfo"`
  8967. } `json:"output"`
  8968. RefmsgTime string `json:"refmsg_time"`
  8969. RespondTime string `json:"respond_time"`
  8970. Signtype interface{} `json:"signtype"`
  8971. WarnInfo interface{} `json:"warn_info"`
  8972. }
  8973. type ResultThree struct {
  8974. Cainfo interface{} `json:"cainfo"`
  8975. ErrMsg interface{} `json:"err_msg"`
  8976. InfRefmsgid string `json:"inf_refmsgid"`
  8977. Infcode int64 `json:"infcode"`
  8978. Output struct {
  8979. Data struct {
  8980. IptOtpNo string `json:"ipt_otp_no"`
  8981. MdtrtID string `json:"mdtrt_id"`
  8982. PsnNo string `json:"psn_no"`
  8983. } `json:"data"`
  8984. } `json:"output"`
  8985. RefmsgTime string `json:"refmsg_time"`
  8986. RespondTime string `json:"respond_time"`
  8987. Signtype interface{} `json:"signtype"`
  8988. WarnMsg interface{} `json:"warn_msg"`
  8989. }
  8990. type ResultFour struct {
  8991. Cainfo string `json:"cainfo"`
  8992. ErrMsg string `json:"err_msg"`
  8993. InfRefmsgid string `json:"inf_refmsgid"`
  8994. Infcode int64 `json:"infcode"`
  8995. Output struct {
  8996. Result []struct {
  8997. BasMednFlag string `json:"bas_medn_flag"`
  8998. ChldMedcFlag string `json:"chld_medc_flag"`
  8999. ChrgitmLv string `json:"chrgitm_lv"`
  9000. Cnt float64 `json:"cnt"`
  9001. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  9002. DrtReimFlag string `json:"drt_reim_flag"`
  9003. FeedetlSn string `json:"feedetl_sn"`
  9004. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9005. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  9006. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9007. ListSpItemFlag string `json:"list_sp_item_flag"`
  9008. LmtUsedFlag string `json:"lmt_used_flag"`
  9009. MedChrgitmType string `json:"med_chrgitm_type"`
  9010. Memo string `json:"memo"`
  9011. OverlmtAmt float64 `json:"overlmt_amt"`
  9012. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9013. Pric float64 `json:"pric"`
  9014. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  9015. SelfpayProp float64 `json:"selfpay_prop"`
  9016. } `json:"result"`
  9017. } `json:"output"`
  9018. RefmsgTime string `json:"refmsg_time"`
  9019. RespondTime string `json:"respond_time"`
  9020. Signtype string `json:"signtype"`
  9021. WarnMsg string `json:"warn_msg"`
  9022. }
  9023. type ResultFive struct {
  9024. Insutype string `json:"insutype"`
  9025. }
  9026. type ResultSix struct {
  9027. Cainfo interface{} `json:"cainfo"`
  9028. ErrMsg interface{} `json:"err_msg"`
  9029. InfRefmsgid string `json:"inf_refmsgid"`
  9030. Infcode int64 `json:"infcode"`
  9031. Output struct {
  9032. } `json:"output"`
  9033. RefmsgTime string `json:"refmsg_time"`
  9034. RespondTime string `json:"respond_time"`
  9035. Signtype interface{} `json:"signtype"`
  9036. WarnMsg interface{} `json:"warn_msg"`
  9037. }
  9038. type ResultSeven struct {
  9039. Cainfo string `json:"cainfo"`
  9040. ErrMsg string `json:"err_msg"`
  9041. InfRefmsgid string `json:"inf_refmsgid"`
  9042. Infcode int64 `json:"infcode"`
  9043. Output struct {
  9044. Setldetail []interface{} `json:"setldetail"`
  9045. Setlinfo struct {
  9046. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9047. AcctPay float64 `json:"acct_pay"`
  9048. ActPayDedc float64 `json:"act_pay_dedc"`
  9049. Age float64 `json:"age"`
  9050. Balc float64 `json:"balc"`
  9051. Brdy string `json:"brdy"`
  9052. Certno string `json:"certno"`
  9053. ClrOptins string `json:"clr_optins"`
  9054. ClrType string `json:"clr_type"`
  9055. ClrWay string `json:"clr_way"`
  9056. CvlservFlag string `json:"cvlserv_flag"`
  9057. CvlservPay float64 `json:"cvlserv_pay"`
  9058. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9059. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9060. Gend string `json:"gend"`
  9061. HifesPay float64 `json:"hifes_pay"`
  9062. HifmiPay float64 `json:"hifmi_pay"`
  9063. HifobPay float64 `json:"hifob_pay"`
  9064. HifpPay float64 `json:"hifp_pay"`
  9065. HospPartAmt float64 `json:"hosp_part_amt"`
  9066. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9067. Insutype string `json:"insutype"`
  9068. MafPay float64 `json:"maf_pay"`
  9069. MdtrtCertType string `json:"mdtrt_cert_type"`
  9070. MdtrtID string `json:"mdtrt_id"`
  9071. MedType string `json:"med_type"`
  9072. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9073. MedinsSetlID string `json:"medins_setl_id"`
  9074. Naty string `json:"naty"`
  9075. OthPay float64 `json:"oth_pay"`
  9076. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9077. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9078. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9079. PsnCashPay float64 `json:"psn_cash_pay"`
  9080. PsnCertType string `json:"psn_cert_type"`
  9081. PsnName string `json:"psn_name"`
  9082. PsnNo string `json:"psn_no"`
  9083. PsnPartAmt float64 `json:"psn_part_amt"`
  9084. PsnType string `json:"psn_type"`
  9085. SetlID string `json:"setl_id"`
  9086. SetlTime string `json:"setl_time"`
  9087. } `json:"setlinfo"`
  9088. } `json:"output"`
  9089. RefmsgTime string `json:"refmsg_time"`
  9090. RespondTime string `json:"respond_time"`
  9091. Signtype interface{} `json:"signtype"`
  9092. WarnMsg interface{} `json:"warn_msg"`
  9093. }
  9094. type ResultEight struct {
  9095. Cainfo string `json:"cainfo"`
  9096. ErrMsg string `json:"err_msg"`
  9097. InfRefmsgid string `json:"inf_refmsgid"`
  9098. Infcode int64 `json:"infcode"`
  9099. Output struct {
  9100. Stmtinfo struct {
  9101. SetlOptins string `json:"setl_optins"`
  9102. StmtRslt string `json:"stmt_rslt"`
  9103. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  9104. } `json:"stmtinfo"`
  9105. } `json:"output"`
  9106. RefmsgTime string `json:"refmsg_time"`
  9107. RespondTime string `json:"respond_time"`
  9108. Signtype interface{} `json:"signtype"`
  9109. WarnMsg interface{} `json:"warn_msg"`
  9110. }
  9111. type ResultNine struct {
  9112. Cainfo string `json:"cainfo"`
  9113. ErrMsg string `json:"err_msg"`
  9114. InfRefmsgid string `json:"inf_refmsgid"`
  9115. Infcode int64 `json:"infcode"`
  9116. Output struct {
  9117. FileQuryNo string `json:"file_qury_no"`
  9118. } `json:"output"`
  9119. RefmsgTime string `json:"refmsg_time"`
  9120. RespondTime string `json:"respond_time"`
  9121. Signtype interface{} `json:"signtype"`
  9122. WarnMsg interface{} `json:"warn_msg"`
  9123. }
  9124. type ResultTen struct {
  9125. Cainfo string `json:"cainfo"`
  9126. ErrMsg string `json:"err_msg"`
  9127. InfRefmsgid string `json:"inf_refmsgid"`
  9128. Infcode int64 `json:"infcode"`
  9129. Output struct {
  9130. DldEndtime string `json:"dld_endtime"`
  9131. FileQuryNo string `json:"file_qury_no"`
  9132. Filename string `json:"filename"`
  9133. } `json:"output"`
  9134. RefmsgTime string `json:"refmsg_time"`
  9135. RespondTime string `json:"respond_time"`
  9136. Signtype interface{} `json:"signtype"`
  9137. WarnMsg interface{} `json:"warn_msg"`
  9138. }
  9139. type ResultEleven struct {
  9140. Cainfo string `json:"cainfo"`
  9141. ErrMsg string `json:"err_msg"`
  9142. InfRefmsgid string `json:"inf_refmsgid"`
  9143. Infcode int64 `json:"infcode"`
  9144. Output struct {
  9145. Setlinfo struct {
  9146. FixmedinsName string `json:"fixmedins_name"`
  9147. FixmedinsCode string `json:"fixmedins_code"`
  9148. PsnNo string `json:"psn_no"`
  9149. PsnName string `json:"psn_name"`
  9150. HifobPay float64 `json:"hifob_pay"`
  9151. Gend string `json:"gend"`
  9152. Brdy string `json:"brdy"`
  9153. PsnCertType string `json:"psn_cert_type"`
  9154. PsnType string `json:"psn_type"`
  9155. EmpName string `json:"emp_name"`
  9156. Certno string `json:"certno"`
  9157. Insutype string `json:"insutype"`
  9158. MedfeeSumamt float64 `json:"medfee_sumamt"`
  9159. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  9160. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  9161. PreselfpayAmt float64 `json:"preselfpay_amt"`
  9162. InscpScpAmt float64 `json:"inscp_scp_amt"`
  9163. ActPayDedc float64 `json:"act_pay_dedc"`
  9164. HifpPay float64 `json:"hifp_pay"`
  9165. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  9166. CvlservPay float64 `json:"cvlserv_pay"`
  9167. HifesPay float64 `json:"hifes_pay"`
  9168. HifmiPay float64 `json:"hifmi_pay"`
  9169. MafPay float64 `json:"maf_pay"`
  9170. OthPay float64 `json:"oth_pay"`
  9171. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  9172. PsnPay float64 `json:"psn_pay"`
  9173. AcctPay float64 `json:"acct_pay"`
  9174. CashPayamt float64 `json:"cash_payamt"`
  9175. Balc float64 `json:"balc"`
  9176. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  9177. MedinsSetlId string `json:"medins_setl_id"`
  9178. RefdSetlFlag string `json:"refd_setl_flag"`
  9179. SetlTime string `json:"setl_time"`
  9180. MedType string `json:"med_type"`
  9181. } `json:"setlinfo"`
  9182. } `json:"output"`
  9183. RefmsgTime string `json:"refmsg_time"`
  9184. RespondTime string `json:"respond_time"`
  9185. Signtype interface{} `json:"signtype"`
  9186. WarnMsg interface{} `json:"warn_msg"`
  9187. }
  9188. type Custom struct {
  9189. DetItemFeeSumamt string
  9190. Cut string
  9191. FeedetlSn string
  9192. Price string
  9193. MedListCodg string
  9194. Type int64
  9195. AdviceId int64
  9196. ProjectId int64
  9197. ItemId int64
  9198. CostType int64
  9199. }
  9200. // 获取个人信息----挂号-----上传就诊信息
  9201. func (c *HisApiController) GetRegisterInfo() {
  9202. id, _ := c.GetInt64("id")
  9203. record_time := c.GetString("record_time")
  9204. settlementValue, _ := c.GetInt64("settlement_value")
  9205. medical_insurance_card := c.GetString("medical_insurance_card")
  9206. name := c.GetString("name")
  9207. id_card_type, _ := c.GetInt64("id_card_type")
  9208. certificates, _ := c.GetInt64("certificates")
  9209. medical_care, _ := c.GetInt64("medical_care")
  9210. birthday := c.GetString("birthday")
  9211. age, _ := c.GetInt64("age")
  9212. id_card := c.GetString("id_card")
  9213. register_type, _ := c.GetInt64("register")
  9214. doctor, _ := c.GetInt64("doctor")
  9215. department, _ := c.GetInt64("department")
  9216. gender, _ := c.GetInt64("sex")
  9217. phone := c.GetString("phone")
  9218. registration_fee, _ := c.GetFloat("registration_fee")
  9219. medical_expenses, _ := c.GetFloat("medical_expenses")
  9220. social_type, _ := c.GetInt64("social_type")
  9221. //diagnosis_id, _ := c.GetInt64("diagnosis")
  9222. diagnosis_ids := c.GetString("diagnosis")
  9223. sick_type, _ := c.GetInt64("sick_type")
  9224. reg_type := c.GetString("p_type")
  9225. timeLayout := "2006-01-02"
  9226. loc, _ := time.LoadLocation("Local")
  9227. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  9228. birthUnix := birthdays.Unix()
  9229. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9230. if err != nil {
  9231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9232. return
  9233. }
  9234. recordDateTime := theTime.Unix()
  9235. adminInfo := c.GetAdminUserInfo()
  9236. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  9237. if tempPatient.ID == 0 {
  9238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  9239. return
  9240. }
  9241. var patient service.Patients
  9242. if id == 0 {
  9243. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  9244. } else {
  9245. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  9246. }
  9247. if patient.ID == 0 {
  9248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9249. return
  9250. }
  9251. if len(patient.IdCardNo) == 0 {
  9252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  9253. return
  9254. }
  9255. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9256. if len(his) >= 1 {
  9257. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  9258. if len(his) >= 1 && order.ID == 0 {
  9259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  9260. return
  9261. }
  9262. }
  9263. timeStr := time.Now().Format("2006-01-02 15:04:05")
  9264. fmt.Println(timeStr)
  9265. timeArr := strings.Split(timeStr, " ")
  9266. fmt.Println(timeArr)
  9267. timeArrTwo := strings.Split(timeArr[0], "-")
  9268. timeArrThree := strings.Split(timeArr[1], ":")
  9269. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  9270. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  9271. if len(lists) == 0 {
  9272. var hisPatient models.XtHisPatient
  9273. hisPatient = models.XtHisPatient{
  9274. Name: name,
  9275. Age: age,
  9276. Gender: gender,
  9277. Birthday: birthUnix,
  9278. Phone: phone,
  9279. MedicalTreatmentType: medical_care,
  9280. IdType: certificates,
  9281. IdCardNo: id_card,
  9282. BalanceAccountsType: settlementValue,
  9283. SocialType: social_type,
  9284. MedicalInsuranceNumber: medical_insurance_card,
  9285. RegisterType: register_type,
  9286. RegisterCost: registration_fee,
  9287. TreatmentCost: medical_expenses,
  9288. AdminUserId: adminInfo.AdminUser.Id,
  9289. UserOrgId: adminInfo.CurrentOrgId,
  9290. Status: 1,
  9291. RecordDate: recordDateTime,
  9292. IsReturn: 1,
  9293. PatientId: patient.ID,
  9294. Ctime: time.Now().Unix(),
  9295. Mtime: time.Now().Unix(),
  9296. Number: str,
  9297. IdCardType: id_card_type,
  9298. Departments: department,
  9299. Doctor: doctor,
  9300. PType: reg_type,
  9301. Diagnosis: diagnosis_ids,
  9302. SickType: sick_type,
  9303. }
  9304. service.CreateHisPatient(&hisPatient)
  9305. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9306. c.ServeSuccessJSON(map[string]interface{}{
  9307. "his_info": hisPatient,
  9308. })
  9309. } else {
  9310. //chrgBchno := rand.Intn(1000000) + 10000
  9311. var hisPatient models.XtHisPatient
  9312. hisPatient = models.XtHisPatient{
  9313. Name: name,
  9314. Age: age,
  9315. Gender: gender,
  9316. Birthday: birthUnix,
  9317. Phone: phone,
  9318. MedicalTreatmentType: medical_care,
  9319. IdType: certificates,
  9320. IdCardNo: id_card,
  9321. BalanceAccountsType: settlementValue,
  9322. SocialType: social_type,
  9323. MedicalInsuranceNumber: medical_insurance_card,
  9324. RegisterType: register_type,
  9325. RegisterCost: registration_fee,
  9326. TreatmentCost: medical_expenses,
  9327. AdminUserId: adminInfo.AdminUser.Id,
  9328. UserOrgId: adminInfo.CurrentOrgId,
  9329. Status: 1,
  9330. RecordDate: recordDateTime,
  9331. IsReturn: 1,
  9332. PatientId: patient.ID,
  9333. Ctime: time.Now().Unix(),
  9334. Mtime: time.Now().Unix(),
  9335. Number: str,
  9336. IdCardType: id_card_type,
  9337. Departments: department,
  9338. Doctor: doctor,
  9339. PType: reg_type,
  9340. Diagnosis: diagnosis_ids,
  9341. SickType: sick_type,
  9342. }
  9343. service.CreateHisPatient(&hisPatient)
  9344. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  9345. c.ServeSuccessJSON(map[string]interface{}{
  9346. "his_info": hisPatient,
  9347. })
  9348. }
  9349. }
  9350. // 上传明细----结算
  9351. func (c *HisApiController) GetUploadInfo() {
  9352. id, _ := c.GetInt64("id")
  9353. record_time := c.GetString("record_time")
  9354. his_patient_id, _ := c.GetInt64("his_patient_id")
  9355. oth_desc := c.GetString("oth_desc")
  9356. pay_way, _ := c.GetInt64("pay_way")
  9357. pay_ways := c.GetString("pay_ways")
  9358. pay_price, _ := c.GetFloat("pay_price")
  9359. pay_card_no := c.GetString("pay_card_no")
  9360. discount_price, _ := c.GetFloat("discount_price")
  9361. preferential_price, _ := c.GetFloat("preferential_price")
  9362. reality_price, _ := c.GetFloat("reality_price")
  9363. found_price, _ := c.GetFloat("found_price")
  9364. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  9365. private_price, _ := c.GetFloat("private_price")
  9366. timeLayout := "2006-01-02"
  9367. loc, _ := time.LoadLocation("Local")
  9368. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9369. fapiao_code := c.GetString("fapiao_code")
  9370. fapiao_number := c.GetString("fapiao_number")
  9371. diagnosis_id := c.GetString("diagnosis")
  9372. sick_type, _ := c.GetInt64("sick_type")
  9373. reg_type, _ := c.GetInt64("p_type")
  9374. order_id, _ := c.GetInt64("order_id")
  9375. cash_pay := c.GetString("cash_pay")
  9376. wechat_pay := c.GetString("wechat_pay")
  9377. ali_pay := c.GetString("ali_pay")
  9378. jifen_pay := c.GetString("jifen_pay")
  9379. card_desc := c.GetString("card_desc")
  9380. band_card_pay := c.GetString("band_card_pay")
  9381. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  9382. tmp_decimal := c.GetString("tmp_decimal")
  9383. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  9384. var decimal float64 //本次使用的押金
  9385. var errmsg error
  9386. tx := service.XTWriteDB().Begin() //开了事务
  9387. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  9388. defer func() {
  9389. if errmsg != nil {
  9390. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  9391. tx.Rollback()
  9392. } else {
  9393. tx.Commit()
  9394. }
  9395. }()
  9396. fmt.Println("dec_way", dec_way)
  9397. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  9398. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  9399. return
  9400. }
  9401. if len(tmp_decimal) > 0 {
  9402. if tmp_decimal[0] == 45 {
  9403. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  9404. return
  9405. }
  9406. }
  9407. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  9408. fmt.Println(errs)
  9409. decimal = tt
  9410. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  9411. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  9412. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9413. if err != nil {
  9414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9415. return
  9416. }
  9417. recordDateTime := theTime.Unix()
  9418. adminUser := c.GetAdminUserInfo()
  9419. var prescriptions []*models.HisPrescription
  9420. var prescriptionsOne []*models.HisPrescription
  9421. var start_time int64
  9422. var end_time int64
  9423. ids_str := c.GetString("ids")
  9424. ids_arr := strings.Split(ids_str, ",")
  9425. if tempOrder.ID == 0 {
  9426. if settle_accounts_type == 1 { //日结
  9427. fmt.Println(reg_type)
  9428. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9429. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  9430. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  9431. } else {
  9432. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9433. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9434. }
  9435. } else { //月结
  9436. start_time_str := c.GetString("start_time")
  9437. end_time_str := c.GetString("end_time")
  9438. timeLayout := "2006-01-02"
  9439. loc, _ := time.LoadLocation("Local")
  9440. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9441. if err != nil {
  9442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9443. return
  9444. }
  9445. recordStartTime := theStartTime.Unix()
  9446. start_time = recordStartTime
  9447. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9448. if err != nil {
  9449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9450. return
  9451. }
  9452. recordEndTime := theEndTime.Unix()
  9453. end_time = recordEndTime
  9454. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  9455. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  9456. }
  9457. var goods []*models.DialysisBeforePrepareGoods
  9458. var newGoods []*models.NewDialysisBeforePrepareGoods
  9459. var oldGoods []*models.OldDialysisBeforePrepareGoods
  9460. var infos []*models.HisDoctorAdviceInfo
  9461. var infoList []*models.HisDoctorAdviceInfo
  9462. var hisAdvice []*models.HisDoctorAdviceInfo
  9463. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  9464. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  9465. //判断库存不足
  9466. //结算出库开关
  9467. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9468. if settConfig.IsOpen == 1 {
  9469. //判断库存的地方
  9470. for _, info := range prescriptions {
  9471. if info.Type == 1 {
  9472. infos = append(infos, info.HisDoctorAdviceInfo...)
  9473. }
  9474. if info.Type == 2 {
  9475. for _, sumItem := range info.HisPrescriptionProject {
  9476. if sumItem.Type == 3 {
  9477. var good models.DialysisBeforePrepareGoods
  9478. var newGood models.NewDialysisBeforePrepareGoods
  9479. good.GoodId = sumItem.GoodInfo.ID
  9480. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9481. count, _ := strconv.Atoi(sumItem.Count)
  9482. good.Count = int64(count)
  9483. good.StorehouseId = houseConfig.StorehouseOutInfo
  9484. good.ProjectId = sumItem.ID
  9485. goods = append(goods, &good)
  9486. newGood.GoodId = sumItem.GoodInfo.ID
  9487. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9488. count2, _ := strconv.Atoi(sumItem.Count)
  9489. newGood.Count = int64(count2)
  9490. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9491. newGood.ProjectId = sumItem.ID
  9492. newGoods = append(newGoods, &newGood)
  9493. }
  9494. }
  9495. }
  9496. }
  9497. for _, info := range prescriptionsOne {
  9498. if info.Type == 1 {
  9499. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  9500. }
  9501. if info.Type == 2 {
  9502. for _, sumItem := range info.HisPrescriptionProject {
  9503. if sumItem.Type == 3 {
  9504. var newGood models.NewDialysisBeforePrepareGoods
  9505. newGood.GoodId = sumItem.GoodInfo.ID
  9506. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9507. count2, _ := strconv.Atoi(sumItem.Count)
  9508. newGood.Count = int64(count2)
  9509. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9510. newGood.ProjectId = sumItem.ID
  9511. newGoodOne = append(newGoodOne, &newGood)
  9512. }
  9513. }
  9514. }
  9515. }
  9516. //判断
  9517. for _, itemOne := range infos {
  9518. for _, itemTwo := range hisAdvice {
  9519. if itemOne.DrugId == itemTwo.DrugId {
  9520. itemTwo.Child = append(itemTwo.Child, itemOne)
  9521. }
  9522. }
  9523. }
  9524. for _, itemTwo := range hisAdvice {
  9525. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  9526. var sum_out_count int64
  9527. for _, itemThree := range itemTwo.Child {
  9528. var prescribing_number int64
  9529. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9530. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9531. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9532. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9533. }
  9534. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9535. prescribing_number = parseIntPrescribingNumber
  9536. }
  9537. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9538. prescribing_number = parseIntPrescribingNumber
  9539. }
  9540. sum_out_count += prescribing_number
  9541. }
  9542. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  9543. if sum_out_count > drugStockOut.FlushCount {
  9544. c.ServeSuccessJSON(map[string]interface{}{
  9545. "msg": "2",
  9546. "drug": medical,
  9547. })
  9548. return
  9549. }
  9550. }
  9551. for _, itemOne := range newGoods {
  9552. for _, item := range newGoodOne {
  9553. if itemOne.GoodId == item.GoodId {
  9554. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  9555. }
  9556. }
  9557. }
  9558. for _, item := range newGoodOne {
  9559. var sum_out_count_one int64
  9560. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  9561. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  9562. sum_out_count_one += itemOne.Count
  9563. }
  9564. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9565. fmt.Println("sum_out_count_one", sum_out_count_one)
  9566. fmt.Println("list.FlushCount", list.FlushCount)
  9567. if sum_out_count_one > list.FlushCount {
  9568. c.ServeSuccessJSON(map[string]interface{}{
  9569. "msg": "3",
  9570. "good": good,
  9571. })
  9572. return
  9573. }
  9574. }
  9575. }
  9576. timestamp := time.Now().Unix()
  9577. tempTime := time.Unix(timestamp, 0)
  9578. timeFormat := tempTime.Format("20060102150405")
  9579. chrgBchno := rand.Intn(100000) + 10000
  9580. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9581. strconv.FormatInt(his.PatientId, 10)
  9582. var ids []int64
  9583. for _, item := range prescriptions {
  9584. ids = append(ids, item.ID)
  9585. }
  9586. var total float64
  9587. for _, item := range prescriptions {
  9588. fmt.Println(item)
  9589. if item.Type == 1 { //药品
  9590. for _, subItem := range item.HisDoctorAdviceInfo {
  9591. if subItem.Drug.IsUser != 1 {
  9592. total = total + (subItem.Price * subItem.PrescribingNumber)
  9593. }
  9594. }
  9595. }
  9596. if item.Type == 2 { //项目
  9597. for _, subItem := range item.HisPrescriptionProject {
  9598. if subItem.Type == 2 {
  9599. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9600. total = total + (subItem.Price * cnt)
  9601. } else {
  9602. if subItem.GoodInfo.IsUser != 1 {
  9603. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9604. total = total + (subItem.Price * cnt)
  9605. }
  9606. }
  9607. }
  9608. }
  9609. for _, subItem := range item.HisAdditionalCharge {
  9610. total = total + (subItem.Price * float64(subItem.Count))
  9611. }
  9612. }
  9613. if reg_type == 1111 || reg_type == 1112 {
  9614. reg_type = 11
  9615. }
  9616. tm := time.Unix(time.Now().Unix(), 0)
  9617. allTotal := fmt.Sprintf("%.4f", total)
  9618. totals, _ := strconv.ParseFloat(allTotal, 64)
  9619. order := &models.HisOrder{
  9620. UserOrgId: adminUser.CurrentOrgId,
  9621. HisPatientId: his.ID,
  9622. PatientId: id,
  9623. SettleAccountsDate: recordDateTime,
  9624. Ctime: time.Now().Unix(),
  9625. Mtime: time.Now().Unix(),
  9626. Status: 1,
  9627. OrderStatus: 2,
  9628. MdtrtId: his.Number,
  9629. Number: chrg_bchno,
  9630. MedfeeSumamt: totals,
  9631. PayWay: pay_way,
  9632. PayWays: pay_ways,
  9633. PayPrice: pay_price,
  9634. MedType: strconv.Itoa(int(reg_type)),
  9635. PayCardNo: pay_card_no,
  9636. DiscountPrice: discount_price,
  9637. PreferentialPrice: preferential_price,
  9638. RealityPrice: reality_price,
  9639. FoundPrice: found_price,
  9640. MedicalInsurancePrice: medical_insurance_price,
  9641. PrivatePrice: private_price,
  9642. SettleEndTime: end_time,
  9643. SettleStartTime: start_time,
  9644. PsnPartAmt: totals,
  9645. PsnCashPay: totals,
  9646. SettleType: settle_accounts_type,
  9647. FaPiaoCode: fapiao_code,
  9648. FaPiaoNumber: fapiao_number,
  9649. Diagnosis: diagnosis_id,
  9650. PType: 2,
  9651. SetlTime: tm.Format("2006-01-02 15:04:05"),
  9652. Decimal: decimal,
  9653. OthDesc: oth_desc,
  9654. CashPay: cash_pay,
  9655. WechatPay: wechat_pay,
  9656. AliPay: ali_pay,
  9657. JifenPay: jifen_pay,
  9658. BandCardPay: band_card_pay,
  9659. Creator: adminUser.AdminUser.Id,
  9660. CardDesc: card_desc,
  9661. }
  9662. err = service.CreateOrderTX(order, tx)
  9663. if err != nil {
  9664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9665. return
  9666. }
  9667. var customs []*Custom
  9668. for _, item := range prescriptions {
  9669. if item.Type == 1 { //药品a
  9670. for _, subItem := range item.HisDoctorAdviceInfo {
  9671. if subItem.Drug.IsUser != 1 {
  9672. cus := &Custom{
  9673. AdviceId: subItem.ID,
  9674. ProjectId: 0,
  9675. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  9676. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  9677. FeedetlSn: subItem.FeedetlSn,
  9678. Price: fmt.Sprintf("%.4f", subItem.Price),
  9679. MedListCodg: subItem.MedListCodg,
  9680. Type: 1,
  9681. CostType: 9,
  9682. }
  9683. customs = append(customs, cus)
  9684. }
  9685. }
  9686. }
  9687. if item.Type == 2 { //项目
  9688. for _, subItem := range item.HisPrescriptionProject {
  9689. if subItem.Type == 2 {
  9690. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9691. cus := &Custom{
  9692. AdviceId: 0,
  9693. ProjectId: subItem.ID,
  9694. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9695. Cut: fmt.Sprintf("%.4f", cnt),
  9696. FeedetlSn: subItem.FeedetlSn,
  9697. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9698. MedListCodg: subItem.MedListCodg,
  9699. Type: 2,
  9700. CostType: subItem.HisProject.CostClassify,
  9701. }
  9702. customs = append(customs, cus)
  9703. } else {
  9704. if subItem.GoodInfo.IsUser != 1 {
  9705. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9706. cus := &Custom{
  9707. AdviceId: 0,
  9708. ProjectId: subItem.ID,
  9709. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  9710. Cut: fmt.Sprintf("%.4f", cnt),
  9711. FeedetlSn: subItem.FeedetlSn,
  9712. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  9713. MedListCodg: subItem.MedListCodg,
  9714. Type: 2,
  9715. CostType: subItem.HisProject.CostClassify,
  9716. }
  9717. customs = append(customs, cus)
  9718. }
  9719. }
  9720. }
  9721. }
  9722. for _, item := range item.HisAdditionalCharge {
  9723. cus := &Custom{
  9724. ItemId: item.ID,
  9725. AdviceId: 0,
  9726. ProjectId: 0,
  9727. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  9728. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  9729. FeedetlSn: item.FeedetlSn,
  9730. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  9731. MedListCodg: item.XtHisAddtionConfig.Code,
  9732. Type: 3,
  9733. CostType: 5,
  9734. }
  9735. customs = append(customs, cus)
  9736. }
  9737. }
  9738. for _, item := range customs {
  9739. var advice_id int64 = 0
  9740. var project_id int64 = 0
  9741. var item_id int64 = 0
  9742. var types int64 = 0
  9743. var med_chrgitm_type string
  9744. if item.Type == 1 {
  9745. advice_id = item.AdviceId
  9746. project_id = 0
  9747. item_id = 0
  9748. med_chrgitm_type = "09"
  9749. } else if item.Type == 2 {
  9750. med_chrgitm_type = "05"
  9751. if item.CostType == 3 {
  9752. med_chrgitm_type = "04"
  9753. }
  9754. if item.CostType == 8 {
  9755. med_chrgitm_type = "03"
  9756. }
  9757. advice_id = 0
  9758. item_id = 0
  9759. project_id = item.ProjectId
  9760. } else if item.Type == 3 {
  9761. advice_id = 0
  9762. item_id = item.ItemId
  9763. project_id = 0
  9764. med_chrgitm_type = "08"
  9765. }
  9766. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9767. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9768. pric, _ := strconv.ParseFloat(item.Price, 32)
  9769. info := &models.HisOrderInfo{
  9770. OrderNumber: order.Number,
  9771. UploadDate: time.Now().Unix(),
  9772. AdviceId: advice_id,
  9773. DetItemFeeSumamt: detItemFeeSumamt,
  9774. MedChrgitmType: med_chrgitm_type,
  9775. Cnt: cut,
  9776. Pric: pric,
  9777. PatientId: id,
  9778. Status: 1,
  9779. Mtime: time.Now().Unix(),
  9780. Ctime: time.Now().Unix(),
  9781. UserOrgId: adminUser.CurrentOrgId,
  9782. HisPatientId: his.ID,
  9783. OrderId: order.ID,
  9784. ProjectId: project_id,
  9785. Type: types,
  9786. ItemId: item_id,
  9787. }
  9788. service.CreateOrderInfoTX(info, tx)
  9789. }
  9790. his.Diagnosis = diagnosis_id
  9791. his.SickType = sick_type
  9792. his.RegisterType = reg_type
  9793. his.MedicalTreatmentType = reg_type
  9794. service.UpdataHisPateintTX(&his, tx)
  9795. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  9796. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  9797. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  9798. //判断是否使用了押金
  9799. if dec_way == "true" {
  9800. tmpstring := strconv.FormatInt(order.ID, 10)
  9801. //扣押金
  9802. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  9803. order.Decimal = decimal
  9804. service.UpDateOrderTwo(order, tx)
  9805. if errmsg != nil {
  9806. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  9807. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9808. return
  9809. }
  9810. }
  9811. if err == nil {
  9812. for _, info := range prescriptions {
  9813. if info.Type == 1 {
  9814. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  9815. }
  9816. if info.Type == 2 {
  9817. for _, sumItem := range info.HisPrescriptionProject {
  9818. if sumItem.Type == 3 {
  9819. var good models.DialysisBeforePrepareGoods
  9820. var newGood models.NewDialysisBeforePrepareGoods
  9821. var oldGood models.OldDialysisBeforePrepareGoods
  9822. good.GoodId = sumItem.GoodInfo.ID
  9823. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9824. count, _ := strconv.Atoi(sumItem.Count)
  9825. good.Count = int64(count)
  9826. good.StorehouseId = houseConfig.StorehouseOutInfo
  9827. good.ProjectId = sumItem.ID
  9828. good.PatientId = sumItem.PatientId
  9829. goods = append(goods, &good)
  9830. newGood.GoodId = sumItem.GoodInfo.ID
  9831. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9832. count2, _ := strconv.Atoi(sumItem.Count)
  9833. newGood.Count = int64(count2)
  9834. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9835. newGood.ProjectId = sumItem.ID
  9836. newGood.PatientId = sumItem.HisPatientId
  9837. newGoods = append(newGoods, &newGood)
  9838. oldGood.GoodId = sumItem.GoodInfo.ID
  9839. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  9840. count3, _ := strconv.Atoi(sumItem.Count)
  9841. oldGood.Count = int64(count3)
  9842. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  9843. oldGood.ProjectId = sumItem.ID
  9844. oldGood.RecordDate = sumItem.RecordDate
  9845. oldGood.PatientId = sumItem.HisPatientId
  9846. oldGoods = append(oldGoods, &oldGood)
  9847. }
  9848. }
  9849. }
  9850. }
  9851. if settConfig.IsOpen == 1 {
  9852. for _, item := range infoList {
  9853. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9854. if medical.IsUse == 2 {
  9855. //药品出库
  9856. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  9857. //查询默认仓库
  9858. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  9859. //查询默认仓库剩余多少库存
  9860. var sum_count int64
  9861. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9862. for _, its := range stockInfo {
  9863. if its.MaxUnit == medical.MaxUnit {
  9864. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9865. }
  9866. sum_count += its.StockMaxNumber + its.StockMinNumber
  9867. }
  9868. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9869. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9870. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  9871. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  9872. }
  9873. }
  9874. orgId := c.GetAdminUserInfo().CurrentOrgId
  9875. if len(oldGoods) > 0 {
  9876. timeStr := time.Now().Format("2006-01-02")
  9877. timeArr := strings.Split(timeStr, "-")
  9878. total, _ := service.FindAllWarehouseOut(orgId)
  9879. total = total + 1
  9880. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  9881. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  9882. number = number + total
  9883. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  9884. operation_time := time.Now().Unix()
  9885. creater := c.GetAdminUserInfo().AdminUser.Id
  9886. //查询默认出库仓库库存
  9887. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9888. recordDateStr := time.Now().Format("2006-01-02")
  9889. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9890. nowtime := recordDate.Unix()
  9891. warehouseOut := models.WarehouseOut{
  9892. WarehouseOutOrderNumber: warehousing_out_order,
  9893. OperationTime: operation_time,
  9894. OrgId: orgId,
  9895. Creater: creater,
  9896. Ctime: time.Now().Unix(),
  9897. Status: 1,
  9898. WarehouseOutTime: nowtime,
  9899. Type: 1,
  9900. StorehouseId: storeConfig.StorehouseOutInfo,
  9901. IsCheck: 1,
  9902. OrderId: order.ID,
  9903. IsSys: 5,
  9904. }
  9905. //查询是否生成出库单
  9906. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9907. if out.ID == 0 {
  9908. service.AddSigleWarehouseOutOne(&warehouseOut)
  9909. }
  9910. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  9911. for _, item := range oldGoods {
  9912. dialyPrepareOne := models.DialysisBeforePrepare{
  9913. GoodTypeId: item.GoodTypeId,
  9914. GoodId: item.GoodId,
  9915. PatientId: his.PatientId,
  9916. RecordDate: item.RecordDate,
  9917. UserOrgId: adminUser.CurrentOrgId,
  9918. Count: item.Count,
  9919. Ctime: time.Now().Unix(),
  9920. Creater: adminUser.AdminUser.Id,
  9921. CommdityCode: item.CommdityCode,
  9922. Status: 1,
  9923. StorehouseId: houseConfig.StorehouseOutInfo,
  9924. }
  9925. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  9926. //非零用
  9927. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  9928. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9929. //查询剩余库存
  9930. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9931. var sum_count int64
  9932. for _, item := range goodList {
  9933. sum_count += item.StockCount
  9934. }
  9935. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9936. //耗材
  9937. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9938. }
  9939. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  9940. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  9941. //查询剩余库存
  9942. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  9943. var sum_count int64
  9944. for _, item := range goodList {
  9945. sum_count += item.StockCount
  9946. }
  9947. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  9948. //耗材
  9949. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  9950. }
  9951. }
  9952. }
  9953. }
  9954. c.ServeSuccessJSON(map[string]interface{}{
  9955. "msg": "结算成功",
  9956. })
  9957. }
  9958. }
  9959. }
  9960. // 退款
  9961. func (c *HisApiController) Refund() {
  9962. order_id, _ := c.GetInt64("order_id")
  9963. order, _ := service.GetHisOrderByID(order_id)
  9964. adminUser := c.GetAdminUserInfo()
  9965. orgid := c.GetAdminUserInfo().CurrentOrgId
  9966. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9967. if err != nil {
  9968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9969. return
  9970. }
  9971. tmp := strconv.FormatInt(order.ID, 10)
  9972. //当押金不为零时产生退费记录
  9973. if order.Decimal != 0 {
  9974. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9975. if err != nil {
  9976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9977. return
  9978. }
  9979. }
  9980. fapiao, _ := service.GetFaPiaoHisOrderByID(order_id)
  9981. if fapiao.ID > 0 {
  9982. c.ServeSuccessJSON(map[string]interface{}{
  9983. "failed_code": -10,
  9984. "msg": "该结算已经开具发票无法退费,请先红冲发票",
  9985. })
  9986. return
  9987. }
  9988. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9989. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9990. var goods []*models.DialysisBeforePrepareGoods
  9991. var newGoods []*models.NewDialysisBeforePrepareGoods
  9992. var infos []*models.HisDoctorAdviceInfo
  9993. for _, info := range orders {
  9994. if info.AdviceId > 0 && info.ProjectId == 0 {
  9995. infos = append(infos, &info.HisDoctorAdviceInfo)
  9996. }
  9997. if info.ProjectId > 0 && info.AdviceId == 0 {
  9998. if info.HisPrescriptionProject.Type == 3 {
  9999. var good models.DialysisBeforePrepareGoods
  10000. var newGood models.NewDialysisBeforePrepareGoods
  10001. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10002. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10003. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10004. good.Count = int64(count)
  10005. good.StorehouseId = houseConfig.StorehouseOutInfo
  10006. good.ProjectId = info.HisPrescriptionProject.ID
  10007. good.PatientId = info.PatientId
  10008. good.OrderId = order_id
  10009. goods = append(goods, &good)
  10010. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  10011. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  10012. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  10013. newGood.Count = int64(count2)
  10014. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  10015. newGood.ProjectId = info.HisPrescriptionProject.ID
  10016. newGood.RecordDate = order.SettleAccountsDate
  10017. newGood.UserOrgId = order.UserOrgId
  10018. newGood.PatientId = info.PatientId
  10019. newGood.OrderId = order_id
  10020. newGoods = append(newGoods, &newGood)
  10021. }
  10022. }
  10023. }
  10024. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  10025. if settConfig.IsOpen == 1 {
  10026. for _, item := range infos {
  10027. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10028. }
  10029. for _, item := range newGoods {
  10030. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  10031. }
  10032. }
  10033. c.ServeSuccessJSON(map[string]interface{}{
  10034. "msg": "退费成功",
  10035. })
  10036. }
  10037. func (c *HisApiController) RefundNumber() {
  10038. his_patient_id, _ := c.GetInt64("id")
  10039. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10040. info.Status = 0
  10041. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  10042. if count > 0 {
  10043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  10044. return
  10045. }
  10046. err := service.SaveHisPatient(info)
  10047. if err == nil {
  10048. c.ServeSuccessJSON(map[string]interface{}{
  10049. "msg": "退号成功",
  10050. })
  10051. } else {
  10052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10053. return
  10054. }
  10055. }
  10056. func (this *HisApiController) AdditionalCharge() {
  10057. dataBody := make(map[string]interface{}, 0)
  10058. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10059. fmt.Println(err)
  10060. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  10061. patient_id := int64(dataBody["patient_id"].(float64))
  10062. medicineData, _ := dataBody["medicineData"].([]interface{})
  10063. adminUserInfo := this.GetAdminUserInfo()
  10064. orgId := adminUserInfo.CurrentOrgId
  10065. admin_user_id := adminUserInfo.AdminUser.Id
  10066. timeStr := time.Now().Format("2006-01-02")
  10067. timeLayout := "2006-01-02 15:04:05"
  10068. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10069. timenow := timeStringToTime.Unix()
  10070. var additionalCharges []*models.HisAdditionalCharge
  10071. for _, item := range medicineData {
  10072. var randNum int
  10073. randNum = rand.Intn(10000) + 1000
  10074. timestamp := time.Now().Unix()
  10075. tempTime := time.Unix(timestamp, 0)
  10076. timeFormat := tempTime.Format("20060102150405")
  10077. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  10078. items := item.(map[string]interface{})
  10079. money := items["price"].(string)
  10080. item_id_str := items["item_id"].(string)
  10081. name := items["name"].(string)
  10082. id_str := items["id"].(string)
  10083. moneys, _ := strconv.ParseInt(money, 10, 64)
  10084. monStr := strconv.FormatInt(moneys, 10)
  10085. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  10086. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  10087. id, _ := strconv.ParseInt(id_str, 10, 64)
  10088. additionalCharge := &models.HisAdditionalCharge{
  10089. ID: id,
  10090. HisPatientId: his_patient_id,
  10091. UserOrgId: orgId,
  10092. PatientId: patient_id,
  10093. RecordDate: timenow,
  10094. Price: monneyStr,
  10095. Status: 1,
  10096. ItemName: name,
  10097. ItemId: item_id,
  10098. AdminUserId: admin_user_id,
  10099. CreatedTime: time.Now().Unix(),
  10100. OrderStatus: 0,
  10101. PrescriptionNumber: "",
  10102. BatchNumber: "",
  10103. FeedetlSn: p_number,
  10104. }
  10105. service.CreateAdditionalCharge(additionalCharge)
  10106. additionalCharges = append(additionalCharges, additionalCharge)
  10107. }
  10108. this.ServeSuccessJSON(map[string]interface{}{
  10109. "msg": "添加成功",
  10110. "additional_charges": additionalCharges,
  10111. })
  10112. }
  10113. func (this *HisApiController) DeleteAddition() {
  10114. id, _ := this.GetInt64("id")
  10115. //TODO 需要判断是否已经结算
  10116. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  10117. if err == nil {
  10118. this.ServeSuccessJSON(map[string]interface{}{
  10119. "msg": "删除成功",
  10120. })
  10121. return
  10122. } else {
  10123. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10124. return
  10125. }
  10126. }
  10127. func (this *HisApiController) GetAdminUsers() {
  10128. adminUser := this.GetAdminUserInfo()
  10129. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  10130. this.ServeSuccessJSON(map[string]interface{}{
  10131. "doctors": doctors,
  10132. })
  10133. }
  10134. func (this *HisApiController) GetLastOrNextHisPrescription() {
  10135. change_type, _ := this.GetInt64("type", 0)
  10136. record_date := this.GetString("record_time")
  10137. patient_id, _ := this.GetInt64("patient_id", 0)
  10138. p_type, _ := this.GetInt64("p_type", 0)
  10139. timeLayout := "2006-01-02"
  10140. loc, _ := time.LoadLocation("Local")
  10141. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  10142. record_time := theAdviceRecordTime.Unix()
  10143. adminUserInfo := this.GetAdminUserInfo()
  10144. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  10145. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10146. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10147. if config.ID > 0 && config.IsOpen == 1 {
  10148. for _, subitems := range prescriptions {
  10149. for _, item := range subitems.VMHisPrescription {
  10150. for _, subItem := range item.HisDoctorAdviceInfo {
  10151. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10152. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10153. if info.RetailPrice > 0 {
  10154. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10155. subItem.Drug.RetailPrice = drug.RetailPrice
  10156. }
  10157. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10158. subItem.Drug.MinPrice = info.RetailPrice
  10159. subItem.Drug.RetailPrice = info.RetailPrice
  10160. }
  10161. }
  10162. }
  10163. }
  10164. }
  10165. }
  10166. if config.ID > 0 && config.IsOpen == 1 {
  10167. for _, subitems := range prescriptions {
  10168. for _, item := range subitems.VMHisPrescription {
  10169. for _, subItem := range item.HisPrescriptionProject {
  10170. if subItem.Type == 3 {
  10171. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10172. if info.Price > 0 {
  10173. subItem.GoodInfo.PackingPrice = info.Price
  10174. }
  10175. }
  10176. }
  10177. }
  10178. }
  10179. }
  10180. }
  10181. if err == nil {
  10182. if len(prescriptions) == 0 {
  10183. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  10184. return
  10185. } else {
  10186. this.ServeSuccessJSON(map[string]interface{}{
  10187. "prescriptions": prescriptions,
  10188. })
  10189. return
  10190. }
  10191. } else {
  10192. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10193. return
  10194. }
  10195. }
  10196. func RemoveRepeatedPurviewElementByHP(arr []service.VMOtherHisPrescriptionInfo) (newArr []service.VMOtherHisPrescriptionInfo) {
  10197. newArr = make([]service.VMOtherHisPrescriptionInfo, 0)
  10198. for i := 0; i < len(arr); i++ {
  10199. repeat := false
  10200. for j := i + 1; j < len(arr); j++ {
  10201. if arr[i].PatientId == arr[j].PatientId && arr[i].RecordDate == arr[j].RecordDate {
  10202. repeat = true
  10203. break
  10204. }
  10205. }
  10206. if !repeat {
  10207. newArr = append(newArr, arr[i])
  10208. }
  10209. }
  10210. return
  10211. }
  10212. func (this *HisApiController) GetCallHisPrescription() {
  10213. patient_id, _ := this.GetInt64("patient_id", 0)
  10214. timeLayout := "2006-01-02"
  10215. loc, _ := time.LoadLocation("Local")
  10216. start_time := this.GetString("start_time")
  10217. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10218. end_time := this.GetString("end_time")
  10219. p_type, _ := this.GetInt64("p_type")
  10220. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10221. adminUserInfo := this.GetAdminUserInfo()
  10222. new_prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  10223. prescriptions := RemoveRepeatedPurviewElementByHP(new_prescriptions)
  10224. //if
  10225. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  10226. //
  10227. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  10228. if adminUserInfo.CurrentOrgId == 10265 || adminUserInfo.CurrentOrgId == 10489 {
  10229. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  10230. if config.ID > 0 && config.IsOpen == 1 {
  10231. for _, subitems := range prescriptions {
  10232. for _, item := range subitems.VMHisPrescription {
  10233. for _, subItem := range item.HisDoctorAdviceInfo {
  10234. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  10235. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  10236. if info.RetailPrice > 0 {
  10237. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  10238. subItem.Drug.RetailPrice = drug.RetailPrice
  10239. }
  10240. if subItem.PrescribingNumberUnit == drug.MinUnit {
  10241. subItem.Drug.MinPrice = info.RetailPrice
  10242. subItem.Drug.RetailPrice = info.RetailPrice
  10243. }
  10244. }
  10245. }
  10246. }
  10247. }
  10248. }
  10249. if config.ID > 0 && config.IsOpen == 1 {
  10250. for _, subitems := range prescriptions {
  10251. for _, item := range subitems.VMHisPrescription {
  10252. for _, subItem := range item.HisPrescriptionProject {
  10253. if subItem.Type == 3 {
  10254. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  10255. if info.Price > 0 {
  10256. subItem.GoodInfo.PackingPrice = info.Price
  10257. }
  10258. }
  10259. }
  10260. }
  10261. }
  10262. }
  10263. }
  10264. if err == nil {
  10265. this.ServeSuccessJSON(map[string]interface{}{
  10266. "prescriptions": prescriptions,
  10267. })
  10268. return
  10269. } else {
  10270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10271. return
  10272. }
  10273. }
  10274. func (this *HisApiController) GetHisDayPrescription() {
  10275. timeLayout := "2006-01-02"
  10276. loc, _ := time.LoadLocation("Local")
  10277. start_time := this.GetString("start_time")
  10278. patient_id, _ := this.GetInt64("patient_id", 0)
  10279. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10280. end_time := this.GetString("end_time")
  10281. p_type, _ := this.GetInt64("p_type")
  10282. order_status, _ := this.GetInt64("type")
  10283. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10284. adminUserInfo := this.GetAdminUserInfo()
  10285. var dayHisPrescription []*models.HisPrescription
  10286. var err error
  10287. if order_status == 1 || order_status == 0 {
  10288. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10289. } else if order_status == 2 {
  10290. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  10291. }
  10292. var settle_total float64
  10293. for _, item := range dayHisPrescription {
  10294. if len(item.HisPrescriptionProject) > 0 {
  10295. for _, subItem := range item.HisPrescriptionProject {
  10296. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10297. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10298. settle_total = settle_total + total
  10299. }
  10300. }
  10301. if len(item.HisDoctorAdviceInfo) > 0 {
  10302. for _, subItem := range item.HisDoctorAdviceInfo {
  10303. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10304. settle_total = settle_total + total
  10305. }
  10306. }
  10307. }
  10308. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10309. if err == nil {
  10310. this.ServeSuccessJSON(map[string]interface{}{
  10311. "day_prescription": dayHisPrescription,
  10312. "settle_total": settle_total,
  10313. })
  10314. return
  10315. } else {
  10316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10317. return
  10318. }
  10319. }
  10320. func (c *HisApiController) GetHisChargePatientList() {
  10321. record_date := c.GetString("record_date")
  10322. order_status, _ := c.GetInt64("type")
  10323. sch_type, _ := c.GetInt64("sch_type")
  10324. timeLayout := "2006-01-02"
  10325. loc, _ := time.LoadLocation("Local")
  10326. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10327. if err != nil {
  10328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10329. return
  10330. }
  10331. recordDateTime := theTime.Unix()
  10332. adminInfo := c.GetAdminUserInfo()
  10333. var tempPatients []*service.NewTempPatients
  10334. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  10335. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  10336. if order_status != 2 {
  10337. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10338. } else {
  10339. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10340. }
  10341. } else {
  10342. if order_status != 2 {
  10343. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10344. } else {
  10345. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  10346. }
  10347. }
  10348. var patients []*service.NewTempPatients
  10349. var patients_two []*service.NewTempPatients
  10350. for _, item := range tempPatients {
  10351. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  10352. //过滤掉没挂号的和没开处方的
  10353. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  10354. patients = append(patients, item)
  10355. }
  10356. //过滤掉没挂号的
  10357. if len(item.HisPatient) > 0 {
  10358. patients_two = append(patients_two, item)
  10359. }
  10360. } else {
  10361. if len(item.HisPrescription) > 0 {
  10362. patients = append(patients, item)
  10363. }
  10364. }
  10365. }
  10366. c.ServeSuccessJSON(map[string]interface{}{
  10367. "list": patients,
  10368. "list_two": patients_two,
  10369. })
  10370. }
  10371. func (c *HisApiController) GetHisUnRegisterPatientList() {
  10372. record_date := c.GetString("record_date")
  10373. timeLayout := "2006-01-02"
  10374. loc, _ := time.LoadLocation("Local")
  10375. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10376. if err != nil {
  10377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10378. return
  10379. }
  10380. recordDateTime := theTime.Unix()
  10381. adminUser := c.GetAdminUserInfo()
  10382. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  10383. var patients []*service.Patients
  10384. for _, item := range tempPatients {
  10385. if item.HisPatient.ID == 0 {
  10386. patients = append(patients, item)
  10387. }
  10388. }
  10389. c.ServeSuccessJSON(map[string]interface{}{
  10390. "list": patients,
  10391. //"list_two": patients_two,
  10392. })
  10393. }
  10394. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  10395. newArr = make([]*service.Patients, 0)
  10396. for i := 0; i < len(patient); i++ {
  10397. repeat := false
  10398. for j := i + 1; j < len(patient); j++ {
  10399. if patient[i].ID == patient[j].ID {
  10400. repeat = true
  10401. break
  10402. }
  10403. }
  10404. if !repeat {
  10405. newArr = append(newArr, patient[i])
  10406. }
  10407. }
  10408. return
  10409. }
  10410. func (c *HisApiController) GetHisChargePatientInfo() {
  10411. patient_id, _ := c.GetInt64("patient_id")
  10412. his_patient_id, _ := c.GetInt64("his_patient_id")
  10413. record_date := c.GetString("record_date")
  10414. //start_time := c.GetString("start_time")
  10415. //end_time := c.GetString("end_time")
  10416. order_status, _ := c.GetInt64("type", 0)
  10417. p_type, _ := c.GetInt64("p_type", 0)
  10418. order_id, _ := c.GetInt64("order_id", 0)
  10419. timeLayout := "2006-01-02"
  10420. loc, _ := time.LoadLocation("Local")
  10421. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10422. if err != nil {
  10423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10424. return
  10425. }
  10426. recordDateTime := theTime.Unix()
  10427. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10428. //if err != nil {
  10429. //
  10430. //}
  10431. //startRecordDateTime := startTime.Unix()
  10432. //
  10433. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10434. //if err != nil {
  10435. //
  10436. //}
  10437. //endRecordDateTime := endTime.Unix()
  10438. admin := c.GetAdminUserInfo()
  10439. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10440. last_his_patient_info, _ := service.GetLastNewHisPatientInfo(patient_id, recordDateTime)
  10441. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10442. var prescriptions []*models.HisPrescription
  10443. //var unChargeMonthPrescriptions []*models.HisPrescription
  10444. order, _ := service.GetHisOrderByID(order_id)
  10445. if order_status == 1 || order_status == 0 {
  10446. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  10447. } else if order_status == 2 {
  10448. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10449. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10450. }
  10451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10454. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10455. //获取所有科室信息
  10456. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10457. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  10458. c.ServeSuccessJSON(map[string]interface{}{
  10459. "his_info": his_patient_info,
  10460. "last_his_patient_info": last_his_patient_info,
  10461. "xt_info": xt_patient_info,
  10462. "prescription": prescriptions,
  10463. "case_history": case_history,
  10464. "info": patientPrescriptionInfo,
  10465. "last_info": lastPatientPrescriptionInfo,
  10466. "order": order,
  10467. "doctors": doctors,
  10468. "department": department,
  10469. "sch": sch,
  10470. })
  10471. return
  10472. }
  10473. func (c *HisApiController) GetAllOrderDetail() {
  10474. order_id, _ := c.GetInt64("id", 0)
  10475. order, _ := service.GetHisOrderByID(order_id)
  10476. if order.ID == 0 {
  10477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10478. return
  10479. }
  10480. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10481. org_id := c.GetAdminUserInfo().CurrentOrgId
  10482. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10483. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10484. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10485. c.ServeSuccessJSON(map[string]interface{}{
  10486. "order": order,
  10487. "order_info": order_info,
  10488. "patient": patient,
  10489. "admin_info": adminInfo,
  10490. "hospital_record": record,
  10491. })
  10492. return
  10493. }
  10494. func (c *HisApiController) GetAllOrderDetailCollect() {
  10495. order_id, _ := c.GetInt64("id", 0)
  10496. order, _ := service.GetHisOrderByID(order_id)
  10497. if order.ID == 0 {
  10498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10499. return
  10500. }
  10501. org_id := c.GetAdminUserInfo().CurrentOrgId
  10502. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10503. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10504. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10505. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  10506. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  10507. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10508. var bedCostTotal float64 = 0 //床位总费
  10509. //var bedCostSelfTotal float64 = 0 //床位自费
  10510. var operationCostTotal float64 = 0 //手术费
  10511. //var operationCostSelfTotal float64 = 0 //手术费
  10512. var otherCostTotal float64 = 0 //其他费用
  10513. //var otherCostSelfTotal float64 = 0 //其他费用
  10514. var materialCostTotal float64 = 0 //材料费
  10515. //var materialCostSelfTotal float64 = 0 //材料费
  10516. var westernMedicineCostTotal float64 = 0 //西药费
  10517. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  10518. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10519. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10520. var checkCostTotal float64 = 0 //检查费
  10521. //var checkCostSelfTotal float64 = 0 //检查费
  10522. var laboratoryCostTotal float64 = 0 //化验费
  10523. //var laboratoryCostSelfTotal float64 = 0 //化验费
  10524. var treatCostTotal float64 = 0 //治疗费用
  10525. //var treatCostSelfTotal float64 = 0 //治疗费用
  10526. var zhenChaCostTotal float64 = 0 //其他费用
  10527. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10528. decimal.DivisionPrecision = 2
  10529. var BalanceAccountsType int64
  10530. if his.ID > 0 {
  10531. BalanceAccountsType = his.BalanceAccountsType
  10532. } else {
  10533. BalanceAccountsType = record.BalanceAccountsType
  10534. }
  10535. if BalanceAccountsType != 2 {
  10536. for _, item := range order_info {
  10537. if org_id == 10215 {
  10538. if item.MedChrgitmType == "01" { //床位费
  10539. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10540. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10541. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10542. }
  10543. if item.MedChrgitmType == "02" { //诊察费
  10544. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10545. //zhenChaCostSelfTotal = zhenChaCostTotal
  10546. }
  10547. if item.MedChrgitmType == "03" { //检查费
  10548. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10549. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10550. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10551. }
  10552. //if item.MedChrgitmType == "02" { //检查费
  10553. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10554. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10555. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10556. //}
  10557. if item.MedChrgitmType == "04" { //化验费
  10558. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10559. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10560. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10561. }
  10562. if item.MedChrgitmType == "05" { //治疗费
  10563. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10564. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10565. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10566. }
  10567. if item.MedChrgitmType == "06" { //手术费
  10568. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10569. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10570. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10571. }
  10572. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10573. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10574. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10575. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10576. }
  10577. if item.MedChrgitmType == "09" { //西药费
  10578. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10579. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10580. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10581. }
  10582. if item.MedChrgitmType == "11" { //中成费
  10583. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10584. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10585. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10586. }
  10587. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10588. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10589. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10590. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10591. }
  10592. } else if org_id == 10188 || org_id == 10217 {
  10593. if item.MedChrgitmType == "01" { //床位费
  10594. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10595. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10596. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10597. }
  10598. if item.MedChrgitmType == "02" { //诊察费
  10599. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10600. //zhenChaCostSelfTotal = zhenChaCostTotal
  10601. }
  10602. if item.MedChrgitmType == "03" { //检查费
  10603. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10604. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10605. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10606. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10607. }
  10608. //if item.MedChrgitmType == "02" { //检查费
  10609. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10610. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10611. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10612. //}
  10613. if item.MedChrgitmType == "04" { //化验费
  10614. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10615. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10616. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10617. }
  10618. if item.MedChrgitmType == "05" { //治疗费
  10619. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10620. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10621. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10622. }
  10623. if item.MedChrgitmType == "06" { //手术费
  10624. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10625. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10626. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10627. }
  10628. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10629. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10630. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10631. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10632. }
  10633. if item.MedChrgitmType == "09" { //西药费
  10634. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10635. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10636. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10637. }
  10638. if item.MedChrgitmType == "11" { //中成费
  10639. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10640. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10641. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10642. }
  10643. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10644. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10645. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10646. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10647. }
  10648. } else {
  10649. if item.MedChrgitmType == "01" { //床位费
  10650. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10651. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10652. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10653. }
  10654. //if item.MedChrgitmType == "02" { //诊察费
  10655. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10656. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10657. //}
  10658. if item.MedChrgitmType == "03" { //检查费
  10659. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10660. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10661. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10662. }
  10663. //if item.MedChrgitmType == "02" { //检查费
  10664. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10665. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10666. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10667. //}
  10668. if item.MedChrgitmType == "04" { //化验费
  10669. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10670. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10671. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10672. }
  10673. if item.MedChrgitmType == "05" { //治疗费
  10674. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10675. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10676. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10677. }
  10678. if item.MedChrgitmType == "06" { //手术费
  10679. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10680. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10681. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10682. }
  10683. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10684. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10685. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10686. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10687. }
  10688. if item.MedChrgitmType == "09" { //西药费
  10689. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10690. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10691. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10692. }
  10693. if item.MedChrgitmType == "11" { //中成费
  10694. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10695. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10696. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10697. }
  10698. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10699. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10700. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10701. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10702. }
  10703. }
  10704. }
  10705. c.ServeSuccessJSON(map[string]interface{}{
  10706. "order": order,
  10707. "order_info": order_info,
  10708. "patient": patient,
  10709. "admin_info": adminInfo,
  10710. "his_hospital": record,
  10711. "bedCostTotal": bedCostTotal,
  10712. "operationCostTotal": operationCostTotal,
  10713. "otherCostTotal": otherCostTotal,
  10714. "materialCostTotal": materialCostTotal,
  10715. "westernMedicineCostTotal": westernMedicineCostTotal,
  10716. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10717. "checkCostTotal": checkCostTotal,
  10718. "zhenChaCostTotal": zhenChaCostTotal,
  10719. "laboratoryCostTotal": laboratoryCostTotal,
  10720. "treatCostTotal": treatCostTotal,
  10721. })
  10722. } else {
  10723. for _, item := range order_info {
  10724. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10725. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10726. item.MedChrgitmType = "09"
  10727. }
  10728. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10729. if item.HisPrescriptionProject.Type == 2 {
  10730. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10731. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10732. case 0:
  10733. item.MedChrgitmType = "0"
  10734. break
  10735. case 1:
  10736. item.MedChrgitmType = "14"
  10737. break
  10738. case 2:
  10739. item.MedChrgitmType = "05"
  10740. break
  10741. case 3:
  10742. item.MedChrgitmType = "03"
  10743. break
  10744. case 4:
  10745. item.MedChrgitmType = "03"
  10746. break
  10747. case 5:
  10748. item.MedChrgitmType = "08"
  10749. break
  10750. case 6:
  10751. item.MedChrgitmType = "14"
  10752. break
  10753. case 7:
  10754. item.MedChrgitmType = "14"
  10755. break
  10756. case 8:
  10757. item.MedChrgitmType = "03"
  10758. break
  10759. case 9:
  10760. item.MedChrgitmType = "14"
  10761. break
  10762. case 10:
  10763. item.MedChrgitmType = "14"
  10764. break
  10765. case 11:
  10766. item.MedChrgitmType = "06"
  10767. break
  10768. case 12:
  10769. item.MedChrgitmType = "12"
  10770. break
  10771. case 13:
  10772. item.MedChrgitmType = "01"
  10773. break
  10774. case 14:
  10775. item.MedChrgitmType = "04"
  10776. break
  10777. case 15:
  10778. item.MedChrgitmType = "14"
  10779. break
  10780. }
  10781. } else {
  10782. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10783. case 1:
  10784. item.MedChrgitmType = "14"
  10785. break
  10786. case 2:
  10787. item.MedChrgitmType = "05"
  10788. break
  10789. case 3:
  10790. item.MedChrgitmType = "04"
  10791. break
  10792. case 4:
  10793. item.MedChrgitmType = "14"
  10794. break
  10795. case 5:
  10796. item.MedChrgitmType = "08"
  10797. break
  10798. case 6:
  10799. item.MedChrgitmType = "14"
  10800. break
  10801. case 7:
  10802. item.MedChrgitmType = "14"
  10803. break
  10804. case 8:
  10805. item.MedChrgitmType = "03"
  10806. break
  10807. case 9:
  10808. item.MedChrgitmType = "14"
  10809. break
  10810. }
  10811. }
  10812. } else if item.HisPrescriptionProject.Type == 3 {
  10813. item.MedChrgitmType = "08"
  10814. }
  10815. }
  10816. }
  10817. for _, item := range order_info {
  10818. if org_id == 10215 {
  10819. if item.MedChrgitmType == "01" { //床位费
  10820. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10821. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10822. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10823. }
  10824. if item.MedChrgitmType == "02" { //诊察费
  10825. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10826. //zhenChaCostSelfTotal = zhenChaCostTotal
  10827. }
  10828. if item.MedChrgitmType == "03" { //检查费
  10829. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10830. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10831. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10832. }
  10833. //if item.MedChrgitmType == "02" { //检查费
  10834. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10835. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10836. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10837. //}
  10838. if item.MedChrgitmType == "04" { //化验费
  10839. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10840. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10841. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10842. }
  10843. if item.MedChrgitmType == "05" { //治疗费
  10844. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10845. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10846. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10847. }
  10848. if item.MedChrgitmType == "06" { //手术费
  10849. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10850. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10851. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10852. }
  10853. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10854. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10855. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10856. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10857. }
  10858. if item.MedChrgitmType == "09" { //西药费
  10859. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10860. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10861. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10862. }
  10863. if item.MedChrgitmType == "11" { //中成费
  10864. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10865. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10866. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10867. }
  10868. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10869. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10870. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10871. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10872. }
  10873. } else {
  10874. if item.MedChrgitmType == "01" { //床位费
  10875. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10876. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10877. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10878. }
  10879. //if item.MedChrgitmType == "02" { //诊察费
  10880. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10881. // //zhenChaCostSelfTotal = zhenChaCostTotal
  10882. //}
  10883. if item.MedChrgitmType == "03" { //检查费
  10884. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10885. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10886. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10887. }
  10888. //if item.MedChrgitmType == "02" { //检查费
  10889. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10890. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10891. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10892. //}
  10893. if item.MedChrgitmType == "04" { //化验费
  10894. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10895. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10896. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10897. }
  10898. if item.MedChrgitmType == "05" { //治疗费
  10899. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10900. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10901. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10902. }
  10903. if item.MedChrgitmType == "06" { //手术费
  10904. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10905. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10906. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10907. }
  10908. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  10909. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10910. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10911. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10912. }
  10913. if item.MedChrgitmType == "09" { //西药费
  10914. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10915. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10916. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10917. }
  10918. if item.MedChrgitmType == "11" { //中成费
  10919. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10920. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10921. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10922. }
  10923. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10924. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10925. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10926. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10927. }
  10928. }
  10929. }
  10930. c.ServeSuccessJSON(map[string]interface{}{
  10931. "order": order,
  10932. "order_info": order_info,
  10933. "patient": patient,
  10934. "admin_info": adminInfo,
  10935. "his_hospital": record,
  10936. "bedCostTotal": bedCostTotal,
  10937. "operationCostTotal": operationCostTotal,
  10938. "otherCostTotal": otherCostTotal,
  10939. "materialCostTotal": materialCostTotal,
  10940. "westernMedicineCostTotal": westernMedicineCostTotal,
  10941. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10942. "checkCostTotal": checkCostTotal,
  10943. "zhenChaCostTotal": zhenChaCostTotal,
  10944. "laboratoryCostTotal": laboratoryCostTotal,
  10945. "treatCostTotal": treatCostTotal,
  10946. })
  10947. }
  10948. }
  10949. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  10950. page, _ := c.GetInt64("page")
  10951. limit, _ := c.GetInt64("limit")
  10952. keywords := c.GetString("keywords")
  10953. start_time := c.GetString("start_time")
  10954. end_time := c.GetString("end_time")
  10955. //clr_type := c.GetString("clr_type")
  10956. insutype := c.GetString("insutype")
  10957. timeLayout := "2006-01-02"
  10958. loc, _ := time.LoadLocation("Local")
  10959. var theStartTIme int64
  10960. if len(start_time) > 0 {
  10961. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10962. theStartTIme = theTime.Unix()
  10963. }
  10964. var theEndtTIme int64
  10965. if len(end_time) > 0 {
  10966. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10967. theEndtTIme = theTime.Unix()
  10968. }
  10969. if page <= 0 {
  10970. page = 1
  10971. }
  10972. if limit <= 0 {
  10973. limit = 10
  10974. }
  10975. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  10976. c.ServeSuccessJSON(map[string]interface{}{
  10977. "total": total,
  10978. "list": list,
  10979. })
  10980. return
  10981. }
  10982. func (c *HisApiController) GetPutOnRecordList() {
  10983. page, _ := c.GetInt64("page")
  10984. limit, _ := c.GetInt64("limit")
  10985. keywords := c.GetString("keywords")
  10986. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10987. if page <= 0 {
  10988. page = 1
  10989. }
  10990. if limit <= 0 {
  10991. limit = 10
  10992. }
  10993. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10994. c.ServeSuccessJSON(map[string]interface{}{
  10995. "total": total,
  10996. "list": list,
  10997. })
  10998. return
  10999. }
  11000. func (c *HisApiController) GetCompareData() {
  11001. start_time := c.GetString("start_time")
  11002. end_time := c.GetString("end_time")
  11003. insutype := c.GetString("insutype")
  11004. clr_type := c.GetString("clr_type")
  11005. timeLayout := "2006-01-02"
  11006. loc, _ := time.LoadLocation("Local")
  11007. var theStartTIme int64
  11008. if len(start_time) > 0 {
  11009. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11010. if err != nil {
  11011. theStartTIme = 0
  11012. }
  11013. theStartTIme = theTime.Unix()
  11014. }
  11015. var theEndtTIme int64
  11016. if len(end_time) > 0 {
  11017. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11018. if err != nil {
  11019. theEndtTIme = 0
  11020. }
  11021. theEndtTIme = theTime.Unix()
  11022. }
  11023. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  11024. fmt.Println(err)
  11025. if err == nil {
  11026. c.ServeSuccessJSON(map[string]interface{}{
  11027. "list": formData,
  11028. })
  11029. } else {
  11030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  11031. return
  11032. }
  11033. }
  11034. func (c *HisApiController) GetFaPiaoData() {
  11035. order_id, _ := c.GetInt64("order_id")
  11036. patient_id, _ := c.GetInt64("patient_id")
  11037. //number := c.GetString("number")
  11038. adminUser := c.GetAdminUserInfo()
  11039. order, _ := service.GetHisOrderByID(order_id)
  11040. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11041. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11042. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11043. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11044. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  11045. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  11046. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11047. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11048. var bedCostTotal float64 = 0 //床位总费
  11049. var bedCostSelfTotal float64 = 0 //床位自费
  11050. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11051. var operationCostTotal float64 = 0 //手术费
  11052. var operationCostSelfTotal float64 = 0 //手术费
  11053. var operationCostPartSelfTotal float64 = 0 //手术费
  11054. var otherCostTotal float64 = 0 //其他费用
  11055. var otherCostSelfTotal float64 = 0 //其他费用
  11056. var otherCostPartSelfTotal float64 = 0 //其他费用
  11057. var materialCostTotal float64 = 0 //材料费
  11058. var materialCostSelfTotal float64 = 0 //材料费
  11059. var materialCostPartSelfTotal float64 = 0 //材料费
  11060. var westernMedicineCostTotal float64 = 0 //西药费
  11061. var westernMedicineCostSelfTotal float64 = 0 //西药费
  11062. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11063. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11064. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11065. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11066. var checkCostTotal float64 = 0 //检查费
  11067. var checkCostSelfTotal float64 = 0 //检查费
  11068. var checkCostPartSelfTotal float64 = 0 //检查费
  11069. var hiliCostTotal float64 = 0 //护理费
  11070. var hiliCostSelfTotal float64 = 0 //护理费
  11071. var hiliCostPartSelfTotal float64 = 0 //护理费
  11072. var laboratoryCostTotal float64 = 0 //化验费
  11073. var laboratoryCostSelfTotal float64 = 0 //化验费
  11074. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11075. var treatCostTotal float64 = 0 //治疗费用
  11076. var treatCostSelfTotal float64 = 0 //治疗费用
  11077. var treatCostPartSelfTotal float64 = 0 //治疗费用
  11078. var zhenChaCostTotal float64 = 0 //其他费用
  11079. var zhenChaCostSelfTotal float64 = 0 //其他费用
  11080. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11081. decimal.DivisionPrecision = 2
  11082. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11083. var balanceAccountsType int64
  11084. if his.ID > 0 {
  11085. balanceAccountsType = his.BalanceAccountsType
  11086. } else {
  11087. balanceAccountsType = his_hospital_record.BalanceAccountsType
  11088. }
  11089. if balanceAccountsType == 2 {
  11090. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11091. for _, item := range orderInfos_two {
  11092. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11093. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11094. item.MedChrgitmType = "09"
  11095. }
  11096. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11097. if item.HisPrescriptionProject.Type == 2 {
  11098. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11099. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11100. case 0:
  11101. item.MedChrgitmType = "0"
  11102. break
  11103. case 1:
  11104. item.MedChrgitmType = "14"
  11105. break
  11106. case 2:
  11107. item.MedChrgitmType = "05"
  11108. break
  11109. case 3:
  11110. item.MedChrgitmType = "03"
  11111. break
  11112. case 4:
  11113. item.MedChrgitmType = "03"
  11114. break
  11115. case 5:
  11116. item.MedChrgitmType = "08"
  11117. break
  11118. case 6:
  11119. item.MedChrgitmType = "14"
  11120. break
  11121. case 7:
  11122. item.MedChrgitmType = "14"
  11123. break
  11124. case 8:
  11125. item.MedChrgitmType = "03"
  11126. break
  11127. case 9:
  11128. item.MedChrgitmType = "14"
  11129. break
  11130. case 10:
  11131. item.MedChrgitmType = "14"
  11132. break
  11133. case 11:
  11134. item.MedChrgitmType = "06"
  11135. break
  11136. case 12:
  11137. item.MedChrgitmType = "12"
  11138. break
  11139. case 13:
  11140. item.MedChrgitmType = "01"
  11141. break
  11142. case 14:
  11143. item.MedChrgitmType = "04"
  11144. break
  11145. case 15:
  11146. item.MedChrgitmType = "02"
  11147. break
  11148. }
  11149. } else {
  11150. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11151. case 1:
  11152. item.MedChrgitmType = "14"
  11153. break
  11154. case 2:
  11155. item.MedChrgitmType = "05"
  11156. break
  11157. case 3:
  11158. item.MedChrgitmType = "04"
  11159. break
  11160. case 4:
  11161. item.MedChrgitmType = "03"
  11162. break
  11163. case 5:
  11164. item.MedChrgitmType = "08"
  11165. break
  11166. case 6:
  11167. item.MedChrgitmType = "14"
  11168. break
  11169. case 7:
  11170. item.MedChrgitmType = "14"
  11171. break
  11172. case 8:
  11173. item.MedChrgitmType = "03"
  11174. break
  11175. case 9:
  11176. item.MedChrgitmType = "14"
  11177. break
  11178. }
  11179. }
  11180. } else if item.HisPrescriptionProject.Type == 3 {
  11181. item.MedChrgitmType = "08"
  11182. }
  11183. }
  11184. }
  11185. for _, item := range orderInfos_two {
  11186. fmt.Println(item.MedChrgitmType)
  11187. if item.MedChrgitmType == "07" { //床位费
  11188. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11189. hiliCostSelfTotal = hiliCostTotal
  11190. }
  11191. if item.MedChrgitmType == "01" { //床位费
  11192. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11193. bedCostSelfTotal = bedCostTotal
  11194. }
  11195. if item.MedChrgitmType == "02" { //诊察费
  11196. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11197. zhenChaCostSelfTotal = zhenChaCostTotal
  11198. }
  11199. if item.MedChrgitmType == "03" { //检查费
  11200. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11201. checkCostSelfTotal = checkCostTotal
  11202. }
  11203. if item.MedChrgitmType == "04" { //化验费
  11204. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11205. laboratoryCostSelfTotal = laboratoryCostTotal
  11206. }
  11207. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11208. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11209. treatCostSelfTotal = treatCostTotal
  11210. }
  11211. if item.MedChrgitmType == "06" { //手术费
  11212. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11213. operationCostSelfTotal = treatCostTotal
  11214. }
  11215. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  11216. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11217. materialCostSelfTotal = materialCostTotal
  11218. }
  11219. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11220. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11221. westernMedicineCostSelfTotal = westernMedicineCostTotal
  11222. }
  11223. if item.MedChrgitmType == "11" { //中成费
  11224. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11225. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11226. }
  11227. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11228. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11229. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11230. otherCostSelfTotal = otherCostTotal
  11231. }
  11232. } else {
  11233. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11234. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11235. otherCostSelfTotal = otherCostTotal
  11236. }
  11237. }
  11238. }
  11239. } else {
  11240. for _, item := range orderInfos {
  11241. if item.MedChrgitmType == "01" { //床位费
  11242. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11243. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11244. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11245. }
  11246. if item.MedChrgitmType == "02" { //诊察费
  11247. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11248. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11249. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11250. }
  11251. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11252. if item.MedChrgitmType == "03" { //检查费
  11253. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11254. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11255. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11256. }
  11257. } else {
  11258. if item.MedChrgitmType == "03" { //检查费
  11259. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11260. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11261. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11262. }
  11263. }
  11264. if item.MedChrgitmType == "04" { //化验费
  11265. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11266. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11267. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11268. }
  11269. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  11270. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11271. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11272. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11273. }
  11274. if item.MedChrgitmType == "06" { //手术费
  11275. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11276. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11277. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11278. }
  11279. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  11280. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11281. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11282. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11283. }
  11284. if item.MedChrgitmType == "07" { //护理
  11285. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11286. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11287. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11288. }
  11289. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  11290. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11291. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11292. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11293. }
  11294. if item.MedChrgitmType == "11" { //中成费
  11295. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11296. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11297. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11298. }
  11299. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11300. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11301. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11302. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11303. }
  11304. }
  11305. }
  11306. timeLayout := "2006-01-02"
  11307. loc, _ := time.LoadLocation("Local")
  11308. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11309. if err != nil {
  11310. }
  11311. startRecordDateTime := startTime.Unix()
  11312. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11313. if err != nil {
  11314. }
  11315. endRecordDateTime := endTime.Unix()
  11316. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11317. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11318. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11319. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  11320. c.ServeSuccessJSON(map[string]interface{}{
  11321. "charge_admin_name": charge_admin.UserName,
  11322. "order_number": order.Number, //业务流水号
  11323. "id_card_no": his.IdCardNo, //社会保障号
  11324. "patient": patient,
  11325. "department_name": department.Name, //科室
  11326. "number": his.Number, //门诊号
  11327. "date": order.SettleAccountsDate, //结算日期
  11328. "name": order.PsnName, //姓名
  11329. "gender": patient.Gender, //性别
  11330. "psn_cash_money": order.PsnCashPay, //个人支付
  11331. "pay_way": "门诊", //结算方式
  11332. "medfee_sumamt": order.MedfeeSumamt, //总费用
  11333. "admin_user_name": admin.UserName, //收款员
  11334. "order": order,
  11335. "order_info": orderInfos_two,
  11336. "his": his,
  11337. "bedCostTotal": bedCostTotal,
  11338. "bedCostSelfTotal": bedCostSelfTotal,
  11339. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11340. "operationCostTotal": operationCostTotal,
  11341. "operationCostSelfTotal": operationCostSelfTotal,
  11342. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11343. "otherCostTotal": otherCostTotal,
  11344. "otherCostSelfTotal": otherCostSelfTotal,
  11345. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11346. "materialCostTotal": materialCostTotal,
  11347. "materialCostSelfTotal": materialCostSelfTotal,
  11348. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11349. "westernMedicineCostTotal": westernMedicineCostTotal,
  11350. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11351. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11352. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11353. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11354. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11355. "checkCostTotal": checkCostTotal,
  11356. "checkCostSelfTotal": checkCostSelfTotal,
  11357. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11358. "laboratoryCostTotal": laboratoryCostTotal,
  11359. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11360. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11361. "treatCostTotal": treatCostTotal,
  11362. "treatCostSelfTotal": treatCostSelfTotal,
  11363. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11364. "zhenChaCostTotal": zhenChaCostTotal,
  11365. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11366. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11367. "his_hospital_record": his_hospital_record,
  11368. "pre_pay_money": pre_pay_money,
  11369. "refund_sum": sum,
  11370. "doctor_info": doctor_info,
  11371. "hiliCostTotal": hiliCostTotal,
  11372. "hiliCostSelfTotal": hiliCostSelfTotal,
  11373. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  11374. })
  11375. }
  11376. //func (c *HisApiController) GetFaPiaoDatas() {
  11377. // order_ids := c.GetString("order_ids")
  11378. // patient_id, _ := c.GetInt64("patient_id")
  11379. // adminUser := c.GetAdminUserInfo()
  11380. //
  11381. // orders := strings.Split(order_ids, ",")
  11382. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  11383. //
  11384. // for _, item := range orders {
  11385. // order_id, _ := strconv.ParseInt(item, 10, 64)
  11386. // order, _ := service.GetHisOrderByID(order_id)
  11387. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  11388. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  11389. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  11390. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  11391. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  11392. //
  11393. // }
  11394. //
  11395. // var bedCostTotal float64 = 0 //床位总费
  11396. // var bedCostSelfTotal float64 = 0 //床位自费
  11397. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  11398. //
  11399. // var operationCostTotal float64 = 0 //手术费
  11400. // var operationCostSelfTotal float64 = 0 //手术费
  11401. // var operationCostPartSelfTotal float64 = 0 //手术费
  11402. //
  11403. // var otherCostTotal float64 = 0 //其他费用
  11404. // var otherCostSelfTotal float64 = 0 //其他费用
  11405. // var otherCostPartSelfTotal float64 = 0 //其他费用
  11406. //
  11407. // var materialCostTotal float64 = 0 //材料费
  11408. // var materialCostSelfTotal float64 = 0 //材料费
  11409. // var materialCostPartSelfTotal float64 = 0 //材料费
  11410. //
  11411. // var westernMedicineCostTotal float64 = 0 //西药费
  11412. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  11413. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  11414. //
  11415. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  11416. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  11417. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  11418. //
  11419. // var checkCostTotal float64 = 0 //检查费
  11420. // var checkCostSelfTotal float64 = 0 //检查费
  11421. // var checkCostPartSelfTotal float64 = 0 //检查费
  11422. //
  11423. // var laboratoryCostTotal float64 = 0 //化验费
  11424. // var laboratoryCostSelfTotal float64 = 0 //化验费
  11425. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  11426. //
  11427. // var treatCostTotal float64 = 0 //治疗费用
  11428. // var treatCostSelfTotal float64 = 0 //治疗费用
  11429. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  11430. //
  11431. // var zhenChaCostTotal float64 = 0 //其他费用
  11432. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  11433. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  11434. //
  11435. // decimal.DivisionPrecision = 2
  11436. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11437. //
  11438. // var balanceAccountsType int64
  11439. // if his.ID > 0 {
  11440. // balanceAccountsType = his.BalanceAccountsType
  11441. // } else {
  11442. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  11443. // }
  11444. // if balanceAccountsType == 2 {
  11445. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  11446. // for _, item := range orderInfos_two {
  11447. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  11448. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  11449. // item.MedChrgitmType = "09"
  11450. // }
  11451. //
  11452. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  11453. // if item.HisPrescriptionProject.Type == 2 {
  11454. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  11455. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11456. // case 0:
  11457. // item.MedChrgitmType = "0"
  11458. // break
  11459. // case 1:
  11460. // item.MedChrgitmType = "14"
  11461. // break
  11462. // case 2:
  11463. // item.MedChrgitmType = "05"
  11464. //
  11465. // break
  11466. // case 3:
  11467. // item.MedChrgitmType = "03"
  11468. //
  11469. // break
  11470. // case 4:
  11471. // item.MedChrgitmType = "03"
  11472. //
  11473. // break
  11474. // case 5:
  11475. // item.MedChrgitmType = "08"
  11476. //
  11477. // break
  11478. // case 6:
  11479. // item.MedChrgitmType = "14"
  11480. //
  11481. // break
  11482. // case 7:
  11483. // item.MedChrgitmType = "14"
  11484. //
  11485. // break
  11486. // case 8:
  11487. // item.MedChrgitmType = "03"
  11488. // break
  11489. // case 9:
  11490. // item.MedChrgitmType = "14"
  11491. // break
  11492. // case 10:
  11493. // item.MedChrgitmType = "14"
  11494. // break
  11495. // case 11:
  11496. // item.MedChrgitmType = "06"
  11497. // break
  11498. // case 12:
  11499. // item.MedChrgitmType = "12"
  11500. // break
  11501. // case 13:
  11502. // item.MedChrgitmType = "01"
  11503. // break
  11504. // case 14:
  11505. // item.MedChrgitmType = "04"
  11506. // break
  11507. // case 15:
  11508. // item.MedChrgitmType = "02"
  11509. // break
  11510. //
  11511. // }
  11512. //
  11513. // } else {
  11514. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  11515. //
  11516. // case 1:
  11517. // item.MedChrgitmType = "14"
  11518. // break
  11519. // case 2:
  11520. // item.MedChrgitmType = "05"
  11521. //
  11522. // break
  11523. // case 3:
  11524. // item.MedChrgitmType = "03"
  11525. //
  11526. // break
  11527. // case 4:
  11528. // item.MedChrgitmType = "03"
  11529. //
  11530. // break
  11531. // case 5:
  11532. // item.MedChrgitmType = "08"
  11533. //
  11534. // break
  11535. // case 6:
  11536. // item.MedChrgitmType = "14"
  11537. //
  11538. // break
  11539. // case 7:
  11540. // item.MedChrgitmType = "14"
  11541. //
  11542. // break
  11543. // case 8:
  11544. // item.MedChrgitmType = "03"
  11545. // break
  11546. // case 9:
  11547. // item.MedChrgitmType = "14"
  11548. // break
  11549. //
  11550. // }
  11551. //
  11552. // }
  11553. //
  11554. // } else if item.HisPrescriptionProject.Type == 3 {
  11555. // item.MedChrgitmType = "08"
  11556. // }
  11557. // }
  11558. // }
  11559. //
  11560. // for _, item := range orderInfos_two {
  11561. // fmt.Println(item.MedChrgitmType)
  11562. // if item.MedChrgitmType == "01" { //床位费
  11563. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11564. // bedCostSelfTotal = bedCostTotal
  11565. // }
  11566. //
  11567. // if item.MedChrgitmType == "02" { //诊察费
  11568. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11569. // zhenChaCostSelfTotal = zhenChaCostTotal
  11570. // }
  11571. //
  11572. // if item.MedChrgitmType == "03" { //检查费
  11573. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11574. // checkCostSelfTotal = checkCostTotal
  11575. // }
  11576. //
  11577. // if item.MedChrgitmType == "04" { //化验费
  11578. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11579. // laboratoryCostSelfTotal = laboratoryCostTotal
  11580. // }
  11581. //
  11582. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  11583. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11584. // treatCostSelfTotal = treatCostTotal
  11585. // }
  11586. //
  11587. // if item.MedChrgitmType == "06" { //手术费
  11588. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11589. // operationCostSelfTotal = treatCostTotal
  11590. // }
  11591. //
  11592. // if item.MedChrgitmType == "08" { //材料费
  11593. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11594. // materialCostSelfTotal = materialCostTotal
  11595. // }
  11596. //
  11597. // if item.MedChrgitmType == "09" { //西药费
  11598. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11599. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  11600. // }
  11601. //
  11602. // if item.MedChrgitmType == "11" { //中成费
  11603. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11604. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  11605. // }
  11606. //
  11607. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  11608. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  11609. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11610. // otherCostSelfTotal = otherCostTotal
  11611. // }
  11612. // } else {
  11613. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11614. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11615. // otherCostSelfTotal = otherCostTotal
  11616. // }
  11617. //
  11618. // }
  11619. //
  11620. // }
  11621. //
  11622. // } else {
  11623. // for _, item := range orderInfos {
  11624. // if item.MedChrgitmType == "01" { //床位费
  11625. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11626. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11627. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11628. // }
  11629. //
  11630. // if item.MedChrgitmType == "02" { //诊察费
  11631. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11632. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11633. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11634. // }
  11635. //
  11636. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  11637. // if item.MedChrgitmType == "03" { //检查费
  11638. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11639. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11640. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11641. //
  11642. // }
  11643. // } else {
  11644. // if item.MedChrgitmType == "03" { //检查费
  11645. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11646. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11647. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11648. // }
  11649. //
  11650. // }
  11651. //
  11652. // if item.MedChrgitmType == "04" { //化验费
  11653. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11654. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11655. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11656. //
  11657. // }
  11658. //
  11659. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  11660. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11661. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11662. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11663. //
  11664. // }
  11665. //
  11666. // if item.MedChrgitmType == "06" { //手术费
  11667. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11668. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11669. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11670. // }
  11671. //
  11672. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  11673. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11674. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11675. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11676. // }
  11677. //
  11678. // if item.MedChrgitmType == "09" { //西药费
  11679. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11680. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11681. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11682. // }
  11683. //
  11684. // if item.MedChrgitmType == "11" { //中成费
  11685. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11686. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11687. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11688. // }
  11689. //
  11690. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  11691. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  11692. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  11693. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  11694. // }
  11695. //
  11696. // }
  11697. // }
  11698. // timeLayout := "2006-01-02"
  11699. // loc, _ := time.LoadLocation("Local")
  11700. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  11701. // if err != nil {
  11702. // }
  11703. // startRecordDateTime := startTime.Unix()
  11704. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  11705. // if err != nil {
  11706. // }
  11707. // endRecordDateTime := endTime.Unix()
  11708. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  11709. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  11710. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  11711. //
  11712. // c.ServeSuccessJSON(map[string]interface{}{
  11713. // "order_number": order.Number, //业务流水号
  11714. // "id_card_no": his.IdCardNo, //社会保障号
  11715. // "department_name": department.Name, //科室
  11716. // "number": his.Number, //门诊号
  11717. // "date": order.SettleAccountsDate, //结算日期
  11718. // "name": order.PsnName, //姓名
  11719. // "gender": patient.Gender, //性别
  11720. // "psn_cash_money": order.PsnCashPay, //个人支付
  11721. // "pay_way": "门诊", //结算方式
  11722. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  11723. // "admin_user_name": admin.UserName, //收款员
  11724. // "order": order,
  11725. // "order_info": orderInfos_two,
  11726. // "his": his,
  11727. // "bedCostTotal": bedCostTotal,
  11728. // "bedCostSelfTotal": bedCostSelfTotal,
  11729. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  11730. // "operationCostTotal": operationCostTotal,
  11731. // "operationCostSelfTotal": operationCostSelfTotal,
  11732. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  11733. // "otherCostTotal": otherCostTotal,
  11734. // "otherCostSelfTotal": otherCostSelfTotal,
  11735. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  11736. // "materialCostTotal": materialCostTotal,
  11737. // "materialCostSelfTotal": materialCostSelfTotal,
  11738. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  11739. // "westernMedicineCostTotal": westernMedicineCostTotal,
  11740. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  11741. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  11742. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  11743. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  11744. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  11745. // "checkCostTotal": checkCostTotal,
  11746. // "checkCostSelfTotal": checkCostSelfTotal,
  11747. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  11748. // "laboratoryCostTotal": laboratoryCostTotal,
  11749. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  11750. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  11751. // "treatCostTotal": treatCostTotal,
  11752. // "treatCostSelfTotal": treatCostSelfTotal,
  11753. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  11754. // "zhenChaCostTotal": zhenChaCostTotal,
  11755. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  11756. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  11757. // "his_hospital_record": his_hospital_record,
  11758. // "pre_pay_money": pre_pay_money,
  11759. // "refund_sum": sum,
  11760. // })
  11761. //
  11762. //}
  11763. func (this *HisApiController) GetIncomeStatisticsData() {
  11764. start_time := this.GetString("start_time")
  11765. end_time := this.GetString("end_time")
  11766. key_words := this.GetString("key_words")
  11767. limit, _ := this.GetInt64("limit")
  11768. page, _ := this.GetInt64("page")
  11769. if page <= 0 {
  11770. page = 1
  11771. }
  11772. if limit <= 0 {
  11773. limit = 10
  11774. }
  11775. statistics_type, _ := this.GetInt64("statistics_type")
  11776. admin := this.GetAdminUserInfo()
  11777. timeLayout := "2006-01-02"
  11778. loc, _ := time.LoadLocation("Local")
  11779. var theStartTIme int64
  11780. if len(start_time) > 0 {
  11781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11782. if err != nil {
  11783. theStartTIme = 0
  11784. }
  11785. theStartTIme = theTime.Unix()
  11786. }
  11787. var theEndtTIme int64
  11788. if len(end_time) > 0 {
  11789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11790. if err != nil {
  11791. theEndtTIme = 0
  11792. }
  11793. theEndtTIme = theTime.Unix()
  11794. }
  11795. if statistics_type == 1 {
  11796. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11797. this.ServeSuccessJSON(map[string]interface{}{
  11798. "list": list,
  11799. "total": total,
  11800. })
  11801. } else {
  11802. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  11803. this.ServeSuccessJSON(map[string]interface{}{
  11804. "list": list,
  11805. "total": total,
  11806. })
  11807. }
  11808. }
  11809. func (c *HisApiController) PostProjectInformation() {
  11810. adminUser := c.GetAdminUserInfo()
  11811. orgId := adminUser.CurrentOrgId
  11812. dataBody := make(map[string]interface{}, 0)
  11813. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11814. if err != nil {
  11815. utils.ErrorLog(err.Error())
  11816. return
  11817. }
  11818. utils.ErrorLog("%v", dataBody)
  11819. var projectList []*models.HisProject
  11820. var total_goods []interface{}
  11821. tempProjects := dataBody["projects"].([]interface{})
  11822. total_goods = tempProjects
  11823. for index, projectMap := range tempProjects {
  11824. projectM := projectMap.(map[string]interface{})
  11825. var project models.HisProject
  11826. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  11827. utils.ErrorLog("project_name")
  11828. return
  11829. }
  11830. project_name, _ := projectM["project_name"].(string)
  11831. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  11832. err_log := models.ExportErrLog{
  11833. LogType: 6,
  11834. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11835. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  11836. Status: 1,
  11837. CreateTime: time.Now().Unix(),
  11838. UpdateTime: time.Now().Unix(),
  11839. ExportTime: time.Now().Unix(),
  11840. }
  11841. service.CreateExportErrLog(&err_log)
  11842. continue
  11843. }
  11844. project.ProjectName = project_name
  11845. prices := projectM["price"].(string)
  11846. price, _ := strconv.ParseFloat(prices, 64)
  11847. if price <= 0 { //名字为空则生成一条导入错误日志
  11848. err_log := models.ExportErrLog{
  11849. LogType: 6,
  11850. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11851. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  11852. Status: 1,
  11853. CreateTime: time.Now().Unix(),
  11854. UpdateTime: time.Now().Unix(),
  11855. ExportTime: time.Now().Unix(),
  11856. }
  11857. service.CreateExportErrLog(&err_log)
  11858. continue
  11859. }
  11860. project.Price = price
  11861. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  11862. utils.ErrorLog("unit_id")
  11863. return
  11864. }
  11865. unit := projectM["unit"].(string)
  11866. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  11867. err_log := models.ExportErrLog{
  11868. LogType: 6,
  11869. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11870. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  11871. Status: 1,
  11872. CreateTime: time.Now().Unix(),
  11873. UpdateTime: time.Now().Unix(),
  11874. ExportTime: time.Now().Unix(),
  11875. }
  11876. service.CreateExportErrLog(&err_log)
  11877. continue
  11878. }
  11879. project.Unit = unit
  11880. cost_classify := projectM["cost_classify"].(string)
  11881. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  11882. err_log := models.ExportErrLog{
  11883. LogType: 6,
  11884. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11885. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11886. Status: 1,
  11887. CreateTime: time.Now().Unix(),
  11888. UpdateTime: time.Now().Unix(),
  11889. ExportTime: time.Now().Unix(),
  11890. }
  11891. service.CreateExportErrLog(&err_log)
  11892. continue
  11893. }
  11894. var costClassify = "费用类别"
  11895. var cost_classify_id int64
  11896. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  11897. if len(cost_classify) != 0 {
  11898. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  11899. if errcode == gorm.ErrRecordNotFound {
  11900. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  11901. dataconfig := models.DictDataconfig{
  11902. ParentId: costClassifyConfig.ID,
  11903. Module: "system",
  11904. OrgId: orgId,
  11905. Name: cost_classify,
  11906. FieldName: "",
  11907. Value: costConfig.Value + 1,
  11908. CreatedTime: "",
  11909. UpdatedTime: "",
  11910. CreateUserId: adminUser.AdminUser.Id,
  11911. Status: 1,
  11912. Remark: "",
  11913. DeleteIdSystem: 0,
  11914. Title: "",
  11915. Content: "",
  11916. Order: 0,
  11917. Code: "",
  11918. }
  11919. service.CreatedDicConfig(&dataconfig)
  11920. }
  11921. }
  11922. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  11923. for _, it := range costClassList {
  11924. if cost_classify == it.Name {
  11925. cost_classify_id = int64(it.Value)
  11926. }
  11927. }
  11928. project.CostClassify = cost_classify_id
  11929. executive_section := projectM["executive_section"].(string)
  11930. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  11931. err_log := models.ExportErrLog{
  11932. LogType: 6,
  11933. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11934. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  11935. Status: 1,
  11936. CreateTime: time.Now().Unix(),
  11937. UpdateTime: time.Now().Unix(),
  11938. ExportTime: time.Now().Unix(),
  11939. }
  11940. service.CreateExportErrLog(&err_log)
  11941. continue
  11942. }
  11943. if len(executive_section) != 0 {
  11944. //查找科室是否有内容
  11945. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  11946. if errcodedepart == gorm.ErrRecordNotFound {
  11947. department := models.XtHisDepartment{
  11948. Name: executive_section,
  11949. Status: 1,
  11950. UserOrgId: adminUser.CurrentOrgId,
  11951. CreatedTime: time.Now().Unix(),
  11952. }
  11953. service.CreateDePartment(&department)
  11954. }
  11955. }
  11956. var executive_section_id int64
  11957. departMentList, _ := service.GetAllDepartMent(orgId)
  11958. for _, it := range departMentList {
  11959. if executive_section == it.Name {
  11960. executive_section_id = it.ID
  11961. }
  11962. }
  11963. project.ExecutiveSection = executive_section_id
  11964. medical_coverage := projectM["medical_coverage"].(string)
  11965. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  11966. err_log := models.ExportErrLog{
  11967. LogType: 6,
  11968. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11969. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  11970. Status: 1,
  11971. CreateTime: time.Now().Unix(),
  11972. UpdateTime: time.Now().Unix(),
  11973. ExportTime: time.Now().Unix(),
  11974. }
  11975. service.CreateExportErrLog(&err_log)
  11976. continue
  11977. }
  11978. var medicalCoverage = "医保等级"
  11979. var medical_coverage_id int64
  11980. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11981. if len(medical_coverage) != 0 {
  11982. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11983. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11984. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11985. dataconfig := models.DictDataconfig{
  11986. ParentId: medicalCoverageConfig.ID,
  11987. Module: "system",
  11988. OrgId: orgId,
  11989. Name: medical_coverage,
  11990. FieldName: "",
  11991. Value: medicalCoverageConfig.Value + 1,
  11992. CreatedTime: "",
  11993. UpdatedTime: "",
  11994. CreateUserId: adminUser.AdminUser.Id,
  11995. Status: 1,
  11996. Remark: "",
  11997. DeleteIdSystem: 0,
  11998. Title: "",
  11999. Content: "",
  12000. Order: 0,
  12001. Code: "",
  12002. }
  12003. service.CreatedDicConfig(&dataconfig)
  12004. }
  12005. }
  12006. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  12007. for _, it := range medicalCoverageList {
  12008. if medical_coverage == it.Name {
  12009. medical_coverage_id = int64(it.Value)
  12010. }
  12011. }
  12012. project.MedicalCoverage = medical_coverage_id
  12013. pinyin := projectM["pinyin"].(string)
  12014. project.Pinyin = pinyin
  12015. wubi := projectM["wubi"].(string)
  12016. project.Wubi = wubi
  12017. statistical_classification := projectM["statistical_classification"].(string)
  12018. var statisticalClassification = "统计分类"
  12019. var statistical_classification_id int64
  12020. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  12021. if len(statistical_classification) != 0 {
  12022. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  12023. if classificationerrcodes == gorm.ErrRecordNotFound {
  12024. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  12025. dataconfig := models.DictDataconfig{
  12026. ParentId: classiFication.ID,
  12027. Module: "system",
  12028. OrgId: orgId,
  12029. Name: statistical_classification,
  12030. FieldName: "",
  12031. Value: classiFicationConfig.Value + 1,
  12032. CreatedTime: "",
  12033. UpdatedTime: "",
  12034. CreateUserId: adminUser.AdminUser.Id,
  12035. Status: 1,
  12036. Remark: "",
  12037. DeleteIdSystem: 0,
  12038. Title: "",
  12039. Content: "",
  12040. Order: 0,
  12041. Code: "",
  12042. }
  12043. service.CreatedDicConfig(&dataconfig)
  12044. }
  12045. }
  12046. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  12047. for _, it := range classiFicationList {
  12048. if statistical_classification == it.Name {
  12049. statistical_classification_id = int64(it.Value)
  12050. }
  12051. }
  12052. project.StatisticalClassification = statistical_classification_id
  12053. disease_directory := int64(projectM["disease_directory"].(float64))
  12054. project.DiseaseDirectory = disease_directory
  12055. is_record := int64(projectM["is_record"].(float64))
  12056. project.IsRecord = is_record
  12057. medical_code := projectM["medical_code"].(string)
  12058. project.MedicalCode = medical_code
  12059. tube_color := projectM["tube_color"].(string)
  12060. var tubeColor = "试管颜色"
  12061. var tube_color_id int64
  12062. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  12063. if len(tube_color) != 0 {
  12064. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  12065. if errcodetube == gorm.ErrRecordNotFound {
  12066. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  12067. dataconfig := models.DictDataconfig{
  12068. ParentId: tubeColorConfig.ID,
  12069. Module: "system",
  12070. OrgId: orgId,
  12071. Name: tube_color,
  12072. FieldName: "",
  12073. Value: tubeConfig.Value + 1,
  12074. CreatedTime: "",
  12075. UpdatedTime: "",
  12076. CreateUserId: adminUser.AdminUser.Id,
  12077. Status: 1,
  12078. Remark: "",
  12079. DeleteIdSystem: 0,
  12080. Title: "",
  12081. Content: "",
  12082. Order: 0,
  12083. Code: "",
  12084. }
  12085. service.CreatedDicConfig(&dataconfig)
  12086. }
  12087. }
  12088. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  12089. for _, it := range tubeColorList {
  12090. if tube_color == it.Name {
  12091. tube_color_id = int64(it.Value)
  12092. }
  12093. }
  12094. project.TubeColor = tube_color_id
  12095. single_dose := projectM["single_dose"].(string)
  12096. project.SingleDose = single_dose
  12097. execution_frequency := projectM["execution_frequency"].(string)
  12098. project.ExecutionFrequency = execution_frequency
  12099. delivery_way := projectM["delivery_way"].(string)
  12100. project.DeliveryWay = delivery_way
  12101. number_days := projectM["number_days"].(string)
  12102. project.NumberDays = number_days
  12103. total := projectM["total"].(string)
  12104. project.Total = total
  12105. medical_status := int64(projectM["medical_status"].(float64))
  12106. project.MedicalStatus = medical_status
  12107. category := int64(projectM["category"].(float64))
  12108. project.Category = category
  12109. specail_project := int64(projectM["specail_project"].(float64))
  12110. project.SpecailProject = specail_project
  12111. social_security_directory_code := projectM["social_security_directory_code"].(string)
  12112. project.SocialSecurityDirectoryCode = social_security_directory_code
  12113. remark := projectM["remark"].(string)
  12114. project.Remark = remark
  12115. record_date := projectM["record_date"].(string)
  12116. timeLayout := "2006-01-02"
  12117. loc, _ := time.LoadLocation("Local")
  12118. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12119. project.RecordDate = theTime.Unix()
  12120. projectList = append(projectList, &project)
  12121. }
  12122. export_time := time.Now().Unix()
  12123. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  12124. if len(projectList) > 0 {
  12125. for _, item := range projectList {
  12126. hans := item.ProjectName // 要转换的汉字字符串
  12127. // 创建一个拼音转换器
  12128. p := pinyin.NewArgs()
  12129. // 将汉字转为拼音
  12130. pinyinSlice := pinyin.Pinyin(hans, p)
  12131. // 输出拼音
  12132. fmt.Println("Pinyin:", pinyinSlice)
  12133. // 获取首字母
  12134. firstLetter := ""
  12135. for _, py := range pinyinSlice {
  12136. if len(py) > 0 {
  12137. firstLetter += string(py[0][0])
  12138. }
  12139. }
  12140. item.FirstLetter = firstLetter
  12141. project := models.HisProject{
  12142. ProjectName: item.ProjectName,
  12143. Price: item.Price,
  12144. Unit: item.Unit,
  12145. CostClassify: item.CostClassify,
  12146. ExecutiveSection: item.ExecutiveSection,
  12147. MedicalCoverage: item.MedicalCoverage,
  12148. UserOrgId: orgId,
  12149. Status: 1,
  12150. CreatedTime: time.Now().Unix(),
  12151. Pinyin: item.Pinyin,
  12152. Wubi: item.Wubi,
  12153. StatisticalClassification: item.StatisticalClassification,
  12154. DiseaseDirectory: item.DiseaseDirectory,
  12155. IsRecord: item.IsRecord,
  12156. MedicalCode: item.MedicalCode,
  12157. TubeColor: item.TubeColor,
  12158. SingleDose: item.SingleDose,
  12159. DeliveryWay: item.DeliveryWay,
  12160. NumberDays: item.NumberDays,
  12161. Total: item.Total,
  12162. Category: item.Category,
  12163. MedicalStatus: item.MedicalStatus,
  12164. SpecailProject: item.SpecailProject,
  12165. RecordDate: item.RecordDate,
  12166. Remark: item.Remark,
  12167. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  12168. ExecutionFrequency: item.ExecutionFrequency,
  12169. FirstLetter: item.FirstLetter,
  12170. }
  12171. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  12172. if errcodeproject == gorm.ErrRecordNotFound {
  12173. service.CreateProjectInfomation(&project)
  12174. } else if errcodeproject == nil {
  12175. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  12176. }
  12177. log := models.ExportLog{
  12178. LogType: 6,
  12179. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12180. TotalNum: int64(len(total_goods)),
  12181. FailNum: int64(len(errLogs)),
  12182. SuccessNum: int64(len(projectList)),
  12183. CreateTime: time.Now().Unix(),
  12184. UpdateTime: time.Now().Unix(),
  12185. ExportTime: export_time,
  12186. Status: 1,
  12187. }
  12188. service.CreateExportLog(&log)
  12189. c.ServeSuccessJSON(map[string]interface{}{
  12190. "msg": "导入成功",
  12191. "total_num": len(total_goods),
  12192. "success_num": len(projectList),
  12193. "fail_num": int64(len(errLogs)),
  12194. })
  12195. }
  12196. } else {
  12197. log := models.ExportLog{
  12198. LogType: 6,
  12199. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12200. TotalNum: int64(len(total_goods)),
  12201. FailNum: int64(len(errLogs)),
  12202. SuccessNum: int64(len(projectList)),
  12203. CreateTime: time.Now().Unix(),
  12204. UpdateTime: time.Now().Unix(),
  12205. ExportTime: export_time,
  12206. Status: 1,
  12207. }
  12208. service.CreateExportLog(&log)
  12209. c.ServeSuccessJSON(map[string]interface{}{
  12210. "msg": "导入成功",
  12211. "total_num": len(total_goods),
  12212. "success_num": len(projectList),
  12213. "fail_num": int64(len(errLogs)),
  12214. })
  12215. }
  12216. }
  12217. //func (this *HisApiController) EditProjectInformation(){
  12218. //
  12219. // id, _ := this.GetInt64("id")
  12220. // project_team := this.GetString("project_team")
  12221. // price := this.GetString("price")
  12222. // price_float, _ := strconv.ParseFloat(price, 64)
  12223. // pinyin := this.GetString("pinyin")
  12224. // wubi := this.GetString("wubi")
  12225. // tube_color, _ := this.GetInt64("tube_color")
  12226. // team_type, _ := this.GetInt64("team_type")
  12227. // remark := this.GetString("remark")
  12228. // ids := this.GetString("ids")
  12229. // item_id := this.GetString("item_id")
  12230. // projectTeam := models.XtHisProjectTeam{
  12231. // ProjectTeam: project_team,
  12232. // Price: price_float,
  12233. // Pinyin: pinyin,
  12234. // Wubi: wubi,
  12235. // TubeColor: tube_color,
  12236. // TeamType: team_type,
  12237. // Remark: remark,
  12238. // ProjectId: ids,
  12239. // ItemId: item_id,
  12240. // }
  12241. //
  12242. //
  12243. // dataBody := make(map[string]interface{}, 0)
  12244. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  12245. // if err != nil {
  12246. // utils.ErrorLog(err.Error())
  12247. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12248. // return
  12249. // }
  12250. //
  12251. // err = service.UpdatedProjectTeam(id, &projectTeam)
  12252. //
  12253. //
  12254. // if err != nil {
  12255. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  12256. // return
  12257. // }
  12258. //
  12259. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  12260. // infos, _ := dataBody["info"].([]interface{})
  12261. // if len(infos) > 0 {
  12262. // var ids []string
  12263. //
  12264. // for _, item := range infos {
  12265. // items := item.(map[string]interface{})
  12266. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  12267. // utils.ErrorLog("id")
  12268. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12269. // return
  12270. // }
  12271. // id := int64(items["id"].(float64))
  12272. //
  12273. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12274. // utils.ErrorLog("type")
  12275. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12276. // return
  12277. // }
  12278. // types := int64(items["type"].(float64))
  12279. //
  12280. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  12281. // utils.ErrorLog("number")
  12282. // }
  12283. //
  12284. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  12285. //
  12286. // projectList := models.XtHisProjectList{
  12287. // Number: number,
  12288. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  12289. // ProjectId: id,
  12290. // Status: 1,
  12291. // CreatedTime: time.Now().Unix(),
  12292. // UpdatedTime: time.Now().Unix(),
  12293. // TeamId: projectTeam.ID,
  12294. // Type: types,
  12295. // }
  12296. // list := projectList
  12297. //
  12298. // service.CreateProjectList(&list)
  12299. //
  12300. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  12301. //
  12302. // }
  12303. // ids_str := strings.Join(ids, ",")
  12304. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  12305. // service.SaveProjectTeam(&projectTeam)
  12306. // this.ServeSuccessJSON(map[string]interface{}{
  12307. // "projectTeam": projectTeam,
  12308. // })
  12309. // }
  12310. // }
  12311. //}
  12312. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  12313. name := c.GetString("name")
  12314. mode_id, _ := c.GetInt64("mode", 0)
  12315. types, _ := c.GetInt64("type", 0)
  12316. patient_id, _ := c.GetInt64("patient_id", 0)
  12317. types = 1
  12318. adminInfo := c.GetAdminUserInfo()
  12319. template := &models.HisPrescriptionTemplate{
  12320. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  12321. PatientId: patient_id,
  12322. Type: types,
  12323. Status: 1,
  12324. Ctime: time.Now().Unix(),
  12325. Mtime: time.Now().Unix(),
  12326. Name: name,
  12327. Mode: mode_id,
  12328. }
  12329. dataBody := make(map[string]interface{}, 0)
  12330. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  12331. if err != nil {
  12332. utils.ErrorLog(err.Error())
  12333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12334. return
  12335. }
  12336. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  12337. //如果已经存在记录则删除处方
  12338. if template_one.ID > 0 {
  12339. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  12340. var ids []int64
  12341. var org_id int64
  12342. for _, item := range ps {
  12343. org_id = c.GetAdminUserInfo().CurrentOrgId
  12344. ids = append(ids, item.ID)
  12345. }
  12346. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  12347. if err2 == nil {
  12348. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12349. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12350. if len(prescriptions) > 0 {
  12351. for _, item := range prescriptions {
  12352. items := item.(map[string]interface{})
  12353. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12354. utils.ErrorLog("type")
  12355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12356. return
  12357. }
  12358. types := int64(items["type"].(float64))
  12359. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12360. utils.ErrorLog("med_type")
  12361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12362. return
  12363. }
  12364. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12365. ctime := time.Now().Unix()
  12366. prescription := &models.HisPrescriptionInfoTemplate{
  12367. PatientId: patient_id,
  12368. UserOrgId: adminInfo.CurrentOrgId,
  12369. Ctime: ctime,
  12370. Mtime: ctime,
  12371. Type: types,
  12372. Modifier: adminInfo.AdminUser.Id,
  12373. Creator: adminInfo.AdminUser.Id,
  12374. Status: 1,
  12375. PTemplateId: template_one.ID,
  12376. MedType: med_type,
  12377. }
  12378. service.CreateHisPrescriptionInfoTemplate(prescription)
  12379. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12380. advices := items["advices"].([]interface{})
  12381. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12382. ctime := time.Now().Unix()
  12383. mtime := ctime
  12384. if len(advices) > 0 {
  12385. for _, advice := range advices {
  12386. var s models.HisPrescriptionAdviceTemplate
  12387. s.PrescriptionId = prescription.ID
  12388. s.AdviceType = 2
  12389. s.StopState = 2
  12390. s.ExecutionState = 2
  12391. s.Status = 1
  12392. s.UserOrgId = adminInfo.CurrentOrgId
  12393. s.CreatedTime = ctime
  12394. s.UpdatedTime = mtime
  12395. s.PatientId = patient_id
  12396. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12397. if errcode > 0 {
  12398. c.ServeFailJSONWithSGJErrorCode(errcode)
  12399. return
  12400. }
  12401. service.CreateHisPrescriptionAdviceTemplate(&s)
  12402. }
  12403. }
  12404. }
  12405. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12406. projects := items["project"].([]interface{})
  12407. if len(projects) > 0 {
  12408. for _, project := range projects {
  12409. var p models.HisPrescriptionProjectTemplate
  12410. p.PrescriptionId = prescription.ID
  12411. p.Ctime = time.Now().Unix()
  12412. p.Mtime = time.Now().Unix()
  12413. p.PatientId = patient_id
  12414. p.UserOrgId = adminInfo.CurrentOrgId
  12415. p.Status = 1
  12416. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12417. if errcode > 0 {
  12418. c.ServeFailJSONWithSGJErrorCode(errcode)
  12419. return
  12420. }
  12421. service.CreateHisPrescriptionProjectTemplate(&p)
  12422. }
  12423. }
  12424. }
  12425. }
  12426. c.ServeSuccessJSON(map[string]interface{}{
  12427. "msg": "创建成功",
  12428. })
  12429. }
  12430. }
  12431. } else {
  12432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12433. return
  12434. }
  12435. } else {
  12436. err3 := service.CreateHisPrescriptionTemplate(template)
  12437. if err3 == nil {
  12438. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12439. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12440. if len(prescriptions) > 0 {
  12441. for _, item := range prescriptions {
  12442. items := item.(map[string]interface{})
  12443. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  12444. utils.ErrorLog("type")
  12445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12446. return
  12447. }
  12448. types := int64(items["type"].(float64))
  12449. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  12450. utils.ErrorLog("med_type")
  12451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12452. return
  12453. }
  12454. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  12455. ctime := time.Now().Unix()
  12456. prescription := &models.HisPrescriptionInfoTemplate{
  12457. PatientId: patient_id,
  12458. UserOrgId: adminInfo.CurrentOrgId,
  12459. Ctime: ctime,
  12460. Mtime: ctime,
  12461. Type: types,
  12462. Modifier: adminInfo.AdminUser.Id,
  12463. Creator: adminInfo.AdminUser.Id,
  12464. Status: 1,
  12465. PTemplateId: template.ID,
  12466. MedType: med_type,
  12467. }
  12468. service.CreateHisPrescriptionInfoTemplate(prescription)
  12469. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12470. advices := items["advices"].([]interface{})
  12471. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12472. ctime := time.Now().Unix()
  12473. mtime := ctime
  12474. if len(advices) > 0 {
  12475. for _, advice := range advices {
  12476. var s models.HisPrescriptionAdviceTemplate
  12477. s.PrescriptionId = prescription.ID
  12478. s.AdviceType = 2
  12479. s.StopState = 2
  12480. s.ExecutionState = 2
  12481. s.Status = 1
  12482. s.UserOrgId = adminInfo.CurrentOrgId
  12483. s.CreatedTime = ctime
  12484. s.UpdatedTime = mtime
  12485. s.PatientId = patient_id
  12486. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  12487. if errcode > 0 {
  12488. c.ServeFailJSONWithSGJErrorCode(errcode)
  12489. return
  12490. }
  12491. service.CreateHisPrescriptionAdviceTemplate(&s)
  12492. }
  12493. }
  12494. }
  12495. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12496. projects := items["project"].([]interface{})
  12497. if len(projects) > 0 {
  12498. for _, project := range projects {
  12499. var p models.HisPrescriptionProjectTemplate
  12500. p.PrescriptionId = prescription.ID
  12501. p.Ctime = time.Now().Unix()
  12502. p.Mtime = time.Now().Unix()
  12503. p.PatientId = patient_id
  12504. p.UserOrgId = adminInfo.CurrentOrgId
  12505. p.Status = 1
  12506. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  12507. if errcode > 0 {
  12508. c.ServeFailJSONWithSGJErrorCode(errcode)
  12509. return
  12510. }
  12511. service.CreateHisPrescriptionProjectTemplate(&p)
  12512. }
  12513. }
  12514. }
  12515. }
  12516. c.ServeSuccessJSON(map[string]interface{}{
  12517. "msg": "创建成功",
  12518. })
  12519. }
  12520. }
  12521. } else {
  12522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12523. return
  12524. }
  12525. }
  12526. }
  12527. func (c *HisApiController) PreSettle() {
  12528. id, _ := c.GetInt64("id")
  12529. record_time := c.GetString("record_time")
  12530. his_patient_id, _ := c.GetInt64("his_patient_id")
  12531. timeLayout := "2006-01-02"
  12532. loc, _ := time.LoadLocation("Local")
  12533. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  12534. diagnosis_id := c.GetString("diagnosis")
  12535. sick_type, _ := c.GetInt64("sick_type")
  12536. reg_type, _ := c.GetInt64("p_type")
  12537. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  12539. if err != nil {
  12540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12541. return
  12542. }
  12543. recordDateTime := theTime.Unix()
  12544. adminUser := c.GetAdminUserInfo()
  12545. var prescriptions []*models.HisPrescription
  12546. var start_time int64
  12547. var end_time int64
  12548. ids_str := c.GetString("ids")
  12549. ids_arr := strings.Split(ids_str, ",")
  12550. fmt.Println(reg_type)
  12551. if settle_accounts_type == 1 { //日结
  12552. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  12553. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  12554. } else {
  12555. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  12556. }
  12557. fmt.Println(prescriptions)
  12558. } else { //月结
  12559. start_time_str := c.GetString("start_time")
  12560. end_time_str := c.GetString("end_time")
  12561. timeLayout := "2006-01-02"
  12562. loc, _ := time.LoadLocation("Local")
  12563. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  12564. if err != nil {
  12565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12566. return
  12567. }
  12568. recordStartTime := theStartTime.Unix()
  12569. start_time = recordStartTime
  12570. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  12571. if err != nil {
  12572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12573. return
  12574. }
  12575. recordEndTime := theEndTime.Unix()
  12576. end_time = recordEndTime
  12577. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  12578. }
  12579. if reg_type == 1111 || reg_type == 1112 {
  12580. reg_type = 11
  12581. }
  12582. timestamp := time.Now().Unix()
  12583. tempTime := time.Unix(timestamp, 0)
  12584. timeFormat := tempTime.Format("20060102150405")
  12585. chrgBchno := rand.Intn(100000) + 10000
  12586. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  12587. strconv.FormatInt(his.PatientId, 10)
  12588. var ids []int64
  12589. for _, item := range prescriptions {
  12590. ids = append(ids, item.ID)
  12591. }
  12592. fmt.Println(ids)
  12593. var total float64
  12594. for _, item := range prescriptions {
  12595. fmt.Println(item)
  12596. if item.Type == 1 { //药品
  12597. for _, subItem := range item.HisDoctorAdviceInfo {
  12598. total = total + (subItem.Price * subItem.PrescribingNumber)
  12599. }
  12600. }
  12601. if item.Type == 2 { //项目
  12602. for _, subItem := range item.HisPrescriptionProject {
  12603. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12604. total = total + (subItem.Price * cnt)
  12605. }
  12606. }
  12607. for _, subItem := range item.HisAdditionalCharge {
  12608. total = total + (subItem.Price * float64(subItem.Count))
  12609. }
  12610. }
  12611. allTotal := fmt.Sprintf("%.2f", total)
  12612. totals, _ := strconv.ParseFloat(allTotal, 64)
  12613. order := &models.HisOrder{
  12614. UserOrgId: adminUser.CurrentOrgId,
  12615. HisPatientId: his.ID,
  12616. PatientId: id,
  12617. SettleAccountsDate: recordDateTime,
  12618. Ctime: time.Now().Unix(),
  12619. Mtime: time.Now().Unix(),
  12620. Status: 1,
  12621. OrderStatus: 1,
  12622. MdtrtId: his.Number,
  12623. Number: chrg_bchno,
  12624. MedfeeSumamt: totals,
  12625. SettleEndTime: end_time,
  12626. SettleStartTime: start_time,
  12627. SettleType: settle_accounts_type,
  12628. PsnPartAmt: totals,
  12629. PsnCashPay: totals,
  12630. PType: 2,
  12631. IsPre: 1,
  12632. MedType: strconv.Itoa(int(reg_type)),
  12633. Diagnosis: diagnosis_id,
  12634. }
  12635. err = service.CreateOrder(order)
  12636. if err != nil {
  12637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  12638. return
  12639. }
  12640. var customs []*Custom
  12641. for _, item := range prescriptions {
  12642. fmt.Println(item.Type)
  12643. if item.Type == 1 { //药品
  12644. for _, subItem := range item.HisDoctorAdviceInfo {
  12645. cus := &Custom{
  12646. AdviceId: subItem.ID,
  12647. ProjectId: 0,
  12648. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  12649. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  12650. FeedetlSn: subItem.FeedetlSn,
  12651. Price: fmt.Sprintf("%.2f", subItem.Price),
  12652. MedListCodg: subItem.MedListCodg,
  12653. Type: 1,
  12654. }
  12655. customs = append(customs, cus)
  12656. }
  12657. }
  12658. if item.Type == 2 { //项目
  12659. for _, subItem := range item.HisPrescriptionProject {
  12660. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  12661. cus := &Custom{
  12662. AdviceId: 0,
  12663. ProjectId: subItem.ID,
  12664. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  12665. Cut: fmt.Sprintf("%.2f", cnt),
  12666. FeedetlSn: subItem.FeedetlSn,
  12667. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  12668. MedListCodg: subItem.MedListCodg,
  12669. Type: 2,
  12670. }
  12671. customs = append(customs, cus)
  12672. }
  12673. }
  12674. for _, item := range item.HisAdditionalCharge {
  12675. cus := &Custom{
  12676. ItemId: item.ID,
  12677. AdviceId: 0,
  12678. ProjectId: 0,
  12679. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  12680. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  12681. FeedetlSn: item.FeedetlSn,
  12682. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  12683. MedListCodg: item.XtHisAddtionConfig.Code,
  12684. Type: 3,
  12685. }
  12686. customs = append(customs, cus)
  12687. }
  12688. }
  12689. fmt.Println(customs)
  12690. for _, item := range customs {
  12691. var advice_id int64 = 0
  12692. var project_id int64 = 0
  12693. var item_id int64 = 0
  12694. var types int64 = 0
  12695. if item.Type == 1 {
  12696. advice_id = item.AdviceId
  12697. project_id = 0
  12698. item_id = 0
  12699. } else if item.Type == 2 {
  12700. advice_id = 0
  12701. item_id = 0
  12702. project_id = item.ProjectId
  12703. } else if item.Type == 3 {
  12704. advice_id = 0
  12705. item_id = item.ItemId
  12706. project_id = 0
  12707. }
  12708. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  12709. cut, _ := strconv.ParseFloat(item.Cut, 32)
  12710. pric, _ := strconv.ParseFloat(item.Price, 32)
  12711. info := &models.HisOrderInfo{
  12712. OrderNumber: order.Number,
  12713. UploadDate: time.Now().Unix(),
  12714. AdviceId: advice_id,
  12715. DetItemFeeSumamt: detItemFeeSumamt,
  12716. Cnt: cut,
  12717. Pric: pric,
  12718. PatientId: id,
  12719. Status: 1,
  12720. Mtime: time.Now().Unix(),
  12721. Ctime: time.Now().Unix(),
  12722. UserOrgId: adminUser.CurrentOrgId,
  12723. HisPatientId: his.ID,
  12724. OrderId: order.ID,
  12725. ProjectId: project_id,
  12726. Type: types,
  12727. ItemId: item_id,
  12728. }
  12729. service.CreateOrderInfo(info)
  12730. }
  12731. his.SickType = sick_type
  12732. service.UpdataHisPateint(&his)
  12733. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  12734. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  12735. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  12736. if err == nil {
  12737. c.ServeSuccessJSON(map[string]interface{}{
  12738. "msg": "结算成功",
  12739. })
  12740. }
  12741. }
  12742. type CustomOrderInfo struct {
  12743. Name string
  12744. Spec string
  12745. Unit string
  12746. Count float64
  12747. Price float64
  12748. Total float64
  12749. }
  12750. func (c *HisApiController) GetPrivateExpensesInfo() {
  12751. order_id, _ := c.GetInt64("id", 0)
  12752. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  12753. order, _ := service.GetHisOrderByID(order_id)
  12754. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  12755. if order.ID == 0 {
  12756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  12757. return
  12758. }
  12759. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  12760. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  12761. org_id := c.GetAdminUserInfo().CurrentOrgId
  12762. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  12763. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  12764. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  12765. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  12766. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  12767. //var orderInfos_four []*models.HisOrderInfoTwo
  12768. //for _, item := range orderInfos_three {
  12769. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  12770. // item.HisPrescriptionProject.IsCheckTeam = 1
  12771. // orderInfos_four = append(orderInfos_four, item)
  12772. //
  12773. // }
  12774. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  12775. // item.HisPrescriptionProject.IsCheckTeam = 2
  12776. // orderInfos_two = append(orderInfos_two, item)
  12777. // }
  12778. //}
  12779. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  12780. //var cus_slice []CustomOrderInfo
  12781. //for _, item := range new_order_info {
  12782. // var cus CustomOrderInfo
  12783. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  12784. // cus.Unit = ""
  12785. // cus.Spec = ""
  12786. // var total float64
  12787. // for _, subItem := range orderInfos_four {
  12788. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  12789. // total = total + subItem.DetItemFeeSumamt
  12790. // fmt.Println(subItem.DetItemFeeSumamt)
  12791. // }
  12792. // }
  12793. // cus.Count = 1
  12794. // cus.Total = total
  12795. // cus_slice = append(cus_slice, cus)
  12796. //}
  12797. orderInfos = append(orderInfos, orderInfos_two...)
  12798. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  12799. //orderInfos = append(orderInfos, orderInfos_three...)
  12800. //}/**/
  12801. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  12802. c.ServeSuccessJSON(map[string]interface{}{
  12803. "order": order,
  12804. "order_info": orderInfos,
  12805. "patient": patient,
  12806. "admin_info": adminInfo,
  12807. "his": his,
  12808. "current_admin": role,
  12809. "org_config": miConfig,
  12810. //"new_order_info": cus_slice,
  12811. })
  12812. }
  12813. func (this *HisApiController) ChangeMedType() {
  12814. med_type := this.GetString("med_type")
  12815. old_med_type := this.GetString("old_med_type")
  12816. ids := this.GetString("ids")
  12817. settle_type, _ := this.GetInt64("settle_type")
  12818. start_time := this.GetString("start_time")
  12819. end_time := this.GetString("end_time")
  12820. ids_arr := strings.Split(ids, ",")
  12821. if settle_type == 1 { //日结
  12822. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  12823. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  12824. prescription.MedType = med_type
  12825. err := service.SaveHisPrescriptionTwo(&prescription)
  12826. if err == nil {
  12827. this.ServeSuccessJSON(map[string]interface{}{
  12828. "msg": "修改成功",
  12829. })
  12830. } else {
  12831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12832. return
  12833. }
  12834. } else if settle_type == 2 {
  12835. timeLayout := "2006-01-02"
  12836. loc, _ := time.LoadLocation("Local")
  12837. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12838. if err != nil {
  12839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12840. return
  12841. }
  12842. recordStartTime := theStartTime.Unix()
  12843. start_time_timestamp := recordStartTime
  12844. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  12845. if err != nil {
  12846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12847. return
  12848. }
  12849. recordEndTime := theEndTime.Unix()
  12850. end_time_timestamp := recordEndTime
  12851. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  12852. if updateErr == nil {
  12853. this.ServeSuccessJSON(map[string]interface{}{
  12854. "msg": "修改成功",
  12855. })
  12856. } else {
  12857. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  12858. return
  12859. }
  12860. }
  12861. }
  12862. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  12863. patient_id, _ := c.GetInt64("patient_id")
  12864. his_patient_id, _ := c.GetInt64("his_patient_id")
  12865. record_date := c.GetString("record_date")
  12866. start_time := c.GetString("start_time")
  12867. end_time := c.GetString("end_time")
  12868. order_status, _ := c.GetInt64("type", 0)
  12869. p_type, _ := c.GetInt64("p_type", 0)
  12870. order_id, _ := c.GetInt64("order_id", 0)
  12871. timeLayout := "2006-01-02"
  12872. loc, _ := time.LoadLocation("Local")
  12873. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12874. if err != nil {
  12875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12876. return
  12877. }
  12878. recordDateTime := theTime.Unix()
  12879. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12880. if err != nil {
  12881. }
  12882. startRecordDateTime := startTime.Unix()
  12883. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12884. if err != nil {
  12885. }
  12886. endRecordDateTime := endTime.Unix()
  12887. admin := c.GetAdminUserInfo()
  12888. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  12889. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12890. order, _ := service.GetHisOrderByID(order_id)
  12891. var monthPrescriptions []*models.HisPrescription
  12892. if order_status == 1 || order_status == 0 {
  12893. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12894. } else if order_status == 2 {
  12895. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  12896. }
  12897. var settle_total float64
  12898. for _, item := range monthPrescriptions {
  12899. if len(item.HisPrescriptionProject) > 0 {
  12900. for _, subItem := range item.HisPrescriptionProject {
  12901. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12902. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12903. settle_total = settle_total + total
  12904. }
  12905. }
  12906. if len(item.HisDoctorAdviceInfo) > 0 {
  12907. for _, subItem := range item.HisDoctorAdviceInfo {
  12908. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12909. settle_total = settle_total + total
  12910. }
  12911. }
  12912. }
  12913. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12914. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12915. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12916. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12917. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12918. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12919. //获取所有科室信息
  12920. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12921. var dia string
  12922. for _, item := range month_p_info {
  12923. if len(dia) == 0 {
  12924. dia = item.Diagnosis
  12925. } else {
  12926. dia = dia + "," + item.Diagnosis
  12927. }
  12928. }
  12929. dia_arr := removeDuplicates(strings.Split(dia, ","))
  12930. dia_arr = removeEmptyStrings(dia_arr)
  12931. c.ServeSuccessJSON(map[string]interface{}{
  12932. "his_info": his_patient_info,
  12933. "xt_info": xt_patient_info,
  12934. "case_history": case_history,
  12935. "info": patientPrescriptionInfo,
  12936. "last_info": lastPatientPrescriptionInfo,
  12937. "month_prescriptions": monthPrescriptions,
  12938. "order": order,
  12939. "doctors": doctors,
  12940. "department": department,
  12941. "settle_total": settle_total,
  12942. "dia_arr": dia_arr,
  12943. })
  12944. return
  12945. }
  12946. func removeEmptyStrings(input []string) []string {
  12947. var output []string
  12948. for _, s := range input {
  12949. if s != "" {
  12950. output = append(output, s)
  12951. }
  12952. }
  12953. return output
  12954. }
  12955. func removeDuplicates(input []string) []string {
  12956. seen := make(map[string]bool)
  12957. output := []string{}
  12958. for _, s := range input {
  12959. if _, exists := seen[s]; !exists {
  12960. seen[s] = true
  12961. output = append(output, s)
  12962. }
  12963. }
  12964. return output
  12965. }
  12966. func (c *HisApiController) GetHisMonthPatientInfo() {
  12967. patient_id, _ := c.GetInt64("patient_id")
  12968. his_patient_id, _ := c.GetInt64("his_patient_id")
  12969. record_date := c.GetString("record_date")
  12970. number := c.GetString("number")
  12971. start_time := c.GetString("start_time")
  12972. end_time := c.GetString("end_time")
  12973. p_type, _ := c.GetInt64("p_type")
  12974. timeLayout := "2006-01-02"
  12975. loc, _ := time.LoadLocation("Local")
  12976. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12977. if err != nil {
  12978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12979. return
  12980. }
  12981. recordDateTime := theTime.Unix()
  12982. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12983. if err != nil {
  12984. }
  12985. startRecordDateTime := startTime.Unix()
  12986. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12987. if err != nil {
  12988. }
  12989. endRecordDateTime := endTime.Unix()
  12990. admin := c.GetAdminUserInfo()
  12991. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12992. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12993. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12994. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12995. var settle_total float64
  12996. for _, item := range monthPrescriptions {
  12997. if len(item.HisPrescriptionProject) > 0 {
  12998. for _, subItem := range item.HisPrescriptionProject {
  12999. count, _ := strconv.ParseFloat(subItem.Count, 64)
  13000. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  13001. settle_total = settle_total + total
  13002. }
  13003. }
  13004. if len(item.HisDoctorAdviceInfo) > 0 {
  13005. for _, subItem := range item.HisDoctorAdviceInfo {
  13006. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  13007. settle_total = settle_total + total
  13008. }
  13009. }
  13010. }
  13011. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  13012. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  13013. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  13014. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  13015. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  13016. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  13017. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  13018. //获取所有科室信息
  13019. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  13020. c.ServeSuccessJSON(map[string]interface{}{
  13021. "his_info": his_patient_info,
  13022. "xt_info": xt_patient_info,
  13023. "case_history": case_history,
  13024. "info": patientPrescriptionInfo,
  13025. "month_prescriptions": monthPrescriptions,
  13026. "order": order,
  13027. "doctors": doctors,
  13028. "department": department,
  13029. "count": count,
  13030. "drugStockConfig": drugStockConfig,
  13031. "last_info": lastPatientPrescriptionInfo,
  13032. "settle_total": settle_total,
  13033. })
  13034. return
  13035. }
  13036. func (c *HisApiController) GetAllOrder() {
  13037. org_id := c.GetAdminUserInfo().CurrentOrgId
  13038. orders, _ := service.GetNewHisOrderList(org_id)
  13039. c.ServeSuccessJSON(map[string]interface{}{
  13040. "order": orders,
  13041. })
  13042. return
  13043. }
  13044. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  13045. newArr = make([]*models.HisOrderInfoTwo, 0)
  13046. for i := 0; i < len(arr); i++ {
  13047. repeat := false
  13048. for j := i + 1; j < len(arr); j++ {
  13049. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  13050. repeat = true
  13051. break
  13052. }
  13053. }
  13054. if !repeat {
  13055. newArr = append(newArr, arr[i])
  13056. }
  13057. }
  13058. return
  13059. }
  13060. // 修改处方退库操作 参数传修改之前的处方数据
  13061. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  13062. if advice.ExecutionState == 1 {
  13063. //查询该病人该药品是否有库存记录
  13064. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  13065. if errcode == gorm.ErrRecordNotFound {
  13066. } else {
  13067. //退库
  13068. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  13069. if advice.PrescribingNumberUnit == drug.MinUnit {
  13070. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13071. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13072. //退库
  13073. warehouseInfo := models.DrugWarehouseInfo{
  13074. StockMinNumber: prescribingNumber,
  13075. }
  13076. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  13077. operation_time := time.Now().Unix()
  13078. creater := advice.AdviceDoctor
  13079. ctime := time.Now().Unix()
  13080. timeStr := time.Now().Format("2006-01-02")
  13081. timeArr := strings.Split(timeStr, "-")
  13082. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13083. total = total + 1
  13084. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13085. cancelStock := models.DrugCancelStock{
  13086. OrderNumber: orderNumber,
  13087. OperaTime: operation_time,
  13088. OrgId: advice.UserOrgId,
  13089. Creater: creater,
  13090. Ctime: ctime,
  13091. Status: 1,
  13092. ReturnTime: advice.AdviceDate,
  13093. Dealer: info.Dealer,
  13094. Manufacturer: info.Manufacturer,
  13095. Type: 1,
  13096. }
  13097. service.AddSigleDrugCancelStock(&cancelStock)
  13098. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13099. dealer, _ := service.GetDealerById(info.Dealer)
  13100. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13101. cancelStockInfo := models.DrugCancelStockInfo{
  13102. OrderNumber: cancelInfo.OrderNumber,
  13103. CancelStockId: cancelInfo.ID,
  13104. DrugId: info.DrugId,
  13105. Count: info.Count,
  13106. Status: 1,
  13107. Ctime: ctime,
  13108. OrgId: advice.UserOrgId,
  13109. Type: 1,
  13110. Manufacturer: manufactureName.ManufacturerName,
  13111. Dealer: dealer.DealerName,
  13112. Total: 0,
  13113. RetailPrice: info.RetailPrice,
  13114. RetailTotalPrice: info.RetailTotalPrice,
  13115. Price: info.Price,
  13116. RegisterAccount: "",
  13117. Remark: info.Remark,
  13118. BatchNumber: info.BatchNumber,
  13119. MaxUnit: info.CountUnit,
  13120. ProductDate: info.ProductDate,
  13121. ExpiryDate: info.ExpiryDate,
  13122. BatchNumberId: info.WarehouseInfoId,
  13123. }
  13124. flow := models.DrugFlow{
  13125. WarehousingId: 0,
  13126. DrugId: info.DrugId,
  13127. Number: "",
  13128. BatchNumber: info.BatchNumber,
  13129. Count: info.Count,
  13130. UserOrgId: advice.UserOrgId,
  13131. PatientId: 0,
  13132. SystemTime: ctime,
  13133. ConsumableType: 4,
  13134. IsSys: 0,
  13135. WarehousingOrder: "",
  13136. WarehouseOutId: 0,
  13137. WarehouseOutOrderNumber: "",
  13138. IsEdit: 0,
  13139. CancelStockId: cancelStock.ID,
  13140. CancelOrderNumber: cancelStock.OrderNumber,
  13141. Manufacturer: info.Manufacturer,
  13142. Dealer: info.Dealer,
  13143. Creator: advice.UserOrgId,
  13144. UpdateCreator: 0,
  13145. Status: 1,
  13146. Ctime: time.Now().Unix(),
  13147. Mtime: 0,
  13148. Price: info.Price,
  13149. WarehousingDetailId: 0,
  13150. WarehouseOutDetailId: 0,
  13151. CancelOutDetailId: 0,
  13152. ExpireDate: info.ExpiryDate,
  13153. ProductDate: info.ProductDate,
  13154. MaxUnit: info.CountUnit,
  13155. MinUnit: "",
  13156. }
  13157. service.CreatedCancelStock(cancelStockInfo)
  13158. service.CreateDrugFlowOne(flow)
  13159. } else {
  13160. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  13161. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  13162. if advice.PrescribingNumberUnit == drug.MaxUnit {
  13163. warehouseInfo := models.DrugWarehouseInfo{
  13164. StockMinNumber: prescribingNumber,
  13165. }
  13166. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  13167. }
  13168. operation_time := time.Now().Unix()
  13169. creater := advice.AdviceDoctor
  13170. ctime := time.Now().Unix()
  13171. timeStr := time.Now().Format("2006-01-02")
  13172. timeArr := strings.Split(timeStr, "-")
  13173. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  13174. total = total + 1
  13175. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  13176. cancelStock := models.DrugCancelStock{
  13177. OrderNumber: orderNumber,
  13178. OperaTime: operation_time,
  13179. OrgId: advice.UserOrgId,
  13180. Creater: creater,
  13181. Ctime: ctime,
  13182. Status: 1,
  13183. ReturnTime: advice.AdviceDate,
  13184. Dealer: info.Dealer,
  13185. Manufacturer: info.Manufacturer,
  13186. Type: 1,
  13187. }
  13188. service.AddSigleDrugCancelStock(&cancelStock)
  13189. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  13190. dealer, _ := service.GetDealerById(info.Dealer)
  13191. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  13192. cancelStockInfo := models.DrugCancelStockInfo{
  13193. OrderNumber: cancelInfo.OrderNumber,
  13194. CancelStockId: cancelInfo.ID,
  13195. DrugId: info.DrugId,
  13196. Count: info.Count,
  13197. Status: 1,
  13198. Ctime: ctime,
  13199. OrgId: advice.UserOrgId,
  13200. Type: 1,
  13201. Manufacturer: manufactureName.ManufacturerName,
  13202. Dealer: dealer.DealerName,
  13203. Total: 0,
  13204. RetailPrice: info.RetailPrice,
  13205. RetailTotalPrice: info.RetailTotalPrice,
  13206. Price: info.Price,
  13207. RegisterAccount: "",
  13208. Remark: info.Remark,
  13209. BatchNumber: info.BatchNumber,
  13210. MaxUnit: info.CountUnit,
  13211. ProductDate: info.ProductDate,
  13212. ExpiryDate: info.ExpiryDate,
  13213. BatchNumberId: info.WarehouseInfoId,
  13214. }
  13215. flow := models.DrugFlow{
  13216. WarehousingId: 0,
  13217. DrugId: info.DrugId,
  13218. Number: "",
  13219. BatchNumber: info.BatchNumber,
  13220. Count: info.Count,
  13221. UserOrgId: advice.UserOrgId,
  13222. PatientId: 0,
  13223. SystemTime: ctime,
  13224. ConsumableType: 4,
  13225. IsSys: 0,
  13226. WarehousingOrder: "",
  13227. WarehouseOutId: 0,
  13228. WarehouseOutOrderNumber: "",
  13229. IsEdit: 0,
  13230. CancelStockId: cancelStock.ID,
  13231. CancelOrderNumber: cancelStock.OrderNumber,
  13232. Manufacturer: info.Manufacturer,
  13233. Dealer: info.Dealer,
  13234. Creator: advice.AdviceDoctor,
  13235. UpdateCreator: 0,
  13236. Status: 1,
  13237. Ctime: time.Now().Unix(),
  13238. Mtime: 0,
  13239. Price: info.Price,
  13240. WarehousingDetailId: 0,
  13241. WarehouseOutDetailId: 0,
  13242. CancelOutDetailId: 0,
  13243. ExpireDate: info.ExpiryDate,
  13244. ProductDate: info.ProductDate,
  13245. MaxUnit: info.CountUnit,
  13246. MinUnit: "",
  13247. }
  13248. service.CreatedCancelStock(cancelStockInfo)
  13249. service.CreateDrugFlowOne(flow)
  13250. }
  13251. }
  13252. }
  13253. return err
  13254. }
  13255. func (this *HisApiController) DeleteNCDS() {
  13256. id, _ := this.GetInt64("id", 0)
  13257. if id > 0 {
  13258. service.DeletePsnNCDSRecordById(id)
  13259. this.ServeSuccessJSON(map[string]interface{}{
  13260. "msg": "删除成功",
  13261. })
  13262. } else {
  13263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  13264. return
  13265. }
  13266. }
  13267. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  13268. id, _ := c.GetInt64("id")
  13269. advice, _ := service.GetHisDoctorAdviceInfo(id)
  13270. c.ServeSuccessJSON(map[string]interface{}{
  13271. "advice": advice,
  13272. })
  13273. return
  13274. }
  13275. func (c *HisApiController) GetHisMonthChargePatientList() {
  13276. record_date := c.GetString("record_date")
  13277. start_time := c.GetString("start_time")
  13278. end_time := c.GetString("end_time")
  13279. timeLayout := "2006-01-02"
  13280. loc, _ := time.LoadLocation("Local")
  13281. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  13282. if err != nil {
  13283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13284. return
  13285. }
  13286. if err != nil {
  13287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13288. return
  13289. }
  13290. recordDateTime := theTime.Unix()
  13291. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  13292. if err != nil {
  13293. }
  13294. startRecordDateTime := startTime.Unix()
  13295. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  13296. if err != nil {
  13297. }
  13298. endRecordDateTime := endTime.Unix()
  13299. adminInfo := c.GetAdminUserInfo()
  13300. var tempMonthChargePatients []*service.MonthChargePatients
  13301. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  13302. for _, item := range tempPatients {
  13303. //过滤没有处方的
  13304. if len(item.HisPrescription) == 0 {
  13305. tempMonthChargePatients = append(tempMonthChargePatients, item)
  13306. }
  13307. }
  13308. c.ServeSuccessJSON(map[string]interface{}{
  13309. "list": tempMonthChargePatients,
  13310. })
  13311. }
  13312. // PrescriptionDifference 医嘱数量差值结构体
  13313. type PrescriptionDrugDifference struct {
  13314. DrugID int64 //基础库药品id
  13315. ID int64 //医嘱id
  13316. Difference float64 //差值
  13317. Unit string //单位
  13318. }
  13319. type PrescriptionGoodDifference struct {
  13320. GoodID int64 //基础库项目耗材id
  13321. ID int64 //医嘱id
  13322. Difference int64 //差值
  13323. Unit string //单位
  13324. Type int64 //类型
  13325. }
  13326. type EditCustomData struct {
  13327. adviceList []*models.HisDoctorAdviceInfo
  13328. projectList []*models.HisPrescriptionProject
  13329. }
  13330. type SrcCustomData struct {
  13331. adviceList []*models.HisDoctorAdviceInfo
  13332. projectList []*models.HisPrescriptionProject
  13333. }
  13334. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  13335. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  13336. differences := make([]*PrescriptionDrugDifference, 0)
  13337. // 创建一个 map 来存储第一个切片中的药品信息
  13338. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  13339. for _, advice := range firstPrescription {
  13340. firstMap[advice.DrugId] = advice
  13341. }
  13342. // 遍历第二个切片中的药品信息,并比较数量差值
  13343. for _, advice := range secondPrescription {
  13344. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  13345. diff := &PrescriptionDrugDifference{
  13346. DrugID: advice.DrugId,
  13347. ID: firstAdvice.ID,
  13348. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  13349. Unit: firstAdvice.PrescribingNumberUnit,
  13350. }
  13351. differences = append(differences, diff)
  13352. }
  13353. }
  13354. return differences
  13355. }
  13356. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  13357. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  13358. differences := make([]*PrescriptionGoodDifference, 0)
  13359. // 创建一个 map 来存储第一个切片中的耗材信息
  13360. firstMap := make(map[int64]*models.HisPrescriptionProject)
  13361. for _, good := range firstPrescription {
  13362. firstMap[good.ProjectId] = good
  13363. }
  13364. // 遍历第二个切片中的耗材信息,并比较数量差值
  13365. for _, good := range secondPrescription {
  13366. if firstGood, ok := firstMap[good.ProjectId]; ok {
  13367. count, _ := strconv.ParseInt(good.Count, 10, 64)
  13368. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  13369. diff := &PrescriptionGoodDifference{
  13370. GoodID: good.ProjectId,
  13371. ID: firstGood.ID,
  13372. Difference: count - firstCount,
  13373. Unit: firstGood.Unit,
  13374. Type: firstGood.Type,
  13375. }
  13376. differences = append(differences, diff)
  13377. }
  13378. }
  13379. return differences
  13380. }
  13381. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  13382. var adviceList []*models.HisDoctorAdviceInfo
  13383. var projectList []*models.HisPrescriptionProject
  13384. var advice_ids []int64
  13385. var project_ids []int64
  13386. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  13387. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  13388. //var tempPrescription *models.HisPrescriptionProjectscription
  13389. if len(prescriptions) > 0 {
  13390. for _, item := range prescriptions {
  13391. items := item.(map[string]interface{})
  13392. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  13393. advices := items["advices"].([]interface{})
  13394. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  13395. groupNo := int64(0)
  13396. ctime := time.Now().Unix()
  13397. mtime := ctime
  13398. if len(advices) > 0 {
  13399. for _, advice := range advices {
  13400. var s models.HisDoctorAdviceInfo
  13401. s.AdviceType = 2
  13402. s.StopState = 2
  13403. s.ExecutionState = 2
  13404. s.Status = 1
  13405. s.Groupno = groupNo
  13406. s.CreatedTime = ctime
  13407. s.UpdatedTime = mtime
  13408. s.IsSettle = 2
  13409. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  13410. //存储切片中
  13411. if s.ID > 0 {
  13412. advice_ids = append(advice_ids, s.ID)
  13413. adviceList = append(adviceList, &s)
  13414. }
  13415. }
  13416. }
  13417. }
  13418. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  13419. projects := items["project"].([]interface{})
  13420. if len(projects) > 0 {
  13421. for _, project := range projects {
  13422. var p models.HisPrescriptionProject
  13423. p.Ctime = time.Now().Unix()
  13424. p.Mtime = time.Now().Unix()
  13425. p.Status = 1
  13426. SetProjectWithJSON(&p, project.(map[string]interface{}))
  13427. if p.ID > 0 {
  13428. project_ids = append(project_ids, p.ID)
  13429. projectList = append(projectList, &p)
  13430. }
  13431. }
  13432. }
  13433. }
  13434. }
  13435. }
  13436. }
  13437. editCustomData.projectList = projectList
  13438. editCustomData.adviceList = adviceList
  13439. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  13440. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  13441. srcCustomData.adviceList = list
  13442. srcCustomData.projectList = list2
  13443. return
  13444. }
  13445. func (c *HisApiController) GetAllGoodInforList() {
  13446. orgId := c.GetAdminUserInfo().CurrentOrgId
  13447. goodList, _ := service.GetAllGoodList(orgId)
  13448. c.ServeSuccessJSON(map[string]interface{}{
  13449. "goodList": goodList,
  13450. })
  13451. return
  13452. }
  13453. func (this *HisApiController) SaveGoodList() {
  13454. project_name := this.GetString("project_name")
  13455. sort, _ := this.GetInt64("sort")
  13456. orgId := this.GetAdminUserInfo().CurrentOrgId
  13457. dataBody := make(map[string]interface{}, 0)
  13458. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13459. if err != nil {
  13460. utils.ErrorLog(err.Error())
  13461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13462. return
  13463. }
  13464. goodTeam := models.XtGoodTeam{
  13465. ProjectName: project_name,
  13466. Sort: sort,
  13467. UserOrgId: orgId,
  13468. Status: 1,
  13469. Ctime: time.Now().Unix(),
  13470. Mtime: time.Now().Unix(),
  13471. }
  13472. service.CreateGoodTeam(goodTeam)
  13473. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13474. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13475. infos, _ := dataBody["info"].([]interface{})
  13476. if len(infos) > 0 {
  13477. for _, item := range infos {
  13478. items := item.(map[string]interface{})
  13479. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13480. utils.ErrorLog("good_id")
  13481. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13482. return
  13483. }
  13484. good_id := int64(items["good_id"].(float64))
  13485. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13486. utils.ErrorLog("number")
  13487. }
  13488. number := int64(items["number"].(float64))
  13489. xtGoodTeamList := models.XtGoodTeamList{
  13490. GoodId: good_id,
  13491. Count: number,
  13492. TeamId: lastGoodTeam.ID,
  13493. UserOrgId: orgId,
  13494. Status: 1,
  13495. Ctime: time.Now().Unix(),
  13496. Mtime: time.Now().Unix(),
  13497. }
  13498. service.CreateGoodList(xtGoodTeamList)
  13499. }
  13500. this.ServeSuccessJSON(map[string]interface{}{
  13501. "lastGoodTeam": lastGoodTeam,
  13502. })
  13503. }
  13504. }
  13505. return
  13506. }
  13507. func (this *HisApiController) GetGoodList() {
  13508. orgId := this.GetAdminUserInfo().CurrentOrgId
  13509. limit, _ := this.GetInt64("limit")
  13510. page, _ := this.GetInt64("page")
  13511. keyword := this.GetString("keyword")
  13512. list, total, _ := service.GetGoodList(orgId, limit, page, keyword)
  13513. this.ServeSuccessJSON(map[string]interface{}{
  13514. "list": list,
  13515. "total": total,
  13516. })
  13517. }
  13518. func (this *HisApiController) GetGoodNameDetail() {
  13519. id, _ := this.GetInt64("id")
  13520. orgId := this.GetAdminUserInfo().CurrentOrgId
  13521. goodNameDetail, _ := service.GetGoodNameDetail(id, orgId)
  13522. goodList, _ := service.GetAllGoodList(orgId)
  13523. this.ServeSuccessJSON(map[string]interface{}{
  13524. "goodNameDetail": goodNameDetail,
  13525. "goodList": goodList,
  13526. })
  13527. }
  13528. func (this *HisApiController) UpdateGoodList() {
  13529. project_name := this.GetString("project_name")
  13530. sort, _ := this.GetInt64("sort")
  13531. id, _ := this.GetInt64("id")
  13532. orgId := this.GetAdminUserInfo().CurrentOrgId
  13533. dataBody := make(map[string]interface{}, 0)
  13534. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  13535. if err != nil {
  13536. utils.ErrorLog(err.Error())
  13537. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13538. return
  13539. }
  13540. goodTeam := models.XtGoodTeam{
  13541. ProjectName: project_name,
  13542. Sort: sort,
  13543. UserOrgId: orgId,
  13544. Status: 1,
  13545. Ctime: time.Now().Unix(),
  13546. Mtime: time.Now().Unix(),
  13547. ID: id,
  13548. }
  13549. service.SaveGoodTeam(goodTeam)
  13550. lastGoodTeam, _ := service.GetLastGoodTeam(orgId)
  13551. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  13552. infos, _ := dataBody["info"].([]interface{})
  13553. if len(infos) > 0 {
  13554. for _, item := range infos {
  13555. items := item.(map[string]interface{})
  13556. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  13557. utils.ErrorLog("good_id")
  13558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13559. return
  13560. }
  13561. good_id := int64(items["good_id"].(float64))
  13562. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  13563. utils.ErrorLog("id")
  13564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  13565. return
  13566. }
  13567. id := int64(items["id"].(float64))
  13568. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "float64" {
  13569. utils.ErrorLog("number")
  13570. }
  13571. number := int64(items["number"].(float64))
  13572. xtGoodTeamList := models.XtGoodTeamList{
  13573. ID: id,
  13574. GoodId: good_id,
  13575. Count: number,
  13576. TeamId: lastGoodTeam.ID,
  13577. UserOrgId: orgId,
  13578. Status: 1,
  13579. Ctime: time.Now().Unix(),
  13580. Mtime: time.Now().Unix(),
  13581. }
  13582. service.SaveGoodList(xtGoodTeamList)
  13583. }
  13584. this.ServeSuccessJSON(map[string]interface{}{
  13585. "lastGoodTeam": lastGoodTeam,
  13586. })
  13587. }
  13588. }
  13589. return
  13590. }
  13591. func (this *HisApiController) DeleteGoodTeam() {
  13592. id, _ := this.GetInt64("id")
  13593. team, _ := service.DeleteGoodTeam(id)
  13594. this.ServeSuccessJSON(map[string]interface{}{
  13595. "team": team,
  13596. })
  13597. }
  13598. func (this *HisApiController) DeleteGood() {
  13599. id, _ := this.GetInt64("id")
  13600. good, _ := service.DeleteGood(id)
  13601. this.ServeSuccessJSON(map[string]interface{}{
  13602. "good": good,
  13603. })
  13604. }