his_api_controller.go 429KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. }
  87. func (c *HisApiController) ChangeOrderDesc() {
  88. id, _ := c.GetInt64("id")
  89. desc := c.GetString("desc")
  90. change_type := c.GetString("change_type")
  91. order, _ := service.GetHisOrderByID(id)
  92. if order.ID == 0 {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. switch change_type {
  97. case "oth_desc":
  98. order.OthDesc = desc
  99. break
  100. case "cash_pay":
  101. order.CashPay = desc
  102. break
  103. case "jifen_pay":
  104. order.JifenPay = desc
  105. break
  106. case "band_card_pay":
  107. order.BandCardPay = desc
  108. break
  109. case "ali_pay":
  110. order.AliPay = desc
  111. break
  112. case "wechat_pay":
  113. order.WechatPay = desc
  114. break
  115. }
  116. err := service.SaveHisOrder(&order)
  117. if err == nil {
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "msg": "修改成功",
  120. })
  121. return
  122. } else {
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  124. return
  125. }
  126. }
  127. func (c *HisApiController) GetMonthHisPatient() {
  128. record_date := c.GetString("record_date")
  129. //order_status, _ := c.GetInt64("type")
  130. timeLayout := "2006-01-02"
  131. loc, _ := time.LoadLocation("Local")
  132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. recordDateTime := theTime.Unix()
  138. adminInfo := c.GetAdminUserInfo()
  139. var tempPatients []service.NewTempPatients
  140. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  141. // 获取当前时间
  142. now := time.Now()
  143. // 获取本月的第一天
  144. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  145. // 获取下个月的第一天
  146. nextMonth := firstDay.AddDate(0, 1, 0)
  147. // 获取本月的最后一天
  148. lastDay := nextMonth.Add(-time.Nanosecond)
  149. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  150. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  151. var patients []service.NewTempPatients
  152. var patients_two []service.NewTempPatients
  153. for _, item := range tempPatients {
  154. //过滤掉没挂号的和没开处方的
  155. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  156. patients = append(patients, item)
  157. }
  158. ////过滤掉没挂号的
  159. //if len(item.HisPatient) > 0 {
  160. // patients_two = append(patients_two, item)
  161. //}
  162. }
  163. c.ServeSuccessJSON(map[string]interface{}{
  164. "list": patients,
  165. "list_two": patients_two,
  166. "chargePatients": chargePatients,
  167. })
  168. }
  169. func (c *HisApiController) GetBatchSettleAccounts() {
  170. order_ids := c.GetString("order_ids")
  171. admin_user_id, _ := c.GetInt64("admin_user_id")
  172. adminUser := c.GetAdminUserInfo()
  173. orders := strings.Split(order_ids, ",")
  174. var newOrders []models.Orders
  175. for _, item := range orders {
  176. order, _ := service.GetHisOrderByIDTenOne(item)
  177. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  178. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  179. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  180. orderInfos = append(orderInfos, orderInfos_two...)
  181. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  182. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  183. var diagnosis_ids []string
  184. if his.ID > 0 {
  185. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  186. } else {
  187. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  188. }
  189. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  190. var dia_config []*models.HisXtDiagnoseConfig
  191. var name string
  192. for _, item := range diagnosis_ids {
  193. id, _ := strconv.ParseInt(item, 10, 64)
  194. diagnosisConfig, _ := service.FindDiagnoseById(id)
  195. dia_config = append(dia_config, diagnosisConfig)
  196. if len(name) == 0 {
  197. name = diagnosisConfig.ClassName
  198. } else {
  199. name = name + "," + diagnosisConfig.ClassName
  200. }
  201. }
  202. var bedCostTotal float64 = 0 //床位总费
  203. var bedCostSelfTotal float64 = 0 //床位自费
  204. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  205. var bedSelfTotal float64 = 0 //床位部分项目自费
  206. var bedInscpTotal float64 = 0 //床位部分项目自费
  207. var operationCostTotal float64 = 0 //手术费
  208. var operationCostSelfTotal float64 = 0 //手术费
  209. var operationCostPartSelfTotal float64 = 0 //手术费
  210. var operationSelfTotal float64 = 0 //床位部分项目自费
  211. var operationInscpTotal float64 = 0 //床位部分项目自费
  212. var otherCostTotal float64 = 0 //其他费用
  213. var otherCostSelfTotal float64 = 0 //其他费用
  214. var otherCostPartSelfTotal float64 = 0 //其他费用
  215. var otherSelfTotal float64 = 0 //床位部分项目自费
  216. var otherInscpTotal float64 = 0 //床位部分项目自费
  217. var materialCostTotal float64 = 0 //材料费
  218. var materialCostSelfTotal float64 = 0 //材料费
  219. var materialCostPartSelfTotal float64 = 0 //材料费
  220. var materialSelfTotal float64 = 0 //床位部分项目自费
  221. var materialInscpTotal float64 = 0 //床位部分项目自费
  222. var westernMedicineCostTotal float64 = 0 //西药费
  223. var westernMedicineCostSelfTotal float64 = 0 //西药费
  224. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  225. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  226. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  227. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  228. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  229. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  230. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  231. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  232. var checkCostTotal float64 = 0 //检查费
  233. var checkCostSelfTotal float64 = 0 //检查费
  234. var checkCostPartSelfTotal float64 = 0 //检查费
  235. var checkSelfTotal float64 = 0 //床位部分项目自费
  236. var checkInscpTotal float64 = 0 //床位部分项目自费
  237. var laboratoryCostTotal float64 = 0 //化验费
  238. var laboratoryCostSelfTotal float64 = 0 //化验费
  239. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  240. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  241. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  242. var treatCostTotal float64 = 0 //治疗费用
  243. var treatCostSelfTotal float64 = 0 //治疗费用
  244. var treatCostPartSelfTotal float64 = 0 //治疗费用
  245. var treatSelfTotal float64 = 0 //床位部分项目自费
  246. var treatInscpTotal float64 = 0 //床位部分项目自费
  247. decimal.DivisionPrecision = 2
  248. for _, item := range orderInfos {
  249. if item.MedChrgitmType == "01" { //床位费
  250. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  251. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  253. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  254. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  255. }
  256. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  257. if item.MedChrgitmType == "03" { //检查费
  258. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  259. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  260. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  261. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  262. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  263. }
  264. } else {
  265. if item.MedChrgitmType == "03" { //检查费
  266. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  267. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  268. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  269. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  270. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  271. }
  272. }
  273. if item.MedChrgitmType == "04" { //化验费
  274. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  275. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  276. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  277. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  278. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  279. }
  280. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  281. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. if item.MedChrgitmType == "06" { //手术费
  288. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  289. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  290. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  291. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  292. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  293. }
  294. if item.MedChrgitmType == "08" { //材料费
  295. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  296. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  298. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  299. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  300. }
  301. if item.MedChrgitmType == "09" { //西药费
  302. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  306. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  307. }
  308. if item.MedChrgitmType == "11" { //中成费
  309. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  310. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  311. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  312. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  313. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  316. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  320. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  321. }
  322. }
  323. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  324. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  325. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  326. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  327. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  328. var doctor_name string
  329. if roles.ID == 0 {
  330. doctor_name = "管理员"
  331. } else {
  332. doctor_name = roles.UserName
  333. }
  334. yiliao_leibie := ""
  335. switch order.MedType {
  336. case "11":
  337. yiliao_leibie = "普通门诊"
  338. break
  339. case "12":
  340. yiliao_leibie = "门诊挂号"
  341. break
  342. case "13":
  343. yiliao_leibie = "急诊"
  344. break
  345. case "14":
  346. yiliao_leibie = "门诊特殊病"
  347. break
  348. case "15":
  349. yiliao_leibie = "门诊统筹"
  350. break
  351. case "16":
  352. yiliao_leibie = "门诊慢性病"
  353. break
  354. case "21":
  355. yiliao_leibie = "普通住院"
  356. break
  357. }
  358. var newOrder models.Orders
  359. newOrder.Diagnosis = name
  360. newOrder.OrderInfos = orderInfos
  361. newOrder.Number = order.MdtrtId
  362. newOrder.Date = order.SettleAccountsDate
  363. newOrder.ChargeAdmin = charge_admin
  364. newOrder.PrintorAdmin = printor_admin
  365. newOrder.Order = order
  366. newOrder.BedCostTotal = bedCostTotal
  367. newOrder.BedCostSelfTotal = bedCostSelfTotal
  368. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  369. newOrder.BedSelfTotal = bedSelfTotal
  370. newOrder.BedInscpTotal = bedInscpTotal
  371. newOrder.OperationCostTotal = operationCostTotal
  372. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  373. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  374. newOrder.OperationSelfTotal = operationSelfTotal
  375. newOrder.OperationInscpTotal = operationInscpTotal
  376. newOrder.OtherCostTotal = otherCostTotal
  377. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  378. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  379. newOrder.OtherSelfTotal = otherSelfTotal
  380. newOrder.OtherInscpTotal = otherInscpTotal
  381. newOrder.MaterialCostTotal = materialCostTotal
  382. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  383. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  384. newOrder.MaterialSelfTotal = materialSelfTotal
  385. newOrder.MaterialInscpTotal = materialInscpTotal
  386. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  387. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  388. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  389. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  390. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  391. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  392. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  393. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  394. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  395. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  396. newOrder.CheckCostTotal = checkCostTotal
  397. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  398. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  399. newOrder.CheckSelfTotal = checkSelfTotal
  400. newOrder.CheckInscpTotal = checkInscpTotal
  401. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  402. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  403. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  404. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  405. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  406. newOrder.TreatCostTotal = treatCostTotal
  407. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  408. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  409. newOrder.TreatSelfTotal = treatSelfTotal
  410. newOrder.TreatInscpTotal = treatInscpTotal
  411. newOrder.DoctorInfo = doctor_info
  412. newOrder.DoctorName = doctor_name
  413. newOrder.HealthCardNo = order.PsnNo
  414. newOrder.YiliaoLeibie = yiliao_leibie
  415. newOrder.Patient = patient
  416. newOrder.OrgName = miConfig.OrgName
  417. newOrder.OrgCode = miConfig.Code
  418. newOrder.OrderNumber = order.Number
  419. newOrder.HisPatient = his
  420. newOrder.DiaConfig = dia_config
  421. newOrders = append(newOrders, newOrder)
  422. }
  423. c.ServeSuccessJSON(map[string]interface{}{
  424. "orders": newOrders,
  425. })
  426. }
  427. func (c *HisApiController) GetTestOrder() {
  428. order_id, _ := c.GetInt64("order_id")
  429. admin_user_id, _ := c.GetInt64("admin_user_id")
  430. adminUser := c.GetAdminUserInfo()
  431. order, _ := service.GetHisOrderByID(order_id)
  432. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  433. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  434. orderInfos = append(orderInfos, orderInfos_two...)
  435. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  436. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  437. var dia_config []*models.HisXtDiagnoseConfig
  438. var name string
  439. var bedCostTotal float64 = 0 //床位总费
  440. var bedCostSelfTotal float64 = 0 //床位自费
  441. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  442. var bedSelfTotal float64 = 0 //床位部分项目自费
  443. var bedInscpTotal float64 = 0 //床位部分项目自费
  444. var operationCostTotal float64 = 0 //手术费
  445. var operationCostSelfTotal float64 = 0 //手术费
  446. var operationCostPartSelfTotal float64 = 0 //手术费
  447. var operationSelfTotal float64 = 0 //床位部分项目自费
  448. var operationInscpTotal float64 = 0 //床位部分项目自费
  449. var otherCostTotal float64 = 0 //其他费用
  450. var otherCostSelfTotal float64 = 0 //其他费用
  451. var otherCostPartSelfTotal float64 = 0 //其他费用
  452. var otherSelfTotal float64 = 0 //床位部分项目自费
  453. var otherInscpTotal float64 = 0 //床位部分项目自费
  454. var materialCostTotal float64 = 0 //材料费
  455. var materialCostSelfTotal float64 = 0 //材料费
  456. var materialCostPartSelfTotal float64 = 0 //材料费
  457. var materialSelfTotal float64 = 0 //床位部分项目自费
  458. var materialInscpTotal float64 = 0 //床位部分项目自费
  459. var westernMedicineCostTotal float64 = 0 //西药费
  460. var westernMedicineCostSelfTotal float64 = 0 //西药费
  461. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  462. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  463. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  464. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  465. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  466. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  467. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  468. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  469. var checkCostTotal float64 = 0 //检查费
  470. var checkCostSelfTotal float64 = 0 //检查费
  471. var checkCostPartSelfTotal float64 = 0 //检查费
  472. var checkSelfTotal float64 = 0 //床位部分项目自费
  473. var checkInscpTotal float64 = 0 //床位部分项目自费
  474. var laboratoryCostTotal float64 = 0 //化验费
  475. var laboratoryCostSelfTotal float64 = 0 //化验费
  476. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  477. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  478. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  479. var treatCostTotal float64 = 0 //治疗费用
  480. var treatCostSelfTotal float64 = 0 //治疗费用
  481. var treatCostPartSelfTotal float64 = 0 //治疗费用
  482. var treatSelfTotal float64 = 0 //床位部分项目自费
  483. var treatInscpTotal float64 = 0 //床位部分项目自费
  484. decimal.DivisionPrecision = 2
  485. for _, item := range orderInfos {
  486. if item.MedChrgitmType == "01" { //床位费
  487. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  488. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  489. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  490. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  491. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  492. }
  493. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  494. if item.MedChrgitmType == "03" { //检查费
  495. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  496. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  497. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  498. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  499. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  500. }
  501. } else {
  502. if item.MedChrgitmType == "03" { //检查费
  503. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  504. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  505. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  506. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  507. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  508. }
  509. }
  510. if item.MedChrgitmType == "04" { //化验费
  511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  512. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  513. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  514. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  515. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  516. }
  517. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  518. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. if item.MedChrgitmType == "06" { //手术费
  525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  526. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  527. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  528. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  529. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  530. }
  531. if item.MedChrgitmType == "08" { //材料费
  532. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  533. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  534. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  535. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  536. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  537. }
  538. if item.MedChrgitmType == "09" { //西药费
  539. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  540. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  541. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  543. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  544. }
  545. if item.MedChrgitmType == "11" { //中成费
  546. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  550. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  551. }
  552. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  553. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  555. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  556. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  557. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  558. }
  559. }
  560. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  561. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  562. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  563. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  564. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  565. var doctor_name string
  566. if roles.ID == 0 {
  567. doctor_name = "管理员"
  568. } else {
  569. doctor_name = roles.UserName
  570. }
  571. yiliao_leibie := ""
  572. switch order.MedType {
  573. case "11":
  574. yiliao_leibie = "普通门诊"
  575. break
  576. case "12":
  577. yiliao_leibie = "门诊挂号"
  578. break
  579. case "13":
  580. yiliao_leibie = "急诊"
  581. break
  582. case "14":
  583. yiliao_leibie = "门诊特殊病"
  584. break
  585. case "15":
  586. yiliao_leibie = "门诊统筹"
  587. break
  588. case "16":
  589. yiliao_leibie = "门诊慢性病"
  590. break
  591. case "21":
  592. yiliao_leibie = "普通住院"
  593. break
  594. }
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "diagnosis": name,
  597. "order_infos": orderInfos,
  598. "number": order.MdtrtId,
  599. "date": order.SettleAccountsDate,
  600. "charge_admin": charge_admin,
  601. "printor_admin": printor_admin,
  602. "info": order,
  603. "order": order,
  604. "bedCostTotal": bedCostTotal,
  605. "bedCostSelfTotal": bedCostSelfTotal,
  606. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  607. "bedSelfTotal": bedSelfTotal,
  608. "bedInscpTotal": bedInscpTotal,
  609. "operationCostTotal": operationCostTotal,
  610. "operationCostSelfTotal": operationCostSelfTotal,
  611. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  612. "operationSelfTotal": operationSelfTotal,
  613. "operationInscpTotal": operationInscpTotal,
  614. "otherCostTotal": otherCostTotal,
  615. "otherCostSelfTotal": otherCostSelfTotal,
  616. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  617. "otherSelfTotal": otherSelfTotal,
  618. "otherInscpTotal": otherInscpTotal,
  619. "materialCostTotal": materialCostTotal,
  620. "materialCostSelfTotal": materialCostSelfTotal,
  621. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  622. "materialSelfTotal": materialSelfTotal,
  623. "materialInscpTotal": materialInscpTotal,
  624. "westernMedicineCostTotal": westernMedicineCostTotal,
  625. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  626. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  627. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  628. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  629. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  630. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  631. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  632. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  633. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  634. "checkCostTotal": checkCostTotal,
  635. "checkCostSelfTotal": checkCostSelfTotal,
  636. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  637. "checkSelfTotal": checkSelfTotal,
  638. "checkInscpTotal": checkInscpTotal,
  639. "laboratoryCostTotal": laboratoryCostTotal,
  640. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  641. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  642. "laboratorySelfTotal": laboratorySelfTotal,
  643. "laboratoryInscpTotal": laboratoryInscpTotal,
  644. "treatCostTotal": treatCostTotal,
  645. "treatCostSelfTotal": treatCostSelfTotal,
  646. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  647. "treatSelfTotal": treatSelfTotal,
  648. "treatInscpTotal": treatInscpTotal,
  649. "doctor_info": doctor_info,
  650. "doctor_name": doctor_name,
  651. "health_card_no": order.PsnNo,
  652. "yiliao_leibie": yiliao_leibie,
  653. "patient": patient,
  654. "org_name": miConfig.OrgName,
  655. "org_code": miConfig.Code,
  656. "order_number": order.Number,
  657. "his_hospital": his_hospital,
  658. "dia_config": dia_config,
  659. })
  660. }
  661. func (c *PublicApiController) GetBaiLinExportData() {
  662. data := service.GetBaiLinOrderData()
  663. fmt.Println(len(data))
  664. var new_data []*models.NewCustomHisOrder
  665. for _, item := range data {
  666. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  667. new_data = append(new_data, item)
  668. }
  669. }
  670. fmt.Println(len(new_data))
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "list": new_data,
  673. })
  674. }
  675. func (c *HisApiController) GetHisUnChargePatientList() {
  676. record_date := c.GetString("record_date")
  677. sch_type, _ := c.GetInt64("sch_type")
  678. timeLayout := "2006-01-02"
  679. loc, _ := time.LoadLocation("Local")
  680. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  681. if err != nil {
  682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  683. return
  684. }
  685. recordDateTime := theTime.Unix()
  686. adminInfo := c.GetAdminUserInfo()
  687. var tempPatients []*service.NewTempPatients
  688. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  689. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  690. var patients []*service.NewTempPatients
  691. var patients_two []*service.NewTempPatients
  692. for _, item := range tempPatients {
  693. //过滤掉没挂号的和没开处方的
  694. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  695. patients = append(patients, item)
  696. }
  697. //过滤掉没挂号的
  698. if len(item.HisPatient) > 0 {
  699. patients_two = append(patients_two, item)
  700. }
  701. }
  702. c.ServeSuccessJSON(map[string]interface{}{
  703. "list": patients,
  704. "list_two": patients_two,
  705. })
  706. }
  707. func (c *HisApiController) GetPrivateExpensesOrder() {
  708. //id, _ := c.GetInt64("id")
  709. //record_time := c.GetString("record_time")
  710. order_id, _ := c.GetInt64("order_id")
  711. admin_user_id, _ := c.GetInt64("admin_user_id")
  712. //timeLayout := "2006-01-02"
  713. //loc, _ := time.LoadLocation("Local")
  714. //
  715. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  716. //if err != nil {
  717. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  718. // return
  719. //}
  720. //recordDateTime := theTime.Unix()
  721. adminUser := c.GetAdminUserInfo()
  722. order, _ := service.GetHisOrderByID(order_id)
  723. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  724. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  725. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  726. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  727. //var config []*models.HisXtDiagnoseConfig
  728. var name string
  729. if order.PType == 1 {
  730. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  731. for _, item := range diagnosis_ids {
  732. id, _ := strconv.ParseInt(item, 10, 64)
  733. diagnosisConfig, _ := service.FindDiagnoseById(id)
  734. if len(name) == 0 {
  735. name = diagnosisConfig.ClassName
  736. } else {
  737. name = name + "," + diagnosisConfig.ClassName
  738. }
  739. }
  740. } else {
  741. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  742. for _, item := range diagnosis_ids {
  743. id, _ := strconv.ParseInt(item, 10, 64)
  744. diagnosisConfig, _ := service.FindDiagnoseById(id)
  745. if len(name) == 0 {
  746. name = diagnosisConfig.ClassName
  747. } else {
  748. name = name + "," + diagnosisConfig.ClassName
  749. }
  750. }
  751. }
  752. var bedCostTotal float64 = 0 //床位总费
  753. //var bedCostSelfTotal float64 = 0 //床位自费
  754. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  755. var operationCostTotal float64 = 0 //手术费
  756. //var operationCostSelfTotal float64 = 0 //手术费
  757. var operationCostPartSelfTotal float64 = 0 //手术费
  758. var otherCostTotal float64 = 0 //其他费用
  759. //var otherCostSelfTotal float64 = 0 //其他费用
  760. var otherCostPartSelfTotal float64 = 0 //其他费用
  761. var materialCostTotal float64 = 0 //材料费
  762. //var materialCostSelfTotal float64 = 0 //材料费
  763. var materialCostPartSelfTotal float64 = 0 //材料费
  764. var westernMedicineCostTotal float64 = 0 //西药费
  765. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  766. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  767. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  768. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  769. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  770. var checkCostTotal float64 = 0 //检查费
  771. //var checkCostSelfTotal float64 = 0 //检查费
  772. var checkCostPartSelfTotal float64 = 0 //检查费
  773. var laboratoryCostTotal float64 = 0 //化验费
  774. //var laboratoryCostSelfTotal float64 = 0 //化验费
  775. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  776. var treatCostTotal float64 = 0 //治疗费用
  777. //var treatCostSelfTotal float64 = 0 //治疗费用
  778. var treatCostPartSelfTotal float64 = 0 //治疗费用
  779. var zhenChaCostTotal float64 = 0 //其他费用
  780. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  781. decimal.DivisionPrecision = 2
  782. for _, item := range orderInfos {
  783. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  784. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  785. item.MedChrgitmType = "09"
  786. }
  787. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  788. if item.HisPrescriptionProject.Type == 2 {
  789. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  790. fmt.Println("CostClassify")
  791. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  792. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  793. case 0:
  794. item.MedChrgitmType = "0"
  795. break
  796. case 1:
  797. item.MedChrgitmType = "14"
  798. break
  799. case 2:
  800. item.MedChrgitmType = "05"
  801. break
  802. case 3:
  803. item.MedChrgitmType = "03"
  804. break
  805. case 4:
  806. item.MedChrgitmType = "03"
  807. break
  808. case 5:
  809. item.MedChrgitmType = "08"
  810. break
  811. case 6:
  812. item.MedChrgitmType = "14"
  813. break
  814. case 7:
  815. item.MedChrgitmType = "14"
  816. break
  817. case 8:
  818. item.MedChrgitmType = "03"
  819. break
  820. case 9:
  821. item.MedChrgitmType = "14"
  822. break
  823. case 10:
  824. item.MedChrgitmType = "14"
  825. break
  826. case 11:
  827. item.MedChrgitmType = "06"
  828. break
  829. case 12:
  830. item.MedChrgitmType = "12"
  831. break
  832. case 13:
  833. item.MedChrgitmType = "01"
  834. break
  835. case 14:
  836. item.MedChrgitmType = "04"
  837. break
  838. case 15:
  839. item.MedChrgitmType = "14"
  840. break
  841. }
  842. } else {
  843. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  844. case 1:
  845. item.MedChrgitmType = "14"
  846. break
  847. case 2:
  848. item.MedChrgitmType = "05"
  849. break
  850. case 3:
  851. item.MedChrgitmType = "04"
  852. break
  853. case 4:
  854. item.MedChrgitmType = "14"
  855. break
  856. case 5:
  857. item.MedChrgitmType = "08"
  858. break
  859. case 6:
  860. item.MedChrgitmType = "14"
  861. break
  862. case 7:
  863. item.MedChrgitmType = "14"
  864. break
  865. case 8:
  866. item.MedChrgitmType = "03"
  867. break
  868. case 9:
  869. item.MedChrgitmType = "14"
  870. break
  871. }
  872. }
  873. } else if item.HisPrescriptionProject.Type == 3 {
  874. item.MedChrgitmType = "08"
  875. }
  876. }
  877. }
  878. order.PsnCashPay = order.MedfeeSumamt
  879. for _, item := range orderInfos {
  880. if item.MedChrgitmType == "01" { //床位费
  881. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  882. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  883. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  884. }
  885. if item.MedChrgitmType == "02" { //诊察费
  886. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  887. //zhenChaCostSelfTotal = zhenChaCostTotal
  888. }
  889. if item.MedChrgitmType == "03" { //检查费
  890. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  891. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  892. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  893. }
  894. if item.MedChrgitmType == "02" { //检查费
  895. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  896. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  897. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  898. }
  899. if item.MedChrgitmType == "04" { //化验费
  900. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  901. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  902. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  903. }
  904. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  905. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  906. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  907. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  908. }
  909. if item.MedChrgitmType == "06" { //手术费
  910. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  911. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  912. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  913. }
  914. if item.MedChrgitmType == "08" { //材料费
  915. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  916. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  917. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  918. }
  919. if item.MedChrgitmType == "09" { //西药费
  920. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  921. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  922. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  923. }
  924. if item.MedChrgitmType == "11" { //中成费
  925. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  926. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  927. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  928. }
  929. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  930. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  931. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  932. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  933. }
  934. }
  935. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  936. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  937. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  938. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  939. c.ServeSuccessJSON(map[string]interface{}{
  940. "patient": patient,
  941. "order_infos": orderInfos,
  942. "diagnosis": name,
  943. "bedCostTotal": bedCostTotal,
  944. "bedCostSelfTotal": bedCostTotal,
  945. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  946. "operationCostTotal": operationCostTotal,
  947. "operationCostSelfTotal": operationCostTotal,
  948. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  949. "otherCostTotal": otherCostTotal,
  950. "otherCostSelfTotal": otherCostTotal,
  951. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  952. "materialCostTotal": materialCostTotal,
  953. "materialCostSelfTotal": materialCostTotal,
  954. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  955. "westernMedicineCostTotal": westernMedicineCostTotal,
  956. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  957. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  958. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  959. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  960. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  961. "checkCostTotal": checkCostTotal,
  962. "checkCostSelfTotal": checkCostTotal,
  963. "zhenChaCostTotal": zhenChaCostTotal,
  964. "zhenChaCostSelfTotal": zhenChaCostTotal,
  965. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  966. "laboratoryCostTotal": laboratoryCostTotal,
  967. "laboratoryCostSelfTotal": laboratoryCostTotal,
  968. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  969. "treatCostTotal": treatCostTotal,
  970. "treatCostSelfTotal": treatCostTotal,
  971. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  972. "charge_admin": charge_admin,
  973. "printor_admin": printor_admin,
  974. "org_name": org.OrgName,
  975. "org_code": miConfig.Code,
  976. "name": patient.Name,
  977. "number": order.MdtrtId,
  978. "date": order.SettleAccountsDate,
  979. "info": order,
  980. "his_hospital": his_hospital,
  981. "his": his,
  982. })
  983. }
  984. func (c *HisApiController) RefudDetail() {
  985. order_id, _ := c.GetInt64("order_id")
  986. order, _ := service.GetHisOrderByID(order_id)
  987. adminUser := c.GetAdminUserInfo()
  988. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  989. c.ServeSuccessJSON(map[string]interface{}{
  990. "msg": "撤销成功",
  991. })
  992. }
  993. func (c *HisApiController) Sscard() {
  994. //r := CardInit()
  995. //if r == 0 {
  996. // GetBaseInfo()
  997. //}
  998. //c.ServeSuccessJSON(map[string]interface{}{
  999. // "list": "11",
  1000. //})
  1001. }
  1002. func GetBaseInfo() error {
  1003. //handle := syscall.MustLoadDLL("SSCard.dll")
  1004. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1005. //
  1006. //str := make([]byte, 256)
  1007. //str1 := make([]byte, 256)
  1008. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1009. //if ferr != nil {
  1010. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1011. // return ferr
  1012. //}
  1013. //
  1014. //fmt.Println(string(str))
  1015. //
  1016. //fmt.Println(r)
  1017. return nil
  1018. }
  1019. func CardInit() int {
  1020. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1021. //add := DllTestDef.MustFindProc("Init")
  1022. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1023. //if err != nil {
  1024. // fmt.Println("SSCard的运算结果为:", ret)
  1025. //}
  1026. //result := int(ret)
  1027. return 0
  1028. }
  1029. func IntPtr(n int) uintptr {
  1030. return uintptr(n)
  1031. }
  1032. func StrPtr(s string) uintptr {
  1033. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1034. }
  1035. func (c *HisApiController) GetHisPatientList() {
  1036. //types, _ := c.GetInt64("type", 0)
  1037. record_date := c.GetString("record_date")
  1038. sch_type, _ := c.GetInt64("sch_type")
  1039. timeLayout := "2006-01-02"
  1040. loc, _ := time.LoadLocation("Local")
  1041. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1042. if err != nil {
  1043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1044. return
  1045. }
  1046. recordDateTime := theTime.Unix()
  1047. adminInfo := c.GetAdminUserInfo()
  1048. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1049. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1050. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1051. //获取当前用户的信息
  1052. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1053. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1054. //获取所有科室信息
  1055. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1056. c.ServeSuccessJSON(map[string]interface{}{
  1057. "list": patients,
  1058. "list_two": patients_two,
  1059. "info": adminUserInfo,
  1060. "doctors": doctors,
  1061. "department": department,
  1062. })
  1063. }
  1064. type CustomTemplate struct {
  1065. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1066. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1067. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1068. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1069. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1070. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1071. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1072. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1073. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1074. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1075. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1076. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1077. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1078. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1079. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1080. }
  1081. func (c *HisApiController) GetHisPatientInfo() {
  1082. patient_id, _ := c.GetInt64("patient_id")
  1083. his_patient_id, _ := c.GetInt64("his_patient_id")
  1084. record_date := c.GetString("record_date")
  1085. number := c.GetString("number")
  1086. //start_time := c.GetString("start_time")
  1087. //end_time := c.GetString("end_time")
  1088. p_type, _ := c.GetInt64("p_type")
  1089. timeLayout := "2006-01-02"
  1090. loc, _ := time.LoadLocation("Local")
  1091. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1092. if err != nil {
  1093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1094. return
  1095. }
  1096. recordDateTime := theTime.Unix()
  1097. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1098. //if err != nil {
  1099. //
  1100. //}
  1101. //startRecordDateTime := startTime.Unix()
  1102. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1103. //if err != nil {
  1104. //
  1105. //}
  1106. //endRecordDateTime := endTime.Unix()
  1107. admin := c.GetAdminUserInfo()
  1108. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1109. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1110. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1111. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1112. var prescriptions []*models.HisPrescription
  1113. var last_prescriptions []*models.HisPrescription
  1114. var sch_prescriptions []CustomTemplate
  1115. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1116. if p_type == 1 { //住院
  1117. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1118. for _, item := range prescriptions {
  1119. for _, subItem := range item.HisDoctorAdviceInfo {
  1120. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1121. if info.RetailPrice > 0 {
  1122. subItem.Drug.MinPrice = info.RetailPrice
  1123. }
  1124. }
  1125. }
  1126. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1127. } else { //门诊
  1128. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1129. for _, item := range prescriptions {
  1130. for _, subItem := range item.HisDoctorAdviceInfo {
  1131. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1132. if info.RetailPrice > 0 {
  1133. subItem.Drug.MinPrice = info.RetailPrice
  1134. }
  1135. }
  1136. }
  1137. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1138. }
  1139. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1140. if sch.ID > 0 {
  1141. var week string
  1142. t := time.Now()
  1143. switch t.Weekday().String() {
  1144. case "Monday":
  1145. week = "周一"
  1146. break
  1147. case "Tuesday":
  1148. week = "周二"
  1149. break
  1150. case "Wednesday":
  1151. week = "周三"
  1152. break
  1153. case "Thursday":
  1154. week = "周四"
  1155. break
  1156. case "Friday":
  1157. week = "周五"
  1158. break
  1159. case "Saturday":
  1160. week = "周六"
  1161. break
  1162. case "Sunday":
  1163. week = "周日"
  1164. break
  1165. }
  1166. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1167. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1168. //根据推送频率组装新的数组
  1169. for _, item := range temp_sch_prescriptions {
  1170. var cus CustomTemplate
  1171. cus.ID = item.ID
  1172. cus.UserOrgId = item.UserOrgId
  1173. cus.PatientId = item.PatientId
  1174. cus.MedType = item.MedType
  1175. cus.RecordDate = item.RecordDate
  1176. cus.Type = item.Type
  1177. cus.PType = item.PType
  1178. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1179. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1180. if subItem.FrequencyType == 1 { //每次必推
  1181. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1182. }
  1183. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1184. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1185. }
  1186. if subItem.FrequencyType == 2 { //按照天数频率
  1187. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1188. now := p.Unix()
  1189. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1190. dayStr2 := "-" + dayStr
  1191. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1192. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1193. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1194. if len(advices) == 0 {
  1195. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1196. }
  1197. }
  1198. }
  1199. }
  1200. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1201. if subItem.Type == 2 {
  1202. if subItem.XtHisProject.MedicalStatus != 1 {
  1203. if subItem.FrequencyType == 1 {
  1204. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1205. }
  1206. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1207. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1208. }
  1209. if subItem.FrequencyType == 2 {
  1210. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1211. now := p.Unix()
  1212. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1213. dayStr2 := "-" + dayStr
  1214. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1215. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1216. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1217. if len(projects) == 0 {
  1218. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1219. }
  1220. }
  1221. }
  1222. } else if subItem.Type == 3 {
  1223. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1224. if subItem.FrequencyType == 1 {
  1225. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1226. }
  1227. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1228. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1229. }
  1230. if subItem.FrequencyType == 2 {
  1231. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1232. now := p.Unix()
  1233. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1234. dayStr2 := "-" + dayStr
  1235. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1236. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1237. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1238. if len(projects) == 0 {
  1239. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. sch_prescriptions = append(sch_prescriptions, cus)
  1246. }
  1247. for _, item := range sch_prescriptions {
  1248. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1249. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1250. }
  1251. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1252. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1253. }
  1254. }
  1255. }
  1256. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1257. if config.ID > 0 && config.IsOpen == 1 {
  1258. for _, item := range sch_prescriptions {
  1259. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1260. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1261. if info.RetailPrice > 0 {
  1262. subItem.Drug.MinPrice = info.RetailPrice
  1263. }
  1264. }
  1265. }
  1266. }
  1267. if config.ID > 0 && config.IsOpen == 1 {
  1268. for _, item := range sch_prescriptions {
  1269. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1270. if subItem.Type == 3 {
  1271. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1272. if info.Price > 0 {
  1273. subItem.GoodInfo.PackingPrice = info.Price
  1274. }
  1275. }
  1276. }
  1277. }
  1278. }
  1279. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1280. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1281. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1283. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1285. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1286. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1287. //获取所有科室信息
  1288. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1289. c.ServeSuccessJSON(map[string]interface{}{
  1290. "his_info": his_patient_info,
  1291. "xt_info": xt_patient_info,
  1292. "prescription": prescriptions,
  1293. "case_history": case_history,
  1294. "info": patientPrescriptionInfo,
  1295. //"month_prescriptions": monthPrescriptions,
  1296. "order": order,
  1297. "doctors": doctors,
  1298. "department": department,
  1299. "sch_prescriptions": sch_prescriptions,
  1300. "last_prescriptions": last_prescriptions,
  1301. "schedule": sch,
  1302. "count": count,
  1303. "drugStockConfig": drugStockConfig,
  1304. "last_info": lastPatientPrescriptionInfo,
  1305. })
  1306. return
  1307. }
  1308. func (c *HisApiController) GetHisPrescriptionConfig() {
  1309. adminInfo := c.GetAdminUserInfo()
  1310. //获取医嘱模版
  1311. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1312. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1313. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1314. //获取所有基础药
  1315. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1316. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1317. if config.ID > 0 && config.IsOpen == 1 {
  1318. for _, item := range drugs {
  1319. var index = 0
  1320. for _, subItem := range item.OtherDrugWarehouseInfo {
  1321. if index == 0 {
  1322. index = index + 1
  1323. if subItem.RetailPrice > 0 {
  1324. item.MinPrice = subItem.RetailPrice
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1331. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1332. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1333. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1334. //获取所有科室信息
  1335. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1336. //获取诊断信息
  1337. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1338. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1339. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1340. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1341. //获取是否开启保存耗材出库的开关
  1342. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1343. c.ServeSuccessJSON(map[string]interface{}{
  1344. "drugs": drugs,
  1345. "advices_template": advices,
  1346. "drugways": drugways,
  1347. "efs": efs,
  1348. "doctors": doctors,
  1349. "department": department,
  1350. "sick": sick,
  1351. "additions": additions,
  1352. "diagnose": diagnose,
  1353. "manufacturers": manufacturers,
  1354. "goodOutOpen": goodOutOpen,
  1355. "patientDiagnose": patientDiagnose,
  1356. })
  1357. }
  1358. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1359. //获取所有基础药
  1360. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1361. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1362. if config.ID > 0 && config.IsOpen == 1 {
  1363. for _, item := range drugs {
  1364. var index = 0
  1365. for _, subItem := range item.OtherDrugWarehouseInfo {
  1366. if index == 0 {
  1367. index = index + 1
  1368. if subItem.RetailPrice > 0 {
  1369. item.MinPrice = subItem.RetailPrice
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1376. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1377. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1378. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1379. //获取所有科室信息
  1380. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1381. //获取诊断信息
  1382. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1383. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1384. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1385. //获取是否开启保存耗材出库的开关
  1386. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1387. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1388. c.ServeSuccessJSON(map[string]interface{}{
  1389. "drugs": drugs,
  1390. "advices_template": advices,
  1391. "drugways": drugways,
  1392. "efs": efs,
  1393. "doctors": doctors,
  1394. "department": department,
  1395. "sick": sick,
  1396. "additions": additions,
  1397. "diagnose": diagnose,
  1398. "manufacturers": manufacturers,
  1399. "goodOutOpen": goodOutOpen,
  1400. "patientDiagnose": patientDiagnose,
  1401. })
  1402. }
  1403. }
  1404. func (c *HisApiController) CreateHisPrescription() {
  1405. record_date := c.GetString("record_date")
  1406. patient_id, _ := c.GetInt64("patient_id")
  1407. reg_type, _ := c.GetInt64("reg_type")
  1408. diagnose := c.GetString("diagnose")
  1409. sick_type, _ := c.GetInt64("sick_type")
  1410. sick_history := c.GetString("sick_history")
  1411. doctor_id, _ := c.GetInt64("doctor", 0)
  1412. department, _ := c.GetInt64("department", 0)
  1413. his_patient_id, _ := c.GetInt64("his_patient_id")
  1414. p_type, _ := c.GetInt64("p_type")
  1415. patient_diagnose := c.GetString("patient_diagnose")
  1416. dataBody := make(map[string]interface{}, 0)
  1417. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1418. if err != nil {
  1419. utils.ErrorLog(err.Error())
  1420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1421. return
  1422. }
  1423. timeLayout := "2006-01-02"
  1424. loc, _ := time.LoadLocation("Local")
  1425. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1426. if err != nil {
  1427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1428. return
  1429. }
  1430. adminInfo := c.GetAdminUserInfo()
  1431. recordDateTime := theTime.Unix()
  1432. //查询默认出库仓库库存
  1433. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1434. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1435. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1436. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1437. if len(lists) == 1 {
  1438. his_patient_id = lists[0].ID
  1439. }
  1440. }
  1441. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1442. //保存处方出库
  1443. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1444. //自动出库
  1445. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1446. //耗材保存处方出库
  1447. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1448. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1449. //已发药和已收费限制逻辑
  1450. isMidicine := false
  1451. isCharge := false
  1452. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1453. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1454. if len(prescriptions) > 0 {
  1455. for _, item := range prescriptions {
  1456. items := item.(map[string]interface{})
  1457. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1458. utils.ErrorLog("id")
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1460. return
  1461. }
  1462. id := int64(items["id"].(float64))
  1463. if id > 0 {
  1464. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1465. if err != nil {
  1466. if new_prescription.OrderStatus == 4 {
  1467. isCharge = true
  1468. }
  1469. }
  1470. }
  1471. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1472. advices := items["advices"].([]interface{})
  1473. if len(advices) > 0 {
  1474. for _, advice := range advices {
  1475. var adviceId int64
  1476. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1477. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1478. }
  1479. if adviceId > 0 {
  1480. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1481. if err == nil {
  1482. if his_advice_info.IsMedicine == 1 {
  1483. isMidicine = true
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. }
  1493. if isMidicine == true {
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1495. return
  1496. }
  1497. if isCharge == true {
  1498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1499. return
  1500. }
  1501. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1502. //药品发药出库
  1503. if pharmacyConfig.IsOpen == 1 {
  1504. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1505. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1506. if len(prescriptions) > 0 {
  1507. for _, item := range prescriptions {
  1508. items := item.(map[string]interface{})
  1509. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1510. advices := items["advices"].([]interface{})
  1511. if len(advices) > 0 {
  1512. for _, advice := range advices {
  1513. var drug_id int64
  1514. var prescribing_number float64
  1515. var prescribingNumberUnit string
  1516. var adviceId int64
  1517. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1518. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1519. }
  1520. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1521. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1522. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1523. }
  1524. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1525. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1526. }
  1527. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1528. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1529. }
  1530. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1531. if drug.ID == 0 {
  1532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1533. return
  1534. }
  1535. //查询药品的所有库存
  1536. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1537. var total_count int64
  1538. for _, it := range list {
  1539. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1540. }
  1541. totals := strconv.FormatInt(total_count, 10)
  1542. //查询该药品是否存在开药记录
  1543. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1544. //新增处方
  1545. if advicelist.ID == 0 {
  1546. all_count, _ := strconv.ParseFloat(totals, 64)
  1547. if prescribingNumberUnit == drug.MinUnit {
  1548. if drug.IsUse != 1 {
  1549. if prescribing_number > all_count {
  1550. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1551. return
  1552. }
  1553. }
  1554. }
  1555. if prescribingNumberUnit == drug.MaxUnit {
  1556. num := prescribing_number * float64(drug.MinNumber)
  1557. if drug.IsUse != 1 {
  1558. if num > all_count {
  1559. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1560. return
  1561. }
  1562. }
  1563. }
  1564. }
  1565. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1566. if drugOutConfig.IsOpen != 1 {
  1567. //修改处方
  1568. for _, advice := range advices {
  1569. var drug_id int64
  1570. var prescribing_number float64
  1571. var prescribingNumberUnit string
  1572. var prescribingNumber string
  1573. var adviceId int64
  1574. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1575. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1576. }
  1577. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1578. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1579. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1580. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1581. }
  1582. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1583. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1584. }
  1585. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1586. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1587. }
  1588. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1589. if drug.ID == 0 {
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //查询药品的所有库存
  1594. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1595. var total_count int64
  1596. for _, it := range list {
  1597. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1598. }
  1599. totals := strconv.FormatInt(total_count, 10)
  1600. //查询该药品是否存在开药记录
  1601. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1602. //新增处方
  1603. if advicelist.ID == 0 {
  1604. all_count, _ := strconv.ParseFloat(totals, 64)
  1605. if prescribingNumberUnit == drug.MinUnit {
  1606. if drug.IsUse != 1 {
  1607. if prescribing_number > all_count {
  1608. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1609. return
  1610. }
  1611. }
  1612. } else {
  1613. if prescribingNumberUnit == drug.MaxUnit {
  1614. num := prescribing_number * float64(drug.MinNumber)
  1615. if drug.IsUse != 1 {
  1616. if num > all_count {
  1617. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1618. return
  1619. }
  1620. }
  1621. }
  1622. }
  1623. }
  1624. //修改处方
  1625. if advicelist.ID > 0 {
  1626. var device_number int64
  1627. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1628. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1629. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1630. device_number = prescribingNumberInt * drug.MinNumber
  1631. }
  1632. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1633. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1634. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1635. device_number = prescribingNumberInt
  1636. }
  1637. var number_count int64
  1638. if prescribingNumberUnit == drug.MaxUnit {
  1639. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1640. number_count = prescribingNumberInt * drug.MinNumber
  1641. }
  1642. if prescribingNumberUnit == drug.MinUnit {
  1643. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1644. number_count = prescribingNumberInt
  1645. }
  1646. //如果修改的数量大于之前修改的数量
  1647. if (number_count - device_number) > 0 {
  1648. //如果修改的差数量 大于库存数量
  1649. if drug.IsUse != 1 {
  1650. if (number_count - device_number) > total_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1652. return
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. //已发药和已收费限制逻辑
  1667. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1668. //校验库存总量
  1669. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1670. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1671. if len(prescriptions) > 0 {
  1672. for _, item := range prescriptions {
  1673. items := item.(map[string]interface{})
  1674. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1675. advices := items["advices"].([]interface{})
  1676. if len(advices) > 0 {
  1677. for _, advice := range advices {
  1678. var drug_id int64
  1679. var prescribing_number float64
  1680. var prescribingNumberUnit string
  1681. var adviceId int64
  1682. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1683. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1684. }
  1685. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1686. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1687. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1688. }
  1689. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1690. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1691. }
  1692. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1693. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1694. }
  1695. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1696. if drug.ID == 0 {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1698. return
  1699. }
  1700. //查询药品的所有库存
  1701. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1702. var total_count int64
  1703. for _, it := range list {
  1704. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1705. }
  1706. totals := strconv.FormatInt(total_count, 10)
  1707. //查询该药品是否存在开药记录
  1708. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1709. //查询最新批次库存
  1710. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1711. var batch_number_count int64
  1712. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1713. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1714. //新增处方
  1715. if advicelist.ID == 0 {
  1716. all_count, _ := strconv.ParseFloat(totals, 64)
  1717. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1718. if prescribingNumberUnit == drug.MinUnit {
  1719. if drug.IsUse != 1 {
  1720. if prescribing_number > all_count {
  1721. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1722. return
  1723. }
  1724. if adminInfo.CurrentOrgId == 10215 {
  1725. if prescribing_number > batch_number_all_count {
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1727. return
  1728. }
  1729. }
  1730. }
  1731. }
  1732. if prescribingNumberUnit == drug.MaxUnit {
  1733. num := prescribing_number * float64(drug.MinNumber)
  1734. if drug.IsUse != 1 {
  1735. if num > all_count {
  1736. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1737. return
  1738. }
  1739. if adminInfo.CurrentOrgId == 10215 {
  1740. if num > batch_number_all_count {
  1741. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1742. return
  1743. }
  1744. }
  1745. }
  1746. }
  1747. }
  1748. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1749. if drugOutConfig.IsOpen != 1 {
  1750. //修改处方
  1751. for _, advice := range advices {
  1752. var drug_id int64
  1753. var prescribing_number float64
  1754. var prescribingNumberUnit string
  1755. var prescribingNumber string
  1756. var adviceId int64
  1757. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1758. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1759. }
  1760. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1761. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1762. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1763. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1764. }
  1765. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1766. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1767. }
  1768. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1769. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1770. }
  1771. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1772. if drug.ID == 0 {
  1773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1774. return
  1775. }
  1776. //查询药品的所有库存
  1777. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1778. var total_count int64
  1779. for _, it := range list {
  1780. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1781. }
  1782. totals := strconv.FormatInt(total_count, 10)
  1783. //查询该药品是否存在开药记录
  1784. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1785. //新增处方
  1786. if advicelist.ID == 0 {
  1787. //查询最新批次库存
  1788. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1789. var batch_number_count int64
  1790. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1791. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1792. all_count, _ := strconv.ParseFloat(totals, 64)
  1793. if prescribingNumberUnit == drug.MinUnit {
  1794. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1795. if drug.IsUse != 1 {
  1796. if prescribing_number > all_count {
  1797. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1798. return
  1799. }
  1800. if adminInfo.CurrentOrgId == 10215 {
  1801. if prescribing_number > batch_number_all_count {
  1802. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1803. return
  1804. }
  1805. }
  1806. }
  1807. } else {
  1808. if prescribingNumberUnit == drug.MaxUnit {
  1809. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1810. num := prescribing_number * float64(drug.MinNumber)
  1811. if drug.IsUse != 1 {
  1812. if num > all_count {
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. if adminInfo.CurrentOrgId == 10215 {
  1817. if prescribing_number > batch_number_all_count {
  1818. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1819. return
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. //修改处方
  1827. if advicelist.ID > 0 {
  1828. //查询最新批次库存
  1829. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1830. var batch_number_count int64
  1831. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1832. var device_number int64
  1833. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1834. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1835. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1836. device_number = prescribingNumberInt * drug.MinNumber
  1837. }
  1838. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1839. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1840. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1841. device_number = prescribingNumberInt
  1842. }
  1843. var number_count int64
  1844. if prescribingNumberUnit == drug.MaxUnit {
  1845. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1846. number_count = prescribingNumberInt * drug.MinNumber
  1847. }
  1848. if prescribingNumberUnit == drug.MinUnit {
  1849. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1850. number_count = prescribingNumberInt
  1851. }
  1852. //如果修改的数量大于之前修改的数量
  1853. if (number_count - device_number) > 0 {
  1854. //如果修改的差数量 大于库存数量
  1855. if drug.IsUse != 1 {
  1856. if (number_count - device_number) > total_count {
  1857. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1858. return
  1859. }
  1860. if (number_count - device_number) > batch_number_count {
  1861. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1862. return
  1863. }
  1864. if adminInfo.CurrentOrgId == 10215 {
  1865. // 查询该药品最后一次出库记录
  1866. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1867. var out_count int64
  1868. var in_count int64
  1869. var stock_max_number int64
  1870. var stock_min_number int64
  1871. for _, it := range outInfo {
  1872. if it.CountUnit == drug.MaxUnit {
  1873. it.Count = it.Count * drug.MinNumber
  1874. }
  1875. out_count += it.Count
  1876. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1877. stock_max_number = warehouseInfoList.StockMaxNumber
  1878. stock_min_number = warehouseInfoList.StockMinNumber
  1879. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1880. }
  1881. if out_count > 0 {
  1882. if (number_count - device_number) > in_count {
  1883. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1884. return
  1885. }
  1886. }
  1887. // 未出库
  1888. if out_count == 0 {
  1889. var sum_in_count int64
  1890. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1891. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1892. fmt.Println("sum_in_count", sum_in_count)
  1893. //如果修改的数量大于有库存的第一个批次
  1894. if number_count > sum_in_count {
  1895. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1896. return
  1897. }
  1898. }
  1899. }
  1900. }
  1901. }
  1902. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1903. if pharmacyConfig.IsOpen != 1 {
  1904. if device_number != number_count {
  1905. // 查询该药品最后一次出库记录
  1906. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1907. //回退库存
  1908. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1909. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1910. }
  1911. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1912. var stock_max_number int64
  1913. var stock_min_number int64
  1914. if number_count >= drug.MinNumber {
  1915. stock_max_number = device_number / drug.MinNumber
  1916. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1917. stock_min_number = device_number % drug.MinNumber
  1918. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1919. } else {
  1920. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1921. }
  1922. }
  1923. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1924. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1925. }
  1926. //删除记录
  1927. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1928. //查询默认仓库剩余多少库存
  1929. var sum_count int64
  1930. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1931. for _, its := range stockInfo {
  1932. if its.MaxUnit == drug.MaxUnit {
  1933. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1934. }
  1935. sum_count += its.StockMaxNumber + its.StockMinNumber
  1936. }
  1937. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1938. }
  1939. }
  1940. }
  1941. }
  1942. }
  1943. //保存处方开药
  1944. if drugOutConfig.IsOpen == 1 {
  1945. //修改处方
  1946. for _, advice := range advices {
  1947. var drug_id int64
  1948. var prescribing_number float64
  1949. var prescribingNumberUnit string
  1950. var prescribingNumber string
  1951. var adviceId int64
  1952. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1953. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1954. }
  1955. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1956. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1957. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1958. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1959. }
  1960. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1961. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1962. }
  1963. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1964. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1965. }
  1966. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1967. if drug.ID == 0 {
  1968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1969. return
  1970. }
  1971. //查询药品的所有库存
  1972. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1973. var total_count int64
  1974. for _, it := range list {
  1975. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1976. }
  1977. totals := strconv.FormatInt(total_count, 10)
  1978. //查询该药品是否存在开药记录
  1979. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1980. //新增处方
  1981. if advicelist.ID == 0 {
  1982. //查询最新批次库存
  1983. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1984. var batch_number_count int64
  1985. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1986. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1987. all_count, _ := strconv.ParseFloat(totals, 64)
  1988. if prescribingNumberUnit == drug.MinUnit {
  1989. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1990. if drug.IsUse != 1 {
  1991. if prescribing_number > all_count {
  1992. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1993. return
  1994. }
  1995. if adminInfo.CurrentOrgId == 10215 {
  1996. if prescribing_number > batch_number_all_count {
  1997. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1998. return
  1999. }
  2000. }
  2001. }
  2002. } else {
  2003. if prescribingNumberUnit == drug.MaxUnit {
  2004. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2005. num := prescribing_number * float64(drug.MinNumber)
  2006. if drug.IsUse != 1 {
  2007. if num > all_count {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2009. return
  2010. }
  2011. if adminInfo.CurrentOrgId == 10215 {
  2012. if prescribing_number > batch_number_all_count {
  2013. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2014. return
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. //修改处方
  2022. if advicelist.ID > 0 {
  2023. //查询最新批次库存
  2024. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2025. var batch_number_count int64
  2026. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2027. var device_number int64
  2028. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2029. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2030. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2031. device_number = prescribingNumberInt * drug.MinNumber
  2032. }
  2033. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2034. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2035. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2036. device_number = prescribingNumberInt
  2037. }
  2038. var number_count int64
  2039. if prescribingNumberUnit == drug.MaxUnit {
  2040. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2041. number_count = prescribingNumberInt * drug.MinNumber
  2042. }
  2043. if prescribingNumberUnit == drug.MinUnit {
  2044. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2045. number_count = prescribingNumberInt
  2046. }
  2047. //如果修改的数量大于之前修改的数量
  2048. if (number_count - device_number) > 0 {
  2049. //如果修改的差数量 大于库存数量
  2050. if drug.IsUse != 1 {
  2051. if (number_count - device_number) > total_count {
  2052. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2053. return
  2054. }
  2055. if adminInfo.CurrentOrgId == 10215 {
  2056. if (number_count - device_number) > batch_number_count {
  2057. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2058. return
  2059. }
  2060. }
  2061. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2062. //查询历史出库数据总批次
  2063. // 查询该药品最后一次出库记录
  2064. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2065. var out_count int64
  2066. var in_count int64
  2067. var stock_max_number int64
  2068. var stock_min_number int64
  2069. for _, it := range outInfo {
  2070. if it.CountUnit == drug.MaxUnit {
  2071. it.Count = it.Count * drug.MinNumber
  2072. }
  2073. out_count += it.Count
  2074. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2075. stock_max_number = warehouseInfoList.StockMaxNumber
  2076. stock_min_number = warehouseInfoList.StockMinNumber
  2077. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2078. }
  2079. if out_count > 0 {
  2080. if (number_count - device_number) > in_count {
  2081. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2082. return
  2083. }
  2084. }
  2085. // 未出库
  2086. if out_count == 0 {
  2087. var sum_in_count int64
  2088. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2089. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2090. //如果修改的数量大于有库存的第一个批次
  2091. if number_count > sum_in_count {
  2092. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2093. return
  2094. }
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. }
  2109. //校验耗材库存
  2110. if goodOutConfig.IsOpen == 1 {
  2111. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2112. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2113. if len(prescriptions) > 0 {
  2114. for _, item := range prescriptions {
  2115. items := item.(map[string]interface{})
  2116. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2117. projects := items["project"].([]interface{})
  2118. if len(projects) > 0 {
  2119. for _, project := range projects {
  2120. var project_id int64
  2121. var project_type int64
  2122. var totals float64
  2123. var project_name string
  2124. var parsetotal int64
  2125. var id int64
  2126. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2127. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2128. }
  2129. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2130. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2131. }
  2132. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2133. total, _ := project.(map[string]interface{})["total"].(string)
  2134. totals, _ = strconv.ParseFloat(total, 64)
  2135. }
  2136. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2137. project_name = project.(map[string]interface{})["project_name"].(string)
  2138. }
  2139. if project_type == 3 {
  2140. //查找该耗材的出库记录
  2141. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2142. if len(goodWarehouseInfo) == 0 {
  2143. //查询耗材库存
  2144. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2145. var stock_count int64
  2146. for _, it := range list {
  2147. stock_count += it.StockCount
  2148. }
  2149. stock_counts := strconv.FormatInt(stock_count, 10)
  2150. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2151. if totals > stock_total_count {
  2152. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2153. return
  2154. }
  2155. }
  2156. if len(goodWarehouseInfo) > 0 {
  2157. //查询该患者耗材的历史数据
  2158. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2159. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2160. //数量发生改变
  2161. if parsetotal != count {
  2162. //如果现在的数量大于历史数量,就要看库存是否足够
  2163. if parsetotal > count {
  2164. //查询耗材所有库存
  2165. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2166. var stock_count int64
  2167. for _, it := range list {
  2168. stock_count += it.StockCount
  2169. }
  2170. //库存不足
  2171. if (parsetotal - count) > stock_count {
  2172. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2173. return
  2174. }
  2175. }
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. //不使用耗材保存处方出库
  2187. if goodOutConfig.IsOpen != 1 {
  2188. if stockConfig.IsOpen == 1 {
  2189. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2190. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2191. if len(prescriptions) > 0 {
  2192. for _, item := range prescriptions {
  2193. items := item.(map[string]interface{})
  2194. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2195. projects := items["project"].([]interface{})
  2196. if len(projects) > 0 {
  2197. for _, project := range projects {
  2198. var project_id int64
  2199. var project_type int64
  2200. var totals float64
  2201. var project_name string
  2202. var parsetotal int64
  2203. var id int64
  2204. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2205. id = int64(project.(map[string]interface{})["id"].(float64))
  2206. }
  2207. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2208. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2209. }
  2210. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2211. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2212. }
  2213. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2214. total, _ := project.(map[string]interface{})["total"].(string)
  2215. totals, _ = strconv.ParseFloat(total, 64)
  2216. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2217. }
  2218. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2219. project_name = project.(map[string]interface{})["project_name"].(string)
  2220. }
  2221. if project_type == 3 {
  2222. //查找该耗材的出库记录
  2223. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2224. //没有出库记录
  2225. if len(goodWarehouseInfo) == 0 {
  2226. //查询耗材库存
  2227. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2228. var stock_count int64
  2229. for _, it := range list {
  2230. stock_count += it.StockCount
  2231. }
  2232. stock_counts := strconv.FormatInt(stock_count, 10)
  2233. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2234. if totals > stock_total_count {
  2235. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2236. return
  2237. }
  2238. //查找今日该患者已经出库的所有耗材
  2239. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2240. for _, item := range goodList {
  2241. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2242. var flush_count int64
  2243. for _, it := range goodListSix {
  2244. flush_count += it.StockCount
  2245. }
  2246. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2247. creater := adminInfo.AdminUser.Id
  2248. if errs != nil {
  2249. goodErrcode := models.XtGoodErrcode{
  2250. UserOrgId: item.OrgId,
  2251. Errcode: "手动出库更新剩余出库失败",
  2252. GoodId: item.GoodId,
  2253. Status: 1,
  2254. Ctime: time.Now().Unix(),
  2255. Mtime: 0,
  2256. Count: 0,
  2257. StockCount: 0,
  2258. Creater: creater,
  2259. BatchNumberId: 0,
  2260. WarehouseOutId: 0,
  2261. }
  2262. service.CreateGoodErrcode(goodErrcode)
  2263. }
  2264. }
  2265. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2266. }
  2267. //有出库记录
  2268. if len(goodWarehouseInfo) > 0 {
  2269. //查询该患者耗材的历史数据
  2270. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2271. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2272. //数量发生改变
  2273. if parsetotal != count {
  2274. //查找今日该患者已经出库的所有耗材
  2275. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2276. for _, item := range goodList {
  2277. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2278. var flush_count int64
  2279. for _, it := range goodListSix {
  2280. flush_count += it.StockCount
  2281. }
  2282. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2283. //减少出库数量
  2284. creater := adminInfo.AdminUser.Id
  2285. if errs != nil {
  2286. goodErrcode := models.XtGoodErrcode{
  2287. UserOrgId: item.OrgId,
  2288. Errcode: "手动出库更新剩余出库失败",
  2289. GoodId: item.GoodId,
  2290. Status: 1,
  2291. Ctime: time.Now().Unix(),
  2292. Mtime: 0,
  2293. Count: 0,
  2294. StockCount: 0,
  2295. Creater: creater,
  2296. BatchNumberId: 0,
  2297. WarehouseOutId: 0,
  2298. }
  2299. service.CreateGoodErrcode(goodErrcode)
  2300. }
  2301. //查询默认仓库
  2302. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2303. var total_count int64
  2304. for _, it := range stockList {
  2305. total_count += it.StockCount
  2306. }
  2307. //基础库插入数据
  2308. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2309. }
  2310. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. }
  2322. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2323. var hpInfo models.HisPrescriptionInfo
  2324. if info.ID == 0 {
  2325. var randNum int
  2326. randNum = rand.Intn(10000) + 1000
  2327. timestamp := time.Now().Unix()
  2328. tempTime := time.Unix(timestamp, 0)
  2329. timeFormat := tempTime.Format("20060102150405")
  2330. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2331. hpInfo = models.HisPrescriptionInfo{
  2332. HisPatientId: his_patient_id,
  2333. UserOrgId: adminInfo.CurrentOrgId,
  2334. RecordDate: theTime.Unix(),
  2335. PatientId: patient_id,
  2336. Status: 1,
  2337. Ctime: time.Now().Unix(),
  2338. Mtime: time.Now().Unix(),
  2339. Creator: adminInfo.AdminUser.Id,
  2340. Modifier: adminInfo.AdminUser.Id,
  2341. Diagnosis: diagnose,
  2342. SickHistory: sick_history,
  2343. Departments: department,
  2344. RegisterType: reg_type,
  2345. PrescriptionNumber: p_number,
  2346. PrescriptionStatus: 1,
  2347. Doctor: role.UserName,
  2348. DoctorId: doctor_id,
  2349. SickType: sick_type,
  2350. PType: p_type,
  2351. PatientDiagnosis: patient_diagnose,
  2352. }
  2353. service.SavePatientPrescriptionInfo(hpInfo)
  2354. //创建步骤表
  2355. finish := models.XtDialysisFinish{
  2356. IsFinish: 1,
  2357. UserOrgId: adminInfo.CurrentOrgId,
  2358. Status: 1,
  2359. Ctime: time.Now().Unix(),
  2360. Mtime: 0,
  2361. Module: 4,
  2362. RecordDate: theTime.Unix(),
  2363. Sourse: 1,
  2364. PatientId: patient_id,
  2365. }
  2366. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2367. if dialysisFinish.ID == 0 {
  2368. service.CreateDialysisFinish(finish)
  2369. }
  2370. redis := service.RedisClient()
  2371. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2372. redis.Set(key, "", time.Second)
  2373. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2374. redis.Set(keyOne, "", time.Second)
  2375. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2376. redis.Set(keySeven, "", time.Second)
  2377. defer redis.Close()
  2378. } else {
  2379. hpInfo = models.HisPrescriptionInfo{
  2380. ID: info.ID,
  2381. UserOrgId: adminInfo.CurrentOrgId,
  2382. RecordDate: info.RecordDate,
  2383. PatientId: info.PatientId,
  2384. Status: 1,
  2385. Ctime: info.Ctime,
  2386. Mtime: time.Now().Unix(),
  2387. Creator: info.Creator,
  2388. Modifier: adminInfo.AdminUser.Id,
  2389. Diagnosis: diagnose,
  2390. SickHistory: sick_history,
  2391. Departments: department,
  2392. RegisterType: reg_type,
  2393. PrescriptionNumber: info.PrescriptionNumber,
  2394. Doctor: role.UserName,
  2395. PrescriptionStatus: info.PrescriptionStatus,
  2396. DoctorId: doctor_id,
  2397. SickType: sick_type,
  2398. PType: info.PType,
  2399. HisPatientId: info.HisPatientId,
  2400. PatientDiagnosis: patient_diagnose,
  2401. }
  2402. service.SavePatientPrescriptionInfo(hpInfo)
  2403. //创建步骤表
  2404. finish := models.XtDialysisFinish{
  2405. IsFinish: 1,
  2406. UserOrgId: adminInfo.CurrentOrgId,
  2407. Status: 1,
  2408. Ctime: time.Now().Unix(),
  2409. Mtime: 0,
  2410. Module: 4,
  2411. RecordDate: info.RecordDate,
  2412. Sourse: 1,
  2413. PatientId: info.PatientId,
  2414. }
  2415. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2416. if dialysisFinish.ID == 0 {
  2417. service.CreateDialysisFinish(finish)
  2418. }
  2419. redis := service.RedisClient()
  2420. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2421. redis.Set(key, "", time.Second)
  2422. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2423. redis.Set(keyOne, "", time.Second)
  2424. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2425. redis.Set(keySeven, "", time.Second)
  2426. defer redis.Close()
  2427. }
  2428. //定义切片
  2429. var adviceList []models.HisDoctorAdviceInfo
  2430. var projectList []models.HisPrescriptionProject
  2431. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2432. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2433. var tempPrescription *models.HisPrescription
  2434. if len(prescriptions) > 0 {
  2435. for _, item := range prescriptions {
  2436. items := item.(map[string]interface{})
  2437. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2438. utils.ErrorLog("id")
  2439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2440. return
  2441. }
  2442. id := int64(items["id"].(float64))
  2443. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2444. tempPrescription = &new_prescription
  2445. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2446. utils.ErrorLog("type")
  2447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2448. return
  2449. }
  2450. types := int64(items["type"].(float64))
  2451. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2452. utils.ErrorLog("med_type")
  2453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2454. return
  2455. }
  2456. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2457. if med_type == "0" {
  2458. med_type = "14"
  2459. }
  2460. //if order_status == 0 {
  2461. // order_status = 1
  2462. //}
  2463. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2464. utils.ErrorLog("pre_time")
  2465. }
  2466. preTime, _ := items["pre_time"].(string)
  2467. timeLayout := "2006-01-02"
  2468. loc, _ := time.LoadLocation("Local")
  2469. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2470. if err != nil {
  2471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2472. return
  2473. }
  2474. pTime := theTime2.Unix()
  2475. ctime := time.Now().Unix()
  2476. if tempPrescription.ID == 0 {
  2477. prescription := &models.HisPrescription{
  2478. ID: 0,
  2479. PatientId: patient_id,
  2480. UserOrgId: adminInfo.CurrentOrgId,
  2481. RecordDate: recordDateTime,
  2482. Ctime: ctime,
  2483. Mtime: ctime,
  2484. Type: types,
  2485. Modifier: adminInfo.AdminUser.Id,
  2486. Creator: adminInfo.AdminUser.Id,
  2487. Status: 1,
  2488. Doctor: role.UserName,
  2489. HisPatientId: his_patient_id,
  2490. OrderStatus: 1,
  2491. BatchNumber: "",
  2492. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2493. PreTime: pTime,
  2494. PType: p_type,
  2495. MedType: med_type,
  2496. }
  2497. tempPrescription = prescription
  2498. service.SaveHisPrescription(tempPrescription)
  2499. redis := service.RedisClient()
  2500. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2501. redis.Set(key, "", time.Second)
  2502. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2503. redis.Set(keyOne, "", time.Second)
  2504. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2505. redis.Set(keySeven, "", time.Second)
  2506. defer redis.Close()
  2507. } else {
  2508. tempPrescription.ID = id
  2509. tempPrescription.Type = types
  2510. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2511. tempPrescription.Mtime = time.Now().Unix()
  2512. tempPrescription.Doctor = role.UserName
  2513. //tempPrescription.OrderStatus = order_status
  2514. tempPrescription.PreTime = pTime
  2515. tempPrescription.MedType = med_type
  2516. service.SaveHisPrescription(tempPrescription)
  2517. redis := service.RedisClient()
  2518. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2519. redis.Set(key, "", time.Second)
  2520. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2521. redis.Set(keyOne, "", time.Second)
  2522. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2523. redis.Set(keySeven, "", time.Second)
  2524. defer redis.Close()
  2525. }
  2526. //service.SaveHisPrescription(prescription)
  2527. //更改患者挂号状态
  2528. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2529. fmt.Println("更改失败", err2)
  2530. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2531. advices := items["advices"].([]interface{})
  2532. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2533. groupNo := int64(0)
  2534. ctime := time.Now().Unix()
  2535. mtime := ctime
  2536. if len(advices) > 0 {
  2537. for _, advice := range advices {
  2538. var s models.HisDoctorAdviceInfo
  2539. s.PrescriptionId = tempPrescription.ID
  2540. s.AdviceType = 2
  2541. s.AdviceDoctor = doctor_id
  2542. s.StopState = 2
  2543. s.ExecutionState = 2
  2544. s.AdviceDate = recordDateTime
  2545. s.Status = 1
  2546. s.UserOrgId = adminInfo.CurrentOrgId
  2547. s.RecordDate = recordDateTime
  2548. s.StartTime = tempPrescription.PreTime
  2549. s.Groupno = groupNo
  2550. s.CreatedTime = ctime
  2551. s.UpdatedTime = mtime
  2552. s.PatientId = patient_id
  2553. s.HisPatientId = his_patient_id
  2554. s.StartTime = pTime
  2555. s.IsSettle = 2
  2556. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2557. if errcode > 0 {
  2558. c.ServeFailJSONWithSGJErrorCode(errcode)
  2559. return
  2560. }
  2561. s.StartTime = pTime
  2562. var total_count int64 //处方总库存
  2563. //查询改药品信息
  2564. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2565. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2566. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2567. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2568. total_count += prescribingNumberSeven * medical.MinNumber
  2569. }
  2570. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2571. total_count += prescribingNumberSeven
  2572. }
  2573. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2574. total_count += prescribingNumberSeven
  2575. }
  2576. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2577. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2578. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2579. if s.Price != lastWarehouse.RetailPrice {
  2580. s.Price = lastWarehouse.RetailPrice
  2581. }
  2582. if s.Price == 0 {
  2583. s.Price = lastWarehouse.RetailPrice
  2584. }
  2585. }
  2586. service.CreateHisDoctorAdvice(&s)
  2587. //记录日志
  2588. byterequest, _ := json.Marshal(s)
  2589. adviceLog := models.XtDoctorAdviceLog{
  2590. UserOrgId: s.UserOrgId,
  2591. PatientId: s.PatientId,
  2592. AdminUserId: adminInfo.AdminUser.Id,
  2593. Module: 1,
  2594. ErrLog: string(byterequest),
  2595. Status: 1,
  2596. Ctime: time.Now().Unix(),
  2597. Mtime: 0,
  2598. Source: "电脑端新建his医嘱",
  2599. RecordDate: s.AdviceDate,
  2600. }
  2601. service.CreateDoctorAdviceLog(adviceLog)
  2602. //存储切片中
  2603. adviceList = append(adviceList, s)
  2604. redis := service.RedisClient()
  2605. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2606. redis.Set(key, "", time.Second)
  2607. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2608. redis.Set(keyOne, "", time.Second)
  2609. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2610. redis.Set(keySeven, "", time.Second)
  2611. var randNum int
  2612. randNum = rand.Intn(10000) + 1000
  2613. timestamp := time.Now().Unix()
  2614. tempTime := time.Unix(timestamp, 0)
  2615. timeFormat := tempTime.Format("20060102150405")
  2616. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2617. service.CreateHisDoctorAdvice(&s)
  2618. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2619. redis.Set(keySix, "", time.Second)
  2620. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2621. redis.Set(keyFive, "", time.Second)
  2622. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2623. redis.Set(keyEight, "", time.Second)
  2624. defer redis.Close()
  2625. }
  2626. }
  2627. }
  2628. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2629. projects := items["project"].([]interface{})
  2630. if len(projects) > 0 {
  2631. for _, project := range projects {
  2632. var p models.HisPrescriptionProject
  2633. p.PrescriptionId = tempPrescription.ID
  2634. p.Ctime = time.Now().Unix()
  2635. p.Mtime = time.Now().Unix()
  2636. p.PatientId = patient_id
  2637. p.RecordDate = recordDateTime
  2638. p.Doctor = doctor_id
  2639. p.UserOrgId = adminInfo.CurrentOrgId
  2640. p.HisPatientId = his_patient_id
  2641. p.Status = 1
  2642. p.StartTime = pTime
  2643. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2644. if errcode > 0 {
  2645. c.ServeFailJSONWithSGJErrorCode(errcode)
  2646. return
  2647. }
  2648. if p.ID == 0 {
  2649. p.IsOut = 2
  2650. }
  2651. if p.ID > 0 {
  2652. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2653. p.IsOut = projectDetail.IsOut
  2654. }
  2655. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2656. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2657. if p.Type == 3 {
  2658. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2659. if p.Price != lastWarehouse.PackingPrice {
  2660. p.Price = lastWarehouse.PackingPrice
  2661. }
  2662. if p.Unit == "" {
  2663. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2664. p.Unit = goodInfoOne.PackingUnit
  2665. }
  2666. }
  2667. }
  2668. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2669. //
  2670. // if p.Type == 3 {
  2671. // //查询该耗材是否停用
  2672. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2673. // //表示该耗材已经停用,不能保存
  2674. // if goodInfoSeven.ID == 0 {
  2675. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2676. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2677. // return
  2678. // }
  2679. // }
  2680. //
  2681. //}
  2682. service.CreateHisProjectTwo(&p)
  2683. //记录日志
  2684. byterequest, _ := json.Marshal(p)
  2685. adviceLog := models.XtDoctorAdviceLog{
  2686. UserOrgId: p.UserOrgId,
  2687. PatientId: p.PatientId,
  2688. AdminUserId: adminInfo.AdminUser.Id,
  2689. Module: 1,
  2690. ErrLog: string(byterequest),
  2691. Status: 1,
  2692. Ctime: time.Now().Unix(),
  2693. Mtime: 0,
  2694. Source: "电脑端新建his项目",
  2695. RecordDate: p.RecordDate,
  2696. }
  2697. service.CreateDoctorAdviceLog(adviceLog)
  2698. projectList = append(projectList, p)
  2699. var randNum int
  2700. randNum = rand.Intn(10000) + 1000
  2701. timestamp := time.Now().Unix()
  2702. tempTime := time.Unix(timestamp, 0)
  2703. timeFormat := tempTime.Format("20060102150405")
  2704. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2705. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2706. //新增或者编辑项目,修改对应的标签数据
  2707. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2708. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2709. var label models.HisLabelPrintInfo
  2710. project, _ := service.GetProjectDetail(p.ProjectId)
  2711. if project.CostClassify == 3 { //类别为检验检查
  2712. if p.TeamId > 0 { //检验检查组套
  2713. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2714. if tempLabel.ID == 0 {
  2715. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2716. label.Number = tempPrescription.PrescriptionNumber
  2717. label.ProjectId = project.ID
  2718. label.Status = 1
  2719. label.IsPrint = 2
  2720. label.DoctorId = info.DoctorId
  2721. label.UserOrgId = p.UserOrgId
  2722. label.PatientId = patient_id
  2723. label.RecordDate = recordDateTime
  2724. label.Ctime = time.Now().Unix()
  2725. label.Mtime = time.Now().Unix()
  2726. label.ItemId = p.TeamId
  2727. label.FeedetlSn = p.FeedetlSn
  2728. label.PProjectId = p.ID
  2729. label.ProjectName = team.ProjectTeam
  2730. label.PatientName = patient.Name
  2731. service.CreateHisLabelRecord(&label)
  2732. }
  2733. } else { //单条检验检查项目
  2734. label.Number = tempPrescription.PrescriptionNumber
  2735. label.ProjectId = project.ID
  2736. label.Status = 1
  2737. label.DoctorId = info.DoctorId
  2738. label.UserOrgId = p.UserOrgId
  2739. label.PatientId = patient_id
  2740. label.RecordDate = recordDateTime
  2741. label.IsPrint = 2
  2742. label.Ctime = time.Now().Unix()
  2743. label.Mtime = time.Now().Unix()
  2744. label.FeedetlSn = p.FeedetlSn
  2745. label.PProjectId = p.ID
  2746. label.ItemId = p.TeamId
  2747. label.ProjectName = project.ProjectName
  2748. label.PatientName = patient.Name
  2749. service.CreateHisLabelRecord(&label)
  2750. }
  2751. }
  2752. }
  2753. }
  2754. service.SaveHisProjectTwo(&p)
  2755. }
  2756. }
  2757. }
  2758. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2759. // addition := items["addition"].([]interface{})
  2760. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2761. // ctime := time.Now().Unix()
  2762. // mtime := ctime
  2763. // if len(addition) > 0 {
  2764. // for _, item := range addition {
  2765. // var s models.HisAdditionalCharge
  2766. // s.PrescriptionId = tempPrescription.ID
  2767. // s.Status = 1
  2768. // s.UserOrgId = adminInfo.CurrentOrgId
  2769. // s.RecordDate = recordDateTime
  2770. // s.CreatedTime = ctime
  2771. // s.UpdatedTime = mtime
  2772. // s.PatientId = patient_id
  2773. // s.HisPatientId = his_patient_id
  2774. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2775. // if errcode > 0 {
  2776. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2777. // return
  2778. // }
  2779. // service.CreateAdditionalCharge(&s)
  2780. // var randNum int
  2781. // randNum = rand.Intn(10000) + 1000
  2782. // timestamp := time.Now().Unix()
  2783. // tempTime := time.Unix(timestamp, 0)
  2784. // timeFormat := tempTime.Format("20060102150405")
  2785. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2786. // service.CreateAdditionalCharge(&s)
  2787. //
  2788. // }
  2789. // }
  2790. //}
  2791. }
  2792. }
  2793. //查询今日该患者开的药品处方
  2794. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2795. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2796. //药品出库
  2797. if drugOutConfig.IsOpen == 1 {
  2798. for _, item := range hisdoctorlist {
  2799. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2800. // 查询该药品最后一次出库记录
  2801. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2802. if len(druginfo) > 0 {
  2803. //回退库存
  2804. for _, it := range druginfo {
  2805. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2806. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2807. }
  2808. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2809. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2810. }
  2811. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2812. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2813. }
  2814. }
  2815. }
  2816. //删除记录
  2817. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2818. //查询最后一次数据
  2819. if drugOutConfig.IsOpen == 1 {
  2820. //出库
  2821. if drug.IsUse == 2 {
  2822. creater := adminInfo.AdminUser.Id
  2823. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2824. }
  2825. //更新字典里面的库存
  2826. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2827. var sum_count int64
  2828. for _, its := range stockInfo {
  2829. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2830. if its.MaxUnit == baseDrug.MaxUnit {
  2831. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2832. }
  2833. sum_count += its.StockMaxNumber + its.StockMinNumber
  2834. }
  2835. //更新基础库存
  2836. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2837. //剩余库存
  2838. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2839. }
  2840. }
  2841. }
  2842. //耗材保存处方出库
  2843. if goodOutConfig.IsOpen == 1 {
  2844. //查询今日耗材出库数量
  2845. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2846. for _, item := range hisgoodlist {
  2847. //查询历史出库数据
  2848. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2849. var out_count_five int64
  2850. for _, item := range flowGood {
  2851. out_count_five += item.Count
  2852. }
  2853. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2854. if out_count_five != parseIntCount {
  2855. //查询耗材最后一次出库记录
  2856. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2857. //查询默认出库仓库库存
  2858. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2859. if len(wareOut) > 0 {
  2860. for _, it := range wareOut {
  2861. //回退库存
  2862. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2863. //删除出库记录
  2864. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2865. }
  2866. }
  2867. timeStr := time.Now().Format("2006-01-02")
  2868. timeArr := strings.Split(timeStr, "-")
  2869. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2870. total = total + 1
  2871. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2872. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2873. number = number + total
  2874. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2875. operation_time := time.Now().Unix()
  2876. creater := c.GetAdminUserInfo().AdminUser.Id
  2877. recordDateStr := time.Now().Format("2006-01-02")
  2878. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2879. nowtime := recordDate.Unix()
  2880. warehouseOut := models.WarehouseOut{
  2881. WarehouseOutOrderNumber: warehousing_out_order,
  2882. OperationTime: operation_time,
  2883. OrgId: adminInfo.CurrentOrgId,
  2884. Creater: creater,
  2885. Ctime: time.Now().Unix(),
  2886. Status: 1,
  2887. WarehouseOutTime: nowtime,
  2888. Type: 1,
  2889. StorehouseId: storeConfig.StorehouseOutInfo,
  2890. IsCheck: 1,
  2891. IsSys: 1,
  2892. }
  2893. //查询是否生成出库单
  2894. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2895. if out.ID == 0 {
  2896. service.AddSigleWarehouseOut(&warehouseOut)
  2897. }
  2898. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2899. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2900. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2901. dialyPrepareOne := models.DialysisBeforePrepare{
  2902. GoodTypeId: goodObj.GoodTypeId,
  2903. GoodId: item.ProjectId,
  2904. PatientId: item.PatientId,
  2905. RecordDate: item.RecordDate,
  2906. UserOrgId: adminInfo.CurrentOrgId,
  2907. Count: parseIntCount,
  2908. Ctime: time.Now().Unix(),
  2909. Creater: creater,
  2910. Status: 1,
  2911. StorehouseId: houseConfig.StorehouseOutInfo,
  2912. ProjectId: item.ID,
  2913. }
  2914. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2915. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2916. //查询历史出库数据
  2917. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2918. var out_count int64
  2919. for _, item := range flowGood {
  2920. out_count += item.Count
  2921. }
  2922. //如果历史数和当前数据不想等才进行退库出库
  2923. if out_count != parseIntCount {
  2924. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2925. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2926. detail := models.AutomaticReduceDetail{
  2927. WarehouseOutId: 0,
  2928. WarehouseOutOrderNumber: "",
  2929. PatientId: item.PatientId,
  2930. Ctime: time.Now().Unix(),
  2931. Mtime: 0,
  2932. Status: 1,
  2933. RecordTime: item.RecordDate,
  2934. OrgId: item.UserOrgId,
  2935. GoodId: item.ProjectId,
  2936. GoodTypeId: 0,
  2937. Count: parseIntCount,
  2938. Type: 0,
  2939. ProjectId: item.ID,
  2940. StorehouseId: 0,
  2941. }
  2942. service.CreateAutoDetail(detail)
  2943. //查询剩余库存
  2944. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2945. var sum_count int64
  2946. for _, item := range goodList {
  2947. sum_count += item.StockCount
  2948. }
  2949. //更新剩余库存
  2950. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2951. //耗材
  2952. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2953. }
  2954. }
  2955. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2956. //查询历史出库数据
  2957. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2958. var out_count int64
  2959. for _, item := range flowGood {
  2960. out_count += item.Count
  2961. }
  2962. //如果历史数和当前数据不想等才进行退库出库
  2963. if out_count != parseIntCount {
  2964. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2965. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2966. detail := models.AutomaticReduceDetail{
  2967. WarehouseOutId: 0,
  2968. WarehouseOutOrderNumber: "",
  2969. PatientId: item.PatientId,
  2970. Ctime: time.Now().Unix(),
  2971. Mtime: 0,
  2972. Status: 1,
  2973. RecordTime: item.RecordDate,
  2974. OrgId: item.UserOrgId,
  2975. GoodId: item.ProjectId,
  2976. GoodTypeId: 0,
  2977. Count: parseIntCount,
  2978. Type: 0,
  2979. ProjectId: item.ID,
  2980. StorehouseId: 0,
  2981. }
  2982. service.CreateAutoDetail(detail)
  2983. //查询剩余库存
  2984. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2985. var sum_count int64
  2986. for _, item := range goodList {
  2987. sum_count += item.StockCount
  2988. }
  2989. //更新剩余库存
  2990. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2991. //耗材
  2992. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2993. }
  2994. }
  2995. }
  2996. }
  2997. }
  2998. }
  2999. //redisClient := service.RedisClient()
  3000. //defer redisClient.Close()
  3001. //
  3002. //list := models.HisList{
  3003. // Patient_id: patient_id,
  3004. // Advice_id:0,
  3005. // Record_date: 0,
  3006. // Advice: adviceList,
  3007. // Project: nil,
  3008. //}
  3009. //hisLis = append(hisLis, list)
  3010. //
  3011. //advice_json, _ := json.Marshal(&hisLis)
  3012. //redisClient.RPush("111", advice_json).Result()
  3013. //result, _ := redisClient.RPop("111").Result()
  3014. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3015. //
  3016. //var dat []map[string]interface{}
  3017. //json.Unmarshal([]byte(result), &dat)
  3018. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3019. //
  3020. //for k,v:=range dat{
  3021. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3022. //}
  3023. //project_json, _ := json.Marshal(&projectList)
  3024. //redisClient.LPush("222", project_json).Result()
  3025. if err == nil {
  3026. c.ServeSuccessJSON(map[string]interface{}{
  3027. "msg": "保存成功",
  3028. })
  3029. return
  3030. } else {
  3031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3032. return
  3033. }
  3034. }
  3035. func (c *HisApiController) EditHisPrescription() {
  3036. record_date := c.GetString("record_date")
  3037. patient_id, _ := c.GetInt64("patient_id")
  3038. reg_type, _ := c.GetInt64("reg_type")
  3039. //diagnose, _ := c.GetInt64("diagnose", 0)
  3040. diagnose := c.GetString("diagnose")
  3041. sick_type, _ := c.GetInt64("sick_type")
  3042. sick_history := c.GetString("sick_history")
  3043. doctor_id, _ := c.GetInt64("doctor", 0)
  3044. department, _ := c.GetInt64("department", 0)
  3045. his_patient_id, _ := c.GetInt64("his_patient_id")
  3046. p_type, _ := c.GetInt64("p_type")
  3047. dataBody := make(map[string]interface{}, 0)
  3048. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3049. if err != nil {
  3050. utils.ErrorLog(err.Error())
  3051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3052. return
  3053. }
  3054. timeLayout := "2006-01-02"
  3055. loc, _ := time.LoadLocation("Local")
  3056. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3057. if err != nil {
  3058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3059. return
  3060. }
  3061. adminInfo := c.GetAdminUserInfo()
  3062. recordDateTime := theTime.Unix()
  3063. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3064. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3065. var hpInfo models.HisPrescriptionInfo
  3066. if info.ID == 0 {
  3067. var randNum int
  3068. randNum = rand.Intn(10000) + 1000
  3069. timestamp := time.Now().Unix()
  3070. tempTime := time.Unix(timestamp, 0)
  3071. timeFormat := tempTime.Format("20060102150405")
  3072. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3073. hpInfo = models.HisPrescriptionInfo{
  3074. UserOrgId: adminInfo.CurrentOrgId,
  3075. RecordDate: theTime.Unix(),
  3076. PatientId: patient_id,
  3077. Status: 1,
  3078. Ctime: time.Now().Unix(),
  3079. Mtime: time.Now().Unix(),
  3080. Creator: adminInfo.AdminUser.Id,
  3081. Modifier: adminInfo.AdminUser.Id,
  3082. Diagnosis: diagnose,
  3083. SickHistory: sick_history,
  3084. Departments: department,
  3085. RegisterType: reg_type,
  3086. PrescriptionNumber: p_number,
  3087. PrescriptionStatus: 1,
  3088. Doctor: role.UserName,
  3089. DoctorId: doctor_id,
  3090. SickType: sick_type,
  3091. PType: p_type,
  3092. }
  3093. service.SavePatientPrescriptionInfo(hpInfo)
  3094. } else {
  3095. hpInfo = models.HisPrescriptionInfo{
  3096. ID: info.ID,
  3097. UserOrgId: adminInfo.CurrentOrgId,
  3098. RecordDate: info.RecordDate,
  3099. PatientId: info.PatientId,
  3100. Status: 1,
  3101. Ctime: info.Ctime,
  3102. Mtime: time.Now().Unix(),
  3103. Creator: info.Creator,
  3104. Modifier: adminInfo.AdminUser.Id,
  3105. Diagnosis: diagnose,
  3106. SickHistory: sick_history,
  3107. Departments: department,
  3108. RegisterType: reg_type,
  3109. PrescriptionNumber: info.PrescriptionNumber,
  3110. Doctor: role.UserName,
  3111. PrescriptionStatus: info.PrescriptionStatus,
  3112. DoctorId: doctor_id,
  3113. SickType: sick_type,
  3114. PType: info.PType,
  3115. }
  3116. service.SavePatientPrescriptionInfo(hpInfo)
  3117. }
  3118. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3119. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3120. if len(prescriptions) > 0 {
  3121. for _, item := range prescriptions {
  3122. items := item.(map[string]interface{})
  3123. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3124. utils.ErrorLog("id")
  3125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3126. return
  3127. }
  3128. id := int64(items["id"].(float64))
  3129. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3130. utils.ErrorLog("type")
  3131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3132. return
  3133. }
  3134. types := int64(items["type"].(float64))
  3135. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3136. utils.ErrorLog("med_type")
  3137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3138. return
  3139. }
  3140. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3141. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3142. ctime := time.Now().Unix()
  3143. prescription := &models.HisPrescription{
  3144. ID: id,
  3145. PatientId: patient_id,
  3146. UserOrgId: adminInfo.CurrentOrgId,
  3147. RecordDate: recordDateTime,
  3148. Ctime: ctime,
  3149. Mtime: ctime,
  3150. Type: types,
  3151. Modifier: adminInfo.AdminUser.Id,
  3152. Creator: adminInfo.AdminUser.Id,
  3153. Status: 1,
  3154. Doctor: role.UserName,
  3155. HisPatientId: his_patient_id,
  3156. OrderStatus: 1,
  3157. BatchNumber: "",
  3158. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3159. PType: hpInfo.PType,
  3160. MedType: med_type,
  3161. }
  3162. if historyPrescription.ID > 0 {
  3163. prescription.PreTime = historyPrescription.PreTime
  3164. }
  3165. service.SaveHisPrescription(prescription)
  3166. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3167. advices := items["advices"].([]interface{})
  3168. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3169. groupNo := int64(0)
  3170. ctime := time.Now().Unix()
  3171. mtime := ctime
  3172. if len(advices) > 0 {
  3173. for _, advice := range advices {
  3174. var s models.HisDoctorAdviceInfo
  3175. s.PrescriptionId = prescription.ID
  3176. s.AdviceType = 2
  3177. s.AdviceDoctor = adminInfo.AdminUser.Id
  3178. s.StopState = 2
  3179. s.ExecutionState = 2
  3180. s.AdviceDate = recordDateTime
  3181. s.Status = 1
  3182. s.UserOrgId = adminInfo.CurrentOrgId
  3183. s.RecordDate = recordDateTime
  3184. s.StartTime = prescription.PreTime
  3185. s.Groupno = groupNo
  3186. s.CreatedTime = ctime
  3187. s.UpdatedTime = mtime
  3188. s.PatientId = patient_id
  3189. s.HisPatientId = his_patient_id
  3190. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3191. if errcode > 0 {
  3192. c.ServeFailJSONWithSGJErrorCode(errcode)
  3193. return
  3194. }
  3195. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3196. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3197. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3198. if s.Price == 0 {
  3199. s.Price = lastWarehouse.RetailPrice
  3200. }
  3201. }
  3202. service.CreateHisDoctorAdvice(&s)
  3203. //记录日志
  3204. byterequest, _ := json.Marshal(s)
  3205. adviceLog := models.XtDoctorAdviceLog{
  3206. UserOrgId: s.UserOrgId,
  3207. PatientId: s.PatientId,
  3208. AdminUserId: adminInfo.AdminUser.Id,
  3209. Module: 1,
  3210. ErrLog: string(byterequest),
  3211. Status: 1,
  3212. Ctime: time.Now().Unix(),
  3213. Mtime: 0,
  3214. Source: "电脑端his医嘱修改",
  3215. RecordDate: s.AdviceDate,
  3216. }
  3217. service.CreateDoctorAdviceLog(adviceLog)
  3218. redis := service.RedisClient()
  3219. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3220. redis.Set(key, "", time.Second)
  3221. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3222. fmt.Println("keyOne", keyOne)
  3223. redis.Set(keyOne, "", time.Second)
  3224. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3225. redis.Set(keySeven, "", time.Second)
  3226. redis.Close()
  3227. }
  3228. }
  3229. }
  3230. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3231. projects := items["project"].([]interface{})
  3232. if len(projects) > 0 {
  3233. for _, project := range projects {
  3234. var p models.HisPrescriptionProject
  3235. p.PrescriptionId = prescription.ID
  3236. p.Ctime = time.Now().Unix()
  3237. p.Mtime = time.Now().Unix()
  3238. p.PatientId = patient_id
  3239. p.RecordDate = recordDateTime
  3240. p.UserOrgId = adminInfo.CurrentOrgId
  3241. p.HisPatientId = his_patient_id
  3242. p.Status = 1
  3243. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3244. if errcode > 0 {
  3245. c.ServeFailJSONWithSGJErrorCode(errcode)
  3246. return
  3247. }
  3248. service.CreateHisProjectTwo(&p)
  3249. //记录日志
  3250. byterequest, _ := json.Marshal(p)
  3251. adviceLog := models.XtDoctorAdviceLog{
  3252. UserOrgId: p.UserOrgId,
  3253. PatientId: p.PatientId,
  3254. AdminUserId: adminInfo.AdminUser.Id,
  3255. Module: 1,
  3256. ErrLog: string(byterequest),
  3257. Status: 1,
  3258. Ctime: time.Now().Unix(),
  3259. Mtime: 0,
  3260. Source: "电脑端his项目修改",
  3261. RecordDate: p.RecordDate,
  3262. }
  3263. service.CreateDoctorAdviceLog(adviceLog)
  3264. }
  3265. }
  3266. }
  3267. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3268. addition := items["addition"].([]interface{})
  3269. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3270. ctime := time.Now().Unix()
  3271. mtime := ctime
  3272. if len(addition) > 0 {
  3273. for _, item := range addition {
  3274. var s models.HisAdditionalCharge
  3275. s.PrescriptionId = prescription.ID
  3276. s.Status = 1
  3277. s.UserOrgId = adminInfo.CurrentOrgId
  3278. s.RecordDate = recordDateTime
  3279. s.CreatedTime = ctime
  3280. s.UpdatedTime = mtime
  3281. s.PatientId = patient_id
  3282. s.HisPatientId = his_patient_id
  3283. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3284. if errcode > 0 {
  3285. c.ServeFailJSONWithSGJErrorCode(errcode)
  3286. return
  3287. }
  3288. service.CreateAdditionalCharge(&s)
  3289. }
  3290. }
  3291. }
  3292. }
  3293. }
  3294. }
  3295. if err == nil {
  3296. c.ServeSuccessJSON(map[string]interface{}{
  3297. "msg": "保存成功",
  3298. })
  3299. return
  3300. } else {
  3301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3302. return
  3303. }
  3304. }
  3305. func (c *HisApiController) DeletePrescription() {
  3306. prescription_id, _ := c.GetInt64("id")
  3307. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3308. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3309. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3310. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3311. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3312. //耗材保存处方出库
  3313. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3314. //已收费和已发药限制逻辑
  3315. isCharge := false
  3316. isMedicine := false
  3317. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3318. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3319. for _, item := range new_prescriptions {
  3320. if item.IsMedicine == 1 {
  3321. isMedicine = true
  3322. }
  3323. }
  3324. for _, item := range new_prescriptions {
  3325. if item.OrderStatus == 4 {
  3326. isCharge = true
  3327. }
  3328. }
  3329. if p_err != nil {
  3330. if new_prescription.ID > 0 {
  3331. if new_prescription.OrderStatus == 2 {
  3332. isCharge = true
  3333. }
  3334. }
  3335. }
  3336. for _, item := range advices {
  3337. if item.IsMedicine == 1 {
  3338. isMedicine = true
  3339. }
  3340. }
  3341. if isCharge {
  3342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3343. return
  3344. }
  3345. if isMedicine {
  3346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3347. return
  3348. }
  3349. //已收费和已发药限制逻辑
  3350. if len(projects) > 0 {
  3351. for _, item := range projects {
  3352. service.DeletePrintInfo(item.ID) //删除打印信息
  3353. if goodOutConfig.IsOpen != 1 {
  3354. if stockConfig.IsOpen == 1 {
  3355. if item.Type == 3 && item.IsOut == 1 {
  3356. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3357. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3358. good.Total = good.Total + f_count
  3359. service.UpdateGoodInfo(&good)
  3360. operation_time := time.Now().Unix()
  3361. creater := c.GetAdminUserInfo().AdminUser.Id
  3362. //创建退库单
  3363. timeStr := time.Now().Format("2006-01-02")
  3364. timeArr := strings.Split(timeStr, "-")
  3365. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3366. total = total + 1
  3367. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3368. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3369. cancelStock := models.CancelStock{
  3370. OrderNumber: orderNumber,
  3371. OperaTime: operation_time,
  3372. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3373. Creater: creater,
  3374. Ctime: time.Now().Unix(),
  3375. Status: 1,
  3376. ReturnTime: item.RecordDate,
  3377. Type: 1,
  3378. StorehouseId: houseConfig.StorehouseOutInfo,
  3379. IsCheck: 1,
  3380. }
  3381. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3382. if msgerrkonde == gorm.ErrRecordNotFound {
  3383. service.AddSigleCancelStock(&cancelStock)
  3384. }
  3385. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3386. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3387. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3388. //查询该耗材是否出库
  3389. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3390. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3391. deaerler, _ := service.GetDealerById(info.Dealer)
  3392. var total_count int64
  3393. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3394. total_count += count
  3395. if info.ID > 0 {
  3396. if info.Count >= total_count {
  3397. //回退库存
  3398. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3399. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3400. var flush_count int64
  3401. for _, it := range goodList {
  3402. flush_count += it.StockCount
  3403. }
  3404. cancelStockInfo := models.CancelStockInfo{
  3405. GoodId: item.ProjectId,
  3406. CancelStockId: cancel.ID,
  3407. GoodTypeId: good.GoodTypeId,
  3408. Count: prescribingNumber,
  3409. Price: info.Price,
  3410. Total: 0,
  3411. ProductDate: info.ProductDate,
  3412. ExpiryDate: info.ExpiryDate,
  3413. Ctime: time.Now().Unix(),
  3414. Status: 1,
  3415. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3416. OrderNumber: cancel.OrderNumber,
  3417. Type: 0,
  3418. Dealer: deaerler.DealerName,
  3419. Manufacturer: manufacturer.ManufacturerName,
  3420. Number: info.Number,
  3421. RegisterAccount: "",
  3422. Remark: "",
  3423. WarehouseInfoId: info.WarehouseInfotId,
  3424. PatientId: info.PatientId,
  3425. RecordDate: info.SysRecordTime,
  3426. StorehouseId: houseConfig.StorehouseOutInfo,
  3427. IsCheck: 1,
  3428. }
  3429. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3430. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3431. flow := models.VmStockFlow{
  3432. WarehousingId: info.WarehouseInfotId,
  3433. GoodId: item.ProjectId,
  3434. Number: info.Number,
  3435. LicenseNumber: info.LicenseNumber,
  3436. Count: prescribingNumber,
  3437. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3438. PatientId: item.PatientId,
  3439. SystemTime: info.SysRecordTime,
  3440. ConsumableType: 7,
  3441. IsSys: 0,
  3442. WarehousingOrder: "",
  3443. WarehouseOutId: info.WarehouseOutId,
  3444. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3445. IsEdit: 0,
  3446. CancelStockId: cancel.ID,
  3447. CancelOrderNumber: cancel.OrderNumber,
  3448. Manufacturer: manufacturer.ID,
  3449. Dealer: 0,
  3450. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3451. UpdateCreator: 0,
  3452. Status: 1,
  3453. Ctime: time.Now().Unix(),
  3454. Mtime: 0,
  3455. Price: info.Price,
  3456. WarehousingDetailId: info.WarehouseInfotId,
  3457. WarehouseOutDetailId: info.ID,
  3458. CancelOutDetailId: cancelInfo.ID,
  3459. ProductDate: info.ProductDate,
  3460. ExpireDate: info.ExpiryDate,
  3461. StorehouseId: houseConfig.StorehouseOutInfo,
  3462. OverCount: flush_count,
  3463. }
  3464. service.CreateStockFlowOne(flow)
  3465. //退库数量增加
  3466. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3467. //出库数量减少
  3468. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3469. }
  3470. if info.Count < total_count {
  3471. //回退库存
  3472. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3473. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3474. var flush_count int64
  3475. for _, it := range goodList {
  3476. flush_count += it.StockCount
  3477. }
  3478. cancelStockInfo := models.CancelStockInfo{
  3479. GoodId: item.ProjectId,
  3480. CancelStockId: cancel.ID,
  3481. GoodTypeId: good.GoodTypeId,
  3482. Count: info.Count,
  3483. Price: info.Price,
  3484. Total: 0,
  3485. ProductDate: info.ProductDate,
  3486. ExpiryDate: info.ExpiryDate,
  3487. Ctime: time.Now().Unix(),
  3488. Status: 1,
  3489. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3490. OrderNumber: cancel.OrderNumber,
  3491. Type: 0,
  3492. Dealer: deaerler.DealerName,
  3493. Manufacturer: manufacturer.ManufacturerName,
  3494. Number: info.Number,
  3495. RegisterAccount: "",
  3496. Remark: "",
  3497. WarehouseInfoId: info.WarehouseInfotId,
  3498. PatientId: info.PatientId,
  3499. RecordDate: info.SysRecordTime,
  3500. StorehouseId: houseConfig.StorehouseOutInfo,
  3501. IsCheck: 1,
  3502. }
  3503. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3504. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3505. flow := models.VmStockFlow{
  3506. WarehousingId: info.WarehouseInfotId,
  3507. GoodId: item.ProjectId,
  3508. Number: info.Number,
  3509. LicenseNumber: info.LicenseNumber,
  3510. Count: info.Count,
  3511. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3512. PatientId: item.PatientId,
  3513. SystemTime: info.SysRecordTime,
  3514. ConsumableType: 7,
  3515. IsSys: 0,
  3516. WarehousingOrder: "",
  3517. WarehouseOutId: info.WarehouseOutId,
  3518. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3519. IsEdit: 0,
  3520. CancelStockId: cancel.ID,
  3521. CancelOrderNumber: cancel.OrderNumber,
  3522. Manufacturer: manufacturer.ID,
  3523. Dealer: 0,
  3524. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3525. UpdateCreator: 0,
  3526. Status: 1,
  3527. Ctime: time.Now().Unix(),
  3528. Mtime: 0,
  3529. Price: info.Price,
  3530. WarehousingDetailId: info.WarehouseInfotId,
  3531. WarehouseOutDetailId: info.ID,
  3532. CancelOutDetailId: cancelInfo.ID,
  3533. ProductDate: info.ProductDate,
  3534. ExpireDate: info.ExpiryDate,
  3535. StorehouseId: houseConfig.StorehouseOutInfo,
  3536. OverCount: flush_count,
  3537. }
  3538. service.CreateStockFlowOne(flow)
  3539. //退库数量增加
  3540. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3541. //出库数量减少
  3542. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3543. }
  3544. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3545. var flush_count int64
  3546. for _, it := range goodList {
  3547. flush_count += it.StockCount
  3548. }
  3549. //查询已出库数量
  3550. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3551. if prescribingNumber < dialysisInfo.Count {
  3552. //改变数量
  3553. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3554. }
  3555. if prescribingNumber >= dialysisInfo.Count {
  3556. //删除出库表
  3557. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3558. }
  3559. //更新库存
  3560. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3561. //更新基础库库存
  3562. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3563. }
  3564. }
  3565. }
  3566. }
  3567. //保存耗材出库
  3568. if goodOutConfig.IsOpen == 1 {
  3569. if item.Type == 3 {
  3570. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3571. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3572. good.Total = good.Total + f_count
  3573. service.UpdateGoodInfo(&good)
  3574. operation_time := time.Now().Unix()
  3575. creater := c.GetAdminUserInfo().AdminUser.Id
  3576. //创建退库单
  3577. timeStr := time.Now().Format("2006-01-02")
  3578. timeArr := strings.Split(timeStr, "-")
  3579. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3580. total = total + 1
  3581. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3582. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3583. cancelStock := models.CancelStock{
  3584. OrderNumber: orderNumber,
  3585. OperaTime: operation_time,
  3586. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3587. Creater: creater,
  3588. Ctime: time.Now().Unix(),
  3589. Status: 1,
  3590. ReturnTime: item.RecordDate,
  3591. Type: 1,
  3592. StorehouseId: houseConfig.StorehouseOutInfo,
  3593. IsCheck: 1,
  3594. }
  3595. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3596. if msgerrkonde == gorm.ErrRecordNotFound {
  3597. service.AddSigleCancelStock(&cancelStock)
  3598. }
  3599. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3600. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3601. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3602. //查询该耗材是否出库
  3603. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3604. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3605. deaerler, _ := service.GetDealerById(info.Dealer)
  3606. var total_count int64
  3607. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3608. total_count += count
  3609. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3610. var flush_count int64
  3611. for _, it := range goodList {
  3612. flush_count += it.StockCount
  3613. }
  3614. fmt.Println("历史出库数据", info.Count)
  3615. fmt.Println("出库数量", total_count)
  3616. if info.ID > 0 {
  3617. cancelStockInfo := models.CancelStockInfo{
  3618. GoodId: item.ProjectId,
  3619. CancelStockId: cancel.ID,
  3620. GoodTypeId: good.GoodTypeId,
  3621. Count: prescribingNumber,
  3622. Price: info.Price,
  3623. Total: 0,
  3624. ProductDate: info.ProductDate,
  3625. ExpiryDate: info.ExpiryDate,
  3626. Ctime: time.Now().Unix(),
  3627. Status: 1,
  3628. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3629. OrderNumber: cancel.OrderNumber,
  3630. Type: 0,
  3631. Dealer: deaerler.DealerName,
  3632. Manufacturer: manufacturer.ManufacturerName,
  3633. Number: info.Number,
  3634. RegisterAccount: "",
  3635. Remark: "",
  3636. WarehouseInfoId: info.WarehouseInfotId,
  3637. PatientId: info.PatientId,
  3638. RecordDate: info.SysRecordTime,
  3639. StorehouseId: houseConfig.StorehouseOutInfo,
  3640. IsCheck: 1,
  3641. }
  3642. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3643. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3644. //查询出库数量
  3645. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3646. //出库数据 大于 退库数量
  3647. if len(list) > 0 {
  3648. for _, it := range list {
  3649. //回退库存
  3650. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3651. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3652. var flush_count_one int64
  3653. for _, it := range goodList {
  3654. flush_count_one += it.StockCount
  3655. }
  3656. //查询该批次是否有退库数据
  3657. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3658. creater := c.GetAdminUserInfo().AdminUser.Id
  3659. flow := models.VmStockFlow{
  3660. WarehousingId: it.WarehouseInfotId,
  3661. GoodId: it.GoodId,
  3662. Number: it.Number,
  3663. LicenseNumber: it.LicenseNumber,
  3664. Count: it.Count,
  3665. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3666. PatientId: it.PatientId,
  3667. SystemTime: it.SysRecordTime,
  3668. ConsumableType: 7,
  3669. IsSys: 0,
  3670. WarehousingOrder: "",
  3671. WarehouseOutId: it.WarehouseOutId,
  3672. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3673. IsEdit: 0,
  3674. CancelStockId: cancel.ID,
  3675. CancelOrderNumber: cancel.OrderNumber,
  3676. Manufacturer: manufacturer.ID,
  3677. Dealer: 0,
  3678. Creator: creater,
  3679. UpdateCreator: 0,
  3680. Status: 1,
  3681. Ctime: time.Now().Unix(),
  3682. Mtime: 0,
  3683. Price: it.Price,
  3684. WarehousingDetailId: it.WarehouseInfotId,
  3685. WarehouseOutDetailId: it.ID,
  3686. CancelOutDetailId: cancelInfo.ID,
  3687. ProductDate: it.ProductDate,
  3688. ExpireDate: it.ExpiryDate,
  3689. StorehouseId: houseConfig.StorehouseOutInfo,
  3690. OverCount: flush_count_one,
  3691. }
  3692. service.CreateStockFlowOne(flow)
  3693. //if flow.ID > 0 {
  3694. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3695. //}
  3696. }
  3697. }
  3698. //flow := models.VmStockFlow{
  3699. // WarehousingId: info.WarehouseInfotId,
  3700. // GoodId: item.ProjectId,
  3701. // Number: info.Number,
  3702. // LicenseNumber: info.LicenseNumber,
  3703. // Count: prescribingNumber,
  3704. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3705. // PatientId: item.PatientId,
  3706. // SystemTime: info.SysRecordTime,
  3707. // ConsumableType: 7,
  3708. // IsSys: 0,
  3709. // WarehousingOrder: "",
  3710. // WarehouseOutId: info.WarehouseOutId,
  3711. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3712. // IsEdit: 0,
  3713. // CancelStockId: cancel.ID,
  3714. // CancelOrderNumber: cancel.OrderNumber,
  3715. // Manufacturer: manufacturer.ID,
  3716. // Dealer: 0,
  3717. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3718. // UpdateCreator: 0,
  3719. // Status: 1,
  3720. // Ctime: time.Now().Unix(),
  3721. // Mtime: 0,
  3722. // Price: info.Price,
  3723. // WarehousingDetailId: info.WarehouseInfotId,
  3724. // WarehouseOutDetailId: info.ID,
  3725. // CancelOutDetailId: cancelInfo.ID,
  3726. // ProductDate: info.ProductDate,
  3727. // ExpireDate: info.ExpiryDate,
  3728. // StorehouseId: houseConfig.StorehouseOutInfo,
  3729. // OverCount: flush_count,
  3730. //}
  3731. //service.CreateStockFlowOne(flow)
  3732. //退库数量增加
  3733. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3734. //出库数量减少
  3735. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3736. //查询已出库数量
  3737. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3738. if prescribingNumber < dialysisInfo.Count {
  3739. //改变数量
  3740. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3741. }
  3742. if prescribingNumber >= dialysisInfo.Count {
  3743. //删除出库表
  3744. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3745. }
  3746. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3747. var flush_count_one int64
  3748. for _, it := range goodList {
  3749. flush_count_one += it.StockCount
  3750. }
  3751. //更新库存
  3752. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3753. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3754. //更新基础库库存
  3755. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3756. }
  3757. }
  3758. }
  3759. }
  3760. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3761. fmt.Println(err)
  3762. }
  3763. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3764. fmt.Println(err)
  3765. if len(advices) > 0 {
  3766. for _, item := range advices {
  3767. redis := service.RedisClient()
  3768. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3769. redis.Set(keyFive, "", time.Second)
  3770. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3771. redis.Set(keyOne, "", time.Second)
  3772. redis.Close()
  3773. }
  3774. }
  3775. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3776. if len(advices) > 0 {
  3777. for _, item := range advices {
  3778. creater := c.GetAdminUserInfo().AdminUser.Id
  3779. service.DrugAutoAddCancelInfo(item, creater)
  3780. }
  3781. }
  3782. } else {
  3783. if drugOutConfig.IsOpen == 1 {
  3784. if len(advices) > 0 {
  3785. for _, item := range advices {
  3786. creater := c.GetAdminUserInfo().AdminUser.Id
  3787. service.DrugAutoAddCancelInfo(item, creater)
  3788. }
  3789. }
  3790. } else {
  3791. if len(advices) > 0 {
  3792. for _, item := range advices {
  3793. creater := c.GetAdminUserInfo().AdminUser.Id
  3794. service.DrugAutoAddCancelInfo(item, creater)
  3795. }
  3796. }
  3797. }
  3798. }
  3799. c.ServeSuccessJSON(map[string]interface{}{
  3800. "msg": "删除成功",
  3801. })
  3802. return
  3803. }
  3804. func (c *HisApiController) DeleteDoctorAdvice() {
  3805. id, _ := c.GetInt64("id")
  3806. advice, _ := service.GetHisDoctorAdvicesById(id)
  3807. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3808. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3809. //已收费和已发药的限制逻辑
  3810. isCharge := false
  3811. isMedicine := false
  3812. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3813. //获取今天该患者所有处方,判断是否发药或者收费
  3814. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3815. for _, item := range new_prescriptions {
  3816. if item.IsMedicine == 1 {
  3817. isMedicine = true
  3818. }
  3819. }
  3820. for _, item := range new_prescriptions {
  3821. if item.OrderStatus == 4 {
  3822. isCharge = true
  3823. }
  3824. }
  3825. if isMedicine {
  3826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3827. return
  3828. }
  3829. if isCharge {
  3830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3831. return
  3832. }
  3833. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3834. for _, item := range advices {
  3835. if item.IsMedicine == 1 {
  3836. isMedicine = true
  3837. }
  3838. }
  3839. if isMedicine {
  3840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3841. return
  3842. }
  3843. if new_prescription.ID > 0 {
  3844. if new_prescription.OrderStatus == 2 {
  3845. isCharge = true
  3846. }
  3847. }
  3848. if isCharge {
  3849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3850. return
  3851. }
  3852. //已收费和已发药的限制逻辑
  3853. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3854. redis := service.RedisClient()
  3855. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3856. redis.Set(keyFive, "", time.Second)
  3857. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3858. redis.Set(keyOne, "", time.Second)
  3859. defer redis.Close()
  3860. if err == nil {
  3861. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3862. //查询是否在处方中出库
  3863. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3864. if openConfig.IsOpen != 1 {
  3865. //判断该医嘱是否执行了
  3866. if advice.ExecutionState == 1 {
  3867. creater := c.GetAdminUserInfo().AdminUser.Id
  3868. service.DrugAutoAddCancelInfo(&advice, creater)
  3869. }
  3870. }
  3871. //开启保存处方扣减功能
  3872. if openConfig.IsOpen == 1 {
  3873. creater := c.GetAdminUserInfo().AdminUser.Id
  3874. service.DrugAutoAddCancelInfo(&advice, creater)
  3875. }
  3876. } else {
  3877. if drugOutConfig.IsOpen == 1 {
  3878. //查询是否在处方中出库
  3879. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3880. if openConfig.IsOpen != 1 {
  3881. //判断该医嘱是否执行了
  3882. if advice.ExecutionState == 1 {
  3883. creater := c.GetAdminUserInfo().AdminUser.Id
  3884. service.DrugAutoAddCancelInfo(&advice, creater)
  3885. }
  3886. }
  3887. //开启保存处方扣减功能
  3888. if openConfig.IsOpen == 1 {
  3889. creater := c.GetAdminUserInfo().AdminUser.Id
  3890. service.DrugAutoAddCancelInfo(&advice, creater)
  3891. }
  3892. } else {
  3893. //判断该医嘱是否执行了
  3894. if advice.ExecutionState == 1 {
  3895. creater := c.GetAdminUserInfo().AdminUser.Id
  3896. service.DrugAutoAddCancelInfo(&advice, creater)
  3897. }
  3898. }
  3899. }
  3900. c.ServeSuccessJSON(map[string]interface{}{
  3901. "msg": "删除成功",
  3902. })
  3903. return
  3904. } else {
  3905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3906. return
  3907. }
  3908. }
  3909. func (c *HisApiController) DeleteProject() {
  3910. id, _ := c.GetInt64("id")
  3911. adminInfo := c.GetAdminUserInfo()
  3912. project, _ := service.GetHisProjectByID(id)
  3913. // var consumable models.DialysisBeforePrepare
  3914. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3915. //耗材保存处方出库
  3916. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3917. isCharge := false
  3918. isMedicine := false
  3919. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3920. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3921. for _, item := range new_prescriptions {
  3922. if item.IsMedicine == 1 {
  3923. isMedicine = true
  3924. }
  3925. }
  3926. for _, item := range new_prescriptions {
  3927. if item.OrderStatus == 4 {
  3928. isCharge = true
  3929. }
  3930. }
  3931. if isMedicine {
  3932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3933. return
  3934. }
  3935. if isCharge {
  3936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3937. return
  3938. }
  3939. if new_prescription.ID > 0 {
  3940. if new_prescription.OrderStatus == 2 {
  3941. isCharge = true
  3942. }
  3943. }
  3944. if isCharge {
  3945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3946. return
  3947. }
  3948. service.DeletePrintInfo(id)
  3949. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3950. label.Status = 0
  3951. service.CreateHisLabelRecord(&label)
  3952. fmt.Println(goodOutConfig.IsOpen)
  3953. if goodOutConfig.IsOpen != 1 {
  3954. if stockConfig.IsOpen == 1 {
  3955. if project.Type == 2 {
  3956. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3957. fmt.Println(err)
  3958. }
  3959. if project.Type == 3 && project.IsOut == 1 {
  3960. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3961. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3962. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3963. operation_time := time.Now().Unix()
  3964. creater := adminInfo.AdminUser.Id
  3965. //创建退库单
  3966. timeStr := time.Now().Format("2006-01-02")
  3967. timeArr := strings.Split(timeStr, "-")
  3968. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3969. total = total + 1
  3970. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3971. cancelStock := models.CancelStock{
  3972. OrderNumber: orderNumber,
  3973. OperaTime: operation_time,
  3974. OrgId: adminInfo.CurrentOrgId,
  3975. Creater: creater,
  3976. Ctime: time.Now().Unix(),
  3977. Status: 1,
  3978. ReturnTime: project.RecordDate,
  3979. Type: 1,
  3980. StorehouseId: houseConfig.StorehouseOutInfo,
  3981. IsCheck: 1,
  3982. }
  3983. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3984. if msgerrkonde == gorm.ErrRecordNotFound {
  3985. service.AddSigleCancelStock(&cancelStock)
  3986. }
  3987. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3988. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3989. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3990. //查询是否有出库
  3991. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3992. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3993. deaerler, _ := service.GetDealerById(info.Dealer)
  3994. if info.ID > 0 {
  3995. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3996. if info.Count >= prescribingNumber {
  3997. cancelStockInfo := models.CancelStockInfo{
  3998. GoodId: project.ProjectId,
  3999. CancelStockId: cancel.ID,
  4000. GoodTypeId: good.GoodTypeId,
  4001. Count: prescribingNumber,
  4002. Price: info.Price,
  4003. Total: 0,
  4004. ProductDate: info.ProductDate,
  4005. ExpiryDate: info.ExpiryDate,
  4006. Ctime: time.Now().Unix(),
  4007. Status: 1,
  4008. OrgId: adminInfo.CurrentOrgId,
  4009. OrderNumber: cancel.OrderNumber,
  4010. Type: 0,
  4011. Dealer: deaerler.DealerName,
  4012. Manufacturer: manufacturer.ManufacturerName,
  4013. Number: info.Number,
  4014. RegisterAccount: "",
  4015. Remark: "",
  4016. WarehouseInfoId: info.WarehouseInfotId,
  4017. PatientId: info.PatientId,
  4018. RecordDate: info.SysRecordTime,
  4019. StorehouseId: houseConfig.StorehouseOutInfo,
  4020. IsCheck: 1,
  4021. }
  4022. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4023. //回退库存
  4024. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4025. //退库数量增加
  4026. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4027. //出库数量减少
  4028. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4029. }
  4030. if info.Count < prescribingNumber {
  4031. cancelStockInfo := models.CancelStockInfo{
  4032. GoodId: project.ProjectId,
  4033. CancelStockId: cancel.ID,
  4034. GoodTypeId: good.GoodTypeId,
  4035. Count: info.Count,
  4036. Price: info.Price,
  4037. Total: 0,
  4038. ProductDate: info.ProductDate,
  4039. ExpiryDate: info.ExpiryDate,
  4040. Ctime: time.Now().Unix(),
  4041. Status: 1,
  4042. OrgId: adminInfo.CurrentOrgId,
  4043. OrderNumber: cancel.OrderNumber,
  4044. Type: 0,
  4045. Dealer: deaerler.DealerName,
  4046. Manufacturer: manufacturer.ManufacturerName,
  4047. Number: info.Number,
  4048. RegisterAccount: "",
  4049. Remark: "",
  4050. WarehouseInfoId: info.WarehouseInfotId,
  4051. PatientId: info.PatientId,
  4052. RecordDate: info.SysRecordTime,
  4053. StorehouseId: houseConfig.StorehouseOutInfo,
  4054. IsCheck: 1,
  4055. }
  4056. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4057. //回退库存
  4058. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4059. //退库数量增加
  4060. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4061. //出库数量减少
  4062. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4063. }
  4064. //查询剩余库存
  4065. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4066. var over_count int64
  4067. for _, it := range goodList {
  4068. over_count += it.StockCount
  4069. }
  4070. //出库数据 大于 退库数量
  4071. if info.Count >= prescribingNumber {
  4072. flow := models.VmStockFlow{
  4073. WarehousingId: info.WarehouseInfotId,
  4074. GoodId: project.ProjectId,
  4075. Number: info.Number,
  4076. LicenseNumber: info.LicenseNumber,
  4077. Count: prescribingNumber,
  4078. UserOrgId: adminInfo.CurrentOrgId,
  4079. PatientId: project.PatientId,
  4080. SystemTime: info.SysRecordTime,
  4081. ConsumableType: 7,
  4082. IsSys: 0,
  4083. WarehousingOrder: "",
  4084. WarehouseOutId: info.WarehouseOutId,
  4085. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4086. IsEdit: 0,
  4087. CancelStockId: cancel.ID,
  4088. CancelOrderNumber: cancel.OrderNumber,
  4089. Manufacturer: manufacturer.ID,
  4090. Dealer: 0,
  4091. Creator: adminInfo.AdminUser.Id,
  4092. UpdateCreator: 0,
  4093. Status: 1,
  4094. Ctime: time.Now().Unix(),
  4095. Mtime: 0,
  4096. Price: info.Price,
  4097. WarehousingDetailId: info.WarehouseInfotId,
  4098. WarehouseOutDetailId: info.ID,
  4099. CancelOutDetailId: cancelInfo.ID,
  4100. ProductDate: info.ProductDate,
  4101. ExpireDate: info.ExpiryDate,
  4102. StorehouseId: houseConfig.StorehouseOutInfo,
  4103. OverCount: over_count,
  4104. }
  4105. service.CreateStockFlowOne(flow)
  4106. }
  4107. //出库数据小于退库数据
  4108. if info.Count < prescribingNumber {
  4109. flow := models.VmStockFlow{
  4110. WarehousingId: info.WarehouseInfotId,
  4111. GoodId: project.ProjectId,
  4112. Number: info.Number,
  4113. LicenseNumber: info.LicenseNumber,
  4114. Count: info.Count,
  4115. UserOrgId: adminInfo.CurrentOrgId,
  4116. PatientId: project.PatientId,
  4117. SystemTime: info.SysRecordTime,
  4118. ConsumableType: 7,
  4119. IsSys: 0,
  4120. WarehousingOrder: "",
  4121. WarehouseOutId: info.WarehouseOutId,
  4122. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4123. IsEdit: 0,
  4124. CancelStockId: cancel.ID,
  4125. CancelOrderNumber: cancel.OrderNumber,
  4126. Manufacturer: manufacturer.ID,
  4127. Dealer: 0,
  4128. Creator: adminInfo.AdminUser.Id,
  4129. UpdateCreator: 0,
  4130. Status: 1,
  4131. Ctime: time.Now().Unix(),
  4132. Mtime: 0,
  4133. Price: info.Price,
  4134. WarehousingDetailId: info.WarehouseInfotId,
  4135. WarehouseOutDetailId: info.ID,
  4136. CancelOutDetailId: cancelInfo.ID,
  4137. ProductDate: info.ProductDate,
  4138. ExpireDate: info.ExpiryDate,
  4139. StorehouseId: houseConfig.StorehouseOutInfo,
  4140. OverCount: over_count,
  4141. }
  4142. service.CreateStockFlowOne(flow)
  4143. }
  4144. //查询已出库数量
  4145. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4146. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4147. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4148. if prescribingNumber < dialysisInfo.Count {
  4149. //改变数量
  4150. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4151. }
  4152. if prescribingNumber >= dialysisInfo.Count {
  4153. //删除出库表
  4154. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4155. }
  4156. //更新剩余库存
  4157. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4158. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4159. var total_count_one int64
  4160. for _, it := range stockList {
  4161. total_count_one += it.StockCount
  4162. }
  4163. //基础库插入数据
  4164. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4165. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4166. var flush_count int64
  4167. for _, it := range goodListOne {
  4168. flush_count += it.StockCount
  4169. }
  4170. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4171. if errs != nil {
  4172. goodErrcode := models.XtGoodErrcode{
  4173. UserOrgId: project.UserOrgId,
  4174. Errcode: "手动出库更新剩余出库失败",
  4175. GoodId: project.ProjectId,
  4176. Status: 1,
  4177. Ctime: time.Now().Unix(),
  4178. Mtime: 0,
  4179. Count: 0,
  4180. StockCount: 0,
  4181. Creater: creater,
  4182. BatchNumberId: 0,
  4183. WarehouseOutId: 0,
  4184. }
  4185. service.CreateGoodErrcode(goodErrcode)
  4186. }
  4187. }
  4188. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4189. fmt.Println(err)
  4190. } else {
  4191. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4192. fmt.Println(err)
  4193. }
  4194. } else {
  4195. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4196. fmt.Println(err)
  4197. }
  4198. }
  4199. //保存处方出库
  4200. if goodOutConfig.IsOpen == 1 {
  4201. if project.Type == 3 {
  4202. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4203. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4204. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4205. operation_time := time.Now().Unix()
  4206. creater := adminInfo.AdminUser.Id
  4207. //创建退库单
  4208. timeStr := time.Now().Format("2006-01-02")
  4209. timeArr := strings.Split(timeStr, "-")
  4210. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4211. total = total + 1
  4212. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4213. cancelStock := models.CancelStock{
  4214. OrderNumber: orderNumber,
  4215. OperaTime: operation_time,
  4216. OrgId: adminInfo.CurrentOrgId,
  4217. Creater: creater,
  4218. Ctime: time.Now().Unix(),
  4219. Status: 1,
  4220. ReturnTime: project.RecordDate,
  4221. Type: 1,
  4222. StorehouseId: houseConfig.StorehouseOutInfo,
  4223. IsCheck: 1,
  4224. }
  4225. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4226. if msgerrkonde == gorm.ErrRecordNotFound {
  4227. service.AddSigleCancelStock(&cancelStock)
  4228. }
  4229. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4230. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4231. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4232. //获取出库数据
  4233. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4234. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4235. deaerler, _ := service.GetDealerById(info.Dealer)
  4236. if info.ID > 0 {
  4237. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4238. if info.Count >= prescribingNumber {
  4239. cancelStockInfo := models.CancelStockInfo{
  4240. GoodId: project.ProjectId,
  4241. CancelStockId: cancel.ID,
  4242. GoodTypeId: good.GoodTypeId,
  4243. Count: prescribingNumber,
  4244. Price: info.Price,
  4245. Total: 0,
  4246. ProductDate: info.ProductDate,
  4247. ExpiryDate: info.ExpiryDate,
  4248. Ctime: time.Now().Unix(),
  4249. Status: 1,
  4250. OrgId: adminInfo.CurrentOrgId,
  4251. OrderNumber: cancel.OrderNumber,
  4252. Type: 0,
  4253. Dealer: deaerler.DealerName,
  4254. Manufacturer: manufacturer.ManufacturerName,
  4255. Number: info.Number,
  4256. RegisterAccount: "",
  4257. Remark: "",
  4258. WarehouseInfoId: info.WarehouseInfotId,
  4259. PatientId: info.PatientId,
  4260. RecordDate: info.SysRecordTime,
  4261. StorehouseId: houseConfig.StorehouseOutInfo,
  4262. IsCheck: 1,
  4263. }
  4264. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4265. //退库数量增加
  4266. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4267. //出库数量减少
  4268. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4269. }
  4270. if info.Count < prescribingNumber {
  4271. cancelStockInfo := models.CancelStockInfo{
  4272. GoodId: project.ProjectId,
  4273. CancelStockId: cancel.ID,
  4274. GoodTypeId: good.GoodTypeId,
  4275. Count: prescribingNumber,
  4276. Price: info.Price,
  4277. Total: 0,
  4278. ProductDate: info.ProductDate,
  4279. ExpiryDate: info.ExpiryDate,
  4280. Ctime: time.Now().Unix(),
  4281. Status: 1,
  4282. OrgId: adminInfo.CurrentOrgId,
  4283. OrderNumber: cancel.OrderNumber,
  4284. Type: 0,
  4285. Dealer: deaerler.DealerName,
  4286. Manufacturer: manufacturer.ManufacturerName,
  4287. Number: info.Number,
  4288. RegisterAccount: "",
  4289. Remark: "",
  4290. WarehouseInfoId: info.WarehouseInfotId,
  4291. PatientId: info.PatientId,
  4292. RecordDate: info.SysRecordTime,
  4293. StorehouseId: houseConfig.StorehouseOutInfo,
  4294. IsCheck: 1,
  4295. }
  4296. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4297. //回退库存
  4298. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4299. }
  4300. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4301. var over_count int64
  4302. for _, it := range goodList {
  4303. over_count += it.StockCount
  4304. }
  4305. //查询出库数量
  4306. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4307. //出库数据 大于 退库数量
  4308. if len(list) > 0 {
  4309. for _, it := range list {
  4310. //回退库存
  4311. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4312. //退库数量增加
  4313. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4314. //出库数量减少
  4315. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4316. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4317. var over_count_one int64
  4318. for _, it := range goodList {
  4319. over_count_one += it.StockCount
  4320. }
  4321. //查询该批次是否有退库数据
  4322. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4323. flow := models.VmStockFlow{
  4324. WarehousingId: it.WarehouseInfotId,
  4325. GoodId: it.GoodId,
  4326. Number: it.Number,
  4327. LicenseNumber: it.LicenseNumber,
  4328. Count: it.Count,
  4329. UserOrgId: adminInfo.CurrentOrgId,
  4330. PatientId: it.PatientId,
  4331. SystemTime: it.SysRecordTime,
  4332. ConsumableType: 7,
  4333. IsSys: 0,
  4334. WarehousingOrder: "",
  4335. WarehouseOutId: it.WarehouseOutId,
  4336. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4337. IsEdit: 0,
  4338. CancelStockId: cancel.ID,
  4339. CancelOrderNumber: cancel.OrderNumber,
  4340. Manufacturer: manufacturer.ID,
  4341. Dealer: 0,
  4342. Creator: adminInfo.AdminUser.Id,
  4343. UpdateCreator: 0,
  4344. Status: 1,
  4345. Ctime: time.Now().Unix(),
  4346. Mtime: 0,
  4347. Price: it.Price,
  4348. WarehousingDetailId: it.WarehouseInfotId,
  4349. WarehouseOutDetailId: it.ID,
  4350. CancelOutDetailId: cancelInfo.ID,
  4351. ProductDate: it.ProductDate,
  4352. ExpireDate: it.ExpiryDate,
  4353. StorehouseId: houseConfig.StorehouseOutInfo,
  4354. OverCount: over_count_one,
  4355. }
  4356. service.CreateStockFlowOne(flow)
  4357. }
  4358. }
  4359. //查询已出库数量
  4360. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4361. if prescribingNumber < dialysisInfo.Count {
  4362. //改变数量
  4363. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4364. }
  4365. if prescribingNumber >= dialysisInfo.Count {
  4366. //删除出库表
  4367. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4368. }
  4369. //更新剩余库存
  4370. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4371. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4372. var total_count_one int64
  4373. for _, it := range stockList {
  4374. total_count_one += it.StockCount
  4375. }
  4376. //基础库插入数据
  4377. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4378. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4379. var flush_count int64
  4380. for _, it := range goodListOne {
  4381. flush_count += it.StockCount
  4382. }
  4383. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4384. if errs != nil {
  4385. goodErrcode := models.XtGoodErrcode{
  4386. UserOrgId: project.UserOrgId,
  4387. Errcode: "手动出库更新剩余出库失败",
  4388. GoodId: project.ProjectId,
  4389. Status: 1,
  4390. Ctime: time.Now().Unix(),
  4391. Mtime: 0,
  4392. Count: 0,
  4393. StockCount: 0,
  4394. Creater: creater,
  4395. BatchNumberId: 0,
  4396. WarehouseOutId: 0,
  4397. }
  4398. service.CreateGoodErrcode(goodErrcode)
  4399. }
  4400. }
  4401. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4402. fmt.Println(err)
  4403. } else {
  4404. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4405. fmt.Println(err)
  4406. }
  4407. }
  4408. c.ServeSuccessJSON(map[string]interface{}{
  4409. "msg": "删除成功",
  4410. })
  4411. return
  4412. }
  4413. func (c *HisApiController) CreateHisAdditionalCharge() {
  4414. his_patient_id, _ := c.GetInt64("his_patient_id")
  4415. patient_id, _ := c.GetInt64("patient_id")
  4416. record_date := c.GetString("record_date")
  4417. timeLayout := "2006-01-02"
  4418. loc, _ := time.LoadLocation("Local")
  4419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4420. if err != nil {
  4421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4422. return
  4423. }
  4424. adminInfo := c.GetAdminUserInfo()
  4425. recordDateTime := theTime.Unix()
  4426. dataBody := make(map[string]interface{}, 0)
  4427. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4428. if err != nil {
  4429. utils.ErrorLog(err.Error())
  4430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4431. return
  4432. }
  4433. var additions []*models.HisAdditionalCharge
  4434. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4435. additions, _ := dataBody["addition"].([]interface{})
  4436. if len(additions) > 0 {
  4437. for _, item := range additions {
  4438. items := item.(map[string]interface{})
  4439. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4440. utils.ErrorLog("item_id")
  4441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4442. return
  4443. }
  4444. item_id := int64(items["item_id"].(float64))
  4445. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4446. utils.ErrorLog("item_name")
  4447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4448. return
  4449. }
  4450. item_name := items["item_name"].(string)
  4451. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4452. utils.ErrorLog("price")
  4453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4454. return
  4455. }
  4456. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4457. ctime := time.Now().Unix()
  4458. additional := &models.HisAdditionalCharge{
  4459. PatientId: patient_id,
  4460. HisPatientId: his_patient_id,
  4461. UserOrgId: adminInfo.CurrentOrgId,
  4462. RecordDate: recordDateTime,
  4463. CreatedTime: ctime,
  4464. UpdatedTime: ctime,
  4465. Modifier: adminInfo.AdminUser.Id,
  4466. Creator: adminInfo.AdminUser.Id,
  4467. Price: price,
  4468. ItemName: item_name,
  4469. ItemId: item_id,
  4470. Status: 1,
  4471. }
  4472. additions = append(additions, additional)
  4473. }
  4474. }
  4475. }
  4476. for _, item := range additions {
  4477. service.CreateAddtionalCharge(item)
  4478. }
  4479. c.ServeSuccessJSON(map[string]interface{}{
  4480. "msg": "创建成功",
  4481. })
  4482. }
  4483. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4484. blood_fat := c.GetString("blood_fat")
  4485. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4486. blood_sugar := c.GetString("blood_sugar")
  4487. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4488. chief_conplaint := c.GetString("chief_conplaint")
  4489. dbp := c.GetString("dbp")
  4490. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4491. delivery_way, _ := c.GetInt64("delivery_way")
  4492. diagnostic := c.GetString("diagnostic")
  4493. family_history := c.GetString("family_history")
  4494. height := c.GetString("height")
  4495. history_of_present_illness := c.GetString("history_of_present_illness")
  4496. is_infect, _ := c.GetInt64("is_infect")
  4497. past_history := c.GetString("past_history")
  4498. patient_id, _ := c.GetInt64("patient_id")
  4499. his_patient_id, _ := c.GetInt64("his_patient_id")
  4500. personal_history := c.GetString("personal_history")
  4501. pulse := c.GetString("pulse")
  4502. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4503. sbp := c.GetString("sbp")
  4504. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4505. heightfloat, _ := strconv.ParseFloat(height, 64)
  4506. sicktype := c.GetString("sick_type")
  4507. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4508. symptom := c.GetString("symptom")
  4509. sick_date := c.GetString("sick_date")
  4510. temperatures := c.GetString("temperature")
  4511. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4512. record_date := c.GetString("record_date")
  4513. breathing := c.GetString("breathing")
  4514. doctor_advice := c.GetString("doctor_advice")
  4515. remark := c.GetString("remark")
  4516. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4517. sick, _ := c.GetInt64("sick")
  4518. diagnose, _ := c.GetInt64("diagnose")
  4519. //id, _ := c.GetInt64("id")
  4520. timeLayout := "2006-01-02"
  4521. loc, _ := time.LoadLocation("Local")
  4522. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4523. allergic_history := c.GetString("allergic_history")
  4524. if err != nil {
  4525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4526. return
  4527. }
  4528. recordDateTime := theTime.Unix()
  4529. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4530. if err != nil {
  4531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4532. return
  4533. }
  4534. sickTimes := sickTime.Unix()
  4535. ctime := time.Now().Unix()
  4536. primary_disease := c.GetString("primary_disease")
  4537. confirm_failure_date := c.GetString("confirm_failure_date")
  4538. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4539. drug_allergy_history := c.GetString("drug_allergy_history")
  4540. physical_examination := c.GetString("physical_examination")
  4541. special_inspection := c.GetString("special_inspection")
  4542. lab_apparatus := c.GetString("lab_apparatus")
  4543. caseHistory := models.HisPatientCaseHistory{
  4544. HisPatientId: his_patient_id,
  4545. PatientId: patient_id,
  4546. Temperature: temperature,
  4547. BloodSugar: bloodsugarfloat,
  4548. Pulse: pulsefloat,
  4549. Sbp: sbpfloat,
  4550. Dbp: dbpfloat,
  4551. Height: heightfloat,
  4552. BloodFat: bloodfatfloat,
  4553. SickType: sick_type,
  4554. Symptom: symptom,
  4555. SickDate: sickTimes,
  4556. IsInfect: is_infect,
  4557. HistoryOfPresentIllness: history_of_present_illness,
  4558. PastHistory: past_history,
  4559. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4560. ChiefConplaint: chief_conplaint,
  4561. PersonalHistory: personal_history,
  4562. FamilyHistory: family_history,
  4563. Diagnostic: diagnostic,
  4564. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4565. Status: 1,
  4566. Ctime: ctime,
  4567. Mtime: ctime,
  4568. RecordDate: recordDateTime,
  4569. DeliveryWay: delivery_way,
  4570. Breathing: breathingfloat,
  4571. DoctorAdvice: doctor_advice,
  4572. Remark: remark,
  4573. Sick: sick,
  4574. Diagnose: diagnose,
  4575. AllergicHistory: allergic_history,
  4576. PrimaryDisease: primary_disease,
  4577. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4578. DrugAllergyHistory: drug_allergy_history,
  4579. PhysicalExamination: physical_examination,
  4580. SpecialInspection: special_inspection,
  4581. LabApparatus: lab_apparatus,
  4582. }
  4583. //查询该患者是否有病历
  4584. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4585. if errcodes == gorm.ErrRecordNotFound {
  4586. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4587. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4588. if err != nil {
  4589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4590. return
  4591. }
  4592. c.ServeSuccessJSON(map[string]interface{}{
  4593. "caseHistory": caseHistory,
  4594. "historyInfo": historyInfo,
  4595. })
  4596. return
  4597. } else if errcodes == nil {
  4598. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4599. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4600. if err != nil {
  4601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4602. return
  4603. }
  4604. c.ServeSuccessJSON(map[string]interface{}{
  4605. "caseHistory": caseHistory,
  4606. "historyInfo": historyInfo,
  4607. })
  4608. }
  4609. //查询该患者是否有病历
  4610. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4611. //if errcode == gorm.ErrRecordNotFound {
  4612. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4613. // if err != nil {
  4614. // c.ServeSuccessJSON(map[string]interface{}{
  4615. // "msg": "保存成功",
  4616. // })
  4617. // }
  4618. //} else if errcode == nil {
  4619. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4620. // return
  4621. //}
  4622. }
  4623. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4624. patient_id, _ := c.GetInt64("patient_id", 0)
  4625. adminUser := c.GetAdminUserInfo()
  4626. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4627. c.ServeSuccessJSON(map[string]interface{}{
  4628. "list": caseHistorys,
  4629. })
  4630. }
  4631. func (c *HisApiController) GetHisPatientCaseHistory() {
  4632. record_date, _ := c.GetInt64("record_date", 0)
  4633. patient_id, _ := c.GetInt64("patient_id", 0)
  4634. admin := c.GetAdminUserInfo()
  4635. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4636. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4637. c.ServeSuccessJSON(map[string]interface{}{
  4638. "info": info,
  4639. "case_history": case_history,
  4640. })
  4641. }
  4642. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4643. template_name := c.GetString("template_name")
  4644. template_remark := c.GetString("template_remark")
  4645. doctor := c.GetAdminUserInfo().AdminUser.Id
  4646. diagnostic := c.GetString("diagnostic")
  4647. chief_conplaint := c.GetString("chief_conplain")
  4648. history_of_present_illness := c.GetString("history_of_present_illness")
  4649. past_history := c.GetString("past_history")
  4650. personal_history := c.GetString("personal_history")
  4651. family_history := c.GetString("family_history")
  4652. user_name := c.GetString("user_name")
  4653. doctor_advice := c.GetString("doctor_advice")
  4654. remark := c.GetString("remark")
  4655. //record_date := c.GetString("record_date")
  4656. //fmt.Println("record_date--------",record_date)
  4657. //timeLayout := "2006-01-02"
  4658. //loc, _ := time.LoadLocation("Local")
  4659. //
  4660. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4661. //if err != nil {
  4662. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4663. // return
  4664. //}
  4665. //recordDateTime := theTime.Unix()
  4666. ctime := time.Now().Unix()
  4667. template := models.HisCaseHistoryTemplate{
  4668. HistoryOfPresentIllness: history_of_present_illness,
  4669. PastHistory: past_history,
  4670. ChiefConplaint: chief_conplaint,
  4671. PersonalHistory: personal_history,
  4672. FamilyHistory: family_history,
  4673. Diagnostic: diagnostic,
  4674. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4675. Status: 1,
  4676. Ctime: ctime,
  4677. Mtime: ctime,
  4678. RecordDate: time.Now().Unix(),
  4679. TemplateName: template_name,
  4680. TemplateRemark: template_remark,
  4681. Creator: doctor,
  4682. Modifier: doctor,
  4683. UserName: user_name,
  4684. DoctorAdvice: doctor_advice,
  4685. Remark: remark,
  4686. }
  4687. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4688. if err == nil {
  4689. c.ServeSuccessJSON(map[string]interface{}{
  4690. "msg": "保存成功",
  4691. })
  4692. } else {
  4693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4694. return
  4695. }
  4696. }
  4697. func (c *HisApiController) GetCaseHistoryTemplate() {
  4698. timeLayout := "2006-01-02"
  4699. loc, _ := time.LoadLocation("Local")
  4700. keyword := c.GetString("keyword")
  4701. start_time := c.GetString("start_time")
  4702. end_time := c.GetString("end_time")
  4703. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4704. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4705. admin := c.GetAdminUserInfo()
  4706. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4707. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4708. c.ServeSuccessJSON(map[string]interface{}{
  4709. "template": template,
  4710. //"history": history,
  4711. })
  4712. }
  4713. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4714. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4715. utils.ErrorLog("drug_name")
  4716. return enums.ErrorCodeParamWrong
  4717. }
  4718. adviceName, _ := json["drug_name"].(string)
  4719. if len(adviceName) == 0 {
  4720. utils.ErrorLog("len(advice_name) == 0")
  4721. return enums.ErrorCodeParamWrong
  4722. }
  4723. advice.AdviceName = adviceName
  4724. adviceDesc, _ := json["advice_desc"].(string)
  4725. advice.AdviceDesc = adviceDesc
  4726. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4727. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4728. advice.DrugSpec = drugSpec
  4729. }
  4730. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4731. remark, _ := json["remark"].(string)
  4732. advice.Remark = remark
  4733. }
  4734. if json["id"] == nil {
  4735. advice.DrugId = 0
  4736. } else {
  4737. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4738. drug_id := int64(json["id"].(float64))
  4739. advice.DrugId = drug_id
  4740. }
  4741. }
  4742. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4743. advice_id := int64(json["advice_id"].(float64))
  4744. advice.ID = advice_id
  4745. if advice.ID > 0 {
  4746. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4747. if err == nil {
  4748. if hisAdvice.ID > 0 {
  4749. advice.ExecutionTime = hisAdvice.ExecutionTime
  4750. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4751. advice.ExecutionState = hisAdvice.ExecutionState
  4752. advice.CheckTime = hisAdvice.CheckTime
  4753. advice.Checker = hisAdvice.Checker
  4754. advice.CheckState = hisAdvice.CheckState
  4755. advice.StartTime = hisAdvice.StartTime
  4756. advice.FeedetlSn = hisAdvice.FeedetlSn
  4757. }
  4758. }
  4759. }
  4760. }
  4761. //
  4762. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4763. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4764. // advice.ExecutionTime = execution_time
  4765. //}
  4766. //
  4767. //
  4768. //
  4769. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4770. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4771. // advice.ExecutionStaff = execution_staff
  4772. //}
  4773. //
  4774. //
  4775. //
  4776. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4777. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4778. // advice.ExecutionState = execution_state
  4779. //}
  4780. //
  4781. //
  4782. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4783. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4784. // advice.CheckTime = check_time
  4785. //}
  4786. //
  4787. //
  4788. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4789. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4790. // advice.CheckState = check_state
  4791. //}
  4792. //
  4793. //
  4794. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4795. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4796. // advice.Checker = checker
  4797. //}
  4798. //
  4799. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4800. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4801. // advice.StartTime = start_time
  4802. //}
  4803. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4804. drugSpecUnit, _ := json["min_unit"].(string)
  4805. advice.DrugSpecUnit = drugSpecUnit
  4806. }
  4807. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4808. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4809. advice.SingleDose = singleDose
  4810. }
  4811. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4812. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4813. advice.SingleDoseUnit = singleDoseUnit
  4814. }
  4815. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4816. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4817. advice.PrescribingNumber = prescribingNumber
  4818. }
  4819. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4820. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4821. advice.PrescribingNumberUnit = prescribingNumberUnit
  4822. }
  4823. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4824. deliveryWay, _ := json["delivery_way"].(string)
  4825. advice.DeliveryWay = deliveryWay
  4826. }
  4827. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4828. executionFrequency, _ := json["execution_frequency"].(string)
  4829. advice.ExecutionFrequency = executionFrequency
  4830. }
  4831. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4832. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4833. advice.Price = price
  4834. }
  4835. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4836. med_list_codg, _ := json["medical_insurance_number"].(string)
  4837. advice.MedListCodg = med_list_codg
  4838. }
  4839. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4840. day := int64(json["day"].(float64))
  4841. advice.Day = day
  4842. }
  4843. return 0
  4844. }
  4845. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4846. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4847. id := int64(json["id"].(float64))
  4848. project.ID = id
  4849. historyProject, _ := service.GetHisProjectByID(id)
  4850. project.FeedetlSn = historyProject.FeedetlSn
  4851. }
  4852. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4853. project_id := int64(json["project_id"].(float64))
  4854. project.ProjectId = project_id
  4855. }
  4856. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4857. // price := int64(json["price"].(float64))
  4858. // formatInt_price := strconv.FormatInt(price, 10)
  4859. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4860. // project.Price = float_price
  4861. // }
  4862. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4863. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4864. project.Price = price
  4865. }
  4866. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4867. total, _ := json["total"].(string)
  4868. project.Count = total
  4869. }
  4870. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4871. medical_code, _ := json["medical_code"].(string)
  4872. project.MedListCodg = medical_code
  4873. }
  4874. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4875. single_dose, _ := json["single_dose"].(string)
  4876. project.SingleDose = single_dose
  4877. }
  4878. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4879. delivery_way, _ := json["delivery_way"].(string)
  4880. project.DeliveryWay = delivery_way
  4881. }
  4882. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4883. execution_frequency, _ := json["execution_frequency"].(string)
  4884. project.ExecutionFrequency = execution_frequency
  4885. }
  4886. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4887. remark, _ := json["remark"].(string)
  4888. project.Remark = remark
  4889. }
  4890. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4891. day, _ := json["number_days"].(string)
  4892. project.Day = day
  4893. }
  4894. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4895. unit, _ := json["unit"].(string)
  4896. project.Unit = unit
  4897. }
  4898. return 0
  4899. }
  4900. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4901. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4902. id := int64(json["id"].(float64))
  4903. historyAddtions, _ := service.GetHisAdditionByID(id)
  4904. additionalCharge.ID = id
  4905. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4906. }
  4907. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4908. item_id := int64(json["item_id"].(float64))
  4909. additionalCharge.ItemId = item_id
  4910. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4911. if config.ID > 0 {
  4912. if len(config.Code) > 0 {
  4913. additionalCharge.MedListCodg = config.Code
  4914. }
  4915. }
  4916. }
  4917. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4918. // price := int64(json["price"].(float64))
  4919. // formatInt_price := strconv.FormatInt(price, 10)
  4920. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4921. // additionalCharge.Price = float_price
  4922. // }
  4923. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4924. // price := int64(json["price"].(float64))
  4925. // formatInt_price := strconv.FormatInt(price, 10)
  4926. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4927. // additionalCharge.Price = float_price
  4928. //}
  4929. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4930. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4931. additionalCharge.Price = price
  4932. }
  4933. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4934. count, _ := json["count"].(string)
  4935. counts, _ := strconv.ParseInt(count, 10, 64)
  4936. additionalCharge.Count = counts
  4937. }
  4938. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4939. item_name, _ := json["item_name"].(string)
  4940. additionalCharge.ItemName = item_name
  4941. }
  4942. return 0
  4943. }
  4944. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4945. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4946. utils.ErrorLog("drug_name")
  4947. return enums.ErrorCodeParamWrong
  4948. }
  4949. adviceName, _ := json["drug_name"].(string)
  4950. if len(adviceName) == 0 {
  4951. utils.ErrorLog("len(advice_name) == 0")
  4952. return enums.ErrorCodeParamWrong
  4953. }
  4954. advice.AdviceName = adviceName
  4955. adviceDesc, _ := json["advice_desc"].(string)
  4956. advice.AdviceDesc = adviceDesc
  4957. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4958. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4959. advice.DrugSpec = drugSpec
  4960. }
  4961. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4962. remark, _ := json["remark"].(string)
  4963. advice.Remark = remark
  4964. }
  4965. if json["id"] == nil {
  4966. advice.DrugId = 0
  4967. } else {
  4968. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4969. drug_id := int64(json["id"].(float64))
  4970. advice.DrugId = drug_id
  4971. }
  4972. }
  4973. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4974. groupno := int64(json["groupno"].(float64))
  4975. advice.Groupno = groupno
  4976. }
  4977. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4978. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4979. advice.HospApprFlag = hosp_appr_flag
  4980. }
  4981. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4982. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4983. advice.PrescribingNumber = prescribingNumber
  4984. }
  4985. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4986. // frequency_type := int64(json["frequency_type"].(float64))
  4987. // advice.FrequencyType = frequency_type
  4988. //}
  4989. //
  4990. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4991. // day_count := int64(json["day_count"].(float64))
  4992. // advice.DayCount = day_count
  4993. //}
  4994. //
  4995. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4996. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4997. // week_day, _ := json["week_day"].(string)
  4998. // advice.WeekDay = week_day
  4999. //}
  5000. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5001. drugSpecUnit, _ := json["min_unit"].(string)
  5002. advice.DrugSpecUnit = drugSpecUnit
  5003. }
  5004. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5005. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5006. advice.SingleDose = singleDose
  5007. }
  5008. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5009. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5010. advice.SingleDoseUnit = singleDoseUnit
  5011. }
  5012. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5013. deliveryWay, _ := json["delivery_way"].(string)
  5014. advice.DeliveryWay = deliveryWay
  5015. }
  5016. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5017. executionFrequency, _ := json["execution_frequency"].(string)
  5018. advice.ExecutionFrequency = executionFrequency
  5019. }
  5020. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5021. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5022. advice.Price = price
  5023. }
  5024. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5025. med_list_codg, _ := json["medical_insurance_number"].(string)
  5026. advice.MedListCodg = med_list_codg
  5027. }
  5028. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5029. day := int64(json["day"].(float64))
  5030. advice.Day = day
  5031. }
  5032. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5033. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5034. advice.PrescribingNumberUnit = prescribingNumberUnit
  5035. }
  5036. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5037. advice_id := int64(json["advice_id"].(float64))
  5038. advice.ID = advice_id
  5039. if advice.ID > 0 {
  5040. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5041. if err == nil {
  5042. if hisAdvice.ID > 0 {
  5043. advice.ExecutionTime = hisAdvice.ExecutionTime
  5044. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5045. advice.ExecutionState = hisAdvice.ExecutionState
  5046. advice.CheckTime = hisAdvice.CheckTime
  5047. advice.Checker = hisAdvice.Checker
  5048. advice.CheckState = hisAdvice.CheckState
  5049. advice.StartTime = hisAdvice.StartTime
  5050. advice.HospApprFlag = hisAdvice.HospApprFlag
  5051. advice.IsMedicine = hisAdvice.IsMedicine
  5052. if hisAdvice.UserOrgId == 10028 {
  5053. 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 {
  5054. advice.ExecutionTime = 0
  5055. advice.ExecutionStaff = 0
  5056. advice.ExecutionState = 2
  5057. advice.CheckTime = 0
  5058. advice.Checker = 0
  5059. advice.CheckState = 2
  5060. }
  5061. } else {
  5062. 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 {
  5063. advice.ExecutionTime = 0
  5064. advice.ExecutionStaff = 0
  5065. advice.ExecutionState = 2
  5066. advice.CheckTime = 0
  5067. advice.Checker = 0
  5068. advice.CheckState = 2
  5069. }
  5070. }
  5071. //advice.Groupno = hisAdvice.Groupno
  5072. }
  5073. }
  5074. }
  5075. }
  5076. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5077. //
  5078. //if drugStockConfig.IsOpen == 1 {
  5079. //
  5080. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5081. // if advice.ID == 0 { //医嘱不存在
  5082. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5083. // drug.Total = drug.Total - advice.PrescribingNumber
  5084. // service.UpdateBaseDrugLib(&drug)
  5085. //
  5086. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5087. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5088. // drug.Total = drug.Total - num
  5089. // service.UpdateBaseDrugLib(&drug)
  5090. // }
  5091. //
  5092. // } else if advice.ID > 0 { //医嘱存在
  5093. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5094. // var num float64
  5095. //
  5096. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5097. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5098. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5099. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5100. // drug.Total = drug.Total + num
  5101. // service.UpdateBaseDrugLib(&drug)
  5102. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5103. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5104. // drug.Total = drug.Total - num
  5105. // service.UpdateBaseDrugLib(&drug)
  5106. // }
  5107. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5108. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5109. // if num2 > advice.PrescribingNumber {
  5110. // num = num2 - advice.PrescribingNumber
  5111. // drug.Total = drug.Total + num
  5112. // service.UpdateBaseDrugLib(&drug)
  5113. // } else if num2 < advice.PrescribingNumber {
  5114. // num = advice.PrescribingNumber - num2
  5115. // drug.Total = drug.Total - num
  5116. // service.UpdateBaseDrugLib(&drug)
  5117. // }
  5118. //
  5119. // }
  5120. //
  5121. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5122. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5123. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5124. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5125. // if num1 > num2 {
  5126. // num = num1 - num2
  5127. // drug.Total = drug.Total + num
  5128. // service.UpdateBaseDrugLib(&drug)
  5129. // } else if num1 < num2 {
  5130. // num = num2 - num1
  5131. // drug.Total = drug.Total - num
  5132. // service.UpdateBaseDrugLib(&drug)
  5133. // }
  5134. //
  5135. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5136. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5137. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5138. // if hisAdvice.PrescribingNumber > num2 {
  5139. // num = hisAdvice.PrescribingNumber - num2
  5140. // drug.Total = drug.Total + num
  5141. // service.UpdateBaseDrugLib(&drug)
  5142. // } else if num2 < advice.PrescribingNumber {
  5143. // num = num2 - hisAdvice.PrescribingNumber
  5144. // drug.Total = drug.Total - num
  5145. // service.UpdateBaseDrugLib(&drug)
  5146. // }
  5147. //
  5148. // }
  5149. // }
  5150. // }
  5151. //}
  5152. //
  5153. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5154. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5155. // advice.ExecutionTime = execution_time
  5156. //}
  5157. //
  5158. //
  5159. //
  5160. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5161. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5162. // advice.ExecutionStaff = execution_staff
  5163. //}
  5164. //
  5165. //
  5166. //
  5167. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5168. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5169. // advice.ExecutionState = execution_state
  5170. //}
  5171. //
  5172. //
  5173. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5174. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5175. // advice.CheckTime = check_time
  5176. //}
  5177. //
  5178. //
  5179. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5180. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5181. // advice.CheckState = check_state
  5182. //}
  5183. //
  5184. //
  5185. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5186. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5187. // advice.Checker = checker
  5188. //}
  5189. //
  5190. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5191. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5192. // advice.StartTime = start_time
  5193. //}
  5194. return 0
  5195. }
  5196. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5197. project.ExecutionStaff = 0
  5198. project.ExecutionState = 2
  5199. project.ExecutionTime = 0
  5200. project.Checker = 0
  5201. project.CheckState = 2
  5202. project.CheckTime = 0
  5203. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5204. id := int64(json["id"].(float64))
  5205. project.ID = id
  5206. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5207. project.ExecutionStaff = temp_project.ExecutionStaff
  5208. project.ExecutionState = temp_project.ExecutionState
  5209. project.ExecutionTime = temp_project.ExecutionTime
  5210. project.Checker = temp_project.Checker
  5211. project.CheckState = temp_project.CheckState
  5212. project.CheckTime = temp_project.CheckTime
  5213. project.TeamId = temp_project.TeamId
  5214. }
  5215. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5216. types := int64(json["type"].(float64))
  5217. project.Type = types
  5218. }
  5219. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5220. project_id := int64(json["project_id"].(float64))
  5221. project.ProjectId = project_id
  5222. }
  5223. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5224. team_id := int64(json["team_id"].(float64))
  5225. project.TeamId = team_id
  5226. }
  5227. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5228. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5229. project.Price = price
  5230. }
  5231. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5232. total, _ := json["total"].(string)
  5233. //totals, _ := strconv.ParseInt(total, 10, 64)
  5234. project.Count = total
  5235. }
  5236. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5237. medical_code, _ := json["medical_code"].(string)
  5238. project.MedListCodg = medical_code
  5239. }
  5240. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5241. single_dose, _ := json["single_dose"].(string)
  5242. project.SingleDose = single_dose
  5243. }
  5244. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5245. delivery_way, _ := json["delivery_way"].(string)
  5246. project.DeliveryWay = delivery_way
  5247. }
  5248. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5249. execution_frequency, _ := json["execution_frequency"].(string)
  5250. project.ExecutionFrequency = execution_frequency
  5251. }
  5252. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5253. remark, _ := json["remark"].(string)
  5254. project.Remark = remark
  5255. }
  5256. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5257. day, _ := json["number_days"].(string)
  5258. project.Day = day
  5259. }
  5260. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5261. unit, _ := json["unit"].(string)
  5262. project.Unit = unit
  5263. }
  5264. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5265. // frequency_type := int64(json["frequency_type"].(float64))
  5266. // project.FrequencyType = frequency_type
  5267. //}
  5268. //
  5269. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5270. // day_count := int64(json["day_count"].(float64))
  5271. // project.DayCount = day_count
  5272. //}
  5273. //
  5274. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5275. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5276. // week_day, _ := json["week_day"].(string)
  5277. // project.WeekDay = week_day
  5278. //}
  5279. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5280. //
  5281. //if project.ID == 0 {
  5282. // if stockConfig.IsOpen == 1 {
  5283. // if project.Type == 3 {
  5284. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5285. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5286. // good.Total = good.Total - f_count
  5287. // service.UpdateGoodInfo(&good)
  5288. // }
  5289. // }
  5290. //
  5291. //} else {
  5292. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5293. //
  5294. // if stockConfig.IsOpen == 1 {
  5295. // if project.Type == 3 {
  5296. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5297. // if project.Count < temp_project.Count {
  5298. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5299. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5300. //
  5301. // other_count := f_count_two - f_count_one
  5302. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5303. // good.Total = good.Total + other_count_two
  5304. // service.UpdateGoodInfo(&good)
  5305. // } else if project.Count > temp_project.Count {
  5306. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5307. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5308. //
  5309. // other_count := f_count_one - f_count_two
  5310. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5311. // good.Total = good.Total - other_count_two
  5312. // service.UpdateGoodInfo(&good)
  5313. // }
  5314. //
  5315. // }
  5316. // }
  5317. //
  5318. //}
  5319. return 0
  5320. }
  5321. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5322. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5323. id := int64(json["id"].(float64))
  5324. additionalCharge.ID = id
  5325. }
  5326. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5327. item_id := int64(json["item_id"].(float64))
  5328. additionalCharge.ItemId = item_id
  5329. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5330. if config.ID > 0 {
  5331. if len(config.Code) > 0 {
  5332. additionalCharge.MedListCodg = config.Code
  5333. }
  5334. }
  5335. }
  5336. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5337. // price := int64(json["price"].(float64))
  5338. // formatInt_price := strconv.FormatInt(price, 10)
  5339. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5340. // additionalCharge.Price = float_price
  5341. // }
  5342. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5343. // price := int64(json["price"].(float64))
  5344. // formatInt_price := strconv.FormatInt(price, 10)
  5345. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5346. // additionalCharge.Price = float_price
  5347. //}
  5348. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5349. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5350. additionalCharge.Price = price
  5351. }
  5352. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5353. count, _ := json["count"].(string)
  5354. counts, _ := strconv.ParseInt(count, 10, 64)
  5355. additionalCharge.Count = counts
  5356. }
  5357. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5358. item_name, _ := json["item_name"].(string)
  5359. additionalCharge.ItemName = item_name
  5360. }
  5361. return 0
  5362. }
  5363. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5364. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5365. utils.ErrorLog("drug_name")
  5366. return enums.ErrorCodeParamWrong
  5367. }
  5368. adviceName, _ := json["drug_name"].(string)
  5369. if len(adviceName) == 0 {
  5370. utils.ErrorLog("len(advice_name) == 0")
  5371. return enums.ErrorCodeParamWrong
  5372. }
  5373. advice.AdviceName = adviceName
  5374. adviceDesc, _ := json["advice_desc"].(string)
  5375. advice.AdviceDesc = adviceDesc
  5376. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5377. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5378. advice.DrugSpec = drugSpec
  5379. }
  5380. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5381. remark, _ := json["remark"].(string)
  5382. advice.Remark = remark
  5383. }
  5384. if json["id"] == nil {
  5385. advice.DrugId = 0
  5386. } else {
  5387. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5388. drug_id := int64(json["id"].(float64))
  5389. advice.DrugId = drug_id
  5390. }
  5391. }
  5392. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5393. groupno := int64(json["groupno"].(float64))
  5394. advice.Groupno = groupno
  5395. }
  5396. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5397. drugSpecUnit, _ := json["min_unit"].(string)
  5398. advice.DrugSpecUnit = drugSpecUnit
  5399. }
  5400. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5401. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5402. advice.SingleDose = singleDose
  5403. }
  5404. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5405. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5406. advice.SingleDoseUnit = singleDoseUnit
  5407. }
  5408. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5409. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5410. advice.PrescribingNumber = prescribingNumber
  5411. }
  5412. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5413. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5414. advice.PrescribingNumberUnit = prescribingNumberUnit
  5415. }
  5416. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5417. deliveryWay, _ := json["delivery_way"].(string)
  5418. advice.DeliveryWay = deliveryWay
  5419. }
  5420. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5421. executionFrequency, _ := json["execution_frequency"].(string)
  5422. advice.ExecutionFrequency = executionFrequency
  5423. }
  5424. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5425. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5426. advice.Price = price
  5427. }
  5428. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5429. med_list_codg, _ := json["medical_insurance_number"].(string)
  5430. advice.MedListCodg = med_list_codg
  5431. }
  5432. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5433. day := int64(json["day"].(float64))
  5434. advice.Day = day
  5435. }
  5436. advice.FrequencyType = 1
  5437. return 0
  5438. }
  5439. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5440. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5441. types := int64(json["type"].(float64))
  5442. project.Type = types
  5443. }
  5444. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5445. project_id := int64(json["project_id"].(float64))
  5446. project.ProjectId = project_id
  5447. }
  5448. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5449. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5450. project.Price = price
  5451. }
  5452. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5453. total, _ := json["total"].(string)
  5454. //totals, _ := strconv.ParseInt(total, 10, 64)
  5455. project.Count = total
  5456. }
  5457. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5458. medical_code, _ := json["medical_code"].(string)
  5459. project.MedListCodg = medical_code
  5460. }
  5461. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5462. single_dose, _ := json["single_dose"].(string)
  5463. project.SingleDose = single_dose
  5464. }
  5465. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5466. delivery_way, _ := json["delivery_way"].(string)
  5467. project.DeliveryWay = delivery_way
  5468. }
  5469. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5470. execution_frequency, _ := json["execution_frequency"].(string)
  5471. project.ExecutionFrequency = execution_frequency
  5472. }
  5473. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5474. remark, _ := json["remark"].(string)
  5475. project.Remark = remark
  5476. }
  5477. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5478. day, _ := json["number_days"].(string)
  5479. project.Day = day
  5480. }
  5481. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5482. unit, _ := json["unit"].(string)
  5483. project.Unit = unit
  5484. }
  5485. project.FrequencyType = 1
  5486. return 0
  5487. }
  5488. func (c *HisApiController) GetHisOrderList() {
  5489. page, _ := c.GetInt64("page", -1)
  5490. limit, _ := c.GetInt64("limit", -1)
  5491. start_time := c.GetString("start_time")
  5492. end_time := c.GetString("end_time")
  5493. types, _ := c.GetInt64("type", 0)
  5494. keywords := c.GetString("keywords")
  5495. p_type, _ := c.GetInt64("p_type", 0)
  5496. sort_type, _ := c.GetInt64("sort_type", 0)
  5497. charge_type, _ := c.GetInt64("charge_type", 0)
  5498. sch_type, _ := c.GetInt64("sch_type", 0)
  5499. zone_type, _ := c.GetInt64("zone_type", 0)
  5500. med_type, _ := c.GetInt64("med_type", 0)
  5501. timeLayout := "2006-01-02"
  5502. loc, _ := time.LoadLocation("Local")
  5503. var startTime int64
  5504. if len(start_time) > 0 {
  5505. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5506. if err != nil {
  5507. //fmt.Println(err)
  5508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5509. return
  5510. }
  5511. startTime = theTime.Unix()
  5512. }
  5513. var endTime int64
  5514. if len(end_time) > 0 {
  5515. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5516. if err != nil {
  5517. utils.ErrorLog(err.Error())
  5518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5519. return
  5520. }
  5521. endTime = theTime.Unix()
  5522. }
  5523. adminUser := c.GetAdminUserInfo()
  5524. org_id := adminUser.CurrentOrgId
  5525. 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)
  5526. for _, item := range order {
  5527. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5528. item.DoctorName = info.Doctor
  5529. item.DepartmentName = info.XtHisDepartment.Name
  5530. }
  5531. if err == nil {
  5532. c.ServeSuccessJSON(map[string]interface{}{
  5533. "order": order,
  5534. "total": total,
  5535. })
  5536. } else {
  5537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5538. return
  5539. }
  5540. }
  5541. func (c *HisApiController) GetHisOrder() {
  5542. patient_id, _ := c.GetInt64("patient_id", 0)
  5543. number := c.GetString("number")
  5544. adminInfo := c.GetAdminUserInfo()
  5545. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5546. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5547. if err == nil {
  5548. c.ServeSuccessJSON(map[string]interface{}{
  5549. "order": order,
  5550. "prescription": prescriptions,
  5551. })
  5552. } else {
  5553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5554. return
  5555. }
  5556. }
  5557. func (c *HisApiController) GetHisPrescriptionList() {
  5558. record_date := c.GetString("record_date")
  5559. keywords := c.GetString("keywords")
  5560. page, _ := c.GetInt64("page")
  5561. limit, _ := c.GetInt64("limit")
  5562. sch_type, _ := c.GetInt64("sch_type")
  5563. timeLayout := "2006-01-02"
  5564. loc, _ := time.LoadLocation("Local")
  5565. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5566. if err != nil {
  5567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5568. return
  5569. }
  5570. recordDateTime := theTime.Unix()
  5571. adminInfo := c.GetAdminUserInfo()
  5572. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5573. //adminInfo := c.GetAdminUserInfo()
  5574. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5575. //fmt.Println(prescriptionOrder)
  5576. if err == nil {
  5577. c.ServeSuccessJSON(map[string]interface{}{
  5578. "order": prescriptionOrder,
  5579. "total": total,
  5580. })
  5581. } else {
  5582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5583. return
  5584. }
  5585. }
  5586. func (c *HisApiController) GetHisPrescriptionInfo() {
  5587. id, _ := c.GetInt64("id")
  5588. adminInfo := c.GetAdminUserInfo()
  5589. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5590. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5591. if err == nil {
  5592. c.ServeSuccessJSON(map[string]interface{}{
  5593. "order": prescriptionOrder,
  5594. "prescription": prescription,
  5595. })
  5596. } else {
  5597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5598. return
  5599. }
  5600. }
  5601. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5602. adminUser := c.GetAdminUserInfo()
  5603. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5604. c.ServeSuccessJSON(map[string]interface{}{
  5605. "config": config,
  5606. })
  5607. }
  5608. type ResultTwo struct {
  5609. ErrMsg interface{} `json:"err_msg"`
  5610. InfRefmsgid string `json:"inf_refmsgid"`
  5611. Infcode int64 `json:"infcode"`
  5612. Output struct {
  5613. Baseinfo struct {
  5614. Age float64 `json:"age"`
  5615. Brdy string `json:"brdy"`
  5616. Certno string `json:"certno"`
  5617. Gend string `json:"gend"`
  5618. Naty string `json:"naty"`
  5619. PsnCertType string `json:"psn_cert_type"`
  5620. PsnName string `json:"psn_name"`
  5621. PsnNo string `json:"psn_no"`
  5622. } `json:"baseinfo"`
  5623. Idetinfo []interface{} `json:"idetinfo"`
  5624. Iinfo []struct {
  5625. Balc float64 `json:"balc"`
  5626. CvlservFlag string `json:"cvlserv_flag"`
  5627. EmpName string `json:"emp_name"`
  5628. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5629. Insutype string `json:"insutype"`
  5630. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5631. PausInsuDate interface{} `json:"paus_insu_date"`
  5632. PsnInsuDate string `json:"psn_insu_date"`
  5633. PsnInsuStas string `json:"psn_insu_stas"`
  5634. PsnType string `json:"psn_type"`
  5635. } `json:"insuinfo"`
  5636. } `json:"output"`
  5637. RefmsgTime string `json:"refmsg_time"`
  5638. RespondTime string `json:"respond_time"`
  5639. Signtype interface{} `json:"signtype"`
  5640. WarnInfo interface{} `json:"warn_info"`
  5641. }
  5642. type ResultThree struct {
  5643. Cainfo interface{} `json:"cainfo"`
  5644. ErrMsg interface{} `json:"err_msg"`
  5645. InfRefmsgid string `json:"inf_refmsgid"`
  5646. Infcode int64 `json:"infcode"`
  5647. Output struct {
  5648. Data struct {
  5649. IptOtpNo string `json:"ipt_otp_no"`
  5650. MdtrtID string `json:"mdtrt_id"`
  5651. PsnNo string `json:"psn_no"`
  5652. } `json:"data"`
  5653. } `json:"output"`
  5654. RefmsgTime string `json:"refmsg_time"`
  5655. RespondTime string `json:"respond_time"`
  5656. Signtype interface{} `json:"signtype"`
  5657. WarnMsg interface{} `json:"warn_msg"`
  5658. }
  5659. type ResultFour struct {
  5660. Cainfo string `json:"cainfo"`
  5661. ErrMsg string `json:"err_msg"`
  5662. InfRefmsgid string `json:"inf_refmsgid"`
  5663. Infcode int64 `json:"infcode"`
  5664. Output struct {
  5665. Result []struct {
  5666. BasMednFlag string `json:"bas_medn_flag"`
  5667. ChldMedcFlag string `json:"chld_medc_flag"`
  5668. ChrgitmLv string `json:"chrgitm_lv"`
  5669. Cnt float64 `json:"cnt"`
  5670. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5671. DrtReimFlag string `json:"drt_reim_flag"`
  5672. FeedetlSn string `json:"feedetl_sn"`
  5673. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5674. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5675. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5676. ListSpItemFlag string `json:"list_sp_item_flag"`
  5677. LmtUsedFlag string `json:"lmt_used_flag"`
  5678. MedChrgitmType string `json:"med_chrgitm_type"`
  5679. Memo string `json:"memo"`
  5680. OverlmtAmt float64 `json:"overlmt_amt"`
  5681. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5682. Pric float64 `json:"pric"`
  5683. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5684. SelfpayProp float64 `json:"selfpay_prop"`
  5685. } `json:"result"`
  5686. } `json:"output"`
  5687. RefmsgTime string `json:"refmsg_time"`
  5688. RespondTime string `json:"respond_time"`
  5689. Signtype string `json:"signtype"`
  5690. WarnMsg string `json:"warn_msg"`
  5691. }
  5692. type ResultFive struct {
  5693. Insutype string `json:"insutype"`
  5694. }
  5695. type ResultSix struct {
  5696. Cainfo interface{} `json:"cainfo"`
  5697. ErrMsg interface{} `json:"err_msg"`
  5698. InfRefmsgid string `json:"inf_refmsgid"`
  5699. Infcode int64 `json:"infcode"`
  5700. Output struct {
  5701. } `json:"output"`
  5702. RefmsgTime string `json:"refmsg_time"`
  5703. RespondTime string `json:"respond_time"`
  5704. Signtype interface{} `json:"signtype"`
  5705. WarnMsg interface{} `json:"warn_msg"`
  5706. }
  5707. type ResultSeven struct {
  5708. Cainfo string `json:"cainfo"`
  5709. ErrMsg string `json:"err_msg"`
  5710. InfRefmsgid string `json:"inf_refmsgid"`
  5711. Infcode int64 `json:"infcode"`
  5712. Output struct {
  5713. Setldetail []interface{} `json:"setldetail"`
  5714. Setlinfo struct {
  5715. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5716. AcctPay float64 `json:"acct_pay"`
  5717. ActPayDedc float64 `json:"act_pay_dedc"`
  5718. Age float64 `json:"age"`
  5719. Balc float64 `json:"balc"`
  5720. Brdy string `json:"brdy"`
  5721. Certno string `json:"certno"`
  5722. ClrOptins string `json:"clr_optins"`
  5723. ClrType string `json:"clr_type"`
  5724. ClrWay string `json:"clr_way"`
  5725. CvlservFlag string `json:"cvlserv_flag"`
  5726. CvlservPay float64 `json:"cvlserv_pay"`
  5727. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5728. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5729. Gend string `json:"gend"`
  5730. HifesPay float64 `json:"hifes_pay"`
  5731. HifmiPay float64 `json:"hifmi_pay"`
  5732. HifobPay float64 `json:"hifob_pay"`
  5733. HifpPay float64 `json:"hifp_pay"`
  5734. HospPartAmt float64 `json:"hosp_part_amt"`
  5735. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5736. Insutype string `json:"insutype"`
  5737. MafPay float64 `json:"maf_pay"`
  5738. MdtrtCertType string `json:"mdtrt_cert_type"`
  5739. MdtrtID string `json:"mdtrt_id"`
  5740. MedType string `json:"med_type"`
  5741. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5742. MedinsSetlID string `json:"medins_setl_id"`
  5743. Naty string `json:"naty"`
  5744. OthPay float64 `json:"oth_pay"`
  5745. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5746. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5747. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5748. PsnCashPay float64 `json:"psn_cash_pay"`
  5749. PsnCertType string `json:"psn_cert_type"`
  5750. PsnName string `json:"psn_name"`
  5751. PsnNo string `json:"psn_no"`
  5752. PsnPartAmt float64 `json:"psn_part_amt"`
  5753. PsnType string `json:"psn_type"`
  5754. SetlID string `json:"setl_id"`
  5755. SetlTime string `json:"setl_time"`
  5756. } `json:"setlinfo"`
  5757. } `json:"output"`
  5758. RefmsgTime string `json:"refmsg_time"`
  5759. RespondTime string `json:"respond_time"`
  5760. Signtype interface{} `json:"signtype"`
  5761. WarnMsg interface{} `json:"warn_msg"`
  5762. }
  5763. type ResultEight struct {
  5764. Cainfo string `json:"cainfo"`
  5765. ErrMsg string `json:"err_msg"`
  5766. InfRefmsgid string `json:"inf_refmsgid"`
  5767. Infcode int64 `json:"infcode"`
  5768. Output struct {
  5769. Stmtinfo struct {
  5770. SetlOptins string `json:"setl_optins"`
  5771. StmtRslt string `json:"stmt_rslt"`
  5772. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5773. } `json:"stmtinfo"`
  5774. } `json:"output"`
  5775. RefmsgTime string `json:"refmsg_time"`
  5776. RespondTime string `json:"respond_time"`
  5777. Signtype interface{} `json:"signtype"`
  5778. WarnMsg interface{} `json:"warn_msg"`
  5779. }
  5780. type ResultNine struct {
  5781. Cainfo string `json:"cainfo"`
  5782. ErrMsg string `json:"err_msg"`
  5783. InfRefmsgid string `json:"inf_refmsgid"`
  5784. Infcode int64 `json:"infcode"`
  5785. Output struct {
  5786. FileQuryNo string `json:"file_qury_no"`
  5787. } `json:"output"`
  5788. RefmsgTime string `json:"refmsg_time"`
  5789. RespondTime string `json:"respond_time"`
  5790. Signtype interface{} `json:"signtype"`
  5791. WarnMsg interface{} `json:"warn_msg"`
  5792. }
  5793. type ResultTen struct {
  5794. Cainfo string `json:"cainfo"`
  5795. ErrMsg string `json:"err_msg"`
  5796. InfRefmsgid string `json:"inf_refmsgid"`
  5797. Infcode int64 `json:"infcode"`
  5798. Output struct {
  5799. DldEndtime string `json:"dld_endtime"`
  5800. FileQuryNo string `json:"file_qury_no"`
  5801. Filename string `json:"filename"`
  5802. } `json:"output"`
  5803. RefmsgTime string `json:"refmsg_time"`
  5804. RespondTime string `json:"respond_time"`
  5805. Signtype interface{} `json:"signtype"`
  5806. WarnMsg interface{} `json:"warn_msg"`
  5807. }
  5808. type ResultEleven struct {
  5809. Cainfo string `json:"cainfo"`
  5810. ErrMsg string `json:"err_msg"`
  5811. InfRefmsgid string `json:"inf_refmsgid"`
  5812. Infcode int64 `json:"infcode"`
  5813. Output struct {
  5814. Setlinfo struct {
  5815. FixmedinsName string `json:"fixmedins_name"`
  5816. FixmedinsCode string `json:"fixmedins_code"`
  5817. PsnNo string `json:"psn_no"`
  5818. PsnName string `json:"psn_name"`
  5819. HifobPay float64 `json:"hifob_pay"`
  5820. Gend string `json:"gend"`
  5821. Brdy string `json:"brdy"`
  5822. PsnCertType string `json:"psn_cert_type"`
  5823. PsnType string `json:"psn_type"`
  5824. EmpName string `json:"emp_name"`
  5825. Certno string `json:"certno"`
  5826. Insutype string `json:"insutype"`
  5827. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5828. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5829. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5830. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5831. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5832. ActPayDedc float64 `json:"act_pay_dedc"`
  5833. HifpPay float64 `json:"hifp_pay"`
  5834. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5835. CvlservPay float64 `json:"cvlserv_pay"`
  5836. HifesPay float64 `json:"hifes_pay"`
  5837. HifmiPay float64 `json:"hifmi_pay"`
  5838. MafPay float64 `json:"maf_pay"`
  5839. OthPay float64 `json:"oth_pay"`
  5840. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5841. PsnPay float64 `json:"psn_pay"`
  5842. AcctPay float64 `json:"acct_pay"`
  5843. CashPayamt float64 `json:"cash_payamt"`
  5844. Balc float64 `json:"balc"`
  5845. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5846. MedinsSetlId string `json:"medins_setl_id"`
  5847. RefdSetlFlag string `json:"refd_setl_flag"`
  5848. SetlTime string `json:"setl_time"`
  5849. MedType string `json:"med_type"`
  5850. } `json:"setlinfo"`
  5851. } `json:"output"`
  5852. RefmsgTime string `json:"refmsg_time"`
  5853. RespondTime string `json:"respond_time"`
  5854. Signtype interface{} `json:"signtype"`
  5855. WarnMsg interface{} `json:"warn_msg"`
  5856. }
  5857. type Custom struct {
  5858. DetItemFeeSumamt string
  5859. Cut string
  5860. FeedetlSn string
  5861. Price string
  5862. MedListCodg string
  5863. Type int64
  5864. AdviceId int64
  5865. ProjectId int64
  5866. ItemId int64
  5867. }
  5868. // 获取个人信息----挂号-----上传就诊信息
  5869. func (c *HisApiController) GetRegisterInfo() {
  5870. id, _ := c.GetInt64("id")
  5871. record_time := c.GetString("record_time")
  5872. settlementValue, _ := c.GetInt64("settlement_value")
  5873. medical_insurance_card := c.GetString("medical_insurance_card")
  5874. name := c.GetString("name")
  5875. id_card_type, _ := c.GetInt64("id_card_type")
  5876. certificates, _ := c.GetInt64("certificates")
  5877. medical_care, _ := c.GetInt64("medical_care")
  5878. birthday := c.GetString("birthday")
  5879. age, _ := c.GetInt64("age")
  5880. id_card := c.GetString("id_card")
  5881. register_type, _ := c.GetInt64("register")
  5882. doctor, _ := c.GetInt64("doctor")
  5883. department, _ := c.GetInt64("department")
  5884. gender, _ := c.GetInt64("sex")
  5885. phone := c.GetString("phone")
  5886. registration_fee, _ := c.GetFloat("registration_fee")
  5887. medical_expenses, _ := c.GetFloat("medical_expenses")
  5888. social_type, _ := c.GetInt64("social_type")
  5889. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5890. diagnosis_ids := c.GetString("diagnosis")
  5891. sick_type, _ := c.GetInt64("sick_type")
  5892. reg_type := c.GetString("p_type")
  5893. timeLayout := "2006-01-02"
  5894. loc, _ := time.LoadLocation("Local")
  5895. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5896. birthUnix := birthdays.Unix()
  5897. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5898. if err != nil {
  5899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5900. return
  5901. }
  5902. recordDateTime := theTime.Unix()
  5903. adminInfo := c.GetAdminUserInfo()
  5904. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5905. if tempPatient.ID == 0 {
  5906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5907. return
  5908. }
  5909. var patient service.Patients
  5910. if id == 0 {
  5911. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5912. } else {
  5913. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5914. }
  5915. if patient.ID == 0 {
  5916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5917. return
  5918. }
  5919. if len(patient.IdCardNo) == 0 {
  5920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5921. return
  5922. }
  5923. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5924. if len(his) >= 1 {
  5925. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5926. if len(his) >= 1 && order.ID == 0 {
  5927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5928. return
  5929. }
  5930. }
  5931. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5932. fmt.Println(timeStr)
  5933. timeArr := strings.Split(timeStr, " ")
  5934. fmt.Println(timeArr)
  5935. timeArrTwo := strings.Split(timeArr[0], "-")
  5936. timeArrThree := strings.Split(timeArr[1], ":")
  5937. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5938. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5939. if len(lists) == 0 {
  5940. var hisPatient models.XtHisPatient
  5941. hisPatient = models.XtHisPatient{
  5942. Name: name,
  5943. Age: age,
  5944. Gender: gender,
  5945. Birthday: birthUnix,
  5946. Phone: phone,
  5947. MedicalTreatmentType: medical_care,
  5948. IdType: certificates,
  5949. IdCardNo: id_card,
  5950. BalanceAccountsType: settlementValue,
  5951. SocialType: social_type,
  5952. MedicalInsuranceNumber: medical_insurance_card,
  5953. RegisterType: register_type,
  5954. RegisterCost: registration_fee,
  5955. TreatmentCost: medical_expenses,
  5956. AdminUserId: adminInfo.AdminUser.Id,
  5957. UserOrgId: adminInfo.CurrentOrgId,
  5958. Status: 1,
  5959. RecordDate: recordDateTime,
  5960. IsReturn: 1,
  5961. PatientId: patient.ID,
  5962. Ctime: time.Now().Unix(),
  5963. Mtime: time.Now().Unix(),
  5964. Number: str,
  5965. IdCardType: id_card_type,
  5966. Departments: department,
  5967. Doctor: doctor,
  5968. PType: reg_type,
  5969. Diagnosis: diagnosis_ids,
  5970. SickType: sick_type,
  5971. }
  5972. service.CreateHisPatient(&hisPatient)
  5973. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5974. c.ServeSuccessJSON(map[string]interface{}{
  5975. "his_info": hisPatient,
  5976. })
  5977. } else {
  5978. //chrgBchno := rand.Intn(1000000) + 10000
  5979. var hisPatient models.XtHisPatient
  5980. hisPatient = models.XtHisPatient{
  5981. Name: name,
  5982. Age: age,
  5983. Gender: gender,
  5984. Birthday: birthUnix,
  5985. Phone: phone,
  5986. MedicalTreatmentType: medical_care,
  5987. IdType: certificates,
  5988. IdCardNo: id_card,
  5989. BalanceAccountsType: settlementValue,
  5990. SocialType: social_type,
  5991. MedicalInsuranceNumber: medical_insurance_card,
  5992. RegisterType: register_type,
  5993. RegisterCost: registration_fee,
  5994. TreatmentCost: medical_expenses,
  5995. AdminUserId: adminInfo.AdminUser.Id,
  5996. UserOrgId: adminInfo.CurrentOrgId,
  5997. Status: 1,
  5998. RecordDate: recordDateTime,
  5999. IsReturn: 1,
  6000. PatientId: patient.ID,
  6001. Ctime: time.Now().Unix(),
  6002. Mtime: time.Now().Unix(),
  6003. Number: str,
  6004. IdCardType: id_card_type,
  6005. Departments: department,
  6006. Doctor: doctor,
  6007. PType: reg_type,
  6008. Diagnosis: diagnosis_ids,
  6009. SickType: sick_type,
  6010. }
  6011. service.CreateHisPatient(&hisPatient)
  6012. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6013. c.ServeSuccessJSON(map[string]interface{}{
  6014. "his_info": hisPatient,
  6015. })
  6016. }
  6017. }
  6018. // 上传明细----结算
  6019. func (c *HisApiController) GetUploadInfo() {
  6020. id, _ := c.GetInt64("id")
  6021. record_time := c.GetString("record_time")
  6022. his_patient_id, _ := c.GetInt64("his_patient_id")
  6023. oth_desc := c.GetString("oth_desc")
  6024. pay_way, _ := c.GetInt64("pay_way")
  6025. pay_ways := c.GetString("pay_ways")
  6026. pay_price, _ := c.GetFloat("pay_price")
  6027. pay_card_no := c.GetString("pay_card_no")
  6028. discount_price, _ := c.GetFloat("discount_price")
  6029. preferential_price, _ := c.GetFloat("preferential_price")
  6030. reality_price, _ := c.GetFloat("reality_price")
  6031. found_price, _ := c.GetFloat("found_price")
  6032. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6033. private_price, _ := c.GetFloat("private_price")
  6034. timeLayout := "2006-01-02"
  6035. loc, _ := time.LoadLocation("Local")
  6036. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6037. fapiao_code := c.GetString("fapiao_code")
  6038. fapiao_number := c.GetString("fapiao_number")
  6039. diagnosis_id := c.GetString("diagnosis")
  6040. sick_type, _ := c.GetInt64("sick_type")
  6041. reg_type, _ := c.GetInt64("p_type")
  6042. order_id, _ := c.GetInt64("order_id")
  6043. cash_pay := c.GetString("cash_pay")
  6044. wechat_pay := c.GetString("wechat_pay")
  6045. ali_pay := c.GetString("ali_pay")
  6046. jifen_pay := c.GetString("jifen_pay")
  6047. band_card_pay := c.GetString("band_card_pay")
  6048. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6049. tmp_decimal := c.GetString("tmp_decimal")
  6050. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6051. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  6052. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  6053. fmt.Println(count)
  6054. var zero string
  6055. number := count + 1
  6056. if number >= 1000 {
  6057. zero = "0000" + strconv.FormatInt(number, 10)
  6058. } else if number >= 10000 {
  6059. zero = "000" + strconv.FormatInt(number, 10)
  6060. } else if number >= 100000 {
  6061. zero = "00" + strconv.FormatInt(number, 10)
  6062. } else if number >= 1000000 {
  6063. zero = "0" + strconv.FormatInt(number, 10)
  6064. } else {
  6065. zero = strconv.FormatInt(number, 10)
  6066. }
  6067. fapiao_number = zero
  6068. var decimal float64 //本次使用的押金
  6069. var errmsg error
  6070. tx := service.XTWriteDB().Begin() //开了事务
  6071. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6072. defer func() {
  6073. if errmsg != nil {
  6074. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6075. tx.Rollback()
  6076. } else {
  6077. tx.Commit()
  6078. }
  6079. }()
  6080. fmt.Println("dec_way", dec_way)
  6081. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6082. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6083. return
  6084. }
  6085. if len(tmp_decimal) > 0 {
  6086. if tmp_decimal[0] == 45 {
  6087. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6088. return
  6089. }
  6090. }
  6091. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6092. fmt.Println(errs)
  6093. decimal = tt
  6094. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6095. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6096. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6097. if err != nil {
  6098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6099. return
  6100. }
  6101. recordDateTime := theTime.Unix()
  6102. adminUser := c.GetAdminUserInfo()
  6103. var prescriptions []*models.HisPrescription
  6104. var prescriptionsOne []*models.HisPrescription
  6105. var start_time int64
  6106. var end_time int64
  6107. ids_str := c.GetString("ids")
  6108. ids_arr := strings.Split(ids_str, ",")
  6109. if tempOrder.ID == 0 {
  6110. if settle_accounts_type == 1 { //日结
  6111. fmt.Println(reg_type)
  6112. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6113. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6114. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6115. } else {
  6116. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6117. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6118. }
  6119. } else { //月结
  6120. start_time_str := c.GetString("start_time")
  6121. end_time_str := c.GetString("end_time")
  6122. timeLayout := "2006-01-02"
  6123. loc, _ := time.LoadLocation("Local")
  6124. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6125. if err != nil {
  6126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6127. return
  6128. }
  6129. recordStartTime := theStartTime.Unix()
  6130. start_time = recordStartTime
  6131. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6132. if err != nil {
  6133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6134. return
  6135. }
  6136. recordEndTime := theEndTime.Unix()
  6137. end_time = recordEndTime
  6138. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6139. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6140. }
  6141. var goods []*models.DialysisBeforePrepareGoods
  6142. var newGoods []*models.NewDialysisBeforePrepareGoods
  6143. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6144. var infos []*models.HisDoctorAdviceInfo
  6145. var infoList []*models.HisDoctorAdviceInfo
  6146. var hisAdvice []*models.HisDoctorAdviceInfo
  6147. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6148. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6149. //判断库存不足
  6150. //结算出库开关
  6151. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6152. if settConfig.IsOpen == 1 {
  6153. //判断库存的地方
  6154. for _, info := range prescriptions {
  6155. if info.Type == 1 {
  6156. infos = append(infos, info.HisDoctorAdviceInfo...)
  6157. }
  6158. if info.Type == 2 {
  6159. for _, sumItem := range info.HisPrescriptionProject {
  6160. if sumItem.Type == 3 {
  6161. var good models.DialysisBeforePrepareGoods
  6162. var newGood models.NewDialysisBeforePrepareGoods
  6163. good.GoodId = sumItem.GoodInfo.ID
  6164. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6165. count, _ := strconv.Atoi(sumItem.Count)
  6166. good.Count = int64(count)
  6167. good.StorehouseId = houseConfig.StorehouseOutInfo
  6168. good.ProjectId = sumItem.ID
  6169. goods = append(goods, &good)
  6170. newGood.GoodId = sumItem.GoodInfo.ID
  6171. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6172. count2, _ := strconv.Atoi(sumItem.Count)
  6173. newGood.Count = int64(count2)
  6174. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6175. newGood.ProjectId = sumItem.ID
  6176. newGoods = append(newGoods, &newGood)
  6177. }
  6178. }
  6179. }
  6180. }
  6181. for _, info := range prescriptionsOne {
  6182. if info.Type == 1 {
  6183. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6184. }
  6185. if info.Type == 2 {
  6186. for _, sumItem := range info.HisPrescriptionProject {
  6187. if sumItem.Type == 3 {
  6188. var newGood models.NewDialysisBeforePrepareGoods
  6189. newGood.GoodId = sumItem.GoodInfo.ID
  6190. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6191. count2, _ := strconv.Atoi(sumItem.Count)
  6192. newGood.Count = int64(count2)
  6193. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6194. newGood.ProjectId = sumItem.ID
  6195. newGoodOne = append(newGoodOne, &newGood)
  6196. }
  6197. }
  6198. }
  6199. }
  6200. //判断
  6201. for _, itemOne := range infos {
  6202. for _, itemTwo := range hisAdvice {
  6203. if itemOne.DrugId == itemTwo.DrugId {
  6204. itemTwo.Child = append(itemTwo.Child, itemOne)
  6205. }
  6206. }
  6207. }
  6208. for _, itemTwo := range hisAdvice {
  6209. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6210. var sum_out_count int64
  6211. for _, itemThree := range itemTwo.Child {
  6212. var prescribing_number int64
  6213. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6214. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6215. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6216. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6217. }
  6218. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6219. prescribing_number = parseIntPrescribingNumber
  6220. }
  6221. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6222. prescribing_number = parseIntPrescribingNumber
  6223. }
  6224. sum_out_count += prescribing_number
  6225. }
  6226. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6227. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6228. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6229. if sum_out_count > drugStockOut.FlushCount {
  6230. c.ServeSuccessJSON(map[string]interface{}{
  6231. "msg": "2",
  6232. "drug": medical,
  6233. })
  6234. return
  6235. }
  6236. }
  6237. fmt.Println("newGoods99999988882os", newGoods)
  6238. for _, itemOne := range newGoods {
  6239. for _, item := range newGoodOne {
  6240. if itemOne.GoodId == item.GoodId {
  6241. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6242. }
  6243. }
  6244. }
  6245. for _, item := range newGoodOne {
  6246. var sum_out_count_one int64
  6247. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6248. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6249. sum_out_count_one += itemOne.Count
  6250. }
  6251. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6252. fmt.Println("sum_out_count_one", sum_out_count_one)
  6253. fmt.Println("list.FlushCount", list.FlushCount)
  6254. if sum_out_count_one > list.FlushCount {
  6255. c.ServeSuccessJSON(map[string]interface{}{
  6256. "msg": "3",
  6257. "good": good,
  6258. })
  6259. return
  6260. }
  6261. }
  6262. }
  6263. timestamp := time.Now().Unix()
  6264. tempTime := time.Unix(timestamp, 0)
  6265. timeFormat := tempTime.Format("20060102150405")
  6266. chrgBchno := rand.Intn(100000) + 10000
  6267. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6268. strconv.FormatInt(his.PatientId, 10)
  6269. var ids []int64
  6270. for _, item := range prescriptions {
  6271. ids = append(ids, item.ID)
  6272. }
  6273. var total float64
  6274. for _, item := range prescriptions {
  6275. fmt.Println(item)
  6276. if item.Type == 1 { //药品
  6277. for _, subItem := range item.HisDoctorAdviceInfo {
  6278. total = total + (subItem.Price * subItem.PrescribingNumber)
  6279. }
  6280. }
  6281. if item.Type == 2 { //项目
  6282. for _, subItem := range item.HisPrescriptionProject {
  6283. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6284. total = total + (subItem.Price * cnt)
  6285. }
  6286. }
  6287. for _, subItem := range item.HisAdditionalCharge {
  6288. total = total + (subItem.Price * float64(subItem.Count))
  6289. }
  6290. }
  6291. if reg_type == 1111 || reg_type == 1112 {
  6292. reg_type = 11
  6293. }
  6294. tm := time.Unix(time.Now().Unix(), 0)
  6295. allTotal := fmt.Sprintf("%.4f", total)
  6296. totals, _ := strconv.ParseFloat(allTotal, 64)
  6297. order := &models.HisOrder{
  6298. UserOrgId: adminUser.CurrentOrgId,
  6299. HisPatientId: his.ID,
  6300. PatientId: id,
  6301. SettleAccountsDate: recordDateTime,
  6302. Ctime: time.Now().Unix(),
  6303. Mtime: time.Now().Unix(),
  6304. Status: 1,
  6305. OrderStatus: 2,
  6306. MdtrtId: his.Number,
  6307. Number: chrg_bchno,
  6308. MedfeeSumamt: totals,
  6309. PayWay: pay_way,
  6310. PayWays: pay_ways,
  6311. PayPrice: pay_price,
  6312. MedType: strconv.Itoa(int(reg_type)),
  6313. PayCardNo: pay_card_no,
  6314. DiscountPrice: discount_price,
  6315. PreferentialPrice: preferential_price,
  6316. RealityPrice: reality_price,
  6317. FoundPrice: found_price,
  6318. MedicalInsurancePrice: medical_insurance_price,
  6319. PrivatePrice: private_price,
  6320. SettleEndTime: end_time,
  6321. SettleStartTime: start_time,
  6322. PsnPartAmt: totals,
  6323. PsnCashPay: totals,
  6324. SettleType: settle_accounts_type,
  6325. FaPiaoCode: fapiao_code,
  6326. FaPiaoNumber: fapiao_number,
  6327. Diagnosis: diagnosis_id,
  6328. PType: 2,
  6329. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6330. Decimal: decimal,
  6331. OthDesc: oth_desc,
  6332. CashPay: cash_pay,
  6333. WechatPay: wechat_pay,
  6334. AliPay: ali_pay,
  6335. JifenPay: jifen_pay,
  6336. BandCardPay: band_card_pay,
  6337. }
  6338. err = service.CreateOrderTX(order, tx)
  6339. if err != nil {
  6340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6341. return
  6342. }
  6343. var customs []*Custom
  6344. for _, item := range prescriptions {
  6345. if item.Type == 1 { //药品a
  6346. for _, subItem := range item.HisDoctorAdviceInfo {
  6347. cus := &Custom{
  6348. AdviceId: subItem.ID,
  6349. ProjectId: 0,
  6350. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6351. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6352. FeedetlSn: subItem.FeedetlSn,
  6353. Price: fmt.Sprintf("%.4f", subItem.Price),
  6354. MedListCodg: subItem.MedListCodg,
  6355. Type: 1,
  6356. }
  6357. customs = append(customs, cus)
  6358. }
  6359. }
  6360. if item.Type == 2 { //项目
  6361. for _, subItem := range item.HisPrescriptionProject {
  6362. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6363. cus := &Custom{
  6364. AdviceId: 0,
  6365. ProjectId: subItem.ID,
  6366. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6367. Cut: fmt.Sprintf("%.4f", cnt),
  6368. FeedetlSn: subItem.FeedetlSn,
  6369. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6370. MedListCodg: subItem.MedListCodg,
  6371. Type: 2,
  6372. }
  6373. customs = append(customs, cus)
  6374. }
  6375. }
  6376. for _, item := range item.HisAdditionalCharge {
  6377. cus := &Custom{
  6378. ItemId: item.ID,
  6379. AdviceId: 0,
  6380. ProjectId: 0,
  6381. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6382. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6383. FeedetlSn: item.FeedetlSn,
  6384. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6385. MedListCodg: item.XtHisAddtionConfig.Code,
  6386. Type: 3,
  6387. }
  6388. customs = append(customs, cus)
  6389. }
  6390. }
  6391. for _, item := range customs {
  6392. var advice_id int64 = 0
  6393. var project_id int64 = 0
  6394. var item_id int64 = 0
  6395. var types int64 = 0
  6396. if item.Type == 1 {
  6397. advice_id = item.AdviceId
  6398. project_id = 0
  6399. item_id = 0
  6400. } else if item.Type == 2 {
  6401. advice_id = 0
  6402. item_id = 0
  6403. project_id = item.ProjectId
  6404. } else if item.Type == 3 {
  6405. advice_id = 0
  6406. item_id = item.ItemId
  6407. project_id = 0
  6408. }
  6409. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6410. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6411. pric, _ := strconv.ParseFloat(item.Price, 32)
  6412. info := &models.HisOrderInfo{
  6413. OrderNumber: order.Number,
  6414. UploadDate: time.Now().Unix(),
  6415. AdviceId: advice_id,
  6416. DetItemFeeSumamt: detItemFeeSumamt,
  6417. Cnt: cut,
  6418. Pric: pric,
  6419. PatientId: id,
  6420. Status: 1,
  6421. Mtime: time.Now().Unix(),
  6422. Ctime: time.Now().Unix(),
  6423. UserOrgId: adminUser.CurrentOrgId,
  6424. HisPatientId: his.ID,
  6425. OrderId: order.ID,
  6426. ProjectId: project_id,
  6427. Type: types,
  6428. ItemId: item_id,
  6429. }
  6430. service.CreateOrderInfoTX(info, tx)
  6431. }
  6432. his.Diagnosis = diagnosis_id
  6433. his.SickType = sick_type
  6434. his.RegisterType = reg_type
  6435. his.MedicalTreatmentType = reg_type
  6436. service.UpdataHisPateintTX(&his, tx)
  6437. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6438. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6439. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6440. //判断是否使用了押金
  6441. if dec_way == "true" {
  6442. tmpstring := strconv.FormatInt(order.ID, 10)
  6443. //扣押金
  6444. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6445. order.Decimal = decimal
  6446. service.UpDateOrderTwo(order, tx)
  6447. if errmsg != nil {
  6448. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6449. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6450. return
  6451. }
  6452. }
  6453. if err == nil {
  6454. for _, info := range prescriptions {
  6455. if info.Type == 1 {
  6456. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6457. }
  6458. if info.Type == 2 {
  6459. for _, sumItem := range info.HisPrescriptionProject {
  6460. if sumItem.Type == 3 {
  6461. var good models.DialysisBeforePrepareGoods
  6462. var newGood models.NewDialysisBeforePrepareGoods
  6463. var oldGood models.OldDialysisBeforePrepareGoods
  6464. good.GoodId = sumItem.GoodInfo.ID
  6465. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6466. count, _ := strconv.Atoi(sumItem.Count)
  6467. good.Count = int64(count)
  6468. good.StorehouseId = houseConfig.StorehouseOutInfo
  6469. good.ProjectId = sumItem.ID
  6470. good.PatientId = sumItem.PatientId
  6471. goods = append(goods, &good)
  6472. newGood.GoodId = sumItem.GoodInfo.ID
  6473. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6474. count2, _ := strconv.Atoi(sumItem.Count)
  6475. newGood.Count = int64(count2)
  6476. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6477. newGood.ProjectId = sumItem.ID
  6478. newGood.PatientId = sumItem.HisPatientId
  6479. newGoods = append(newGoods, &newGood)
  6480. oldGood.GoodId = sumItem.GoodInfo.ID
  6481. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6482. count3, _ := strconv.Atoi(sumItem.Count)
  6483. oldGood.Count = int64(count3)
  6484. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6485. oldGood.ProjectId = sumItem.ID
  6486. oldGood.RecordDate = sumItem.RecordDate
  6487. oldGood.PatientId = sumItem.HisPatientId
  6488. oldGoods = append(oldGoods, &oldGood)
  6489. }
  6490. }
  6491. }
  6492. }
  6493. if settConfig.IsOpen == 1 {
  6494. for _, item := range infoList {
  6495. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6496. if medical.IsUse == 2 {
  6497. //药品出库
  6498. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6499. //查询默认仓库
  6500. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6501. //查询默认仓库剩余多少库存
  6502. var sum_count int64
  6503. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6504. for _, its := range stockInfo {
  6505. if its.MaxUnit == medical.MaxUnit {
  6506. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6507. }
  6508. sum_count += its.StockMaxNumber + its.StockMinNumber
  6509. }
  6510. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6511. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6512. }
  6513. }
  6514. orgId := c.GetAdminUserInfo().CurrentOrgId
  6515. if len(oldGoods) > 0 {
  6516. timeStr := time.Now().Format("2006-01-02")
  6517. timeArr := strings.Split(timeStr, "-")
  6518. total, _ := service.FindAllWarehouseOut(orgId)
  6519. total = total + 1
  6520. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6521. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6522. number = number + total
  6523. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6524. operation_time := time.Now().Unix()
  6525. creater := c.GetAdminUserInfo().AdminUser.Id
  6526. //查询默认出库仓库库存
  6527. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6528. recordDateStr := time.Now().Format("2006-01-02")
  6529. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6530. nowtime := recordDate.Unix()
  6531. warehouseOut := models.WarehouseOut{
  6532. WarehouseOutOrderNumber: warehousing_out_order,
  6533. OperationTime: operation_time,
  6534. OrgId: orgId,
  6535. Creater: creater,
  6536. Ctime: time.Now().Unix(),
  6537. Status: 1,
  6538. WarehouseOutTime: nowtime,
  6539. Type: 1,
  6540. StorehouseId: storeConfig.StorehouseOutInfo,
  6541. IsCheck: 1,
  6542. OrderId: order.ID,
  6543. IsSys: 5,
  6544. }
  6545. //查询是否生成出库单
  6546. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6547. if out.ID == 0 {
  6548. service.AddSigleWarehouseOut(&warehouseOut)
  6549. }
  6550. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6551. for _, item := range oldGoods {
  6552. dialyPrepareOne := models.DialysisBeforePrepare{
  6553. GoodTypeId: item.GoodTypeId,
  6554. GoodId: item.GoodId,
  6555. PatientId: his.PatientId,
  6556. RecordDate: item.RecordDate,
  6557. UserOrgId: adminUser.CurrentOrgId,
  6558. Count: item.Count,
  6559. Ctime: time.Now().Unix(),
  6560. Creater: adminUser.AdminUser.Id,
  6561. CommdityCode: item.CommdityCode,
  6562. Status: 1,
  6563. StorehouseId: houseConfig.StorehouseOutInfo,
  6564. }
  6565. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6566. //非零用
  6567. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6568. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6569. //查询剩余库存
  6570. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6571. var sum_count int64
  6572. for _, item := range goodList {
  6573. sum_count += item.StockCount
  6574. }
  6575. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6576. //耗材
  6577. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6578. }
  6579. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6580. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6581. //查询剩余库存
  6582. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6583. var sum_count int64
  6584. for _, item := range goodList {
  6585. sum_count += item.StockCount
  6586. }
  6587. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6588. //耗材
  6589. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6590. }
  6591. }
  6592. }
  6593. }
  6594. c.ServeSuccessJSON(map[string]interface{}{
  6595. "msg": "结算成功",
  6596. })
  6597. }
  6598. }
  6599. }
  6600. // 退款
  6601. func (c *HisApiController) Refund() {
  6602. order_id, _ := c.GetInt64("order_id")
  6603. order, _ := service.GetHisOrderByID(order_id)
  6604. adminUser := c.GetAdminUserInfo()
  6605. orgid := c.GetAdminUserInfo().CurrentOrgId
  6606. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6607. if err != nil {
  6608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6609. return
  6610. }
  6611. tmp := strconv.FormatInt(order.ID, 10)
  6612. //当押金不为零时产生退费记录
  6613. if order.Decimal != 0 {
  6614. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6615. if err != nil {
  6616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6617. return
  6618. }
  6619. }
  6620. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6621. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6622. var goods []*models.DialysisBeforePrepareGoods
  6623. var newGoods []*models.NewDialysisBeforePrepareGoods
  6624. var infos []*models.HisDoctorAdviceInfo
  6625. for _, info := range orders {
  6626. if info.AdviceId > 0 && info.ProjectId == 0 {
  6627. infos = append(infos, &info.HisDoctorAdviceInfo)
  6628. }
  6629. if info.ProjectId > 0 && info.AdviceId == 0 {
  6630. if info.HisPrescriptionProject.Type == 3 {
  6631. var good models.DialysisBeforePrepareGoods
  6632. var newGood models.NewDialysisBeforePrepareGoods
  6633. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6634. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6635. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6636. good.Count = int64(count)
  6637. good.StorehouseId = houseConfig.StorehouseOutInfo
  6638. good.ProjectId = info.HisPrescriptionProject.ID
  6639. good.PatientId = info.PatientId
  6640. good.OrderId = order_id
  6641. goods = append(goods, &good)
  6642. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6643. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6644. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6645. newGood.Count = int64(count2)
  6646. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6647. newGood.ProjectId = info.HisPrescriptionProject.ID
  6648. newGood.RecordDate = order.SettleAccountsDate
  6649. newGood.UserOrgId = order.UserOrgId
  6650. newGood.PatientId = info.PatientId
  6651. newGood.OrderId = order_id
  6652. newGoods = append(newGoods, &newGood)
  6653. }
  6654. }
  6655. }
  6656. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6657. if settConfig.IsOpen == 1 {
  6658. for _, item := range infos {
  6659. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6660. }
  6661. for _, item := range newGoods {
  6662. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6663. }
  6664. }
  6665. c.ServeSuccessJSON(map[string]interface{}{
  6666. "msg": "退费成功",
  6667. })
  6668. }
  6669. func (c *HisApiController) RefundNumber() {
  6670. his_patient_id, _ := c.GetInt64("id")
  6671. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6672. info.Status = 0
  6673. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6674. if count > 0 {
  6675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6676. return
  6677. }
  6678. err := service.SaveHisPatient(info)
  6679. if err == nil {
  6680. c.ServeSuccessJSON(map[string]interface{}{
  6681. "msg": "退号成功",
  6682. })
  6683. } else {
  6684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6685. return
  6686. }
  6687. }
  6688. func (this *HisApiController) AdditionalCharge() {
  6689. dataBody := make(map[string]interface{}, 0)
  6690. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6691. fmt.Println(err)
  6692. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6693. patient_id := int64(dataBody["patient_id"].(float64))
  6694. medicineData, _ := dataBody["medicineData"].([]interface{})
  6695. adminUserInfo := this.GetAdminUserInfo()
  6696. orgId := adminUserInfo.CurrentOrgId
  6697. admin_user_id := adminUserInfo.AdminUser.Id
  6698. timeStr := time.Now().Format("2006-01-02")
  6699. timeLayout := "2006-01-02 15:04:05"
  6700. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6701. timenow := timeStringToTime.Unix()
  6702. var additionalCharges []*models.HisAdditionalCharge
  6703. for _, item := range medicineData {
  6704. var randNum int
  6705. randNum = rand.Intn(10000) + 1000
  6706. timestamp := time.Now().Unix()
  6707. tempTime := time.Unix(timestamp, 0)
  6708. timeFormat := tempTime.Format("20060102150405")
  6709. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6710. items := item.(map[string]interface{})
  6711. money := items["price"].(string)
  6712. item_id_str := items["item_id"].(string)
  6713. name := items["name"].(string)
  6714. id_str := items["id"].(string)
  6715. moneys, _ := strconv.ParseInt(money, 10, 64)
  6716. monStr := strconv.FormatInt(moneys, 10)
  6717. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6718. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6719. id, _ := strconv.ParseInt(id_str, 10, 64)
  6720. additionalCharge := &models.HisAdditionalCharge{
  6721. ID: id,
  6722. HisPatientId: his_patient_id,
  6723. UserOrgId: orgId,
  6724. PatientId: patient_id,
  6725. RecordDate: timenow,
  6726. Price: monneyStr,
  6727. Status: 1,
  6728. ItemName: name,
  6729. ItemId: item_id,
  6730. AdminUserId: admin_user_id,
  6731. CreatedTime: time.Now().Unix(),
  6732. OrderStatus: 0,
  6733. PrescriptionNumber: "",
  6734. BatchNumber: "",
  6735. FeedetlSn: p_number,
  6736. }
  6737. service.CreateAdditionalCharge(additionalCharge)
  6738. additionalCharges = append(additionalCharges, additionalCharge)
  6739. }
  6740. this.ServeSuccessJSON(map[string]interface{}{
  6741. "msg": "添加成功",
  6742. "additional_charges": additionalCharges,
  6743. })
  6744. }
  6745. func (this *HisApiController) DeleteAddition() {
  6746. id, _ := this.GetInt64("id")
  6747. //TODO 需要判断是否已经结算
  6748. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6749. if err == nil {
  6750. this.ServeSuccessJSON(map[string]interface{}{
  6751. "msg": "删除成功",
  6752. })
  6753. return
  6754. } else {
  6755. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6756. return
  6757. }
  6758. }
  6759. func (this *HisApiController) GetAdminUsers() {
  6760. adminUser := this.GetAdminUserInfo()
  6761. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6762. this.ServeSuccessJSON(map[string]interface{}{
  6763. "doctors": doctors,
  6764. })
  6765. }
  6766. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6767. change_type, _ := this.GetInt64("type", 0)
  6768. record_date := this.GetString("record_time")
  6769. patient_id, _ := this.GetInt64("patient_id", 0)
  6770. p_type, _ := this.GetInt64("p_type", 0)
  6771. timeLayout := "2006-01-02"
  6772. loc, _ := time.LoadLocation("Local")
  6773. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6774. record_time := theAdviceRecordTime.Unix()
  6775. adminUserInfo := this.GetAdminUserInfo()
  6776. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6777. if err == nil {
  6778. if len(prescriptions) == 0 {
  6779. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6780. return
  6781. } else {
  6782. this.ServeSuccessJSON(map[string]interface{}{
  6783. "prescriptions": prescriptions,
  6784. })
  6785. return
  6786. }
  6787. } else {
  6788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6789. return
  6790. }
  6791. }
  6792. func (this *HisApiController) GetCallHisPrescription() {
  6793. patient_id, _ := this.GetInt64("patient_id", 0)
  6794. timeLayout := "2006-01-02"
  6795. loc, _ := time.LoadLocation("Local")
  6796. start_time := this.GetString("start_time")
  6797. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6798. end_time := this.GetString("end_time")
  6799. p_type, _ := this.GetInt64("p_type")
  6800. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6801. adminUserInfo := this.GetAdminUserInfo()
  6802. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6803. if err == nil {
  6804. this.ServeSuccessJSON(map[string]interface{}{
  6805. "prescriptions": prescriptions,
  6806. })
  6807. return
  6808. } else {
  6809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6810. return
  6811. }
  6812. }
  6813. func (this *HisApiController) GetHisDayPrescription() {
  6814. timeLayout := "2006-01-02"
  6815. loc, _ := time.LoadLocation("Local")
  6816. start_time := this.GetString("start_time")
  6817. patient_id, _ := this.GetInt64("patient_id", 0)
  6818. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6819. end_time := this.GetString("end_time")
  6820. p_type, _ := this.GetInt64("p_type")
  6821. order_status, _ := this.GetInt64("type")
  6822. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6823. adminUserInfo := this.GetAdminUserInfo()
  6824. var dayHisPrescription []*models.HisPrescription
  6825. var err error
  6826. if order_status == 1 || order_status == 0 {
  6827. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6828. } else if order_status == 2 {
  6829. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6830. }
  6831. var settle_total float64
  6832. for _, item := range dayHisPrescription {
  6833. if len(item.HisPrescriptionProject) > 0 {
  6834. for _, subItem := range item.HisPrescriptionProject {
  6835. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6836. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6837. settle_total = settle_total + total
  6838. }
  6839. }
  6840. if len(item.HisDoctorAdviceInfo) > 0 {
  6841. for _, subItem := range item.HisDoctorAdviceInfo {
  6842. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6843. settle_total = settle_total + total
  6844. }
  6845. }
  6846. }
  6847. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6848. if err == nil {
  6849. this.ServeSuccessJSON(map[string]interface{}{
  6850. "day_prescription": dayHisPrescription,
  6851. "settle_total": settle_total,
  6852. })
  6853. return
  6854. } else {
  6855. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6856. return
  6857. }
  6858. }
  6859. func (c *HisApiController) GetHisChargePatientList() {
  6860. record_date := c.GetString("record_date")
  6861. order_status, _ := c.GetInt64("type")
  6862. sch_type, _ := c.GetInt64("sch_type")
  6863. timeLayout := "2006-01-02"
  6864. loc, _ := time.LoadLocation("Local")
  6865. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6866. if err != nil {
  6867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6868. return
  6869. }
  6870. recordDateTime := theTime.Unix()
  6871. adminInfo := c.GetAdminUserInfo()
  6872. var tempPatients []*service.NewTempPatients
  6873. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6874. if order_status != 2 {
  6875. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6876. } else {
  6877. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6878. }
  6879. var patients []*service.NewTempPatients
  6880. var patients_two []*service.NewTempPatients
  6881. for _, item := range tempPatients {
  6882. //过滤掉没挂号的和没开处方的
  6883. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6884. patients = append(patients, item)
  6885. }
  6886. //过滤掉没挂号的
  6887. if len(item.HisPatient) > 0 {
  6888. patients_two = append(patients_two, item)
  6889. }
  6890. }
  6891. c.ServeSuccessJSON(map[string]interface{}{
  6892. "list": patients,
  6893. "list_two": patients_two,
  6894. })
  6895. }
  6896. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6897. record_date := c.GetString("record_date")
  6898. timeLayout := "2006-01-02"
  6899. loc, _ := time.LoadLocation("Local")
  6900. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6901. if err != nil {
  6902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6903. return
  6904. }
  6905. recordDateTime := theTime.Unix()
  6906. adminUser := c.GetAdminUserInfo()
  6907. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6908. var patients []*service.Patients
  6909. for _, item := range tempPatients {
  6910. if item.HisPatient.ID == 0 {
  6911. patients = append(patients, item)
  6912. }
  6913. }
  6914. c.ServeSuccessJSON(map[string]interface{}{
  6915. "list": patients,
  6916. //"list_two": patients_two,
  6917. })
  6918. }
  6919. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6920. newArr = make([]*service.Patients, 0)
  6921. for i := 0; i < len(patient); i++ {
  6922. repeat := false
  6923. for j := i + 1; j < len(patient); j++ {
  6924. if patient[i].ID == patient[j].ID {
  6925. repeat = true
  6926. break
  6927. }
  6928. }
  6929. if !repeat {
  6930. newArr = append(newArr, patient[i])
  6931. }
  6932. }
  6933. return
  6934. }
  6935. func (c *HisApiController) GetHisChargePatientInfo() {
  6936. patient_id, _ := c.GetInt64("patient_id")
  6937. his_patient_id, _ := c.GetInt64("his_patient_id")
  6938. record_date := c.GetString("record_date")
  6939. //start_time := c.GetString("start_time")
  6940. //end_time := c.GetString("end_time")
  6941. order_status, _ := c.GetInt64("type", 0)
  6942. p_type, _ := c.GetInt64("p_type", 0)
  6943. order_id, _ := c.GetInt64("order_id", 0)
  6944. timeLayout := "2006-01-02"
  6945. loc, _ := time.LoadLocation("Local")
  6946. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6947. if err != nil {
  6948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6949. return
  6950. }
  6951. recordDateTime := theTime.Unix()
  6952. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6953. //if err != nil {
  6954. //
  6955. //}
  6956. //startRecordDateTime := startTime.Unix()
  6957. //
  6958. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6959. //if err != nil {
  6960. //
  6961. //}
  6962. //endRecordDateTime := endTime.Unix()
  6963. admin := c.GetAdminUserInfo()
  6964. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6965. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6966. var prescriptions []*models.HisPrescription
  6967. //var unChargeMonthPrescriptions []*models.HisPrescription
  6968. order, _ := service.GetHisOrderByID(order_id)
  6969. if order_status == 1 || order_status == 0 {
  6970. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6971. } else if order_status == 2 {
  6972. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6973. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6974. }
  6975. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6976. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6977. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6978. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6979. //获取所有科室信息
  6980. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6981. c.ServeSuccessJSON(map[string]interface{}{
  6982. "his_info": his_patient_info,
  6983. "xt_info": xt_patient_info,
  6984. "prescription": prescriptions,
  6985. "case_history": case_history,
  6986. "info": patientPrescriptionInfo,
  6987. "last_info": lastPatientPrescriptionInfo,
  6988. "order": order,
  6989. "doctors": doctors,
  6990. "department": department,
  6991. })
  6992. return
  6993. }
  6994. func (c *HisApiController) GetAllOrderDetail() {
  6995. order_id, _ := c.GetInt64("id", 0)
  6996. order, _ := service.GetHisOrderByID(order_id)
  6997. if order.ID == 0 {
  6998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6999. return
  7000. }
  7001. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7002. org_id := c.GetAdminUserInfo().CurrentOrgId
  7003. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7004. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7005. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7006. c.ServeSuccessJSON(map[string]interface{}{
  7007. "order": order,
  7008. "order_info": order_info,
  7009. "patient": patient,
  7010. "admin_info": adminInfo,
  7011. "hospital_record": record,
  7012. })
  7013. return
  7014. }
  7015. func (c *HisApiController) GetAllOrderDetailCollect() {
  7016. order_id, _ := c.GetInt64("id", 0)
  7017. order, _ := service.GetHisOrderByID(order_id)
  7018. if order.ID == 0 {
  7019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7020. return
  7021. }
  7022. org_id := c.GetAdminUserInfo().CurrentOrgId
  7023. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7024. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7025. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7026. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7027. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7028. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7029. var bedCostTotal float64 = 0 //床位总费
  7030. //var bedCostSelfTotal float64 = 0 //床位自费
  7031. var operationCostTotal float64 = 0 //手术费
  7032. //var operationCostSelfTotal float64 = 0 //手术费
  7033. var otherCostTotal float64 = 0 //其他费用
  7034. //var otherCostSelfTotal float64 = 0 //其他费用
  7035. var materialCostTotal float64 = 0 //材料费
  7036. //var materialCostSelfTotal float64 = 0 //材料费
  7037. var westernMedicineCostTotal float64 = 0 //西药费
  7038. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7039. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7040. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7041. var checkCostTotal float64 = 0 //检查费
  7042. //var checkCostSelfTotal float64 = 0 //检查费
  7043. var laboratoryCostTotal float64 = 0 //化验费
  7044. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7045. var treatCostTotal float64 = 0 //治疗费用
  7046. //var treatCostSelfTotal float64 = 0 //治疗费用
  7047. var zhenChaCostTotal float64 = 0 //其他费用
  7048. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7049. decimal.DivisionPrecision = 2
  7050. var BalanceAccountsType int64
  7051. if his.ID > 0 {
  7052. BalanceAccountsType = his.BalanceAccountsType
  7053. } else {
  7054. BalanceAccountsType = record.BalanceAccountsType
  7055. }
  7056. if BalanceAccountsType != 2 {
  7057. for _, item := range order_info {
  7058. if org_id == 10215 {
  7059. if item.MedChrgitmType == "01" { //床位费
  7060. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7061. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7062. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7063. }
  7064. if item.MedChrgitmType == "02" { //诊察费
  7065. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7066. //zhenChaCostSelfTotal = zhenChaCostTotal
  7067. }
  7068. if item.MedChrgitmType == "03" { //检查费
  7069. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7070. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7071. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7072. }
  7073. //if item.MedChrgitmType == "02" { //检查费
  7074. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7075. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7076. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7077. //}
  7078. if item.MedChrgitmType == "04" { //化验费
  7079. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7080. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7081. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7082. }
  7083. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7084. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7085. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7086. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7087. }
  7088. if item.MedChrgitmType == "06" { //手术费
  7089. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7090. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7091. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7092. }
  7093. if item.MedChrgitmType == "08" { //材料费
  7094. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7095. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7096. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7097. }
  7098. if item.MedChrgitmType == "09" { //西药费
  7099. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7100. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7101. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7102. }
  7103. if item.MedChrgitmType == "11" { //中成费
  7104. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7105. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7106. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7107. }
  7108. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7109. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7110. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7111. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7112. }
  7113. } else if org_id == 10188 || org_id == 10217 {
  7114. if item.MedChrgitmType == "01" { //床位费
  7115. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7116. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7117. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7118. }
  7119. if item.MedChrgitmType == "02" { //诊察费
  7120. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7121. //zhenChaCostSelfTotal = zhenChaCostTotal
  7122. }
  7123. if item.MedChrgitmType == "03" { //检查费
  7124. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7125. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7126. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7127. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7128. }
  7129. //if item.MedChrgitmType == "02" { //检查费
  7130. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7131. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7132. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7133. //}
  7134. if item.MedChrgitmType == "04" { //化验费
  7135. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7136. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7137. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7138. }
  7139. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7140. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7141. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7142. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7143. }
  7144. if item.MedChrgitmType == "06" { //手术费
  7145. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7146. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7147. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7148. }
  7149. if item.MedChrgitmType == "08" { //材料费
  7150. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7151. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7152. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7153. }
  7154. if item.MedChrgitmType == "09" { //西药费
  7155. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7156. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7157. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7158. }
  7159. if item.MedChrgitmType == "11" { //中成费
  7160. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7161. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7162. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7163. }
  7164. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7165. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7166. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7167. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7168. }
  7169. } else {
  7170. if item.MedChrgitmType == "01" { //床位费
  7171. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7172. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7173. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7174. }
  7175. //if item.MedChrgitmType == "02" { //诊察费
  7176. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7177. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7178. //}
  7179. if item.MedChrgitmType == "03" { //检查费
  7180. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7181. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7182. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7183. }
  7184. //if item.MedChrgitmType == "02" { //检查费
  7185. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7186. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7187. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7188. //}
  7189. if item.MedChrgitmType == "04" { //化验费
  7190. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7191. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7192. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7193. }
  7194. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7195. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7196. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7197. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7198. }
  7199. if item.MedChrgitmType == "06" { //手术费
  7200. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7201. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7202. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7203. }
  7204. if item.MedChrgitmType == "08" { //材料费
  7205. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7206. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7207. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7208. }
  7209. if item.MedChrgitmType == "09" { //西药费
  7210. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7211. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7212. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7213. }
  7214. if item.MedChrgitmType == "11" { //中成费
  7215. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7216. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7217. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7218. }
  7219. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7220. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7221. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7222. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7223. }
  7224. }
  7225. }
  7226. c.ServeSuccessJSON(map[string]interface{}{
  7227. "order": order,
  7228. "order_info": order_info,
  7229. "patient": patient,
  7230. "admin_info": adminInfo,
  7231. "his_hospital": record,
  7232. "bedCostTotal": bedCostTotal,
  7233. "operationCostTotal": operationCostTotal,
  7234. "otherCostTotal": otherCostTotal,
  7235. "materialCostTotal": materialCostTotal,
  7236. "westernMedicineCostTotal": westernMedicineCostTotal,
  7237. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7238. "checkCostTotal": checkCostTotal,
  7239. "zhenChaCostTotal": zhenChaCostTotal,
  7240. "laboratoryCostTotal": laboratoryCostTotal,
  7241. "treatCostTotal": treatCostTotal,
  7242. })
  7243. } else {
  7244. for _, item := range order_info {
  7245. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7246. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7247. item.MedChrgitmType = "09"
  7248. }
  7249. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7250. if item.HisPrescriptionProject.Type == 2 {
  7251. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7252. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7253. case 0:
  7254. item.MedChrgitmType = "0"
  7255. break
  7256. case 1:
  7257. item.MedChrgitmType = "14"
  7258. break
  7259. case 2:
  7260. item.MedChrgitmType = "05"
  7261. break
  7262. case 3:
  7263. item.MedChrgitmType = "03"
  7264. break
  7265. case 4:
  7266. item.MedChrgitmType = "03"
  7267. break
  7268. case 5:
  7269. item.MedChrgitmType = "08"
  7270. break
  7271. case 6:
  7272. item.MedChrgitmType = "14"
  7273. break
  7274. case 7:
  7275. item.MedChrgitmType = "14"
  7276. break
  7277. case 8:
  7278. item.MedChrgitmType = "03"
  7279. break
  7280. case 9:
  7281. item.MedChrgitmType = "14"
  7282. break
  7283. case 10:
  7284. item.MedChrgitmType = "14"
  7285. break
  7286. case 11:
  7287. item.MedChrgitmType = "06"
  7288. break
  7289. case 12:
  7290. item.MedChrgitmType = "12"
  7291. break
  7292. case 13:
  7293. item.MedChrgitmType = "01"
  7294. break
  7295. case 14:
  7296. item.MedChrgitmType = "04"
  7297. break
  7298. case 15:
  7299. item.MedChrgitmType = "14"
  7300. break
  7301. }
  7302. } else {
  7303. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7304. case 1:
  7305. item.MedChrgitmType = "14"
  7306. break
  7307. case 2:
  7308. item.MedChrgitmType = "05"
  7309. break
  7310. case 3:
  7311. item.MedChrgitmType = "04"
  7312. break
  7313. case 4:
  7314. item.MedChrgitmType = "14"
  7315. break
  7316. case 5:
  7317. item.MedChrgitmType = "08"
  7318. break
  7319. case 6:
  7320. item.MedChrgitmType = "14"
  7321. break
  7322. case 7:
  7323. item.MedChrgitmType = "14"
  7324. break
  7325. case 8:
  7326. item.MedChrgitmType = "03"
  7327. break
  7328. case 9:
  7329. item.MedChrgitmType = "14"
  7330. break
  7331. }
  7332. }
  7333. } else if item.HisPrescriptionProject.Type == 3 {
  7334. item.MedChrgitmType = "08"
  7335. }
  7336. }
  7337. }
  7338. for _, item := range order_info {
  7339. if org_id == 10215 {
  7340. if item.MedChrgitmType == "01" { //床位费
  7341. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7342. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7343. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7344. }
  7345. if item.MedChrgitmType == "02" { //诊察费
  7346. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7347. //zhenChaCostSelfTotal = zhenChaCostTotal
  7348. }
  7349. if item.MedChrgitmType == "03" { //检查费
  7350. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7351. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7352. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7353. }
  7354. //if item.MedChrgitmType == "02" { //检查费
  7355. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7356. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7357. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7358. //}
  7359. if item.MedChrgitmType == "04" { //化验费
  7360. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7361. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7362. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7363. }
  7364. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7365. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7366. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7367. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7368. }
  7369. if item.MedChrgitmType == "06" { //手术费
  7370. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7371. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7372. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7373. }
  7374. if item.MedChrgitmType == "08" { //材料费
  7375. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7376. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7377. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7378. }
  7379. if item.MedChrgitmType == "09" { //西药费
  7380. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7381. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7382. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7383. }
  7384. if item.MedChrgitmType == "11" { //中成费
  7385. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7386. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7387. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7388. }
  7389. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7390. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7391. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7392. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7393. }
  7394. } else {
  7395. if item.MedChrgitmType == "01" { //床位费
  7396. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7397. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7398. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7399. }
  7400. //if item.MedChrgitmType == "02" { //诊察费
  7401. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7402. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7403. //}
  7404. if item.MedChrgitmType == "03" { //检查费
  7405. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7406. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7407. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7408. }
  7409. //if item.MedChrgitmType == "02" { //检查费
  7410. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7411. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7412. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7413. //}
  7414. if item.MedChrgitmType == "04" { //化验费
  7415. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7416. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7417. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7418. }
  7419. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7420. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7421. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7422. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7423. }
  7424. if item.MedChrgitmType == "06" { //手术费
  7425. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7426. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7427. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7428. }
  7429. if item.MedChrgitmType == "08" { //材料费
  7430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7431. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7432. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7433. }
  7434. if item.MedChrgitmType == "09" { //西药费
  7435. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7436. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7437. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7438. }
  7439. if item.MedChrgitmType == "11" { //中成费
  7440. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7441. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7442. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7443. }
  7444. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7445. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7446. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7447. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7448. }
  7449. }
  7450. }
  7451. c.ServeSuccessJSON(map[string]interface{}{
  7452. "order": order,
  7453. "order_info": order_info,
  7454. "patient": patient,
  7455. "admin_info": adminInfo,
  7456. "his_hospital": record,
  7457. "bedCostTotal": bedCostTotal,
  7458. "operationCostTotal": operationCostTotal,
  7459. "otherCostTotal": otherCostTotal,
  7460. "materialCostTotal": materialCostTotal,
  7461. "westernMedicineCostTotal": westernMedicineCostTotal,
  7462. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7463. "checkCostTotal": checkCostTotal,
  7464. "zhenChaCostTotal": zhenChaCostTotal,
  7465. "laboratoryCostTotal": laboratoryCostTotal,
  7466. "treatCostTotal": treatCostTotal,
  7467. })
  7468. }
  7469. }
  7470. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7471. page, _ := c.GetInt64("page")
  7472. limit, _ := c.GetInt64("limit")
  7473. keywords := c.GetString("keywords")
  7474. start_time := c.GetString("start_time")
  7475. end_time := c.GetString("end_time")
  7476. //clr_type := c.GetString("clr_type")
  7477. insutype := c.GetString("insutype")
  7478. timeLayout := "2006-01-02"
  7479. loc, _ := time.LoadLocation("Local")
  7480. var theStartTIme int64
  7481. if len(start_time) > 0 {
  7482. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7483. theStartTIme = theTime.Unix()
  7484. }
  7485. var theEndtTIme int64
  7486. if len(end_time) > 0 {
  7487. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7488. theEndtTIme = theTime.Unix()
  7489. }
  7490. if page <= 0 {
  7491. page = 1
  7492. }
  7493. if limit <= 0 {
  7494. limit = 10
  7495. }
  7496. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7497. c.ServeSuccessJSON(map[string]interface{}{
  7498. "total": total,
  7499. "list": list,
  7500. })
  7501. return
  7502. }
  7503. func (c *HisApiController) GetPutOnRecordList() {
  7504. page, _ := c.GetInt64("page")
  7505. limit, _ := c.GetInt64("limit")
  7506. keywords := c.GetString("keywords")
  7507. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7508. if page <= 0 {
  7509. page = 1
  7510. }
  7511. if limit <= 0 {
  7512. limit = 10
  7513. }
  7514. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7515. c.ServeSuccessJSON(map[string]interface{}{
  7516. "total": total,
  7517. "list": list,
  7518. })
  7519. return
  7520. }
  7521. func (c *HisApiController) GetCompareData() {
  7522. start_time := c.GetString("start_time")
  7523. end_time := c.GetString("end_time")
  7524. insutype := c.GetString("insutype")
  7525. clr_type := c.GetString("clr_type")
  7526. timeLayout := "2006-01-02"
  7527. loc, _ := time.LoadLocation("Local")
  7528. var theStartTIme int64
  7529. if len(start_time) > 0 {
  7530. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7531. if err != nil {
  7532. theStartTIme = 0
  7533. }
  7534. theStartTIme = theTime.Unix()
  7535. }
  7536. var theEndtTIme int64
  7537. if len(end_time) > 0 {
  7538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7539. if err != nil {
  7540. theEndtTIme = 0
  7541. }
  7542. theEndtTIme = theTime.Unix()
  7543. }
  7544. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7545. fmt.Println(err)
  7546. if err == nil {
  7547. c.ServeSuccessJSON(map[string]interface{}{
  7548. "list": formData,
  7549. })
  7550. } else {
  7551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7552. return
  7553. }
  7554. }
  7555. func (c *HisApiController) GetFaPiaoData() {
  7556. order_id, _ := c.GetInt64("order_id")
  7557. patient_id, _ := c.GetInt64("patient_id")
  7558. //number := c.GetString("number")
  7559. adminUser := c.GetAdminUserInfo()
  7560. order, _ := service.GetHisOrderByID(order_id)
  7561. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7562. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7563. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7564. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7565. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7566. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7567. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7568. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7569. var bedCostTotal float64 = 0 //床位总费
  7570. var bedCostSelfTotal float64 = 0 //床位自费
  7571. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7572. var operationCostTotal float64 = 0 //手术费
  7573. var operationCostSelfTotal float64 = 0 //手术费
  7574. var operationCostPartSelfTotal float64 = 0 //手术费
  7575. var otherCostTotal float64 = 0 //其他费用
  7576. var otherCostSelfTotal float64 = 0 //其他费用
  7577. var otherCostPartSelfTotal float64 = 0 //其他费用
  7578. var materialCostTotal float64 = 0 //材料费
  7579. var materialCostSelfTotal float64 = 0 //材料费
  7580. var materialCostPartSelfTotal float64 = 0 //材料费
  7581. var westernMedicineCostTotal float64 = 0 //西药费
  7582. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7583. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7584. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7585. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7586. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7587. var checkCostTotal float64 = 0 //检查费
  7588. var checkCostSelfTotal float64 = 0 //检查费
  7589. var checkCostPartSelfTotal float64 = 0 //检查费
  7590. var hiliCostTotal float64 = 0 //护理费
  7591. var hiliCostSelfTotal float64 = 0 //护理费
  7592. var hiliCostPartSelfTotal float64 = 0 //护理费
  7593. var laboratoryCostTotal float64 = 0 //化验费
  7594. var laboratoryCostSelfTotal float64 = 0 //化验费
  7595. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7596. var treatCostTotal float64 = 0 //治疗费用
  7597. var treatCostSelfTotal float64 = 0 //治疗费用
  7598. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7599. var zhenChaCostTotal float64 = 0 //其他费用
  7600. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7601. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7602. decimal.DivisionPrecision = 2
  7603. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7604. var balanceAccountsType int64
  7605. if his.ID > 0 {
  7606. balanceAccountsType = his.BalanceAccountsType
  7607. } else {
  7608. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7609. }
  7610. if balanceAccountsType == 2 {
  7611. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7612. for _, item := range orderInfos_two {
  7613. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7614. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7615. item.MedChrgitmType = "09"
  7616. }
  7617. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7618. if item.HisPrescriptionProject.Type == 2 {
  7619. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7620. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7621. case 0:
  7622. item.MedChrgitmType = "0"
  7623. break
  7624. case 1:
  7625. item.MedChrgitmType = "14"
  7626. break
  7627. case 2:
  7628. item.MedChrgitmType = "05"
  7629. break
  7630. case 3:
  7631. item.MedChrgitmType = "03"
  7632. break
  7633. case 4:
  7634. item.MedChrgitmType = "03"
  7635. break
  7636. case 5:
  7637. item.MedChrgitmType = "08"
  7638. break
  7639. case 6:
  7640. item.MedChrgitmType = "14"
  7641. break
  7642. case 7:
  7643. item.MedChrgitmType = "14"
  7644. break
  7645. case 8:
  7646. item.MedChrgitmType = "03"
  7647. break
  7648. case 9:
  7649. item.MedChrgitmType = "14"
  7650. break
  7651. case 10:
  7652. item.MedChrgitmType = "14"
  7653. break
  7654. case 11:
  7655. item.MedChrgitmType = "06"
  7656. break
  7657. case 12:
  7658. item.MedChrgitmType = "12"
  7659. break
  7660. case 13:
  7661. item.MedChrgitmType = "01"
  7662. break
  7663. case 14:
  7664. item.MedChrgitmType = "04"
  7665. break
  7666. case 15:
  7667. item.MedChrgitmType = "02"
  7668. break
  7669. }
  7670. } else {
  7671. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7672. case 1:
  7673. item.MedChrgitmType = "14"
  7674. break
  7675. case 2:
  7676. item.MedChrgitmType = "05"
  7677. break
  7678. case 3:
  7679. item.MedChrgitmType = "03"
  7680. break
  7681. case 4:
  7682. item.MedChrgitmType = "03"
  7683. break
  7684. case 5:
  7685. item.MedChrgitmType = "08"
  7686. break
  7687. case 6:
  7688. item.MedChrgitmType = "14"
  7689. break
  7690. case 7:
  7691. item.MedChrgitmType = "14"
  7692. break
  7693. case 8:
  7694. item.MedChrgitmType = "03"
  7695. break
  7696. case 9:
  7697. item.MedChrgitmType = "14"
  7698. break
  7699. }
  7700. }
  7701. } else if item.HisPrescriptionProject.Type == 3 {
  7702. item.MedChrgitmType = "08"
  7703. }
  7704. }
  7705. }
  7706. for _, item := range orderInfos_two {
  7707. fmt.Println(item.MedChrgitmType)
  7708. if item.MedChrgitmType == "07" { //床位费
  7709. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7710. hiliCostSelfTotal = hiliCostTotal
  7711. }
  7712. if item.MedChrgitmType == "01" { //床位费
  7713. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7714. bedCostSelfTotal = bedCostTotal
  7715. }
  7716. if item.MedChrgitmType == "02" { //诊察费
  7717. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7718. zhenChaCostSelfTotal = zhenChaCostTotal
  7719. }
  7720. if item.MedChrgitmType == "03" { //检查费
  7721. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7722. checkCostSelfTotal = checkCostTotal
  7723. }
  7724. if item.MedChrgitmType == "04" { //化验费
  7725. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7726. laboratoryCostSelfTotal = laboratoryCostTotal
  7727. }
  7728. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7729. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7730. treatCostSelfTotal = treatCostTotal
  7731. }
  7732. if item.MedChrgitmType == "06" { //手术费
  7733. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7734. operationCostSelfTotal = treatCostTotal
  7735. }
  7736. if item.MedChrgitmType == "08" { //材料费
  7737. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7738. materialCostSelfTotal = materialCostTotal
  7739. }
  7740. if item.MedChrgitmType == "09" { //西药费
  7741. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7742. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7743. }
  7744. if item.MedChrgitmType == "11" { //中成费
  7745. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7746. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7747. }
  7748. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7749. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7750. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7751. otherCostSelfTotal = otherCostTotal
  7752. }
  7753. } else {
  7754. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7755. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7756. otherCostSelfTotal = otherCostTotal
  7757. }
  7758. }
  7759. }
  7760. } else {
  7761. for _, item := range orderInfos {
  7762. if item.MedChrgitmType == "01" { //床位费
  7763. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7764. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7765. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7766. }
  7767. if item.MedChrgitmType == "02" { //诊察费
  7768. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7769. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7770. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7771. }
  7772. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7773. if item.MedChrgitmType == "03" { //检查费
  7774. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7775. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7776. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7777. }
  7778. } else {
  7779. if item.MedChrgitmType == "03" { //检查费
  7780. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7781. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7782. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7783. }
  7784. }
  7785. if item.MedChrgitmType == "04" { //化验费
  7786. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7787. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7788. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7789. }
  7790. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7791. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7792. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7793. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7794. }
  7795. if item.MedChrgitmType == "06" { //手术费
  7796. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7797. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7798. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7799. }
  7800. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7801. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7802. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7803. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7804. }
  7805. if item.MedChrgitmType == "07" { //西药费
  7806. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7807. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7808. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7809. }
  7810. if item.MedChrgitmType == "09" { //西药费
  7811. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7812. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7813. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7814. }
  7815. if item.MedChrgitmType == "11" { //中成费
  7816. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7817. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7818. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7819. }
  7820. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7821. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7822. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7823. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7824. }
  7825. }
  7826. }
  7827. timeLayout := "2006-01-02"
  7828. loc, _ := time.LoadLocation("Local")
  7829. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7830. if err != nil {
  7831. }
  7832. startRecordDateTime := startTime.Unix()
  7833. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7834. if err != nil {
  7835. }
  7836. endRecordDateTime := endTime.Unix()
  7837. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7838. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7839. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7840. c.ServeSuccessJSON(map[string]interface{}{
  7841. "order_number": order.Number, //业务流水号
  7842. "id_card_no": his.IdCardNo, //社会保障号
  7843. "patient": patient,
  7844. "department_name": department.Name, //科室
  7845. "number": his.Number, //门诊号
  7846. "date": order.SettleAccountsDate, //结算日期
  7847. "name": order.PsnName, //姓名
  7848. "gender": patient.Gender, //性别
  7849. "psn_cash_money": order.PsnCashPay, //个人支付
  7850. "pay_way": "门诊", //结算方式
  7851. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7852. "admin_user_name": admin.UserName, //收款员
  7853. "order": order,
  7854. "order_info": orderInfos_two,
  7855. "his": his,
  7856. "bedCostTotal": bedCostTotal,
  7857. "bedCostSelfTotal": bedCostSelfTotal,
  7858. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7859. "operationCostTotal": operationCostTotal,
  7860. "operationCostSelfTotal": operationCostSelfTotal,
  7861. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7862. "otherCostTotal": otherCostTotal,
  7863. "otherCostSelfTotal": otherCostSelfTotal,
  7864. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7865. "materialCostTotal": materialCostTotal,
  7866. "materialCostSelfTotal": materialCostSelfTotal,
  7867. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7868. "westernMedicineCostTotal": westernMedicineCostTotal,
  7869. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7870. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7871. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7872. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7873. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7874. "checkCostTotal": checkCostTotal,
  7875. "checkCostSelfTotal": checkCostSelfTotal,
  7876. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7877. "laboratoryCostTotal": laboratoryCostTotal,
  7878. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7879. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7880. "treatCostTotal": treatCostTotal,
  7881. "treatCostSelfTotal": treatCostSelfTotal,
  7882. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7883. "zhenChaCostTotal": zhenChaCostTotal,
  7884. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7885. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7886. "his_hospital_record": his_hospital_record,
  7887. "pre_pay_money": pre_pay_money,
  7888. "refund_sum": sum,
  7889. "doctor_info": doctor_info,
  7890. "hiliCostTotal": hiliCostTotal,
  7891. "hiliCostSelfTotal": hiliCostSelfTotal,
  7892. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  7893. })
  7894. }
  7895. //func (c *HisApiController) GetFaPiaoDatas() {
  7896. // order_ids := c.GetString("order_ids")
  7897. // patient_id, _ := c.GetInt64("patient_id")
  7898. // adminUser := c.GetAdminUserInfo()
  7899. //
  7900. // orders := strings.Split(order_ids, ",")
  7901. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7902. //
  7903. // for _, item := range orders {
  7904. // order_id, _ := strconv.ParseInt(item, 10, 64)
  7905. // order, _ := service.GetHisOrderByID(order_id)
  7906. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7907. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7908. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7909. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7910. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7911. //
  7912. // }
  7913. //
  7914. // var bedCostTotal float64 = 0 //床位总费
  7915. // var bedCostSelfTotal float64 = 0 //床位自费
  7916. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7917. //
  7918. // var operationCostTotal float64 = 0 //手术费
  7919. // var operationCostSelfTotal float64 = 0 //手术费
  7920. // var operationCostPartSelfTotal float64 = 0 //手术费
  7921. //
  7922. // var otherCostTotal float64 = 0 //其他费用
  7923. // var otherCostSelfTotal float64 = 0 //其他费用
  7924. // var otherCostPartSelfTotal float64 = 0 //其他费用
  7925. //
  7926. // var materialCostTotal float64 = 0 //材料费
  7927. // var materialCostSelfTotal float64 = 0 //材料费
  7928. // var materialCostPartSelfTotal float64 = 0 //材料费
  7929. //
  7930. // var westernMedicineCostTotal float64 = 0 //西药费
  7931. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  7932. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7933. //
  7934. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7935. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7936. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7937. //
  7938. // var checkCostTotal float64 = 0 //检查费
  7939. // var checkCostSelfTotal float64 = 0 //检查费
  7940. // var checkCostPartSelfTotal float64 = 0 //检查费
  7941. //
  7942. // var laboratoryCostTotal float64 = 0 //化验费
  7943. // var laboratoryCostSelfTotal float64 = 0 //化验费
  7944. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7945. //
  7946. // var treatCostTotal float64 = 0 //治疗费用
  7947. // var treatCostSelfTotal float64 = 0 //治疗费用
  7948. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  7949. //
  7950. // var zhenChaCostTotal float64 = 0 //其他费用
  7951. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  7952. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7953. //
  7954. // decimal.DivisionPrecision = 2
  7955. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7956. //
  7957. // var balanceAccountsType int64
  7958. // if his.ID > 0 {
  7959. // balanceAccountsType = his.BalanceAccountsType
  7960. // } else {
  7961. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  7962. // }
  7963. // if balanceAccountsType == 2 {
  7964. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7965. // for _, item := range orderInfos_two {
  7966. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7967. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7968. // item.MedChrgitmType = "09"
  7969. // }
  7970. //
  7971. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7972. // if item.HisPrescriptionProject.Type == 2 {
  7973. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7974. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7975. // case 0:
  7976. // item.MedChrgitmType = "0"
  7977. // break
  7978. // case 1:
  7979. // item.MedChrgitmType = "14"
  7980. // break
  7981. // case 2:
  7982. // item.MedChrgitmType = "05"
  7983. //
  7984. // break
  7985. // case 3:
  7986. // item.MedChrgitmType = "03"
  7987. //
  7988. // break
  7989. // case 4:
  7990. // item.MedChrgitmType = "03"
  7991. //
  7992. // break
  7993. // case 5:
  7994. // item.MedChrgitmType = "08"
  7995. //
  7996. // break
  7997. // case 6:
  7998. // item.MedChrgitmType = "14"
  7999. //
  8000. // break
  8001. // case 7:
  8002. // item.MedChrgitmType = "14"
  8003. //
  8004. // break
  8005. // case 8:
  8006. // item.MedChrgitmType = "03"
  8007. // break
  8008. // case 9:
  8009. // item.MedChrgitmType = "14"
  8010. // break
  8011. // case 10:
  8012. // item.MedChrgitmType = "14"
  8013. // break
  8014. // case 11:
  8015. // item.MedChrgitmType = "06"
  8016. // break
  8017. // case 12:
  8018. // item.MedChrgitmType = "12"
  8019. // break
  8020. // case 13:
  8021. // item.MedChrgitmType = "01"
  8022. // break
  8023. // case 14:
  8024. // item.MedChrgitmType = "04"
  8025. // break
  8026. // case 15:
  8027. // item.MedChrgitmType = "02"
  8028. // break
  8029. //
  8030. // }
  8031. //
  8032. // } else {
  8033. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8034. //
  8035. // case 1:
  8036. // item.MedChrgitmType = "14"
  8037. // break
  8038. // case 2:
  8039. // item.MedChrgitmType = "05"
  8040. //
  8041. // break
  8042. // case 3:
  8043. // item.MedChrgitmType = "03"
  8044. //
  8045. // break
  8046. // case 4:
  8047. // item.MedChrgitmType = "03"
  8048. //
  8049. // break
  8050. // case 5:
  8051. // item.MedChrgitmType = "08"
  8052. //
  8053. // break
  8054. // case 6:
  8055. // item.MedChrgitmType = "14"
  8056. //
  8057. // break
  8058. // case 7:
  8059. // item.MedChrgitmType = "14"
  8060. //
  8061. // break
  8062. // case 8:
  8063. // item.MedChrgitmType = "03"
  8064. // break
  8065. // case 9:
  8066. // item.MedChrgitmType = "14"
  8067. // break
  8068. //
  8069. // }
  8070. //
  8071. // }
  8072. //
  8073. // } else if item.HisPrescriptionProject.Type == 3 {
  8074. // item.MedChrgitmType = "08"
  8075. // }
  8076. // }
  8077. // }
  8078. //
  8079. // for _, item := range orderInfos_two {
  8080. // fmt.Println(item.MedChrgitmType)
  8081. // if item.MedChrgitmType == "01" { //床位费
  8082. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8083. // bedCostSelfTotal = bedCostTotal
  8084. // }
  8085. //
  8086. // if item.MedChrgitmType == "02" { //诊察费
  8087. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8088. // zhenChaCostSelfTotal = zhenChaCostTotal
  8089. // }
  8090. //
  8091. // if item.MedChrgitmType == "03" { //检查费
  8092. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8093. // checkCostSelfTotal = checkCostTotal
  8094. // }
  8095. //
  8096. // if item.MedChrgitmType == "04" { //化验费
  8097. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8098. // laboratoryCostSelfTotal = laboratoryCostTotal
  8099. // }
  8100. //
  8101. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8102. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8103. // treatCostSelfTotal = treatCostTotal
  8104. // }
  8105. //
  8106. // if item.MedChrgitmType == "06" { //手术费
  8107. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8108. // operationCostSelfTotal = treatCostTotal
  8109. // }
  8110. //
  8111. // if item.MedChrgitmType == "08" { //材料费
  8112. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8113. // materialCostSelfTotal = materialCostTotal
  8114. // }
  8115. //
  8116. // if item.MedChrgitmType == "09" { //西药费
  8117. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8118. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8119. // }
  8120. //
  8121. // if item.MedChrgitmType == "11" { //中成费
  8122. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8123. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8124. // }
  8125. //
  8126. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8127. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8128. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8129. // otherCostSelfTotal = otherCostTotal
  8130. // }
  8131. // } else {
  8132. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8133. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8134. // otherCostSelfTotal = otherCostTotal
  8135. // }
  8136. //
  8137. // }
  8138. //
  8139. // }
  8140. //
  8141. // } else {
  8142. // for _, item := range orderInfos {
  8143. // if item.MedChrgitmType == "01" { //床位费
  8144. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8145. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8146. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8147. // }
  8148. //
  8149. // if item.MedChrgitmType == "02" { //诊察费
  8150. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8151. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8152. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8153. // }
  8154. //
  8155. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8156. // if item.MedChrgitmType == "03" { //检查费
  8157. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8158. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8159. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8160. //
  8161. // }
  8162. // } else {
  8163. // if item.MedChrgitmType == "03" { //检查费
  8164. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8165. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8166. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8167. // }
  8168. //
  8169. // }
  8170. //
  8171. // if item.MedChrgitmType == "04" { //化验费
  8172. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8173. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8174. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8175. //
  8176. // }
  8177. //
  8178. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8179. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8180. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8181. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8182. //
  8183. // }
  8184. //
  8185. // if item.MedChrgitmType == "06" { //手术费
  8186. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8187. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8188. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8189. // }
  8190. //
  8191. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8192. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8193. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8194. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8195. // }
  8196. //
  8197. // if item.MedChrgitmType == "09" { //西药费
  8198. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8199. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8200. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8201. // }
  8202. //
  8203. // if item.MedChrgitmType == "11" { //中成费
  8204. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8205. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8206. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8207. // }
  8208. //
  8209. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8210. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8211. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8212. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8213. // }
  8214. //
  8215. // }
  8216. // }
  8217. // timeLayout := "2006-01-02"
  8218. // loc, _ := time.LoadLocation("Local")
  8219. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8220. // if err != nil {
  8221. // }
  8222. // startRecordDateTime := startTime.Unix()
  8223. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8224. // if err != nil {
  8225. // }
  8226. // endRecordDateTime := endTime.Unix()
  8227. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8228. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8229. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8230. //
  8231. // c.ServeSuccessJSON(map[string]interface{}{
  8232. // "order_number": order.Number, //业务流水号
  8233. // "id_card_no": his.IdCardNo, //社会保障号
  8234. // "department_name": department.Name, //科室
  8235. // "number": his.Number, //门诊号
  8236. // "date": order.SettleAccountsDate, //结算日期
  8237. // "name": order.PsnName, //姓名
  8238. // "gender": patient.Gender, //性别
  8239. // "psn_cash_money": order.PsnCashPay, //个人支付
  8240. // "pay_way": "门诊", //结算方式
  8241. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8242. // "admin_user_name": admin.UserName, //收款员
  8243. // "order": order,
  8244. // "order_info": orderInfos_two,
  8245. // "his": his,
  8246. // "bedCostTotal": bedCostTotal,
  8247. // "bedCostSelfTotal": bedCostSelfTotal,
  8248. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8249. // "operationCostTotal": operationCostTotal,
  8250. // "operationCostSelfTotal": operationCostSelfTotal,
  8251. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8252. // "otherCostTotal": otherCostTotal,
  8253. // "otherCostSelfTotal": otherCostSelfTotal,
  8254. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8255. // "materialCostTotal": materialCostTotal,
  8256. // "materialCostSelfTotal": materialCostSelfTotal,
  8257. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8258. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8259. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8260. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8261. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8262. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8263. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8264. // "checkCostTotal": checkCostTotal,
  8265. // "checkCostSelfTotal": checkCostSelfTotal,
  8266. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8267. // "laboratoryCostTotal": laboratoryCostTotal,
  8268. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8269. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8270. // "treatCostTotal": treatCostTotal,
  8271. // "treatCostSelfTotal": treatCostSelfTotal,
  8272. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8273. // "zhenChaCostTotal": zhenChaCostTotal,
  8274. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8275. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8276. // "his_hospital_record": his_hospital_record,
  8277. // "pre_pay_money": pre_pay_money,
  8278. // "refund_sum": sum,
  8279. // })
  8280. //
  8281. //}
  8282. func (this *HisApiController) GetIncomeStatisticsData() {
  8283. start_time := this.GetString("start_time")
  8284. end_time := this.GetString("end_time")
  8285. key_words := this.GetString("key_words")
  8286. limit, _ := this.GetInt64("limit")
  8287. page, _ := this.GetInt64("page")
  8288. if page <= 0 {
  8289. page = 1
  8290. }
  8291. if limit <= 0 {
  8292. limit = 10
  8293. }
  8294. statistics_type, _ := this.GetInt64("statistics_type")
  8295. admin := this.GetAdminUserInfo()
  8296. timeLayout := "2006-01-02"
  8297. loc, _ := time.LoadLocation("Local")
  8298. var theStartTIme int64
  8299. if len(start_time) > 0 {
  8300. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8301. if err != nil {
  8302. theStartTIme = 0
  8303. }
  8304. theStartTIme = theTime.Unix()
  8305. }
  8306. var theEndtTIme int64
  8307. if len(end_time) > 0 {
  8308. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8309. if err != nil {
  8310. theEndtTIme = 0
  8311. }
  8312. theEndtTIme = theTime.Unix()
  8313. }
  8314. if statistics_type == 1 {
  8315. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8316. this.ServeSuccessJSON(map[string]interface{}{
  8317. "list": list,
  8318. "total": total,
  8319. })
  8320. } else {
  8321. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8322. this.ServeSuccessJSON(map[string]interface{}{
  8323. "list": list,
  8324. "total": total,
  8325. })
  8326. }
  8327. }
  8328. func (c *HisApiController) PostProjectInformation() {
  8329. adminUser := c.GetAdminUserInfo()
  8330. orgId := adminUser.CurrentOrgId
  8331. dataBody := make(map[string]interface{}, 0)
  8332. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8333. if err != nil {
  8334. utils.ErrorLog(err.Error())
  8335. return
  8336. }
  8337. utils.ErrorLog("%v", dataBody)
  8338. var projectList []*models.HisProject
  8339. var total_goods []interface{}
  8340. tempProjects := dataBody["projects"].([]interface{})
  8341. total_goods = tempProjects
  8342. for index, projectMap := range tempProjects {
  8343. projectM := projectMap.(map[string]interface{})
  8344. var project models.HisProject
  8345. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8346. utils.ErrorLog("project_name")
  8347. return
  8348. }
  8349. project_name, _ := projectM["project_name"].(string)
  8350. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8351. err_log := models.ExportErrLog{
  8352. LogType: 6,
  8353. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8354. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8355. Status: 1,
  8356. CreateTime: time.Now().Unix(),
  8357. UpdateTime: time.Now().Unix(),
  8358. ExportTime: time.Now().Unix(),
  8359. }
  8360. service.CreateExportErrLog(&err_log)
  8361. continue
  8362. }
  8363. project.ProjectName = project_name
  8364. prices := projectM["price"].(string)
  8365. price, _ := strconv.ParseFloat(prices, 64)
  8366. if price <= 0 { //名字为空则生成一条导入错误日志
  8367. err_log := models.ExportErrLog{
  8368. LogType: 6,
  8369. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8370. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8371. Status: 1,
  8372. CreateTime: time.Now().Unix(),
  8373. UpdateTime: time.Now().Unix(),
  8374. ExportTime: time.Now().Unix(),
  8375. }
  8376. service.CreateExportErrLog(&err_log)
  8377. continue
  8378. }
  8379. project.Price = price
  8380. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8381. utils.ErrorLog("unit_id")
  8382. return
  8383. }
  8384. unit := projectM["unit"].(string)
  8385. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8386. err_log := models.ExportErrLog{
  8387. LogType: 6,
  8388. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8389. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8390. Status: 1,
  8391. CreateTime: time.Now().Unix(),
  8392. UpdateTime: time.Now().Unix(),
  8393. ExportTime: time.Now().Unix(),
  8394. }
  8395. service.CreateExportErrLog(&err_log)
  8396. continue
  8397. }
  8398. project.Unit = unit
  8399. cost_classify := projectM["cost_classify"].(string)
  8400. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8401. err_log := models.ExportErrLog{
  8402. LogType: 6,
  8403. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8404. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8405. Status: 1,
  8406. CreateTime: time.Now().Unix(),
  8407. UpdateTime: time.Now().Unix(),
  8408. ExportTime: time.Now().Unix(),
  8409. }
  8410. service.CreateExportErrLog(&err_log)
  8411. continue
  8412. }
  8413. var costClassify = "费用类别"
  8414. var cost_classify_id int64
  8415. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8416. if len(cost_classify) != 0 {
  8417. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8418. if errcode == gorm.ErrRecordNotFound {
  8419. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8420. dataconfig := models.DictDataconfig{
  8421. ParentId: costClassifyConfig.ID,
  8422. Module: "system",
  8423. OrgId: orgId,
  8424. Name: cost_classify,
  8425. FieldName: "",
  8426. Value: costConfig.Value + 1,
  8427. CreatedTime: "",
  8428. UpdatedTime: "",
  8429. CreateUserId: adminUser.AdminUser.Id,
  8430. Status: 1,
  8431. Remark: "",
  8432. DeleteIdSystem: 0,
  8433. Title: "",
  8434. Content: "",
  8435. Order: 0,
  8436. Code: "",
  8437. }
  8438. service.CreatedDicConfig(&dataconfig)
  8439. }
  8440. }
  8441. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8442. for _, it := range costClassList {
  8443. if cost_classify == it.Name {
  8444. cost_classify_id = int64(it.Value)
  8445. }
  8446. }
  8447. project.CostClassify = cost_classify_id
  8448. executive_section := projectM["executive_section"].(string)
  8449. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8450. err_log := models.ExportErrLog{
  8451. LogType: 6,
  8452. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8453. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8454. Status: 1,
  8455. CreateTime: time.Now().Unix(),
  8456. UpdateTime: time.Now().Unix(),
  8457. ExportTime: time.Now().Unix(),
  8458. }
  8459. service.CreateExportErrLog(&err_log)
  8460. continue
  8461. }
  8462. if len(executive_section) != 0 {
  8463. //查找科室是否有内容
  8464. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8465. if errcodedepart == gorm.ErrRecordNotFound {
  8466. department := models.XtHisDepartment{
  8467. Name: executive_section,
  8468. Status: 1,
  8469. UserOrgId: adminUser.CurrentOrgId,
  8470. CreatedTime: time.Now().Unix(),
  8471. }
  8472. service.CreateDePartment(&department)
  8473. }
  8474. }
  8475. var executive_section_id int64
  8476. departMentList, _ := service.GetAllDepartMent(orgId)
  8477. for _, it := range departMentList {
  8478. if executive_section == it.Name {
  8479. executive_section_id = it.ID
  8480. }
  8481. }
  8482. project.ExecutiveSection = executive_section_id
  8483. medical_coverage := projectM["medical_coverage"].(string)
  8484. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8485. err_log := models.ExportErrLog{
  8486. LogType: 6,
  8487. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8488. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8489. Status: 1,
  8490. CreateTime: time.Now().Unix(),
  8491. UpdateTime: time.Now().Unix(),
  8492. ExportTime: time.Now().Unix(),
  8493. }
  8494. service.CreateExportErrLog(&err_log)
  8495. continue
  8496. }
  8497. var medicalCoverage = "医保等级"
  8498. var medical_coverage_id int64
  8499. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8500. if len(medical_coverage) != 0 {
  8501. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8502. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8503. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8504. dataconfig := models.DictDataconfig{
  8505. ParentId: medicalCoverageConfig.ID,
  8506. Module: "system",
  8507. OrgId: orgId,
  8508. Name: medical_coverage,
  8509. FieldName: "",
  8510. Value: medicalCoverageConfig.Value + 1,
  8511. CreatedTime: "",
  8512. UpdatedTime: "",
  8513. CreateUserId: adminUser.AdminUser.Id,
  8514. Status: 1,
  8515. Remark: "",
  8516. DeleteIdSystem: 0,
  8517. Title: "",
  8518. Content: "",
  8519. Order: 0,
  8520. Code: "",
  8521. }
  8522. service.CreatedDicConfig(&dataconfig)
  8523. }
  8524. }
  8525. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8526. for _, it := range medicalCoverageList {
  8527. if medical_coverage == it.Name {
  8528. medical_coverage_id = int64(it.Value)
  8529. }
  8530. }
  8531. project.MedicalCoverage = medical_coverage_id
  8532. pinyin := projectM["pinyin"].(string)
  8533. project.Pinyin = pinyin
  8534. wubi := projectM["wubi"].(string)
  8535. project.Wubi = wubi
  8536. statistical_classification := projectM["statistical_classification"].(string)
  8537. var statisticalClassification = "统计分类"
  8538. var statistical_classification_id int64
  8539. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8540. if len(statistical_classification) != 0 {
  8541. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8542. if classificationerrcodes == gorm.ErrRecordNotFound {
  8543. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8544. dataconfig := models.DictDataconfig{
  8545. ParentId: classiFication.ID,
  8546. Module: "system",
  8547. OrgId: orgId,
  8548. Name: statistical_classification,
  8549. FieldName: "",
  8550. Value: classiFicationConfig.Value + 1,
  8551. CreatedTime: "",
  8552. UpdatedTime: "",
  8553. CreateUserId: adminUser.AdminUser.Id,
  8554. Status: 1,
  8555. Remark: "",
  8556. DeleteIdSystem: 0,
  8557. Title: "",
  8558. Content: "",
  8559. Order: 0,
  8560. Code: "",
  8561. }
  8562. service.CreatedDicConfig(&dataconfig)
  8563. }
  8564. }
  8565. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8566. for _, it := range classiFicationList {
  8567. if statistical_classification == it.Name {
  8568. statistical_classification_id = int64(it.Value)
  8569. }
  8570. }
  8571. project.StatisticalClassification = statistical_classification_id
  8572. disease_directory := int64(projectM["disease_directory"].(float64))
  8573. project.DiseaseDirectory = disease_directory
  8574. is_record := int64(projectM["is_record"].(float64))
  8575. project.IsRecord = is_record
  8576. medical_code := projectM["medical_code"].(string)
  8577. project.MedicalCode = medical_code
  8578. tube_color := projectM["tube_color"].(string)
  8579. var tubeColor = "试管颜色"
  8580. var tube_color_id int64
  8581. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8582. if len(tube_color) != 0 {
  8583. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8584. if errcodetube == gorm.ErrRecordNotFound {
  8585. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8586. dataconfig := models.DictDataconfig{
  8587. ParentId: tubeColorConfig.ID,
  8588. Module: "system",
  8589. OrgId: orgId,
  8590. Name: tube_color,
  8591. FieldName: "",
  8592. Value: tubeConfig.Value + 1,
  8593. CreatedTime: "",
  8594. UpdatedTime: "",
  8595. CreateUserId: adminUser.AdminUser.Id,
  8596. Status: 1,
  8597. Remark: "",
  8598. DeleteIdSystem: 0,
  8599. Title: "",
  8600. Content: "",
  8601. Order: 0,
  8602. Code: "",
  8603. }
  8604. service.CreatedDicConfig(&dataconfig)
  8605. }
  8606. }
  8607. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8608. for _, it := range tubeColorList {
  8609. if tube_color == it.Name {
  8610. tube_color_id = int64(it.Value)
  8611. }
  8612. }
  8613. project.TubeColor = tube_color_id
  8614. single_dose := projectM["single_dose"].(string)
  8615. project.SingleDose = single_dose
  8616. execution_frequency := projectM["execution_frequency"].(string)
  8617. project.ExecutionFrequency = execution_frequency
  8618. delivery_way := projectM["delivery_way"].(string)
  8619. project.DeliveryWay = delivery_way
  8620. number_days := projectM["number_days"].(string)
  8621. project.NumberDays = number_days
  8622. total := projectM["total"].(string)
  8623. project.Total = total
  8624. medical_status := int64(projectM["medical_status"].(float64))
  8625. project.MedicalStatus = medical_status
  8626. category := int64(projectM["category"].(float64))
  8627. project.Category = category
  8628. specail_project := int64(projectM["specail_project"].(float64))
  8629. project.SpecailProject = specail_project
  8630. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8631. project.SocialSecurityDirectoryCode = social_security_directory_code
  8632. remark := projectM["remark"].(string)
  8633. project.Remark = remark
  8634. record_date := projectM["record_date"].(string)
  8635. timeLayout := "2006-01-02"
  8636. loc, _ := time.LoadLocation("Local")
  8637. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8638. project.RecordDate = theTime.Unix()
  8639. projectList = append(projectList, &project)
  8640. }
  8641. export_time := time.Now().Unix()
  8642. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8643. if len(projectList) > 0 {
  8644. for _, item := range projectList {
  8645. project := models.HisProject{
  8646. ProjectName: item.ProjectName,
  8647. Price: item.Price,
  8648. Unit: item.Unit,
  8649. CostClassify: item.CostClassify,
  8650. ExecutiveSection: item.ExecutiveSection,
  8651. MedicalCoverage: item.MedicalCoverage,
  8652. UserOrgId: orgId,
  8653. Status: 1,
  8654. CreatedTime: time.Now().Unix(),
  8655. Pinyin: item.Pinyin,
  8656. Wubi: item.Wubi,
  8657. StatisticalClassification: item.StatisticalClassification,
  8658. DiseaseDirectory: item.DiseaseDirectory,
  8659. IsRecord: item.IsRecord,
  8660. MedicalCode: item.MedicalCode,
  8661. TubeColor: item.TubeColor,
  8662. SingleDose: item.SingleDose,
  8663. DeliveryWay: item.DeliveryWay,
  8664. NumberDays: item.NumberDays,
  8665. Total: item.Total,
  8666. Category: item.Category,
  8667. MedicalStatus: item.MedicalStatus,
  8668. SpecailProject: item.SpecailProject,
  8669. RecordDate: item.RecordDate,
  8670. Remark: item.Remark,
  8671. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8672. ExecutionFrequency: item.ExecutionFrequency,
  8673. }
  8674. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8675. if errcodeproject == gorm.ErrRecordNotFound {
  8676. service.CreateProjectInfomation(&project)
  8677. } else if errcodeproject == nil {
  8678. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8679. }
  8680. log := models.ExportLog{
  8681. LogType: 6,
  8682. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8683. TotalNum: int64(len(total_goods)),
  8684. FailNum: int64(len(errLogs)),
  8685. SuccessNum: int64(len(projectList)),
  8686. CreateTime: time.Now().Unix(),
  8687. UpdateTime: time.Now().Unix(),
  8688. ExportTime: export_time,
  8689. Status: 1,
  8690. }
  8691. service.CreateExportLog(&log)
  8692. c.ServeSuccessJSON(map[string]interface{}{
  8693. "msg": "导入成功",
  8694. "total_num": len(total_goods),
  8695. "success_num": len(projectList),
  8696. "fail_num": int64(len(errLogs)),
  8697. })
  8698. }
  8699. } else {
  8700. log := models.ExportLog{
  8701. LogType: 6,
  8702. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8703. TotalNum: int64(len(total_goods)),
  8704. FailNum: int64(len(errLogs)),
  8705. SuccessNum: int64(len(projectList)),
  8706. CreateTime: time.Now().Unix(),
  8707. UpdateTime: time.Now().Unix(),
  8708. ExportTime: export_time,
  8709. Status: 1,
  8710. }
  8711. service.CreateExportLog(&log)
  8712. c.ServeSuccessJSON(map[string]interface{}{
  8713. "msg": "导入成功",
  8714. "total_num": len(total_goods),
  8715. "success_num": len(projectList),
  8716. "fail_num": int64(len(errLogs)),
  8717. })
  8718. }
  8719. }
  8720. //func (this *HisApiController) EditProjectInformation(){
  8721. //
  8722. // id, _ := this.GetInt64("id")
  8723. // project_team := this.GetString("project_team")
  8724. // price := this.GetString("price")
  8725. // price_float, _ := strconv.ParseFloat(price, 64)
  8726. // pinyin := this.GetString("pinyin")
  8727. // wubi := this.GetString("wubi")
  8728. // tube_color, _ := this.GetInt64("tube_color")
  8729. // team_type, _ := this.GetInt64("team_type")
  8730. // remark := this.GetString("remark")
  8731. // ids := this.GetString("ids")
  8732. // item_id := this.GetString("item_id")
  8733. // projectTeam := models.XtHisProjectTeam{
  8734. // ProjectTeam: project_team,
  8735. // Price: price_float,
  8736. // Pinyin: pinyin,
  8737. // Wubi: wubi,
  8738. // TubeColor: tube_color,
  8739. // TeamType: team_type,
  8740. // Remark: remark,
  8741. // ProjectId: ids,
  8742. // ItemId: item_id,
  8743. // }
  8744. //
  8745. //
  8746. // dataBody := make(map[string]interface{}, 0)
  8747. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8748. // if err != nil {
  8749. // utils.ErrorLog(err.Error())
  8750. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8751. // return
  8752. // }
  8753. //
  8754. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8755. //
  8756. //
  8757. // if err != nil {
  8758. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8759. // return
  8760. // }
  8761. //
  8762. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8763. // infos, _ := dataBody["info"].([]interface{})
  8764. // if len(infos) > 0 {
  8765. // var ids []string
  8766. //
  8767. // for _, item := range infos {
  8768. // items := item.(map[string]interface{})
  8769. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8770. // utils.ErrorLog("id")
  8771. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8772. // return
  8773. // }
  8774. // id := int64(items["id"].(float64))
  8775. //
  8776. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8777. // utils.ErrorLog("type")
  8778. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8779. // return
  8780. // }
  8781. // types := int64(items["type"].(float64))
  8782. //
  8783. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8784. // utils.ErrorLog("number")
  8785. // }
  8786. //
  8787. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8788. //
  8789. // projectList := models.XtHisProjectList{
  8790. // Number: number,
  8791. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8792. // ProjectId: id,
  8793. // Status: 1,
  8794. // CreatedTime: time.Now().Unix(),
  8795. // UpdatedTime: time.Now().Unix(),
  8796. // TeamId: projectTeam.ID,
  8797. // Type: types,
  8798. // }
  8799. // list := projectList
  8800. //
  8801. // service.CreateProjectList(&list)
  8802. //
  8803. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8804. //
  8805. // }
  8806. // ids_str := strings.Join(ids, ",")
  8807. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8808. // service.SaveProjectTeam(&projectTeam)
  8809. // this.ServeSuccessJSON(map[string]interface{}{
  8810. // "projectTeam": projectTeam,
  8811. // })
  8812. // }
  8813. // }
  8814. //}
  8815. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8816. name := c.GetString("name")
  8817. mode_id, _ := c.GetInt64("mode", 0)
  8818. types, _ := c.GetInt64("type", 0)
  8819. patient_id, _ := c.GetInt64("patient_id", 0)
  8820. types = 1
  8821. adminInfo := c.GetAdminUserInfo()
  8822. template := &models.HisPrescriptionTemplate{
  8823. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8824. PatientId: patient_id,
  8825. Type: types,
  8826. Status: 1,
  8827. Ctime: time.Now().Unix(),
  8828. Mtime: time.Now().Unix(),
  8829. Name: name,
  8830. Mode: mode_id,
  8831. }
  8832. dataBody := make(map[string]interface{}, 0)
  8833. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8834. if err != nil {
  8835. utils.ErrorLog(err.Error())
  8836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8837. return
  8838. }
  8839. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8840. //如果已经存在记录则删除处方
  8841. if template_one.ID > 0 {
  8842. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8843. for _, item := range ps {
  8844. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8845. }
  8846. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8847. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8848. if len(prescriptions) > 0 {
  8849. for _, item := range prescriptions {
  8850. items := item.(map[string]interface{})
  8851. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8852. utils.ErrorLog("type")
  8853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8854. return
  8855. }
  8856. types := int64(items["type"].(float64))
  8857. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8858. utils.ErrorLog("med_type")
  8859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8860. return
  8861. }
  8862. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8863. ctime := time.Now().Unix()
  8864. prescription := &models.HisPrescriptionInfoTemplate{
  8865. PatientId: patient_id,
  8866. UserOrgId: adminInfo.CurrentOrgId,
  8867. Ctime: ctime,
  8868. Mtime: ctime,
  8869. Type: types,
  8870. Modifier: adminInfo.AdminUser.Id,
  8871. Creator: adminInfo.AdminUser.Id,
  8872. Status: 1,
  8873. PTemplateId: template_one.ID,
  8874. MedType: med_type,
  8875. }
  8876. service.CreateHisPrescriptionInfoTemplate(prescription)
  8877. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8878. advices := items["advices"].([]interface{})
  8879. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8880. ctime := time.Now().Unix()
  8881. mtime := ctime
  8882. if len(advices) > 0 {
  8883. for _, advice := range advices {
  8884. var s models.HisPrescriptionAdviceTemplate
  8885. s.PrescriptionId = prescription.ID
  8886. s.AdviceType = 2
  8887. s.StopState = 2
  8888. s.ExecutionState = 2
  8889. s.Status = 1
  8890. s.UserOrgId = adminInfo.CurrentOrgId
  8891. s.CreatedTime = ctime
  8892. s.UpdatedTime = mtime
  8893. s.PatientId = patient_id
  8894. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8895. if errcode > 0 {
  8896. c.ServeFailJSONWithSGJErrorCode(errcode)
  8897. return
  8898. }
  8899. service.CreateHisPrescriptionAdviceTemplate(&s)
  8900. }
  8901. }
  8902. }
  8903. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8904. projects := items["project"].([]interface{})
  8905. if len(projects) > 0 {
  8906. for _, project := range projects {
  8907. var p models.HisPrescriptionProjectTemplate
  8908. p.PrescriptionId = prescription.ID
  8909. p.Ctime = time.Now().Unix()
  8910. p.Mtime = time.Now().Unix()
  8911. p.PatientId = patient_id
  8912. p.UserOrgId = adminInfo.CurrentOrgId
  8913. p.Status = 1
  8914. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8915. if errcode > 0 {
  8916. c.ServeFailJSONWithSGJErrorCode(errcode)
  8917. return
  8918. }
  8919. service.CreateHisPrescriptionProjectTemplate(&p)
  8920. }
  8921. }
  8922. }
  8923. }
  8924. c.ServeSuccessJSON(map[string]interface{}{
  8925. "msg": "创建成功",
  8926. })
  8927. }
  8928. }
  8929. } else {
  8930. err = service.CreateHisPrescriptionTemplate(template)
  8931. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8932. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8933. if len(prescriptions) > 0 {
  8934. for _, item := range prescriptions {
  8935. items := item.(map[string]interface{})
  8936. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8937. utils.ErrorLog("type")
  8938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8939. return
  8940. }
  8941. types := int64(items["type"].(float64))
  8942. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8943. utils.ErrorLog("med_type")
  8944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8945. return
  8946. }
  8947. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8948. ctime := time.Now().Unix()
  8949. prescription := &models.HisPrescriptionInfoTemplate{
  8950. PatientId: patient_id,
  8951. UserOrgId: adminInfo.CurrentOrgId,
  8952. Ctime: ctime,
  8953. Mtime: ctime,
  8954. Type: types,
  8955. Modifier: adminInfo.AdminUser.Id,
  8956. Creator: adminInfo.AdminUser.Id,
  8957. Status: 1,
  8958. PTemplateId: template.ID,
  8959. MedType: med_type,
  8960. }
  8961. service.CreateHisPrescriptionInfoTemplate(prescription)
  8962. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8963. advices := items["advices"].([]interface{})
  8964. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8965. ctime := time.Now().Unix()
  8966. mtime := ctime
  8967. if len(advices) > 0 {
  8968. for _, advice := range advices {
  8969. var s models.HisPrescriptionAdviceTemplate
  8970. s.PrescriptionId = prescription.ID
  8971. s.AdviceType = 2
  8972. s.StopState = 2
  8973. s.ExecutionState = 2
  8974. s.Status = 1
  8975. s.UserOrgId = adminInfo.CurrentOrgId
  8976. s.CreatedTime = ctime
  8977. s.UpdatedTime = mtime
  8978. s.PatientId = patient_id
  8979. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8980. if errcode > 0 {
  8981. c.ServeFailJSONWithSGJErrorCode(errcode)
  8982. return
  8983. }
  8984. service.CreateHisPrescriptionAdviceTemplate(&s)
  8985. }
  8986. }
  8987. }
  8988. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8989. projects := items["project"].([]interface{})
  8990. if len(projects) > 0 {
  8991. for _, project := range projects {
  8992. var p models.HisPrescriptionProjectTemplate
  8993. p.PrescriptionId = prescription.ID
  8994. p.Ctime = time.Now().Unix()
  8995. p.Mtime = time.Now().Unix()
  8996. p.PatientId = patient_id
  8997. p.UserOrgId = adminInfo.CurrentOrgId
  8998. p.Status = 1
  8999. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9000. if errcode > 0 {
  9001. c.ServeFailJSONWithSGJErrorCode(errcode)
  9002. return
  9003. }
  9004. service.CreateHisPrescriptionProjectTemplate(&p)
  9005. }
  9006. }
  9007. }
  9008. }
  9009. c.ServeSuccessJSON(map[string]interface{}{
  9010. "msg": "创建成功",
  9011. })
  9012. }
  9013. }
  9014. }
  9015. }
  9016. func (c *HisApiController) PreSettle() {
  9017. id, _ := c.GetInt64("id")
  9018. record_time := c.GetString("record_time")
  9019. his_patient_id, _ := c.GetInt64("his_patient_id")
  9020. timeLayout := "2006-01-02"
  9021. loc, _ := time.LoadLocation("Local")
  9022. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9023. diagnosis_id := c.GetString("diagnosis")
  9024. sick_type, _ := c.GetInt64("sick_type")
  9025. reg_type, _ := c.GetInt64("p_type")
  9026. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9028. if err != nil {
  9029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9030. return
  9031. }
  9032. recordDateTime := theTime.Unix()
  9033. adminUser := c.GetAdminUserInfo()
  9034. var prescriptions []*models.HisPrescription
  9035. var start_time int64
  9036. var end_time int64
  9037. ids_str := c.GetString("ids")
  9038. ids_arr := strings.Split(ids_str, ",")
  9039. fmt.Println(reg_type)
  9040. if settle_accounts_type == 1 { //日结
  9041. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9042. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9043. } else {
  9044. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9045. }
  9046. fmt.Println(prescriptions)
  9047. } else { //月结
  9048. start_time_str := c.GetString("start_time")
  9049. end_time_str := c.GetString("end_time")
  9050. timeLayout := "2006-01-02"
  9051. loc, _ := time.LoadLocation("Local")
  9052. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9053. if err != nil {
  9054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9055. return
  9056. }
  9057. recordStartTime := theStartTime.Unix()
  9058. start_time = recordStartTime
  9059. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9060. if err != nil {
  9061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9062. return
  9063. }
  9064. recordEndTime := theEndTime.Unix()
  9065. end_time = recordEndTime
  9066. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9067. }
  9068. if reg_type == 1111 || reg_type == 1112 {
  9069. reg_type = 11
  9070. }
  9071. timestamp := time.Now().Unix()
  9072. tempTime := time.Unix(timestamp, 0)
  9073. timeFormat := tempTime.Format("20060102150405")
  9074. chrgBchno := rand.Intn(100000) + 10000
  9075. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9076. strconv.FormatInt(his.PatientId, 10)
  9077. var ids []int64
  9078. for _, item := range prescriptions {
  9079. ids = append(ids, item.ID)
  9080. }
  9081. fmt.Println(ids)
  9082. var total float64
  9083. for _, item := range prescriptions {
  9084. fmt.Println(item)
  9085. if item.Type == 1 { //药品
  9086. for _, subItem := range item.HisDoctorAdviceInfo {
  9087. total = total + (subItem.Price * subItem.PrescribingNumber)
  9088. }
  9089. }
  9090. if item.Type == 2 { //项目
  9091. for _, subItem := range item.HisPrescriptionProject {
  9092. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9093. total = total + (subItem.Price * cnt)
  9094. }
  9095. }
  9096. for _, subItem := range item.HisAdditionalCharge {
  9097. total = total + (subItem.Price * float64(subItem.Count))
  9098. }
  9099. }
  9100. allTotal := fmt.Sprintf("%.2f", total)
  9101. totals, _ := strconv.ParseFloat(allTotal, 64)
  9102. order := &models.HisOrder{
  9103. UserOrgId: adminUser.CurrentOrgId,
  9104. HisPatientId: his.ID,
  9105. PatientId: id,
  9106. SettleAccountsDate: recordDateTime,
  9107. Ctime: time.Now().Unix(),
  9108. Mtime: time.Now().Unix(),
  9109. Status: 1,
  9110. OrderStatus: 1,
  9111. MdtrtId: his.Number,
  9112. Number: chrg_bchno,
  9113. MedfeeSumamt: totals,
  9114. SettleEndTime: end_time,
  9115. SettleStartTime: start_time,
  9116. SettleType: settle_accounts_type,
  9117. PsnPartAmt: totals,
  9118. PsnCashPay: totals,
  9119. PType: 2,
  9120. IsPre: 1,
  9121. MedType: strconv.Itoa(int(reg_type)),
  9122. Diagnosis: diagnosis_id,
  9123. }
  9124. err = service.CreateOrder(order)
  9125. if err != nil {
  9126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9127. return
  9128. }
  9129. var customs []*Custom
  9130. for _, item := range prescriptions {
  9131. fmt.Println(item.Type)
  9132. if item.Type == 1 { //药品
  9133. for _, subItem := range item.HisDoctorAdviceInfo {
  9134. cus := &Custom{
  9135. AdviceId: subItem.ID,
  9136. ProjectId: 0,
  9137. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9138. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9139. FeedetlSn: subItem.FeedetlSn,
  9140. Price: fmt.Sprintf("%.2f", subItem.Price),
  9141. MedListCodg: subItem.MedListCodg,
  9142. Type: 1,
  9143. }
  9144. customs = append(customs, cus)
  9145. }
  9146. }
  9147. if item.Type == 2 { //项目
  9148. for _, subItem := range item.HisPrescriptionProject {
  9149. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9150. cus := &Custom{
  9151. AdviceId: 0,
  9152. ProjectId: subItem.ID,
  9153. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9154. Cut: fmt.Sprintf("%.2f", cnt),
  9155. FeedetlSn: subItem.FeedetlSn,
  9156. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9157. MedListCodg: subItem.MedListCodg,
  9158. Type: 2,
  9159. }
  9160. customs = append(customs, cus)
  9161. }
  9162. }
  9163. for _, item := range item.HisAdditionalCharge {
  9164. cus := &Custom{
  9165. ItemId: item.ID,
  9166. AdviceId: 0,
  9167. ProjectId: 0,
  9168. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9169. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9170. FeedetlSn: item.FeedetlSn,
  9171. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9172. MedListCodg: item.XtHisAddtionConfig.Code,
  9173. Type: 3,
  9174. }
  9175. customs = append(customs, cus)
  9176. }
  9177. }
  9178. fmt.Println(customs)
  9179. for _, item := range customs {
  9180. var advice_id int64 = 0
  9181. var project_id int64 = 0
  9182. var item_id int64 = 0
  9183. var types int64 = 0
  9184. if item.Type == 1 {
  9185. advice_id = item.AdviceId
  9186. project_id = 0
  9187. item_id = 0
  9188. } else if item.Type == 2 {
  9189. advice_id = 0
  9190. item_id = 0
  9191. project_id = item.ProjectId
  9192. } else if item.Type == 3 {
  9193. advice_id = 0
  9194. item_id = item.ItemId
  9195. project_id = 0
  9196. }
  9197. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9198. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9199. pric, _ := strconv.ParseFloat(item.Price, 32)
  9200. info := &models.HisOrderInfo{
  9201. OrderNumber: order.Number,
  9202. UploadDate: time.Now().Unix(),
  9203. AdviceId: advice_id,
  9204. DetItemFeeSumamt: detItemFeeSumamt,
  9205. Cnt: cut,
  9206. Pric: pric,
  9207. PatientId: id,
  9208. Status: 1,
  9209. Mtime: time.Now().Unix(),
  9210. Ctime: time.Now().Unix(),
  9211. UserOrgId: adminUser.CurrentOrgId,
  9212. HisPatientId: his.ID,
  9213. OrderId: order.ID,
  9214. ProjectId: project_id,
  9215. Type: types,
  9216. ItemId: item_id,
  9217. }
  9218. service.CreateOrderInfo(info)
  9219. }
  9220. his.SickType = sick_type
  9221. service.UpdataHisPateint(&his)
  9222. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9223. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9224. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9225. if err == nil {
  9226. c.ServeSuccessJSON(map[string]interface{}{
  9227. "msg": "结算成功",
  9228. })
  9229. }
  9230. }
  9231. type CustomOrderInfo struct {
  9232. Name string
  9233. Spec string
  9234. Unit string
  9235. Count float64
  9236. Price float64
  9237. Total float64
  9238. }
  9239. func (c *HisApiController) GetPrivateExpensesInfo() {
  9240. order_id, _ := c.GetInt64("id", 0)
  9241. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9242. order, _ := service.GetHisOrderByID(order_id)
  9243. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9244. if order.ID == 0 {
  9245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9246. return
  9247. }
  9248. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9249. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9250. org_id := c.GetAdminUserInfo().CurrentOrgId
  9251. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9252. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9253. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9254. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9255. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9256. //var orderInfos_four []*models.HisOrderInfoTwo
  9257. //for _, item := range orderInfos_three {
  9258. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9259. // item.HisPrescriptionProject.IsCheckTeam = 1
  9260. // orderInfos_four = append(orderInfos_four, item)
  9261. //
  9262. // }
  9263. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9264. // item.HisPrescriptionProject.IsCheckTeam = 2
  9265. // orderInfos_two = append(orderInfos_two, item)
  9266. // }
  9267. //}
  9268. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9269. //var cus_slice []CustomOrderInfo
  9270. //for _, item := range new_order_info {
  9271. // var cus CustomOrderInfo
  9272. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9273. // cus.Unit = ""
  9274. // cus.Spec = ""
  9275. // var total float64
  9276. // for _, subItem := range orderInfos_four {
  9277. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9278. // total = total + subItem.DetItemFeeSumamt
  9279. // fmt.Println(subItem.DetItemFeeSumamt)
  9280. // }
  9281. // }
  9282. // cus.Count = 1
  9283. // cus.Total = total
  9284. // cus_slice = append(cus_slice, cus)
  9285. //}
  9286. orderInfos = append(orderInfos, orderInfos_two...)
  9287. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9288. //orderInfos = append(orderInfos, orderInfos_three...)
  9289. //}/**/
  9290. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9291. c.ServeSuccessJSON(map[string]interface{}{
  9292. "order": order,
  9293. "order_info": orderInfos,
  9294. "patient": patient,
  9295. "admin_info": adminInfo,
  9296. "his": his,
  9297. "current_admin": role,
  9298. "org_config": miConfig,
  9299. //"new_order_info": cus_slice,
  9300. })
  9301. }
  9302. func (this *HisApiController) ChangeMedType() {
  9303. med_type := this.GetString("med_type")
  9304. old_med_type := this.GetString("old_med_type")
  9305. ids := this.GetString("ids")
  9306. settle_type, _ := this.GetInt64("settle_type")
  9307. start_time := this.GetString("start_time")
  9308. end_time := this.GetString("end_time")
  9309. ids_arr := strings.Split(ids, ",")
  9310. if settle_type == 1 { //日结
  9311. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9312. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9313. prescription.MedType = med_type
  9314. err := service.SaveHisPrescription(&prescription)
  9315. if err == nil {
  9316. this.ServeSuccessJSON(map[string]interface{}{
  9317. "msg": "修改成功",
  9318. })
  9319. } else {
  9320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9321. return
  9322. }
  9323. } else if settle_type == 2 {
  9324. timeLayout := "2006-01-02"
  9325. loc, _ := time.LoadLocation("Local")
  9326. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9327. if err != nil {
  9328. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9329. return
  9330. }
  9331. recordStartTime := theStartTime.Unix()
  9332. start_time_timestamp := recordStartTime
  9333. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9334. if err != nil {
  9335. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9336. return
  9337. }
  9338. recordEndTime := theEndTime.Unix()
  9339. end_time_timestamp := recordEndTime
  9340. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9341. if updateErr == nil {
  9342. this.ServeSuccessJSON(map[string]interface{}{
  9343. "msg": "修改成功",
  9344. })
  9345. } else {
  9346. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9347. return
  9348. }
  9349. }
  9350. }
  9351. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9352. patient_id, _ := c.GetInt64("patient_id")
  9353. his_patient_id, _ := c.GetInt64("his_patient_id")
  9354. record_date := c.GetString("record_date")
  9355. start_time := c.GetString("start_time")
  9356. end_time := c.GetString("end_time")
  9357. order_status, _ := c.GetInt64("type", 0)
  9358. p_type, _ := c.GetInt64("p_type", 0)
  9359. order_id, _ := c.GetInt64("order_id", 0)
  9360. timeLayout := "2006-01-02"
  9361. loc, _ := time.LoadLocation("Local")
  9362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9363. if err != nil {
  9364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9365. return
  9366. }
  9367. recordDateTime := theTime.Unix()
  9368. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9369. if err != nil {
  9370. }
  9371. startRecordDateTime := startTime.Unix()
  9372. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9373. if err != nil {
  9374. }
  9375. endRecordDateTime := endTime.Unix()
  9376. admin := c.GetAdminUserInfo()
  9377. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9378. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9379. order, _ := service.GetHisOrderByID(order_id)
  9380. var monthPrescriptions []*models.HisPrescription
  9381. if order_status == 1 || order_status == 0 {
  9382. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9383. } else if order_status == 2 {
  9384. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9385. }
  9386. var settle_total float64
  9387. for _, item := range monthPrescriptions {
  9388. if len(item.HisPrescriptionProject) > 0 {
  9389. for _, subItem := range item.HisPrescriptionProject {
  9390. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9391. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9392. settle_total = settle_total + total
  9393. }
  9394. }
  9395. if len(item.HisDoctorAdviceInfo) > 0 {
  9396. for _, subItem := range item.HisDoctorAdviceInfo {
  9397. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9398. settle_total = settle_total + total
  9399. }
  9400. }
  9401. }
  9402. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9403. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9404. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9405. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9406. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9407. //获取所有科室信息
  9408. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9409. c.ServeSuccessJSON(map[string]interface{}{
  9410. "his_info": his_patient_info,
  9411. "xt_info": xt_patient_info,
  9412. "case_history": case_history,
  9413. "info": patientPrescriptionInfo,
  9414. "last_info": lastPatientPrescriptionInfo,
  9415. "month_prescriptions": monthPrescriptions,
  9416. "order": order,
  9417. "doctors": doctors,
  9418. "department": department,
  9419. "settle_total": settle_total,
  9420. })
  9421. return
  9422. }
  9423. func (c *HisApiController) GetHisMonthPatientInfo() {
  9424. patient_id, _ := c.GetInt64("patient_id")
  9425. his_patient_id, _ := c.GetInt64("his_patient_id")
  9426. record_date := c.GetString("record_date")
  9427. number := c.GetString("number")
  9428. start_time := c.GetString("start_time")
  9429. end_time := c.GetString("end_time")
  9430. p_type, _ := c.GetInt64("p_type")
  9431. timeLayout := "2006-01-02"
  9432. loc, _ := time.LoadLocation("Local")
  9433. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9434. if err != nil {
  9435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9436. return
  9437. }
  9438. recordDateTime := theTime.Unix()
  9439. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9440. if err != nil {
  9441. }
  9442. startRecordDateTime := startTime.Unix()
  9443. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9444. if err != nil {
  9445. }
  9446. endRecordDateTime := endTime.Unix()
  9447. admin := c.GetAdminUserInfo()
  9448. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9449. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9450. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9451. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9452. var settle_total float64
  9453. for _, item := range monthPrescriptions {
  9454. if len(item.HisPrescriptionProject) > 0 {
  9455. for _, subItem := range item.HisPrescriptionProject {
  9456. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9457. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9458. settle_total = settle_total + total
  9459. }
  9460. }
  9461. if len(item.HisDoctorAdviceInfo) > 0 {
  9462. for _, subItem := range item.HisDoctorAdviceInfo {
  9463. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9464. settle_total = settle_total + total
  9465. }
  9466. }
  9467. }
  9468. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9469. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9470. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9471. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9472. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9473. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9474. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9475. //获取所有科室信息
  9476. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9477. c.ServeSuccessJSON(map[string]interface{}{
  9478. "his_info": his_patient_info,
  9479. "xt_info": xt_patient_info,
  9480. "case_history": case_history,
  9481. "info": patientPrescriptionInfo,
  9482. "month_prescriptions": monthPrescriptions,
  9483. "order": order,
  9484. "doctors": doctors,
  9485. "department": department,
  9486. "count": count,
  9487. "drugStockConfig": drugStockConfig,
  9488. "last_info": lastPatientPrescriptionInfo,
  9489. "settle_total": settle_total,
  9490. })
  9491. return
  9492. }
  9493. func (c *HisApiController) GetAllOrder() {
  9494. org_id := c.GetAdminUserInfo().CurrentOrgId
  9495. orders, _ := service.GetNewHisOrderList(org_id)
  9496. c.ServeSuccessJSON(map[string]interface{}{
  9497. "order": orders,
  9498. })
  9499. return
  9500. }
  9501. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9502. newArr = make([]*models.HisOrderInfoTwo, 0)
  9503. for i := 0; i < len(arr); i++ {
  9504. repeat := false
  9505. for j := i + 1; j < len(arr); j++ {
  9506. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9507. repeat = true
  9508. break
  9509. }
  9510. }
  9511. if !repeat {
  9512. newArr = append(newArr, arr[i])
  9513. }
  9514. }
  9515. return
  9516. }
  9517. // 修改处方退库操作 参数传修改之前的处方数据
  9518. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9519. if advice.ExecutionState == 1 {
  9520. //查询该病人该药品是否有库存记录
  9521. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9522. if errcode == gorm.ErrRecordNotFound {
  9523. } else {
  9524. //退库
  9525. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9526. if advice.PrescribingNumberUnit == drug.MinUnit {
  9527. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9528. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9529. //退库
  9530. warehouseInfo := models.DrugWarehouseInfo{
  9531. StockMinNumber: prescribingNumber,
  9532. }
  9533. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9534. operation_time := time.Now().Unix()
  9535. creater := advice.AdviceDoctor
  9536. ctime := time.Now().Unix()
  9537. timeStr := time.Now().Format("2006-01-02")
  9538. timeArr := strings.Split(timeStr, "-")
  9539. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9540. total = total + 1
  9541. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9542. cancelStock := models.DrugCancelStock{
  9543. OrderNumber: orderNumber,
  9544. OperaTime: operation_time,
  9545. OrgId: advice.UserOrgId,
  9546. Creater: creater,
  9547. Ctime: ctime,
  9548. Status: 1,
  9549. ReturnTime: advice.AdviceDate,
  9550. Dealer: info.Dealer,
  9551. Manufacturer: info.Manufacturer,
  9552. Type: 1,
  9553. }
  9554. service.AddSigleDrugCancelStock(&cancelStock)
  9555. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9556. dealer, _ := service.GetDealerById(info.Dealer)
  9557. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9558. cancelStockInfo := models.DrugCancelStockInfo{
  9559. OrderNumber: cancelInfo.OrderNumber,
  9560. CancelStockId: cancelInfo.ID,
  9561. DrugId: info.DrugId,
  9562. Count: info.Count,
  9563. Status: 1,
  9564. Ctime: ctime,
  9565. OrgId: advice.UserOrgId,
  9566. Type: 1,
  9567. Manufacturer: manufactureName.ManufacturerName,
  9568. Dealer: dealer.DealerName,
  9569. Total: 0,
  9570. RetailPrice: info.RetailPrice,
  9571. RetailTotalPrice: info.RetailTotalPrice,
  9572. Price: info.Price,
  9573. RegisterAccount: "",
  9574. Remark: info.Remark,
  9575. BatchNumber: info.BatchNumber,
  9576. MaxUnit: info.CountUnit,
  9577. ProductDate: info.ProductDate,
  9578. ExpiryDate: info.ExpiryDate,
  9579. BatchNumberId: info.WarehouseInfoId,
  9580. }
  9581. flow := models.DrugFlow{
  9582. WarehousingId: 0,
  9583. DrugId: info.DrugId,
  9584. Number: "",
  9585. BatchNumber: info.BatchNumber,
  9586. Count: info.Count,
  9587. UserOrgId: advice.UserOrgId,
  9588. PatientId: 0,
  9589. SystemTime: ctime,
  9590. ConsumableType: 4,
  9591. IsSys: 0,
  9592. WarehousingOrder: "",
  9593. WarehouseOutId: 0,
  9594. WarehouseOutOrderNumber: "",
  9595. IsEdit: 0,
  9596. CancelStockId: cancelStock.ID,
  9597. CancelOrderNumber: cancelStock.OrderNumber,
  9598. Manufacturer: info.Manufacturer,
  9599. Dealer: info.Dealer,
  9600. Creator: advice.UserOrgId,
  9601. UpdateCreator: 0,
  9602. Status: 1,
  9603. Ctime: time.Now().Unix(),
  9604. Mtime: 0,
  9605. Price: info.Price,
  9606. WarehousingDetailId: 0,
  9607. WarehouseOutDetailId: 0,
  9608. CancelOutDetailId: 0,
  9609. ExpireDate: info.ExpiryDate,
  9610. ProductDate: info.ProductDate,
  9611. MaxUnit: info.CountUnit,
  9612. MinUnit: "",
  9613. }
  9614. service.CreatedCancelStock(cancelStockInfo)
  9615. service.CreateDrugFlowOne(flow)
  9616. } else {
  9617. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9618. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9619. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9620. warehouseInfo := models.DrugWarehouseInfo{
  9621. StockMinNumber: prescribingNumber,
  9622. }
  9623. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9624. }
  9625. operation_time := time.Now().Unix()
  9626. creater := advice.AdviceDoctor
  9627. ctime := time.Now().Unix()
  9628. timeStr := time.Now().Format("2006-01-02")
  9629. timeArr := strings.Split(timeStr, "-")
  9630. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9631. total = total + 1
  9632. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9633. cancelStock := models.DrugCancelStock{
  9634. OrderNumber: orderNumber,
  9635. OperaTime: operation_time,
  9636. OrgId: advice.UserOrgId,
  9637. Creater: creater,
  9638. Ctime: ctime,
  9639. Status: 1,
  9640. ReturnTime: advice.AdviceDate,
  9641. Dealer: info.Dealer,
  9642. Manufacturer: info.Manufacturer,
  9643. Type: 1,
  9644. }
  9645. service.AddSigleDrugCancelStock(&cancelStock)
  9646. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9647. dealer, _ := service.GetDealerById(info.Dealer)
  9648. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9649. cancelStockInfo := models.DrugCancelStockInfo{
  9650. OrderNumber: cancelInfo.OrderNumber,
  9651. CancelStockId: cancelInfo.ID,
  9652. DrugId: info.DrugId,
  9653. Count: info.Count,
  9654. Status: 1,
  9655. Ctime: ctime,
  9656. OrgId: advice.UserOrgId,
  9657. Type: 1,
  9658. Manufacturer: manufactureName.ManufacturerName,
  9659. Dealer: dealer.DealerName,
  9660. Total: 0,
  9661. RetailPrice: info.RetailPrice,
  9662. RetailTotalPrice: info.RetailTotalPrice,
  9663. Price: info.Price,
  9664. RegisterAccount: "",
  9665. Remark: info.Remark,
  9666. BatchNumber: info.BatchNumber,
  9667. MaxUnit: info.CountUnit,
  9668. ProductDate: info.ProductDate,
  9669. ExpiryDate: info.ExpiryDate,
  9670. BatchNumberId: info.WarehouseInfoId,
  9671. }
  9672. flow := models.DrugFlow{
  9673. WarehousingId: 0,
  9674. DrugId: info.DrugId,
  9675. Number: "",
  9676. BatchNumber: info.BatchNumber,
  9677. Count: info.Count,
  9678. UserOrgId: advice.UserOrgId,
  9679. PatientId: 0,
  9680. SystemTime: ctime,
  9681. ConsumableType: 4,
  9682. IsSys: 0,
  9683. WarehousingOrder: "",
  9684. WarehouseOutId: 0,
  9685. WarehouseOutOrderNumber: "",
  9686. IsEdit: 0,
  9687. CancelStockId: cancelStock.ID,
  9688. CancelOrderNumber: cancelStock.OrderNumber,
  9689. Manufacturer: info.Manufacturer,
  9690. Dealer: info.Dealer,
  9691. Creator: advice.AdviceDoctor,
  9692. UpdateCreator: 0,
  9693. Status: 1,
  9694. Ctime: time.Now().Unix(),
  9695. Mtime: 0,
  9696. Price: info.Price,
  9697. WarehousingDetailId: 0,
  9698. WarehouseOutDetailId: 0,
  9699. CancelOutDetailId: 0,
  9700. ExpireDate: info.ExpiryDate,
  9701. ProductDate: info.ProductDate,
  9702. MaxUnit: info.CountUnit,
  9703. MinUnit: "",
  9704. }
  9705. service.CreatedCancelStock(cancelStockInfo)
  9706. service.CreateDrugFlowOne(flow)
  9707. }
  9708. }
  9709. }
  9710. return err
  9711. }
  9712. func (this *HisApiController) DeleteNCDS() {
  9713. id, _ := this.GetInt64("id", 0)
  9714. if id > 0 {
  9715. service.DeletePsnNCDSRecordById(id)
  9716. this.ServeSuccessJSON(map[string]interface{}{
  9717. "msg": "删除成功",
  9718. })
  9719. } else {
  9720. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9721. return
  9722. }
  9723. }
  9724. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9725. id, _ := c.GetInt64("id")
  9726. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9727. c.ServeSuccessJSON(map[string]interface{}{
  9728. "advice": advice,
  9729. })
  9730. return
  9731. }
  9732. func (c *HisApiController) GetHisMonthChargePatientList() {
  9733. record_date := c.GetString("record_date")
  9734. start_time := c.GetString("start_time")
  9735. end_time := c.GetString("end_time")
  9736. timeLayout := "2006-01-02"
  9737. loc, _ := time.LoadLocation("Local")
  9738. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9739. if err != nil {
  9740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9741. return
  9742. }
  9743. if err != nil {
  9744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9745. return
  9746. }
  9747. recordDateTime := theTime.Unix()
  9748. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9749. if err != nil {
  9750. }
  9751. startRecordDateTime := startTime.Unix()
  9752. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9753. if err != nil {
  9754. }
  9755. endRecordDateTime := endTime.Unix()
  9756. adminInfo := c.GetAdminUserInfo()
  9757. var tempMonthChargePatients []*service.MonthChargePatients
  9758. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9759. for _, item := range tempPatients {
  9760. //过滤没有处方的
  9761. if len(item.HisPrescription) == 0 {
  9762. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9763. }
  9764. }
  9765. c.ServeSuccessJSON(map[string]interface{}{
  9766. "list": tempMonthChargePatients,
  9767. })
  9768. }