his_api_controller.go 545KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014
  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. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. //if number >= 1000 {
  187. // zero = "0000" + strconv.FormatInt(number, 10)
  188. //} else if number >= 10000 {
  189. // zero = "000" + strconv.FormatInt(number, 10)
  190. //} else if number >= 100000 {
  191. // zero = "00" + strconv.FormatInt(number, 10)
  192. //} else if number >= 1000000 {
  193. // zero = "0" + strconv.FormatInt(number, 10)
  194. //} else {
  195. zero = "0" + strconv.FormatInt(number, 10)
  196. //}
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. if order.IsMedicineInsurance != 1 {
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. }
  1023. for _, item := range orderInfos {
  1024. if item.MedChrgitmType == "01" { //床位费
  1025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1028. }
  1029. if item.MedChrgitmType == "02" { //诊察费
  1030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1031. //zhenChaCostSelfTotal = zhenChaCostTotal
  1032. }
  1033. if item.MedChrgitmType == "03" { //检查费
  1034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1037. }
  1038. if item.MedChrgitmType == "02" { //检查费
  1039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1042. }
  1043. if item.MedChrgitmType == "04" { //化验费
  1044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "05" { //治疗费
  1049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "06" { //手术费
  1054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "09" { //西药费
  1064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "11" { //中成费
  1069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. }
  1079. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1080. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1081. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1082. var dia_config []*models.HisXtDiagnoseConfig
  1083. var diagnosis_ids []string
  1084. if his.ID > 0 {
  1085. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1086. } else {
  1087. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1088. }
  1089. for _, item := range diagnosis_ids {
  1090. id, _ := strconv.ParseInt(item, 10, 64)
  1091. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1092. dia_config = append(dia_config, diagnosisConfig)
  1093. }
  1094. var rf []CustomFundPay
  1095. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1096. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "patient": patient,
  1099. "order_infos": orderInfos,
  1100. "diagnosis": name,
  1101. "bedCostTotal": bedCostTotal,
  1102. "bedCostSelfTotal": bedCostTotal,
  1103. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1104. "operationCostTotal": operationCostTotal,
  1105. "operationCostSelfTotal": operationCostTotal,
  1106. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1107. "otherCostTotal": otherCostTotal,
  1108. "otherCostSelfTotal": otherCostTotal,
  1109. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1110. "materialCostTotal": materialCostTotal,
  1111. "materialCostSelfTotal": materialCostTotal,
  1112. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1113. "westernMedicineCostTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1116. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1119. "checkCostTotal": checkCostTotal,
  1120. "checkCostSelfTotal": checkCostTotal,
  1121. "zhenChaCostTotal": zhenChaCostTotal,
  1122. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1123. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1124. "laboratoryCostTotal": laboratoryCostTotal,
  1125. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1126. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1127. "treatCostTotal": treatCostTotal,
  1128. "treatCostSelfTotal": treatCostTotal,
  1129. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1130. "charge_admin": charge_admin,
  1131. "printor_admin": printor_admin,
  1132. "org_name": org.OrgName,
  1133. "org_code": miConfig.Code,
  1134. "name": patient.Name,
  1135. "number": order.MdtrtId,
  1136. "date": order.SettleAccountsDate,
  1137. "info": order,
  1138. "new_order": order,
  1139. "his_hospital": his_hospital,
  1140. "his": his,
  1141. "funds": rf,
  1142. "dia_config": dia_config,
  1143. })
  1144. }
  1145. func (c *HisApiController) RefudDetail() {
  1146. order_id, _ := c.GetInt64("order_id")
  1147. order, _ := service.GetHisOrderByID(order_id)
  1148. adminUser := c.GetAdminUserInfo()
  1149. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "撤销成功",
  1152. })
  1153. }
  1154. func (c *HisApiController) Sscard() {
  1155. //r := CardInit()
  1156. //if r == 0 {
  1157. // GetBaseInfo()
  1158. //}
  1159. //c.ServeSuccessJSON(map[string]interface{}{
  1160. // "list": "11",
  1161. //})
  1162. }
  1163. func GetBaseInfo() error {
  1164. //handle := syscall.MustLoadDLL("SSCard.dll")
  1165. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1166. //
  1167. //str := make([]byte, 256)
  1168. //str1 := make([]byte, 256)
  1169. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1170. //if ferr != nil {
  1171. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1172. // return ferr
  1173. //}
  1174. //
  1175. //fmt.Println(string(str))
  1176. //
  1177. //fmt.Println(r)
  1178. return nil
  1179. }
  1180. func CardInit() int {
  1181. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1182. //add := DllTestDef.MustFindProc("Init")
  1183. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1184. //if err != nil {
  1185. // fmt.Println("SSCard的运算结果为:", ret)
  1186. //}
  1187. //result := int(ret)
  1188. return 0
  1189. }
  1190. func IntPtr(n int) uintptr {
  1191. return uintptr(n)
  1192. }
  1193. func StrPtr(s string) uintptr {
  1194. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1195. }
  1196. func (c *HisApiController) GetHisPatientList() {
  1197. //types, _ := c.GetInt64("type", 0)
  1198. record_date := c.GetString("record_date")
  1199. sch_type, _ := c.GetInt64("sch_type")
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. recordDateTime := theTime.Unix()
  1208. adminInfo := c.GetAdminUserInfo()
  1209. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1210. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1211. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1212. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1213. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1214. //获取当前用户的信息
  1215. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1216. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1217. //获取所有科室信息
  1218. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1219. //var aa []service.PatientThree
  1220. noElementsSlice := make([]service.PatientThree, 0)
  1221. c.ServeSuccessJSON(map[string]interface{}{
  1222. "list": patients,
  1223. "list_two": patients_two,
  1224. "list_three": noElementsSlice,
  1225. "info": adminUserInfo,
  1226. "doctors": doctors,
  1227. "department": department,
  1228. })
  1229. }
  1230. type CustomTemplate struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1233. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1235. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1236. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1237. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1238. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1239. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1240. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1241. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1242. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1243. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1244. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1245. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1246. }
  1247. func (c *HisApiController) GetHisPatientInfo() {
  1248. patient_id, _ := c.GetInt64("patient_id")
  1249. his_patient_id, _ := c.GetInt64("his_patient_id")
  1250. record_date := c.GetString("record_date")
  1251. number := c.GetString("number")
  1252. //start_time := c.GetString("start_time")
  1253. //end_time := c.GetString("end_time")
  1254. p_type, _ := c.GetInt64("p_type")
  1255. timeLayout := "2006-01-02"
  1256. loc, _ := time.LoadLocation("Local")
  1257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1258. if err != nil {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. recordDateTime := theTime.Unix()
  1263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1264. //if err != nil {
  1265. //
  1266. //}
  1267. //startRecordDateTime := startTime.Unix()
  1268. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1269. //if err != nil {
  1270. //
  1271. //}
  1272. //endRecordDateTime := endTime.Unix()
  1273. admin := c.GetAdminUserInfo()
  1274. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1275. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1277. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. var prescriptions []*models.HisPrescription
  1279. var last_prescriptions []*models.HisPrescription
  1280. var sch_prescriptions []CustomTemplate
  1281. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. if p_type == 1 { //住院
  1283. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. for _, item := range prescriptions {
  1285. for _, subItem := range item.HisDoctorAdviceInfo {
  1286. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1287. if info.RetailPrice > 0 {
  1288. subItem.Drug.MinPrice = info.RetailPrice
  1289. }
  1290. }
  1291. }
  1292. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1293. } else { //门诊
  1294. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1295. for _, item := range prescriptions {
  1296. for _, subItem := range item.HisDoctorAdviceInfo {
  1297. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1298. if info.RetailPrice > 0 {
  1299. subItem.Drug.MinPrice = info.RetailPrice
  1300. }
  1301. }
  1302. }
  1303. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1304. }
  1305. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1306. if sch.ID > 0 {
  1307. var week string
  1308. t := time.Now()
  1309. switch t.Weekday().String() {
  1310. case "Monday":
  1311. week = "周一"
  1312. break
  1313. case "Tuesday":
  1314. week = "周二"
  1315. break
  1316. case "Wednesday":
  1317. week = "周三"
  1318. break
  1319. case "Thursday":
  1320. week = "周四"
  1321. break
  1322. case "Friday":
  1323. week = "周五"
  1324. break
  1325. case "Saturday":
  1326. week = "周六"
  1327. break
  1328. case "Sunday":
  1329. week = "周日"
  1330. break
  1331. }
  1332. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1333. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1334. //根据推送频率组装新的数组
  1335. for _, item := range temp_sch_prescriptions {
  1336. var cus CustomTemplate
  1337. cus.ID = item.ID
  1338. cus.UserOrgId = item.UserOrgId
  1339. cus.PatientId = item.PatientId
  1340. cus.MedType = item.MedType
  1341. cus.RecordDate = item.RecordDate
  1342. cus.Type = item.Type
  1343. cus.PType = item.PType
  1344. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1345. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1346. if subItem.FrequencyType == 1 { //每次必推
  1347. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1348. }
  1349. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1350. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1351. }
  1352. if subItem.FrequencyType == 2 { //按照天数频率
  1353. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1354. now := p.Unix()
  1355. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1356. dayStr2 := "-" + dayStr
  1357. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1358. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1359. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1360. if len(advices) == 0 {
  1361. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1362. }
  1363. }
  1364. }
  1365. }
  1366. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1367. if subItem.Type == 2 {
  1368. if subItem.XtHisProject.MedicalStatus != 1 {
  1369. if subItem.FrequencyType == 1 {
  1370. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1371. }
  1372. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1373. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1374. }
  1375. if subItem.FrequencyType == 2 {
  1376. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1377. now := p.Unix()
  1378. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1379. dayStr2 := "-" + dayStr
  1380. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1381. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1382. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1383. if len(projects) == 0 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. }
  1387. }
  1388. } else if subItem.Type == 3 {
  1389. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1390. if subItem.FrequencyType == 1 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1394. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1395. }
  1396. if subItem.FrequencyType == 2 {
  1397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1398. now := p.Unix()
  1399. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1400. dayStr2 := "-" + dayStr
  1401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1403. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1404. if len(projects) == 0 {
  1405. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sch_prescriptions = append(sch_prescriptions, cus)
  1412. }
  1413. for _, item := range sch_prescriptions {
  1414. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1415. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1416. }
  1417. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1418. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1419. }
  1420. }
  1421. }
  1422. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1423. if config.ID > 0 && config.IsOpen == 1 {
  1424. for _, item := range sch_prescriptions {
  1425. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1426. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1427. if info.RetailPrice > 0 {
  1428. subItem.Drug.MinPrice = info.RetailPrice
  1429. if admin.CurrentOrgId != 10598 {
  1430. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1431. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if config.ID > 0 && config.IsOpen == 1 {
  1438. for _, item := range sch_prescriptions {
  1439. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1440. if subItem.Type == 3 {
  1441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1442. if info.Price > 0 {
  1443. subItem.GoodInfo.PackingPrice = info.Price
  1444. if admin.CurrentOrgId != 10598 {
  1445. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1446. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1454. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1455. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1456. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1457. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1458. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1459. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1460. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1463. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1464. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1465. c.ServeSuccessJSON(map[string]interface{}{
  1466. "his_info": his_patient_info,
  1467. "xt_info": xt_patient_info,
  1468. "prescription": prescriptions,
  1469. "case_history": case_history,
  1470. "info": patientPrescriptionInfo,
  1471. //"month_prescriptions": monthPrescriptions,
  1472. "order": order,
  1473. "doctors": doctors,
  1474. "department": department,
  1475. "sch_prescriptions": sch_prescriptions,
  1476. "last_prescriptions": last_prescriptions,
  1477. "schedule": sch,
  1478. "count": count,
  1479. "drugStockConfig": drugStockConfig,
  1480. "last_info": lastPatientPrescriptionInfo,
  1481. "befor": beforThrity,
  1482. "LastCaseHistory": LastCaseHistory,
  1483. })
  1484. return
  1485. }
  1486. func (c *HisApiController) GetHisPrescriptionConfig() {
  1487. adminInfo := c.GetAdminUserInfo()
  1488. //获取医嘱模版
  1489. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1490. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1491. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1492. //获取所有基础药
  1493. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1494. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1495. if config.ID > 0 && config.IsOpen == 1 {
  1496. for _, item := range drugs {
  1497. var index = 0
  1498. for _, subItem := range item.OtherDrugWarehouseInfo {
  1499. if index == 0 {
  1500. index = index + 1
  1501. if subItem.RetailPrice > 0 {
  1502. item.MinPrice = subItem.RetailPrice
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1509. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1510. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1511. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1512. //获取所有科室信息
  1513. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1514. //获取诊断信息
  1515. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1516. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1517. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1518. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1519. //获取是否开启保存耗材出库的开关
  1520. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "drugs": drugs,
  1523. "advices_template": advices,
  1524. "drugways": drugways,
  1525. "efs": efs,
  1526. "doctors": doctors,
  1527. "department": department,
  1528. "sick": sick,
  1529. "additions": additions,
  1530. "diagnose": diagnose,
  1531. "manufacturers": manufacturers,
  1532. "goodOutOpen": goodOutOpen,
  1533. "patientDiagnose": patientDiagnose,
  1534. })
  1535. }
  1536. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1537. //获取所有基础药
  1538. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1539. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1540. if config.ID > 0 && config.IsOpen == 1 {
  1541. for _, item := range drugs {
  1542. var index = 0
  1543. for _, subItem := range item.OtherDrugWarehouseInfo {
  1544. if index == 0 {
  1545. index = index + 1
  1546. if subItem.RetailPrice > 0 {
  1547. item.MinPrice = subItem.RetailPrice
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1554. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1555. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1556. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1557. //获取所有科室信息
  1558. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1559. //获取诊断信息
  1560. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1561. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1562. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1563. //获取是否开启保存耗材出库的开关
  1564. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1565. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1566. c.ServeSuccessJSON(map[string]interface{}{
  1567. "drugs": drugs,
  1568. "advices_template": advices,
  1569. "drugways": drugways,
  1570. "efs": efs,
  1571. "doctors": doctors,
  1572. "department": department,
  1573. "sick": sick,
  1574. "additions": additions,
  1575. "diagnose": diagnose,
  1576. "manufacturers": manufacturers,
  1577. "goodOutOpen": goodOutOpen,
  1578. "patientDiagnose": patientDiagnose,
  1579. })
  1580. }
  1581. }
  1582. func (c *HisApiController) CreateHisPrescription() {
  1583. record_date := c.GetString("record_date")
  1584. patient_id, _ := c.GetInt64("patient_id")
  1585. reg_type, _ := c.GetInt64("reg_type")
  1586. diagnose := c.GetString("diagnose")
  1587. sick_type, _ := c.GetInt64("sick_type")
  1588. sick_history := c.GetString("sick_history")
  1589. doctor_id, _ := c.GetInt64("doctor", 0)
  1590. department, _ := c.GetInt64("department", 0)
  1591. his_patient_id, _ := c.GetInt64("his_patient_id")
  1592. p_type, _ := c.GetInt64("p_type")
  1593. patient_diagnose := c.GetString("patient_diagnose")
  1594. dataBody := make(map[string]interface{}, 0)
  1595. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1596. if err != nil {
  1597. utils.ErrorLog(err.Error())
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. //edit, src := GetCompareData(dataBody)
  1602. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1603. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1604. //fmt.Println(drugResult)
  1605. //fmt.Println(goodResult)
  1606. timeLayout := "2006-01-02"
  1607. loc, _ := time.LoadLocation("Local")
  1608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1609. if err != nil {
  1610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1611. return
  1612. }
  1613. adminInfo := c.GetAdminUserInfo()
  1614. recordDateTime := theTime.Unix()
  1615. //查询默认出库仓库库存
  1616. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1617. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1618. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1619. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1620. if len(lists) == 1 {
  1621. his_patient_id = lists[0].ID
  1622. }
  1623. }
  1624. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1625. //自动出库的开关开启
  1626. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1627. //自动出库
  1628. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1629. //耗材保存处方出库
  1630. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1631. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. //已发药和已收费限制逻辑
  1633. isMidicine := false
  1634. isCharge := false
  1635. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1636. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1637. if len(prescriptions) > 0 {
  1638. for _, item := range prescriptions {
  1639. items := item.(map[string]interface{})
  1640. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1641. utils.ErrorLog("id")
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1643. return
  1644. }
  1645. id := int64(items["id"].(float64))
  1646. if id > 0 {
  1647. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1648. if err != nil {
  1649. if new_prescription.OrderStatus == 4 {
  1650. isCharge = true
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. tx.Rollback()
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. //查询药品的所有库存
  1710. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1711. var total_count int64
  1712. for _, it := range list {
  1713. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1714. }
  1715. totals := strconv.FormatInt(total_count, 10)
  1716. //查询该药品是否存在开药记录
  1717. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1718. //新增处方盘点库存是否充足
  1719. if advicelist.ID == 0 {
  1720. all_count, _ := strconv.ParseFloat(totals, 64)
  1721. if prescribingNumberUnit == drug.MinUnit {
  1722. if drug.IsUse != 1 {
  1723. if drug.IsProject == 0 || drug.IsProject == 2 {
  1724. if all_count == 0 {
  1725. tx.Rollback()
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1727. return
  1728. }
  1729. if prescribing_number > all_count {
  1730. tx.Rollback()
  1731. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1732. return
  1733. }
  1734. }
  1735. }
  1736. }
  1737. if prescribingNumberUnit == drug.MaxUnit {
  1738. num := prescribing_number * float64(drug.MinNumber)
  1739. if drug.IsUse != 1 {
  1740. if drug.IsProject == 0 || drug.IsProject == 2 {
  1741. if all_count == 0 {
  1742. tx.Rollback()
  1743. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1744. return
  1745. }
  1746. if num > all_count {
  1747. tx.Rollback()
  1748. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1749. return
  1750. }
  1751. }
  1752. }
  1753. }
  1754. }
  1755. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1756. //不使用保存处方出库
  1757. if drugOutConfig.IsOpen != 1 {
  1758. //修改处方
  1759. for _, advice := range advices {
  1760. var drug_id int64
  1761. var prescribing_number float64
  1762. var prescribingNumberUnit string
  1763. var prescribingNumber string
  1764. var adviceId int64
  1765. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1766. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1767. }
  1768. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1769. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1770. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1771. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1772. }
  1773. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1774. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1775. }
  1776. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1777. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1778. }
  1779. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1780. if drug.ID == 0 {
  1781. tx.Rollback()
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1783. return
  1784. }
  1785. //查询药品的所有库存
  1786. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1787. var total_count int64
  1788. for _, it := range list {
  1789. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1790. }
  1791. totals := strconv.FormatInt(total_count, 10)
  1792. //查询该药品是否存在开药记录
  1793. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1794. //新增处方
  1795. if advicelist.ID == 0 {
  1796. all_count, _ := strconv.ParseFloat(totals, 64)
  1797. if prescribingNumberUnit == drug.MinUnit {
  1798. if drug.IsUse != 1 {
  1799. if drug.IsProject == 0 || drug.IsProject == 2 {
  1800. if all_count == 0 {
  1801. tx.Rollback()
  1802. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1803. return
  1804. }
  1805. if prescribing_number > all_count {
  1806. tx.Rollback()
  1807. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1808. return
  1809. }
  1810. }
  1811. }
  1812. } else {
  1813. if prescribingNumberUnit == drug.MaxUnit {
  1814. num := prescribing_number * float64(drug.MinNumber)
  1815. if drug.IsUse != 1 {
  1816. if drug.IsProject == 0 || drug.IsProject == 2 {
  1817. if all_count == 0 {
  1818. tx.Rollback()
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1820. return
  1821. }
  1822. if num > all_count {
  1823. tx.Rollback()
  1824. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1825. return
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //修改处方
  1833. if advicelist.ID > 0 {
  1834. var device_number int64
  1835. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1838. device_number = prescribingNumberInt * drug.MinNumber
  1839. }
  1840. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1841. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1842. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1843. device_number = prescribingNumberInt
  1844. }
  1845. var number_count int64
  1846. if prescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1848. number_count = prescribingNumberInt * drug.MinNumber
  1849. }
  1850. if prescribingNumberUnit == drug.MinUnit {
  1851. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1852. number_count = prescribingNumberInt
  1853. }
  1854. //如果修改的数量大于之前修改的数量
  1855. if (number_count - device_number) > 0 {
  1856. //如果修改的差数量 大于库存数量
  1857. if drug.IsUse != 1 {
  1858. if (number_count - device_number) > total_count {
  1859. tx.Rollback()
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1861. return
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. //已发药和已收费限制逻辑
  1876. //执行出库的逻辑
  1877. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1878. //校验库存总量
  1879. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1880. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1881. if len(prescriptions) > 0 {
  1882. for _, item := range prescriptions {
  1883. items := item.(map[string]interface{})
  1884. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1885. advices := items["advices"].([]interface{})
  1886. if len(advices) > 0 {
  1887. for _, advice := range advices {
  1888. var drug_id int64
  1889. var prescribing_number float64
  1890. var prescribingNumberUnit string
  1891. var adviceId int64
  1892. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1893. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1894. }
  1895. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1896. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1897. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1898. }
  1899. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1900. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1901. }
  1902. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1903. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1904. }
  1905. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1906. if drug.ID == 0 {
  1907. tx.Rollback()
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1909. return
  1910. }
  1911. //查询药品的所有库存
  1912. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1913. var total_count int64
  1914. for _, it := range list {
  1915. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1916. }
  1917. totals := strconv.FormatInt(total_count, 10)
  1918. //查询该药品是否存在开药记录
  1919. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1920. //查询最新批次库存
  1921. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1922. var batch_number_count int64
  1923. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1924. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1925. //新增处方
  1926. if advicelist.ID == 0 {
  1927. all_count, _ := strconv.ParseFloat(totals, 64)
  1928. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1929. if prescribingNumberUnit == drug.MinUnit {
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. tx.Rollback()
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1935. return
  1936. }
  1937. if prescribing_number > all_count {
  1938. tx.Rollback()
  1939. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1940. return
  1941. }
  1942. }
  1943. if adminInfo.CurrentOrgId == 10215 {
  1944. if prescribing_number > batch_number_all_count {
  1945. tx.Rollback()
  1946. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1947. return
  1948. }
  1949. }
  1950. }
  1951. }
  1952. if prescribingNumberUnit == drug.MaxUnit {
  1953. num := prescribing_number * float64(drug.MinNumber)
  1954. if drug.IsUse != 1 {
  1955. if drug.IsProject == 0 || drug.IsProject == 2 {
  1956. if all_count == 0 {
  1957. tx.Rollback()
  1958. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1959. return
  1960. }
  1961. if num > all_count {
  1962. tx.Rollback()
  1963. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1964. return
  1965. }
  1966. }
  1967. if adminInfo.CurrentOrgId == 10215 {
  1968. if num > batch_number_all_count {
  1969. tx.Rollback()
  1970. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1971. return
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. //不是保存处方出库
  1978. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1979. if drugOutConfig.IsOpen != 1 {
  1980. //修改处方
  1981. for _, advice := range advices {
  1982. var drug_id int64
  1983. var prescribing_number float64
  1984. var prescribingNumberUnit string
  1985. var prescribingNumber string
  1986. var adviceId int64
  1987. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1988. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1989. }
  1990. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1991. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1992. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1993. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1994. }
  1995. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1996. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1997. }
  1998. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1999. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2000. }
  2001. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2002. if drug.ID == 0 {
  2003. tx.Rollback()
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2005. return
  2006. }
  2007. //查询药品的所有库存
  2008. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2009. var total_count int64
  2010. for _, it := range list {
  2011. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2012. }
  2013. totals := strconv.FormatInt(total_count, 10)
  2014. //查询该药品是否存在开药记录
  2015. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2016. //新增处方
  2017. if advicelist.ID == 0 {
  2018. //查询最新批次库存
  2019. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2020. var batch_number_count int64
  2021. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2022. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2023. all_count, _ := strconv.ParseFloat(totals, 64)
  2024. if all_count == 0 {
  2025. tx.Rollback()
  2026. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2027. return
  2028. }
  2029. if prescribingNumberUnit == drug.MinUnit {
  2030. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2031. if drug.IsUse != 1 {
  2032. if drug.IsProject == 0 || drug.IsProject == 2 {
  2033. if all_count == 0 {
  2034. tx.Rollback()
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2036. return
  2037. }
  2038. if prescribing_number > all_count {
  2039. tx.Rollback()
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2041. return
  2042. }
  2043. }
  2044. if adminInfo.CurrentOrgId == 10215 {
  2045. if prescribing_number > batch_number_all_count {
  2046. tx.Rollback()
  2047. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2048. return
  2049. }
  2050. }
  2051. }
  2052. } else {
  2053. if prescribingNumberUnit == drug.MaxUnit {
  2054. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2055. num := prescribing_number * float64(drug.MinNumber)
  2056. if drug.IsUse != 1 {
  2057. if drug.IsProject == 0 || drug.IsProject == 2 {
  2058. if all_count == 0 {
  2059. tx.Rollback()
  2060. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2061. return
  2062. }
  2063. if num > all_count {
  2064. tx.Rollback()
  2065. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2066. return
  2067. }
  2068. }
  2069. if adminInfo.CurrentOrgId == 10215 {
  2070. if prescribing_number > batch_number_all_count {
  2071. tx.Rollback()
  2072. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2073. return
  2074. }
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. //修改处方
  2081. if advicelist.ID > 0 {
  2082. //查询最新批次库存
  2083. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2084. var batch_number_count int64
  2085. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2086. var device_number int64
  2087. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2088. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2090. device_number = prescribingNumberInt * drug.MinNumber
  2091. }
  2092. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2093. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2094. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2095. device_number = prescribingNumberInt
  2096. //回退库存
  2097. }
  2098. var number_count int64
  2099. if prescribingNumberUnit == drug.MaxUnit {
  2100. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2101. number_count = prescribingNumberInt * drug.MinNumber
  2102. //回退库存
  2103. }
  2104. if prescribingNumberUnit == drug.MinUnit {
  2105. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2106. number_count = prescribingNumberInt
  2107. //回退库存
  2108. }
  2109. //如果修改的数量大于之前修改的数量
  2110. if (number_count - device_number) > 0 {
  2111. //如果修改的差数量 大于库存数量
  2112. if drug.IsUse != 1 {
  2113. if drug.IsProject == 0 || drug.IsProject == 2 {
  2114. if total_count == 0 {
  2115. tx.Rollback()
  2116. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2117. return
  2118. }
  2119. if (number_count - device_number) > total_count {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. if (number_count - device_number) > batch_number_count {
  2125. tx.Rollback()
  2126. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2127. return
  2128. }
  2129. }
  2130. if adminInfo.CurrentOrgId == 10215 {
  2131. // 查询该药品最后一次出库记录
  2132. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2133. var out_count int64
  2134. var in_count int64
  2135. var stock_max_number int64
  2136. var stock_min_number int64
  2137. for _, it := range outInfo {
  2138. if it.CountUnit == drug.MaxUnit {
  2139. it.Count = it.Count * drug.MinNumber
  2140. }
  2141. out_count += it.Count
  2142. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2143. stock_max_number = warehouseInfoList.StockMaxNumber
  2144. stock_min_number = warehouseInfoList.StockMinNumber
  2145. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2146. }
  2147. if out_count > 0 {
  2148. if (number_count - device_number) > in_count {
  2149. tx.Rollback()
  2150. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2151. return
  2152. }
  2153. }
  2154. // 未出库
  2155. if out_count == 0 {
  2156. var sum_in_count int64
  2157. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2158. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2159. //如果修改的数量大于有库存的第一个批次
  2160. if number_count > sum_in_count {
  2161. tx.Rollback()
  2162. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2163. return
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. //药品发药
  2170. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2171. //不使用药品发药的功能
  2172. //if pharmacyConfig.IsOpen != 1 {
  2173. // if device_number != number_count {
  2174. //
  2175. // //查询该药品的出库记录
  2176. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2177. // if len(outListExport) > 0 {
  2178. // //
  2179. // for _, item := range outListExport {
  2180. // //回退库存
  2181. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2182. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2183. // }
  2184. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2185. // var stock_max_number int64
  2186. // var stock_min_number int64
  2187. //
  2188. // if number_count >= drug.MinNumber {
  2189. //
  2190. // stock_max_number = device_number / drug.MinNumber
  2191. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2192. //
  2193. // stock_min_number = device_number % drug.MinNumber
  2194. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2195. //
  2196. // } else {
  2197. //
  2198. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2199. //
  2200. // }
  2201. // }
  2202. //
  2203. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2204. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2205. // }
  2206. // }
  2207. // }
  2208. //
  2209. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2210. // var sum_count int64
  2211. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2212. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2213. // for _, its := range stockInfo {
  2214. // if its.MaxUnit == drug.MaxUnit {
  2215. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2216. // }
  2217. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2218. // }
  2219. // //更新字典里面的库存
  2220. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2221. //
  2222. // //剩余库存
  2223. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2224. //
  2225. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2226. // //减少出库数量
  2227. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2228. //
  2229. // }
  2230. //}
  2231. }
  2232. }
  2233. }
  2234. //保存处方开药
  2235. if drugOutConfig.IsOpen == 1 {
  2236. //修改处方
  2237. for _, advice := range advices {
  2238. var drug_id int64
  2239. var prescribing_number float64
  2240. var prescribingNumberUnit string
  2241. var prescribingNumber string
  2242. var adviceId int64
  2243. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2244. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2247. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2248. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2249. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2250. }
  2251. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2252. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2253. }
  2254. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2255. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2256. }
  2257. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2258. if drug.ID == 0 {
  2259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2260. return
  2261. }
  2262. //查询药品的所有库存
  2263. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2264. var total_count int64
  2265. for _, it := range list {
  2266. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2267. }
  2268. totals := strconv.FormatInt(total_count, 10)
  2269. //查询该药品是否存在开药记录
  2270. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2271. //新增处方
  2272. if advicelist.ID == 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2278. all_count, _ := strconv.ParseFloat(totals, 64)
  2279. if prescribingNumberUnit == drug.MinUnit {
  2280. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2281. if drug.IsUse != 1 {
  2282. if drug.IsProject == 0 || drug.IsProject == 2 {
  2283. if all_count == 0 {
  2284. tx.Rollback()
  2285. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2286. return
  2287. }
  2288. if prescribing_number > all_count {
  2289. tx.Rollback()
  2290. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2291. return
  2292. }
  2293. }
  2294. if adminInfo.CurrentOrgId == 10215 {
  2295. if prescribing_number > batch_number_all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2298. return
  2299. }
  2300. }
  2301. }
  2302. } else {
  2303. if prescribingNumberUnit == drug.MaxUnit {
  2304. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2305. num := prescribing_number * float64(drug.MinNumber)
  2306. if drug.IsUse != 1 {
  2307. if drug.IsProject == 0 || drug.IsProject == 2 {
  2308. if all_count == 0 {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2311. return
  2312. }
  2313. if num > all_count {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. }
  2319. if adminInfo.CurrentOrgId == 10215 {
  2320. if prescribing_number > batch_number_all_count {
  2321. tx.Rollback()
  2322. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2323. return
  2324. }
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. //修改处方
  2331. if advicelist.ID > 0 {
  2332. //查询最新批次库存
  2333. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2334. var batch_number_count int64
  2335. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2336. var device_number int64
  2337. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2338. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2339. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2340. device_number = prescribingNumberInt * drug.MinNumber
  2341. }
  2342. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2343. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2344. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2345. device_number = prescribingNumberInt
  2346. }
  2347. var number_count int64
  2348. if prescribingNumberUnit == drug.MaxUnit {
  2349. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2350. number_count = prescribingNumberInt * drug.MinNumber
  2351. }
  2352. if prescribingNumberUnit == drug.MinUnit {
  2353. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2354. number_count = prescribingNumberInt
  2355. }
  2356. //如果修改的数量大于之前修改的数量
  2357. if (number_count - device_number) > 0 {
  2358. //如果修改的差数量 大于库存数量
  2359. if drug.IsUse != 1 {
  2360. if drug.IsProject == 0 || drug.IsProject == 2 {
  2361. if total_count == 0 {
  2362. tx.Rollback()
  2363. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2364. return
  2365. }
  2366. if (number_count - device_number) > total_count {
  2367. tx.Rollback()
  2368. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2369. return
  2370. }
  2371. }
  2372. if adminInfo.CurrentOrgId == 10215 {
  2373. if (number_count - device_number) > batch_number_count {
  2374. tx.Rollback()
  2375. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2376. return
  2377. }
  2378. }
  2379. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2380. //查询历史出库数据总批次
  2381. // 查询该药品最后一次出库记录
  2382. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2383. var out_count int64
  2384. var in_count int64
  2385. var stock_max_number int64
  2386. var stock_min_number int64
  2387. for _, it := range outInfo {
  2388. if it.CountUnit == drug.MaxUnit {
  2389. it.Count = it.Count * drug.MinNumber
  2390. }
  2391. out_count += it.Count
  2392. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2393. stock_max_number = warehouseInfoList.StockMaxNumber
  2394. stock_min_number = warehouseInfoList.StockMinNumber
  2395. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2396. }
  2397. if out_count > 0 {
  2398. if (number_count - device_number) > in_count {
  2399. tx.Rollback()
  2400. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2401. return
  2402. }
  2403. }
  2404. // 未出库
  2405. if out_count == 0 {
  2406. var sum_in_count int64
  2407. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2408. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2409. if sum_in_count == 0 {
  2410. tx.Rollback()
  2411. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2412. return
  2413. }
  2414. //如果修改的数量大于有库存的第一个批次
  2415. if number_count > sum_in_count {
  2416. tx.Rollback()
  2417. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2418. return
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. //校验耗材库存
  2435. if goodOutConfig.IsOpen == 1 {
  2436. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2437. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2438. if len(prescriptions) > 0 {
  2439. for _, item := range prescriptions {
  2440. items := item.(map[string]interface{})
  2441. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2442. projects := items["project"].([]interface{})
  2443. if len(projects) > 0 {
  2444. for _, project := range projects {
  2445. var project_id int64
  2446. var project_type int64
  2447. var totals float64
  2448. var project_name string
  2449. var parsetotal int64
  2450. var id int64
  2451. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2452. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2453. }
  2454. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2455. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2456. }
  2457. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2458. total, _ := project.(map[string]interface{})["total"].(string)
  2459. totals, _ = strconv.ParseFloat(total, 64)
  2460. }
  2461. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2462. project_name = project.(map[string]interface{})["project_name"].(string)
  2463. }
  2464. if project_type == 3 {
  2465. //查找该耗材的出库记录
  2466. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2467. if len(goodWarehouseInfo) == 0 {
  2468. //查询耗材库存
  2469. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2470. var stock_count int64
  2471. for _, it := range list {
  2472. stock_count += it.StockCount
  2473. }
  2474. stock_counts := strconv.FormatInt(stock_count, 10)
  2475. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2476. if stock_total_count == 0 {
  2477. tx.Rollback()
  2478. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2479. return
  2480. }
  2481. if totals > stock_total_count {
  2482. tx.Rollback()
  2483. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2484. return
  2485. }
  2486. }
  2487. if len(goodWarehouseInfo) > 0 {
  2488. //查询该患者耗材的历史数据
  2489. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2490. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2491. //数量发生改变
  2492. if parsetotal != count {
  2493. //如果现在的数量大于历史数量,就要看库存是否足够
  2494. if parsetotal > count {
  2495. //查询耗材所有库存
  2496. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2497. var stock_count int64
  2498. for _, it := range list {
  2499. stock_count += it.StockCount
  2500. }
  2501. //库存不足
  2502. if stock_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2505. return
  2506. }
  2507. if (parsetotal - count) > stock_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2510. return
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. //不使用耗材保存处方出库
  2524. if goodOutConfig.IsOpen != 1 {
  2525. if stockConfig.IsOpen == 1 {
  2526. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2527. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2528. if len(prescriptions) > 0 {
  2529. for _, item := range prescriptions {
  2530. items := item.(map[string]interface{})
  2531. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2532. projects := items["project"].([]interface{})
  2533. if len(projects) > 0 {
  2534. for _, project := range projects {
  2535. var project_id int64
  2536. var project_type int64
  2537. var totals float64
  2538. var project_name string
  2539. var parsetotal int64
  2540. var id int64
  2541. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2542. id = int64(project.(map[string]interface{})["id"].(float64))
  2543. }
  2544. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2545. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2546. }
  2547. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2548. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2549. }
  2550. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2551. total, _ := project.(map[string]interface{})["total"].(string)
  2552. totals, _ = strconv.ParseFloat(total, 64)
  2553. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2554. }
  2555. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2556. project_name = project.(map[string]interface{})["project_name"].(string)
  2557. }
  2558. if project_type == 3 {
  2559. //查找该耗材的出库记录
  2560. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2561. //没有出库记录
  2562. if len(goodWarehouseInfo) == 0 {
  2563. //查询耗材库存
  2564. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2565. var stock_count int64
  2566. for _, it := range list {
  2567. stock_count += it.StockCount
  2568. }
  2569. stock_counts := strconv.FormatInt(stock_count, 10)
  2570. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2571. if stock_total_count == 0 {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2574. return
  2575. }
  2576. if totals > stock_total_count {
  2577. tx.Rollback()
  2578. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2579. return
  2580. }
  2581. //查找今日该患者已经出库的所有耗材
  2582. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2583. for _, item := range goodList {
  2584. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2585. var flush_count int64
  2586. for _, it := range goodListSix {
  2587. flush_count += it.StockCount
  2588. }
  2589. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2590. creater := adminInfo.AdminUser.Id
  2591. if errs != nil {
  2592. goodErrcode := models.XtGoodErrcode{
  2593. UserOrgId: item.OrgId,
  2594. Errcode: "手动出库更新剩余出库失败",
  2595. GoodId: item.GoodId,
  2596. Status: 1,
  2597. Ctime: time.Now().Unix(),
  2598. Mtime: 0,
  2599. Count: 0,
  2600. StockCount: 0,
  2601. Creater: creater,
  2602. BatchNumberId: 0,
  2603. WarehouseOutId: 0,
  2604. }
  2605. service.CreateGoodErrcode(goodErrcode)
  2606. }
  2607. }
  2608. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2609. }
  2610. //有出库记录
  2611. if len(goodWarehouseInfo) > 0 {
  2612. //查询该患者耗材的历史数据
  2613. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2614. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2615. //数量发生改变
  2616. if parsetotal != count {
  2617. //查找今日该患者已经出库的所有耗材
  2618. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2619. for _, item := range goodList {
  2620. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2621. var flush_count int64
  2622. for _, it := range goodListSix {
  2623. flush_count += it.StockCount
  2624. }
  2625. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2626. //减少出库数量
  2627. creater := adminInfo.AdminUser.Id
  2628. if errs != nil {
  2629. goodErrcode := models.XtGoodErrcode{
  2630. UserOrgId: item.OrgId,
  2631. Errcode: "手动出库更新剩余出库失败",
  2632. GoodId: item.GoodId,
  2633. Status: 1,
  2634. Ctime: time.Now().Unix(),
  2635. Mtime: 0,
  2636. Count: 0,
  2637. StockCount: 0,
  2638. Creater: creater,
  2639. BatchNumberId: 0,
  2640. WarehouseOutId: 0,
  2641. }
  2642. service.CreateGoodErrcode(goodErrcode)
  2643. }
  2644. //查询默认仓库
  2645. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2646. var total_count int64
  2647. for _, it := range stockList {
  2648. total_count += it.StockCount
  2649. }
  2650. //基础库插入数据
  2651. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2652. }
  2653. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2666. var hpInfo models.HisPrescriptionInfo
  2667. if info.ID == 0 {
  2668. var randNum int
  2669. randNum = rand.Intn(10000) + 1000
  2670. timestamp := time.Now().Unix()
  2671. tempTime := time.Unix(timestamp, 0)
  2672. timeFormat := tempTime.Format("20060102150405")
  2673. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2674. hpInfo = models.HisPrescriptionInfo{
  2675. HisPatientId: his_patient_id,
  2676. UserOrgId: adminInfo.CurrentOrgId,
  2677. RecordDate: theTime.Unix(),
  2678. PatientId: patient_id,
  2679. Status: 1,
  2680. Ctime: time.Now().Unix(),
  2681. Mtime: time.Now().Unix(),
  2682. Creator: adminInfo.AdminUser.Id,
  2683. Modifier: adminInfo.AdminUser.Id,
  2684. Diagnosis: diagnose,
  2685. SickHistory: sick_history,
  2686. Departments: department,
  2687. RegisterType: reg_type,
  2688. PrescriptionNumber: p_number,
  2689. PrescriptionStatus: 1,
  2690. Doctor: role.UserName,
  2691. DoctorId: doctor_id,
  2692. SickType: sick_type,
  2693. PType: p_type,
  2694. PatientDiagnosis: patient_diagnose,
  2695. }
  2696. service.SavePatientPrescriptionInfo(hpInfo)
  2697. //创建步骤表
  2698. finish := models.XtDialysisFinish{
  2699. IsFinish: 1,
  2700. UserOrgId: adminInfo.CurrentOrgId,
  2701. Status: 1,
  2702. Ctime: time.Now().Unix(),
  2703. Mtime: 0,
  2704. Module: 4,
  2705. RecordDate: theTime.Unix(),
  2706. Sourse: 1,
  2707. PatientId: patient_id,
  2708. }
  2709. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2710. if dialysisFinish.ID == 0 {
  2711. service.CreateDialysisFinish(finish)
  2712. }
  2713. redis := service.RedisClient()
  2714. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2715. redis.Set(key, "", time.Second)
  2716. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2717. redis.Set(keyOne, "", time.Second)
  2718. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2719. redis.Set(keySeven, "", time.Second)
  2720. defer redis.Close()
  2721. } else {
  2722. hpInfo = models.HisPrescriptionInfo{
  2723. ID: info.ID,
  2724. UserOrgId: adminInfo.CurrentOrgId,
  2725. RecordDate: info.RecordDate,
  2726. PatientId: info.PatientId,
  2727. Status: 1,
  2728. Ctime: info.Ctime,
  2729. Mtime: time.Now().Unix(),
  2730. Creator: info.Creator,
  2731. Modifier: adminInfo.AdminUser.Id,
  2732. Diagnosis: diagnose,
  2733. SickHistory: sick_history,
  2734. Departments: department,
  2735. RegisterType: reg_type,
  2736. PrescriptionNumber: info.PrescriptionNumber,
  2737. Doctor: role.UserName,
  2738. PrescriptionStatus: info.PrescriptionStatus,
  2739. DoctorId: doctor_id,
  2740. SickType: sick_type,
  2741. PType: info.PType,
  2742. HisPatientId: info.HisPatientId,
  2743. PatientDiagnosis: patient_diagnose,
  2744. }
  2745. service.SavePatientPrescriptionInfo(hpInfo)
  2746. //创建步骤表
  2747. finish := models.XtDialysisFinish{
  2748. IsFinish: 1,
  2749. UserOrgId: adminInfo.CurrentOrgId,
  2750. Status: 1,
  2751. Ctime: time.Now().Unix(),
  2752. Mtime: 0,
  2753. Module: 4,
  2754. RecordDate: info.RecordDate,
  2755. Sourse: 1,
  2756. PatientId: info.PatientId,
  2757. }
  2758. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2759. if dialysisFinish.ID == 0 {
  2760. service.CreateDialysisFinish(finish)
  2761. }
  2762. redis := service.RedisClient()
  2763. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2764. redis.Set(key, "", time.Second)
  2765. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2766. redis.Set(keyOne, "", time.Second)
  2767. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2768. redis.Set(keySeven, "", time.Second)
  2769. defer redis.Close()
  2770. }
  2771. //定义切片
  2772. var adviceList []models.HisDoctorAdviceInfo
  2773. var projectList []models.HisPrescriptionProject
  2774. 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 {
  2775. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2776. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2777. var tempPrescription *models.HisPrescription
  2778. if len(prescriptions) > 0 {
  2779. for _, item := range prescriptions {
  2780. // 开始外部循环的事务
  2781. tx := db.Begin()
  2782. // 在函数结束时处理事务回滚
  2783. defer func() {
  2784. if r := recover(); r != nil {
  2785. tx.Rollback()
  2786. }
  2787. }()
  2788. items := item.(map[string]interface{})
  2789. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2790. utils.ErrorLog("id")
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2792. return
  2793. }
  2794. id := int64(items["id"].(float64))
  2795. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2796. tempPrescription = &new_prescription
  2797. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2798. utils.ErrorLog("type")
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2800. return
  2801. }
  2802. types := int64(items["type"].(float64))
  2803. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2804. utils.ErrorLog("med_type")
  2805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2806. return
  2807. }
  2808. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2809. if med_type == "0" {
  2810. med_type = "14"
  2811. }
  2812. //if order_status == 0 {
  2813. // order_status = 1
  2814. //}
  2815. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2816. utils.ErrorLog("pre_time")
  2817. }
  2818. preTime, _ := items["pre_time"].(string)
  2819. fmt.Println("preTime", preTime)
  2820. timeLayout := "2006-01-02"
  2821. loc, _ := time.LoadLocation("Local")
  2822. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2823. result := strings.Split(preTime, " ")
  2824. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2825. if err != nil {
  2826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2827. return
  2828. }
  2829. pTime := theTime2.Unix()
  2830. ctime := time.Now().Unix()
  2831. if tempPrescription.ID == 0 {
  2832. prescription := &models.HisPrescription{
  2833. ID: 0,
  2834. PatientId: patient_id,
  2835. UserOrgId: adminInfo.CurrentOrgId,
  2836. RecordDate: recordDateTime,
  2837. Ctime: ctime,
  2838. Mtime: ctime,
  2839. Type: types,
  2840. Modifier: adminInfo.AdminUser.Id,
  2841. Creator: adminInfo.AdminUser.Id,
  2842. Status: 1,
  2843. Doctor: role.UserName,
  2844. HisPatientId: his_patient_id,
  2845. OrderStatus: 1,
  2846. BatchNumber: "",
  2847. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2848. PreTime: pTime,
  2849. PType: p_type,
  2850. MedType: med_type,
  2851. }
  2852. tempPrescription = prescription
  2853. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2854. redis := service.RedisClient()
  2855. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2856. redis.Set(key, "", time.Second)
  2857. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2858. redis.Set(keyOne, "", time.Second)
  2859. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2860. redis.Set(keySeven, "", time.Second)
  2861. defer redis.Close()
  2862. } else {
  2863. tempPrescription.ID = id
  2864. tempPrescription.Type = types
  2865. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2866. tempPrescription.Mtime = time.Now().Unix()
  2867. tempPrescription.Doctor = role.UserName
  2868. //tempPrescription.OrderStatus = order_status
  2869. tempPrescription.PreTime = pTime
  2870. tempPrescription.MedType = med_type
  2871. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2872. redis := service.RedisClient()
  2873. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2874. redis.Set(key, "", time.Second)
  2875. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2876. redis.Set(keyOne, "", time.Second)
  2877. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2878. redis.Set(keySeven, "", time.Second)
  2879. defer redis.Close()
  2880. }
  2881. //service.SaveHisPrescription(prescription)
  2882. //更改患者挂号状态
  2883. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2884. fmt.Println("更改失败", err2)
  2885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2886. advices := items["advices"].([]interface{})
  2887. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2888. groupNo := int64(0)
  2889. if len(advices) > 0 {
  2890. for _, advice := range advices {
  2891. tx := db.Begin()
  2892. // 在函数结束时处理事务回滚
  2893. defer func() {
  2894. if r := recover(); r != nil {
  2895. tx.Rollback()
  2896. }
  2897. }()
  2898. var s models.HisDoctorAdviceInfo
  2899. s.PrescriptionId = tempPrescription.ID
  2900. s.AdviceType = 2
  2901. s.AdviceDoctor = doctor_id
  2902. s.StopState = 2
  2903. s.ExecutionState = 2
  2904. s.AdviceDate = theTime3.Unix()
  2905. s.Status = 1
  2906. s.UserOrgId = adminInfo.CurrentOrgId
  2907. s.RecordDate = theTime3.Unix()
  2908. s.StartTime = tempPrescription.PreTime
  2909. s.Groupno = groupNo
  2910. s.PatientId = patient_id
  2911. s.HisPatientId = his_patient_id
  2912. s.StartTime = pTime
  2913. s.IsSettle = 2
  2914. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2915. if errcode > 0 {
  2916. c.ServeFailJSONWithSGJErrorCode(errcode)
  2917. return
  2918. }
  2919. s.StartTime = pTime
  2920. var total_count int64 //处方总库存
  2921. //查询改药品信息
  2922. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2923. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2924. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2925. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2926. total_count += prescribingNumberSeven * medical.MinNumber
  2927. }
  2928. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2929. total_count += prescribingNumberSeven
  2930. }
  2931. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2932. total_count += prescribingNumberSeven
  2933. }
  2934. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2935. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2936. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2937. if s.Price != lastWarehouse.RetailPrice {
  2938. s.Price = lastWarehouse.RetailPrice
  2939. }
  2940. if s.Price == 0 {
  2941. if lastWarehouse.ID == 0 {
  2942. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2943. s.Price = lastWarehouseTwo.RetailPrice
  2944. }
  2945. }
  2946. }
  2947. //查询保存处方出库开关是否打开
  2948. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2949. if s.PatientId != 30038 {
  2950. if drugOutConfig.IsOpen == 1 {
  2951. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2952. // 查询该药品最后一次出库记录
  2953. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2954. var is_user_total int64
  2955. var no_user_total int64
  2956. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2957. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2958. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2959. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2960. }
  2961. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2962. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2963. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2964. no_user_total += prescribingNumberSevenTy
  2965. }
  2966. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2967. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2968. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2969. no_user_total += prescribingNumberSevenTy
  2970. }
  2971. if len(druginfo) > 0 {
  2972. for _, it := range druginfo {
  2973. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2974. it.Count = it.Count * drug.MinNumber
  2975. is_user_total += it.Count
  2976. }
  2977. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2978. is_user_total += it.Count
  2979. }
  2980. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2981. is_user_total += it.Count
  2982. }
  2983. }
  2984. }
  2985. //fmt.Println("药品名称----------------------", drug.DrugName)
  2986. //fmt.Println("药品名称----------------------", drug.IsUse)
  2987. //fmt.Println("is_user_total-------------------------", is_user_total)
  2988. //fmt.Println("no_user_total-------------------------", no_user_total)
  2989. if is_user_total != no_user_total {
  2990. //出库
  2991. if drug.IsUse == 2 {
  2992. creater := adminInfo.AdminUser.Id
  2993. newadviceInfo := &models.HisDoctorAdviceInfo{
  2994. ID: s.ID,
  2995. UserOrgId: s.UserOrgId,
  2996. PatientId: s.PatientId,
  2997. HisPatientId: s.HisPatientId,
  2998. AdviceType: s.AdviceType,
  2999. AdviceDate: s.AdviceDate,
  3000. StartTime: s.StartTime,
  3001. AdviceName: s.AdviceName,
  3002. AdviceDesc: s.AdviceDesc,
  3003. ReminderDate: s.ReminderDate,
  3004. SingleDose: s.SingleDose,
  3005. SingleDoseUnit: s.SingleDoseUnit,
  3006. PrescribingNumber: s.PrescribingNumber,
  3007. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3008. DeliveryWay: s.DeliveryWay,
  3009. ExecutionFrequency: s.ExecutionFrequency,
  3010. AdviceDoctor: s.AdviceDoctor,
  3011. Status: s.Status,
  3012. CreatedTime: s.CreatedTime,
  3013. UpdatedTime: s.UpdatedTime,
  3014. AdviceAffirm: s.AdviceAffirm,
  3015. Remark: s.Remark,
  3016. StopTime: s.StopTime,
  3017. StopReason: s.StopReason,
  3018. StopDoctor: s.StopDoctor,
  3019. StopState: s.StopState,
  3020. ParentId: s.ParentId,
  3021. ExecutionTime: s.ExecutionTime,
  3022. ExecutionStaff: s.ExecutionStaff,
  3023. ExecutionState: s.ExecutionState,
  3024. Checker: s.Checker,
  3025. RecordDate: s.RecordDate,
  3026. DialysisOrderId: s.DialysisOrderId,
  3027. CheckTime: s.CheckTime,
  3028. CheckState: s.CheckState,
  3029. DrugSpec: s.DrugSpec,
  3030. DrugSpecUnit: s.DrugSpecUnit,
  3031. Groupno: s.Groupno,
  3032. RemindType: s.RemindType,
  3033. FrequencyType: s.FrequencyType,
  3034. DayCount: s.DayCount,
  3035. WeekDay: s.WeekDay,
  3036. TemplateId: s.TemplateId,
  3037. Modifier: s.Modifier,
  3038. DrugId: s.DrugId,
  3039. Price: s.Price,
  3040. PrescriptionId: s.PrescriptionId,
  3041. MedListCodg: s.MedListCodg,
  3042. FeedetlSn: s.FeedetlSn,
  3043. Day: s.DayCount,
  3044. ChildDoctorAdvice: nil,
  3045. Drug: models.Drug{},
  3046. Diagnosis: s.Diagnosis,
  3047. Way: s.Way,
  3048. HospApprFlag: s.HospApprFlag,
  3049. LmtUsedFlag: s.LmtUsedFlag,
  3050. HisOrderInfo: models.HisOrderInfo{},
  3051. IsMedicine: s.IsMedicine,
  3052. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3053. Child: nil,
  3054. IsSettle: s.IsSettle,
  3055. IsMobile: s.IsMobile,
  3056. IsSelfDrug: s.IsSelfDrug,
  3057. DrugWayCount: s.DrugWayCount,
  3058. }
  3059. var history_count int64
  3060. var local_count int64
  3061. //查找已经开过的医嘱信息
  3062. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3063. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3064. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3065. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3066. local_count += prescribingNumberSevenTy * drug.MinNumber
  3067. }
  3068. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3069. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3070. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3071. local_count += prescribingNumberSevenTy
  3072. }
  3073. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3074. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3075. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3076. local_count += prescribingNumberSevenTy
  3077. }
  3078. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3079. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3080. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3081. history_count += prescribingNumberSevenTy * drug.MinNumber
  3082. }
  3083. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3084. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3085. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3086. history_count += prescribingNumberSevenTy
  3087. }
  3088. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3089. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3090. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3091. history_count += prescribingNumberSevenTy
  3092. }
  3093. //如果当前出库数量大于历史出库数量则需要出库
  3094. if local_count > history_count {
  3095. //按最小单位出库
  3096. var cha_count = local_count - history_count
  3097. newadviceInfo.PrescribingNumber = float64(cha_count)
  3098. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3099. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3100. }
  3101. //如果当前出库数量小于历史出库数量则需要退库
  3102. if local_count < history_count {
  3103. var cha_count = history_count - local_count
  3104. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3105. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. }
  3107. if local_count == history_count {
  3108. if is_user_total == 0 {
  3109. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3110. }
  3111. }
  3112. }
  3113. //更新字典里面的库存
  3114. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3115. var sum_count int64
  3116. for _, its := range stockInfo {
  3117. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3118. if its.MaxUnit == baseDrug.MaxUnit {
  3119. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3120. }
  3121. sum_count += its.StockMaxNumber + its.StockMinNumber
  3122. }
  3123. //更新基础库存
  3124. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3125. //剩余库存
  3126. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3127. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3128. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3129. //创建医嘱
  3130. service.CreateHisDoctorAdviceOne(&s, tx)
  3131. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3132. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. if len(outInfoTwo) > 0 {
  3134. for _, item := range outInfoTwo {
  3135. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3136. }
  3137. }
  3138. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3139. if len(drugAutoDetail) > 0 {
  3140. for _, item := range drugAutoDetail {
  3141. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3142. }
  3143. }
  3144. }
  3145. }
  3146. }
  3147. //记录日志
  3148. byterequest, _ := json.Marshal(s)
  3149. adviceLog := models.XtDoctorAdviceLog{
  3150. UserOrgId: s.UserOrgId,
  3151. PatientId: s.PatientId,
  3152. AdminUserId: adminInfo.AdminUser.Id,
  3153. Module: 1,
  3154. ErrLog: string(byterequest),
  3155. Status: 1,
  3156. Ctime: time.Now().Unix(),
  3157. Mtime: 0,
  3158. Source: "电脑端新建his医嘱",
  3159. RecordDate: s.AdviceDate,
  3160. }
  3161. service.CreateDoctorAdviceLog(adviceLog)
  3162. //存储切片中
  3163. adviceList = append(adviceList, s)
  3164. redis := service.RedisClient()
  3165. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3166. redis.Set(key, "", time.Second)
  3167. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3168. redis.Set(keyOne, "", time.Second)
  3169. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3170. redis.Set(keySeven, "", time.Second)
  3171. var randNum int
  3172. randNum = rand.Intn(10000) + 1000
  3173. timestamp := time.Now().Unix()
  3174. tempTime := time.Unix(timestamp, 0)
  3175. timeFormat := tempTime.Format("20060102150405")
  3176. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3177. //查询改药品是否已经停用
  3178. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3179. if base.ID > 0 {
  3180. tx.Rollback()
  3181. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3182. return
  3183. }
  3184. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3185. if drugMedical.SumCount == 0 {
  3186. tx.Rollback()
  3187. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3188. return
  3189. }
  3190. service.CreateHisDoctorAdviceOne(&s, tx)
  3191. tx.Commit()
  3192. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3193. redis.Set(keySix, "", time.Second)
  3194. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3195. redis.Set(keyFive, "", time.Second)
  3196. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3197. redis.Set(keyEight, "", time.Second)
  3198. defer redis.Close()
  3199. }
  3200. }
  3201. }
  3202. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3203. projects := items["project"].([]interface{})
  3204. if len(projects) > 0 {
  3205. for _, project := range projects {
  3206. tx := db.Begin()
  3207. // 在函数结束时处理事务回滚
  3208. defer func() {
  3209. if r := recover(); r != nil {
  3210. tx.Rollback()
  3211. }
  3212. }()
  3213. var p models.HisPrescriptionProject
  3214. p.PrescriptionId = tempPrescription.ID
  3215. p.PatientId = patient_id
  3216. p.RecordDate = theTime3.Unix()
  3217. p.Doctor = doctor_id
  3218. p.UserOrgId = adminInfo.CurrentOrgId
  3219. p.HisPatientId = his_patient_id
  3220. p.Status = 1
  3221. p.StartTime = pTime
  3222. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3223. if errcode > 0 {
  3224. c.ServeFailJSONWithSGJErrorCode(errcode)
  3225. return
  3226. }
  3227. if p.ID == 0 {
  3228. p.IsOut = 2
  3229. }
  3230. if p.ID > 0 {
  3231. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3232. p.IsOut = projectDetail.IsOut
  3233. }
  3234. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3235. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3236. if p.Type == 3 {
  3237. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3238. if p.Price != lastWarehouse.PackingPrice {
  3239. p.Price = lastWarehouse.PackingPrice
  3240. }
  3241. if p.Price == 0 {
  3242. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3243. p.Price = lastWarehouseTwo.PackingPrice
  3244. }
  3245. if p.Unit == "" {
  3246. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3247. p.Unit = goodInfoOne.PackingUnit
  3248. }
  3249. }
  3250. }
  3251. if p.Type == 3 {
  3252. //查询该耗材是否停用
  3253. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3254. //表示该耗材已经停用,不能保存
  3255. if goodInfoSeven.ID == 0 {
  3256. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3257. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3258. return
  3259. }
  3260. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3261. if goodInfoOne.SumCount == 0 {
  3262. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3263. return
  3264. }
  3265. }
  3266. //查询保存耗材出库开关是否打开
  3267. if p.PatientId != 30038 {
  3268. if goodOutConfig.IsOpen == 1 {
  3269. //耗材出库
  3270. if p.Type == 3 {
  3271. //对比当前数据和历史出库数据
  3272. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3273. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3274. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3275. //如果当前处方数量大于历史数据,则需要出库
  3276. if nowCount > historyCount {
  3277. var cha_count int64
  3278. cha_count = nowCount - historyCount
  3279. timeStr := time.Now().Format("2006-01-02")
  3280. timeArr := strings.Split(timeStr, "-")
  3281. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3282. total = total + 1
  3283. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3284. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3285. number = number + total
  3286. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3287. operation_time := time.Now().Unix()
  3288. creater := c.GetAdminUserInfo().AdminUser.Id
  3289. recordDateStr := time.Now().Format("2006-01-02")
  3290. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3291. nowtime := recordDate.Unix()
  3292. warehouseOut := models.WarehouseOut{
  3293. WarehouseOutOrderNumber: warehousing_out_order,
  3294. OperationTime: operation_time,
  3295. OrgId: adminInfo.CurrentOrgId,
  3296. Creater: creater,
  3297. Ctime: time.Now().Unix(),
  3298. Status: 1,
  3299. WarehouseOutTime: nowtime,
  3300. Type: 1,
  3301. StorehouseId: storeConfig.StorehouseOutInfo,
  3302. IsCheck: 1,
  3303. IsSys: 1,
  3304. }
  3305. //查询是否生成出库单
  3306. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3307. if out.ID == 0 {
  3308. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3309. }
  3310. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3311. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3312. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3313. dialyPrepareOne := models.DialysisBeforePrepare{
  3314. GoodTypeId: goodObj.GoodTypeId,
  3315. GoodId: p.ProjectId,
  3316. PatientId: p.PatientId,
  3317. RecordDate: p.RecordDate,
  3318. UserOrgId: adminInfo.CurrentOrgId,
  3319. Count: cha_count,
  3320. Ctime: time.Now().Unix(),
  3321. Creater: creater,
  3322. Status: 1,
  3323. StorehouseId: houseConfig.StorehouseOutInfo,
  3324. ProjectId: p.ID,
  3325. }
  3326. //出库
  3327. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3328. }
  3329. //如果当前处方数量小于历史数据,怎需要退库
  3330. if nowCount < historyCount {
  3331. var cha_count int64
  3332. cha_count = historyCount - nowCount
  3333. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3334. creater := c.GetAdminUserInfo().AdminUser.Id
  3335. newPrescriptionProject := &models.HisPrescriptionProject{
  3336. ID: p.ID,
  3337. ProjectId: p.ProjectId,
  3338. Price: p.Price,
  3339. UserOrgId: p.UserOrgId,
  3340. Status: 1,
  3341. Ctime: time.Now().Unix(),
  3342. Mtime: time.Now().Unix(),
  3343. PatientId: p.PatientId,
  3344. HisPatientId: p.HisPatientId,
  3345. RecordDate: p.RecordDate,
  3346. PrescriptionId: p.PrescriptionId,
  3347. Count: p.Count,
  3348. FeedetlSn: p.FeedetlSn,
  3349. MedListCodg: p.MedListCodg,
  3350. SingleDose: p.SingleDose,
  3351. DeliveryWay: p.DeliveryWay,
  3352. ExecutionFrequency: p.ExecutionFrequency,
  3353. Day: p.Day,
  3354. HisProject: models.HisProject{},
  3355. GoodInfo: models.GoodInfo{},
  3356. Remark: p.Remark,
  3357. Unit: p.Unit,
  3358. Type: p.Type,
  3359. Doctor: p.Doctor,
  3360. ExecutionTime: p.ExecutionTime,
  3361. ExecutionStaff: p.ExecutionStaff,
  3362. ExecutionState: p.ExecutionState,
  3363. CheckTime: p.CheckTime,
  3364. CheckState: p.CheckState,
  3365. Checker: p.Checker,
  3366. StartTime: p.StartTime,
  3367. TeamId: p.TeamId,
  3368. XtHisProjectTeam: models.XtHisProjectTeam{},
  3369. FrequencyType: p.FrequencyType,
  3370. DayCount: p.DayCount,
  3371. WeekDay: p.WeekDay,
  3372. IsCheckTeam: p.IsCheckTeam,
  3373. HisOrderInfo: models.HisOrderInfo{},
  3374. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3375. IsOut: p.IsOut,
  3376. YbSyncStatus: p.YbSyncStatus,
  3377. }
  3378. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3379. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3380. }
  3381. if nowCount == historyCount {
  3382. if historyCount == 0 {
  3383. recordDateStr := time.Now().Format("2006-01-02")
  3384. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3385. nowtime := recordDate.Unix()
  3386. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3387. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3388. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3389. creater := c.GetAdminUserInfo().AdminUser.Id
  3390. dialyPrepareOne := models.DialysisBeforePrepare{
  3391. GoodTypeId: goodObj.GoodTypeId,
  3392. GoodId: p.ProjectId,
  3393. PatientId: p.PatientId,
  3394. RecordDate: p.RecordDate,
  3395. UserOrgId: adminInfo.CurrentOrgId,
  3396. Count: nowCount,
  3397. Ctime: time.Now().Unix(),
  3398. Creater: creater,
  3399. Status: 1,
  3400. StorehouseId: houseConfig.StorehouseOutInfo,
  3401. ProjectId: p.ID,
  3402. }
  3403. //出库
  3404. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3405. }
  3406. }
  3407. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3408. ////查询历史出库数据
  3409. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3410. //
  3411. //var out_count_five int64
  3412. //for _, item := range flowGood {
  3413. // out_count_five += item.Count
  3414. //}
  3415. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3416. //
  3417. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3418. //if out_count_five != parseIntCount {
  3419. // //查询耗材最后一次出库记录
  3420. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3421. // //查询默认出库仓库库存
  3422. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3423. // if len(wareOut) > 0 {
  3424. //
  3425. // for _, it := range wareOut {
  3426. // //回退库存
  3427. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3428. //
  3429. // //删除出库记录
  3430. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3431. //
  3432. // }
  3433. // }
  3434. //
  3435. // timeStr := time.Now().Format("2006-01-02")
  3436. // timeArr := strings.Split(timeStr, "-")
  3437. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3438. //
  3439. // total = total + 1
  3440. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3441. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3442. // number = number + total
  3443. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3444. //
  3445. // operation_time := time.Now().Unix()
  3446. // creater := c.GetAdminUserInfo().AdminUser.Id
  3447. //
  3448. // recordDateStr := time.Now().Format("2006-01-02")
  3449. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3450. // nowtime := recordDate.Unix()
  3451. // warehouseOut := models.WarehouseOut{
  3452. // WarehouseOutOrderNumber: warehousing_out_order,
  3453. // OperationTime: operation_time,
  3454. // OrgId: adminInfo.CurrentOrgId,
  3455. // Creater: creater,
  3456. // Ctime: time.Now().Unix(),
  3457. // Status: 1,
  3458. // WarehouseOutTime: nowtime,
  3459. // Type: 1,
  3460. // StorehouseId: storeConfig.StorehouseOutInfo,
  3461. // IsCheck: 1,
  3462. // IsSys: 1,
  3463. // }
  3464. // //查询是否生成出库单
  3465. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3466. // if out.ID == 0 {
  3467. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3468. // }
  3469. //
  3470. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3471. //
  3472. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3473. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3474. //
  3475. // dialyPrepareOne := models.DialysisBeforePrepare{
  3476. // GoodTypeId: goodObj.GoodTypeId,
  3477. // GoodId: p.ProjectId,
  3478. // PatientId: p.PatientId,
  3479. // RecordDate: p.RecordDate,
  3480. // UserOrgId: adminInfo.CurrentOrgId,
  3481. // Count: parseIntCount,
  3482. // Ctime: time.Now().Unix(),
  3483. // Creater: creater,
  3484. // Status: 1,
  3485. // StorehouseId: houseConfig.StorehouseOutInfo,
  3486. // ProjectId: lastHisProject.ID,
  3487. // }
  3488. // //判断是否是零用耗材(非零用)
  3489. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3490. //
  3491. // //查询历史出库数据
  3492. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3493. // var out_count int64
  3494. // for _, item := range flowGood {
  3495. // out_count += item.Count
  3496. // }
  3497. // //如果历史数和当前数据不想等才进行退库出库
  3498. // if out_count != parseIntCount {
  3499. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3500. //
  3501. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3502. // detail := models.AutomaticReduceDetail{
  3503. // WarehouseOutId: 0,
  3504. // WarehouseOutOrderNumber: "",
  3505. // PatientId: p.PatientId,
  3506. // Ctime: time.Now().Unix(),
  3507. // Mtime: 0,
  3508. // Status: 1,
  3509. // RecordTime: p.RecordDate,
  3510. // OrgId: p.UserOrgId,
  3511. // GoodId: p.ProjectId,
  3512. // GoodTypeId: 0,
  3513. // Count: parseIntCount,
  3514. // Type: 0,
  3515. // ProjectId: lastHisProject.ID,
  3516. // StorehouseId: 0,
  3517. // }
  3518. //
  3519. // service.CreateNewAutoDetail(detail, tx)
  3520. //
  3521. // //查询剩余库存
  3522. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3523. // var sum_count int64
  3524. // for _, item := range goodList {
  3525. // sum_count += item.StockCount
  3526. // }
  3527. //
  3528. // //更新剩余库存
  3529. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3530. //
  3531. // //耗材
  3532. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3533. //
  3534. // }
  3535. // //判断是否是零用耗材(零用但是是出库耗材)
  3536. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3537. //
  3538. // //查询历史出库数据
  3539. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3540. // var out_count int64
  3541. // for _, item := range flowGood {
  3542. // out_count += item.Count
  3543. // }
  3544. // //如果历史数和当前数据不想等才进行退库出库
  3545. // if out_count != parseIntCount {
  3546. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3547. //
  3548. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3549. // detail := models.AutomaticReduceDetail{
  3550. // WarehouseOutId: 0,
  3551. // WarehouseOutOrderNumber: "",
  3552. // PatientId: p.PatientId,
  3553. // Ctime: time.Now().Unix(),
  3554. // Mtime: 0,
  3555. // Status: 1,
  3556. // RecordTime: p.RecordDate,
  3557. // OrgId: p.UserOrgId,
  3558. // GoodId: p.ProjectId,
  3559. // GoodTypeId: 0,
  3560. // Count: parseIntCount,
  3561. // Type: 0,
  3562. // ProjectId: p.ID,
  3563. // StorehouseId: 0,
  3564. // }
  3565. //
  3566. // service.CreateNewAutoDetail(detail, tx)
  3567. //
  3568. // //查询剩余库存
  3569. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3570. // var sum_count int64
  3571. // for _, item := range goodList {
  3572. // sum_count += item.StockCount
  3573. // }
  3574. //
  3575. // //更新剩余库存
  3576. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3577. //
  3578. // //耗材
  3579. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3580. // }
  3581. //
  3582. // }
  3583. //
  3584. // }
  3585. //
  3586. //}
  3587. //记录日志
  3588. byterequest, _ := json.Marshal(p)
  3589. adviceLog := models.XtDoctorAdviceLog{
  3590. UserOrgId: p.UserOrgId,
  3591. PatientId: p.PatientId,
  3592. AdminUserId: adminInfo.AdminUser.Id,
  3593. Module: 1,
  3594. ErrLog: string(byterequest),
  3595. Status: 1,
  3596. Ctime: time.Now().Unix(),
  3597. Mtime: 0,
  3598. Source: "电脑端新建his项目",
  3599. RecordDate: p.RecordDate,
  3600. }
  3601. service.CreateDoctorAdviceLog(adviceLog)
  3602. projectList = append(projectList, p)
  3603. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3604. //新增或者编辑项目,修改对应的标签数据
  3605. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3606. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3607. var label models.HisLabelPrintInfo
  3608. project, _ := service.GetProjectDetail(p.ProjectId)
  3609. if project.CostClassify == 3 { //类别为检验检查
  3610. if p.TeamId > 0 { //检验检查组套
  3611. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3612. if tempLabel.ID == 0 {
  3613. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3614. label.Number = tempPrescription.PrescriptionNumber
  3615. label.ProjectId = project.ID
  3616. label.Status = 1
  3617. label.IsPrint = 2
  3618. label.DoctorId = info.DoctorId
  3619. label.UserOrgId = p.UserOrgId
  3620. label.PatientId = patient_id
  3621. label.RecordDate = recordDateTime
  3622. label.Ctime = time.Now().Unix()
  3623. label.Mtime = time.Now().Unix()
  3624. label.ItemId = p.TeamId
  3625. label.FeedetlSn = p.FeedetlSn
  3626. label.PProjectId = p.ID
  3627. label.ProjectName = team.ProjectTeam
  3628. label.PatientName = patient.Name
  3629. service.CreateNewHisLabelRecord(&label, tx)
  3630. }
  3631. } else { //单条检验检查项目
  3632. label.Number = tempPrescription.PrescriptionNumber
  3633. label.ProjectId = project.ID
  3634. label.Status = 1
  3635. label.DoctorId = info.DoctorId
  3636. label.UserOrgId = p.UserOrgId
  3637. label.PatientId = patient_id
  3638. label.RecordDate = recordDateTime
  3639. label.IsPrint = 2
  3640. label.Ctime = time.Now().Unix()
  3641. label.Mtime = time.Now().Unix()
  3642. label.FeedetlSn = p.FeedetlSn
  3643. label.PProjectId = p.ID
  3644. label.ItemId = p.TeamId
  3645. label.ProjectName = project.ProjectName
  3646. label.PatientName = patient.Name
  3647. service.CreateNewHisLabelRecord(&label, tx)
  3648. }
  3649. }
  3650. }
  3651. }
  3652. }
  3653. }
  3654. }
  3655. service.CreateNewHisProjectTwo(&p, tx)
  3656. var randNum int
  3657. randNum = rand.Intn(10000) + 1000
  3658. timestamp := time.Now().Unix()
  3659. tempTime := time.Unix(timestamp, 0)
  3660. timeFormat := tempTime.Format("20060102150405")
  3661. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3662. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3663. if goodBase.ID > 0 {
  3664. tx.Rollback()
  3665. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3666. return
  3667. }
  3668. service.CreateNewHisProjectTwo(&p, tx)
  3669. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3670. //查询剩余库存
  3671. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3672. var sum_count int64
  3673. for _, item := range goodList {
  3674. sum_count += item.StockCount
  3675. }
  3676. //更新剩余库存
  3677. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3678. //耗材
  3679. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3680. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3681. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3682. if len(outInfoTwo) > 0 {
  3683. for _, item := range outInfoTwo {
  3684. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3685. }
  3686. }
  3687. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3688. if len(drugAutoDetail) > 0 {
  3689. for _, item := range drugAutoDetail {
  3690. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3691. }
  3692. }
  3693. tx.Commit()
  3694. }
  3695. }
  3696. }
  3697. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3698. // addition := items["addition"].([]interface{})
  3699. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3700. // ctime := time.Now().Unix()
  3701. // mtime := ctime
  3702. // if len(addition) > 0 {
  3703. // for _, item := range addition {
  3704. // var s models.HisAdditionalCharge
  3705. // s.PrescriptionId = tempPrescription.ID
  3706. // s.Status = 1
  3707. // s.UserOrgId = adminInfo.CurrentOrgId
  3708. // s.RecordDate = recordDateTime
  3709. // s.CreatedTime = ctime
  3710. // s.UpdatedTime = mtime
  3711. // s.PatientId = patient_id
  3712. // s.HisPatientId = his_patient_id
  3713. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3714. // if errcode > 0 {
  3715. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3716. // return
  3717. // }
  3718. // service.CreateAdditionalCharge(&s)
  3719. // var randNum int
  3720. // randNum = rand.Intn(10000) + 1000
  3721. // timestamp := time.Now().Unix()
  3722. // tempTime := time.Unix(timestamp, 0)
  3723. // timeFormat := tempTime.Format("20060102150405")
  3724. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3725. // service.CreateAdditionalCharge(&s)
  3726. //
  3727. // }
  3728. // }
  3729. //}
  3730. }
  3731. }
  3732. }
  3733. tx.Commit()
  3734. if err == nil {
  3735. c.ServeSuccessJSON(map[string]interface{}{
  3736. "msg": "保存成功",
  3737. })
  3738. return
  3739. } else {
  3740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3741. return
  3742. }
  3743. } else {
  3744. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3745. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3746. var tempPrescription *models.HisPrescription
  3747. if len(prescriptions) > 0 {
  3748. for _, item := range prescriptions {
  3749. items := item.(map[string]interface{})
  3750. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3751. utils.ErrorLog("id")
  3752. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3753. return
  3754. }
  3755. id := int64(items["id"].(float64))
  3756. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3757. tempPrescription = &new_prescription
  3758. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3759. utils.ErrorLog("type")
  3760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. types := int64(items["type"].(float64))
  3764. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3765. utils.ErrorLog("med_type")
  3766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3767. return
  3768. }
  3769. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3770. if med_type == "0" {
  3771. med_type = "14"
  3772. }
  3773. //if order_status == 0 {
  3774. // order_status = 1
  3775. //}
  3776. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3777. utils.ErrorLog("pre_time")
  3778. }
  3779. preTime, _ := items["pre_time"].(string)
  3780. timeLayout := "2006-01-02"
  3781. loc, _ := time.LoadLocation("Local")
  3782. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3783. result := strings.Split(preTime, " ")
  3784. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3785. if err != nil {
  3786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3787. return
  3788. }
  3789. pTime := theTime2.Unix()
  3790. ctime := time.Now().Unix()
  3791. if tempPrescription.ID == 0 {
  3792. prescription := &models.HisPrescription{
  3793. ID: 0,
  3794. PatientId: patient_id,
  3795. UserOrgId: adminInfo.CurrentOrgId,
  3796. RecordDate: recordDateTime,
  3797. Ctime: ctime,
  3798. Mtime: ctime,
  3799. Type: types,
  3800. Modifier: adminInfo.AdminUser.Id,
  3801. Creator: adminInfo.AdminUser.Id,
  3802. Status: 1,
  3803. Doctor: role.UserName,
  3804. HisPatientId: his_patient_id,
  3805. OrderStatus: 1,
  3806. BatchNumber: "",
  3807. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3808. PreTime: pTime,
  3809. PType: p_type,
  3810. MedType: med_type,
  3811. }
  3812. tempPrescription = prescription
  3813. service.SaveHisPrescription(tempPrescription)
  3814. redis := service.RedisClient()
  3815. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3816. redis.Set(key, "", time.Second)
  3817. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3818. redis.Set(keyOne, "", time.Second)
  3819. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3820. redis.Set(keySeven, "", time.Second)
  3821. defer redis.Close()
  3822. } else {
  3823. tempPrescription.ID = id
  3824. tempPrescription.Type = types
  3825. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3826. tempPrescription.Mtime = time.Now().Unix()
  3827. tempPrescription.Doctor = role.UserName
  3828. //tempPrescription.OrderStatus = order_status
  3829. tempPrescription.PreTime = pTime
  3830. tempPrescription.MedType = med_type
  3831. service.SaveHisPrescription(tempPrescription)
  3832. redis := service.RedisClient()
  3833. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3834. redis.Set(key, "", time.Second)
  3835. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3836. redis.Set(keyOne, "", time.Second)
  3837. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3838. redis.Set(keySeven, "", time.Second)
  3839. defer redis.Close()
  3840. }
  3841. //service.SaveHisPrescription(prescription)
  3842. //更改患者挂号状态
  3843. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3844. fmt.Println("更改失败", err2)
  3845. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3846. advices := items["advices"].([]interface{})
  3847. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3848. groupNo := int64(0)
  3849. if len(advices) > 0 {
  3850. for _, advice := range advices {
  3851. var s models.HisDoctorAdviceInfo
  3852. s.PrescriptionId = tempPrescription.ID
  3853. s.AdviceType = 2
  3854. s.AdviceDoctor = doctor_id
  3855. s.StopState = 2
  3856. s.ExecutionState = 2
  3857. s.AdviceDate = theTime3.Unix()
  3858. s.Status = 1
  3859. s.UserOrgId = adminInfo.CurrentOrgId
  3860. s.RecordDate = theTime3.Unix()
  3861. s.StartTime = tempPrescription.PreTime
  3862. s.Groupno = groupNo
  3863. s.PatientId = patient_id
  3864. s.HisPatientId = his_patient_id
  3865. s.StartTime = pTime
  3866. s.IsSettle = 2
  3867. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3868. if errcode > 0 {
  3869. c.ServeFailJSONWithSGJErrorCode(errcode)
  3870. return
  3871. }
  3872. s.StartTime = pTime
  3873. var total_count int64 //处方总库存
  3874. //查询改药品信息
  3875. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3876. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3877. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3878. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3879. total_count += prescribingNumberSeven * medical.MinNumber
  3880. }
  3881. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3882. total_count += prescribingNumberSeven
  3883. }
  3884. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3885. total_count += prescribingNumberSeven
  3886. }
  3887. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3888. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3889. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3890. if s.Price != lastWarehouse.RetailPrice {
  3891. s.Price = lastWarehouse.RetailPrice
  3892. }
  3893. if s.Price == 0 {
  3894. if lastWarehouse.ID == 0 {
  3895. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3896. s.Price = lastWarehouseTwo.RetailPrice
  3897. }
  3898. }
  3899. }
  3900. //查询改药品是否已经停用
  3901. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3902. if base.ID > 0 {
  3903. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3904. return
  3905. }
  3906. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3907. if drugMedical.SumCount == 0 {
  3908. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3909. return
  3910. }
  3911. service.CreateHisDoctorAdvice(&s)
  3912. //记录日志
  3913. byterequest, _ := json.Marshal(s)
  3914. adviceLog := models.XtDoctorAdviceLog{
  3915. UserOrgId: s.UserOrgId,
  3916. PatientId: s.PatientId,
  3917. AdminUserId: adminInfo.AdminUser.Id,
  3918. Module: 1,
  3919. ErrLog: string(byterequest),
  3920. Status: 1,
  3921. Ctime: time.Now().Unix(),
  3922. Mtime: 0,
  3923. Source: "电脑端新建his医嘱",
  3924. RecordDate: s.AdviceDate,
  3925. }
  3926. service.CreateDoctorAdviceLog(adviceLog)
  3927. //存储切片中
  3928. adviceList = append(adviceList, s)
  3929. redis := service.RedisClient()
  3930. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3931. redis.Set(key, "", time.Second)
  3932. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3933. redis.Set(keyOne, "", time.Second)
  3934. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3935. redis.Set(keySeven, "", time.Second)
  3936. var randNum int
  3937. randNum = rand.Intn(10000) + 1000
  3938. timestamp := time.Now().Unix()
  3939. tempTime := time.Unix(timestamp, 0)
  3940. timeFormat := tempTime.Format("20060102150405")
  3941. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3942. service.CreateHisDoctorAdvice(&s)
  3943. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3944. redis.Set(keySix, "", time.Second)
  3945. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3946. redis.Set(keyFive, "", time.Second)
  3947. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3948. redis.Set(keyEight, "", time.Second)
  3949. defer redis.Close()
  3950. }
  3951. }
  3952. }
  3953. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3954. projects := items["project"].([]interface{})
  3955. if len(projects) > 0 {
  3956. for _, project := range projects {
  3957. var p models.HisPrescriptionProject
  3958. p.PrescriptionId = tempPrescription.ID
  3959. p.PatientId = patient_id
  3960. p.RecordDate = theTime3.Unix()
  3961. p.Doctor = doctor_id
  3962. p.UserOrgId = adminInfo.CurrentOrgId
  3963. p.HisPatientId = his_patient_id
  3964. p.Status = 1
  3965. p.StartTime = pTime
  3966. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3967. if errcode > 0 {
  3968. c.ServeFailJSONWithSGJErrorCode(errcode)
  3969. return
  3970. }
  3971. if p.ID == 0 {
  3972. p.IsOut = 2
  3973. }
  3974. if p.ID > 0 {
  3975. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3976. p.IsOut = projectDetail.IsOut
  3977. }
  3978. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3979. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3980. if p.Type == 3 {
  3981. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3982. if p.Price != lastWarehouse.PackingPrice {
  3983. p.Price = lastWarehouse.PackingPrice
  3984. }
  3985. if p.Price == 0 {
  3986. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3987. p.Price = lastWarehouseTwo.PackingPrice
  3988. }
  3989. if p.Unit == "" {
  3990. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3991. p.Unit = goodInfoOne.PackingUnit
  3992. }
  3993. }
  3994. }
  3995. if p.Type == 3 {
  3996. //查询该耗材是否停用
  3997. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3998. //表示该耗材已经停用,不能保存
  3999. if goodInfoSeven.ID == 0 {
  4000. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4001. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4002. return
  4003. }
  4004. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4005. if goodInfoOne.SumCount == 0 {
  4006. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4007. return
  4008. }
  4009. }
  4010. service.CreateHisProjectTwo(&p)
  4011. //记录日志
  4012. byterequest, _ := json.Marshal(p)
  4013. adviceLog := models.XtDoctorAdviceLog{
  4014. UserOrgId: p.UserOrgId,
  4015. PatientId: p.PatientId,
  4016. AdminUserId: adminInfo.AdminUser.Id,
  4017. Module: 1,
  4018. ErrLog: string(byterequest),
  4019. Status: 1,
  4020. Ctime: time.Now().Unix(),
  4021. Mtime: 0,
  4022. Source: "电脑端新建his项目",
  4023. RecordDate: p.RecordDate,
  4024. }
  4025. service.CreateDoctorAdviceLog(adviceLog)
  4026. projectList = append(projectList, p)
  4027. var randNum int
  4028. randNum = rand.Intn(10000) + 1000
  4029. timestamp := time.Now().Unix()
  4030. tempTime := time.Unix(timestamp, 0)
  4031. timeFormat := tempTime.Format("20060102150405")
  4032. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4033. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4034. //新增或者编辑项目,修改对应的标签数据
  4035. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4036. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4037. var label models.HisLabelPrintInfo
  4038. project, _ := service.GetProjectDetail(p.ProjectId)
  4039. if project.CostClassify == 3 { //类别为检验检查
  4040. if p.TeamId > 0 { //检验检查组套
  4041. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4042. if tempLabel.ID == 0 {
  4043. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4044. label.Number = tempPrescription.PrescriptionNumber
  4045. label.ProjectId = project.ID
  4046. label.Status = 1
  4047. label.IsPrint = 2
  4048. label.DoctorId = info.DoctorId
  4049. label.UserOrgId = p.UserOrgId
  4050. label.PatientId = patient_id
  4051. label.RecordDate = recordDateTime
  4052. label.Ctime = time.Now().Unix()
  4053. label.Mtime = time.Now().Unix()
  4054. label.ItemId = p.TeamId
  4055. label.FeedetlSn = p.FeedetlSn
  4056. label.PProjectId = p.ID
  4057. label.ProjectName = team.ProjectTeam
  4058. label.PatientName = patient.Name
  4059. service.CreateHisLabelRecord(&label)
  4060. }
  4061. } else { //单条检验检查项目
  4062. label.Number = tempPrescription.PrescriptionNumber
  4063. label.ProjectId = project.ID
  4064. label.Status = 1
  4065. label.DoctorId = info.DoctorId
  4066. label.UserOrgId = p.UserOrgId
  4067. label.PatientId = patient_id
  4068. label.RecordDate = recordDateTime
  4069. label.IsPrint = 2
  4070. label.Ctime = time.Now().Unix()
  4071. label.Mtime = time.Now().Unix()
  4072. label.FeedetlSn = p.FeedetlSn
  4073. label.PProjectId = p.ID
  4074. label.ItemId = p.TeamId
  4075. label.ProjectName = project.ProjectName
  4076. label.PatientName = patient.Name
  4077. service.CreateHisLabelRecord(&label)
  4078. }
  4079. }
  4080. }
  4081. }
  4082. service.SaveHisProjectTwo(&p)
  4083. }
  4084. }
  4085. }
  4086. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4087. // addition := items["addition"].([]interface{})
  4088. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4089. // ctime := time.Now().Unix()
  4090. // mtime := ctime
  4091. // if len(addition) > 0 {
  4092. // for _, item := range addition {
  4093. // var s models.HisAdditionalCharge
  4094. // s.PrescriptionId = tempPrescription.ID
  4095. // s.Status = 1
  4096. // s.UserOrgId = adminInfo.CurrentOrgId
  4097. // s.RecordDate = recordDateTime
  4098. // s.CreatedTime = ctime
  4099. // s.UpdatedTime = mtime
  4100. // s.PatientId = patient_id
  4101. // s.HisPatientId = his_patient_id
  4102. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4103. // if errcode > 0 {
  4104. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4105. // return
  4106. // }
  4107. // service.CreateAdditionalCharge(&s)
  4108. // var randNum int
  4109. // randNum = rand.Intn(10000) + 1000
  4110. // timestamp := time.Now().Unix()
  4111. // tempTime := time.Unix(timestamp, 0)
  4112. // timeFormat := tempTime.Format("20060102150405")
  4113. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4114. // service.CreateAdditionalCharge(&s)
  4115. //
  4116. // }
  4117. // }
  4118. //}
  4119. }
  4120. }
  4121. //查询今日该患者开的药品处方
  4122. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4123. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4124. //药品出库
  4125. if drugOutConfig.IsOpen == 1 {
  4126. for _, item := range hisdoctorlist {
  4127. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4128. // 查询该药品最后一次出库记录
  4129. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4130. if len(druginfo) > 0 {
  4131. //回退库存
  4132. for _, it := range druginfo {
  4133. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4134. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4135. }
  4136. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4137. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4138. }
  4139. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4140. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4141. }
  4142. }
  4143. }
  4144. //删除记录
  4145. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4146. //查询最后一次数据
  4147. if drugOutConfig.IsOpen == 1 {
  4148. //出库
  4149. if drug.IsUse == 2 {
  4150. creater := adminInfo.AdminUser.Id
  4151. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4152. }
  4153. //更新字典里面的库存
  4154. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4155. var sum_count int64
  4156. for _, its := range stockInfo {
  4157. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4158. if its.MaxUnit == baseDrug.MaxUnit {
  4159. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4160. }
  4161. sum_count += its.StockMaxNumber + its.StockMinNumber
  4162. }
  4163. //更新基础库存
  4164. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4165. //剩余库存
  4166. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4167. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4168. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4169. }
  4170. }
  4171. }
  4172. //耗材保存处方出库
  4173. if goodOutConfig.IsOpen == 1 {
  4174. //查询今日耗材出库数量
  4175. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4176. for _, item := range hisgoodlist {
  4177. //查询历史出库数据
  4178. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4179. var out_count_five int64
  4180. for _, item := range flowGood {
  4181. out_count_five += item.Count
  4182. }
  4183. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4184. if out_count_five != parseIntCount {
  4185. //查询耗材最后一次出库记录
  4186. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4187. //查询默认出库仓库库存
  4188. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4189. if len(wareOut) > 0 {
  4190. for _, it := range wareOut {
  4191. //回退库存
  4192. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4193. //删除出库记录
  4194. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4195. }
  4196. }
  4197. timeStr := time.Now().Format("2006-01-02")
  4198. timeArr := strings.Split(timeStr, "-")
  4199. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4200. total = total + 1
  4201. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4202. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4203. number = number + total
  4204. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4205. operation_time := time.Now().Unix()
  4206. creater := c.GetAdminUserInfo().AdminUser.Id
  4207. recordDateStr := time.Now().Format("2006-01-02")
  4208. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4209. nowtime := recordDate.Unix()
  4210. warehouseOut := models.WarehouseOut{
  4211. WarehouseOutOrderNumber: warehousing_out_order,
  4212. OperationTime: operation_time,
  4213. OrgId: adminInfo.CurrentOrgId,
  4214. Creater: creater,
  4215. Ctime: time.Now().Unix(),
  4216. Status: 1,
  4217. WarehouseOutTime: nowtime,
  4218. Type: 1,
  4219. StorehouseId: storeConfig.StorehouseOutInfo,
  4220. IsCheck: 1,
  4221. IsSys: 1,
  4222. }
  4223. //查询是否生成出库单
  4224. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4225. if out.ID == 0 {
  4226. service.AddSigleWarehouseOut(&warehouseOut)
  4227. }
  4228. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4229. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4230. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4231. dialyPrepareOne := models.DialysisBeforePrepare{
  4232. GoodTypeId: goodObj.GoodTypeId,
  4233. GoodId: item.ProjectId,
  4234. PatientId: item.PatientId,
  4235. RecordDate: item.RecordDate,
  4236. UserOrgId: adminInfo.CurrentOrgId,
  4237. Count: parseIntCount,
  4238. Ctime: time.Now().Unix(),
  4239. Creater: creater,
  4240. Status: 1,
  4241. StorehouseId: houseConfig.StorehouseOutInfo,
  4242. ProjectId: item.ID,
  4243. }
  4244. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4245. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4246. //查询历史出库数据
  4247. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4248. var out_count int64
  4249. for _, item := range flowGood {
  4250. out_count += item.Count
  4251. }
  4252. //如果历史数和当前数据不想等才进行退库出库
  4253. if out_count != parseIntCount {
  4254. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4255. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4256. detail := models.AutomaticReduceDetail{
  4257. WarehouseOutId: 0,
  4258. WarehouseOutOrderNumber: "",
  4259. PatientId: item.PatientId,
  4260. Ctime: time.Now().Unix(),
  4261. Mtime: 0,
  4262. Status: 1,
  4263. RecordTime: item.RecordDate,
  4264. OrgId: item.UserOrgId,
  4265. GoodId: item.ProjectId,
  4266. GoodTypeId: 0,
  4267. Count: parseIntCount,
  4268. Type: 0,
  4269. ProjectId: item.ID,
  4270. StorehouseId: 0,
  4271. }
  4272. service.CreateAutoDetail(detail)
  4273. //查询剩余库存
  4274. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4275. var sum_count int64
  4276. for _, item := range goodList {
  4277. sum_count += item.StockCount
  4278. }
  4279. //更新剩余库存
  4280. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4281. //耗材
  4282. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4283. }
  4284. }
  4285. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4286. //查询历史出库数据
  4287. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4288. var out_count int64
  4289. for _, item := range flowGood {
  4290. out_count += item.Count
  4291. }
  4292. //如果历史数和当前数据不想等才进行退库出库
  4293. if out_count != parseIntCount {
  4294. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4295. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4296. detail := models.AutomaticReduceDetail{
  4297. WarehouseOutId: 0,
  4298. WarehouseOutOrderNumber: "",
  4299. PatientId: item.PatientId,
  4300. Ctime: time.Now().Unix(),
  4301. Mtime: 0,
  4302. Status: 1,
  4303. RecordTime: item.RecordDate,
  4304. OrgId: item.UserOrgId,
  4305. GoodId: item.ProjectId,
  4306. GoodTypeId: 0,
  4307. Count: parseIntCount,
  4308. Type: 0,
  4309. ProjectId: item.ID,
  4310. StorehouseId: 0,
  4311. }
  4312. service.CreateAutoDetail(detail)
  4313. //查询剩余库存
  4314. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4315. var sum_count int64
  4316. for _, item := range goodList {
  4317. sum_count += item.StockCount
  4318. }
  4319. //更新剩余库存
  4320. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4321. //耗材
  4322. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4323. }
  4324. }
  4325. }
  4326. }
  4327. }
  4328. ////同步到自备药
  4329. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4330. if selfPrescriptionOpen.IsOpen == 1 {
  4331. timeStr := time.Now().Format("2006-01-02")
  4332. timeArr := strings.Split(timeStr, "-")
  4333. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4334. total = total + 1
  4335. operation_time := time.Now().Unix()
  4336. creater := adminInfo.AdminUser.Id
  4337. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4338. warehousing := models.XtSelfDrugWarehouse{
  4339. WarehousingOrder: warehousing_order,
  4340. OperationTime: operation_time,
  4341. OrgId: adminInfo.CurrentOrgId,
  4342. Creater: creater,
  4343. Ctime: time.Now().Unix(),
  4344. Status: 1,
  4345. WarehousingTime: recordDateTime,
  4346. Type: 0,
  4347. StorehouseId: 0,
  4348. IsCheck: 1,
  4349. PatientId: patient_id,
  4350. IsSys: 1,
  4351. }
  4352. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4353. if selfDrugWarehouse.ID == 0 {
  4354. service.AddSelfDrugWarehouse(&warehousing, tx)
  4355. }
  4356. if selfDrugWarehouse.ID > 0 {
  4357. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4358. }
  4359. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4360. fmt.Println(info)
  4361. for _, item := range hisdoctorlist {
  4362. //查询该病人的该药品是否已经入库
  4363. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4364. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4365. var in_count int64
  4366. if len(selfdruginfo) > 0 {
  4367. for _, item := range selfdruginfo {
  4368. var in_count_one int64
  4369. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4370. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4371. }
  4372. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4373. in_count_one = item.WarehousingCount
  4374. }
  4375. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4376. in_count_one = item.WarehousingCount
  4377. }
  4378. in_count += in_count_one
  4379. }
  4380. }
  4381. if selfBasedrug.IsSelfDrug == 1 {
  4382. var total_count int64
  4383. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4384. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4385. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4386. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4387. }
  4388. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4389. total_count += prescribingNumberSeven
  4390. }
  4391. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4392. total_count += prescribingNumberSeven
  4393. }
  4394. //入库
  4395. if total_count > in_count {
  4396. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4397. WarehousingOrder: warehousing_order,
  4398. WarehousingId: info.ID,
  4399. DrugId: item.DrugId,
  4400. Number: "",
  4401. ProductDate: 0,
  4402. ExpiryDate: 0,
  4403. WarehousingCount: total_count - in_count,
  4404. WarehouseingUnit: selfBasedrug.MinUnit,
  4405. Price: 0,
  4406. TotalPrice: 0,
  4407. Status: 1,
  4408. Ctime: time.Now().Unix(),
  4409. Remark: "",
  4410. OrgId: adminInfo.CurrentOrgId,
  4411. Type: 0,
  4412. Manufacturer: selfBasedrug.Manufacturer,
  4413. Dealer: selfBasedrug.Dealer,
  4414. StockMaxNumber: total_count - in_count,
  4415. RetailTotalPrice: 0,
  4416. BatchNumber: "",
  4417. MaxUnit: selfBasedrug.MinUnit,
  4418. MinUnit: selfBasedrug.MinUnit,
  4419. RetailPrice: 0,
  4420. StorehouseId: 0,
  4421. IsCheck: 1,
  4422. StockMinNumber: 0,
  4423. PatientId: patient_id,
  4424. IsSys: 1,
  4425. RecordDate: item.RecordDate,
  4426. AdviceId: item.ID,
  4427. }
  4428. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4429. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4430. Creator := adminInfo.AdminUser.Id
  4431. //查询默认仓库剩余多少库存
  4432. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4433. var sum_count int64
  4434. for _, it := range list {
  4435. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4436. if it.MaxUnit == baseDrug.MaxUnit {
  4437. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4438. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4439. }
  4440. sum_count += it.StockMaxNumber + it.StockMinNumber
  4441. }
  4442. flow := &models.XtSelfDrugFlow{
  4443. WarehousingId: info.ID,
  4444. DrugId: item.DrugId,
  4445. Number: "",
  4446. BatchNumber: "",
  4447. Count: total_count - in_count,
  4448. UserOrgId: adminInfo.CurrentOrgId,
  4449. PatientId: item.PatientId,
  4450. SystemTime: time.Now().Unix(),
  4451. ConsumableType: 1,
  4452. IsSys: 1,
  4453. WarehousingOrder: warehousing_order,
  4454. WarehouseOutId: 0,
  4455. WarehouseOutOrderNumber: "",
  4456. IsEdit: 0,
  4457. CancelStockId: 0,
  4458. CancelOrderNumber: "",
  4459. Manufacturer: selfBasedrug.Manufacturer,
  4460. Dealer: selfBasedrug.Dealer,
  4461. Creator: Creator,
  4462. UpdateCreator: Creator,
  4463. Status: 1,
  4464. Ctime: item.AdviceDate,
  4465. Mtime: 0,
  4466. Price: item.Price,
  4467. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4468. WarehouseOutDetailId: 0,
  4469. CancelOutDetailId: 0,
  4470. ExpireDate: 0,
  4471. ProductDate: 0,
  4472. MaxUnit: selfBasedrug.MinUnit,
  4473. MinUnit: selfBasedrug.MinUnit,
  4474. StorehouseId: 0,
  4475. OverCount: sum_count,
  4476. OperateTime: time.Now().Unix(),
  4477. AdviceId: item.ID,
  4478. }
  4479. service.CreateSelfDrugFlow(flow, tx)
  4480. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4481. var total_count int64 // 入库总数量
  4482. var over_count int64 //剩余库存
  4483. for _, it := range drugInfolist {
  4484. if it.MaxUnit == selfBasedrug.MaxUnit {
  4485. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4486. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4487. }
  4488. }
  4489. for _, it := range drugInfolist {
  4490. total_count += it.WarehousingCount
  4491. over_count += it.StockMaxNumber + it.StockMinNumber
  4492. }
  4493. //查询该仓库是否有默认数据
  4494. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4495. if selfDrugStock.ID == 0 {
  4496. drugStock := models.XtSelfDrugStockCount{
  4497. UserOrgId: item.UserOrgId,
  4498. PatientId: item.PatientId,
  4499. SumInCount: total_count,
  4500. SumOutCount: 0,
  4501. SumCancelCount: 0,
  4502. DrugId: item.DrugId,
  4503. Ctime: time.Now().Unix(),
  4504. Mtime: 0,
  4505. Status: 1,
  4506. FlushCount: over_count,
  4507. SumActOutCount: 0,
  4508. }
  4509. service.CreateSelfDrugStockSum(drugStock, tx)
  4510. }
  4511. if selfDrugStock.ID > 0 {
  4512. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4513. }
  4514. }
  4515. //查询这个单据的出库数量
  4516. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4517. var his_out_count int64
  4518. for _, item := range drugFlowList {
  4519. his_out_count += item.Count
  4520. }
  4521. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4522. if (total_count + his_out_count) <= in_count {
  4523. // 出库
  4524. if total_count < in_count {
  4525. var cha_count int64
  4526. cha_count = in_count - total_count
  4527. var stock_number int64 = 0
  4528. //查询库存是否充足
  4529. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4530. // 将该批次的剩余库存数量转换为拆零数量
  4531. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4532. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4533. }
  4534. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4535. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4536. }
  4537. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4538. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4539. }
  4540. if stock_number >= cha_count {
  4541. var maxNumber int64 = 0
  4542. var minNumber int64 = 0
  4543. maxNumber = cha_count / selfBasedrug.MinNumber
  4544. minNumber = cha_count % selfBasedrug.MinNumber
  4545. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4546. minNumber = maxNumber
  4547. }
  4548. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4549. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4551. return
  4552. }
  4553. }
  4554. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4555. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4556. }
  4557. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4558. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4559. }
  4560. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4561. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4562. }
  4563. if warehouse.StockMaxNumber < 0 {
  4564. warehouse.StockMaxNumber = 0
  4565. }
  4566. if warehouse.StockMinNumber < 0 {
  4567. warehouse.StockMinNumber = 0
  4568. }
  4569. warehouse.Mtime = time.Now().Unix()
  4570. if warehouse.StockMinNumber < minNumber {
  4571. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4572. if warehouse.MaxUnit != warehouse.MinUnit {
  4573. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4574. }
  4575. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4576. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4577. }
  4578. } else {
  4579. if minNumber > 0 {
  4580. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4581. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4582. }
  4583. }
  4584. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4585. if warehouse.StockMinNumber > 0 {
  4586. if warehouse.StockMinNumber-cha_count >= 0 {
  4587. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4588. }
  4589. }
  4590. }
  4591. }
  4592. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4593. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4594. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4595. }
  4596. }
  4597. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4598. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4600. return
  4601. }
  4602. }
  4603. if warehouse.StockMinNumber <= 0 {
  4604. warehouse.StockMinNumber = 0
  4605. }
  4606. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4607. //查询该药品剩余库存
  4608. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4609. var over_count int64
  4610. for _, its := range infolist {
  4611. if its.MaxUnit == selfBasedrug.MaxUnit {
  4612. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4613. }
  4614. over_count += its.StockMaxNumber + its.StockMinNumber
  4615. }
  4616. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4617. drugflow := models.XtSelfDrugFlow{
  4618. WarehouseOutId: 0,
  4619. WarehouseOutOrderNumber: warehousing_order,
  4620. WarehousingOrder: warehousing_order,
  4621. DrugId: item.DrugId,
  4622. Number: warehouse.Number,
  4623. ProductDate: warehouse.ProductDate,
  4624. ExpireDate: warehouse.ExpiryDate,
  4625. Count: cha_count,
  4626. Price: warehouse.RetailPrice,
  4627. Status: 1,
  4628. Ctime: item.AdviceDate,
  4629. Mtime: time.Now().Unix(),
  4630. UserOrgId: item.UserOrgId,
  4631. Manufacturer: warehouse.Manufacturer,
  4632. Dealer: warehouse.Dealer,
  4633. BatchNumber: warehouse.BatchNumber,
  4634. MaxUnit: selfBasedrug.MinUnit,
  4635. ConsumableType: 20,
  4636. IsEdit: 1,
  4637. Creator: 0,
  4638. IsSys: 3,
  4639. WarehouseOutDetailId: drugWareInfo.ID,
  4640. AdviceId: item.ID,
  4641. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4642. StorehouseId: 0,
  4643. AdminUserId: creater,
  4644. LastPrice: warehouse.Price,
  4645. StockCount: "",
  4646. WarehousingDetailId: 0,
  4647. OverCount: over_count,
  4648. RetailPrice: item.Price, //手动出库出库价格
  4649. WarehousingId: warehouse.ID,
  4650. SystemTime: item.AdviceDate,
  4651. PatientId: item.PatientId,
  4652. Remark: "保存处方入库数据差",
  4653. OperateTime: time.Now().Unix(),
  4654. }
  4655. if warehouse.RetailPrice == 0 {
  4656. drugflow.Price = item.Price
  4657. }
  4658. service.CreateSelfDrugFlowOne(drugflow, tx)
  4659. var out_count int64
  4660. out_count = in_count - total_count
  4661. fmt.Println("in_count------------------", in_count)
  4662. fmt.Println("total_count------------------", total_count)
  4663. //添加出库数量
  4664. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4665. //查询剩余库存
  4666. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4667. var sum_count int64
  4668. for _, its := range stockInfo {
  4669. if its.MaxUnit == selfBasedrug.MaxUnit {
  4670. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4671. }
  4672. sum_count += its.StockMaxNumber + its.StockMinNumber
  4673. }
  4674. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4675. } else {
  4676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4677. return
  4678. }
  4679. }
  4680. }
  4681. }
  4682. }
  4683. }
  4684. }
  4685. tx.Commit()
  4686. if err == nil {
  4687. c.ServeSuccessJSON(map[string]interface{}{
  4688. "msg": "保存成功",
  4689. })
  4690. return
  4691. } else {
  4692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4693. return
  4694. }
  4695. }
  4696. }
  4697. //func (c *HisApiController) EditHisPrescription() {
  4698. // record_date := c.GetString("record_date")
  4699. // patient_id, _ := c.GetInt64("patient_id")
  4700. // reg_type, _ := c.GetInt64("reg_type")
  4701. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4702. // diagnose := c.GetString("diagnose")
  4703. // sick_type, _ := c.GetInt64("sick_type")
  4704. // sick_history := c.GetString("sick_history")
  4705. // doctor_id, _ := c.GetInt64("doctor", 0)
  4706. // department, _ := c.GetInt64("department", 0)
  4707. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4708. // p_type, _ := c.GetInt64("p_type")
  4709. //
  4710. // dataBody := make(map[string]interface{}, 0)
  4711. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4712. // if err != nil {
  4713. // utils.ErrorLog(err.Error())
  4714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4715. // return
  4716. // }
  4717. //
  4718. // timeLayout := "2006-01-02"
  4719. // loc, _ := time.LoadLocation("Local")
  4720. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4721. // if err != nil {
  4722. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4723. // return
  4724. // }
  4725. // adminInfo := c.GetAdminUserInfo()
  4726. // recordDateTime := theTime.Unix()
  4727. //
  4728. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4729. //
  4730. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4731. // var hpInfo models.HisPrescriptionInfo
  4732. // if info.ID == 0 {
  4733. // var randNum int
  4734. // randNum = rand.Intn(10000) + 1000
  4735. // timestamp := time.Now().Unix()
  4736. // tempTime := time.Unix(timestamp, 0)
  4737. // timeFormat := tempTime.Format("20060102150405")
  4738. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4739. //
  4740. // hpInfo = models.HisPrescriptionInfo{
  4741. // UserOrgId: adminInfo.CurrentOrgId,
  4742. // RecordDate: theTime.Unix(),
  4743. // PatientId: patient_id,
  4744. // Status: 1,
  4745. // Ctime: time.Now().Unix(),
  4746. // Mtime: time.Now().Unix(),
  4747. // Creator: adminInfo.AdminUser.Id,
  4748. // Modifier: adminInfo.AdminUser.Id,
  4749. // Diagnosis: diagnose,
  4750. // SickHistory: sick_history,
  4751. // Departments: department,
  4752. // RegisterType: reg_type,
  4753. // PrescriptionNumber: p_number,
  4754. // PrescriptionStatus: 1,
  4755. // Doctor: role.UserName,
  4756. // DoctorId: doctor_id,
  4757. // SickType: sick_type,
  4758. // PType: p_type,
  4759. // }
  4760. // service.SavePatientPrescriptionInfo(hpInfo)
  4761. //
  4762. // } else {
  4763. // hpInfo = models.HisPrescriptionInfo{
  4764. // ID: info.ID,
  4765. // UserOrgId: adminInfo.CurrentOrgId,
  4766. // RecordDate: info.RecordDate,
  4767. // PatientId: info.PatientId,
  4768. // Status: 1,
  4769. // Ctime: info.Ctime,
  4770. // Mtime: time.Now().Unix(),
  4771. // Creator: info.Creator,
  4772. // Modifier: adminInfo.AdminUser.Id,
  4773. // Diagnosis: diagnose,
  4774. // SickHistory: sick_history,
  4775. // Departments: department,
  4776. // RegisterType: reg_type,
  4777. // PrescriptionNumber: info.PrescriptionNumber,
  4778. // Doctor: role.UserName,
  4779. // PrescriptionStatus: info.PrescriptionStatus,
  4780. // DoctorId: doctor_id,
  4781. // SickType: sick_type,
  4782. // PType: info.PType,
  4783. // }
  4784. // service.SavePatientPrescriptionInfo(hpInfo)
  4785. // }
  4786. //
  4787. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4788. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4789. //
  4790. // if len(prescriptions) > 0 {
  4791. // for _, item := range prescriptions {
  4792. // items := item.(map[string]interface{})
  4793. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4794. // utils.ErrorLog("id")
  4795. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4796. // return
  4797. // }
  4798. // id := int64(items["id"].(float64))
  4799. //
  4800. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4801. // utils.ErrorLog("type")
  4802. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4803. // return
  4804. // }
  4805. // types := int64(items["type"].(float64))
  4806. //
  4807. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4808. // utils.ErrorLog("med_type")
  4809. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4810. // return
  4811. // }
  4812. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4813. //
  4814. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4815. //
  4816. // ctime := time.Now().Unix()
  4817. //
  4818. // prescription := &models.HisPrescription{
  4819. // ID: id,
  4820. // PatientId: patient_id,
  4821. // UserOrgId: adminInfo.CurrentOrgId,
  4822. // RecordDate: recordDateTime,
  4823. // Ctime: ctime,
  4824. // Mtime: ctime,
  4825. // Type: types,
  4826. // Modifier: adminInfo.AdminUser.Id,
  4827. // Creator: adminInfo.AdminUser.Id,
  4828. // Status: 1,
  4829. // Doctor: role.UserName,
  4830. // HisPatientId: his_patient_id,
  4831. // OrderStatus: 1,
  4832. // BatchNumber: "",
  4833. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4834. // PType: hpInfo.PType,
  4835. // MedType: med_type,
  4836. // }
  4837. //
  4838. // if historyPrescription.ID > 0 {
  4839. // prescription.PreTime = historyPrescription.PreTime
  4840. //
  4841. // }
  4842. //
  4843. // service.SaveHisPrescription(prescription)
  4844. //
  4845. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4846. // advices := items["advices"].([]interface{})
  4847. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4848. // groupNo := int64(0)
  4849. // ctime := time.Now().Unix()
  4850. // mtime := ctime
  4851. // if len(advices) > 0 {
  4852. // for _, advice := range advices {
  4853. // var s models.HisDoctorAdviceInfo
  4854. // s.PrescriptionId = prescription.ID
  4855. // s.AdviceType = 2
  4856. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4857. // s.StopState = 2
  4858. // s.ExecutionState = 2
  4859. // s.AdviceDate = recordDateTime
  4860. // s.Status = 1
  4861. // s.UserOrgId = adminInfo.CurrentOrgId
  4862. // s.RecordDate = recordDateTime
  4863. // s.StartTime = prescription.PreTime
  4864. // s.Groupno = groupNo
  4865. // s.CreatedTime = ctime
  4866. // s.UpdatedTime = mtime
  4867. // s.PatientId = patient_id
  4868. // s.HisPatientId = his_patient_id
  4869. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4870. // if errcode > 0 {
  4871. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4872. // return
  4873. // }
  4874. //
  4875. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4876. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4877. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4878. // if s.Price == 0 {
  4879. // s.Price = lastWarehouse.RetailPrice
  4880. // }
  4881. // }
  4882. //
  4883. // service.CreateHisDoctorAdvice(&s)
  4884. // //记录日志
  4885. // byterequest, _ := json.Marshal(s)
  4886. // adviceLog := models.XtDoctorAdviceLog{
  4887. // UserOrgId: s.UserOrgId,
  4888. // PatientId: s.PatientId,
  4889. // AdminUserId: adminInfo.AdminUser.Id,
  4890. // Module: 1,
  4891. // ErrLog: string(byterequest),
  4892. // Status: 1,
  4893. // Ctime: time.Now().Unix(),
  4894. // Mtime: 0,
  4895. // Source: "电脑端his医嘱修改",
  4896. // RecordDate: s.AdviceDate,
  4897. // }
  4898. // service.CreateDoctorAdviceLog(adviceLog)
  4899. // redis := service.RedisClient()
  4900. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4901. // redis.Set(key, "", time.Second)
  4902. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4903. // fmt.Println("keyOne", keyOne)
  4904. // redis.Set(keyOne, "", time.Second)
  4905. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4906. // redis.Set(keySeven, "", time.Second)
  4907. // redis.Close()
  4908. //
  4909. // }
  4910. // }
  4911. // }
  4912. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4913. // projects := items["project"].([]interface{})
  4914. // if len(projects) > 0 {
  4915. // for _, project := range projects {
  4916. // var p models.HisPrescriptionProject
  4917. // p.PrescriptionId = prescription.ID
  4918. // p.Ctime = time.Now().Unix()
  4919. // p.Mtime = time.Now().Unix()
  4920. // p.PatientId = patient_id
  4921. // p.RecordDate = recordDateTime
  4922. // p.UserOrgId = adminInfo.CurrentOrgId
  4923. // p.HisPatientId = his_patient_id
  4924. // p.Status = 1
  4925. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4926. // if errcode > 0 {
  4927. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4928. // return
  4929. // }
  4930. // service.CreateHisProjectTwo(&p)
  4931. //
  4932. // //记录日志
  4933. // byterequest, _ := json.Marshal(p)
  4934. // adviceLog := models.XtDoctorAdviceLog{
  4935. // UserOrgId: p.UserOrgId,
  4936. // PatientId: p.PatientId,
  4937. // AdminUserId: adminInfo.AdminUser.Id,
  4938. // Module: 1,
  4939. // ErrLog: string(byterequest),
  4940. // Status: 1,
  4941. // Ctime: time.Now().Unix(),
  4942. // Mtime: 0,
  4943. // Source: "电脑端his项目修改",
  4944. // RecordDate: p.RecordDate,
  4945. // }
  4946. // service.CreateDoctorAdviceLog(adviceLog)
  4947. // }
  4948. // }
  4949. // }
  4950. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4951. // addition := items["addition"].([]interface{})
  4952. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4953. // ctime := time.Now().Unix()
  4954. // mtime := ctime
  4955. // if len(addition) > 0 {
  4956. // for _, item := range addition {
  4957. // var s models.HisAdditionalCharge
  4958. // s.PrescriptionId = prescription.ID
  4959. // s.Status = 1
  4960. // s.UserOrgId = adminInfo.CurrentOrgId
  4961. // s.RecordDate = recordDateTime
  4962. // s.CreatedTime = ctime
  4963. // s.UpdatedTime = mtime
  4964. // s.PatientId = patient_id
  4965. // s.HisPatientId = his_patient_id
  4966. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4967. // if errcode > 0 {
  4968. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4969. // return
  4970. // }
  4971. // service.CreateAdditionalCharge(&s)
  4972. // }
  4973. // }
  4974. // }
  4975. //
  4976. // }
  4977. // }
  4978. // }
  4979. // if err == nil {
  4980. // c.ServeSuccessJSON(map[string]interface{}{
  4981. // "msg": "保存成功",
  4982. // })
  4983. // return
  4984. //
  4985. // } else {
  4986. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4987. // return
  4988. // }
  4989. //}
  4990. func (c *HisApiController) DeletePrescription() {
  4991. prescription_id, _ := c.GetInt64("id")
  4992. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4993. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4994. ////同步到自备药
  4995. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  4996. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  4997. if selfPrescriptionOpen.IsOpen == 1 {
  4998. // 在函数结束时处理事务回滚
  4999. db := service.XTWriteDB()
  5000. tx := db.Begin()
  5001. defer func() {
  5002. if r := recover(); r != nil {
  5003. tx.Rollback()
  5004. } else {
  5005. tx.Commit()
  5006. }
  5007. }()
  5008. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5009. for _, item := range advicesList {
  5010. timeStr := time.Now().Format("2006-01-02")
  5011. timeArr := strings.Split(timeStr, "-")
  5012. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5013. total = total + 1
  5014. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5015. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5016. number = number + total
  5017. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5018. operation_time := time.Now().Unix()
  5019. creater := c.GetAdminUserInfo().AdminUser.Id
  5020. //创建一个出库单
  5021. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5022. WarehouseOutOrderNumber: warehousing_out_order,
  5023. OperationTime: operation_time,
  5024. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5025. Creater: creater,
  5026. Ctime: time.Now().Unix(),
  5027. Status: 1,
  5028. WarehouseOutTime: item.AdviceDate,
  5029. Type: 0,
  5030. PatientId: item.PatientId,
  5031. IsCheck: 1,
  5032. }
  5033. //查询今日是否有出库数据
  5034. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5035. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5036. if lastWarehouseOut.ID == 0 {
  5037. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5038. }
  5039. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5040. var total_count int64
  5041. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5042. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5043. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5044. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5045. }
  5046. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5047. total_count += prescribingNumberSeven
  5048. }
  5049. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5050. total_count += prescribingNumberSeven
  5051. }
  5052. //出库
  5053. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5054. WarehouseOutOrderNumber: warehousing_out_order,
  5055. WarehouseOutId: lastWarehouseOut.ID,
  5056. DrugId: item.DrugId,
  5057. Count: total_count,
  5058. Price: 0,
  5059. TotalPrice: 0,
  5060. Status: 1,
  5061. Ctime: item.AdviceDate,
  5062. Mtime: item.AdviceDate,
  5063. Remark: "",
  5064. OrgId: item.UserOrgId,
  5065. Type: 0,
  5066. Manufacturer: selfBasedrug.Manufacturer,
  5067. Dealer: selfBasedrug.Dealer,
  5068. RetailPrice: 0,
  5069. RetailTotalPrice: 0,
  5070. CountUnit: selfBasedrug.MinUnit,
  5071. ExpiryDate: 0,
  5072. ProductDate: 0,
  5073. Number: "",
  5074. BatchNumber: "",
  5075. IsSys: 1,
  5076. WarehouseInfoId: 0,
  5077. AdminUserId: 0,
  5078. StockCount: "",
  5079. IsCheck: 1,
  5080. SysRecordTime: item.AdviceDate,
  5081. PatientId: item.PatientId,
  5082. ClassType: "",
  5083. AdviceId: item.ID,
  5084. }
  5085. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5086. }
  5087. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5088. for _, it := range warehousingOutInfo {
  5089. //查询今日是否有出库数据
  5090. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5091. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5092. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5093. //出库逻辑
  5094. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5095. //查询剩余库存
  5096. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5097. var sum_count int64
  5098. for _, its := range stockInfo {
  5099. if its.MaxUnit == medical.MaxUnit {
  5100. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5101. }
  5102. sum_count += its.StockMaxNumber + its.StockMinNumber
  5103. }
  5104. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5105. }
  5106. }
  5107. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5108. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5109. //耗材保存处方出库
  5110. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5111. //已收费和已发药限制逻辑
  5112. isCharge := false
  5113. isMedicine := false
  5114. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5115. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5116. if new_prescription.IsMedicine == 1 {
  5117. isMedicine = true
  5118. }
  5119. for _, item := range new_prescriptions {
  5120. if item.OrderStatus == 4 {
  5121. isCharge = true
  5122. }
  5123. }
  5124. if p_err != nil {
  5125. if new_prescription.ID > 0 {
  5126. if new_prescription.OrderStatus == 2 {
  5127. isCharge = true
  5128. }
  5129. }
  5130. }
  5131. for _, item := range advices {
  5132. if item.IsMedicine == 1 {
  5133. isMedicine = true
  5134. }
  5135. }
  5136. if isCharge {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5138. return
  5139. }
  5140. if isMedicine {
  5141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5142. return
  5143. }
  5144. //已收费和已发药限制逻辑
  5145. if len(projects) > 0 {
  5146. for _, item := range projects {
  5147. service.DeletePrintInfo(item.ID) //删除打印信息
  5148. if goodOutConfig.IsOpen != 1 {
  5149. if stockConfig.IsOpen == 1 {
  5150. if item.Type == 3 && item.IsOut == 1 {
  5151. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5152. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5153. good.Total = good.Total + f_count
  5154. service.UpdateGoodInfo(&good)
  5155. operation_time := time.Now().Unix()
  5156. creater := c.GetAdminUserInfo().AdminUser.Id
  5157. //创建退库单
  5158. timeStr := time.Now().Format("2006-01-02")
  5159. timeArr := strings.Split(timeStr, "-")
  5160. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5161. total = total + 1
  5162. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5163. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5164. cancelStock := models.CancelStock{
  5165. OrderNumber: orderNumber,
  5166. OperaTime: operation_time,
  5167. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5168. Creater: creater,
  5169. Ctime: time.Now().Unix(),
  5170. Status: 1,
  5171. ReturnTime: item.RecordDate,
  5172. Type: 1,
  5173. StorehouseId: houseConfig.StorehouseOutInfo,
  5174. IsCheck: 1,
  5175. }
  5176. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5177. if msgerrkonde == gorm.ErrRecordNotFound {
  5178. service.AddSigleCancelStock(&cancelStock)
  5179. }
  5180. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5181. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5182. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5183. //查询该耗材是否出库
  5184. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5185. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5186. deaerler, _ := service.GetDealerById(info.Dealer)
  5187. var total_count int64
  5188. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5189. total_count += count
  5190. if info.ID > 0 {
  5191. if info.Count >= total_count {
  5192. //回退库存
  5193. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5194. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5195. var flush_count int64
  5196. for _, it := range goodList {
  5197. flush_count += it.StockCount
  5198. }
  5199. cancelStockInfo := models.CancelStockInfo{
  5200. GoodId: item.ProjectId,
  5201. CancelStockId: cancel.ID,
  5202. GoodTypeId: good.GoodTypeId,
  5203. Count: prescribingNumber,
  5204. Price: info.Price,
  5205. Total: 0,
  5206. ProductDate: info.ProductDate,
  5207. ExpiryDate: info.ExpiryDate,
  5208. Ctime: time.Now().Unix(),
  5209. Status: 1,
  5210. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5211. OrderNumber: cancel.OrderNumber,
  5212. Type: 0,
  5213. Dealer: deaerler.DealerName,
  5214. Manufacturer: manufacturer.ManufacturerName,
  5215. Number: info.Number,
  5216. RegisterAccount: "",
  5217. Remark: "",
  5218. WarehouseInfoId: info.WarehouseInfotId,
  5219. PatientId: info.PatientId,
  5220. RecordDate: info.SysRecordTime,
  5221. StorehouseId: houseConfig.StorehouseOutInfo,
  5222. IsCheck: 1,
  5223. }
  5224. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5225. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5226. flow := models.VmStockFlow{
  5227. WarehousingId: info.WarehouseInfotId,
  5228. GoodId: item.ProjectId,
  5229. Number: info.Number,
  5230. LicenseNumber: info.LicenseNumber,
  5231. Count: prescribingNumber,
  5232. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5233. PatientId: item.PatientId,
  5234. SystemTime: info.SysRecordTime,
  5235. ConsumableType: 7,
  5236. IsSys: 0,
  5237. WarehousingOrder: "",
  5238. WarehouseOutId: info.WarehouseOutId,
  5239. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5240. IsEdit: 0,
  5241. CancelStockId: cancel.ID,
  5242. CancelOrderNumber: cancel.OrderNumber,
  5243. Manufacturer: manufacturer.ID,
  5244. Dealer: 0,
  5245. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5246. UpdateCreator: 0,
  5247. Status: 1,
  5248. Ctime: time.Now().Unix(),
  5249. Mtime: 0,
  5250. Price: info.Price,
  5251. WarehousingDetailId: info.WarehouseInfotId,
  5252. WarehouseOutDetailId: info.ID,
  5253. CancelOutDetailId: cancelInfo.ID,
  5254. ProductDate: info.ProductDate,
  5255. ExpireDate: info.ExpiryDate,
  5256. StorehouseId: houseConfig.StorehouseOutInfo,
  5257. OverCount: flush_count,
  5258. OperateTime: time.Now().Unix(),
  5259. }
  5260. service.CreateStockFlowOne(flow)
  5261. //退库数量增加
  5262. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5263. //出库数量减少
  5264. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5265. }
  5266. if info.Count < total_count {
  5267. //回退库存
  5268. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5269. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5270. var flush_count int64
  5271. for _, it := range goodList {
  5272. flush_count += it.StockCount
  5273. }
  5274. cancelStockInfo := models.CancelStockInfo{
  5275. GoodId: item.ProjectId,
  5276. CancelStockId: cancel.ID,
  5277. GoodTypeId: good.GoodTypeId,
  5278. Count: info.Count,
  5279. Price: info.Price,
  5280. Total: 0,
  5281. ProductDate: info.ProductDate,
  5282. ExpiryDate: info.ExpiryDate,
  5283. Ctime: time.Now().Unix(),
  5284. Status: 1,
  5285. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5286. OrderNumber: cancel.OrderNumber,
  5287. Type: 0,
  5288. Dealer: deaerler.DealerName,
  5289. Manufacturer: manufacturer.ManufacturerName,
  5290. Number: info.Number,
  5291. RegisterAccount: "",
  5292. Remark: "",
  5293. WarehouseInfoId: info.WarehouseInfotId,
  5294. PatientId: info.PatientId,
  5295. RecordDate: info.SysRecordTime,
  5296. StorehouseId: houseConfig.StorehouseOutInfo,
  5297. IsCheck: 1,
  5298. }
  5299. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5300. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5301. flow := models.VmStockFlow{
  5302. WarehousingId: info.WarehouseInfotId,
  5303. GoodId: item.ProjectId,
  5304. Number: info.Number,
  5305. LicenseNumber: info.LicenseNumber,
  5306. Count: info.Count,
  5307. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5308. PatientId: item.PatientId,
  5309. SystemTime: info.SysRecordTime,
  5310. ConsumableType: 7,
  5311. IsSys: 0,
  5312. WarehousingOrder: "",
  5313. WarehouseOutId: info.WarehouseOutId,
  5314. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5315. IsEdit: 0,
  5316. CancelStockId: cancel.ID,
  5317. CancelOrderNumber: cancel.OrderNumber,
  5318. Manufacturer: manufacturer.ID,
  5319. Dealer: 0,
  5320. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5321. UpdateCreator: 0,
  5322. Status: 1,
  5323. Ctime: time.Now().Unix(),
  5324. Mtime: 0,
  5325. Price: info.Price,
  5326. WarehousingDetailId: info.WarehouseInfotId,
  5327. WarehouseOutDetailId: info.ID,
  5328. CancelOutDetailId: cancelInfo.ID,
  5329. ProductDate: info.ProductDate,
  5330. ExpireDate: info.ExpiryDate,
  5331. StorehouseId: houseConfig.StorehouseOutInfo,
  5332. OverCount: flush_count,
  5333. OperateTime: time.Now().Unix(),
  5334. }
  5335. service.CreateStockFlowOne(flow)
  5336. //退库数量增加
  5337. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5338. //出库数量减少
  5339. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5340. }
  5341. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5342. var flush_count int64
  5343. for _, it := range goodList {
  5344. flush_count += it.StockCount
  5345. }
  5346. //查询已出库数量
  5347. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5348. if prescribingNumber < dialysisInfo.Count {
  5349. //改变数量
  5350. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5351. }
  5352. if prescribingNumber >= dialysisInfo.Count {
  5353. //删除出库表
  5354. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5355. }
  5356. //更新库存
  5357. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5358. //更新基础库库存
  5359. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5360. }
  5361. }
  5362. }
  5363. }
  5364. //保存耗材出库
  5365. if goodOutConfig.IsOpen == 1 {
  5366. if item.Type == 3 {
  5367. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5368. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5369. good.Total = good.Total + f_count
  5370. service.UpdateGoodInfo(&good)
  5371. operation_time := time.Now().Unix()
  5372. creater := c.GetAdminUserInfo().AdminUser.Id
  5373. //创建退库单
  5374. timeStr := time.Now().Format("2006-01-02")
  5375. timeArr := strings.Split(timeStr, "-")
  5376. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5377. total = total + 1
  5378. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5379. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5380. cancelStock := models.CancelStock{
  5381. OrderNumber: orderNumber,
  5382. OperaTime: operation_time,
  5383. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5384. Creater: creater,
  5385. Ctime: time.Now().Unix(),
  5386. Status: 1,
  5387. ReturnTime: item.RecordDate,
  5388. Type: 1,
  5389. StorehouseId: houseConfig.StorehouseOutInfo,
  5390. IsCheck: 1,
  5391. }
  5392. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5393. if msgerrkonde == gorm.ErrRecordNotFound {
  5394. service.AddSigleCancelStock(&cancelStock)
  5395. }
  5396. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5397. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5398. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5399. //查询该耗材是否出库
  5400. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5401. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5402. deaerler, _ := service.GetDealerById(info.Dealer)
  5403. var total_count int64
  5404. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5405. total_count += count
  5406. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5407. var flush_count int64
  5408. for _, it := range goodList {
  5409. flush_count += it.StockCount
  5410. }
  5411. fmt.Println("历史出库数据", info.Count)
  5412. fmt.Println("出库数量", total_count)
  5413. if info.ID > 0 {
  5414. cancelStockInfo := models.CancelStockInfo{
  5415. GoodId: item.ProjectId,
  5416. CancelStockId: cancel.ID,
  5417. GoodTypeId: good.GoodTypeId,
  5418. Count: prescribingNumber,
  5419. Price: info.Price,
  5420. Total: 0,
  5421. ProductDate: info.ProductDate,
  5422. ExpiryDate: info.ExpiryDate,
  5423. Ctime: time.Now().Unix(),
  5424. Status: 1,
  5425. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5426. OrderNumber: cancel.OrderNumber,
  5427. Type: 0,
  5428. Dealer: deaerler.DealerName,
  5429. Manufacturer: manufacturer.ManufacturerName,
  5430. Number: info.Number,
  5431. RegisterAccount: "",
  5432. Remark: "",
  5433. WarehouseInfoId: info.WarehouseInfotId,
  5434. PatientId: info.PatientId,
  5435. RecordDate: info.SysRecordTime,
  5436. StorehouseId: houseConfig.StorehouseOutInfo,
  5437. IsCheck: 1,
  5438. }
  5439. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5440. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5441. //查询出库数量
  5442. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5443. //出库数据 大于 退库数量
  5444. if len(list) > 0 {
  5445. for _, it := range list {
  5446. //回退库存
  5447. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5448. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5449. var flush_count_one int64
  5450. for _, it := range goodList {
  5451. flush_count_one += it.StockCount
  5452. }
  5453. //查询该批次是否有退库数据
  5454. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5455. creater := c.GetAdminUserInfo().AdminUser.Id
  5456. flow := models.VmStockFlow{
  5457. WarehousingId: it.WarehouseInfotId,
  5458. GoodId: it.GoodId,
  5459. Number: it.Number,
  5460. LicenseNumber: it.LicenseNumber,
  5461. Count: it.Count,
  5462. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5463. PatientId: it.PatientId,
  5464. SystemTime: it.SysRecordTime,
  5465. ConsumableType: 7,
  5466. IsSys: 0,
  5467. WarehousingOrder: "",
  5468. WarehouseOutId: it.WarehouseOutId,
  5469. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5470. IsEdit: 0,
  5471. CancelStockId: cancel.ID,
  5472. CancelOrderNumber: cancel.OrderNumber,
  5473. Manufacturer: manufacturer.ID,
  5474. Dealer: 0,
  5475. Creator: creater,
  5476. UpdateCreator: 0,
  5477. Status: 1,
  5478. Ctime: time.Now().Unix(),
  5479. Mtime: 0,
  5480. Price: it.Price,
  5481. WarehousingDetailId: it.WarehouseInfotId,
  5482. WarehouseOutDetailId: it.ID,
  5483. CancelOutDetailId: cancelInfo.ID,
  5484. ProductDate: it.ProductDate,
  5485. ExpireDate: it.ExpiryDate,
  5486. StorehouseId: houseConfig.StorehouseOutInfo,
  5487. OverCount: flush_count_one,
  5488. }
  5489. service.CreateStockFlowOne(flow)
  5490. //if flow.ID > 0 {
  5491. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5492. //}
  5493. }
  5494. }
  5495. //flow := models.VmStockFlow{
  5496. // WarehousingId: info.WarehouseInfotId,
  5497. // GoodId: item.ProjectId,
  5498. // Number: info.Number,
  5499. // LicenseNumber: info.LicenseNumber,
  5500. // Count: prescribingNumber,
  5501. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5502. // PatientId: item.PatientId,
  5503. // SystemTime: info.SysRecordTime,
  5504. // ConsumableType: 7,
  5505. // IsSys: 0,
  5506. // WarehousingOrder: "",
  5507. // WarehouseOutId: info.WarehouseOutId,
  5508. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5509. // IsEdit: 0,
  5510. // CancelStockId: cancel.ID,
  5511. // CancelOrderNumber: cancel.OrderNumber,
  5512. // Manufacturer: manufacturer.ID,
  5513. // Dealer: 0,
  5514. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5515. // UpdateCreator: 0,
  5516. // Status: 1,
  5517. // Ctime: time.Now().Unix(),
  5518. // Mtime: 0,
  5519. // Price: info.Price,
  5520. // WarehousingDetailId: info.WarehouseInfotId,
  5521. // WarehouseOutDetailId: info.ID,
  5522. // CancelOutDetailId: cancelInfo.ID,
  5523. // ProductDate: info.ProductDate,
  5524. // ExpireDate: info.ExpiryDate,
  5525. // StorehouseId: houseConfig.StorehouseOutInfo,
  5526. // OverCount: flush_count,
  5527. //}
  5528. //service.CreateStockFlowOne(flow)
  5529. //退库数量增加
  5530. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5531. //出库数量减少
  5532. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5533. //查询已出库数量
  5534. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5535. if prescribingNumber < dialysisInfo.Count {
  5536. //改变数量
  5537. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5538. }
  5539. if prescribingNumber >= dialysisInfo.Count {
  5540. //删除出库表
  5541. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5542. }
  5543. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5544. var flush_count_one int64
  5545. for _, it := range goodList {
  5546. flush_count_one += it.StockCount
  5547. }
  5548. //更新库存
  5549. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5550. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5551. //更新基础库库存
  5552. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5553. }
  5554. }
  5555. }
  5556. }
  5557. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5558. fmt.Println(err)
  5559. }
  5560. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5561. fmt.Println(err)
  5562. if len(advices) > 0 {
  5563. for _, item := range advices {
  5564. redis := service.RedisClient()
  5565. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5566. redis.Set(keyFive, "", time.Second)
  5567. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5568. redis.Set(keyOne, "", time.Second)
  5569. redis.Close()
  5570. }
  5571. }
  5572. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5573. if len(advices) > 0 {
  5574. for _, item := range advices {
  5575. creater := c.GetAdminUserInfo().AdminUser.Id
  5576. service.DrugAutoAddCancelInfo(item, creater)
  5577. }
  5578. }
  5579. } else {
  5580. if drugOutConfig.IsOpen == 1 {
  5581. if len(advices) > 0 {
  5582. for _, item := range advices {
  5583. creater := c.GetAdminUserInfo().AdminUser.Id
  5584. service.DrugAutoAddCancelInfo(item, creater)
  5585. }
  5586. }
  5587. } else {
  5588. if len(advices) > 0 {
  5589. for _, item := range advices {
  5590. creater := c.GetAdminUserInfo().AdminUser.Id
  5591. service.DrugAutoAddCancelInfo(item, creater)
  5592. }
  5593. }
  5594. }
  5595. }
  5596. c.ServeSuccessJSON(map[string]interface{}{
  5597. "msg": "删除成功",
  5598. })
  5599. return
  5600. }
  5601. func (c *HisApiController) DeleteDoctorAdvice() {
  5602. id, _ := c.GetInt64("id")
  5603. advice, _ := service.GetHisDoctorAdvicesById(id)
  5604. ////同步到自备药
  5605. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5606. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5607. if selfPrescriptionOpen.IsOpen == 1 {
  5608. db := service.XTWriteDB()
  5609. tx := db.Begin()
  5610. defer func() {
  5611. if r := recover(); r != nil {
  5612. tx.Rollback()
  5613. } else {
  5614. tx.Commit()
  5615. }
  5616. }()
  5617. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5618. var total_count int64
  5619. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5620. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5621. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5622. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5623. }
  5624. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5625. total_count += prescribingNumberSeven
  5626. }
  5627. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5628. total_count += prescribingNumberSeven
  5629. }
  5630. timeStr := time.Now().Format("2006-01-02")
  5631. timeArr := strings.Split(timeStr, "-")
  5632. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5633. total = total + 1
  5634. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5635. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5636. number = number + total
  5637. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5638. operation_time := time.Now().Unix()
  5639. creater := c.GetAdminUserInfo().AdminUser.Id
  5640. //创建一个出库单
  5641. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5642. WarehouseOutOrderNumber: warehousing_out_order,
  5643. OperationTime: operation_time,
  5644. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5645. Creater: creater,
  5646. Ctime: time.Now().Unix(),
  5647. Status: 1,
  5648. WarehouseOutTime: advice.AdviceDate,
  5649. Type: 0,
  5650. PatientId: advice.PatientId,
  5651. IsCheck: 1,
  5652. }
  5653. //查询今日是否有出库数据
  5654. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5655. if lastWarehouseOut.ID == 0 {
  5656. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5657. }
  5658. //出库
  5659. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5660. WarehouseOutId: lastWarehouseOut.ID,
  5661. WarehouseOutOrderNumber: warehousing_out_order,
  5662. DrugId: advice.DrugId,
  5663. Count: total_count,
  5664. Price: 0,
  5665. TotalPrice: 0,
  5666. Status: 1,
  5667. Ctime: advice.AdviceDate,
  5668. Mtime: advice.AdviceDate,
  5669. Remark: "",
  5670. OrgId: advice.UserOrgId,
  5671. Type: 0,
  5672. Manufacturer: selfBasedrug.Manufacturer,
  5673. Dealer: selfBasedrug.Dealer,
  5674. RetailPrice: 0,
  5675. RetailTotalPrice: 0,
  5676. CountUnit: advice.PrescribingNumberUnit,
  5677. ExpiryDate: 0,
  5678. ProductDate: 0,
  5679. Number: "",
  5680. BatchNumber: "",
  5681. IsSys: 0,
  5682. WarehouseInfoId: 0,
  5683. AdminUserId: 0,
  5684. StockCount: "",
  5685. IsCheck: 1,
  5686. SysRecordTime: advice.AdviceDate,
  5687. PatientId: advice.PatientId,
  5688. AdviceId: advice.ID,
  5689. ClassType: "",
  5690. }
  5691. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5692. for _, it := range warehousingOutInfo {
  5693. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5694. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5695. //出库逻辑
  5696. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5697. //查询剩余库存
  5698. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5699. var sum_count int64
  5700. for _, its := range stockInfo {
  5701. if its.MaxUnit == medical.MaxUnit {
  5702. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5703. }
  5704. sum_count += its.StockMaxNumber + its.StockMinNumber
  5705. }
  5706. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5707. }
  5708. }
  5709. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5710. //已收费和已发药的限制逻辑
  5711. isCharge := false
  5712. isMedicine := false
  5713. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5714. //获取今天该患者所有处方,判断是否发药或者收费
  5715. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5716. //for _, item := range new_prescriptions {
  5717. if new_prescription.IsMedicine == 1 {
  5718. isMedicine = true
  5719. }
  5720. //}
  5721. for _, item := range new_prescriptions {
  5722. if item.OrderStatus == 4 {
  5723. isCharge = true
  5724. }
  5725. }
  5726. if isMedicine {
  5727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5728. return
  5729. }
  5730. if isCharge {
  5731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5732. return
  5733. }
  5734. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5735. for _, item := range advices {
  5736. if item.IsMedicine == 1 {
  5737. isMedicine = true
  5738. }
  5739. }
  5740. if isMedicine {
  5741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5742. return
  5743. }
  5744. if new_prescription.ID > 0 {
  5745. if new_prescription.OrderStatus == 2 {
  5746. isCharge = true
  5747. }
  5748. }
  5749. if isCharge {
  5750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5751. return
  5752. }
  5753. //已收费和已发药的限制逻辑
  5754. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5755. redis := service.RedisClient()
  5756. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5757. redis.Set(keyFive, "", time.Second)
  5758. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5759. redis.Set(keyOne, "", time.Second)
  5760. defer redis.Close()
  5761. if err == nil {
  5762. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5763. //查询是否在处方中出库
  5764. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5765. if openConfig.IsOpen != 1 {
  5766. //判断该医嘱是否执行了
  5767. if advice.ExecutionState == 1 {
  5768. creater := c.GetAdminUserInfo().AdminUser.Id
  5769. service.DrugAutoAddCancelInfo(&advice, creater)
  5770. }
  5771. }
  5772. //开启保存处方扣减功能
  5773. if openConfig.IsOpen == 1 {
  5774. creater := c.GetAdminUserInfo().AdminUser.Id
  5775. service.DrugAutoAddCancelInfo(&advice, creater)
  5776. }
  5777. } else {
  5778. if drugOutConfig.IsOpen == 1 {
  5779. //查询是否在处方中出库
  5780. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5781. if openConfig.IsOpen != 1 {
  5782. //判断该医嘱是否执行了
  5783. if advice.ExecutionState == 1 {
  5784. creater := c.GetAdminUserInfo().AdminUser.Id
  5785. service.DrugAutoAddCancelInfo(&advice, creater)
  5786. }
  5787. }
  5788. //开启保存处方扣减功能
  5789. if openConfig.IsOpen == 1 {
  5790. creater := c.GetAdminUserInfo().AdminUser.Id
  5791. service.DrugAutoAddCancelInfo(&advice, creater)
  5792. }
  5793. } else {
  5794. //判断该医嘱是否执行了
  5795. if advice.ExecutionState == 1 {
  5796. creater := c.GetAdminUserInfo().AdminUser.Id
  5797. service.DrugAutoAddCancelInfo(&advice, creater)
  5798. }
  5799. }
  5800. }
  5801. c.ServeSuccessJSON(map[string]interface{}{
  5802. "msg": "删除成功",
  5803. })
  5804. return
  5805. } else {
  5806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5807. return
  5808. }
  5809. }
  5810. func (c *HisApiController) DeleteProject() {
  5811. id, _ := c.GetInt64("id")
  5812. adminInfo := c.GetAdminUserInfo()
  5813. project, _ := service.GetHisProjectByID(id)
  5814. // var consumable models.DialysisBeforePrepare
  5815. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5816. //耗材保存处方出库
  5817. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5818. isCharge := false
  5819. isMedicine := false
  5820. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5821. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5822. for _, item := range new_prescriptions {
  5823. if item.IsMedicine == 1 {
  5824. isMedicine = true
  5825. }
  5826. }
  5827. for _, item := range new_prescriptions {
  5828. if item.OrderStatus == 4 {
  5829. isCharge = true
  5830. }
  5831. }
  5832. if isMedicine {
  5833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5834. return
  5835. }
  5836. if isCharge {
  5837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5838. return
  5839. }
  5840. if new_prescription.ID > 0 {
  5841. if new_prescription.OrderStatus == 2 {
  5842. isCharge = true
  5843. }
  5844. }
  5845. if isCharge {
  5846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5847. return
  5848. }
  5849. service.DeletePrintInfo(id)
  5850. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5851. label.Status = 0
  5852. service.CreateHisLabelRecordTwo(&label)
  5853. fmt.Println(goodOutConfig.IsOpen)
  5854. if goodOutConfig.IsOpen != 1 {
  5855. if stockConfig.IsOpen == 1 {
  5856. if project.Type == 2 {
  5857. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5858. fmt.Println(err)
  5859. }
  5860. if project.Type == 3 && project.IsOut == 1 {
  5861. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5862. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5863. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5864. operation_time := time.Now().Unix()
  5865. creater := adminInfo.AdminUser.Id
  5866. //创建退库单
  5867. timeStr := time.Now().Format("2006-01-02")
  5868. timeArr := strings.Split(timeStr, "-")
  5869. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5870. total = total + 1
  5871. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5872. cancelStock := models.CancelStock{
  5873. OrderNumber: orderNumber,
  5874. OperaTime: operation_time,
  5875. OrgId: adminInfo.CurrentOrgId,
  5876. Creater: creater,
  5877. Ctime: time.Now().Unix(),
  5878. Status: 1,
  5879. ReturnTime: project.RecordDate,
  5880. Type: 1,
  5881. StorehouseId: houseConfig.StorehouseOutInfo,
  5882. IsCheck: 1,
  5883. }
  5884. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5885. if msgerrkonde == gorm.ErrRecordNotFound {
  5886. service.AddSigleCancelStock(&cancelStock)
  5887. }
  5888. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5889. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5890. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5891. //查询是否有出库
  5892. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5893. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5894. deaerler, _ := service.GetDealerById(info.Dealer)
  5895. if info.ID > 0 {
  5896. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5897. if info.Count >= prescribingNumber {
  5898. cancelStockInfo := models.CancelStockInfo{
  5899. GoodId: project.ProjectId,
  5900. CancelStockId: cancel.ID,
  5901. GoodTypeId: good.GoodTypeId,
  5902. Count: prescribingNumber,
  5903. Price: info.Price,
  5904. Total: 0,
  5905. ProductDate: info.ProductDate,
  5906. ExpiryDate: info.ExpiryDate,
  5907. Ctime: time.Now().Unix(),
  5908. Status: 1,
  5909. OrgId: adminInfo.CurrentOrgId,
  5910. OrderNumber: cancel.OrderNumber,
  5911. Type: 0,
  5912. Dealer: deaerler.DealerName,
  5913. Manufacturer: manufacturer.ManufacturerName,
  5914. Number: info.Number,
  5915. RegisterAccount: "",
  5916. Remark: "",
  5917. WarehouseInfoId: info.WarehouseInfotId,
  5918. PatientId: info.PatientId,
  5919. RecordDate: info.SysRecordTime,
  5920. StorehouseId: houseConfig.StorehouseOutInfo,
  5921. IsCheck: 1,
  5922. }
  5923. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5924. //回退库存
  5925. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5926. //退库数量增加
  5927. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5928. //出库数量减少
  5929. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5930. }
  5931. if info.Count < prescribingNumber {
  5932. cancelStockInfo := models.CancelStockInfo{
  5933. GoodId: project.ProjectId,
  5934. CancelStockId: cancel.ID,
  5935. GoodTypeId: good.GoodTypeId,
  5936. Count: info.Count,
  5937. Price: info.Price,
  5938. Total: 0,
  5939. ProductDate: info.ProductDate,
  5940. ExpiryDate: info.ExpiryDate,
  5941. Ctime: time.Now().Unix(),
  5942. Status: 1,
  5943. OrgId: adminInfo.CurrentOrgId,
  5944. OrderNumber: cancel.OrderNumber,
  5945. Type: 0,
  5946. Dealer: deaerler.DealerName,
  5947. Manufacturer: manufacturer.ManufacturerName,
  5948. Number: info.Number,
  5949. RegisterAccount: "",
  5950. Remark: "",
  5951. WarehouseInfoId: info.WarehouseInfotId,
  5952. PatientId: info.PatientId,
  5953. RecordDate: info.SysRecordTime,
  5954. StorehouseId: houseConfig.StorehouseOutInfo,
  5955. IsCheck: 1,
  5956. }
  5957. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5958. //回退库存
  5959. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5960. //退库数量增加
  5961. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5962. //出库数量减少
  5963. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5964. }
  5965. //查询剩余库存
  5966. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5967. var over_count int64
  5968. for _, it := range goodList {
  5969. over_count += it.StockCount
  5970. }
  5971. //出库数据 大于 退库数量
  5972. if info.Count >= prescribingNumber {
  5973. flow := models.VmStockFlow{
  5974. WarehousingId: info.WarehouseInfotId,
  5975. GoodId: project.ProjectId,
  5976. Number: info.Number,
  5977. LicenseNumber: info.LicenseNumber,
  5978. Count: prescribingNumber,
  5979. UserOrgId: adminInfo.CurrentOrgId,
  5980. PatientId: project.PatientId,
  5981. SystemTime: info.SysRecordTime,
  5982. ConsumableType: 7,
  5983. IsSys: 0,
  5984. WarehousingOrder: "",
  5985. WarehouseOutId: info.WarehouseOutId,
  5986. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5987. IsEdit: 0,
  5988. CancelStockId: cancel.ID,
  5989. CancelOrderNumber: cancel.OrderNumber,
  5990. Manufacturer: manufacturer.ID,
  5991. Dealer: 0,
  5992. Creator: adminInfo.AdminUser.Id,
  5993. UpdateCreator: 0,
  5994. Status: 1,
  5995. Ctime: time.Now().Unix(),
  5996. Mtime: 0,
  5997. Price: info.Price,
  5998. WarehousingDetailId: info.WarehouseInfotId,
  5999. WarehouseOutDetailId: info.ID,
  6000. CancelOutDetailId: cancelInfo.ID,
  6001. ProductDate: info.ProductDate,
  6002. ExpireDate: info.ExpiryDate,
  6003. StorehouseId: houseConfig.StorehouseOutInfo,
  6004. OverCount: over_count,
  6005. OperateTime: time.Now().Unix(),
  6006. }
  6007. service.CreateStockFlowOne(flow)
  6008. }
  6009. //出库数据小于退库数据
  6010. if info.Count < prescribingNumber {
  6011. flow := models.VmStockFlow{
  6012. WarehousingId: info.WarehouseInfotId,
  6013. GoodId: project.ProjectId,
  6014. Number: info.Number,
  6015. LicenseNumber: info.LicenseNumber,
  6016. Count: info.Count,
  6017. UserOrgId: adminInfo.CurrentOrgId,
  6018. PatientId: project.PatientId,
  6019. SystemTime: info.SysRecordTime,
  6020. ConsumableType: 7,
  6021. IsSys: 0,
  6022. WarehousingOrder: "",
  6023. WarehouseOutId: info.WarehouseOutId,
  6024. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6025. IsEdit: 0,
  6026. CancelStockId: cancel.ID,
  6027. CancelOrderNumber: cancel.OrderNumber,
  6028. Manufacturer: manufacturer.ID,
  6029. Dealer: 0,
  6030. Creator: adminInfo.AdminUser.Id,
  6031. UpdateCreator: 0,
  6032. Status: 1,
  6033. Ctime: time.Now().Unix(),
  6034. Mtime: 0,
  6035. Price: info.Price,
  6036. WarehousingDetailId: info.WarehouseInfotId,
  6037. WarehouseOutDetailId: info.ID,
  6038. CancelOutDetailId: cancelInfo.ID,
  6039. ProductDate: info.ProductDate,
  6040. ExpireDate: info.ExpiryDate,
  6041. StorehouseId: houseConfig.StorehouseOutInfo,
  6042. OverCount: over_count,
  6043. OperateTime: time.Now().Unix(),
  6044. }
  6045. service.CreateStockFlowOne(flow)
  6046. }
  6047. //查询已出库数量
  6048. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6049. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6050. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6051. if prescribingNumber < dialysisInfo.Count {
  6052. //改变数量
  6053. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6054. }
  6055. if prescribingNumber >= dialysisInfo.Count {
  6056. //删除出库表
  6057. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6058. }
  6059. //更新剩余库存
  6060. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6061. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6062. var total_count_one int64
  6063. for _, it := range stockList {
  6064. total_count_one += it.StockCount
  6065. }
  6066. //基础库插入数据
  6067. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6068. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6069. var flush_count int64
  6070. for _, it := range goodListOne {
  6071. flush_count += it.StockCount
  6072. }
  6073. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6074. if errs != nil {
  6075. goodErrcode := models.XtGoodErrcode{
  6076. UserOrgId: project.UserOrgId,
  6077. Errcode: "手动出库更新剩余出库失败",
  6078. GoodId: project.ProjectId,
  6079. Status: 1,
  6080. Ctime: time.Now().Unix(),
  6081. Mtime: 0,
  6082. Count: 0,
  6083. StockCount: 0,
  6084. Creater: creater,
  6085. BatchNumberId: 0,
  6086. WarehouseOutId: 0,
  6087. }
  6088. service.CreateGoodErrcode(goodErrcode)
  6089. }
  6090. }
  6091. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6092. fmt.Println(err)
  6093. } else {
  6094. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6095. fmt.Println(err)
  6096. }
  6097. } else {
  6098. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6099. fmt.Println(err)
  6100. }
  6101. }
  6102. //保存处方出库
  6103. if goodOutConfig.IsOpen == 1 {
  6104. if project.Type == 3 {
  6105. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6106. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6107. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6108. operation_time := time.Now().Unix()
  6109. creater := adminInfo.AdminUser.Id
  6110. //创建退库单
  6111. timeStr := time.Now().Format("2006-01-02")
  6112. timeArr := strings.Split(timeStr, "-")
  6113. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6114. total = total + 1
  6115. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6116. cancelStock := models.CancelStock{
  6117. OrderNumber: orderNumber,
  6118. OperaTime: operation_time,
  6119. OrgId: adminInfo.CurrentOrgId,
  6120. Creater: creater,
  6121. Ctime: time.Now().Unix(),
  6122. Status: 1,
  6123. ReturnTime: project.RecordDate,
  6124. Type: 1,
  6125. StorehouseId: houseConfig.StorehouseOutInfo,
  6126. IsCheck: 1,
  6127. }
  6128. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6129. if msgerrkonde == gorm.ErrRecordNotFound {
  6130. service.AddSigleCancelStock(&cancelStock)
  6131. }
  6132. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6133. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6134. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6135. //获取出库数据
  6136. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6137. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6138. deaerler, _ := service.GetDealerById(info.Dealer)
  6139. if info.ID > 0 {
  6140. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6141. if info.Count >= prescribingNumber {
  6142. cancelStockInfo := models.CancelStockInfo{
  6143. GoodId: project.ProjectId,
  6144. CancelStockId: cancel.ID,
  6145. GoodTypeId: good.GoodTypeId,
  6146. Count: prescribingNumber,
  6147. Price: info.Price,
  6148. Total: 0,
  6149. ProductDate: info.ProductDate,
  6150. ExpiryDate: info.ExpiryDate,
  6151. Ctime: time.Now().Unix(),
  6152. Status: 1,
  6153. OrgId: adminInfo.CurrentOrgId,
  6154. OrderNumber: cancel.OrderNumber,
  6155. Type: 0,
  6156. Dealer: deaerler.DealerName,
  6157. Manufacturer: manufacturer.ManufacturerName,
  6158. Number: info.Number,
  6159. RegisterAccount: "",
  6160. Remark: "",
  6161. WarehouseInfoId: info.WarehouseInfotId,
  6162. PatientId: info.PatientId,
  6163. RecordDate: info.SysRecordTime,
  6164. StorehouseId: houseConfig.StorehouseOutInfo,
  6165. IsCheck: 1,
  6166. }
  6167. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6168. //退库数量增加
  6169. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6170. //出库数量减少
  6171. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6172. }
  6173. if info.Count < prescribingNumber {
  6174. cancelStockInfo := models.CancelStockInfo{
  6175. GoodId: project.ProjectId,
  6176. CancelStockId: cancel.ID,
  6177. GoodTypeId: good.GoodTypeId,
  6178. Count: prescribingNumber,
  6179. Price: info.Price,
  6180. Total: 0,
  6181. ProductDate: info.ProductDate,
  6182. ExpiryDate: info.ExpiryDate,
  6183. Ctime: time.Now().Unix(),
  6184. Status: 1,
  6185. OrgId: adminInfo.CurrentOrgId,
  6186. OrderNumber: cancel.OrderNumber,
  6187. Type: 0,
  6188. Dealer: deaerler.DealerName,
  6189. Manufacturer: manufacturer.ManufacturerName,
  6190. Number: info.Number,
  6191. RegisterAccount: "",
  6192. Remark: "",
  6193. WarehouseInfoId: info.WarehouseInfotId,
  6194. PatientId: info.PatientId,
  6195. RecordDate: info.SysRecordTime,
  6196. StorehouseId: houseConfig.StorehouseOutInfo,
  6197. IsCheck: 1,
  6198. }
  6199. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6200. //回退库存
  6201. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6202. }
  6203. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6204. var over_count int64
  6205. for _, it := range goodList {
  6206. over_count += it.StockCount
  6207. }
  6208. //查询出库数量
  6209. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6210. //出库数据 大于 退库数量
  6211. if len(list) > 0 {
  6212. for _, it := range list {
  6213. //回退库存
  6214. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6215. //退库数量增加
  6216. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6217. //出库数量减少
  6218. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6219. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6220. var over_count_one int64
  6221. for _, it := range goodList {
  6222. over_count_one += it.StockCount
  6223. }
  6224. //查询该批次是否有退库数据
  6225. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6226. flow := models.VmStockFlow{
  6227. WarehousingId: it.WarehouseInfotId,
  6228. GoodId: it.GoodId,
  6229. Number: it.Number,
  6230. LicenseNumber: it.LicenseNumber,
  6231. Count: it.Count,
  6232. UserOrgId: adminInfo.CurrentOrgId,
  6233. PatientId: it.PatientId,
  6234. SystemTime: it.SysRecordTime,
  6235. ConsumableType: 7,
  6236. IsSys: 0,
  6237. WarehousingOrder: "",
  6238. WarehouseOutId: it.WarehouseOutId,
  6239. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6240. IsEdit: 0,
  6241. CancelStockId: cancel.ID,
  6242. CancelOrderNumber: cancel.OrderNumber,
  6243. Manufacturer: manufacturer.ID,
  6244. Dealer: 0,
  6245. Creator: adminInfo.AdminUser.Id,
  6246. UpdateCreator: 0,
  6247. Status: 1,
  6248. Ctime: time.Now().Unix(),
  6249. Mtime: 0,
  6250. Price: it.Price,
  6251. WarehousingDetailId: it.WarehouseInfotId,
  6252. WarehouseOutDetailId: it.ID,
  6253. CancelOutDetailId: cancelInfo.ID,
  6254. ProductDate: it.ProductDate,
  6255. ExpireDate: it.ExpiryDate,
  6256. StorehouseId: houseConfig.StorehouseOutInfo,
  6257. OverCount: over_count_one,
  6258. OperateTime: time.Now().Unix(),
  6259. }
  6260. service.CreateStockFlowOne(flow)
  6261. }
  6262. }
  6263. //查询已出库数量
  6264. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6265. if prescribingNumber < dialysisInfo.Count {
  6266. //改变数量
  6267. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6268. }
  6269. if prescribingNumber >= dialysisInfo.Count {
  6270. //删除出库表
  6271. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6272. }
  6273. //更新剩余库存
  6274. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6275. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6276. var total_count_one int64
  6277. for _, it := range stockList {
  6278. total_count_one += it.StockCount
  6279. }
  6280. //基础库插入数据
  6281. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6282. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6283. var flush_count int64
  6284. for _, it := range goodListOne {
  6285. flush_count += it.StockCount
  6286. }
  6287. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6288. if errs != nil {
  6289. goodErrcode := models.XtGoodErrcode{
  6290. UserOrgId: project.UserOrgId,
  6291. Errcode: "手动出库更新剩余出库失败",
  6292. GoodId: project.ProjectId,
  6293. Status: 1,
  6294. Ctime: time.Now().Unix(),
  6295. Mtime: 0,
  6296. Count: 0,
  6297. StockCount: 0,
  6298. Creater: creater,
  6299. BatchNumberId: 0,
  6300. WarehouseOutId: 0,
  6301. }
  6302. service.CreateGoodErrcode(goodErrcode)
  6303. }
  6304. }
  6305. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6306. fmt.Println(err)
  6307. } else {
  6308. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6309. fmt.Println(err)
  6310. }
  6311. }
  6312. c.ServeSuccessJSON(map[string]interface{}{
  6313. "msg": "删除成功",
  6314. })
  6315. return
  6316. }
  6317. func (c *HisApiController) CreateHisAdditionalCharge() {
  6318. his_patient_id, _ := c.GetInt64("his_patient_id")
  6319. patient_id, _ := c.GetInt64("patient_id")
  6320. record_date := c.GetString("record_date")
  6321. timeLayout := "2006-01-02"
  6322. loc, _ := time.LoadLocation("Local")
  6323. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6324. if err != nil {
  6325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6326. return
  6327. }
  6328. adminInfo := c.GetAdminUserInfo()
  6329. recordDateTime := theTime.Unix()
  6330. dataBody := make(map[string]interface{}, 0)
  6331. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6332. if err != nil {
  6333. utils.ErrorLog(err.Error())
  6334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6335. return
  6336. }
  6337. var additions []*models.HisAdditionalCharge
  6338. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6339. additions, _ := dataBody["addition"].([]interface{})
  6340. if len(additions) > 0 {
  6341. for _, item := range additions {
  6342. items := item.(map[string]interface{})
  6343. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6344. utils.ErrorLog("item_id")
  6345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6346. return
  6347. }
  6348. item_id := int64(items["item_id"].(float64))
  6349. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6350. utils.ErrorLog("item_name")
  6351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6352. return
  6353. }
  6354. item_name := items["item_name"].(string)
  6355. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6356. utils.ErrorLog("price")
  6357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6358. return
  6359. }
  6360. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6361. ctime := time.Now().Unix()
  6362. additional := &models.HisAdditionalCharge{
  6363. PatientId: patient_id,
  6364. HisPatientId: his_patient_id,
  6365. UserOrgId: adminInfo.CurrentOrgId,
  6366. RecordDate: recordDateTime,
  6367. CreatedTime: ctime,
  6368. UpdatedTime: ctime,
  6369. Modifier: adminInfo.AdminUser.Id,
  6370. Creator: adminInfo.AdminUser.Id,
  6371. Price: price,
  6372. ItemName: item_name,
  6373. ItemId: item_id,
  6374. Status: 1,
  6375. }
  6376. additions = append(additions, additional)
  6377. }
  6378. }
  6379. }
  6380. for _, item := range additions {
  6381. service.CreateAddtionalCharge(item)
  6382. }
  6383. c.ServeSuccessJSON(map[string]interface{}{
  6384. "msg": "创建成功",
  6385. })
  6386. }
  6387. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6388. blood_fat := c.GetString("blood_fat")
  6389. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6390. blood_sugar := c.GetString("blood_sugar")
  6391. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6392. chief_conplaint := c.GetString("chief_conplaint")
  6393. dbp := c.GetString("dbp")
  6394. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6395. delivery_way, _ := c.GetInt64("delivery_way")
  6396. diagnostic := c.GetString("diagnostic")
  6397. family_history := c.GetString("family_history")
  6398. height := c.GetString("height")
  6399. history_of_present_illness := c.GetString("history_of_present_illness")
  6400. is_infect, _ := c.GetInt64("is_infect")
  6401. past_history := c.GetString("past_history")
  6402. patient_id, _ := c.GetInt64("patient_id")
  6403. his_patient_id, _ := c.GetInt64("his_patient_id")
  6404. personal_history := c.GetString("personal_history")
  6405. pulse := c.GetString("pulse")
  6406. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6407. sbp := c.GetString("sbp")
  6408. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6409. heightfloat, _ := strconv.ParseFloat(height, 64)
  6410. sicktype := c.GetString("sick_type")
  6411. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6412. symptom := c.GetString("symptom")
  6413. sick_date := c.GetString("sick_date")
  6414. temperatures := c.GetString("temperature")
  6415. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6416. record_date := c.GetString("record_date")
  6417. breathing := c.GetString("breathing")
  6418. doctor_advice := c.GetString("doctor_advice")
  6419. remark := c.GetString("remark")
  6420. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6421. sick, _ := c.GetInt64("sick")
  6422. diagnose, _ := c.GetInt64("diagnose")
  6423. //id, _ := c.GetInt64("id")
  6424. timeLayout := "2006-01-02"
  6425. loc, _ := time.LoadLocation("Local")
  6426. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6427. allergic_history := c.GetString("allergic_history")
  6428. if err != nil {
  6429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6430. return
  6431. }
  6432. recordDateTime := theTime.Unix()
  6433. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6434. if err != nil {
  6435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6436. return
  6437. }
  6438. sickTimes := sickTime.Unix()
  6439. ctime := time.Now().Unix()
  6440. primary_disease := c.GetString("primary_disease")
  6441. confirm_failure_date := c.GetString("confirm_failure_date")
  6442. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6443. drug_allergy_history := c.GetString("drug_allergy_history")
  6444. physical_examination := c.GetString("physical_examination")
  6445. special_inspection := c.GetString("special_inspection")
  6446. lab_apparatus := c.GetString("lab_apparatus")
  6447. caseHistory := models.HisPatientCaseHistory{
  6448. HisPatientId: his_patient_id,
  6449. PatientId: patient_id,
  6450. Temperature: temperature,
  6451. BloodSugar: bloodsugarfloat,
  6452. Pulse: pulsefloat,
  6453. Sbp: sbpfloat,
  6454. Dbp: dbpfloat,
  6455. Height: heightfloat,
  6456. BloodFat: bloodfatfloat,
  6457. SickType: sick_type,
  6458. Symptom: symptom,
  6459. SickDate: sickTimes,
  6460. IsInfect: is_infect,
  6461. HistoryOfPresentIllness: history_of_present_illness,
  6462. PastHistory: past_history,
  6463. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6464. ChiefConplaint: chief_conplaint,
  6465. PersonalHistory: personal_history,
  6466. FamilyHistory: family_history,
  6467. Diagnostic: diagnostic,
  6468. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6469. Status: 1,
  6470. Ctime: ctime,
  6471. Mtime: ctime,
  6472. RecordDate: recordDateTime,
  6473. DeliveryWay: delivery_way,
  6474. Breathing: breathingfloat,
  6475. DoctorAdvice: doctor_advice,
  6476. Remark: remark,
  6477. Sick: sick,
  6478. Diagnose: diagnose,
  6479. AllergicHistory: allergic_history,
  6480. PrimaryDisease: primary_disease,
  6481. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6482. DrugAllergyHistory: drug_allergy_history,
  6483. PhysicalExamination: physical_examination,
  6484. SpecialInspection: special_inspection,
  6485. LabApparatus: lab_apparatus,
  6486. }
  6487. //查询该患者是否有病历
  6488. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6489. if errcodes == gorm.ErrRecordNotFound {
  6490. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6491. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6492. if err != nil {
  6493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6494. return
  6495. }
  6496. c.ServeSuccessJSON(map[string]interface{}{
  6497. "caseHistory": caseHistory,
  6498. "historyInfo": historyInfo,
  6499. })
  6500. return
  6501. } else if errcodes == nil {
  6502. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6503. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6504. if err != nil {
  6505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6506. return
  6507. }
  6508. c.ServeSuccessJSON(map[string]interface{}{
  6509. "caseHistory": caseHistory,
  6510. "historyInfo": historyInfo,
  6511. })
  6512. }
  6513. //查询该患者是否有病历
  6514. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6515. //if errcode == gorm.ErrRecordNotFound {
  6516. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6517. // if err != nil {
  6518. // c.ServeSuccessJSON(map[string]interface{}{
  6519. // "msg": "保存成功",
  6520. // })
  6521. // }
  6522. //} else if errcode == nil {
  6523. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6524. // return
  6525. //}
  6526. }
  6527. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6528. patient_id, _ := c.GetInt64("patient_id", 0)
  6529. adminUser := c.GetAdminUserInfo()
  6530. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6531. c.ServeSuccessJSON(map[string]interface{}{
  6532. "list": caseHistorys,
  6533. })
  6534. }
  6535. func (c *HisApiController) GetHisPatientCaseHistory() {
  6536. record_date, _ := c.GetInt64("record_date", 0)
  6537. patient_id, _ := c.GetInt64("patient_id", 0)
  6538. admin := c.GetAdminUserInfo()
  6539. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6540. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6541. c.ServeSuccessJSON(map[string]interface{}{
  6542. "info": info,
  6543. "case_history": case_history,
  6544. })
  6545. }
  6546. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6547. template_name := c.GetString("template_name")
  6548. template_remark := c.GetString("template_remark")
  6549. doctor := c.GetAdminUserInfo().AdminUser.Id
  6550. diagnostic := c.GetString("diagnostic")
  6551. chief_conplaint := c.GetString("chief_conplain")
  6552. history_of_present_illness := c.GetString("history_of_present_illness")
  6553. past_history := c.GetString("past_history")
  6554. personal_history := c.GetString("personal_history")
  6555. family_history := c.GetString("family_history")
  6556. user_name := c.GetString("user_name")
  6557. doctor_advice := c.GetString("doctor_advice")
  6558. remark := c.GetString("remark")
  6559. //record_date := c.GetString("record_date")
  6560. //fmt.Println("record_date--------",record_date)
  6561. //timeLayout := "2006-01-02"
  6562. //loc, _ := time.LoadLocation("Local")
  6563. //
  6564. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6565. //if err != nil {
  6566. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6567. // return
  6568. //}
  6569. //recordDateTime := theTime.Unix()
  6570. ctime := time.Now().Unix()
  6571. template := models.HisCaseHistoryTemplate{
  6572. HistoryOfPresentIllness: history_of_present_illness,
  6573. PastHistory: past_history,
  6574. ChiefConplaint: chief_conplaint,
  6575. PersonalHistory: personal_history,
  6576. FamilyHistory: family_history,
  6577. Diagnostic: diagnostic,
  6578. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6579. Status: 1,
  6580. Ctime: ctime,
  6581. Mtime: ctime,
  6582. RecordDate: time.Now().Unix(),
  6583. TemplateName: template_name,
  6584. TemplateRemark: template_remark,
  6585. Creator: doctor,
  6586. Modifier: doctor,
  6587. UserName: user_name,
  6588. DoctorAdvice: doctor_advice,
  6589. Remark: remark,
  6590. }
  6591. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6592. if err == nil {
  6593. c.ServeSuccessJSON(map[string]interface{}{
  6594. "msg": "保存成功",
  6595. })
  6596. } else {
  6597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6598. return
  6599. }
  6600. }
  6601. func (c *HisApiController) GetCaseHistoryTemplate() {
  6602. timeLayout := "2006-01-02"
  6603. loc, _ := time.LoadLocation("Local")
  6604. keyword := c.GetString("keyword")
  6605. start_time := c.GetString("start_time")
  6606. end_time := c.GetString("end_time")
  6607. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6608. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6609. admin := c.GetAdminUserInfo()
  6610. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6611. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6612. c.ServeSuccessJSON(map[string]interface{}{
  6613. "template": template,
  6614. //"history": history,
  6615. })
  6616. }
  6617. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6618. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6619. utils.ErrorLog("drug_name")
  6620. return enums.ErrorCodeParamWrong
  6621. }
  6622. adviceName, _ := json["drug_name"].(string)
  6623. if len(adviceName) == 0 {
  6624. utils.ErrorLog("len(advice_name) == 0")
  6625. return enums.ErrorCodeParamWrong
  6626. }
  6627. advice.AdviceName = adviceName
  6628. adviceDesc, _ := json["advice_desc"].(string)
  6629. advice.AdviceDesc = adviceDesc
  6630. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6631. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6632. advice.DrugSpec = drugSpec
  6633. }
  6634. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6635. remark, _ := json["remark"].(string)
  6636. advice.Remark = remark
  6637. }
  6638. if json["id"] == nil {
  6639. advice.DrugId = 0
  6640. } else {
  6641. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6642. drug_id := int64(json["id"].(float64))
  6643. advice.DrugId = drug_id
  6644. }
  6645. }
  6646. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6647. advice_id := int64(json["advice_id"].(float64))
  6648. advice.ID = advice_id
  6649. if advice.ID > 0 {
  6650. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6651. if err == nil {
  6652. if hisAdvice.ID > 0 {
  6653. advice.ExecutionTime = hisAdvice.ExecutionTime
  6654. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6655. advice.ExecutionState = hisAdvice.ExecutionState
  6656. advice.CheckTime = hisAdvice.CheckTime
  6657. advice.Checker = hisAdvice.Checker
  6658. advice.CheckState = hisAdvice.CheckState
  6659. advice.StartTime = hisAdvice.StartTime
  6660. advice.FeedetlSn = hisAdvice.FeedetlSn
  6661. }
  6662. }
  6663. }
  6664. }
  6665. //
  6666. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6667. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6668. // advice.ExecutionTime = execution_time
  6669. //}
  6670. //
  6671. //
  6672. //
  6673. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6674. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6675. // advice.ExecutionStaff = execution_staff
  6676. //}
  6677. //
  6678. //
  6679. //
  6680. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6681. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6682. // advice.ExecutionState = execution_state
  6683. //}
  6684. //
  6685. //
  6686. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6687. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6688. // advice.CheckTime = check_time
  6689. //}
  6690. //
  6691. //
  6692. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6693. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6694. // advice.CheckState = check_state
  6695. //}
  6696. //
  6697. //
  6698. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6699. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6700. // advice.Checker = checker
  6701. //}
  6702. //
  6703. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6704. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6705. // advice.StartTime = start_time
  6706. //}
  6707. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6708. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6709. advice.IsSelfDrug = is_self_drug
  6710. }
  6711. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6712. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6713. drug_way_count, _ := json["drug_way_count"].(string)
  6714. advice.DrugWayCount = drug_way_count
  6715. }
  6716. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6717. drugSpecUnit, _ := json["min_unit"].(string)
  6718. advice.DrugSpecUnit = drugSpecUnit
  6719. }
  6720. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6721. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6722. advice.SingleDose = singleDose
  6723. }
  6724. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6725. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6726. advice.SingleDoseUnit = singleDoseUnit
  6727. }
  6728. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6729. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6730. advice.PrescribingNumber = prescribingNumber
  6731. }
  6732. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6733. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6734. advice.PrescribingNumberUnit = prescribingNumberUnit
  6735. }
  6736. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6737. deliveryWay, _ := json["delivery_way"].(string)
  6738. advice.DeliveryWay = deliveryWay
  6739. }
  6740. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6741. executionFrequency, _ := json["execution_frequency"].(string)
  6742. advice.ExecutionFrequency = executionFrequency
  6743. }
  6744. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6745. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6746. advice.Price = price
  6747. }
  6748. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6749. med_list_codg, _ := json["medical_insurance_number"].(string)
  6750. advice.MedListCodg = med_list_codg
  6751. }
  6752. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6753. day := int64(json["day"].(float64))
  6754. advice.Day = day
  6755. }
  6756. return 0
  6757. }
  6758. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6759. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6760. id := int64(json["id"].(float64))
  6761. project.ID = id
  6762. historyProject, _ := service.GetHisProjectByID(id)
  6763. project.FeedetlSn = historyProject.FeedetlSn
  6764. }
  6765. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6766. project_id := int64(json["project_id"].(float64))
  6767. project.ProjectId = project_id
  6768. }
  6769. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6770. // price := int64(json["price"].(float64))
  6771. // formatInt_price := strconv.FormatInt(price, 10)
  6772. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6773. // project.Price = float_price
  6774. // }
  6775. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6776. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6777. project.Price = price
  6778. }
  6779. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6780. total, _ := json["total"].(string)
  6781. project.Count = total
  6782. }
  6783. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6784. medical_code, _ := json["medical_code"].(string)
  6785. project.MedListCodg = medical_code
  6786. }
  6787. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6788. single_dose, _ := json["single_dose"].(string)
  6789. project.SingleDose = single_dose
  6790. }
  6791. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6792. delivery_way, _ := json["delivery_way"].(string)
  6793. project.DeliveryWay = delivery_way
  6794. }
  6795. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6796. execution_frequency, _ := json["execution_frequency"].(string)
  6797. project.ExecutionFrequency = execution_frequency
  6798. }
  6799. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6800. remark, _ := json["remark"].(string)
  6801. project.Remark = remark
  6802. }
  6803. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6804. day, _ := json["number_days"].(string)
  6805. project.Day = day
  6806. }
  6807. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6808. unit, _ := json["unit"].(string)
  6809. project.Unit = unit
  6810. }
  6811. return 0
  6812. }
  6813. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6814. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6815. id := int64(json["id"].(float64))
  6816. historyAddtions, _ := service.GetHisAdditionByID(id)
  6817. additionalCharge.ID = id
  6818. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6819. }
  6820. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6821. item_id := int64(json["item_id"].(float64))
  6822. additionalCharge.ItemId = item_id
  6823. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6824. if config.ID > 0 {
  6825. if len(config.Code) > 0 {
  6826. additionalCharge.MedListCodg = config.Code
  6827. }
  6828. }
  6829. }
  6830. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6831. // price := int64(json["price"].(float64))
  6832. // formatInt_price := strconv.FormatInt(price, 10)
  6833. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6834. // additionalCharge.Price = float_price
  6835. // }
  6836. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6837. // price := int64(json["price"].(float64))
  6838. // formatInt_price := strconv.FormatInt(price, 10)
  6839. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6840. // additionalCharge.Price = float_price
  6841. //}
  6842. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6843. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6844. additionalCharge.Price = price
  6845. }
  6846. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6847. count, _ := json["count"].(string)
  6848. counts, _ := strconv.ParseInt(count, 10, 64)
  6849. additionalCharge.Count = counts
  6850. }
  6851. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6852. item_name, _ := json["item_name"].(string)
  6853. additionalCharge.ItemName = item_name
  6854. }
  6855. return 0
  6856. }
  6857. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6858. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6859. utils.ErrorLog("drug_name")
  6860. return enums.ErrorCodeParamWrong
  6861. }
  6862. adviceName, _ := json["drug_name"].(string)
  6863. if len(adviceName) == 0 {
  6864. utils.ErrorLog("len(advice_name) == 0")
  6865. return enums.ErrorCodeParamWrong
  6866. }
  6867. advice.AdviceName = adviceName
  6868. adviceDesc, _ := json["advice_desc"].(string)
  6869. advice.AdviceDesc = adviceDesc
  6870. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6871. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6872. advice.DrugSpec = drugSpec
  6873. }
  6874. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6875. remark, _ := json["remark"].(string)
  6876. advice.Remark = remark
  6877. }
  6878. if json["id"] == nil {
  6879. advice.DrugId = 0
  6880. } else {
  6881. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6882. drug_id := int64(json["id"].(float64))
  6883. advice.DrugId = drug_id
  6884. }
  6885. }
  6886. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6887. groupno := int64(json["groupno"].(float64))
  6888. advice.Groupno = groupno
  6889. }
  6890. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6891. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6892. advice.IsSelfDrug = is_self_drug
  6893. }
  6894. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6895. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6896. drug_way_count, _ := json["drug_way_count"].(string)
  6897. advice.DrugWayCount = drug_way_count
  6898. }
  6899. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6900. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6901. advice.HospApprFlag = hosp_appr_flag
  6902. }
  6903. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6904. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6905. advice.PrescribingNumber = prescribingNumber
  6906. }
  6907. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6908. // frequency_type := int64(json["frequency_type"].(float64))
  6909. // advice.FrequencyType = frequency_type
  6910. //}
  6911. //
  6912. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6913. // day_count := int64(json["day_count"].(float64))
  6914. // advice.DayCount = day_count
  6915. //}
  6916. //
  6917. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6918. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6919. // week_day, _ := json["week_day"].(string)
  6920. // advice.WeekDay = week_day
  6921. //}
  6922. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6923. drugSpecUnit, _ := json["min_unit"].(string)
  6924. advice.DrugSpecUnit = drugSpecUnit
  6925. }
  6926. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6927. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6928. advice.SingleDose = singleDose
  6929. }
  6930. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6931. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6932. advice.SingleDoseUnit = singleDoseUnit
  6933. }
  6934. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6935. deliveryWay, _ := json["delivery_way"].(string)
  6936. advice.DeliveryWay = deliveryWay
  6937. }
  6938. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6939. executionFrequency, _ := json["execution_frequency"].(string)
  6940. advice.ExecutionFrequency = executionFrequency
  6941. }
  6942. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6943. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6944. advice.Price = price
  6945. }
  6946. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6947. med_list_codg, _ := json["medical_insurance_number"].(string)
  6948. advice.MedListCodg = med_list_codg
  6949. }
  6950. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6951. day := int64(json["day"].(float64))
  6952. advice.Day = day
  6953. }
  6954. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6955. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6956. advice.PrescribingNumberUnit = prescribingNumberUnit
  6957. }
  6958. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6959. advice_id := int64(json["advice_id"].(float64))
  6960. advice.ID = advice_id
  6961. if advice.ID > 0 {
  6962. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6963. if err == nil {
  6964. if hisAdvice.ID > 0 {
  6965. advice.ExecutionTime = hisAdvice.ExecutionTime
  6966. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6967. advice.ExecutionState = hisAdvice.ExecutionState
  6968. advice.CheckTime = hisAdvice.CheckTime
  6969. advice.Checker = hisAdvice.Checker
  6970. advice.CheckState = hisAdvice.CheckState
  6971. advice.StartTime = hisAdvice.StartTime
  6972. advice.HospApprFlag = hisAdvice.HospApprFlag
  6973. advice.IsMedicine = hisAdvice.IsMedicine
  6974. if hisAdvice.UserOrgId == 10028 {
  6975. 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 {
  6976. advice.ExecutionTime = 0
  6977. advice.ExecutionStaff = 0
  6978. advice.ExecutionState = 2
  6979. advice.CheckTime = 0
  6980. advice.Checker = 0
  6981. advice.CheckState = 2
  6982. }
  6983. } else {
  6984. 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 {
  6985. advice.ExecutionTime = 0
  6986. advice.ExecutionStaff = 0
  6987. advice.ExecutionState = 2
  6988. advice.CheckTime = 0
  6989. advice.Checker = 0
  6990. advice.CheckState = 2
  6991. advice.UpdatedTime = time.Now().Unix()
  6992. }
  6993. }
  6994. //advice.Groupno = hisAdvice.Groupno
  6995. }
  6996. }
  6997. }
  6998. }
  6999. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7000. //
  7001. //if drugStockConfig.IsOpen == 1 {
  7002. //
  7003. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7004. // if advice.ID == 0 { //医嘱不存在
  7005. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7006. // drug.Total = drug.Total - advice.PrescribingNumber
  7007. // service.UpdateBaseDrugLib(&drug)
  7008. //
  7009. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7010. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7011. // drug.Total = drug.Total - num
  7012. // service.UpdateBaseDrugLib(&drug)
  7013. // }
  7014. //
  7015. // } else if advice.ID > 0 { //医嘱存在
  7016. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7017. // var num float64
  7018. //
  7019. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7020. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7021. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7022. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7023. // drug.Total = drug.Total + num
  7024. // service.UpdateBaseDrugLib(&drug)
  7025. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7026. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7027. // drug.Total = drug.Total - num
  7028. // service.UpdateBaseDrugLib(&drug)
  7029. // }
  7030. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7031. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7032. // if num2 > advice.PrescribingNumber {
  7033. // num = num2 - advice.PrescribingNumber
  7034. // drug.Total = drug.Total + num
  7035. // service.UpdateBaseDrugLib(&drug)
  7036. // } else if num2 < advice.PrescribingNumber {
  7037. // num = advice.PrescribingNumber - num2
  7038. // drug.Total = drug.Total - num
  7039. // service.UpdateBaseDrugLib(&drug)
  7040. // }
  7041. //
  7042. // }
  7043. //
  7044. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7045. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7046. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7047. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7048. // if num1 > num2 {
  7049. // num = num1 - num2
  7050. // drug.Total = drug.Total + num
  7051. // service.UpdateBaseDrugLib(&drug)
  7052. // } else if num1 < num2 {
  7053. // num = num2 - num1
  7054. // drug.Total = drug.Total - num
  7055. // service.UpdateBaseDrugLib(&drug)
  7056. // }
  7057. //
  7058. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7059. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7060. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7061. // if hisAdvice.PrescribingNumber > num2 {
  7062. // num = hisAdvice.PrescribingNumber - num2
  7063. // drug.Total = drug.Total + num
  7064. // service.UpdateBaseDrugLib(&drug)
  7065. // } else if num2 < advice.PrescribingNumber {
  7066. // num = num2 - hisAdvice.PrescribingNumber
  7067. // drug.Total = drug.Total - num
  7068. // service.UpdateBaseDrugLib(&drug)
  7069. // }
  7070. //
  7071. // }
  7072. // }
  7073. // }
  7074. //}
  7075. //
  7076. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7077. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7078. // advice.ExecutionTime = execution_time
  7079. //}
  7080. //
  7081. //
  7082. //
  7083. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7084. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7085. // advice.ExecutionStaff = execution_staff
  7086. //}
  7087. //
  7088. //
  7089. //
  7090. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7091. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7092. // advice.ExecutionState = execution_state
  7093. //}
  7094. //
  7095. //
  7096. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7097. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7098. // advice.CheckTime = check_time
  7099. //}
  7100. //
  7101. //
  7102. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7103. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7104. // advice.CheckState = check_state
  7105. //}
  7106. //
  7107. //
  7108. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7109. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7110. // advice.Checker = checker
  7111. //}
  7112. //
  7113. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7114. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7115. // advice.StartTime = start_time
  7116. //}
  7117. return 0
  7118. }
  7119. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7120. project.ExecutionStaff = 0
  7121. project.ExecutionState = 2
  7122. project.ExecutionTime = 0
  7123. project.Checker = 0
  7124. project.CheckState = 2
  7125. project.CheckTime = 0
  7126. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7127. id := int64(json["id"].(float64))
  7128. project.ID = id
  7129. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7130. project.ExecutionStaff = temp_project.ExecutionStaff
  7131. project.ExecutionState = temp_project.ExecutionState
  7132. project.ExecutionTime = temp_project.ExecutionTime
  7133. project.Checker = temp_project.Checker
  7134. project.CheckState = temp_project.CheckState
  7135. project.CheckTime = temp_project.CheckTime
  7136. project.TeamId = temp_project.TeamId
  7137. }
  7138. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7139. types := int64(json["type"].(float64))
  7140. project.Type = types
  7141. }
  7142. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7143. project_id := int64(json["project_id"].(float64))
  7144. project.ProjectId = project_id
  7145. }
  7146. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7147. team_id := int64(json["team_id"].(float64))
  7148. project.TeamId = team_id
  7149. }
  7150. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7151. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7152. project.Price = price
  7153. }
  7154. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7155. total, _ := json["total"].(string)
  7156. //totals, _ := strconv.ParseInt(total, 10, 64)
  7157. project.Count = total
  7158. }
  7159. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7160. medical_code, _ := json["medical_code"].(string)
  7161. project.MedListCodg = medical_code
  7162. }
  7163. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7164. single_dose, _ := json["single_dose"].(string)
  7165. project.SingleDose = single_dose
  7166. }
  7167. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7168. delivery_way, _ := json["delivery_way"].(string)
  7169. project.DeliveryWay = delivery_way
  7170. }
  7171. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7172. execution_frequency, _ := json["execution_frequency"].(string)
  7173. project.ExecutionFrequency = execution_frequency
  7174. }
  7175. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7176. remark, _ := json["remark"].(string)
  7177. project.Remark = remark
  7178. }
  7179. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7180. day, _ := json["number_days"].(string)
  7181. project.Day = day
  7182. }
  7183. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7184. unit, _ := json["unit"].(string)
  7185. project.Unit = unit
  7186. }
  7187. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7188. // frequency_type := int64(json["frequency_type"].(float64))
  7189. // project.FrequencyType = frequency_type
  7190. //}
  7191. //
  7192. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7193. // day_count := int64(json["day_count"].(float64))
  7194. // project.DayCount = day_count
  7195. //}
  7196. //
  7197. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7198. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7199. // week_day, _ := json["week_day"].(string)
  7200. // project.WeekDay = week_day
  7201. //}
  7202. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7203. //
  7204. //if project.ID == 0 {
  7205. // if stockConfig.IsOpen == 1 {
  7206. // if project.Type == 3 {
  7207. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7208. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7209. // good.Total = good.Total - f_count
  7210. // service.UpdateGoodInfo(&good)
  7211. // }
  7212. // }
  7213. //
  7214. //} else {
  7215. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7216. //
  7217. // if stockConfig.IsOpen == 1 {
  7218. // if project.Type == 3 {
  7219. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7220. // if project.Count < temp_project.Count {
  7221. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7222. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7223. //
  7224. // other_count := f_count_two - f_count_one
  7225. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7226. // good.Total = good.Total + other_count_two
  7227. // service.UpdateGoodInfo(&good)
  7228. // } else if project.Count > temp_project.Count {
  7229. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7230. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7231. //
  7232. // other_count := f_count_one - f_count_two
  7233. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7234. // good.Total = good.Total - other_count_two
  7235. // service.UpdateGoodInfo(&good)
  7236. // }
  7237. //
  7238. // }
  7239. // }
  7240. //
  7241. //}
  7242. return 0
  7243. }
  7244. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7245. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7246. utils.ErrorLog("drug_name")
  7247. return enums.ErrorCodeParamWrong
  7248. }
  7249. adviceName, _ := json["drug_name"].(string)
  7250. if len(adviceName) == 0 {
  7251. utils.ErrorLog("len(advice_name) == 0")
  7252. return enums.ErrorCodeParamWrong
  7253. }
  7254. advice.AdviceName = adviceName
  7255. adviceDesc, _ := json["advice_desc"].(string)
  7256. advice.AdviceDesc = adviceDesc
  7257. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7258. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7259. advice.DrugSpec = drugSpec
  7260. }
  7261. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7262. remark, _ := json["remark"].(string)
  7263. advice.Remark = remark
  7264. }
  7265. if json["id"] == nil {
  7266. advice.DrugId = 0
  7267. } else {
  7268. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7269. drug_id := int64(json["id"].(float64))
  7270. advice.DrugId = drug_id
  7271. }
  7272. }
  7273. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7274. groupno := int64(json["groupno"].(float64))
  7275. advice.Groupno = groupno
  7276. }
  7277. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7278. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7279. advice.IsSelfDrug = is_self_drug
  7280. }
  7281. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7282. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7283. drug_way_count, _ := json["drug_way_count"].(string)
  7284. advice.DrugWayCount = drug_way_count
  7285. }
  7286. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7287. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7288. advice.HospApprFlag = hosp_appr_flag
  7289. }
  7290. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7291. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7292. advice.PrescribingNumber = prescribingNumber
  7293. }
  7294. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7295. // frequency_type := int64(json["frequency_type"].(float64))
  7296. // advice.FrequencyType = frequency_type
  7297. //}
  7298. //
  7299. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7300. // day_count := int64(json["day_count"].(float64))
  7301. // advice.DayCount = day_count
  7302. //}
  7303. //
  7304. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7305. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7306. // week_day, _ := json["week_day"].(string)
  7307. // advice.WeekDay = week_day
  7308. //}
  7309. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7310. drugSpecUnit, _ := json["min_unit"].(string)
  7311. advice.DrugSpecUnit = drugSpecUnit
  7312. }
  7313. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7314. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7315. advice.SingleDose = singleDose
  7316. }
  7317. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7318. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7319. advice.SingleDoseUnit = singleDoseUnit
  7320. }
  7321. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7322. deliveryWay, _ := json["delivery_way"].(string)
  7323. advice.DeliveryWay = deliveryWay
  7324. }
  7325. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7326. executionFrequency, _ := json["execution_frequency"].(string)
  7327. advice.ExecutionFrequency = executionFrequency
  7328. }
  7329. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7330. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7331. advice.Price = price
  7332. }
  7333. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7334. med_list_codg, _ := json["medical_insurance_number"].(string)
  7335. advice.MedListCodg = med_list_codg
  7336. }
  7337. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7338. day := int64(json["day"].(float64))
  7339. advice.Day = day
  7340. }
  7341. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7342. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7343. advice.PrescribingNumberUnit = prescribingNumberUnit
  7344. }
  7345. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7346. advice_id := int64(json["advice_id"].(float64))
  7347. advice.ID = advice_id
  7348. if advice.ID > 0 {
  7349. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7350. if err == nil {
  7351. if hisAdvice.ID > 0 {
  7352. advice.ExecutionTime = hisAdvice.ExecutionTime
  7353. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7354. advice.ExecutionState = hisAdvice.ExecutionState
  7355. advice.CheckTime = hisAdvice.CheckTime
  7356. advice.Checker = hisAdvice.Checker
  7357. advice.CheckState = hisAdvice.CheckState
  7358. advice.StartTime = hisAdvice.StartTime
  7359. advice.HospApprFlag = hisAdvice.HospApprFlag
  7360. advice.IsMedicine = hisAdvice.IsMedicine
  7361. if hisAdvice.UserOrgId == 10028 {
  7362. 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 {
  7363. advice.ExecutionTime = 0
  7364. advice.ExecutionStaff = 0
  7365. advice.ExecutionState = 2
  7366. advice.CheckTime = 0
  7367. advice.Checker = 0
  7368. advice.CheckState = 2
  7369. }
  7370. } else {
  7371. 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 {
  7372. advice.ExecutionTime = 0
  7373. advice.ExecutionStaff = 0
  7374. advice.ExecutionState = 2
  7375. advice.CheckTime = 0
  7376. advice.Checker = 0
  7377. advice.CheckState = 2
  7378. //advice.UpdatedTime = time.Now().Unix()
  7379. advice.CreatedTime = hisAdvice.CreatedTime
  7380. advice.UpdatedTime = time.Now().Unix()
  7381. } else {
  7382. advice.CreatedTime = hisAdvice.CreatedTime
  7383. advice.UpdatedTime = hisAdvice.UpdatedTime
  7384. }
  7385. }
  7386. //advice.Groupno = hisAdvice.Groupno
  7387. } else {
  7388. advice.IsMedicine = 0
  7389. ctime := time.Now().Unix()
  7390. advice.CreatedTime = ctime
  7391. advice.UpdatedTime = ctime
  7392. }
  7393. }
  7394. } else {
  7395. advice.IsMedicine = 0
  7396. ctime := time.Now().Unix()
  7397. advice.CreatedTime = ctime
  7398. advice.UpdatedTime = ctime
  7399. }
  7400. }
  7401. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7402. //
  7403. //if drugStockConfig.IsOpen == 1 {
  7404. //
  7405. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7406. // if advice.ID == 0 { //医嘱不存在
  7407. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7408. // drug.Total = drug.Total - advice.PrescribingNumber
  7409. // service.UpdateBaseDrugLib(&drug)
  7410. //
  7411. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7412. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7413. // drug.Total = drug.Total - num
  7414. // service.UpdateBaseDrugLib(&drug)
  7415. // }
  7416. //
  7417. // } else if advice.ID > 0 { //医嘱存在
  7418. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7419. // var num float64
  7420. //
  7421. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7422. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7423. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7424. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7425. // drug.Total = drug.Total + num
  7426. // service.UpdateBaseDrugLib(&drug)
  7427. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7428. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7429. // drug.Total = drug.Total - num
  7430. // service.UpdateBaseDrugLib(&drug)
  7431. // }
  7432. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7433. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7434. // if num2 > advice.PrescribingNumber {
  7435. // num = num2 - advice.PrescribingNumber
  7436. // drug.Total = drug.Total + num
  7437. // service.UpdateBaseDrugLib(&drug)
  7438. // } else if num2 < advice.PrescribingNumber {
  7439. // num = advice.PrescribingNumber - num2
  7440. // drug.Total = drug.Total - num
  7441. // service.UpdateBaseDrugLib(&drug)
  7442. // }
  7443. //
  7444. // }
  7445. //
  7446. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7447. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7448. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7449. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7450. // if num1 > num2 {
  7451. // num = num1 - num2
  7452. // drug.Total = drug.Total + num
  7453. // service.UpdateBaseDrugLib(&drug)
  7454. // } else if num1 < num2 {
  7455. // num = num2 - num1
  7456. // drug.Total = drug.Total - num
  7457. // service.UpdateBaseDrugLib(&drug)
  7458. // }
  7459. //
  7460. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7461. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7462. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7463. // if hisAdvice.PrescribingNumber > num2 {
  7464. // num = hisAdvice.PrescribingNumber - num2
  7465. // drug.Total = drug.Total + num
  7466. // service.UpdateBaseDrugLib(&drug)
  7467. // } else if num2 < advice.PrescribingNumber {
  7468. // num = num2 - hisAdvice.PrescribingNumber
  7469. // drug.Total = drug.Total - num
  7470. // service.UpdateBaseDrugLib(&drug)
  7471. // }
  7472. //
  7473. // }
  7474. // }
  7475. // }
  7476. //}
  7477. //
  7478. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7479. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7480. // advice.ExecutionTime = execution_time
  7481. //}
  7482. //
  7483. //
  7484. //
  7485. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7486. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7487. // advice.ExecutionStaff = execution_staff
  7488. //}
  7489. //
  7490. //
  7491. //
  7492. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7493. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7494. // advice.ExecutionState = execution_state
  7495. //}
  7496. //
  7497. //
  7498. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7499. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7500. // advice.CheckTime = check_time
  7501. //}
  7502. //
  7503. //
  7504. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7505. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7506. // advice.CheckState = check_state
  7507. //}
  7508. //
  7509. //
  7510. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7511. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7512. // advice.Checker = checker
  7513. //}
  7514. //
  7515. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7516. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7517. // advice.StartTime = start_time
  7518. //}
  7519. return 0
  7520. }
  7521. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7522. project.ExecutionStaff = 0
  7523. project.ExecutionState = 2
  7524. project.ExecutionTime = 0
  7525. project.Checker = 0
  7526. project.CheckState = 2
  7527. project.CheckTime = 0
  7528. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7529. id := int64(json["id"].(float64))
  7530. project.ID = id
  7531. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7532. project.ExecutionStaff = temp_project.ExecutionStaff
  7533. project.ExecutionState = temp_project.ExecutionState
  7534. project.ExecutionTime = temp_project.ExecutionTime
  7535. project.Checker = temp_project.Checker
  7536. project.CheckState = temp_project.CheckState
  7537. project.CheckTime = temp_project.CheckTime
  7538. project.TeamId = temp_project.TeamId
  7539. }
  7540. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7541. types := int64(json["type"].(float64))
  7542. project.Type = types
  7543. }
  7544. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7545. project_id := int64(json["project_id"].(float64))
  7546. project.ProjectId = project_id
  7547. }
  7548. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7549. team_id := int64(json["team_id"].(float64))
  7550. project.TeamId = team_id
  7551. }
  7552. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7553. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7554. project.Price = price
  7555. }
  7556. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7557. total, _ := json["total"].(string)
  7558. //totals, _ := strconv.ParseInt(total, 10, 64)
  7559. project.Count = total
  7560. }
  7561. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7562. medical_code, _ := json["medical_code"].(string)
  7563. project.MedListCodg = medical_code
  7564. }
  7565. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7566. single_dose, _ := json["single_dose"].(string)
  7567. project.SingleDose = single_dose
  7568. }
  7569. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7570. delivery_way, _ := json["delivery_way"].(string)
  7571. project.DeliveryWay = delivery_way
  7572. }
  7573. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7574. execution_frequency, _ := json["execution_frequency"].(string)
  7575. project.ExecutionFrequency = execution_frequency
  7576. }
  7577. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7578. remark, _ := json["remark"].(string)
  7579. project.Remark = remark
  7580. }
  7581. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7582. day, _ := json["number_days"].(string)
  7583. project.Day = day
  7584. }
  7585. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7586. unit, _ := json["unit"].(string)
  7587. project.Unit = unit
  7588. }
  7589. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7590. // frequency_type := int64(json["frequency_type"].(float64))
  7591. // project.FrequencyType = frequency_type
  7592. //}
  7593. //
  7594. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7595. // day_count := int64(json["day_count"].(float64))
  7596. // project.DayCount = day_count
  7597. //}
  7598. //
  7599. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7600. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7601. // week_day, _ := json["week_day"].(string)
  7602. // project.WeekDay = week_day
  7603. //}
  7604. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7605. //
  7606. //if project.ID == 0 {
  7607. // if stockConfig.IsOpen == 1 {
  7608. // if project.Type == 3 {
  7609. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7610. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7611. // good.Total = good.Total - f_count
  7612. // service.UpdateGoodInfo(&good)
  7613. // }
  7614. // }
  7615. //
  7616. //} else {
  7617. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7618. //
  7619. // if stockConfig.IsOpen == 1 {
  7620. // if project.Type == 3 {
  7621. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7622. // if project.Count < temp_project.Count {
  7623. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7624. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7625. //
  7626. // other_count := f_count_two - f_count_one
  7627. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7628. // good.Total = good.Total + other_count_two
  7629. // service.UpdateGoodInfo(&good)
  7630. // } else if project.Count > temp_project.Count {
  7631. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7632. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7633. //
  7634. // other_count := f_count_one - f_count_two
  7635. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7636. // good.Total = good.Total - other_count_two
  7637. // service.UpdateGoodInfo(&good)
  7638. // }
  7639. //
  7640. // }
  7641. // }
  7642. //
  7643. //}
  7644. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7645. id := int64(json["id"].(float64))
  7646. if id > 0 {
  7647. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7648. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7649. fmt.Println("666666")
  7650. project.Mtime = time.Now().Unix()
  7651. project.Ctime = temp_project.Ctime
  7652. } else {
  7653. project.Mtime = temp_project.Mtime
  7654. project.Ctime = temp_project.Ctime
  7655. }
  7656. } else {
  7657. ctime := time.Now().Unix()
  7658. project.Mtime = ctime
  7659. project.Ctime = ctime
  7660. }
  7661. }
  7662. return 0
  7663. }
  7664. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7665. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7666. id := int64(json["id"].(float64))
  7667. additionalCharge.ID = id
  7668. }
  7669. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7670. item_id := int64(json["item_id"].(float64))
  7671. additionalCharge.ItemId = item_id
  7672. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7673. if config.ID > 0 {
  7674. if len(config.Code) > 0 {
  7675. additionalCharge.MedListCodg = config.Code
  7676. }
  7677. }
  7678. }
  7679. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7680. // price := int64(json["price"].(float64))
  7681. // formatInt_price := strconv.FormatInt(price, 10)
  7682. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7683. // additionalCharge.Price = float_price
  7684. // }
  7685. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7686. // price := int64(json["price"].(float64))
  7687. // formatInt_price := strconv.FormatInt(price, 10)
  7688. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7689. // additionalCharge.Price = float_price
  7690. //}
  7691. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7692. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7693. additionalCharge.Price = price
  7694. }
  7695. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7696. count, _ := json["count"].(string)
  7697. counts, _ := strconv.ParseInt(count, 10, 64)
  7698. additionalCharge.Count = counts
  7699. }
  7700. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7701. item_name, _ := json["item_name"].(string)
  7702. additionalCharge.ItemName = item_name
  7703. }
  7704. return 0
  7705. }
  7706. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7707. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7708. utils.ErrorLog("drug_name")
  7709. return enums.ErrorCodeParamWrong
  7710. }
  7711. adviceName, _ := json["drug_name"].(string)
  7712. if len(adviceName) == 0 {
  7713. utils.ErrorLog("len(advice_name) == 0")
  7714. return enums.ErrorCodeParamWrong
  7715. }
  7716. advice.AdviceName = adviceName
  7717. adviceDesc, _ := json["advice_desc"].(string)
  7718. advice.AdviceDesc = adviceDesc
  7719. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7720. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7721. advice.DrugSpec = drugSpec
  7722. }
  7723. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7724. remark, _ := json["remark"].(string)
  7725. advice.Remark = remark
  7726. }
  7727. if json["id"] == nil {
  7728. advice.DrugId = 0
  7729. } else {
  7730. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7731. drug_id := int64(json["id"].(float64))
  7732. advice.DrugId = drug_id
  7733. }
  7734. }
  7735. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7736. groupno := int64(json["groupno"].(float64))
  7737. advice.Groupno = groupno
  7738. }
  7739. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7740. drugSpecUnit, _ := json["min_unit"].(string)
  7741. advice.DrugSpecUnit = drugSpecUnit
  7742. }
  7743. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7744. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7745. advice.SingleDose = singleDose
  7746. }
  7747. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7748. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7749. advice.SingleDoseUnit = singleDoseUnit
  7750. }
  7751. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7752. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7753. advice.PrescribingNumber = prescribingNumber
  7754. }
  7755. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7756. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7757. advice.PrescribingNumberUnit = prescribingNumberUnit
  7758. }
  7759. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7760. deliveryWay, _ := json["delivery_way"].(string)
  7761. advice.DeliveryWay = deliveryWay
  7762. }
  7763. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7764. executionFrequency, _ := json["execution_frequency"].(string)
  7765. advice.ExecutionFrequency = executionFrequency
  7766. }
  7767. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7768. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7769. advice.Price = price
  7770. }
  7771. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7772. med_list_codg, _ := json["medical_insurance_number"].(string)
  7773. advice.MedListCodg = med_list_codg
  7774. }
  7775. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7776. day := int64(json["day"].(float64))
  7777. advice.Day = day
  7778. }
  7779. advice.FrequencyType = 1
  7780. return 0
  7781. }
  7782. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7783. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7784. types := int64(json["type"].(float64))
  7785. project.Type = types
  7786. }
  7787. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7788. project_id := int64(json["project_id"].(float64))
  7789. project.ProjectId = project_id
  7790. }
  7791. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7792. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7793. project.Price = price
  7794. }
  7795. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7796. total, _ := json["total"].(string)
  7797. //totals, _ := strconv.ParseInt(total, 10, 64)
  7798. project.Count = total
  7799. }
  7800. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7801. medical_code, _ := json["medical_code"].(string)
  7802. project.MedListCodg = medical_code
  7803. }
  7804. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7805. single_dose, _ := json["single_dose"].(string)
  7806. project.SingleDose = single_dose
  7807. }
  7808. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7809. delivery_way, _ := json["delivery_way"].(string)
  7810. project.DeliveryWay = delivery_way
  7811. }
  7812. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7813. execution_frequency, _ := json["execution_frequency"].(string)
  7814. project.ExecutionFrequency = execution_frequency
  7815. }
  7816. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7817. remark, _ := json["remark"].(string)
  7818. project.Remark = remark
  7819. }
  7820. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7821. day, _ := json["number_days"].(string)
  7822. project.Day = day
  7823. }
  7824. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7825. unit, _ := json["unit"].(string)
  7826. project.Unit = unit
  7827. }
  7828. project.FrequencyType = 1
  7829. return 0
  7830. }
  7831. func (c *HisApiController) GetHisOrderListTwo() {
  7832. start_time := c.GetString("start_time")
  7833. end_time := c.GetString("end_time")
  7834. timeLayout := "2006-01-02"
  7835. loc, _ := time.LoadLocation("Local")
  7836. var startTime int64
  7837. if len(start_time) > 0 {
  7838. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7839. if err != nil {
  7840. //fmt.Println(err)
  7841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7842. return
  7843. }
  7844. startTime = theTime.Unix()
  7845. }
  7846. var endTime int64
  7847. if len(end_time) > 0 {
  7848. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7849. if err != nil {
  7850. utils.ErrorLog(err.Error())
  7851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7852. return
  7853. }
  7854. endTime = theTime.Unix()
  7855. }
  7856. adminUser := c.GetAdminUserInfo()
  7857. org_id := adminUser.CurrentOrgId
  7858. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7859. if err == nil {
  7860. c.ServeSuccessJSON(map[string]interface{}{
  7861. "order2": order,
  7862. })
  7863. } else {
  7864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7865. return
  7866. }
  7867. }
  7868. func (c *HisApiController) GetHisOrderList() {
  7869. page, _ := c.GetInt64("page", -1)
  7870. limit, _ := c.GetInt64("limit", -1)
  7871. start_time := c.GetString("start_time")
  7872. end_time := c.GetString("end_time")
  7873. types, _ := c.GetInt64("type", 0)
  7874. keywords := c.GetString("keywords")
  7875. p_type, _ := c.GetInt64("p_type", 0)
  7876. sort_type, _ := c.GetInt64("sort_type", 0)
  7877. charge_type, _ := c.GetInt64("charge_type", 0)
  7878. sch_type, _ := c.GetInt64("sch_type", 0)
  7879. zone_type, _ := c.GetInt64("zone_type", 0)
  7880. med_type, _ := c.GetInt64("med_type", 0)
  7881. timeLayout := "2006-01-02"
  7882. loc, _ := time.LoadLocation("Local")
  7883. var startTime int64
  7884. if len(start_time) > 0 {
  7885. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7886. if err != nil {
  7887. //fmt.Println(err)
  7888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7889. return
  7890. }
  7891. startTime = theTime.Unix()
  7892. }
  7893. var endTime int64
  7894. if len(end_time) > 0 {
  7895. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7896. if err != nil {
  7897. utils.ErrorLog(err.Error())
  7898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7899. return
  7900. }
  7901. endTime = theTime.Unix()
  7902. }
  7903. adminUser := c.GetAdminUserInfo()
  7904. org_id := adminUser.CurrentOrgId
  7905. 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)
  7906. for _, item := range order {
  7907. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7908. item.DoctorName = info.Doctor
  7909. item.DepartmentName = info.XtHisDepartment.Name
  7910. }
  7911. if err == nil {
  7912. c.ServeSuccessJSON(map[string]interface{}{
  7913. "order": order,
  7914. "total": total,
  7915. })
  7916. } else {
  7917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7918. return
  7919. }
  7920. }
  7921. func (c *HisApiController) GetHisOrder() {
  7922. patient_id, _ := c.GetInt64("patient_id", 0)
  7923. number := c.GetString("number")
  7924. adminInfo := c.GetAdminUserInfo()
  7925. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7926. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7927. if err == nil {
  7928. c.ServeSuccessJSON(map[string]interface{}{
  7929. "order": order,
  7930. "prescription": prescriptions,
  7931. })
  7932. } else {
  7933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7934. return
  7935. }
  7936. }
  7937. func (c *HisApiController) GetHisPrescriptionList() {
  7938. record_date := c.GetString("record_date")
  7939. keywords := c.GetString("keywords")
  7940. page, _ := c.GetInt64("page")
  7941. limit, _ := c.GetInt64("limit")
  7942. sch_type, _ := c.GetInt64("sch_type")
  7943. timeLayout := "2006-01-02"
  7944. loc, _ := time.LoadLocation("Local")
  7945. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7946. if err != nil {
  7947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7948. return
  7949. }
  7950. recordDateTime := theTime.Unix()
  7951. adminInfo := c.GetAdminUserInfo()
  7952. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7953. //adminInfo := c.GetAdminUserInfo()
  7954. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7955. //fmt.Println(prescriptionOrder)
  7956. if err == nil {
  7957. c.ServeSuccessJSON(map[string]interface{}{
  7958. "order": prescriptionOrder,
  7959. "total": total,
  7960. })
  7961. } else {
  7962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7963. return
  7964. }
  7965. }
  7966. func (c *HisApiController) GetHisPrescriptionInfo() {
  7967. id, _ := c.GetInt64("id")
  7968. adminInfo := c.GetAdminUserInfo()
  7969. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7970. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7971. if err == nil {
  7972. c.ServeSuccessJSON(map[string]interface{}{
  7973. "order": prescriptionOrder,
  7974. "prescription": prescription,
  7975. })
  7976. } else {
  7977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7978. return
  7979. }
  7980. }
  7981. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7982. adminUser := c.GetAdminUserInfo()
  7983. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7984. c.ServeSuccessJSON(map[string]interface{}{
  7985. "config": config,
  7986. })
  7987. }
  7988. type ResultTwo struct {
  7989. ErrMsg interface{} `json:"err_msg"`
  7990. InfRefmsgid string `json:"inf_refmsgid"`
  7991. Infcode int64 `json:"infcode"`
  7992. Output struct {
  7993. Baseinfo struct {
  7994. Age float64 `json:"age"`
  7995. Brdy string `json:"brdy"`
  7996. Certno string `json:"certno"`
  7997. Gend string `json:"gend"`
  7998. Naty string `json:"naty"`
  7999. PsnCertType string `json:"psn_cert_type"`
  8000. PsnName string `json:"psn_name"`
  8001. PsnNo string `json:"psn_no"`
  8002. } `json:"baseinfo"`
  8003. Idetinfo []interface{} `json:"idetinfo"`
  8004. Iinfo []struct {
  8005. Balc float64 `json:"balc"`
  8006. CvlservFlag string `json:"cvlserv_flag"`
  8007. EmpName string `json:"emp_name"`
  8008. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8009. Insutype string `json:"insutype"`
  8010. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8011. PausInsuDate interface{} `json:"paus_insu_date"`
  8012. PsnInsuDate string `json:"psn_insu_date"`
  8013. PsnInsuStas string `json:"psn_insu_stas"`
  8014. PsnType string `json:"psn_type"`
  8015. } `json:"insuinfo"`
  8016. } `json:"output"`
  8017. RefmsgTime string `json:"refmsg_time"`
  8018. RespondTime string `json:"respond_time"`
  8019. Signtype interface{} `json:"signtype"`
  8020. WarnInfo interface{} `json:"warn_info"`
  8021. }
  8022. type ResultThree struct {
  8023. Cainfo interface{} `json:"cainfo"`
  8024. ErrMsg interface{} `json:"err_msg"`
  8025. InfRefmsgid string `json:"inf_refmsgid"`
  8026. Infcode int64 `json:"infcode"`
  8027. Output struct {
  8028. Data struct {
  8029. IptOtpNo string `json:"ipt_otp_no"`
  8030. MdtrtID string `json:"mdtrt_id"`
  8031. PsnNo string `json:"psn_no"`
  8032. } `json:"data"`
  8033. } `json:"output"`
  8034. RefmsgTime string `json:"refmsg_time"`
  8035. RespondTime string `json:"respond_time"`
  8036. Signtype interface{} `json:"signtype"`
  8037. WarnMsg interface{} `json:"warn_msg"`
  8038. }
  8039. type ResultFour struct {
  8040. Cainfo string `json:"cainfo"`
  8041. ErrMsg string `json:"err_msg"`
  8042. InfRefmsgid string `json:"inf_refmsgid"`
  8043. Infcode int64 `json:"infcode"`
  8044. Output struct {
  8045. Result []struct {
  8046. BasMednFlag string `json:"bas_medn_flag"`
  8047. ChldMedcFlag string `json:"chld_medc_flag"`
  8048. ChrgitmLv string `json:"chrgitm_lv"`
  8049. Cnt float64 `json:"cnt"`
  8050. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8051. DrtReimFlag string `json:"drt_reim_flag"`
  8052. FeedetlSn string `json:"feedetl_sn"`
  8053. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8054. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8055. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8056. ListSpItemFlag string `json:"list_sp_item_flag"`
  8057. LmtUsedFlag string `json:"lmt_used_flag"`
  8058. MedChrgitmType string `json:"med_chrgitm_type"`
  8059. Memo string `json:"memo"`
  8060. OverlmtAmt float64 `json:"overlmt_amt"`
  8061. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8062. Pric float64 `json:"pric"`
  8063. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8064. SelfpayProp float64 `json:"selfpay_prop"`
  8065. } `json:"result"`
  8066. } `json:"output"`
  8067. RefmsgTime string `json:"refmsg_time"`
  8068. RespondTime string `json:"respond_time"`
  8069. Signtype string `json:"signtype"`
  8070. WarnMsg string `json:"warn_msg"`
  8071. }
  8072. type ResultFive struct {
  8073. Insutype string `json:"insutype"`
  8074. }
  8075. type ResultSix struct {
  8076. Cainfo interface{} `json:"cainfo"`
  8077. ErrMsg interface{} `json:"err_msg"`
  8078. InfRefmsgid string `json:"inf_refmsgid"`
  8079. Infcode int64 `json:"infcode"`
  8080. Output struct {
  8081. } `json:"output"`
  8082. RefmsgTime string `json:"refmsg_time"`
  8083. RespondTime string `json:"respond_time"`
  8084. Signtype interface{} `json:"signtype"`
  8085. WarnMsg interface{} `json:"warn_msg"`
  8086. }
  8087. type ResultSeven struct {
  8088. Cainfo string `json:"cainfo"`
  8089. ErrMsg string `json:"err_msg"`
  8090. InfRefmsgid string `json:"inf_refmsgid"`
  8091. Infcode int64 `json:"infcode"`
  8092. Output struct {
  8093. Setldetail []interface{} `json:"setldetail"`
  8094. Setlinfo struct {
  8095. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8096. AcctPay float64 `json:"acct_pay"`
  8097. ActPayDedc float64 `json:"act_pay_dedc"`
  8098. Age float64 `json:"age"`
  8099. Balc float64 `json:"balc"`
  8100. Brdy string `json:"brdy"`
  8101. Certno string `json:"certno"`
  8102. ClrOptins string `json:"clr_optins"`
  8103. ClrType string `json:"clr_type"`
  8104. ClrWay string `json:"clr_way"`
  8105. CvlservFlag string `json:"cvlserv_flag"`
  8106. CvlservPay float64 `json:"cvlserv_pay"`
  8107. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8108. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8109. Gend string `json:"gend"`
  8110. HifesPay float64 `json:"hifes_pay"`
  8111. HifmiPay float64 `json:"hifmi_pay"`
  8112. HifobPay float64 `json:"hifob_pay"`
  8113. HifpPay float64 `json:"hifp_pay"`
  8114. HospPartAmt float64 `json:"hosp_part_amt"`
  8115. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8116. Insutype string `json:"insutype"`
  8117. MafPay float64 `json:"maf_pay"`
  8118. MdtrtCertType string `json:"mdtrt_cert_type"`
  8119. MdtrtID string `json:"mdtrt_id"`
  8120. MedType string `json:"med_type"`
  8121. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8122. MedinsSetlID string `json:"medins_setl_id"`
  8123. Naty string `json:"naty"`
  8124. OthPay float64 `json:"oth_pay"`
  8125. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8126. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8127. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8128. PsnCashPay float64 `json:"psn_cash_pay"`
  8129. PsnCertType string `json:"psn_cert_type"`
  8130. PsnName string `json:"psn_name"`
  8131. PsnNo string `json:"psn_no"`
  8132. PsnPartAmt float64 `json:"psn_part_amt"`
  8133. PsnType string `json:"psn_type"`
  8134. SetlID string `json:"setl_id"`
  8135. SetlTime string `json:"setl_time"`
  8136. } `json:"setlinfo"`
  8137. } `json:"output"`
  8138. RefmsgTime string `json:"refmsg_time"`
  8139. RespondTime string `json:"respond_time"`
  8140. Signtype interface{} `json:"signtype"`
  8141. WarnMsg interface{} `json:"warn_msg"`
  8142. }
  8143. type ResultEight struct {
  8144. Cainfo string `json:"cainfo"`
  8145. ErrMsg string `json:"err_msg"`
  8146. InfRefmsgid string `json:"inf_refmsgid"`
  8147. Infcode int64 `json:"infcode"`
  8148. Output struct {
  8149. Stmtinfo struct {
  8150. SetlOptins string `json:"setl_optins"`
  8151. StmtRslt string `json:"stmt_rslt"`
  8152. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8153. } `json:"stmtinfo"`
  8154. } `json:"output"`
  8155. RefmsgTime string `json:"refmsg_time"`
  8156. RespondTime string `json:"respond_time"`
  8157. Signtype interface{} `json:"signtype"`
  8158. WarnMsg interface{} `json:"warn_msg"`
  8159. }
  8160. type ResultNine struct {
  8161. Cainfo string `json:"cainfo"`
  8162. ErrMsg string `json:"err_msg"`
  8163. InfRefmsgid string `json:"inf_refmsgid"`
  8164. Infcode int64 `json:"infcode"`
  8165. Output struct {
  8166. FileQuryNo string `json:"file_qury_no"`
  8167. } `json:"output"`
  8168. RefmsgTime string `json:"refmsg_time"`
  8169. RespondTime string `json:"respond_time"`
  8170. Signtype interface{} `json:"signtype"`
  8171. WarnMsg interface{} `json:"warn_msg"`
  8172. }
  8173. type ResultTen struct {
  8174. Cainfo string `json:"cainfo"`
  8175. ErrMsg string `json:"err_msg"`
  8176. InfRefmsgid string `json:"inf_refmsgid"`
  8177. Infcode int64 `json:"infcode"`
  8178. Output struct {
  8179. DldEndtime string `json:"dld_endtime"`
  8180. FileQuryNo string `json:"file_qury_no"`
  8181. Filename string `json:"filename"`
  8182. } `json:"output"`
  8183. RefmsgTime string `json:"refmsg_time"`
  8184. RespondTime string `json:"respond_time"`
  8185. Signtype interface{} `json:"signtype"`
  8186. WarnMsg interface{} `json:"warn_msg"`
  8187. }
  8188. type ResultEleven struct {
  8189. Cainfo string `json:"cainfo"`
  8190. ErrMsg string `json:"err_msg"`
  8191. InfRefmsgid string `json:"inf_refmsgid"`
  8192. Infcode int64 `json:"infcode"`
  8193. Output struct {
  8194. Setlinfo struct {
  8195. FixmedinsName string `json:"fixmedins_name"`
  8196. FixmedinsCode string `json:"fixmedins_code"`
  8197. PsnNo string `json:"psn_no"`
  8198. PsnName string `json:"psn_name"`
  8199. HifobPay float64 `json:"hifob_pay"`
  8200. Gend string `json:"gend"`
  8201. Brdy string `json:"brdy"`
  8202. PsnCertType string `json:"psn_cert_type"`
  8203. PsnType string `json:"psn_type"`
  8204. EmpName string `json:"emp_name"`
  8205. Certno string `json:"certno"`
  8206. Insutype string `json:"insutype"`
  8207. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8208. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8209. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8210. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8211. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8212. ActPayDedc float64 `json:"act_pay_dedc"`
  8213. HifpPay float64 `json:"hifp_pay"`
  8214. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8215. CvlservPay float64 `json:"cvlserv_pay"`
  8216. HifesPay float64 `json:"hifes_pay"`
  8217. HifmiPay float64 `json:"hifmi_pay"`
  8218. MafPay float64 `json:"maf_pay"`
  8219. OthPay float64 `json:"oth_pay"`
  8220. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8221. PsnPay float64 `json:"psn_pay"`
  8222. AcctPay float64 `json:"acct_pay"`
  8223. CashPayamt float64 `json:"cash_payamt"`
  8224. Balc float64 `json:"balc"`
  8225. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8226. MedinsSetlId string `json:"medins_setl_id"`
  8227. RefdSetlFlag string `json:"refd_setl_flag"`
  8228. SetlTime string `json:"setl_time"`
  8229. MedType string `json:"med_type"`
  8230. } `json:"setlinfo"`
  8231. } `json:"output"`
  8232. RefmsgTime string `json:"refmsg_time"`
  8233. RespondTime string `json:"respond_time"`
  8234. Signtype interface{} `json:"signtype"`
  8235. WarnMsg interface{} `json:"warn_msg"`
  8236. }
  8237. type Custom struct {
  8238. DetItemFeeSumamt string
  8239. Cut string
  8240. FeedetlSn string
  8241. Price string
  8242. MedListCodg string
  8243. Type int64
  8244. AdviceId int64
  8245. ProjectId int64
  8246. ItemId int64
  8247. }
  8248. // 获取个人信息----挂号-----上传就诊信息
  8249. func (c *HisApiController) GetRegisterInfo() {
  8250. id, _ := c.GetInt64("id")
  8251. record_time := c.GetString("record_time")
  8252. settlementValue, _ := c.GetInt64("settlement_value")
  8253. medical_insurance_card := c.GetString("medical_insurance_card")
  8254. name := c.GetString("name")
  8255. id_card_type, _ := c.GetInt64("id_card_type")
  8256. certificates, _ := c.GetInt64("certificates")
  8257. medical_care, _ := c.GetInt64("medical_care")
  8258. birthday := c.GetString("birthday")
  8259. age, _ := c.GetInt64("age")
  8260. id_card := c.GetString("id_card")
  8261. register_type, _ := c.GetInt64("register")
  8262. doctor, _ := c.GetInt64("doctor")
  8263. department, _ := c.GetInt64("department")
  8264. gender, _ := c.GetInt64("sex")
  8265. phone := c.GetString("phone")
  8266. registration_fee, _ := c.GetFloat("registration_fee")
  8267. medical_expenses, _ := c.GetFloat("medical_expenses")
  8268. social_type, _ := c.GetInt64("social_type")
  8269. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8270. diagnosis_ids := c.GetString("diagnosis")
  8271. sick_type, _ := c.GetInt64("sick_type")
  8272. reg_type := c.GetString("p_type")
  8273. timeLayout := "2006-01-02"
  8274. loc, _ := time.LoadLocation("Local")
  8275. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8276. birthUnix := birthdays.Unix()
  8277. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8278. if err != nil {
  8279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8280. return
  8281. }
  8282. recordDateTime := theTime.Unix()
  8283. adminInfo := c.GetAdminUserInfo()
  8284. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8285. if tempPatient.ID == 0 {
  8286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8287. return
  8288. }
  8289. var patient service.Patients
  8290. if id == 0 {
  8291. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8292. } else {
  8293. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8294. }
  8295. if patient.ID == 0 {
  8296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8297. return
  8298. }
  8299. if len(patient.IdCardNo) == 0 {
  8300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8301. return
  8302. }
  8303. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8304. if len(his) >= 1 {
  8305. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8306. if len(his) >= 1 && order.ID == 0 {
  8307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8308. return
  8309. }
  8310. }
  8311. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8312. fmt.Println(timeStr)
  8313. timeArr := strings.Split(timeStr, " ")
  8314. fmt.Println(timeArr)
  8315. timeArrTwo := strings.Split(timeArr[0], "-")
  8316. timeArrThree := strings.Split(timeArr[1], ":")
  8317. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8318. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8319. if len(lists) == 0 {
  8320. var hisPatient models.XtHisPatient
  8321. hisPatient = models.XtHisPatient{
  8322. Name: name,
  8323. Age: age,
  8324. Gender: gender,
  8325. Birthday: birthUnix,
  8326. Phone: phone,
  8327. MedicalTreatmentType: medical_care,
  8328. IdType: certificates,
  8329. IdCardNo: id_card,
  8330. BalanceAccountsType: settlementValue,
  8331. SocialType: social_type,
  8332. MedicalInsuranceNumber: medical_insurance_card,
  8333. RegisterType: register_type,
  8334. RegisterCost: registration_fee,
  8335. TreatmentCost: medical_expenses,
  8336. AdminUserId: adminInfo.AdminUser.Id,
  8337. UserOrgId: adminInfo.CurrentOrgId,
  8338. Status: 1,
  8339. RecordDate: recordDateTime,
  8340. IsReturn: 1,
  8341. PatientId: patient.ID,
  8342. Ctime: time.Now().Unix(),
  8343. Mtime: time.Now().Unix(),
  8344. Number: str,
  8345. IdCardType: id_card_type,
  8346. Departments: department,
  8347. Doctor: doctor,
  8348. PType: reg_type,
  8349. Diagnosis: diagnosis_ids,
  8350. SickType: sick_type,
  8351. }
  8352. service.CreateHisPatient(&hisPatient)
  8353. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8354. c.ServeSuccessJSON(map[string]interface{}{
  8355. "his_info": hisPatient,
  8356. })
  8357. } else {
  8358. //chrgBchno := rand.Intn(1000000) + 10000
  8359. var hisPatient models.XtHisPatient
  8360. hisPatient = models.XtHisPatient{
  8361. Name: name,
  8362. Age: age,
  8363. Gender: gender,
  8364. Birthday: birthUnix,
  8365. Phone: phone,
  8366. MedicalTreatmentType: medical_care,
  8367. IdType: certificates,
  8368. IdCardNo: id_card,
  8369. BalanceAccountsType: settlementValue,
  8370. SocialType: social_type,
  8371. MedicalInsuranceNumber: medical_insurance_card,
  8372. RegisterType: register_type,
  8373. RegisterCost: registration_fee,
  8374. TreatmentCost: medical_expenses,
  8375. AdminUserId: adminInfo.AdminUser.Id,
  8376. UserOrgId: adminInfo.CurrentOrgId,
  8377. Status: 1,
  8378. RecordDate: recordDateTime,
  8379. IsReturn: 1,
  8380. PatientId: patient.ID,
  8381. Ctime: time.Now().Unix(),
  8382. Mtime: time.Now().Unix(),
  8383. Number: str,
  8384. IdCardType: id_card_type,
  8385. Departments: department,
  8386. Doctor: doctor,
  8387. PType: reg_type,
  8388. Diagnosis: diagnosis_ids,
  8389. SickType: sick_type,
  8390. }
  8391. service.CreateHisPatient(&hisPatient)
  8392. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8393. c.ServeSuccessJSON(map[string]interface{}{
  8394. "his_info": hisPatient,
  8395. })
  8396. }
  8397. }
  8398. // 上传明细----结算
  8399. func (c *HisApiController) GetUploadInfo() {
  8400. id, _ := c.GetInt64("id")
  8401. record_time := c.GetString("record_time")
  8402. his_patient_id, _ := c.GetInt64("his_patient_id")
  8403. oth_desc := c.GetString("oth_desc")
  8404. pay_way, _ := c.GetInt64("pay_way")
  8405. pay_ways := c.GetString("pay_ways")
  8406. pay_price, _ := c.GetFloat("pay_price")
  8407. pay_card_no := c.GetString("pay_card_no")
  8408. discount_price, _ := c.GetFloat("discount_price")
  8409. preferential_price, _ := c.GetFloat("preferential_price")
  8410. reality_price, _ := c.GetFloat("reality_price")
  8411. found_price, _ := c.GetFloat("found_price")
  8412. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8413. private_price, _ := c.GetFloat("private_price")
  8414. timeLayout := "2006-01-02"
  8415. loc, _ := time.LoadLocation("Local")
  8416. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8417. fapiao_code := c.GetString("fapiao_code")
  8418. fapiao_number := c.GetString("fapiao_number")
  8419. diagnosis_id := c.GetString("diagnosis")
  8420. sick_type, _ := c.GetInt64("sick_type")
  8421. reg_type, _ := c.GetInt64("p_type")
  8422. order_id, _ := c.GetInt64("order_id")
  8423. cash_pay := c.GetString("cash_pay")
  8424. wechat_pay := c.GetString("wechat_pay")
  8425. ali_pay := c.GetString("ali_pay")
  8426. jifen_pay := c.GetString("jifen_pay")
  8427. band_card_pay := c.GetString("band_card_pay")
  8428. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8429. tmp_decimal := c.GetString("tmp_decimal")
  8430. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8431. var decimal float64 //本次使用的押金
  8432. var errmsg error
  8433. tx := service.XTWriteDB().Begin() //开了事务
  8434. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8435. defer func() {
  8436. if errmsg != nil {
  8437. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8438. tx.Rollback()
  8439. } else {
  8440. tx.Commit()
  8441. }
  8442. }()
  8443. fmt.Println("dec_way", dec_way)
  8444. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8445. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8446. return
  8447. }
  8448. if len(tmp_decimal) > 0 {
  8449. if tmp_decimal[0] == 45 {
  8450. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8451. return
  8452. }
  8453. }
  8454. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8455. fmt.Println(errs)
  8456. decimal = tt
  8457. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8458. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8459. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8460. if err != nil {
  8461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8462. return
  8463. }
  8464. recordDateTime := theTime.Unix()
  8465. adminUser := c.GetAdminUserInfo()
  8466. var prescriptions []*models.HisPrescription
  8467. var prescriptionsOne []*models.HisPrescription
  8468. var start_time int64
  8469. var end_time int64
  8470. ids_str := c.GetString("ids")
  8471. ids_arr := strings.Split(ids_str, ",")
  8472. if tempOrder.ID == 0 {
  8473. if settle_accounts_type == 1 { //日结
  8474. fmt.Println(reg_type)
  8475. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8476. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8477. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8478. } else {
  8479. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8480. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8481. }
  8482. } else { //月结
  8483. start_time_str := c.GetString("start_time")
  8484. end_time_str := c.GetString("end_time")
  8485. timeLayout := "2006-01-02"
  8486. loc, _ := time.LoadLocation("Local")
  8487. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8488. if err != nil {
  8489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8490. return
  8491. }
  8492. recordStartTime := theStartTime.Unix()
  8493. start_time = recordStartTime
  8494. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8495. if err != nil {
  8496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8497. return
  8498. }
  8499. recordEndTime := theEndTime.Unix()
  8500. end_time = recordEndTime
  8501. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8502. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8503. }
  8504. var goods []*models.DialysisBeforePrepareGoods
  8505. var newGoods []*models.NewDialysisBeforePrepareGoods
  8506. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8507. var infos []*models.HisDoctorAdviceInfo
  8508. var infoList []*models.HisDoctorAdviceInfo
  8509. var hisAdvice []*models.HisDoctorAdviceInfo
  8510. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8511. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8512. //判断库存不足
  8513. //结算出库开关
  8514. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8515. if settConfig.IsOpen == 1 {
  8516. //判断库存的地方
  8517. for _, info := range prescriptions {
  8518. if info.Type == 1 {
  8519. infos = append(infos, info.HisDoctorAdviceInfo...)
  8520. }
  8521. if info.Type == 2 {
  8522. for _, sumItem := range info.HisPrescriptionProject {
  8523. if sumItem.Type == 3 {
  8524. var good models.DialysisBeforePrepareGoods
  8525. var newGood models.NewDialysisBeforePrepareGoods
  8526. good.GoodId = sumItem.GoodInfo.ID
  8527. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8528. count, _ := strconv.Atoi(sumItem.Count)
  8529. good.Count = int64(count)
  8530. good.StorehouseId = houseConfig.StorehouseOutInfo
  8531. good.ProjectId = sumItem.ID
  8532. goods = append(goods, &good)
  8533. newGood.GoodId = sumItem.GoodInfo.ID
  8534. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8535. count2, _ := strconv.Atoi(sumItem.Count)
  8536. newGood.Count = int64(count2)
  8537. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8538. newGood.ProjectId = sumItem.ID
  8539. newGoods = append(newGoods, &newGood)
  8540. }
  8541. }
  8542. }
  8543. }
  8544. for _, info := range prescriptionsOne {
  8545. if info.Type == 1 {
  8546. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8547. }
  8548. if info.Type == 2 {
  8549. for _, sumItem := range info.HisPrescriptionProject {
  8550. if sumItem.Type == 3 {
  8551. var newGood models.NewDialysisBeforePrepareGoods
  8552. newGood.GoodId = sumItem.GoodInfo.ID
  8553. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8554. count2, _ := strconv.Atoi(sumItem.Count)
  8555. newGood.Count = int64(count2)
  8556. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8557. newGood.ProjectId = sumItem.ID
  8558. newGoodOne = append(newGoodOne, &newGood)
  8559. }
  8560. }
  8561. }
  8562. }
  8563. //判断
  8564. for _, itemOne := range infos {
  8565. for _, itemTwo := range hisAdvice {
  8566. if itemOne.DrugId == itemTwo.DrugId {
  8567. itemTwo.Child = append(itemTwo.Child, itemOne)
  8568. }
  8569. }
  8570. }
  8571. for _, itemTwo := range hisAdvice {
  8572. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8573. var sum_out_count int64
  8574. for _, itemThree := range itemTwo.Child {
  8575. var prescribing_number int64
  8576. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8577. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8578. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8579. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8580. }
  8581. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8582. prescribing_number = parseIntPrescribingNumber
  8583. }
  8584. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8585. prescribing_number = parseIntPrescribingNumber
  8586. }
  8587. sum_out_count += prescribing_number
  8588. }
  8589. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8590. if sum_out_count > drugStockOut.FlushCount {
  8591. c.ServeSuccessJSON(map[string]interface{}{
  8592. "msg": "2",
  8593. "drug": medical,
  8594. })
  8595. return
  8596. }
  8597. }
  8598. for _, itemOne := range newGoods {
  8599. for _, item := range newGoodOne {
  8600. if itemOne.GoodId == item.GoodId {
  8601. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8602. }
  8603. }
  8604. }
  8605. for _, item := range newGoodOne {
  8606. var sum_out_count_one int64
  8607. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8608. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8609. sum_out_count_one += itemOne.Count
  8610. }
  8611. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8612. fmt.Println("sum_out_count_one", sum_out_count_one)
  8613. fmt.Println("list.FlushCount", list.FlushCount)
  8614. if sum_out_count_one > list.FlushCount {
  8615. c.ServeSuccessJSON(map[string]interface{}{
  8616. "msg": "3",
  8617. "good": good,
  8618. })
  8619. return
  8620. }
  8621. }
  8622. }
  8623. timestamp := time.Now().Unix()
  8624. tempTime := time.Unix(timestamp, 0)
  8625. timeFormat := tempTime.Format("20060102150405")
  8626. chrgBchno := rand.Intn(100000) + 10000
  8627. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8628. strconv.FormatInt(his.PatientId, 10)
  8629. var ids []int64
  8630. for _, item := range prescriptions {
  8631. ids = append(ids, item.ID)
  8632. }
  8633. var total float64
  8634. for _, item := range prescriptions {
  8635. fmt.Println(item)
  8636. if item.Type == 1 { //药品
  8637. for _, subItem := range item.HisDoctorAdviceInfo {
  8638. total = total + (subItem.Price * subItem.PrescribingNumber)
  8639. }
  8640. }
  8641. if item.Type == 2 { //项目
  8642. for _, subItem := range item.HisPrescriptionProject {
  8643. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8644. total = total + (subItem.Price * cnt)
  8645. }
  8646. }
  8647. for _, subItem := range item.HisAdditionalCharge {
  8648. total = total + (subItem.Price * float64(subItem.Count))
  8649. }
  8650. }
  8651. if reg_type == 1111 || reg_type == 1112 {
  8652. reg_type = 11
  8653. }
  8654. tm := time.Unix(time.Now().Unix(), 0)
  8655. allTotal := fmt.Sprintf("%.4f", total)
  8656. totals, _ := strconv.ParseFloat(allTotal, 64)
  8657. order := &models.HisOrder{
  8658. UserOrgId: adminUser.CurrentOrgId,
  8659. HisPatientId: his.ID,
  8660. PatientId: id,
  8661. SettleAccountsDate: recordDateTime,
  8662. Ctime: time.Now().Unix(),
  8663. Mtime: time.Now().Unix(),
  8664. Status: 1,
  8665. OrderStatus: 2,
  8666. MdtrtId: his.Number,
  8667. Number: chrg_bchno,
  8668. MedfeeSumamt: totals,
  8669. PayWay: pay_way,
  8670. PayWays: pay_ways,
  8671. PayPrice: pay_price,
  8672. MedType: strconv.Itoa(int(reg_type)),
  8673. PayCardNo: pay_card_no,
  8674. DiscountPrice: discount_price,
  8675. PreferentialPrice: preferential_price,
  8676. RealityPrice: reality_price,
  8677. FoundPrice: found_price,
  8678. MedicalInsurancePrice: medical_insurance_price,
  8679. PrivatePrice: private_price,
  8680. SettleEndTime: end_time,
  8681. SettleStartTime: start_time,
  8682. PsnPartAmt: totals,
  8683. PsnCashPay: totals,
  8684. SettleType: settle_accounts_type,
  8685. FaPiaoCode: fapiao_code,
  8686. FaPiaoNumber: fapiao_number,
  8687. Diagnosis: diagnosis_id,
  8688. PType: 2,
  8689. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8690. Decimal: decimal,
  8691. OthDesc: oth_desc,
  8692. CashPay: cash_pay,
  8693. WechatPay: wechat_pay,
  8694. AliPay: ali_pay,
  8695. JifenPay: jifen_pay,
  8696. BandCardPay: band_card_pay,
  8697. Creator: adminUser.AdminUser.Id,
  8698. }
  8699. err = service.CreateOrderTX(order, tx)
  8700. if err != nil {
  8701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8702. return
  8703. }
  8704. var customs []*Custom
  8705. for _, item := range prescriptions {
  8706. if item.Type == 1 { //药品a
  8707. for _, subItem := range item.HisDoctorAdviceInfo {
  8708. cus := &Custom{
  8709. AdviceId: subItem.ID,
  8710. ProjectId: 0,
  8711. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8712. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8713. FeedetlSn: subItem.FeedetlSn,
  8714. Price: fmt.Sprintf("%.4f", subItem.Price),
  8715. MedListCodg: subItem.MedListCodg,
  8716. Type: 1,
  8717. }
  8718. customs = append(customs, cus)
  8719. }
  8720. }
  8721. if item.Type == 2 { //项目
  8722. for _, subItem := range item.HisPrescriptionProject {
  8723. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8724. cus := &Custom{
  8725. AdviceId: 0,
  8726. ProjectId: subItem.ID,
  8727. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8728. Cut: fmt.Sprintf("%.4f", cnt),
  8729. FeedetlSn: subItem.FeedetlSn,
  8730. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8731. MedListCodg: subItem.MedListCodg,
  8732. Type: 2,
  8733. }
  8734. customs = append(customs, cus)
  8735. }
  8736. }
  8737. for _, item := range item.HisAdditionalCharge {
  8738. cus := &Custom{
  8739. ItemId: item.ID,
  8740. AdviceId: 0,
  8741. ProjectId: 0,
  8742. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8743. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8744. FeedetlSn: item.FeedetlSn,
  8745. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8746. MedListCodg: item.XtHisAddtionConfig.Code,
  8747. Type: 3,
  8748. }
  8749. customs = append(customs, cus)
  8750. }
  8751. }
  8752. for _, item := range customs {
  8753. var advice_id int64 = 0
  8754. var project_id int64 = 0
  8755. var item_id int64 = 0
  8756. var types int64 = 0
  8757. if item.Type == 1 {
  8758. advice_id = item.AdviceId
  8759. project_id = 0
  8760. item_id = 0
  8761. } else if item.Type == 2 {
  8762. advice_id = 0
  8763. item_id = 0
  8764. project_id = item.ProjectId
  8765. } else if item.Type == 3 {
  8766. advice_id = 0
  8767. item_id = item.ItemId
  8768. project_id = 0
  8769. }
  8770. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8771. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8772. pric, _ := strconv.ParseFloat(item.Price, 32)
  8773. info := &models.HisOrderInfo{
  8774. OrderNumber: order.Number,
  8775. UploadDate: time.Now().Unix(),
  8776. AdviceId: advice_id,
  8777. DetItemFeeSumamt: detItemFeeSumamt,
  8778. Cnt: cut,
  8779. Pric: pric,
  8780. PatientId: id,
  8781. Status: 1,
  8782. Mtime: time.Now().Unix(),
  8783. Ctime: time.Now().Unix(),
  8784. UserOrgId: adminUser.CurrentOrgId,
  8785. HisPatientId: his.ID,
  8786. OrderId: order.ID,
  8787. ProjectId: project_id,
  8788. Type: types,
  8789. ItemId: item_id,
  8790. }
  8791. service.CreateOrderInfoTX(info, tx)
  8792. }
  8793. his.Diagnosis = diagnosis_id
  8794. his.SickType = sick_type
  8795. his.RegisterType = reg_type
  8796. his.MedicalTreatmentType = reg_type
  8797. service.UpdataHisPateintTX(&his, tx)
  8798. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8799. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8800. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8801. //判断是否使用了押金
  8802. if dec_way == "true" {
  8803. tmpstring := strconv.FormatInt(order.ID, 10)
  8804. //扣押金
  8805. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8806. order.Decimal = decimal
  8807. service.UpDateOrderTwo(order, tx)
  8808. if errmsg != nil {
  8809. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8810. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8811. return
  8812. }
  8813. }
  8814. if err == nil {
  8815. for _, info := range prescriptions {
  8816. if info.Type == 1 {
  8817. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8818. }
  8819. if info.Type == 2 {
  8820. for _, sumItem := range info.HisPrescriptionProject {
  8821. if sumItem.Type == 3 {
  8822. var good models.DialysisBeforePrepareGoods
  8823. var newGood models.NewDialysisBeforePrepareGoods
  8824. var oldGood models.OldDialysisBeforePrepareGoods
  8825. good.GoodId = sumItem.GoodInfo.ID
  8826. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8827. count, _ := strconv.Atoi(sumItem.Count)
  8828. good.Count = int64(count)
  8829. good.StorehouseId = houseConfig.StorehouseOutInfo
  8830. good.ProjectId = sumItem.ID
  8831. good.PatientId = sumItem.PatientId
  8832. goods = append(goods, &good)
  8833. newGood.GoodId = sumItem.GoodInfo.ID
  8834. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8835. count2, _ := strconv.Atoi(sumItem.Count)
  8836. newGood.Count = int64(count2)
  8837. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8838. newGood.ProjectId = sumItem.ID
  8839. newGood.PatientId = sumItem.HisPatientId
  8840. newGoods = append(newGoods, &newGood)
  8841. oldGood.GoodId = sumItem.GoodInfo.ID
  8842. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8843. count3, _ := strconv.Atoi(sumItem.Count)
  8844. oldGood.Count = int64(count3)
  8845. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8846. oldGood.ProjectId = sumItem.ID
  8847. oldGood.RecordDate = sumItem.RecordDate
  8848. oldGood.PatientId = sumItem.HisPatientId
  8849. oldGoods = append(oldGoods, &oldGood)
  8850. }
  8851. }
  8852. }
  8853. }
  8854. if settConfig.IsOpen == 1 {
  8855. for _, item := range infoList {
  8856. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8857. if medical.IsUse == 2 {
  8858. //药品出库
  8859. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8860. //查询默认仓库
  8861. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8862. //查询默认仓库剩余多少库存
  8863. var sum_count int64
  8864. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8865. for _, its := range stockInfo {
  8866. if its.MaxUnit == medical.MaxUnit {
  8867. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8868. }
  8869. sum_count += its.StockMaxNumber + its.StockMinNumber
  8870. }
  8871. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8872. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8873. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8874. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8875. }
  8876. }
  8877. orgId := c.GetAdminUserInfo().CurrentOrgId
  8878. if len(oldGoods) > 0 {
  8879. timeStr := time.Now().Format("2006-01-02")
  8880. timeArr := strings.Split(timeStr, "-")
  8881. total, _ := service.FindAllWarehouseOut(orgId)
  8882. total = total + 1
  8883. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8884. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8885. number = number + total
  8886. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8887. operation_time := time.Now().Unix()
  8888. creater := c.GetAdminUserInfo().AdminUser.Id
  8889. //查询默认出库仓库库存
  8890. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8891. recordDateStr := time.Now().Format("2006-01-02")
  8892. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8893. nowtime := recordDate.Unix()
  8894. warehouseOut := models.WarehouseOut{
  8895. WarehouseOutOrderNumber: warehousing_out_order,
  8896. OperationTime: operation_time,
  8897. OrgId: orgId,
  8898. Creater: creater,
  8899. Ctime: time.Now().Unix(),
  8900. Status: 1,
  8901. WarehouseOutTime: nowtime,
  8902. Type: 1,
  8903. StorehouseId: storeConfig.StorehouseOutInfo,
  8904. IsCheck: 1,
  8905. OrderId: order.ID,
  8906. IsSys: 5,
  8907. }
  8908. //查询是否生成出库单
  8909. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8910. if out.ID == 0 {
  8911. service.AddSigleWarehouseOut(&warehouseOut)
  8912. }
  8913. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8914. for _, item := range oldGoods {
  8915. dialyPrepareOne := models.DialysisBeforePrepare{
  8916. GoodTypeId: item.GoodTypeId,
  8917. GoodId: item.GoodId,
  8918. PatientId: his.PatientId,
  8919. RecordDate: item.RecordDate,
  8920. UserOrgId: adminUser.CurrentOrgId,
  8921. Count: item.Count,
  8922. Ctime: time.Now().Unix(),
  8923. Creater: adminUser.AdminUser.Id,
  8924. CommdityCode: item.CommdityCode,
  8925. Status: 1,
  8926. StorehouseId: houseConfig.StorehouseOutInfo,
  8927. }
  8928. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8929. //非零用
  8930. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8931. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8932. //查询剩余库存
  8933. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8934. var sum_count int64
  8935. for _, item := range goodList {
  8936. sum_count += item.StockCount
  8937. }
  8938. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8939. //耗材
  8940. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8941. }
  8942. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8943. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8944. //查询剩余库存
  8945. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8946. var sum_count int64
  8947. for _, item := range goodList {
  8948. sum_count += item.StockCount
  8949. }
  8950. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8951. //耗材
  8952. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8953. }
  8954. }
  8955. }
  8956. }
  8957. c.ServeSuccessJSON(map[string]interface{}{
  8958. "msg": "结算成功",
  8959. })
  8960. }
  8961. }
  8962. }
  8963. // 退款
  8964. func (c *HisApiController) Refund() {
  8965. order_id, _ := c.GetInt64("order_id")
  8966. order, _ := service.GetHisOrderByID(order_id)
  8967. adminUser := c.GetAdminUserInfo()
  8968. orgid := c.GetAdminUserInfo().CurrentOrgId
  8969. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8970. if err != nil {
  8971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8972. return
  8973. }
  8974. tmp := strconv.FormatInt(order.ID, 10)
  8975. //当押金不为零时产生退费记录
  8976. if order.Decimal != 0 {
  8977. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8978. if err != nil {
  8979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8980. return
  8981. }
  8982. }
  8983. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8984. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8985. var goods []*models.DialysisBeforePrepareGoods
  8986. var newGoods []*models.NewDialysisBeforePrepareGoods
  8987. var infos []*models.HisDoctorAdviceInfo
  8988. for _, info := range orders {
  8989. if info.AdviceId > 0 && info.ProjectId == 0 {
  8990. infos = append(infos, &info.HisDoctorAdviceInfo)
  8991. }
  8992. if info.ProjectId > 0 && info.AdviceId == 0 {
  8993. if info.HisPrescriptionProject.Type == 3 {
  8994. var good models.DialysisBeforePrepareGoods
  8995. var newGood models.NewDialysisBeforePrepareGoods
  8996. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8997. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8998. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8999. good.Count = int64(count)
  9000. good.StorehouseId = houseConfig.StorehouseOutInfo
  9001. good.ProjectId = info.HisPrescriptionProject.ID
  9002. good.PatientId = info.PatientId
  9003. good.OrderId = order_id
  9004. goods = append(goods, &good)
  9005. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9006. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9007. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9008. newGood.Count = int64(count2)
  9009. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9010. newGood.ProjectId = info.HisPrescriptionProject.ID
  9011. newGood.RecordDate = order.SettleAccountsDate
  9012. newGood.UserOrgId = order.UserOrgId
  9013. newGood.PatientId = info.PatientId
  9014. newGood.OrderId = order_id
  9015. newGoods = append(newGoods, &newGood)
  9016. }
  9017. }
  9018. }
  9019. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9020. if settConfig.IsOpen == 1 {
  9021. for _, item := range infos {
  9022. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9023. }
  9024. for _, item := range newGoods {
  9025. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9026. }
  9027. }
  9028. c.ServeSuccessJSON(map[string]interface{}{
  9029. "msg": "退费成功",
  9030. })
  9031. }
  9032. func (c *HisApiController) RefundNumber() {
  9033. his_patient_id, _ := c.GetInt64("id")
  9034. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9035. info.Status = 0
  9036. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9037. if count > 0 {
  9038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9039. return
  9040. }
  9041. err := service.SaveHisPatient(info)
  9042. if err == nil {
  9043. c.ServeSuccessJSON(map[string]interface{}{
  9044. "msg": "退号成功",
  9045. })
  9046. } else {
  9047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9048. return
  9049. }
  9050. }
  9051. func (this *HisApiController) AdditionalCharge() {
  9052. dataBody := make(map[string]interface{}, 0)
  9053. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9054. fmt.Println(err)
  9055. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9056. patient_id := int64(dataBody["patient_id"].(float64))
  9057. medicineData, _ := dataBody["medicineData"].([]interface{})
  9058. adminUserInfo := this.GetAdminUserInfo()
  9059. orgId := adminUserInfo.CurrentOrgId
  9060. admin_user_id := adminUserInfo.AdminUser.Id
  9061. timeStr := time.Now().Format("2006-01-02")
  9062. timeLayout := "2006-01-02 15:04:05"
  9063. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9064. timenow := timeStringToTime.Unix()
  9065. var additionalCharges []*models.HisAdditionalCharge
  9066. for _, item := range medicineData {
  9067. var randNum int
  9068. randNum = rand.Intn(10000) + 1000
  9069. timestamp := time.Now().Unix()
  9070. tempTime := time.Unix(timestamp, 0)
  9071. timeFormat := tempTime.Format("20060102150405")
  9072. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9073. items := item.(map[string]interface{})
  9074. money := items["price"].(string)
  9075. item_id_str := items["item_id"].(string)
  9076. name := items["name"].(string)
  9077. id_str := items["id"].(string)
  9078. moneys, _ := strconv.ParseInt(money, 10, 64)
  9079. monStr := strconv.FormatInt(moneys, 10)
  9080. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9081. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9082. id, _ := strconv.ParseInt(id_str, 10, 64)
  9083. additionalCharge := &models.HisAdditionalCharge{
  9084. ID: id,
  9085. HisPatientId: his_patient_id,
  9086. UserOrgId: orgId,
  9087. PatientId: patient_id,
  9088. RecordDate: timenow,
  9089. Price: monneyStr,
  9090. Status: 1,
  9091. ItemName: name,
  9092. ItemId: item_id,
  9093. AdminUserId: admin_user_id,
  9094. CreatedTime: time.Now().Unix(),
  9095. OrderStatus: 0,
  9096. PrescriptionNumber: "",
  9097. BatchNumber: "",
  9098. FeedetlSn: p_number,
  9099. }
  9100. service.CreateAdditionalCharge(additionalCharge)
  9101. additionalCharges = append(additionalCharges, additionalCharge)
  9102. }
  9103. this.ServeSuccessJSON(map[string]interface{}{
  9104. "msg": "添加成功",
  9105. "additional_charges": additionalCharges,
  9106. })
  9107. }
  9108. func (this *HisApiController) DeleteAddition() {
  9109. id, _ := this.GetInt64("id")
  9110. //TODO 需要判断是否已经结算
  9111. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9112. if err == nil {
  9113. this.ServeSuccessJSON(map[string]interface{}{
  9114. "msg": "删除成功",
  9115. })
  9116. return
  9117. } else {
  9118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9119. return
  9120. }
  9121. }
  9122. func (this *HisApiController) GetAdminUsers() {
  9123. adminUser := this.GetAdminUserInfo()
  9124. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9125. this.ServeSuccessJSON(map[string]interface{}{
  9126. "doctors": doctors,
  9127. })
  9128. }
  9129. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9130. change_type, _ := this.GetInt64("type", 0)
  9131. record_date := this.GetString("record_time")
  9132. patient_id, _ := this.GetInt64("patient_id", 0)
  9133. p_type, _ := this.GetInt64("p_type", 0)
  9134. timeLayout := "2006-01-02"
  9135. loc, _ := time.LoadLocation("Local")
  9136. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9137. record_time := theAdviceRecordTime.Unix()
  9138. adminUserInfo := this.GetAdminUserInfo()
  9139. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9140. if adminUserInfo.CurrentOrgId == 10265 {
  9141. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9142. if config.ID > 0 && config.IsOpen == 1 {
  9143. for _, subitems := range prescriptions {
  9144. for _, item := range subitems.VMHisPrescription {
  9145. for _, subItem := range item.HisDoctorAdviceInfo {
  9146. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9147. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9148. if info.RetailPrice > 0 {
  9149. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9150. subItem.Drug.RetailPrice = drug.RetailPrice
  9151. }
  9152. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9153. subItem.Drug.MinPrice = info.RetailPrice
  9154. subItem.Drug.RetailPrice = info.RetailPrice
  9155. }
  9156. }
  9157. }
  9158. }
  9159. }
  9160. }
  9161. if config.ID > 0 && config.IsOpen == 1 {
  9162. for _, subitems := range prescriptions {
  9163. for _, item := range subitems.VMHisPrescription {
  9164. for _, subItem := range item.HisPrescriptionProject {
  9165. if subItem.Type == 3 {
  9166. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9167. if info.Price > 0 {
  9168. subItem.GoodInfo.PackingPrice = info.Price
  9169. }
  9170. }
  9171. }
  9172. }
  9173. }
  9174. }
  9175. }
  9176. if err == nil {
  9177. if len(prescriptions) == 0 {
  9178. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9179. return
  9180. } else {
  9181. this.ServeSuccessJSON(map[string]interface{}{
  9182. "prescriptions": prescriptions,
  9183. })
  9184. return
  9185. }
  9186. } else {
  9187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9188. return
  9189. }
  9190. }
  9191. func (this *HisApiController) GetCallHisPrescription() {
  9192. patient_id, _ := this.GetInt64("patient_id", 0)
  9193. timeLayout := "2006-01-02"
  9194. loc, _ := time.LoadLocation("Local")
  9195. start_time := this.GetString("start_time")
  9196. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9197. end_time := this.GetString("end_time")
  9198. p_type, _ := this.GetInt64("p_type")
  9199. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9200. adminUserInfo := this.GetAdminUserInfo()
  9201. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9202. //if
  9203. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9204. //
  9205. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9206. if adminUserInfo.CurrentOrgId == 10265 {
  9207. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9208. if config.ID > 0 && config.IsOpen == 1 {
  9209. for _, subitems := range prescriptions {
  9210. for _, item := range subitems.VMHisPrescription {
  9211. for _, subItem := range item.HisDoctorAdviceInfo {
  9212. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9213. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9214. if info.RetailPrice > 0 {
  9215. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9216. subItem.Drug.RetailPrice = drug.RetailPrice
  9217. }
  9218. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9219. subItem.Drug.MinPrice = info.RetailPrice
  9220. subItem.Drug.RetailPrice = info.RetailPrice
  9221. }
  9222. }
  9223. }
  9224. }
  9225. }
  9226. }
  9227. if config.ID > 0 && config.IsOpen == 1 {
  9228. for _, subitems := range prescriptions {
  9229. for _, item := range subitems.VMHisPrescription {
  9230. for _, subItem := range item.HisPrescriptionProject {
  9231. if subItem.Type == 3 {
  9232. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9233. if info.Price > 0 {
  9234. subItem.GoodInfo.PackingPrice = info.Price
  9235. }
  9236. }
  9237. }
  9238. }
  9239. }
  9240. }
  9241. }
  9242. if err == nil {
  9243. this.ServeSuccessJSON(map[string]interface{}{
  9244. "prescriptions": prescriptions,
  9245. })
  9246. return
  9247. } else {
  9248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9249. return
  9250. }
  9251. }
  9252. func (this *HisApiController) GetHisDayPrescription() {
  9253. timeLayout := "2006-01-02"
  9254. loc, _ := time.LoadLocation("Local")
  9255. start_time := this.GetString("start_time")
  9256. patient_id, _ := this.GetInt64("patient_id", 0)
  9257. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9258. end_time := this.GetString("end_time")
  9259. p_type, _ := this.GetInt64("p_type")
  9260. order_status, _ := this.GetInt64("type")
  9261. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9262. adminUserInfo := this.GetAdminUserInfo()
  9263. var dayHisPrescription []*models.HisPrescription
  9264. var err error
  9265. if order_status == 1 || order_status == 0 {
  9266. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9267. } else if order_status == 2 {
  9268. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9269. }
  9270. var settle_total float64
  9271. for _, item := range dayHisPrescription {
  9272. if len(item.HisPrescriptionProject) > 0 {
  9273. for _, subItem := range item.HisPrescriptionProject {
  9274. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9275. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9276. settle_total = settle_total + total
  9277. }
  9278. }
  9279. if len(item.HisDoctorAdviceInfo) > 0 {
  9280. for _, subItem := range item.HisDoctorAdviceInfo {
  9281. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9282. settle_total = settle_total + total
  9283. }
  9284. }
  9285. }
  9286. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9287. if err == nil {
  9288. this.ServeSuccessJSON(map[string]interface{}{
  9289. "day_prescription": dayHisPrescription,
  9290. "settle_total": settle_total,
  9291. })
  9292. return
  9293. } else {
  9294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9295. return
  9296. }
  9297. }
  9298. func (c *HisApiController) GetHisChargePatientList() {
  9299. record_date := c.GetString("record_date")
  9300. order_status, _ := c.GetInt64("type")
  9301. sch_type, _ := c.GetInt64("sch_type")
  9302. timeLayout := "2006-01-02"
  9303. loc, _ := time.LoadLocation("Local")
  9304. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9305. if err != nil {
  9306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9307. return
  9308. }
  9309. recordDateTime := theTime.Unix()
  9310. adminInfo := c.GetAdminUserInfo()
  9311. var tempPatients []*service.NewTempPatients
  9312. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9313. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9314. if order_status != 2 {
  9315. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9316. } else {
  9317. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9318. }
  9319. } else {
  9320. if order_status != 2 {
  9321. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9322. } else {
  9323. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9324. }
  9325. }
  9326. var patients []*service.NewTempPatients
  9327. var patients_two []*service.NewTempPatients
  9328. for _, item := range tempPatients {
  9329. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9330. //过滤掉没挂号的和没开处方的
  9331. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9332. patients = append(patients, item)
  9333. }
  9334. //过滤掉没挂号的
  9335. if len(item.HisPatient) > 0 {
  9336. patients_two = append(patients_two, item)
  9337. }
  9338. } else {
  9339. if len(item.HisPrescription) > 0 {
  9340. patients = append(patients, item)
  9341. }
  9342. }
  9343. }
  9344. c.ServeSuccessJSON(map[string]interface{}{
  9345. "list": patients,
  9346. "list_two": patients_two,
  9347. })
  9348. }
  9349. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9350. record_date := c.GetString("record_date")
  9351. timeLayout := "2006-01-02"
  9352. loc, _ := time.LoadLocation("Local")
  9353. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9354. if err != nil {
  9355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9356. return
  9357. }
  9358. recordDateTime := theTime.Unix()
  9359. adminUser := c.GetAdminUserInfo()
  9360. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9361. var patients []*service.Patients
  9362. for _, item := range tempPatients {
  9363. if item.HisPatient.ID == 0 {
  9364. patients = append(patients, item)
  9365. }
  9366. }
  9367. c.ServeSuccessJSON(map[string]interface{}{
  9368. "list": patients,
  9369. //"list_two": patients_two,
  9370. })
  9371. }
  9372. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9373. newArr = make([]*service.Patients, 0)
  9374. for i := 0; i < len(patient); i++ {
  9375. repeat := false
  9376. for j := i + 1; j < len(patient); j++ {
  9377. if patient[i].ID == patient[j].ID {
  9378. repeat = true
  9379. break
  9380. }
  9381. }
  9382. if !repeat {
  9383. newArr = append(newArr, patient[i])
  9384. }
  9385. }
  9386. return
  9387. }
  9388. func (c *HisApiController) GetHisChargePatientInfo() {
  9389. patient_id, _ := c.GetInt64("patient_id")
  9390. his_patient_id, _ := c.GetInt64("his_patient_id")
  9391. record_date := c.GetString("record_date")
  9392. //start_time := c.GetString("start_time")
  9393. //end_time := c.GetString("end_time")
  9394. order_status, _ := c.GetInt64("type", 0)
  9395. p_type, _ := c.GetInt64("p_type", 0)
  9396. order_id, _ := c.GetInt64("order_id", 0)
  9397. timeLayout := "2006-01-02"
  9398. loc, _ := time.LoadLocation("Local")
  9399. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9400. if err != nil {
  9401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9402. return
  9403. }
  9404. recordDateTime := theTime.Unix()
  9405. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9406. //if err != nil {
  9407. //
  9408. //}
  9409. //startRecordDateTime := startTime.Unix()
  9410. //
  9411. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9412. //if err != nil {
  9413. //
  9414. //}
  9415. //endRecordDateTime := endTime.Unix()
  9416. admin := c.GetAdminUserInfo()
  9417. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9418. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9419. var prescriptions []*models.HisPrescription
  9420. //var unChargeMonthPrescriptions []*models.HisPrescription
  9421. order, _ := service.GetHisOrderByID(order_id)
  9422. if order_status == 1 || order_status == 0 {
  9423. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9424. } else if order_status == 2 {
  9425. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9426. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9427. }
  9428. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9429. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9430. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9431. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9432. //获取所有科室信息
  9433. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9434. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9435. c.ServeSuccessJSON(map[string]interface{}{
  9436. "his_info": his_patient_info,
  9437. "xt_info": xt_patient_info,
  9438. "prescription": prescriptions,
  9439. "case_history": case_history,
  9440. "info": patientPrescriptionInfo,
  9441. "last_info": lastPatientPrescriptionInfo,
  9442. "order": order,
  9443. "doctors": doctors,
  9444. "department": department,
  9445. "sch": sch,
  9446. })
  9447. return
  9448. }
  9449. func (c *HisApiController) GetAllOrderDetail() {
  9450. order_id, _ := c.GetInt64("id", 0)
  9451. order, _ := service.GetHisOrderByID(order_id)
  9452. if order.ID == 0 {
  9453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9454. return
  9455. }
  9456. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9457. org_id := c.GetAdminUserInfo().CurrentOrgId
  9458. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9459. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9460. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9461. c.ServeSuccessJSON(map[string]interface{}{
  9462. "order": order,
  9463. "order_info": order_info,
  9464. "patient": patient,
  9465. "admin_info": adminInfo,
  9466. "hospital_record": record,
  9467. })
  9468. return
  9469. }
  9470. func (c *HisApiController) GetAllOrderDetailCollect() {
  9471. order_id, _ := c.GetInt64("id", 0)
  9472. order, _ := service.GetHisOrderByID(order_id)
  9473. if order.ID == 0 {
  9474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9475. return
  9476. }
  9477. org_id := c.GetAdminUserInfo().CurrentOrgId
  9478. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9479. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9480. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9481. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9482. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9483. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9484. var bedCostTotal float64 = 0 //床位总费
  9485. //var bedCostSelfTotal float64 = 0 //床位自费
  9486. var operationCostTotal float64 = 0 //手术费
  9487. //var operationCostSelfTotal float64 = 0 //手术费
  9488. var otherCostTotal float64 = 0 //其他费用
  9489. //var otherCostSelfTotal float64 = 0 //其他费用
  9490. var materialCostTotal float64 = 0 //材料费
  9491. //var materialCostSelfTotal float64 = 0 //材料费
  9492. var westernMedicineCostTotal float64 = 0 //西药费
  9493. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9494. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9495. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9496. var checkCostTotal float64 = 0 //检查费
  9497. //var checkCostSelfTotal float64 = 0 //检查费
  9498. var laboratoryCostTotal float64 = 0 //化验费
  9499. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9500. var treatCostTotal float64 = 0 //治疗费用
  9501. //var treatCostSelfTotal float64 = 0 //治疗费用
  9502. var zhenChaCostTotal float64 = 0 //其他费用
  9503. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9504. decimal.DivisionPrecision = 2
  9505. var BalanceAccountsType int64
  9506. if his.ID > 0 {
  9507. BalanceAccountsType = his.BalanceAccountsType
  9508. } else {
  9509. BalanceAccountsType = record.BalanceAccountsType
  9510. }
  9511. if BalanceAccountsType != 2 {
  9512. for _, item := range order_info {
  9513. if org_id == 10215 {
  9514. if item.MedChrgitmType == "01" { //床位费
  9515. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9516. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9517. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9518. }
  9519. if item.MedChrgitmType == "02" { //诊察费
  9520. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9521. //zhenChaCostSelfTotal = zhenChaCostTotal
  9522. }
  9523. if item.MedChrgitmType == "03" { //检查费
  9524. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9525. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9526. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9527. }
  9528. //if item.MedChrgitmType == "02" { //检查费
  9529. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9530. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9531. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9532. //}
  9533. if item.MedChrgitmType == "04" { //化验费
  9534. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9535. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9536. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9537. }
  9538. if item.MedChrgitmType == "05" { //治疗费
  9539. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9540. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9541. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9542. }
  9543. if item.MedChrgitmType == "06" { //手术费
  9544. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9545. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9546. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9547. }
  9548. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9549. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9550. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9551. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9552. }
  9553. if item.MedChrgitmType == "09" { //西药费
  9554. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9555. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9556. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9557. }
  9558. if item.MedChrgitmType == "11" { //中成费
  9559. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9560. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9561. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9562. }
  9563. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9564. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9565. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9566. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9567. }
  9568. } else if org_id == 10188 || org_id == 10217 {
  9569. if item.MedChrgitmType == "01" { //床位费
  9570. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9571. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9572. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9573. }
  9574. if item.MedChrgitmType == "02" { //诊察费
  9575. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9576. //zhenChaCostSelfTotal = zhenChaCostTotal
  9577. }
  9578. if item.MedChrgitmType == "03" { //检查费
  9579. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9580. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9581. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9582. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9583. }
  9584. //if item.MedChrgitmType == "02" { //检查费
  9585. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9586. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9587. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9588. //}
  9589. if item.MedChrgitmType == "04" { //化验费
  9590. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9591. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9592. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9593. }
  9594. if item.MedChrgitmType == "05" { //治疗费
  9595. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9596. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9597. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9598. }
  9599. if item.MedChrgitmType == "06" { //手术费
  9600. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9601. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9602. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9603. }
  9604. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9605. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9606. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9607. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9608. }
  9609. if item.MedChrgitmType == "09" { //西药费
  9610. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9611. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9612. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9613. }
  9614. if item.MedChrgitmType == "11" { //中成费
  9615. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9616. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9617. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9618. }
  9619. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9620. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9621. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9622. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9623. }
  9624. } else {
  9625. if item.MedChrgitmType == "01" { //床位费
  9626. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9627. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9628. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9629. }
  9630. //if item.MedChrgitmType == "02" { //诊察费
  9631. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9632. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9633. //}
  9634. if item.MedChrgitmType == "03" { //检查费
  9635. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9636. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9637. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9638. }
  9639. //if item.MedChrgitmType == "02" { //检查费
  9640. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9641. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9642. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9643. //}
  9644. if item.MedChrgitmType == "04" { //化验费
  9645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9646. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9647. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9648. }
  9649. if item.MedChrgitmType == "05" { //治疗费
  9650. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9651. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9652. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9653. }
  9654. if item.MedChrgitmType == "06" { //手术费
  9655. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9656. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9657. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9658. }
  9659. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9660. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9661. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9662. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9663. }
  9664. if item.MedChrgitmType == "09" { //西药费
  9665. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9666. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9667. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9668. }
  9669. if item.MedChrgitmType == "11" { //中成费
  9670. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9671. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9672. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9673. }
  9674. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9675. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9676. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9677. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9678. }
  9679. }
  9680. }
  9681. c.ServeSuccessJSON(map[string]interface{}{
  9682. "order": order,
  9683. "order_info": order_info,
  9684. "patient": patient,
  9685. "admin_info": adminInfo,
  9686. "his_hospital": record,
  9687. "bedCostTotal": bedCostTotal,
  9688. "operationCostTotal": operationCostTotal,
  9689. "otherCostTotal": otherCostTotal,
  9690. "materialCostTotal": materialCostTotal,
  9691. "westernMedicineCostTotal": westernMedicineCostTotal,
  9692. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9693. "checkCostTotal": checkCostTotal,
  9694. "zhenChaCostTotal": zhenChaCostTotal,
  9695. "laboratoryCostTotal": laboratoryCostTotal,
  9696. "treatCostTotal": treatCostTotal,
  9697. })
  9698. } else {
  9699. for _, item := range order_info {
  9700. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9701. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9702. item.MedChrgitmType = "09"
  9703. }
  9704. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9705. if item.HisPrescriptionProject.Type == 2 {
  9706. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9707. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9708. case 0:
  9709. item.MedChrgitmType = "0"
  9710. break
  9711. case 1:
  9712. item.MedChrgitmType = "14"
  9713. break
  9714. case 2:
  9715. item.MedChrgitmType = "05"
  9716. break
  9717. case 3:
  9718. item.MedChrgitmType = "03"
  9719. break
  9720. case 4:
  9721. item.MedChrgitmType = "03"
  9722. break
  9723. case 5:
  9724. item.MedChrgitmType = "08"
  9725. break
  9726. case 6:
  9727. item.MedChrgitmType = "14"
  9728. break
  9729. case 7:
  9730. item.MedChrgitmType = "14"
  9731. break
  9732. case 8:
  9733. item.MedChrgitmType = "03"
  9734. break
  9735. case 9:
  9736. item.MedChrgitmType = "14"
  9737. break
  9738. case 10:
  9739. item.MedChrgitmType = "14"
  9740. break
  9741. case 11:
  9742. item.MedChrgitmType = "06"
  9743. break
  9744. case 12:
  9745. item.MedChrgitmType = "12"
  9746. break
  9747. case 13:
  9748. item.MedChrgitmType = "01"
  9749. break
  9750. case 14:
  9751. item.MedChrgitmType = "04"
  9752. break
  9753. case 15:
  9754. item.MedChrgitmType = "14"
  9755. break
  9756. }
  9757. } else {
  9758. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9759. case 1:
  9760. item.MedChrgitmType = "14"
  9761. break
  9762. case 2:
  9763. item.MedChrgitmType = "05"
  9764. break
  9765. case 3:
  9766. item.MedChrgitmType = "04"
  9767. break
  9768. case 4:
  9769. item.MedChrgitmType = "14"
  9770. break
  9771. case 5:
  9772. item.MedChrgitmType = "08"
  9773. break
  9774. case 6:
  9775. item.MedChrgitmType = "14"
  9776. break
  9777. case 7:
  9778. item.MedChrgitmType = "14"
  9779. break
  9780. case 8:
  9781. item.MedChrgitmType = "03"
  9782. break
  9783. case 9:
  9784. item.MedChrgitmType = "14"
  9785. break
  9786. }
  9787. }
  9788. } else if item.HisPrescriptionProject.Type == 3 {
  9789. item.MedChrgitmType = "08"
  9790. }
  9791. }
  9792. }
  9793. for _, item := range order_info {
  9794. if org_id == 10215 {
  9795. if item.MedChrgitmType == "01" { //床位费
  9796. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9797. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9798. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9799. }
  9800. if item.MedChrgitmType == "02" { //诊察费
  9801. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9802. //zhenChaCostSelfTotal = zhenChaCostTotal
  9803. }
  9804. if item.MedChrgitmType == "03" { //检查费
  9805. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9806. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9807. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9808. }
  9809. //if item.MedChrgitmType == "02" { //检查费
  9810. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9811. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9812. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9813. //}
  9814. if item.MedChrgitmType == "04" { //化验费
  9815. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9816. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9817. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9818. }
  9819. if item.MedChrgitmType == "05" { //治疗费
  9820. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9821. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9822. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9823. }
  9824. if item.MedChrgitmType == "06" { //手术费
  9825. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9826. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9827. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9828. }
  9829. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9830. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9831. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9832. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9833. }
  9834. if item.MedChrgitmType == "09" { //西药费
  9835. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9836. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9837. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9838. }
  9839. if item.MedChrgitmType == "11" { //中成费
  9840. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9841. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9842. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9843. }
  9844. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9845. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9846. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9847. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9848. }
  9849. } else {
  9850. if item.MedChrgitmType == "01" { //床位费
  9851. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9852. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9853. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9854. }
  9855. //if item.MedChrgitmType == "02" { //诊察费
  9856. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9857. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9858. //}
  9859. if item.MedChrgitmType == "03" { //检查费
  9860. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9861. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9862. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9863. }
  9864. //if item.MedChrgitmType == "02" { //检查费
  9865. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9866. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9867. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9868. //}
  9869. if item.MedChrgitmType == "04" { //化验费
  9870. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9871. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9872. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9873. }
  9874. if item.MedChrgitmType == "05" { //治疗费
  9875. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9876. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9877. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9878. }
  9879. if item.MedChrgitmType == "06" { //手术费
  9880. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9881. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9882. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9883. }
  9884. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9885. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9886. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9887. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9888. }
  9889. if item.MedChrgitmType == "09" { //西药费
  9890. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9891. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9892. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9893. }
  9894. if item.MedChrgitmType == "11" { //中成费
  9895. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9896. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9897. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9898. }
  9899. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9900. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9901. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9902. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9903. }
  9904. }
  9905. }
  9906. c.ServeSuccessJSON(map[string]interface{}{
  9907. "order": order,
  9908. "order_info": order_info,
  9909. "patient": patient,
  9910. "admin_info": adminInfo,
  9911. "his_hospital": record,
  9912. "bedCostTotal": bedCostTotal,
  9913. "operationCostTotal": operationCostTotal,
  9914. "otherCostTotal": otherCostTotal,
  9915. "materialCostTotal": materialCostTotal,
  9916. "westernMedicineCostTotal": westernMedicineCostTotal,
  9917. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9918. "checkCostTotal": checkCostTotal,
  9919. "zhenChaCostTotal": zhenChaCostTotal,
  9920. "laboratoryCostTotal": laboratoryCostTotal,
  9921. "treatCostTotal": treatCostTotal,
  9922. })
  9923. }
  9924. }
  9925. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9926. page, _ := c.GetInt64("page")
  9927. limit, _ := c.GetInt64("limit")
  9928. keywords := c.GetString("keywords")
  9929. start_time := c.GetString("start_time")
  9930. end_time := c.GetString("end_time")
  9931. //clr_type := c.GetString("clr_type")
  9932. insutype := c.GetString("insutype")
  9933. timeLayout := "2006-01-02"
  9934. loc, _ := time.LoadLocation("Local")
  9935. var theStartTIme int64
  9936. if len(start_time) > 0 {
  9937. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9938. theStartTIme = theTime.Unix()
  9939. }
  9940. var theEndtTIme int64
  9941. if len(end_time) > 0 {
  9942. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9943. theEndtTIme = theTime.Unix()
  9944. }
  9945. if page <= 0 {
  9946. page = 1
  9947. }
  9948. if limit <= 0 {
  9949. limit = 10
  9950. }
  9951. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9952. c.ServeSuccessJSON(map[string]interface{}{
  9953. "total": total,
  9954. "list": list,
  9955. })
  9956. return
  9957. }
  9958. func (c *HisApiController) GetPutOnRecordList() {
  9959. page, _ := c.GetInt64("page")
  9960. limit, _ := c.GetInt64("limit")
  9961. keywords := c.GetString("keywords")
  9962. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9963. if page <= 0 {
  9964. page = 1
  9965. }
  9966. if limit <= 0 {
  9967. limit = 10
  9968. }
  9969. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9970. c.ServeSuccessJSON(map[string]interface{}{
  9971. "total": total,
  9972. "list": list,
  9973. })
  9974. return
  9975. }
  9976. func (c *HisApiController) GetCompareData() {
  9977. start_time := c.GetString("start_time")
  9978. end_time := c.GetString("end_time")
  9979. insutype := c.GetString("insutype")
  9980. clr_type := c.GetString("clr_type")
  9981. timeLayout := "2006-01-02"
  9982. loc, _ := time.LoadLocation("Local")
  9983. var theStartTIme int64
  9984. if len(start_time) > 0 {
  9985. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9986. if err != nil {
  9987. theStartTIme = 0
  9988. }
  9989. theStartTIme = theTime.Unix()
  9990. }
  9991. var theEndtTIme int64
  9992. if len(end_time) > 0 {
  9993. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9994. if err != nil {
  9995. theEndtTIme = 0
  9996. }
  9997. theEndtTIme = theTime.Unix()
  9998. }
  9999. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10000. fmt.Println(err)
  10001. if err == nil {
  10002. c.ServeSuccessJSON(map[string]interface{}{
  10003. "list": formData,
  10004. })
  10005. } else {
  10006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10007. return
  10008. }
  10009. }
  10010. func (c *HisApiController) GetFaPiaoData() {
  10011. order_id, _ := c.GetInt64("order_id")
  10012. patient_id, _ := c.GetInt64("patient_id")
  10013. //number := c.GetString("number")
  10014. adminUser := c.GetAdminUserInfo()
  10015. order, _ := service.GetHisOrderByID(order_id)
  10016. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10017. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10018. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10019. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10020. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10021. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10022. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10023. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10024. var bedCostTotal float64 = 0 //床位总费
  10025. var bedCostSelfTotal float64 = 0 //床位自费
  10026. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10027. var operationCostTotal float64 = 0 //手术费
  10028. var operationCostSelfTotal float64 = 0 //手术费
  10029. var operationCostPartSelfTotal float64 = 0 //手术费
  10030. var otherCostTotal float64 = 0 //其他费用
  10031. var otherCostSelfTotal float64 = 0 //其他费用
  10032. var otherCostPartSelfTotal float64 = 0 //其他费用
  10033. var materialCostTotal float64 = 0 //材料费
  10034. var materialCostSelfTotal float64 = 0 //材料费
  10035. var materialCostPartSelfTotal float64 = 0 //材料费
  10036. var westernMedicineCostTotal float64 = 0 //西药费
  10037. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10038. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10039. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10040. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10041. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10042. var checkCostTotal float64 = 0 //检查费
  10043. var checkCostSelfTotal float64 = 0 //检查费
  10044. var checkCostPartSelfTotal float64 = 0 //检查费
  10045. var hiliCostTotal float64 = 0 //护理费
  10046. var hiliCostSelfTotal float64 = 0 //护理费
  10047. var hiliCostPartSelfTotal float64 = 0 //护理费
  10048. var laboratoryCostTotal float64 = 0 //化验费
  10049. var laboratoryCostSelfTotal float64 = 0 //化验费
  10050. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10051. var treatCostTotal float64 = 0 //治疗费用
  10052. var treatCostSelfTotal float64 = 0 //治疗费用
  10053. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10054. var zhenChaCostTotal float64 = 0 //其他费用
  10055. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10056. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10057. decimal.DivisionPrecision = 2
  10058. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10059. var balanceAccountsType int64
  10060. if his.ID > 0 {
  10061. balanceAccountsType = his.BalanceAccountsType
  10062. } else {
  10063. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10064. }
  10065. if balanceAccountsType == 2 {
  10066. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10067. for _, item := range orderInfos_two {
  10068. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10069. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10070. item.MedChrgitmType = "09"
  10071. }
  10072. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10073. if item.HisPrescriptionProject.Type == 2 {
  10074. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10075. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10076. case 0:
  10077. item.MedChrgitmType = "0"
  10078. break
  10079. case 1:
  10080. item.MedChrgitmType = "14"
  10081. break
  10082. case 2:
  10083. item.MedChrgitmType = "05"
  10084. break
  10085. case 3:
  10086. item.MedChrgitmType = "03"
  10087. break
  10088. case 4:
  10089. item.MedChrgitmType = "03"
  10090. break
  10091. case 5:
  10092. item.MedChrgitmType = "08"
  10093. break
  10094. case 6:
  10095. item.MedChrgitmType = "14"
  10096. break
  10097. case 7:
  10098. item.MedChrgitmType = "14"
  10099. break
  10100. case 8:
  10101. item.MedChrgitmType = "03"
  10102. break
  10103. case 9:
  10104. item.MedChrgitmType = "14"
  10105. break
  10106. case 10:
  10107. item.MedChrgitmType = "14"
  10108. break
  10109. case 11:
  10110. item.MedChrgitmType = "06"
  10111. break
  10112. case 12:
  10113. item.MedChrgitmType = "12"
  10114. break
  10115. case 13:
  10116. item.MedChrgitmType = "01"
  10117. break
  10118. case 14:
  10119. item.MedChrgitmType = "04"
  10120. break
  10121. case 15:
  10122. item.MedChrgitmType = "02"
  10123. break
  10124. }
  10125. } else {
  10126. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10127. case 1:
  10128. item.MedChrgitmType = "14"
  10129. break
  10130. case 2:
  10131. item.MedChrgitmType = "05"
  10132. break
  10133. case 3:
  10134. item.MedChrgitmType = "04"
  10135. break
  10136. case 4:
  10137. item.MedChrgitmType = "03"
  10138. break
  10139. case 5:
  10140. item.MedChrgitmType = "08"
  10141. break
  10142. case 6:
  10143. item.MedChrgitmType = "14"
  10144. break
  10145. case 7:
  10146. item.MedChrgitmType = "14"
  10147. break
  10148. case 8:
  10149. item.MedChrgitmType = "03"
  10150. break
  10151. case 9:
  10152. item.MedChrgitmType = "14"
  10153. break
  10154. }
  10155. }
  10156. } else if item.HisPrescriptionProject.Type == 3 {
  10157. item.MedChrgitmType = "08"
  10158. }
  10159. }
  10160. }
  10161. for _, item := range orderInfos_two {
  10162. fmt.Println(item.MedChrgitmType)
  10163. if item.MedChrgitmType == "07" { //床位费
  10164. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10165. hiliCostSelfTotal = hiliCostTotal
  10166. }
  10167. if item.MedChrgitmType == "01" { //床位费
  10168. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10169. bedCostSelfTotal = bedCostTotal
  10170. }
  10171. if item.MedChrgitmType == "02" { //诊察费
  10172. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10173. zhenChaCostSelfTotal = zhenChaCostTotal
  10174. }
  10175. if item.MedChrgitmType == "03" { //检查费
  10176. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10177. checkCostSelfTotal = checkCostTotal
  10178. }
  10179. if item.MedChrgitmType == "04" { //化验费
  10180. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10181. laboratoryCostSelfTotal = laboratoryCostTotal
  10182. }
  10183. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10184. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10185. treatCostSelfTotal = treatCostTotal
  10186. }
  10187. if item.MedChrgitmType == "06" { //手术费
  10188. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10189. operationCostSelfTotal = treatCostTotal
  10190. }
  10191. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10192. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10193. materialCostSelfTotal = materialCostTotal
  10194. }
  10195. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10196. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10197. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10198. }
  10199. if item.MedChrgitmType == "11" { //中成费
  10200. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10201. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10202. }
  10203. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10204. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10205. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10206. otherCostSelfTotal = otherCostTotal
  10207. }
  10208. } else {
  10209. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10210. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10211. otherCostSelfTotal = otherCostTotal
  10212. }
  10213. }
  10214. }
  10215. } else {
  10216. for _, item := range orderInfos {
  10217. if item.MedChrgitmType == "01" { //床位费
  10218. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10219. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10220. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10221. }
  10222. if item.MedChrgitmType == "02" { //诊察费
  10223. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10224. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10225. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10226. }
  10227. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10228. if item.MedChrgitmType == "03" { //检查费
  10229. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10230. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10231. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10232. }
  10233. } else {
  10234. if item.MedChrgitmType == "03" { //检查费
  10235. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10236. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10237. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10238. }
  10239. }
  10240. if item.MedChrgitmType == "04" { //化验费
  10241. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10242. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10243. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10244. }
  10245. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10246. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10247. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10248. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10249. }
  10250. if item.MedChrgitmType == "06" { //手术费
  10251. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10252. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10253. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10254. }
  10255. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10256. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10257. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10258. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10259. }
  10260. if item.MedChrgitmType == "07" { //护理
  10261. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10262. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10263. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10264. }
  10265. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10266. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10267. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10268. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10269. }
  10270. if item.MedChrgitmType == "11" { //中成费
  10271. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10272. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10273. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10274. }
  10275. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10276. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10277. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10278. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10279. }
  10280. }
  10281. }
  10282. timeLayout := "2006-01-02"
  10283. loc, _ := time.LoadLocation("Local")
  10284. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10285. if err != nil {
  10286. }
  10287. startRecordDateTime := startTime.Unix()
  10288. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10289. if err != nil {
  10290. }
  10291. endRecordDateTime := endTime.Unix()
  10292. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10293. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10294. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10295. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10296. c.ServeSuccessJSON(map[string]interface{}{
  10297. "charge_admin_name": charge_admin.UserName,
  10298. "order_number": order.Number, //业务流水号
  10299. "id_card_no": his.IdCardNo, //社会保障号
  10300. "patient": patient,
  10301. "department_name": department.Name, //科室
  10302. "number": his.Number, //门诊号
  10303. "date": order.SettleAccountsDate, //结算日期
  10304. "name": order.PsnName, //姓名
  10305. "gender": patient.Gender, //性别
  10306. "psn_cash_money": order.PsnCashPay, //个人支付
  10307. "pay_way": "门诊", //结算方式
  10308. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10309. "admin_user_name": admin.UserName, //收款员
  10310. "order": order,
  10311. "order_info": orderInfos_two,
  10312. "his": his,
  10313. "bedCostTotal": bedCostTotal,
  10314. "bedCostSelfTotal": bedCostSelfTotal,
  10315. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10316. "operationCostTotal": operationCostTotal,
  10317. "operationCostSelfTotal": operationCostSelfTotal,
  10318. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10319. "otherCostTotal": otherCostTotal,
  10320. "otherCostSelfTotal": otherCostSelfTotal,
  10321. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10322. "materialCostTotal": materialCostTotal,
  10323. "materialCostSelfTotal": materialCostSelfTotal,
  10324. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10325. "westernMedicineCostTotal": westernMedicineCostTotal,
  10326. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10327. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10328. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10329. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10330. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10331. "checkCostTotal": checkCostTotal,
  10332. "checkCostSelfTotal": checkCostSelfTotal,
  10333. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10334. "laboratoryCostTotal": laboratoryCostTotal,
  10335. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10336. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10337. "treatCostTotal": treatCostTotal,
  10338. "treatCostSelfTotal": treatCostSelfTotal,
  10339. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10340. "zhenChaCostTotal": zhenChaCostTotal,
  10341. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10342. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10343. "his_hospital_record": his_hospital_record,
  10344. "pre_pay_money": pre_pay_money,
  10345. "refund_sum": sum,
  10346. "doctor_info": doctor_info,
  10347. "hiliCostTotal": hiliCostTotal,
  10348. "hiliCostSelfTotal": hiliCostSelfTotal,
  10349. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10350. })
  10351. }
  10352. //func (c *HisApiController) GetFaPiaoDatas() {
  10353. // order_ids := c.GetString("order_ids")
  10354. // patient_id, _ := c.GetInt64("patient_id")
  10355. // adminUser := c.GetAdminUserInfo()
  10356. //
  10357. // orders := strings.Split(order_ids, ",")
  10358. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10359. //
  10360. // for _, item := range orders {
  10361. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10362. // order, _ := service.GetHisOrderByID(order_id)
  10363. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10364. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10365. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10366. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10367. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10368. //
  10369. // }
  10370. //
  10371. // var bedCostTotal float64 = 0 //床位总费
  10372. // var bedCostSelfTotal float64 = 0 //床位自费
  10373. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10374. //
  10375. // var operationCostTotal float64 = 0 //手术费
  10376. // var operationCostSelfTotal float64 = 0 //手术费
  10377. // var operationCostPartSelfTotal float64 = 0 //手术费
  10378. //
  10379. // var otherCostTotal float64 = 0 //其他费用
  10380. // var otherCostSelfTotal float64 = 0 //其他费用
  10381. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10382. //
  10383. // var materialCostTotal float64 = 0 //材料费
  10384. // var materialCostSelfTotal float64 = 0 //材料费
  10385. // var materialCostPartSelfTotal float64 = 0 //材料费
  10386. //
  10387. // var westernMedicineCostTotal float64 = 0 //西药费
  10388. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10389. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10390. //
  10391. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10392. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10393. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10394. //
  10395. // var checkCostTotal float64 = 0 //检查费
  10396. // var checkCostSelfTotal float64 = 0 //检查费
  10397. // var checkCostPartSelfTotal float64 = 0 //检查费
  10398. //
  10399. // var laboratoryCostTotal float64 = 0 //化验费
  10400. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10401. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10402. //
  10403. // var treatCostTotal float64 = 0 //治疗费用
  10404. // var treatCostSelfTotal float64 = 0 //治疗费用
  10405. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10406. //
  10407. // var zhenChaCostTotal float64 = 0 //其他费用
  10408. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10409. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10410. //
  10411. // decimal.DivisionPrecision = 2
  10412. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10413. //
  10414. // var balanceAccountsType int64
  10415. // if his.ID > 0 {
  10416. // balanceAccountsType = his.BalanceAccountsType
  10417. // } else {
  10418. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10419. // }
  10420. // if balanceAccountsType == 2 {
  10421. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10422. // for _, item := range orderInfos_two {
  10423. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10424. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10425. // item.MedChrgitmType = "09"
  10426. // }
  10427. //
  10428. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10429. // if item.HisPrescriptionProject.Type == 2 {
  10430. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10431. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10432. // case 0:
  10433. // item.MedChrgitmType = "0"
  10434. // break
  10435. // case 1:
  10436. // item.MedChrgitmType = "14"
  10437. // break
  10438. // case 2:
  10439. // item.MedChrgitmType = "05"
  10440. //
  10441. // break
  10442. // case 3:
  10443. // item.MedChrgitmType = "03"
  10444. //
  10445. // break
  10446. // case 4:
  10447. // item.MedChrgitmType = "03"
  10448. //
  10449. // break
  10450. // case 5:
  10451. // item.MedChrgitmType = "08"
  10452. //
  10453. // break
  10454. // case 6:
  10455. // item.MedChrgitmType = "14"
  10456. //
  10457. // break
  10458. // case 7:
  10459. // item.MedChrgitmType = "14"
  10460. //
  10461. // break
  10462. // case 8:
  10463. // item.MedChrgitmType = "03"
  10464. // break
  10465. // case 9:
  10466. // item.MedChrgitmType = "14"
  10467. // break
  10468. // case 10:
  10469. // item.MedChrgitmType = "14"
  10470. // break
  10471. // case 11:
  10472. // item.MedChrgitmType = "06"
  10473. // break
  10474. // case 12:
  10475. // item.MedChrgitmType = "12"
  10476. // break
  10477. // case 13:
  10478. // item.MedChrgitmType = "01"
  10479. // break
  10480. // case 14:
  10481. // item.MedChrgitmType = "04"
  10482. // break
  10483. // case 15:
  10484. // item.MedChrgitmType = "02"
  10485. // break
  10486. //
  10487. // }
  10488. //
  10489. // } else {
  10490. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10491. //
  10492. // case 1:
  10493. // item.MedChrgitmType = "14"
  10494. // break
  10495. // case 2:
  10496. // item.MedChrgitmType = "05"
  10497. //
  10498. // break
  10499. // case 3:
  10500. // item.MedChrgitmType = "03"
  10501. //
  10502. // break
  10503. // case 4:
  10504. // item.MedChrgitmType = "03"
  10505. //
  10506. // break
  10507. // case 5:
  10508. // item.MedChrgitmType = "08"
  10509. //
  10510. // break
  10511. // case 6:
  10512. // item.MedChrgitmType = "14"
  10513. //
  10514. // break
  10515. // case 7:
  10516. // item.MedChrgitmType = "14"
  10517. //
  10518. // break
  10519. // case 8:
  10520. // item.MedChrgitmType = "03"
  10521. // break
  10522. // case 9:
  10523. // item.MedChrgitmType = "14"
  10524. // break
  10525. //
  10526. // }
  10527. //
  10528. // }
  10529. //
  10530. // } else if item.HisPrescriptionProject.Type == 3 {
  10531. // item.MedChrgitmType = "08"
  10532. // }
  10533. // }
  10534. // }
  10535. //
  10536. // for _, item := range orderInfos_two {
  10537. // fmt.Println(item.MedChrgitmType)
  10538. // if item.MedChrgitmType == "01" { //床位费
  10539. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10540. // bedCostSelfTotal = bedCostTotal
  10541. // }
  10542. //
  10543. // if item.MedChrgitmType == "02" { //诊察费
  10544. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10545. // zhenChaCostSelfTotal = zhenChaCostTotal
  10546. // }
  10547. //
  10548. // if item.MedChrgitmType == "03" { //检查费
  10549. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10550. // checkCostSelfTotal = checkCostTotal
  10551. // }
  10552. //
  10553. // if item.MedChrgitmType == "04" { //化验费
  10554. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10555. // laboratoryCostSelfTotal = laboratoryCostTotal
  10556. // }
  10557. //
  10558. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10559. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10560. // treatCostSelfTotal = treatCostTotal
  10561. // }
  10562. //
  10563. // if item.MedChrgitmType == "06" { //手术费
  10564. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10565. // operationCostSelfTotal = treatCostTotal
  10566. // }
  10567. //
  10568. // if item.MedChrgitmType == "08" { //材料费
  10569. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10570. // materialCostSelfTotal = materialCostTotal
  10571. // }
  10572. //
  10573. // if item.MedChrgitmType == "09" { //西药费
  10574. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10575. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10576. // }
  10577. //
  10578. // if item.MedChrgitmType == "11" { //中成费
  10579. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10580. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10581. // }
  10582. //
  10583. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10584. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10585. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10586. // otherCostSelfTotal = otherCostTotal
  10587. // }
  10588. // } else {
  10589. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10590. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10591. // otherCostSelfTotal = otherCostTotal
  10592. // }
  10593. //
  10594. // }
  10595. //
  10596. // }
  10597. //
  10598. // } else {
  10599. // for _, item := range orderInfos {
  10600. // if item.MedChrgitmType == "01" { //床位费
  10601. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10602. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10603. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10604. // }
  10605. //
  10606. // if item.MedChrgitmType == "02" { //诊察费
  10607. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10608. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10609. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10610. // }
  10611. //
  10612. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10613. // if item.MedChrgitmType == "03" { //检查费
  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. // }
  10619. // } else {
  10620. // if item.MedChrgitmType == "03" { //检查费
  10621. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10622. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10623. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10624. // }
  10625. //
  10626. // }
  10627. //
  10628. // if item.MedChrgitmType == "04" { //化验费
  10629. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10630. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10631. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10632. //
  10633. // }
  10634. //
  10635. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10636. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10637. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10638. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10639. //
  10640. // }
  10641. //
  10642. // if item.MedChrgitmType == "06" { //手术费
  10643. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10644. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10645. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10646. // }
  10647. //
  10648. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10649. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10650. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10651. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10652. // }
  10653. //
  10654. // if item.MedChrgitmType == "09" { //西药费
  10655. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10656. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10657. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10658. // }
  10659. //
  10660. // if item.MedChrgitmType == "11" { //中成费
  10661. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10662. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10663. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10664. // }
  10665. //
  10666. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10667. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10668. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10669. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10670. // }
  10671. //
  10672. // }
  10673. // }
  10674. // timeLayout := "2006-01-02"
  10675. // loc, _ := time.LoadLocation("Local")
  10676. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10677. // if err != nil {
  10678. // }
  10679. // startRecordDateTime := startTime.Unix()
  10680. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10681. // if err != nil {
  10682. // }
  10683. // endRecordDateTime := endTime.Unix()
  10684. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10685. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10686. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10687. //
  10688. // c.ServeSuccessJSON(map[string]interface{}{
  10689. // "order_number": order.Number, //业务流水号
  10690. // "id_card_no": his.IdCardNo, //社会保障号
  10691. // "department_name": department.Name, //科室
  10692. // "number": his.Number, //门诊号
  10693. // "date": order.SettleAccountsDate, //结算日期
  10694. // "name": order.PsnName, //姓名
  10695. // "gender": patient.Gender, //性别
  10696. // "psn_cash_money": order.PsnCashPay, //个人支付
  10697. // "pay_way": "门诊", //结算方式
  10698. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10699. // "admin_user_name": admin.UserName, //收款员
  10700. // "order": order,
  10701. // "order_info": orderInfos_two,
  10702. // "his": his,
  10703. // "bedCostTotal": bedCostTotal,
  10704. // "bedCostSelfTotal": bedCostSelfTotal,
  10705. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10706. // "operationCostTotal": operationCostTotal,
  10707. // "operationCostSelfTotal": operationCostSelfTotal,
  10708. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10709. // "otherCostTotal": otherCostTotal,
  10710. // "otherCostSelfTotal": otherCostSelfTotal,
  10711. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10712. // "materialCostTotal": materialCostTotal,
  10713. // "materialCostSelfTotal": materialCostSelfTotal,
  10714. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10715. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10716. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10717. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10718. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10719. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10720. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10721. // "checkCostTotal": checkCostTotal,
  10722. // "checkCostSelfTotal": checkCostSelfTotal,
  10723. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10724. // "laboratoryCostTotal": laboratoryCostTotal,
  10725. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10726. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10727. // "treatCostTotal": treatCostTotal,
  10728. // "treatCostSelfTotal": treatCostSelfTotal,
  10729. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10730. // "zhenChaCostTotal": zhenChaCostTotal,
  10731. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10732. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10733. // "his_hospital_record": his_hospital_record,
  10734. // "pre_pay_money": pre_pay_money,
  10735. // "refund_sum": sum,
  10736. // })
  10737. //
  10738. //}
  10739. func (this *HisApiController) GetIncomeStatisticsData() {
  10740. start_time := this.GetString("start_time")
  10741. end_time := this.GetString("end_time")
  10742. key_words := this.GetString("key_words")
  10743. limit, _ := this.GetInt64("limit")
  10744. page, _ := this.GetInt64("page")
  10745. if page <= 0 {
  10746. page = 1
  10747. }
  10748. if limit <= 0 {
  10749. limit = 10
  10750. }
  10751. statistics_type, _ := this.GetInt64("statistics_type")
  10752. admin := this.GetAdminUserInfo()
  10753. timeLayout := "2006-01-02"
  10754. loc, _ := time.LoadLocation("Local")
  10755. var theStartTIme int64
  10756. if len(start_time) > 0 {
  10757. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10758. if err != nil {
  10759. theStartTIme = 0
  10760. }
  10761. theStartTIme = theTime.Unix()
  10762. }
  10763. var theEndtTIme int64
  10764. if len(end_time) > 0 {
  10765. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10766. if err != nil {
  10767. theEndtTIme = 0
  10768. }
  10769. theEndtTIme = theTime.Unix()
  10770. }
  10771. if statistics_type == 1 {
  10772. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10773. this.ServeSuccessJSON(map[string]interface{}{
  10774. "list": list,
  10775. "total": total,
  10776. })
  10777. } else {
  10778. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10779. this.ServeSuccessJSON(map[string]interface{}{
  10780. "list": list,
  10781. "total": total,
  10782. })
  10783. }
  10784. }
  10785. func (c *HisApiController) PostProjectInformation() {
  10786. adminUser := c.GetAdminUserInfo()
  10787. orgId := adminUser.CurrentOrgId
  10788. dataBody := make(map[string]interface{}, 0)
  10789. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10790. if err != nil {
  10791. utils.ErrorLog(err.Error())
  10792. return
  10793. }
  10794. utils.ErrorLog("%v", dataBody)
  10795. var projectList []*models.HisProject
  10796. var total_goods []interface{}
  10797. tempProjects := dataBody["projects"].([]interface{})
  10798. total_goods = tempProjects
  10799. for index, projectMap := range tempProjects {
  10800. projectM := projectMap.(map[string]interface{})
  10801. var project models.HisProject
  10802. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10803. utils.ErrorLog("project_name")
  10804. return
  10805. }
  10806. project_name, _ := projectM["project_name"].(string)
  10807. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10808. err_log := models.ExportErrLog{
  10809. LogType: 6,
  10810. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10811. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10812. Status: 1,
  10813. CreateTime: time.Now().Unix(),
  10814. UpdateTime: time.Now().Unix(),
  10815. ExportTime: time.Now().Unix(),
  10816. }
  10817. service.CreateExportErrLog(&err_log)
  10818. continue
  10819. }
  10820. project.ProjectName = project_name
  10821. prices := projectM["price"].(string)
  10822. price, _ := strconv.ParseFloat(prices, 64)
  10823. if price <= 0 { //名字为空则生成一条导入错误日志
  10824. err_log := models.ExportErrLog{
  10825. LogType: 6,
  10826. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10827. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10828. Status: 1,
  10829. CreateTime: time.Now().Unix(),
  10830. UpdateTime: time.Now().Unix(),
  10831. ExportTime: time.Now().Unix(),
  10832. }
  10833. service.CreateExportErrLog(&err_log)
  10834. continue
  10835. }
  10836. project.Price = price
  10837. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10838. utils.ErrorLog("unit_id")
  10839. return
  10840. }
  10841. unit := projectM["unit"].(string)
  10842. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10843. err_log := models.ExportErrLog{
  10844. LogType: 6,
  10845. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10846. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10847. Status: 1,
  10848. CreateTime: time.Now().Unix(),
  10849. UpdateTime: time.Now().Unix(),
  10850. ExportTime: time.Now().Unix(),
  10851. }
  10852. service.CreateExportErrLog(&err_log)
  10853. continue
  10854. }
  10855. project.Unit = unit
  10856. cost_classify := projectM["cost_classify"].(string)
  10857. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10858. err_log := models.ExportErrLog{
  10859. LogType: 6,
  10860. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10861. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10862. Status: 1,
  10863. CreateTime: time.Now().Unix(),
  10864. UpdateTime: time.Now().Unix(),
  10865. ExportTime: time.Now().Unix(),
  10866. }
  10867. service.CreateExportErrLog(&err_log)
  10868. continue
  10869. }
  10870. var costClassify = "费用类别"
  10871. var cost_classify_id int64
  10872. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10873. if len(cost_classify) != 0 {
  10874. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10875. if errcode == gorm.ErrRecordNotFound {
  10876. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10877. dataconfig := models.DictDataconfig{
  10878. ParentId: costClassifyConfig.ID,
  10879. Module: "system",
  10880. OrgId: orgId,
  10881. Name: cost_classify,
  10882. FieldName: "",
  10883. Value: costConfig.Value + 1,
  10884. CreatedTime: "",
  10885. UpdatedTime: "",
  10886. CreateUserId: adminUser.AdminUser.Id,
  10887. Status: 1,
  10888. Remark: "",
  10889. DeleteIdSystem: 0,
  10890. Title: "",
  10891. Content: "",
  10892. Order: 0,
  10893. Code: "",
  10894. }
  10895. service.CreatedDicConfig(&dataconfig)
  10896. }
  10897. }
  10898. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10899. for _, it := range costClassList {
  10900. if cost_classify == it.Name {
  10901. cost_classify_id = int64(it.Value)
  10902. }
  10903. }
  10904. project.CostClassify = cost_classify_id
  10905. executive_section := projectM["executive_section"].(string)
  10906. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10907. err_log := models.ExportErrLog{
  10908. LogType: 6,
  10909. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10910. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10911. Status: 1,
  10912. CreateTime: time.Now().Unix(),
  10913. UpdateTime: time.Now().Unix(),
  10914. ExportTime: time.Now().Unix(),
  10915. }
  10916. service.CreateExportErrLog(&err_log)
  10917. continue
  10918. }
  10919. if len(executive_section) != 0 {
  10920. //查找科室是否有内容
  10921. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10922. if errcodedepart == gorm.ErrRecordNotFound {
  10923. department := models.XtHisDepartment{
  10924. Name: executive_section,
  10925. Status: 1,
  10926. UserOrgId: adminUser.CurrentOrgId,
  10927. CreatedTime: time.Now().Unix(),
  10928. }
  10929. service.CreateDePartment(&department)
  10930. }
  10931. }
  10932. var executive_section_id int64
  10933. departMentList, _ := service.GetAllDepartMent(orgId)
  10934. for _, it := range departMentList {
  10935. if executive_section == it.Name {
  10936. executive_section_id = it.ID
  10937. }
  10938. }
  10939. project.ExecutiveSection = executive_section_id
  10940. medical_coverage := projectM["medical_coverage"].(string)
  10941. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10942. err_log := models.ExportErrLog{
  10943. LogType: 6,
  10944. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10945. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10946. Status: 1,
  10947. CreateTime: time.Now().Unix(),
  10948. UpdateTime: time.Now().Unix(),
  10949. ExportTime: time.Now().Unix(),
  10950. }
  10951. service.CreateExportErrLog(&err_log)
  10952. continue
  10953. }
  10954. var medicalCoverage = "医保等级"
  10955. var medical_coverage_id int64
  10956. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10957. if len(medical_coverage) != 0 {
  10958. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10959. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10960. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10961. dataconfig := models.DictDataconfig{
  10962. ParentId: medicalCoverageConfig.ID,
  10963. Module: "system",
  10964. OrgId: orgId,
  10965. Name: medical_coverage,
  10966. FieldName: "",
  10967. Value: medicalCoverageConfig.Value + 1,
  10968. CreatedTime: "",
  10969. UpdatedTime: "",
  10970. CreateUserId: adminUser.AdminUser.Id,
  10971. Status: 1,
  10972. Remark: "",
  10973. DeleteIdSystem: 0,
  10974. Title: "",
  10975. Content: "",
  10976. Order: 0,
  10977. Code: "",
  10978. }
  10979. service.CreatedDicConfig(&dataconfig)
  10980. }
  10981. }
  10982. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10983. for _, it := range medicalCoverageList {
  10984. if medical_coverage == it.Name {
  10985. medical_coverage_id = int64(it.Value)
  10986. }
  10987. }
  10988. project.MedicalCoverage = medical_coverage_id
  10989. pinyin := projectM["pinyin"].(string)
  10990. project.Pinyin = pinyin
  10991. wubi := projectM["wubi"].(string)
  10992. project.Wubi = wubi
  10993. statistical_classification := projectM["statistical_classification"].(string)
  10994. var statisticalClassification = "统计分类"
  10995. var statistical_classification_id int64
  10996. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10997. if len(statistical_classification) != 0 {
  10998. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10999. if classificationerrcodes == gorm.ErrRecordNotFound {
  11000. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11001. dataconfig := models.DictDataconfig{
  11002. ParentId: classiFication.ID,
  11003. Module: "system",
  11004. OrgId: orgId,
  11005. Name: statistical_classification,
  11006. FieldName: "",
  11007. Value: classiFicationConfig.Value + 1,
  11008. CreatedTime: "",
  11009. UpdatedTime: "",
  11010. CreateUserId: adminUser.AdminUser.Id,
  11011. Status: 1,
  11012. Remark: "",
  11013. DeleteIdSystem: 0,
  11014. Title: "",
  11015. Content: "",
  11016. Order: 0,
  11017. Code: "",
  11018. }
  11019. service.CreatedDicConfig(&dataconfig)
  11020. }
  11021. }
  11022. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11023. for _, it := range classiFicationList {
  11024. if statistical_classification == it.Name {
  11025. statistical_classification_id = int64(it.Value)
  11026. }
  11027. }
  11028. project.StatisticalClassification = statistical_classification_id
  11029. disease_directory := int64(projectM["disease_directory"].(float64))
  11030. project.DiseaseDirectory = disease_directory
  11031. is_record := int64(projectM["is_record"].(float64))
  11032. project.IsRecord = is_record
  11033. medical_code := projectM["medical_code"].(string)
  11034. project.MedicalCode = medical_code
  11035. tube_color := projectM["tube_color"].(string)
  11036. var tubeColor = "试管颜色"
  11037. var tube_color_id int64
  11038. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11039. if len(tube_color) != 0 {
  11040. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11041. if errcodetube == gorm.ErrRecordNotFound {
  11042. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11043. dataconfig := models.DictDataconfig{
  11044. ParentId: tubeColorConfig.ID,
  11045. Module: "system",
  11046. OrgId: orgId,
  11047. Name: tube_color,
  11048. FieldName: "",
  11049. Value: tubeConfig.Value + 1,
  11050. CreatedTime: "",
  11051. UpdatedTime: "",
  11052. CreateUserId: adminUser.AdminUser.Id,
  11053. Status: 1,
  11054. Remark: "",
  11055. DeleteIdSystem: 0,
  11056. Title: "",
  11057. Content: "",
  11058. Order: 0,
  11059. Code: "",
  11060. }
  11061. service.CreatedDicConfig(&dataconfig)
  11062. }
  11063. }
  11064. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11065. for _, it := range tubeColorList {
  11066. if tube_color == it.Name {
  11067. tube_color_id = int64(it.Value)
  11068. }
  11069. }
  11070. project.TubeColor = tube_color_id
  11071. single_dose := projectM["single_dose"].(string)
  11072. project.SingleDose = single_dose
  11073. execution_frequency := projectM["execution_frequency"].(string)
  11074. project.ExecutionFrequency = execution_frequency
  11075. delivery_way := projectM["delivery_way"].(string)
  11076. project.DeliveryWay = delivery_way
  11077. number_days := projectM["number_days"].(string)
  11078. project.NumberDays = number_days
  11079. total := projectM["total"].(string)
  11080. project.Total = total
  11081. medical_status := int64(projectM["medical_status"].(float64))
  11082. project.MedicalStatus = medical_status
  11083. category := int64(projectM["category"].(float64))
  11084. project.Category = category
  11085. specail_project := int64(projectM["specail_project"].(float64))
  11086. project.SpecailProject = specail_project
  11087. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11088. project.SocialSecurityDirectoryCode = social_security_directory_code
  11089. remark := projectM["remark"].(string)
  11090. project.Remark = remark
  11091. record_date := projectM["record_date"].(string)
  11092. timeLayout := "2006-01-02"
  11093. loc, _ := time.LoadLocation("Local")
  11094. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11095. project.RecordDate = theTime.Unix()
  11096. projectList = append(projectList, &project)
  11097. }
  11098. export_time := time.Now().Unix()
  11099. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11100. if len(projectList) > 0 {
  11101. for _, item := range projectList {
  11102. hans := item.ProjectName // 要转换的汉字字符串
  11103. // 创建一个拼音转换器
  11104. p := pinyin.NewArgs()
  11105. // 将汉字转为拼音
  11106. pinyinSlice := pinyin.Pinyin(hans, p)
  11107. // 输出拼音
  11108. fmt.Println("Pinyin:", pinyinSlice)
  11109. // 获取首字母
  11110. firstLetter := ""
  11111. for _, py := range pinyinSlice {
  11112. if len(py) > 0 {
  11113. firstLetter += string(py[0][0])
  11114. }
  11115. }
  11116. item.FirstLetter = firstLetter
  11117. project := models.HisProject{
  11118. ProjectName: item.ProjectName,
  11119. Price: item.Price,
  11120. Unit: item.Unit,
  11121. CostClassify: item.CostClassify,
  11122. ExecutiveSection: item.ExecutiveSection,
  11123. MedicalCoverage: item.MedicalCoverage,
  11124. UserOrgId: orgId,
  11125. Status: 1,
  11126. CreatedTime: time.Now().Unix(),
  11127. Pinyin: item.Pinyin,
  11128. Wubi: item.Wubi,
  11129. StatisticalClassification: item.StatisticalClassification,
  11130. DiseaseDirectory: item.DiseaseDirectory,
  11131. IsRecord: item.IsRecord,
  11132. MedicalCode: item.MedicalCode,
  11133. TubeColor: item.TubeColor,
  11134. SingleDose: item.SingleDose,
  11135. DeliveryWay: item.DeliveryWay,
  11136. NumberDays: item.NumberDays,
  11137. Total: item.Total,
  11138. Category: item.Category,
  11139. MedicalStatus: item.MedicalStatus,
  11140. SpecailProject: item.SpecailProject,
  11141. RecordDate: item.RecordDate,
  11142. Remark: item.Remark,
  11143. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11144. ExecutionFrequency: item.ExecutionFrequency,
  11145. FirstLetter: item.FirstLetter,
  11146. }
  11147. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11148. if errcodeproject == gorm.ErrRecordNotFound {
  11149. service.CreateProjectInfomation(&project)
  11150. } else if errcodeproject == nil {
  11151. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11152. }
  11153. log := models.ExportLog{
  11154. LogType: 6,
  11155. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11156. TotalNum: int64(len(total_goods)),
  11157. FailNum: int64(len(errLogs)),
  11158. SuccessNum: int64(len(projectList)),
  11159. CreateTime: time.Now().Unix(),
  11160. UpdateTime: time.Now().Unix(),
  11161. ExportTime: export_time,
  11162. Status: 1,
  11163. }
  11164. service.CreateExportLog(&log)
  11165. c.ServeSuccessJSON(map[string]interface{}{
  11166. "msg": "导入成功",
  11167. "total_num": len(total_goods),
  11168. "success_num": len(projectList),
  11169. "fail_num": int64(len(errLogs)),
  11170. })
  11171. }
  11172. } else {
  11173. log := models.ExportLog{
  11174. LogType: 6,
  11175. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11176. TotalNum: int64(len(total_goods)),
  11177. FailNum: int64(len(errLogs)),
  11178. SuccessNum: int64(len(projectList)),
  11179. CreateTime: time.Now().Unix(),
  11180. UpdateTime: time.Now().Unix(),
  11181. ExportTime: export_time,
  11182. Status: 1,
  11183. }
  11184. service.CreateExportLog(&log)
  11185. c.ServeSuccessJSON(map[string]interface{}{
  11186. "msg": "导入成功",
  11187. "total_num": len(total_goods),
  11188. "success_num": len(projectList),
  11189. "fail_num": int64(len(errLogs)),
  11190. })
  11191. }
  11192. }
  11193. //func (this *HisApiController) EditProjectInformation(){
  11194. //
  11195. // id, _ := this.GetInt64("id")
  11196. // project_team := this.GetString("project_team")
  11197. // price := this.GetString("price")
  11198. // price_float, _ := strconv.ParseFloat(price, 64)
  11199. // pinyin := this.GetString("pinyin")
  11200. // wubi := this.GetString("wubi")
  11201. // tube_color, _ := this.GetInt64("tube_color")
  11202. // team_type, _ := this.GetInt64("team_type")
  11203. // remark := this.GetString("remark")
  11204. // ids := this.GetString("ids")
  11205. // item_id := this.GetString("item_id")
  11206. // projectTeam := models.XtHisProjectTeam{
  11207. // ProjectTeam: project_team,
  11208. // Price: price_float,
  11209. // Pinyin: pinyin,
  11210. // Wubi: wubi,
  11211. // TubeColor: tube_color,
  11212. // TeamType: team_type,
  11213. // Remark: remark,
  11214. // ProjectId: ids,
  11215. // ItemId: item_id,
  11216. // }
  11217. //
  11218. //
  11219. // dataBody := make(map[string]interface{}, 0)
  11220. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11221. // if err != nil {
  11222. // utils.ErrorLog(err.Error())
  11223. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11224. // return
  11225. // }
  11226. //
  11227. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11228. //
  11229. //
  11230. // if err != nil {
  11231. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11232. // return
  11233. // }
  11234. //
  11235. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11236. // infos, _ := dataBody["info"].([]interface{})
  11237. // if len(infos) > 0 {
  11238. // var ids []string
  11239. //
  11240. // for _, item := range infos {
  11241. // items := item.(map[string]interface{})
  11242. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11243. // utils.ErrorLog("id")
  11244. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11245. // return
  11246. // }
  11247. // id := int64(items["id"].(float64))
  11248. //
  11249. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11250. // utils.ErrorLog("type")
  11251. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11252. // return
  11253. // }
  11254. // types := int64(items["type"].(float64))
  11255. //
  11256. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11257. // utils.ErrorLog("number")
  11258. // }
  11259. //
  11260. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11261. //
  11262. // projectList := models.XtHisProjectList{
  11263. // Number: number,
  11264. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11265. // ProjectId: id,
  11266. // Status: 1,
  11267. // CreatedTime: time.Now().Unix(),
  11268. // UpdatedTime: time.Now().Unix(),
  11269. // TeamId: projectTeam.ID,
  11270. // Type: types,
  11271. // }
  11272. // list := projectList
  11273. //
  11274. // service.CreateProjectList(&list)
  11275. //
  11276. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11277. //
  11278. // }
  11279. // ids_str := strings.Join(ids, ",")
  11280. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11281. // service.SaveProjectTeam(&projectTeam)
  11282. // this.ServeSuccessJSON(map[string]interface{}{
  11283. // "projectTeam": projectTeam,
  11284. // })
  11285. // }
  11286. // }
  11287. //}
  11288. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11289. name := c.GetString("name")
  11290. mode_id, _ := c.GetInt64("mode", 0)
  11291. types, _ := c.GetInt64("type", 0)
  11292. patient_id, _ := c.GetInt64("patient_id", 0)
  11293. types = 1
  11294. adminInfo := c.GetAdminUserInfo()
  11295. template := &models.HisPrescriptionTemplate{
  11296. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11297. PatientId: patient_id,
  11298. Type: types,
  11299. Status: 1,
  11300. Ctime: time.Now().Unix(),
  11301. Mtime: time.Now().Unix(),
  11302. Name: name,
  11303. Mode: mode_id,
  11304. }
  11305. dataBody := make(map[string]interface{}, 0)
  11306. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11307. if err != nil {
  11308. utils.ErrorLog(err.Error())
  11309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11310. return
  11311. }
  11312. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11313. //如果已经存在记录则删除处方
  11314. if template_one.ID > 0 {
  11315. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11316. var ids []int64
  11317. var org_id int64
  11318. for _, item := range ps {
  11319. org_id = c.GetAdminUserInfo().CurrentOrgId
  11320. ids = append(ids, item.ID)
  11321. }
  11322. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11323. if err2 == nil {
  11324. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11325. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11326. if len(prescriptions) > 0 {
  11327. for _, item := range prescriptions {
  11328. items := item.(map[string]interface{})
  11329. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11330. utils.ErrorLog("type")
  11331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11332. return
  11333. }
  11334. types := int64(items["type"].(float64))
  11335. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11336. utils.ErrorLog("med_type")
  11337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11338. return
  11339. }
  11340. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11341. ctime := time.Now().Unix()
  11342. prescription := &models.HisPrescriptionInfoTemplate{
  11343. PatientId: patient_id,
  11344. UserOrgId: adminInfo.CurrentOrgId,
  11345. Ctime: ctime,
  11346. Mtime: ctime,
  11347. Type: types,
  11348. Modifier: adminInfo.AdminUser.Id,
  11349. Creator: adminInfo.AdminUser.Id,
  11350. Status: 1,
  11351. PTemplateId: template_one.ID,
  11352. MedType: med_type,
  11353. }
  11354. service.CreateHisPrescriptionInfoTemplate(prescription)
  11355. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11356. advices := items["advices"].([]interface{})
  11357. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11358. ctime := time.Now().Unix()
  11359. mtime := ctime
  11360. if len(advices) > 0 {
  11361. for _, advice := range advices {
  11362. var s models.HisPrescriptionAdviceTemplate
  11363. s.PrescriptionId = prescription.ID
  11364. s.AdviceType = 2
  11365. s.StopState = 2
  11366. s.ExecutionState = 2
  11367. s.Status = 1
  11368. s.UserOrgId = adminInfo.CurrentOrgId
  11369. s.CreatedTime = ctime
  11370. s.UpdatedTime = mtime
  11371. s.PatientId = patient_id
  11372. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11373. if errcode > 0 {
  11374. c.ServeFailJSONWithSGJErrorCode(errcode)
  11375. return
  11376. }
  11377. service.CreateHisPrescriptionAdviceTemplate(&s)
  11378. }
  11379. }
  11380. }
  11381. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11382. projects := items["project"].([]interface{})
  11383. if len(projects) > 0 {
  11384. for _, project := range projects {
  11385. var p models.HisPrescriptionProjectTemplate
  11386. p.PrescriptionId = prescription.ID
  11387. p.Ctime = time.Now().Unix()
  11388. p.Mtime = time.Now().Unix()
  11389. p.PatientId = patient_id
  11390. p.UserOrgId = adminInfo.CurrentOrgId
  11391. p.Status = 1
  11392. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11393. if errcode > 0 {
  11394. c.ServeFailJSONWithSGJErrorCode(errcode)
  11395. return
  11396. }
  11397. service.CreateHisPrescriptionProjectTemplate(&p)
  11398. }
  11399. }
  11400. }
  11401. }
  11402. c.ServeSuccessJSON(map[string]interface{}{
  11403. "msg": "创建成功",
  11404. })
  11405. }
  11406. }
  11407. } else {
  11408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11409. return
  11410. }
  11411. } else {
  11412. err3 := service.CreateHisPrescriptionTemplate(template)
  11413. if err3 == nil {
  11414. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11415. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11416. if len(prescriptions) > 0 {
  11417. for _, item := range prescriptions {
  11418. items := item.(map[string]interface{})
  11419. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11420. utils.ErrorLog("type")
  11421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11422. return
  11423. }
  11424. types := int64(items["type"].(float64))
  11425. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11426. utils.ErrorLog("med_type")
  11427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11428. return
  11429. }
  11430. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11431. ctime := time.Now().Unix()
  11432. prescription := &models.HisPrescriptionInfoTemplate{
  11433. PatientId: patient_id,
  11434. UserOrgId: adminInfo.CurrentOrgId,
  11435. Ctime: ctime,
  11436. Mtime: ctime,
  11437. Type: types,
  11438. Modifier: adminInfo.AdminUser.Id,
  11439. Creator: adminInfo.AdminUser.Id,
  11440. Status: 1,
  11441. PTemplateId: template.ID,
  11442. MedType: med_type,
  11443. }
  11444. service.CreateHisPrescriptionInfoTemplate(prescription)
  11445. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11446. advices := items["advices"].([]interface{})
  11447. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11448. ctime := time.Now().Unix()
  11449. mtime := ctime
  11450. if len(advices) > 0 {
  11451. for _, advice := range advices {
  11452. var s models.HisPrescriptionAdviceTemplate
  11453. s.PrescriptionId = prescription.ID
  11454. s.AdviceType = 2
  11455. s.StopState = 2
  11456. s.ExecutionState = 2
  11457. s.Status = 1
  11458. s.UserOrgId = adminInfo.CurrentOrgId
  11459. s.CreatedTime = ctime
  11460. s.UpdatedTime = mtime
  11461. s.PatientId = patient_id
  11462. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11463. if errcode > 0 {
  11464. c.ServeFailJSONWithSGJErrorCode(errcode)
  11465. return
  11466. }
  11467. service.CreateHisPrescriptionAdviceTemplate(&s)
  11468. }
  11469. }
  11470. }
  11471. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11472. projects := items["project"].([]interface{})
  11473. if len(projects) > 0 {
  11474. for _, project := range projects {
  11475. var p models.HisPrescriptionProjectTemplate
  11476. p.PrescriptionId = prescription.ID
  11477. p.Ctime = time.Now().Unix()
  11478. p.Mtime = time.Now().Unix()
  11479. p.PatientId = patient_id
  11480. p.UserOrgId = adminInfo.CurrentOrgId
  11481. p.Status = 1
  11482. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11483. if errcode > 0 {
  11484. c.ServeFailJSONWithSGJErrorCode(errcode)
  11485. return
  11486. }
  11487. service.CreateHisPrescriptionProjectTemplate(&p)
  11488. }
  11489. }
  11490. }
  11491. }
  11492. c.ServeSuccessJSON(map[string]interface{}{
  11493. "msg": "创建成功",
  11494. })
  11495. }
  11496. }
  11497. } else {
  11498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11499. return
  11500. }
  11501. }
  11502. }
  11503. func (c *HisApiController) PreSettle() {
  11504. id, _ := c.GetInt64("id")
  11505. record_time := c.GetString("record_time")
  11506. his_patient_id, _ := c.GetInt64("his_patient_id")
  11507. timeLayout := "2006-01-02"
  11508. loc, _ := time.LoadLocation("Local")
  11509. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11510. diagnosis_id := c.GetString("diagnosis")
  11511. sick_type, _ := c.GetInt64("sick_type")
  11512. reg_type, _ := c.GetInt64("p_type")
  11513. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11514. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11515. if err != nil {
  11516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11517. return
  11518. }
  11519. recordDateTime := theTime.Unix()
  11520. adminUser := c.GetAdminUserInfo()
  11521. var prescriptions []*models.HisPrescription
  11522. var start_time int64
  11523. var end_time int64
  11524. ids_str := c.GetString("ids")
  11525. ids_arr := strings.Split(ids_str, ",")
  11526. fmt.Println(reg_type)
  11527. if settle_accounts_type == 1 { //日结
  11528. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11529. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11530. } else {
  11531. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11532. }
  11533. fmt.Println(prescriptions)
  11534. } else { //月结
  11535. start_time_str := c.GetString("start_time")
  11536. end_time_str := c.GetString("end_time")
  11537. timeLayout := "2006-01-02"
  11538. loc, _ := time.LoadLocation("Local")
  11539. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11540. if err != nil {
  11541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11542. return
  11543. }
  11544. recordStartTime := theStartTime.Unix()
  11545. start_time = recordStartTime
  11546. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11547. if err != nil {
  11548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11549. return
  11550. }
  11551. recordEndTime := theEndTime.Unix()
  11552. end_time = recordEndTime
  11553. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11554. }
  11555. if reg_type == 1111 || reg_type == 1112 {
  11556. reg_type = 11
  11557. }
  11558. timestamp := time.Now().Unix()
  11559. tempTime := time.Unix(timestamp, 0)
  11560. timeFormat := tempTime.Format("20060102150405")
  11561. chrgBchno := rand.Intn(100000) + 10000
  11562. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11563. strconv.FormatInt(his.PatientId, 10)
  11564. var ids []int64
  11565. for _, item := range prescriptions {
  11566. ids = append(ids, item.ID)
  11567. }
  11568. fmt.Println(ids)
  11569. var total float64
  11570. for _, item := range prescriptions {
  11571. fmt.Println(item)
  11572. if item.Type == 1 { //药品
  11573. for _, subItem := range item.HisDoctorAdviceInfo {
  11574. total = total + (subItem.Price * subItem.PrescribingNumber)
  11575. }
  11576. }
  11577. if item.Type == 2 { //项目
  11578. for _, subItem := range item.HisPrescriptionProject {
  11579. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11580. total = total + (subItem.Price * cnt)
  11581. }
  11582. }
  11583. for _, subItem := range item.HisAdditionalCharge {
  11584. total = total + (subItem.Price * float64(subItem.Count))
  11585. }
  11586. }
  11587. allTotal := fmt.Sprintf("%.2f", total)
  11588. totals, _ := strconv.ParseFloat(allTotal, 64)
  11589. order := &models.HisOrder{
  11590. UserOrgId: adminUser.CurrentOrgId,
  11591. HisPatientId: his.ID,
  11592. PatientId: id,
  11593. SettleAccountsDate: recordDateTime,
  11594. Ctime: time.Now().Unix(),
  11595. Mtime: time.Now().Unix(),
  11596. Status: 1,
  11597. OrderStatus: 1,
  11598. MdtrtId: his.Number,
  11599. Number: chrg_bchno,
  11600. MedfeeSumamt: totals,
  11601. SettleEndTime: end_time,
  11602. SettleStartTime: start_time,
  11603. SettleType: settle_accounts_type,
  11604. PsnPartAmt: totals,
  11605. PsnCashPay: totals,
  11606. PType: 2,
  11607. IsPre: 1,
  11608. MedType: strconv.Itoa(int(reg_type)),
  11609. Diagnosis: diagnosis_id,
  11610. }
  11611. err = service.CreateOrder(order)
  11612. if err != nil {
  11613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11614. return
  11615. }
  11616. var customs []*Custom
  11617. for _, item := range prescriptions {
  11618. fmt.Println(item.Type)
  11619. if item.Type == 1 { //药品
  11620. for _, subItem := range item.HisDoctorAdviceInfo {
  11621. cus := &Custom{
  11622. AdviceId: subItem.ID,
  11623. ProjectId: 0,
  11624. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11625. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11626. FeedetlSn: subItem.FeedetlSn,
  11627. Price: fmt.Sprintf("%.2f", subItem.Price),
  11628. MedListCodg: subItem.MedListCodg,
  11629. Type: 1,
  11630. }
  11631. customs = append(customs, cus)
  11632. }
  11633. }
  11634. if item.Type == 2 { //项目
  11635. for _, subItem := range item.HisPrescriptionProject {
  11636. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11637. cus := &Custom{
  11638. AdviceId: 0,
  11639. ProjectId: subItem.ID,
  11640. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11641. Cut: fmt.Sprintf("%.2f", cnt),
  11642. FeedetlSn: subItem.FeedetlSn,
  11643. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11644. MedListCodg: subItem.MedListCodg,
  11645. Type: 2,
  11646. }
  11647. customs = append(customs, cus)
  11648. }
  11649. }
  11650. for _, item := range item.HisAdditionalCharge {
  11651. cus := &Custom{
  11652. ItemId: item.ID,
  11653. AdviceId: 0,
  11654. ProjectId: 0,
  11655. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11656. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11657. FeedetlSn: item.FeedetlSn,
  11658. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11659. MedListCodg: item.XtHisAddtionConfig.Code,
  11660. Type: 3,
  11661. }
  11662. customs = append(customs, cus)
  11663. }
  11664. }
  11665. fmt.Println(customs)
  11666. for _, item := range customs {
  11667. var advice_id int64 = 0
  11668. var project_id int64 = 0
  11669. var item_id int64 = 0
  11670. var types int64 = 0
  11671. if item.Type == 1 {
  11672. advice_id = item.AdviceId
  11673. project_id = 0
  11674. item_id = 0
  11675. } else if item.Type == 2 {
  11676. advice_id = 0
  11677. item_id = 0
  11678. project_id = item.ProjectId
  11679. } else if item.Type == 3 {
  11680. advice_id = 0
  11681. item_id = item.ItemId
  11682. project_id = 0
  11683. }
  11684. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11685. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11686. pric, _ := strconv.ParseFloat(item.Price, 32)
  11687. info := &models.HisOrderInfo{
  11688. OrderNumber: order.Number,
  11689. UploadDate: time.Now().Unix(),
  11690. AdviceId: advice_id,
  11691. DetItemFeeSumamt: detItemFeeSumamt,
  11692. Cnt: cut,
  11693. Pric: pric,
  11694. PatientId: id,
  11695. Status: 1,
  11696. Mtime: time.Now().Unix(),
  11697. Ctime: time.Now().Unix(),
  11698. UserOrgId: adminUser.CurrentOrgId,
  11699. HisPatientId: his.ID,
  11700. OrderId: order.ID,
  11701. ProjectId: project_id,
  11702. Type: types,
  11703. ItemId: item_id,
  11704. }
  11705. service.CreateOrderInfo(info)
  11706. }
  11707. his.SickType = sick_type
  11708. service.UpdataHisPateint(&his)
  11709. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11710. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11711. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11712. if err == nil {
  11713. c.ServeSuccessJSON(map[string]interface{}{
  11714. "msg": "结算成功",
  11715. })
  11716. }
  11717. }
  11718. type CustomOrderInfo struct {
  11719. Name string
  11720. Spec string
  11721. Unit string
  11722. Count float64
  11723. Price float64
  11724. Total float64
  11725. }
  11726. func (c *HisApiController) GetPrivateExpensesInfo() {
  11727. order_id, _ := c.GetInt64("id", 0)
  11728. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11729. order, _ := service.GetHisOrderByID(order_id)
  11730. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11731. if order.ID == 0 {
  11732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11733. return
  11734. }
  11735. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11736. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11737. org_id := c.GetAdminUserInfo().CurrentOrgId
  11738. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11739. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11740. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11741. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11742. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11743. //var orderInfos_four []*models.HisOrderInfoTwo
  11744. //for _, item := range orderInfos_three {
  11745. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11746. // item.HisPrescriptionProject.IsCheckTeam = 1
  11747. // orderInfos_four = append(orderInfos_four, item)
  11748. //
  11749. // }
  11750. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11751. // item.HisPrescriptionProject.IsCheckTeam = 2
  11752. // orderInfos_two = append(orderInfos_two, item)
  11753. // }
  11754. //}
  11755. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11756. //var cus_slice []CustomOrderInfo
  11757. //for _, item := range new_order_info {
  11758. // var cus CustomOrderInfo
  11759. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11760. // cus.Unit = ""
  11761. // cus.Spec = ""
  11762. // var total float64
  11763. // for _, subItem := range orderInfos_four {
  11764. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11765. // total = total + subItem.DetItemFeeSumamt
  11766. // fmt.Println(subItem.DetItemFeeSumamt)
  11767. // }
  11768. // }
  11769. // cus.Count = 1
  11770. // cus.Total = total
  11771. // cus_slice = append(cus_slice, cus)
  11772. //}
  11773. orderInfos = append(orderInfos, orderInfos_two...)
  11774. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11775. //orderInfos = append(orderInfos, orderInfos_three...)
  11776. //}/**/
  11777. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11778. c.ServeSuccessJSON(map[string]interface{}{
  11779. "order": order,
  11780. "order_info": orderInfos,
  11781. "patient": patient,
  11782. "admin_info": adminInfo,
  11783. "his": his,
  11784. "current_admin": role,
  11785. "org_config": miConfig,
  11786. //"new_order_info": cus_slice,
  11787. })
  11788. }
  11789. func (this *HisApiController) ChangeMedType() {
  11790. med_type := this.GetString("med_type")
  11791. old_med_type := this.GetString("old_med_type")
  11792. ids := this.GetString("ids")
  11793. settle_type, _ := this.GetInt64("settle_type")
  11794. start_time := this.GetString("start_time")
  11795. end_time := this.GetString("end_time")
  11796. ids_arr := strings.Split(ids, ",")
  11797. if settle_type == 1 { //日结
  11798. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11799. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11800. prescription.MedType = med_type
  11801. err := service.SaveHisPrescriptionTwo(&prescription)
  11802. if err == nil {
  11803. this.ServeSuccessJSON(map[string]interface{}{
  11804. "msg": "修改成功",
  11805. })
  11806. } else {
  11807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11808. return
  11809. }
  11810. } else if settle_type == 2 {
  11811. timeLayout := "2006-01-02"
  11812. loc, _ := time.LoadLocation("Local")
  11813. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11814. if err != nil {
  11815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11816. return
  11817. }
  11818. recordStartTime := theStartTime.Unix()
  11819. start_time_timestamp := recordStartTime
  11820. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11821. if err != nil {
  11822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11823. return
  11824. }
  11825. recordEndTime := theEndTime.Unix()
  11826. end_time_timestamp := recordEndTime
  11827. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11828. if updateErr == nil {
  11829. this.ServeSuccessJSON(map[string]interface{}{
  11830. "msg": "修改成功",
  11831. })
  11832. } else {
  11833. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11834. return
  11835. }
  11836. }
  11837. }
  11838. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11839. patient_id, _ := c.GetInt64("patient_id")
  11840. his_patient_id, _ := c.GetInt64("his_patient_id")
  11841. record_date := c.GetString("record_date")
  11842. start_time := c.GetString("start_time")
  11843. end_time := c.GetString("end_time")
  11844. order_status, _ := c.GetInt64("type", 0)
  11845. p_type, _ := c.GetInt64("p_type", 0)
  11846. order_id, _ := c.GetInt64("order_id", 0)
  11847. timeLayout := "2006-01-02"
  11848. loc, _ := time.LoadLocation("Local")
  11849. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11850. if err != nil {
  11851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11852. return
  11853. }
  11854. recordDateTime := theTime.Unix()
  11855. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11856. if err != nil {
  11857. }
  11858. startRecordDateTime := startTime.Unix()
  11859. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11860. if err != nil {
  11861. }
  11862. endRecordDateTime := endTime.Unix()
  11863. admin := c.GetAdminUserInfo()
  11864. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11865. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11866. order, _ := service.GetHisOrderByID(order_id)
  11867. var monthPrescriptions []*models.HisPrescription
  11868. if order_status == 1 || order_status == 0 {
  11869. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11870. } else if order_status == 2 {
  11871. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11872. }
  11873. var settle_total float64
  11874. for _, item := range monthPrescriptions {
  11875. if len(item.HisPrescriptionProject) > 0 {
  11876. for _, subItem := range item.HisPrescriptionProject {
  11877. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11878. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11879. settle_total = settle_total + total
  11880. }
  11881. }
  11882. if len(item.HisDoctorAdviceInfo) > 0 {
  11883. for _, subItem := range item.HisDoctorAdviceInfo {
  11884. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11885. settle_total = settle_total + total
  11886. }
  11887. }
  11888. }
  11889. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11890. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11891. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11892. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11893. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11894. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11895. //获取所有科室信息
  11896. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11897. var dia string
  11898. for _, item := range month_p_info {
  11899. if len(dia) == 0 {
  11900. dia = item.Diagnosis
  11901. } else {
  11902. dia = dia + "," + item.Diagnosis
  11903. }
  11904. }
  11905. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11906. dia_arr = removeEmptyStrings(dia_arr)
  11907. c.ServeSuccessJSON(map[string]interface{}{
  11908. "his_info": his_patient_info,
  11909. "xt_info": xt_patient_info,
  11910. "case_history": case_history,
  11911. "info": patientPrescriptionInfo,
  11912. "last_info": lastPatientPrescriptionInfo,
  11913. "month_prescriptions": monthPrescriptions,
  11914. "order": order,
  11915. "doctors": doctors,
  11916. "department": department,
  11917. "settle_total": settle_total,
  11918. "dia_arr": dia_arr,
  11919. })
  11920. return
  11921. }
  11922. func removeEmptyStrings(input []string) []string {
  11923. var output []string
  11924. for _, s := range input {
  11925. if s != "" {
  11926. output = append(output, s)
  11927. }
  11928. }
  11929. return output
  11930. }
  11931. func removeDuplicates(input []string) []string {
  11932. seen := make(map[string]bool)
  11933. output := []string{}
  11934. for _, s := range input {
  11935. if _, exists := seen[s]; !exists {
  11936. seen[s] = true
  11937. output = append(output, s)
  11938. }
  11939. }
  11940. return output
  11941. }
  11942. func (c *HisApiController) GetHisMonthPatientInfo() {
  11943. patient_id, _ := c.GetInt64("patient_id")
  11944. his_patient_id, _ := c.GetInt64("his_patient_id")
  11945. record_date := c.GetString("record_date")
  11946. number := c.GetString("number")
  11947. start_time := c.GetString("start_time")
  11948. end_time := c.GetString("end_time")
  11949. p_type, _ := c.GetInt64("p_type")
  11950. timeLayout := "2006-01-02"
  11951. loc, _ := time.LoadLocation("Local")
  11952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11953. if err != nil {
  11954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11955. return
  11956. }
  11957. recordDateTime := theTime.Unix()
  11958. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11959. if err != nil {
  11960. }
  11961. startRecordDateTime := startTime.Unix()
  11962. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11963. if err != nil {
  11964. }
  11965. endRecordDateTime := endTime.Unix()
  11966. admin := c.GetAdminUserInfo()
  11967. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11968. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11969. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11970. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11971. var settle_total float64
  11972. for _, item := range monthPrescriptions {
  11973. if len(item.HisPrescriptionProject) > 0 {
  11974. for _, subItem := range item.HisPrescriptionProject {
  11975. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11976. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11977. settle_total = settle_total + total
  11978. }
  11979. }
  11980. if len(item.HisDoctorAdviceInfo) > 0 {
  11981. for _, subItem := range item.HisDoctorAdviceInfo {
  11982. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11983. settle_total = settle_total + total
  11984. }
  11985. }
  11986. }
  11987. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11988. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11989. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11990. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11991. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11992. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11993. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11994. //获取所有科室信息
  11995. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11996. c.ServeSuccessJSON(map[string]interface{}{
  11997. "his_info": his_patient_info,
  11998. "xt_info": xt_patient_info,
  11999. "case_history": case_history,
  12000. "info": patientPrescriptionInfo,
  12001. "month_prescriptions": monthPrescriptions,
  12002. "order": order,
  12003. "doctors": doctors,
  12004. "department": department,
  12005. "count": count,
  12006. "drugStockConfig": drugStockConfig,
  12007. "last_info": lastPatientPrescriptionInfo,
  12008. "settle_total": settle_total,
  12009. })
  12010. return
  12011. }
  12012. func (c *HisApiController) GetAllOrder() {
  12013. org_id := c.GetAdminUserInfo().CurrentOrgId
  12014. orders, _ := service.GetNewHisOrderList(org_id)
  12015. c.ServeSuccessJSON(map[string]interface{}{
  12016. "order": orders,
  12017. })
  12018. return
  12019. }
  12020. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12021. newArr = make([]*models.HisOrderInfoTwo, 0)
  12022. for i := 0; i < len(arr); i++ {
  12023. repeat := false
  12024. for j := i + 1; j < len(arr); j++ {
  12025. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12026. repeat = true
  12027. break
  12028. }
  12029. }
  12030. if !repeat {
  12031. newArr = append(newArr, arr[i])
  12032. }
  12033. }
  12034. return
  12035. }
  12036. // 修改处方退库操作 参数传修改之前的处方数据
  12037. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12038. if advice.ExecutionState == 1 {
  12039. //查询该病人该药品是否有库存记录
  12040. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12041. if errcode == gorm.ErrRecordNotFound {
  12042. } else {
  12043. //退库
  12044. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12045. if advice.PrescribingNumberUnit == drug.MinUnit {
  12046. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12047. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12048. //退库
  12049. warehouseInfo := models.DrugWarehouseInfo{
  12050. StockMinNumber: prescribingNumber,
  12051. }
  12052. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12053. operation_time := time.Now().Unix()
  12054. creater := advice.AdviceDoctor
  12055. ctime := time.Now().Unix()
  12056. timeStr := time.Now().Format("2006-01-02")
  12057. timeArr := strings.Split(timeStr, "-")
  12058. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12059. total = total + 1
  12060. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12061. cancelStock := models.DrugCancelStock{
  12062. OrderNumber: orderNumber,
  12063. OperaTime: operation_time,
  12064. OrgId: advice.UserOrgId,
  12065. Creater: creater,
  12066. Ctime: ctime,
  12067. Status: 1,
  12068. ReturnTime: advice.AdviceDate,
  12069. Dealer: info.Dealer,
  12070. Manufacturer: info.Manufacturer,
  12071. Type: 1,
  12072. }
  12073. service.AddSigleDrugCancelStock(&cancelStock)
  12074. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12075. dealer, _ := service.GetDealerById(info.Dealer)
  12076. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12077. cancelStockInfo := models.DrugCancelStockInfo{
  12078. OrderNumber: cancelInfo.OrderNumber,
  12079. CancelStockId: cancelInfo.ID,
  12080. DrugId: info.DrugId,
  12081. Count: info.Count,
  12082. Status: 1,
  12083. Ctime: ctime,
  12084. OrgId: advice.UserOrgId,
  12085. Type: 1,
  12086. Manufacturer: manufactureName.ManufacturerName,
  12087. Dealer: dealer.DealerName,
  12088. Total: 0,
  12089. RetailPrice: info.RetailPrice,
  12090. RetailTotalPrice: info.RetailTotalPrice,
  12091. Price: info.Price,
  12092. RegisterAccount: "",
  12093. Remark: info.Remark,
  12094. BatchNumber: info.BatchNumber,
  12095. MaxUnit: info.CountUnit,
  12096. ProductDate: info.ProductDate,
  12097. ExpiryDate: info.ExpiryDate,
  12098. BatchNumberId: info.WarehouseInfoId,
  12099. }
  12100. flow := models.DrugFlow{
  12101. WarehousingId: 0,
  12102. DrugId: info.DrugId,
  12103. Number: "",
  12104. BatchNumber: info.BatchNumber,
  12105. Count: info.Count,
  12106. UserOrgId: advice.UserOrgId,
  12107. PatientId: 0,
  12108. SystemTime: ctime,
  12109. ConsumableType: 4,
  12110. IsSys: 0,
  12111. WarehousingOrder: "",
  12112. WarehouseOutId: 0,
  12113. WarehouseOutOrderNumber: "",
  12114. IsEdit: 0,
  12115. CancelStockId: cancelStock.ID,
  12116. CancelOrderNumber: cancelStock.OrderNumber,
  12117. Manufacturer: info.Manufacturer,
  12118. Dealer: info.Dealer,
  12119. Creator: advice.UserOrgId,
  12120. UpdateCreator: 0,
  12121. Status: 1,
  12122. Ctime: time.Now().Unix(),
  12123. Mtime: 0,
  12124. Price: info.Price,
  12125. WarehousingDetailId: 0,
  12126. WarehouseOutDetailId: 0,
  12127. CancelOutDetailId: 0,
  12128. ExpireDate: info.ExpiryDate,
  12129. ProductDate: info.ProductDate,
  12130. MaxUnit: info.CountUnit,
  12131. MinUnit: "",
  12132. }
  12133. service.CreatedCancelStock(cancelStockInfo)
  12134. service.CreateDrugFlowOne(flow)
  12135. } else {
  12136. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12137. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12138. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12139. warehouseInfo := models.DrugWarehouseInfo{
  12140. StockMinNumber: prescribingNumber,
  12141. }
  12142. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12143. }
  12144. operation_time := time.Now().Unix()
  12145. creater := advice.AdviceDoctor
  12146. ctime := time.Now().Unix()
  12147. timeStr := time.Now().Format("2006-01-02")
  12148. timeArr := strings.Split(timeStr, "-")
  12149. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12150. total = total + 1
  12151. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12152. cancelStock := models.DrugCancelStock{
  12153. OrderNumber: orderNumber,
  12154. OperaTime: operation_time,
  12155. OrgId: advice.UserOrgId,
  12156. Creater: creater,
  12157. Ctime: ctime,
  12158. Status: 1,
  12159. ReturnTime: advice.AdviceDate,
  12160. Dealer: info.Dealer,
  12161. Manufacturer: info.Manufacturer,
  12162. Type: 1,
  12163. }
  12164. service.AddSigleDrugCancelStock(&cancelStock)
  12165. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12166. dealer, _ := service.GetDealerById(info.Dealer)
  12167. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12168. cancelStockInfo := models.DrugCancelStockInfo{
  12169. OrderNumber: cancelInfo.OrderNumber,
  12170. CancelStockId: cancelInfo.ID,
  12171. DrugId: info.DrugId,
  12172. Count: info.Count,
  12173. Status: 1,
  12174. Ctime: ctime,
  12175. OrgId: advice.UserOrgId,
  12176. Type: 1,
  12177. Manufacturer: manufactureName.ManufacturerName,
  12178. Dealer: dealer.DealerName,
  12179. Total: 0,
  12180. RetailPrice: info.RetailPrice,
  12181. RetailTotalPrice: info.RetailTotalPrice,
  12182. Price: info.Price,
  12183. RegisterAccount: "",
  12184. Remark: info.Remark,
  12185. BatchNumber: info.BatchNumber,
  12186. MaxUnit: info.CountUnit,
  12187. ProductDate: info.ProductDate,
  12188. ExpiryDate: info.ExpiryDate,
  12189. BatchNumberId: info.WarehouseInfoId,
  12190. }
  12191. flow := models.DrugFlow{
  12192. WarehousingId: 0,
  12193. DrugId: info.DrugId,
  12194. Number: "",
  12195. BatchNumber: info.BatchNumber,
  12196. Count: info.Count,
  12197. UserOrgId: advice.UserOrgId,
  12198. PatientId: 0,
  12199. SystemTime: ctime,
  12200. ConsumableType: 4,
  12201. IsSys: 0,
  12202. WarehousingOrder: "",
  12203. WarehouseOutId: 0,
  12204. WarehouseOutOrderNumber: "",
  12205. IsEdit: 0,
  12206. CancelStockId: cancelStock.ID,
  12207. CancelOrderNumber: cancelStock.OrderNumber,
  12208. Manufacturer: info.Manufacturer,
  12209. Dealer: info.Dealer,
  12210. Creator: advice.AdviceDoctor,
  12211. UpdateCreator: 0,
  12212. Status: 1,
  12213. Ctime: time.Now().Unix(),
  12214. Mtime: 0,
  12215. Price: info.Price,
  12216. WarehousingDetailId: 0,
  12217. WarehouseOutDetailId: 0,
  12218. CancelOutDetailId: 0,
  12219. ExpireDate: info.ExpiryDate,
  12220. ProductDate: info.ProductDate,
  12221. MaxUnit: info.CountUnit,
  12222. MinUnit: "",
  12223. }
  12224. service.CreatedCancelStock(cancelStockInfo)
  12225. service.CreateDrugFlowOne(flow)
  12226. }
  12227. }
  12228. }
  12229. return err
  12230. }
  12231. func (this *HisApiController) DeleteNCDS() {
  12232. id, _ := this.GetInt64("id", 0)
  12233. if id > 0 {
  12234. service.DeletePsnNCDSRecordById(id)
  12235. this.ServeSuccessJSON(map[string]interface{}{
  12236. "msg": "删除成功",
  12237. })
  12238. } else {
  12239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12240. return
  12241. }
  12242. }
  12243. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12244. id, _ := c.GetInt64("id")
  12245. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12246. c.ServeSuccessJSON(map[string]interface{}{
  12247. "advice": advice,
  12248. })
  12249. return
  12250. }
  12251. func (c *HisApiController) GetHisMonthChargePatientList() {
  12252. record_date := c.GetString("record_date")
  12253. start_time := c.GetString("start_time")
  12254. end_time := c.GetString("end_time")
  12255. timeLayout := "2006-01-02"
  12256. loc, _ := time.LoadLocation("Local")
  12257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12258. if err != nil {
  12259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12260. return
  12261. }
  12262. if err != nil {
  12263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12264. return
  12265. }
  12266. recordDateTime := theTime.Unix()
  12267. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12268. if err != nil {
  12269. }
  12270. startRecordDateTime := startTime.Unix()
  12271. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12272. if err != nil {
  12273. }
  12274. endRecordDateTime := endTime.Unix()
  12275. adminInfo := c.GetAdminUserInfo()
  12276. var tempMonthChargePatients []*service.MonthChargePatients
  12277. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12278. for _, item := range tempPatients {
  12279. //过滤没有处方的
  12280. if len(item.HisPrescription) == 0 {
  12281. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12282. }
  12283. }
  12284. c.ServeSuccessJSON(map[string]interface{}{
  12285. "list": tempMonthChargePatients,
  12286. })
  12287. }
  12288. // PrescriptionDifference 医嘱数量差值结构体
  12289. type PrescriptionDrugDifference struct {
  12290. DrugID int64 //基础库药品id
  12291. ID int64 //医嘱id
  12292. Difference float64 //差值
  12293. Unit string //单位
  12294. }
  12295. type PrescriptionGoodDifference struct {
  12296. GoodID int64 //基础库项目耗材id
  12297. ID int64 //医嘱id
  12298. Difference int64 //差值
  12299. Unit string //单位
  12300. Type int64 //类型
  12301. }
  12302. type EditCustomData struct {
  12303. adviceList []*models.HisDoctorAdviceInfo
  12304. projectList []*models.HisPrescriptionProject
  12305. }
  12306. type SrcCustomData struct {
  12307. adviceList []*models.HisDoctorAdviceInfo
  12308. projectList []*models.HisPrescriptionProject
  12309. }
  12310. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12311. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12312. differences := make([]*PrescriptionDrugDifference, 0)
  12313. // 创建一个 map 来存储第一个切片中的药品信息
  12314. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12315. for _, advice := range firstPrescription {
  12316. firstMap[advice.DrugId] = advice
  12317. }
  12318. // 遍历第二个切片中的药品信息,并比较数量差值
  12319. for _, advice := range secondPrescription {
  12320. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12321. diff := &PrescriptionDrugDifference{
  12322. DrugID: advice.DrugId,
  12323. ID: firstAdvice.ID,
  12324. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12325. Unit: firstAdvice.PrescribingNumberUnit,
  12326. }
  12327. differences = append(differences, diff)
  12328. }
  12329. }
  12330. return differences
  12331. }
  12332. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12333. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12334. differences := make([]*PrescriptionGoodDifference, 0)
  12335. // 创建一个 map 来存储第一个切片中的耗材信息
  12336. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12337. for _, good := range firstPrescription {
  12338. firstMap[good.ProjectId] = good
  12339. }
  12340. // 遍历第二个切片中的耗材信息,并比较数量差值
  12341. for _, good := range secondPrescription {
  12342. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12343. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12344. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12345. diff := &PrescriptionGoodDifference{
  12346. GoodID: good.ProjectId,
  12347. ID: firstGood.ID,
  12348. Difference: count - firstCount,
  12349. Unit: firstGood.Unit,
  12350. Type: firstGood.Type,
  12351. }
  12352. differences = append(differences, diff)
  12353. }
  12354. }
  12355. return differences
  12356. }
  12357. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12358. var adviceList []*models.HisDoctorAdviceInfo
  12359. var projectList []*models.HisPrescriptionProject
  12360. var advice_ids []int64
  12361. var project_ids []int64
  12362. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12363. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12364. //var tempPrescription *models.HisPrescriptionProjectscription
  12365. if len(prescriptions) > 0 {
  12366. for _, item := range prescriptions {
  12367. items := item.(map[string]interface{})
  12368. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12369. advices := items["advices"].([]interface{})
  12370. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12371. groupNo := int64(0)
  12372. ctime := time.Now().Unix()
  12373. mtime := ctime
  12374. if len(advices) > 0 {
  12375. for _, advice := range advices {
  12376. var s models.HisDoctorAdviceInfo
  12377. s.AdviceType = 2
  12378. s.StopState = 2
  12379. s.ExecutionState = 2
  12380. s.Status = 1
  12381. s.Groupno = groupNo
  12382. s.CreatedTime = ctime
  12383. s.UpdatedTime = mtime
  12384. s.IsSettle = 2
  12385. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12386. //存储切片中
  12387. if s.ID > 0 {
  12388. advice_ids = append(advice_ids, s.ID)
  12389. adviceList = append(adviceList, &s)
  12390. }
  12391. }
  12392. }
  12393. }
  12394. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12395. projects := items["project"].([]interface{})
  12396. if len(projects) > 0 {
  12397. for _, project := range projects {
  12398. var p models.HisPrescriptionProject
  12399. p.Ctime = time.Now().Unix()
  12400. p.Mtime = time.Now().Unix()
  12401. p.Status = 1
  12402. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12403. if p.ID > 0 {
  12404. project_ids = append(project_ids, p.ID)
  12405. projectList = append(projectList, &p)
  12406. }
  12407. }
  12408. }
  12409. }
  12410. }
  12411. }
  12412. }
  12413. editCustomData.projectList = projectList
  12414. editCustomData.adviceList = adviceList
  12415. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12416. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12417. srcCustomData.adviceList = list
  12418. srcCustomData.projectList = list2
  12419. return
  12420. }