his_api_controller.go 541KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903
  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/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1214. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1215. //获取当前用户的信息
  1216. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1217. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1218. //获取所有科室信息
  1219. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1220. //var aa []service.PatientThree
  1221. noElementsSlice := make([]service.PatientThree, 0)
  1222. c.ServeSuccessJSON(map[string]interface{}{
  1223. "list": patients,
  1224. "list_two": patients_two,
  1225. "list_three": noElementsSlice,
  1226. "info": adminUserInfo,
  1227. "doctors": doctors,
  1228. "department": department,
  1229. })
  1230. }
  1231. type CustomTemplate struct {
  1232. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1233. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1234. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1235. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1236. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1237. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1238. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1239. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1240. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1241. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1242. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1243. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1244. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1245. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1246. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1247. }
  1248. func (c *HisApiController) GetHisPatientInfo() {
  1249. patient_id, _ := c.GetInt64("patient_id")
  1250. his_patient_id, _ := c.GetInt64("his_patient_id")
  1251. record_date := c.GetString("record_date")
  1252. number := c.GetString("number")
  1253. //start_time := c.GetString("start_time")
  1254. //end_time := c.GetString("end_time")
  1255. p_type, _ := c.GetInt64("p_type")
  1256. timeLayout := "2006-01-02"
  1257. loc, _ := time.LoadLocation("Local")
  1258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1259. if err != nil {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. recordDateTime := theTime.Unix()
  1264. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //startRecordDateTime := startTime.Unix()
  1269. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1270. //if err != nil {
  1271. //
  1272. //}
  1273. //endRecordDateTime := endTime.Unix()
  1274. admin := c.GetAdminUserInfo()
  1275. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1277. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1278. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1279. var prescriptions []*models.HisPrescription
  1280. var last_prescriptions []*models.HisPrescription
  1281. var sch_prescriptions []CustomTemplate
  1282. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1283. if p_type == 1 { //住院
  1284. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1285. for _, item := range prescriptions {
  1286. for _, subItem := range item.HisDoctorAdviceInfo {
  1287. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1288. if info.RetailPrice > 0 {
  1289. subItem.Drug.MinPrice = info.RetailPrice
  1290. }
  1291. }
  1292. }
  1293. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1294. } else { //门诊
  1295. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1296. for _, item := range prescriptions {
  1297. for _, subItem := range item.HisDoctorAdviceInfo {
  1298. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1299. if info.RetailPrice > 0 {
  1300. subItem.Drug.MinPrice = info.RetailPrice
  1301. }
  1302. }
  1303. }
  1304. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1305. }
  1306. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1307. if sch.ID > 0 {
  1308. var week string
  1309. t := time.Now()
  1310. switch t.Weekday().String() {
  1311. case "Monday":
  1312. week = "周一"
  1313. break
  1314. case "Tuesday":
  1315. week = "周二"
  1316. break
  1317. case "Wednesday":
  1318. week = "周三"
  1319. break
  1320. case "Thursday":
  1321. week = "周四"
  1322. break
  1323. case "Friday":
  1324. week = "周五"
  1325. break
  1326. case "Saturday":
  1327. week = "周六"
  1328. break
  1329. case "Sunday":
  1330. week = "周日"
  1331. break
  1332. }
  1333. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1334. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1335. //根据推送频率组装新的数组
  1336. for _, item := range temp_sch_prescriptions {
  1337. var cus CustomTemplate
  1338. cus.ID = item.ID
  1339. cus.UserOrgId = item.UserOrgId
  1340. cus.PatientId = item.PatientId
  1341. cus.MedType = item.MedType
  1342. cus.RecordDate = item.RecordDate
  1343. cus.Type = item.Type
  1344. cus.PType = item.PType
  1345. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1346. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1347. if subItem.FrequencyType == 1 { //每次必推
  1348. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1349. }
  1350. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1351. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1352. }
  1353. if subItem.FrequencyType == 2 { //按照天数频率
  1354. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1355. now := p.Unix()
  1356. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1357. dayStr2 := "-" + dayStr
  1358. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1359. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1360. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1361. if len(advices) == 0 {
  1362. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1363. }
  1364. }
  1365. }
  1366. }
  1367. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1368. if subItem.Type == 2 {
  1369. if subItem.XtHisProject.MedicalStatus != 1 {
  1370. if subItem.FrequencyType == 1 {
  1371. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1372. }
  1373. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1374. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1375. }
  1376. if subItem.FrequencyType == 2 {
  1377. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1378. now := p.Unix()
  1379. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1380. dayStr2 := "-" + dayStr
  1381. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1382. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1383. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1384. if len(projects) == 0 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. }
  1388. }
  1389. } else if subItem.Type == 3 {
  1390. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1391. if subItem.FrequencyType == 1 {
  1392. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1393. }
  1394. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1395. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1396. }
  1397. if subItem.FrequencyType == 2 {
  1398. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1399. now := p.Unix()
  1400. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1401. dayStr2 := "-" + dayStr
  1402. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1403. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1404. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1405. if len(projects) == 0 {
  1406. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. sch_prescriptions = append(sch_prescriptions, cus)
  1413. }
  1414. for _, item := range sch_prescriptions {
  1415. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1416. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1417. }
  1418. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1419. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1420. }
  1421. }
  1422. }
  1423. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1424. if config.ID > 0 && config.IsOpen == 1 {
  1425. for _, item := range sch_prescriptions {
  1426. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1427. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1428. if info.RetailPrice > 0 {
  1429. subItem.Drug.MinPrice = info.RetailPrice
  1430. if admin.CurrentOrgId != 10598 {
  1431. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1432. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if config.ID > 0 && config.IsOpen == 1 {
  1439. for _, item := range sch_prescriptions {
  1440. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1441. if subItem.Type == 3 {
  1442. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1443. if info.Price > 0 {
  1444. subItem.GoodInfo.PackingPrice = info.Price
  1445. if admin.CurrentOrgId != 10598 {
  1446. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1447. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1455. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1456. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1457. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1458. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1459. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1460. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1461. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1462. //获取所有科室信息
  1463. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1464. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1465. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1466. c.ServeSuccessJSON(map[string]interface{}{
  1467. "his_info": his_patient_info,
  1468. "xt_info": xt_patient_info,
  1469. "prescription": prescriptions,
  1470. "case_history": case_history,
  1471. "info": patientPrescriptionInfo,
  1472. //"month_prescriptions": monthPrescriptions,
  1473. "order": order,
  1474. "doctors": doctors,
  1475. "department": department,
  1476. "sch_prescriptions": sch_prescriptions,
  1477. "last_prescriptions": last_prescriptions,
  1478. "schedule": sch,
  1479. "count": count,
  1480. "drugStockConfig": drugStockConfig,
  1481. "last_info": lastPatientPrescriptionInfo,
  1482. "befor": beforThrity,
  1483. "LastCaseHistory": LastCaseHistory,
  1484. })
  1485. return
  1486. }
  1487. func (c *HisApiController) GetHisPrescriptionConfig() {
  1488. adminInfo := c.GetAdminUserInfo()
  1489. //获取医嘱模版
  1490. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1491. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1492. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1493. //获取所有基础药
  1494. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1495. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1496. if config.ID > 0 && config.IsOpen == 1 {
  1497. for _, item := range drugs {
  1498. var index = 0
  1499. for _, subItem := range item.OtherDrugWarehouseInfo {
  1500. if index == 0 {
  1501. index = index + 1
  1502. if subItem.RetailPrice > 0 {
  1503. item.MinPrice = subItem.RetailPrice
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1510. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1511. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1512. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1513. //获取所有科室信息
  1514. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1515. //获取诊断信息
  1516. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1517. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1518. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1519. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1520. //获取是否开启保存耗材出库的开关
  1521. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1522. c.ServeSuccessJSON(map[string]interface{}{
  1523. "drugs": drugs,
  1524. "advices_template": advices,
  1525. "drugways": drugways,
  1526. "efs": efs,
  1527. "doctors": doctors,
  1528. "department": department,
  1529. "sick": sick,
  1530. "additions": additions,
  1531. "diagnose": diagnose,
  1532. "manufacturers": manufacturers,
  1533. "goodOutOpen": goodOutOpen,
  1534. "patientDiagnose": patientDiagnose,
  1535. })
  1536. }
  1537. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1538. //获取所有基础药
  1539. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1540. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1541. if config.ID > 0 && config.IsOpen == 1 {
  1542. for _, item := range drugs {
  1543. var index = 0
  1544. for _, subItem := range item.OtherDrugWarehouseInfo {
  1545. if index == 0 {
  1546. index = index + 1
  1547. if subItem.RetailPrice > 0 {
  1548. item.MinPrice = subItem.RetailPrice
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1555. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1556. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1557. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1558. //获取所有科室信息
  1559. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1560. //获取诊断信息
  1561. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1562. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1563. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1564. //获取是否开启保存耗材出库的开关
  1565. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1566. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1567. c.ServeSuccessJSON(map[string]interface{}{
  1568. "drugs": drugs,
  1569. "advices_template": advices,
  1570. "drugways": drugways,
  1571. "efs": efs,
  1572. "doctors": doctors,
  1573. "department": department,
  1574. "sick": sick,
  1575. "additions": additions,
  1576. "diagnose": diagnose,
  1577. "manufacturers": manufacturers,
  1578. "goodOutOpen": goodOutOpen,
  1579. "patientDiagnose": patientDiagnose,
  1580. })
  1581. }
  1582. }
  1583. func (c *HisApiController) CreateHisPrescription() {
  1584. record_date := c.GetString("record_date")
  1585. patient_id, _ := c.GetInt64("patient_id")
  1586. reg_type, _ := c.GetInt64("reg_type")
  1587. diagnose := c.GetString("diagnose")
  1588. sick_type, _ := c.GetInt64("sick_type")
  1589. sick_history := c.GetString("sick_history")
  1590. doctor_id, _ := c.GetInt64("doctor", 0)
  1591. department, _ := c.GetInt64("department", 0)
  1592. his_patient_id, _ := c.GetInt64("his_patient_id")
  1593. p_type, _ := c.GetInt64("p_type")
  1594. patient_diagnose := c.GetString("patient_diagnose")
  1595. dataBody := make(map[string]interface{}, 0)
  1596. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1597. if err != nil {
  1598. utils.ErrorLog(err.Error())
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. //edit, src := GetCompareData(dataBody)
  1603. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1604. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1605. //fmt.Println(drugResult)
  1606. //fmt.Println(goodResult)
  1607. timeLayout := "2006-01-02"
  1608. loc, _ := time.LoadLocation("Local")
  1609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1610. if err != nil {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1612. return
  1613. }
  1614. adminInfo := c.GetAdminUserInfo()
  1615. recordDateTime := theTime.Unix()
  1616. //查询默认出库仓库库存
  1617. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1618. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1619. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1620. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1621. if len(lists) == 1 {
  1622. his_patient_id = lists[0].ID
  1623. }
  1624. }
  1625. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1626. //自动出库的开关开启
  1627. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1628. //自动出库
  1629. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1630. //耗材保存处方出库
  1631. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1633. //已发药和已收费限制逻辑
  1634. isMidicine := false
  1635. isCharge := false
  1636. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1637. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1638. if len(prescriptions) > 0 {
  1639. for _, item := range prescriptions {
  1640. items := item.(map[string]interface{})
  1641. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1642. utils.ErrorLog("id")
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. id := int64(items["id"].(float64))
  1647. if id > 0 {
  1648. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1649. if err != nil {
  1650. if new_prescription.OrderStatus == 4 {
  1651. isCharge = true
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. if isMidicine == true {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1660. return
  1661. }
  1662. if isCharge == true {
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1664. return
  1665. }
  1666. // 开始主事务
  1667. db := service.XTWriteDB()
  1668. tx := db.Begin()
  1669. // 在函数结束时处理事务回滚
  1670. defer func() {
  1671. if r := recover(); r != nil {
  1672. tx.Rollback()
  1673. }
  1674. }()
  1675. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1676. //药品发药出库
  1677. if pharmacyConfig.IsOpen == 1 {
  1678. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1679. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1680. if len(prescriptions) > 0 {
  1681. for _, item := range prescriptions {
  1682. items := item.(map[string]interface{})
  1683. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1684. advices := items["advices"].([]interface{})
  1685. if len(advices) > 0 {
  1686. for _, advice := range advices {
  1687. var drug_id int64
  1688. var prescribing_number float64
  1689. var prescribingNumberUnit string
  1690. var adviceId int64
  1691. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1692. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1693. }
  1694. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1695. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1696. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1697. }
  1698. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1699. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1700. }
  1701. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1702. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1703. }
  1704. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1705. if drug.ID == 0 {
  1706. tx.Rollback()
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. return
  1709. }
  1710. //查询药品的所有库存
  1711. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1712. var total_count int64
  1713. for _, it := range list {
  1714. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1715. }
  1716. totals := strconv.FormatInt(total_count, 10)
  1717. //查询该药品是否存在开药记录
  1718. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1719. //新增处方盘点库存是否充足
  1720. if advicelist.ID == 0 {
  1721. all_count, _ := strconv.ParseFloat(totals, 64)
  1722. if prescribingNumberUnit == drug.MinUnit {
  1723. if drug.IsUse != 1 {
  1724. if drug.IsProject == 0 || drug.IsProject == 2 {
  1725. if all_count == 0 {
  1726. tx.Rollback()
  1727. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1728. return
  1729. }
  1730. if prescribing_number > all_count {
  1731. tx.Rollback()
  1732. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1733. return
  1734. }
  1735. }
  1736. }
  1737. }
  1738. if prescribingNumberUnit == drug.MaxUnit {
  1739. num := prescribing_number * float64(drug.MinNumber)
  1740. if drug.IsUse != 1 {
  1741. if drug.IsProject == 0 || drug.IsProject == 2 {
  1742. if all_count == 0 {
  1743. tx.Rollback()
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. if num > all_count {
  1748. tx.Rollback()
  1749. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1750. return
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }
  1756. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1757. //不使用保存处方出库
  1758. if drugOutConfig.IsOpen != 1 {
  1759. //修改处方
  1760. for _, advice := range advices {
  1761. var drug_id int64
  1762. var prescribing_number float64
  1763. var prescribingNumberUnit string
  1764. var prescribingNumber string
  1765. var adviceId int64
  1766. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1767. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1768. }
  1769. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1770. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1771. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1772. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1773. }
  1774. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1775. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1776. }
  1777. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1778. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1779. }
  1780. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1781. if drug.ID == 0 {
  1782. tx.Rollback()
  1783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1784. return
  1785. }
  1786. //查询药品的所有库存
  1787. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1788. var total_count int64
  1789. for _, it := range list {
  1790. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1791. }
  1792. totals := strconv.FormatInt(total_count, 10)
  1793. //查询该药品是否存在开药记录
  1794. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1795. //新增处方
  1796. if advicelist.ID == 0 {
  1797. all_count, _ := strconv.ParseFloat(totals, 64)
  1798. if prescribingNumberUnit == drug.MinUnit {
  1799. if drug.IsUse != 1 {
  1800. if drug.IsProject == 0 || drug.IsProject == 2 {
  1801. if all_count == 0 {
  1802. tx.Rollback()
  1803. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1804. return
  1805. }
  1806. if prescribing_number > all_count {
  1807. tx.Rollback()
  1808. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1809. return
  1810. }
  1811. }
  1812. }
  1813. } else {
  1814. if prescribingNumberUnit == drug.MaxUnit {
  1815. num := prescribing_number * float64(drug.MinNumber)
  1816. if drug.IsUse != 1 {
  1817. if drug.IsProject == 0 || drug.IsProject == 2 {
  1818. if all_count == 0 {
  1819. tx.Rollback()
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. if num > all_count {
  1824. tx.Rollback()
  1825. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1826. return
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. //修改处方
  1834. if advicelist.ID > 0 {
  1835. var device_number int64
  1836. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1837. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1838. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1839. device_number = prescribingNumberInt * drug.MinNumber
  1840. }
  1841. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1842. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1843. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1844. device_number = prescribingNumberInt
  1845. }
  1846. var number_count int64
  1847. if prescribingNumberUnit == drug.MaxUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if prescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1853. number_count = prescribingNumberInt
  1854. }
  1855. //如果修改的数量大于之前修改的数量
  1856. if (number_count - device_number) > 0 {
  1857. //如果修改的差数量 大于库存数量
  1858. if drug.IsUse != 1 {
  1859. if (number_count - device_number) > total_count {
  1860. tx.Rollback()
  1861. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1862. return
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. //已发药和已收费限制逻辑
  1877. //执行出库的逻辑
  1878. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1879. //校验库存总量
  1880. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1881. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1882. if len(prescriptions) > 0 {
  1883. for _, item := range prescriptions {
  1884. items := item.(map[string]interface{})
  1885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1886. advices := items["advices"].([]interface{})
  1887. if len(advices) > 0 {
  1888. for _, advice := range advices {
  1889. var drug_id int64
  1890. var prescribing_number float64
  1891. var prescribingNumberUnit string
  1892. var adviceId int64
  1893. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1894. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1895. }
  1896. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1897. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1898. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1899. }
  1900. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1901. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1902. }
  1903. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1904. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1905. }
  1906. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1907. if drug.ID == 0 {
  1908. tx.Rollback()
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1910. return
  1911. }
  1912. //查询药品的所有库存
  1913. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1914. var total_count int64
  1915. for _, it := range list {
  1916. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1917. }
  1918. totals := strconv.FormatInt(total_count, 10)
  1919. //查询该药品是否存在开药记录
  1920. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1921. //查询最新批次库存
  1922. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1923. var batch_number_count int64
  1924. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1925. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1926. //新增处方
  1927. if advicelist.ID == 0 {
  1928. all_count, _ := strconv.ParseFloat(totals, 64)
  1929. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1930. if prescribingNumberUnit == drug.MinUnit {
  1931. if drug.IsUse != 1 {
  1932. if drug.IsProject == 0 || drug.IsProject == 2 {
  1933. if all_count == 0 {
  1934. tx.Rollback()
  1935. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1936. return
  1937. }
  1938. if prescribing_number > all_count {
  1939. tx.Rollback()
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1941. return
  1942. }
  1943. }
  1944. if adminInfo.CurrentOrgId == 10215 {
  1945. if prescribing_number > batch_number_all_count {
  1946. tx.Rollback()
  1947. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1948. return
  1949. }
  1950. }
  1951. }
  1952. }
  1953. if prescribingNumberUnit == drug.MaxUnit {
  1954. num := prescribing_number * float64(drug.MinNumber)
  1955. if drug.IsUse != 1 {
  1956. if drug.IsProject == 0 || drug.IsProject == 2 {
  1957. if all_count == 0 {
  1958. tx.Rollback()
  1959. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1960. return
  1961. }
  1962. if num > all_count {
  1963. tx.Rollback()
  1964. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1965. return
  1966. }
  1967. }
  1968. if adminInfo.CurrentOrgId == 10215 {
  1969. if num > batch_number_all_count {
  1970. tx.Rollback()
  1971. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1972. return
  1973. }
  1974. }
  1975. }
  1976. }
  1977. }
  1978. //不是保存处方出库
  1979. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1980. if drugOutConfig.IsOpen != 1 {
  1981. //修改处方
  1982. for _, advice := range advices {
  1983. var drug_id int64
  1984. var prescribing_number float64
  1985. var prescribingNumberUnit string
  1986. var prescribingNumber string
  1987. var adviceId int64
  1988. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1989. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1990. }
  1991. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1992. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1993. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1994. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1995. }
  1996. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1997. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1998. }
  1999. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2000. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2001. }
  2002. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2003. if drug.ID == 0 {
  2004. tx.Rollback()
  2005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2006. return
  2007. }
  2008. //查询药品的所有库存
  2009. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2010. var total_count int64
  2011. for _, it := range list {
  2012. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2013. }
  2014. totals := strconv.FormatInt(total_count, 10)
  2015. //查询该药品是否存在开药记录
  2016. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2017. //新增处方
  2018. if advicelist.ID == 0 {
  2019. //查询最新批次库存
  2020. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2021. var batch_number_count int64
  2022. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2023. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2024. all_count, _ := strconv.ParseFloat(totals, 64)
  2025. if all_count == 0 {
  2026. tx.Rollback()
  2027. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2028. return
  2029. }
  2030. if prescribingNumberUnit == drug.MinUnit {
  2031. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2032. if drug.IsUse != 1 {
  2033. if drug.IsProject == 0 || drug.IsProject == 2 {
  2034. if all_count == 0 {
  2035. tx.Rollback()
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2037. return
  2038. }
  2039. if prescribing_number > all_count {
  2040. tx.Rollback()
  2041. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2042. return
  2043. }
  2044. }
  2045. if adminInfo.CurrentOrgId == 10215 {
  2046. if prescribing_number > batch_number_all_count {
  2047. tx.Rollback()
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2049. return
  2050. }
  2051. }
  2052. }
  2053. } else {
  2054. if prescribingNumberUnit == drug.MaxUnit {
  2055. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2056. num := prescribing_number * float64(drug.MinNumber)
  2057. if drug.IsUse != 1 {
  2058. if drug.IsProject == 0 || drug.IsProject == 2 {
  2059. if all_count == 0 {
  2060. tx.Rollback()
  2061. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2062. return
  2063. }
  2064. if num > all_count {
  2065. tx.Rollback()
  2066. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2067. return
  2068. }
  2069. }
  2070. if adminInfo.CurrentOrgId == 10215 {
  2071. if prescribing_number > batch_number_all_count {
  2072. tx.Rollback()
  2073. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2074. return
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. //修改处方
  2082. if advicelist.ID > 0 {
  2083. //查询最新批次库存
  2084. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2085. var batch_number_count int64
  2086. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2087. var device_number int64
  2088. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2089. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2090. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2091. device_number = prescribingNumberInt * drug.MinNumber
  2092. }
  2093. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2094. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2095. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2096. device_number = prescribingNumberInt
  2097. //回退库存
  2098. }
  2099. var number_count int64
  2100. if prescribingNumberUnit == drug.MaxUnit {
  2101. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2102. number_count = prescribingNumberInt * drug.MinNumber
  2103. //回退库存
  2104. }
  2105. if prescribingNumberUnit == drug.MinUnit {
  2106. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2107. number_count = prescribingNumberInt
  2108. //回退库存
  2109. }
  2110. //如果修改的数量大于之前修改的数量
  2111. if (number_count - device_number) > 0 {
  2112. //如果修改的差数量 大于库存数量
  2113. if drug.IsUse != 1 {
  2114. if drug.IsProject == 0 || drug.IsProject == 2 {
  2115. if total_count == 0 {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if (number_count - device_number) > total_count {
  2121. tx.Rollback()
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2123. return
  2124. }
  2125. if (number_count - device_number) > batch_number_count {
  2126. tx.Rollback()
  2127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2128. return
  2129. }
  2130. }
  2131. if adminInfo.CurrentOrgId == 10215 {
  2132. // 查询该药品最后一次出库记录
  2133. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2134. var out_count int64
  2135. var in_count int64
  2136. var stock_max_number int64
  2137. var stock_min_number int64
  2138. for _, it := range outInfo {
  2139. if it.CountUnit == drug.MaxUnit {
  2140. it.Count = it.Count * drug.MinNumber
  2141. }
  2142. out_count += it.Count
  2143. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2144. stock_max_number = warehouseInfoList.StockMaxNumber
  2145. stock_min_number = warehouseInfoList.StockMinNumber
  2146. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2147. }
  2148. if out_count > 0 {
  2149. if (number_count - device_number) > in_count {
  2150. tx.Rollback()
  2151. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2152. return
  2153. }
  2154. }
  2155. // 未出库
  2156. if out_count == 0 {
  2157. var sum_in_count int64
  2158. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2159. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2160. //如果修改的数量大于有库存的第一个批次
  2161. if number_count > sum_in_count {
  2162. tx.Rollback()
  2163. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2164. return
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //药品发药
  2171. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. //不使用药品发药的功能
  2173. //if pharmacyConfig.IsOpen != 1 {
  2174. // if device_number != number_count {
  2175. //
  2176. // //查询该药品的出库记录
  2177. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2178. // if len(outListExport) > 0 {
  2179. // //
  2180. // for _, item := range outListExport {
  2181. // //回退库存
  2182. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2183. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2184. // }
  2185. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2186. // var stock_max_number int64
  2187. // var stock_min_number int64
  2188. //
  2189. // if number_count >= drug.MinNumber {
  2190. //
  2191. // stock_max_number = device_number / drug.MinNumber
  2192. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2193. //
  2194. // stock_min_number = device_number % drug.MinNumber
  2195. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2196. //
  2197. // } else {
  2198. //
  2199. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2200. //
  2201. // }
  2202. // }
  2203. //
  2204. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2205. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2206. // }
  2207. // }
  2208. // }
  2209. //
  2210. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2211. // var sum_count int64
  2212. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2213. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2214. // for _, its := range stockInfo {
  2215. // if its.MaxUnit == drug.MaxUnit {
  2216. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2217. // }
  2218. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2219. // }
  2220. // //更新字典里面的库存
  2221. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2222. //
  2223. // //剩余库存
  2224. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2225. //
  2226. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2227. // //减少出库数量
  2228. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2229. //
  2230. // }
  2231. //}
  2232. }
  2233. }
  2234. }
  2235. //保存处方开药
  2236. if drugOutConfig.IsOpen == 1 {
  2237. //修改处方
  2238. for _, advice := range advices {
  2239. var drug_id int64
  2240. var prescribing_number float64
  2241. var prescribingNumberUnit string
  2242. var prescribingNumber string
  2243. var adviceId int64
  2244. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2245. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2246. }
  2247. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2248. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2249. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2250. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2251. }
  2252. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2253. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2254. }
  2255. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2256. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2257. }
  2258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2259. if drug.ID == 0 {
  2260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2261. return
  2262. }
  2263. //查询药品的所有库存
  2264. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2265. var total_count int64
  2266. for _, it := range list {
  2267. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2268. }
  2269. totals := strconv.FormatInt(total_count, 10)
  2270. //查询该药品是否存在开药记录
  2271. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2272. //新增处方
  2273. if advicelist.ID == 0 {
  2274. //查询最新批次库存
  2275. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2276. var batch_number_count int64
  2277. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2278. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2279. all_count, _ := strconv.ParseFloat(totals, 64)
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. }
  2348. var number_count int64
  2349. if prescribingNumberUnit == drug.MaxUnit {
  2350. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2351. number_count = prescribingNumberInt * drug.MinNumber
  2352. }
  2353. if prescribingNumberUnit == drug.MinUnit {
  2354. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2355. number_count = prescribingNumberInt
  2356. }
  2357. //如果修改的数量大于之前修改的数量
  2358. if (number_count - device_number) > 0 {
  2359. //如果修改的差数量 大于库存数量
  2360. if drug.IsUse != 1 {
  2361. if drug.IsProject == 0 || drug.IsProject == 2 {
  2362. if total_count == 0 {
  2363. tx.Rollback()
  2364. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2365. return
  2366. }
  2367. if (number_count - device_number) > total_count {
  2368. tx.Rollback()
  2369. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2370. return
  2371. }
  2372. }
  2373. if adminInfo.CurrentOrgId == 10215 {
  2374. if (number_count - device_number) > batch_number_count {
  2375. tx.Rollback()
  2376. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2377. return
  2378. }
  2379. }
  2380. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2381. //查询历史出库数据总批次
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. if sum_in_count == 0 {
  2411. tx.Rollback()
  2412. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2413. return
  2414. }
  2415. //如果修改的数量大于有库存的第一个批次
  2416. if number_count > sum_in_count {
  2417. tx.Rollback()
  2418. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2419. return
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. //校验耗材库存
  2436. if goodOutConfig.IsOpen == 1 {
  2437. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2438. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2439. if len(prescriptions) > 0 {
  2440. for _, item := range prescriptions {
  2441. items := item.(map[string]interface{})
  2442. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2443. projects := items["project"].([]interface{})
  2444. if len(projects) > 0 {
  2445. for _, project := range projects {
  2446. var project_id int64
  2447. var project_type int64
  2448. var totals float64
  2449. var project_name string
  2450. var parsetotal int64
  2451. var id int64
  2452. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2453. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2454. }
  2455. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2456. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2457. }
  2458. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2459. total, _ := project.(map[string]interface{})["total"].(string)
  2460. totals, _ = strconv.ParseFloat(total, 64)
  2461. }
  2462. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2463. project_name = project.(map[string]interface{})["project_name"].(string)
  2464. }
  2465. if project_type == 3 {
  2466. //查找该耗材的出库记录
  2467. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2468. if len(goodWarehouseInfo) == 0 {
  2469. //查询耗材库存
  2470. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2471. var stock_count int64
  2472. for _, it := range list {
  2473. stock_count += it.StockCount
  2474. }
  2475. stock_counts := strconv.FormatInt(stock_count, 10)
  2476. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2477. if stock_total_count == 0 {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2480. return
  2481. }
  2482. if totals > stock_total_count {
  2483. tx.Rollback()
  2484. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2485. return
  2486. }
  2487. }
  2488. if len(goodWarehouseInfo) > 0 {
  2489. //查询该患者耗材的历史数据
  2490. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2491. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2492. //数量发生改变
  2493. if parsetotal != count {
  2494. //如果现在的数量大于历史数量,就要看库存是否足够
  2495. if parsetotal > count {
  2496. //查询耗材所有库存
  2497. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2498. var stock_count int64
  2499. for _, it := range list {
  2500. stock_count += it.StockCount
  2501. }
  2502. //库存不足
  2503. if stock_count == 0 {
  2504. tx.Rollback()
  2505. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2506. return
  2507. }
  2508. if (parsetotal - count) > stock_count {
  2509. tx.Rollback()
  2510. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2511. return
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. //不使用耗材保存处方出库
  2525. if goodOutConfig.IsOpen != 1 {
  2526. if stockConfig.IsOpen == 1 {
  2527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2529. if len(prescriptions) > 0 {
  2530. for _, item := range prescriptions {
  2531. items := item.(map[string]interface{})
  2532. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2533. projects := items["project"].([]interface{})
  2534. if len(projects) > 0 {
  2535. for _, project := range projects {
  2536. var project_id int64
  2537. var project_type int64
  2538. var totals float64
  2539. var project_name string
  2540. var parsetotal int64
  2541. var id int64
  2542. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2543. id = int64(project.(map[string]interface{})["id"].(float64))
  2544. }
  2545. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2546. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2547. }
  2548. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2549. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2550. }
  2551. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2552. total, _ := project.(map[string]interface{})["total"].(string)
  2553. totals, _ = strconv.ParseFloat(total, 64)
  2554. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2555. }
  2556. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2557. project_name = project.(map[string]interface{})["project_name"].(string)
  2558. }
  2559. if project_type == 3 {
  2560. //查找该耗材的出库记录
  2561. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2562. //没有出库记录
  2563. if len(goodWarehouseInfo) == 0 {
  2564. //查询耗材库存
  2565. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2566. var stock_count int64
  2567. for _, it := range list {
  2568. stock_count += it.StockCount
  2569. }
  2570. stock_counts := strconv.FormatInt(stock_count, 10)
  2571. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2572. if stock_total_count == 0 {
  2573. tx.Rollback()
  2574. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2575. return
  2576. }
  2577. if totals > stock_total_count {
  2578. tx.Rollback()
  2579. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2580. return
  2581. }
  2582. //查找今日该患者已经出库的所有耗材
  2583. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2584. for _, item := range goodList {
  2585. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2586. var flush_count int64
  2587. for _, it := range goodListSix {
  2588. flush_count += it.StockCount
  2589. }
  2590. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2591. creater := adminInfo.AdminUser.Id
  2592. if errs != nil {
  2593. goodErrcode := models.XtGoodErrcode{
  2594. UserOrgId: item.OrgId,
  2595. Errcode: "手动出库更新剩余出库失败",
  2596. GoodId: item.GoodId,
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: 0,
  2600. Count: 0,
  2601. StockCount: 0,
  2602. Creater: creater,
  2603. BatchNumberId: 0,
  2604. WarehouseOutId: 0,
  2605. }
  2606. service.CreateGoodErrcode(goodErrcode)
  2607. }
  2608. }
  2609. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2610. }
  2611. //有出库记录
  2612. if len(goodWarehouseInfo) > 0 {
  2613. //查询该患者耗材的历史数据
  2614. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2615. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2616. //数量发生改变
  2617. if parsetotal != count {
  2618. //查找今日该患者已经出库的所有耗材
  2619. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2620. for _, item := range goodList {
  2621. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2622. var flush_count int64
  2623. for _, it := range goodListSix {
  2624. flush_count += it.StockCount
  2625. }
  2626. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2627. //减少出库数量
  2628. creater := adminInfo.AdminUser.Id
  2629. if errs != nil {
  2630. goodErrcode := models.XtGoodErrcode{
  2631. UserOrgId: item.OrgId,
  2632. Errcode: "手动出库更新剩余出库失败",
  2633. GoodId: item.GoodId,
  2634. Status: 1,
  2635. Ctime: time.Now().Unix(),
  2636. Mtime: 0,
  2637. Count: 0,
  2638. StockCount: 0,
  2639. Creater: creater,
  2640. BatchNumberId: 0,
  2641. WarehouseOutId: 0,
  2642. }
  2643. service.CreateGoodErrcode(goodErrcode)
  2644. }
  2645. //查询默认仓库
  2646. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2647. var total_count int64
  2648. for _, it := range stockList {
  2649. total_count += it.StockCount
  2650. }
  2651. //基础库插入数据
  2652. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2653. }
  2654. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2667. var hpInfo models.HisPrescriptionInfo
  2668. if info.ID == 0 {
  2669. var randNum int
  2670. randNum = rand.Intn(10000) + 1000
  2671. timestamp := time.Now().Unix()
  2672. tempTime := time.Unix(timestamp, 0)
  2673. timeFormat := tempTime.Format("20060102150405")
  2674. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2675. hpInfo = models.HisPrescriptionInfo{
  2676. HisPatientId: his_patient_id,
  2677. UserOrgId: adminInfo.CurrentOrgId,
  2678. RecordDate: theTime.Unix(),
  2679. PatientId: patient_id,
  2680. Status: 1,
  2681. Ctime: time.Now().Unix(),
  2682. Mtime: time.Now().Unix(),
  2683. Creator: adminInfo.AdminUser.Id,
  2684. Modifier: adminInfo.AdminUser.Id,
  2685. Diagnosis: diagnose,
  2686. SickHistory: sick_history,
  2687. Departments: department,
  2688. RegisterType: reg_type,
  2689. PrescriptionNumber: p_number,
  2690. PrescriptionStatus: 1,
  2691. Doctor: role.UserName,
  2692. DoctorId: doctor_id,
  2693. SickType: sick_type,
  2694. PType: p_type,
  2695. PatientDiagnosis: patient_diagnose,
  2696. }
  2697. service.SavePatientPrescriptionInfo(hpInfo)
  2698. //创建步骤表
  2699. finish := models.XtDialysisFinish{
  2700. IsFinish: 1,
  2701. UserOrgId: adminInfo.CurrentOrgId,
  2702. Status: 1,
  2703. Ctime: time.Now().Unix(),
  2704. Mtime: 0,
  2705. Module: 4,
  2706. RecordDate: theTime.Unix(),
  2707. Sourse: 1,
  2708. PatientId: patient_id,
  2709. }
  2710. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2711. if dialysisFinish.ID == 0 {
  2712. service.CreateDialysisFinish(finish)
  2713. }
  2714. redis := service.RedisClient()
  2715. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2716. redis.Set(key, "", time.Second)
  2717. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2718. redis.Set(keyOne, "", time.Second)
  2719. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2720. redis.Set(keySeven, "", time.Second)
  2721. defer redis.Close()
  2722. } else {
  2723. hpInfo = models.HisPrescriptionInfo{
  2724. ID: info.ID,
  2725. UserOrgId: adminInfo.CurrentOrgId,
  2726. RecordDate: info.RecordDate,
  2727. PatientId: info.PatientId,
  2728. Status: 1,
  2729. Ctime: info.Ctime,
  2730. Mtime: time.Now().Unix(),
  2731. Creator: info.Creator,
  2732. Modifier: adminInfo.AdminUser.Id,
  2733. Diagnosis: diagnose,
  2734. SickHistory: sick_history,
  2735. Departments: department,
  2736. RegisterType: reg_type,
  2737. PrescriptionNumber: info.PrescriptionNumber,
  2738. Doctor: role.UserName,
  2739. PrescriptionStatus: info.PrescriptionStatus,
  2740. DoctorId: doctor_id,
  2741. SickType: sick_type,
  2742. PType: info.PType,
  2743. HisPatientId: info.HisPatientId,
  2744. PatientDiagnosis: patient_diagnose,
  2745. }
  2746. service.SavePatientPrescriptionInfo(hpInfo)
  2747. //创建步骤表
  2748. finish := models.XtDialysisFinish{
  2749. IsFinish: 1,
  2750. UserOrgId: adminInfo.CurrentOrgId,
  2751. Status: 1,
  2752. Ctime: time.Now().Unix(),
  2753. Mtime: 0,
  2754. Module: 4,
  2755. RecordDate: info.RecordDate,
  2756. Sourse: 1,
  2757. PatientId: info.PatientId,
  2758. }
  2759. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2760. if dialysisFinish.ID == 0 {
  2761. service.CreateDialysisFinish(finish)
  2762. }
  2763. redis := service.RedisClient()
  2764. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2765. redis.Set(key, "", time.Second)
  2766. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2767. redis.Set(keyOne, "", time.Second)
  2768. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2769. redis.Set(keySeven, "", time.Second)
  2770. defer redis.Close()
  2771. }
  2772. //定义切片
  2773. var adviceList []models.HisDoctorAdviceInfo
  2774. var projectList []models.HisPrescriptionProject
  2775. 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 {
  2776. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2777. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2778. var tempPrescription *models.HisPrescription
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. // 开始外部循环的事务
  2782. tx := db.Begin()
  2783. // 在函数结束时处理事务回滚
  2784. defer func() {
  2785. if r := recover(); r != nil {
  2786. tx.Rollback()
  2787. }
  2788. }()
  2789. items := item.(map[string]interface{})
  2790. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2791. utils.ErrorLog("id")
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. id := int64(items["id"].(float64))
  2796. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2797. tempPrescription = &new_prescription
  2798. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2799. utils.ErrorLog("type")
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. types := int64(items["type"].(float64))
  2804. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2805. utils.ErrorLog("med_type")
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2810. if med_type == "0" {
  2811. med_type = "14"
  2812. }
  2813. //if order_status == 0 {
  2814. // order_status = 1
  2815. //}
  2816. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2817. utils.ErrorLog("pre_time")
  2818. }
  2819. preTime, _ := items["pre_time"].(string)
  2820. fmt.Println("preTime", preTime)
  2821. timeLayout := "2006-01-02"
  2822. loc, _ := time.LoadLocation("Local")
  2823. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2824. result := strings.Split(preTime, " ")
  2825. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2826. if err != nil {
  2827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2828. return
  2829. }
  2830. pTime := theTime2.Unix()
  2831. ctime := time.Now().Unix()
  2832. if tempPrescription.ID == 0 {
  2833. prescription := &models.HisPrescription{
  2834. ID: 0,
  2835. PatientId: patient_id,
  2836. UserOrgId: adminInfo.CurrentOrgId,
  2837. RecordDate: recordDateTime,
  2838. Ctime: ctime,
  2839. Mtime: ctime,
  2840. Type: types,
  2841. Modifier: adminInfo.AdminUser.Id,
  2842. Creator: adminInfo.AdminUser.Id,
  2843. Status: 1,
  2844. Doctor: role.UserName,
  2845. HisPatientId: his_patient_id,
  2846. OrderStatus: 1,
  2847. BatchNumber: "",
  2848. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2849. PreTime: pTime,
  2850. PType: p_type,
  2851. MedType: med_type,
  2852. }
  2853. tempPrescription = prescription
  2854. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2855. redis := service.RedisClient()
  2856. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2857. redis.Set(key, "", time.Second)
  2858. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2859. redis.Set(keyOne, "", time.Second)
  2860. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2861. redis.Set(keySeven, "", time.Second)
  2862. defer redis.Close()
  2863. } else {
  2864. tempPrescription.ID = id
  2865. tempPrescription.Type = types
  2866. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2867. tempPrescription.Mtime = time.Now().Unix()
  2868. tempPrescription.Doctor = role.UserName
  2869. //tempPrescription.OrderStatus = order_status
  2870. tempPrescription.PreTime = pTime
  2871. tempPrescription.MedType = med_type
  2872. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2873. redis := service.RedisClient()
  2874. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2875. redis.Set(key, "", time.Second)
  2876. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2877. redis.Set(keyOne, "", time.Second)
  2878. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2879. redis.Set(keySeven, "", time.Second)
  2880. defer redis.Close()
  2881. }
  2882. //service.SaveHisPrescription(prescription)
  2883. //更改患者挂号状态
  2884. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2885. fmt.Println("更改失败", err2)
  2886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2887. advices := items["advices"].([]interface{})
  2888. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2889. groupNo := int64(0)
  2890. if len(advices) > 0 {
  2891. for _, advice := range advices {
  2892. tx := db.Begin()
  2893. // 在函数结束时处理事务回滚
  2894. defer func() {
  2895. if r := recover(); r != nil {
  2896. tx.Rollback()
  2897. }
  2898. }()
  2899. var s models.HisDoctorAdviceInfo
  2900. s.PrescriptionId = tempPrescription.ID
  2901. s.AdviceType = 2
  2902. s.AdviceDoctor = doctor_id
  2903. s.StopState = 2
  2904. s.ExecutionState = 2
  2905. s.AdviceDate = theTime3.Unix()
  2906. s.Status = 1
  2907. s.UserOrgId = adminInfo.CurrentOrgId
  2908. s.RecordDate = theTime3.Unix()
  2909. s.StartTime = tempPrescription.PreTime
  2910. s.Groupno = groupNo
  2911. s.PatientId = patient_id
  2912. s.HisPatientId = his_patient_id
  2913. s.StartTime = pTime
  2914. s.IsSettle = 2
  2915. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2916. if errcode > 0 {
  2917. c.ServeFailJSONWithSGJErrorCode(errcode)
  2918. return
  2919. }
  2920. s.StartTime = pTime
  2921. var total_count int64 //处方总库存
  2922. //查询改药品信息
  2923. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2924. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2925. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2926. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2927. total_count += prescribingNumberSeven * medical.MinNumber
  2928. }
  2929. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2930. total_count += prescribingNumberSeven
  2931. }
  2932. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2933. total_count += prescribingNumberSeven
  2934. }
  2935. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  2936. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2937. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2938. if s.Price != lastWarehouse.RetailPrice {
  2939. s.Price = lastWarehouse.RetailPrice
  2940. }
  2941. if s.Price == 0 {
  2942. if lastWarehouse.ID == 0 {
  2943. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2944. s.Price = lastWarehouseTwo.RetailPrice
  2945. }
  2946. }
  2947. }
  2948. //查询保存处方出库开关是否打开
  2949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2950. if s.PatientId != 30038 {
  2951. if drugOutConfig.IsOpen == 1 {
  2952. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2953. // 查询该药品最后一次出库记录
  2954. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2955. var is_user_total int64
  2956. var no_user_total int64
  2957. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2958. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2959. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2960. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2961. }
  2962. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2963. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2964. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2965. no_user_total += prescribingNumberSevenTy
  2966. }
  2967. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2968. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2969. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2970. no_user_total += prescribingNumberSevenTy
  2971. }
  2972. if len(druginfo) > 0 {
  2973. for _, it := range druginfo {
  2974. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2975. it.Count = it.Count * drug.MinNumber
  2976. is_user_total += it.Count
  2977. }
  2978. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2979. is_user_total += it.Count
  2980. }
  2981. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2982. is_user_total += it.Count
  2983. }
  2984. }
  2985. }
  2986. //fmt.Println("药品名称----------------------", drug.DrugName)
  2987. //fmt.Println("药品名称----------------------", drug.IsUse)
  2988. //fmt.Println("is_user_total-------------------------", is_user_total)
  2989. //fmt.Println("no_user_total-------------------------", no_user_total)
  2990. if is_user_total != no_user_total {
  2991. //出库
  2992. if drug.IsUse == 2 {
  2993. creater := adminInfo.AdminUser.Id
  2994. newadviceInfo := &models.HisDoctorAdviceInfo{
  2995. ID: s.ID,
  2996. UserOrgId: s.UserOrgId,
  2997. PatientId: s.PatientId,
  2998. HisPatientId: s.HisPatientId,
  2999. AdviceType: s.AdviceType,
  3000. AdviceDate: s.AdviceDate,
  3001. StartTime: s.StartTime,
  3002. AdviceName: s.AdviceName,
  3003. AdviceDesc: s.AdviceDesc,
  3004. ReminderDate: s.ReminderDate,
  3005. SingleDose: s.SingleDose,
  3006. SingleDoseUnit: s.SingleDoseUnit,
  3007. PrescribingNumber: s.PrescribingNumber,
  3008. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3009. DeliveryWay: s.DeliveryWay,
  3010. ExecutionFrequency: s.ExecutionFrequency,
  3011. AdviceDoctor: s.AdviceDoctor,
  3012. Status: s.Status,
  3013. CreatedTime: s.CreatedTime,
  3014. UpdatedTime: s.UpdatedTime,
  3015. AdviceAffirm: s.AdviceAffirm,
  3016. Remark: s.Remark,
  3017. StopTime: s.StopTime,
  3018. StopReason: s.StopReason,
  3019. StopDoctor: s.StopDoctor,
  3020. StopState: s.StopState,
  3021. ParentId: s.ParentId,
  3022. ExecutionTime: s.ExecutionTime,
  3023. ExecutionStaff: s.ExecutionStaff,
  3024. ExecutionState: s.ExecutionState,
  3025. Checker: s.Checker,
  3026. RecordDate: s.RecordDate,
  3027. DialysisOrderId: s.DialysisOrderId,
  3028. CheckTime: s.CheckTime,
  3029. CheckState: s.CheckState,
  3030. DrugSpec: s.DrugSpec,
  3031. DrugSpecUnit: s.DrugSpecUnit,
  3032. Groupno: s.Groupno,
  3033. RemindType: s.RemindType,
  3034. FrequencyType: s.FrequencyType,
  3035. DayCount: s.DayCount,
  3036. WeekDay: s.WeekDay,
  3037. TemplateId: s.TemplateId,
  3038. Modifier: s.Modifier,
  3039. DrugId: s.DrugId,
  3040. Price: s.Price,
  3041. PrescriptionId: s.PrescriptionId,
  3042. MedListCodg: s.MedListCodg,
  3043. FeedetlSn: s.FeedetlSn,
  3044. Day: s.DayCount,
  3045. ChildDoctorAdvice: nil,
  3046. Drug: models.Drug{},
  3047. Diagnosis: s.Diagnosis,
  3048. Way: s.Way,
  3049. HospApprFlag: s.HospApprFlag,
  3050. LmtUsedFlag: s.LmtUsedFlag,
  3051. HisOrderInfo: models.HisOrderInfo{},
  3052. IsMedicine: s.IsMedicine,
  3053. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3054. Child: nil,
  3055. IsSettle: s.IsSettle,
  3056. IsMobile: s.IsMobile,
  3057. IsSelfDrug: s.IsSelfDrug,
  3058. DrugWayCount: s.DrugWayCount,
  3059. }
  3060. var history_count int64
  3061. var local_count int64
  3062. //查找已经开过的医嘱信息
  3063. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3064. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. local_count += prescribingNumberSevenTy * drug.MinNumber
  3068. }
  3069. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. local_count += prescribingNumberSevenTy
  3073. }
  3074. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3075. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3076. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3077. local_count += prescribingNumberSevenTy
  3078. }
  3079. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3080. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3081. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3082. history_count += prescribingNumberSevenTy * drug.MinNumber
  3083. }
  3084. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3085. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3086. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3087. history_count += prescribingNumberSevenTy
  3088. }
  3089. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3090. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3091. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3092. history_count += prescribingNumberSevenTy
  3093. }
  3094. //如果当前出库数量大于历史出库数量则需要出库
  3095. if local_count > history_count {
  3096. //按最小单位出库
  3097. var cha_count = local_count - history_count
  3098. newadviceInfo.PrescribingNumber = float64(cha_count)
  3099. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3100. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3101. }
  3102. //如果当前出库数量小于历史出库数量则需要退库
  3103. if local_count < history_count {
  3104. var cha_count = history_count - local_count
  3105. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. }
  3108. if local_count == history_count {
  3109. if is_user_total == 0 {
  3110. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3111. }
  3112. }
  3113. }
  3114. //更新字典里面的库存
  3115. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3116. var sum_count int64
  3117. for _, its := range stockInfo {
  3118. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3119. if its.MaxUnit == baseDrug.MaxUnit {
  3120. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3121. }
  3122. sum_count += its.StockMaxNumber + its.StockMinNumber
  3123. }
  3124. //更新基础库存
  3125. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3126. //剩余库存
  3127. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3128. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3129. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3130. //创建医嘱
  3131. service.CreateHisDoctorAdviceOne(&s, tx)
  3132. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. if len(outInfoTwo) > 0 {
  3135. for _, item := range outInfoTwo {
  3136. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3137. }
  3138. }
  3139. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3140. if len(drugAutoDetail) > 0 {
  3141. for _, item := range drugAutoDetail {
  3142. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. //记录日志
  3149. byterequest, _ := json.Marshal(s)
  3150. adviceLog := models.XtDoctorAdviceLog{
  3151. UserOrgId: s.UserOrgId,
  3152. PatientId: s.PatientId,
  3153. AdminUserId: adminInfo.AdminUser.Id,
  3154. Module: 1,
  3155. ErrLog: string(byterequest),
  3156. Status: 1,
  3157. Ctime: time.Now().Unix(),
  3158. Mtime: 0,
  3159. Source: "电脑端新建his医嘱",
  3160. RecordDate: s.AdviceDate,
  3161. }
  3162. service.CreateDoctorAdviceLog(adviceLog)
  3163. //存储切片中
  3164. adviceList = append(adviceList, s)
  3165. redis := service.RedisClient()
  3166. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3167. redis.Set(key, "", time.Second)
  3168. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3169. redis.Set(keyOne, "", time.Second)
  3170. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3171. redis.Set(keySeven, "", time.Second)
  3172. var randNum int
  3173. randNum = rand.Intn(10000) + 1000
  3174. timestamp := time.Now().Unix()
  3175. tempTime := time.Unix(timestamp, 0)
  3176. timeFormat := tempTime.Format("20060102150405")
  3177. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3178. //查询改药品是否已经停用
  3179. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3180. if base.ID > 0 {
  3181. tx.Rollback()
  3182. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3183. return
  3184. }
  3185. service.CreateHisDoctorAdviceOne(&s, tx)
  3186. tx.Commit()
  3187. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3188. redis.Set(keySix, "", time.Second)
  3189. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3190. redis.Set(keyFive, "", time.Second)
  3191. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3192. redis.Set(keyEight, "", time.Second)
  3193. defer redis.Close()
  3194. }
  3195. }
  3196. }
  3197. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3198. projects := items["project"].([]interface{})
  3199. if len(projects) > 0 {
  3200. for _, project := range projects {
  3201. tx := db.Begin()
  3202. // 在函数结束时处理事务回滚
  3203. defer func() {
  3204. if r := recover(); r != nil {
  3205. tx.Rollback()
  3206. }
  3207. }()
  3208. var p models.HisPrescriptionProject
  3209. p.PrescriptionId = tempPrescription.ID
  3210. p.PatientId = patient_id
  3211. p.RecordDate = theTime3.Unix()
  3212. p.Doctor = doctor_id
  3213. p.UserOrgId = adminInfo.CurrentOrgId
  3214. p.HisPatientId = his_patient_id
  3215. p.Status = 1
  3216. p.StartTime = pTime
  3217. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3218. if errcode > 0 {
  3219. c.ServeFailJSONWithSGJErrorCode(errcode)
  3220. return
  3221. }
  3222. if p.ID == 0 {
  3223. p.IsOut = 2
  3224. }
  3225. if p.ID > 0 {
  3226. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3227. p.IsOut = projectDetail.IsOut
  3228. }
  3229. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3230. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3231. if p.Type == 3 {
  3232. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3233. if p.Price != lastWarehouse.PackingPrice {
  3234. p.Price = lastWarehouse.PackingPrice
  3235. }
  3236. if p.Price == 0 {
  3237. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3238. p.Price = lastWarehouseTwo.PackingPrice
  3239. }
  3240. if p.Unit == "" {
  3241. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3242. p.Unit = goodInfoOne.PackingUnit
  3243. }
  3244. }
  3245. }
  3246. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3247. //
  3248. // if p.Type == 3 {
  3249. // //查询该耗材是否停用
  3250. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3251. // //表示该耗材已经停用,不能保存
  3252. // if goodInfoSeven.ID == 0 {
  3253. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3254. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3255. // return
  3256. // }
  3257. // }
  3258. //
  3259. //}
  3260. //查询保存耗材出库开关是否打开
  3261. if p.PatientId != 30038 {
  3262. if goodOutConfig.IsOpen == 1 {
  3263. //耗材出库
  3264. if p.Type == 3 {
  3265. //对比当前数据和历史出库数据
  3266. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3267. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3268. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3269. //如果当前处方数量大于历史数据,则需要出库
  3270. if nowCount > historyCount {
  3271. var cha_count int64
  3272. cha_count = nowCount - historyCount
  3273. timeStr := time.Now().Format("2006-01-02")
  3274. timeArr := strings.Split(timeStr, "-")
  3275. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3276. total = total + 1
  3277. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3278. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3279. number = number + total
  3280. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3281. operation_time := time.Now().Unix()
  3282. creater := c.GetAdminUserInfo().AdminUser.Id
  3283. recordDateStr := time.Now().Format("2006-01-02")
  3284. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3285. nowtime := recordDate.Unix()
  3286. warehouseOut := models.WarehouseOut{
  3287. WarehouseOutOrderNumber: warehousing_out_order,
  3288. OperationTime: operation_time,
  3289. OrgId: adminInfo.CurrentOrgId,
  3290. Creater: creater,
  3291. Ctime: time.Now().Unix(),
  3292. Status: 1,
  3293. WarehouseOutTime: nowtime,
  3294. Type: 1,
  3295. StorehouseId: storeConfig.StorehouseOutInfo,
  3296. IsCheck: 1,
  3297. IsSys: 1,
  3298. }
  3299. //查询是否生成出库单
  3300. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3301. if out.ID == 0 {
  3302. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3303. }
  3304. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3305. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3306. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3307. dialyPrepareOne := models.DialysisBeforePrepare{
  3308. GoodTypeId: goodObj.GoodTypeId,
  3309. GoodId: p.ProjectId,
  3310. PatientId: p.PatientId,
  3311. RecordDate: p.RecordDate,
  3312. UserOrgId: adminInfo.CurrentOrgId,
  3313. Count: cha_count,
  3314. Ctime: time.Now().Unix(),
  3315. Creater: creater,
  3316. Status: 1,
  3317. StorehouseId: houseConfig.StorehouseOutInfo,
  3318. ProjectId: p.ID,
  3319. }
  3320. //出库
  3321. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3322. }
  3323. //如果当前处方数量小于历史数据,怎需要退库
  3324. if nowCount < historyCount {
  3325. var cha_count int64
  3326. cha_count = historyCount - nowCount
  3327. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3328. creater := c.GetAdminUserInfo().AdminUser.Id
  3329. newPrescriptionProject := &models.HisPrescriptionProject{
  3330. ID: p.ID,
  3331. ProjectId: p.ProjectId,
  3332. Price: p.Price,
  3333. UserOrgId: p.UserOrgId,
  3334. Status: 1,
  3335. Ctime: time.Now().Unix(),
  3336. Mtime: time.Now().Unix(),
  3337. PatientId: p.PatientId,
  3338. HisPatientId: p.HisPatientId,
  3339. RecordDate: p.RecordDate,
  3340. PrescriptionId: p.PrescriptionId,
  3341. Count: p.Count,
  3342. FeedetlSn: p.FeedetlSn,
  3343. MedListCodg: p.MedListCodg,
  3344. SingleDose: p.SingleDose,
  3345. DeliveryWay: p.DeliveryWay,
  3346. ExecutionFrequency: p.ExecutionFrequency,
  3347. Day: p.Day,
  3348. HisProject: models.HisProject{},
  3349. GoodInfo: models.GoodInfo{},
  3350. Remark: p.Remark,
  3351. Unit: p.Unit,
  3352. Type: p.Type,
  3353. Doctor: p.Doctor,
  3354. ExecutionTime: p.ExecutionTime,
  3355. ExecutionStaff: p.ExecutionStaff,
  3356. ExecutionState: p.ExecutionState,
  3357. CheckTime: p.CheckTime,
  3358. CheckState: p.CheckState,
  3359. Checker: p.Checker,
  3360. StartTime: p.StartTime,
  3361. TeamId: p.TeamId,
  3362. XtHisProjectTeam: models.XtHisProjectTeam{},
  3363. FrequencyType: p.FrequencyType,
  3364. DayCount: p.DayCount,
  3365. WeekDay: p.WeekDay,
  3366. IsCheckTeam: p.IsCheckTeam,
  3367. HisOrderInfo: models.HisOrderInfo{},
  3368. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3369. IsOut: p.IsOut,
  3370. YbSyncStatus: p.YbSyncStatus,
  3371. }
  3372. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3373. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3374. }
  3375. if nowCount == historyCount {
  3376. if historyCount == 0 {
  3377. recordDateStr := time.Now().Format("2006-01-02")
  3378. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3379. nowtime := recordDate.Unix()
  3380. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3381. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3382. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3383. creater := c.GetAdminUserInfo().AdminUser.Id
  3384. dialyPrepareOne := models.DialysisBeforePrepare{
  3385. GoodTypeId: goodObj.GoodTypeId,
  3386. GoodId: p.ProjectId,
  3387. PatientId: p.PatientId,
  3388. RecordDate: p.RecordDate,
  3389. UserOrgId: adminInfo.CurrentOrgId,
  3390. Count: nowCount,
  3391. Ctime: time.Now().Unix(),
  3392. Creater: creater,
  3393. Status: 1,
  3394. StorehouseId: houseConfig.StorehouseOutInfo,
  3395. ProjectId: p.ID,
  3396. }
  3397. //出库
  3398. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3399. }
  3400. }
  3401. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3402. ////查询历史出库数据
  3403. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3404. //
  3405. //var out_count_five int64
  3406. //for _, item := range flowGood {
  3407. // out_count_five += item.Count
  3408. //}
  3409. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3410. //
  3411. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3412. //if out_count_five != parseIntCount {
  3413. // //查询耗材最后一次出库记录
  3414. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3415. // //查询默认出库仓库库存
  3416. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3417. // if len(wareOut) > 0 {
  3418. //
  3419. // for _, it := range wareOut {
  3420. // //回退库存
  3421. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3422. //
  3423. // //删除出库记录
  3424. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3425. //
  3426. // }
  3427. // }
  3428. //
  3429. // timeStr := time.Now().Format("2006-01-02")
  3430. // timeArr := strings.Split(timeStr, "-")
  3431. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3432. //
  3433. // total = total + 1
  3434. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3435. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3436. // number = number + total
  3437. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3438. //
  3439. // operation_time := time.Now().Unix()
  3440. // creater := c.GetAdminUserInfo().AdminUser.Id
  3441. //
  3442. // recordDateStr := time.Now().Format("2006-01-02")
  3443. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3444. // nowtime := recordDate.Unix()
  3445. // warehouseOut := models.WarehouseOut{
  3446. // WarehouseOutOrderNumber: warehousing_out_order,
  3447. // OperationTime: operation_time,
  3448. // OrgId: adminInfo.CurrentOrgId,
  3449. // Creater: creater,
  3450. // Ctime: time.Now().Unix(),
  3451. // Status: 1,
  3452. // WarehouseOutTime: nowtime,
  3453. // Type: 1,
  3454. // StorehouseId: storeConfig.StorehouseOutInfo,
  3455. // IsCheck: 1,
  3456. // IsSys: 1,
  3457. // }
  3458. // //查询是否生成出库单
  3459. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3460. // if out.ID == 0 {
  3461. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3462. // }
  3463. //
  3464. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3465. //
  3466. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3467. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3468. //
  3469. // dialyPrepareOne := models.DialysisBeforePrepare{
  3470. // GoodTypeId: goodObj.GoodTypeId,
  3471. // GoodId: p.ProjectId,
  3472. // PatientId: p.PatientId,
  3473. // RecordDate: p.RecordDate,
  3474. // UserOrgId: adminInfo.CurrentOrgId,
  3475. // Count: parseIntCount,
  3476. // Ctime: time.Now().Unix(),
  3477. // Creater: creater,
  3478. // Status: 1,
  3479. // StorehouseId: houseConfig.StorehouseOutInfo,
  3480. // ProjectId: lastHisProject.ID,
  3481. // }
  3482. // //判断是否是零用耗材(非零用)
  3483. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3484. //
  3485. // //查询历史出库数据
  3486. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3487. // var out_count int64
  3488. // for _, item := range flowGood {
  3489. // out_count += item.Count
  3490. // }
  3491. // //如果历史数和当前数据不想等才进行退库出库
  3492. // if out_count != parseIntCount {
  3493. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3494. //
  3495. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3496. // detail := models.AutomaticReduceDetail{
  3497. // WarehouseOutId: 0,
  3498. // WarehouseOutOrderNumber: "",
  3499. // PatientId: p.PatientId,
  3500. // Ctime: time.Now().Unix(),
  3501. // Mtime: 0,
  3502. // Status: 1,
  3503. // RecordTime: p.RecordDate,
  3504. // OrgId: p.UserOrgId,
  3505. // GoodId: p.ProjectId,
  3506. // GoodTypeId: 0,
  3507. // Count: parseIntCount,
  3508. // Type: 0,
  3509. // ProjectId: lastHisProject.ID,
  3510. // StorehouseId: 0,
  3511. // }
  3512. //
  3513. // service.CreateNewAutoDetail(detail, tx)
  3514. //
  3515. // //查询剩余库存
  3516. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3517. // var sum_count int64
  3518. // for _, item := range goodList {
  3519. // sum_count += item.StockCount
  3520. // }
  3521. //
  3522. // //更新剩余库存
  3523. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3524. //
  3525. // //耗材
  3526. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3527. //
  3528. // }
  3529. // //判断是否是零用耗材(零用但是是出库耗材)
  3530. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3531. //
  3532. // //查询历史出库数据
  3533. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3534. // var out_count int64
  3535. // for _, item := range flowGood {
  3536. // out_count += item.Count
  3537. // }
  3538. // //如果历史数和当前数据不想等才进行退库出库
  3539. // if out_count != parseIntCount {
  3540. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3541. //
  3542. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3543. // detail := models.AutomaticReduceDetail{
  3544. // WarehouseOutId: 0,
  3545. // WarehouseOutOrderNumber: "",
  3546. // PatientId: p.PatientId,
  3547. // Ctime: time.Now().Unix(),
  3548. // Mtime: 0,
  3549. // Status: 1,
  3550. // RecordTime: p.RecordDate,
  3551. // OrgId: p.UserOrgId,
  3552. // GoodId: p.ProjectId,
  3553. // GoodTypeId: 0,
  3554. // Count: parseIntCount,
  3555. // Type: 0,
  3556. // ProjectId: p.ID,
  3557. // StorehouseId: 0,
  3558. // }
  3559. //
  3560. // service.CreateNewAutoDetail(detail, tx)
  3561. //
  3562. // //查询剩余库存
  3563. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3564. // var sum_count int64
  3565. // for _, item := range goodList {
  3566. // sum_count += item.StockCount
  3567. // }
  3568. //
  3569. // //更新剩余库存
  3570. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3571. //
  3572. // //耗材
  3573. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3574. // }
  3575. //
  3576. // }
  3577. //
  3578. // }
  3579. //
  3580. //}
  3581. //记录日志
  3582. byterequest, _ := json.Marshal(p)
  3583. adviceLog := models.XtDoctorAdviceLog{
  3584. UserOrgId: p.UserOrgId,
  3585. PatientId: p.PatientId,
  3586. AdminUserId: adminInfo.AdminUser.Id,
  3587. Module: 1,
  3588. ErrLog: string(byterequest),
  3589. Status: 1,
  3590. Ctime: time.Now().Unix(),
  3591. Mtime: 0,
  3592. Source: "电脑端新建his项目",
  3593. RecordDate: p.RecordDate,
  3594. }
  3595. service.CreateDoctorAdviceLog(adviceLog)
  3596. projectList = append(projectList, p)
  3597. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3598. //新增或者编辑项目,修改对应的标签数据
  3599. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3600. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3601. var label models.HisLabelPrintInfo
  3602. project, _ := service.GetProjectDetail(p.ProjectId)
  3603. if project.CostClassify == 3 { //类别为检验检查
  3604. if p.TeamId > 0 { //检验检查组套
  3605. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3606. if tempLabel.ID == 0 {
  3607. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3608. label.Number = tempPrescription.PrescriptionNumber
  3609. label.ProjectId = project.ID
  3610. label.Status = 1
  3611. label.IsPrint = 2
  3612. label.DoctorId = info.DoctorId
  3613. label.UserOrgId = p.UserOrgId
  3614. label.PatientId = patient_id
  3615. label.RecordDate = recordDateTime
  3616. label.Ctime = time.Now().Unix()
  3617. label.Mtime = time.Now().Unix()
  3618. label.ItemId = p.TeamId
  3619. label.FeedetlSn = p.FeedetlSn
  3620. label.PProjectId = p.ID
  3621. label.ProjectName = team.ProjectTeam
  3622. label.PatientName = patient.Name
  3623. service.CreateNewHisLabelRecord(&label, tx)
  3624. }
  3625. } else { //单条检验检查项目
  3626. label.Number = tempPrescription.PrescriptionNumber
  3627. label.ProjectId = project.ID
  3628. label.Status = 1
  3629. label.DoctorId = info.DoctorId
  3630. label.UserOrgId = p.UserOrgId
  3631. label.PatientId = patient_id
  3632. label.RecordDate = recordDateTime
  3633. label.IsPrint = 2
  3634. label.Ctime = time.Now().Unix()
  3635. label.Mtime = time.Now().Unix()
  3636. label.FeedetlSn = p.FeedetlSn
  3637. label.PProjectId = p.ID
  3638. label.ItemId = p.TeamId
  3639. label.ProjectName = project.ProjectName
  3640. label.PatientName = patient.Name
  3641. service.CreateNewHisLabelRecord(&label, tx)
  3642. }
  3643. }
  3644. }
  3645. }
  3646. }
  3647. }
  3648. }
  3649. service.CreateNewHisProjectTwo(&p, tx)
  3650. var randNum int
  3651. randNum = rand.Intn(10000) + 1000
  3652. timestamp := time.Now().Unix()
  3653. tempTime := time.Unix(timestamp, 0)
  3654. timeFormat := tempTime.Format("20060102150405")
  3655. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3656. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3657. if goodBase.ID > 0 {
  3658. tx.Rollback()
  3659. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3660. return
  3661. }
  3662. service.CreateNewHisProjectTwo(&p, tx)
  3663. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3664. //查询剩余库存
  3665. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3666. var sum_count int64
  3667. for _, item := range goodList {
  3668. sum_count += item.StockCount
  3669. }
  3670. //更新剩余库存
  3671. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3672. //耗材
  3673. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3674. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3675. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3676. if len(outInfoTwo) > 0 {
  3677. for _, item := range outInfoTwo {
  3678. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3679. }
  3680. }
  3681. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3682. if len(drugAutoDetail) > 0 {
  3683. for _, item := range drugAutoDetail {
  3684. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3685. }
  3686. }
  3687. tx.Commit()
  3688. }
  3689. }
  3690. }
  3691. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3692. // addition := items["addition"].([]interface{})
  3693. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3694. // ctime := time.Now().Unix()
  3695. // mtime := ctime
  3696. // if len(addition) > 0 {
  3697. // for _, item := range addition {
  3698. // var s models.HisAdditionalCharge
  3699. // s.PrescriptionId = tempPrescription.ID
  3700. // s.Status = 1
  3701. // s.UserOrgId = adminInfo.CurrentOrgId
  3702. // s.RecordDate = recordDateTime
  3703. // s.CreatedTime = ctime
  3704. // s.UpdatedTime = mtime
  3705. // s.PatientId = patient_id
  3706. // s.HisPatientId = his_patient_id
  3707. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3708. // if errcode > 0 {
  3709. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3710. // return
  3711. // }
  3712. // service.CreateAdditionalCharge(&s)
  3713. // var randNum int
  3714. // randNum = rand.Intn(10000) + 1000
  3715. // timestamp := time.Now().Unix()
  3716. // tempTime := time.Unix(timestamp, 0)
  3717. // timeFormat := tempTime.Format("20060102150405")
  3718. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3719. // service.CreateAdditionalCharge(&s)
  3720. //
  3721. // }
  3722. // }
  3723. //}
  3724. }
  3725. }
  3726. }
  3727. tx.Commit()
  3728. if err == nil {
  3729. c.ServeSuccessJSON(map[string]interface{}{
  3730. "msg": "保存成功",
  3731. })
  3732. return
  3733. } else {
  3734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3735. return
  3736. }
  3737. } else {
  3738. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3739. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3740. var tempPrescription *models.HisPrescription
  3741. if len(prescriptions) > 0 {
  3742. for _, item := range prescriptions {
  3743. items := item.(map[string]interface{})
  3744. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3745. utils.ErrorLog("id")
  3746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3747. return
  3748. }
  3749. id := int64(items["id"].(float64))
  3750. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3751. tempPrescription = &new_prescription
  3752. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3753. utils.ErrorLog("type")
  3754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3755. return
  3756. }
  3757. types := int64(items["type"].(float64))
  3758. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3759. utils.ErrorLog("med_type")
  3760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3764. if med_type == "0" {
  3765. med_type = "14"
  3766. }
  3767. //if order_status == 0 {
  3768. // order_status = 1
  3769. //}
  3770. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3771. utils.ErrorLog("pre_time")
  3772. }
  3773. preTime, _ := items["pre_time"].(string)
  3774. timeLayout := "2006-01-02"
  3775. loc, _ := time.LoadLocation("Local")
  3776. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3777. result := strings.Split(preTime, " ")
  3778. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3779. if err != nil {
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3781. return
  3782. }
  3783. pTime := theTime2.Unix()
  3784. ctime := time.Now().Unix()
  3785. if tempPrescription.ID == 0 {
  3786. prescription := &models.HisPrescription{
  3787. ID: 0,
  3788. PatientId: patient_id,
  3789. UserOrgId: adminInfo.CurrentOrgId,
  3790. RecordDate: recordDateTime,
  3791. Ctime: ctime,
  3792. Mtime: ctime,
  3793. Type: types,
  3794. Modifier: adminInfo.AdminUser.Id,
  3795. Creator: adminInfo.AdminUser.Id,
  3796. Status: 1,
  3797. Doctor: role.UserName,
  3798. HisPatientId: his_patient_id,
  3799. OrderStatus: 1,
  3800. BatchNumber: "",
  3801. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3802. PreTime: pTime,
  3803. PType: p_type,
  3804. MedType: med_type,
  3805. }
  3806. tempPrescription = prescription
  3807. service.SaveHisPrescription(tempPrescription)
  3808. redis := service.RedisClient()
  3809. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3810. redis.Set(key, "", time.Second)
  3811. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3812. redis.Set(keyOne, "", time.Second)
  3813. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3814. redis.Set(keySeven, "", time.Second)
  3815. defer redis.Close()
  3816. } else {
  3817. tempPrescription.ID = id
  3818. tempPrescription.Type = types
  3819. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3820. tempPrescription.Mtime = time.Now().Unix()
  3821. tempPrescription.Doctor = role.UserName
  3822. //tempPrescription.OrderStatus = order_status
  3823. tempPrescription.PreTime = pTime
  3824. tempPrescription.MedType = med_type
  3825. service.SaveHisPrescription(tempPrescription)
  3826. redis := service.RedisClient()
  3827. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3828. redis.Set(key, "", time.Second)
  3829. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3830. redis.Set(keyOne, "", time.Second)
  3831. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3832. redis.Set(keySeven, "", time.Second)
  3833. defer redis.Close()
  3834. }
  3835. //service.SaveHisPrescription(prescription)
  3836. //更改患者挂号状态
  3837. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3838. fmt.Println("更改失败", err2)
  3839. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3840. advices := items["advices"].([]interface{})
  3841. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3842. groupNo := int64(0)
  3843. if len(advices) > 0 {
  3844. for _, advice := range advices {
  3845. var s models.HisDoctorAdviceInfo
  3846. s.PrescriptionId = tempPrescription.ID
  3847. s.AdviceType = 2
  3848. s.AdviceDoctor = doctor_id
  3849. s.StopState = 2
  3850. s.ExecutionState = 2
  3851. s.AdviceDate = theTime3.Unix()
  3852. s.Status = 1
  3853. s.UserOrgId = adminInfo.CurrentOrgId
  3854. s.RecordDate = theTime3.Unix()
  3855. s.StartTime = tempPrescription.PreTime
  3856. s.Groupno = groupNo
  3857. s.PatientId = patient_id
  3858. s.HisPatientId = his_patient_id
  3859. s.StartTime = pTime
  3860. s.IsSettle = 2
  3861. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3862. if errcode > 0 {
  3863. c.ServeFailJSONWithSGJErrorCode(errcode)
  3864. return
  3865. }
  3866. s.StartTime = pTime
  3867. var total_count int64 //处方总库存
  3868. //查询改药品信息
  3869. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3870. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3871. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3872. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3873. total_count += prescribingNumberSeven * medical.MinNumber
  3874. }
  3875. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3876. total_count += prescribingNumberSeven
  3877. }
  3878. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3879. total_count += prescribingNumberSeven
  3880. }
  3881. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3882. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3883. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3884. if s.Price != lastWarehouse.RetailPrice {
  3885. s.Price = lastWarehouse.RetailPrice
  3886. }
  3887. if s.Price == 0 {
  3888. if lastWarehouse.ID == 0 {
  3889. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3890. s.Price = lastWarehouseTwo.RetailPrice
  3891. }
  3892. }
  3893. }
  3894. service.CreateHisDoctorAdvice(&s)
  3895. //记录日志
  3896. byterequest, _ := json.Marshal(s)
  3897. adviceLog := models.XtDoctorAdviceLog{
  3898. UserOrgId: s.UserOrgId,
  3899. PatientId: s.PatientId,
  3900. AdminUserId: adminInfo.AdminUser.Id,
  3901. Module: 1,
  3902. ErrLog: string(byterequest),
  3903. Status: 1,
  3904. Ctime: time.Now().Unix(),
  3905. Mtime: 0,
  3906. Source: "电脑端新建his医嘱",
  3907. RecordDate: s.AdviceDate,
  3908. }
  3909. service.CreateDoctorAdviceLog(adviceLog)
  3910. //存储切片中
  3911. adviceList = append(adviceList, s)
  3912. redis := service.RedisClient()
  3913. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3914. redis.Set(key, "", time.Second)
  3915. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3916. redis.Set(keyOne, "", time.Second)
  3917. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3918. redis.Set(keySeven, "", time.Second)
  3919. var randNum int
  3920. randNum = rand.Intn(10000) + 1000
  3921. timestamp := time.Now().Unix()
  3922. tempTime := time.Unix(timestamp, 0)
  3923. timeFormat := tempTime.Format("20060102150405")
  3924. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3925. service.CreateHisDoctorAdvice(&s)
  3926. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3927. redis.Set(keySix, "", time.Second)
  3928. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3929. redis.Set(keyFive, "", time.Second)
  3930. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3931. redis.Set(keyEight, "", time.Second)
  3932. defer redis.Close()
  3933. }
  3934. }
  3935. }
  3936. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3937. projects := items["project"].([]interface{})
  3938. if len(projects) > 0 {
  3939. for _, project := range projects {
  3940. var p models.HisPrescriptionProject
  3941. p.PrescriptionId = tempPrescription.ID
  3942. p.PatientId = patient_id
  3943. p.RecordDate = theTime3.Unix()
  3944. p.Doctor = doctor_id
  3945. p.UserOrgId = adminInfo.CurrentOrgId
  3946. p.HisPatientId = his_patient_id
  3947. p.Status = 1
  3948. p.StartTime = pTime
  3949. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3950. if errcode > 0 {
  3951. c.ServeFailJSONWithSGJErrorCode(errcode)
  3952. return
  3953. }
  3954. if p.ID == 0 {
  3955. p.IsOut = 2
  3956. }
  3957. if p.ID > 0 {
  3958. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3959. p.IsOut = projectDetail.IsOut
  3960. }
  3961. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3962. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3963. if p.Type == 3 {
  3964. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3965. if p.Price != lastWarehouse.PackingPrice {
  3966. p.Price = lastWarehouse.PackingPrice
  3967. }
  3968. if p.Price == 0 {
  3969. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3970. p.Price = lastWarehouseTwo.PackingPrice
  3971. }
  3972. if p.Unit == "" {
  3973. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3974. p.Unit = goodInfoOne.PackingUnit
  3975. }
  3976. }
  3977. }
  3978. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3979. //
  3980. // if p.Type == 3 {
  3981. // //查询该耗材是否停用
  3982. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3983. // //表示该耗材已经停用,不能保存
  3984. // if goodInfoSeven.ID == 0 {
  3985. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3986. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3987. // return
  3988. // }
  3989. // }
  3990. //
  3991. //}
  3992. service.CreateHisProjectTwo(&p)
  3993. //记录日志
  3994. byterequest, _ := json.Marshal(p)
  3995. adviceLog := models.XtDoctorAdviceLog{
  3996. UserOrgId: p.UserOrgId,
  3997. PatientId: p.PatientId,
  3998. AdminUserId: adminInfo.AdminUser.Id,
  3999. Module: 1,
  4000. ErrLog: string(byterequest),
  4001. Status: 1,
  4002. Ctime: time.Now().Unix(),
  4003. Mtime: 0,
  4004. Source: "电脑端新建his项目",
  4005. RecordDate: p.RecordDate,
  4006. }
  4007. service.CreateDoctorAdviceLog(adviceLog)
  4008. projectList = append(projectList, p)
  4009. var randNum int
  4010. randNum = rand.Intn(10000) + 1000
  4011. timestamp := time.Now().Unix()
  4012. tempTime := time.Unix(timestamp, 0)
  4013. timeFormat := tempTime.Format("20060102150405")
  4014. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4015. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4016. //新增或者编辑项目,修改对应的标签数据
  4017. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4018. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4019. var label models.HisLabelPrintInfo
  4020. project, _ := service.GetProjectDetail(p.ProjectId)
  4021. if project.CostClassify == 3 { //类别为检验检查
  4022. if p.TeamId > 0 { //检验检查组套
  4023. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4024. if tempLabel.ID == 0 {
  4025. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4026. label.Number = tempPrescription.PrescriptionNumber
  4027. label.ProjectId = project.ID
  4028. label.Status = 1
  4029. label.IsPrint = 2
  4030. label.DoctorId = info.DoctorId
  4031. label.UserOrgId = p.UserOrgId
  4032. label.PatientId = patient_id
  4033. label.RecordDate = recordDateTime
  4034. label.Ctime = time.Now().Unix()
  4035. label.Mtime = time.Now().Unix()
  4036. label.ItemId = p.TeamId
  4037. label.FeedetlSn = p.FeedetlSn
  4038. label.PProjectId = p.ID
  4039. label.ProjectName = team.ProjectTeam
  4040. label.PatientName = patient.Name
  4041. service.CreateHisLabelRecord(&label)
  4042. }
  4043. } else { //单条检验检查项目
  4044. label.Number = tempPrescription.PrescriptionNumber
  4045. label.ProjectId = project.ID
  4046. label.Status = 1
  4047. label.DoctorId = info.DoctorId
  4048. label.UserOrgId = p.UserOrgId
  4049. label.PatientId = patient_id
  4050. label.RecordDate = recordDateTime
  4051. label.IsPrint = 2
  4052. label.Ctime = time.Now().Unix()
  4053. label.Mtime = time.Now().Unix()
  4054. label.FeedetlSn = p.FeedetlSn
  4055. label.PProjectId = p.ID
  4056. label.ItemId = p.TeamId
  4057. label.ProjectName = project.ProjectName
  4058. label.PatientName = patient.Name
  4059. service.CreateHisLabelRecord(&label)
  4060. }
  4061. }
  4062. }
  4063. }
  4064. service.SaveHisProjectTwo(&p)
  4065. }
  4066. }
  4067. }
  4068. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4069. // addition := items["addition"].([]interface{})
  4070. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4071. // ctime := time.Now().Unix()
  4072. // mtime := ctime
  4073. // if len(addition) > 0 {
  4074. // for _, item := range addition {
  4075. // var s models.HisAdditionalCharge
  4076. // s.PrescriptionId = tempPrescription.ID
  4077. // s.Status = 1
  4078. // s.UserOrgId = adminInfo.CurrentOrgId
  4079. // s.RecordDate = recordDateTime
  4080. // s.CreatedTime = ctime
  4081. // s.UpdatedTime = mtime
  4082. // s.PatientId = patient_id
  4083. // s.HisPatientId = his_patient_id
  4084. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4085. // if errcode > 0 {
  4086. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4087. // return
  4088. // }
  4089. // service.CreateAdditionalCharge(&s)
  4090. // var randNum int
  4091. // randNum = rand.Intn(10000) + 1000
  4092. // timestamp := time.Now().Unix()
  4093. // tempTime := time.Unix(timestamp, 0)
  4094. // timeFormat := tempTime.Format("20060102150405")
  4095. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4096. // service.CreateAdditionalCharge(&s)
  4097. //
  4098. // }
  4099. // }
  4100. //}
  4101. }
  4102. }
  4103. //查询今日该患者开的药品处方
  4104. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4105. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4106. //药品出库
  4107. if drugOutConfig.IsOpen == 1 {
  4108. for _, item := range hisdoctorlist {
  4109. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4110. // 查询该药品最后一次出库记录
  4111. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4112. if len(druginfo) > 0 {
  4113. //回退库存
  4114. for _, it := range druginfo {
  4115. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4116. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4117. }
  4118. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4119. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4120. }
  4121. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4122. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4123. }
  4124. }
  4125. }
  4126. //删除记录
  4127. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4128. //查询最后一次数据
  4129. if drugOutConfig.IsOpen == 1 {
  4130. //出库
  4131. if drug.IsUse == 2 {
  4132. creater := adminInfo.AdminUser.Id
  4133. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4134. }
  4135. //更新字典里面的库存
  4136. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4137. var sum_count int64
  4138. for _, its := range stockInfo {
  4139. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4140. if its.MaxUnit == baseDrug.MaxUnit {
  4141. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4142. }
  4143. sum_count += its.StockMaxNumber + its.StockMinNumber
  4144. }
  4145. //更新基础库存
  4146. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4147. //剩余库存
  4148. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4149. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4150. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4151. }
  4152. }
  4153. }
  4154. //耗材保存处方出库
  4155. if goodOutConfig.IsOpen == 1 {
  4156. //查询今日耗材出库数量
  4157. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4158. for _, item := range hisgoodlist {
  4159. //查询历史出库数据
  4160. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4161. var out_count_five int64
  4162. for _, item := range flowGood {
  4163. out_count_five += item.Count
  4164. }
  4165. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4166. if out_count_five != parseIntCount {
  4167. //查询耗材最后一次出库记录
  4168. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4169. //查询默认出库仓库库存
  4170. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4171. if len(wareOut) > 0 {
  4172. for _, it := range wareOut {
  4173. //回退库存
  4174. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4175. //删除出库记录
  4176. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4177. }
  4178. }
  4179. timeStr := time.Now().Format("2006-01-02")
  4180. timeArr := strings.Split(timeStr, "-")
  4181. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4182. total = total + 1
  4183. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4184. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4185. number = number + total
  4186. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4187. operation_time := time.Now().Unix()
  4188. creater := c.GetAdminUserInfo().AdminUser.Id
  4189. recordDateStr := time.Now().Format("2006-01-02")
  4190. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4191. nowtime := recordDate.Unix()
  4192. warehouseOut := models.WarehouseOut{
  4193. WarehouseOutOrderNumber: warehousing_out_order,
  4194. OperationTime: operation_time,
  4195. OrgId: adminInfo.CurrentOrgId,
  4196. Creater: creater,
  4197. Ctime: time.Now().Unix(),
  4198. Status: 1,
  4199. WarehouseOutTime: nowtime,
  4200. Type: 1,
  4201. StorehouseId: storeConfig.StorehouseOutInfo,
  4202. IsCheck: 1,
  4203. IsSys: 1,
  4204. }
  4205. //查询是否生成出库单
  4206. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4207. if out.ID == 0 {
  4208. service.AddSigleWarehouseOut(&warehouseOut)
  4209. }
  4210. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4211. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4212. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4213. dialyPrepareOne := models.DialysisBeforePrepare{
  4214. GoodTypeId: goodObj.GoodTypeId,
  4215. GoodId: item.ProjectId,
  4216. PatientId: item.PatientId,
  4217. RecordDate: item.RecordDate,
  4218. UserOrgId: adminInfo.CurrentOrgId,
  4219. Count: parseIntCount,
  4220. Ctime: time.Now().Unix(),
  4221. Creater: creater,
  4222. Status: 1,
  4223. StorehouseId: houseConfig.StorehouseOutInfo,
  4224. ProjectId: item.ID,
  4225. }
  4226. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4227. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4228. //查询历史出库数据
  4229. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4230. var out_count int64
  4231. for _, item := range flowGood {
  4232. out_count += item.Count
  4233. }
  4234. //如果历史数和当前数据不想等才进行退库出库
  4235. if out_count != parseIntCount {
  4236. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4237. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4238. detail := models.AutomaticReduceDetail{
  4239. WarehouseOutId: 0,
  4240. WarehouseOutOrderNumber: "",
  4241. PatientId: item.PatientId,
  4242. Ctime: time.Now().Unix(),
  4243. Mtime: 0,
  4244. Status: 1,
  4245. RecordTime: item.RecordDate,
  4246. OrgId: item.UserOrgId,
  4247. GoodId: item.ProjectId,
  4248. GoodTypeId: 0,
  4249. Count: parseIntCount,
  4250. Type: 0,
  4251. ProjectId: item.ID,
  4252. StorehouseId: 0,
  4253. }
  4254. service.CreateAutoDetail(detail)
  4255. //查询剩余库存
  4256. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4257. var sum_count int64
  4258. for _, item := range goodList {
  4259. sum_count += item.StockCount
  4260. }
  4261. //更新剩余库存
  4262. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4263. //耗材
  4264. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4265. }
  4266. }
  4267. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4268. //查询历史出库数据
  4269. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4270. var out_count int64
  4271. for _, item := range flowGood {
  4272. out_count += item.Count
  4273. }
  4274. //如果历史数和当前数据不想等才进行退库出库
  4275. if out_count != parseIntCount {
  4276. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4277. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4278. detail := models.AutomaticReduceDetail{
  4279. WarehouseOutId: 0,
  4280. WarehouseOutOrderNumber: "",
  4281. PatientId: item.PatientId,
  4282. Ctime: time.Now().Unix(),
  4283. Mtime: 0,
  4284. Status: 1,
  4285. RecordTime: item.RecordDate,
  4286. OrgId: item.UserOrgId,
  4287. GoodId: item.ProjectId,
  4288. GoodTypeId: 0,
  4289. Count: parseIntCount,
  4290. Type: 0,
  4291. ProjectId: item.ID,
  4292. StorehouseId: 0,
  4293. }
  4294. service.CreateAutoDetail(detail)
  4295. //查询剩余库存
  4296. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4297. var sum_count int64
  4298. for _, item := range goodList {
  4299. sum_count += item.StockCount
  4300. }
  4301. //更新剩余库存
  4302. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4303. //耗材
  4304. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4305. }
  4306. }
  4307. }
  4308. }
  4309. }
  4310. ////同步到自备药
  4311. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4312. if selfPrescriptionOpen.IsOpen == 1 {
  4313. timeStr := time.Now().Format("2006-01-02")
  4314. timeArr := strings.Split(timeStr, "-")
  4315. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4316. total = total + 1
  4317. operation_time := time.Now().Unix()
  4318. creater := adminInfo.AdminUser.Id
  4319. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4320. warehousing := models.XtSelfDrugWarehouse{
  4321. WarehousingOrder: warehousing_order,
  4322. OperationTime: operation_time,
  4323. OrgId: adminInfo.CurrentOrgId,
  4324. Creater: creater,
  4325. Ctime: time.Now().Unix(),
  4326. Status: 1,
  4327. WarehousingTime: recordDateTime,
  4328. Type: 0,
  4329. StorehouseId: 0,
  4330. IsCheck: 1,
  4331. PatientId: patient_id,
  4332. IsSys: 1,
  4333. }
  4334. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4335. if selfDrugWarehouse.ID == 0 {
  4336. service.AddSelfDrugWarehouse(&warehousing, tx)
  4337. }
  4338. if selfDrugWarehouse.ID > 0 {
  4339. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4340. }
  4341. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4342. fmt.Println(info)
  4343. for _, item := range hisdoctorlist {
  4344. //查询该病人的该药品是否已经入库
  4345. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4346. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
  4347. var in_count int64
  4348. if len(selfdruginfo) > 0 {
  4349. for _, item := range selfdruginfo {
  4350. var in_count_one int64
  4351. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4352. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4353. }
  4354. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4355. in_count_one = item.WarehousingCount
  4356. }
  4357. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4358. in_count_one = item.WarehousingCount
  4359. }
  4360. in_count += in_count_one
  4361. }
  4362. }
  4363. if selfBasedrug.IsSelfDrug == 1 {
  4364. var total_count int64
  4365. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4366. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4367. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4368. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4369. }
  4370. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4371. total_count += prescribingNumberSeven
  4372. }
  4373. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4374. total_count += prescribingNumberSeven
  4375. }
  4376. //入库
  4377. if total_count > in_count {
  4378. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4379. WarehousingOrder: warehousing_order,
  4380. WarehousingId: info.ID,
  4381. DrugId: item.DrugId,
  4382. Number: "",
  4383. ProductDate: 0,
  4384. ExpiryDate: 0,
  4385. WarehousingCount: total_count - in_count,
  4386. WarehouseingUnit: selfBasedrug.MinUnit,
  4387. Price: 0,
  4388. TotalPrice: 0,
  4389. Status: 1,
  4390. Ctime: time.Now().Unix(),
  4391. Remark: "",
  4392. OrgId: adminInfo.CurrentOrgId,
  4393. Type: 0,
  4394. Manufacturer: selfBasedrug.Manufacturer,
  4395. Dealer: selfBasedrug.Dealer,
  4396. StockMaxNumber: total_count - in_count,
  4397. RetailTotalPrice: 0,
  4398. BatchNumber: "",
  4399. MaxUnit: selfBasedrug.MinUnit,
  4400. MinUnit: selfBasedrug.MinUnit,
  4401. RetailPrice: 0,
  4402. StorehouseId: 0,
  4403. IsCheck: 1,
  4404. StockMinNumber: 0,
  4405. PatientId: patient_id,
  4406. IsSys: 1,
  4407. RecordDate: item.RecordDate,
  4408. AdviceId: item.ID,
  4409. }
  4410. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4411. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4412. Creator := adminInfo.AdminUser.Id
  4413. //查询默认仓库剩余多少库存
  4414. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4415. var sum_count int64
  4416. for _, it := range list {
  4417. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4418. if it.MaxUnit == baseDrug.MaxUnit {
  4419. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4420. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4421. }
  4422. sum_count += it.StockMaxNumber + it.StockMinNumber
  4423. }
  4424. flow := &models.XtSelfDrugFlow{
  4425. WarehousingId: info.ID,
  4426. DrugId: item.DrugId,
  4427. Number: "",
  4428. BatchNumber: "",
  4429. Count: total_count - in_count,
  4430. UserOrgId: adminInfo.CurrentOrgId,
  4431. PatientId: item.PatientId,
  4432. SystemTime: time.Now().Unix(),
  4433. ConsumableType: 1,
  4434. IsSys: 1,
  4435. WarehousingOrder: warehousing_order,
  4436. WarehouseOutId: 0,
  4437. WarehouseOutOrderNumber: "",
  4438. IsEdit: 0,
  4439. CancelStockId: 0,
  4440. CancelOrderNumber: "",
  4441. Manufacturer: selfBasedrug.Manufacturer,
  4442. Dealer: selfBasedrug.Dealer,
  4443. Creator: Creator,
  4444. UpdateCreator: Creator,
  4445. Status: 1,
  4446. Ctime: item.AdviceDate,
  4447. Mtime: 0,
  4448. Price: item.Price,
  4449. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4450. WarehouseOutDetailId: 0,
  4451. CancelOutDetailId: 0,
  4452. ExpireDate: 0,
  4453. ProductDate: 0,
  4454. MaxUnit: selfBasedrug.MinUnit,
  4455. MinUnit: selfBasedrug.MinUnit,
  4456. StorehouseId: 0,
  4457. OverCount: sum_count,
  4458. OperateTime: time.Now().Unix(),
  4459. AdviceId: item.ID,
  4460. }
  4461. service.CreateSelfDrugFlow(flow, tx)
  4462. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4463. var total_count int64 // 入库总数量
  4464. var over_count int64 //剩余库存
  4465. for _, it := range drugInfolist {
  4466. if it.MaxUnit == selfBasedrug.MaxUnit {
  4467. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4468. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4469. }
  4470. }
  4471. for _, it := range drugInfolist {
  4472. total_count += it.WarehousingCount
  4473. over_count += it.StockMaxNumber + it.StockMinNumber
  4474. }
  4475. //查询该仓库是否有默认数据
  4476. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4477. if selfDrugStock.ID == 0 {
  4478. drugStock := models.XtSelfDrugStockCount{
  4479. UserOrgId: item.UserOrgId,
  4480. PatientId: item.PatientId,
  4481. SumInCount: total_count,
  4482. SumOutCount: 0,
  4483. SumCancelCount: 0,
  4484. DrugId: item.DrugId,
  4485. Ctime: time.Now().Unix(),
  4486. Mtime: 0,
  4487. Status: 1,
  4488. FlushCount: over_count,
  4489. SumActOutCount: 0,
  4490. }
  4491. service.CreateSelfDrugStockSum(drugStock, tx)
  4492. }
  4493. if selfDrugStock.ID > 0 {
  4494. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4495. }
  4496. }
  4497. //查询这个单据的出库数量
  4498. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4499. var his_out_count int64
  4500. for _, item := range drugFlowList {
  4501. his_out_count += item.Count
  4502. }
  4503. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4504. if (total_count + his_out_count) <= in_count {
  4505. // 出库
  4506. if total_count < in_count {
  4507. var cha_count int64
  4508. cha_count = in_count - total_count
  4509. var stock_number int64 = 0
  4510. //查询库存是否充足
  4511. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4512. // 将该批次的剩余库存数量转换为拆零数量
  4513. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4514. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4515. }
  4516. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4517. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4518. }
  4519. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4520. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4521. }
  4522. if stock_number >= cha_count {
  4523. var maxNumber int64 = 0
  4524. var minNumber int64 = 0
  4525. maxNumber = cha_count / selfBasedrug.MinNumber
  4526. minNumber = cha_count % selfBasedrug.MinNumber
  4527. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4528. minNumber = maxNumber
  4529. }
  4530. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4531. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4533. return
  4534. }
  4535. }
  4536. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4537. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4538. }
  4539. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4540. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4541. }
  4542. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4543. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4544. }
  4545. if warehouse.StockMaxNumber < 0 {
  4546. warehouse.StockMaxNumber = 0
  4547. }
  4548. if warehouse.StockMinNumber < 0 {
  4549. warehouse.StockMinNumber = 0
  4550. }
  4551. warehouse.Mtime = time.Now().Unix()
  4552. if warehouse.StockMinNumber < minNumber {
  4553. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4554. if warehouse.MaxUnit != warehouse.MinUnit {
  4555. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4556. }
  4557. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4558. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4559. }
  4560. } else {
  4561. if minNumber > 0 {
  4562. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4563. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4564. }
  4565. }
  4566. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4567. if warehouse.StockMinNumber > 0 {
  4568. if warehouse.StockMinNumber-cha_count >= 0 {
  4569. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4570. }
  4571. }
  4572. }
  4573. }
  4574. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4575. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4576. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4577. }
  4578. }
  4579. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4580. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4582. return
  4583. }
  4584. }
  4585. if warehouse.StockMinNumber <= 0 {
  4586. warehouse.StockMinNumber = 0
  4587. }
  4588. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4589. //查询该药品剩余库存
  4590. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4591. var over_count int64
  4592. for _, its := range infolist {
  4593. if its.MaxUnit == selfBasedrug.MaxUnit {
  4594. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4595. }
  4596. over_count += its.StockMaxNumber + its.StockMinNumber
  4597. }
  4598. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4599. drugflow := models.XtSelfDrugFlow{
  4600. WarehouseOutId: 0,
  4601. WarehouseOutOrderNumber: warehousing_order,
  4602. WarehousingOrder: warehousing_order,
  4603. DrugId: item.DrugId,
  4604. Number: warehouse.Number,
  4605. ProductDate: warehouse.ProductDate,
  4606. ExpireDate: warehouse.ExpiryDate,
  4607. Count: cha_count,
  4608. Price: warehouse.RetailPrice,
  4609. Status: 1,
  4610. Ctime: item.AdviceDate,
  4611. Mtime: time.Now().Unix(),
  4612. UserOrgId: item.UserOrgId,
  4613. Manufacturer: warehouse.Manufacturer,
  4614. Dealer: warehouse.Dealer,
  4615. BatchNumber: warehouse.BatchNumber,
  4616. MaxUnit: selfBasedrug.MinUnit,
  4617. ConsumableType: 20,
  4618. IsEdit: 1,
  4619. Creator: 0,
  4620. IsSys: 3,
  4621. WarehouseOutDetailId: drugWareInfo.ID,
  4622. AdviceId: item.ID,
  4623. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4624. StorehouseId: 0,
  4625. AdminUserId: creater,
  4626. LastPrice: warehouse.Price,
  4627. StockCount: "",
  4628. WarehousingDetailId: 0,
  4629. OverCount: over_count,
  4630. RetailPrice: item.Price, //手动出库出库价格
  4631. WarehousingId: warehouse.ID,
  4632. SystemTime: item.AdviceDate,
  4633. PatientId: item.PatientId,
  4634. Remark: "保存处方入库数据差",
  4635. OperateTime: time.Now().Unix(),
  4636. }
  4637. if warehouse.RetailPrice == 0 {
  4638. drugflow.Price = item.Price
  4639. }
  4640. service.CreateSelfDrugFlowOne(drugflow, tx)
  4641. var out_count int64
  4642. out_count = in_count - total_count
  4643. fmt.Println("in_count------------------", in_count)
  4644. fmt.Println("total_count------------------", total_count)
  4645. //添加出库数量
  4646. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4647. //查询剩余库存
  4648. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4649. var sum_count int64
  4650. for _, its := range stockInfo {
  4651. if its.MaxUnit == selfBasedrug.MaxUnit {
  4652. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4653. }
  4654. sum_count += its.StockMaxNumber + its.StockMinNumber
  4655. }
  4656. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4657. } else {
  4658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4659. return
  4660. }
  4661. }
  4662. }
  4663. }
  4664. }
  4665. }
  4666. }
  4667. tx.Commit()
  4668. if err == nil {
  4669. c.ServeSuccessJSON(map[string]interface{}{
  4670. "msg": "保存成功",
  4671. })
  4672. return
  4673. } else {
  4674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4675. return
  4676. }
  4677. }
  4678. }
  4679. //func (c *HisApiController) EditHisPrescription() {
  4680. // record_date := c.GetString("record_date")
  4681. // patient_id, _ := c.GetInt64("patient_id")
  4682. // reg_type, _ := c.GetInt64("reg_type")
  4683. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4684. // diagnose := c.GetString("diagnose")
  4685. // sick_type, _ := c.GetInt64("sick_type")
  4686. // sick_history := c.GetString("sick_history")
  4687. // doctor_id, _ := c.GetInt64("doctor", 0)
  4688. // department, _ := c.GetInt64("department", 0)
  4689. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4690. // p_type, _ := c.GetInt64("p_type")
  4691. //
  4692. // dataBody := make(map[string]interface{}, 0)
  4693. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4694. // if err != nil {
  4695. // utils.ErrorLog(err.Error())
  4696. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4697. // return
  4698. // }
  4699. //
  4700. // timeLayout := "2006-01-02"
  4701. // loc, _ := time.LoadLocation("Local")
  4702. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4703. // if err != nil {
  4704. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4705. // return
  4706. // }
  4707. // adminInfo := c.GetAdminUserInfo()
  4708. // recordDateTime := theTime.Unix()
  4709. //
  4710. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4711. //
  4712. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4713. // var hpInfo models.HisPrescriptionInfo
  4714. // if info.ID == 0 {
  4715. // var randNum int
  4716. // randNum = rand.Intn(10000) + 1000
  4717. // timestamp := time.Now().Unix()
  4718. // tempTime := time.Unix(timestamp, 0)
  4719. // timeFormat := tempTime.Format("20060102150405")
  4720. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4721. //
  4722. // hpInfo = models.HisPrescriptionInfo{
  4723. // UserOrgId: adminInfo.CurrentOrgId,
  4724. // RecordDate: theTime.Unix(),
  4725. // PatientId: patient_id,
  4726. // Status: 1,
  4727. // Ctime: time.Now().Unix(),
  4728. // Mtime: time.Now().Unix(),
  4729. // Creator: adminInfo.AdminUser.Id,
  4730. // Modifier: adminInfo.AdminUser.Id,
  4731. // Diagnosis: diagnose,
  4732. // SickHistory: sick_history,
  4733. // Departments: department,
  4734. // RegisterType: reg_type,
  4735. // PrescriptionNumber: p_number,
  4736. // PrescriptionStatus: 1,
  4737. // Doctor: role.UserName,
  4738. // DoctorId: doctor_id,
  4739. // SickType: sick_type,
  4740. // PType: p_type,
  4741. // }
  4742. // service.SavePatientPrescriptionInfo(hpInfo)
  4743. //
  4744. // } else {
  4745. // hpInfo = models.HisPrescriptionInfo{
  4746. // ID: info.ID,
  4747. // UserOrgId: adminInfo.CurrentOrgId,
  4748. // RecordDate: info.RecordDate,
  4749. // PatientId: info.PatientId,
  4750. // Status: 1,
  4751. // Ctime: info.Ctime,
  4752. // Mtime: time.Now().Unix(),
  4753. // Creator: info.Creator,
  4754. // Modifier: adminInfo.AdminUser.Id,
  4755. // Diagnosis: diagnose,
  4756. // SickHistory: sick_history,
  4757. // Departments: department,
  4758. // RegisterType: reg_type,
  4759. // PrescriptionNumber: info.PrescriptionNumber,
  4760. // Doctor: role.UserName,
  4761. // PrescriptionStatus: info.PrescriptionStatus,
  4762. // DoctorId: doctor_id,
  4763. // SickType: sick_type,
  4764. // PType: info.PType,
  4765. // }
  4766. // service.SavePatientPrescriptionInfo(hpInfo)
  4767. // }
  4768. //
  4769. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4770. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4771. //
  4772. // if len(prescriptions) > 0 {
  4773. // for _, item := range prescriptions {
  4774. // items := item.(map[string]interface{})
  4775. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4776. // utils.ErrorLog("id")
  4777. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4778. // return
  4779. // }
  4780. // id := int64(items["id"].(float64))
  4781. //
  4782. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4783. // utils.ErrorLog("type")
  4784. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4785. // return
  4786. // }
  4787. // types := int64(items["type"].(float64))
  4788. //
  4789. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4790. // utils.ErrorLog("med_type")
  4791. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4792. // return
  4793. // }
  4794. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4795. //
  4796. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4797. //
  4798. // ctime := time.Now().Unix()
  4799. //
  4800. // prescription := &models.HisPrescription{
  4801. // ID: id,
  4802. // PatientId: patient_id,
  4803. // UserOrgId: adminInfo.CurrentOrgId,
  4804. // RecordDate: recordDateTime,
  4805. // Ctime: ctime,
  4806. // Mtime: ctime,
  4807. // Type: types,
  4808. // Modifier: adminInfo.AdminUser.Id,
  4809. // Creator: adminInfo.AdminUser.Id,
  4810. // Status: 1,
  4811. // Doctor: role.UserName,
  4812. // HisPatientId: his_patient_id,
  4813. // OrderStatus: 1,
  4814. // BatchNumber: "",
  4815. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4816. // PType: hpInfo.PType,
  4817. // MedType: med_type,
  4818. // }
  4819. //
  4820. // if historyPrescription.ID > 0 {
  4821. // prescription.PreTime = historyPrescription.PreTime
  4822. //
  4823. // }
  4824. //
  4825. // service.SaveHisPrescription(prescription)
  4826. //
  4827. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4828. // advices := items["advices"].([]interface{})
  4829. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4830. // groupNo := int64(0)
  4831. // ctime := time.Now().Unix()
  4832. // mtime := ctime
  4833. // if len(advices) > 0 {
  4834. // for _, advice := range advices {
  4835. // var s models.HisDoctorAdviceInfo
  4836. // s.PrescriptionId = prescription.ID
  4837. // s.AdviceType = 2
  4838. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4839. // s.StopState = 2
  4840. // s.ExecutionState = 2
  4841. // s.AdviceDate = recordDateTime
  4842. // s.Status = 1
  4843. // s.UserOrgId = adminInfo.CurrentOrgId
  4844. // s.RecordDate = recordDateTime
  4845. // s.StartTime = prescription.PreTime
  4846. // s.Groupno = groupNo
  4847. // s.CreatedTime = ctime
  4848. // s.UpdatedTime = mtime
  4849. // s.PatientId = patient_id
  4850. // s.HisPatientId = his_patient_id
  4851. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4852. // if errcode > 0 {
  4853. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4854. // return
  4855. // }
  4856. //
  4857. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4858. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4859. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4860. // if s.Price == 0 {
  4861. // s.Price = lastWarehouse.RetailPrice
  4862. // }
  4863. // }
  4864. //
  4865. // service.CreateHisDoctorAdvice(&s)
  4866. // //记录日志
  4867. // byterequest, _ := json.Marshal(s)
  4868. // adviceLog := models.XtDoctorAdviceLog{
  4869. // UserOrgId: s.UserOrgId,
  4870. // PatientId: s.PatientId,
  4871. // AdminUserId: adminInfo.AdminUser.Id,
  4872. // Module: 1,
  4873. // ErrLog: string(byterequest),
  4874. // Status: 1,
  4875. // Ctime: time.Now().Unix(),
  4876. // Mtime: 0,
  4877. // Source: "电脑端his医嘱修改",
  4878. // RecordDate: s.AdviceDate,
  4879. // }
  4880. // service.CreateDoctorAdviceLog(adviceLog)
  4881. // redis := service.RedisClient()
  4882. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4883. // redis.Set(key, "", time.Second)
  4884. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4885. // fmt.Println("keyOne", keyOne)
  4886. // redis.Set(keyOne, "", time.Second)
  4887. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4888. // redis.Set(keySeven, "", time.Second)
  4889. // redis.Close()
  4890. //
  4891. // }
  4892. // }
  4893. // }
  4894. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4895. // projects := items["project"].([]interface{})
  4896. // if len(projects) > 0 {
  4897. // for _, project := range projects {
  4898. // var p models.HisPrescriptionProject
  4899. // p.PrescriptionId = prescription.ID
  4900. // p.Ctime = time.Now().Unix()
  4901. // p.Mtime = time.Now().Unix()
  4902. // p.PatientId = patient_id
  4903. // p.RecordDate = recordDateTime
  4904. // p.UserOrgId = adminInfo.CurrentOrgId
  4905. // p.HisPatientId = his_patient_id
  4906. // p.Status = 1
  4907. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4908. // if errcode > 0 {
  4909. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4910. // return
  4911. // }
  4912. // service.CreateHisProjectTwo(&p)
  4913. //
  4914. // //记录日志
  4915. // byterequest, _ := json.Marshal(p)
  4916. // adviceLog := models.XtDoctorAdviceLog{
  4917. // UserOrgId: p.UserOrgId,
  4918. // PatientId: p.PatientId,
  4919. // AdminUserId: adminInfo.AdminUser.Id,
  4920. // Module: 1,
  4921. // ErrLog: string(byterequest),
  4922. // Status: 1,
  4923. // Ctime: time.Now().Unix(),
  4924. // Mtime: 0,
  4925. // Source: "电脑端his项目修改",
  4926. // RecordDate: p.RecordDate,
  4927. // }
  4928. // service.CreateDoctorAdviceLog(adviceLog)
  4929. // }
  4930. // }
  4931. // }
  4932. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4933. // addition := items["addition"].([]interface{})
  4934. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4935. // ctime := time.Now().Unix()
  4936. // mtime := ctime
  4937. // if len(addition) > 0 {
  4938. // for _, item := range addition {
  4939. // var s models.HisAdditionalCharge
  4940. // s.PrescriptionId = prescription.ID
  4941. // s.Status = 1
  4942. // s.UserOrgId = adminInfo.CurrentOrgId
  4943. // s.RecordDate = recordDateTime
  4944. // s.CreatedTime = ctime
  4945. // s.UpdatedTime = mtime
  4946. // s.PatientId = patient_id
  4947. // s.HisPatientId = his_patient_id
  4948. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4949. // if errcode > 0 {
  4950. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4951. // return
  4952. // }
  4953. // service.CreateAdditionalCharge(&s)
  4954. // }
  4955. // }
  4956. // }
  4957. //
  4958. // }
  4959. // }
  4960. // }
  4961. // if err == nil {
  4962. // c.ServeSuccessJSON(map[string]interface{}{
  4963. // "msg": "保存成功",
  4964. // })
  4965. // return
  4966. //
  4967. // } else {
  4968. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4969. // return
  4970. // }
  4971. //}
  4972. func (c *HisApiController) DeletePrescription() {
  4973. prescription_id, _ := c.GetInt64("id")
  4974. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4975. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4976. ////同步到自备药
  4977. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  4978. fmt.Println("selfPrescriptionOpen=---------------------------", selfPrescriptionOpen)
  4979. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  4980. if selfPrescriptionOpen.IsOpen == 1 {
  4981. // 在函数结束时处理事务回滚
  4982. db := service.XTWriteDB()
  4983. tx := db.Begin()
  4984. defer func() {
  4985. if r := recover(); r != nil {
  4986. tx.Rollback()
  4987. } else {
  4988. tx.Commit()
  4989. }
  4990. }()
  4991. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  4992. for _, item := range advicesList {
  4993. timeStr := time.Now().Format("2006-01-02")
  4994. timeArr := strings.Split(timeStr, "-")
  4995. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  4996. total = total + 1
  4997. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4998. fmt.Println("warehousing_out_order--------------------------------------", warehousing_out_order)
  4999. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5000. number = number + total
  5001. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5002. operation_time := time.Now().Unix()
  5003. creater := c.GetAdminUserInfo().AdminUser.Id
  5004. //创建一个出库单
  5005. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5006. WarehouseOutOrderNumber: warehousing_out_order,
  5007. OperationTime: operation_time,
  5008. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5009. Creater: creater,
  5010. Ctime: time.Now().Unix(),
  5011. Status: 1,
  5012. WarehouseOutTime: item.AdviceDate,
  5013. Type: 0,
  5014. PatientId: item.PatientId,
  5015. IsCheck: 1,
  5016. }
  5017. //查询今日是否有出库数据
  5018. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5019. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5020. if lastWarehouseOut.ID == 0 {
  5021. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5022. }
  5023. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
  5024. var total_count int64
  5025. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5026. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5027. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5028. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5029. }
  5030. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5031. total_count += prescribingNumberSeven
  5032. }
  5033. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5034. total_count += prescribingNumberSeven
  5035. }
  5036. //出库
  5037. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5038. WarehouseOutOrderNumber: warehousing_out_order,
  5039. WarehouseOutId: lastWarehouseOut.ID,
  5040. DrugId: item.DrugId,
  5041. Count: total_count,
  5042. Price: 0,
  5043. TotalPrice: 0,
  5044. Status: 1,
  5045. Ctime: item.AdviceDate,
  5046. Mtime: item.AdviceDate,
  5047. Remark: "",
  5048. OrgId: item.UserOrgId,
  5049. Type: 0,
  5050. Manufacturer: selfBasedrug.Manufacturer,
  5051. Dealer: selfBasedrug.Dealer,
  5052. RetailPrice: 0,
  5053. RetailTotalPrice: 0,
  5054. CountUnit: selfBasedrug.MinUnit,
  5055. ExpiryDate: 0,
  5056. ProductDate: 0,
  5057. Number: "",
  5058. BatchNumber: "",
  5059. IsSys: 1,
  5060. WarehouseInfoId: 0,
  5061. AdminUserId: 0,
  5062. StockCount: "",
  5063. IsCheck: 1,
  5064. SysRecordTime: item.AdviceDate,
  5065. PatientId: item.PatientId,
  5066. ClassType: "",
  5067. AdviceId: item.ID,
  5068. }
  5069. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5070. }
  5071. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5072. for _, it := range warehousingOutInfo {
  5073. //查询今日是否有出库数据
  5074. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5075. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5076. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5077. //出库逻辑
  5078. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5079. //查询剩余库存
  5080. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5081. var sum_count int64
  5082. for _, its := range stockInfo {
  5083. if its.MaxUnit == medical.MaxUnit {
  5084. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5085. }
  5086. sum_count += its.StockMaxNumber + its.StockMinNumber
  5087. }
  5088. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5089. }
  5090. }
  5091. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5092. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5093. //耗材保存处方出库
  5094. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5095. //已收费和已发药限制逻辑
  5096. isCharge := false
  5097. isMedicine := false
  5098. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5099. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5100. if new_prescription.IsMedicine == 1 {
  5101. isMedicine = true
  5102. }
  5103. for _, item := range new_prescriptions {
  5104. if item.OrderStatus == 4 {
  5105. isCharge = true
  5106. }
  5107. }
  5108. if p_err != nil {
  5109. if new_prescription.ID > 0 {
  5110. if new_prescription.OrderStatus == 2 {
  5111. isCharge = true
  5112. }
  5113. }
  5114. }
  5115. for _, item := range advices {
  5116. if item.IsMedicine == 1 {
  5117. isMedicine = true
  5118. }
  5119. }
  5120. if isCharge {
  5121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5122. return
  5123. }
  5124. if isMedicine {
  5125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5126. return
  5127. }
  5128. //已收费和已发药限制逻辑
  5129. if len(projects) > 0 {
  5130. for _, item := range projects {
  5131. service.DeletePrintInfo(item.ID) //删除打印信息
  5132. if goodOutConfig.IsOpen != 1 {
  5133. if stockConfig.IsOpen == 1 {
  5134. if item.Type == 3 && item.IsOut == 1 {
  5135. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5136. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5137. good.Total = good.Total + f_count
  5138. service.UpdateGoodInfo(&good)
  5139. operation_time := time.Now().Unix()
  5140. creater := c.GetAdminUserInfo().AdminUser.Id
  5141. //创建退库单
  5142. timeStr := time.Now().Format("2006-01-02")
  5143. timeArr := strings.Split(timeStr, "-")
  5144. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5145. total = total + 1
  5146. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5147. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5148. cancelStock := models.CancelStock{
  5149. OrderNumber: orderNumber,
  5150. OperaTime: operation_time,
  5151. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5152. Creater: creater,
  5153. Ctime: time.Now().Unix(),
  5154. Status: 1,
  5155. ReturnTime: item.RecordDate,
  5156. Type: 1,
  5157. StorehouseId: houseConfig.StorehouseOutInfo,
  5158. IsCheck: 1,
  5159. }
  5160. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5161. if msgerrkonde == gorm.ErrRecordNotFound {
  5162. service.AddSigleCancelStock(&cancelStock)
  5163. }
  5164. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5165. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5166. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5167. //查询该耗材是否出库
  5168. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5169. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5170. deaerler, _ := service.GetDealerById(info.Dealer)
  5171. var total_count int64
  5172. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5173. total_count += count
  5174. if info.ID > 0 {
  5175. if info.Count >= total_count {
  5176. //回退库存
  5177. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5178. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5179. var flush_count int64
  5180. for _, it := range goodList {
  5181. flush_count += it.StockCount
  5182. }
  5183. cancelStockInfo := models.CancelStockInfo{
  5184. GoodId: item.ProjectId,
  5185. CancelStockId: cancel.ID,
  5186. GoodTypeId: good.GoodTypeId,
  5187. Count: prescribingNumber,
  5188. Price: info.Price,
  5189. Total: 0,
  5190. ProductDate: info.ProductDate,
  5191. ExpiryDate: info.ExpiryDate,
  5192. Ctime: time.Now().Unix(),
  5193. Status: 1,
  5194. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5195. OrderNumber: cancel.OrderNumber,
  5196. Type: 0,
  5197. Dealer: deaerler.DealerName,
  5198. Manufacturer: manufacturer.ManufacturerName,
  5199. Number: info.Number,
  5200. RegisterAccount: "",
  5201. Remark: "",
  5202. WarehouseInfoId: info.WarehouseInfotId,
  5203. PatientId: info.PatientId,
  5204. RecordDate: info.SysRecordTime,
  5205. StorehouseId: houseConfig.StorehouseOutInfo,
  5206. IsCheck: 1,
  5207. }
  5208. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5209. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5210. flow := models.VmStockFlow{
  5211. WarehousingId: info.WarehouseInfotId,
  5212. GoodId: item.ProjectId,
  5213. Number: info.Number,
  5214. LicenseNumber: info.LicenseNumber,
  5215. Count: prescribingNumber,
  5216. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5217. PatientId: item.PatientId,
  5218. SystemTime: info.SysRecordTime,
  5219. ConsumableType: 7,
  5220. IsSys: 0,
  5221. WarehousingOrder: "",
  5222. WarehouseOutId: info.WarehouseOutId,
  5223. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5224. IsEdit: 0,
  5225. CancelStockId: cancel.ID,
  5226. CancelOrderNumber: cancel.OrderNumber,
  5227. Manufacturer: manufacturer.ID,
  5228. Dealer: 0,
  5229. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5230. UpdateCreator: 0,
  5231. Status: 1,
  5232. Ctime: time.Now().Unix(),
  5233. Mtime: 0,
  5234. Price: info.Price,
  5235. WarehousingDetailId: info.WarehouseInfotId,
  5236. WarehouseOutDetailId: info.ID,
  5237. CancelOutDetailId: cancelInfo.ID,
  5238. ProductDate: info.ProductDate,
  5239. ExpireDate: info.ExpiryDate,
  5240. StorehouseId: houseConfig.StorehouseOutInfo,
  5241. OverCount: flush_count,
  5242. OperateTime: time.Now().Unix(),
  5243. }
  5244. service.CreateStockFlowOne(flow)
  5245. //退库数量增加
  5246. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5247. //出库数量减少
  5248. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5249. }
  5250. if info.Count < total_count {
  5251. //回退库存
  5252. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5253. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5254. var flush_count int64
  5255. for _, it := range goodList {
  5256. flush_count += it.StockCount
  5257. }
  5258. cancelStockInfo := models.CancelStockInfo{
  5259. GoodId: item.ProjectId,
  5260. CancelStockId: cancel.ID,
  5261. GoodTypeId: good.GoodTypeId,
  5262. Count: info.Count,
  5263. Price: info.Price,
  5264. Total: 0,
  5265. ProductDate: info.ProductDate,
  5266. ExpiryDate: info.ExpiryDate,
  5267. Ctime: time.Now().Unix(),
  5268. Status: 1,
  5269. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5270. OrderNumber: cancel.OrderNumber,
  5271. Type: 0,
  5272. Dealer: deaerler.DealerName,
  5273. Manufacturer: manufacturer.ManufacturerName,
  5274. Number: info.Number,
  5275. RegisterAccount: "",
  5276. Remark: "",
  5277. WarehouseInfoId: info.WarehouseInfotId,
  5278. PatientId: info.PatientId,
  5279. RecordDate: info.SysRecordTime,
  5280. StorehouseId: houseConfig.StorehouseOutInfo,
  5281. IsCheck: 1,
  5282. }
  5283. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5284. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5285. flow := models.VmStockFlow{
  5286. WarehousingId: info.WarehouseInfotId,
  5287. GoodId: item.ProjectId,
  5288. Number: info.Number,
  5289. LicenseNumber: info.LicenseNumber,
  5290. Count: info.Count,
  5291. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5292. PatientId: item.PatientId,
  5293. SystemTime: info.SysRecordTime,
  5294. ConsumableType: 7,
  5295. IsSys: 0,
  5296. WarehousingOrder: "",
  5297. WarehouseOutId: info.WarehouseOutId,
  5298. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5299. IsEdit: 0,
  5300. CancelStockId: cancel.ID,
  5301. CancelOrderNumber: cancel.OrderNumber,
  5302. Manufacturer: manufacturer.ID,
  5303. Dealer: 0,
  5304. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5305. UpdateCreator: 0,
  5306. Status: 1,
  5307. Ctime: time.Now().Unix(),
  5308. Mtime: 0,
  5309. Price: info.Price,
  5310. WarehousingDetailId: info.WarehouseInfotId,
  5311. WarehouseOutDetailId: info.ID,
  5312. CancelOutDetailId: cancelInfo.ID,
  5313. ProductDate: info.ProductDate,
  5314. ExpireDate: info.ExpiryDate,
  5315. StorehouseId: houseConfig.StorehouseOutInfo,
  5316. OverCount: flush_count,
  5317. OperateTime: time.Now().Unix(),
  5318. }
  5319. service.CreateStockFlowOne(flow)
  5320. //退库数量增加
  5321. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5322. //出库数量减少
  5323. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5324. }
  5325. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5326. var flush_count int64
  5327. for _, it := range goodList {
  5328. flush_count += it.StockCount
  5329. }
  5330. //查询已出库数量
  5331. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5332. if prescribingNumber < dialysisInfo.Count {
  5333. //改变数量
  5334. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5335. }
  5336. if prescribingNumber >= dialysisInfo.Count {
  5337. //删除出库表
  5338. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5339. }
  5340. //更新库存
  5341. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5342. //更新基础库库存
  5343. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5344. }
  5345. }
  5346. }
  5347. }
  5348. //保存耗材出库
  5349. if goodOutConfig.IsOpen == 1 {
  5350. if item.Type == 3 {
  5351. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5352. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5353. good.Total = good.Total + f_count
  5354. service.UpdateGoodInfo(&good)
  5355. operation_time := time.Now().Unix()
  5356. creater := c.GetAdminUserInfo().AdminUser.Id
  5357. //创建退库单
  5358. timeStr := time.Now().Format("2006-01-02")
  5359. timeArr := strings.Split(timeStr, "-")
  5360. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5361. total = total + 1
  5362. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5363. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5364. cancelStock := models.CancelStock{
  5365. OrderNumber: orderNumber,
  5366. OperaTime: operation_time,
  5367. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5368. Creater: creater,
  5369. Ctime: time.Now().Unix(),
  5370. Status: 1,
  5371. ReturnTime: item.RecordDate,
  5372. Type: 1,
  5373. StorehouseId: houseConfig.StorehouseOutInfo,
  5374. IsCheck: 1,
  5375. }
  5376. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5377. if msgerrkonde == gorm.ErrRecordNotFound {
  5378. service.AddSigleCancelStock(&cancelStock)
  5379. }
  5380. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5381. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5382. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5383. //查询该耗材是否出库
  5384. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5385. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5386. deaerler, _ := service.GetDealerById(info.Dealer)
  5387. var total_count int64
  5388. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5389. total_count += count
  5390. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5391. var flush_count int64
  5392. for _, it := range goodList {
  5393. flush_count += it.StockCount
  5394. }
  5395. fmt.Println("历史出库数据", info.Count)
  5396. fmt.Println("出库数量", total_count)
  5397. if info.ID > 0 {
  5398. cancelStockInfo := models.CancelStockInfo{
  5399. GoodId: item.ProjectId,
  5400. CancelStockId: cancel.ID,
  5401. GoodTypeId: good.GoodTypeId,
  5402. Count: prescribingNumber,
  5403. Price: info.Price,
  5404. Total: 0,
  5405. ProductDate: info.ProductDate,
  5406. ExpiryDate: info.ExpiryDate,
  5407. Ctime: time.Now().Unix(),
  5408. Status: 1,
  5409. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5410. OrderNumber: cancel.OrderNumber,
  5411. Type: 0,
  5412. Dealer: deaerler.DealerName,
  5413. Manufacturer: manufacturer.ManufacturerName,
  5414. Number: info.Number,
  5415. RegisterAccount: "",
  5416. Remark: "",
  5417. WarehouseInfoId: info.WarehouseInfotId,
  5418. PatientId: info.PatientId,
  5419. RecordDate: info.SysRecordTime,
  5420. StorehouseId: houseConfig.StorehouseOutInfo,
  5421. IsCheck: 1,
  5422. }
  5423. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5424. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5425. //查询出库数量
  5426. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5427. //出库数据 大于 退库数量
  5428. if len(list) > 0 {
  5429. for _, it := range list {
  5430. //回退库存
  5431. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5432. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5433. var flush_count_one int64
  5434. for _, it := range goodList {
  5435. flush_count_one += it.StockCount
  5436. }
  5437. //查询该批次是否有退库数据
  5438. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5439. creater := c.GetAdminUserInfo().AdminUser.Id
  5440. flow := models.VmStockFlow{
  5441. WarehousingId: it.WarehouseInfotId,
  5442. GoodId: it.GoodId,
  5443. Number: it.Number,
  5444. LicenseNumber: it.LicenseNumber,
  5445. Count: it.Count,
  5446. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5447. PatientId: it.PatientId,
  5448. SystemTime: it.SysRecordTime,
  5449. ConsumableType: 7,
  5450. IsSys: 0,
  5451. WarehousingOrder: "",
  5452. WarehouseOutId: it.WarehouseOutId,
  5453. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5454. IsEdit: 0,
  5455. CancelStockId: cancel.ID,
  5456. CancelOrderNumber: cancel.OrderNumber,
  5457. Manufacturer: manufacturer.ID,
  5458. Dealer: 0,
  5459. Creator: creater,
  5460. UpdateCreator: 0,
  5461. Status: 1,
  5462. Ctime: time.Now().Unix(),
  5463. Mtime: 0,
  5464. Price: it.Price,
  5465. WarehousingDetailId: it.WarehouseInfotId,
  5466. WarehouseOutDetailId: it.ID,
  5467. CancelOutDetailId: cancelInfo.ID,
  5468. ProductDate: it.ProductDate,
  5469. ExpireDate: it.ExpiryDate,
  5470. StorehouseId: houseConfig.StorehouseOutInfo,
  5471. OverCount: flush_count_one,
  5472. }
  5473. service.CreateStockFlowOne(flow)
  5474. //if flow.ID > 0 {
  5475. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5476. //}
  5477. }
  5478. }
  5479. //flow := models.VmStockFlow{
  5480. // WarehousingId: info.WarehouseInfotId,
  5481. // GoodId: item.ProjectId,
  5482. // Number: info.Number,
  5483. // LicenseNumber: info.LicenseNumber,
  5484. // Count: prescribingNumber,
  5485. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5486. // PatientId: item.PatientId,
  5487. // SystemTime: info.SysRecordTime,
  5488. // ConsumableType: 7,
  5489. // IsSys: 0,
  5490. // WarehousingOrder: "",
  5491. // WarehouseOutId: info.WarehouseOutId,
  5492. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5493. // IsEdit: 0,
  5494. // CancelStockId: cancel.ID,
  5495. // CancelOrderNumber: cancel.OrderNumber,
  5496. // Manufacturer: manufacturer.ID,
  5497. // Dealer: 0,
  5498. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5499. // UpdateCreator: 0,
  5500. // Status: 1,
  5501. // Ctime: time.Now().Unix(),
  5502. // Mtime: 0,
  5503. // Price: info.Price,
  5504. // WarehousingDetailId: info.WarehouseInfotId,
  5505. // WarehouseOutDetailId: info.ID,
  5506. // CancelOutDetailId: cancelInfo.ID,
  5507. // ProductDate: info.ProductDate,
  5508. // ExpireDate: info.ExpiryDate,
  5509. // StorehouseId: houseConfig.StorehouseOutInfo,
  5510. // OverCount: flush_count,
  5511. //}
  5512. //service.CreateStockFlowOne(flow)
  5513. //退库数量增加
  5514. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5515. //出库数量减少
  5516. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5517. //查询已出库数量
  5518. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5519. if prescribingNumber < dialysisInfo.Count {
  5520. //改变数量
  5521. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5522. }
  5523. if prescribingNumber >= dialysisInfo.Count {
  5524. //删除出库表
  5525. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5526. }
  5527. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5528. var flush_count_one int64
  5529. for _, it := range goodList {
  5530. flush_count_one += it.StockCount
  5531. }
  5532. //更新库存
  5533. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5534. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5535. //更新基础库库存
  5536. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5537. }
  5538. }
  5539. }
  5540. }
  5541. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5542. fmt.Println(err)
  5543. }
  5544. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5545. fmt.Println(err)
  5546. if len(advices) > 0 {
  5547. for _, item := range advices {
  5548. redis := service.RedisClient()
  5549. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5550. redis.Set(keyFive, "", time.Second)
  5551. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5552. redis.Set(keyOne, "", time.Second)
  5553. redis.Close()
  5554. }
  5555. }
  5556. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5557. if len(advices) > 0 {
  5558. for _, item := range advices {
  5559. creater := c.GetAdminUserInfo().AdminUser.Id
  5560. service.DrugAutoAddCancelInfo(item, creater)
  5561. }
  5562. }
  5563. } else {
  5564. if drugOutConfig.IsOpen == 1 {
  5565. if len(advices) > 0 {
  5566. for _, item := range advices {
  5567. creater := c.GetAdminUserInfo().AdminUser.Id
  5568. service.DrugAutoAddCancelInfo(item, creater)
  5569. }
  5570. }
  5571. } else {
  5572. if len(advices) > 0 {
  5573. for _, item := range advices {
  5574. creater := c.GetAdminUserInfo().AdminUser.Id
  5575. service.DrugAutoAddCancelInfo(item, creater)
  5576. }
  5577. }
  5578. }
  5579. }
  5580. c.ServeSuccessJSON(map[string]interface{}{
  5581. "msg": "删除成功",
  5582. })
  5583. return
  5584. }
  5585. func (c *HisApiController) DeleteDoctorAdvice() {
  5586. id, _ := c.GetInt64("id")
  5587. advice, _ := service.GetHisDoctorAdvicesById(id)
  5588. ////同步到自备药
  5589. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5590. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5591. if selfPrescriptionOpen.IsOpen == 1 {
  5592. db := service.XTWriteDB()
  5593. tx := db.Begin()
  5594. defer func() {
  5595. if r := recover(); r != nil {
  5596. tx.Rollback()
  5597. } else {
  5598. tx.Commit()
  5599. }
  5600. }()
  5601. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
  5602. var total_count int64
  5603. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5604. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5605. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5606. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5607. }
  5608. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5609. total_count += prescribingNumberSeven
  5610. }
  5611. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5612. total_count += prescribingNumberSeven
  5613. }
  5614. timeStr := time.Now().Format("2006-01-02")
  5615. timeArr := strings.Split(timeStr, "-")
  5616. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5617. total = total + 1
  5618. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5619. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5620. number = number + total
  5621. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5622. operation_time := time.Now().Unix()
  5623. creater := c.GetAdminUserInfo().AdminUser.Id
  5624. //创建一个出库单
  5625. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5626. WarehouseOutOrderNumber: warehousing_out_order,
  5627. OperationTime: operation_time,
  5628. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5629. Creater: creater,
  5630. Ctime: time.Now().Unix(),
  5631. Status: 1,
  5632. WarehouseOutTime: advice.AdviceDate,
  5633. Type: 0,
  5634. PatientId: advice.PatientId,
  5635. IsCheck: 1,
  5636. }
  5637. //查询今日是否有出库数据
  5638. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5639. if lastWarehouseOut.ID == 0 {
  5640. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5641. }
  5642. //出库
  5643. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5644. WarehouseOutId: lastWarehouseOut.ID,
  5645. WarehouseOutOrderNumber: warehousing_out_order,
  5646. DrugId: advice.DrugId,
  5647. Count: total_count,
  5648. Price: 0,
  5649. TotalPrice: 0,
  5650. Status: 1,
  5651. Ctime: advice.AdviceDate,
  5652. Mtime: advice.AdviceDate,
  5653. Remark: "",
  5654. OrgId: advice.UserOrgId,
  5655. Type: 0,
  5656. Manufacturer: selfBasedrug.Manufacturer,
  5657. Dealer: selfBasedrug.Dealer,
  5658. RetailPrice: 0,
  5659. RetailTotalPrice: 0,
  5660. CountUnit: advice.PrescribingNumberUnit,
  5661. ExpiryDate: 0,
  5662. ProductDate: 0,
  5663. Number: "",
  5664. BatchNumber: "",
  5665. IsSys: 0,
  5666. WarehouseInfoId: 0,
  5667. AdminUserId: 0,
  5668. StockCount: "",
  5669. IsCheck: 1,
  5670. SysRecordTime: advice.AdviceDate,
  5671. PatientId: advice.PatientId,
  5672. AdviceId: advice.ID,
  5673. ClassType: "",
  5674. }
  5675. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5676. for _, it := range warehousingOutInfo {
  5677. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5678. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5679. //出库逻辑
  5680. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5681. //查询剩余库存
  5682. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5683. var sum_count int64
  5684. for _, its := range stockInfo {
  5685. if its.MaxUnit == medical.MaxUnit {
  5686. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5687. }
  5688. sum_count += its.StockMaxNumber + its.StockMinNumber
  5689. }
  5690. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5691. }
  5692. }
  5693. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5694. //已收费和已发药的限制逻辑
  5695. isCharge := false
  5696. isMedicine := false
  5697. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5698. //获取今天该患者所有处方,判断是否发药或者收费
  5699. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5700. //for _, item := range new_prescriptions {
  5701. if new_prescription.IsMedicine == 1 {
  5702. isMedicine = true
  5703. }
  5704. //}
  5705. for _, item := range new_prescriptions {
  5706. if item.OrderStatus == 4 {
  5707. isCharge = true
  5708. }
  5709. }
  5710. if isMedicine {
  5711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5712. return
  5713. }
  5714. if isCharge {
  5715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5716. return
  5717. }
  5718. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5719. for _, item := range advices {
  5720. if item.IsMedicine == 1 {
  5721. isMedicine = true
  5722. }
  5723. }
  5724. if isMedicine {
  5725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5726. return
  5727. }
  5728. if new_prescription.ID > 0 {
  5729. if new_prescription.OrderStatus == 2 {
  5730. isCharge = true
  5731. }
  5732. }
  5733. if isCharge {
  5734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5735. return
  5736. }
  5737. //已收费和已发药的限制逻辑
  5738. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5739. redis := service.RedisClient()
  5740. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5741. redis.Set(keyFive, "", time.Second)
  5742. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5743. redis.Set(keyOne, "", time.Second)
  5744. defer redis.Close()
  5745. if err == nil {
  5746. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5747. //查询是否在处方中出库
  5748. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5749. if openConfig.IsOpen != 1 {
  5750. //判断该医嘱是否执行了
  5751. if advice.ExecutionState == 1 {
  5752. creater := c.GetAdminUserInfo().AdminUser.Id
  5753. service.DrugAutoAddCancelInfo(&advice, creater)
  5754. }
  5755. }
  5756. //开启保存处方扣减功能
  5757. if openConfig.IsOpen == 1 {
  5758. creater := c.GetAdminUserInfo().AdminUser.Id
  5759. service.DrugAutoAddCancelInfo(&advice, creater)
  5760. }
  5761. } else {
  5762. if drugOutConfig.IsOpen == 1 {
  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. //判断该医嘱是否执行了
  5779. if advice.ExecutionState == 1 {
  5780. creater := c.GetAdminUserInfo().AdminUser.Id
  5781. service.DrugAutoAddCancelInfo(&advice, creater)
  5782. }
  5783. }
  5784. }
  5785. c.ServeSuccessJSON(map[string]interface{}{
  5786. "msg": "删除成功",
  5787. })
  5788. return
  5789. } else {
  5790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5791. return
  5792. }
  5793. }
  5794. func (c *HisApiController) DeleteProject() {
  5795. id, _ := c.GetInt64("id")
  5796. adminInfo := c.GetAdminUserInfo()
  5797. project, _ := service.GetHisProjectByID(id)
  5798. // var consumable models.DialysisBeforePrepare
  5799. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5800. //耗材保存处方出库
  5801. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5802. isCharge := false
  5803. isMedicine := false
  5804. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5805. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5806. for _, item := range new_prescriptions {
  5807. if item.IsMedicine == 1 {
  5808. isMedicine = true
  5809. }
  5810. }
  5811. for _, item := range new_prescriptions {
  5812. if item.OrderStatus == 4 {
  5813. isCharge = true
  5814. }
  5815. }
  5816. if isMedicine {
  5817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5818. return
  5819. }
  5820. if isCharge {
  5821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5822. return
  5823. }
  5824. if new_prescription.ID > 0 {
  5825. if new_prescription.OrderStatus == 2 {
  5826. isCharge = true
  5827. }
  5828. }
  5829. if isCharge {
  5830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5831. return
  5832. }
  5833. service.DeletePrintInfo(id)
  5834. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5835. label.Status = 0
  5836. service.CreateHisLabelRecordTwo(&label)
  5837. fmt.Println(goodOutConfig.IsOpen)
  5838. if goodOutConfig.IsOpen != 1 {
  5839. if stockConfig.IsOpen == 1 {
  5840. if project.Type == 2 {
  5841. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5842. fmt.Println(err)
  5843. }
  5844. if project.Type == 3 && project.IsOut == 1 {
  5845. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5846. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5847. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5848. operation_time := time.Now().Unix()
  5849. creater := adminInfo.AdminUser.Id
  5850. //创建退库单
  5851. timeStr := time.Now().Format("2006-01-02")
  5852. timeArr := strings.Split(timeStr, "-")
  5853. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5854. total = total + 1
  5855. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5856. cancelStock := models.CancelStock{
  5857. OrderNumber: orderNumber,
  5858. OperaTime: operation_time,
  5859. OrgId: adminInfo.CurrentOrgId,
  5860. Creater: creater,
  5861. Ctime: time.Now().Unix(),
  5862. Status: 1,
  5863. ReturnTime: project.RecordDate,
  5864. Type: 1,
  5865. StorehouseId: houseConfig.StorehouseOutInfo,
  5866. IsCheck: 1,
  5867. }
  5868. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5869. if msgerrkonde == gorm.ErrRecordNotFound {
  5870. service.AddSigleCancelStock(&cancelStock)
  5871. }
  5872. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5873. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5874. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5875. //查询是否有出库
  5876. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5877. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5878. deaerler, _ := service.GetDealerById(info.Dealer)
  5879. if info.ID > 0 {
  5880. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5881. if info.Count >= prescribingNumber {
  5882. cancelStockInfo := models.CancelStockInfo{
  5883. GoodId: project.ProjectId,
  5884. CancelStockId: cancel.ID,
  5885. GoodTypeId: good.GoodTypeId,
  5886. Count: prescribingNumber,
  5887. Price: info.Price,
  5888. Total: 0,
  5889. ProductDate: info.ProductDate,
  5890. ExpiryDate: info.ExpiryDate,
  5891. Ctime: time.Now().Unix(),
  5892. Status: 1,
  5893. OrgId: adminInfo.CurrentOrgId,
  5894. OrderNumber: cancel.OrderNumber,
  5895. Type: 0,
  5896. Dealer: deaerler.DealerName,
  5897. Manufacturer: manufacturer.ManufacturerName,
  5898. Number: info.Number,
  5899. RegisterAccount: "",
  5900. Remark: "",
  5901. WarehouseInfoId: info.WarehouseInfotId,
  5902. PatientId: info.PatientId,
  5903. RecordDate: info.SysRecordTime,
  5904. StorehouseId: houseConfig.StorehouseOutInfo,
  5905. IsCheck: 1,
  5906. }
  5907. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5908. //回退库存
  5909. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5910. //退库数量增加
  5911. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5912. //出库数量减少
  5913. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5914. }
  5915. if info.Count < prescribingNumber {
  5916. cancelStockInfo := models.CancelStockInfo{
  5917. GoodId: project.ProjectId,
  5918. CancelStockId: cancel.ID,
  5919. GoodTypeId: good.GoodTypeId,
  5920. Count: info.Count,
  5921. Price: info.Price,
  5922. Total: 0,
  5923. ProductDate: info.ProductDate,
  5924. ExpiryDate: info.ExpiryDate,
  5925. Ctime: time.Now().Unix(),
  5926. Status: 1,
  5927. OrgId: adminInfo.CurrentOrgId,
  5928. OrderNumber: cancel.OrderNumber,
  5929. Type: 0,
  5930. Dealer: deaerler.DealerName,
  5931. Manufacturer: manufacturer.ManufacturerName,
  5932. Number: info.Number,
  5933. RegisterAccount: "",
  5934. Remark: "",
  5935. WarehouseInfoId: info.WarehouseInfotId,
  5936. PatientId: info.PatientId,
  5937. RecordDate: info.SysRecordTime,
  5938. StorehouseId: houseConfig.StorehouseOutInfo,
  5939. IsCheck: 1,
  5940. }
  5941. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5942. //回退库存
  5943. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5944. //退库数量增加
  5945. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5946. //出库数量减少
  5947. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5948. }
  5949. //查询剩余库存
  5950. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5951. var over_count int64
  5952. for _, it := range goodList {
  5953. over_count += it.StockCount
  5954. }
  5955. //出库数据 大于 退库数量
  5956. if info.Count >= prescribingNumber {
  5957. flow := models.VmStockFlow{
  5958. WarehousingId: info.WarehouseInfotId,
  5959. GoodId: project.ProjectId,
  5960. Number: info.Number,
  5961. LicenseNumber: info.LicenseNumber,
  5962. Count: prescribingNumber,
  5963. UserOrgId: adminInfo.CurrentOrgId,
  5964. PatientId: project.PatientId,
  5965. SystemTime: info.SysRecordTime,
  5966. ConsumableType: 7,
  5967. IsSys: 0,
  5968. WarehousingOrder: "",
  5969. WarehouseOutId: info.WarehouseOutId,
  5970. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5971. IsEdit: 0,
  5972. CancelStockId: cancel.ID,
  5973. CancelOrderNumber: cancel.OrderNumber,
  5974. Manufacturer: manufacturer.ID,
  5975. Dealer: 0,
  5976. Creator: adminInfo.AdminUser.Id,
  5977. UpdateCreator: 0,
  5978. Status: 1,
  5979. Ctime: time.Now().Unix(),
  5980. Mtime: 0,
  5981. Price: info.Price,
  5982. WarehousingDetailId: info.WarehouseInfotId,
  5983. WarehouseOutDetailId: info.ID,
  5984. CancelOutDetailId: cancelInfo.ID,
  5985. ProductDate: info.ProductDate,
  5986. ExpireDate: info.ExpiryDate,
  5987. StorehouseId: houseConfig.StorehouseOutInfo,
  5988. OverCount: over_count,
  5989. OperateTime: time.Now().Unix(),
  5990. }
  5991. service.CreateStockFlowOne(flow)
  5992. }
  5993. //出库数据小于退库数据
  5994. if info.Count < prescribingNumber {
  5995. flow := models.VmStockFlow{
  5996. WarehousingId: info.WarehouseInfotId,
  5997. GoodId: project.ProjectId,
  5998. Number: info.Number,
  5999. LicenseNumber: info.LicenseNumber,
  6000. Count: info.Count,
  6001. UserOrgId: adminInfo.CurrentOrgId,
  6002. PatientId: project.PatientId,
  6003. SystemTime: info.SysRecordTime,
  6004. ConsumableType: 7,
  6005. IsSys: 0,
  6006. WarehousingOrder: "",
  6007. WarehouseOutId: info.WarehouseOutId,
  6008. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6009. IsEdit: 0,
  6010. CancelStockId: cancel.ID,
  6011. CancelOrderNumber: cancel.OrderNumber,
  6012. Manufacturer: manufacturer.ID,
  6013. Dealer: 0,
  6014. Creator: adminInfo.AdminUser.Id,
  6015. UpdateCreator: 0,
  6016. Status: 1,
  6017. Ctime: time.Now().Unix(),
  6018. Mtime: 0,
  6019. Price: info.Price,
  6020. WarehousingDetailId: info.WarehouseInfotId,
  6021. WarehouseOutDetailId: info.ID,
  6022. CancelOutDetailId: cancelInfo.ID,
  6023. ProductDate: info.ProductDate,
  6024. ExpireDate: info.ExpiryDate,
  6025. StorehouseId: houseConfig.StorehouseOutInfo,
  6026. OverCount: over_count,
  6027. OperateTime: time.Now().Unix(),
  6028. }
  6029. service.CreateStockFlowOne(flow)
  6030. }
  6031. //查询已出库数量
  6032. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6033. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6034. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6035. if prescribingNumber < dialysisInfo.Count {
  6036. //改变数量
  6037. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6038. }
  6039. if prescribingNumber >= dialysisInfo.Count {
  6040. //删除出库表
  6041. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6042. }
  6043. //更新剩余库存
  6044. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6045. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6046. var total_count_one int64
  6047. for _, it := range stockList {
  6048. total_count_one += it.StockCount
  6049. }
  6050. //基础库插入数据
  6051. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6052. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6053. var flush_count int64
  6054. for _, it := range goodListOne {
  6055. flush_count += it.StockCount
  6056. }
  6057. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6058. if errs != nil {
  6059. goodErrcode := models.XtGoodErrcode{
  6060. UserOrgId: project.UserOrgId,
  6061. Errcode: "手动出库更新剩余出库失败",
  6062. GoodId: project.ProjectId,
  6063. Status: 1,
  6064. Ctime: time.Now().Unix(),
  6065. Mtime: 0,
  6066. Count: 0,
  6067. StockCount: 0,
  6068. Creater: creater,
  6069. BatchNumberId: 0,
  6070. WarehouseOutId: 0,
  6071. }
  6072. service.CreateGoodErrcode(goodErrcode)
  6073. }
  6074. }
  6075. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6076. fmt.Println(err)
  6077. } else {
  6078. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6079. fmt.Println(err)
  6080. }
  6081. } else {
  6082. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6083. fmt.Println(err)
  6084. }
  6085. }
  6086. //保存处方出库
  6087. if goodOutConfig.IsOpen == 1 {
  6088. if project.Type == 3 {
  6089. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6090. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6091. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6092. operation_time := time.Now().Unix()
  6093. creater := adminInfo.AdminUser.Id
  6094. //创建退库单
  6095. timeStr := time.Now().Format("2006-01-02")
  6096. timeArr := strings.Split(timeStr, "-")
  6097. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6098. total = total + 1
  6099. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6100. cancelStock := models.CancelStock{
  6101. OrderNumber: orderNumber,
  6102. OperaTime: operation_time,
  6103. OrgId: adminInfo.CurrentOrgId,
  6104. Creater: creater,
  6105. Ctime: time.Now().Unix(),
  6106. Status: 1,
  6107. ReturnTime: project.RecordDate,
  6108. Type: 1,
  6109. StorehouseId: houseConfig.StorehouseOutInfo,
  6110. IsCheck: 1,
  6111. }
  6112. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6113. if msgerrkonde == gorm.ErrRecordNotFound {
  6114. service.AddSigleCancelStock(&cancelStock)
  6115. }
  6116. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6117. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6118. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6119. //获取出库数据
  6120. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6121. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6122. deaerler, _ := service.GetDealerById(info.Dealer)
  6123. if info.ID > 0 {
  6124. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6125. if info.Count >= prescribingNumber {
  6126. cancelStockInfo := models.CancelStockInfo{
  6127. GoodId: project.ProjectId,
  6128. CancelStockId: cancel.ID,
  6129. GoodTypeId: good.GoodTypeId,
  6130. Count: prescribingNumber,
  6131. Price: info.Price,
  6132. Total: 0,
  6133. ProductDate: info.ProductDate,
  6134. ExpiryDate: info.ExpiryDate,
  6135. Ctime: time.Now().Unix(),
  6136. Status: 1,
  6137. OrgId: adminInfo.CurrentOrgId,
  6138. OrderNumber: cancel.OrderNumber,
  6139. Type: 0,
  6140. Dealer: deaerler.DealerName,
  6141. Manufacturer: manufacturer.ManufacturerName,
  6142. Number: info.Number,
  6143. RegisterAccount: "",
  6144. Remark: "",
  6145. WarehouseInfoId: info.WarehouseInfotId,
  6146. PatientId: info.PatientId,
  6147. RecordDate: info.SysRecordTime,
  6148. StorehouseId: houseConfig.StorehouseOutInfo,
  6149. IsCheck: 1,
  6150. }
  6151. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6152. //退库数量增加
  6153. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6154. //出库数量减少
  6155. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6156. }
  6157. if info.Count < prescribingNumber {
  6158. cancelStockInfo := models.CancelStockInfo{
  6159. GoodId: project.ProjectId,
  6160. CancelStockId: cancel.ID,
  6161. GoodTypeId: good.GoodTypeId,
  6162. Count: prescribingNumber,
  6163. Price: info.Price,
  6164. Total: 0,
  6165. ProductDate: info.ProductDate,
  6166. ExpiryDate: info.ExpiryDate,
  6167. Ctime: time.Now().Unix(),
  6168. Status: 1,
  6169. OrgId: adminInfo.CurrentOrgId,
  6170. OrderNumber: cancel.OrderNumber,
  6171. Type: 0,
  6172. Dealer: deaerler.DealerName,
  6173. Manufacturer: manufacturer.ManufacturerName,
  6174. Number: info.Number,
  6175. RegisterAccount: "",
  6176. Remark: "",
  6177. WarehouseInfoId: info.WarehouseInfotId,
  6178. PatientId: info.PatientId,
  6179. RecordDate: info.SysRecordTime,
  6180. StorehouseId: houseConfig.StorehouseOutInfo,
  6181. IsCheck: 1,
  6182. }
  6183. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6184. //回退库存
  6185. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6186. }
  6187. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6188. var over_count int64
  6189. for _, it := range goodList {
  6190. over_count += it.StockCount
  6191. }
  6192. //查询出库数量
  6193. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6194. //出库数据 大于 退库数量
  6195. if len(list) > 0 {
  6196. for _, it := range list {
  6197. //回退库存
  6198. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6199. //退库数量增加
  6200. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6201. //出库数量减少
  6202. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6203. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6204. var over_count_one int64
  6205. for _, it := range goodList {
  6206. over_count_one += it.StockCount
  6207. }
  6208. //查询该批次是否有退库数据
  6209. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6210. flow := models.VmStockFlow{
  6211. WarehousingId: it.WarehouseInfotId,
  6212. GoodId: it.GoodId,
  6213. Number: it.Number,
  6214. LicenseNumber: it.LicenseNumber,
  6215. Count: it.Count,
  6216. UserOrgId: adminInfo.CurrentOrgId,
  6217. PatientId: it.PatientId,
  6218. SystemTime: it.SysRecordTime,
  6219. ConsumableType: 7,
  6220. IsSys: 0,
  6221. WarehousingOrder: "",
  6222. WarehouseOutId: it.WarehouseOutId,
  6223. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6224. IsEdit: 0,
  6225. CancelStockId: cancel.ID,
  6226. CancelOrderNumber: cancel.OrderNumber,
  6227. Manufacturer: manufacturer.ID,
  6228. Dealer: 0,
  6229. Creator: adminInfo.AdminUser.Id,
  6230. UpdateCreator: 0,
  6231. Status: 1,
  6232. Ctime: time.Now().Unix(),
  6233. Mtime: 0,
  6234. Price: it.Price,
  6235. WarehousingDetailId: it.WarehouseInfotId,
  6236. WarehouseOutDetailId: it.ID,
  6237. CancelOutDetailId: cancelInfo.ID,
  6238. ProductDate: it.ProductDate,
  6239. ExpireDate: it.ExpiryDate,
  6240. StorehouseId: houseConfig.StorehouseOutInfo,
  6241. OverCount: over_count_one,
  6242. OperateTime: time.Now().Unix(),
  6243. }
  6244. service.CreateStockFlowOne(flow)
  6245. }
  6246. }
  6247. //查询已出库数量
  6248. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6249. if prescribingNumber < dialysisInfo.Count {
  6250. //改变数量
  6251. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6252. }
  6253. if prescribingNumber >= dialysisInfo.Count {
  6254. //删除出库表
  6255. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6256. }
  6257. //更新剩余库存
  6258. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6259. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6260. var total_count_one int64
  6261. for _, it := range stockList {
  6262. total_count_one += it.StockCount
  6263. }
  6264. //基础库插入数据
  6265. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6266. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6267. var flush_count int64
  6268. for _, it := range goodListOne {
  6269. flush_count += it.StockCount
  6270. }
  6271. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6272. if errs != nil {
  6273. goodErrcode := models.XtGoodErrcode{
  6274. UserOrgId: project.UserOrgId,
  6275. Errcode: "手动出库更新剩余出库失败",
  6276. GoodId: project.ProjectId,
  6277. Status: 1,
  6278. Ctime: time.Now().Unix(),
  6279. Mtime: 0,
  6280. Count: 0,
  6281. StockCount: 0,
  6282. Creater: creater,
  6283. BatchNumberId: 0,
  6284. WarehouseOutId: 0,
  6285. }
  6286. service.CreateGoodErrcode(goodErrcode)
  6287. }
  6288. }
  6289. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6290. fmt.Println(err)
  6291. } else {
  6292. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6293. fmt.Println(err)
  6294. }
  6295. }
  6296. c.ServeSuccessJSON(map[string]interface{}{
  6297. "msg": "删除成功",
  6298. })
  6299. return
  6300. }
  6301. func (c *HisApiController) CreateHisAdditionalCharge() {
  6302. his_patient_id, _ := c.GetInt64("his_patient_id")
  6303. patient_id, _ := c.GetInt64("patient_id")
  6304. record_date := c.GetString("record_date")
  6305. timeLayout := "2006-01-02"
  6306. loc, _ := time.LoadLocation("Local")
  6307. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6308. if err != nil {
  6309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6310. return
  6311. }
  6312. adminInfo := c.GetAdminUserInfo()
  6313. recordDateTime := theTime.Unix()
  6314. dataBody := make(map[string]interface{}, 0)
  6315. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6316. if err != nil {
  6317. utils.ErrorLog(err.Error())
  6318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6319. return
  6320. }
  6321. var additions []*models.HisAdditionalCharge
  6322. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6323. additions, _ := dataBody["addition"].([]interface{})
  6324. if len(additions) > 0 {
  6325. for _, item := range additions {
  6326. items := item.(map[string]interface{})
  6327. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6328. utils.ErrorLog("item_id")
  6329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6330. return
  6331. }
  6332. item_id := int64(items["item_id"].(float64))
  6333. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6334. utils.ErrorLog("item_name")
  6335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6336. return
  6337. }
  6338. item_name := items["item_name"].(string)
  6339. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6340. utils.ErrorLog("price")
  6341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6342. return
  6343. }
  6344. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6345. ctime := time.Now().Unix()
  6346. additional := &models.HisAdditionalCharge{
  6347. PatientId: patient_id,
  6348. HisPatientId: his_patient_id,
  6349. UserOrgId: adminInfo.CurrentOrgId,
  6350. RecordDate: recordDateTime,
  6351. CreatedTime: ctime,
  6352. UpdatedTime: ctime,
  6353. Modifier: adminInfo.AdminUser.Id,
  6354. Creator: adminInfo.AdminUser.Id,
  6355. Price: price,
  6356. ItemName: item_name,
  6357. ItemId: item_id,
  6358. Status: 1,
  6359. }
  6360. additions = append(additions, additional)
  6361. }
  6362. }
  6363. }
  6364. for _, item := range additions {
  6365. service.CreateAddtionalCharge(item)
  6366. }
  6367. c.ServeSuccessJSON(map[string]interface{}{
  6368. "msg": "创建成功",
  6369. })
  6370. }
  6371. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6372. blood_fat := c.GetString("blood_fat")
  6373. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6374. blood_sugar := c.GetString("blood_sugar")
  6375. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6376. chief_conplaint := c.GetString("chief_conplaint")
  6377. dbp := c.GetString("dbp")
  6378. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6379. delivery_way, _ := c.GetInt64("delivery_way")
  6380. diagnostic := c.GetString("diagnostic")
  6381. family_history := c.GetString("family_history")
  6382. height := c.GetString("height")
  6383. history_of_present_illness := c.GetString("history_of_present_illness")
  6384. is_infect, _ := c.GetInt64("is_infect")
  6385. past_history := c.GetString("past_history")
  6386. patient_id, _ := c.GetInt64("patient_id")
  6387. his_patient_id, _ := c.GetInt64("his_patient_id")
  6388. personal_history := c.GetString("personal_history")
  6389. pulse := c.GetString("pulse")
  6390. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6391. sbp := c.GetString("sbp")
  6392. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6393. heightfloat, _ := strconv.ParseFloat(height, 64)
  6394. sicktype := c.GetString("sick_type")
  6395. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6396. symptom := c.GetString("symptom")
  6397. sick_date := c.GetString("sick_date")
  6398. temperatures := c.GetString("temperature")
  6399. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6400. record_date := c.GetString("record_date")
  6401. breathing := c.GetString("breathing")
  6402. doctor_advice := c.GetString("doctor_advice")
  6403. remark := c.GetString("remark")
  6404. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6405. sick, _ := c.GetInt64("sick")
  6406. diagnose, _ := c.GetInt64("diagnose")
  6407. //id, _ := c.GetInt64("id")
  6408. timeLayout := "2006-01-02"
  6409. loc, _ := time.LoadLocation("Local")
  6410. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6411. allergic_history := c.GetString("allergic_history")
  6412. if err != nil {
  6413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6414. return
  6415. }
  6416. recordDateTime := theTime.Unix()
  6417. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6418. if err != nil {
  6419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6420. return
  6421. }
  6422. sickTimes := sickTime.Unix()
  6423. ctime := time.Now().Unix()
  6424. primary_disease := c.GetString("primary_disease")
  6425. confirm_failure_date := c.GetString("confirm_failure_date")
  6426. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6427. drug_allergy_history := c.GetString("drug_allergy_history")
  6428. physical_examination := c.GetString("physical_examination")
  6429. special_inspection := c.GetString("special_inspection")
  6430. lab_apparatus := c.GetString("lab_apparatus")
  6431. caseHistory := models.HisPatientCaseHistory{
  6432. HisPatientId: his_patient_id,
  6433. PatientId: patient_id,
  6434. Temperature: temperature,
  6435. BloodSugar: bloodsugarfloat,
  6436. Pulse: pulsefloat,
  6437. Sbp: sbpfloat,
  6438. Dbp: dbpfloat,
  6439. Height: heightfloat,
  6440. BloodFat: bloodfatfloat,
  6441. SickType: sick_type,
  6442. Symptom: symptom,
  6443. SickDate: sickTimes,
  6444. IsInfect: is_infect,
  6445. HistoryOfPresentIllness: history_of_present_illness,
  6446. PastHistory: past_history,
  6447. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6448. ChiefConplaint: chief_conplaint,
  6449. PersonalHistory: personal_history,
  6450. FamilyHistory: family_history,
  6451. Diagnostic: diagnostic,
  6452. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6453. Status: 1,
  6454. Ctime: ctime,
  6455. Mtime: ctime,
  6456. RecordDate: recordDateTime,
  6457. DeliveryWay: delivery_way,
  6458. Breathing: breathingfloat,
  6459. DoctorAdvice: doctor_advice,
  6460. Remark: remark,
  6461. Sick: sick,
  6462. Diagnose: diagnose,
  6463. AllergicHistory: allergic_history,
  6464. PrimaryDisease: primary_disease,
  6465. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6466. DrugAllergyHistory: drug_allergy_history,
  6467. PhysicalExamination: physical_examination,
  6468. SpecialInspection: special_inspection,
  6469. LabApparatus: lab_apparatus,
  6470. }
  6471. //查询该患者是否有病历
  6472. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6473. if errcodes == gorm.ErrRecordNotFound {
  6474. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6475. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6476. if err != nil {
  6477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6478. return
  6479. }
  6480. c.ServeSuccessJSON(map[string]interface{}{
  6481. "caseHistory": caseHistory,
  6482. "historyInfo": historyInfo,
  6483. })
  6484. return
  6485. } else if errcodes == nil {
  6486. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6487. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6488. if err != nil {
  6489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6490. return
  6491. }
  6492. c.ServeSuccessJSON(map[string]interface{}{
  6493. "caseHistory": caseHistory,
  6494. "historyInfo": historyInfo,
  6495. })
  6496. }
  6497. //查询该患者是否有病历
  6498. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6499. //if errcode == gorm.ErrRecordNotFound {
  6500. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6501. // if err != nil {
  6502. // c.ServeSuccessJSON(map[string]interface{}{
  6503. // "msg": "保存成功",
  6504. // })
  6505. // }
  6506. //} else if errcode == nil {
  6507. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6508. // return
  6509. //}
  6510. }
  6511. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6512. patient_id, _ := c.GetInt64("patient_id", 0)
  6513. adminUser := c.GetAdminUserInfo()
  6514. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6515. c.ServeSuccessJSON(map[string]interface{}{
  6516. "list": caseHistorys,
  6517. })
  6518. }
  6519. func (c *HisApiController) GetHisPatientCaseHistory() {
  6520. record_date, _ := c.GetInt64("record_date", 0)
  6521. patient_id, _ := c.GetInt64("patient_id", 0)
  6522. admin := c.GetAdminUserInfo()
  6523. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6524. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6525. c.ServeSuccessJSON(map[string]interface{}{
  6526. "info": info,
  6527. "case_history": case_history,
  6528. })
  6529. }
  6530. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6531. template_name := c.GetString("template_name")
  6532. template_remark := c.GetString("template_remark")
  6533. doctor := c.GetAdminUserInfo().AdminUser.Id
  6534. diagnostic := c.GetString("diagnostic")
  6535. chief_conplaint := c.GetString("chief_conplain")
  6536. history_of_present_illness := c.GetString("history_of_present_illness")
  6537. past_history := c.GetString("past_history")
  6538. personal_history := c.GetString("personal_history")
  6539. family_history := c.GetString("family_history")
  6540. user_name := c.GetString("user_name")
  6541. doctor_advice := c.GetString("doctor_advice")
  6542. remark := c.GetString("remark")
  6543. //record_date := c.GetString("record_date")
  6544. //fmt.Println("record_date--------",record_date)
  6545. //timeLayout := "2006-01-02"
  6546. //loc, _ := time.LoadLocation("Local")
  6547. //
  6548. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6549. //if err != nil {
  6550. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6551. // return
  6552. //}
  6553. //recordDateTime := theTime.Unix()
  6554. ctime := time.Now().Unix()
  6555. template := models.HisCaseHistoryTemplate{
  6556. HistoryOfPresentIllness: history_of_present_illness,
  6557. PastHistory: past_history,
  6558. ChiefConplaint: chief_conplaint,
  6559. PersonalHistory: personal_history,
  6560. FamilyHistory: family_history,
  6561. Diagnostic: diagnostic,
  6562. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6563. Status: 1,
  6564. Ctime: ctime,
  6565. Mtime: ctime,
  6566. RecordDate: time.Now().Unix(),
  6567. TemplateName: template_name,
  6568. TemplateRemark: template_remark,
  6569. Creator: doctor,
  6570. Modifier: doctor,
  6571. UserName: user_name,
  6572. DoctorAdvice: doctor_advice,
  6573. Remark: remark,
  6574. }
  6575. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6576. if err == nil {
  6577. c.ServeSuccessJSON(map[string]interface{}{
  6578. "msg": "保存成功",
  6579. })
  6580. } else {
  6581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6582. return
  6583. }
  6584. }
  6585. func (c *HisApiController) GetCaseHistoryTemplate() {
  6586. timeLayout := "2006-01-02"
  6587. loc, _ := time.LoadLocation("Local")
  6588. keyword := c.GetString("keyword")
  6589. start_time := c.GetString("start_time")
  6590. end_time := c.GetString("end_time")
  6591. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6592. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6593. admin := c.GetAdminUserInfo()
  6594. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6595. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6596. c.ServeSuccessJSON(map[string]interface{}{
  6597. "template": template,
  6598. //"history": history,
  6599. })
  6600. }
  6601. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6602. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6603. utils.ErrorLog("drug_name")
  6604. return enums.ErrorCodeParamWrong
  6605. }
  6606. adviceName, _ := json["drug_name"].(string)
  6607. if len(adviceName) == 0 {
  6608. utils.ErrorLog("len(advice_name) == 0")
  6609. return enums.ErrorCodeParamWrong
  6610. }
  6611. advice.AdviceName = adviceName
  6612. adviceDesc, _ := json["advice_desc"].(string)
  6613. advice.AdviceDesc = adviceDesc
  6614. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6615. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6616. advice.DrugSpec = drugSpec
  6617. }
  6618. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6619. remark, _ := json["remark"].(string)
  6620. advice.Remark = remark
  6621. }
  6622. if json["id"] == nil {
  6623. advice.DrugId = 0
  6624. } else {
  6625. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6626. drug_id := int64(json["id"].(float64))
  6627. advice.DrugId = drug_id
  6628. }
  6629. }
  6630. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6631. advice_id := int64(json["advice_id"].(float64))
  6632. advice.ID = advice_id
  6633. if advice.ID > 0 {
  6634. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6635. if err == nil {
  6636. if hisAdvice.ID > 0 {
  6637. advice.ExecutionTime = hisAdvice.ExecutionTime
  6638. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6639. advice.ExecutionState = hisAdvice.ExecutionState
  6640. advice.CheckTime = hisAdvice.CheckTime
  6641. advice.Checker = hisAdvice.Checker
  6642. advice.CheckState = hisAdvice.CheckState
  6643. advice.StartTime = hisAdvice.StartTime
  6644. advice.FeedetlSn = hisAdvice.FeedetlSn
  6645. }
  6646. }
  6647. }
  6648. }
  6649. //
  6650. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6651. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6652. // advice.ExecutionTime = execution_time
  6653. //}
  6654. //
  6655. //
  6656. //
  6657. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6658. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6659. // advice.ExecutionStaff = execution_staff
  6660. //}
  6661. //
  6662. //
  6663. //
  6664. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6665. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6666. // advice.ExecutionState = execution_state
  6667. //}
  6668. //
  6669. //
  6670. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6671. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6672. // advice.CheckTime = check_time
  6673. //}
  6674. //
  6675. //
  6676. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6677. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6678. // advice.CheckState = check_state
  6679. //}
  6680. //
  6681. //
  6682. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6683. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6684. // advice.Checker = checker
  6685. //}
  6686. //
  6687. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6688. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6689. // advice.StartTime = start_time
  6690. //}
  6691. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6692. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6693. advice.IsSelfDrug = is_self_drug
  6694. }
  6695. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6696. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6697. drug_way_count, _ := json["drug_way_count"].(string)
  6698. advice.DrugWayCount = drug_way_count
  6699. }
  6700. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6701. drugSpecUnit, _ := json["min_unit"].(string)
  6702. advice.DrugSpecUnit = drugSpecUnit
  6703. }
  6704. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6705. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6706. advice.SingleDose = singleDose
  6707. }
  6708. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6709. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6710. advice.SingleDoseUnit = singleDoseUnit
  6711. }
  6712. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6713. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6714. advice.PrescribingNumber = prescribingNumber
  6715. }
  6716. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6717. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6718. advice.PrescribingNumberUnit = prescribingNumberUnit
  6719. }
  6720. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6721. deliveryWay, _ := json["delivery_way"].(string)
  6722. advice.DeliveryWay = deliveryWay
  6723. }
  6724. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6725. executionFrequency, _ := json["execution_frequency"].(string)
  6726. advice.ExecutionFrequency = executionFrequency
  6727. }
  6728. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6729. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6730. advice.Price = price
  6731. }
  6732. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6733. med_list_codg, _ := json["medical_insurance_number"].(string)
  6734. advice.MedListCodg = med_list_codg
  6735. }
  6736. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6737. day := int64(json["day"].(float64))
  6738. advice.Day = day
  6739. }
  6740. return 0
  6741. }
  6742. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6743. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6744. id := int64(json["id"].(float64))
  6745. project.ID = id
  6746. historyProject, _ := service.GetHisProjectByID(id)
  6747. project.FeedetlSn = historyProject.FeedetlSn
  6748. }
  6749. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6750. project_id := int64(json["project_id"].(float64))
  6751. project.ProjectId = project_id
  6752. }
  6753. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6754. // price := int64(json["price"].(float64))
  6755. // formatInt_price := strconv.FormatInt(price, 10)
  6756. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6757. // project.Price = float_price
  6758. // }
  6759. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6760. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6761. project.Price = price
  6762. }
  6763. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6764. total, _ := json["total"].(string)
  6765. project.Count = total
  6766. }
  6767. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6768. medical_code, _ := json["medical_code"].(string)
  6769. project.MedListCodg = medical_code
  6770. }
  6771. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6772. single_dose, _ := json["single_dose"].(string)
  6773. project.SingleDose = single_dose
  6774. }
  6775. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6776. delivery_way, _ := json["delivery_way"].(string)
  6777. project.DeliveryWay = delivery_way
  6778. }
  6779. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6780. execution_frequency, _ := json["execution_frequency"].(string)
  6781. project.ExecutionFrequency = execution_frequency
  6782. }
  6783. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6784. remark, _ := json["remark"].(string)
  6785. project.Remark = remark
  6786. }
  6787. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6788. day, _ := json["number_days"].(string)
  6789. project.Day = day
  6790. }
  6791. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6792. unit, _ := json["unit"].(string)
  6793. project.Unit = unit
  6794. }
  6795. return 0
  6796. }
  6797. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6798. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6799. id := int64(json["id"].(float64))
  6800. historyAddtions, _ := service.GetHisAdditionByID(id)
  6801. additionalCharge.ID = id
  6802. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6803. }
  6804. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6805. item_id := int64(json["item_id"].(float64))
  6806. additionalCharge.ItemId = item_id
  6807. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6808. if config.ID > 0 {
  6809. if len(config.Code) > 0 {
  6810. additionalCharge.MedListCodg = config.Code
  6811. }
  6812. }
  6813. }
  6814. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6815. // price := int64(json["price"].(float64))
  6816. // formatInt_price := strconv.FormatInt(price, 10)
  6817. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6818. // additionalCharge.Price = float_price
  6819. // }
  6820. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6821. // price := int64(json["price"].(float64))
  6822. // formatInt_price := strconv.FormatInt(price, 10)
  6823. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6824. // additionalCharge.Price = float_price
  6825. //}
  6826. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6827. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6828. additionalCharge.Price = price
  6829. }
  6830. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6831. count, _ := json["count"].(string)
  6832. counts, _ := strconv.ParseInt(count, 10, 64)
  6833. additionalCharge.Count = counts
  6834. }
  6835. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6836. item_name, _ := json["item_name"].(string)
  6837. additionalCharge.ItemName = item_name
  6838. }
  6839. return 0
  6840. }
  6841. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6842. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6843. utils.ErrorLog("drug_name")
  6844. return enums.ErrorCodeParamWrong
  6845. }
  6846. adviceName, _ := json["drug_name"].(string)
  6847. if len(adviceName) == 0 {
  6848. utils.ErrorLog("len(advice_name) == 0")
  6849. return enums.ErrorCodeParamWrong
  6850. }
  6851. advice.AdviceName = adviceName
  6852. adviceDesc, _ := json["advice_desc"].(string)
  6853. advice.AdviceDesc = adviceDesc
  6854. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6855. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6856. advice.DrugSpec = drugSpec
  6857. }
  6858. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6859. remark, _ := json["remark"].(string)
  6860. advice.Remark = remark
  6861. }
  6862. if json["id"] == nil {
  6863. advice.DrugId = 0
  6864. } else {
  6865. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6866. drug_id := int64(json["id"].(float64))
  6867. advice.DrugId = drug_id
  6868. }
  6869. }
  6870. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6871. groupno := int64(json["groupno"].(float64))
  6872. advice.Groupno = groupno
  6873. }
  6874. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6875. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6876. advice.IsSelfDrug = is_self_drug
  6877. }
  6878. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6879. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6880. drug_way_count, _ := json["drug_way_count"].(string)
  6881. advice.DrugWayCount = drug_way_count
  6882. }
  6883. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6884. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6885. advice.HospApprFlag = hosp_appr_flag
  6886. }
  6887. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6888. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6889. advice.PrescribingNumber = prescribingNumber
  6890. }
  6891. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6892. // frequency_type := int64(json["frequency_type"].(float64))
  6893. // advice.FrequencyType = frequency_type
  6894. //}
  6895. //
  6896. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6897. // day_count := int64(json["day_count"].(float64))
  6898. // advice.DayCount = day_count
  6899. //}
  6900. //
  6901. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6902. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6903. // week_day, _ := json["week_day"].(string)
  6904. // advice.WeekDay = week_day
  6905. //}
  6906. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6907. drugSpecUnit, _ := json["min_unit"].(string)
  6908. advice.DrugSpecUnit = drugSpecUnit
  6909. }
  6910. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6911. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6912. advice.SingleDose = singleDose
  6913. }
  6914. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6915. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6916. advice.SingleDoseUnit = singleDoseUnit
  6917. }
  6918. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6919. deliveryWay, _ := json["delivery_way"].(string)
  6920. advice.DeliveryWay = deliveryWay
  6921. }
  6922. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6923. executionFrequency, _ := json["execution_frequency"].(string)
  6924. advice.ExecutionFrequency = executionFrequency
  6925. }
  6926. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6927. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6928. advice.Price = price
  6929. }
  6930. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6931. med_list_codg, _ := json["medical_insurance_number"].(string)
  6932. advice.MedListCodg = med_list_codg
  6933. }
  6934. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6935. day := int64(json["day"].(float64))
  6936. advice.Day = day
  6937. }
  6938. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6939. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6940. advice.PrescribingNumberUnit = prescribingNumberUnit
  6941. }
  6942. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6943. advice_id := int64(json["advice_id"].(float64))
  6944. advice.ID = advice_id
  6945. if advice.ID > 0 {
  6946. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6947. if err == nil {
  6948. if hisAdvice.ID > 0 {
  6949. advice.ExecutionTime = hisAdvice.ExecutionTime
  6950. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6951. advice.ExecutionState = hisAdvice.ExecutionState
  6952. advice.CheckTime = hisAdvice.CheckTime
  6953. advice.Checker = hisAdvice.Checker
  6954. advice.CheckState = hisAdvice.CheckState
  6955. advice.StartTime = hisAdvice.StartTime
  6956. advice.HospApprFlag = hisAdvice.HospApprFlag
  6957. advice.IsMedicine = hisAdvice.IsMedicine
  6958. if hisAdvice.UserOrgId == 10028 {
  6959. 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 {
  6960. advice.ExecutionTime = 0
  6961. advice.ExecutionStaff = 0
  6962. advice.ExecutionState = 2
  6963. advice.CheckTime = 0
  6964. advice.Checker = 0
  6965. advice.CheckState = 2
  6966. }
  6967. } else {
  6968. 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 {
  6969. advice.ExecutionTime = 0
  6970. advice.ExecutionStaff = 0
  6971. advice.ExecutionState = 2
  6972. advice.CheckTime = 0
  6973. advice.Checker = 0
  6974. advice.CheckState = 2
  6975. advice.UpdatedTime = time.Now().Unix()
  6976. }
  6977. }
  6978. //advice.Groupno = hisAdvice.Groupno
  6979. }
  6980. }
  6981. }
  6982. }
  6983. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6984. //
  6985. //if drugStockConfig.IsOpen == 1 {
  6986. //
  6987. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6988. // if advice.ID == 0 { //医嘱不存在
  6989. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6990. // drug.Total = drug.Total - advice.PrescribingNumber
  6991. // service.UpdateBaseDrugLib(&drug)
  6992. //
  6993. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6994. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6995. // drug.Total = drug.Total - num
  6996. // service.UpdateBaseDrugLib(&drug)
  6997. // }
  6998. //
  6999. // } else if advice.ID > 0 { //医嘱存在
  7000. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7001. // var num float64
  7002. //
  7003. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7004. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7005. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7006. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7007. // drug.Total = drug.Total + num
  7008. // service.UpdateBaseDrugLib(&drug)
  7009. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7010. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7011. // drug.Total = drug.Total - num
  7012. // service.UpdateBaseDrugLib(&drug)
  7013. // }
  7014. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7015. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7016. // if num2 > advice.PrescribingNumber {
  7017. // num = num2 - advice.PrescribingNumber
  7018. // drug.Total = drug.Total + num
  7019. // service.UpdateBaseDrugLib(&drug)
  7020. // } else if num2 < advice.PrescribingNumber {
  7021. // num = advice.PrescribingNumber - num2
  7022. // drug.Total = drug.Total - num
  7023. // service.UpdateBaseDrugLib(&drug)
  7024. // }
  7025. //
  7026. // }
  7027. //
  7028. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7029. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7030. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7031. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7032. // if num1 > num2 {
  7033. // num = num1 - num2
  7034. // drug.Total = drug.Total + num
  7035. // service.UpdateBaseDrugLib(&drug)
  7036. // } else if num1 < num2 {
  7037. // num = num2 - num1
  7038. // drug.Total = drug.Total - num
  7039. // service.UpdateBaseDrugLib(&drug)
  7040. // }
  7041. //
  7042. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7043. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7044. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7045. // if hisAdvice.PrescribingNumber > num2 {
  7046. // num = hisAdvice.PrescribingNumber - num2
  7047. // drug.Total = drug.Total + num
  7048. // service.UpdateBaseDrugLib(&drug)
  7049. // } else if num2 < advice.PrescribingNumber {
  7050. // num = num2 - hisAdvice.PrescribingNumber
  7051. // drug.Total = drug.Total - num
  7052. // service.UpdateBaseDrugLib(&drug)
  7053. // }
  7054. //
  7055. // }
  7056. // }
  7057. // }
  7058. //}
  7059. //
  7060. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7061. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7062. // advice.ExecutionTime = execution_time
  7063. //}
  7064. //
  7065. //
  7066. //
  7067. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7068. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7069. // advice.ExecutionStaff = execution_staff
  7070. //}
  7071. //
  7072. //
  7073. //
  7074. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7075. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7076. // advice.ExecutionState = execution_state
  7077. //}
  7078. //
  7079. //
  7080. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7081. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7082. // advice.CheckTime = check_time
  7083. //}
  7084. //
  7085. //
  7086. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7087. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7088. // advice.CheckState = check_state
  7089. //}
  7090. //
  7091. //
  7092. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7093. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7094. // advice.Checker = checker
  7095. //}
  7096. //
  7097. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7098. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7099. // advice.StartTime = start_time
  7100. //}
  7101. return 0
  7102. }
  7103. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7104. project.ExecutionStaff = 0
  7105. project.ExecutionState = 2
  7106. project.ExecutionTime = 0
  7107. project.Checker = 0
  7108. project.CheckState = 2
  7109. project.CheckTime = 0
  7110. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7111. id := int64(json["id"].(float64))
  7112. project.ID = id
  7113. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7114. project.ExecutionStaff = temp_project.ExecutionStaff
  7115. project.ExecutionState = temp_project.ExecutionState
  7116. project.ExecutionTime = temp_project.ExecutionTime
  7117. project.Checker = temp_project.Checker
  7118. project.CheckState = temp_project.CheckState
  7119. project.CheckTime = temp_project.CheckTime
  7120. project.TeamId = temp_project.TeamId
  7121. }
  7122. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7123. types := int64(json["type"].(float64))
  7124. project.Type = types
  7125. }
  7126. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7127. project_id := int64(json["project_id"].(float64))
  7128. project.ProjectId = project_id
  7129. }
  7130. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7131. team_id := int64(json["team_id"].(float64))
  7132. project.TeamId = team_id
  7133. }
  7134. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7135. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7136. project.Price = price
  7137. }
  7138. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7139. total, _ := json["total"].(string)
  7140. //totals, _ := strconv.ParseInt(total, 10, 64)
  7141. project.Count = total
  7142. }
  7143. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7144. medical_code, _ := json["medical_code"].(string)
  7145. project.MedListCodg = medical_code
  7146. }
  7147. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7148. single_dose, _ := json["single_dose"].(string)
  7149. project.SingleDose = single_dose
  7150. }
  7151. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7152. delivery_way, _ := json["delivery_way"].(string)
  7153. project.DeliveryWay = delivery_way
  7154. }
  7155. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7156. execution_frequency, _ := json["execution_frequency"].(string)
  7157. project.ExecutionFrequency = execution_frequency
  7158. }
  7159. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7160. remark, _ := json["remark"].(string)
  7161. project.Remark = remark
  7162. }
  7163. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7164. day, _ := json["number_days"].(string)
  7165. project.Day = day
  7166. }
  7167. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7168. unit, _ := json["unit"].(string)
  7169. project.Unit = unit
  7170. }
  7171. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7172. // frequency_type := int64(json["frequency_type"].(float64))
  7173. // project.FrequencyType = frequency_type
  7174. //}
  7175. //
  7176. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7177. // day_count := int64(json["day_count"].(float64))
  7178. // project.DayCount = day_count
  7179. //}
  7180. //
  7181. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7182. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7183. // week_day, _ := json["week_day"].(string)
  7184. // project.WeekDay = week_day
  7185. //}
  7186. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7187. //
  7188. //if project.ID == 0 {
  7189. // if stockConfig.IsOpen == 1 {
  7190. // if project.Type == 3 {
  7191. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7192. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7193. // good.Total = good.Total - f_count
  7194. // service.UpdateGoodInfo(&good)
  7195. // }
  7196. // }
  7197. //
  7198. //} else {
  7199. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7200. //
  7201. // if stockConfig.IsOpen == 1 {
  7202. // if project.Type == 3 {
  7203. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7204. // if project.Count < temp_project.Count {
  7205. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7206. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7207. //
  7208. // other_count := f_count_two - f_count_one
  7209. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7210. // good.Total = good.Total + other_count_two
  7211. // service.UpdateGoodInfo(&good)
  7212. // } else if project.Count > temp_project.Count {
  7213. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7214. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7215. //
  7216. // other_count := f_count_one - f_count_two
  7217. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7218. // good.Total = good.Total - other_count_two
  7219. // service.UpdateGoodInfo(&good)
  7220. // }
  7221. //
  7222. // }
  7223. // }
  7224. //
  7225. //}
  7226. return 0
  7227. }
  7228. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7229. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7230. utils.ErrorLog("drug_name")
  7231. return enums.ErrorCodeParamWrong
  7232. }
  7233. adviceName, _ := json["drug_name"].(string)
  7234. if len(adviceName) == 0 {
  7235. utils.ErrorLog("len(advice_name) == 0")
  7236. return enums.ErrorCodeParamWrong
  7237. }
  7238. advice.AdviceName = adviceName
  7239. adviceDesc, _ := json["advice_desc"].(string)
  7240. advice.AdviceDesc = adviceDesc
  7241. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7242. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7243. advice.DrugSpec = drugSpec
  7244. }
  7245. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7246. remark, _ := json["remark"].(string)
  7247. advice.Remark = remark
  7248. }
  7249. if json["id"] == nil {
  7250. advice.DrugId = 0
  7251. } else {
  7252. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7253. drug_id := int64(json["id"].(float64))
  7254. advice.DrugId = drug_id
  7255. }
  7256. }
  7257. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7258. groupno := int64(json["groupno"].(float64))
  7259. advice.Groupno = groupno
  7260. }
  7261. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7262. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7263. advice.IsSelfDrug = is_self_drug
  7264. }
  7265. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7266. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7267. drug_way_count, _ := json["drug_way_count"].(string)
  7268. advice.DrugWayCount = drug_way_count
  7269. }
  7270. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7271. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7272. advice.HospApprFlag = hosp_appr_flag
  7273. }
  7274. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7275. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7276. advice.PrescribingNumber = prescribingNumber
  7277. }
  7278. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7279. // frequency_type := int64(json["frequency_type"].(float64))
  7280. // advice.FrequencyType = frequency_type
  7281. //}
  7282. //
  7283. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7284. // day_count := int64(json["day_count"].(float64))
  7285. // advice.DayCount = day_count
  7286. //}
  7287. //
  7288. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7289. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7290. // week_day, _ := json["week_day"].(string)
  7291. // advice.WeekDay = week_day
  7292. //}
  7293. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7294. drugSpecUnit, _ := json["min_unit"].(string)
  7295. advice.DrugSpecUnit = drugSpecUnit
  7296. }
  7297. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7298. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7299. advice.SingleDose = singleDose
  7300. }
  7301. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7302. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7303. advice.SingleDoseUnit = singleDoseUnit
  7304. }
  7305. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7306. deliveryWay, _ := json["delivery_way"].(string)
  7307. advice.DeliveryWay = deliveryWay
  7308. }
  7309. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7310. executionFrequency, _ := json["execution_frequency"].(string)
  7311. advice.ExecutionFrequency = executionFrequency
  7312. }
  7313. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7314. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7315. advice.Price = price
  7316. }
  7317. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7318. med_list_codg, _ := json["medical_insurance_number"].(string)
  7319. advice.MedListCodg = med_list_codg
  7320. }
  7321. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7322. day := int64(json["day"].(float64))
  7323. advice.Day = day
  7324. }
  7325. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7326. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7327. advice.PrescribingNumberUnit = prescribingNumberUnit
  7328. }
  7329. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7330. advice_id := int64(json["advice_id"].(float64))
  7331. advice.ID = advice_id
  7332. if advice.ID > 0 {
  7333. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7334. if err == nil {
  7335. if hisAdvice.ID > 0 {
  7336. advice.ExecutionTime = hisAdvice.ExecutionTime
  7337. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7338. advice.ExecutionState = hisAdvice.ExecutionState
  7339. advice.CheckTime = hisAdvice.CheckTime
  7340. advice.Checker = hisAdvice.Checker
  7341. advice.CheckState = hisAdvice.CheckState
  7342. advice.StartTime = hisAdvice.StartTime
  7343. advice.HospApprFlag = hisAdvice.HospApprFlag
  7344. advice.IsMedicine = hisAdvice.IsMedicine
  7345. if hisAdvice.UserOrgId == 10028 {
  7346. 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 {
  7347. advice.ExecutionTime = 0
  7348. advice.ExecutionStaff = 0
  7349. advice.ExecutionState = 2
  7350. advice.CheckTime = 0
  7351. advice.Checker = 0
  7352. advice.CheckState = 2
  7353. }
  7354. } else {
  7355. 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 {
  7356. advice.ExecutionTime = 0
  7357. advice.ExecutionStaff = 0
  7358. advice.ExecutionState = 2
  7359. advice.CheckTime = 0
  7360. advice.Checker = 0
  7361. advice.CheckState = 2
  7362. //advice.UpdatedTime = time.Now().Unix()
  7363. advice.CreatedTime = hisAdvice.CreatedTime
  7364. advice.UpdatedTime = time.Now().Unix()
  7365. } else {
  7366. advice.CreatedTime = hisAdvice.CreatedTime
  7367. advice.UpdatedTime = hisAdvice.UpdatedTime
  7368. }
  7369. }
  7370. //advice.Groupno = hisAdvice.Groupno
  7371. } else {
  7372. advice.IsMedicine = 0
  7373. ctime := time.Now().Unix()
  7374. advice.CreatedTime = ctime
  7375. advice.UpdatedTime = ctime
  7376. }
  7377. }
  7378. } else {
  7379. advice.IsMedicine = 0
  7380. ctime := time.Now().Unix()
  7381. advice.CreatedTime = ctime
  7382. advice.UpdatedTime = ctime
  7383. }
  7384. }
  7385. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7386. //
  7387. //if drugStockConfig.IsOpen == 1 {
  7388. //
  7389. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7390. // if advice.ID == 0 { //医嘱不存在
  7391. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7392. // drug.Total = drug.Total - advice.PrescribingNumber
  7393. // service.UpdateBaseDrugLib(&drug)
  7394. //
  7395. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7396. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7397. // drug.Total = drug.Total - num
  7398. // service.UpdateBaseDrugLib(&drug)
  7399. // }
  7400. //
  7401. // } else if advice.ID > 0 { //医嘱存在
  7402. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7403. // var num float64
  7404. //
  7405. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7406. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7407. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7408. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7409. // drug.Total = drug.Total + num
  7410. // service.UpdateBaseDrugLib(&drug)
  7411. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7412. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7413. // drug.Total = drug.Total - num
  7414. // service.UpdateBaseDrugLib(&drug)
  7415. // }
  7416. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7417. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7418. // if num2 > advice.PrescribingNumber {
  7419. // num = num2 - advice.PrescribingNumber
  7420. // drug.Total = drug.Total + num
  7421. // service.UpdateBaseDrugLib(&drug)
  7422. // } else if num2 < advice.PrescribingNumber {
  7423. // num = advice.PrescribingNumber - num2
  7424. // drug.Total = drug.Total - num
  7425. // service.UpdateBaseDrugLib(&drug)
  7426. // }
  7427. //
  7428. // }
  7429. //
  7430. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7431. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7432. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7433. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7434. // if num1 > num2 {
  7435. // num = num1 - num2
  7436. // drug.Total = drug.Total + num
  7437. // service.UpdateBaseDrugLib(&drug)
  7438. // } else if num1 < num2 {
  7439. // num = num2 - num1
  7440. // drug.Total = drug.Total - num
  7441. // service.UpdateBaseDrugLib(&drug)
  7442. // }
  7443. //
  7444. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7445. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7446. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7447. // if hisAdvice.PrescribingNumber > num2 {
  7448. // num = hisAdvice.PrescribingNumber - num2
  7449. // drug.Total = drug.Total + num
  7450. // service.UpdateBaseDrugLib(&drug)
  7451. // } else if num2 < advice.PrescribingNumber {
  7452. // num = num2 - hisAdvice.PrescribingNumber
  7453. // drug.Total = drug.Total - num
  7454. // service.UpdateBaseDrugLib(&drug)
  7455. // }
  7456. //
  7457. // }
  7458. // }
  7459. // }
  7460. //}
  7461. //
  7462. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7463. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7464. // advice.ExecutionTime = execution_time
  7465. //}
  7466. //
  7467. //
  7468. //
  7469. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7470. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7471. // advice.ExecutionStaff = execution_staff
  7472. //}
  7473. //
  7474. //
  7475. //
  7476. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7477. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7478. // advice.ExecutionState = execution_state
  7479. //}
  7480. //
  7481. //
  7482. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7483. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7484. // advice.CheckTime = check_time
  7485. //}
  7486. //
  7487. //
  7488. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7489. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7490. // advice.CheckState = check_state
  7491. //}
  7492. //
  7493. //
  7494. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7495. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7496. // advice.Checker = checker
  7497. //}
  7498. //
  7499. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7500. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7501. // advice.StartTime = start_time
  7502. //}
  7503. return 0
  7504. }
  7505. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7506. project.ExecutionStaff = 0
  7507. project.ExecutionState = 2
  7508. project.ExecutionTime = 0
  7509. project.Checker = 0
  7510. project.CheckState = 2
  7511. project.CheckTime = 0
  7512. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7513. id := int64(json["id"].(float64))
  7514. project.ID = id
  7515. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7516. project.ExecutionStaff = temp_project.ExecutionStaff
  7517. project.ExecutionState = temp_project.ExecutionState
  7518. project.ExecutionTime = temp_project.ExecutionTime
  7519. project.Checker = temp_project.Checker
  7520. project.CheckState = temp_project.CheckState
  7521. project.CheckTime = temp_project.CheckTime
  7522. project.TeamId = temp_project.TeamId
  7523. }
  7524. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7525. types := int64(json["type"].(float64))
  7526. project.Type = types
  7527. }
  7528. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7529. project_id := int64(json["project_id"].(float64))
  7530. project.ProjectId = project_id
  7531. }
  7532. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7533. team_id := int64(json["team_id"].(float64))
  7534. project.TeamId = team_id
  7535. }
  7536. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7537. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7538. project.Price = price
  7539. }
  7540. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7541. total, _ := json["total"].(string)
  7542. //totals, _ := strconv.ParseInt(total, 10, 64)
  7543. project.Count = total
  7544. }
  7545. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7546. medical_code, _ := json["medical_code"].(string)
  7547. project.MedListCodg = medical_code
  7548. }
  7549. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7550. single_dose, _ := json["single_dose"].(string)
  7551. project.SingleDose = single_dose
  7552. }
  7553. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7554. delivery_way, _ := json["delivery_way"].(string)
  7555. project.DeliveryWay = delivery_way
  7556. }
  7557. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7558. execution_frequency, _ := json["execution_frequency"].(string)
  7559. project.ExecutionFrequency = execution_frequency
  7560. }
  7561. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7562. remark, _ := json["remark"].(string)
  7563. project.Remark = remark
  7564. }
  7565. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7566. day, _ := json["number_days"].(string)
  7567. project.Day = day
  7568. }
  7569. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7570. unit, _ := json["unit"].(string)
  7571. project.Unit = unit
  7572. }
  7573. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7574. // frequency_type := int64(json["frequency_type"].(float64))
  7575. // project.FrequencyType = frequency_type
  7576. //}
  7577. //
  7578. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7579. // day_count := int64(json["day_count"].(float64))
  7580. // project.DayCount = day_count
  7581. //}
  7582. //
  7583. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7584. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7585. // week_day, _ := json["week_day"].(string)
  7586. // project.WeekDay = week_day
  7587. //}
  7588. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7589. //
  7590. //if project.ID == 0 {
  7591. // if stockConfig.IsOpen == 1 {
  7592. // if project.Type == 3 {
  7593. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7594. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7595. // good.Total = good.Total - f_count
  7596. // service.UpdateGoodInfo(&good)
  7597. // }
  7598. // }
  7599. //
  7600. //} else {
  7601. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7602. //
  7603. // if stockConfig.IsOpen == 1 {
  7604. // if project.Type == 3 {
  7605. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7606. // if project.Count < temp_project.Count {
  7607. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7608. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7609. //
  7610. // other_count := f_count_two - f_count_one
  7611. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7612. // good.Total = good.Total + other_count_two
  7613. // service.UpdateGoodInfo(&good)
  7614. // } else if project.Count > temp_project.Count {
  7615. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7616. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7617. //
  7618. // other_count := f_count_one - f_count_two
  7619. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7620. // good.Total = good.Total - other_count_two
  7621. // service.UpdateGoodInfo(&good)
  7622. // }
  7623. //
  7624. // }
  7625. // }
  7626. //
  7627. //}
  7628. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7629. id := int64(json["id"].(float64))
  7630. if id > 0 {
  7631. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7632. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7633. fmt.Println("666666")
  7634. project.Mtime = time.Now().Unix()
  7635. project.Ctime = temp_project.Ctime
  7636. } else {
  7637. project.Mtime = temp_project.Mtime
  7638. project.Ctime = temp_project.Ctime
  7639. }
  7640. } else {
  7641. ctime := time.Now().Unix()
  7642. project.Mtime = ctime
  7643. project.Ctime = ctime
  7644. }
  7645. }
  7646. return 0
  7647. }
  7648. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7649. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7650. id := int64(json["id"].(float64))
  7651. additionalCharge.ID = id
  7652. }
  7653. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7654. item_id := int64(json["item_id"].(float64))
  7655. additionalCharge.ItemId = item_id
  7656. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7657. if config.ID > 0 {
  7658. if len(config.Code) > 0 {
  7659. additionalCharge.MedListCodg = config.Code
  7660. }
  7661. }
  7662. }
  7663. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7664. // price := int64(json["price"].(float64))
  7665. // formatInt_price := strconv.FormatInt(price, 10)
  7666. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7667. // additionalCharge.Price = float_price
  7668. // }
  7669. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7670. // price := int64(json["price"].(float64))
  7671. // formatInt_price := strconv.FormatInt(price, 10)
  7672. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7673. // additionalCharge.Price = float_price
  7674. //}
  7675. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7676. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7677. additionalCharge.Price = price
  7678. }
  7679. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7680. count, _ := json["count"].(string)
  7681. counts, _ := strconv.ParseInt(count, 10, 64)
  7682. additionalCharge.Count = counts
  7683. }
  7684. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7685. item_name, _ := json["item_name"].(string)
  7686. additionalCharge.ItemName = item_name
  7687. }
  7688. return 0
  7689. }
  7690. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7691. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7692. utils.ErrorLog("drug_name")
  7693. return enums.ErrorCodeParamWrong
  7694. }
  7695. adviceName, _ := json["drug_name"].(string)
  7696. if len(adviceName) == 0 {
  7697. utils.ErrorLog("len(advice_name) == 0")
  7698. return enums.ErrorCodeParamWrong
  7699. }
  7700. advice.AdviceName = adviceName
  7701. adviceDesc, _ := json["advice_desc"].(string)
  7702. advice.AdviceDesc = adviceDesc
  7703. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7704. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7705. advice.DrugSpec = drugSpec
  7706. }
  7707. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7708. remark, _ := json["remark"].(string)
  7709. advice.Remark = remark
  7710. }
  7711. if json["id"] == nil {
  7712. advice.DrugId = 0
  7713. } else {
  7714. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7715. drug_id := int64(json["id"].(float64))
  7716. advice.DrugId = drug_id
  7717. }
  7718. }
  7719. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7720. groupno := int64(json["groupno"].(float64))
  7721. advice.Groupno = groupno
  7722. }
  7723. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7724. drugSpecUnit, _ := json["min_unit"].(string)
  7725. advice.DrugSpecUnit = drugSpecUnit
  7726. }
  7727. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7728. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7729. advice.SingleDose = singleDose
  7730. }
  7731. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7732. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7733. advice.SingleDoseUnit = singleDoseUnit
  7734. }
  7735. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7736. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7737. advice.PrescribingNumber = prescribingNumber
  7738. }
  7739. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7740. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7741. advice.PrescribingNumberUnit = prescribingNumberUnit
  7742. }
  7743. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7744. deliveryWay, _ := json["delivery_way"].(string)
  7745. advice.DeliveryWay = deliveryWay
  7746. }
  7747. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7748. executionFrequency, _ := json["execution_frequency"].(string)
  7749. advice.ExecutionFrequency = executionFrequency
  7750. }
  7751. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7752. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7753. advice.Price = price
  7754. }
  7755. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7756. med_list_codg, _ := json["medical_insurance_number"].(string)
  7757. advice.MedListCodg = med_list_codg
  7758. }
  7759. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7760. day := int64(json["day"].(float64))
  7761. advice.Day = day
  7762. }
  7763. advice.FrequencyType = 1
  7764. return 0
  7765. }
  7766. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7767. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7768. types := int64(json["type"].(float64))
  7769. project.Type = types
  7770. }
  7771. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7772. project_id := int64(json["project_id"].(float64))
  7773. project.ProjectId = project_id
  7774. }
  7775. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7776. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7777. project.Price = price
  7778. }
  7779. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7780. total, _ := json["total"].(string)
  7781. //totals, _ := strconv.ParseInt(total, 10, 64)
  7782. project.Count = total
  7783. }
  7784. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7785. medical_code, _ := json["medical_code"].(string)
  7786. project.MedListCodg = medical_code
  7787. }
  7788. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7789. single_dose, _ := json["single_dose"].(string)
  7790. project.SingleDose = single_dose
  7791. }
  7792. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7793. delivery_way, _ := json["delivery_way"].(string)
  7794. project.DeliveryWay = delivery_way
  7795. }
  7796. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7797. execution_frequency, _ := json["execution_frequency"].(string)
  7798. project.ExecutionFrequency = execution_frequency
  7799. }
  7800. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7801. remark, _ := json["remark"].(string)
  7802. project.Remark = remark
  7803. }
  7804. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7805. day, _ := json["number_days"].(string)
  7806. project.Day = day
  7807. }
  7808. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7809. unit, _ := json["unit"].(string)
  7810. project.Unit = unit
  7811. }
  7812. project.FrequencyType = 1
  7813. return 0
  7814. }
  7815. func (c *HisApiController) GetHisOrderListTwo() {
  7816. start_time := c.GetString("start_time")
  7817. end_time := c.GetString("end_time")
  7818. timeLayout := "2006-01-02"
  7819. loc, _ := time.LoadLocation("Local")
  7820. var startTime int64
  7821. if len(start_time) > 0 {
  7822. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7823. if err != nil {
  7824. //fmt.Println(err)
  7825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7826. return
  7827. }
  7828. startTime = theTime.Unix()
  7829. }
  7830. var endTime int64
  7831. if len(end_time) > 0 {
  7832. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7833. if err != nil {
  7834. utils.ErrorLog(err.Error())
  7835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7836. return
  7837. }
  7838. endTime = theTime.Unix()
  7839. }
  7840. adminUser := c.GetAdminUserInfo()
  7841. org_id := adminUser.CurrentOrgId
  7842. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7843. if err == nil {
  7844. c.ServeSuccessJSON(map[string]interface{}{
  7845. "order2": order,
  7846. })
  7847. } else {
  7848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7849. return
  7850. }
  7851. }
  7852. func (c *HisApiController) GetHisOrderList() {
  7853. page, _ := c.GetInt64("page", -1)
  7854. limit, _ := c.GetInt64("limit", -1)
  7855. start_time := c.GetString("start_time")
  7856. end_time := c.GetString("end_time")
  7857. types, _ := c.GetInt64("type", 0)
  7858. keywords := c.GetString("keywords")
  7859. p_type, _ := c.GetInt64("p_type", 0)
  7860. sort_type, _ := c.GetInt64("sort_type", 0)
  7861. charge_type, _ := c.GetInt64("charge_type", 0)
  7862. sch_type, _ := c.GetInt64("sch_type", 0)
  7863. zone_type, _ := c.GetInt64("zone_type", 0)
  7864. med_type, _ := c.GetInt64("med_type", 0)
  7865. timeLayout := "2006-01-02"
  7866. loc, _ := time.LoadLocation("Local")
  7867. var startTime int64
  7868. if len(start_time) > 0 {
  7869. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7870. if err != nil {
  7871. //fmt.Println(err)
  7872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7873. return
  7874. }
  7875. startTime = theTime.Unix()
  7876. }
  7877. var endTime int64
  7878. if len(end_time) > 0 {
  7879. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7880. if err != nil {
  7881. utils.ErrorLog(err.Error())
  7882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7883. return
  7884. }
  7885. endTime = theTime.Unix()
  7886. }
  7887. adminUser := c.GetAdminUserInfo()
  7888. org_id := adminUser.CurrentOrgId
  7889. 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)
  7890. for _, item := range order {
  7891. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7892. item.DoctorName = info.Doctor
  7893. item.DepartmentName = info.XtHisDepartment.Name
  7894. }
  7895. if err == nil {
  7896. c.ServeSuccessJSON(map[string]interface{}{
  7897. "order": order,
  7898. "total": total,
  7899. })
  7900. } else {
  7901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7902. return
  7903. }
  7904. }
  7905. func (c *HisApiController) GetHisOrder() {
  7906. patient_id, _ := c.GetInt64("patient_id", 0)
  7907. number := c.GetString("number")
  7908. adminInfo := c.GetAdminUserInfo()
  7909. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7910. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7911. if err == nil {
  7912. c.ServeSuccessJSON(map[string]interface{}{
  7913. "order": order,
  7914. "prescription": prescriptions,
  7915. })
  7916. } else {
  7917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7918. return
  7919. }
  7920. }
  7921. func (c *HisApiController) GetHisPrescriptionList() {
  7922. record_date := c.GetString("record_date")
  7923. keywords := c.GetString("keywords")
  7924. page, _ := c.GetInt64("page")
  7925. limit, _ := c.GetInt64("limit")
  7926. sch_type, _ := c.GetInt64("sch_type")
  7927. timeLayout := "2006-01-02"
  7928. loc, _ := time.LoadLocation("Local")
  7929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7930. if err != nil {
  7931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7932. return
  7933. }
  7934. recordDateTime := theTime.Unix()
  7935. adminInfo := c.GetAdminUserInfo()
  7936. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7937. //adminInfo := c.GetAdminUserInfo()
  7938. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7939. //fmt.Println(prescriptionOrder)
  7940. if err == nil {
  7941. c.ServeSuccessJSON(map[string]interface{}{
  7942. "order": prescriptionOrder,
  7943. "total": total,
  7944. })
  7945. } else {
  7946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7947. return
  7948. }
  7949. }
  7950. func (c *HisApiController) GetHisPrescriptionInfo() {
  7951. id, _ := c.GetInt64("id")
  7952. adminInfo := c.GetAdminUserInfo()
  7953. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7954. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7955. if err == nil {
  7956. c.ServeSuccessJSON(map[string]interface{}{
  7957. "order": prescriptionOrder,
  7958. "prescription": prescription,
  7959. })
  7960. } else {
  7961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7962. return
  7963. }
  7964. }
  7965. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7966. adminUser := c.GetAdminUserInfo()
  7967. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7968. c.ServeSuccessJSON(map[string]interface{}{
  7969. "config": config,
  7970. })
  7971. }
  7972. type ResultTwo struct {
  7973. ErrMsg interface{} `json:"err_msg"`
  7974. InfRefmsgid string `json:"inf_refmsgid"`
  7975. Infcode int64 `json:"infcode"`
  7976. Output struct {
  7977. Baseinfo struct {
  7978. Age float64 `json:"age"`
  7979. Brdy string `json:"brdy"`
  7980. Certno string `json:"certno"`
  7981. Gend string `json:"gend"`
  7982. Naty string `json:"naty"`
  7983. PsnCertType string `json:"psn_cert_type"`
  7984. PsnName string `json:"psn_name"`
  7985. PsnNo string `json:"psn_no"`
  7986. } `json:"baseinfo"`
  7987. Idetinfo []interface{} `json:"idetinfo"`
  7988. Iinfo []struct {
  7989. Balc float64 `json:"balc"`
  7990. CvlservFlag string `json:"cvlserv_flag"`
  7991. EmpName string `json:"emp_name"`
  7992. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7993. Insutype string `json:"insutype"`
  7994. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7995. PausInsuDate interface{} `json:"paus_insu_date"`
  7996. PsnInsuDate string `json:"psn_insu_date"`
  7997. PsnInsuStas string `json:"psn_insu_stas"`
  7998. PsnType string `json:"psn_type"`
  7999. } `json:"insuinfo"`
  8000. } `json:"output"`
  8001. RefmsgTime string `json:"refmsg_time"`
  8002. RespondTime string `json:"respond_time"`
  8003. Signtype interface{} `json:"signtype"`
  8004. WarnInfo interface{} `json:"warn_info"`
  8005. }
  8006. type ResultThree struct {
  8007. Cainfo interface{} `json:"cainfo"`
  8008. ErrMsg interface{} `json:"err_msg"`
  8009. InfRefmsgid string `json:"inf_refmsgid"`
  8010. Infcode int64 `json:"infcode"`
  8011. Output struct {
  8012. Data struct {
  8013. IptOtpNo string `json:"ipt_otp_no"`
  8014. MdtrtID string `json:"mdtrt_id"`
  8015. PsnNo string `json:"psn_no"`
  8016. } `json:"data"`
  8017. } `json:"output"`
  8018. RefmsgTime string `json:"refmsg_time"`
  8019. RespondTime string `json:"respond_time"`
  8020. Signtype interface{} `json:"signtype"`
  8021. WarnMsg interface{} `json:"warn_msg"`
  8022. }
  8023. type ResultFour struct {
  8024. Cainfo string `json:"cainfo"`
  8025. ErrMsg string `json:"err_msg"`
  8026. InfRefmsgid string `json:"inf_refmsgid"`
  8027. Infcode int64 `json:"infcode"`
  8028. Output struct {
  8029. Result []struct {
  8030. BasMednFlag string `json:"bas_medn_flag"`
  8031. ChldMedcFlag string `json:"chld_medc_flag"`
  8032. ChrgitmLv string `json:"chrgitm_lv"`
  8033. Cnt float64 `json:"cnt"`
  8034. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8035. DrtReimFlag string `json:"drt_reim_flag"`
  8036. FeedetlSn string `json:"feedetl_sn"`
  8037. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8038. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8039. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8040. ListSpItemFlag string `json:"list_sp_item_flag"`
  8041. LmtUsedFlag string `json:"lmt_used_flag"`
  8042. MedChrgitmType string `json:"med_chrgitm_type"`
  8043. Memo string `json:"memo"`
  8044. OverlmtAmt float64 `json:"overlmt_amt"`
  8045. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8046. Pric float64 `json:"pric"`
  8047. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8048. SelfpayProp float64 `json:"selfpay_prop"`
  8049. } `json:"result"`
  8050. } `json:"output"`
  8051. RefmsgTime string `json:"refmsg_time"`
  8052. RespondTime string `json:"respond_time"`
  8053. Signtype string `json:"signtype"`
  8054. WarnMsg string `json:"warn_msg"`
  8055. }
  8056. type ResultFive struct {
  8057. Insutype string `json:"insutype"`
  8058. }
  8059. type ResultSix struct {
  8060. Cainfo interface{} `json:"cainfo"`
  8061. ErrMsg interface{} `json:"err_msg"`
  8062. InfRefmsgid string `json:"inf_refmsgid"`
  8063. Infcode int64 `json:"infcode"`
  8064. Output struct {
  8065. } `json:"output"`
  8066. RefmsgTime string `json:"refmsg_time"`
  8067. RespondTime string `json:"respond_time"`
  8068. Signtype interface{} `json:"signtype"`
  8069. WarnMsg interface{} `json:"warn_msg"`
  8070. }
  8071. type ResultSeven struct {
  8072. Cainfo string `json:"cainfo"`
  8073. ErrMsg string `json:"err_msg"`
  8074. InfRefmsgid string `json:"inf_refmsgid"`
  8075. Infcode int64 `json:"infcode"`
  8076. Output struct {
  8077. Setldetail []interface{} `json:"setldetail"`
  8078. Setlinfo struct {
  8079. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8080. AcctPay float64 `json:"acct_pay"`
  8081. ActPayDedc float64 `json:"act_pay_dedc"`
  8082. Age float64 `json:"age"`
  8083. Balc float64 `json:"balc"`
  8084. Brdy string `json:"brdy"`
  8085. Certno string `json:"certno"`
  8086. ClrOptins string `json:"clr_optins"`
  8087. ClrType string `json:"clr_type"`
  8088. ClrWay string `json:"clr_way"`
  8089. CvlservFlag string `json:"cvlserv_flag"`
  8090. CvlservPay float64 `json:"cvlserv_pay"`
  8091. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8092. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8093. Gend string `json:"gend"`
  8094. HifesPay float64 `json:"hifes_pay"`
  8095. HifmiPay float64 `json:"hifmi_pay"`
  8096. HifobPay float64 `json:"hifob_pay"`
  8097. HifpPay float64 `json:"hifp_pay"`
  8098. HospPartAmt float64 `json:"hosp_part_amt"`
  8099. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8100. Insutype string `json:"insutype"`
  8101. MafPay float64 `json:"maf_pay"`
  8102. MdtrtCertType string `json:"mdtrt_cert_type"`
  8103. MdtrtID string `json:"mdtrt_id"`
  8104. MedType string `json:"med_type"`
  8105. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8106. MedinsSetlID string `json:"medins_setl_id"`
  8107. Naty string `json:"naty"`
  8108. OthPay float64 `json:"oth_pay"`
  8109. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8110. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8111. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8112. PsnCashPay float64 `json:"psn_cash_pay"`
  8113. PsnCertType string `json:"psn_cert_type"`
  8114. PsnName string `json:"psn_name"`
  8115. PsnNo string `json:"psn_no"`
  8116. PsnPartAmt float64 `json:"psn_part_amt"`
  8117. PsnType string `json:"psn_type"`
  8118. SetlID string `json:"setl_id"`
  8119. SetlTime string `json:"setl_time"`
  8120. } `json:"setlinfo"`
  8121. } `json:"output"`
  8122. RefmsgTime string `json:"refmsg_time"`
  8123. RespondTime string `json:"respond_time"`
  8124. Signtype interface{} `json:"signtype"`
  8125. WarnMsg interface{} `json:"warn_msg"`
  8126. }
  8127. type ResultEight struct {
  8128. Cainfo string `json:"cainfo"`
  8129. ErrMsg string `json:"err_msg"`
  8130. InfRefmsgid string `json:"inf_refmsgid"`
  8131. Infcode int64 `json:"infcode"`
  8132. Output struct {
  8133. Stmtinfo struct {
  8134. SetlOptins string `json:"setl_optins"`
  8135. StmtRslt string `json:"stmt_rslt"`
  8136. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8137. } `json:"stmtinfo"`
  8138. } `json:"output"`
  8139. RefmsgTime string `json:"refmsg_time"`
  8140. RespondTime string `json:"respond_time"`
  8141. Signtype interface{} `json:"signtype"`
  8142. WarnMsg interface{} `json:"warn_msg"`
  8143. }
  8144. type ResultNine struct {
  8145. Cainfo string `json:"cainfo"`
  8146. ErrMsg string `json:"err_msg"`
  8147. InfRefmsgid string `json:"inf_refmsgid"`
  8148. Infcode int64 `json:"infcode"`
  8149. Output struct {
  8150. FileQuryNo string `json:"file_qury_no"`
  8151. } `json:"output"`
  8152. RefmsgTime string `json:"refmsg_time"`
  8153. RespondTime string `json:"respond_time"`
  8154. Signtype interface{} `json:"signtype"`
  8155. WarnMsg interface{} `json:"warn_msg"`
  8156. }
  8157. type ResultTen struct {
  8158. Cainfo string `json:"cainfo"`
  8159. ErrMsg string `json:"err_msg"`
  8160. InfRefmsgid string `json:"inf_refmsgid"`
  8161. Infcode int64 `json:"infcode"`
  8162. Output struct {
  8163. DldEndtime string `json:"dld_endtime"`
  8164. FileQuryNo string `json:"file_qury_no"`
  8165. Filename string `json:"filename"`
  8166. } `json:"output"`
  8167. RefmsgTime string `json:"refmsg_time"`
  8168. RespondTime string `json:"respond_time"`
  8169. Signtype interface{} `json:"signtype"`
  8170. WarnMsg interface{} `json:"warn_msg"`
  8171. }
  8172. type ResultEleven struct {
  8173. Cainfo string `json:"cainfo"`
  8174. ErrMsg string `json:"err_msg"`
  8175. InfRefmsgid string `json:"inf_refmsgid"`
  8176. Infcode int64 `json:"infcode"`
  8177. Output struct {
  8178. Setlinfo struct {
  8179. FixmedinsName string `json:"fixmedins_name"`
  8180. FixmedinsCode string `json:"fixmedins_code"`
  8181. PsnNo string `json:"psn_no"`
  8182. PsnName string `json:"psn_name"`
  8183. HifobPay float64 `json:"hifob_pay"`
  8184. Gend string `json:"gend"`
  8185. Brdy string `json:"brdy"`
  8186. PsnCertType string `json:"psn_cert_type"`
  8187. PsnType string `json:"psn_type"`
  8188. EmpName string `json:"emp_name"`
  8189. Certno string `json:"certno"`
  8190. Insutype string `json:"insutype"`
  8191. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8192. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8193. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8194. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8195. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8196. ActPayDedc float64 `json:"act_pay_dedc"`
  8197. HifpPay float64 `json:"hifp_pay"`
  8198. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8199. CvlservPay float64 `json:"cvlserv_pay"`
  8200. HifesPay float64 `json:"hifes_pay"`
  8201. HifmiPay float64 `json:"hifmi_pay"`
  8202. MafPay float64 `json:"maf_pay"`
  8203. OthPay float64 `json:"oth_pay"`
  8204. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8205. PsnPay float64 `json:"psn_pay"`
  8206. AcctPay float64 `json:"acct_pay"`
  8207. CashPayamt float64 `json:"cash_payamt"`
  8208. Balc float64 `json:"balc"`
  8209. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8210. MedinsSetlId string `json:"medins_setl_id"`
  8211. RefdSetlFlag string `json:"refd_setl_flag"`
  8212. SetlTime string `json:"setl_time"`
  8213. MedType string `json:"med_type"`
  8214. } `json:"setlinfo"`
  8215. } `json:"output"`
  8216. RefmsgTime string `json:"refmsg_time"`
  8217. RespondTime string `json:"respond_time"`
  8218. Signtype interface{} `json:"signtype"`
  8219. WarnMsg interface{} `json:"warn_msg"`
  8220. }
  8221. type Custom struct {
  8222. DetItemFeeSumamt string
  8223. Cut string
  8224. FeedetlSn string
  8225. Price string
  8226. MedListCodg string
  8227. Type int64
  8228. AdviceId int64
  8229. ProjectId int64
  8230. ItemId int64
  8231. }
  8232. // 获取个人信息----挂号-----上传就诊信息
  8233. func (c *HisApiController) GetRegisterInfo() {
  8234. id, _ := c.GetInt64("id")
  8235. record_time := c.GetString("record_time")
  8236. settlementValue, _ := c.GetInt64("settlement_value")
  8237. medical_insurance_card := c.GetString("medical_insurance_card")
  8238. name := c.GetString("name")
  8239. id_card_type, _ := c.GetInt64("id_card_type")
  8240. certificates, _ := c.GetInt64("certificates")
  8241. medical_care, _ := c.GetInt64("medical_care")
  8242. birthday := c.GetString("birthday")
  8243. age, _ := c.GetInt64("age")
  8244. id_card := c.GetString("id_card")
  8245. register_type, _ := c.GetInt64("register")
  8246. doctor, _ := c.GetInt64("doctor")
  8247. department, _ := c.GetInt64("department")
  8248. gender, _ := c.GetInt64("sex")
  8249. phone := c.GetString("phone")
  8250. registration_fee, _ := c.GetFloat("registration_fee")
  8251. medical_expenses, _ := c.GetFloat("medical_expenses")
  8252. social_type, _ := c.GetInt64("social_type")
  8253. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8254. diagnosis_ids := c.GetString("diagnosis")
  8255. sick_type, _ := c.GetInt64("sick_type")
  8256. reg_type := c.GetString("p_type")
  8257. timeLayout := "2006-01-02"
  8258. loc, _ := time.LoadLocation("Local")
  8259. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8260. birthUnix := birthdays.Unix()
  8261. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8262. if err != nil {
  8263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8264. return
  8265. }
  8266. recordDateTime := theTime.Unix()
  8267. adminInfo := c.GetAdminUserInfo()
  8268. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8269. if tempPatient.ID == 0 {
  8270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8271. return
  8272. }
  8273. var patient service.Patients
  8274. if id == 0 {
  8275. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8276. } else {
  8277. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8278. }
  8279. if patient.ID == 0 {
  8280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8281. return
  8282. }
  8283. if len(patient.IdCardNo) == 0 {
  8284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8285. return
  8286. }
  8287. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8288. if len(his) >= 1 {
  8289. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8290. if len(his) >= 1 && order.ID == 0 {
  8291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8292. return
  8293. }
  8294. }
  8295. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8296. fmt.Println(timeStr)
  8297. timeArr := strings.Split(timeStr, " ")
  8298. fmt.Println(timeArr)
  8299. timeArrTwo := strings.Split(timeArr[0], "-")
  8300. timeArrThree := strings.Split(timeArr[1], ":")
  8301. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8302. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8303. if len(lists) == 0 {
  8304. var hisPatient models.XtHisPatient
  8305. hisPatient = models.XtHisPatient{
  8306. Name: name,
  8307. Age: age,
  8308. Gender: gender,
  8309. Birthday: birthUnix,
  8310. Phone: phone,
  8311. MedicalTreatmentType: medical_care,
  8312. IdType: certificates,
  8313. IdCardNo: id_card,
  8314. BalanceAccountsType: settlementValue,
  8315. SocialType: social_type,
  8316. MedicalInsuranceNumber: medical_insurance_card,
  8317. RegisterType: register_type,
  8318. RegisterCost: registration_fee,
  8319. TreatmentCost: medical_expenses,
  8320. AdminUserId: adminInfo.AdminUser.Id,
  8321. UserOrgId: adminInfo.CurrentOrgId,
  8322. Status: 1,
  8323. RecordDate: recordDateTime,
  8324. IsReturn: 1,
  8325. PatientId: patient.ID,
  8326. Ctime: time.Now().Unix(),
  8327. Mtime: time.Now().Unix(),
  8328. Number: str,
  8329. IdCardType: id_card_type,
  8330. Departments: department,
  8331. Doctor: doctor,
  8332. PType: reg_type,
  8333. Diagnosis: diagnosis_ids,
  8334. SickType: sick_type,
  8335. }
  8336. service.CreateHisPatient(&hisPatient)
  8337. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8338. c.ServeSuccessJSON(map[string]interface{}{
  8339. "his_info": hisPatient,
  8340. })
  8341. } else {
  8342. //chrgBchno := rand.Intn(1000000) + 10000
  8343. var hisPatient models.XtHisPatient
  8344. hisPatient = models.XtHisPatient{
  8345. Name: name,
  8346. Age: age,
  8347. Gender: gender,
  8348. Birthday: birthUnix,
  8349. Phone: phone,
  8350. MedicalTreatmentType: medical_care,
  8351. IdType: certificates,
  8352. IdCardNo: id_card,
  8353. BalanceAccountsType: settlementValue,
  8354. SocialType: social_type,
  8355. MedicalInsuranceNumber: medical_insurance_card,
  8356. RegisterType: register_type,
  8357. RegisterCost: registration_fee,
  8358. TreatmentCost: medical_expenses,
  8359. AdminUserId: adminInfo.AdminUser.Id,
  8360. UserOrgId: adminInfo.CurrentOrgId,
  8361. Status: 1,
  8362. RecordDate: recordDateTime,
  8363. IsReturn: 1,
  8364. PatientId: patient.ID,
  8365. Ctime: time.Now().Unix(),
  8366. Mtime: time.Now().Unix(),
  8367. Number: str,
  8368. IdCardType: id_card_type,
  8369. Departments: department,
  8370. Doctor: doctor,
  8371. PType: reg_type,
  8372. Diagnosis: diagnosis_ids,
  8373. SickType: sick_type,
  8374. }
  8375. service.CreateHisPatient(&hisPatient)
  8376. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8377. c.ServeSuccessJSON(map[string]interface{}{
  8378. "his_info": hisPatient,
  8379. })
  8380. }
  8381. }
  8382. // 上传明细----结算
  8383. func (c *HisApiController) GetUploadInfo() {
  8384. id, _ := c.GetInt64("id")
  8385. record_time := c.GetString("record_time")
  8386. his_patient_id, _ := c.GetInt64("his_patient_id")
  8387. oth_desc := c.GetString("oth_desc")
  8388. pay_way, _ := c.GetInt64("pay_way")
  8389. pay_ways := c.GetString("pay_ways")
  8390. pay_price, _ := c.GetFloat("pay_price")
  8391. pay_card_no := c.GetString("pay_card_no")
  8392. discount_price, _ := c.GetFloat("discount_price")
  8393. preferential_price, _ := c.GetFloat("preferential_price")
  8394. reality_price, _ := c.GetFloat("reality_price")
  8395. found_price, _ := c.GetFloat("found_price")
  8396. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8397. private_price, _ := c.GetFloat("private_price")
  8398. timeLayout := "2006-01-02"
  8399. loc, _ := time.LoadLocation("Local")
  8400. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8401. fapiao_code := c.GetString("fapiao_code")
  8402. fapiao_number := c.GetString("fapiao_number")
  8403. diagnosis_id := c.GetString("diagnosis")
  8404. sick_type, _ := c.GetInt64("sick_type")
  8405. reg_type, _ := c.GetInt64("p_type")
  8406. order_id, _ := c.GetInt64("order_id")
  8407. cash_pay := c.GetString("cash_pay")
  8408. wechat_pay := c.GetString("wechat_pay")
  8409. ali_pay := c.GetString("ali_pay")
  8410. jifen_pay := c.GetString("jifen_pay")
  8411. band_card_pay := c.GetString("band_card_pay")
  8412. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8413. tmp_decimal := c.GetString("tmp_decimal")
  8414. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8415. var decimal float64 //本次使用的押金
  8416. var errmsg error
  8417. tx := service.XTWriteDB().Begin() //开了事务
  8418. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8419. defer func() {
  8420. if errmsg != nil {
  8421. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8422. tx.Rollback()
  8423. } else {
  8424. tx.Commit()
  8425. }
  8426. }()
  8427. fmt.Println("dec_way", dec_way)
  8428. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8429. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8430. return
  8431. }
  8432. if len(tmp_decimal) > 0 {
  8433. if tmp_decimal[0] == 45 {
  8434. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8435. return
  8436. }
  8437. }
  8438. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8439. fmt.Println(errs)
  8440. decimal = tt
  8441. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8442. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8443. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8444. if err != nil {
  8445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8446. return
  8447. }
  8448. recordDateTime := theTime.Unix()
  8449. adminUser := c.GetAdminUserInfo()
  8450. var prescriptions []*models.HisPrescription
  8451. var prescriptionsOne []*models.HisPrescription
  8452. var start_time int64
  8453. var end_time int64
  8454. ids_str := c.GetString("ids")
  8455. ids_arr := strings.Split(ids_str, ",")
  8456. if tempOrder.ID == 0 {
  8457. if settle_accounts_type == 1 { //日结
  8458. fmt.Println(reg_type)
  8459. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8460. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8461. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8462. } else {
  8463. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8464. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8465. }
  8466. } else { //月结
  8467. start_time_str := c.GetString("start_time")
  8468. end_time_str := c.GetString("end_time")
  8469. timeLayout := "2006-01-02"
  8470. loc, _ := time.LoadLocation("Local")
  8471. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8472. if err != nil {
  8473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8474. return
  8475. }
  8476. recordStartTime := theStartTime.Unix()
  8477. start_time = recordStartTime
  8478. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8479. if err != nil {
  8480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8481. return
  8482. }
  8483. recordEndTime := theEndTime.Unix()
  8484. end_time = recordEndTime
  8485. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8486. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8487. }
  8488. var goods []*models.DialysisBeforePrepareGoods
  8489. var newGoods []*models.NewDialysisBeforePrepareGoods
  8490. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8491. var infos []*models.HisDoctorAdviceInfo
  8492. var infoList []*models.HisDoctorAdviceInfo
  8493. var hisAdvice []*models.HisDoctorAdviceInfo
  8494. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8495. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8496. //判断库存不足
  8497. //结算出库开关
  8498. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8499. if settConfig.IsOpen == 1 {
  8500. //判断库存的地方
  8501. for _, info := range prescriptions {
  8502. if info.Type == 1 {
  8503. infos = append(infos, info.HisDoctorAdviceInfo...)
  8504. }
  8505. if info.Type == 2 {
  8506. for _, sumItem := range info.HisPrescriptionProject {
  8507. if sumItem.Type == 3 {
  8508. var good models.DialysisBeforePrepareGoods
  8509. var newGood models.NewDialysisBeforePrepareGoods
  8510. good.GoodId = sumItem.GoodInfo.ID
  8511. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8512. count, _ := strconv.Atoi(sumItem.Count)
  8513. good.Count = int64(count)
  8514. good.StorehouseId = houseConfig.StorehouseOutInfo
  8515. good.ProjectId = sumItem.ID
  8516. goods = append(goods, &good)
  8517. newGood.GoodId = sumItem.GoodInfo.ID
  8518. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8519. count2, _ := strconv.Atoi(sumItem.Count)
  8520. newGood.Count = int64(count2)
  8521. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8522. newGood.ProjectId = sumItem.ID
  8523. newGoods = append(newGoods, &newGood)
  8524. }
  8525. }
  8526. }
  8527. }
  8528. for _, info := range prescriptionsOne {
  8529. if info.Type == 1 {
  8530. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8531. }
  8532. if info.Type == 2 {
  8533. for _, sumItem := range info.HisPrescriptionProject {
  8534. if sumItem.Type == 3 {
  8535. var newGood models.NewDialysisBeforePrepareGoods
  8536. newGood.GoodId = sumItem.GoodInfo.ID
  8537. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8538. count2, _ := strconv.Atoi(sumItem.Count)
  8539. newGood.Count = int64(count2)
  8540. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8541. newGood.ProjectId = sumItem.ID
  8542. newGoodOne = append(newGoodOne, &newGood)
  8543. }
  8544. }
  8545. }
  8546. }
  8547. //判断
  8548. for _, itemOne := range infos {
  8549. for _, itemTwo := range hisAdvice {
  8550. if itemOne.DrugId == itemTwo.DrugId {
  8551. itemTwo.Child = append(itemTwo.Child, itemOne)
  8552. }
  8553. }
  8554. }
  8555. for _, itemTwo := range hisAdvice {
  8556. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8557. var sum_out_count int64
  8558. for _, itemThree := range itemTwo.Child {
  8559. var prescribing_number int64
  8560. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8561. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8562. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8563. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8564. }
  8565. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8566. prescribing_number = parseIntPrescribingNumber
  8567. }
  8568. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8569. prescribing_number = parseIntPrescribingNumber
  8570. }
  8571. sum_out_count += prescribing_number
  8572. }
  8573. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8574. if sum_out_count > drugStockOut.FlushCount {
  8575. c.ServeSuccessJSON(map[string]interface{}{
  8576. "msg": "2",
  8577. "drug": medical,
  8578. })
  8579. return
  8580. }
  8581. }
  8582. for _, itemOne := range newGoods {
  8583. for _, item := range newGoodOne {
  8584. if itemOne.GoodId == item.GoodId {
  8585. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8586. }
  8587. }
  8588. }
  8589. for _, item := range newGoodOne {
  8590. var sum_out_count_one int64
  8591. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8592. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8593. sum_out_count_one += itemOne.Count
  8594. }
  8595. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8596. fmt.Println("sum_out_count_one", sum_out_count_one)
  8597. fmt.Println("list.FlushCount", list.FlushCount)
  8598. if sum_out_count_one > list.FlushCount {
  8599. c.ServeSuccessJSON(map[string]interface{}{
  8600. "msg": "3",
  8601. "good": good,
  8602. })
  8603. return
  8604. }
  8605. }
  8606. }
  8607. timestamp := time.Now().Unix()
  8608. tempTime := time.Unix(timestamp, 0)
  8609. timeFormat := tempTime.Format("20060102150405")
  8610. chrgBchno := rand.Intn(100000) + 10000
  8611. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8612. strconv.FormatInt(his.PatientId, 10)
  8613. var ids []int64
  8614. for _, item := range prescriptions {
  8615. ids = append(ids, item.ID)
  8616. }
  8617. var total float64
  8618. for _, item := range prescriptions {
  8619. fmt.Println(item)
  8620. if item.Type == 1 { //药品
  8621. for _, subItem := range item.HisDoctorAdviceInfo {
  8622. total = total + (subItem.Price * subItem.PrescribingNumber)
  8623. }
  8624. }
  8625. if item.Type == 2 { //项目
  8626. for _, subItem := range item.HisPrescriptionProject {
  8627. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8628. total = total + (subItem.Price * cnt)
  8629. }
  8630. }
  8631. for _, subItem := range item.HisAdditionalCharge {
  8632. total = total + (subItem.Price * float64(subItem.Count))
  8633. }
  8634. }
  8635. if reg_type == 1111 || reg_type == 1112 {
  8636. reg_type = 11
  8637. }
  8638. tm := time.Unix(time.Now().Unix(), 0)
  8639. allTotal := fmt.Sprintf("%.4f", total)
  8640. totals, _ := strconv.ParseFloat(allTotal, 64)
  8641. order := &models.HisOrder{
  8642. UserOrgId: adminUser.CurrentOrgId,
  8643. HisPatientId: his.ID,
  8644. PatientId: id,
  8645. SettleAccountsDate: recordDateTime,
  8646. Ctime: time.Now().Unix(),
  8647. Mtime: time.Now().Unix(),
  8648. Status: 1,
  8649. OrderStatus: 2,
  8650. MdtrtId: his.Number,
  8651. Number: chrg_bchno,
  8652. MedfeeSumamt: totals,
  8653. PayWay: pay_way,
  8654. PayWays: pay_ways,
  8655. PayPrice: pay_price,
  8656. MedType: strconv.Itoa(int(reg_type)),
  8657. PayCardNo: pay_card_no,
  8658. DiscountPrice: discount_price,
  8659. PreferentialPrice: preferential_price,
  8660. RealityPrice: reality_price,
  8661. FoundPrice: found_price,
  8662. MedicalInsurancePrice: medical_insurance_price,
  8663. PrivatePrice: private_price,
  8664. SettleEndTime: end_time,
  8665. SettleStartTime: start_time,
  8666. PsnPartAmt: totals,
  8667. PsnCashPay: totals,
  8668. SettleType: settle_accounts_type,
  8669. FaPiaoCode: fapiao_code,
  8670. FaPiaoNumber: fapiao_number,
  8671. Diagnosis: diagnosis_id,
  8672. PType: 2,
  8673. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8674. Decimal: decimal,
  8675. OthDesc: oth_desc,
  8676. CashPay: cash_pay,
  8677. WechatPay: wechat_pay,
  8678. AliPay: ali_pay,
  8679. JifenPay: jifen_pay,
  8680. BandCardPay: band_card_pay,
  8681. Creator: adminUser.AdminUser.Id,
  8682. }
  8683. err = service.CreateOrderTX(order, tx)
  8684. if err != nil {
  8685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8686. return
  8687. }
  8688. var customs []*Custom
  8689. for _, item := range prescriptions {
  8690. if item.Type == 1 { //药品a
  8691. for _, subItem := range item.HisDoctorAdviceInfo {
  8692. cus := &Custom{
  8693. AdviceId: subItem.ID,
  8694. ProjectId: 0,
  8695. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8696. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8697. FeedetlSn: subItem.FeedetlSn,
  8698. Price: fmt.Sprintf("%.4f", subItem.Price),
  8699. MedListCodg: subItem.MedListCodg,
  8700. Type: 1,
  8701. }
  8702. customs = append(customs, cus)
  8703. }
  8704. }
  8705. if item.Type == 2 { //项目
  8706. for _, subItem := range item.HisPrescriptionProject {
  8707. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8708. cus := &Custom{
  8709. AdviceId: 0,
  8710. ProjectId: subItem.ID,
  8711. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8712. Cut: fmt.Sprintf("%.4f", cnt),
  8713. FeedetlSn: subItem.FeedetlSn,
  8714. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8715. MedListCodg: subItem.MedListCodg,
  8716. Type: 2,
  8717. }
  8718. customs = append(customs, cus)
  8719. }
  8720. }
  8721. for _, item := range item.HisAdditionalCharge {
  8722. cus := &Custom{
  8723. ItemId: item.ID,
  8724. AdviceId: 0,
  8725. ProjectId: 0,
  8726. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8727. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8728. FeedetlSn: item.FeedetlSn,
  8729. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8730. MedListCodg: item.XtHisAddtionConfig.Code,
  8731. Type: 3,
  8732. }
  8733. customs = append(customs, cus)
  8734. }
  8735. }
  8736. for _, item := range customs {
  8737. var advice_id int64 = 0
  8738. var project_id int64 = 0
  8739. var item_id int64 = 0
  8740. var types int64 = 0
  8741. if item.Type == 1 {
  8742. advice_id = item.AdviceId
  8743. project_id = 0
  8744. item_id = 0
  8745. } else if item.Type == 2 {
  8746. advice_id = 0
  8747. item_id = 0
  8748. project_id = item.ProjectId
  8749. } else if item.Type == 3 {
  8750. advice_id = 0
  8751. item_id = item.ItemId
  8752. project_id = 0
  8753. }
  8754. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8755. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8756. pric, _ := strconv.ParseFloat(item.Price, 32)
  8757. info := &models.HisOrderInfo{
  8758. OrderNumber: order.Number,
  8759. UploadDate: time.Now().Unix(),
  8760. AdviceId: advice_id,
  8761. DetItemFeeSumamt: detItemFeeSumamt,
  8762. Cnt: cut,
  8763. Pric: pric,
  8764. PatientId: id,
  8765. Status: 1,
  8766. Mtime: time.Now().Unix(),
  8767. Ctime: time.Now().Unix(),
  8768. UserOrgId: adminUser.CurrentOrgId,
  8769. HisPatientId: his.ID,
  8770. OrderId: order.ID,
  8771. ProjectId: project_id,
  8772. Type: types,
  8773. ItemId: item_id,
  8774. }
  8775. service.CreateOrderInfoTX(info, tx)
  8776. }
  8777. his.Diagnosis = diagnosis_id
  8778. his.SickType = sick_type
  8779. his.RegisterType = reg_type
  8780. his.MedicalTreatmentType = reg_type
  8781. service.UpdataHisPateintTX(&his, tx)
  8782. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8783. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8784. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8785. //判断是否使用了押金
  8786. if dec_way == "true" {
  8787. tmpstring := strconv.FormatInt(order.ID, 10)
  8788. //扣押金
  8789. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8790. order.Decimal = decimal
  8791. service.UpDateOrderTwo(order, tx)
  8792. if errmsg != nil {
  8793. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8794. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8795. return
  8796. }
  8797. }
  8798. if err == nil {
  8799. for _, info := range prescriptions {
  8800. if info.Type == 1 {
  8801. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8802. }
  8803. if info.Type == 2 {
  8804. for _, sumItem := range info.HisPrescriptionProject {
  8805. if sumItem.Type == 3 {
  8806. var good models.DialysisBeforePrepareGoods
  8807. var newGood models.NewDialysisBeforePrepareGoods
  8808. var oldGood models.OldDialysisBeforePrepareGoods
  8809. good.GoodId = sumItem.GoodInfo.ID
  8810. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8811. count, _ := strconv.Atoi(sumItem.Count)
  8812. good.Count = int64(count)
  8813. good.StorehouseId = houseConfig.StorehouseOutInfo
  8814. good.ProjectId = sumItem.ID
  8815. good.PatientId = sumItem.PatientId
  8816. goods = append(goods, &good)
  8817. newGood.GoodId = sumItem.GoodInfo.ID
  8818. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8819. count2, _ := strconv.Atoi(sumItem.Count)
  8820. newGood.Count = int64(count2)
  8821. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8822. newGood.ProjectId = sumItem.ID
  8823. newGood.PatientId = sumItem.HisPatientId
  8824. newGoods = append(newGoods, &newGood)
  8825. oldGood.GoodId = sumItem.GoodInfo.ID
  8826. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8827. count3, _ := strconv.Atoi(sumItem.Count)
  8828. oldGood.Count = int64(count3)
  8829. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8830. oldGood.ProjectId = sumItem.ID
  8831. oldGood.RecordDate = sumItem.RecordDate
  8832. oldGood.PatientId = sumItem.HisPatientId
  8833. oldGoods = append(oldGoods, &oldGood)
  8834. }
  8835. }
  8836. }
  8837. }
  8838. if settConfig.IsOpen == 1 {
  8839. for _, item := range infoList {
  8840. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8841. if medical.IsUse == 2 {
  8842. //药品出库
  8843. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8844. //查询默认仓库
  8845. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8846. //查询默认仓库剩余多少库存
  8847. var sum_count int64
  8848. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8849. for _, its := range stockInfo {
  8850. if its.MaxUnit == medical.MaxUnit {
  8851. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8852. }
  8853. sum_count += its.StockMaxNumber + its.StockMinNumber
  8854. }
  8855. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8856. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8857. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8858. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8859. }
  8860. }
  8861. orgId := c.GetAdminUserInfo().CurrentOrgId
  8862. if len(oldGoods) > 0 {
  8863. timeStr := time.Now().Format("2006-01-02")
  8864. timeArr := strings.Split(timeStr, "-")
  8865. total, _ := service.FindAllWarehouseOut(orgId)
  8866. total = total + 1
  8867. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8868. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8869. number = number + total
  8870. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8871. operation_time := time.Now().Unix()
  8872. creater := c.GetAdminUserInfo().AdminUser.Id
  8873. //查询默认出库仓库库存
  8874. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8875. recordDateStr := time.Now().Format("2006-01-02")
  8876. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8877. nowtime := recordDate.Unix()
  8878. warehouseOut := models.WarehouseOut{
  8879. WarehouseOutOrderNumber: warehousing_out_order,
  8880. OperationTime: operation_time,
  8881. OrgId: orgId,
  8882. Creater: creater,
  8883. Ctime: time.Now().Unix(),
  8884. Status: 1,
  8885. WarehouseOutTime: nowtime,
  8886. Type: 1,
  8887. StorehouseId: storeConfig.StorehouseOutInfo,
  8888. IsCheck: 1,
  8889. OrderId: order.ID,
  8890. IsSys: 5,
  8891. }
  8892. //查询是否生成出库单
  8893. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8894. if out.ID == 0 {
  8895. service.AddSigleWarehouseOut(&warehouseOut)
  8896. }
  8897. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8898. for _, item := range oldGoods {
  8899. dialyPrepareOne := models.DialysisBeforePrepare{
  8900. GoodTypeId: item.GoodTypeId,
  8901. GoodId: item.GoodId,
  8902. PatientId: his.PatientId,
  8903. RecordDate: item.RecordDate,
  8904. UserOrgId: adminUser.CurrentOrgId,
  8905. Count: item.Count,
  8906. Ctime: time.Now().Unix(),
  8907. Creater: adminUser.AdminUser.Id,
  8908. CommdityCode: item.CommdityCode,
  8909. Status: 1,
  8910. StorehouseId: houseConfig.StorehouseOutInfo,
  8911. }
  8912. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8913. //非零用
  8914. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8915. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8916. //查询剩余库存
  8917. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8918. var sum_count int64
  8919. for _, item := range goodList {
  8920. sum_count += item.StockCount
  8921. }
  8922. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8923. //耗材
  8924. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8925. }
  8926. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8927. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8928. //查询剩余库存
  8929. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8930. var sum_count int64
  8931. for _, item := range goodList {
  8932. sum_count += item.StockCount
  8933. }
  8934. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8935. //耗材
  8936. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8937. }
  8938. }
  8939. }
  8940. }
  8941. c.ServeSuccessJSON(map[string]interface{}{
  8942. "msg": "结算成功",
  8943. })
  8944. }
  8945. }
  8946. }
  8947. // 退款
  8948. func (c *HisApiController) Refund() {
  8949. order_id, _ := c.GetInt64("order_id")
  8950. order, _ := service.GetHisOrderByID(order_id)
  8951. adminUser := c.GetAdminUserInfo()
  8952. orgid := c.GetAdminUserInfo().CurrentOrgId
  8953. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8954. if err != nil {
  8955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8956. return
  8957. }
  8958. tmp := strconv.FormatInt(order.ID, 10)
  8959. //当押金不为零时产生退费记录
  8960. if order.Decimal != 0 {
  8961. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8962. if err != nil {
  8963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8964. return
  8965. }
  8966. }
  8967. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8968. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8969. var goods []*models.DialysisBeforePrepareGoods
  8970. var newGoods []*models.NewDialysisBeforePrepareGoods
  8971. var infos []*models.HisDoctorAdviceInfo
  8972. for _, info := range orders {
  8973. if info.AdviceId > 0 && info.ProjectId == 0 {
  8974. infos = append(infos, &info.HisDoctorAdviceInfo)
  8975. }
  8976. if info.ProjectId > 0 && info.AdviceId == 0 {
  8977. if info.HisPrescriptionProject.Type == 3 {
  8978. var good models.DialysisBeforePrepareGoods
  8979. var newGood models.NewDialysisBeforePrepareGoods
  8980. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8981. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8982. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8983. good.Count = int64(count)
  8984. good.StorehouseId = houseConfig.StorehouseOutInfo
  8985. good.ProjectId = info.HisPrescriptionProject.ID
  8986. good.PatientId = info.PatientId
  8987. good.OrderId = order_id
  8988. goods = append(goods, &good)
  8989. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8990. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8991. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8992. newGood.Count = int64(count2)
  8993. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8994. newGood.ProjectId = info.HisPrescriptionProject.ID
  8995. newGood.RecordDate = order.SettleAccountsDate
  8996. newGood.UserOrgId = order.UserOrgId
  8997. newGood.PatientId = info.PatientId
  8998. newGood.OrderId = order_id
  8999. newGoods = append(newGoods, &newGood)
  9000. }
  9001. }
  9002. }
  9003. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9004. if settConfig.IsOpen == 1 {
  9005. for _, item := range infos {
  9006. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9007. }
  9008. for _, item := range newGoods {
  9009. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9010. }
  9011. }
  9012. c.ServeSuccessJSON(map[string]interface{}{
  9013. "msg": "退费成功",
  9014. })
  9015. }
  9016. func (c *HisApiController) RefundNumber() {
  9017. his_patient_id, _ := c.GetInt64("id")
  9018. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9019. info.Status = 0
  9020. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9021. if count > 0 {
  9022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9023. return
  9024. }
  9025. err := service.SaveHisPatient(info)
  9026. if err == nil {
  9027. c.ServeSuccessJSON(map[string]interface{}{
  9028. "msg": "退号成功",
  9029. })
  9030. } else {
  9031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9032. return
  9033. }
  9034. }
  9035. func (this *HisApiController) AdditionalCharge() {
  9036. dataBody := make(map[string]interface{}, 0)
  9037. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9038. fmt.Println(err)
  9039. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9040. patient_id := int64(dataBody["patient_id"].(float64))
  9041. medicineData, _ := dataBody["medicineData"].([]interface{})
  9042. adminUserInfo := this.GetAdminUserInfo()
  9043. orgId := adminUserInfo.CurrentOrgId
  9044. admin_user_id := adminUserInfo.AdminUser.Id
  9045. timeStr := time.Now().Format("2006-01-02")
  9046. timeLayout := "2006-01-02 15:04:05"
  9047. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9048. timenow := timeStringToTime.Unix()
  9049. var additionalCharges []*models.HisAdditionalCharge
  9050. for _, item := range medicineData {
  9051. var randNum int
  9052. randNum = rand.Intn(10000) + 1000
  9053. timestamp := time.Now().Unix()
  9054. tempTime := time.Unix(timestamp, 0)
  9055. timeFormat := tempTime.Format("20060102150405")
  9056. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9057. items := item.(map[string]interface{})
  9058. money := items["price"].(string)
  9059. item_id_str := items["item_id"].(string)
  9060. name := items["name"].(string)
  9061. id_str := items["id"].(string)
  9062. moneys, _ := strconv.ParseInt(money, 10, 64)
  9063. monStr := strconv.FormatInt(moneys, 10)
  9064. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9065. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9066. id, _ := strconv.ParseInt(id_str, 10, 64)
  9067. additionalCharge := &models.HisAdditionalCharge{
  9068. ID: id,
  9069. HisPatientId: his_patient_id,
  9070. UserOrgId: orgId,
  9071. PatientId: patient_id,
  9072. RecordDate: timenow,
  9073. Price: monneyStr,
  9074. Status: 1,
  9075. ItemName: name,
  9076. ItemId: item_id,
  9077. AdminUserId: admin_user_id,
  9078. CreatedTime: time.Now().Unix(),
  9079. OrderStatus: 0,
  9080. PrescriptionNumber: "",
  9081. BatchNumber: "",
  9082. FeedetlSn: p_number,
  9083. }
  9084. service.CreateAdditionalCharge(additionalCharge)
  9085. additionalCharges = append(additionalCharges, additionalCharge)
  9086. }
  9087. this.ServeSuccessJSON(map[string]interface{}{
  9088. "msg": "添加成功",
  9089. "additional_charges": additionalCharges,
  9090. })
  9091. }
  9092. func (this *HisApiController) DeleteAddition() {
  9093. id, _ := this.GetInt64("id")
  9094. //TODO 需要判断是否已经结算
  9095. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9096. if err == nil {
  9097. this.ServeSuccessJSON(map[string]interface{}{
  9098. "msg": "删除成功",
  9099. })
  9100. return
  9101. } else {
  9102. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9103. return
  9104. }
  9105. }
  9106. func (this *HisApiController) GetAdminUsers() {
  9107. adminUser := this.GetAdminUserInfo()
  9108. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9109. this.ServeSuccessJSON(map[string]interface{}{
  9110. "doctors": doctors,
  9111. })
  9112. }
  9113. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9114. change_type, _ := this.GetInt64("type", 0)
  9115. record_date := this.GetString("record_time")
  9116. patient_id, _ := this.GetInt64("patient_id", 0)
  9117. p_type, _ := this.GetInt64("p_type", 0)
  9118. timeLayout := "2006-01-02"
  9119. loc, _ := time.LoadLocation("Local")
  9120. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9121. record_time := theAdviceRecordTime.Unix()
  9122. adminUserInfo := this.GetAdminUserInfo()
  9123. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9124. if err == nil {
  9125. if len(prescriptions) == 0 {
  9126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9127. return
  9128. } else {
  9129. this.ServeSuccessJSON(map[string]interface{}{
  9130. "prescriptions": prescriptions,
  9131. })
  9132. return
  9133. }
  9134. } else {
  9135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9136. return
  9137. }
  9138. }
  9139. func (this *HisApiController) GetCallHisPrescription() {
  9140. patient_id, _ := this.GetInt64("patient_id", 0)
  9141. timeLayout := "2006-01-02"
  9142. loc, _ := time.LoadLocation("Local")
  9143. start_time := this.GetString("start_time")
  9144. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9145. end_time := this.GetString("end_time")
  9146. p_type, _ := this.GetInt64("p_type")
  9147. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9148. adminUserInfo := this.GetAdminUserInfo()
  9149. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9150. if err == nil {
  9151. this.ServeSuccessJSON(map[string]interface{}{
  9152. "prescriptions": prescriptions,
  9153. })
  9154. return
  9155. } else {
  9156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9157. return
  9158. }
  9159. }
  9160. func (this *HisApiController) GetHisDayPrescription() {
  9161. timeLayout := "2006-01-02"
  9162. loc, _ := time.LoadLocation("Local")
  9163. start_time := this.GetString("start_time")
  9164. patient_id, _ := this.GetInt64("patient_id", 0)
  9165. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9166. end_time := this.GetString("end_time")
  9167. p_type, _ := this.GetInt64("p_type")
  9168. order_status, _ := this.GetInt64("type")
  9169. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9170. adminUserInfo := this.GetAdminUserInfo()
  9171. var dayHisPrescription []*models.HisPrescription
  9172. var err error
  9173. if order_status == 1 || order_status == 0 {
  9174. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9175. } else if order_status == 2 {
  9176. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9177. }
  9178. var settle_total float64
  9179. for _, item := range dayHisPrescription {
  9180. if len(item.HisPrescriptionProject) > 0 {
  9181. for _, subItem := range item.HisPrescriptionProject {
  9182. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9183. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9184. settle_total = settle_total + total
  9185. }
  9186. }
  9187. if len(item.HisDoctorAdviceInfo) > 0 {
  9188. for _, subItem := range item.HisDoctorAdviceInfo {
  9189. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9190. settle_total = settle_total + total
  9191. }
  9192. }
  9193. }
  9194. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9195. if err == nil {
  9196. this.ServeSuccessJSON(map[string]interface{}{
  9197. "day_prescription": dayHisPrescription,
  9198. "settle_total": settle_total,
  9199. })
  9200. return
  9201. } else {
  9202. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9203. return
  9204. }
  9205. }
  9206. func (c *HisApiController) GetHisChargePatientList() {
  9207. record_date := c.GetString("record_date")
  9208. order_status, _ := c.GetInt64("type")
  9209. sch_type, _ := c.GetInt64("sch_type")
  9210. timeLayout := "2006-01-02"
  9211. loc, _ := time.LoadLocation("Local")
  9212. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9213. if err != nil {
  9214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9215. return
  9216. }
  9217. recordDateTime := theTime.Unix()
  9218. adminInfo := c.GetAdminUserInfo()
  9219. var tempPatients []*service.NewTempPatients
  9220. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9221. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9222. if order_status != 2 {
  9223. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9224. } else {
  9225. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9226. }
  9227. } else {
  9228. if order_status != 2 {
  9229. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9230. } else {
  9231. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9232. }
  9233. }
  9234. var patients []*service.NewTempPatients
  9235. var patients_two []*service.NewTempPatients
  9236. for _, item := range tempPatients {
  9237. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9238. //过滤掉没挂号的和没开处方的
  9239. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9240. patients = append(patients, item)
  9241. }
  9242. //过滤掉没挂号的
  9243. if len(item.HisPatient) > 0 {
  9244. patients_two = append(patients_two, item)
  9245. }
  9246. } else {
  9247. if len(item.HisPrescription) > 0 {
  9248. patients = append(patients, item)
  9249. }
  9250. }
  9251. }
  9252. c.ServeSuccessJSON(map[string]interface{}{
  9253. "list": patients,
  9254. "list_two": patients_two,
  9255. })
  9256. }
  9257. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9258. record_date := c.GetString("record_date")
  9259. timeLayout := "2006-01-02"
  9260. loc, _ := time.LoadLocation("Local")
  9261. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9262. if err != nil {
  9263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9264. return
  9265. }
  9266. recordDateTime := theTime.Unix()
  9267. adminUser := c.GetAdminUserInfo()
  9268. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9269. var patients []*service.Patients
  9270. for _, item := range tempPatients {
  9271. if item.HisPatient.ID == 0 {
  9272. patients = append(patients, item)
  9273. }
  9274. }
  9275. c.ServeSuccessJSON(map[string]interface{}{
  9276. "list": patients,
  9277. //"list_two": patients_two,
  9278. })
  9279. }
  9280. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9281. newArr = make([]*service.Patients, 0)
  9282. for i := 0; i < len(patient); i++ {
  9283. repeat := false
  9284. for j := i + 1; j < len(patient); j++ {
  9285. if patient[i].ID == patient[j].ID {
  9286. repeat = true
  9287. break
  9288. }
  9289. }
  9290. if !repeat {
  9291. newArr = append(newArr, patient[i])
  9292. }
  9293. }
  9294. return
  9295. }
  9296. func (c *HisApiController) GetHisChargePatientInfo() {
  9297. patient_id, _ := c.GetInt64("patient_id")
  9298. his_patient_id, _ := c.GetInt64("his_patient_id")
  9299. record_date := c.GetString("record_date")
  9300. //start_time := c.GetString("start_time")
  9301. //end_time := c.GetString("end_time")
  9302. order_status, _ := c.GetInt64("type", 0)
  9303. p_type, _ := c.GetInt64("p_type", 0)
  9304. order_id, _ := c.GetInt64("order_id", 0)
  9305. timeLayout := "2006-01-02"
  9306. loc, _ := time.LoadLocation("Local")
  9307. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9308. if err != nil {
  9309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9310. return
  9311. }
  9312. recordDateTime := theTime.Unix()
  9313. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9314. //if err != nil {
  9315. //
  9316. //}
  9317. //startRecordDateTime := startTime.Unix()
  9318. //
  9319. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9320. //if err != nil {
  9321. //
  9322. //}
  9323. //endRecordDateTime := endTime.Unix()
  9324. admin := c.GetAdminUserInfo()
  9325. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9326. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9327. var prescriptions []*models.HisPrescription
  9328. //var unChargeMonthPrescriptions []*models.HisPrescription
  9329. order, _ := service.GetHisOrderByID(order_id)
  9330. if order_status == 1 || order_status == 0 {
  9331. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9332. } else if order_status == 2 {
  9333. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9334. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9335. }
  9336. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9337. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9338. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9339. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9340. //获取所有科室信息
  9341. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9342. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9343. c.ServeSuccessJSON(map[string]interface{}{
  9344. "his_info": his_patient_info,
  9345. "xt_info": xt_patient_info,
  9346. "prescription": prescriptions,
  9347. "case_history": case_history,
  9348. "info": patientPrescriptionInfo,
  9349. "last_info": lastPatientPrescriptionInfo,
  9350. "order": order,
  9351. "doctors": doctors,
  9352. "department": department,
  9353. "sch": sch,
  9354. })
  9355. return
  9356. }
  9357. func (c *HisApiController) GetAllOrderDetail() {
  9358. order_id, _ := c.GetInt64("id", 0)
  9359. order, _ := service.GetHisOrderByID(order_id)
  9360. if order.ID == 0 {
  9361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9362. return
  9363. }
  9364. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9365. org_id := c.GetAdminUserInfo().CurrentOrgId
  9366. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9367. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9368. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9369. c.ServeSuccessJSON(map[string]interface{}{
  9370. "order": order,
  9371. "order_info": order_info,
  9372. "patient": patient,
  9373. "admin_info": adminInfo,
  9374. "hospital_record": record,
  9375. })
  9376. return
  9377. }
  9378. func (c *HisApiController) GetAllOrderDetailCollect() {
  9379. order_id, _ := c.GetInt64("id", 0)
  9380. order, _ := service.GetHisOrderByID(order_id)
  9381. if order.ID == 0 {
  9382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9383. return
  9384. }
  9385. org_id := c.GetAdminUserInfo().CurrentOrgId
  9386. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9387. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9388. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9389. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9390. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9391. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9392. var bedCostTotal float64 = 0 //床位总费
  9393. //var bedCostSelfTotal float64 = 0 //床位自费
  9394. var operationCostTotal float64 = 0 //手术费
  9395. //var operationCostSelfTotal float64 = 0 //手术费
  9396. var otherCostTotal float64 = 0 //其他费用
  9397. //var otherCostSelfTotal float64 = 0 //其他费用
  9398. var materialCostTotal float64 = 0 //材料费
  9399. //var materialCostSelfTotal float64 = 0 //材料费
  9400. var westernMedicineCostTotal float64 = 0 //西药费
  9401. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9402. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9403. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9404. var checkCostTotal float64 = 0 //检查费
  9405. //var checkCostSelfTotal float64 = 0 //检查费
  9406. var laboratoryCostTotal float64 = 0 //化验费
  9407. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9408. var treatCostTotal float64 = 0 //治疗费用
  9409. //var treatCostSelfTotal float64 = 0 //治疗费用
  9410. var zhenChaCostTotal float64 = 0 //其他费用
  9411. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9412. decimal.DivisionPrecision = 2
  9413. var BalanceAccountsType int64
  9414. if his.ID > 0 {
  9415. BalanceAccountsType = his.BalanceAccountsType
  9416. } else {
  9417. BalanceAccountsType = record.BalanceAccountsType
  9418. }
  9419. if BalanceAccountsType != 2 {
  9420. for _, item := range order_info {
  9421. if org_id == 10215 {
  9422. if item.MedChrgitmType == "01" { //床位费
  9423. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9424. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9425. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9426. }
  9427. if item.MedChrgitmType == "02" { //诊察费
  9428. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9429. //zhenChaCostSelfTotal = zhenChaCostTotal
  9430. }
  9431. if item.MedChrgitmType == "03" { //检查费
  9432. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9433. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9434. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9435. }
  9436. //if item.MedChrgitmType == "02" { //检查费
  9437. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9438. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9439. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9440. //}
  9441. if item.MedChrgitmType == "04" { //化验费
  9442. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9443. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9444. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9445. }
  9446. if item.MedChrgitmType == "05" { //治疗费
  9447. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9448. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9449. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9450. }
  9451. if item.MedChrgitmType == "06" { //手术费
  9452. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9453. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9454. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9455. }
  9456. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9457. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9458. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9459. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9460. }
  9461. if item.MedChrgitmType == "09" { //西药费
  9462. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9463. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9464. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9465. }
  9466. if item.MedChrgitmType == "11" { //中成费
  9467. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9468. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9469. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9470. }
  9471. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9472. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9473. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9474. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9475. }
  9476. } else if org_id == 10188 || org_id == 10217 {
  9477. if item.MedChrgitmType == "01" { //床位费
  9478. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9479. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9480. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9481. }
  9482. if item.MedChrgitmType == "02" { //诊察费
  9483. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9484. //zhenChaCostSelfTotal = zhenChaCostTotal
  9485. }
  9486. if item.MedChrgitmType == "03" { //检查费
  9487. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9488. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9489. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9490. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9491. }
  9492. //if item.MedChrgitmType == "02" { //检查费
  9493. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9494. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9495. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9496. //}
  9497. if item.MedChrgitmType == "04" { //化验费
  9498. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9499. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9500. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9501. }
  9502. if item.MedChrgitmType == "05" { //治疗费
  9503. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9504. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9505. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9506. }
  9507. if item.MedChrgitmType == "06" { //手术费
  9508. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9509. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9510. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9511. }
  9512. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9513. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9514. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9515. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9516. }
  9517. if item.MedChrgitmType == "09" { //西药费
  9518. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9519. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9520. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9521. }
  9522. if item.MedChrgitmType == "11" { //中成费
  9523. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9524. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9525. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9526. }
  9527. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9528. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9529. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9530. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9531. }
  9532. } else {
  9533. if item.MedChrgitmType == "01" { //床位费
  9534. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9535. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9536. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9537. }
  9538. //if item.MedChrgitmType == "02" { //诊察费
  9539. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9540. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9541. //}
  9542. if item.MedChrgitmType == "03" { //检查费
  9543. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9544. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9545. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9546. }
  9547. //if item.MedChrgitmType == "02" { //检查费
  9548. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9549. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9550. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9551. //}
  9552. if item.MedChrgitmType == "04" { //化验费
  9553. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9554. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9555. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9556. }
  9557. if item.MedChrgitmType == "05" { //治疗费
  9558. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9559. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9560. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9561. }
  9562. if item.MedChrgitmType == "06" { //手术费
  9563. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9564. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9565. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9566. }
  9567. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9568. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9569. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9570. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9571. }
  9572. if item.MedChrgitmType == "09" { //西药费
  9573. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9574. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9575. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9576. }
  9577. if item.MedChrgitmType == "11" { //中成费
  9578. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9579. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9580. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9581. }
  9582. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9583. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9584. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9585. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9586. }
  9587. }
  9588. }
  9589. c.ServeSuccessJSON(map[string]interface{}{
  9590. "order": order,
  9591. "order_info": order_info,
  9592. "patient": patient,
  9593. "admin_info": adminInfo,
  9594. "his_hospital": record,
  9595. "bedCostTotal": bedCostTotal,
  9596. "operationCostTotal": operationCostTotal,
  9597. "otherCostTotal": otherCostTotal,
  9598. "materialCostTotal": materialCostTotal,
  9599. "westernMedicineCostTotal": westernMedicineCostTotal,
  9600. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9601. "checkCostTotal": checkCostTotal,
  9602. "zhenChaCostTotal": zhenChaCostTotal,
  9603. "laboratoryCostTotal": laboratoryCostTotal,
  9604. "treatCostTotal": treatCostTotal,
  9605. })
  9606. } else {
  9607. for _, item := range order_info {
  9608. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9609. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9610. item.MedChrgitmType = "09"
  9611. }
  9612. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9613. if item.HisPrescriptionProject.Type == 2 {
  9614. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9615. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9616. case 0:
  9617. item.MedChrgitmType = "0"
  9618. break
  9619. case 1:
  9620. item.MedChrgitmType = "14"
  9621. break
  9622. case 2:
  9623. item.MedChrgitmType = "05"
  9624. break
  9625. case 3:
  9626. item.MedChrgitmType = "03"
  9627. break
  9628. case 4:
  9629. item.MedChrgitmType = "03"
  9630. break
  9631. case 5:
  9632. item.MedChrgitmType = "08"
  9633. break
  9634. case 6:
  9635. item.MedChrgitmType = "14"
  9636. break
  9637. case 7:
  9638. item.MedChrgitmType = "14"
  9639. break
  9640. case 8:
  9641. item.MedChrgitmType = "03"
  9642. break
  9643. case 9:
  9644. item.MedChrgitmType = "14"
  9645. break
  9646. case 10:
  9647. item.MedChrgitmType = "14"
  9648. break
  9649. case 11:
  9650. item.MedChrgitmType = "06"
  9651. break
  9652. case 12:
  9653. item.MedChrgitmType = "12"
  9654. break
  9655. case 13:
  9656. item.MedChrgitmType = "01"
  9657. break
  9658. case 14:
  9659. item.MedChrgitmType = "04"
  9660. break
  9661. case 15:
  9662. item.MedChrgitmType = "14"
  9663. break
  9664. }
  9665. } else {
  9666. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9667. case 1:
  9668. item.MedChrgitmType = "14"
  9669. break
  9670. case 2:
  9671. item.MedChrgitmType = "05"
  9672. break
  9673. case 3:
  9674. item.MedChrgitmType = "04"
  9675. break
  9676. case 4:
  9677. item.MedChrgitmType = "14"
  9678. break
  9679. case 5:
  9680. item.MedChrgitmType = "08"
  9681. break
  9682. case 6:
  9683. item.MedChrgitmType = "14"
  9684. break
  9685. case 7:
  9686. item.MedChrgitmType = "14"
  9687. break
  9688. case 8:
  9689. item.MedChrgitmType = "03"
  9690. break
  9691. case 9:
  9692. item.MedChrgitmType = "14"
  9693. break
  9694. }
  9695. }
  9696. } else if item.HisPrescriptionProject.Type == 3 {
  9697. item.MedChrgitmType = "08"
  9698. }
  9699. }
  9700. }
  9701. for _, item := range order_info {
  9702. if org_id == 10215 {
  9703. if item.MedChrgitmType == "01" { //床位费
  9704. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9705. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9706. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9707. }
  9708. if item.MedChrgitmType == "02" { //诊察费
  9709. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9710. //zhenChaCostSelfTotal = zhenChaCostTotal
  9711. }
  9712. if item.MedChrgitmType == "03" { //检查费
  9713. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9714. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9715. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9716. }
  9717. //if item.MedChrgitmType == "02" { //检查费
  9718. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9719. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9720. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9721. //}
  9722. if item.MedChrgitmType == "04" { //化验费
  9723. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9724. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9725. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9726. }
  9727. if item.MedChrgitmType == "05" { //治疗费
  9728. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9729. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9730. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9731. }
  9732. if item.MedChrgitmType == "06" { //手术费
  9733. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9734. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9735. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9736. }
  9737. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9738. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9739. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9740. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9741. }
  9742. if item.MedChrgitmType == "09" { //西药费
  9743. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9744. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9745. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9746. }
  9747. if item.MedChrgitmType == "11" { //中成费
  9748. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9749. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9750. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9751. }
  9752. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9753. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9754. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9755. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9756. }
  9757. } else {
  9758. if item.MedChrgitmType == "01" { //床位费
  9759. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9760. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9761. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9762. }
  9763. //if item.MedChrgitmType == "02" { //诊察费
  9764. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9765. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9766. //}
  9767. if item.MedChrgitmType == "03" { //检查费
  9768. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9769. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9770. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9771. }
  9772. //if item.MedChrgitmType == "02" { //检查费
  9773. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9774. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9775. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9776. //}
  9777. if item.MedChrgitmType == "04" { //化验费
  9778. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9779. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9780. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9781. }
  9782. if item.MedChrgitmType == "05" { //治疗费
  9783. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9784. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9785. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9786. }
  9787. if item.MedChrgitmType == "06" { //手术费
  9788. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9789. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9790. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9791. }
  9792. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9793. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9794. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9795. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9796. }
  9797. if item.MedChrgitmType == "09" { //西药费
  9798. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9799. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9800. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9801. }
  9802. if item.MedChrgitmType == "11" { //中成费
  9803. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9804. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9805. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9806. }
  9807. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9808. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9809. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9810. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9811. }
  9812. }
  9813. }
  9814. c.ServeSuccessJSON(map[string]interface{}{
  9815. "order": order,
  9816. "order_info": order_info,
  9817. "patient": patient,
  9818. "admin_info": adminInfo,
  9819. "his_hospital": record,
  9820. "bedCostTotal": bedCostTotal,
  9821. "operationCostTotal": operationCostTotal,
  9822. "otherCostTotal": otherCostTotal,
  9823. "materialCostTotal": materialCostTotal,
  9824. "westernMedicineCostTotal": westernMedicineCostTotal,
  9825. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9826. "checkCostTotal": checkCostTotal,
  9827. "zhenChaCostTotal": zhenChaCostTotal,
  9828. "laboratoryCostTotal": laboratoryCostTotal,
  9829. "treatCostTotal": treatCostTotal,
  9830. })
  9831. }
  9832. }
  9833. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9834. page, _ := c.GetInt64("page")
  9835. limit, _ := c.GetInt64("limit")
  9836. keywords := c.GetString("keywords")
  9837. start_time := c.GetString("start_time")
  9838. end_time := c.GetString("end_time")
  9839. //clr_type := c.GetString("clr_type")
  9840. insutype := c.GetString("insutype")
  9841. timeLayout := "2006-01-02"
  9842. loc, _ := time.LoadLocation("Local")
  9843. var theStartTIme int64
  9844. if len(start_time) > 0 {
  9845. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9846. theStartTIme = theTime.Unix()
  9847. }
  9848. var theEndtTIme int64
  9849. if len(end_time) > 0 {
  9850. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9851. theEndtTIme = theTime.Unix()
  9852. }
  9853. if page <= 0 {
  9854. page = 1
  9855. }
  9856. if limit <= 0 {
  9857. limit = 10
  9858. }
  9859. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9860. c.ServeSuccessJSON(map[string]interface{}{
  9861. "total": total,
  9862. "list": list,
  9863. })
  9864. return
  9865. }
  9866. func (c *HisApiController) GetPutOnRecordList() {
  9867. page, _ := c.GetInt64("page")
  9868. limit, _ := c.GetInt64("limit")
  9869. keywords := c.GetString("keywords")
  9870. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9871. if page <= 0 {
  9872. page = 1
  9873. }
  9874. if limit <= 0 {
  9875. limit = 10
  9876. }
  9877. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9878. c.ServeSuccessJSON(map[string]interface{}{
  9879. "total": total,
  9880. "list": list,
  9881. })
  9882. return
  9883. }
  9884. func (c *HisApiController) GetCompareData() {
  9885. start_time := c.GetString("start_time")
  9886. end_time := c.GetString("end_time")
  9887. insutype := c.GetString("insutype")
  9888. clr_type := c.GetString("clr_type")
  9889. timeLayout := "2006-01-02"
  9890. loc, _ := time.LoadLocation("Local")
  9891. var theStartTIme int64
  9892. if len(start_time) > 0 {
  9893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9894. if err != nil {
  9895. theStartTIme = 0
  9896. }
  9897. theStartTIme = theTime.Unix()
  9898. }
  9899. var theEndtTIme int64
  9900. if len(end_time) > 0 {
  9901. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9902. if err != nil {
  9903. theEndtTIme = 0
  9904. }
  9905. theEndtTIme = theTime.Unix()
  9906. }
  9907. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9908. fmt.Println(err)
  9909. if err == nil {
  9910. c.ServeSuccessJSON(map[string]interface{}{
  9911. "list": formData,
  9912. })
  9913. } else {
  9914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9915. return
  9916. }
  9917. }
  9918. func (c *HisApiController) GetFaPiaoData() {
  9919. order_id, _ := c.GetInt64("order_id")
  9920. patient_id, _ := c.GetInt64("patient_id")
  9921. //number := c.GetString("number")
  9922. adminUser := c.GetAdminUserInfo()
  9923. order, _ := service.GetHisOrderByID(order_id)
  9924. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9925. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9926. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9927. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9928. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9929. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9930. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9931. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9932. var bedCostTotal float64 = 0 //床位总费
  9933. var bedCostSelfTotal float64 = 0 //床位自费
  9934. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9935. var operationCostTotal float64 = 0 //手术费
  9936. var operationCostSelfTotal float64 = 0 //手术费
  9937. var operationCostPartSelfTotal float64 = 0 //手术费
  9938. var otherCostTotal float64 = 0 //其他费用
  9939. var otherCostSelfTotal float64 = 0 //其他费用
  9940. var otherCostPartSelfTotal float64 = 0 //其他费用
  9941. var materialCostTotal float64 = 0 //材料费
  9942. var materialCostSelfTotal float64 = 0 //材料费
  9943. var materialCostPartSelfTotal float64 = 0 //材料费
  9944. var westernMedicineCostTotal float64 = 0 //西药费
  9945. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9946. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9947. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9948. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9949. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9950. var checkCostTotal float64 = 0 //检查费
  9951. var checkCostSelfTotal float64 = 0 //检查费
  9952. var checkCostPartSelfTotal float64 = 0 //检查费
  9953. var hiliCostTotal float64 = 0 //护理费
  9954. var hiliCostSelfTotal float64 = 0 //护理费
  9955. var hiliCostPartSelfTotal float64 = 0 //护理费
  9956. var laboratoryCostTotal float64 = 0 //化验费
  9957. var laboratoryCostSelfTotal float64 = 0 //化验费
  9958. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9959. var treatCostTotal float64 = 0 //治疗费用
  9960. var treatCostSelfTotal float64 = 0 //治疗费用
  9961. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9962. var zhenChaCostTotal float64 = 0 //其他费用
  9963. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9964. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9965. decimal.DivisionPrecision = 2
  9966. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9967. var balanceAccountsType int64
  9968. if his.ID > 0 {
  9969. balanceAccountsType = his.BalanceAccountsType
  9970. } else {
  9971. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9972. }
  9973. if balanceAccountsType == 2 {
  9974. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9975. for _, item := range orderInfos_two {
  9976. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9977. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9978. item.MedChrgitmType = "09"
  9979. }
  9980. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9981. if item.HisPrescriptionProject.Type == 2 {
  9982. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9984. case 0:
  9985. item.MedChrgitmType = "0"
  9986. break
  9987. case 1:
  9988. item.MedChrgitmType = "14"
  9989. break
  9990. case 2:
  9991. item.MedChrgitmType = "05"
  9992. break
  9993. case 3:
  9994. item.MedChrgitmType = "03"
  9995. break
  9996. case 4:
  9997. item.MedChrgitmType = "03"
  9998. break
  9999. case 5:
  10000. item.MedChrgitmType = "08"
  10001. break
  10002. case 6:
  10003. item.MedChrgitmType = "14"
  10004. break
  10005. case 7:
  10006. item.MedChrgitmType = "14"
  10007. break
  10008. case 8:
  10009. item.MedChrgitmType = "03"
  10010. break
  10011. case 9:
  10012. item.MedChrgitmType = "14"
  10013. break
  10014. case 10:
  10015. item.MedChrgitmType = "14"
  10016. break
  10017. case 11:
  10018. item.MedChrgitmType = "06"
  10019. break
  10020. case 12:
  10021. item.MedChrgitmType = "12"
  10022. break
  10023. case 13:
  10024. item.MedChrgitmType = "01"
  10025. break
  10026. case 14:
  10027. item.MedChrgitmType = "04"
  10028. break
  10029. case 15:
  10030. item.MedChrgitmType = "02"
  10031. break
  10032. }
  10033. } else {
  10034. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10035. case 1:
  10036. item.MedChrgitmType = "14"
  10037. break
  10038. case 2:
  10039. item.MedChrgitmType = "05"
  10040. break
  10041. case 3:
  10042. item.MedChrgitmType = "04"
  10043. break
  10044. case 4:
  10045. item.MedChrgitmType = "03"
  10046. break
  10047. case 5:
  10048. item.MedChrgitmType = "08"
  10049. break
  10050. case 6:
  10051. item.MedChrgitmType = "14"
  10052. break
  10053. case 7:
  10054. item.MedChrgitmType = "14"
  10055. break
  10056. case 8:
  10057. item.MedChrgitmType = "03"
  10058. break
  10059. case 9:
  10060. item.MedChrgitmType = "14"
  10061. break
  10062. }
  10063. }
  10064. } else if item.HisPrescriptionProject.Type == 3 {
  10065. item.MedChrgitmType = "08"
  10066. }
  10067. }
  10068. }
  10069. for _, item := range orderInfos_two {
  10070. fmt.Println(item.MedChrgitmType)
  10071. if item.MedChrgitmType == "07" { //床位费
  10072. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10073. hiliCostSelfTotal = hiliCostTotal
  10074. }
  10075. if item.MedChrgitmType == "01" { //床位费
  10076. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10077. bedCostSelfTotal = bedCostTotal
  10078. }
  10079. if item.MedChrgitmType == "02" { //诊察费
  10080. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10081. zhenChaCostSelfTotal = zhenChaCostTotal
  10082. }
  10083. if item.MedChrgitmType == "03" { //检查费
  10084. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10085. checkCostSelfTotal = checkCostTotal
  10086. }
  10087. if item.MedChrgitmType == "04" { //化验费
  10088. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10089. laboratoryCostSelfTotal = laboratoryCostTotal
  10090. }
  10091. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10092. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10093. treatCostSelfTotal = treatCostTotal
  10094. }
  10095. if item.MedChrgitmType == "06" { //手术费
  10096. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10097. operationCostSelfTotal = treatCostTotal
  10098. }
  10099. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10100. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10101. materialCostSelfTotal = materialCostTotal
  10102. }
  10103. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10104. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10105. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10106. }
  10107. if item.MedChrgitmType == "11" { //中成费
  10108. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10109. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10110. }
  10111. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10112. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10113. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10114. otherCostSelfTotal = otherCostTotal
  10115. }
  10116. } else {
  10117. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10118. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10119. otherCostSelfTotal = otherCostTotal
  10120. }
  10121. }
  10122. }
  10123. } else {
  10124. for _, item := range orderInfos {
  10125. if item.MedChrgitmType == "01" { //床位费
  10126. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10127. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10128. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10129. }
  10130. if item.MedChrgitmType == "02" { //诊察费
  10131. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10132. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10133. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10134. }
  10135. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10136. if item.MedChrgitmType == "03" { //检查费
  10137. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10138. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10139. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10140. }
  10141. } else {
  10142. if item.MedChrgitmType == "03" { //检查费
  10143. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10144. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10145. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10146. }
  10147. }
  10148. if item.MedChrgitmType == "04" { //化验费
  10149. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10150. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10151. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10152. }
  10153. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10154. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10155. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10156. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10157. }
  10158. if item.MedChrgitmType == "06" { //手术费
  10159. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10160. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10161. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10162. }
  10163. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10164. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10165. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10166. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10167. }
  10168. if item.MedChrgitmType == "07" { //护理
  10169. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10170. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10171. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10172. }
  10173. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10174. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10175. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10176. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10177. }
  10178. if item.MedChrgitmType == "11" { //中成费
  10179. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10180. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10181. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10182. }
  10183. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10184. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10185. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10186. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10187. }
  10188. }
  10189. }
  10190. timeLayout := "2006-01-02"
  10191. loc, _ := time.LoadLocation("Local")
  10192. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10193. if err != nil {
  10194. }
  10195. startRecordDateTime := startTime.Unix()
  10196. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10197. if err != nil {
  10198. }
  10199. endRecordDateTime := endTime.Unix()
  10200. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10201. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10202. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10203. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10204. c.ServeSuccessJSON(map[string]interface{}{
  10205. "charge_admin_name": charge_admin.UserName,
  10206. "order_number": order.Number, //业务流水号
  10207. "id_card_no": his.IdCardNo, //社会保障号
  10208. "patient": patient,
  10209. "department_name": department.Name, //科室
  10210. "number": his.Number, //门诊号
  10211. "date": order.SettleAccountsDate, //结算日期
  10212. "name": order.PsnName, //姓名
  10213. "gender": patient.Gender, //性别
  10214. "psn_cash_money": order.PsnCashPay, //个人支付
  10215. "pay_way": "门诊", //结算方式
  10216. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10217. "admin_user_name": admin.UserName, //收款员
  10218. "order": order,
  10219. "order_info": orderInfos_two,
  10220. "his": his,
  10221. "bedCostTotal": bedCostTotal,
  10222. "bedCostSelfTotal": bedCostSelfTotal,
  10223. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10224. "operationCostTotal": operationCostTotal,
  10225. "operationCostSelfTotal": operationCostSelfTotal,
  10226. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10227. "otherCostTotal": otherCostTotal,
  10228. "otherCostSelfTotal": otherCostSelfTotal,
  10229. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10230. "materialCostTotal": materialCostTotal,
  10231. "materialCostSelfTotal": materialCostSelfTotal,
  10232. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10233. "westernMedicineCostTotal": westernMedicineCostTotal,
  10234. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10235. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10236. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10237. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10238. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10239. "checkCostTotal": checkCostTotal,
  10240. "checkCostSelfTotal": checkCostSelfTotal,
  10241. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10242. "laboratoryCostTotal": laboratoryCostTotal,
  10243. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10244. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10245. "treatCostTotal": treatCostTotal,
  10246. "treatCostSelfTotal": treatCostSelfTotal,
  10247. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10248. "zhenChaCostTotal": zhenChaCostTotal,
  10249. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10250. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10251. "his_hospital_record": his_hospital_record,
  10252. "pre_pay_money": pre_pay_money,
  10253. "refund_sum": sum,
  10254. "doctor_info": doctor_info,
  10255. "hiliCostTotal": hiliCostTotal,
  10256. "hiliCostSelfTotal": hiliCostSelfTotal,
  10257. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10258. })
  10259. }
  10260. //func (c *HisApiController) GetFaPiaoDatas() {
  10261. // order_ids := c.GetString("order_ids")
  10262. // patient_id, _ := c.GetInt64("patient_id")
  10263. // adminUser := c.GetAdminUserInfo()
  10264. //
  10265. // orders := strings.Split(order_ids, ",")
  10266. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10267. //
  10268. // for _, item := range orders {
  10269. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10270. // order, _ := service.GetHisOrderByID(order_id)
  10271. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10272. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10273. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10274. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10275. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10276. //
  10277. // }
  10278. //
  10279. // var bedCostTotal float64 = 0 //床位总费
  10280. // var bedCostSelfTotal float64 = 0 //床位自费
  10281. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10282. //
  10283. // var operationCostTotal float64 = 0 //手术费
  10284. // var operationCostSelfTotal float64 = 0 //手术费
  10285. // var operationCostPartSelfTotal float64 = 0 //手术费
  10286. //
  10287. // var otherCostTotal float64 = 0 //其他费用
  10288. // var otherCostSelfTotal float64 = 0 //其他费用
  10289. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10290. //
  10291. // var materialCostTotal float64 = 0 //材料费
  10292. // var materialCostSelfTotal float64 = 0 //材料费
  10293. // var materialCostPartSelfTotal float64 = 0 //材料费
  10294. //
  10295. // var westernMedicineCostTotal float64 = 0 //西药费
  10296. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10297. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10298. //
  10299. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10300. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10301. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10302. //
  10303. // var checkCostTotal float64 = 0 //检查费
  10304. // var checkCostSelfTotal float64 = 0 //检查费
  10305. // var checkCostPartSelfTotal float64 = 0 //检查费
  10306. //
  10307. // var laboratoryCostTotal float64 = 0 //化验费
  10308. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10309. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10310. //
  10311. // var treatCostTotal float64 = 0 //治疗费用
  10312. // var treatCostSelfTotal float64 = 0 //治疗费用
  10313. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10314. //
  10315. // var zhenChaCostTotal float64 = 0 //其他费用
  10316. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10317. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10318. //
  10319. // decimal.DivisionPrecision = 2
  10320. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10321. //
  10322. // var balanceAccountsType int64
  10323. // if his.ID > 0 {
  10324. // balanceAccountsType = his.BalanceAccountsType
  10325. // } else {
  10326. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10327. // }
  10328. // if balanceAccountsType == 2 {
  10329. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10330. // for _, item := range orderInfos_two {
  10331. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10332. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10333. // item.MedChrgitmType = "09"
  10334. // }
  10335. //
  10336. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10337. // if item.HisPrescriptionProject.Type == 2 {
  10338. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10339. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10340. // case 0:
  10341. // item.MedChrgitmType = "0"
  10342. // break
  10343. // case 1:
  10344. // item.MedChrgitmType = "14"
  10345. // break
  10346. // case 2:
  10347. // item.MedChrgitmType = "05"
  10348. //
  10349. // break
  10350. // case 3:
  10351. // item.MedChrgitmType = "03"
  10352. //
  10353. // break
  10354. // case 4:
  10355. // item.MedChrgitmType = "03"
  10356. //
  10357. // break
  10358. // case 5:
  10359. // item.MedChrgitmType = "08"
  10360. //
  10361. // break
  10362. // case 6:
  10363. // item.MedChrgitmType = "14"
  10364. //
  10365. // break
  10366. // case 7:
  10367. // item.MedChrgitmType = "14"
  10368. //
  10369. // break
  10370. // case 8:
  10371. // item.MedChrgitmType = "03"
  10372. // break
  10373. // case 9:
  10374. // item.MedChrgitmType = "14"
  10375. // break
  10376. // case 10:
  10377. // item.MedChrgitmType = "14"
  10378. // break
  10379. // case 11:
  10380. // item.MedChrgitmType = "06"
  10381. // break
  10382. // case 12:
  10383. // item.MedChrgitmType = "12"
  10384. // break
  10385. // case 13:
  10386. // item.MedChrgitmType = "01"
  10387. // break
  10388. // case 14:
  10389. // item.MedChrgitmType = "04"
  10390. // break
  10391. // case 15:
  10392. // item.MedChrgitmType = "02"
  10393. // break
  10394. //
  10395. // }
  10396. //
  10397. // } else {
  10398. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10399. //
  10400. // case 1:
  10401. // item.MedChrgitmType = "14"
  10402. // break
  10403. // case 2:
  10404. // item.MedChrgitmType = "05"
  10405. //
  10406. // break
  10407. // case 3:
  10408. // item.MedChrgitmType = "03"
  10409. //
  10410. // break
  10411. // case 4:
  10412. // item.MedChrgitmType = "03"
  10413. //
  10414. // break
  10415. // case 5:
  10416. // item.MedChrgitmType = "08"
  10417. //
  10418. // break
  10419. // case 6:
  10420. // item.MedChrgitmType = "14"
  10421. //
  10422. // break
  10423. // case 7:
  10424. // item.MedChrgitmType = "14"
  10425. //
  10426. // break
  10427. // case 8:
  10428. // item.MedChrgitmType = "03"
  10429. // break
  10430. // case 9:
  10431. // item.MedChrgitmType = "14"
  10432. // break
  10433. //
  10434. // }
  10435. //
  10436. // }
  10437. //
  10438. // } else if item.HisPrescriptionProject.Type == 3 {
  10439. // item.MedChrgitmType = "08"
  10440. // }
  10441. // }
  10442. // }
  10443. //
  10444. // for _, item := range orderInfos_two {
  10445. // fmt.Println(item.MedChrgitmType)
  10446. // if item.MedChrgitmType == "01" { //床位费
  10447. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10448. // bedCostSelfTotal = bedCostTotal
  10449. // }
  10450. //
  10451. // if item.MedChrgitmType == "02" { //诊察费
  10452. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10453. // zhenChaCostSelfTotal = zhenChaCostTotal
  10454. // }
  10455. //
  10456. // if item.MedChrgitmType == "03" { //检查费
  10457. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10458. // checkCostSelfTotal = checkCostTotal
  10459. // }
  10460. //
  10461. // if item.MedChrgitmType == "04" { //化验费
  10462. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10463. // laboratoryCostSelfTotal = laboratoryCostTotal
  10464. // }
  10465. //
  10466. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10467. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10468. // treatCostSelfTotal = treatCostTotal
  10469. // }
  10470. //
  10471. // if item.MedChrgitmType == "06" { //手术费
  10472. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10473. // operationCostSelfTotal = treatCostTotal
  10474. // }
  10475. //
  10476. // if item.MedChrgitmType == "08" { //材料费
  10477. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10478. // materialCostSelfTotal = materialCostTotal
  10479. // }
  10480. //
  10481. // if item.MedChrgitmType == "09" { //西药费
  10482. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10483. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10484. // }
  10485. //
  10486. // if item.MedChrgitmType == "11" { //中成费
  10487. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10488. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10489. // }
  10490. //
  10491. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10492. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10493. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10494. // otherCostSelfTotal = otherCostTotal
  10495. // }
  10496. // } else {
  10497. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10498. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10499. // otherCostSelfTotal = otherCostTotal
  10500. // }
  10501. //
  10502. // }
  10503. //
  10504. // }
  10505. //
  10506. // } else {
  10507. // for _, item := range orderInfos {
  10508. // if item.MedChrgitmType == "01" { //床位费
  10509. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10510. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10511. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10512. // }
  10513. //
  10514. // if item.MedChrgitmType == "02" { //诊察费
  10515. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10516. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10517. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10518. // }
  10519. //
  10520. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10521. // if item.MedChrgitmType == "03" { //检查费
  10522. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10523. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10524. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10525. //
  10526. // }
  10527. // } else {
  10528. // if item.MedChrgitmType == "03" { //检查费
  10529. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10530. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10531. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10532. // }
  10533. //
  10534. // }
  10535. //
  10536. // if item.MedChrgitmType == "04" { //化验费
  10537. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10538. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10539. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10540. //
  10541. // }
  10542. //
  10543. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10544. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10545. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10546. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10547. //
  10548. // }
  10549. //
  10550. // if item.MedChrgitmType == "06" { //手术费
  10551. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10552. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10553. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10554. // }
  10555. //
  10556. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10557. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10558. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10559. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10560. // }
  10561. //
  10562. // if item.MedChrgitmType == "09" { //西药费
  10563. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10564. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10565. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10566. // }
  10567. //
  10568. // if item.MedChrgitmType == "11" { //中成费
  10569. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10570. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10571. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10572. // }
  10573. //
  10574. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10575. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10576. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10577. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10578. // }
  10579. //
  10580. // }
  10581. // }
  10582. // timeLayout := "2006-01-02"
  10583. // loc, _ := time.LoadLocation("Local")
  10584. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10585. // if err != nil {
  10586. // }
  10587. // startRecordDateTime := startTime.Unix()
  10588. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10589. // if err != nil {
  10590. // }
  10591. // endRecordDateTime := endTime.Unix()
  10592. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10593. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10594. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10595. //
  10596. // c.ServeSuccessJSON(map[string]interface{}{
  10597. // "order_number": order.Number, //业务流水号
  10598. // "id_card_no": his.IdCardNo, //社会保障号
  10599. // "department_name": department.Name, //科室
  10600. // "number": his.Number, //门诊号
  10601. // "date": order.SettleAccountsDate, //结算日期
  10602. // "name": order.PsnName, //姓名
  10603. // "gender": patient.Gender, //性别
  10604. // "psn_cash_money": order.PsnCashPay, //个人支付
  10605. // "pay_way": "门诊", //结算方式
  10606. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10607. // "admin_user_name": admin.UserName, //收款员
  10608. // "order": order,
  10609. // "order_info": orderInfos_two,
  10610. // "his": his,
  10611. // "bedCostTotal": bedCostTotal,
  10612. // "bedCostSelfTotal": bedCostSelfTotal,
  10613. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10614. // "operationCostTotal": operationCostTotal,
  10615. // "operationCostSelfTotal": operationCostSelfTotal,
  10616. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10617. // "otherCostTotal": otherCostTotal,
  10618. // "otherCostSelfTotal": otherCostSelfTotal,
  10619. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10620. // "materialCostTotal": materialCostTotal,
  10621. // "materialCostSelfTotal": materialCostSelfTotal,
  10622. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10623. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10624. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10625. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10626. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10627. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10628. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10629. // "checkCostTotal": checkCostTotal,
  10630. // "checkCostSelfTotal": checkCostSelfTotal,
  10631. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10632. // "laboratoryCostTotal": laboratoryCostTotal,
  10633. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10634. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10635. // "treatCostTotal": treatCostTotal,
  10636. // "treatCostSelfTotal": treatCostSelfTotal,
  10637. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10638. // "zhenChaCostTotal": zhenChaCostTotal,
  10639. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10640. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10641. // "his_hospital_record": his_hospital_record,
  10642. // "pre_pay_money": pre_pay_money,
  10643. // "refund_sum": sum,
  10644. // })
  10645. //
  10646. //}
  10647. func (this *HisApiController) GetIncomeStatisticsData() {
  10648. start_time := this.GetString("start_time")
  10649. end_time := this.GetString("end_time")
  10650. key_words := this.GetString("key_words")
  10651. limit, _ := this.GetInt64("limit")
  10652. page, _ := this.GetInt64("page")
  10653. if page <= 0 {
  10654. page = 1
  10655. }
  10656. if limit <= 0 {
  10657. limit = 10
  10658. }
  10659. statistics_type, _ := this.GetInt64("statistics_type")
  10660. admin := this.GetAdminUserInfo()
  10661. timeLayout := "2006-01-02"
  10662. loc, _ := time.LoadLocation("Local")
  10663. var theStartTIme int64
  10664. if len(start_time) > 0 {
  10665. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10666. if err != nil {
  10667. theStartTIme = 0
  10668. }
  10669. theStartTIme = theTime.Unix()
  10670. }
  10671. var theEndtTIme int64
  10672. if len(end_time) > 0 {
  10673. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10674. if err != nil {
  10675. theEndtTIme = 0
  10676. }
  10677. theEndtTIme = theTime.Unix()
  10678. }
  10679. if statistics_type == 1 {
  10680. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10681. this.ServeSuccessJSON(map[string]interface{}{
  10682. "list": list,
  10683. "total": total,
  10684. })
  10685. } else {
  10686. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10687. this.ServeSuccessJSON(map[string]interface{}{
  10688. "list": list,
  10689. "total": total,
  10690. })
  10691. }
  10692. }
  10693. func (c *HisApiController) PostProjectInformation() {
  10694. adminUser := c.GetAdminUserInfo()
  10695. orgId := adminUser.CurrentOrgId
  10696. dataBody := make(map[string]interface{}, 0)
  10697. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10698. if err != nil {
  10699. utils.ErrorLog(err.Error())
  10700. return
  10701. }
  10702. utils.ErrorLog("%v", dataBody)
  10703. var projectList []*models.HisProject
  10704. var total_goods []interface{}
  10705. tempProjects := dataBody["projects"].([]interface{})
  10706. total_goods = tempProjects
  10707. for index, projectMap := range tempProjects {
  10708. projectM := projectMap.(map[string]interface{})
  10709. var project models.HisProject
  10710. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10711. utils.ErrorLog("project_name")
  10712. return
  10713. }
  10714. project_name, _ := projectM["project_name"].(string)
  10715. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10716. err_log := models.ExportErrLog{
  10717. LogType: 6,
  10718. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10719. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10720. Status: 1,
  10721. CreateTime: time.Now().Unix(),
  10722. UpdateTime: time.Now().Unix(),
  10723. ExportTime: time.Now().Unix(),
  10724. }
  10725. service.CreateExportErrLog(&err_log)
  10726. continue
  10727. }
  10728. project.ProjectName = project_name
  10729. prices := projectM["price"].(string)
  10730. price, _ := strconv.ParseFloat(prices, 64)
  10731. if price <= 0 { //名字为空则生成一条导入错误日志
  10732. err_log := models.ExportErrLog{
  10733. LogType: 6,
  10734. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10735. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10736. Status: 1,
  10737. CreateTime: time.Now().Unix(),
  10738. UpdateTime: time.Now().Unix(),
  10739. ExportTime: time.Now().Unix(),
  10740. }
  10741. service.CreateExportErrLog(&err_log)
  10742. continue
  10743. }
  10744. project.Price = price
  10745. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10746. utils.ErrorLog("unit_id")
  10747. return
  10748. }
  10749. unit := projectM["unit"].(string)
  10750. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10751. err_log := models.ExportErrLog{
  10752. LogType: 6,
  10753. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10754. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10755. Status: 1,
  10756. CreateTime: time.Now().Unix(),
  10757. UpdateTime: time.Now().Unix(),
  10758. ExportTime: time.Now().Unix(),
  10759. }
  10760. service.CreateExportErrLog(&err_log)
  10761. continue
  10762. }
  10763. project.Unit = unit
  10764. cost_classify := projectM["cost_classify"].(string)
  10765. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10766. err_log := models.ExportErrLog{
  10767. LogType: 6,
  10768. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10769. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10770. Status: 1,
  10771. CreateTime: time.Now().Unix(),
  10772. UpdateTime: time.Now().Unix(),
  10773. ExportTime: time.Now().Unix(),
  10774. }
  10775. service.CreateExportErrLog(&err_log)
  10776. continue
  10777. }
  10778. var costClassify = "费用类别"
  10779. var cost_classify_id int64
  10780. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10781. if len(cost_classify) != 0 {
  10782. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10783. if errcode == gorm.ErrRecordNotFound {
  10784. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10785. dataconfig := models.DictDataconfig{
  10786. ParentId: costClassifyConfig.ID,
  10787. Module: "system",
  10788. OrgId: orgId,
  10789. Name: cost_classify,
  10790. FieldName: "",
  10791. Value: costConfig.Value + 1,
  10792. CreatedTime: "",
  10793. UpdatedTime: "",
  10794. CreateUserId: adminUser.AdminUser.Id,
  10795. Status: 1,
  10796. Remark: "",
  10797. DeleteIdSystem: 0,
  10798. Title: "",
  10799. Content: "",
  10800. Order: 0,
  10801. Code: "",
  10802. }
  10803. service.CreatedDicConfig(&dataconfig)
  10804. }
  10805. }
  10806. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10807. for _, it := range costClassList {
  10808. if cost_classify == it.Name {
  10809. cost_classify_id = int64(it.Value)
  10810. }
  10811. }
  10812. project.CostClassify = cost_classify_id
  10813. executive_section := projectM["executive_section"].(string)
  10814. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10815. err_log := models.ExportErrLog{
  10816. LogType: 6,
  10817. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10818. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10819. Status: 1,
  10820. CreateTime: time.Now().Unix(),
  10821. UpdateTime: time.Now().Unix(),
  10822. ExportTime: time.Now().Unix(),
  10823. }
  10824. service.CreateExportErrLog(&err_log)
  10825. continue
  10826. }
  10827. if len(executive_section) != 0 {
  10828. //查找科室是否有内容
  10829. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10830. if errcodedepart == gorm.ErrRecordNotFound {
  10831. department := models.XtHisDepartment{
  10832. Name: executive_section,
  10833. Status: 1,
  10834. UserOrgId: adminUser.CurrentOrgId,
  10835. CreatedTime: time.Now().Unix(),
  10836. }
  10837. service.CreateDePartment(&department)
  10838. }
  10839. }
  10840. var executive_section_id int64
  10841. departMentList, _ := service.GetAllDepartMent(orgId)
  10842. for _, it := range departMentList {
  10843. if executive_section == it.Name {
  10844. executive_section_id = it.ID
  10845. }
  10846. }
  10847. project.ExecutiveSection = executive_section_id
  10848. medical_coverage := projectM["medical_coverage"].(string)
  10849. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10850. err_log := models.ExportErrLog{
  10851. LogType: 6,
  10852. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10853. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10854. Status: 1,
  10855. CreateTime: time.Now().Unix(),
  10856. UpdateTime: time.Now().Unix(),
  10857. ExportTime: time.Now().Unix(),
  10858. }
  10859. service.CreateExportErrLog(&err_log)
  10860. continue
  10861. }
  10862. var medicalCoverage = "医保等级"
  10863. var medical_coverage_id int64
  10864. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10865. if len(medical_coverage) != 0 {
  10866. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10867. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10868. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10869. dataconfig := models.DictDataconfig{
  10870. ParentId: medicalCoverageConfig.ID,
  10871. Module: "system",
  10872. OrgId: orgId,
  10873. Name: medical_coverage,
  10874. FieldName: "",
  10875. Value: medicalCoverageConfig.Value + 1,
  10876. CreatedTime: "",
  10877. UpdatedTime: "",
  10878. CreateUserId: adminUser.AdminUser.Id,
  10879. Status: 1,
  10880. Remark: "",
  10881. DeleteIdSystem: 0,
  10882. Title: "",
  10883. Content: "",
  10884. Order: 0,
  10885. Code: "",
  10886. }
  10887. service.CreatedDicConfig(&dataconfig)
  10888. }
  10889. }
  10890. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10891. for _, it := range medicalCoverageList {
  10892. if medical_coverage == it.Name {
  10893. medical_coverage_id = int64(it.Value)
  10894. }
  10895. }
  10896. project.MedicalCoverage = medical_coverage_id
  10897. pinyin := projectM["pinyin"].(string)
  10898. project.Pinyin = pinyin
  10899. wubi := projectM["wubi"].(string)
  10900. project.Wubi = wubi
  10901. statistical_classification := projectM["statistical_classification"].(string)
  10902. var statisticalClassification = "统计分类"
  10903. var statistical_classification_id int64
  10904. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10905. if len(statistical_classification) != 0 {
  10906. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10907. if classificationerrcodes == gorm.ErrRecordNotFound {
  10908. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10909. dataconfig := models.DictDataconfig{
  10910. ParentId: classiFication.ID,
  10911. Module: "system",
  10912. OrgId: orgId,
  10913. Name: statistical_classification,
  10914. FieldName: "",
  10915. Value: classiFicationConfig.Value + 1,
  10916. CreatedTime: "",
  10917. UpdatedTime: "",
  10918. CreateUserId: adminUser.AdminUser.Id,
  10919. Status: 1,
  10920. Remark: "",
  10921. DeleteIdSystem: 0,
  10922. Title: "",
  10923. Content: "",
  10924. Order: 0,
  10925. Code: "",
  10926. }
  10927. service.CreatedDicConfig(&dataconfig)
  10928. }
  10929. }
  10930. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10931. for _, it := range classiFicationList {
  10932. if statistical_classification == it.Name {
  10933. statistical_classification_id = int64(it.Value)
  10934. }
  10935. }
  10936. project.StatisticalClassification = statistical_classification_id
  10937. disease_directory := int64(projectM["disease_directory"].(float64))
  10938. project.DiseaseDirectory = disease_directory
  10939. is_record := int64(projectM["is_record"].(float64))
  10940. project.IsRecord = is_record
  10941. medical_code := projectM["medical_code"].(string)
  10942. project.MedicalCode = medical_code
  10943. tube_color := projectM["tube_color"].(string)
  10944. var tubeColor = "试管颜色"
  10945. var tube_color_id int64
  10946. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10947. if len(tube_color) != 0 {
  10948. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10949. if errcodetube == gorm.ErrRecordNotFound {
  10950. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10951. dataconfig := models.DictDataconfig{
  10952. ParentId: tubeColorConfig.ID,
  10953. Module: "system",
  10954. OrgId: orgId,
  10955. Name: tube_color,
  10956. FieldName: "",
  10957. Value: tubeConfig.Value + 1,
  10958. CreatedTime: "",
  10959. UpdatedTime: "",
  10960. CreateUserId: adminUser.AdminUser.Id,
  10961. Status: 1,
  10962. Remark: "",
  10963. DeleteIdSystem: 0,
  10964. Title: "",
  10965. Content: "",
  10966. Order: 0,
  10967. Code: "",
  10968. }
  10969. service.CreatedDicConfig(&dataconfig)
  10970. }
  10971. }
  10972. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10973. for _, it := range tubeColorList {
  10974. if tube_color == it.Name {
  10975. tube_color_id = int64(it.Value)
  10976. }
  10977. }
  10978. project.TubeColor = tube_color_id
  10979. single_dose := projectM["single_dose"].(string)
  10980. project.SingleDose = single_dose
  10981. execution_frequency := projectM["execution_frequency"].(string)
  10982. project.ExecutionFrequency = execution_frequency
  10983. delivery_way := projectM["delivery_way"].(string)
  10984. project.DeliveryWay = delivery_way
  10985. number_days := projectM["number_days"].(string)
  10986. project.NumberDays = number_days
  10987. total := projectM["total"].(string)
  10988. project.Total = total
  10989. medical_status := int64(projectM["medical_status"].(float64))
  10990. project.MedicalStatus = medical_status
  10991. category := int64(projectM["category"].(float64))
  10992. project.Category = category
  10993. specail_project := int64(projectM["specail_project"].(float64))
  10994. project.SpecailProject = specail_project
  10995. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10996. project.SocialSecurityDirectoryCode = social_security_directory_code
  10997. remark := projectM["remark"].(string)
  10998. project.Remark = remark
  10999. record_date := projectM["record_date"].(string)
  11000. timeLayout := "2006-01-02"
  11001. loc, _ := time.LoadLocation("Local")
  11002. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11003. project.RecordDate = theTime.Unix()
  11004. projectList = append(projectList, &project)
  11005. }
  11006. export_time := time.Now().Unix()
  11007. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11008. if len(projectList) > 0 {
  11009. for _, item := range projectList {
  11010. hans := item.ProjectName // 要转换的汉字字符串
  11011. // 创建一个拼音转换器
  11012. p := pinyin.NewArgs()
  11013. // 将汉字转为拼音
  11014. pinyinSlice := pinyin.Pinyin(hans, p)
  11015. // 输出拼音
  11016. fmt.Println("Pinyin:", pinyinSlice)
  11017. // 获取首字母
  11018. firstLetter := ""
  11019. for _, py := range pinyinSlice {
  11020. if len(py) > 0 {
  11021. firstLetter += string(py[0][0])
  11022. }
  11023. }
  11024. item.FirstLetter = firstLetter
  11025. project := models.HisProject{
  11026. ProjectName: item.ProjectName,
  11027. Price: item.Price,
  11028. Unit: item.Unit,
  11029. CostClassify: item.CostClassify,
  11030. ExecutiveSection: item.ExecutiveSection,
  11031. MedicalCoverage: item.MedicalCoverage,
  11032. UserOrgId: orgId,
  11033. Status: 1,
  11034. CreatedTime: time.Now().Unix(),
  11035. Pinyin: item.Pinyin,
  11036. Wubi: item.Wubi,
  11037. StatisticalClassification: item.StatisticalClassification,
  11038. DiseaseDirectory: item.DiseaseDirectory,
  11039. IsRecord: item.IsRecord,
  11040. MedicalCode: item.MedicalCode,
  11041. TubeColor: item.TubeColor,
  11042. SingleDose: item.SingleDose,
  11043. DeliveryWay: item.DeliveryWay,
  11044. NumberDays: item.NumberDays,
  11045. Total: item.Total,
  11046. Category: item.Category,
  11047. MedicalStatus: item.MedicalStatus,
  11048. SpecailProject: item.SpecailProject,
  11049. RecordDate: item.RecordDate,
  11050. Remark: item.Remark,
  11051. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11052. ExecutionFrequency: item.ExecutionFrequency,
  11053. FirstLetter: item.FirstLetter,
  11054. }
  11055. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11056. if errcodeproject == gorm.ErrRecordNotFound {
  11057. service.CreateProjectInfomation(&project)
  11058. } else if errcodeproject == nil {
  11059. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11060. }
  11061. log := models.ExportLog{
  11062. LogType: 6,
  11063. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11064. TotalNum: int64(len(total_goods)),
  11065. FailNum: int64(len(errLogs)),
  11066. SuccessNum: int64(len(projectList)),
  11067. CreateTime: time.Now().Unix(),
  11068. UpdateTime: time.Now().Unix(),
  11069. ExportTime: export_time,
  11070. Status: 1,
  11071. }
  11072. service.CreateExportLog(&log)
  11073. c.ServeSuccessJSON(map[string]interface{}{
  11074. "msg": "导入成功",
  11075. "total_num": len(total_goods),
  11076. "success_num": len(projectList),
  11077. "fail_num": int64(len(errLogs)),
  11078. })
  11079. }
  11080. } else {
  11081. log := models.ExportLog{
  11082. LogType: 6,
  11083. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11084. TotalNum: int64(len(total_goods)),
  11085. FailNum: int64(len(errLogs)),
  11086. SuccessNum: int64(len(projectList)),
  11087. CreateTime: time.Now().Unix(),
  11088. UpdateTime: time.Now().Unix(),
  11089. ExportTime: export_time,
  11090. Status: 1,
  11091. }
  11092. service.CreateExportLog(&log)
  11093. c.ServeSuccessJSON(map[string]interface{}{
  11094. "msg": "导入成功",
  11095. "total_num": len(total_goods),
  11096. "success_num": len(projectList),
  11097. "fail_num": int64(len(errLogs)),
  11098. })
  11099. }
  11100. }
  11101. //func (this *HisApiController) EditProjectInformation(){
  11102. //
  11103. // id, _ := this.GetInt64("id")
  11104. // project_team := this.GetString("project_team")
  11105. // price := this.GetString("price")
  11106. // price_float, _ := strconv.ParseFloat(price, 64)
  11107. // pinyin := this.GetString("pinyin")
  11108. // wubi := this.GetString("wubi")
  11109. // tube_color, _ := this.GetInt64("tube_color")
  11110. // team_type, _ := this.GetInt64("team_type")
  11111. // remark := this.GetString("remark")
  11112. // ids := this.GetString("ids")
  11113. // item_id := this.GetString("item_id")
  11114. // projectTeam := models.XtHisProjectTeam{
  11115. // ProjectTeam: project_team,
  11116. // Price: price_float,
  11117. // Pinyin: pinyin,
  11118. // Wubi: wubi,
  11119. // TubeColor: tube_color,
  11120. // TeamType: team_type,
  11121. // Remark: remark,
  11122. // ProjectId: ids,
  11123. // ItemId: item_id,
  11124. // }
  11125. //
  11126. //
  11127. // dataBody := make(map[string]interface{}, 0)
  11128. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11129. // if err != nil {
  11130. // utils.ErrorLog(err.Error())
  11131. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11132. // return
  11133. // }
  11134. //
  11135. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11136. //
  11137. //
  11138. // if err != nil {
  11139. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11140. // return
  11141. // }
  11142. //
  11143. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11144. // infos, _ := dataBody["info"].([]interface{})
  11145. // if len(infos) > 0 {
  11146. // var ids []string
  11147. //
  11148. // for _, item := range infos {
  11149. // items := item.(map[string]interface{})
  11150. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11151. // utils.ErrorLog("id")
  11152. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11153. // return
  11154. // }
  11155. // id := int64(items["id"].(float64))
  11156. //
  11157. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11158. // utils.ErrorLog("type")
  11159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11160. // return
  11161. // }
  11162. // types := int64(items["type"].(float64))
  11163. //
  11164. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11165. // utils.ErrorLog("number")
  11166. // }
  11167. //
  11168. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11169. //
  11170. // projectList := models.XtHisProjectList{
  11171. // Number: number,
  11172. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11173. // ProjectId: id,
  11174. // Status: 1,
  11175. // CreatedTime: time.Now().Unix(),
  11176. // UpdatedTime: time.Now().Unix(),
  11177. // TeamId: projectTeam.ID,
  11178. // Type: types,
  11179. // }
  11180. // list := projectList
  11181. //
  11182. // service.CreateProjectList(&list)
  11183. //
  11184. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11185. //
  11186. // }
  11187. // ids_str := strings.Join(ids, ",")
  11188. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11189. // service.SaveProjectTeam(&projectTeam)
  11190. // this.ServeSuccessJSON(map[string]interface{}{
  11191. // "projectTeam": projectTeam,
  11192. // })
  11193. // }
  11194. // }
  11195. //}
  11196. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11197. name := c.GetString("name")
  11198. mode_id, _ := c.GetInt64("mode", 0)
  11199. types, _ := c.GetInt64("type", 0)
  11200. patient_id, _ := c.GetInt64("patient_id", 0)
  11201. types = 1
  11202. adminInfo := c.GetAdminUserInfo()
  11203. template := &models.HisPrescriptionTemplate{
  11204. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11205. PatientId: patient_id,
  11206. Type: types,
  11207. Status: 1,
  11208. Ctime: time.Now().Unix(),
  11209. Mtime: time.Now().Unix(),
  11210. Name: name,
  11211. Mode: mode_id,
  11212. }
  11213. dataBody := make(map[string]interface{}, 0)
  11214. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11215. if err != nil {
  11216. utils.ErrorLog(err.Error())
  11217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11218. return
  11219. }
  11220. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11221. //如果已经存在记录则删除处方
  11222. if template_one.ID > 0 {
  11223. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11224. var ids []int64
  11225. var org_id int64
  11226. for _, item := range ps {
  11227. org_id = c.GetAdminUserInfo().CurrentOrgId
  11228. ids = append(ids, item.ID)
  11229. }
  11230. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11231. if err2 == nil {
  11232. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11233. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11234. if len(prescriptions) > 0 {
  11235. for _, item := range prescriptions {
  11236. items := item.(map[string]interface{})
  11237. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11238. utils.ErrorLog("type")
  11239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11240. return
  11241. }
  11242. types := int64(items["type"].(float64))
  11243. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11244. utils.ErrorLog("med_type")
  11245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11246. return
  11247. }
  11248. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11249. ctime := time.Now().Unix()
  11250. prescription := &models.HisPrescriptionInfoTemplate{
  11251. PatientId: patient_id,
  11252. UserOrgId: adminInfo.CurrentOrgId,
  11253. Ctime: ctime,
  11254. Mtime: ctime,
  11255. Type: types,
  11256. Modifier: adminInfo.AdminUser.Id,
  11257. Creator: adminInfo.AdminUser.Id,
  11258. Status: 1,
  11259. PTemplateId: template_one.ID,
  11260. MedType: med_type,
  11261. }
  11262. service.CreateHisPrescriptionInfoTemplate(prescription)
  11263. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11264. advices := items["advices"].([]interface{})
  11265. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11266. ctime := time.Now().Unix()
  11267. mtime := ctime
  11268. if len(advices) > 0 {
  11269. for _, advice := range advices {
  11270. var s models.HisPrescriptionAdviceTemplate
  11271. s.PrescriptionId = prescription.ID
  11272. s.AdviceType = 2
  11273. s.StopState = 2
  11274. s.ExecutionState = 2
  11275. s.Status = 1
  11276. s.UserOrgId = adminInfo.CurrentOrgId
  11277. s.CreatedTime = ctime
  11278. s.UpdatedTime = mtime
  11279. s.PatientId = patient_id
  11280. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11281. if errcode > 0 {
  11282. c.ServeFailJSONWithSGJErrorCode(errcode)
  11283. return
  11284. }
  11285. service.CreateHisPrescriptionAdviceTemplate(&s)
  11286. }
  11287. }
  11288. }
  11289. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11290. projects := items["project"].([]interface{})
  11291. if len(projects) > 0 {
  11292. for _, project := range projects {
  11293. var p models.HisPrescriptionProjectTemplate
  11294. p.PrescriptionId = prescription.ID
  11295. p.Ctime = time.Now().Unix()
  11296. p.Mtime = time.Now().Unix()
  11297. p.PatientId = patient_id
  11298. p.UserOrgId = adminInfo.CurrentOrgId
  11299. p.Status = 1
  11300. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11301. if errcode > 0 {
  11302. c.ServeFailJSONWithSGJErrorCode(errcode)
  11303. return
  11304. }
  11305. service.CreateHisPrescriptionProjectTemplate(&p)
  11306. }
  11307. }
  11308. }
  11309. }
  11310. c.ServeSuccessJSON(map[string]interface{}{
  11311. "msg": "创建成功",
  11312. })
  11313. }
  11314. }
  11315. } else {
  11316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11317. return
  11318. }
  11319. } else {
  11320. err3 := service.CreateHisPrescriptionTemplate(template)
  11321. if err3 == nil {
  11322. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11323. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11324. if len(prescriptions) > 0 {
  11325. for _, item := range prescriptions {
  11326. items := item.(map[string]interface{})
  11327. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11328. utils.ErrorLog("type")
  11329. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11330. return
  11331. }
  11332. types := int64(items["type"].(float64))
  11333. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11334. utils.ErrorLog("med_type")
  11335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11336. return
  11337. }
  11338. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11339. ctime := time.Now().Unix()
  11340. prescription := &models.HisPrescriptionInfoTemplate{
  11341. PatientId: patient_id,
  11342. UserOrgId: adminInfo.CurrentOrgId,
  11343. Ctime: ctime,
  11344. Mtime: ctime,
  11345. Type: types,
  11346. Modifier: adminInfo.AdminUser.Id,
  11347. Creator: adminInfo.AdminUser.Id,
  11348. Status: 1,
  11349. PTemplateId: template.ID,
  11350. MedType: med_type,
  11351. }
  11352. service.CreateHisPrescriptionInfoTemplate(prescription)
  11353. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11354. advices := items["advices"].([]interface{})
  11355. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11356. ctime := time.Now().Unix()
  11357. mtime := ctime
  11358. if len(advices) > 0 {
  11359. for _, advice := range advices {
  11360. var s models.HisPrescriptionAdviceTemplate
  11361. s.PrescriptionId = prescription.ID
  11362. s.AdviceType = 2
  11363. s.StopState = 2
  11364. s.ExecutionState = 2
  11365. s.Status = 1
  11366. s.UserOrgId = adminInfo.CurrentOrgId
  11367. s.CreatedTime = ctime
  11368. s.UpdatedTime = mtime
  11369. s.PatientId = patient_id
  11370. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11371. if errcode > 0 {
  11372. c.ServeFailJSONWithSGJErrorCode(errcode)
  11373. return
  11374. }
  11375. service.CreateHisPrescriptionAdviceTemplate(&s)
  11376. }
  11377. }
  11378. }
  11379. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11380. projects := items["project"].([]interface{})
  11381. if len(projects) > 0 {
  11382. for _, project := range projects {
  11383. var p models.HisPrescriptionProjectTemplate
  11384. p.PrescriptionId = prescription.ID
  11385. p.Ctime = time.Now().Unix()
  11386. p.Mtime = time.Now().Unix()
  11387. p.PatientId = patient_id
  11388. p.UserOrgId = adminInfo.CurrentOrgId
  11389. p.Status = 1
  11390. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11391. if errcode > 0 {
  11392. c.ServeFailJSONWithSGJErrorCode(errcode)
  11393. return
  11394. }
  11395. service.CreateHisPrescriptionProjectTemplate(&p)
  11396. }
  11397. }
  11398. }
  11399. }
  11400. c.ServeSuccessJSON(map[string]interface{}{
  11401. "msg": "创建成功",
  11402. })
  11403. }
  11404. }
  11405. } else {
  11406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11407. return
  11408. }
  11409. }
  11410. }
  11411. func (c *HisApiController) PreSettle() {
  11412. id, _ := c.GetInt64("id")
  11413. record_time := c.GetString("record_time")
  11414. his_patient_id, _ := c.GetInt64("his_patient_id")
  11415. timeLayout := "2006-01-02"
  11416. loc, _ := time.LoadLocation("Local")
  11417. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11418. diagnosis_id := c.GetString("diagnosis")
  11419. sick_type, _ := c.GetInt64("sick_type")
  11420. reg_type, _ := c.GetInt64("p_type")
  11421. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11422. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11423. if err != nil {
  11424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11425. return
  11426. }
  11427. recordDateTime := theTime.Unix()
  11428. adminUser := c.GetAdminUserInfo()
  11429. var prescriptions []*models.HisPrescription
  11430. var start_time int64
  11431. var end_time int64
  11432. ids_str := c.GetString("ids")
  11433. ids_arr := strings.Split(ids_str, ",")
  11434. fmt.Println(reg_type)
  11435. if settle_accounts_type == 1 { //日结
  11436. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11437. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11438. } else {
  11439. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11440. }
  11441. fmt.Println(prescriptions)
  11442. } else { //月结
  11443. start_time_str := c.GetString("start_time")
  11444. end_time_str := c.GetString("end_time")
  11445. timeLayout := "2006-01-02"
  11446. loc, _ := time.LoadLocation("Local")
  11447. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11448. if err != nil {
  11449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11450. return
  11451. }
  11452. recordStartTime := theStartTime.Unix()
  11453. start_time = recordStartTime
  11454. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11455. if err != nil {
  11456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11457. return
  11458. }
  11459. recordEndTime := theEndTime.Unix()
  11460. end_time = recordEndTime
  11461. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11462. }
  11463. if reg_type == 1111 || reg_type == 1112 {
  11464. reg_type = 11
  11465. }
  11466. timestamp := time.Now().Unix()
  11467. tempTime := time.Unix(timestamp, 0)
  11468. timeFormat := tempTime.Format("20060102150405")
  11469. chrgBchno := rand.Intn(100000) + 10000
  11470. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11471. strconv.FormatInt(his.PatientId, 10)
  11472. var ids []int64
  11473. for _, item := range prescriptions {
  11474. ids = append(ids, item.ID)
  11475. }
  11476. fmt.Println(ids)
  11477. var total float64
  11478. for _, item := range prescriptions {
  11479. fmt.Println(item)
  11480. if item.Type == 1 { //药品
  11481. for _, subItem := range item.HisDoctorAdviceInfo {
  11482. total = total + (subItem.Price * subItem.PrescribingNumber)
  11483. }
  11484. }
  11485. if item.Type == 2 { //项目
  11486. for _, subItem := range item.HisPrescriptionProject {
  11487. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11488. total = total + (subItem.Price * cnt)
  11489. }
  11490. }
  11491. for _, subItem := range item.HisAdditionalCharge {
  11492. total = total + (subItem.Price * float64(subItem.Count))
  11493. }
  11494. }
  11495. allTotal := fmt.Sprintf("%.2f", total)
  11496. totals, _ := strconv.ParseFloat(allTotal, 64)
  11497. order := &models.HisOrder{
  11498. UserOrgId: adminUser.CurrentOrgId,
  11499. HisPatientId: his.ID,
  11500. PatientId: id,
  11501. SettleAccountsDate: recordDateTime,
  11502. Ctime: time.Now().Unix(),
  11503. Mtime: time.Now().Unix(),
  11504. Status: 1,
  11505. OrderStatus: 1,
  11506. MdtrtId: his.Number,
  11507. Number: chrg_bchno,
  11508. MedfeeSumamt: totals,
  11509. SettleEndTime: end_time,
  11510. SettleStartTime: start_time,
  11511. SettleType: settle_accounts_type,
  11512. PsnPartAmt: totals,
  11513. PsnCashPay: totals,
  11514. PType: 2,
  11515. IsPre: 1,
  11516. MedType: strconv.Itoa(int(reg_type)),
  11517. Diagnosis: diagnosis_id,
  11518. }
  11519. err = service.CreateOrder(order)
  11520. if err != nil {
  11521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11522. return
  11523. }
  11524. var customs []*Custom
  11525. for _, item := range prescriptions {
  11526. fmt.Println(item.Type)
  11527. if item.Type == 1 { //药品
  11528. for _, subItem := range item.HisDoctorAdviceInfo {
  11529. cus := &Custom{
  11530. AdviceId: subItem.ID,
  11531. ProjectId: 0,
  11532. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11533. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11534. FeedetlSn: subItem.FeedetlSn,
  11535. Price: fmt.Sprintf("%.2f", subItem.Price),
  11536. MedListCodg: subItem.MedListCodg,
  11537. Type: 1,
  11538. }
  11539. customs = append(customs, cus)
  11540. }
  11541. }
  11542. if item.Type == 2 { //项目
  11543. for _, subItem := range item.HisPrescriptionProject {
  11544. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11545. cus := &Custom{
  11546. AdviceId: 0,
  11547. ProjectId: subItem.ID,
  11548. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11549. Cut: fmt.Sprintf("%.2f", cnt),
  11550. FeedetlSn: subItem.FeedetlSn,
  11551. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11552. MedListCodg: subItem.MedListCodg,
  11553. Type: 2,
  11554. }
  11555. customs = append(customs, cus)
  11556. }
  11557. }
  11558. for _, item := range item.HisAdditionalCharge {
  11559. cus := &Custom{
  11560. ItemId: item.ID,
  11561. AdviceId: 0,
  11562. ProjectId: 0,
  11563. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11564. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11565. FeedetlSn: item.FeedetlSn,
  11566. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11567. MedListCodg: item.XtHisAddtionConfig.Code,
  11568. Type: 3,
  11569. }
  11570. customs = append(customs, cus)
  11571. }
  11572. }
  11573. fmt.Println(customs)
  11574. for _, item := range customs {
  11575. var advice_id int64 = 0
  11576. var project_id int64 = 0
  11577. var item_id int64 = 0
  11578. var types int64 = 0
  11579. if item.Type == 1 {
  11580. advice_id = item.AdviceId
  11581. project_id = 0
  11582. item_id = 0
  11583. } else if item.Type == 2 {
  11584. advice_id = 0
  11585. item_id = 0
  11586. project_id = item.ProjectId
  11587. } else if item.Type == 3 {
  11588. advice_id = 0
  11589. item_id = item.ItemId
  11590. project_id = 0
  11591. }
  11592. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11593. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11594. pric, _ := strconv.ParseFloat(item.Price, 32)
  11595. info := &models.HisOrderInfo{
  11596. OrderNumber: order.Number,
  11597. UploadDate: time.Now().Unix(),
  11598. AdviceId: advice_id,
  11599. DetItemFeeSumamt: detItemFeeSumamt,
  11600. Cnt: cut,
  11601. Pric: pric,
  11602. PatientId: id,
  11603. Status: 1,
  11604. Mtime: time.Now().Unix(),
  11605. Ctime: time.Now().Unix(),
  11606. UserOrgId: adminUser.CurrentOrgId,
  11607. HisPatientId: his.ID,
  11608. OrderId: order.ID,
  11609. ProjectId: project_id,
  11610. Type: types,
  11611. ItemId: item_id,
  11612. }
  11613. service.CreateOrderInfo(info)
  11614. }
  11615. his.SickType = sick_type
  11616. service.UpdataHisPateint(&his)
  11617. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11618. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11619. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11620. if err == nil {
  11621. c.ServeSuccessJSON(map[string]interface{}{
  11622. "msg": "结算成功",
  11623. })
  11624. }
  11625. }
  11626. type CustomOrderInfo struct {
  11627. Name string
  11628. Spec string
  11629. Unit string
  11630. Count float64
  11631. Price float64
  11632. Total float64
  11633. }
  11634. func (c *HisApiController) GetPrivateExpensesInfo() {
  11635. order_id, _ := c.GetInt64("id", 0)
  11636. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11637. order, _ := service.GetHisOrderByID(order_id)
  11638. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11639. if order.ID == 0 {
  11640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11641. return
  11642. }
  11643. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11644. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11645. org_id := c.GetAdminUserInfo().CurrentOrgId
  11646. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11647. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11648. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11649. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11650. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11651. //var orderInfos_four []*models.HisOrderInfoTwo
  11652. //for _, item := range orderInfos_three {
  11653. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11654. // item.HisPrescriptionProject.IsCheckTeam = 1
  11655. // orderInfos_four = append(orderInfos_four, item)
  11656. //
  11657. // }
  11658. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11659. // item.HisPrescriptionProject.IsCheckTeam = 2
  11660. // orderInfos_two = append(orderInfos_two, item)
  11661. // }
  11662. //}
  11663. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11664. //var cus_slice []CustomOrderInfo
  11665. //for _, item := range new_order_info {
  11666. // var cus CustomOrderInfo
  11667. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11668. // cus.Unit = ""
  11669. // cus.Spec = ""
  11670. // var total float64
  11671. // for _, subItem := range orderInfos_four {
  11672. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11673. // total = total + subItem.DetItemFeeSumamt
  11674. // fmt.Println(subItem.DetItemFeeSumamt)
  11675. // }
  11676. // }
  11677. // cus.Count = 1
  11678. // cus.Total = total
  11679. // cus_slice = append(cus_slice, cus)
  11680. //}
  11681. orderInfos = append(orderInfos, orderInfos_two...)
  11682. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11683. //orderInfos = append(orderInfos, orderInfos_three...)
  11684. //}/**/
  11685. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11686. c.ServeSuccessJSON(map[string]interface{}{
  11687. "order": order,
  11688. "order_info": orderInfos,
  11689. "patient": patient,
  11690. "admin_info": adminInfo,
  11691. "his": his,
  11692. "current_admin": role,
  11693. "org_config": miConfig,
  11694. //"new_order_info": cus_slice,
  11695. })
  11696. }
  11697. func (this *HisApiController) ChangeMedType() {
  11698. med_type := this.GetString("med_type")
  11699. old_med_type := this.GetString("old_med_type")
  11700. ids := this.GetString("ids")
  11701. settle_type, _ := this.GetInt64("settle_type")
  11702. start_time := this.GetString("start_time")
  11703. end_time := this.GetString("end_time")
  11704. ids_arr := strings.Split(ids, ",")
  11705. if settle_type == 1 { //日结
  11706. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11707. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11708. prescription.MedType = med_type
  11709. err := service.SaveHisPrescriptionTwo(&prescription)
  11710. if err == nil {
  11711. this.ServeSuccessJSON(map[string]interface{}{
  11712. "msg": "修改成功",
  11713. })
  11714. } else {
  11715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11716. return
  11717. }
  11718. } else if settle_type == 2 {
  11719. timeLayout := "2006-01-02"
  11720. loc, _ := time.LoadLocation("Local")
  11721. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11722. if err != nil {
  11723. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11724. return
  11725. }
  11726. recordStartTime := theStartTime.Unix()
  11727. start_time_timestamp := recordStartTime
  11728. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11729. if err != nil {
  11730. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11731. return
  11732. }
  11733. recordEndTime := theEndTime.Unix()
  11734. end_time_timestamp := recordEndTime
  11735. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11736. if updateErr == nil {
  11737. this.ServeSuccessJSON(map[string]interface{}{
  11738. "msg": "修改成功",
  11739. })
  11740. } else {
  11741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11742. return
  11743. }
  11744. }
  11745. }
  11746. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11747. patient_id, _ := c.GetInt64("patient_id")
  11748. his_patient_id, _ := c.GetInt64("his_patient_id")
  11749. record_date := c.GetString("record_date")
  11750. start_time := c.GetString("start_time")
  11751. end_time := c.GetString("end_time")
  11752. order_status, _ := c.GetInt64("type", 0)
  11753. p_type, _ := c.GetInt64("p_type", 0)
  11754. order_id, _ := c.GetInt64("order_id", 0)
  11755. timeLayout := "2006-01-02"
  11756. loc, _ := time.LoadLocation("Local")
  11757. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11758. if err != nil {
  11759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11760. return
  11761. }
  11762. recordDateTime := theTime.Unix()
  11763. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11764. if err != nil {
  11765. }
  11766. startRecordDateTime := startTime.Unix()
  11767. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11768. if err != nil {
  11769. }
  11770. endRecordDateTime := endTime.Unix()
  11771. admin := c.GetAdminUserInfo()
  11772. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11773. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11774. order, _ := service.GetHisOrderByID(order_id)
  11775. var monthPrescriptions []*models.HisPrescription
  11776. if order_status == 1 || order_status == 0 {
  11777. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11778. } else if order_status == 2 {
  11779. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11780. }
  11781. var settle_total float64
  11782. for _, item := range monthPrescriptions {
  11783. if len(item.HisPrescriptionProject) > 0 {
  11784. for _, subItem := range item.HisPrescriptionProject {
  11785. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11786. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11787. settle_total = settle_total + total
  11788. }
  11789. }
  11790. if len(item.HisDoctorAdviceInfo) > 0 {
  11791. for _, subItem := range item.HisDoctorAdviceInfo {
  11792. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11793. settle_total = settle_total + total
  11794. }
  11795. }
  11796. }
  11797. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11798. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11799. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11800. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11801. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11802. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11803. //获取所有科室信息
  11804. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11805. var dia string
  11806. for _, item := range month_p_info {
  11807. if len(dia) == 0 {
  11808. dia = item.Diagnosis
  11809. } else {
  11810. dia = dia + "," + item.Diagnosis
  11811. }
  11812. }
  11813. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11814. dia_arr = removeEmptyStrings(dia_arr)
  11815. c.ServeSuccessJSON(map[string]interface{}{
  11816. "his_info": his_patient_info,
  11817. "xt_info": xt_patient_info,
  11818. "case_history": case_history,
  11819. "info": patientPrescriptionInfo,
  11820. "last_info": lastPatientPrescriptionInfo,
  11821. "month_prescriptions": monthPrescriptions,
  11822. "order": order,
  11823. "doctors": doctors,
  11824. "department": department,
  11825. "settle_total": settle_total,
  11826. "dia_arr": dia_arr,
  11827. })
  11828. return
  11829. }
  11830. func removeEmptyStrings(input []string) []string {
  11831. var output []string
  11832. for _, s := range input {
  11833. if s != "" {
  11834. output = append(output, s)
  11835. }
  11836. }
  11837. return output
  11838. }
  11839. func removeDuplicates(input []string) []string {
  11840. seen := make(map[string]bool)
  11841. output := []string{}
  11842. for _, s := range input {
  11843. if _, exists := seen[s]; !exists {
  11844. seen[s] = true
  11845. output = append(output, s)
  11846. }
  11847. }
  11848. return output
  11849. }
  11850. func (c *HisApiController) GetHisMonthPatientInfo() {
  11851. patient_id, _ := c.GetInt64("patient_id")
  11852. his_patient_id, _ := c.GetInt64("his_patient_id")
  11853. record_date := c.GetString("record_date")
  11854. number := c.GetString("number")
  11855. start_time := c.GetString("start_time")
  11856. end_time := c.GetString("end_time")
  11857. p_type, _ := c.GetInt64("p_type")
  11858. timeLayout := "2006-01-02"
  11859. loc, _ := time.LoadLocation("Local")
  11860. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11861. if err != nil {
  11862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11863. return
  11864. }
  11865. recordDateTime := theTime.Unix()
  11866. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11867. if err != nil {
  11868. }
  11869. startRecordDateTime := startTime.Unix()
  11870. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11871. if err != nil {
  11872. }
  11873. endRecordDateTime := endTime.Unix()
  11874. admin := c.GetAdminUserInfo()
  11875. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11876. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11877. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11878. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11879. var settle_total float64
  11880. for _, item := range monthPrescriptions {
  11881. if len(item.HisPrescriptionProject) > 0 {
  11882. for _, subItem := range item.HisPrescriptionProject {
  11883. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11884. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11885. settle_total = settle_total + total
  11886. }
  11887. }
  11888. if len(item.HisDoctorAdviceInfo) > 0 {
  11889. for _, subItem := range item.HisDoctorAdviceInfo {
  11890. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11891. settle_total = settle_total + total
  11892. }
  11893. }
  11894. }
  11895. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11896. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11897. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11898. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11899. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11900. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11901. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11902. //获取所有科室信息
  11903. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11904. c.ServeSuccessJSON(map[string]interface{}{
  11905. "his_info": his_patient_info,
  11906. "xt_info": xt_patient_info,
  11907. "case_history": case_history,
  11908. "info": patientPrescriptionInfo,
  11909. "month_prescriptions": monthPrescriptions,
  11910. "order": order,
  11911. "doctors": doctors,
  11912. "department": department,
  11913. "count": count,
  11914. "drugStockConfig": drugStockConfig,
  11915. "last_info": lastPatientPrescriptionInfo,
  11916. "settle_total": settle_total,
  11917. })
  11918. return
  11919. }
  11920. func (c *HisApiController) GetAllOrder() {
  11921. org_id := c.GetAdminUserInfo().CurrentOrgId
  11922. orders, _ := service.GetNewHisOrderList(org_id)
  11923. c.ServeSuccessJSON(map[string]interface{}{
  11924. "order": orders,
  11925. })
  11926. return
  11927. }
  11928. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11929. newArr = make([]*models.HisOrderInfoTwo, 0)
  11930. for i := 0; i < len(arr); i++ {
  11931. repeat := false
  11932. for j := i + 1; j < len(arr); j++ {
  11933. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11934. repeat = true
  11935. break
  11936. }
  11937. }
  11938. if !repeat {
  11939. newArr = append(newArr, arr[i])
  11940. }
  11941. }
  11942. return
  11943. }
  11944. // 修改处方退库操作 参数传修改之前的处方数据
  11945. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11946. if advice.ExecutionState == 1 {
  11947. //查询该病人该药品是否有库存记录
  11948. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11949. if errcode == gorm.ErrRecordNotFound {
  11950. } else {
  11951. //退库
  11952. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11953. if advice.PrescribingNumberUnit == drug.MinUnit {
  11954. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11955. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11956. //退库
  11957. warehouseInfo := models.DrugWarehouseInfo{
  11958. StockMinNumber: prescribingNumber,
  11959. }
  11960. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11961. operation_time := time.Now().Unix()
  11962. creater := advice.AdviceDoctor
  11963. ctime := time.Now().Unix()
  11964. timeStr := time.Now().Format("2006-01-02")
  11965. timeArr := strings.Split(timeStr, "-")
  11966. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11967. total = total + 1
  11968. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11969. cancelStock := models.DrugCancelStock{
  11970. OrderNumber: orderNumber,
  11971. OperaTime: operation_time,
  11972. OrgId: advice.UserOrgId,
  11973. Creater: creater,
  11974. Ctime: ctime,
  11975. Status: 1,
  11976. ReturnTime: advice.AdviceDate,
  11977. Dealer: info.Dealer,
  11978. Manufacturer: info.Manufacturer,
  11979. Type: 1,
  11980. }
  11981. service.AddSigleDrugCancelStock(&cancelStock)
  11982. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11983. dealer, _ := service.GetDealerById(info.Dealer)
  11984. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11985. cancelStockInfo := models.DrugCancelStockInfo{
  11986. OrderNumber: cancelInfo.OrderNumber,
  11987. CancelStockId: cancelInfo.ID,
  11988. DrugId: info.DrugId,
  11989. Count: info.Count,
  11990. Status: 1,
  11991. Ctime: ctime,
  11992. OrgId: advice.UserOrgId,
  11993. Type: 1,
  11994. Manufacturer: manufactureName.ManufacturerName,
  11995. Dealer: dealer.DealerName,
  11996. Total: 0,
  11997. RetailPrice: info.RetailPrice,
  11998. RetailTotalPrice: info.RetailTotalPrice,
  11999. Price: info.Price,
  12000. RegisterAccount: "",
  12001. Remark: info.Remark,
  12002. BatchNumber: info.BatchNumber,
  12003. MaxUnit: info.CountUnit,
  12004. ProductDate: info.ProductDate,
  12005. ExpiryDate: info.ExpiryDate,
  12006. BatchNumberId: info.WarehouseInfoId,
  12007. }
  12008. flow := models.DrugFlow{
  12009. WarehousingId: 0,
  12010. DrugId: info.DrugId,
  12011. Number: "",
  12012. BatchNumber: info.BatchNumber,
  12013. Count: info.Count,
  12014. UserOrgId: advice.UserOrgId,
  12015. PatientId: 0,
  12016. SystemTime: ctime,
  12017. ConsumableType: 4,
  12018. IsSys: 0,
  12019. WarehousingOrder: "",
  12020. WarehouseOutId: 0,
  12021. WarehouseOutOrderNumber: "",
  12022. IsEdit: 0,
  12023. CancelStockId: cancelStock.ID,
  12024. CancelOrderNumber: cancelStock.OrderNumber,
  12025. Manufacturer: info.Manufacturer,
  12026. Dealer: info.Dealer,
  12027. Creator: advice.UserOrgId,
  12028. UpdateCreator: 0,
  12029. Status: 1,
  12030. Ctime: time.Now().Unix(),
  12031. Mtime: 0,
  12032. Price: info.Price,
  12033. WarehousingDetailId: 0,
  12034. WarehouseOutDetailId: 0,
  12035. CancelOutDetailId: 0,
  12036. ExpireDate: info.ExpiryDate,
  12037. ProductDate: info.ProductDate,
  12038. MaxUnit: info.CountUnit,
  12039. MinUnit: "",
  12040. }
  12041. service.CreatedCancelStock(cancelStockInfo)
  12042. service.CreateDrugFlowOne(flow)
  12043. } else {
  12044. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12045. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12046. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12047. warehouseInfo := models.DrugWarehouseInfo{
  12048. StockMinNumber: prescribingNumber,
  12049. }
  12050. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12051. }
  12052. operation_time := time.Now().Unix()
  12053. creater := advice.AdviceDoctor
  12054. ctime := time.Now().Unix()
  12055. timeStr := time.Now().Format("2006-01-02")
  12056. timeArr := strings.Split(timeStr, "-")
  12057. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12058. total = total + 1
  12059. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12060. cancelStock := models.DrugCancelStock{
  12061. OrderNumber: orderNumber,
  12062. OperaTime: operation_time,
  12063. OrgId: advice.UserOrgId,
  12064. Creater: creater,
  12065. Ctime: ctime,
  12066. Status: 1,
  12067. ReturnTime: advice.AdviceDate,
  12068. Dealer: info.Dealer,
  12069. Manufacturer: info.Manufacturer,
  12070. Type: 1,
  12071. }
  12072. service.AddSigleDrugCancelStock(&cancelStock)
  12073. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12074. dealer, _ := service.GetDealerById(info.Dealer)
  12075. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12076. cancelStockInfo := models.DrugCancelStockInfo{
  12077. OrderNumber: cancelInfo.OrderNumber,
  12078. CancelStockId: cancelInfo.ID,
  12079. DrugId: info.DrugId,
  12080. Count: info.Count,
  12081. Status: 1,
  12082. Ctime: ctime,
  12083. OrgId: advice.UserOrgId,
  12084. Type: 1,
  12085. Manufacturer: manufactureName.ManufacturerName,
  12086. Dealer: dealer.DealerName,
  12087. Total: 0,
  12088. RetailPrice: info.RetailPrice,
  12089. RetailTotalPrice: info.RetailTotalPrice,
  12090. Price: info.Price,
  12091. RegisterAccount: "",
  12092. Remark: info.Remark,
  12093. BatchNumber: info.BatchNumber,
  12094. MaxUnit: info.CountUnit,
  12095. ProductDate: info.ProductDate,
  12096. ExpiryDate: info.ExpiryDate,
  12097. BatchNumberId: info.WarehouseInfoId,
  12098. }
  12099. flow := models.DrugFlow{
  12100. WarehousingId: 0,
  12101. DrugId: info.DrugId,
  12102. Number: "",
  12103. BatchNumber: info.BatchNumber,
  12104. Count: info.Count,
  12105. UserOrgId: advice.UserOrgId,
  12106. PatientId: 0,
  12107. SystemTime: ctime,
  12108. ConsumableType: 4,
  12109. IsSys: 0,
  12110. WarehousingOrder: "",
  12111. WarehouseOutId: 0,
  12112. WarehouseOutOrderNumber: "",
  12113. IsEdit: 0,
  12114. CancelStockId: cancelStock.ID,
  12115. CancelOrderNumber: cancelStock.OrderNumber,
  12116. Manufacturer: info.Manufacturer,
  12117. Dealer: info.Dealer,
  12118. Creator: advice.AdviceDoctor,
  12119. UpdateCreator: 0,
  12120. Status: 1,
  12121. Ctime: time.Now().Unix(),
  12122. Mtime: 0,
  12123. Price: info.Price,
  12124. WarehousingDetailId: 0,
  12125. WarehouseOutDetailId: 0,
  12126. CancelOutDetailId: 0,
  12127. ExpireDate: info.ExpiryDate,
  12128. ProductDate: info.ProductDate,
  12129. MaxUnit: info.CountUnit,
  12130. MinUnit: "",
  12131. }
  12132. service.CreatedCancelStock(cancelStockInfo)
  12133. service.CreateDrugFlowOne(flow)
  12134. }
  12135. }
  12136. }
  12137. return err
  12138. }
  12139. func (this *HisApiController) DeleteNCDS() {
  12140. id, _ := this.GetInt64("id", 0)
  12141. if id > 0 {
  12142. service.DeletePsnNCDSRecordById(id)
  12143. this.ServeSuccessJSON(map[string]interface{}{
  12144. "msg": "删除成功",
  12145. })
  12146. } else {
  12147. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12148. return
  12149. }
  12150. }
  12151. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12152. id, _ := c.GetInt64("id")
  12153. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12154. c.ServeSuccessJSON(map[string]interface{}{
  12155. "advice": advice,
  12156. })
  12157. return
  12158. }
  12159. func (c *HisApiController) GetHisMonthChargePatientList() {
  12160. record_date := c.GetString("record_date")
  12161. start_time := c.GetString("start_time")
  12162. end_time := c.GetString("end_time")
  12163. timeLayout := "2006-01-02"
  12164. loc, _ := time.LoadLocation("Local")
  12165. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12166. if err != nil {
  12167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12168. return
  12169. }
  12170. if err != nil {
  12171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12172. return
  12173. }
  12174. recordDateTime := theTime.Unix()
  12175. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12176. if err != nil {
  12177. }
  12178. startRecordDateTime := startTime.Unix()
  12179. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12180. if err != nil {
  12181. }
  12182. endRecordDateTime := endTime.Unix()
  12183. adminInfo := c.GetAdminUserInfo()
  12184. var tempMonthChargePatients []*service.MonthChargePatients
  12185. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12186. for _, item := range tempPatients {
  12187. //过滤没有处方的
  12188. if len(item.HisPrescription) == 0 {
  12189. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12190. }
  12191. }
  12192. c.ServeSuccessJSON(map[string]interface{}{
  12193. "list": tempMonthChargePatients,
  12194. })
  12195. }
  12196. // PrescriptionDifference 医嘱数量差值结构体
  12197. type PrescriptionDrugDifference struct {
  12198. DrugID int64 //基础库药品id
  12199. ID int64 //医嘱id
  12200. Difference float64 //差值
  12201. Unit string //单位
  12202. }
  12203. type PrescriptionGoodDifference struct {
  12204. GoodID int64 //基础库项目耗材id
  12205. ID int64 //医嘱id
  12206. Difference int64 //差值
  12207. Unit string //单位
  12208. Type int64 //类型
  12209. }
  12210. type EditCustomData struct {
  12211. adviceList []*models.HisDoctorAdviceInfo
  12212. projectList []*models.HisPrescriptionProject
  12213. }
  12214. type SrcCustomData struct {
  12215. adviceList []*models.HisDoctorAdviceInfo
  12216. projectList []*models.HisPrescriptionProject
  12217. }
  12218. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12219. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12220. differences := make([]*PrescriptionDrugDifference, 0)
  12221. // 创建一个 map 来存储第一个切片中的药品信息
  12222. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12223. for _, advice := range firstPrescription {
  12224. firstMap[advice.DrugId] = advice
  12225. }
  12226. // 遍历第二个切片中的药品信息,并比较数量差值
  12227. for _, advice := range secondPrescription {
  12228. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12229. diff := &PrescriptionDrugDifference{
  12230. DrugID: advice.DrugId,
  12231. ID: firstAdvice.ID,
  12232. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12233. Unit: firstAdvice.PrescribingNumberUnit,
  12234. }
  12235. differences = append(differences, diff)
  12236. }
  12237. }
  12238. return differences
  12239. }
  12240. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12241. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12242. differences := make([]*PrescriptionGoodDifference, 0)
  12243. // 创建一个 map 来存储第一个切片中的耗材信息
  12244. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12245. for _, good := range firstPrescription {
  12246. firstMap[good.ProjectId] = good
  12247. }
  12248. // 遍历第二个切片中的耗材信息,并比较数量差值
  12249. for _, good := range secondPrescription {
  12250. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12251. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12252. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12253. diff := &PrescriptionGoodDifference{
  12254. GoodID: good.ProjectId,
  12255. ID: firstGood.ID,
  12256. Difference: count - firstCount,
  12257. Unit: firstGood.Unit,
  12258. Type: firstGood.Type,
  12259. }
  12260. differences = append(differences, diff)
  12261. }
  12262. }
  12263. return differences
  12264. }
  12265. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12266. var adviceList []*models.HisDoctorAdviceInfo
  12267. var projectList []*models.HisPrescriptionProject
  12268. var advice_ids []int64
  12269. var project_ids []int64
  12270. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12271. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12272. //var tempPrescription *models.HisPrescriptionProjectscription
  12273. if len(prescriptions) > 0 {
  12274. for _, item := range prescriptions {
  12275. items := item.(map[string]interface{})
  12276. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12277. advices := items["advices"].([]interface{})
  12278. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12279. groupNo := int64(0)
  12280. ctime := time.Now().Unix()
  12281. mtime := ctime
  12282. if len(advices) > 0 {
  12283. for _, advice := range advices {
  12284. var s models.HisDoctorAdviceInfo
  12285. s.AdviceType = 2
  12286. s.StopState = 2
  12287. s.ExecutionState = 2
  12288. s.Status = 1
  12289. s.Groupno = groupNo
  12290. s.CreatedTime = ctime
  12291. s.UpdatedTime = mtime
  12292. s.IsSettle = 2
  12293. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12294. //存储切片中
  12295. if s.ID > 0 {
  12296. advice_ids = append(advice_ids, s.ID)
  12297. adviceList = append(adviceList, &s)
  12298. }
  12299. }
  12300. }
  12301. }
  12302. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12303. projects := items["project"].([]interface{})
  12304. if len(projects) > 0 {
  12305. for _, project := range projects {
  12306. var p models.HisPrescriptionProject
  12307. p.Ctime = time.Now().Unix()
  12308. p.Mtime = time.Now().Unix()
  12309. p.Status = 1
  12310. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12311. if p.ID > 0 {
  12312. project_ids = append(project_ids, p.ID)
  12313. projectList = append(projectList, &p)
  12314. }
  12315. }
  12316. }
  12317. }
  12318. }
  12319. }
  12320. }
  12321. editCustomData.projectList = projectList
  12322. editCustomData.adviceList = adviceList
  12323. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12324. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12325. srcCustomData.adviceList = list
  12326. srcCustomData.projectList = list2
  12327. return
  12328. }