his_api_controller.go 504KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985
  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. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "his_info": his_patient_info,
  1461. "xt_info": xt_patient_info,
  1462. "prescription": prescriptions,
  1463. "case_history": case_history,
  1464. "info": patientPrescriptionInfo,
  1465. //"month_prescriptions": monthPrescriptions,
  1466. "order": order,
  1467. "doctors": doctors,
  1468. "department": department,
  1469. "sch_prescriptions": sch_prescriptions,
  1470. "last_prescriptions": last_prescriptions,
  1471. "schedule": sch,
  1472. "count": count,
  1473. "drugStockConfig": drugStockConfig,
  1474. "last_info": lastPatientPrescriptionInfo,
  1475. })
  1476. return
  1477. }
  1478. func (c *HisApiController) GetHisPrescriptionConfig() {
  1479. adminInfo := c.GetAdminUserInfo()
  1480. //获取医嘱模版
  1481. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1483. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1484. //获取所有基础药
  1485. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1486. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1487. if config.ID > 0 && config.IsOpen == 1 {
  1488. for _, item := range drugs {
  1489. var index = 0
  1490. for _, subItem := range item.OtherDrugWarehouseInfo {
  1491. if index == 0 {
  1492. index = index + 1
  1493. if subItem.RetailPrice > 0 {
  1494. item.MinPrice = subItem.RetailPrice
  1495. }
  1496. }
  1497. }
  1498. }
  1499. }
  1500. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1501. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1502. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1503. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1504. //获取所有科室信息
  1505. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1506. //获取诊断信息
  1507. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1508. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1509. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1510. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1511. //获取是否开启保存耗材出库的开关
  1512. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "drugs": drugs,
  1515. "advices_template": advices,
  1516. "drugways": drugways,
  1517. "efs": efs,
  1518. "doctors": doctors,
  1519. "department": department,
  1520. "sick": sick,
  1521. "additions": additions,
  1522. "diagnose": diagnose,
  1523. "manufacturers": manufacturers,
  1524. "goodOutOpen": goodOutOpen,
  1525. "patientDiagnose": patientDiagnose,
  1526. })
  1527. }
  1528. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1529. //获取所有基础药
  1530. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1531. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1532. if config.ID > 0 && config.IsOpen == 1 {
  1533. for _, item := range drugs {
  1534. var index = 0
  1535. for _, subItem := range item.OtherDrugWarehouseInfo {
  1536. if index == 0 {
  1537. index = index + 1
  1538. if subItem.RetailPrice > 0 {
  1539. item.MinPrice = subItem.RetailPrice
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1546. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1547. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1548. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1551. //获取诊断信息
  1552. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1553. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1554. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1555. //获取是否开启保存耗材出库的开关
  1556. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1557. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1558. c.ServeSuccessJSON(map[string]interface{}{
  1559. "drugs": drugs,
  1560. "advices_template": advices,
  1561. "drugways": drugways,
  1562. "efs": efs,
  1563. "doctors": doctors,
  1564. "department": department,
  1565. "sick": sick,
  1566. "additions": additions,
  1567. "diagnose": diagnose,
  1568. "manufacturers": manufacturers,
  1569. "goodOutOpen": goodOutOpen,
  1570. "patientDiagnose": patientDiagnose,
  1571. })
  1572. }
  1573. }
  1574. func (c *HisApiController) CreateHisPrescription() {
  1575. record_date := c.GetString("record_date")
  1576. patient_id, _ := c.GetInt64("patient_id")
  1577. reg_type, _ := c.GetInt64("reg_type")
  1578. diagnose := c.GetString("diagnose")
  1579. sick_type, _ := c.GetInt64("sick_type")
  1580. sick_history := c.GetString("sick_history")
  1581. doctor_id, _ := c.GetInt64("doctor", 0)
  1582. department, _ := c.GetInt64("department", 0)
  1583. his_patient_id, _ := c.GetInt64("his_patient_id")
  1584. p_type, _ := c.GetInt64("p_type")
  1585. patient_diagnose := c.GetString("patient_diagnose")
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //edit, src := GetCompareData(dataBody)
  1594. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1595. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1596. //fmt.Println(drugResult)
  1597. //fmt.Println(goodResult)
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. adminInfo := c.GetAdminUserInfo()
  1606. recordDateTime := theTime.Unix()
  1607. //查询默认出库仓库库存
  1608. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1610. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1611. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1612. if len(lists) == 1 {
  1613. his_patient_id = lists[0].ID
  1614. }
  1615. }
  1616. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1617. //自动出库的开关开启
  1618. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1619. //自动出库
  1620. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1621. //耗材保存处方出库
  1622. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1623. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1624. //已发药和已收费限制逻辑
  1625. isMidicine := false
  1626. isCharge := false
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1633. utils.ErrorLog("id")
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. id := int64(items["id"].(float64))
  1638. if id > 0 {
  1639. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1640. if err != nil {
  1641. if new_prescription.OrderStatus == 4 {
  1642. isCharge = true
  1643. }
  1644. }
  1645. }
  1646. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1647. advices := items["advices"].([]interface{})
  1648. if len(advices) > 0 {
  1649. for _, advice := range advices {
  1650. var adviceId int64
  1651. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1652. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1653. }
  1654. if adviceId > 0 {
  1655. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1656. if err == nil {
  1657. if his_advice_info.IsMedicine == 1 {
  1658. isMidicine = true
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. }
  1667. }
  1668. if isMidicine == true {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1670. return
  1671. }
  1672. if isCharge == true {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1674. return
  1675. }
  1676. // 开始主事务
  1677. db := service.XTWriteDB()
  1678. tx := db.Begin()
  1679. // 在函数结束时处理事务回滚
  1680. defer func() {
  1681. if r := recover(); r != nil {
  1682. tx.Rollback()
  1683. }
  1684. }()
  1685. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1686. //药品发药出库
  1687. if pharmacyConfig.IsOpen == 1 {
  1688. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1689. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1690. if len(prescriptions) > 0 {
  1691. for _, item := range prescriptions {
  1692. items := item.(map[string]interface{})
  1693. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1694. advices := items["advices"].([]interface{})
  1695. if len(advices) > 0 {
  1696. for _, advice := range advices {
  1697. var drug_id int64
  1698. var prescribing_number float64
  1699. var prescribingNumberUnit string
  1700. var adviceId int64
  1701. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1702. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1703. }
  1704. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1705. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1706. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1709. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1710. }
  1711. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1712. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1713. }
  1714. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1715. if drug.ID == 0 {
  1716. tx.Rollback()
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. //查询药品的所有库存
  1721. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1722. var total_count int64
  1723. for _, it := range list {
  1724. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1725. }
  1726. totals := strconv.FormatInt(total_count, 10)
  1727. //查询该药品是否存在开药记录
  1728. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1729. //新增处方盘点库存是否充足
  1730. if advicelist.ID == 0 {
  1731. all_count, _ := strconv.ParseFloat(totals, 64)
  1732. if prescribingNumberUnit == drug.MinUnit {
  1733. if drug.IsUse != 1 {
  1734. if drug.IsProject == 0 || drug.IsProject == 2 {
  1735. if all_count == 0 {
  1736. tx.Rollback()
  1737. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1738. return
  1739. }
  1740. if prescribing_number > all_count {
  1741. tx.Rollback()
  1742. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1743. return
  1744. }
  1745. }
  1746. }
  1747. }
  1748. if prescribingNumberUnit == drug.MaxUnit {
  1749. num := prescribing_number * float64(drug.MinNumber)
  1750. if drug.IsUse != 1 {
  1751. if drug.IsProject == 0 || drug.IsProject == 2 {
  1752. if all_count == 0 {
  1753. tx.Rollback()
  1754. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1755. return
  1756. }
  1757. if num > all_count {
  1758. tx.Rollback()
  1759. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1760. return
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1767. //不使用保存处方出库
  1768. if drugOutConfig.IsOpen != 1 {
  1769. //修改处方
  1770. for _, advice := range advices {
  1771. var drug_id int64
  1772. var prescribing_number float64
  1773. var prescribingNumberUnit string
  1774. var prescribingNumber string
  1775. var adviceId int64
  1776. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1777. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1778. }
  1779. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1780. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1781. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1782. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1783. }
  1784. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1785. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1786. }
  1787. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1788. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1789. }
  1790. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1791. if drug.ID == 0 {
  1792. tx.Rollback()
  1793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1794. return
  1795. }
  1796. //查询药品的所有库存
  1797. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1798. var total_count int64
  1799. for _, it := range list {
  1800. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1801. }
  1802. totals := strconv.FormatInt(total_count, 10)
  1803. //查询该药品是否存在开药记录
  1804. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1805. //新增处方
  1806. if advicelist.ID == 0 {
  1807. all_count, _ := strconv.ParseFloat(totals, 64)
  1808. if prescribingNumberUnit == drug.MinUnit {
  1809. if drug.IsUse != 1 {
  1810. if drug.IsProject == 0 || drug.IsProject == 2 {
  1811. if all_count == 0 {
  1812. tx.Rollback()
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. if prescribing_number > all_count {
  1817. tx.Rollback()
  1818. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1819. return
  1820. }
  1821. }
  1822. }
  1823. } else {
  1824. if prescribingNumberUnit == drug.MaxUnit {
  1825. num := prescribing_number * float64(drug.MinNumber)
  1826. if drug.IsUse != 1 {
  1827. if drug.IsProject == 0 || drug.IsProject == 2 {
  1828. if all_count == 0 {
  1829. tx.Rollback()
  1830. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1831. return
  1832. }
  1833. if num > all_count {
  1834. tx.Rollback()
  1835. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1836. return
  1837. }
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. //修改处方
  1844. if advicelist.ID > 0 {
  1845. var device_number int64
  1846. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1849. device_number = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1853. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1854. device_number = prescribingNumberInt
  1855. }
  1856. var number_count int64
  1857. if prescribingNumberUnit == drug.MaxUnit {
  1858. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1859. number_count = prescribingNumberInt * drug.MinNumber
  1860. }
  1861. if prescribingNumberUnit == drug.MinUnit {
  1862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1863. number_count = prescribingNumberInt
  1864. }
  1865. //如果修改的数量大于之前修改的数量
  1866. if (number_count - device_number) > 0 {
  1867. //如果修改的差数量 大于库存数量
  1868. if drug.IsUse != 1 {
  1869. if (number_count - device_number) > total_count {
  1870. tx.Rollback()
  1871. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1872. return
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. //已发药和已收费限制逻辑
  1887. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1888. //校验库存总量
  1889. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1890. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1891. if len(prescriptions) > 0 {
  1892. for _, item := range prescriptions {
  1893. items := item.(map[string]interface{})
  1894. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1895. advices := items["advices"].([]interface{})
  1896. if len(advices) > 0 {
  1897. for _, advice := range advices {
  1898. var drug_id int64
  1899. var prescribing_number float64
  1900. var prescribingNumberUnit string
  1901. var adviceId int64
  1902. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1903. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1904. }
  1905. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1906. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1907. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1908. }
  1909. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1910. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1911. }
  1912. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1913. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1914. }
  1915. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1916. if drug.ID == 0 {
  1917. tx.Rollback()
  1918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1919. return
  1920. }
  1921. //查询药品的所有库存
  1922. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1923. var total_count int64
  1924. for _, it := range list {
  1925. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1926. }
  1927. totals := strconv.FormatInt(total_count, 10)
  1928. //查询该药品是否存在开药记录
  1929. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1930. //查询最新批次库存
  1931. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1932. var batch_number_count int64
  1933. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1934. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1935. //新增处方
  1936. if advicelist.ID == 0 {
  1937. all_count, _ := strconv.ParseFloat(totals, 64)
  1938. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1939. if prescribingNumberUnit == drug.MinUnit {
  1940. if drug.IsUse != 1 {
  1941. if drug.IsProject == 0 || drug.IsProject == 2 {
  1942. if all_count == 0 {
  1943. tx.Rollback()
  1944. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1945. return
  1946. }
  1947. if prescribing_number > all_count {
  1948. tx.Rollback()
  1949. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1950. return
  1951. }
  1952. }
  1953. if adminInfo.CurrentOrgId == 10215 {
  1954. if prescribing_number > batch_number_all_count {
  1955. tx.Rollback()
  1956. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1957. return
  1958. }
  1959. }
  1960. }
  1961. }
  1962. if prescribingNumberUnit == drug.MaxUnit {
  1963. num := prescribing_number * float64(drug.MinNumber)
  1964. if drug.IsUse != 1 {
  1965. if drug.IsProject == 0 || drug.IsProject == 2 {
  1966. if all_count == 0 {
  1967. tx.Rollback()
  1968. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1969. return
  1970. }
  1971. if num > all_count {
  1972. tx.Rollback()
  1973. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1974. return
  1975. }
  1976. }
  1977. if adminInfo.CurrentOrgId == 10215 {
  1978. if num > batch_number_all_count {
  1979. tx.Rollback()
  1980. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1981. return
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1988. if drugOutConfig.IsOpen != 1 {
  1989. //修改处方
  1990. for _, advice := range advices {
  1991. var drug_id int64
  1992. var prescribing_number float64
  1993. var prescribingNumberUnit string
  1994. var prescribingNumber string
  1995. var adviceId int64
  1996. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1997. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1998. }
  1999. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2000. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2001. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2002. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2003. }
  2004. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2005. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2006. }
  2007. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2008. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2009. }
  2010. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2011. if drug.ID == 0 {
  2012. tx.Rollback()
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2014. return
  2015. }
  2016. //查询药品的所有库存
  2017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2018. var total_count int64
  2019. for _, it := range list {
  2020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2021. }
  2022. totals := strconv.FormatInt(total_count, 10)
  2023. //查询该药品是否存在开药记录
  2024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2025. //新增处方
  2026. if advicelist.ID == 0 {
  2027. //查询最新批次库存
  2028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2029. var batch_number_count int64
  2030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2032. all_count, _ := strconv.ParseFloat(totals, 64)
  2033. if prescribingNumberUnit == drug.MinUnit {
  2034. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2035. if drug.IsUse != 1 {
  2036. if drug.IsProject == 0 || drug.IsProject == 2 {
  2037. if all_count == 0 {
  2038. tx.Rollback()
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2040. return
  2041. }
  2042. if prescribing_number > all_count {
  2043. tx.Rollback()
  2044. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2045. return
  2046. }
  2047. }
  2048. if adminInfo.CurrentOrgId == 10215 {
  2049. if prescribing_number > batch_number_all_count {
  2050. tx.Rollback()
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2052. return
  2053. }
  2054. }
  2055. }
  2056. } else {
  2057. if prescribingNumberUnit == drug.MaxUnit {
  2058. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2059. num := prescribing_number * float64(drug.MinNumber)
  2060. if drug.IsUse != 1 {
  2061. if drug.IsProject == 0 || drug.IsProject == 2 {
  2062. if all_count == 0 {
  2063. tx.Rollback()
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2065. return
  2066. }
  2067. if num > all_count {
  2068. tx.Rollback()
  2069. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2070. return
  2071. }
  2072. }
  2073. if adminInfo.CurrentOrgId == 10215 {
  2074. if prescribing_number > batch_number_all_count {
  2075. tx.Rollback()
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2077. return
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. }
  2084. //修改处方
  2085. if advicelist.ID > 0 {
  2086. //查询最新批次库存
  2087. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2088. var batch_number_count int64
  2089. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2090. var device_number int64
  2091. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt * drug.MinNumber
  2095. }
  2096. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2097. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2099. device_number = prescribingNumberInt
  2100. }
  2101. var number_count int64
  2102. if prescribingNumberUnit == drug.MaxUnit {
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2104. number_count = prescribingNumberInt * drug.MinNumber
  2105. }
  2106. if prescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt
  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. fmt.Println("sum_in_count", sum_in_count)
  2161. //如果修改的数量大于有库存的第一个批次
  2162. if number_count > sum_in_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. if pharmacyConfig.IsOpen != 1 {
  2173. if device_number != number_count {
  2174. // 查询该药品最后一次出库记录
  2175. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2176. //回退库存
  2177. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2178. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2179. }
  2180. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2181. var stock_max_number int64
  2182. var stock_min_number int64
  2183. if number_count >= drug.MinNumber {
  2184. stock_max_number = device_number / drug.MinNumber
  2185. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2186. stock_min_number = device_number % drug.MinNumber
  2187. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2188. } else {
  2189. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2190. }
  2191. }
  2192. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2193. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2194. }
  2195. //删除记录
  2196. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2197. //查询默认仓库剩余多少库存
  2198. var sum_count int64
  2199. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2200. for _, its := range stockInfo {
  2201. if its.MaxUnit == drug.MaxUnit {
  2202. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2203. }
  2204. sum_count += its.StockMaxNumber + its.StockMinNumber
  2205. }
  2206. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. //保存处方开药
  2213. if drugOutConfig.IsOpen == 1 {
  2214. //修改处方
  2215. for _, advice := range advices {
  2216. var drug_id int64
  2217. var prescribing_number float64
  2218. var prescribingNumberUnit string
  2219. var prescribingNumber string
  2220. var adviceId int64
  2221. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2222. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2223. }
  2224. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2225. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2226. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2227. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2228. }
  2229. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2230. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2231. }
  2232. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2233. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2234. }
  2235. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2236. if drug.ID == 0 {
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2238. return
  2239. }
  2240. //查询药品的所有库存
  2241. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2242. var total_count int64
  2243. for _, it := range list {
  2244. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2245. }
  2246. totals := strconv.FormatInt(total_count, 10)
  2247. //查询该药品是否存在开药记录
  2248. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2249. //新增处方
  2250. if advicelist.ID == 0 {
  2251. //查询最新批次库存
  2252. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2253. var batch_number_count int64
  2254. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2255. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2256. all_count, _ := strconv.ParseFloat(totals, 64)
  2257. if prescribingNumberUnit == drug.MinUnit {
  2258. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2259. if drug.IsUse != 1 {
  2260. if drug.IsProject == 0 || drug.IsProject == 2 {
  2261. if all_count == 0 {
  2262. tx.Rollback()
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2264. return
  2265. }
  2266. if prescribing_number > all_count {
  2267. tx.Rollback()
  2268. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2269. return
  2270. }
  2271. }
  2272. if adminInfo.CurrentOrgId == 10215 {
  2273. if prescribing_number > batch_number_all_count {
  2274. tx.Rollback()
  2275. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2276. return
  2277. }
  2278. }
  2279. }
  2280. } else {
  2281. if prescribingNumberUnit == drug.MaxUnit {
  2282. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2283. num := prescribing_number * float64(drug.MinNumber)
  2284. if drug.IsUse != 1 {
  2285. if drug.IsProject == 0 || drug.IsProject == 2 {
  2286. if all_count == 0 {
  2287. tx.Rollback()
  2288. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2289. return
  2290. }
  2291. if num > all_count {
  2292. tx.Rollback()
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. }
  2297. if adminInfo.CurrentOrgId == 10215 {
  2298. if prescribing_number > batch_number_all_count {
  2299. tx.Rollback()
  2300. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2301. return
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. //修改处方
  2309. if advicelist.ID > 0 {
  2310. //查询最新批次库存
  2311. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2312. var batch_number_count int64
  2313. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2314. var device_number int64
  2315. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2316. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2317. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2318. device_number = prescribingNumberInt * drug.MinNumber
  2319. }
  2320. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2321. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2322. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2323. device_number = prescribingNumberInt
  2324. }
  2325. var number_count int64
  2326. if prescribingNumberUnit == drug.MaxUnit {
  2327. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2328. number_count = prescribingNumberInt * drug.MinNumber
  2329. }
  2330. if prescribingNumberUnit == drug.MinUnit {
  2331. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2332. number_count = prescribingNumberInt
  2333. }
  2334. fmt.Println("number_count--------------", number_count)
  2335. fmt.Println("device_number--------------", device_number)
  2336. fmt.Println("batch_number_count", batch_number_count)
  2337. //如果修改的数量大于之前修改的数量
  2338. if (number_count - device_number) > 0 {
  2339. //如果修改的差数量 大于库存数量
  2340. if drug.IsUse != 1 {
  2341. if drug.IsProject == 0 || drug.IsProject == 2 {
  2342. if total_count == 0 {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2345. return
  2346. }
  2347. if (number_count - device_number) > total_count {
  2348. tx.Rollback()
  2349. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2350. return
  2351. }
  2352. }
  2353. if adminInfo.CurrentOrgId == 10215 {
  2354. if (number_count - device_number) > batch_number_count {
  2355. tx.Rollback()
  2356. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2357. return
  2358. }
  2359. }
  2360. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2361. //查询历史出库数据总批次
  2362. // 查询该药品最后一次出库记录
  2363. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2364. var out_count int64
  2365. var in_count int64
  2366. var stock_max_number int64
  2367. var stock_min_number int64
  2368. for _, it := range outInfo {
  2369. if it.CountUnit == drug.MaxUnit {
  2370. it.Count = it.Count * drug.MinNumber
  2371. }
  2372. out_count += it.Count
  2373. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2374. stock_max_number = warehouseInfoList.StockMaxNumber
  2375. stock_min_number = warehouseInfoList.StockMinNumber
  2376. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2377. }
  2378. if out_count > 0 {
  2379. if (number_count - device_number) > in_count {
  2380. tx.Rollback()
  2381. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2382. return
  2383. }
  2384. }
  2385. // 未出库
  2386. if out_count == 0 {
  2387. var sum_in_count int64
  2388. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2389. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2390. if sum_in_count == 0 {
  2391. tx.Rollback()
  2392. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2393. return
  2394. }
  2395. //如果修改的数量大于有库存的第一个批次
  2396. if number_count > sum_in_count {
  2397. tx.Rollback()
  2398. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2399. return
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. //校验耗材库存
  2416. if goodOutConfig.IsOpen == 1 {
  2417. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2418. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2419. if len(prescriptions) > 0 {
  2420. for _, item := range prescriptions {
  2421. items := item.(map[string]interface{})
  2422. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2423. projects := items["project"].([]interface{})
  2424. if len(projects) > 0 {
  2425. for _, project := range projects {
  2426. var project_id int64
  2427. var project_type int64
  2428. var totals float64
  2429. var project_name string
  2430. var parsetotal int64
  2431. var id int64
  2432. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2433. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2434. }
  2435. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2436. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2437. }
  2438. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2439. total, _ := project.(map[string]interface{})["total"].(string)
  2440. totals, _ = strconv.ParseFloat(total, 64)
  2441. }
  2442. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2443. project_name = project.(map[string]interface{})["project_name"].(string)
  2444. }
  2445. if project_type == 3 {
  2446. //查找该耗材的出库记录
  2447. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2448. if len(goodWarehouseInfo) == 0 {
  2449. //查询耗材库存
  2450. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2451. var stock_count int64
  2452. for _, it := range list {
  2453. stock_count += it.StockCount
  2454. }
  2455. stock_counts := strconv.FormatInt(stock_count, 10)
  2456. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2457. if stock_total_count == 0 {
  2458. tx.Rollback()
  2459. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2460. return
  2461. }
  2462. if totals > stock_total_count {
  2463. tx.Rollback()
  2464. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2465. return
  2466. }
  2467. }
  2468. if len(goodWarehouseInfo) > 0 {
  2469. //查询该患者耗材的历史数据
  2470. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2471. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2472. //数量发生改变
  2473. if parsetotal != count {
  2474. //如果现在的数量大于历史数量,就要看库存是否足够
  2475. if parsetotal > count {
  2476. //查询耗材所有库存
  2477. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2478. var stock_count int64
  2479. for _, it := range list {
  2480. stock_count += it.StockCount
  2481. }
  2482. //库存不足
  2483. if stock_count == 0 {
  2484. tx.Rollback()
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. if (parsetotal - count) > stock_count {
  2489. tx.Rollback()
  2490. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2491. return
  2492. }
  2493. }
  2494. }
  2495. }
  2496. }
  2497. }
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. //不使用耗材保存处方出库
  2505. if goodOutConfig.IsOpen != 1 {
  2506. if stockConfig.IsOpen == 1 {
  2507. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2508. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2509. if len(prescriptions) > 0 {
  2510. for _, item := range prescriptions {
  2511. items := item.(map[string]interface{})
  2512. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2513. projects := items["project"].([]interface{})
  2514. if len(projects) > 0 {
  2515. for _, project := range projects {
  2516. var project_id int64
  2517. var project_type int64
  2518. var totals float64
  2519. var project_name string
  2520. var parsetotal int64
  2521. var id int64
  2522. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2523. id = int64(project.(map[string]interface{})["id"].(float64))
  2524. }
  2525. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2526. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2527. }
  2528. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2529. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2530. }
  2531. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2532. total, _ := project.(map[string]interface{})["total"].(string)
  2533. totals, _ = strconv.ParseFloat(total, 64)
  2534. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2535. }
  2536. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2537. project_name = project.(map[string]interface{})["project_name"].(string)
  2538. }
  2539. if project_type == 3 {
  2540. //查找该耗材的出库记录
  2541. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2542. //没有出库记录
  2543. if len(goodWarehouseInfo) == 0 {
  2544. //查询耗材库存
  2545. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2546. var stock_count int64
  2547. for _, it := range list {
  2548. stock_count += it.StockCount
  2549. }
  2550. stock_counts := strconv.FormatInt(stock_count, 10)
  2551. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2552. if stock_total_count == 0 {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2555. return
  2556. }
  2557. if totals > stock_total_count {
  2558. tx.Rollback()
  2559. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2560. return
  2561. }
  2562. //查找今日该患者已经出库的所有耗材
  2563. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2564. for _, item := range goodList {
  2565. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2566. var flush_count int64
  2567. for _, it := range goodListSix {
  2568. flush_count += it.StockCount
  2569. }
  2570. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2571. creater := adminInfo.AdminUser.Id
  2572. if errs != nil {
  2573. goodErrcode := models.XtGoodErrcode{
  2574. UserOrgId: item.OrgId,
  2575. Errcode: "手动出库更新剩余出库失败",
  2576. GoodId: item.GoodId,
  2577. Status: 1,
  2578. Ctime: time.Now().Unix(),
  2579. Mtime: 0,
  2580. Count: 0,
  2581. StockCount: 0,
  2582. Creater: creater,
  2583. BatchNumberId: 0,
  2584. WarehouseOutId: 0,
  2585. }
  2586. service.CreateGoodErrcode(goodErrcode)
  2587. }
  2588. }
  2589. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2590. }
  2591. //有出库记录
  2592. if len(goodWarehouseInfo) > 0 {
  2593. //查询该患者耗材的历史数据
  2594. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2595. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2596. //数量发生改变
  2597. if parsetotal != count {
  2598. //查找今日该患者已经出库的所有耗材
  2599. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2600. for _, item := range goodList {
  2601. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2602. var flush_count int64
  2603. for _, it := range goodListSix {
  2604. flush_count += it.StockCount
  2605. }
  2606. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2607. //减少出库数量
  2608. creater := adminInfo.AdminUser.Id
  2609. if errs != nil {
  2610. goodErrcode := models.XtGoodErrcode{
  2611. UserOrgId: item.OrgId,
  2612. Errcode: "手动出库更新剩余出库失败",
  2613. GoodId: item.GoodId,
  2614. Status: 1,
  2615. Ctime: time.Now().Unix(),
  2616. Mtime: 0,
  2617. Count: 0,
  2618. StockCount: 0,
  2619. Creater: creater,
  2620. BatchNumberId: 0,
  2621. WarehouseOutId: 0,
  2622. }
  2623. service.CreateGoodErrcode(goodErrcode)
  2624. }
  2625. //查询默认仓库
  2626. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2627. var total_count int64
  2628. for _, it := range stockList {
  2629. total_count += it.StockCount
  2630. }
  2631. //基础库插入数据
  2632. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2633. }
  2634. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2635. }
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2647. var hpInfo models.HisPrescriptionInfo
  2648. if info.ID == 0 {
  2649. var randNum int
  2650. randNum = rand.Intn(10000) + 1000
  2651. timestamp := time.Now().Unix()
  2652. tempTime := time.Unix(timestamp, 0)
  2653. timeFormat := tempTime.Format("20060102150405")
  2654. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2655. hpInfo = models.HisPrescriptionInfo{
  2656. HisPatientId: his_patient_id,
  2657. UserOrgId: adminInfo.CurrentOrgId,
  2658. RecordDate: theTime.Unix(),
  2659. PatientId: patient_id,
  2660. Status: 1,
  2661. Ctime: time.Now().Unix(),
  2662. Mtime: time.Now().Unix(),
  2663. Creator: adminInfo.AdminUser.Id,
  2664. Modifier: adminInfo.AdminUser.Id,
  2665. Diagnosis: diagnose,
  2666. SickHistory: sick_history,
  2667. Departments: department,
  2668. RegisterType: reg_type,
  2669. PrescriptionNumber: p_number,
  2670. PrescriptionStatus: 1,
  2671. Doctor: role.UserName,
  2672. DoctorId: doctor_id,
  2673. SickType: sick_type,
  2674. PType: p_type,
  2675. PatientDiagnosis: patient_diagnose,
  2676. }
  2677. service.SavePatientPrescriptionInfo(hpInfo)
  2678. //创建步骤表
  2679. finish := models.XtDialysisFinish{
  2680. IsFinish: 1,
  2681. UserOrgId: adminInfo.CurrentOrgId,
  2682. Status: 1,
  2683. Ctime: time.Now().Unix(),
  2684. Mtime: 0,
  2685. Module: 4,
  2686. RecordDate: theTime.Unix(),
  2687. Sourse: 1,
  2688. PatientId: patient_id,
  2689. }
  2690. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2691. if dialysisFinish.ID == 0 {
  2692. service.CreateDialysisFinish(finish)
  2693. }
  2694. redis := service.RedisClient()
  2695. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2696. redis.Set(key, "", time.Second)
  2697. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2698. redis.Set(keyOne, "", time.Second)
  2699. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2700. redis.Set(keySeven, "", time.Second)
  2701. defer redis.Close()
  2702. } else {
  2703. hpInfo = models.HisPrescriptionInfo{
  2704. ID: info.ID,
  2705. UserOrgId: adminInfo.CurrentOrgId,
  2706. RecordDate: info.RecordDate,
  2707. PatientId: info.PatientId,
  2708. Status: 1,
  2709. Ctime: info.Ctime,
  2710. Mtime: time.Now().Unix(),
  2711. Creator: info.Creator,
  2712. Modifier: adminInfo.AdminUser.Id,
  2713. Diagnosis: diagnose,
  2714. SickHistory: sick_history,
  2715. Departments: department,
  2716. RegisterType: reg_type,
  2717. PrescriptionNumber: info.PrescriptionNumber,
  2718. Doctor: role.UserName,
  2719. PrescriptionStatus: info.PrescriptionStatus,
  2720. DoctorId: doctor_id,
  2721. SickType: sick_type,
  2722. PType: info.PType,
  2723. HisPatientId: info.HisPatientId,
  2724. PatientDiagnosis: patient_diagnose,
  2725. }
  2726. service.SavePatientPrescriptionInfo(hpInfo)
  2727. //创建步骤表
  2728. finish := models.XtDialysisFinish{
  2729. IsFinish: 1,
  2730. UserOrgId: adminInfo.CurrentOrgId,
  2731. Status: 1,
  2732. Ctime: time.Now().Unix(),
  2733. Mtime: 0,
  2734. Module: 4,
  2735. RecordDate: info.RecordDate,
  2736. Sourse: 1,
  2737. PatientId: info.PatientId,
  2738. }
  2739. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2740. if dialysisFinish.ID == 0 {
  2741. service.CreateDialysisFinish(finish)
  2742. }
  2743. redis := service.RedisClient()
  2744. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2745. redis.Set(key, "", time.Second)
  2746. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2747. redis.Set(keyOne, "", time.Second)
  2748. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2749. redis.Set(keySeven, "", time.Second)
  2750. defer redis.Close()
  2751. }
  2752. //定义切片
  2753. var adviceList []models.HisDoctorAdviceInfo
  2754. var projectList []models.HisPrescriptionProject
  2755. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10598 {
  2756. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2757. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2758. var tempPrescription *models.HisPrescription
  2759. if len(prescriptions) > 0 {
  2760. for _, item := range prescriptions {
  2761. // 开始外部循环的事务
  2762. tx := db.Begin()
  2763. // 在函数结束时处理事务回滚
  2764. defer func() {
  2765. if r := recover(); r != nil {
  2766. tx.Rollback()
  2767. }
  2768. }()
  2769. items := item.(map[string]interface{})
  2770. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2771. utils.ErrorLog("id")
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2773. return
  2774. }
  2775. id := int64(items["id"].(float64))
  2776. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2777. tempPrescription = &new_prescription
  2778. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2779. utils.ErrorLog("type")
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2781. return
  2782. }
  2783. types := int64(items["type"].(float64))
  2784. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2785. utils.ErrorLog("med_type")
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. return
  2788. }
  2789. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2790. if med_type == "0" {
  2791. med_type = "14"
  2792. }
  2793. //if order_status == 0 {
  2794. // order_status = 1
  2795. //}
  2796. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2797. utils.ErrorLog("pre_time")
  2798. }
  2799. preTime, _ := items["pre_time"].(string)
  2800. fmt.Println("preTime", preTime)
  2801. timeLayout := "2006-01-02"
  2802. loc, _ := time.LoadLocation("Local")
  2803. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2804. result := strings.Split(preTime, " ")
  2805. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2806. if err != nil {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. pTime := theTime2.Unix()
  2811. ctime := time.Now().Unix()
  2812. if tempPrescription.ID == 0 {
  2813. prescription := &models.HisPrescription{
  2814. ID: 0,
  2815. PatientId: patient_id,
  2816. UserOrgId: adminInfo.CurrentOrgId,
  2817. RecordDate: recordDateTime,
  2818. Ctime: ctime,
  2819. Mtime: ctime,
  2820. Type: types,
  2821. Modifier: adminInfo.AdminUser.Id,
  2822. Creator: adminInfo.AdminUser.Id,
  2823. Status: 1,
  2824. Doctor: role.UserName,
  2825. HisPatientId: his_patient_id,
  2826. OrderStatus: 1,
  2827. BatchNumber: "",
  2828. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2829. PreTime: pTime,
  2830. PType: p_type,
  2831. MedType: med_type,
  2832. }
  2833. tempPrescription = prescription
  2834. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2835. redis := service.RedisClient()
  2836. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2837. redis.Set(key, "", time.Second)
  2838. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2839. redis.Set(keyOne, "", time.Second)
  2840. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2841. redis.Set(keySeven, "", time.Second)
  2842. defer redis.Close()
  2843. } else {
  2844. tempPrescription.ID = id
  2845. tempPrescription.Type = types
  2846. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2847. tempPrescription.Mtime = time.Now().Unix()
  2848. tempPrescription.Doctor = role.UserName
  2849. //tempPrescription.OrderStatus = order_status
  2850. tempPrescription.PreTime = pTime
  2851. tempPrescription.MedType = med_type
  2852. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2853. redis := service.RedisClient()
  2854. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2855. redis.Set(key, "", time.Second)
  2856. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2857. redis.Set(keyOne, "", time.Second)
  2858. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2859. redis.Set(keySeven, "", time.Second)
  2860. defer redis.Close()
  2861. }
  2862. //service.SaveHisPrescription(prescription)
  2863. //更改患者挂号状态
  2864. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2865. fmt.Println("更改失败", err2)
  2866. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2867. advices := items["advices"].([]interface{})
  2868. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2869. groupNo := int64(0)
  2870. if len(advices) > 0 {
  2871. for _, advice := range advices {
  2872. tx := db.Begin()
  2873. // 在函数结束时处理事务回滚
  2874. defer func() {
  2875. if r := recover(); r != nil {
  2876. tx.Rollback()
  2877. }
  2878. }()
  2879. var s models.HisDoctorAdviceInfo
  2880. s.PrescriptionId = tempPrescription.ID
  2881. s.AdviceType = 2
  2882. s.AdviceDoctor = doctor_id
  2883. s.StopState = 2
  2884. s.ExecutionState = 2
  2885. s.AdviceDate = theTime3.Unix()
  2886. s.Status = 1
  2887. s.UserOrgId = adminInfo.CurrentOrgId
  2888. s.RecordDate = theTime3.Unix()
  2889. s.StartTime = tempPrescription.PreTime
  2890. s.Groupno = groupNo
  2891. s.PatientId = patient_id
  2892. s.HisPatientId = his_patient_id
  2893. s.StartTime = pTime
  2894. s.IsSettle = 2
  2895. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2896. if errcode > 0 {
  2897. c.ServeFailJSONWithSGJErrorCode(errcode)
  2898. return
  2899. }
  2900. s.StartTime = pTime
  2901. var total_count int64 //处方总库存
  2902. //查询改药品信息
  2903. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2904. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2905. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2906. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2907. total_count += prescribingNumberSeven * medical.MinNumber
  2908. }
  2909. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2910. total_count += prescribingNumberSeven
  2911. }
  2912. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2913. total_count += prescribingNumberSeven
  2914. }
  2915. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2916. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2917. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2918. if s.Price != lastWarehouse.RetailPrice {
  2919. s.Price = lastWarehouse.RetailPrice
  2920. }
  2921. if s.Price == 0 {
  2922. if lastWarehouse.ID == 0 {
  2923. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2924. s.Price = lastWarehouseTwo.RetailPrice
  2925. }
  2926. }
  2927. }
  2928. //查询保存处方出库开关是否打开
  2929. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2930. if s.PatientId != 30038 {
  2931. if drugOutConfig.IsOpen == 1 {
  2932. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2933. // 查询该药品最后一次出库记录
  2934. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2935. var is_user_total int64
  2936. var no_user_total int64
  2937. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2938. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2939. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2940. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2941. }
  2942. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2943. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2944. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2945. no_user_total += prescribingNumberSevenTy
  2946. }
  2947. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2948. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2949. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2950. no_user_total += prescribingNumberSevenTy
  2951. }
  2952. if len(druginfo) > 0 {
  2953. for _, it := range druginfo {
  2954. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2955. it.Count = it.Count * drug.MinNumber
  2956. is_user_total += it.Count
  2957. }
  2958. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2959. is_user_total += it.Count
  2960. }
  2961. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2962. is_user_total += it.Count
  2963. }
  2964. }
  2965. }
  2966. //fmt.Println("is_user_total-----------------------------", is_user_total)
  2967. //fmt.Println("no_user_total-----------------------------", no_user_total)
  2968. if is_user_total != no_user_total {
  2969. //出库
  2970. if drug.IsUse == 2 {
  2971. creater := adminInfo.AdminUser.Id
  2972. newadviceInfo := &models.HisDoctorAdviceInfo{
  2973. ID: s.ID,
  2974. UserOrgId: s.UserOrgId,
  2975. PatientId: s.PatientId,
  2976. HisPatientId: s.HisPatientId,
  2977. AdviceType: s.AdviceType,
  2978. AdviceDate: s.AdviceDate,
  2979. StartTime: s.StartTime,
  2980. AdviceName: s.AdviceName,
  2981. AdviceDesc: s.AdviceDesc,
  2982. ReminderDate: s.ReminderDate,
  2983. SingleDose: s.SingleDose,
  2984. SingleDoseUnit: s.SingleDoseUnit,
  2985. PrescribingNumber: s.PrescribingNumber,
  2986. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2987. DeliveryWay: s.DeliveryWay,
  2988. ExecutionFrequency: s.ExecutionFrequency,
  2989. AdviceDoctor: s.AdviceDoctor,
  2990. Status: s.Status,
  2991. CreatedTime: s.CreatedTime,
  2992. UpdatedTime: s.UpdatedTime,
  2993. AdviceAffirm: s.AdviceAffirm,
  2994. Remark: s.Remark,
  2995. StopTime: s.StopTime,
  2996. StopReason: s.StopReason,
  2997. StopDoctor: s.StopDoctor,
  2998. StopState: s.StopState,
  2999. ParentId: s.ParentId,
  3000. ExecutionTime: s.ExecutionTime,
  3001. ExecutionStaff: s.ExecutionStaff,
  3002. ExecutionState: s.ExecutionState,
  3003. Checker: s.Checker,
  3004. RecordDate: s.RecordDate,
  3005. DialysisOrderId: s.DialysisOrderId,
  3006. CheckTime: s.CheckTime,
  3007. CheckState: s.CheckState,
  3008. DrugSpec: s.DrugSpec,
  3009. DrugSpecUnit: s.DrugSpecUnit,
  3010. Groupno: s.Groupno,
  3011. RemindType: s.RemindType,
  3012. FrequencyType: s.FrequencyType,
  3013. DayCount: s.DayCount,
  3014. WeekDay: s.WeekDay,
  3015. TemplateId: s.TemplateId,
  3016. Modifier: s.Modifier,
  3017. DrugId: s.DrugId,
  3018. Price: s.Price,
  3019. PrescriptionId: s.PrescriptionId,
  3020. MedListCodg: s.MedListCodg,
  3021. FeedetlSn: s.FeedetlSn,
  3022. Day: s.DayCount,
  3023. ChildDoctorAdvice: nil,
  3024. Drug: models.Drug{},
  3025. Diagnosis: s.Diagnosis,
  3026. Way: s.Way,
  3027. HospApprFlag: s.HospApprFlag,
  3028. LmtUsedFlag: s.LmtUsedFlag,
  3029. HisOrderInfo: models.HisOrderInfo{},
  3030. IsMedicine: s.IsMedicine,
  3031. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3032. Child: nil,
  3033. IsSettle: s.IsSettle,
  3034. IsMobile: s.IsMobile,
  3035. IsSelfDrug: s.IsSelfDrug,
  3036. DrugWayCount: s.DrugWayCount,
  3037. }
  3038. var history_count int64
  3039. var local_count int64
  3040. //查找已经开过的医嘱信息
  3041. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3042. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3043. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3044. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3045. local_count += prescribingNumberSevenTy * drug.MinNumber
  3046. }
  3047. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3048. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3049. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3050. local_count += prescribingNumberSevenTy
  3051. }
  3052. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3053. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3054. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3055. local_count += prescribingNumberSevenTy
  3056. }
  3057. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3058. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3059. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3060. history_count += prescribingNumberSevenTy * drug.MinNumber
  3061. }
  3062. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3063. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3064. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3065. history_count += prescribingNumberSevenTy
  3066. }
  3067. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3068. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3069. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3070. history_count += prescribingNumberSevenTy
  3071. }
  3072. //fmt.Println("local_count0000000000000000000000000000000000000000000", local_count)
  3073. //
  3074. //fmt.Println("history_count999999999999999999999999999999999999999", history_count)
  3075. //如果当前出库数量大于历史出库数量则需要出库
  3076. if local_count > history_count {
  3077. //按最小单位出库
  3078. var cha_count = local_count - history_count
  3079. //fmt.Println("cha_count000000000000000000000000000", cha_count)
  3080. newadviceInfo.PrescribingNumber = float64(cha_count)
  3081. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3082. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3083. }
  3084. //如果当前出库数量小于历史出库数量则需要退库
  3085. if local_count < history_count {
  3086. var cha_count = history_count - local_count
  3087. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3088. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3089. }
  3090. }
  3091. //更新字典里面的库存
  3092. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3093. var sum_count int64
  3094. for _, its := range stockInfo {
  3095. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3096. if its.MaxUnit == baseDrug.MaxUnit {
  3097. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3098. }
  3099. sum_count += its.StockMaxNumber + its.StockMinNumber
  3100. }
  3101. //更新基础库存
  3102. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3103. //剩余库存
  3104. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3105. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3106. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3107. //创建医嘱
  3108. service.CreateHisDoctorAdviceOne(&s, tx)
  3109. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3110. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3111. if len(outInfoTwo) > 0 {
  3112. for _, item := range outInfoTwo {
  3113. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3114. }
  3115. }
  3116. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3117. if len(drugAutoDetail) > 0 {
  3118. for _, item := range drugAutoDetail {
  3119. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3120. }
  3121. }
  3122. }
  3123. }
  3124. }
  3125. //记录日志
  3126. byterequest, _ := json.Marshal(s)
  3127. adviceLog := models.XtDoctorAdviceLog{
  3128. UserOrgId: s.UserOrgId,
  3129. PatientId: s.PatientId,
  3130. AdminUserId: adminInfo.AdminUser.Id,
  3131. Module: 1,
  3132. ErrLog: string(byterequest),
  3133. Status: 1,
  3134. Ctime: time.Now().Unix(),
  3135. Mtime: 0,
  3136. Source: "电脑端新建his医嘱",
  3137. RecordDate: s.AdviceDate,
  3138. }
  3139. service.CreateDoctorAdviceLog(adviceLog)
  3140. //存储切片中
  3141. adviceList = append(adviceList, s)
  3142. redis := service.RedisClient()
  3143. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3144. redis.Set(key, "", time.Second)
  3145. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3146. redis.Set(keyOne, "", time.Second)
  3147. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3148. redis.Set(keySeven, "", time.Second)
  3149. var randNum int
  3150. randNum = rand.Intn(10000) + 1000
  3151. timestamp := time.Now().Unix()
  3152. tempTime := time.Unix(timestamp, 0)
  3153. timeFormat := tempTime.Format("20060102150405")
  3154. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3155. service.CreateHisDoctorAdviceOne(&s, tx)
  3156. tx.Commit()
  3157. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3158. redis.Set(keySix, "", time.Second)
  3159. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3160. redis.Set(keyFive, "", time.Second)
  3161. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3162. redis.Set(keyEight, "", time.Second)
  3163. defer redis.Close()
  3164. }
  3165. }
  3166. }
  3167. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3168. projects := items["project"].([]interface{})
  3169. if len(projects) > 0 {
  3170. for _, project := range projects {
  3171. tx := db.Begin()
  3172. // 在函数结束时处理事务回滚
  3173. defer func() {
  3174. if r := recover(); r != nil {
  3175. tx.Rollback()
  3176. }
  3177. }()
  3178. var p models.HisPrescriptionProject
  3179. p.PrescriptionId = tempPrescription.ID
  3180. p.PatientId = patient_id
  3181. p.RecordDate = theTime3.Unix()
  3182. p.Doctor = doctor_id
  3183. p.UserOrgId = adminInfo.CurrentOrgId
  3184. p.HisPatientId = his_patient_id
  3185. p.Status = 1
  3186. p.StartTime = pTime
  3187. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3188. if errcode > 0 {
  3189. c.ServeFailJSONWithSGJErrorCode(errcode)
  3190. return
  3191. }
  3192. if p.ID == 0 {
  3193. p.IsOut = 2
  3194. }
  3195. if p.ID > 0 {
  3196. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3197. p.IsOut = projectDetail.IsOut
  3198. }
  3199. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3200. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3201. if p.Type == 3 {
  3202. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3203. if p.Price != lastWarehouse.PackingPrice {
  3204. p.Price = lastWarehouse.PackingPrice
  3205. }
  3206. if p.Unit == "" {
  3207. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3208. p.Unit = goodInfoOne.PackingUnit
  3209. }
  3210. }
  3211. }
  3212. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3213. //
  3214. // if p.Type == 3 {
  3215. // //查询该耗材是否停用
  3216. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3217. // //表示该耗材已经停用,不能保存
  3218. // if goodInfoSeven.ID == 0 {
  3219. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3220. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3221. // return
  3222. // }
  3223. // }
  3224. //
  3225. //}
  3226. service.CreateNewHisProjectTwo(&p, tx)
  3227. var randNum int
  3228. randNum = rand.Intn(10000) + 1000
  3229. timestamp := time.Now().Unix()
  3230. tempTime := time.Unix(timestamp, 0)
  3231. timeFormat := tempTime.Format("20060102150405")
  3232. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3233. service.CreateNewHisProjectTwo(&p, tx)
  3234. //查询保存耗材出库开关是否打开
  3235. if p.PatientId != 30038 {
  3236. if goodOutConfig.IsOpen == 1 {
  3237. //耗材出库
  3238. if p.Type == 3 {
  3239. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3240. //查询历史出库数据
  3241. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3242. var out_count_five int64
  3243. for _, item := range flowGood {
  3244. out_count_five += item.Count
  3245. }
  3246. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3247. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3248. if out_count_five != parseIntCount {
  3249. //查询耗材最后一次出库记录
  3250. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3251. //查询默认出库仓库库存
  3252. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3253. if len(wareOut) > 0 {
  3254. for _, it := range wareOut {
  3255. //回退库存
  3256. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3257. //删除出库记录
  3258. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3259. }
  3260. }
  3261. timeStr := time.Now().Format("2006-01-02")
  3262. timeArr := strings.Split(timeStr, "-")
  3263. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3264. total = total + 1
  3265. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3266. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3267. number = number + total
  3268. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3269. operation_time := time.Now().Unix()
  3270. creater := c.GetAdminUserInfo().AdminUser.Id
  3271. recordDateStr := time.Now().Format("2006-01-02")
  3272. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3273. nowtime := recordDate.Unix()
  3274. warehouseOut := models.WarehouseOut{
  3275. WarehouseOutOrderNumber: warehousing_out_order,
  3276. OperationTime: operation_time,
  3277. OrgId: adminInfo.CurrentOrgId,
  3278. Creater: creater,
  3279. Ctime: time.Now().Unix(),
  3280. Status: 1,
  3281. WarehouseOutTime: nowtime,
  3282. Type: 1,
  3283. StorehouseId: storeConfig.StorehouseOutInfo,
  3284. IsCheck: 1,
  3285. IsSys: 1,
  3286. }
  3287. //查询是否生成出库单
  3288. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3289. if out.ID == 0 {
  3290. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3291. }
  3292. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3293. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3294. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3295. dialyPrepareOne := models.DialysisBeforePrepare{
  3296. GoodTypeId: goodObj.GoodTypeId,
  3297. GoodId: p.ProjectId,
  3298. PatientId: p.PatientId,
  3299. RecordDate: p.RecordDate,
  3300. UserOrgId: adminInfo.CurrentOrgId,
  3301. Count: parseIntCount,
  3302. Ctime: time.Now().Unix(),
  3303. Creater: creater,
  3304. Status: 1,
  3305. StorehouseId: houseConfig.StorehouseOutInfo,
  3306. ProjectId: lastHisProject.ID,
  3307. }
  3308. //判断是否是零用耗材(非零用)
  3309. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3310. //查询历史出库数据
  3311. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3312. var out_count int64
  3313. for _, item := range flowGood {
  3314. out_count += item.Count
  3315. }
  3316. //如果历史数和当前数据不想等才进行退库出库
  3317. if out_count != parseIntCount {
  3318. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3319. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3320. detail := models.AutomaticReduceDetail{
  3321. WarehouseOutId: 0,
  3322. WarehouseOutOrderNumber: "",
  3323. PatientId: p.PatientId,
  3324. Ctime: time.Now().Unix(),
  3325. Mtime: 0,
  3326. Status: 1,
  3327. RecordTime: p.RecordDate,
  3328. OrgId: p.UserOrgId,
  3329. GoodId: p.ProjectId,
  3330. GoodTypeId: 0,
  3331. Count: parseIntCount,
  3332. Type: 0,
  3333. ProjectId: lastHisProject.ID,
  3334. StorehouseId: 0,
  3335. }
  3336. service.CreateNewAutoDetail(detail, tx)
  3337. //查询剩余库存
  3338. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3339. var sum_count int64
  3340. for _, item := range goodList {
  3341. sum_count += item.StockCount
  3342. }
  3343. //更新剩余库存
  3344. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3345. //耗材
  3346. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3347. }
  3348. //判断是否是零用耗材(零用但是是出库耗材)
  3349. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3350. //查询历史出库数据
  3351. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3352. var out_count int64
  3353. for _, item := range flowGood {
  3354. out_count += item.Count
  3355. }
  3356. //如果历史数和当前数据不想等才进行退库出库
  3357. if out_count != parseIntCount {
  3358. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3359. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3360. detail := models.AutomaticReduceDetail{
  3361. WarehouseOutId: 0,
  3362. WarehouseOutOrderNumber: "",
  3363. PatientId: p.PatientId,
  3364. Ctime: time.Now().Unix(),
  3365. Mtime: 0,
  3366. Status: 1,
  3367. RecordTime: p.RecordDate,
  3368. OrgId: p.UserOrgId,
  3369. GoodId: p.ProjectId,
  3370. GoodTypeId: 0,
  3371. Count: parseIntCount,
  3372. Type: 0,
  3373. ProjectId: p.ID,
  3374. StorehouseId: 0,
  3375. }
  3376. service.CreateNewAutoDetail(detail, tx)
  3377. //查询剩余库存
  3378. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3379. var sum_count int64
  3380. for _, item := range goodList {
  3381. sum_count += item.StockCount
  3382. }
  3383. //更新剩余库存
  3384. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3385. //耗材
  3386. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3387. }
  3388. }
  3389. }
  3390. }
  3391. //记录日志
  3392. byterequest, _ := json.Marshal(p)
  3393. adviceLog := models.XtDoctorAdviceLog{
  3394. UserOrgId: p.UserOrgId,
  3395. PatientId: p.PatientId,
  3396. AdminUserId: adminInfo.AdminUser.Id,
  3397. Module: 1,
  3398. ErrLog: string(byterequest),
  3399. Status: 1,
  3400. Ctime: time.Now().Unix(),
  3401. Mtime: 0,
  3402. Source: "电脑端新建his项目",
  3403. RecordDate: p.RecordDate,
  3404. }
  3405. service.CreateDoctorAdviceLog(adviceLog)
  3406. projectList = append(projectList, p)
  3407. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3408. //新增或者编辑项目,修改对应的标签数据
  3409. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3410. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3411. var label models.HisLabelPrintInfo
  3412. project, _ := service.GetProjectDetail(p.ProjectId)
  3413. if project.CostClassify == 3 { //类别为检验检查
  3414. if p.TeamId > 0 { //检验检查组套
  3415. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3416. if tempLabel.ID == 0 {
  3417. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3418. label.Number = tempPrescription.PrescriptionNumber
  3419. label.ProjectId = project.ID
  3420. label.Status = 1
  3421. label.IsPrint = 2
  3422. label.DoctorId = info.DoctorId
  3423. label.UserOrgId = p.UserOrgId
  3424. label.PatientId = patient_id
  3425. label.RecordDate = recordDateTime
  3426. label.Ctime = time.Now().Unix()
  3427. label.Mtime = time.Now().Unix()
  3428. label.ItemId = p.TeamId
  3429. label.FeedetlSn = p.FeedetlSn
  3430. label.PProjectId = p.ID
  3431. label.ProjectName = team.ProjectTeam
  3432. label.PatientName = patient.Name
  3433. service.CreateNewHisLabelRecord(&label, tx)
  3434. }
  3435. } else { //单条检验检查项目
  3436. label.Number = tempPrescription.PrescriptionNumber
  3437. label.ProjectId = project.ID
  3438. label.Status = 1
  3439. label.DoctorId = info.DoctorId
  3440. label.UserOrgId = p.UserOrgId
  3441. label.PatientId = patient_id
  3442. label.RecordDate = recordDateTime
  3443. label.IsPrint = 2
  3444. label.Ctime = time.Now().Unix()
  3445. label.Mtime = time.Now().Unix()
  3446. label.FeedetlSn = p.FeedetlSn
  3447. label.PProjectId = p.ID
  3448. label.ItemId = p.TeamId
  3449. label.ProjectName = project.ProjectName
  3450. label.PatientName = patient.Name
  3451. service.CreateNewHisLabelRecord(&label, tx)
  3452. }
  3453. }
  3454. }
  3455. }
  3456. }
  3457. }
  3458. }
  3459. tx.Commit()
  3460. }
  3461. }
  3462. }
  3463. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3464. // addition := items["addition"].([]interface{})
  3465. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3466. // ctime := time.Now().Unix()
  3467. // mtime := ctime
  3468. // if len(addition) > 0 {
  3469. // for _, item := range addition {
  3470. // var s models.HisAdditionalCharge
  3471. // s.PrescriptionId = tempPrescription.ID
  3472. // s.Status = 1
  3473. // s.UserOrgId = adminInfo.CurrentOrgId
  3474. // s.RecordDate = recordDateTime
  3475. // s.CreatedTime = ctime
  3476. // s.UpdatedTime = mtime
  3477. // s.PatientId = patient_id
  3478. // s.HisPatientId = his_patient_id
  3479. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3480. // if errcode > 0 {
  3481. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3482. // return
  3483. // }
  3484. // service.CreateAdditionalCharge(&s)
  3485. // var randNum int
  3486. // randNum = rand.Intn(10000) + 1000
  3487. // timestamp := time.Now().Unix()
  3488. // tempTime := time.Unix(timestamp, 0)
  3489. // timeFormat := tempTime.Format("20060102150405")
  3490. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3491. // service.CreateAdditionalCharge(&s)
  3492. //
  3493. // }
  3494. // }
  3495. //}
  3496. }
  3497. }
  3498. }
  3499. tx.Commit()
  3500. if err == nil {
  3501. c.ServeSuccessJSON(map[string]interface{}{
  3502. "msg": "保存成功",
  3503. })
  3504. return
  3505. } else {
  3506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3507. return
  3508. }
  3509. } else {
  3510. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3511. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3512. var tempPrescription *models.HisPrescription
  3513. if len(prescriptions) > 0 {
  3514. for _, item := range prescriptions {
  3515. items := item.(map[string]interface{})
  3516. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3517. utils.ErrorLog("id")
  3518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3519. return
  3520. }
  3521. id := int64(items["id"].(float64))
  3522. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3523. tempPrescription = &new_prescription
  3524. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3525. utils.ErrorLog("type")
  3526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3527. return
  3528. }
  3529. types := int64(items["type"].(float64))
  3530. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3531. utils.ErrorLog("med_type")
  3532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3533. return
  3534. }
  3535. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3536. if med_type == "0" {
  3537. med_type = "14"
  3538. }
  3539. //if order_status == 0 {
  3540. // order_status = 1
  3541. //}
  3542. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3543. utils.ErrorLog("pre_time")
  3544. }
  3545. preTime, _ := items["pre_time"].(string)
  3546. timeLayout := "2006-01-02"
  3547. loc, _ := time.LoadLocation("Local")
  3548. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3549. result := strings.Split(preTime, " ")
  3550. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3551. if err != nil {
  3552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3553. return
  3554. }
  3555. pTime := theTime2.Unix()
  3556. ctime := time.Now().Unix()
  3557. if tempPrescription.ID == 0 {
  3558. prescription := &models.HisPrescription{
  3559. ID: 0,
  3560. PatientId: patient_id,
  3561. UserOrgId: adminInfo.CurrentOrgId,
  3562. RecordDate: recordDateTime,
  3563. Ctime: ctime,
  3564. Mtime: ctime,
  3565. Type: types,
  3566. Modifier: adminInfo.AdminUser.Id,
  3567. Creator: adminInfo.AdminUser.Id,
  3568. Status: 1,
  3569. Doctor: role.UserName,
  3570. HisPatientId: his_patient_id,
  3571. OrderStatus: 1,
  3572. BatchNumber: "",
  3573. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3574. PreTime: pTime,
  3575. PType: p_type,
  3576. MedType: med_type,
  3577. }
  3578. tempPrescription = prescription
  3579. service.SaveHisPrescription(tempPrescription)
  3580. redis := service.RedisClient()
  3581. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3582. redis.Set(key, "", time.Second)
  3583. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3584. redis.Set(keyOne, "", time.Second)
  3585. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3586. redis.Set(keySeven, "", time.Second)
  3587. defer redis.Close()
  3588. } else {
  3589. tempPrescription.ID = id
  3590. tempPrescription.Type = types
  3591. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3592. tempPrescription.Mtime = time.Now().Unix()
  3593. tempPrescription.Doctor = role.UserName
  3594. //tempPrescription.OrderStatus = order_status
  3595. tempPrescription.PreTime = pTime
  3596. tempPrescription.MedType = med_type
  3597. service.SaveHisPrescription(tempPrescription)
  3598. redis := service.RedisClient()
  3599. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3600. redis.Set(key, "", time.Second)
  3601. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3602. redis.Set(keyOne, "", time.Second)
  3603. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3604. redis.Set(keySeven, "", time.Second)
  3605. defer redis.Close()
  3606. }
  3607. //service.SaveHisPrescription(prescription)
  3608. //更改患者挂号状态
  3609. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3610. fmt.Println("更改失败", err2)
  3611. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3612. advices := items["advices"].([]interface{})
  3613. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3614. groupNo := int64(0)
  3615. if len(advices) > 0 {
  3616. for _, advice := range advices {
  3617. var s models.HisDoctorAdviceInfo
  3618. s.PrescriptionId = tempPrescription.ID
  3619. s.AdviceType = 2
  3620. s.AdviceDoctor = doctor_id
  3621. s.StopState = 2
  3622. s.ExecutionState = 2
  3623. s.AdviceDate = theTime3.Unix()
  3624. s.Status = 1
  3625. s.UserOrgId = adminInfo.CurrentOrgId
  3626. s.RecordDate = theTime3.Unix()
  3627. s.StartTime = tempPrescription.PreTime
  3628. s.Groupno = groupNo
  3629. s.PatientId = patient_id
  3630. s.HisPatientId = his_patient_id
  3631. s.StartTime = pTime
  3632. s.IsSettle = 2
  3633. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3634. if errcode > 0 {
  3635. c.ServeFailJSONWithSGJErrorCode(errcode)
  3636. return
  3637. }
  3638. s.StartTime = pTime
  3639. var total_count int64 //处方总库存
  3640. //查询改药品信息
  3641. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3642. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3643. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3644. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3645. total_count += prescribingNumberSeven * medical.MinNumber
  3646. }
  3647. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3648. total_count += prescribingNumberSeven
  3649. }
  3650. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3651. total_count += prescribingNumberSeven
  3652. }
  3653. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3654. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3655. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3656. if s.Price != lastWarehouse.RetailPrice {
  3657. s.Price = lastWarehouse.RetailPrice
  3658. }
  3659. if s.Price == 0 {
  3660. s.Price = lastWarehouse.RetailPrice
  3661. }
  3662. }
  3663. service.CreateHisDoctorAdvice(&s)
  3664. //记录日志
  3665. byterequest, _ := json.Marshal(s)
  3666. adviceLog := models.XtDoctorAdviceLog{
  3667. UserOrgId: s.UserOrgId,
  3668. PatientId: s.PatientId,
  3669. AdminUserId: adminInfo.AdminUser.Id,
  3670. Module: 1,
  3671. ErrLog: string(byterequest),
  3672. Status: 1,
  3673. Ctime: time.Now().Unix(),
  3674. Mtime: 0,
  3675. Source: "电脑端新建his医嘱",
  3676. RecordDate: s.AdviceDate,
  3677. }
  3678. service.CreateDoctorAdviceLog(adviceLog)
  3679. //存储切片中
  3680. adviceList = append(adviceList, s)
  3681. redis := service.RedisClient()
  3682. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3683. redis.Set(key, "", time.Second)
  3684. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3685. redis.Set(keyOne, "", time.Second)
  3686. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3687. redis.Set(keySeven, "", time.Second)
  3688. var randNum int
  3689. randNum = rand.Intn(10000) + 1000
  3690. timestamp := time.Now().Unix()
  3691. tempTime := time.Unix(timestamp, 0)
  3692. timeFormat := tempTime.Format("20060102150405")
  3693. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3694. service.CreateHisDoctorAdvice(&s)
  3695. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3696. redis.Set(keySix, "", time.Second)
  3697. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3698. redis.Set(keyFive, "", time.Second)
  3699. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3700. redis.Set(keyEight, "", time.Second)
  3701. defer redis.Close()
  3702. }
  3703. }
  3704. }
  3705. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3706. projects := items["project"].([]interface{})
  3707. if len(projects) > 0 {
  3708. for _, project := range projects {
  3709. var p models.HisPrescriptionProject
  3710. p.PrescriptionId = tempPrescription.ID
  3711. p.PatientId = patient_id
  3712. p.RecordDate = theTime3.Unix()
  3713. p.Doctor = doctor_id
  3714. p.UserOrgId = adminInfo.CurrentOrgId
  3715. p.HisPatientId = his_patient_id
  3716. p.Status = 1
  3717. p.StartTime = pTime
  3718. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3719. if errcode > 0 {
  3720. c.ServeFailJSONWithSGJErrorCode(errcode)
  3721. return
  3722. }
  3723. if p.ID == 0 {
  3724. p.IsOut = 2
  3725. }
  3726. if p.ID > 0 {
  3727. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3728. p.IsOut = projectDetail.IsOut
  3729. }
  3730. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3731. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3732. if p.Type == 3 {
  3733. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3734. if p.Price != lastWarehouse.PackingPrice {
  3735. p.Price = lastWarehouse.PackingPrice
  3736. }
  3737. if p.Unit == "" {
  3738. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3739. p.Unit = goodInfoOne.PackingUnit
  3740. }
  3741. }
  3742. }
  3743. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3744. //
  3745. // if p.Type == 3 {
  3746. // //查询该耗材是否停用
  3747. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3748. // //表示该耗材已经停用,不能保存
  3749. // if goodInfoSeven.ID == 0 {
  3750. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3751. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3752. // return
  3753. // }
  3754. // }
  3755. //
  3756. //}
  3757. service.CreateHisProjectTwo(&p)
  3758. //记录日志
  3759. byterequest, _ := json.Marshal(p)
  3760. adviceLog := models.XtDoctorAdviceLog{
  3761. UserOrgId: p.UserOrgId,
  3762. PatientId: p.PatientId,
  3763. AdminUserId: adminInfo.AdminUser.Id,
  3764. Module: 1,
  3765. ErrLog: string(byterequest),
  3766. Status: 1,
  3767. Ctime: time.Now().Unix(),
  3768. Mtime: 0,
  3769. Source: "电脑端新建his项目",
  3770. RecordDate: p.RecordDate,
  3771. }
  3772. service.CreateDoctorAdviceLog(adviceLog)
  3773. projectList = append(projectList, p)
  3774. var randNum int
  3775. randNum = rand.Intn(10000) + 1000
  3776. timestamp := time.Now().Unix()
  3777. tempTime := time.Unix(timestamp, 0)
  3778. timeFormat := tempTime.Format("20060102150405")
  3779. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3780. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3781. //新增或者编辑项目,修改对应的标签数据
  3782. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3783. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3784. var label models.HisLabelPrintInfo
  3785. project, _ := service.GetProjectDetail(p.ProjectId)
  3786. if project.CostClassify == 3 { //类别为检验检查
  3787. if p.TeamId > 0 { //检验检查组套
  3788. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3789. if tempLabel.ID == 0 {
  3790. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3791. label.Number = tempPrescription.PrescriptionNumber
  3792. label.ProjectId = project.ID
  3793. label.Status = 1
  3794. label.IsPrint = 2
  3795. label.DoctorId = info.DoctorId
  3796. label.UserOrgId = p.UserOrgId
  3797. label.PatientId = patient_id
  3798. label.RecordDate = recordDateTime
  3799. label.Ctime = time.Now().Unix()
  3800. label.Mtime = time.Now().Unix()
  3801. label.ItemId = p.TeamId
  3802. label.FeedetlSn = p.FeedetlSn
  3803. label.PProjectId = p.ID
  3804. label.ProjectName = team.ProjectTeam
  3805. label.PatientName = patient.Name
  3806. service.CreateHisLabelRecord(&label)
  3807. }
  3808. } else { //单条检验检查项目
  3809. label.Number = tempPrescription.PrescriptionNumber
  3810. label.ProjectId = project.ID
  3811. label.Status = 1
  3812. label.DoctorId = info.DoctorId
  3813. label.UserOrgId = p.UserOrgId
  3814. label.PatientId = patient_id
  3815. label.RecordDate = recordDateTime
  3816. label.IsPrint = 2
  3817. label.Ctime = time.Now().Unix()
  3818. label.Mtime = time.Now().Unix()
  3819. label.FeedetlSn = p.FeedetlSn
  3820. label.PProjectId = p.ID
  3821. label.ItemId = p.TeamId
  3822. label.ProjectName = project.ProjectName
  3823. label.PatientName = patient.Name
  3824. service.CreateHisLabelRecord(&label)
  3825. }
  3826. }
  3827. }
  3828. }
  3829. service.SaveHisProjectTwo(&p)
  3830. }
  3831. }
  3832. }
  3833. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3834. // addition := items["addition"].([]interface{})
  3835. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3836. // ctime := time.Now().Unix()
  3837. // mtime := ctime
  3838. // if len(addition) > 0 {
  3839. // for _, item := range addition {
  3840. // var s models.HisAdditionalCharge
  3841. // s.PrescriptionId = tempPrescription.ID
  3842. // s.Status = 1
  3843. // s.UserOrgId = adminInfo.CurrentOrgId
  3844. // s.RecordDate = recordDateTime
  3845. // s.CreatedTime = ctime
  3846. // s.UpdatedTime = mtime
  3847. // s.PatientId = patient_id
  3848. // s.HisPatientId = his_patient_id
  3849. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3850. // if errcode > 0 {
  3851. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3852. // return
  3853. // }
  3854. // service.CreateAdditionalCharge(&s)
  3855. // var randNum int
  3856. // randNum = rand.Intn(10000) + 1000
  3857. // timestamp := time.Now().Unix()
  3858. // tempTime := time.Unix(timestamp, 0)
  3859. // timeFormat := tempTime.Format("20060102150405")
  3860. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3861. // service.CreateAdditionalCharge(&s)
  3862. //
  3863. // }
  3864. // }
  3865. //}
  3866. }
  3867. }
  3868. //查询今日该患者开的药品处方
  3869. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3870. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3871. //药品出库
  3872. if drugOutConfig.IsOpen == 1 {
  3873. for _, item := range hisdoctorlist {
  3874. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3875. // 查询该药品最后一次出库记录
  3876. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3877. if len(druginfo) > 0 {
  3878. //回退库存
  3879. for _, it := range druginfo {
  3880. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3881. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3882. }
  3883. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3884. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3885. }
  3886. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3887. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3888. }
  3889. }
  3890. }
  3891. //删除记录
  3892. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3893. //查询最后一次数据
  3894. if drugOutConfig.IsOpen == 1 {
  3895. //出库
  3896. if drug.IsUse == 2 {
  3897. creater := adminInfo.AdminUser.Id
  3898. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3899. }
  3900. //更新字典里面的库存
  3901. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3902. var sum_count int64
  3903. for _, its := range stockInfo {
  3904. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3905. if its.MaxUnit == baseDrug.MaxUnit {
  3906. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3907. }
  3908. sum_count += its.StockMaxNumber + its.StockMinNumber
  3909. }
  3910. //更新基础库存
  3911. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3912. //剩余库存
  3913. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3914. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3915. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3916. }
  3917. }
  3918. }
  3919. //耗材保存处方出库
  3920. if goodOutConfig.IsOpen == 1 {
  3921. //查询今日耗材出库数量
  3922. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3923. for _, item := range hisgoodlist {
  3924. //查询历史出库数据
  3925. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3926. var out_count_five int64
  3927. for _, item := range flowGood {
  3928. out_count_five += item.Count
  3929. }
  3930. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3931. if out_count_five != parseIntCount {
  3932. //查询耗材最后一次出库记录
  3933. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3934. //查询默认出库仓库库存
  3935. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3936. if len(wareOut) > 0 {
  3937. for _, it := range wareOut {
  3938. //回退库存
  3939. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3940. //删除出库记录
  3941. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3942. }
  3943. }
  3944. timeStr := time.Now().Format("2006-01-02")
  3945. timeArr := strings.Split(timeStr, "-")
  3946. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3947. total = total + 1
  3948. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3949. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3950. number = number + total
  3951. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3952. operation_time := time.Now().Unix()
  3953. creater := c.GetAdminUserInfo().AdminUser.Id
  3954. recordDateStr := time.Now().Format("2006-01-02")
  3955. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3956. nowtime := recordDate.Unix()
  3957. warehouseOut := models.WarehouseOut{
  3958. WarehouseOutOrderNumber: warehousing_out_order,
  3959. OperationTime: operation_time,
  3960. OrgId: adminInfo.CurrentOrgId,
  3961. Creater: creater,
  3962. Ctime: time.Now().Unix(),
  3963. Status: 1,
  3964. WarehouseOutTime: nowtime,
  3965. Type: 1,
  3966. StorehouseId: storeConfig.StorehouseOutInfo,
  3967. IsCheck: 1,
  3968. IsSys: 1,
  3969. }
  3970. //查询是否生成出库单
  3971. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3972. if out.ID == 0 {
  3973. service.AddSigleWarehouseOut(&warehouseOut)
  3974. }
  3975. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3976. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3977. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3978. dialyPrepareOne := models.DialysisBeforePrepare{
  3979. GoodTypeId: goodObj.GoodTypeId,
  3980. GoodId: item.ProjectId,
  3981. PatientId: item.PatientId,
  3982. RecordDate: item.RecordDate,
  3983. UserOrgId: adminInfo.CurrentOrgId,
  3984. Count: parseIntCount,
  3985. Ctime: time.Now().Unix(),
  3986. Creater: creater,
  3987. Status: 1,
  3988. StorehouseId: houseConfig.StorehouseOutInfo,
  3989. ProjectId: item.ID,
  3990. }
  3991. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3992. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3993. //查询历史出库数据
  3994. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3995. var out_count int64
  3996. for _, item := range flowGood {
  3997. out_count += item.Count
  3998. }
  3999. //如果历史数和当前数据不想等才进行退库出库
  4000. if out_count != parseIntCount {
  4001. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4002. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4003. detail := models.AutomaticReduceDetail{
  4004. WarehouseOutId: 0,
  4005. WarehouseOutOrderNumber: "",
  4006. PatientId: item.PatientId,
  4007. Ctime: time.Now().Unix(),
  4008. Mtime: 0,
  4009. Status: 1,
  4010. RecordTime: item.RecordDate,
  4011. OrgId: item.UserOrgId,
  4012. GoodId: item.ProjectId,
  4013. GoodTypeId: 0,
  4014. Count: parseIntCount,
  4015. Type: 0,
  4016. ProjectId: item.ID,
  4017. StorehouseId: 0,
  4018. }
  4019. service.CreateAutoDetail(detail)
  4020. //查询剩余库存
  4021. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4022. var sum_count int64
  4023. for _, item := range goodList {
  4024. sum_count += item.StockCount
  4025. }
  4026. //更新剩余库存
  4027. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4028. //耗材
  4029. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4030. }
  4031. }
  4032. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4033. //查询历史出库数据
  4034. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4035. var out_count int64
  4036. for _, item := range flowGood {
  4037. out_count += item.Count
  4038. }
  4039. //如果历史数和当前数据不想等才进行退库出库
  4040. if out_count != parseIntCount {
  4041. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4042. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4043. detail := models.AutomaticReduceDetail{
  4044. WarehouseOutId: 0,
  4045. WarehouseOutOrderNumber: "",
  4046. PatientId: item.PatientId,
  4047. Ctime: time.Now().Unix(),
  4048. Mtime: 0,
  4049. Status: 1,
  4050. RecordTime: item.RecordDate,
  4051. OrgId: item.UserOrgId,
  4052. GoodId: item.ProjectId,
  4053. GoodTypeId: 0,
  4054. Count: parseIntCount,
  4055. Type: 0,
  4056. ProjectId: item.ID,
  4057. StorehouseId: 0,
  4058. }
  4059. service.CreateAutoDetail(detail)
  4060. //查询剩余库存
  4061. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4062. var sum_count int64
  4063. for _, item := range goodList {
  4064. sum_count += item.StockCount
  4065. }
  4066. //更新剩余库存
  4067. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4068. //耗材
  4069. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4070. }
  4071. }
  4072. }
  4073. }
  4074. }
  4075. }
  4076. tx.Commit()
  4077. if err == nil {
  4078. c.ServeSuccessJSON(map[string]interface{}{
  4079. "msg": "保存成功",
  4080. })
  4081. return
  4082. } else {
  4083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4084. return
  4085. }
  4086. }
  4087. }
  4088. //func (c *HisApiController) EditHisPrescription() {
  4089. // record_date := c.GetString("record_date")
  4090. // patient_id, _ := c.GetInt64("patient_id")
  4091. // reg_type, _ := c.GetInt64("reg_type")
  4092. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4093. // diagnose := c.GetString("diagnose")
  4094. // sick_type, _ := c.GetInt64("sick_type")
  4095. // sick_history := c.GetString("sick_history")
  4096. // doctor_id, _ := c.GetInt64("doctor", 0)
  4097. // department, _ := c.GetInt64("department", 0)
  4098. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4099. // p_type, _ := c.GetInt64("p_type")
  4100. //
  4101. // dataBody := make(map[string]interface{}, 0)
  4102. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4103. // if err != nil {
  4104. // utils.ErrorLog(err.Error())
  4105. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4106. // return
  4107. // }
  4108. //
  4109. // timeLayout := "2006-01-02"
  4110. // loc, _ := time.LoadLocation("Local")
  4111. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4112. // if err != nil {
  4113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4114. // return
  4115. // }
  4116. // adminInfo := c.GetAdminUserInfo()
  4117. // recordDateTime := theTime.Unix()
  4118. //
  4119. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4120. //
  4121. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4122. // var hpInfo models.HisPrescriptionInfo
  4123. // if info.ID == 0 {
  4124. // var randNum int
  4125. // randNum = rand.Intn(10000) + 1000
  4126. // timestamp := time.Now().Unix()
  4127. // tempTime := time.Unix(timestamp, 0)
  4128. // timeFormat := tempTime.Format("20060102150405")
  4129. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4130. //
  4131. // hpInfo = models.HisPrescriptionInfo{
  4132. // UserOrgId: adminInfo.CurrentOrgId,
  4133. // RecordDate: theTime.Unix(),
  4134. // PatientId: patient_id,
  4135. // Status: 1,
  4136. // Ctime: time.Now().Unix(),
  4137. // Mtime: time.Now().Unix(),
  4138. // Creator: adminInfo.AdminUser.Id,
  4139. // Modifier: adminInfo.AdminUser.Id,
  4140. // Diagnosis: diagnose,
  4141. // SickHistory: sick_history,
  4142. // Departments: department,
  4143. // RegisterType: reg_type,
  4144. // PrescriptionNumber: p_number,
  4145. // PrescriptionStatus: 1,
  4146. // Doctor: role.UserName,
  4147. // DoctorId: doctor_id,
  4148. // SickType: sick_type,
  4149. // PType: p_type,
  4150. // }
  4151. // service.SavePatientPrescriptionInfo(hpInfo)
  4152. //
  4153. // } else {
  4154. // hpInfo = models.HisPrescriptionInfo{
  4155. // ID: info.ID,
  4156. // UserOrgId: adminInfo.CurrentOrgId,
  4157. // RecordDate: info.RecordDate,
  4158. // PatientId: info.PatientId,
  4159. // Status: 1,
  4160. // Ctime: info.Ctime,
  4161. // Mtime: time.Now().Unix(),
  4162. // Creator: info.Creator,
  4163. // Modifier: adminInfo.AdminUser.Id,
  4164. // Diagnosis: diagnose,
  4165. // SickHistory: sick_history,
  4166. // Departments: department,
  4167. // RegisterType: reg_type,
  4168. // PrescriptionNumber: info.PrescriptionNumber,
  4169. // Doctor: role.UserName,
  4170. // PrescriptionStatus: info.PrescriptionStatus,
  4171. // DoctorId: doctor_id,
  4172. // SickType: sick_type,
  4173. // PType: info.PType,
  4174. // }
  4175. // service.SavePatientPrescriptionInfo(hpInfo)
  4176. // }
  4177. //
  4178. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4179. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4180. //
  4181. // if len(prescriptions) > 0 {
  4182. // for _, item := range prescriptions {
  4183. // items := item.(map[string]interface{})
  4184. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4185. // utils.ErrorLog("id")
  4186. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4187. // return
  4188. // }
  4189. // id := int64(items["id"].(float64))
  4190. //
  4191. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4192. // utils.ErrorLog("type")
  4193. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4194. // return
  4195. // }
  4196. // types := int64(items["type"].(float64))
  4197. //
  4198. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4199. // utils.ErrorLog("med_type")
  4200. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4201. // return
  4202. // }
  4203. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4204. //
  4205. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4206. //
  4207. // ctime := time.Now().Unix()
  4208. //
  4209. // prescription := &models.HisPrescription{
  4210. // ID: id,
  4211. // PatientId: patient_id,
  4212. // UserOrgId: adminInfo.CurrentOrgId,
  4213. // RecordDate: recordDateTime,
  4214. // Ctime: ctime,
  4215. // Mtime: ctime,
  4216. // Type: types,
  4217. // Modifier: adminInfo.AdminUser.Id,
  4218. // Creator: adminInfo.AdminUser.Id,
  4219. // Status: 1,
  4220. // Doctor: role.UserName,
  4221. // HisPatientId: his_patient_id,
  4222. // OrderStatus: 1,
  4223. // BatchNumber: "",
  4224. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4225. // PType: hpInfo.PType,
  4226. // MedType: med_type,
  4227. // }
  4228. //
  4229. // if historyPrescription.ID > 0 {
  4230. // prescription.PreTime = historyPrescription.PreTime
  4231. //
  4232. // }
  4233. //
  4234. // service.SaveHisPrescription(prescription)
  4235. //
  4236. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4237. // advices := items["advices"].([]interface{})
  4238. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4239. // groupNo := int64(0)
  4240. // ctime := time.Now().Unix()
  4241. // mtime := ctime
  4242. // if len(advices) > 0 {
  4243. // for _, advice := range advices {
  4244. // var s models.HisDoctorAdviceInfo
  4245. // s.PrescriptionId = prescription.ID
  4246. // s.AdviceType = 2
  4247. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4248. // s.StopState = 2
  4249. // s.ExecutionState = 2
  4250. // s.AdviceDate = recordDateTime
  4251. // s.Status = 1
  4252. // s.UserOrgId = adminInfo.CurrentOrgId
  4253. // s.RecordDate = recordDateTime
  4254. // s.StartTime = prescription.PreTime
  4255. // s.Groupno = groupNo
  4256. // s.CreatedTime = ctime
  4257. // s.UpdatedTime = mtime
  4258. // s.PatientId = patient_id
  4259. // s.HisPatientId = his_patient_id
  4260. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4261. // if errcode > 0 {
  4262. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4263. // return
  4264. // }
  4265. //
  4266. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4267. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4268. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4269. // if s.Price == 0 {
  4270. // s.Price = lastWarehouse.RetailPrice
  4271. // }
  4272. // }
  4273. //
  4274. // service.CreateHisDoctorAdvice(&s)
  4275. // //记录日志
  4276. // byterequest, _ := json.Marshal(s)
  4277. // adviceLog := models.XtDoctorAdviceLog{
  4278. // UserOrgId: s.UserOrgId,
  4279. // PatientId: s.PatientId,
  4280. // AdminUserId: adminInfo.AdminUser.Id,
  4281. // Module: 1,
  4282. // ErrLog: string(byterequest),
  4283. // Status: 1,
  4284. // Ctime: time.Now().Unix(),
  4285. // Mtime: 0,
  4286. // Source: "电脑端his医嘱修改",
  4287. // RecordDate: s.AdviceDate,
  4288. // }
  4289. // service.CreateDoctorAdviceLog(adviceLog)
  4290. // redis := service.RedisClient()
  4291. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4292. // redis.Set(key, "", time.Second)
  4293. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4294. // fmt.Println("keyOne", keyOne)
  4295. // redis.Set(keyOne, "", time.Second)
  4296. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4297. // redis.Set(keySeven, "", time.Second)
  4298. // redis.Close()
  4299. //
  4300. // }
  4301. // }
  4302. // }
  4303. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4304. // projects := items["project"].([]interface{})
  4305. // if len(projects) > 0 {
  4306. // for _, project := range projects {
  4307. // var p models.HisPrescriptionProject
  4308. // p.PrescriptionId = prescription.ID
  4309. // p.Ctime = time.Now().Unix()
  4310. // p.Mtime = time.Now().Unix()
  4311. // p.PatientId = patient_id
  4312. // p.RecordDate = recordDateTime
  4313. // p.UserOrgId = adminInfo.CurrentOrgId
  4314. // p.HisPatientId = his_patient_id
  4315. // p.Status = 1
  4316. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4317. // if errcode > 0 {
  4318. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4319. // return
  4320. // }
  4321. // service.CreateHisProjectTwo(&p)
  4322. //
  4323. // //记录日志
  4324. // byterequest, _ := json.Marshal(p)
  4325. // adviceLog := models.XtDoctorAdviceLog{
  4326. // UserOrgId: p.UserOrgId,
  4327. // PatientId: p.PatientId,
  4328. // AdminUserId: adminInfo.AdminUser.Id,
  4329. // Module: 1,
  4330. // ErrLog: string(byterequest),
  4331. // Status: 1,
  4332. // Ctime: time.Now().Unix(),
  4333. // Mtime: 0,
  4334. // Source: "电脑端his项目修改",
  4335. // RecordDate: p.RecordDate,
  4336. // }
  4337. // service.CreateDoctorAdviceLog(adviceLog)
  4338. // }
  4339. // }
  4340. // }
  4341. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4342. // addition := items["addition"].([]interface{})
  4343. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4344. // ctime := time.Now().Unix()
  4345. // mtime := ctime
  4346. // if len(addition) > 0 {
  4347. // for _, item := range addition {
  4348. // var s models.HisAdditionalCharge
  4349. // s.PrescriptionId = prescription.ID
  4350. // s.Status = 1
  4351. // s.UserOrgId = adminInfo.CurrentOrgId
  4352. // s.RecordDate = recordDateTime
  4353. // s.CreatedTime = ctime
  4354. // s.UpdatedTime = mtime
  4355. // s.PatientId = patient_id
  4356. // s.HisPatientId = his_patient_id
  4357. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4358. // if errcode > 0 {
  4359. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4360. // return
  4361. // }
  4362. // service.CreateAdditionalCharge(&s)
  4363. // }
  4364. // }
  4365. // }
  4366. //
  4367. // }
  4368. // }
  4369. // }
  4370. // if err == nil {
  4371. // c.ServeSuccessJSON(map[string]interface{}{
  4372. // "msg": "保存成功",
  4373. // })
  4374. // return
  4375. //
  4376. // } else {
  4377. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4378. // return
  4379. // }
  4380. //}
  4381. func (c *HisApiController) DeletePrescription() {
  4382. prescription_id, _ := c.GetInt64("id")
  4383. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4384. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4385. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4386. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4387. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4388. //耗材保存处方出库
  4389. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4390. //已收费和已发药限制逻辑
  4391. isCharge := false
  4392. isMedicine := false
  4393. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4394. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4395. for _, item := range new_prescriptions {
  4396. if item.IsMedicine == 1 {
  4397. isMedicine = true
  4398. }
  4399. }
  4400. for _, item := range new_prescriptions {
  4401. if item.OrderStatus == 4 {
  4402. isCharge = true
  4403. }
  4404. }
  4405. if p_err != nil {
  4406. if new_prescription.ID > 0 {
  4407. if new_prescription.OrderStatus == 2 {
  4408. isCharge = true
  4409. }
  4410. }
  4411. }
  4412. for _, item := range advices {
  4413. if item.IsMedicine == 1 {
  4414. isMedicine = true
  4415. }
  4416. }
  4417. if isCharge {
  4418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4419. return
  4420. }
  4421. if isMedicine {
  4422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4423. return
  4424. }
  4425. //已收费和已发药限制逻辑
  4426. if len(projects) > 0 {
  4427. for _, item := range projects {
  4428. service.DeletePrintInfo(item.ID) //删除打印信息
  4429. if goodOutConfig.IsOpen != 1 {
  4430. if stockConfig.IsOpen == 1 {
  4431. if item.Type == 3 && item.IsOut == 1 {
  4432. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4433. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4434. good.Total = good.Total + f_count
  4435. service.UpdateGoodInfo(&good)
  4436. operation_time := time.Now().Unix()
  4437. creater := c.GetAdminUserInfo().AdminUser.Id
  4438. //创建退库单
  4439. timeStr := time.Now().Format("2006-01-02")
  4440. timeArr := strings.Split(timeStr, "-")
  4441. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4442. total = total + 1
  4443. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4444. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4445. cancelStock := models.CancelStock{
  4446. OrderNumber: orderNumber,
  4447. OperaTime: operation_time,
  4448. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4449. Creater: creater,
  4450. Ctime: time.Now().Unix(),
  4451. Status: 1,
  4452. ReturnTime: item.RecordDate,
  4453. Type: 1,
  4454. StorehouseId: houseConfig.StorehouseOutInfo,
  4455. IsCheck: 1,
  4456. }
  4457. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4458. if msgerrkonde == gorm.ErrRecordNotFound {
  4459. service.AddSigleCancelStock(&cancelStock)
  4460. }
  4461. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4462. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4463. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4464. //查询该耗材是否出库
  4465. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4466. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4467. deaerler, _ := service.GetDealerById(info.Dealer)
  4468. var total_count int64
  4469. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4470. total_count += count
  4471. if info.ID > 0 {
  4472. if info.Count >= total_count {
  4473. //回退库存
  4474. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4475. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4476. var flush_count int64
  4477. for _, it := range goodList {
  4478. flush_count += it.StockCount
  4479. }
  4480. cancelStockInfo := models.CancelStockInfo{
  4481. GoodId: item.ProjectId,
  4482. CancelStockId: cancel.ID,
  4483. GoodTypeId: good.GoodTypeId,
  4484. Count: prescribingNumber,
  4485. Price: info.Price,
  4486. Total: 0,
  4487. ProductDate: info.ProductDate,
  4488. ExpiryDate: info.ExpiryDate,
  4489. Ctime: time.Now().Unix(),
  4490. Status: 1,
  4491. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4492. OrderNumber: cancel.OrderNumber,
  4493. Type: 0,
  4494. Dealer: deaerler.DealerName,
  4495. Manufacturer: manufacturer.ManufacturerName,
  4496. Number: info.Number,
  4497. RegisterAccount: "",
  4498. Remark: "",
  4499. WarehouseInfoId: info.WarehouseInfotId,
  4500. PatientId: info.PatientId,
  4501. RecordDate: info.SysRecordTime,
  4502. StorehouseId: houseConfig.StorehouseOutInfo,
  4503. IsCheck: 1,
  4504. }
  4505. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4506. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4507. flow := models.VmStockFlow{
  4508. WarehousingId: info.WarehouseInfotId,
  4509. GoodId: item.ProjectId,
  4510. Number: info.Number,
  4511. LicenseNumber: info.LicenseNumber,
  4512. Count: prescribingNumber,
  4513. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4514. PatientId: item.PatientId,
  4515. SystemTime: info.SysRecordTime,
  4516. ConsumableType: 7,
  4517. IsSys: 0,
  4518. WarehousingOrder: "",
  4519. WarehouseOutId: info.WarehouseOutId,
  4520. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4521. IsEdit: 0,
  4522. CancelStockId: cancel.ID,
  4523. CancelOrderNumber: cancel.OrderNumber,
  4524. Manufacturer: manufacturer.ID,
  4525. Dealer: 0,
  4526. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4527. UpdateCreator: 0,
  4528. Status: 1,
  4529. Ctime: time.Now().Unix(),
  4530. Mtime: 0,
  4531. Price: info.Price,
  4532. WarehousingDetailId: info.WarehouseInfotId,
  4533. WarehouseOutDetailId: info.ID,
  4534. CancelOutDetailId: cancelInfo.ID,
  4535. ProductDate: info.ProductDate,
  4536. ExpireDate: info.ExpiryDate,
  4537. StorehouseId: houseConfig.StorehouseOutInfo,
  4538. OverCount: flush_count,
  4539. }
  4540. service.CreateStockFlowOne(flow)
  4541. //退库数量增加
  4542. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4543. //出库数量减少
  4544. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4545. }
  4546. if info.Count < total_count {
  4547. //回退库存
  4548. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4549. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4550. var flush_count int64
  4551. for _, it := range goodList {
  4552. flush_count += it.StockCount
  4553. }
  4554. cancelStockInfo := models.CancelStockInfo{
  4555. GoodId: item.ProjectId,
  4556. CancelStockId: cancel.ID,
  4557. GoodTypeId: good.GoodTypeId,
  4558. Count: info.Count,
  4559. Price: info.Price,
  4560. Total: 0,
  4561. ProductDate: info.ProductDate,
  4562. ExpiryDate: info.ExpiryDate,
  4563. Ctime: time.Now().Unix(),
  4564. Status: 1,
  4565. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4566. OrderNumber: cancel.OrderNumber,
  4567. Type: 0,
  4568. Dealer: deaerler.DealerName,
  4569. Manufacturer: manufacturer.ManufacturerName,
  4570. Number: info.Number,
  4571. RegisterAccount: "",
  4572. Remark: "",
  4573. WarehouseInfoId: info.WarehouseInfotId,
  4574. PatientId: info.PatientId,
  4575. RecordDate: info.SysRecordTime,
  4576. StorehouseId: houseConfig.StorehouseOutInfo,
  4577. IsCheck: 1,
  4578. }
  4579. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4580. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4581. flow := models.VmStockFlow{
  4582. WarehousingId: info.WarehouseInfotId,
  4583. GoodId: item.ProjectId,
  4584. Number: info.Number,
  4585. LicenseNumber: info.LicenseNumber,
  4586. Count: info.Count,
  4587. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4588. PatientId: item.PatientId,
  4589. SystemTime: info.SysRecordTime,
  4590. ConsumableType: 7,
  4591. IsSys: 0,
  4592. WarehousingOrder: "",
  4593. WarehouseOutId: info.WarehouseOutId,
  4594. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4595. IsEdit: 0,
  4596. CancelStockId: cancel.ID,
  4597. CancelOrderNumber: cancel.OrderNumber,
  4598. Manufacturer: manufacturer.ID,
  4599. Dealer: 0,
  4600. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4601. UpdateCreator: 0,
  4602. Status: 1,
  4603. Ctime: time.Now().Unix(),
  4604. Mtime: 0,
  4605. Price: info.Price,
  4606. WarehousingDetailId: info.WarehouseInfotId,
  4607. WarehouseOutDetailId: info.ID,
  4608. CancelOutDetailId: cancelInfo.ID,
  4609. ProductDate: info.ProductDate,
  4610. ExpireDate: info.ExpiryDate,
  4611. StorehouseId: houseConfig.StorehouseOutInfo,
  4612. OverCount: flush_count,
  4613. }
  4614. service.CreateStockFlowOne(flow)
  4615. //退库数量增加
  4616. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4617. //出库数量减少
  4618. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4619. }
  4620. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4621. var flush_count int64
  4622. for _, it := range goodList {
  4623. flush_count += it.StockCount
  4624. }
  4625. //查询已出库数量
  4626. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4627. if prescribingNumber < dialysisInfo.Count {
  4628. //改变数量
  4629. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4630. }
  4631. if prescribingNumber >= dialysisInfo.Count {
  4632. //删除出库表
  4633. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4634. }
  4635. //更新库存
  4636. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4637. //更新基础库库存
  4638. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4639. }
  4640. }
  4641. }
  4642. }
  4643. //保存耗材出库
  4644. if goodOutConfig.IsOpen == 1 {
  4645. if item.Type == 3 {
  4646. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4647. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4648. good.Total = good.Total + f_count
  4649. service.UpdateGoodInfo(&good)
  4650. operation_time := time.Now().Unix()
  4651. creater := c.GetAdminUserInfo().AdminUser.Id
  4652. //创建退库单
  4653. timeStr := time.Now().Format("2006-01-02")
  4654. timeArr := strings.Split(timeStr, "-")
  4655. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4656. total = total + 1
  4657. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4658. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4659. cancelStock := models.CancelStock{
  4660. OrderNumber: orderNumber,
  4661. OperaTime: operation_time,
  4662. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4663. Creater: creater,
  4664. Ctime: time.Now().Unix(),
  4665. Status: 1,
  4666. ReturnTime: item.RecordDate,
  4667. Type: 1,
  4668. StorehouseId: houseConfig.StorehouseOutInfo,
  4669. IsCheck: 1,
  4670. }
  4671. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4672. if msgerrkonde == gorm.ErrRecordNotFound {
  4673. service.AddSigleCancelStock(&cancelStock)
  4674. }
  4675. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4676. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4677. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4678. //查询该耗材是否出库
  4679. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4680. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4681. deaerler, _ := service.GetDealerById(info.Dealer)
  4682. var total_count int64
  4683. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4684. total_count += count
  4685. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4686. var flush_count int64
  4687. for _, it := range goodList {
  4688. flush_count += it.StockCount
  4689. }
  4690. fmt.Println("历史出库数据", info.Count)
  4691. fmt.Println("出库数量", total_count)
  4692. if info.ID > 0 {
  4693. cancelStockInfo := models.CancelStockInfo{
  4694. GoodId: item.ProjectId,
  4695. CancelStockId: cancel.ID,
  4696. GoodTypeId: good.GoodTypeId,
  4697. Count: prescribingNumber,
  4698. Price: info.Price,
  4699. Total: 0,
  4700. ProductDate: info.ProductDate,
  4701. ExpiryDate: info.ExpiryDate,
  4702. Ctime: time.Now().Unix(),
  4703. Status: 1,
  4704. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4705. OrderNumber: cancel.OrderNumber,
  4706. Type: 0,
  4707. Dealer: deaerler.DealerName,
  4708. Manufacturer: manufacturer.ManufacturerName,
  4709. Number: info.Number,
  4710. RegisterAccount: "",
  4711. Remark: "",
  4712. WarehouseInfoId: info.WarehouseInfotId,
  4713. PatientId: info.PatientId,
  4714. RecordDate: info.SysRecordTime,
  4715. StorehouseId: houseConfig.StorehouseOutInfo,
  4716. IsCheck: 1,
  4717. }
  4718. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4719. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4720. //查询出库数量
  4721. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4722. //出库数据 大于 退库数量
  4723. if len(list) > 0 {
  4724. for _, it := range list {
  4725. //回退库存
  4726. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4727. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4728. var flush_count_one int64
  4729. for _, it := range goodList {
  4730. flush_count_one += it.StockCount
  4731. }
  4732. //查询该批次是否有退库数据
  4733. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4734. creater := c.GetAdminUserInfo().AdminUser.Id
  4735. flow := models.VmStockFlow{
  4736. WarehousingId: it.WarehouseInfotId,
  4737. GoodId: it.GoodId,
  4738. Number: it.Number,
  4739. LicenseNumber: it.LicenseNumber,
  4740. Count: it.Count,
  4741. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4742. PatientId: it.PatientId,
  4743. SystemTime: it.SysRecordTime,
  4744. ConsumableType: 7,
  4745. IsSys: 0,
  4746. WarehousingOrder: "",
  4747. WarehouseOutId: it.WarehouseOutId,
  4748. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4749. IsEdit: 0,
  4750. CancelStockId: cancel.ID,
  4751. CancelOrderNumber: cancel.OrderNumber,
  4752. Manufacturer: manufacturer.ID,
  4753. Dealer: 0,
  4754. Creator: creater,
  4755. UpdateCreator: 0,
  4756. Status: 1,
  4757. Ctime: time.Now().Unix(),
  4758. Mtime: 0,
  4759. Price: it.Price,
  4760. WarehousingDetailId: it.WarehouseInfotId,
  4761. WarehouseOutDetailId: it.ID,
  4762. CancelOutDetailId: cancelInfo.ID,
  4763. ProductDate: it.ProductDate,
  4764. ExpireDate: it.ExpiryDate,
  4765. StorehouseId: houseConfig.StorehouseOutInfo,
  4766. OverCount: flush_count_one,
  4767. }
  4768. service.CreateStockFlowOne(flow)
  4769. //if flow.ID > 0 {
  4770. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4771. //}
  4772. }
  4773. }
  4774. //flow := models.VmStockFlow{
  4775. // WarehousingId: info.WarehouseInfotId,
  4776. // GoodId: item.ProjectId,
  4777. // Number: info.Number,
  4778. // LicenseNumber: info.LicenseNumber,
  4779. // Count: prescribingNumber,
  4780. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4781. // PatientId: item.PatientId,
  4782. // SystemTime: info.SysRecordTime,
  4783. // ConsumableType: 7,
  4784. // IsSys: 0,
  4785. // WarehousingOrder: "",
  4786. // WarehouseOutId: info.WarehouseOutId,
  4787. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4788. // IsEdit: 0,
  4789. // CancelStockId: cancel.ID,
  4790. // CancelOrderNumber: cancel.OrderNumber,
  4791. // Manufacturer: manufacturer.ID,
  4792. // Dealer: 0,
  4793. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4794. // UpdateCreator: 0,
  4795. // Status: 1,
  4796. // Ctime: time.Now().Unix(),
  4797. // Mtime: 0,
  4798. // Price: info.Price,
  4799. // WarehousingDetailId: info.WarehouseInfotId,
  4800. // WarehouseOutDetailId: info.ID,
  4801. // CancelOutDetailId: cancelInfo.ID,
  4802. // ProductDate: info.ProductDate,
  4803. // ExpireDate: info.ExpiryDate,
  4804. // StorehouseId: houseConfig.StorehouseOutInfo,
  4805. // OverCount: flush_count,
  4806. //}
  4807. //service.CreateStockFlowOne(flow)
  4808. //退库数量增加
  4809. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4810. //出库数量减少
  4811. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4812. //查询已出库数量
  4813. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4814. if prescribingNumber < dialysisInfo.Count {
  4815. //改变数量
  4816. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4817. }
  4818. if prescribingNumber >= dialysisInfo.Count {
  4819. //删除出库表
  4820. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4821. }
  4822. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4823. var flush_count_one int64
  4824. for _, it := range goodList {
  4825. flush_count_one += it.StockCount
  4826. }
  4827. //更新库存
  4828. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4829. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4830. //更新基础库库存
  4831. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4832. }
  4833. }
  4834. }
  4835. }
  4836. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4837. fmt.Println(err)
  4838. }
  4839. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4840. fmt.Println(err)
  4841. if len(advices) > 0 {
  4842. for _, item := range advices {
  4843. redis := service.RedisClient()
  4844. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4845. redis.Set(keyFive, "", time.Second)
  4846. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4847. redis.Set(keyOne, "", time.Second)
  4848. redis.Close()
  4849. }
  4850. }
  4851. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4852. if len(advices) > 0 {
  4853. for _, item := range advices {
  4854. creater := c.GetAdminUserInfo().AdminUser.Id
  4855. service.DrugAutoAddCancelInfo(item, creater)
  4856. }
  4857. }
  4858. } else {
  4859. if drugOutConfig.IsOpen == 1 {
  4860. if len(advices) > 0 {
  4861. for _, item := range advices {
  4862. creater := c.GetAdminUserInfo().AdminUser.Id
  4863. service.DrugAutoAddCancelInfo(item, creater)
  4864. }
  4865. }
  4866. } else {
  4867. if len(advices) > 0 {
  4868. for _, item := range advices {
  4869. creater := c.GetAdminUserInfo().AdminUser.Id
  4870. service.DrugAutoAddCancelInfo(item, creater)
  4871. }
  4872. }
  4873. }
  4874. }
  4875. c.ServeSuccessJSON(map[string]interface{}{
  4876. "msg": "删除成功",
  4877. })
  4878. return
  4879. }
  4880. func (c *HisApiController) DeleteDoctorAdvice() {
  4881. id, _ := c.GetInt64("id")
  4882. advice, _ := service.GetHisDoctorAdvicesById(id)
  4883. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4884. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4885. //已收费和已发药的限制逻辑
  4886. isCharge := false
  4887. isMedicine := false
  4888. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4889. //获取今天该患者所有处方,判断是否发药或者收费
  4890. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4891. for _, item := range new_prescriptions {
  4892. if item.IsMedicine == 1 {
  4893. isMedicine = true
  4894. }
  4895. }
  4896. for _, item := range new_prescriptions {
  4897. if item.OrderStatus == 4 {
  4898. isCharge = true
  4899. }
  4900. }
  4901. if isMedicine {
  4902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4903. return
  4904. }
  4905. if isCharge {
  4906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4907. return
  4908. }
  4909. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4910. for _, item := range advices {
  4911. if item.IsMedicine == 1 {
  4912. isMedicine = true
  4913. }
  4914. }
  4915. if isMedicine {
  4916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4917. return
  4918. }
  4919. if new_prescription.ID > 0 {
  4920. if new_prescription.OrderStatus == 2 {
  4921. isCharge = true
  4922. }
  4923. }
  4924. if isCharge {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4926. return
  4927. }
  4928. //已收费和已发药的限制逻辑
  4929. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4930. redis := service.RedisClient()
  4931. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4932. redis.Set(keyFive, "", time.Second)
  4933. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4934. redis.Set(keyOne, "", time.Second)
  4935. defer redis.Close()
  4936. if err == nil {
  4937. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4938. //查询是否在处方中出库
  4939. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4940. if openConfig.IsOpen != 1 {
  4941. //判断该医嘱是否执行了
  4942. if advice.ExecutionState == 1 {
  4943. creater := c.GetAdminUserInfo().AdminUser.Id
  4944. service.DrugAutoAddCancelInfo(&advice, creater)
  4945. }
  4946. }
  4947. //开启保存处方扣减功能
  4948. if openConfig.IsOpen == 1 {
  4949. creater := c.GetAdminUserInfo().AdminUser.Id
  4950. service.DrugAutoAddCancelInfo(&advice, creater)
  4951. }
  4952. } else {
  4953. if drugOutConfig.IsOpen == 1 {
  4954. //查询是否在处方中出库
  4955. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4956. if openConfig.IsOpen != 1 {
  4957. //判断该医嘱是否执行了
  4958. if advice.ExecutionState == 1 {
  4959. creater := c.GetAdminUserInfo().AdminUser.Id
  4960. service.DrugAutoAddCancelInfo(&advice, creater)
  4961. }
  4962. }
  4963. //开启保存处方扣减功能
  4964. if openConfig.IsOpen == 1 {
  4965. creater := c.GetAdminUserInfo().AdminUser.Id
  4966. service.DrugAutoAddCancelInfo(&advice, creater)
  4967. }
  4968. } else {
  4969. //判断该医嘱是否执行了
  4970. if advice.ExecutionState == 1 {
  4971. creater := c.GetAdminUserInfo().AdminUser.Id
  4972. service.DrugAutoAddCancelInfo(&advice, creater)
  4973. }
  4974. }
  4975. }
  4976. c.ServeSuccessJSON(map[string]interface{}{
  4977. "msg": "删除成功",
  4978. })
  4979. return
  4980. } else {
  4981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4982. return
  4983. }
  4984. }
  4985. func (c *HisApiController) DeleteProject() {
  4986. id, _ := c.GetInt64("id")
  4987. adminInfo := c.GetAdminUserInfo()
  4988. project, _ := service.GetHisProjectByID(id)
  4989. // var consumable models.DialysisBeforePrepare
  4990. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4991. //耗材保存处方出库
  4992. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4993. isCharge := false
  4994. isMedicine := false
  4995. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4996. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4997. for _, item := range new_prescriptions {
  4998. if item.IsMedicine == 1 {
  4999. isMedicine = true
  5000. }
  5001. }
  5002. for _, item := range new_prescriptions {
  5003. if item.OrderStatus == 4 {
  5004. isCharge = true
  5005. }
  5006. }
  5007. if isMedicine {
  5008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5009. return
  5010. }
  5011. if isCharge {
  5012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5013. return
  5014. }
  5015. if new_prescription.ID > 0 {
  5016. if new_prescription.OrderStatus == 2 {
  5017. isCharge = true
  5018. }
  5019. }
  5020. if isCharge {
  5021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5022. return
  5023. }
  5024. service.DeletePrintInfo(id)
  5025. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5026. label.Status = 0
  5027. service.CreateHisLabelRecordTwo(&label)
  5028. fmt.Println(goodOutConfig.IsOpen)
  5029. if goodOutConfig.IsOpen != 1 {
  5030. if stockConfig.IsOpen == 1 {
  5031. if project.Type == 2 {
  5032. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5033. fmt.Println(err)
  5034. }
  5035. if project.Type == 3 && project.IsOut == 1 {
  5036. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5037. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5038. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5039. operation_time := time.Now().Unix()
  5040. creater := adminInfo.AdminUser.Id
  5041. //创建退库单
  5042. timeStr := time.Now().Format("2006-01-02")
  5043. timeArr := strings.Split(timeStr, "-")
  5044. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5045. total = total + 1
  5046. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5047. cancelStock := models.CancelStock{
  5048. OrderNumber: orderNumber,
  5049. OperaTime: operation_time,
  5050. OrgId: adminInfo.CurrentOrgId,
  5051. Creater: creater,
  5052. Ctime: time.Now().Unix(),
  5053. Status: 1,
  5054. ReturnTime: project.RecordDate,
  5055. Type: 1,
  5056. StorehouseId: houseConfig.StorehouseOutInfo,
  5057. IsCheck: 1,
  5058. }
  5059. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5060. if msgerrkonde == gorm.ErrRecordNotFound {
  5061. service.AddSigleCancelStock(&cancelStock)
  5062. }
  5063. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5064. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5065. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5066. //查询是否有出库
  5067. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5068. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5069. deaerler, _ := service.GetDealerById(info.Dealer)
  5070. if info.ID > 0 {
  5071. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5072. if info.Count >= prescribingNumber {
  5073. cancelStockInfo := models.CancelStockInfo{
  5074. GoodId: project.ProjectId,
  5075. CancelStockId: cancel.ID,
  5076. GoodTypeId: good.GoodTypeId,
  5077. Count: prescribingNumber,
  5078. Price: info.Price,
  5079. Total: 0,
  5080. ProductDate: info.ProductDate,
  5081. ExpiryDate: info.ExpiryDate,
  5082. Ctime: time.Now().Unix(),
  5083. Status: 1,
  5084. OrgId: adminInfo.CurrentOrgId,
  5085. OrderNumber: cancel.OrderNumber,
  5086. Type: 0,
  5087. Dealer: deaerler.DealerName,
  5088. Manufacturer: manufacturer.ManufacturerName,
  5089. Number: info.Number,
  5090. RegisterAccount: "",
  5091. Remark: "",
  5092. WarehouseInfoId: info.WarehouseInfotId,
  5093. PatientId: info.PatientId,
  5094. RecordDate: info.SysRecordTime,
  5095. StorehouseId: houseConfig.StorehouseOutInfo,
  5096. IsCheck: 1,
  5097. }
  5098. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5099. //回退库存
  5100. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5101. //退库数量增加
  5102. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5103. //出库数量减少
  5104. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5105. }
  5106. if info.Count < prescribingNumber {
  5107. cancelStockInfo := models.CancelStockInfo{
  5108. GoodId: project.ProjectId,
  5109. CancelStockId: cancel.ID,
  5110. GoodTypeId: good.GoodTypeId,
  5111. Count: info.Count,
  5112. Price: info.Price,
  5113. Total: 0,
  5114. ProductDate: info.ProductDate,
  5115. ExpiryDate: info.ExpiryDate,
  5116. Ctime: time.Now().Unix(),
  5117. Status: 1,
  5118. OrgId: adminInfo.CurrentOrgId,
  5119. OrderNumber: cancel.OrderNumber,
  5120. Type: 0,
  5121. Dealer: deaerler.DealerName,
  5122. Manufacturer: manufacturer.ManufacturerName,
  5123. Number: info.Number,
  5124. RegisterAccount: "",
  5125. Remark: "",
  5126. WarehouseInfoId: info.WarehouseInfotId,
  5127. PatientId: info.PatientId,
  5128. RecordDate: info.SysRecordTime,
  5129. StorehouseId: houseConfig.StorehouseOutInfo,
  5130. IsCheck: 1,
  5131. }
  5132. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5133. //回退库存
  5134. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5135. //退库数量增加
  5136. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5137. //出库数量减少
  5138. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5139. }
  5140. //查询剩余库存
  5141. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5142. var over_count int64
  5143. for _, it := range goodList {
  5144. over_count += it.StockCount
  5145. }
  5146. //出库数据 大于 退库数量
  5147. if info.Count >= prescribingNumber {
  5148. flow := models.VmStockFlow{
  5149. WarehousingId: info.WarehouseInfotId,
  5150. GoodId: project.ProjectId,
  5151. Number: info.Number,
  5152. LicenseNumber: info.LicenseNumber,
  5153. Count: prescribingNumber,
  5154. UserOrgId: adminInfo.CurrentOrgId,
  5155. PatientId: project.PatientId,
  5156. SystemTime: info.SysRecordTime,
  5157. ConsumableType: 7,
  5158. IsSys: 0,
  5159. WarehousingOrder: "",
  5160. WarehouseOutId: info.WarehouseOutId,
  5161. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5162. IsEdit: 0,
  5163. CancelStockId: cancel.ID,
  5164. CancelOrderNumber: cancel.OrderNumber,
  5165. Manufacturer: manufacturer.ID,
  5166. Dealer: 0,
  5167. Creator: adminInfo.AdminUser.Id,
  5168. UpdateCreator: 0,
  5169. Status: 1,
  5170. Ctime: time.Now().Unix(),
  5171. Mtime: 0,
  5172. Price: info.Price,
  5173. WarehousingDetailId: info.WarehouseInfotId,
  5174. WarehouseOutDetailId: info.ID,
  5175. CancelOutDetailId: cancelInfo.ID,
  5176. ProductDate: info.ProductDate,
  5177. ExpireDate: info.ExpiryDate,
  5178. StorehouseId: houseConfig.StorehouseOutInfo,
  5179. OverCount: over_count,
  5180. }
  5181. service.CreateStockFlowOne(flow)
  5182. }
  5183. //出库数据小于退库数据
  5184. if info.Count < prescribingNumber {
  5185. flow := models.VmStockFlow{
  5186. WarehousingId: info.WarehouseInfotId,
  5187. GoodId: project.ProjectId,
  5188. Number: info.Number,
  5189. LicenseNumber: info.LicenseNumber,
  5190. Count: info.Count,
  5191. UserOrgId: adminInfo.CurrentOrgId,
  5192. PatientId: project.PatientId,
  5193. SystemTime: info.SysRecordTime,
  5194. ConsumableType: 7,
  5195. IsSys: 0,
  5196. WarehousingOrder: "",
  5197. WarehouseOutId: info.WarehouseOutId,
  5198. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5199. IsEdit: 0,
  5200. CancelStockId: cancel.ID,
  5201. CancelOrderNumber: cancel.OrderNumber,
  5202. Manufacturer: manufacturer.ID,
  5203. Dealer: 0,
  5204. Creator: adminInfo.AdminUser.Id,
  5205. UpdateCreator: 0,
  5206. Status: 1,
  5207. Ctime: time.Now().Unix(),
  5208. Mtime: 0,
  5209. Price: info.Price,
  5210. WarehousingDetailId: info.WarehouseInfotId,
  5211. WarehouseOutDetailId: info.ID,
  5212. CancelOutDetailId: cancelInfo.ID,
  5213. ProductDate: info.ProductDate,
  5214. ExpireDate: info.ExpiryDate,
  5215. StorehouseId: houseConfig.StorehouseOutInfo,
  5216. OverCount: over_count,
  5217. }
  5218. service.CreateStockFlowOne(flow)
  5219. }
  5220. //查询已出库数量
  5221. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5222. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5223. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5224. if prescribingNumber < dialysisInfo.Count {
  5225. //改变数量
  5226. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5227. }
  5228. if prescribingNumber >= dialysisInfo.Count {
  5229. //删除出库表
  5230. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5231. }
  5232. //更新剩余库存
  5233. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5234. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5235. var total_count_one int64
  5236. for _, it := range stockList {
  5237. total_count_one += it.StockCount
  5238. }
  5239. //基础库插入数据
  5240. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5241. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5242. var flush_count int64
  5243. for _, it := range goodListOne {
  5244. flush_count += it.StockCount
  5245. }
  5246. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5247. if errs != nil {
  5248. goodErrcode := models.XtGoodErrcode{
  5249. UserOrgId: project.UserOrgId,
  5250. Errcode: "手动出库更新剩余出库失败",
  5251. GoodId: project.ProjectId,
  5252. Status: 1,
  5253. Ctime: time.Now().Unix(),
  5254. Mtime: 0,
  5255. Count: 0,
  5256. StockCount: 0,
  5257. Creater: creater,
  5258. BatchNumberId: 0,
  5259. WarehouseOutId: 0,
  5260. }
  5261. service.CreateGoodErrcode(goodErrcode)
  5262. }
  5263. }
  5264. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5265. fmt.Println(err)
  5266. } else {
  5267. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5268. fmt.Println(err)
  5269. }
  5270. } else {
  5271. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5272. fmt.Println(err)
  5273. }
  5274. }
  5275. //保存处方出库
  5276. if goodOutConfig.IsOpen == 1 {
  5277. if project.Type == 3 {
  5278. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5279. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5280. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5281. operation_time := time.Now().Unix()
  5282. creater := adminInfo.AdminUser.Id
  5283. //创建退库单
  5284. timeStr := time.Now().Format("2006-01-02")
  5285. timeArr := strings.Split(timeStr, "-")
  5286. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5287. total = total + 1
  5288. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5289. cancelStock := models.CancelStock{
  5290. OrderNumber: orderNumber,
  5291. OperaTime: operation_time,
  5292. OrgId: adminInfo.CurrentOrgId,
  5293. Creater: creater,
  5294. Ctime: time.Now().Unix(),
  5295. Status: 1,
  5296. ReturnTime: project.RecordDate,
  5297. Type: 1,
  5298. StorehouseId: houseConfig.StorehouseOutInfo,
  5299. IsCheck: 1,
  5300. }
  5301. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5302. if msgerrkonde == gorm.ErrRecordNotFound {
  5303. service.AddSigleCancelStock(&cancelStock)
  5304. }
  5305. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5306. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5307. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5308. //获取出库数据
  5309. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5310. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5311. deaerler, _ := service.GetDealerById(info.Dealer)
  5312. if info.ID > 0 {
  5313. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5314. if info.Count >= prescribingNumber {
  5315. cancelStockInfo := models.CancelStockInfo{
  5316. GoodId: project.ProjectId,
  5317. CancelStockId: cancel.ID,
  5318. GoodTypeId: good.GoodTypeId,
  5319. Count: prescribingNumber,
  5320. Price: info.Price,
  5321. Total: 0,
  5322. ProductDate: info.ProductDate,
  5323. ExpiryDate: info.ExpiryDate,
  5324. Ctime: time.Now().Unix(),
  5325. Status: 1,
  5326. OrgId: adminInfo.CurrentOrgId,
  5327. OrderNumber: cancel.OrderNumber,
  5328. Type: 0,
  5329. Dealer: deaerler.DealerName,
  5330. Manufacturer: manufacturer.ManufacturerName,
  5331. Number: info.Number,
  5332. RegisterAccount: "",
  5333. Remark: "",
  5334. WarehouseInfoId: info.WarehouseInfotId,
  5335. PatientId: info.PatientId,
  5336. RecordDate: info.SysRecordTime,
  5337. StorehouseId: houseConfig.StorehouseOutInfo,
  5338. IsCheck: 1,
  5339. }
  5340. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5341. //退库数量增加
  5342. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5343. //出库数量减少
  5344. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5345. }
  5346. if info.Count < prescribingNumber {
  5347. cancelStockInfo := models.CancelStockInfo{
  5348. GoodId: project.ProjectId,
  5349. CancelStockId: cancel.ID,
  5350. GoodTypeId: good.GoodTypeId,
  5351. Count: prescribingNumber,
  5352. Price: info.Price,
  5353. Total: 0,
  5354. ProductDate: info.ProductDate,
  5355. ExpiryDate: info.ExpiryDate,
  5356. Ctime: time.Now().Unix(),
  5357. Status: 1,
  5358. OrgId: adminInfo.CurrentOrgId,
  5359. OrderNumber: cancel.OrderNumber,
  5360. Type: 0,
  5361. Dealer: deaerler.DealerName,
  5362. Manufacturer: manufacturer.ManufacturerName,
  5363. Number: info.Number,
  5364. RegisterAccount: "",
  5365. Remark: "",
  5366. WarehouseInfoId: info.WarehouseInfotId,
  5367. PatientId: info.PatientId,
  5368. RecordDate: info.SysRecordTime,
  5369. StorehouseId: houseConfig.StorehouseOutInfo,
  5370. IsCheck: 1,
  5371. }
  5372. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5373. //回退库存
  5374. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5375. }
  5376. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5377. var over_count int64
  5378. for _, it := range goodList {
  5379. over_count += it.StockCount
  5380. }
  5381. //查询出库数量
  5382. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5383. //出库数据 大于 退库数量
  5384. if len(list) > 0 {
  5385. for _, it := range list {
  5386. //回退库存
  5387. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5388. //退库数量增加
  5389. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5390. //出库数量减少
  5391. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5392. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5393. var over_count_one int64
  5394. for _, it := range goodList {
  5395. over_count_one += it.StockCount
  5396. }
  5397. //查询该批次是否有退库数据
  5398. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5399. flow := models.VmStockFlow{
  5400. WarehousingId: it.WarehouseInfotId,
  5401. GoodId: it.GoodId,
  5402. Number: it.Number,
  5403. LicenseNumber: it.LicenseNumber,
  5404. Count: it.Count,
  5405. UserOrgId: adminInfo.CurrentOrgId,
  5406. PatientId: it.PatientId,
  5407. SystemTime: it.SysRecordTime,
  5408. ConsumableType: 7,
  5409. IsSys: 0,
  5410. WarehousingOrder: "",
  5411. WarehouseOutId: it.WarehouseOutId,
  5412. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5413. IsEdit: 0,
  5414. CancelStockId: cancel.ID,
  5415. CancelOrderNumber: cancel.OrderNumber,
  5416. Manufacturer: manufacturer.ID,
  5417. Dealer: 0,
  5418. Creator: adminInfo.AdminUser.Id,
  5419. UpdateCreator: 0,
  5420. Status: 1,
  5421. Ctime: time.Now().Unix(),
  5422. Mtime: 0,
  5423. Price: it.Price,
  5424. WarehousingDetailId: it.WarehouseInfotId,
  5425. WarehouseOutDetailId: it.ID,
  5426. CancelOutDetailId: cancelInfo.ID,
  5427. ProductDate: it.ProductDate,
  5428. ExpireDate: it.ExpiryDate,
  5429. StorehouseId: houseConfig.StorehouseOutInfo,
  5430. OverCount: over_count_one,
  5431. }
  5432. service.CreateStockFlowOne(flow)
  5433. }
  5434. }
  5435. //查询已出库数量
  5436. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5437. if prescribingNumber < dialysisInfo.Count {
  5438. //改变数量
  5439. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5440. }
  5441. if prescribingNumber >= dialysisInfo.Count {
  5442. //删除出库表
  5443. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5444. }
  5445. //更新剩余库存
  5446. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5447. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5448. var total_count_one int64
  5449. for _, it := range stockList {
  5450. total_count_one += it.StockCount
  5451. }
  5452. //基础库插入数据
  5453. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5454. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5455. var flush_count int64
  5456. for _, it := range goodListOne {
  5457. flush_count += it.StockCount
  5458. }
  5459. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5460. if errs != nil {
  5461. goodErrcode := models.XtGoodErrcode{
  5462. UserOrgId: project.UserOrgId,
  5463. Errcode: "手动出库更新剩余出库失败",
  5464. GoodId: project.ProjectId,
  5465. Status: 1,
  5466. Ctime: time.Now().Unix(),
  5467. Mtime: 0,
  5468. Count: 0,
  5469. StockCount: 0,
  5470. Creater: creater,
  5471. BatchNumberId: 0,
  5472. WarehouseOutId: 0,
  5473. }
  5474. service.CreateGoodErrcode(goodErrcode)
  5475. }
  5476. }
  5477. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5478. fmt.Println(err)
  5479. } else {
  5480. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5481. fmt.Println(err)
  5482. }
  5483. }
  5484. c.ServeSuccessJSON(map[string]interface{}{
  5485. "msg": "删除成功",
  5486. })
  5487. return
  5488. }
  5489. func (c *HisApiController) CreateHisAdditionalCharge() {
  5490. his_patient_id, _ := c.GetInt64("his_patient_id")
  5491. patient_id, _ := c.GetInt64("patient_id")
  5492. record_date := c.GetString("record_date")
  5493. timeLayout := "2006-01-02"
  5494. loc, _ := time.LoadLocation("Local")
  5495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5496. if err != nil {
  5497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5498. return
  5499. }
  5500. adminInfo := c.GetAdminUserInfo()
  5501. recordDateTime := theTime.Unix()
  5502. dataBody := make(map[string]interface{}, 0)
  5503. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5504. if err != nil {
  5505. utils.ErrorLog(err.Error())
  5506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5507. return
  5508. }
  5509. var additions []*models.HisAdditionalCharge
  5510. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5511. additions, _ := dataBody["addition"].([]interface{})
  5512. if len(additions) > 0 {
  5513. for _, item := range additions {
  5514. items := item.(map[string]interface{})
  5515. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5516. utils.ErrorLog("item_id")
  5517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5518. return
  5519. }
  5520. item_id := int64(items["item_id"].(float64))
  5521. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5522. utils.ErrorLog("item_name")
  5523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5524. return
  5525. }
  5526. item_name := items["item_name"].(string)
  5527. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5528. utils.ErrorLog("price")
  5529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5530. return
  5531. }
  5532. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5533. ctime := time.Now().Unix()
  5534. additional := &models.HisAdditionalCharge{
  5535. PatientId: patient_id,
  5536. HisPatientId: his_patient_id,
  5537. UserOrgId: adminInfo.CurrentOrgId,
  5538. RecordDate: recordDateTime,
  5539. CreatedTime: ctime,
  5540. UpdatedTime: ctime,
  5541. Modifier: adminInfo.AdminUser.Id,
  5542. Creator: adminInfo.AdminUser.Id,
  5543. Price: price,
  5544. ItemName: item_name,
  5545. ItemId: item_id,
  5546. Status: 1,
  5547. }
  5548. additions = append(additions, additional)
  5549. }
  5550. }
  5551. }
  5552. for _, item := range additions {
  5553. service.CreateAddtionalCharge(item)
  5554. }
  5555. c.ServeSuccessJSON(map[string]interface{}{
  5556. "msg": "创建成功",
  5557. })
  5558. }
  5559. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5560. blood_fat := c.GetString("blood_fat")
  5561. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5562. blood_sugar := c.GetString("blood_sugar")
  5563. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5564. chief_conplaint := c.GetString("chief_conplaint")
  5565. dbp := c.GetString("dbp")
  5566. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5567. delivery_way, _ := c.GetInt64("delivery_way")
  5568. diagnostic := c.GetString("diagnostic")
  5569. family_history := c.GetString("family_history")
  5570. height := c.GetString("height")
  5571. history_of_present_illness := c.GetString("history_of_present_illness")
  5572. is_infect, _ := c.GetInt64("is_infect")
  5573. past_history := c.GetString("past_history")
  5574. patient_id, _ := c.GetInt64("patient_id")
  5575. his_patient_id, _ := c.GetInt64("his_patient_id")
  5576. personal_history := c.GetString("personal_history")
  5577. pulse := c.GetString("pulse")
  5578. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5579. sbp := c.GetString("sbp")
  5580. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5581. heightfloat, _ := strconv.ParseFloat(height, 64)
  5582. sicktype := c.GetString("sick_type")
  5583. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5584. symptom := c.GetString("symptom")
  5585. sick_date := c.GetString("sick_date")
  5586. temperatures := c.GetString("temperature")
  5587. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5588. record_date := c.GetString("record_date")
  5589. breathing := c.GetString("breathing")
  5590. doctor_advice := c.GetString("doctor_advice")
  5591. remark := c.GetString("remark")
  5592. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5593. sick, _ := c.GetInt64("sick")
  5594. diagnose, _ := c.GetInt64("diagnose")
  5595. //id, _ := c.GetInt64("id")
  5596. timeLayout := "2006-01-02"
  5597. loc, _ := time.LoadLocation("Local")
  5598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5599. allergic_history := c.GetString("allergic_history")
  5600. if err != nil {
  5601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5602. return
  5603. }
  5604. recordDateTime := theTime.Unix()
  5605. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5606. if err != nil {
  5607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5608. return
  5609. }
  5610. sickTimes := sickTime.Unix()
  5611. ctime := time.Now().Unix()
  5612. primary_disease := c.GetString("primary_disease")
  5613. confirm_failure_date := c.GetString("confirm_failure_date")
  5614. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5615. drug_allergy_history := c.GetString("drug_allergy_history")
  5616. physical_examination := c.GetString("physical_examination")
  5617. special_inspection := c.GetString("special_inspection")
  5618. lab_apparatus := c.GetString("lab_apparatus")
  5619. caseHistory := models.HisPatientCaseHistory{
  5620. HisPatientId: his_patient_id,
  5621. PatientId: patient_id,
  5622. Temperature: temperature,
  5623. BloodSugar: bloodsugarfloat,
  5624. Pulse: pulsefloat,
  5625. Sbp: sbpfloat,
  5626. Dbp: dbpfloat,
  5627. Height: heightfloat,
  5628. BloodFat: bloodfatfloat,
  5629. SickType: sick_type,
  5630. Symptom: symptom,
  5631. SickDate: sickTimes,
  5632. IsInfect: is_infect,
  5633. HistoryOfPresentIllness: history_of_present_illness,
  5634. PastHistory: past_history,
  5635. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5636. ChiefConplaint: chief_conplaint,
  5637. PersonalHistory: personal_history,
  5638. FamilyHistory: family_history,
  5639. Diagnostic: diagnostic,
  5640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5641. Status: 1,
  5642. Ctime: ctime,
  5643. Mtime: ctime,
  5644. RecordDate: recordDateTime,
  5645. DeliveryWay: delivery_way,
  5646. Breathing: breathingfloat,
  5647. DoctorAdvice: doctor_advice,
  5648. Remark: remark,
  5649. Sick: sick,
  5650. Diagnose: diagnose,
  5651. AllergicHistory: allergic_history,
  5652. PrimaryDisease: primary_disease,
  5653. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5654. DrugAllergyHistory: drug_allergy_history,
  5655. PhysicalExamination: physical_examination,
  5656. SpecialInspection: special_inspection,
  5657. LabApparatus: lab_apparatus,
  5658. }
  5659. //查询该患者是否有病历
  5660. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5661. if errcodes == gorm.ErrRecordNotFound {
  5662. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5663. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5664. if err != nil {
  5665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5666. return
  5667. }
  5668. c.ServeSuccessJSON(map[string]interface{}{
  5669. "caseHistory": caseHistory,
  5670. "historyInfo": historyInfo,
  5671. })
  5672. return
  5673. } else if errcodes == nil {
  5674. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5675. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5676. if err != nil {
  5677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5678. return
  5679. }
  5680. c.ServeSuccessJSON(map[string]interface{}{
  5681. "caseHistory": caseHistory,
  5682. "historyInfo": historyInfo,
  5683. })
  5684. }
  5685. //查询该患者是否有病历
  5686. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5687. //if errcode == gorm.ErrRecordNotFound {
  5688. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5689. // if err != nil {
  5690. // c.ServeSuccessJSON(map[string]interface{}{
  5691. // "msg": "保存成功",
  5692. // })
  5693. // }
  5694. //} else if errcode == nil {
  5695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5696. // return
  5697. //}
  5698. }
  5699. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5700. patient_id, _ := c.GetInt64("patient_id", 0)
  5701. adminUser := c.GetAdminUserInfo()
  5702. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5703. c.ServeSuccessJSON(map[string]interface{}{
  5704. "list": caseHistorys,
  5705. })
  5706. }
  5707. func (c *HisApiController) GetHisPatientCaseHistory() {
  5708. record_date, _ := c.GetInt64("record_date", 0)
  5709. patient_id, _ := c.GetInt64("patient_id", 0)
  5710. admin := c.GetAdminUserInfo()
  5711. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5712. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5713. c.ServeSuccessJSON(map[string]interface{}{
  5714. "info": info,
  5715. "case_history": case_history,
  5716. })
  5717. }
  5718. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5719. template_name := c.GetString("template_name")
  5720. template_remark := c.GetString("template_remark")
  5721. doctor := c.GetAdminUserInfo().AdminUser.Id
  5722. diagnostic := c.GetString("diagnostic")
  5723. chief_conplaint := c.GetString("chief_conplain")
  5724. history_of_present_illness := c.GetString("history_of_present_illness")
  5725. past_history := c.GetString("past_history")
  5726. personal_history := c.GetString("personal_history")
  5727. family_history := c.GetString("family_history")
  5728. user_name := c.GetString("user_name")
  5729. doctor_advice := c.GetString("doctor_advice")
  5730. remark := c.GetString("remark")
  5731. //record_date := c.GetString("record_date")
  5732. //fmt.Println("record_date--------",record_date)
  5733. //timeLayout := "2006-01-02"
  5734. //loc, _ := time.LoadLocation("Local")
  5735. //
  5736. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5737. //if err != nil {
  5738. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5739. // return
  5740. //}
  5741. //recordDateTime := theTime.Unix()
  5742. ctime := time.Now().Unix()
  5743. template := models.HisCaseHistoryTemplate{
  5744. HistoryOfPresentIllness: history_of_present_illness,
  5745. PastHistory: past_history,
  5746. ChiefConplaint: chief_conplaint,
  5747. PersonalHistory: personal_history,
  5748. FamilyHistory: family_history,
  5749. Diagnostic: diagnostic,
  5750. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5751. Status: 1,
  5752. Ctime: ctime,
  5753. Mtime: ctime,
  5754. RecordDate: time.Now().Unix(),
  5755. TemplateName: template_name,
  5756. TemplateRemark: template_remark,
  5757. Creator: doctor,
  5758. Modifier: doctor,
  5759. UserName: user_name,
  5760. DoctorAdvice: doctor_advice,
  5761. Remark: remark,
  5762. }
  5763. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5764. if err == nil {
  5765. c.ServeSuccessJSON(map[string]interface{}{
  5766. "msg": "保存成功",
  5767. })
  5768. } else {
  5769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5770. return
  5771. }
  5772. }
  5773. func (c *HisApiController) GetCaseHistoryTemplate() {
  5774. timeLayout := "2006-01-02"
  5775. loc, _ := time.LoadLocation("Local")
  5776. keyword := c.GetString("keyword")
  5777. start_time := c.GetString("start_time")
  5778. end_time := c.GetString("end_time")
  5779. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5780. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5781. admin := c.GetAdminUserInfo()
  5782. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5783. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5784. c.ServeSuccessJSON(map[string]interface{}{
  5785. "template": template,
  5786. //"history": history,
  5787. })
  5788. }
  5789. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5790. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5791. utils.ErrorLog("drug_name")
  5792. return enums.ErrorCodeParamWrong
  5793. }
  5794. adviceName, _ := json["drug_name"].(string)
  5795. if len(adviceName) == 0 {
  5796. utils.ErrorLog("len(advice_name) == 0")
  5797. return enums.ErrorCodeParamWrong
  5798. }
  5799. advice.AdviceName = adviceName
  5800. adviceDesc, _ := json["advice_desc"].(string)
  5801. advice.AdviceDesc = adviceDesc
  5802. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5803. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5804. advice.DrugSpec = drugSpec
  5805. }
  5806. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5807. remark, _ := json["remark"].(string)
  5808. advice.Remark = remark
  5809. }
  5810. if json["id"] == nil {
  5811. advice.DrugId = 0
  5812. } else {
  5813. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5814. drug_id := int64(json["id"].(float64))
  5815. advice.DrugId = drug_id
  5816. }
  5817. }
  5818. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5819. advice_id := int64(json["advice_id"].(float64))
  5820. advice.ID = advice_id
  5821. if advice.ID > 0 {
  5822. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5823. if err == nil {
  5824. if hisAdvice.ID > 0 {
  5825. advice.ExecutionTime = hisAdvice.ExecutionTime
  5826. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5827. advice.ExecutionState = hisAdvice.ExecutionState
  5828. advice.CheckTime = hisAdvice.CheckTime
  5829. advice.Checker = hisAdvice.Checker
  5830. advice.CheckState = hisAdvice.CheckState
  5831. advice.StartTime = hisAdvice.StartTime
  5832. advice.FeedetlSn = hisAdvice.FeedetlSn
  5833. }
  5834. }
  5835. }
  5836. }
  5837. //
  5838. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5839. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5840. // advice.ExecutionTime = execution_time
  5841. //}
  5842. //
  5843. //
  5844. //
  5845. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5846. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5847. // advice.ExecutionStaff = execution_staff
  5848. //}
  5849. //
  5850. //
  5851. //
  5852. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5853. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5854. // advice.ExecutionState = execution_state
  5855. //}
  5856. //
  5857. //
  5858. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5859. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5860. // advice.CheckTime = check_time
  5861. //}
  5862. //
  5863. //
  5864. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5865. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5866. // advice.CheckState = check_state
  5867. //}
  5868. //
  5869. //
  5870. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5871. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5872. // advice.Checker = checker
  5873. //}
  5874. //
  5875. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5876. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5877. // advice.StartTime = start_time
  5878. //}
  5879. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5880. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5881. advice.IsSelfDrug = is_self_drug
  5882. }
  5883. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5884. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5885. drug_way_count, _ := json["drug_way_count"].(string)
  5886. advice.DrugWayCount = drug_way_count
  5887. }
  5888. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5889. drugSpecUnit, _ := json["min_unit"].(string)
  5890. advice.DrugSpecUnit = drugSpecUnit
  5891. }
  5892. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5893. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5894. advice.SingleDose = singleDose
  5895. }
  5896. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5897. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5898. advice.SingleDoseUnit = singleDoseUnit
  5899. }
  5900. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5901. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5902. advice.PrescribingNumber = prescribingNumber
  5903. }
  5904. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5905. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5906. advice.PrescribingNumberUnit = prescribingNumberUnit
  5907. }
  5908. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5909. deliveryWay, _ := json["delivery_way"].(string)
  5910. advice.DeliveryWay = deliveryWay
  5911. }
  5912. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5913. executionFrequency, _ := json["execution_frequency"].(string)
  5914. advice.ExecutionFrequency = executionFrequency
  5915. }
  5916. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5917. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5918. advice.Price = price
  5919. }
  5920. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5921. med_list_codg, _ := json["medical_insurance_number"].(string)
  5922. advice.MedListCodg = med_list_codg
  5923. }
  5924. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5925. day := int64(json["day"].(float64))
  5926. advice.Day = day
  5927. }
  5928. return 0
  5929. }
  5930. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5931. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5932. id := int64(json["id"].(float64))
  5933. project.ID = id
  5934. historyProject, _ := service.GetHisProjectByID(id)
  5935. project.FeedetlSn = historyProject.FeedetlSn
  5936. }
  5937. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5938. project_id := int64(json["project_id"].(float64))
  5939. project.ProjectId = project_id
  5940. }
  5941. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5942. // price := int64(json["price"].(float64))
  5943. // formatInt_price := strconv.FormatInt(price, 10)
  5944. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5945. // project.Price = float_price
  5946. // }
  5947. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5948. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5949. project.Price = price
  5950. }
  5951. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5952. total, _ := json["total"].(string)
  5953. project.Count = total
  5954. }
  5955. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5956. medical_code, _ := json["medical_code"].(string)
  5957. project.MedListCodg = medical_code
  5958. }
  5959. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5960. single_dose, _ := json["single_dose"].(string)
  5961. project.SingleDose = single_dose
  5962. }
  5963. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5964. delivery_way, _ := json["delivery_way"].(string)
  5965. project.DeliveryWay = delivery_way
  5966. }
  5967. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5968. execution_frequency, _ := json["execution_frequency"].(string)
  5969. project.ExecutionFrequency = execution_frequency
  5970. }
  5971. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5972. remark, _ := json["remark"].(string)
  5973. project.Remark = remark
  5974. }
  5975. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5976. day, _ := json["number_days"].(string)
  5977. project.Day = day
  5978. }
  5979. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5980. unit, _ := json["unit"].(string)
  5981. project.Unit = unit
  5982. }
  5983. return 0
  5984. }
  5985. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5986. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5987. id := int64(json["id"].(float64))
  5988. historyAddtions, _ := service.GetHisAdditionByID(id)
  5989. additionalCharge.ID = id
  5990. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5991. }
  5992. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5993. item_id := int64(json["item_id"].(float64))
  5994. additionalCharge.ItemId = item_id
  5995. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5996. if config.ID > 0 {
  5997. if len(config.Code) > 0 {
  5998. additionalCharge.MedListCodg = config.Code
  5999. }
  6000. }
  6001. }
  6002. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6003. // price := int64(json["price"].(float64))
  6004. // formatInt_price := strconv.FormatInt(price, 10)
  6005. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6006. // additionalCharge.Price = float_price
  6007. // }
  6008. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6009. // price := int64(json["price"].(float64))
  6010. // formatInt_price := strconv.FormatInt(price, 10)
  6011. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6012. // additionalCharge.Price = float_price
  6013. //}
  6014. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6015. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6016. additionalCharge.Price = price
  6017. }
  6018. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6019. count, _ := json["count"].(string)
  6020. counts, _ := strconv.ParseInt(count, 10, 64)
  6021. additionalCharge.Count = counts
  6022. }
  6023. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6024. item_name, _ := json["item_name"].(string)
  6025. additionalCharge.ItemName = item_name
  6026. }
  6027. return 0
  6028. }
  6029. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6030. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6031. utils.ErrorLog("drug_name")
  6032. return enums.ErrorCodeParamWrong
  6033. }
  6034. adviceName, _ := json["drug_name"].(string)
  6035. if len(adviceName) == 0 {
  6036. utils.ErrorLog("len(advice_name) == 0")
  6037. return enums.ErrorCodeParamWrong
  6038. }
  6039. advice.AdviceName = adviceName
  6040. adviceDesc, _ := json["advice_desc"].(string)
  6041. advice.AdviceDesc = adviceDesc
  6042. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6043. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6044. advice.DrugSpec = drugSpec
  6045. }
  6046. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6047. remark, _ := json["remark"].(string)
  6048. advice.Remark = remark
  6049. }
  6050. if json["id"] == nil {
  6051. advice.DrugId = 0
  6052. } else {
  6053. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6054. drug_id := int64(json["id"].(float64))
  6055. advice.DrugId = drug_id
  6056. }
  6057. }
  6058. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6059. groupno := int64(json["groupno"].(float64))
  6060. advice.Groupno = groupno
  6061. }
  6062. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6063. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6064. advice.IsSelfDrug = is_self_drug
  6065. }
  6066. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6067. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6068. drug_way_count, _ := json["drug_way_count"].(string)
  6069. advice.DrugWayCount = drug_way_count
  6070. }
  6071. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6072. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6073. advice.HospApprFlag = hosp_appr_flag
  6074. }
  6075. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6076. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6077. advice.PrescribingNumber = prescribingNumber
  6078. }
  6079. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6080. // frequency_type := int64(json["frequency_type"].(float64))
  6081. // advice.FrequencyType = frequency_type
  6082. //}
  6083. //
  6084. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6085. // day_count := int64(json["day_count"].(float64))
  6086. // advice.DayCount = day_count
  6087. //}
  6088. //
  6089. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6090. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6091. // week_day, _ := json["week_day"].(string)
  6092. // advice.WeekDay = week_day
  6093. //}
  6094. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6095. drugSpecUnit, _ := json["min_unit"].(string)
  6096. advice.DrugSpecUnit = drugSpecUnit
  6097. }
  6098. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6099. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6100. advice.SingleDose = singleDose
  6101. }
  6102. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6103. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6104. advice.SingleDoseUnit = singleDoseUnit
  6105. }
  6106. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6107. deliveryWay, _ := json["delivery_way"].(string)
  6108. advice.DeliveryWay = deliveryWay
  6109. }
  6110. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6111. executionFrequency, _ := json["execution_frequency"].(string)
  6112. advice.ExecutionFrequency = executionFrequency
  6113. }
  6114. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6115. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6116. advice.Price = price
  6117. }
  6118. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6119. med_list_codg, _ := json["medical_insurance_number"].(string)
  6120. advice.MedListCodg = med_list_codg
  6121. }
  6122. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6123. day := int64(json["day"].(float64))
  6124. advice.Day = day
  6125. }
  6126. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6127. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6128. advice.PrescribingNumberUnit = prescribingNumberUnit
  6129. }
  6130. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6131. advice_id := int64(json["advice_id"].(float64))
  6132. advice.ID = advice_id
  6133. if advice.ID > 0 {
  6134. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6135. if err == nil {
  6136. if hisAdvice.ID > 0 {
  6137. advice.ExecutionTime = hisAdvice.ExecutionTime
  6138. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6139. advice.ExecutionState = hisAdvice.ExecutionState
  6140. advice.CheckTime = hisAdvice.CheckTime
  6141. advice.Checker = hisAdvice.Checker
  6142. advice.CheckState = hisAdvice.CheckState
  6143. advice.StartTime = hisAdvice.StartTime
  6144. advice.HospApprFlag = hisAdvice.HospApprFlag
  6145. advice.IsMedicine = hisAdvice.IsMedicine
  6146. if hisAdvice.UserOrgId == 10028 {
  6147. 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 {
  6148. advice.ExecutionTime = 0
  6149. advice.ExecutionStaff = 0
  6150. advice.ExecutionState = 2
  6151. advice.CheckTime = 0
  6152. advice.Checker = 0
  6153. advice.CheckState = 2
  6154. }
  6155. } else {
  6156. 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 {
  6157. advice.ExecutionTime = 0
  6158. advice.ExecutionStaff = 0
  6159. advice.ExecutionState = 2
  6160. advice.CheckTime = 0
  6161. advice.Checker = 0
  6162. advice.CheckState = 2
  6163. advice.UpdatedTime = time.Now().Unix()
  6164. }
  6165. }
  6166. //advice.Groupno = hisAdvice.Groupno
  6167. }
  6168. }
  6169. }
  6170. }
  6171. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6172. //
  6173. //if drugStockConfig.IsOpen == 1 {
  6174. //
  6175. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6176. // if advice.ID == 0 { //医嘱不存在
  6177. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6178. // drug.Total = drug.Total - advice.PrescribingNumber
  6179. // service.UpdateBaseDrugLib(&drug)
  6180. //
  6181. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6182. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6183. // drug.Total = drug.Total - num
  6184. // service.UpdateBaseDrugLib(&drug)
  6185. // }
  6186. //
  6187. // } else if advice.ID > 0 { //医嘱存在
  6188. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6189. // var num float64
  6190. //
  6191. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6192. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6193. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6194. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6195. // drug.Total = drug.Total + num
  6196. // service.UpdateBaseDrugLib(&drug)
  6197. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6198. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6199. // drug.Total = drug.Total - num
  6200. // service.UpdateBaseDrugLib(&drug)
  6201. // }
  6202. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6203. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6204. // if num2 > advice.PrescribingNumber {
  6205. // num = num2 - advice.PrescribingNumber
  6206. // drug.Total = drug.Total + num
  6207. // service.UpdateBaseDrugLib(&drug)
  6208. // } else if num2 < advice.PrescribingNumber {
  6209. // num = advice.PrescribingNumber - num2
  6210. // drug.Total = drug.Total - num
  6211. // service.UpdateBaseDrugLib(&drug)
  6212. // }
  6213. //
  6214. // }
  6215. //
  6216. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6217. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6218. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6219. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6220. // if num1 > num2 {
  6221. // num = num1 - num2
  6222. // drug.Total = drug.Total + num
  6223. // service.UpdateBaseDrugLib(&drug)
  6224. // } else if num1 < num2 {
  6225. // num = num2 - num1
  6226. // drug.Total = drug.Total - num
  6227. // service.UpdateBaseDrugLib(&drug)
  6228. // }
  6229. //
  6230. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6231. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6232. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6233. // if hisAdvice.PrescribingNumber > num2 {
  6234. // num = hisAdvice.PrescribingNumber - num2
  6235. // drug.Total = drug.Total + num
  6236. // service.UpdateBaseDrugLib(&drug)
  6237. // } else if num2 < advice.PrescribingNumber {
  6238. // num = num2 - hisAdvice.PrescribingNumber
  6239. // drug.Total = drug.Total - num
  6240. // service.UpdateBaseDrugLib(&drug)
  6241. // }
  6242. //
  6243. // }
  6244. // }
  6245. // }
  6246. //}
  6247. //
  6248. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6249. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6250. // advice.ExecutionTime = execution_time
  6251. //}
  6252. //
  6253. //
  6254. //
  6255. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6256. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6257. // advice.ExecutionStaff = execution_staff
  6258. //}
  6259. //
  6260. //
  6261. //
  6262. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6263. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6264. // advice.ExecutionState = execution_state
  6265. //}
  6266. //
  6267. //
  6268. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6269. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6270. // advice.CheckTime = check_time
  6271. //}
  6272. //
  6273. //
  6274. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6275. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6276. // advice.CheckState = check_state
  6277. //}
  6278. //
  6279. //
  6280. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6281. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6282. // advice.Checker = checker
  6283. //}
  6284. //
  6285. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6286. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6287. // advice.StartTime = start_time
  6288. //}
  6289. return 0
  6290. }
  6291. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6292. project.ExecutionStaff = 0
  6293. project.ExecutionState = 2
  6294. project.ExecutionTime = 0
  6295. project.Checker = 0
  6296. project.CheckState = 2
  6297. project.CheckTime = 0
  6298. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6299. id := int64(json["id"].(float64))
  6300. project.ID = id
  6301. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6302. project.ExecutionStaff = temp_project.ExecutionStaff
  6303. project.ExecutionState = temp_project.ExecutionState
  6304. project.ExecutionTime = temp_project.ExecutionTime
  6305. project.Checker = temp_project.Checker
  6306. project.CheckState = temp_project.CheckState
  6307. project.CheckTime = temp_project.CheckTime
  6308. project.TeamId = temp_project.TeamId
  6309. }
  6310. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6311. types := int64(json["type"].(float64))
  6312. project.Type = types
  6313. }
  6314. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6315. project_id := int64(json["project_id"].(float64))
  6316. project.ProjectId = project_id
  6317. }
  6318. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6319. team_id := int64(json["team_id"].(float64))
  6320. project.TeamId = team_id
  6321. }
  6322. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6323. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6324. project.Price = price
  6325. }
  6326. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6327. total, _ := json["total"].(string)
  6328. //totals, _ := strconv.ParseInt(total, 10, 64)
  6329. project.Count = total
  6330. }
  6331. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6332. medical_code, _ := json["medical_code"].(string)
  6333. project.MedListCodg = medical_code
  6334. }
  6335. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6336. single_dose, _ := json["single_dose"].(string)
  6337. project.SingleDose = single_dose
  6338. }
  6339. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6340. delivery_way, _ := json["delivery_way"].(string)
  6341. project.DeliveryWay = delivery_way
  6342. }
  6343. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6344. execution_frequency, _ := json["execution_frequency"].(string)
  6345. project.ExecutionFrequency = execution_frequency
  6346. }
  6347. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6348. remark, _ := json["remark"].(string)
  6349. project.Remark = remark
  6350. }
  6351. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6352. day, _ := json["number_days"].(string)
  6353. project.Day = day
  6354. }
  6355. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6356. unit, _ := json["unit"].(string)
  6357. project.Unit = unit
  6358. }
  6359. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6360. // frequency_type := int64(json["frequency_type"].(float64))
  6361. // project.FrequencyType = frequency_type
  6362. //}
  6363. //
  6364. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6365. // day_count := int64(json["day_count"].(float64))
  6366. // project.DayCount = day_count
  6367. //}
  6368. //
  6369. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6370. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6371. // week_day, _ := json["week_day"].(string)
  6372. // project.WeekDay = week_day
  6373. //}
  6374. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6375. //
  6376. //if project.ID == 0 {
  6377. // if stockConfig.IsOpen == 1 {
  6378. // if project.Type == 3 {
  6379. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6380. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6381. // good.Total = good.Total - f_count
  6382. // service.UpdateGoodInfo(&good)
  6383. // }
  6384. // }
  6385. //
  6386. //} else {
  6387. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6388. //
  6389. // if stockConfig.IsOpen == 1 {
  6390. // if project.Type == 3 {
  6391. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6392. // if project.Count < temp_project.Count {
  6393. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6394. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6395. //
  6396. // other_count := f_count_two - f_count_one
  6397. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6398. // good.Total = good.Total + other_count_two
  6399. // service.UpdateGoodInfo(&good)
  6400. // } else if project.Count > temp_project.Count {
  6401. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6402. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6403. //
  6404. // other_count := f_count_one - f_count_two
  6405. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6406. // good.Total = good.Total - other_count_two
  6407. // service.UpdateGoodInfo(&good)
  6408. // }
  6409. //
  6410. // }
  6411. // }
  6412. //
  6413. //}
  6414. return 0
  6415. }
  6416. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6417. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6418. utils.ErrorLog("drug_name")
  6419. return enums.ErrorCodeParamWrong
  6420. }
  6421. adviceName, _ := json["drug_name"].(string)
  6422. if len(adviceName) == 0 {
  6423. utils.ErrorLog("len(advice_name) == 0")
  6424. return enums.ErrorCodeParamWrong
  6425. }
  6426. advice.AdviceName = adviceName
  6427. adviceDesc, _ := json["advice_desc"].(string)
  6428. advice.AdviceDesc = adviceDesc
  6429. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6430. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6431. advice.DrugSpec = drugSpec
  6432. }
  6433. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6434. remark, _ := json["remark"].(string)
  6435. advice.Remark = remark
  6436. }
  6437. if json["id"] == nil {
  6438. advice.DrugId = 0
  6439. } else {
  6440. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6441. drug_id := int64(json["id"].(float64))
  6442. advice.DrugId = drug_id
  6443. }
  6444. }
  6445. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6446. groupno := int64(json["groupno"].(float64))
  6447. advice.Groupno = groupno
  6448. }
  6449. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6450. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6451. advice.IsSelfDrug = is_self_drug
  6452. }
  6453. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6454. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6455. drug_way_count, _ := json["drug_way_count"].(string)
  6456. advice.DrugWayCount = drug_way_count
  6457. }
  6458. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6459. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6460. advice.HospApprFlag = hosp_appr_flag
  6461. }
  6462. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6463. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6464. advice.PrescribingNumber = prescribingNumber
  6465. }
  6466. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6467. // frequency_type := int64(json["frequency_type"].(float64))
  6468. // advice.FrequencyType = frequency_type
  6469. //}
  6470. //
  6471. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6472. // day_count := int64(json["day_count"].(float64))
  6473. // advice.DayCount = day_count
  6474. //}
  6475. //
  6476. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6477. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6478. // week_day, _ := json["week_day"].(string)
  6479. // advice.WeekDay = week_day
  6480. //}
  6481. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6482. drugSpecUnit, _ := json["min_unit"].(string)
  6483. advice.DrugSpecUnit = drugSpecUnit
  6484. }
  6485. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6486. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6487. advice.SingleDose = singleDose
  6488. }
  6489. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6490. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6491. advice.SingleDoseUnit = singleDoseUnit
  6492. }
  6493. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6494. deliveryWay, _ := json["delivery_way"].(string)
  6495. advice.DeliveryWay = deliveryWay
  6496. }
  6497. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6498. executionFrequency, _ := json["execution_frequency"].(string)
  6499. advice.ExecutionFrequency = executionFrequency
  6500. }
  6501. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6502. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6503. advice.Price = price
  6504. }
  6505. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6506. med_list_codg, _ := json["medical_insurance_number"].(string)
  6507. advice.MedListCodg = med_list_codg
  6508. }
  6509. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6510. day := int64(json["day"].(float64))
  6511. advice.Day = day
  6512. }
  6513. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6514. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6515. advice.PrescribingNumberUnit = prescribingNumberUnit
  6516. }
  6517. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6518. advice_id := int64(json["advice_id"].(float64))
  6519. advice.ID = advice_id
  6520. if advice.ID > 0 {
  6521. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6522. if err == nil {
  6523. if hisAdvice.ID > 0 {
  6524. advice.ExecutionTime = hisAdvice.ExecutionTime
  6525. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6526. advice.ExecutionState = hisAdvice.ExecutionState
  6527. advice.CheckTime = hisAdvice.CheckTime
  6528. advice.Checker = hisAdvice.Checker
  6529. advice.CheckState = hisAdvice.CheckState
  6530. advice.StartTime = hisAdvice.StartTime
  6531. advice.HospApprFlag = hisAdvice.HospApprFlag
  6532. advice.IsMedicine = hisAdvice.IsMedicine
  6533. if hisAdvice.UserOrgId == 10028 {
  6534. 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 {
  6535. advice.ExecutionTime = 0
  6536. advice.ExecutionStaff = 0
  6537. advice.ExecutionState = 2
  6538. advice.CheckTime = 0
  6539. advice.Checker = 0
  6540. advice.CheckState = 2
  6541. }
  6542. } else {
  6543. 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 {
  6544. advice.ExecutionTime = 0
  6545. advice.ExecutionStaff = 0
  6546. advice.ExecutionState = 2
  6547. advice.CheckTime = 0
  6548. advice.Checker = 0
  6549. advice.CheckState = 2
  6550. //advice.UpdatedTime = time.Now().Unix()
  6551. advice.CreatedTime = hisAdvice.CreatedTime
  6552. advice.UpdatedTime = time.Now().Unix()
  6553. } else {
  6554. advice.CreatedTime = hisAdvice.CreatedTime
  6555. advice.UpdatedTime = hisAdvice.UpdatedTime
  6556. }
  6557. }
  6558. //advice.Groupno = hisAdvice.Groupno
  6559. } else {
  6560. ctime := time.Now().Unix()
  6561. advice.CreatedTime = ctime
  6562. advice.UpdatedTime = ctime
  6563. }
  6564. }
  6565. } else {
  6566. ctime := time.Now().Unix()
  6567. advice.CreatedTime = ctime
  6568. advice.UpdatedTime = ctime
  6569. }
  6570. }
  6571. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6572. //
  6573. //if drugStockConfig.IsOpen == 1 {
  6574. //
  6575. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6576. // if advice.ID == 0 { //医嘱不存在
  6577. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6578. // drug.Total = drug.Total - advice.PrescribingNumber
  6579. // service.UpdateBaseDrugLib(&drug)
  6580. //
  6581. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6582. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6583. // drug.Total = drug.Total - num
  6584. // service.UpdateBaseDrugLib(&drug)
  6585. // }
  6586. //
  6587. // } else if advice.ID > 0 { //医嘱存在
  6588. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6589. // var num float64
  6590. //
  6591. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6592. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6593. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6594. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6595. // drug.Total = drug.Total + num
  6596. // service.UpdateBaseDrugLib(&drug)
  6597. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6598. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6599. // drug.Total = drug.Total - num
  6600. // service.UpdateBaseDrugLib(&drug)
  6601. // }
  6602. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6603. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6604. // if num2 > advice.PrescribingNumber {
  6605. // num = num2 - advice.PrescribingNumber
  6606. // drug.Total = drug.Total + num
  6607. // service.UpdateBaseDrugLib(&drug)
  6608. // } else if num2 < advice.PrescribingNumber {
  6609. // num = advice.PrescribingNumber - num2
  6610. // drug.Total = drug.Total - num
  6611. // service.UpdateBaseDrugLib(&drug)
  6612. // }
  6613. //
  6614. // }
  6615. //
  6616. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6617. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6618. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6619. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6620. // if num1 > num2 {
  6621. // num = num1 - num2
  6622. // drug.Total = drug.Total + num
  6623. // service.UpdateBaseDrugLib(&drug)
  6624. // } else if num1 < num2 {
  6625. // num = num2 - num1
  6626. // drug.Total = drug.Total - num
  6627. // service.UpdateBaseDrugLib(&drug)
  6628. // }
  6629. //
  6630. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6631. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6632. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6633. // if hisAdvice.PrescribingNumber > num2 {
  6634. // num = hisAdvice.PrescribingNumber - num2
  6635. // drug.Total = drug.Total + num
  6636. // service.UpdateBaseDrugLib(&drug)
  6637. // } else if num2 < advice.PrescribingNumber {
  6638. // num = num2 - hisAdvice.PrescribingNumber
  6639. // drug.Total = drug.Total - num
  6640. // service.UpdateBaseDrugLib(&drug)
  6641. // }
  6642. //
  6643. // }
  6644. // }
  6645. // }
  6646. //}
  6647. //
  6648. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6649. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6650. // advice.ExecutionTime = execution_time
  6651. //}
  6652. //
  6653. //
  6654. //
  6655. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6656. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6657. // advice.ExecutionStaff = execution_staff
  6658. //}
  6659. //
  6660. //
  6661. //
  6662. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6663. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6664. // advice.ExecutionState = execution_state
  6665. //}
  6666. //
  6667. //
  6668. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6669. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6670. // advice.CheckTime = check_time
  6671. //}
  6672. //
  6673. //
  6674. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6675. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6676. // advice.CheckState = check_state
  6677. //}
  6678. //
  6679. //
  6680. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6681. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6682. // advice.Checker = checker
  6683. //}
  6684. //
  6685. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6686. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6687. // advice.StartTime = start_time
  6688. //}
  6689. return 0
  6690. }
  6691. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6692. project.ExecutionStaff = 0
  6693. project.ExecutionState = 2
  6694. project.ExecutionTime = 0
  6695. project.Checker = 0
  6696. project.CheckState = 2
  6697. project.CheckTime = 0
  6698. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6699. id := int64(json["id"].(float64))
  6700. project.ID = id
  6701. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6702. project.ExecutionStaff = temp_project.ExecutionStaff
  6703. project.ExecutionState = temp_project.ExecutionState
  6704. project.ExecutionTime = temp_project.ExecutionTime
  6705. project.Checker = temp_project.Checker
  6706. project.CheckState = temp_project.CheckState
  6707. project.CheckTime = temp_project.CheckTime
  6708. project.TeamId = temp_project.TeamId
  6709. }
  6710. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6711. types := int64(json["type"].(float64))
  6712. project.Type = types
  6713. }
  6714. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6715. project_id := int64(json["project_id"].(float64))
  6716. project.ProjectId = project_id
  6717. }
  6718. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6719. team_id := int64(json["team_id"].(float64))
  6720. project.TeamId = team_id
  6721. }
  6722. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6723. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6724. project.Price = price
  6725. }
  6726. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6727. total, _ := json["total"].(string)
  6728. //totals, _ := strconv.ParseInt(total, 10, 64)
  6729. project.Count = total
  6730. }
  6731. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6732. medical_code, _ := json["medical_code"].(string)
  6733. project.MedListCodg = medical_code
  6734. }
  6735. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6736. single_dose, _ := json["single_dose"].(string)
  6737. project.SingleDose = single_dose
  6738. }
  6739. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6740. delivery_way, _ := json["delivery_way"].(string)
  6741. project.DeliveryWay = delivery_way
  6742. }
  6743. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6744. execution_frequency, _ := json["execution_frequency"].(string)
  6745. project.ExecutionFrequency = execution_frequency
  6746. }
  6747. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6748. remark, _ := json["remark"].(string)
  6749. project.Remark = remark
  6750. }
  6751. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6752. day, _ := json["number_days"].(string)
  6753. project.Day = day
  6754. }
  6755. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6756. unit, _ := json["unit"].(string)
  6757. project.Unit = unit
  6758. }
  6759. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6760. // frequency_type := int64(json["frequency_type"].(float64))
  6761. // project.FrequencyType = frequency_type
  6762. //}
  6763. //
  6764. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6765. // day_count := int64(json["day_count"].(float64))
  6766. // project.DayCount = day_count
  6767. //}
  6768. //
  6769. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6770. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6771. // week_day, _ := json["week_day"].(string)
  6772. // project.WeekDay = week_day
  6773. //}
  6774. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6775. //
  6776. //if project.ID == 0 {
  6777. // if stockConfig.IsOpen == 1 {
  6778. // if project.Type == 3 {
  6779. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6780. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6781. // good.Total = good.Total - f_count
  6782. // service.UpdateGoodInfo(&good)
  6783. // }
  6784. // }
  6785. //
  6786. //} else {
  6787. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6788. //
  6789. // if stockConfig.IsOpen == 1 {
  6790. // if project.Type == 3 {
  6791. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6792. // if project.Count < temp_project.Count {
  6793. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6794. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6795. //
  6796. // other_count := f_count_two - f_count_one
  6797. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6798. // good.Total = good.Total + other_count_two
  6799. // service.UpdateGoodInfo(&good)
  6800. // } else if project.Count > temp_project.Count {
  6801. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6802. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6803. //
  6804. // other_count := f_count_one - f_count_two
  6805. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6806. // good.Total = good.Total - other_count_two
  6807. // service.UpdateGoodInfo(&good)
  6808. // }
  6809. //
  6810. // }
  6811. // }
  6812. //
  6813. //}
  6814. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6815. id := int64(json["id"].(float64))
  6816. if id > 0 {
  6817. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6818. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  6819. fmt.Println("666666")
  6820. project.Mtime = time.Now().Unix()
  6821. project.Ctime = temp_project.Ctime
  6822. } else {
  6823. project.Mtime = temp_project.Mtime
  6824. project.Ctime = temp_project.Ctime
  6825. }
  6826. } else {
  6827. ctime := time.Now().Unix()
  6828. project.Mtime = ctime
  6829. project.Ctime = ctime
  6830. }
  6831. }
  6832. return 0
  6833. }
  6834. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6835. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6836. id := int64(json["id"].(float64))
  6837. additionalCharge.ID = id
  6838. }
  6839. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6840. item_id := int64(json["item_id"].(float64))
  6841. additionalCharge.ItemId = item_id
  6842. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6843. if config.ID > 0 {
  6844. if len(config.Code) > 0 {
  6845. additionalCharge.MedListCodg = config.Code
  6846. }
  6847. }
  6848. }
  6849. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6850. // price := int64(json["price"].(float64))
  6851. // formatInt_price := strconv.FormatInt(price, 10)
  6852. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6853. // additionalCharge.Price = float_price
  6854. // }
  6855. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6856. // price := int64(json["price"].(float64))
  6857. // formatInt_price := strconv.FormatInt(price, 10)
  6858. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6859. // additionalCharge.Price = float_price
  6860. //}
  6861. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6862. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6863. additionalCharge.Price = price
  6864. }
  6865. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6866. count, _ := json["count"].(string)
  6867. counts, _ := strconv.ParseInt(count, 10, 64)
  6868. additionalCharge.Count = counts
  6869. }
  6870. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6871. item_name, _ := json["item_name"].(string)
  6872. additionalCharge.ItemName = item_name
  6873. }
  6874. return 0
  6875. }
  6876. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6877. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6878. utils.ErrorLog("drug_name")
  6879. return enums.ErrorCodeParamWrong
  6880. }
  6881. adviceName, _ := json["drug_name"].(string)
  6882. if len(adviceName) == 0 {
  6883. utils.ErrorLog("len(advice_name) == 0")
  6884. return enums.ErrorCodeParamWrong
  6885. }
  6886. advice.AdviceName = adviceName
  6887. adviceDesc, _ := json["advice_desc"].(string)
  6888. advice.AdviceDesc = adviceDesc
  6889. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6890. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6891. advice.DrugSpec = drugSpec
  6892. }
  6893. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6894. remark, _ := json["remark"].(string)
  6895. advice.Remark = remark
  6896. }
  6897. if json["id"] == nil {
  6898. advice.DrugId = 0
  6899. } else {
  6900. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6901. drug_id := int64(json["id"].(float64))
  6902. advice.DrugId = drug_id
  6903. }
  6904. }
  6905. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6906. groupno := int64(json["groupno"].(float64))
  6907. advice.Groupno = groupno
  6908. }
  6909. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6910. drugSpecUnit, _ := json["min_unit"].(string)
  6911. advice.DrugSpecUnit = drugSpecUnit
  6912. }
  6913. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6914. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6915. advice.SingleDose = singleDose
  6916. }
  6917. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6918. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6919. advice.SingleDoseUnit = singleDoseUnit
  6920. }
  6921. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6922. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6923. advice.PrescribingNumber = prescribingNumber
  6924. }
  6925. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6926. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6927. advice.PrescribingNumberUnit = prescribingNumberUnit
  6928. }
  6929. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6930. deliveryWay, _ := json["delivery_way"].(string)
  6931. advice.DeliveryWay = deliveryWay
  6932. }
  6933. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6934. executionFrequency, _ := json["execution_frequency"].(string)
  6935. advice.ExecutionFrequency = executionFrequency
  6936. }
  6937. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6938. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6939. advice.Price = price
  6940. }
  6941. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6942. med_list_codg, _ := json["medical_insurance_number"].(string)
  6943. advice.MedListCodg = med_list_codg
  6944. }
  6945. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6946. day := int64(json["day"].(float64))
  6947. advice.Day = day
  6948. }
  6949. advice.FrequencyType = 1
  6950. return 0
  6951. }
  6952. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  6953. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6954. types := int64(json["type"].(float64))
  6955. project.Type = types
  6956. }
  6957. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6958. project_id := int64(json["project_id"].(float64))
  6959. project.ProjectId = project_id
  6960. }
  6961. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6962. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6963. project.Price = price
  6964. }
  6965. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6966. total, _ := json["total"].(string)
  6967. //totals, _ := strconv.ParseInt(total, 10, 64)
  6968. project.Count = total
  6969. }
  6970. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6971. medical_code, _ := json["medical_code"].(string)
  6972. project.MedListCodg = medical_code
  6973. }
  6974. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6975. single_dose, _ := json["single_dose"].(string)
  6976. project.SingleDose = single_dose
  6977. }
  6978. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6979. delivery_way, _ := json["delivery_way"].(string)
  6980. project.DeliveryWay = delivery_way
  6981. }
  6982. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6983. execution_frequency, _ := json["execution_frequency"].(string)
  6984. project.ExecutionFrequency = execution_frequency
  6985. }
  6986. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6987. remark, _ := json["remark"].(string)
  6988. project.Remark = remark
  6989. }
  6990. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6991. day, _ := json["number_days"].(string)
  6992. project.Day = day
  6993. }
  6994. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6995. unit, _ := json["unit"].(string)
  6996. project.Unit = unit
  6997. }
  6998. project.FrequencyType = 1
  6999. return 0
  7000. }
  7001. func (c *HisApiController) GetHisOrderListTwo() {
  7002. start_time := c.GetString("start_time")
  7003. end_time := c.GetString("end_time")
  7004. timeLayout := "2006-01-02"
  7005. loc, _ := time.LoadLocation("Local")
  7006. var startTime int64
  7007. if len(start_time) > 0 {
  7008. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7009. if err != nil {
  7010. //fmt.Println(err)
  7011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7012. return
  7013. }
  7014. startTime = theTime.Unix()
  7015. }
  7016. var endTime int64
  7017. if len(end_time) > 0 {
  7018. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7019. if err != nil {
  7020. utils.ErrorLog(err.Error())
  7021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7022. return
  7023. }
  7024. endTime = theTime.Unix()
  7025. }
  7026. adminUser := c.GetAdminUserInfo()
  7027. org_id := adminUser.CurrentOrgId
  7028. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7029. if err == nil {
  7030. c.ServeSuccessJSON(map[string]interface{}{
  7031. "order2": order,
  7032. })
  7033. } else {
  7034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7035. return
  7036. }
  7037. }
  7038. func (c *HisApiController) GetHisOrderList() {
  7039. page, _ := c.GetInt64("page", -1)
  7040. limit, _ := c.GetInt64("limit", -1)
  7041. start_time := c.GetString("start_time")
  7042. end_time := c.GetString("end_time")
  7043. types, _ := c.GetInt64("type", 0)
  7044. keywords := c.GetString("keywords")
  7045. p_type, _ := c.GetInt64("p_type", 0)
  7046. sort_type, _ := c.GetInt64("sort_type", 0)
  7047. charge_type, _ := c.GetInt64("charge_type", 0)
  7048. sch_type, _ := c.GetInt64("sch_type", 0)
  7049. zone_type, _ := c.GetInt64("zone_type", 0)
  7050. med_type, _ := c.GetInt64("med_type", 0)
  7051. timeLayout := "2006-01-02"
  7052. loc, _ := time.LoadLocation("Local")
  7053. var startTime int64
  7054. if len(start_time) > 0 {
  7055. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7056. if err != nil {
  7057. //fmt.Println(err)
  7058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7059. return
  7060. }
  7061. startTime = theTime.Unix()
  7062. }
  7063. var endTime int64
  7064. if len(end_time) > 0 {
  7065. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7066. if err != nil {
  7067. utils.ErrorLog(err.Error())
  7068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7069. return
  7070. }
  7071. endTime = theTime.Unix()
  7072. }
  7073. adminUser := c.GetAdminUserInfo()
  7074. org_id := adminUser.CurrentOrgId
  7075. 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)
  7076. for _, item := range order {
  7077. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7078. item.DoctorName = info.Doctor
  7079. item.DepartmentName = info.XtHisDepartment.Name
  7080. }
  7081. if err == nil {
  7082. c.ServeSuccessJSON(map[string]interface{}{
  7083. "order": order,
  7084. "total": total,
  7085. })
  7086. } else {
  7087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7088. return
  7089. }
  7090. }
  7091. func (c *HisApiController) GetHisOrder() {
  7092. patient_id, _ := c.GetInt64("patient_id", 0)
  7093. number := c.GetString("number")
  7094. adminInfo := c.GetAdminUserInfo()
  7095. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7096. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7097. if err == nil {
  7098. c.ServeSuccessJSON(map[string]interface{}{
  7099. "order": order,
  7100. "prescription": prescriptions,
  7101. })
  7102. } else {
  7103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7104. return
  7105. }
  7106. }
  7107. func (c *HisApiController) GetHisPrescriptionList() {
  7108. record_date := c.GetString("record_date")
  7109. keywords := c.GetString("keywords")
  7110. page, _ := c.GetInt64("page")
  7111. limit, _ := c.GetInt64("limit")
  7112. sch_type, _ := c.GetInt64("sch_type")
  7113. timeLayout := "2006-01-02"
  7114. loc, _ := time.LoadLocation("Local")
  7115. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7116. if err != nil {
  7117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7118. return
  7119. }
  7120. recordDateTime := theTime.Unix()
  7121. adminInfo := c.GetAdminUserInfo()
  7122. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7123. //adminInfo := c.GetAdminUserInfo()
  7124. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7125. //fmt.Println(prescriptionOrder)
  7126. if err == nil {
  7127. c.ServeSuccessJSON(map[string]interface{}{
  7128. "order": prescriptionOrder,
  7129. "total": total,
  7130. })
  7131. } else {
  7132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7133. return
  7134. }
  7135. }
  7136. func (c *HisApiController) GetHisPrescriptionInfo() {
  7137. id, _ := c.GetInt64("id")
  7138. adminInfo := c.GetAdminUserInfo()
  7139. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7140. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7141. if err == nil {
  7142. c.ServeSuccessJSON(map[string]interface{}{
  7143. "order": prescriptionOrder,
  7144. "prescription": prescription,
  7145. })
  7146. } else {
  7147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7148. return
  7149. }
  7150. }
  7151. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7152. adminUser := c.GetAdminUserInfo()
  7153. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7154. c.ServeSuccessJSON(map[string]interface{}{
  7155. "config": config,
  7156. })
  7157. }
  7158. type ResultTwo struct {
  7159. ErrMsg interface{} `json:"err_msg"`
  7160. InfRefmsgid string `json:"inf_refmsgid"`
  7161. Infcode int64 `json:"infcode"`
  7162. Output struct {
  7163. Baseinfo struct {
  7164. Age float64 `json:"age"`
  7165. Brdy string `json:"brdy"`
  7166. Certno string `json:"certno"`
  7167. Gend string `json:"gend"`
  7168. Naty string `json:"naty"`
  7169. PsnCertType string `json:"psn_cert_type"`
  7170. PsnName string `json:"psn_name"`
  7171. PsnNo string `json:"psn_no"`
  7172. } `json:"baseinfo"`
  7173. Idetinfo []interface{} `json:"idetinfo"`
  7174. Iinfo []struct {
  7175. Balc float64 `json:"balc"`
  7176. CvlservFlag string `json:"cvlserv_flag"`
  7177. EmpName string `json:"emp_name"`
  7178. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7179. Insutype string `json:"insutype"`
  7180. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7181. PausInsuDate interface{} `json:"paus_insu_date"`
  7182. PsnInsuDate string `json:"psn_insu_date"`
  7183. PsnInsuStas string `json:"psn_insu_stas"`
  7184. PsnType string `json:"psn_type"`
  7185. } `json:"insuinfo"`
  7186. } `json:"output"`
  7187. RefmsgTime string `json:"refmsg_time"`
  7188. RespondTime string `json:"respond_time"`
  7189. Signtype interface{} `json:"signtype"`
  7190. WarnInfo interface{} `json:"warn_info"`
  7191. }
  7192. type ResultThree struct {
  7193. Cainfo interface{} `json:"cainfo"`
  7194. ErrMsg interface{} `json:"err_msg"`
  7195. InfRefmsgid string `json:"inf_refmsgid"`
  7196. Infcode int64 `json:"infcode"`
  7197. Output struct {
  7198. Data struct {
  7199. IptOtpNo string `json:"ipt_otp_no"`
  7200. MdtrtID string `json:"mdtrt_id"`
  7201. PsnNo string `json:"psn_no"`
  7202. } `json:"data"`
  7203. } `json:"output"`
  7204. RefmsgTime string `json:"refmsg_time"`
  7205. RespondTime string `json:"respond_time"`
  7206. Signtype interface{} `json:"signtype"`
  7207. WarnMsg interface{} `json:"warn_msg"`
  7208. }
  7209. type ResultFour struct {
  7210. Cainfo string `json:"cainfo"`
  7211. ErrMsg string `json:"err_msg"`
  7212. InfRefmsgid string `json:"inf_refmsgid"`
  7213. Infcode int64 `json:"infcode"`
  7214. Output struct {
  7215. Result []struct {
  7216. BasMednFlag string `json:"bas_medn_flag"`
  7217. ChldMedcFlag string `json:"chld_medc_flag"`
  7218. ChrgitmLv string `json:"chrgitm_lv"`
  7219. Cnt float64 `json:"cnt"`
  7220. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7221. DrtReimFlag string `json:"drt_reim_flag"`
  7222. FeedetlSn string `json:"feedetl_sn"`
  7223. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7224. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7225. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7226. ListSpItemFlag string `json:"list_sp_item_flag"`
  7227. LmtUsedFlag string `json:"lmt_used_flag"`
  7228. MedChrgitmType string `json:"med_chrgitm_type"`
  7229. Memo string `json:"memo"`
  7230. OverlmtAmt float64 `json:"overlmt_amt"`
  7231. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7232. Pric float64 `json:"pric"`
  7233. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7234. SelfpayProp float64 `json:"selfpay_prop"`
  7235. } `json:"result"`
  7236. } `json:"output"`
  7237. RefmsgTime string `json:"refmsg_time"`
  7238. RespondTime string `json:"respond_time"`
  7239. Signtype string `json:"signtype"`
  7240. WarnMsg string `json:"warn_msg"`
  7241. }
  7242. type ResultFive struct {
  7243. Insutype string `json:"insutype"`
  7244. }
  7245. type ResultSix struct {
  7246. Cainfo interface{} `json:"cainfo"`
  7247. ErrMsg interface{} `json:"err_msg"`
  7248. InfRefmsgid string `json:"inf_refmsgid"`
  7249. Infcode int64 `json:"infcode"`
  7250. Output struct {
  7251. } `json:"output"`
  7252. RefmsgTime string `json:"refmsg_time"`
  7253. RespondTime string `json:"respond_time"`
  7254. Signtype interface{} `json:"signtype"`
  7255. WarnMsg interface{} `json:"warn_msg"`
  7256. }
  7257. type ResultSeven struct {
  7258. Cainfo string `json:"cainfo"`
  7259. ErrMsg string `json:"err_msg"`
  7260. InfRefmsgid string `json:"inf_refmsgid"`
  7261. Infcode int64 `json:"infcode"`
  7262. Output struct {
  7263. Setldetail []interface{} `json:"setldetail"`
  7264. Setlinfo struct {
  7265. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7266. AcctPay float64 `json:"acct_pay"`
  7267. ActPayDedc float64 `json:"act_pay_dedc"`
  7268. Age float64 `json:"age"`
  7269. Balc float64 `json:"balc"`
  7270. Brdy string `json:"brdy"`
  7271. Certno string `json:"certno"`
  7272. ClrOptins string `json:"clr_optins"`
  7273. ClrType string `json:"clr_type"`
  7274. ClrWay string `json:"clr_way"`
  7275. CvlservFlag string `json:"cvlserv_flag"`
  7276. CvlservPay float64 `json:"cvlserv_pay"`
  7277. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7278. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7279. Gend string `json:"gend"`
  7280. HifesPay float64 `json:"hifes_pay"`
  7281. HifmiPay float64 `json:"hifmi_pay"`
  7282. HifobPay float64 `json:"hifob_pay"`
  7283. HifpPay float64 `json:"hifp_pay"`
  7284. HospPartAmt float64 `json:"hosp_part_amt"`
  7285. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7286. Insutype string `json:"insutype"`
  7287. MafPay float64 `json:"maf_pay"`
  7288. MdtrtCertType string `json:"mdtrt_cert_type"`
  7289. MdtrtID string `json:"mdtrt_id"`
  7290. MedType string `json:"med_type"`
  7291. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7292. MedinsSetlID string `json:"medins_setl_id"`
  7293. Naty string `json:"naty"`
  7294. OthPay float64 `json:"oth_pay"`
  7295. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7296. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7297. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7298. PsnCashPay float64 `json:"psn_cash_pay"`
  7299. PsnCertType string `json:"psn_cert_type"`
  7300. PsnName string `json:"psn_name"`
  7301. PsnNo string `json:"psn_no"`
  7302. PsnPartAmt float64 `json:"psn_part_amt"`
  7303. PsnType string `json:"psn_type"`
  7304. SetlID string `json:"setl_id"`
  7305. SetlTime string `json:"setl_time"`
  7306. } `json:"setlinfo"`
  7307. } `json:"output"`
  7308. RefmsgTime string `json:"refmsg_time"`
  7309. RespondTime string `json:"respond_time"`
  7310. Signtype interface{} `json:"signtype"`
  7311. WarnMsg interface{} `json:"warn_msg"`
  7312. }
  7313. type ResultEight struct {
  7314. Cainfo string `json:"cainfo"`
  7315. ErrMsg string `json:"err_msg"`
  7316. InfRefmsgid string `json:"inf_refmsgid"`
  7317. Infcode int64 `json:"infcode"`
  7318. Output struct {
  7319. Stmtinfo struct {
  7320. SetlOptins string `json:"setl_optins"`
  7321. StmtRslt string `json:"stmt_rslt"`
  7322. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7323. } `json:"stmtinfo"`
  7324. } `json:"output"`
  7325. RefmsgTime string `json:"refmsg_time"`
  7326. RespondTime string `json:"respond_time"`
  7327. Signtype interface{} `json:"signtype"`
  7328. WarnMsg interface{} `json:"warn_msg"`
  7329. }
  7330. type ResultNine struct {
  7331. Cainfo string `json:"cainfo"`
  7332. ErrMsg string `json:"err_msg"`
  7333. InfRefmsgid string `json:"inf_refmsgid"`
  7334. Infcode int64 `json:"infcode"`
  7335. Output struct {
  7336. FileQuryNo string `json:"file_qury_no"`
  7337. } `json:"output"`
  7338. RefmsgTime string `json:"refmsg_time"`
  7339. RespondTime string `json:"respond_time"`
  7340. Signtype interface{} `json:"signtype"`
  7341. WarnMsg interface{} `json:"warn_msg"`
  7342. }
  7343. type ResultTen struct {
  7344. Cainfo string `json:"cainfo"`
  7345. ErrMsg string `json:"err_msg"`
  7346. InfRefmsgid string `json:"inf_refmsgid"`
  7347. Infcode int64 `json:"infcode"`
  7348. Output struct {
  7349. DldEndtime string `json:"dld_endtime"`
  7350. FileQuryNo string `json:"file_qury_no"`
  7351. Filename string `json:"filename"`
  7352. } `json:"output"`
  7353. RefmsgTime string `json:"refmsg_time"`
  7354. RespondTime string `json:"respond_time"`
  7355. Signtype interface{} `json:"signtype"`
  7356. WarnMsg interface{} `json:"warn_msg"`
  7357. }
  7358. type ResultEleven struct {
  7359. Cainfo string `json:"cainfo"`
  7360. ErrMsg string `json:"err_msg"`
  7361. InfRefmsgid string `json:"inf_refmsgid"`
  7362. Infcode int64 `json:"infcode"`
  7363. Output struct {
  7364. Setlinfo struct {
  7365. FixmedinsName string `json:"fixmedins_name"`
  7366. FixmedinsCode string `json:"fixmedins_code"`
  7367. PsnNo string `json:"psn_no"`
  7368. PsnName string `json:"psn_name"`
  7369. HifobPay float64 `json:"hifob_pay"`
  7370. Gend string `json:"gend"`
  7371. Brdy string `json:"brdy"`
  7372. PsnCertType string `json:"psn_cert_type"`
  7373. PsnType string `json:"psn_type"`
  7374. EmpName string `json:"emp_name"`
  7375. Certno string `json:"certno"`
  7376. Insutype string `json:"insutype"`
  7377. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7378. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7379. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7380. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7381. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7382. ActPayDedc float64 `json:"act_pay_dedc"`
  7383. HifpPay float64 `json:"hifp_pay"`
  7384. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7385. CvlservPay float64 `json:"cvlserv_pay"`
  7386. HifesPay float64 `json:"hifes_pay"`
  7387. HifmiPay float64 `json:"hifmi_pay"`
  7388. MafPay float64 `json:"maf_pay"`
  7389. OthPay float64 `json:"oth_pay"`
  7390. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7391. PsnPay float64 `json:"psn_pay"`
  7392. AcctPay float64 `json:"acct_pay"`
  7393. CashPayamt float64 `json:"cash_payamt"`
  7394. Balc float64 `json:"balc"`
  7395. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7396. MedinsSetlId string `json:"medins_setl_id"`
  7397. RefdSetlFlag string `json:"refd_setl_flag"`
  7398. SetlTime string `json:"setl_time"`
  7399. MedType string `json:"med_type"`
  7400. } `json:"setlinfo"`
  7401. } `json:"output"`
  7402. RefmsgTime string `json:"refmsg_time"`
  7403. RespondTime string `json:"respond_time"`
  7404. Signtype interface{} `json:"signtype"`
  7405. WarnMsg interface{} `json:"warn_msg"`
  7406. }
  7407. type Custom struct {
  7408. DetItemFeeSumamt string
  7409. Cut string
  7410. FeedetlSn string
  7411. Price string
  7412. MedListCodg string
  7413. Type int64
  7414. AdviceId int64
  7415. ProjectId int64
  7416. ItemId int64
  7417. }
  7418. // 获取个人信息----挂号-----上传就诊信息
  7419. func (c *HisApiController) GetRegisterInfo() {
  7420. id, _ := c.GetInt64("id")
  7421. record_time := c.GetString("record_time")
  7422. settlementValue, _ := c.GetInt64("settlement_value")
  7423. medical_insurance_card := c.GetString("medical_insurance_card")
  7424. name := c.GetString("name")
  7425. id_card_type, _ := c.GetInt64("id_card_type")
  7426. certificates, _ := c.GetInt64("certificates")
  7427. medical_care, _ := c.GetInt64("medical_care")
  7428. birthday := c.GetString("birthday")
  7429. age, _ := c.GetInt64("age")
  7430. id_card := c.GetString("id_card")
  7431. register_type, _ := c.GetInt64("register")
  7432. doctor, _ := c.GetInt64("doctor")
  7433. department, _ := c.GetInt64("department")
  7434. gender, _ := c.GetInt64("sex")
  7435. phone := c.GetString("phone")
  7436. registration_fee, _ := c.GetFloat("registration_fee")
  7437. medical_expenses, _ := c.GetFloat("medical_expenses")
  7438. social_type, _ := c.GetInt64("social_type")
  7439. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7440. diagnosis_ids := c.GetString("diagnosis")
  7441. sick_type, _ := c.GetInt64("sick_type")
  7442. reg_type := c.GetString("p_type")
  7443. timeLayout := "2006-01-02"
  7444. loc, _ := time.LoadLocation("Local")
  7445. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7446. birthUnix := birthdays.Unix()
  7447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7448. if err != nil {
  7449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7450. return
  7451. }
  7452. recordDateTime := theTime.Unix()
  7453. adminInfo := c.GetAdminUserInfo()
  7454. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7455. if tempPatient.ID == 0 {
  7456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7457. return
  7458. }
  7459. var patient service.Patients
  7460. if id == 0 {
  7461. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7462. } else {
  7463. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7464. }
  7465. if patient.ID == 0 {
  7466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7467. return
  7468. }
  7469. if len(patient.IdCardNo) == 0 {
  7470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7471. return
  7472. }
  7473. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7474. if len(his) >= 1 {
  7475. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7476. if len(his) >= 1 && order.ID == 0 {
  7477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7478. return
  7479. }
  7480. }
  7481. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7482. fmt.Println(timeStr)
  7483. timeArr := strings.Split(timeStr, " ")
  7484. fmt.Println(timeArr)
  7485. timeArrTwo := strings.Split(timeArr[0], "-")
  7486. timeArrThree := strings.Split(timeArr[1], ":")
  7487. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7488. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7489. if len(lists) == 0 {
  7490. var hisPatient models.XtHisPatient
  7491. hisPatient = models.XtHisPatient{
  7492. Name: name,
  7493. Age: age,
  7494. Gender: gender,
  7495. Birthday: birthUnix,
  7496. Phone: phone,
  7497. MedicalTreatmentType: medical_care,
  7498. IdType: certificates,
  7499. IdCardNo: id_card,
  7500. BalanceAccountsType: settlementValue,
  7501. SocialType: social_type,
  7502. MedicalInsuranceNumber: medical_insurance_card,
  7503. RegisterType: register_type,
  7504. RegisterCost: registration_fee,
  7505. TreatmentCost: medical_expenses,
  7506. AdminUserId: adminInfo.AdminUser.Id,
  7507. UserOrgId: adminInfo.CurrentOrgId,
  7508. Status: 1,
  7509. RecordDate: recordDateTime,
  7510. IsReturn: 1,
  7511. PatientId: patient.ID,
  7512. Ctime: time.Now().Unix(),
  7513. Mtime: time.Now().Unix(),
  7514. Number: str,
  7515. IdCardType: id_card_type,
  7516. Departments: department,
  7517. Doctor: doctor,
  7518. PType: reg_type,
  7519. Diagnosis: diagnosis_ids,
  7520. SickType: sick_type,
  7521. }
  7522. service.CreateHisPatient(&hisPatient)
  7523. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7524. c.ServeSuccessJSON(map[string]interface{}{
  7525. "his_info": hisPatient,
  7526. })
  7527. } else {
  7528. //chrgBchno := rand.Intn(1000000) + 10000
  7529. var hisPatient models.XtHisPatient
  7530. hisPatient = models.XtHisPatient{
  7531. Name: name,
  7532. Age: age,
  7533. Gender: gender,
  7534. Birthday: birthUnix,
  7535. Phone: phone,
  7536. MedicalTreatmentType: medical_care,
  7537. IdType: certificates,
  7538. IdCardNo: id_card,
  7539. BalanceAccountsType: settlementValue,
  7540. SocialType: social_type,
  7541. MedicalInsuranceNumber: medical_insurance_card,
  7542. RegisterType: register_type,
  7543. RegisterCost: registration_fee,
  7544. TreatmentCost: medical_expenses,
  7545. AdminUserId: adminInfo.AdminUser.Id,
  7546. UserOrgId: adminInfo.CurrentOrgId,
  7547. Status: 1,
  7548. RecordDate: recordDateTime,
  7549. IsReturn: 1,
  7550. PatientId: patient.ID,
  7551. Ctime: time.Now().Unix(),
  7552. Mtime: time.Now().Unix(),
  7553. Number: str,
  7554. IdCardType: id_card_type,
  7555. Departments: department,
  7556. Doctor: doctor,
  7557. PType: reg_type,
  7558. Diagnosis: diagnosis_ids,
  7559. SickType: sick_type,
  7560. }
  7561. service.CreateHisPatient(&hisPatient)
  7562. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7563. c.ServeSuccessJSON(map[string]interface{}{
  7564. "his_info": hisPatient,
  7565. })
  7566. }
  7567. }
  7568. // 上传明细----结算
  7569. func (c *HisApiController) GetUploadInfo() {
  7570. id, _ := c.GetInt64("id")
  7571. record_time := c.GetString("record_time")
  7572. his_patient_id, _ := c.GetInt64("his_patient_id")
  7573. oth_desc := c.GetString("oth_desc")
  7574. pay_way, _ := c.GetInt64("pay_way")
  7575. pay_ways := c.GetString("pay_ways")
  7576. pay_price, _ := c.GetFloat("pay_price")
  7577. pay_card_no := c.GetString("pay_card_no")
  7578. discount_price, _ := c.GetFloat("discount_price")
  7579. preferential_price, _ := c.GetFloat("preferential_price")
  7580. reality_price, _ := c.GetFloat("reality_price")
  7581. found_price, _ := c.GetFloat("found_price")
  7582. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7583. private_price, _ := c.GetFloat("private_price")
  7584. timeLayout := "2006-01-02"
  7585. loc, _ := time.LoadLocation("Local")
  7586. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7587. fapiao_code := c.GetString("fapiao_code")
  7588. fapiao_number := c.GetString("fapiao_number")
  7589. diagnosis_id := c.GetString("diagnosis")
  7590. sick_type, _ := c.GetInt64("sick_type")
  7591. reg_type, _ := c.GetInt64("p_type")
  7592. order_id, _ := c.GetInt64("order_id")
  7593. cash_pay := c.GetString("cash_pay")
  7594. wechat_pay := c.GetString("wechat_pay")
  7595. ali_pay := c.GetString("ali_pay")
  7596. jifen_pay := c.GetString("jifen_pay")
  7597. band_card_pay := c.GetString("band_card_pay")
  7598. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7599. tmp_decimal := c.GetString("tmp_decimal")
  7600. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7601. var decimal float64 //本次使用的押金
  7602. var errmsg error
  7603. tx := service.XTWriteDB().Begin() //开了事务
  7604. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7605. defer func() {
  7606. if errmsg != nil {
  7607. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7608. tx.Rollback()
  7609. } else {
  7610. tx.Commit()
  7611. }
  7612. }()
  7613. fmt.Println("dec_way", dec_way)
  7614. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7615. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7616. return
  7617. }
  7618. if len(tmp_decimal) > 0 {
  7619. if tmp_decimal[0] == 45 {
  7620. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7621. return
  7622. }
  7623. }
  7624. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7625. fmt.Println(errs)
  7626. decimal = tt
  7627. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7628. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7629. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7630. if err != nil {
  7631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7632. return
  7633. }
  7634. recordDateTime := theTime.Unix()
  7635. adminUser := c.GetAdminUserInfo()
  7636. var prescriptions []*models.HisPrescription
  7637. var prescriptionsOne []*models.HisPrescription
  7638. var start_time int64
  7639. var end_time int64
  7640. ids_str := c.GetString("ids")
  7641. ids_arr := strings.Split(ids_str, ",")
  7642. if tempOrder.ID == 0 {
  7643. if settle_accounts_type == 1 { //日结
  7644. fmt.Println(reg_type)
  7645. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7646. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7647. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7648. } else {
  7649. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7650. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7651. }
  7652. } else { //月结
  7653. start_time_str := c.GetString("start_time")
  7654. end_time_str := c.GetString("end_time")
  7655. timeLayout := "2006-01-02"
  7656. loc, _ := time.LoadLocation("Local")
  7657. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7658. if err != nil {
  7659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7660. return
  7661. }
  7662. recordStartTime := theStartTime.Unix()
  7663. start_time = recordStartTime
  7664. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7665. if err != nil {
  7666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7667. return
  7668. }
  7669. recordEndTime := theEndTime.Unix()
  7670. end_time = recordEndTime
  7671. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7672. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7673. }
  7674. var goods []*models.DialysisBeforePrepareGoods
  7675. var newGoods []*models.NewDialysisBeforePrepareGoods
  7676. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7677. var infos []*models.HisDoctorAdviceInfo
  7678. var infoList []*models.HisDoctorAdviceInfo
  7679. var hisAdvice []*models.HisDoctorAdviceInfo
  7680. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7681. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7682. //判断库存不足
  7683. //结算出库开关
  7684. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7685. if settConfig.IsOpen == 1 {
  7686. //判断库存的地方
  7687. for _, info := range prescriptions {
  7688. if info.Type == 1 {
  7689. infos = append(infos, info.HisDoctorAdviceInfo...)
  7690. }
  7691. if info.Type == 2 {
  7692. for _, sumItem := range info.HisPrescriptionProject {
  7693. if sumItem.Type == 3 {
  7694. var good models.DialysisBeforePrepareGoods
  7695. var newGood models.NewDialysisBeforePrepareGoods
  7696. good.GoodId = sumItem.GoodInfo.ID
  7697. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7698. count, _ := strconv.Atoi(sumItem.Count)
  7699. good.Count = int64(count)
  7700. good.StorehouseId = houseConfig.StorehouseOutInfo
  7701. good.ProjectId = sumItem.ID
  7702. goods = append(goods, &good)
  7703. newGood.GoodId = sumItem.GoodInfo.ID
  7704. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7705. count2, _ := strconv.Atoi(sumItem.Count)
  7706. newGood.Count = int64(count2)
  7707. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7708. newGood.ProjectId = sumItem.ID
  7709. newGoods = append(newGoods, &newGood)
  7710. }
  7711. }
  7712. }
  7713. }
  7714. for _, info := range prescriptionsOne {
  7715. if info.Type == 1 {
  7716. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7717. }
  7718. if info.Type == 2 {
  7719. for _, sumItem := range info.HisPrescriptionProject {
  7720. if sumItem.Type == 3 {
  7721. var newGood models.NewDialysisBeforePrepareGoods
  7722. newGood.GoodId = sumItem.GoodInfo.ID
  7723. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7724. count2, _ := strconv.Atoi(sumItem.Count)
  7725. newGood.Count = int64(count2)
  7726. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7727. newGood.ProjectId = sumItem.ID
  7728. newGoodOne = append(newGoodOne, &newGood)
  7729. }
  7730. }
  7731. }
  7732. }
  7733. //判断
  7734. for _, itemOne := range infos {
  7735. for _, itemTwo := range hisAdvice {
  7736. if itemOne.DrugId == itemTwo.DrugId {
  7737. itemTwo.Child = append(itemTwo.Child, itemOne)
  7738. }
  7739. }
  7740. }
  7741. for _, itemTwo := range hisAdvice {
  7742. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7743. var sum_out_count int64
  7744. for _, itemThree := range itemTwo.Child {
  7745. var prescribing_number int64
  7746. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7747. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7748. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7749. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7750. }
  7751. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7752. prescribing_number = parseIntPrescribingNumber
  7753. }
  7754. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7755. prescribing_number = parseIntPrescribingNumber
  7756. }
  7757. sum_out_count += prescribing_number
  7758. }
  7759. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7760. if sum_out_count > drugStockOut.FlushCount {
  7761. c.ServeSuccessJSON(map[string]interface{}{
  7762. "msg": "2",
  7763. "drug": medical,
  7764. })
  7765. return
  7766. }
  7767. }
  7768. for _, itemOne := range newGoods {
  7769. for _, item := range newGoodOne {
  7770. if itemOne.GoodId == item.GoodId {
  7771. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7772. }
  7773. }
  7774. }
  7775. for _, item := range newGoodOne {
  7776. var sum_out_count_one int64
  7777. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7778. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7779. sum_out_count_one += itemOne.Count
  7780. }
  7781. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7782. fmt.Println("sum_out_count_one", sum_out_count_one)
  7783. fmt.Println("list.FlushCount", list.FlushCount)
  7784. if sum_out_count_one > list.FlushCount {
  7785. c.ServeSuccessJSON(map[string]interface{}{
  7786. "msg": "3",
  7787. "good": good,
  7788. })
  7789. return
  7790. }
  7791. }
  7792. }
  7793. timestamp := time.Now().Unix()
  7794. tempTime := time.Unix(timestamp, 0)
  7795. timeFormat := tempTime.Format("20060102150405")
  7796. chrgBchno := rand.Intn(100000) + 10000
  7797. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7798. strconv.FormatInt(his.PatientId, 10)
  7799. var ids []int64
  7800. for _, item := range prescriptions {
  7801. ids = append(ids, item.ID)
  7802. }
  7803. var total float64
  7804. for _, item := range prescriptions {
  7805. fmt.Println(item)
  7806. if item.Type == 1 { //药品
  7807. for _, subItem := range item.HisDoctorAdviceInfo {
  7808. total = total + (subItem.Price * subItem.PrescribingNumber)
  7809. }
  7810. }
  7811. if item.Type == 2 { //项目
  7812. for _, subItem := range item.HisPrescriptionProject {
  7813. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7814. total = total + (subItem.Price * cnt)
  7815. }
  7816. }
  7817. for _, subItem := range item.HisAdditionalCharge {
  7818. total = total + (subItem.Price * float64(subItem.Count))
  7819. }
  7820. }
  7821. if reg_type == 1111 || reg_type == 1112 {
  7822. reg_type = 11
  7823. }
  7824. tm := time.Unix(time.Now().Unix(), 0)
  7825. allTotal := fmt.Sprintf("%.4f", total)
  7826. totals, _ := strconv.ParseFloat(allTotal, 64)
  7827. order := &models.HisOrder{
  7828. UserOrgId: adminUser.CurrentOrgId,
  7829. HisPatientId: his.ID,
  7830. PatientId: id,
  7831. SettleAccountsDate: recordDateTime,
  7832. Ctime: time.Now().Unix(),
  7833. Mtime: time.Now().Unix(),
  7834. Status: 1,
  7835. OrderStatus: 2,
  7836. MdtrtId: his.Number,
  7837. Number: chrg_bchno,
  7838. MedfeeSumamt: totals,
  7839. PayWay: pay_way,
  7840. PayWays: pay_ways,
  7841. PayPrice: pay_price,
  7842. MedType: strconv.Itoa(int(reg_type)),
  7843. PayCardNo: pay_card_no,
  7844. DiscountPrice: discount_price,
  7845. PreferentialPrice: preferential_price,
  7846. RealityPrice: reality_price,
  7847. FoundPrice: found_price,
  7848. MedicalInsurancePrice: medical_insurance_price,
  7849. PrivatePrice: private_price,
  7850. SettleEndTime: end_time,
  7851. SettleStartTime: start_time,
  7852. PsnPartAmt: totals,
  7853. PsnCashPay: totals,
  7854. SettleType: settle_accounts_type,
  7855. FaPiaoCode: fapiao_code,
  7856. FaPiaoNumber: fapiao_number,
  7857. Diagnosis: diagnosis_id,
  7858. PType: 2,
  7859. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7860. Decimal: decimal,
  7861. OthDesc: oth_desc,
  7862. CashPay: cash_pay,
  7863. WechatPay: wechat_pay,
  7864. AliPay: ali_pay,
  7865. JifenPay: jifen_pay,
  7866. BandCardPay: band_card_pay,
  7867. Creator: adminUser.AdminUser.Id,
  7868. }
  7869. err = service.CreateOrderTX(order, tx)
  7870. if err != nil {
  7871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7872. return
  7873. }
  7874. var customs []*Custom
  7875. for _, item := range prescriptions {
  7876. if item.Type == 1 { //药品a
  7877. for _, subItem := range item.HisDoctorAdviceInfo {
  7878. cus := &Custom{
  7879. AdviceId: subItem.ID,
  7880. ProjectId: 0,
  7881. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7882. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7883. FeedetlSn: subItem.FeedetlSn,
  7884. Price: fmt.Sprintf("%.4f", subItem.Price),
  7885. MedListCodg: subItem.MedListCodg,
  7886. Type: 1,
  7887. }
  7888. customs = append(customs, cus)
  7889. }
  7890. }
  7891. if item.Type == 2 { //项目
  7892. for _, subItem := range item.HisPrescriptionProject {
  7893. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7894. cus := &Custom{
  7895. AdviceId: 0,
  7896. ProjectId: subItem.ID,
  7897. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7898. Cut: fmt.Sprintf("%.4f", cnt),
  7899. FeedetlSn: subItem.FeedetlSn,
  7900. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7901. MedListCodg: subItem.MedListCodg,
  7902. Type: 2,
  7903. }
  7904. customs = append(customs, cus)
  7905. }
  7906. }
  7907. for _, item := range item.HisAdditionalCharge {
  7908. cus := &Custom{
  7909. ItemId: item.ID,
  7910. AdviceId: 0,
  7911. ProjectId: 0,
  7912. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7913. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7914. FeedetlSn: item.FeedetlSn,
  7915. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7916. MedListCodg: item.XtHisAddtionConfig.Code,
  7917. Type: 3,
  7918. }
  7919. customs = append(customs, cus)
  7920. }
  7921. }
  7922. for _, item := range customs {
  7923. var advice_id int64 = 0
  7924. var project_id int64 = 0
  7925. var item_id int64 = 0
  7926. var types int64 = 0
  7927. if item.Type == 1 {
  7928. advice_id = item.AdviceId
  7929. project_id = 0
  7930. item_id = 0
  7931. } else if item.Type == 2 {
  7932. advice_id = 0
  7933. item_id = 0
  7934. project_id = item.ProjectId
  7935. } else if item.Type == 3 {
  7936. advice_id = 0
  7937. item_id = item.ItemId
  7938. project_id = 0
  7939. }
  7940. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7941. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7942. pric, _ := strconv.ParseFloat(item.Price, 32)
  7943. info := &models.HisOrderInfo{
  7944. OrderNumber: order.Number,
  7945. UploadDate: time.Now().Unix(),
  7946. AdviceId: advice_id,
  7947. DetItemFeeSumamt: detItemFeeSumamt,
  7948. Cnt: cut,
  7949. Pric: pric,
  7950. PatientId: id,
  7951. Status: 1,
  7952. Mtime: time.Now().Unix(),
  7953. Ctime: time.Now().Unix(),
  7954. UserOrgId: adminUser.CurrentOrgId,
  7955. HisPatientId: his.ID,
  7956. OrderId: order.ID,
  7957. ProjectId: project_id,
  7958. Type: types,
  7959. ItemId: item_id,
  7960. }
  7961. service.CreateOrderInfoTX(info, tx)
  7962. }
  7963. his.Diagnosis = diagnosis_id
  7964. his.SickType = sick_type
  7965. his.RegisterType = reg_type
  7966. his.MedicalTreatmentType = reg_type
  7967. service.UpdataHisPateintTX(&his, tx)
  7968. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  7969. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  7970. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  7971. //判断是否使用了押金
  7972. if dec_way == "true" {
  7973. tmpstring := strconv.FormatInt(order.ID, 10)
  7974. //扣押金
  7975. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  7976. order.Decimal = decimal
  7977. service.UpDateOrderTwo(order, tx)
  7978. if errmsg != nil {
  7979. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  7980. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7981. return
  7982. }
  7983. }
  7984. if err == nil {
  7985. for _, info := range prescriptions {
  7986. if info.Type == 1 {
  7987. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  7988. }
  7989. if info.Type == 2 {
  7990. for _, sumItem := range info.HisPrescriptionProject {
  7991. if sumItem.Type == 3 {
  7992. var good models.DialysisBeforePrepareGoods
  7993. var newGood models.NewDialysisBeforePrepareGoods
  7994. var oldGood models.OldDialysisBeforePrepareGoods
  7995. good.GoodId = sumItem.GoodInfo.ID
  7996. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7997. count, _ := strconv.Atoi(sumItem.Count)
  7998. good.Count = int64(count)
  7999. good.StorehouseId = houseConfig.StorehouseOutInfo
  8000. good.ProjectId = sumItem.ID
  8001. good.PatientId = sumItem.PatientId
  8002. goods = append(goods, &good)
  8003. newGood.GoodId = sumItem.GoodInfo.ID
  8004. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8005. count2, _ := strconv.Atoi(sumItem.Count)
  8006. newGood.Count = int64(count2)
  8007. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8008. newGood.ProjectId = sumItem.ID
  8009. newGood.PatientId = sumItem.HisPatientId
  8010. newGoods = append(newGoods, &newGood)
  8011. oldGood.GoodId = sumItem.GoodInfo.ID
  8012. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8013. count3, _ := strconv.Atoi(sumItem.Count)
  8014. oldGood.Count = int64(count3)
  8015. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8016. oldGood.ProjectId = sumItem.ID
  8017. oldGood.RecordDate = sumItem.RecordDate
  8018. oldGood.PatientId = sumItem.HisPatientId
  8019. oldGoods = append(oldGoods, &oldGood)
  8020. }
  8021. }
  8022. }
  8023. }
  8024. if settConfig.IsOpen == 1 {
  8025. for _, item := range infoList {
  8026. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8027. if medical.IsUse == 2 {
  8028. //药品出库
  8029. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8030. //查询默认仓库
  8031. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8032. //查询默认仓库剩余多少库存
  8033. var sum_count int64
  8034. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8035. for _, its := range stockInfo {
  8036. if its.MaxUnit == medical.MaxUnit {
  8037. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8038. }
  8039. sum_count += its.StockMaxNumber + its.StockMinNumber
  8040. }
  8041. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8042. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8043. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8044. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8045. }
  8046. }
  8047. orgId := c.GetAdminUserInfo().CurrentOrgId
  8048. if len(oldGoods) > 0 {
  8049. timeStr := time.Now().Format("2006-01-02")
  8050. timeArr := strings.Split(timeStr, "-")
  8051. total, _ := service.FindAllWarehouseOut(orgId)
  8052. total = total + 1
  8053. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8054. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8055. number = number + total
  8056. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8057. operation_time := time.Now().Unix()
  8058. creater := c.GetAdminUserInfo().AdminUser.Id
  8059. //查询默认出库仓库库存
  8060. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8061. recordDateStr := time.Now().Format("2006-01-02")
  8062. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8063. nowtime := recordDate.Unix()
  8064. warehouseOut := models.WarehouseOut{
  8065. WarehouseOutOrderNumber: warehousing_out_order,
  8066. OperationTime: operation_time,
  8067. OrgId: orgId,
  8068. Creater: creater,
  8069. Ctime: time.Now().Unix(),
  8070. Status: 1,
  8071. WarehouseOutTime: nowtime,
  8072. Type: 1,
  8073. StorehouseId: storeConfig.StorehouseOutInfo,
  8074. IsCheck: 1,
  8075. OrderId: order.ID,
  8076. IsSys: 5,
  8077. }
  8078. //查询是否生成出库单
  8079. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8080. if out.ID == 0 {
  8081. service.AddSigleWarehouseOut(&warehouseOut)
  8082. }
  8083. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8084. for _, item := range oldGoods {
  8085. dialyPrepareOne := models.DialysisBeforePrepare{
  8086. GoodTypeId: item.GoodTypeId,
  8087. GoodId: item.GoodId,
  8088. PatientId: his.PatientId,
  8089. RecordDate: item.RecordDate,
  8090. UserOrgId: adminUser.CurrentOrgId,
  8091. Count: item.Count,
  8092. Ctime: time.Now().Unix(),
  8093. Creater: adminUser.AdminUser.Id,
  8094. CommdityCode: item.CommdityCode,
  8095. Status: 1,
  8096. StorehouseId: houseConfig.StorehouseOutInfo,
  8097. }
  8098. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8099. //非零用
  8100. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8101. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8102. //查询剩余库存
  8103. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8104. var sum_count int64
  8105. for _, item := range goodList {
  8106. sum_count += item.StockCount
  8107. }
  8108. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8109. //耗材
  8110. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8111. }
  8112. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8113. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8114. //查询剩余库存
  8115. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8116. var sum_count int64
  8117. for _, item := range goodList {
  8118. sum_count += item.StockCount
  8119. }
  8120. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8121. //耗材
  8122. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8123. }
  8124. }
  8125. }
  8126. }
  8127. c.ServeSuccessJSON(map[string]interface{}{
  8128. "msg": "结算成功",
  8129. })
  8130. }
  8131. }
  8132. }
  8133. // 退款
  8134. func (c *HisApiController) Refund() {
  8135. order_id, _ := c.GetInt64("order_id")
  8136. order, _ := service.GetHisOrderByID(order_id)
  8137. adminUser := c.GetAdminUserInfo()
  8138. orgid := c.GetAdminUserInfo().CurrentOrgId
  8139. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8140. if err != nil {
  8141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8142. return
  8143. }
  8144. tmp := strconv.FormatInt(order.ID, 10)
  8145. //当押金不为零时产生退费记录
  8146. if order.Decimal != 0 {
  8147. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8148. if err != nil {
  8149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8150. return
  8151. }
  8152. }
  8153. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8154. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8155. var goods []*models.DialysisBeforePrepareGoods
  8156. var newGoods []*models.NewDialysisBeforePrepareGoods
  8157. var infos []*models.HisDoctorAdviceInfo
  8158. for _, info := range orders {
  8159. if info.AdviceId > 0 && info.ProjectId == 0 {
  8160. infos = append(infos, &info.HisDoctorAdviceInfo)
  8161. }
  8162. if info.ProjectId > 0 && info.AdviceId == 0 {
  8163. if info.HisPrescriptionProject.Type == 3 {
  8164. var good models.DialysisBeforePrepareGoods
  8165. var newGood models.NewDialysisBeforePrepareGoods
  8166. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8167. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8168. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8169. good.Count = int64(count)
  8170. good.StorehouseId = houseConfig.StorehouseOutInfo
  8171. good.ProjectId = info.HisPrescriptionProject.ID
  8172. good.PatientId = info.PatientId
  8173. good.OrderId = order_id
  8174. goods = append(goods, &good)
  8175. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8176. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8177. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8178. newGood.Count = int64(count2)
  8179. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8180. newGood.ProjectId = info.HisPrescriptionProject.ID
  8181. newGood.RecordDate = order.SettleAccountsDate
  8182. newGood.UserOrgId = order.UserOrgId
  8183. newGood.PatientId = info.PatientId
  8184. newGood.OrderId = order_id
  8185. newGoods = append(newGoods, &newGood)
  8186. }
  8187. }
  8188. }
  8189. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8190. if settConfig.IsOpen == 1 {
  8191. for _, item := range infos {
  8192. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8193. }
  8194. for _, item := range newGoods {
  8195. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8196. }
  8197. }
  8198. c.ServeSuccessJSON(map[string]interface{}{
  8199. "msg": "退费成功",
  8200. })
  8201. }
  8202. func (c *HisApiController) RefundNumber() {
  8203. his_patient_id, _ := c.GetInt64("id")
  8204. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8205. info.Status = 0
  8206. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8207. if count > 0 {
  8208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8209. return
  8210. }
  8211. err := service.SaveHisPatient(info)
  8212. if err == nil {
  8213. c.ServeSuccessJSON(map[string]interface{}{
  8214. "msg": "退号成功",
  8215. })
  8216. } else {
  8217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8218. return
  8219. }
  8220. }
  8221. func (this *HisApiController) AdditionalCharge() {
  8222. dataBody := make(map[string]interface{}, 0)
  8223. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8224. fmt.Println(err)
  8225. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8226. patient_id := int64(dataBody["patient_id"].(float64))
  8227. medicineData, _ := dataBody["medicineData"].([]interface{})
  8228. adminUserInfo := this.GetAdminUserInfo()
  8229. orgId := adminUserInfo.CurrentOrgId
  8230. admin_user_id := adminUserInfo.AdminUser.Id
  8231. timeStr := time.Now().Format("2006-01-02")
  8232. timeLayout := "2006-01-02 15:04:05"
  8233. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8234. timenow := timeStringToTime.Unix()
  8235. var additionalCharges []*models.HisAdditionalCharge
  8236. for _, item := range medicineData {
  8237. var randNum int
  8238. randNum = rand.Intn(10000) + 1000
  8239. timestamp := time.Now().Unix()
  8240. tempTime := time.Unix(timestamp, 0)
  8241. timeFormat := tempTime.Format("20060102150405")
  8242. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8243. items := item.(map[string]interface{})
  8244. money := items["price"].(string)
  8245. item_id_str := items["item_id"].(string)
  8246. name := items["name"].(string)
  8247. id_str := items["id"].(string)
  8248. moneys, _ := strconv.ParseInt(money, 10, 64)
  8249. monStr := strconv.FormatInt(moneys, 10)
  8250. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8251. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8252. id, _ := strconv.ParseInt(id_str, 10, 64)
  8253. additionalCharge := &models.HisAdditionalCharge{
  8254. ID: id,
  8255. HisPatientId: his_patient_id,
  8256. UserOrgId: orgId,
  8257. PatientId: patient_id,
  8258. RecordDate: timenow,
  8259. Price: monneyStr,
  8260. Status: 1,
  8261. ItemName: name,
  8262. ItemId: item_id,
  8263. AdminUserId: admin_user_id,
  8264. CreatedTime: time.Now().Unix(),
  8265. OrderStatus: 0,
  8266. PrescriptionNumber: "",
  8267. BatchNumber: "",
  8268. FeedetlSn: p_number,
  8269. }
  8270. service.CreateAdditionalCharge(additionalCharge)
  8271. additionalCharges = append(additionalCharges, additionalCharge)
  8272. }
  8273. this.ServeSuccessJSON(map[string]interface{}{
  8274. "msg": "添加成功",
  8275. "additional_charges": additionalCharges,
  8276. })
  8277. }
  8278. func (this *HisApiController) DeleteAddition() {
  8279. id, _ := this.GetInt64("id")
  8280. //TODO 需要判断是否已经结算
  8281. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8282. if err == nil {
  8283. this.ServeSuccessJSON(map[string]interface{}{
  8284. "msg": "删除成功",
  8285. })
  8286. return
  8287. } else {
  8288. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8289. return
  8290. }
  8291. }
  8292. func (this *HisApiController) GetAdminUsers() {
  8293. adminUser := this.GetAdminUserInfo()
  8294. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8295. this.ServeSuccessJSON(map[string]interface{}{
  8296. "doctors": doctors,
  8297. })
  8298. }
  8299. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8300. change_type, _ := this.GetInt64("type", 0)
  8301. record_date := this.GetString("record_time")
  8302. patient_id, _ := this.GetInt64("patient_id", 0)
  8303. p_type, _ := this.GetInt64("p_type", 0)
  8304. timeLayout := "2006-01-02"
  8305. loc, _ := time.LoadLocation("Local")
  8306. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8307. record_time := theAdviceRecordTime.Unix()
  8308. adminUserInfo := this.GetAdminUserInfo()
  8309. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8310. if err == nil {
  8311. if len(prescriptions) == 0 {
  8312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8313. return
  8314. } else {
  8315. this.ServeSuccessJSON(map[string]interface{}{
  8316. "prescriptions": prescriptions,
  8317. })
  8318. return
  8319. }
  8320. } else {
  8321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8322. return
  8323. }
  8324. }
  8325. func (this *HisApiController) GetCallHisPrescription() {
  8326. patient_id, _ := this.GetInt64("patient_id", 0)
  8327. timeLayout := "2006-01-02"
  8328. loc, _ := time.LoadLocation("Local")
  8329. start_time := this.GetString("start_time")
  8330. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8331. end_time := this.GetString("end_time")
  8332. p_type, _ := this.GetInt64("p_type")
  8333. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8334. adminUserInfo := this.GetAdminUserInfo()
  8335. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8336. if err == nil {
  8337. this.ServeSuccessJSON(map[string]interface{}{
  8338. "prescriptions": prescriptions,
  8339. })
  8340. return
  8341. } else {
  8342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8343. return
  8344. }
  8345. }
  8346. func (this *HisApiController) GetHisDayPrescription() {
  8347. timeLayout := "2006-01-02"
  8348. loc, _ := time.LoadLocation("Local")
  8349. start_time := this.GetString("start_time")
  8350. patient_id, _ := this.GetInt64("patient_id", 0)
  8351. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8352. end_time := this.GetString("end_time")
  8353. p_type, _ := this.GetInt64("p_type")
  8354. order_status, _ := this.GetInt64("type")
  8355. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8356. adminUserInfo := this.GetAdminUserInfo()
  8357. var dayHisPrescription []*models.HisPrescription
  8358. var err error
  8359. if order_status == 1 || order_status == 0 {
  8360. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8361. } else if order_status == 2 {
  8362. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8363. }
  8364. var settle_total float64
  8365. for _, item := range dayHisPrescription {
  8366. if len(item.HisPrescriptionProject) > 0 {
  8367. for _, subItem := range item.HisPrescriptionProject {
  8368. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8369. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8370. settle_total = settle_total + total
  8371. }
  8372. }
  8373. if len(item.HisDoctorAdviceInfo) > 0 {
  8374. for _, subItem := range item.HisDoctorAdviceInfo {
  8375. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8376. settle_total = settle_total + total
  8377. }
  8378. }
  8379. }
  8380. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8381. if err == nil {
  8382. this.ServeSuccessJSON(map[string]interface{}{
  8383. "day_prescription": dayHisPrescription,
  8384. "settle_total": settle_total,
  8385. })
  8386. return
  8387. } else {
  8388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8389. return
  8390. }
  8391. }
  8392. func (c *HisApiController) GetHisChargePatientList() {
  8393. record_date := c.GetString("record_date")
  8394. order_status, _ := c.GetInt64("type")
  8395. sch_type, _ := c.GetInt64("sch_type")
  8396. timeLayout := "2006-01-02"
  8397. loc, _ := time.LoadLocation("Local")
  8398. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8399. if err != nil {
  8400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8401. return
  8402. }
  8403. recordDateTime := theTime.Unix()
  8404. adminInfo := c.GetAdminUserInfo()
  8405. var tempPatients []*service.NewTempPatients
  8406. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8407. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8408. if order_status != 2 {
  8409. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8410. } else {
  8411. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8412. }
  8413. } else {
  8414. if order_status != 2 {
  8415. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8416. } else {
  8417. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8418. }
  8419. }
  8420. var patients []*service.NewTempPatients
  8421. var patients_two []*service.NewTempPatients
  8422. for _, item := range tempPatients {
  8423. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8424. //过滤掉没挂号的和没开处方的
  8425. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8426. patients = append(patients, item)
  8427. }
  8428. //过滤掉没挂号的
  8429. if len(item.HisPatient) > 0 {
  8430. patients_two = append(patients_two, item)
  8431. }
  8432. } else {
  8433. if len(item.HisPrescription) > 0 {
  8434. patients = append(patients, item)
  8435. }
  8436. }
  8437. }
  8438. c.ServeSuccessJSON(map[string]interface{}{
  8439. "list": patients,
  8440. "list_two": patients_two,
  8441. })
  8442. }
  8443. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8444. record_date := c.GetString("record_date")
  8445. timeLayout := "2006-01-02"
  8446. loc, _ := time.LoadLocation("Local")
  8447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8448. if err != nil {
  8449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8450. return
  8451. }
  8452. recordDateTime := theTime.Unix()
  8453. adminUser := c.GetAdminUserInfo()
  8454. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8455. var patients []*service.Patients
  8456. for _, item := range tempPatients {
  8457. if item.HisPatient.ID == 0 {
  8458. patients = append(patients, item)
  8459. }
  8460. }
  8461. c.ServeSuccessJSON(map[string]interface{}{
  8462. "list": patients,
  8463. //"list_two": patients_two,
  8464. })
  8465. }
  8466. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8467. newArr = make([]*service.Patients, 0)
  8468. for i := 0; i < len(patient); i++ {
  8469. repeat := false
  8470. for j := i + 1; j < len(patient); j++ {
  8471. if patient[i].ID == patient[j].ID {
  8472. repeat = true
  8473. break
  8474. }
  8475. }
  8476. if !repeat {
  8477. newArr = append(newArr, patient[i])
  8478. }
  8479. }
  8480. return
  8481. }
  8482. func (c *HisApiController) GetHisChargePatientInfo() {
  8483. patient_id, _ := c.GetInt64("patient_id")
  8484. his_patient_id, _ := c.GetInt64("his_patient_id")
  8485. record_date := c.GetString("record_date")
  8486. //start_time := c.GetString("start_time")
  8487. //end_time := c.GetString("end_time")
  8488. order_status, _ := c.GetInt64("type", 0)
  8489. p_type, _ := c.GetInt64("p_type", 0)
  8490. order_id, _ := c.GetInt64("order_id", 0)
  8491. timeLayout := "2006-01-02"
  8492. loc, _ := time.LoadLocation("Local")
  8493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8494. if err != nil {
  8495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8496. return
  8497. }
  8498. recordDateTime := theTime.Unix()
  8499. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8500. //if err != nil {
  8501. //
  8502. //}
  8503. //startRecordDateTime := startTime.Unix()
  8504. //
  8505. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8506. //if err != nil {
  8507. //
  8508. //}
  8509. //endRecordDateTime := endTime.Unix()
  8510. admin := c.GetAdminUserInfo()
  8511. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8512. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8513. var prescriptions []*models.HisPrescription
  8514. //var unChargeMonthPrescriptions []*models.HisPrescription
  8515. order, _ := service.GetHisOrderByID(order_id)
  8516. if order_status == 1 || order_status == 0 {
  8517. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8518. } else if order_status == 2 {
  8519. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8520. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8521. }
  8522. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8523. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8524. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8525. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8526. //获取所有科室信息
  8527. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8528. c.ServeSuccessJSON(map[string]interface{}{
  8529. "his_info": his_patient_info,
  8530. "xt_info": xt_patient_info,
  8531. "prescription": prescriptions,
  8532. "case_history": case_history,
  8533. "info": patientPrescriptionInfo,
  8534. "last_info": lastPatientPrescriptionInfo,
  8535. "order": order,
  8536. "doctors": doctors,
  8537. "department": department,
  8538. })
  8539. return
  8540. }
  8541. func (c *HisApiController) GetAllOrderDetail() {
  8542. order_id, _ := c.GetInt64("id", 0)
  8543. order, _ := service.GetHisOrderByID(order_id)
  8544. if order.ID == 0 {
  8545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8546. return
  8547. }
  8548. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8549. org_id := c.GetAdminUserInfo().CurrentOrgId
  8550. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8551. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8552. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8553. c.ServeSuccessJSON(map[string]interface{}{
  8554. "order": order,
  8555. "order_info": order_info,
  8556. "patient": patient,
  8557. "admin_info": adminInfo,
  8558. "hospital_record": record,
  8559. })
  8560. return
  8561. }
  8562. func (c *HisApiController) GetAllOrderDetailCollect() {
  8563. order_id, _ := c.GetInt64("id", 0)
  8564. order, _ := service.GetHisOrderByID(order_id)
  8565. if order.ID == 0 {
  8566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8567. return
  8568. }
  8569. org_id := c.GetAdminUserInfo().CurrentOrgId
  8570. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8571. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8572. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8573. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8574. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8575. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8576. var bedCostTotal float64 = 0 //床位总费
  8577. //var bedCostSelfTotal float64 = 0 //床位自费
  8578. var operationCostTotal float64 = 0 //手术费
  8579. //var operationCostSelfTotal float64 = 0 //手术费
  8580. var otherCostTotal float64 = 0 //其他费用
  8581. //var otherCostSelfTotal float64 = 0 //其他费用
  8582. var materialCostTotal float64 = 0 //材料费
  8583. //var materialCostSelfTotal float64 = 0 //材料费
  8584. var westernMedicineCostTotal float64 = 0 //西药费
  8585. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8586. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8587. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8588. var checkCostTotal float64 = 0 //检查费
  8589. //var checkCostSelfTotal float64 = 0 //检查费
  8590. var laboratoryCostTotal float64 = 0 //化验费
  8591. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8592. var treatCostTotal float64 = 0 //治疗费用
  8593. //var treatCostSelfTotal float64 = 0 //治疗费用
  8594. var zhenChaCostTotal float64 = 0 //其他费用
  8595. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8596. decimal.DivisionPrecision = 2
  8597. var BalanceAccountsType int64
  8598. if his.ID > 0 {
  8599. BalanceAccountsType = his.BalanceAccountsType
  8600. } else {
  8601. BalanceAccountsType = record.BalanceAccountsType
  8602. }
  8603. if BalanceAccountsType != 2 {
  8604. for _, item := range order_info {
  8605. if org_id == 10215 {
  8606. if item.MedChrgitmType == "01" { //床位费
  8607. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8608. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8609. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8610. }
  8611. if item.MedChrgitmType == "02" { //诊察费
  8612. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8613. //zhenChaCostSelfTotal = zhenChaCostTotal
  8614. }
  8615. if item.MedChrgitmType == "03" { //检查费
  8616. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8617. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8618. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8619. }
  8620. //if item.MedChrgitmType == "02" { //检查费
  8621. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8622. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8623. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8624. //}
  8625. if item.MedChrgitmType == "04" { //化验费
  8626. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8627. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8628. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8629. }
  8630. if item.MedChrgitmType == "05" { //治疗费
  8631. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8632. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8633. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8634. }
  8635. if item.MedChrgitmType == "06" { //手术费
  8636. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8637. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8638. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8639. }
  8640. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8641. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8642. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8643. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8644. }
  8645. if item.MedChrgitmType == "09" { //西药费
  8646. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8647. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8648. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8649. }
  8650. if item.MedChrgitmType == "11" { //中成费
  8651. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8652. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8653. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8654. }
  8655. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8656. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8657. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8658. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8659. }
  8660. } else if org_id == 10188 || org_id == 10217 {
  8661. if item.MedChrgitmType == "01" { //床位费
  8662. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8663. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8664. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8665. }
  8666. if item.MedChrgitmType == "02" { //诊察费
  8667. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8668. //zhenChaCostSelfTotal = zhenChaCostTotal
  8669. }
  8670. if item.MedChrgitmType == "03" { //检查费
  8671. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8672. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8673. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8674. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8675. }
  8676. //if item.MedChrgitmType == "02" { //检查费
  8677. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8678. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8679. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8680. //}
  8681. if item.MedChrgitmType == "04" { //化验费
  8682. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8683. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8684. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8685. }
  8686. if item.MedChrgitmType == "05" { //治疗费
  8687. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8688. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8689. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8690. }
  8691. if item.MedChrgitmType == "06" { //手术费
  8692. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8693. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8694. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8695. }
  8696. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8697. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8698. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8699. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8700. }
  8701. if item.MedChrgitmType == "09" { //西药费
  8702. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8703. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8704. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8705. }
  8706. if item.MedChrgitmType == "11" { //中成费
  8707. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8708. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8709. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8710. }
  8711. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8712. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8713. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8714. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8715. }
  8716. } else {
  8717. if item.MedChrgitmType == "01" { //床位费
  8718. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8719. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8720. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8721. }
  8722. //if item.MedChrgitmType == "02" { //诊察费
  8723. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8724. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8725. //}
  8726. if item.MedChrgitmType == "03" { //检查费
  8727. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8728. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8729. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8730. }
  8731. //if item.MedChrgitmType == "02" { //检查费
  8732. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8733. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8734. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8735. //}
  8736. if item.MedChrgitmType == "04" { //化验费
  8737. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8738. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8739. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8740. }
  8741. if item.MedChrgitmType == "05" { //治疗费
  8742. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8743. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8744. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8745. }
  8746. if item.MedChrgitmType == "06" { //手术费
  8747. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8748. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8749. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8750. }
  8751. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8752. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8753. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8754. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8755. }
  8756. if item.MedChrgitmType == "09" { //西药费
  8757. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8758. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8759. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8760. }
  8761. if item.MedChrgitmType == "11" { //中成费
  8762. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8763. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8764. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8765. }
  8766. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8767. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8768. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8769. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8770. }
  8771. }
  8772. }
  8773. c.ServeSuccessJSON(map[string]interface{}{
  8774. "order": order,
  8775. "order_info": order_info,
  8776. "patient": patient,
  8777. "admin_info": adminInfo,
  8778. "his_hospital": record,
  8779. "bedCostTotal": bedCostTotal,
  8780. "operationCostTotal": operationCostTotal,
  8781. "otherCostTotal": otherCostTotal,
  8782. "materialCostTotal": materialCostTotal,
  8783. "westernMedicineCostTotal": westernMedicineCostTotal,
  8784. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8785. "checkCostTotal": checkCostTotal,
  8786. "zhenChaCostTotal": zhenChaCostTotal,
  8787. "laboratoryCostTotal": laboratoryCostTotal,
  8788. "treatCostTotal": treatCostTotal,
  8789. })
  8790. } else {
  8791. for _, item := range order_info {
  8792. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8793. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8794. item.MedChrgitmType = "09"
  8795. }
  8796. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8797. if item.HisPrescriptionProject.Type == 2 {
  8798. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8799. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8800. case 0:
  8801. item.MedChrgitmType = "0"
  8802. break
  8803. case 1:
  8804. item.MedChrgitmType = "14"
  8805. break
  8806. case 2:
  8807. item.MedChrgitmType = "05"
  8808. break
  8809. case 3:
  8810. item.MedChrgitmType = "03"
  8811. break
  8812. case 4:
  8813. item.MedChrgitmType = "03"
  8814. break
  8815. case 5:
  8816. item.MedChrgitmType = "08"
  8817. break
  8818. case 6:
  8819. item.MedChrgitmType = "14"
  8820. break
  8821. case 7:
  8822. item.MedChrgitmType = "14"
  8823. break
  8824. case 8:
  8825. item.MedChrgitmType = "03"
  8826. break
  8827. case 9:
  8828. item.MedChrgitmType = "14"
  8829. break
  8830. case 10:
  8831. item.MedChrgitmType = "14"
  8832. break
  8833. case 11:
  8834. item.MedChrgitmType = "06"
  8835. break
  8836. case 12:
  8837. item.MedChrgitmType = "12"
  8838. break
  8839. case 13:
  8840. item.MedChrgitmType = "01"
  8841. break
  8842. case 14:
  8843. item.MedChrgitmType = "04"
  8844. break
  8845. case 15:
  8846. item.MedChrgitmType = "14"
  8847. break
  8848. }
  8849. } else {
  8850. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8851. case 1:
  8852. item.MedChrgitmType = "14"
  8853. break
  8854. case 2:
  8855. item.MedChrgitmType = "05"
  8856. break
  8857. case 3:
  8858. item.MedChrgitmType = "04"
  8859. break
  8860. case 4:
  8861. item.MedChrgitmType = "14"
  8862. break
  8863. case 5:
  8864. item.MedChrgitmType = "08"
  8865. break
  8866. case 6:
  8867. item.MedChrgitmType = "14"
  8868. break
  8869. case 7:
  8870. item.MedChrgitmType = "14"
  8871. break
  8872. case 8:
  8873. item.MedChrgitmType = "03"
  8874. break
  8875. case 9:
  8876. item.MedChrgitmType = "14"
  8877. break
  8878. }
  8879. }
  8880. } else if item.HisPrescriptionProject.Type == 3 {
  8881. item.MedChrgitmType = "08"
  8882. }
  8883. }
  8884. }
  8885. for _, item := range order_info {
  8886. if org_id == 10215 {
  8887. if item.MedChrgitmType == "01" { //床位费
  8888. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8889. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8890. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8891. }
  8892. if item.MedChrgitmType == "02" { //诊察费
  8893. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8894. //zhenChaCostSelfTotal = zhenChaCostTotal
  8895. }
  8896. if item.MedChrgitmType == "03" { //检查费
  8897. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8898. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8899. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8900. }
  8901. //if item.MedChrgitmType == "02" { //检查费
  8902. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8903. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8904. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8905. //}
  8906. if item.MedChrgitmType == "04" { //化验费
  8907. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8908. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8909. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8910. }
  8911. if item.MedChrgitmType == "05" { //治疗费
  8912. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8913. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8914. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8915. }
  8916. if item.MedChrgitmType == "06" { //手术费
  8917. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8918. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8919. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8920. }
  8921. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8922. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8923. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8924. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8925. }
  8926. if item.MedChrgitmType == "09" { //西药费
  8927. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8928. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8929. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8930. }
  8931. if item.MedChrgitmType == "11" { //中成费
  8932. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8933. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8934. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8935. }
  8936. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8937. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8938. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8939. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8940. }
  8941. } else {
  8942. if item.MedChrgitmType == "01" { //床位费
  8943. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8944. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8945. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8946. }
  8947. //if item.MedChrgitmType == "02" { //诊察费
  8948. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8949. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8950. //}
  8951. if item.MedChrgitmType == "03" { //检查费
  8952. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8953. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8954. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8955. }
  8956. //if item.MedChrgitmType == "02" { //检查费
  8957. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8958. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8959. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8960. //}
  8961. if item.MedChrgitmType == "04" { //化验费
  8962. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8963. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8964. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8965. }
  8966. if item.MedChrgitmType == "05" { //治疗费
  8967. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8968. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8969. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8970. }
  8971. if item.MedChrgitmType == "06" { //手术费
  8972. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8973. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8974. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8975. }
  8976. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8977. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8978. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8979. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8980. }
  8981. if item.MedChrgitmType == "09" { //西药费
  8982. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8983. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8984. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8985. }
  8986. if item.MedChrgitmType == "11" { //中成费
  8987. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8988. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8989. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8990. }
  8991. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8992. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8993. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8994. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8995. }
  8996. }
  8997. }
  8998. c.ServeSuccessJSON(map[string]interface{}{
  8999. "order": order,
  9000. "order_info": order_info,
  9001. "patient": patient,
  9002. "admin_info": adminInfo,
  9003. "his_hospital": record,
  9004. "bedCostTotal": bedCostTotal,
  9005. "operationCostTotal": operationCostTotal,
  9006. "otherCostTotal": otherCostTotal,
  9007. "materialCostTotal": materialCostTotal,
  9008. "westernMedicineCostTotal": westernMedicineCostTotal,
  9009. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9010. "checkCostTotal": checkCostTotal,
  9011. "zhenChaCostTotal": zhenChaCostTotal,
  9012. "laboratoryCostTotal": laboratoryCostTotal,
  9013. "treatCostTotal": treatCostTotal,
  9014. })
  9015. }
  9016. }
  9017. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9018. page, _ := c.GetInt64("page")
  9019. limit, _ := c.GetInt64("limit")
  9020. keywords := c.GetString("keywords")
  9021. start_time := c.GetString("start_time")
  9022. end_time := c.GetString("end_time")
  9023. //clr_type := c.GetString("clr_type")
  9024. insutype := c.GetString("insutype")
  9025. timeLayout := "2006-01-02"
  9026. loc, _ := time.LoadLocation("Local")
  9027. var theStartTIme int64
  9028. if len(start_time) > 0 {
  9029. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9030. theStartTIme = theTime.Unix()
  9031. }
  9032. var theEndtTIme int64
  9033. if len(end_time) > 0 {
  9034. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9035. theEndtTIme = theTime.Unix()
  9036. }
  9037. if page <= 0 {
  9038. page = 1
  9039. }
  9040. if limit <= 0 {
  9041. limit = 10
  9042. }
  9043. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9044. c.ServeSuccessJSON(map[string]interface{}{
  9045. "total": total,
  9046. "list": list,
  9047. })
  9048. return
  9049. }
  9050. func (c *HisApiController) GetPutOnRecordList() {
  9051. page, _ := c.GetInt64("page")
  9052. limit, _ := c.GetInt64("limit")
  9053. keywords := c.GetString("keywords")
  9054. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9055. if page <= 0 {
  9056. page = 1
  9057. }
  9058. if limit <= 0 {
  9059. limit = 10
  9060. }
  9061. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9062. c.ServeSuccessJSON(map[string]interface{}{
  9063. "total": total,
  9064. "list": list,
  9065. })
  9066. return
  9067. }
  9068. func (c *HisApiController) GetCompareData() {
  9069. start_time := c.GetString("start_time")
  9070. end_time := c.GetString("end_time")
  9071. insutype := c.GetString("insutype")
  9072. clr_type := c.GetString("clr_type")
  9073. timeLayout := "2006-01-02"
  9074. loc, _ := time.LoadLocation("Local")
  9075. var theStartTIme int64
  9076. if len(start_time) > 0 {
  9077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9078. if err != nil {
  9079. theStartTIme = 0
  9080. }
  9081. theStartTIme = theTime.Unix()
  9082. }
  9083. var theEndtTIme int64
  9084. if len(end_time) > 0 {
  9085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9086. if err != nil {
  9087. theEndtTIme = 0
  9088. }
  9089. theEndtTIme = theTime.Unix()
  9090. }
  9091. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9092. fmt.Println(err)
  9093. if err == nil {
  9094. c.ServeSuccessJSON(map[string]interface{}{
  9095. "list": formData,
  9096. })
  9097. } else {
  9098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9099. return
  9100. }
  9101. }
  9102. func (c *HisApiController) GetFaPiaoData() {
  9103. order_id, _ := c.GetInt64("order_id")
  9104. patient_id, _ := c.GetInt64("patient_id")
  9105. //number := c.GetString("number")
  9106. adminUser := c.GetAdminUserInfo()
  9107. order, _ := service.GetHisOrderByID(order_id)
  9108. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9109. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9110. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9111. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9112. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9113. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9114. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9115. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9116. var bedCostTotal float64 = 0 //床位总费
  9117. var bedCostSelfTotal float64 = 0 //床位自费
  9118. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9119. var operationCostTotal float64 = 0 //手术费
  9120. var operationCostSelfTotal float64 = 0 //手术费
  9121. var operationCostPartSelfTotal float64 = 0 //手术费
  9122. var otherCostTotal float64 = 0 //其他费用
  9123. var otherCostSelfTotal float64 = 0 //其他费用
  9124. var otherCostPartSelfTotal float64 = 0 //其他费用
  9125. var materialCostTotal float64 = 0 //材料费
  9126. var materialCostSelfTotal float64 = 0 //材料费
  9127. var materialCostPartSelfTotal float64 = 0 //材料费
  9128. var westernMedicineCostTotal float64 = 0 //西药费
  9129. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9130. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9131. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9132. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9133. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9134. var checkCostTotal float64 = 0 //检查费
  9135. var checkCostSelfTotal float64 = 0 //检查费
  9136. var checkCostPartSelfTotal float64 = 0 //检查费
  9137. var hiliCostTotal float64 = 0 //护理费
  9138. var hiliCostSelfTotal float64 = 0 //护理费
  9139. var hiliCostPartSelfTotal float64 = 0 //护理费
  9140. var laboratoryCostTotal float64 = 0 //化验费
  9141. var laboratoryCostSelfTotal float64 = 0 //化验费
  9142. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9143. var treatCostTotal float64 = 0 //治疗费用
  9144. var treatCostSelfTotal float64 = 0 //治疗费用
  9145. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9146. var zhenChaCostTotal float64 = 0 //其他费用
  9147. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9148. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9149. decimal.DivisionPrecision = 2
  9150. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9151. var balanceAccountsType int64
  9152. if his.ID > 0 {
  9153. balanceAccountsType = his.BalanceAccountsType
  9154. } else {
  9155. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9156. }
  9157. if balanceAccountsType == 2 {
  9158. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9159. for _, item := range orderInfos_two {
  9160. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9161. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9162. item.MedChrgitmType = "09"
  9163. }
  9164. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9165. if item.HisPrescriptionProject.Type == 2 {
  9166. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9167. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9168. case 0:
  9169. item.MedChrgitmType = "0"
  9170. break
  9171. case 1:
  9172. item.MedChrgitmType = "14"
  9173. break
  9174. case 2:
  9175. item.MedChrgitmType = "05"
  9176. break
  9177. case 3:
  9178. item.MedChrgitmType = "03"
  9179. break
  9180. case 4:
  9181. item.MedChrgitmType = "03"
  9182. break
  9183. case 5:
  9184. item.MedChrgitmType = "08"
  9185. break
  9186. case 6:
  9187. item.MedChrgitmType = "14"
  9188. break
  9189. case 7:
  9190. item.MedChrgitmType = "14"
  9191. break
  9192. case 8:
  9193. item.MedChrgitmType = "03"
  9194. break
  9195. case 9:
  9196. item.MedChrgitmType = "14"
  9197. break
  9198. case 10:
  9199. item.MedChrgitmType = "14"
  9200. break
  9201. case 11:
  9202. item.MedChrgitmType = "06"
  9203. break
  9204. case 12:
  9205. item.MedChrgitmType = "12"
  9206. break
  9207. case 13:
  9208. item.MedChrgitmType = "01"
  9209. break
  9210. case 14:
  9211. item.MedChrgitmType = "04"
  9212. break
  9213. case 15:
  9214. item.MedChrgitmType = "02"
  9215. break
  9216. }
  9217. } else {
  9218. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9219. case 1:
  9220. item.MedChrgitmType = "14"
  9221. break
  9222. case 2:
  9223. item.MedChrgitmType = "05"
  9224. break
  9225. case 3:
  9226. item.MedChrgitmType = "04"
  9227. break
  9228. case 4:
  9229. item.MedChrgitmType = "03"
  9230. break
  9231. case 5:
  9232. item.MedChrgitmType = "08"
  9233. break
  9234. case 6:
  9235. item.MedChrgitmType = "14"
  9236. break
  9237. case 7:
  9238. item.MedChrgitmType = "14"
  9239. break
  9240. case 8:
  9241. item.MedChrgitmType = "03"
  9242. break
  9243. case 9:
  9244. item.MedChrgitmType = "14"
  9245. break
  9246. }
  9247. }
  9248. } else if item.HisPrescriptionProject.Type == 3 {
  9249. item.MedChrgitmType = "08"
  9250. }
  9251. }
  9252. }
  9253. for _, item := range orderInfos_two {
  9254. fmt.Println(item.MedChrgitmType)
  9255. if item.MedChrgitmType == "07" { //床位费
  9256. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9257. hiliCostSelfTotal = hiliCostTotal
  9258. }
  9259. if item.MedChrgitmType == "01" { //床位费
  9260. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9261. bedCostSelfTotal = bedCostTotal
  9262. }
  9263. if item.MedChrgitmType == "02" { //诊察费
  9264. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9265. zhenChaCostSelfTotal = zhenChaCostTotal
  9266. }
  9267. if item.MedChrgitmType == "03" { //检查费
  9268. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9269. checkCostSelfTotal = checkCostTotal
  9270. }
  9271. if item.MedChrgitmType == "04" { //化验费
  9272. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9273. laboratoryCostSelfTotal = laboratoryCostTotal
  9274. }
  9275. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9276. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9277. treatCostSelfTotal = treatCostTotal
  9278. }
  9279. if item.MedChrgitmType == "06" { //手术费
  9280. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9281. operationCostSelfTotal = treatCostTotal
  9282. }
  9283. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9284. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9285. materialCostSelfTotal = materialCostTotal
  9286. }
  9287. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9288. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9289. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9290. }
  9291. if item.MedChrgitmType == "11" { //中成费
  9292. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9293. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9294. }
  9295. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9296. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9297. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9298. otherCostSelfTotal = otherCostTotal
  9299. }
  9300. } else {
  9301. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9302. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9303. otherCostSelfTotal = otherCostTotal
  9304. }
  9305. }
  9306. }
  9307. } else {
  9308. for _, item := range orderInfos {
  9309. if item.MedChrgitmType == "01" { //床位费
  9310. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9311. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9312. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9313. }
  9314. if item.MedChrgitmType == "02" { //诊察费
  9315. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9316. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9317. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9318. }
  9319. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9320. if item.MedChrgitmType == "03" { //检查费
  9321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9322. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9323. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9324. }
  9325. } else {
  9326. if item.MedChrgitmType == "03" { //检查费
  9327. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9328. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9329. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9330. }
  9331. }
  9332. if item.MedChrgitmType == "04" { //化验费
  9333. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9334. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9335. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9336. }
  9337. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9338. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9339. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9340. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9341. }
  9342. if item.MedChrgitmType == "06" { //手术费
  9343. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9344. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9345. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9346. }
  9347. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9348. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9349. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9350. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9351. }
  9352. if item.MedChrgitmType == "07" { //护理
  9353. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9354. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9355. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9356. }
  9357. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9358. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9359. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9360. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9361. }
  9362. if item.MedChrgitmType == "11" { //中成费
  9363. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9364. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9365. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9366. }
  9367. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9368. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9369. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9370. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9371. }
  9372. }
  9373. }
  9374. timeLayout := "2006-01-02"
  9375. loc, _ := time.LoadLocation("Local")
  9376. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9377. if err != nil {
  9378. }
  9379. startRecordDateTime := startTime.Unix()
  9380. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9381. if err != nil {
  9382. }
  9383. endRecordDateTime := endTime.Unix()
  9384. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9385. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9386. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9387. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9388. c.ServeSuccessJSON(map[string]interface{}{
  9389. "charge_admin_name": charge_admin.UserName,
  9390. "order_number": order.Number, //业务流水号
  9391. "id_card_no": his.IdCardNo, //社会保障号
  9392. "patient": patient,
  9393. "department_name": department.Name, //科室
  9394. "number": his.Number, //门诊号
  9395. "date": order.SettleAccountsDate, //结算日期
  9396. "name": order.PsnName, //姓名
  9397. "gender": patient.Gender, //性别
  9398. "psn_cash_money": order.PsnCashPay, //个人支付
  9399. "pay_way": "门诊", //结算方式
  9400. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9401. "admin_user_name": admin.UserName, //收款员
  9402. "order": order,
  9403. "order_info": orderInfos_two,
  9404. "his": his,
  9405. "bedCostTotal": bedCostTotal,
  9406. "bedCostSelfTotal": bedCostSelfTotal,
  9407. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9408. "operationCostTotal": operationCostTotal,
  9409. "operationCostSelfTotal": operationCostSelfTotal,
  9410. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9411. "otherCostTotal": otherCostTotal,
  9412. "otherCostSelfTotal": otherCostSelfTotal,
  9413. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9414. "materialCostTotal": materialCostTotal,
  9415. "materialCostSelfTotal": materialCostSelfTotal,
  9416. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9417. "westernMedicineCostTotal": westernMedicineCostTotal,
  9418. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9419. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9420. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9421. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9422. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9423. "checkCostTotal": checkCostTotal,
  9424. "checkCostSelfTotal": checkCostSelfTotal,
  9425. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9426. "laboratoryCostTotal": laboratoryCostTotal,
  9427. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9428. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9429. "treatCostTotal": treatCostTotal,
  9430. "treatCostSelfTotal": treatCostSelfTotal,
  9431. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9432. "zhenChaCostTotal": zhenChaCostTotal,
  9433. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9434. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9435. "his_hospital_record": his_hospital_record,
  9436. "pre_pay_money": pre_pay_money,
  9437. "refund_sum": sum,
  9438. "doctor_info": doctor_info,
  9439. "hiliCostTotal": hiliCostTotal,
  9440. "hiliCostSelfTotal": hiliCostSelfTotal,
  9441. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9442. })
  9443. }
  9444. //func (c *HisApiController) GetFaPiaoDatas() {
  9445. // order_ids := c.GetString("order_ids")
  9446. // patient_id, _ := c.GetInt64("patient_id")
  9447. // adminUser := c.GetAdminUserInfo()
  9448. //
  9449. // orders := strings.Split(order_ids, ",")
  9450. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9451. //
  9452. // for _, item := range orders {
  9453. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9454. // order, _ := service.GetHisOrderByID(order_id)
  9455. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9456. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9457. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9458. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9459. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9460. //
  9461. // }
  9462. //
  9463. // var bedCostTotal float64 = 0 //床位总费
  9464. // var bedCostSelfTotal float64 = 0 //床位自费
  9465. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9466. //
  9467. // var operationCostTotal float64 = 0 //手术费
  9468. // var operationCostSelfTotal float64 = 0 //手术费
  9469. // var operationCostPartSelfTotal float64 = 0 //手术费
  9470. //
  9471. // var otherCostTotal float64 = 0 //其他费用
  9472. // var otherCostSelfTotal float64 = 0 //其他费用
  9473. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9474. //
  9475. // var materialCostTotal float64 = 0 //材料费
  9476. // var materialCostSelfTotal float64 = 0 //材料费
  9477. // var materialCostPartSelfTotal float64 = 0 //材料费
  9478. //
  9479. // var westernMedicineCostTotal float64 = 0 //西药费
  9480. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9481. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9482. //
  9483. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9484. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9485. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9486. //
  9487. // var checkCostTotal float64 = 0 //检查费
  9488. // var checkCostSelfTotal float64 = 0 //检查费
  9489. // var checkCostPartSelfTotal float64 = 0 //检查费
  9490. //
  9491. // var laboratoryCostTotal float64 = 0 //化验费
  9492. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9493. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9494. //
  9495. // var treatCostTotal float64 = 0 //治疗费用
  9496. // var treatCostSelfTotal float64 = 0 //治疗费用
  9497. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9498. //
  9499. // var zhenChaCostTotal float64 = 0 //其他费用
  9500. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9501. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9502. //
  9503. // decimal.DivisionPrecision = 2
  9504. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9505. //
  9506. // var balanceAccountsType int64
  9507. // if his.ID > 0 {
  9508. // balanceAccountsType = his.BalanceAccountsType
  9509. // } else {
  9510. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9511. // }
  9512. // if balanceAccountsType == 2 {
  9513. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9514. // for _, item := range orderInfos_two {
  9515. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9516. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9517. // item.MedChrgitmType = "09"
  9518. // }
  9519. //
  9520. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9521. // if item.HisPrescriptionProject.Type == 2 {
  9522. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9523. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9524. // case 0:
  9525. // item.MedChrgitmType = "0"
  9526. // break
  9527. // case 1:
  9528. // item.MedChrgitmType = "14"
  9529. // break
  9530. // case 2:
  9531. // item.MedChrgitmType = "05"
  9532. //
  9533. // break
  9534. // case 3:
  9535. // item.MedChrgitmType = "03"
  9536. //
  9537. // break
  9538. // case 4:
  9539. // item.MedChrgitmType = "03"
  9540. //
  9541. // break
  9542. // case 5:
  9543. // item.MedChrgitmType = "08"
  9544. //
  9545. // break
  9546. // case 6:
  9547. // item.MedChrgitmType = "14"
  9548. //
  9549. // break
  9550. // case 7:
  9551. // item.MedChrgitmType = "14"
  9552. //
  9553. // break
  9554. // case 8:
  9555. // item.MedChrgitmType = "03"
  9556. // break
  9557. // case 9:
  9558. // item.MedChrgitmType = "14"
  9559. // break
  9560. // case 10:
  9561. // item.MedChrgitmType = "14"
  9562. // break
  9563. // case 11:
  9564. // item.MedChrgitmType = "06"
  9565. // break
  9566. // case 12:
  9567. // item.MedChrgitmType = "12"
  9568. // break
  9569. // case 13:
  9570. // item.MedChrgitmType = "01"
  9571. // break
  9572. // case 14:
  9573. // item.MedChrgitmType = "04"
  9574. // break
  9575. // case 15:
  9576. // item.MedChrgitmType = "02"
  9577. // break
  9578. //
  9579. // }
  9580. //
  9581. // } else {
  9582. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9583. //
  9584. // case 1:
  9585. // item.MedChrgitmType = "14"
  9586. // break
  9587. // case 2:
  9588. // item.MedChrgitmType = "05"
  9589. //
  9590. // break
  9591. // case 3:
  9592. // item.MedChrgitmType = "03"
  9593. //
  9594. // break
  9595. // case 4:
  9596. // item.MedChrgitmType = "03"
  9597. //
  9598. // break
  9599. // case 5:
  9600. // item.MedChrgitmType = "08"
  9601. //
  9602. // break
  9603. // case 6:
  9604. // item.MedChrgitmType = "14"
  9605. //
  9606. // break
  9607. // case 7:
  9608. // item.MedChrgitmType = "14"
  9609. //
  9610. // break
  9611. // case 8:
  9612. // item.MedChrgitmType = "03"
  9613. // break
  9614. // case 9:
  9615. // item.MedChrgitmType = "14"
  9616. // break
  9617. //
  9618. // }
  9619. //
  9620. // }
  9621. //
  9622. // } else if item.HisPrescriptionProject.Type == 3 {
  9623. // item.MedChrgitmType = "08"
  9624. // }
  9625. // }
  9626. // }
  9627. //
  9628. // for _, item := range orderInfos_two {
  9629. // fmt.Println(item.MedChrgitmType)
  9630. // if item.MedChrgitmType == "01" { //床位费
  9631. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9632. // bedCostSelfTotal = bedCostTotal
  9633. // }
  9634. //
  9635. // if item.MedChrgitmType == "02" { //诊察费
  9636. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9637. // zhenChaCostSelfTotal = zhenChaCostTotal
  9638. // }
  9639. //
  9640. // if item.MedChrgitmType == "03" { //检查费
  9641. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9642. // checkCostSelfTotal = checkCostTotal
  9643. // }
  9644. //
  9645. // if item.MedChrgitmType == "04" { //化验费
  9646. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9647. // laboratoryCostSelfTotal = laboratoryCostTotal
  9648. // }
  9649. //
  9650. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9651. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9652. // treatCostSelfTotal = treatCostTotal
  9653. // }
  9654. //
  9655. // if item.MedChrgitmType == "06" { //手术费
  9656. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9657. // operationCostSelfTotal = treatCostTotal
  9658. // }
  9659. //
  9660. // if item.MedChrgitmType == "08" { //材料费
  9661. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9662. // materialCostSelfTotal = materialCostTotal
  9663. // }
  9664. //
  9665. // if item.MedChrgitmType == "09" { //西药费
  9666. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9667. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9668. // }
  9669. //
  9670. // if item.MedChrgitmType == "11" { //中成费
  9671. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9672. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9673. // }
  9674. //
  9675. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9676. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9677. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9678. // otherCostSelfTotal = otherCostTotal
  9679. // }
  9680. // } else {
  9681. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9682. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9683. // otherCostSelfTotal = otherCostTotal
  9684. // }
  9685. //
  9686. // }
  9687. //
  9688. // }
  9689. //
  9690. // } else {
  9691. // for _, item := range orderInfos {
  9692. // if item.MedChrgitmType == "01" { //床位费
  9693. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9694. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9695. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9696. // }
  9697. //
  9698. // if item.MedChrgitmType == "02" { //诊察费
  9699. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9700. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9701. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9702. // }
  9703. //
  9704. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9705. // if item.MedChrgitmType == "03" { //检查费
  9706. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9707. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9708. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9709. //
  9710. // }
  9711. // } else {
  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. //
  9718. // }
  9719. //
  9720. // if item.MedChrgitmType == "04" { //化验费
  9721. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9722. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9723. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9724. //
  9725. // }
  9726. //
  9727. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  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. // }
  9733. //
  9734. // if item.MedChrgitmType == "06" { //手术费
  9735. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9736. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9737. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9738. // }
  9739. //
  9740. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9741. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9742. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9743. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9744. // }
  9745. //
  9746. // if item.MedChrgitmType == "09" { //西药费
  9747. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9748. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9749. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9750. // }
  9751. //
  9752. // if item.MedChrgitmType == "11" { //中成费
  9753. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9754. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9755. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9756. // }
  9757. //
  9758. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9759. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9760. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9761. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9762. // }
  9763. //
  9764. // }
  9765. // }
  9766. // timeLayout := "2006-01-02"
  9767. // loc, _ := time.LoadLocation("Local")
  9768. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9769. // if err != nil {
  9770. // }
  9771. // startRecordDateTime := startTime.Unix()
  9772. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9773. // if err != nil {
  9774. // }
  9775. // endRecordDateTime := endTime.Unix()
  9776. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9777. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9778. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9779. //
  9780. // c.ServeSuccessJSON(map[string]interface{}{
  9781. // "order_number": order.Number, //业务流水号
  9782. // "id_card_no": his.IdCardNo, //社会保障号
  9783. // "department_name": department.Name, //科室
  9784. // "number": his.Number, //门诊号
  9785. // "date": order.SettleAccountsDate, //结算日期
  9786. // "name": order.PsnName, //姓名
  9787. // "gender": patient.Gender, //性别
  9788. // "psn_cash_money": order.PsnCashPay, //个人支付
  9789. // "pay_way": "门诊", //结算方式
  9790. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9791. // "admin_user_name": admin.UserName, //收款员
  9792. // "order": order,
  9793. // "order_info": orderInfos_two,
  9794. // "his": his,
  9795. // "bedCostTotal": bedCostTotal,
  9796. // "bedCostSelfTotal": bedCostSelfTotal,
  9797. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9798. // "operationCostTotal": operationCostTotal,
  9799. // "operationCostSelfTotal": operationCostSelfTotal,
  9800. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9801. // "otherCostTotal": otherCostTotal,
  9802. // "otherCostSelfTotal": otherCostSelfTotal,
  9803. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9804. // "materialCostTotal": materialCostTotal,
  9805. // "materialCostSelfTotal": materialCostSelfTotal,
  9806. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9807. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9808. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9809. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9810. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9811. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9812. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9813. // "checkCostTotal": checkCostTotal,
  9814. // "checkCostSelfTotal": checkCostSelfTotal,
  9815. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9816. // "laboratoryCostTotal": laboratoryCostTotal,
  9817. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9818. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9819. // "treatCostTotal": treatCostTotal,
  9820. // "treatCostSelfTotal": treatCostSelfTotal,
  9821. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9822. // "zhenChaCostTotal": zhenChaCostTotal,
  9823. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9824. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9825. // "his_hospital_record": his_hospital_record,
  9826. // "pre_pay_money": pre_pay_money,
  9827. // "refund_sum": sum,
  9828. // })
  9829. //
  9830. //}
  9831. func (this *HisApiController) GetIncomeStatisticsData() {
  9832. start_time := this.GetString("start_time")
  9833. end_time := this.GetString("end_time")
  9834. key_words := this.GetString("key_words")
  9835. limit, _ := this.GetInt64("limit")
  9836. page, _ := this.GetInt64("page")
  9837. if page <= 0 {
  9838. page = 1
  9839. }
  9840. if limit <= 0 {
  9841. limit = 10
  9842. }
  9843. statistics_type, _ := this.GetInt64("statistics_type")
  9844. admin := this.GetAdminUserInfo()
  9845. timeLayout := "2006-01-02"
  9846. loc, _ := time.LoadLocation("Local")
  9847. var theStartTIme int64
  9848. if len(start_time) > 0 {
  9849. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9850. if err != nil {
  9851. theStartTIme = 0
  9852. }
  9853. theStartTIme = theTime.Unix()
  9854. }
  9855. var theEndtTIme int64
  9856. if len(end_time) > 0 {
  9857. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9858. if err != nil {
  9859. theEndtTIme = 0
  9860. }
  9861. theEndtTIme = theTime.Unix()
  9862. }
  9863. if statistics_type == 1 {
  9864. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9865. this.ServeSuccessJSON(map[string]interface{}{
  9866. "list": list,
  9867. "total": total,
  9868. })
  9869. } else {
  9870. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9871. this.ServeSuccessJSON(map[string]interface{}{
  9872. "list": list,
  9873. "total": total,
  9874. })
  9875. }
  9876. }
  9877. func (c *HisApiController) PostProjectInformation() {
  9878. adminUser := c.GetAdminUserInfo()
  9879. orgId := adminUser.CurrentOrgId
  9880. dataBody := make(map[string]interface{}, 0)
  9881. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9882. if err != nil {
  9883. utils.ErrorLog(err.Error())
  9884. return
  9885. }
  9886. utils.ErrorLog("%v", dataBody)
  9887. var projectList []*models.HisProject
  9888. var total_goods []interface{}
  9889. tempProjects := dataBody["projects"].([]interface{})
  9890. total_goods = tempProjects
  9891. for index, projectMap := range tempProjects {
  9892. projectM := projectMap.(map[string]interface{})
  9893. var project models.HisProject
  9894. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9895. utils.ErrorLog("project_name")
  9896. return
  9897. }
  9898. project_name, _ := projectM["project_name"].(string)
  9899. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9900. err_log := models.ExportErrLog{
  9901. LogType: 6,
  9902. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9903. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9904. Status: 1,
  9905. CreateTime: time.Now().Unix(),
  9906. UpdateTime: time.Now().Unix(),
  9907. ExportTime: time.Now().Unix(),
  9908. }
  9909. service.CreateExportErrLog(&err_log)
  9910. continue
  9911. }
  9912. project.ProjectName = project_name
  9913. prices := projectM["price"].(string)
  9914. price, _ := strconv.ParseFloat(prices, 64)
  9915. if price <= 0 { //名字为空则生成一条导入错误日志
  9916. err_log := models.ExportErrLog{
  9917. LogType: 6,
  9918. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9919. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  9920. Status: 1,
  9921. CreateTime: time.Now().Unix(),
  9922. UpdateTime: time.Now().Unix(),
  9923. ExportTime: time.Now().Unix(),
  9924. }
  9925. service.CreateExportErrLog(&err_log)
  9926. continue
  9927. }
  9928. project.Price = price
  9929. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  9930. utils.ErrorLog("unit_id")
  9931. return
  9932. }
  9933. unit := projectM["unit"].(string)
  9934. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  9935. err_log := models.ExportErrLog{
  9936. LogType: 6,
  9937. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9938. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  9939. Status: 1,
  9940. CreateTime: time.Now().Unix(),
  9941. UpdateTime: time.Now().Unix(),
  9942. ExportTime: time.Now().Unix(),
  9943. }
  9944. service.CreateExportErrLog(&err_log)
  9945. continue
  9946. }
  9947. project.Unit = unit
  9948. cost_classify := projectM["cost_classify"].(string)
  9949. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  9950. err_log := models.ExportErrLog{
  9951. LogType: 6,
  9952. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9953. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9954. Status: 1,
  9955. CreateTime: time.Now().Unix(),
  9956. UpdateTime: time.Now().Unix(),
  9957. ExportTime: time.Now().Unix(),
  9958. }
  9959. service.CreateExportErrLog(&err_log)
  9960. continue
  9961. }
  9962. var costClassify = "费用类别"
  9963. var cost_classify_id int64
  9964. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  9965. if len(cost_classify) != 0 {
  9966. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  9967. if errcode == gorm.ErrRecordNotFound {
  9968. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  9969. dataconfig := models.DictDataconfig{
  9970. ParentId: costClassifyConfig.ID,
  9971. Module: "system",
  9972. OrgId: orgId,
  9973. Name: cost_classify,
  9974. FieldName: "",
  9975. Value: costConfig.Value + 1,
  9976. CreatedTime: "",
  9977. UpdatedTime: "",
  9978. CreateUserId: adminUser.AdminUser.Id,
  9979. Status: 1,
  9980. Remark: "",
  9981. DeleteIdSystem: 0,
  9982. Title: "",
  9983. Content: "",
  9984. Order: 0,
  9985. Code: "",
  9986. }
  9987. service.CreatedDicConfig(&dataconfig)
  9988. }
  9989. }
  9990. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  9991. for _, it := range costClassList {
  9992. if cost_classify == it.Name {
  9993. cost_classify_id = int64(it.Value)
  9994. }
  9995. }
  9996. project.CostClassify = cost_classify_id
  9997. executive_section := projectM["executive_section"].(string)
  9998. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  9999. err_log := models.ExportErrLog{
  10000. LogType: 6,
  10001. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10002. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10003. Status: 1,
  10004. CreateTime: time.Now().Unix(),
  10005. UpdateTime: time.Now().Unix(),
  10006. ExportTime: time.Now().Unix(),
  10007. }
  10008. service.CreateExportErrLog(&err_log)
  10009. continue
  10010. }
  10011. if len(executive_section) != 0 {
  10012. //查找科室是否有内容
  10013. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10014. if errcodedepart == gorm.ErrRecordNotFound {
  10015. department := models.XtHisDepartment{
  10016. Name: executive_section,
  10017. Status: 1,
  10018. UserOrgId: adminUser.CurrentOrgId,
  10019. CreatedTime: time.Now().Unix(),
  10020. }
  10021. service.CreateDePartment(&department)
  10022. }
  10023. }
  10024. var executive_section_id int64
  10025. departMentList, _ := service.GetAllDepartMent(orgId)
  10026. for _, it := range departMentList {
  10027. if executive_section == it.Name {
  10028. executive_section_id = it.ID
  10029. }
  10030. }
  10031. project.ExecutiveSection = executive_section_id
  10032. medical_coverage := projectM["medical_coverage"].(string)
  10033. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10034. err_log := models.ExportErrLog{
  10035. LogType: 6,
  10036. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10037. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10038. Status: 1,
  10039. CreateTime: time.Now().Unix(),
  10040. UpdateTime: time.Now().Unix(),
  10041. ExportTime: time.Now().Unix(),
  10042. }
  10043. service.CreateExportErrLog(&err_log)
  10044. continue
  10045. }
  10046. var medicalCoverage = "医保等级"
  10047. var medical_coverage_id int64
  10048. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10049. if len(medical_coverage) != 0 {
  10050. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10051. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10052. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10053. dataconfig := models.DictDataconfig{
  10054. ParentId: medicalCoverageConfig.ID,
  10055. Module: "system",
  10056. OrgId: orgId,
  10057. Name: medical_coverage,
  10058. FieldName: "",
  10059. Value: medicalCoverageConfig.Value + 1,
  10060. CreatedTime: "",
  10061. UpdatedTime: "",
  10062. CreateUserId: adminUser.AdminUser.Id,
  10063. Status: 1,
  10064. Remark: "",
  10065. DeleteIdSystem: 0,
  10066. Title: "",
  10067. Content: "",
  10068. Order: 0,
  10069. Code: "",
  10070. }
  10071. service.CreatedDicConfig(&dataconfig)
  10072. }
  10073. }
  10074. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10075. for _, it := range medicalCoverageList {
  10076. if medical_coverage == it.Name {
  10077. medical_coverage_id = int64(it.Value)
  10078. }
  10079. }
  10080. project.MedicalCoverage = medical_coverage_id
  10081. pinyin := projectM["pinyin"].(string)
  10082. project.Pinyin = pinyin
  10083. wubi := projectM["wubi"].(string)
  10084. project.Wubi = wubi
  10085. statistical_classification := projectM["statistical_classification"].(string)
  10086. var statisticalClassification = "统计分类"
  10087. var statistical_classification_id int64
  10088. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10089. if len(statistical_classification) != 0 {
  10090. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10091. if classificationerrcodes == gorm.ErrRecordNotFound {
  10092. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10093. dataconfig := models.DictDataconfig{
  10094. ParentId: classiFication.ID,
  10095. Module: "system",
  10096. OrgId: orgId,
  10097. Name: statistical_classification,
  10098. FieldName: "",
  10099. Value: classiFicationConfig.Value + 1,
  10100. CreatedTime: "",
  10101. UpdatedTime: "",
  10102. CreateUserId: adminUser.AdminUser.Id,
  10103. Status: 1,
  10104. Remark: "",
  10105. DeleteIdSystem: 0,
  10106. Title: "",
  10107. Content: "",
  10108. Order: 0,
  10109. Code: "",
  10110. }
  10111. service.CreatedDicConfig(&dataconfig)
  10112. }
  10113. }
  10114. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10115. for _, it := range classiFicationList {
  10116. if statistical_classification == it.Name {
  10117. statistical_classification_id = int64(it.Value)
  10118. }
  10119. }
  10120. project.StatisticalClassification = statistical_classification_id
  10121. disease_directory := int64(projectM["disease_directory"].(float64))
  10122. project.DiseaseDirectory = disease_directory
  10123. is_record := int64(projectM["is_record"].(float64))
  10124. project.IsRecord = is_record
  10125. medical_code := projectM["medical_code"].(string)
  10126. project.MedicalCode = medical_code
  10127. tube_color := projectM["tube_color"].(string)
  10128. var tubeColor = "试管颜色"
  10129. var tube_color_id int64
  10130. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10131. if len(tube_color) != 0 {
  10132. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10133. if errcodetube == gorm.ErrRecordNotFound {
  10134. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10135. dataconfig := models.DictDataconfig{
  10136. ParentId: tubeColorConfig.ID,
  10137. Module: "system",
  10138. OrgId: orgId,
  10139. Name: tube_color,
  10140. FieldName: "",
  10141. Value: tubeConfig.Value + 1,
  10142. CreatedTime: "",
  10143. UpdatedTime: "",
  10144. CreateUserId: adminUser.AdminUser.Id,
  10145. Status: 1,
  10146. Remark: "",
  10147. DeleteIdSystem: 0,
  10148. Title: "",
  10149. Content: "",
  10150. Order: 0,
  10151. Code: "",
  10152. }
  10153. service.CreatedDicConfig(&dataconfig)
  10154. }
  10155. }
  10156. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10157. for _, it := range tubeColorList {
  10158. if tube_color == it.Name {
  10159. tube_color_id = int64(it.Value)
  10160. }
  10161. }
  10162. project.TubeColor = tube_color_id
  10163. single_dose := projectM["single_dose"].(string)
  10164. project.SingleDose = single_dose
  10165. execution_frequency := projectM["execution_frequency"].(string)
  10166. project.ExecutionFrequency = execution_frequency
  10167. delivery_way := projectM["delivery_way"].(string)
  10168. project.DeliveryWay = delivery_way
  10169. number_days := projectM["number_days"].(string)
  10170. project.NumberDays = number_days
  10171. total := projectM["total"].(string)
  10172. project.Total = total
  10173. medical_status := int64(projectM["medical_status"].(float64))
  10174. project.MedicalStatus = medical_status
  10175. category := int64(projectM["category"].(float64))
  10176. project.Category = category
  10177. specail_project := int64(projectM["specail_project"].(float64))
  10178. project.SpecailProject = specail_project
  10179. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10180. project.SocialSecurityDirectoryCode = social_security_directory_code
  10181. remark := projectM["remark"].(string)
  10182. project.Remark = remark
  10183. record_date := projectM["record_date"].(string)
  10184. timeLayout := "2006-01-02"
  10185. loc, _ := time.LoadLocation("Local")
  10186. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10187. project.RecordDate = theTime.Unix()
  10188. projectList = append(projectList, &project)
  10189. }
  10190. export_time := time.Now().Unix()
  10191. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10192. if len(projectList) > 0 {
  10193. for _, item := range projectList {
  10194. hans := item.ProjectName // 要转换的汉字字符串
  10195. // 创建一个拼音转换器
  10196. p := pinyin.NewArgs()
  10197. // 将汉字转为拼音
  10198. pinyinSlice := pinyin.Pinyin(hans, p)
  10199. // 输出拼音
  10200. fmt.Println("Pinyin:", pinyinSlice)
  10201. // 获取首字母
  10202. firstLetter := ""
  10203. for _, py := range pinyinSlice {
  10204. if len(py) > 0 {
  10205. firstLetter += string(py[0][0])
  10206. }
  10207. }
  10208. item.FirstLetter = firstLetter
  10209. project := models.HisProject{
  10210. ProjectName: item.ProjectName,
  10211. Price: item.Price,
  10212. Unit: item.Unit,
  10213. CostClassify: item.CostClassify,
  10214. ExecutiveSection: item.ExecutiveSection,
  10215. MedicalCoverage: item.MedicalCoverage,
  10216. UserOrgId: orgId,
  10217. Status: 1,
  10218. CreatedTime: time.Now().Unix(),
  10219. Pinyin: item.Pinyin,
  10220. Wubi: item.Wubi,
  10221. StatisticalClassification: item.StatisticalClassification,
  10222. DiseaseDirectory: item.DiseaseDirectory,
  10223. IsRecord: item.IsRecord,
  10224. MedicalCode: item.MedicalCode,
  10225. TubeColor: item.TubeColor,
  10226. SingleDose: item.SingleDose,
  10227. DeliveryWay: item.DeliveryWay,
  10228. NumberDays: item.NumberDays,
  10229. Total: item.Total,
  10230. Category: item.Category,
  10231. MedicalStatus: item.MedicalStatus,
  10232. SpecailProject: item.SpecailProject,
  10233. RecordDate: item.RecordDate,
  10234. Remark: item.Remark,
  10235. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10236. ExecutionFrequency: item.ExecutionFrequency,
  10237. FirstLetter: item.FirstLetter,
  10238. }
  10239. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10240. if errcodeproject == gorm.ErrRecordNotFound {
  10241. service.CreateProjectInfomation(&project)
  10242. } else if errcodeproject == nil {
  10243. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10244. }
  10245. log := models.ExportLog{
  10246. LogType: 6,
  10247. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10248. TotalNum: int64(len(total_goods)),
  10249. FailNum: int64(len(errLogs)),
  10250. SuccessNum: int64(len(projectList)),
  10251. CreateTime: time.Now().Unix(),
  10252. UpdateTime: time.Now().Unix(),
  10253. ExportTime: export_time,
  10254. Status: 1,
  10255. }
  10256. service.CreateExportLog(&log)
  10257. c.ServeSuccessJSON(map[string]interface{}{
  10258. "msg": "导入成功",
  10259. "total_num": len(total_goods),
  10260. "success_num": len(projectList),
  10261. "fail_num": int64(len(errLogs)),
  10262. })
  10263. }
  10264. } else {
  10265. log := models.ExportLog{
  10266. LogType: 6,
  10267. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10268. TotalNum: int64(len(total_goods)),
  10269. FailNum: int64(len(errLogs)),
  10270. SuccessNum: int64(len(projectList)),
  10271. CreateTime: time.Now().Unix(),
  10272. UpdateTime: time.Now().Unix(),
  10273. ExportTime: export_time,
  10274. Status: 1,
  10275. }
  10276. service.CreateExportLog(&log)
  10277. c.ServeSuccessJSON(map[string]interface{}{
  10278. "msg": "导入成功",
  10279. "total_num": len(total_goods),
  10280. "success_num": len(projectList),
  10281. "fail_num": int64(len(errLogs)),
  10282. })
  10283. }
  10284. }
  10285. //func (this *HisApiController) EditProjectInformation(){
  10286. //
  10287. // id, _ := this.GetInt64("id")
  10288. // project_team := this.GetString("project_team")
  10289. // price := this.GetString("price")
  10290. // price_float, _ := strconv.ParseFloat(price, 64)
  10291. // pinyin := this.GetString("pinyin")
  10292. // wubi := this.GetString("wubi")
  10293. // tube_color, _ := this.GetInt64("tube_color")
  10294. // team_type, _ := this.GetInt64("team_type")
  10295. // remark := this.GetString("remark")
  10296. // ids := this.GetString("ids")
  10297. // item_id := this.GetString("item_id")
  10298. // projectTeam := models.XtHisProjectTeam{
  10299. // ProjectTeam: project_team,
  10300. // Price: price_float,
  10301. // Pinyin: pinyin,
  10302. // Wubi: wubi,
  10303. // TubeColor: tube_color,
  10304. // TeamType: team_type,
  10305. // Remark: remark,
  10306. // ProjectId: ids,
  10307. // ItemId: item_id,
  10308. // }
  10309. //
  10310. //
  10311. // dataBody := make(map[string]interface{}, 0)
  10312. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10313. // if err != nil {
  10314. // utils.ErrorLog(err.Error())
  10315. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10316. // return
  10317. // }
  10318. //
  10319. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10320. //
  10321. //
  10322. // if err != nil {
  10323. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10324. // return
  10325. // }
  10326. //
  10327. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10328. // infos, _ := dataBody["info"].([]interface{})
  10329. // if len(infos) > 0 {
  10330. // var ids []string
  10331. //
  10332. // for _, item := range infos {
  10333. // items := item.(map[string]interface{})
  10334. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10335. // utils.ErrorLog("id")
  10336. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10337. // return
  10338. // }
  10339. // id := int64(items["id"].(float64))
  10340. //
  10341. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10342. // utils.ErrorLog("type")
  10343. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10344. // return
  10345. // }
  10346. // types := int64(items["type"].(float64))
  10347. //
  10348. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10349. // utils.ErrorLog("number")
  10350. // }
  10351. //
  10352. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10353. //
  10354. // projectList := models.XtHisProjectList{
  10355. // Number: number,
  10356. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10357. // ProjectId: id,
  10358. // Status: 1,
  10359. // CreatedTime: time.Now().Unix(),
  10360. // UpdatedTime: time.Now().Unix(),
  10361. // TeamId: projectTeam.ID,
  10362. // Type: types,
  10363. // }
  10364. // list := projectList
  10365. //
  10366. // service.CreateProjectList(&list)
  10367. //
  10368. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10369. //
  10370. // }
  10371. // ids_str := strings.Join(ids, ",")
  10372. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10373. // service.SaveProjectTeam(&projectTeam)
  10374. // this.ServeSuccessJSON(map[string]interface{}{
  10375. // "projectTeam": projectTeam,
  10376. // })
  10377. // }
  10378. // }
  10379. //}
  10380. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10381. name := c.GetString("name")
  10382. mode_id, _ := c.GetInt64("mode", 0)
  10383. types, _ := c.GetInt64("type", 0)
  10384. patient_id, _ := c.GetInt64("patient_id", 0)
  10385. types = 1
  10386. adminInfo := c.GetAdminUserInfo()
  10387. template := &models.HisPrescriptionTemplate{
  10388. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10389. PatientId: patient_id,
  10390. Type: types,
  10391. Status: 1,
  10392. Ctime: time.Now().Unix(),
  10393. Mtime: time.Now().Unix(),
  10394. Name: name,
  10395. Mode: mode_id,
  10396. }
  10397. dataBody := make(map[string]interface{}, 0)
  10398. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10399. if err != nil {
  10400. utils.ErrorLog(err.Error())
  10401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10402. return
  10403. }
  10404. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10405. //如果已经存在记录则删除处方
  10406. if template_one.ID > 0 {
  10407. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10408. var ids []int64
  10409. var org_id int64
  10410. for _, item := range ps {
  10411. org_id = c.GetAdminUserInfo().CurrentOrgId
  10412. ids = append(ids, item.ID)
  10413. }
  10414. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10415. if err2 == nil {
  10416. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10417. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10418. if len(prescriptions) > 0 {
  10419. for _, item := range prescriptions {
  10420. items := item.(map[string]interface{})
  10421. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10422. utils.ErrorLog("type")
  10423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10424. return
  10425. }
  10426. types := int64(items["type"].(float64))
  10427. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10428. utils.ErrorLog("med_type")
  10429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10430. return
  10431. }
  10432. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10433. ctime := time.Now().Unix()
  10434. prescription := &models.HisPrescriptionInfoTemplate{
  10435. PatientId: patient_id,
  10436. UserOrgId: adminInfo.CurrentOrgId,
  10437. Ctime: ctime,
  10438. Mtime: ctime,
  10439. Type: types,
  10440. Modifier: adminInfo.AdminUser.Id,
  10441. Creator: adminInfo.AdminUser.Id,
  10442. Status: 1,
  10443. PTemplateId: template_one.ID,
  10444. MedType: med_type,
  10445. }
  10446. service.CreateHisPrescriptionInfoTemplate(prescription)
  10447. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10448. advices := items["advices"].([]interface{})
  10449. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10450. ctime := time.Now().Unix()
  10451. mtime := ctime
  10452. if len(advices) > 0 {
  10453. for _, advice := range advices {
  10454. var s models.HisPrescriptionAdviceTemplate
  10455. s.PrescriptionId = prescription.ID
  10456. s.AdviceType = 2
  10457. s.StopState = 2
  10458. s.ExecutionState = 2
  10459. s.Status = 1
  10460. s.UserOrgId = adminInfo.CurrentOrgId
  10461. s.CreatedTime = ctime
  10462. s.UpdatedTime = mtime
  10463. s.PatientId = patient_id
  10464. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10465. if errcode > 0 {
  10466. c.ServeFailJSONWithSGJErrorCode(errcode)
  10467. return
  10468. }
  10469. service.CreateHisPrescriptionAdviceTemplate(&s)
  10470. }
  10471. }
  10472. }
  10473. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10474. projects := items["project"].([]interface{})
  10475. if len(projects) > 0 {
  10476. for _, project := range projects {
  10477. var p models.HisPrescriptionProjectTemplate
  10478. p.PrescriptionId = prescription.ID
  10479. p.Ctime = time.Now().Unix()
  10480. p.Mtime = time.Now().Unix()
  10481. p.PatientId = patient_id
  10482. p.UserOrgId = adminInfo.CurrentOrgId
  10483. p.Status = 1
  10484. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10485. if errcode > 0 {
  10486. c.ServeFailJSONWithSGJErrorCode(errcode)
  10487. return
  10488. }
  10489. service.CreateHisPrescriptionProjectTemplate(&p)
  10490. }
  10491. }
  10492. }
  10493. }
  10494. c.ServeSuccessJSON(map[string]interface{}{
  10495. "msg": "创建成功",
  10496. })
  10497. }
  10498. }
  10499. } else {
  10500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10501. return
  10502. }
  10503. } else {
  10504. err3 := service.CreateHisPrescriptionTemplate(template)
  10505. if err3 == nil {
  10506. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10507. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10508. if len(prescriptions) > 0 {
  10509. for _, item := range prescriptions {
  10510. items := item.(map[string]interface{})
  10511. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10512. utils.ErrorLog("type")
  10513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10514. return
  10515. }
  10516. types := int64(items["type"].(float64))
  10517. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10518. utils.ErrorLog("med_type")
  10519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10520. return
  10521. }
  10522. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10523. ctime := time.Now().Unix()
  10524. prescription := &models.HisPrescriptionInfoTemplate{
  10525. PatientId: patient_id,
  10526. UserOrgId: adminInfo.CurrentOrgId,
  10527. Ctime: ctime,
  10528. Mtime: ctime,
  10529. Type: types,
  10530. Modifier: adminInfo.AdminUser.Id,
  10531. Creator: adminInfo.AdminUser.Id,
  10532. Status: 1,
  10533. PTemplateId: template.ID,
  10534. MedType: med_type,
  10535. }
  10536. service.CreateHisPrescriptionInfoTemplate(prescription)
  10537. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10538. advices := items["advices"].([]interface{})
  10539. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10540. ctime := time.Now().Unix()
  10541. mtime := ctime
  10542. if len(advices) > 0 {
  10543. for _, advice := range advices {
  10544. var s models.HisPrescriptionAdviceTemplate
  10545. s.PrescriptionId = prescription.ID
  10546. s.AdviceType = 2
  10547. s.StopState = 2
  10548. s.ExecutionState = 2
  10549. s.Status = 1
  10550. s.UserOrgId = adminInfo.CurrentOrgId
  10551. s.CreatedTime = ctime
  10552. s.UpdatedTime = mtime
  10553. s.PatientId = patient_id
  10554. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10555. if errcode > 0 {
  10556. c.ServeFailJSONWithSGJErrorCode(errcode)
  10557. return
  10558. }
  10559. service.CreateHisPrescriptionAdviceTemplate(&s)
  10560. }
  10561. }
  10562. }
  10563. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10564. projects := items["project"].([]interface{})
  10565. if len(projects) > 0 {
  10566. for _, project := range projects {
  10567. var p models.HisPrescriptionProjectTemplate
  10568. p.PrescriptionId = prescription.ID
  10569. p.Ctime = time.Now().Unix()
  10570. p.Mtime = time.Now().Unix()
  10571. p.PatientId = patient_id
  10572. p.UserOrgId = adminInfo.CurrentOrgId
  10573. p.Status = 1
  10574. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10575. if errcode > 0 {
  10576. c.ServeFailJSONWithSGJErrorCode(errcode)
  10577. return
  10578. }
  10579. service.CreateHisPrescriptionProjectTemplate(&p)
  10580. }
  10581. }
  10582. }
  10583. }
  10584. c.ServeSuccessJSON(map[string]interface{}{
  10585. "msg": "创建成功",
  10586. })
  10587. }
  10588. }
  10589. } else {
  10590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10591. return
  10592. }
  10593. }
  10594. }
  10595. func (c *HisApiController) PreSettle() {
  10596. id, _ := c.GetInt64("id")
  10597. record_time := c.GetString("record_time")
  10598. his_patient_id, _ := c.GetInt64("his_patient_id")
  10599. timeLayout := "2006-01-02"
  10600. loc, _ := time.LoadLocation("Local")
  10601. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10602. diagnosis_id := c.GetString("diagnosis")
  10603. sick_type, _ := c.GetInt64("sick_type")
  10604. reg_type, _ := c.GetInt64("p_type")
  10605. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10606. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10607. if err != nil {
  10608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10609. return
  10610. }
  10611. recordDateTime := theTime.Unix()
  10612. adminUser := c.GetAdminUserInfo()
  10613. var prescriptions []*models.HisPrescription
  10614. var start_time int64
  10615. var end_time int64
  10616. ids_str := c.GetString("ids")
  10617. ids_arr := strings.Split(ids_str, ",")
  10618. fmt.Println(reg_type)
  10619. if settle_accounts_type == 1 { //日结
  10620. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10621. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10622. } else {
  10623. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10624. }
  10625. fmt.Println(prescriptions)
  10626. } else { //月结
  10627. start_time_str := c.GetString("start_time")
  10628. end_time_str := c.GetString("end_time")
  10629. timeLayout := "2006-01-02"
  10630. loc, _ := time.LoadLocation("Local")
  10631. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10632. if err != nil {
  10633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10634. return
  10635. }
  10636. recordStartTime := theStartTime.Unix()
  10637. start_time = recordStartTime
  10638. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10639. if err != nil {
  10640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10641. return
  10642. }
  10643. recordEndTime := theEndTime.Unix()
  10644. end_time = recordEndTime
  10645. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10646. }
  10647. if reg_type == 1111 || reg_type == 1112 {
  10648. reg_type = 11
  10649. }
  10650. timestamp := time.Now().Unix()
  10651. tempTime := time.Unix(timestamp, 0)
  10652. timeFormat := tempTime.Format("20060102150405")
  10653. chrgBchno := rand.Intn(100000) + 10000
  10654. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10655. strconv.FormatInt(his.PatientId, 10)
  10656. var ids []int64
  10657. for _, item := range prescriptions {
  10658. ids = append(ids, item.ID)
  10659. }
  10660. fmt.Println(ids)
  10661. var total float64
  10662. for _, item := range prescriptions {
  10663. fmt.Println(item)
  10664. if item.Type == 1 { //药品
  10665. for _, subItem := range item.HisDoctorAdviceInfo {
  10666. total = total + (subItem.Price * subItem.PrescribingNumber)
  10667. }
  10668. }
  10669. if item.Type == 2 { //项目
  10670. for _, subItem := range item.HisPrescriptionProject {
  10671. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10672. total = total + (subItem.Price * cnt)
  10673. }
  10674. }
  10675. for _, subItem := range item.HisAdditionalCharge {
  10676. total = total + (subItem.Price * float64(subItem.Count))
  10677. }
  10678. }
  10679. allTotal := fmt.Sprintf("%.2f", total)
  10680. totals, _ := strconv.ParseFloat(allTotal, 64)
  10681. order := &models.HisOrder{
  10682. UserOrgId: adminUser.CurrentOrgId,
  10683. HisPatientId: his.ID,
  10684. PatientId: id,
  10685. SettleAccountsDate: recordDateTime,
  10686. Ctime: time.Now().Unix(),
  10687. Mtime: time.Now().Unix(),
  10688. Status: 1,
  10689. OrderStatus: 1,
  10690. MdtrtId: his.Number,
  10691. Number: chrg_bchno,
  10692. MedfeeSumamt: totals,
  10693. SettleEndTime: end_time,
  10694. SettleStartTime: start_time,
  10695. SettleType: settle_accounts_type,
  10696. PsnPartAmt: totals,
  10697. PsnCashPay: totals,
  10698. PType: 2,
  10699. IsPre: 1,
  10700. MedType: strconv.Itoa(int(reg_type)),
  10701. Diagnosis: diagnosis_id,
  10702. }
  10703. err = service.CreateOrder(order)
  10704. if err != nil {
  10705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10706. return
  10707. }
  10708. var customs []*Custom
  10709. for _, item := range prescriptions {
  10710. fmt.Println(item.Type)
  10711. if item.Type == 1 { //药品
  10712. for _, subItem := range item.HisDoctorAdviceInfo {
  10713. cus := &Custom{
  10714. AdviceId: subItem.ID,
  10715. ProjectId: 0,
  10716. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10717. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10718. FeedetlSn: subItem.FeedetlSn,
  10719. Price: fmt.Sprintf("%.2f", subItem.Price),
  10720. MedListCodg: subItem.MedListCodg,
  10721. Type: 1,
  10722. }
  10723. customs = append(customs, cus)
  10724. }
  10725. }
  10726. if item.Type == 2 { //项目
  10727. for _, subItem := range item.HisPrescriptionProject {
  10728. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10729. cus := &Custom{
  10730. AdviceId: 0,
  10731. ProjectId: subItem.ID,
  10732. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10733. Cut: fmt.Sprintf("%.2f", cnt),
  10734. FeedetlSn: subItem.FeedetlSn,
  10735. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10736. MedListCodg: subItem.MedListCodg,
  10737. Type: 2,
  10738. }
  10739. customs = append(customs, cus)
  10740. }
  10741. }
  10742. for _, item := range item.HisAdditionalCharge {
  10743. cus := &Custom{
  10744. ItemId: item.ID,
  10745. AdviceId: 0,
  10746. ProjectId: 0,
  10747. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10748. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10749. FeedetlSn: item.FeedetlSn,
  10750. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10751. MedListCodg: item.XtHisAddtionConfig.Code,
  10752. Type: 3,
  10753. }
  10754. customs = append(customs, cus)
  10755. }
  10756. }
  10757. fmt.Println(customs)
  10758. for _, item := range customs {
  10759. var advice_id int64 = 0
  10760. var project_id int64 = 0
  10761. var item_id int64 = 0
  10762. var types int64 = 0
  10763. if item.Type == 1 {
  10764. advice_id = item.AdviceId
  10765. project_id = 0
  10766. item_id = 0
  10767. } else if item.Type == 2 {
  10768. advice_id = 0
  10769. item_id = 0
  10770. project_id = item.ProjectId
  10771. } else if item.Type == 3 {
  10772. advice_id = 0
  10773. item_id = item.ItemId
  10774. project_id = 0
  10775. }
  10776. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10777. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10778. pric, _ := strconv.ParseFloat(item.Price, 32)
  10779. info := &models.HisOrderInfo{
  10780. OrderNumber: order.Number,
  10781. UploadDate: time.Now().Unix(),
  10782. AdviceId: advice_id,
  10783. DetItemFeeSumamt: detItemFeeSumamt,
  10784. Cnt: cut,
  10785. Pric: pric,
  10786. PatientId: id,
  10787. Status: 1,
  10788. Mtime: time.Now().Unix(),
  10789. Ctime: time.Now().Unix(),
  10790. UserOrgId: adminUser.CurrentOrgId,
  10791. HisPatientId: his.ID,
  10792. OrderId: order.ID,
  10793. ProjectId: project_id,
  10794. Type: types,
  10795. ItemId: item_id,
  10796. }
  10797. service.CreateOrderInfo(info)
  10798. }
  10799. his.SickType = sick_type
  10800. service.UpdataHisPateint(&his)
  10801. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10802. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10803. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10804. if err == nil {
  10805. c.ServeSuccessJSON(map[string]interface{}{
  10806. "msg": "结算成功",
  10807. })
  10808. }
  10809. }
  10810. type CustomOrderInfo struct {
  10811. Name string
  10812. Spec string
  10813. Unit string
  10814. Count float64
  10815. Price float64
  10816. Total float64
  10817. }
  10818. func (c *HisApiController) GetPrivateExpensesInfo() {
  10819. order_id, _ := c.GetInt64("id", 0)
  10820. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10821. order, _ := service.GetHisOrderByID(order_id)
  10822. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10823. if order.ID == 0 {
  10824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10825. return
  10826. }
  10827. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10828. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10829. org_id := c.GetAdminUserInfo().CurrentOrgId
  10830. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10831. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10832. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10833. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10834. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10835. //var orderInfos_four []*models.HisOrderInfoTwo
  10836. //for _, item := range orderInfos_three {
  10837. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10838. // item.HisPrescriptionProject.IsCheckTeam = 1
  10839. // orderInfos_four = append(orderInfos_four, item)
  10840. //
  10841. // }
  10842. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10843. // item.HisPrescriptionProject.IsCheckTeam = 2
  10844. // orderInfos_two = append(orderInfos_two, item)
  10845. // }
  10846. //}
  10847. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10848. //var cus_slice []CustomOrderInfo
  10849. //for _, item := range new_order_info {
  10850. // var cus CustomOrderInfo
  10851. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10852. // cus.Unit = ""
  10853. // cus.Spec = ""
  10854. // var total float64
  10855. // for _, subItem := range orderInfos_four {
  10856. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10857. // total = total + subItem.DetItemFeeSumamt
  10858. // fmt.Println(subItem.DetItemFeeSumamt)
  10859. // }
  10860. // }
  10861. // cus.Count = 1
  10862. // cus.Total = total
  10863. // cus_slice = append(cus_slice, cus)
  10864. //}
  10865. orderInfos = append(orderInfos, orderInfos_two...)
  10866. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10867. //orderInfos = append(orderInfos, orderInfos_three...)
  10868. //}/**/
  10869. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10870. c.ServeSuccessJSON(map[string]interface{}{
  10871. "order": order,
  10872. "order_info": orderInfos,
  10873. "patient": patient,
  10874. "admin_info": adminInfo,
  10875. "his": his,
  10876. "current_admin": role,
  10877. "org_config": miConfig,
  10878. //"new_order_info": cus_slice,
  10879. })
  10880. }
  10881. func (this *HisApiController) ChangeMedType() {
  10882. med_type := this.GetString("med_type")
  10883. old_med_type := this.GetString("old_med_type")
  10884. ids := this.GetString("ids")
  10885. settle_type, _ := this.GetInt64("settle_type")
  10886. start_time := this.GetString("start_time")
  10887. end_time := this.GetString("end_time")
  10888. ids_arr := strings.Split(ids, ",")
  10889. if settle_type == 1 { //日结
  10890. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10891. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10892. prescription.MedType = med_type
  10893. err := service.SaveHisPrescriptionTwo(&prescription)
  10894. if err == nil {
  10895. this.ServeSuccessJSON(map[string]interface{}{
  10896. "msg": "修改成功",
  10897. })
  10898. } else {
  10899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10900. return
  10901. }
  10902. } else if settle_type == 2 {
  10903. timeLayout := "2006-01-02"
  10904. loc, _ := time.LoadLocation("Local")
  10905. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10906. if err != nil {
  10907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10908. return
  10909. }
  10910. recordStartTime := theStartTime.Unix()
  10911. start_time_timestamp := recordStartTime
  10912. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10913. if err != nil {
  10914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10915. return
  10916. }
  10917. recordEndTime := theEndTime.Unix()
  10918. end_time_timestamp := recordEndTime
  10919. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10920. if updateErr == nil {
  10921. this.ServeSuccessJSON(map[string]interface{}{
  10922. "msg": "修改成功",
  10923. })
  10924. } else {
  10925. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10926. return
  10927. }
  10928. }
  10929. }
  10930. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10931. patient_id, _ := c.GetInt64("patient_id")
  10932. his_patient_id, _ := c.GetInt64("his_patient_id")
  10933. record_date := c.GetString("record_date")
  10934. start_time := c.GetString("start_time")
  10935. end_time := c.GetString("end_time")
  10936. order_status, _ := c.GetInt64("type", 0)
  10937. p_type, _ := c.GetInt64("p_type", 0)
  10938. order_id, _ := c.GetInt64("order_id", 0)
  10939. timeLayout := "2006-01-02"
  10940. loc, _ := time.LoadLocation("Local")
  10941. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10942. if err != nil {
  10943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10944. return
  10945. }
  10946. recordDateTime := theTime.Unix()
  10947. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10948. if err != nil {
  10949. }
  10950. startRecordDateTime := startTime.Unix()
  10951. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10952. if err != nil {
  10953. }
  10954. endRecordDateTime := endTime.Unix()
  10955. admin := c.GetAdminUserInfo()
  10956. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10957. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10958. order, _ := service.GetHisOrderByID(order_id)
  10959. var monthPrescriptions []*models.HisPrescription
  10960. if order_status == 1 || order_status == 0 {
  10961. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10962. } else if order_status == 2 {
  10963. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10964. }
  10965. var settle_total float64
  10966. for _, item := range monthPrescriptions {
  10967. if len(item.HisPrescriptionProject) > 0 {
  10968. for _, subItem := range item.HisPrescriptionProject {
  10969. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10970. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10971. settle_total = settle_total + total
  10972. }
  10973. }
  10974. if len(item.HisDoctorAdviceInfo) > 0 {
  10975. for _, subItem := range item.HisDoctorAdviceInfo {
  10976. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10977. settle_total = settle_total + total
  10978. }
  10979. }
  10980. }
  10981. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10982. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10983. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10984. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10985. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10986. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10987. //获取所有科室信息
  10988. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10989. var dia string
  10990. for _, item := range month_p_info {
  10991. if len(dia) == 0 {
  10992. dia = item.Diagnosis
  10993. } else {
  10994. dia = dia + "," + item.Diagnosis
  10995. }
  10996. }
  10997. dia_arr := removeDuplicates(strings.Split(dia, ","))
  10998. dia_arr = removeEmptyStrings(dia_arr)
  10999. c.ServeSuccessJSON(map[string]interface{}{
  11000. "his_info": his_patient_info,
  11001. "xt_info": xt_patient_info,
  11002. "case_history": case_history,
  11003. "info": patientPrescriptionInfo,
  11004. "last_info": lastPatientPrescriptionInfo,
  11005. "month_prescriptions": monthPrescriptions,
  11006. "order": order,
  11007. "doctors": doctors,
  11008. "department": department,
  11009. "settle_total": settle_total,
  11010. "dia_arr": dia_arr,
  11011. })
  11012. return
  11013. }
  11014. func removeEmptyStrings(input []string) []string {
  11015. var output []string
  11016. for _, s := range input {
  11017. if s != "" {
  11018. output = append(output, s)
  11019. }
  11020. }
  11021. return output
  11022. }
  11023. func removeDuplicates(input []string) []string {
  11024. seen := make(map[string]bool)
  11025. output := []string{}
  11026. for _, s := range input {
  11027. if _, exists := seen[s]; !exists {
  11028. seen[s] = true
  11029. output = append(output, s)
  11030. }
  11031. }
  11032. return output
  11033. }
  11034. func (c *HisApiController) GetHisMonthPatientInfo() {
  11035. patient_id, _ := c.GetInt64("patient_id")
  11036. his_patient_id, _ := c.GetInt64("his_patient_id")
  11037. record_date := c.GetString("record_date")
  11038. number := c.GetString("number")
  11039. start_time := c.GetString("start_time")
  11040. end_time := c.GetString("end_time")
  11041. p_type, _ := c.GetInt64("p_type")
  11042. timeLayout := "2006-01-02"
  11043. loc, _ := time.LoadLocation("Local")
  11044. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11045. if err != nil {
  11046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11047. return
  11048. }
  11049. recordDateTime := theTime.Unix()
  11050. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11051. if err != nil {
  11052. }
  11053. startRecordDateTime := startTime.Unix()
  11054. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11055. if err != nil {
  11056. }
  11057. endRecordDateTime := endTime.Unix()
  11058. admin := c.GetAdminUserInfo()
  11059. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11060. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11061. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11062. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11063. var settle_total float64
  11064. for _, item := range monthPrescriptions {
  11065. if len(item.HisPrescriptionProject) > 0 {
  11066. for _, subItem := range item.HisPrescriptionProject {
  11067. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11068. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11069. settle_total = settle_total + total
  11070. }
  11071. }
  11072. if len(item.HisDoctorAdviceInfo) > 0 {
  11073. for _, subItem := range item.HisDoctorAdviceInfo {
  11074. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11075. settle_total = settle_total + total
  11076. }
  11077. }
  11078. }
  11079. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11080. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11081. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11082. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11083. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11084. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11085. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11086. //获取所有科室信息
  11087. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11088. c.ServeSuccessJSON(map[string]interface{}{
  11089. "his_info": his_patient_info,
  11090. "xt_info": xt_patient_info,
  11091. "case_history": case_history,
  11092. "info": patientPrescriptionInfo,
  11093. "month_prescriptions": monthPrescriptions,
  11094. "order": order,
  11095. "doctors": doctors,
  11096. "department": department,
  11097. "count": count,
  11098. "drugStockConfig": drugStockConfig,
  11099. "last_info": lastPatientPrescriptionInfo,
  11100. "settle_total": settle_total,
  11101. })
  11102. return
  11103. }
  11104. func (c *HisApiController) GetAllOrder() {
  11105. org_id := c.GetAdminUserInfo().CurrentOrgId
  11106. orders, _ := service.GetNewHisOrderList(org_id)
  11107. c.ServeSuccessJSON(map[string]interface{}{
  11108. "order": orders,
  11109. })
  11110. return
  11111. }
  11112. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11113. newArr = make([]*models.HisOrderInfoTwo, 0)
  11114. for i := 0; i < len(arr); i++ {
  11115. repeat := false
  11116. for j := i + 1; j < len(arr); j++ {
  11117. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11118. repeat = true
  11119. break
  11120. }
  11121. }
  11122. if !repeat {
  11123. newArr = append(newArr, arr[i])
  11124. }
  11125. }
  11126. return
  11127. }
  11128. // 修改处方退库操作 参数传修改之前的处方数据
  11129. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11130. if advice.ExecutionState == 1 {
  11131. //查询该病人该药品是否有库存记录
  11132. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11133. if errcode == gorm.ErrRecordNotFound {
  11134. } else {
  11135. //退库
  11136. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11137. if advice.PrescribingNumberUnit == drug.MinUnit {
  11138. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11139. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11140. //退库
  11141. warehouseInfo := models.DrugWarehouseInfo{
  11142. StockMinNumber: prescribingNumber,
  11143. }
  11144. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11145. operation_time := time.Now().Unix()
  11146. creater := advice.AdviceDoctor
  11147. ctime := time.Now().Unix()
  11148. timeStr := time.Now().Format("2006-01-02")
  11149. timeArr := strings.Split(timeStr, "-")
  11150. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11151. total = total + 1
  11152. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11153. cancelStock := models.DrugCancelStock{
  11154. OrderNumber: orderNumber,
  11155. OperaTime: operation_time,
  11156. OrgId: advice.UserOrgId,
  11157. Creater: creater,
  11158. Ctime: ctime,
  11159. Status: 1,
  11160. ReturnTime: advice.AdviceDate,
  11161. Dealer: info.Dealer,
  11162. Manufacturer: info.Manufacturer,
  11163. Type: 1,
  11164. }
  11165. service.AddSigleDrugCancelStock(&cancelStock)
  11166. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11167. dealer, _ := service.GetDealerById(info.Dealer)
  11168. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11169. cancelStockInfo := models.DrugCancelStockInfo{
  11170. OrderNumber: cancelInfo.OrderNumber,
  11171. CancelStockId: cancelInfo.ID,
  11172. DrugId: info.DrugId,
  11173. Count: info.Count,
  11174. Status: 1,
  11175. Ctime: ctime,
  11176. OrgId: advice.UserOrgId,
  11177. Type: 1,
  11178. Manufacturer: manufactureName.ManufacturerName,
  11179. Dealer: dealer.DealerName,
  11180. Total: 0,
  11181. RetailPrice: info.RetailPrice,
  11182. RetailTotalPrice: info.RetailTotalPrice,
  11183. Price: info.Price,
  11184. RegisterAccount: "",
  11185. Remark: info.Remark,
  11186. BatchNumber: info.BatchNumber,
  11187. MaxUnit: info.CountUnit,
  11188. ProductDate: info.ProductDate,
  11189. ExpiryDate: info.ExpiryDate,
  11190. BatchNumberId: info.WarehouseInfoId,
  11191. }
  11192. flow := models.DrugFlow{
  11193. WarehousingId: 0,
  11194. DrugId: info.DrugId,
  11195. Number: "",
  11196. BatchNumber: info.BatchNumber,
  11197. Count: info.Count,
  11198. UserOrgId: advice.UserOrgId,
  11199. PatientId: 0,
  11200. SystemTime: ctime,
  11201. ConsumableType: 4,
  11202. IsSys: 0,
  11203. WarehousingOrder: "",
  11204. WarehouseOutId: 0,
  11205. WarehouseOutOrderNumber: "",
  11206. IsEdit: 0,
  11207. CancelStockId: cancelStock.ID,
  11208. CancelOrderNumber: cancelStock.OrderNumber,
  11209. Manufacturer: info.Manufacturer,
  11210. Dealer: info.Dealer,
  11211. Creator: advice.UserOrgId,
  11212. UpdateCreator: 0,
  11213. Status: 1,
  11214. Ctime: time.Now().Unix(),
  11215. Mtime: 0,
  11216. Price: info.Price,
  11217. WarehousingDetailId: 0,
  11218. WarehouseOutDetailId: 0,
  11219. CancelOutDetailId: 0,
  11220. ExpireDate: info.ExpiryDate,
  11221. ProductDate: info.ProductDate,
  11222. MaxUnit: info.CountUnit,
  11223. MinUnit: "",
  11224. }
  11225. service.CreatedCancelStock(cancelStockInfo)
  11226. service.CreateDrugFlowOne(flow)
  11227. } else {
  11228. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11229. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11230. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11231. warehouseInfo := models.DrugWarehouseInfo{
  11232. StockMinNumber: prescribingNumber,
  11233. }
  11234. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11235. }
  11236. operation_time := time.Now().Unix()
  11237. creater := advice.AdviceDoctor
  11238. ctime := time.Now().Unix()
  11239. timeStr := time.Now().Format("2006-01-02")
  11240. timeArr := strings.Split(timeStr, "-")
  11241. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11242. total = total + 1
  11243. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11244. cancelStock := models.DrugCancelStock{
  11245. OrderNumber: orderNumber,
  11246. OperaTime: operation_time,
  11247. OrgId: advice.UserOrgId,
  11248. Creater: creater,
  11249. Ctime: ctime,
  11250. Status: 1,
  11251. ReturnTime: advice.AdviceDate,
  11252. Dealer: info.Dealer,
  11253. Manufacturer: info.Manufacturer,
  11254. Type: 1,
  11255. }
  11256. service.AddSigleDrugCancelStock(&cancelStock)
  11257. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11258. dealer, _ := service.GetDealerById(info.Dealer)
  11259. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11260. cancelStockInfo := models.DrugCancelStockInfo{
  11261. OrderNumber: cancelInfo.OrderNumber,
  11262. CancelStockId: cancelInfo.ID,
  11263. DrugId: info.DrugId,
  11264. Count: info.Count,
  11265. Status: 1,
  11266. Ctime: ctime,
  11267. OrgId: advice.UserOrgId,
  11268. Type: 1,
  11269. Manufacturer: manufactureName.ManufacturerName,
  11270. Dealer: dealer.DealerName,
  11271. Total: 0,
  11272. RetailPrice: info.RetailPrice,
  11273. RetailTotalPrice: info.RetailTotalPrice,
  11274. Price: info.Price,
  11275. RegisterAccount: "",
  11276. Remark: info.Remark,
  11277. BatchNumber: info.BatchNumber,
  11278. MaxUnit: info.CountUnit,
  11279. ProductDate: info.ProductDate,
  11280. ExpiryDate: info.ExpiryDate,
  11281. BatchNumberId: info.WarehouseInfoId,
  11282. }
  11283. flow := models.DrugFlow{
  11284. WarehousingId: 0,
  11285. DrugId: info.DrugId,
  11286. Number: "",
  11287. BatchNumber: info.BatchNumber,
  11288. Count: info.Count,
  11289. UserOrgId: advice.UserOrgId,
  11290. PatientId: 0,
  11291. SystemTime: ctime,
  11292. ConsumableType: 4,
  11293. IsSys: 0,
  11294. WarehousingOrder: "",
  11295. WarehouseOutId: 0,
  11296. WarehouseOutOrderNumber: "",
  11297. IsEdit: 0,
  11298. CancelStockId: cancelStock.ID,
  11299. CancelOrderNumber: cancelStock.OrderNumber,
  11300. Manufacturer: info.Manufacturer,
  11301. Dealer: info.Dealer,
  11302. Creator: advice.AdviceDoctor,
  11303. UpdateCreator: 0,
  11304. Status: 1,
  11305. Ctime: time.Now().Unix(),
  11306. Mtime: 0,
  11307. Price: info.Price,
  11308. WarehousingDetailId: 0,
  11309. WarehouseOutDetailId: 0,
  11310. CancelOutDetailId: 0,
  11311. ExpireDate: info.ExpiryDate,
  11312. ProductDate: info.ProductDate,
  11313. MaxUnit: info.CountUnit,
  11314. MinUnit: "",
  11315. }
  11316. service.CreatedCancelStock(cancelStockInfo)
  11317. service.CreateDrugFlowOne(flow)
  11318. }
  11319. }
  11320. }
  11321. return err
  11322. }
  11323. func (this *HisApiController) DeleteNCDS() {
  11324. id, _ := this.GetInt64("id", 0)
  11325. if id > 0 {
  11326. service.DeletePsnNCDSRecordById(id)
  11327. this.ServeSuccessJSON(map[string]interface{}{
  11328. "msg": "删除成功",
  11329. })
  11330. } else {
  11331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11332. return
  11333. }
  11334. }
  11335. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11336. id, _ := c.GetInt64("id")
  11337. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11338. c.ServeSuccessJSON(map[string]interface{}{
  11339. "advice": advice,
  11340. })
  11341. return
  11342. }
  11343. func (c *HisApiController) GetHisMonthChargePatientList() {
  11344. record_date := c.GetString("record_date")
  11345. start_time := c.GetString("start_time")
  11346. end_time := c.GetString("end_time")
  11347. timeLayout := "2006-01-02"
  11348. loc, _ := time.LoadLocation("Local")
  11349. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11350. if err != nil {
  11351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11352. return
  11353. }
  11354. if err != nil {
  11355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11356. return
  11357. }
  11358. recordDateTime := theTime.Unix()
  11359. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11360. if err != nil {
  11361. }
  11362. startRecordDateTime := startTime.Unix()
  11363. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11364. if err != nil {
  11365. }
  11366. endRecordDateTime := endTime.Unix()
  11367. adminInfo := c.GetAdminUserInfo()
  11368. var tempMonthChargePatients []*service.MonthChargePatients
  11369. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11370. for _, item := range tempPatients {
  11371. //过滤没有处方的
  11372. if len(item.HisPrescription) == 0 {
  11373. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11374. }
  11375. }
  11376. c.ServeSuccessJSON(map[string]interface{}{
  11377. "list": tempMonthChargePatients,
  11378. })
  11379. }
  11380. // PrescriptionDifference 医嘱数量差值结构体
  11381. type PrescriptionDrugDifference struct {
  11382. DrugID int64 //基础库药品id
  11383. ID int64 //医嘱id
  11384. Difference float64 //差值
  11385. Unit string //单位
  11386. }
  11387. type PrescriptionGoodDifference struct {
  11388. GoodID int64 //基础库项目耗材id
  11389. ID int64 //医嘱id
  11390. Difference int64 //差值
  11391. Unit string //单位
  11392. Type int64 //类型
  11393. }
  11394. type EditCustomData struct {
  11395. adviceList []*models.HisDoctorAdviceInfo
  11396. projectList []*models.HisPrescriptionProject
  11397. }
  11398. type SrcCustomData struct {
  11399. adviceList []*models.HisDoctorAdviceInfo
  11400. projectList []*models.HisPrescriptionProject
  11401. }
  11402. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11403. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11404. differences := make([]*PrescriptionDrugDifference, 0)
  11405. // 创建一个 map 来存储第一个切片中的药品信息
  11406. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11407. for _, advice := range firstPrescription {
  11408. firstMap[advice.DrugId] = advice
  11409. }
  11410. // 遍历第二个切片中的药品信息,并比较数量差值
  11411. for _, advice := range secondPrescription {
  11412. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11413. diff := &PrescriptionDrugDifference{
  11414. DrugID: advice.DrugId,
  11415. ID: firstAdvice.ID,
  11416. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11417. Unit: firstAdvice.PrescribingNumberUnit,
  11418. }
  11419. differences = append(differences, diff)
  11420. }
  11421. }
  11422. return differences
  11423. }
  11424. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11425. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11426. differences := make([]*PrescriptionGoodDifference, 0)
  11427. // 创建一个 map 来存储第一个切片中的耗材信息
  11428. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11429. for _, good := range firstPrescription {
  11430. firstMap[good.ProjectId] = good
  11431. }
  11432. // 遍历第二个切片中的耗材信息,并比较数量差值
  11433. for _, good := range secondPrescription {
  11434. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11435. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11436. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11437. diff := &PrescriptionGoodDifference{
  11438. GoodID: good.ProjectId,
  11439. ID: firstGood.ID,
  11440. Difference: count - firstCount,
  11441. Unit: firstGood.Unit,
  11442. Type: firstGood.Type,
  11443. }
  11444. differences = append(differences, diff)
  11445. }
  11446. }
  11447. return differences
  11448. }
  11449. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11450. var adviceList []*models.HisDoctorAdviceInfo
  11451. var projectList []*models.HisPrescriptionProject
  11452. var advice_ids []int64
  11453. var project_ids []int64
  11454. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11455. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11456. //var tempPrescription *models.HisPrescriptionProjectscription
  11457. if len(prescriptions) > 0 {
  11458. for _, item := range prescriptions {
  11459. items := item.(map[string]interface{})
  11460. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11461. advices := items["advices"].([]interface{})
  11462. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11463. groupNo := int64(0)
  11464. ctime := time.Now().Unix()
  11465. mtime := ctime
  11466. if len(advices) > 0 {
  11467. for _, advice := range advices {
  11468. var s models.HisDoctorAdviceInfo
  11469. s.AdviceType = 2
  11470. s.StopState = 2
  11471. s.ExecutionState = 2
  11472. s.Status = 1
  11473. s.Groupno = groupNo
  11474. s.CreatedTime = ctime
  11475. s.UpdatedTime = mtime
  11476. s.IsSettle = 2
  11477. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11478. //存储切片中
  11479. if s.ID > 0 {
  11480. advice_ids = append(advice_ids, s.ID)
  11481. adviceList = append(adviceList, &s)
  11482. }
  11483. }
  11484. }
  11485. }
  11486. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11487. projects := items["project"].([]interface{})
  11488. if len(projects) > 0 {
  11489. for _, project := range projects {
  11490. var p models.HisPrescriptionProject
  11491. p.Ctime = time.Now().Unix()
  11492. p.Mtime = time.Now().Unix()
  11493. p.Status = 1
  11494. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11495. if p.ID > 0 {
  11496. project_ids = append(project_ids, p.ID)
  11497. projectList = append(projectList, &p)
  11498. }
  11499. }
  11500. }
  11501. }
  11502. }
  11503. }
  11504. }
  11505. editCustomData.projectList = projectList
  11506. editCustomData.adviceList = adviceList
  11507. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11508. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11509. srcCustomData.adviceList = list
  11510. srcCustomData.projectList = list2
  11511. return
  11512. }