his_api_controller.go 430KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041
  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. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. }
  88. func (c *HisApiController) GetFaPiaoNumber() {
  89. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  90. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  91. fmt.Println(count)
  92. var zero string
  93. number := count + 1
  94. if number >= 1000 {
  95. zero = "0000" + strconv.FormatInt(number, 10)
  96. } else if number >= 10000 {
  97. zero = "000" + strconv.FormatInt(number, 10)
  98. } else if number >= 100000 {
  99. zero = "00" + strconv.FormatInt(number, 10)
  100. } else if number >= 1000000 {
  101. zero = "0" + strconv.FormatInt(number, 10)
  102. } else {
  103. zero = strconv.FormatInt(number, 10)
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "fapiao_number": zero,
  107. })
  108. return
  109. }
  110. func (c *HisApiController) ChangeOrderDesc() {
  111. id, _ := c.GetInt64("id")
  112. desc := c.GetString("desc")
  113. change_type := c.GetString("change_type")
  114. order, _ := service.GetHisOrderByID(id)
  115. if order.ID == 0 {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. switch change_type {
  120. case "oth_desc":
  121. order.OthDesc = desc
  122. break
  123. case "cash_pay":
  124. order.CashPay = desc
  125. break
  126. case "jifen_pay":
  127. order.JifenPay = desc
  128. break
  129. case "band_card_pay":
  130. order.BandCardPay = desc
  131. break
  132. case "ali_pay":
  133. order.AliPay = desc
  134. break
  135. case "wechat_pay":
  136. order.WechatPay = desc
  137. break
  138. }
  139. err := service.SaveHisOrder(&order)
  140. if err == nil {
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "msg": "修改成功",
  143. })
  144. return
  145. } else {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  147. return
  148. }
  149. }
  150. func (c *HisApiController) GetMonthHisPatient() {
  151. record_date := c.GetString("record_date")
  152. //order_status, _ := c.GetInt64("type")
  153. timeLayout := "2006-01-02"
  154. loc, _ := time.LoadLocation("Local")
  155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  156. if err != nil {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. recordDateTime := theTime.Unix()
  161. adminInfo := c.GetAdminUserInfo()
  162. var tempPatients []service.NewTempPatients
  163. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  164. // 获取当前时间
  165. now := time.Now()
  166. // 获取本月的第一天
  167. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  168. // 获取下个月的第一天
  169. nextMonth := firstDay.AddDate(0, 1, 0)
  170. // 获取本月的最后一天
  171. lastDay := nextMonth.Add(-time.Nanosecond)
  172. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  173. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  174. var patients []service.NewTempPatients
  175. var patients_two []service.NewTempPatients
  176. for _, item := range tempPatients {
  177. //过滤掉没挂号的和没开处方的
  178. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  179. patients = append(patients, item)
  180. }
  181. ////过滤掉没挂号的
  182. //if len(item.HisPatient) > 0 {
  183. // patients_two = append(patients_two, item)
  184. //}
  185. }
  186. c.ServeSuccessJSON(map[string]interface{}{
  187. "list": patients,
  188. "list_two": patients_two,
  189. "chargePatients": chargePatients,
  190. })
  191. }
  192. func (c *HisApiController) GetBatchSettleAccounts() {
  193. order_ids := c.GetString("order_ids")
  194. admin_user_id, _ := c.GetInt64("admin_user_id")
  195. adminUser := c.GetAdminUserInfo()
  196. orders := strings.Split(order_ids, ",")
  197. var newOrders []models.Orders
  198. for _, item := range orders {
  199. order, _ := service.GetHisOrderByIDTenOne(item)
  200. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  201. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  202. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  203. orderInfos = append(orderInfos, orderInfos_two...)
  204. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  205. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  206. var diagnosis_ids []string
  207. if his.ID > 0 {
  208. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  209. } else {
  210. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  211. }
  212. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  213. var dia_config []*models.HisXtDiagnoseConfig
  214. var name string
  215. for _, item := range diagnosis_ids {
  216. id, _ := strconv.ParseInt(item, 10, 64)
  217. diagnosisConfig, _ := service.FindDiagnoseById(id)
  218. dia_config = append(dia_config, diagnosisConfig)
  219. if len(name) == 0 {
  220. name = diagnosisConfig.ClassName
  221. } else {
  222. name = name + "," + diagnosisConfig.ClassName
  223. }
  224. }
  225. var bedCostTotal float64 = 0 //床位总费
  226. var bedCostSelfTotal float64 = 0 //床位自费
  227. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  228. var bedSelfTotal float64 = 0 //床位部分项目自费
  229. var bedInscpTotal float64 = 0 //床位部分项目自费
  230. var operationCostTotal float64 = 0 //手术费
  231. var operationCostSelfTotal float64 = 0 //手术费
  232. var operationCostPartSelfTotal float64 = 0 //手术费
  233. var operationSelfTotal float64 = 0 //床位部分项目自费
  234. var operationInscpTotal float64 = 0 //床位部分项目自费
  235. var otherCostTotal float64 = 0 //其他费用
  236. var otherCostSelfTotal float64 = 0 //其他费用
  237. var otherCostPartSelfTotal float64 = 0 //其他费用
  238. var otherSelfTotal float64 = 0 //床位部分项目自费
  239. var otherInscpTotal float64 = 0 //床位部分项目自费
  240. var materialCostTotal float64 = 0 //材料费
  241. var materialCostSelfTotal float64 = 0 //材料费
  242. var materialCostPartSelfTotal float64 = 0 //材料费
  243. var materialSelfTotal float64 = 0 //床位部分项目自费
  244. var materialInscpTotal float64 = 0 //床位部分项目自费
  245. var westernMedicineCostTotal float64 = 0 //西药费
  246. var westernMedicineCostSelfTotal float64 = 0 //西药费
  247. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  248. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  249. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  250. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  251. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  252. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  253. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  254. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  255. var checkCostTotal float64 = 0 //检查费
  256. var checkCostSelfTotal float64 = 0 //检查费
  257. var checkCostPartSelfTotal float64 = 0 //检查费
  258. var checkSelfTotal float64 = 0 //床位部分项目自费
  259. var checkInscpTotal float64 = 0 //床位部分项目自费
  260. var laboratoryCostTotal float64 = 0 //化验费
  261. var laboratoryCostSelfTotal float64 = 0 //化验费
  262. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  263. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  264. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  265. var treatCostTotal float64 = 0 //治疗费用
  266. var treatCostSelfTotal float64 = 0 //治疗费用
  267. var treatCostPartSelfTotal float64 = 0 //治疗费用
  268. var treatSelfTotal float64 = 0 //床位部分项目自费
  269. var treatInscpTotal float64 = 0 //床位部分项目自费
  270. decimal.DivisionPrecision = 2
  271. for _, item := range orderInfos {
  272. if item.MedChrgitmType == "01" { //床位费
  273. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  274. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  275. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  276. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  277. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  278. }
  279. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  280. if item.MedChrgitmType == "03" { //检查费
  281. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. } else {
  288. if item.MedChrgitmType == "03" { //检查费
  289. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  290. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  291. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  292. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  293. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  294. }
  295. }
  296. if item.MedChrgitmType == "04" { //化验费
  297. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  298. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  299. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  300. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  301. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  302. }
  303. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  304. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  305. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  306. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  307. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  308. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  309. }
  310. if item.MedChrgitmType == "06" { //手术费
  311. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  315. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  316. }
  317. if item.MedChrgitmType == "08" { //材料费
  318. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  319. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  320. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  321. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  322. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  323. }
  324. if item.MedChrgitmType == "09" { //西药费
  325. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  326. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  327. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  328. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  329. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  330. }
  331. if item.MedChrgitmType == "11" { //中成费
  332. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  333. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  334. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  335. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  336. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  337. }
  338. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  339. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  340. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  341. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  342. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  343. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  344. }
  345. }
  346. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  347. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  348. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  349. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  350. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  351. var doctor_name string
  352. if roles.ID == 0 {
  353. doctor_name = "管理员"
  354. } else {
  355. doctor_name = roles.UserName
  356. }
  357. yiliao_leibie := ""
  358. switch order.MedType {
  359. case "11":
  360. yiliao_leibie = "普通门诊"
  361. break
  362. case "12":
  363. yiliao_leibie = "门诊挂号"
  364. break
  365. case "13":
  366. yiliao_leibie = "急诊"
  367. break
  368. case "14":
  369. yiliao_leibie = "门诊特殊病"
  370. break
  371. case "15":
  372. yiliao_leibie = "门诊统筹"
  373. break
  374. case "16":
  375. yiliao_leibie = "门诊慢性病"
  376. break
  377. case "21":
  378. yiliao_leibie = "普通住院"
  379. break
  380. }
  381. var newOrder models.Orders
  382. newOrder.Diagnosis = name
  383. newOrder.OrderInfos = orderInfos
  384. newOrder.Number = order.MdtrtId
  385. newOrder.Date = order.SettleAccountsDate
  386. newOrder.ChargeAdmin = charge_admin
  387. newOrder.PrintorAdmin = printor_admin
  388. newOrder.Order = order
  389. newOrder.BedCostTotal = bedCostTotal
  390. newOrder.BedCostSelfTotal = bedCostSelfTotal
  391. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  392. newOrder.BedSelfTotal = bedSelfTotal
  393. newOrder.BedInscpTotal = bedInscpTotal
  394. newOrder.OperationCostTotal = operationCostTotal
  395. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  396. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  397. newOrder.OperationSelfTotal = operationSelfTotal
  398. newOrder.OperationInscpTotal = operationInscpTotal
  399. newOrder.OtherCostTotal = otherCostTotal
  400. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  401. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  402. newOrder.OtherSelfTotal = otherSelfTotal
  403. newOrder.OtherInscpTotal = otherInscpTotal
  404. newOrder.MaterialCostTotal = materialCostTotal
  405. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  406. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  407. newOrder.MaterialSelfTotal = materialSelfTotal
  408. newOrder.MaterialInscpTotal = materialInscpTotal
  409. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  410. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  411. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  412. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  413. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  414. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  415. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  416. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  417. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  418. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  419. newOrder.CheckCostTotal = checkCostTotal
  420. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  421. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  422. newOrder.CheckSelfTotal = checkSelfTotal
  423. newOrder.CheckInscpTotal = checkInscpTotal
  424. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  425. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  426. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  427. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  428. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  429. newOrder.TreatCostTotal = treatCostTotal
  430. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  431. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  432. newOrder.TreatSelfTotal = treatSelfTotal
  433. newOrder.TreatInscpTotal = treatInscpTotal
  434. newOrder.DoctorInfo = doctor_info
  435. newOrder.DoctorName = doctor_name
  436. newOrder.HealthCardNo = order.PsnNo
  437. newOrder.YiliaoLeibie = yiliao_leibie
  438. newOrder.Patient = patient
  439. newOrder.OrgName = miConfig.OrgName
  440. newOrder.OrgCode = miConfig.Code
  441. newOrder.OrderNumber = order.Number
  442. newOrder.HisPatient = his
  443. newOrder.DiaConfig = dia_config
  444. newOrders = append(newOrders, newOrder)
  445. }
  446. c.ServeSuccessJSON(map[string]interface{}{
  447. "orders": newOrders,
  448. })
  449. }
  450. func (c *HisApiController) GetTestOrder() {
  451. order_id, _ := c.GetInt64("order_id")
  452. admin_user_id, _ := c.GetInt64("admin_user_id")
  453. adminUser := c.GetAdminUserInfo()
  454. order, _ := service.GetHisOrderByID(order_id)
  455. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  456. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  457. orderInfos = append(orderInfos, orderInfos_two...)
  458. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  459. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  460. var dia_config []*models.HisXtDiagnoseConfig
  461. var name string
  462. var bedCostTotal float64 = 0 //床位总费
  463. var bedCostSelfTotal float64 = 0 //床位自费
  464. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  465. var bedSelfTotal float64 = 0 //床位部分项目自费
  466. var bedInscpTotal float64 = 0 //床位部分项目自费
  467. var operationCostTotal float64 = 0 //手术费
  468. var operationCostSelfTotal float64 = 0 //手术费
  469. var operationCostPartSelfTotal float64 = 0 //手术费
  470. var operationSelfTotal float64 = 0 //床位部分项目自费
  471. var operationInscpTotal float64 = 0 //床位部分项目自费
  472. var otherCostTotal float64 = 0 //其他费用
  473. var otherCostSelfTotal float64 = 0 //其他费用
  474. var otherCostPartSelfTotal float64 = 0 //其他费用
  475. var otherSelfTotal float64 = 0 //床位部分项目自费
  476. var otherInscpTotal float64 = 0 //床位部分项目自费
  477. var materialCostTotal float64 = 0 //材料费
  478. var materialCostSelfTotal float64 = 0 //材料费
  479. var materialCostPartSelfTotal float64 = 0 //材料费
  480. var materialSelfTotal float64 = 0 //床位部分项目自费
  481. var materialInscpTotal float64 = 0 //床位部分项目自费
  482. var westernMedicineCostTotal float64 = 0 //西药费
  483. var westernMedicineCostSelfTotal float64 = 0 //西药费
  484. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  485. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  486. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  487. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  488. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  489. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  490. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  491. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  492. var checkCostTotal float64 = 0 //检查费
  493. var checkCostSelfTotal float64 = 0 //检查费
  494. var checkCostPartSelfTotal float64 = 0 //检查费
  495. var checkSelfTotal float64 = 0 //床位部分项目自费
  496. var checkInscpTotal float64 = 0 //床位部分项目自费
  497. var laboratoryCostTotal float64 = 0 //化验费
  498. var laboratoryCostSelfTotal float64 = 0 //化验费
  499. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  500. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  501. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  502. var treatCostTotal float64 = 0 //治疗费用
  503. var treatCostSelfTotal float64 = 0 //治疗费用
  504. var treatCostPartSelfTotal float64 = 0 //治疗费用
  505. var treatSelfTotal float64 = 0 //床位部分项目自费
  506. var treatInscpTotal float64 = 0 //床位部分项目自费
  507. decimal.DivisionPrecision = 2
  508. for _, item := range orderInfos {
  509. if item.MedChrgitmType == "01" { //床位费
  510. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  511. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  512. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  513. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  514. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  515. }
  516. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  517. if item.MedChrgitmType == "03" { //检查费
  518. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. } else {
  525. if item.MedChrgitmType == "03" { //检查费
  526. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  527. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  528. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  529. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  530. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  531. }
  532. }
  533. if item.MedChrgitmType == "04" { //化验费
  534. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  535. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  536. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  537. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  538. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  539. }
  540. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  541. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  542. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  543. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  544. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  545. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  546. }
  547. if item.MedChrgitmType == "06" { //手术费
  548. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  549. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  550. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  551. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  552. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  553. }
  554. if item.MedChrgitmType == "08" { //材料费
  555. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  556. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  557. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  558. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  559. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  560. }
  561. if item.MedChrgitmType == "09" { //西药费
  562. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  563. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  564. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  565. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  566. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  567. }
  568. if item.MedChrgitmType == "11" { //中成费
  569. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  570. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  571. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  572. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  573. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  574. }
  575. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  576. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  577. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  578. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  579. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  580. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  581. }
  582. }
  583. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  584. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  585. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  586. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  587. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  588. var doctor_name string
  589. if roles.ID == 0 {
  590. doctor_name = "管理员"
  591. } else {
  592. doctor_name = roles.UserName
  593. }
  594. yiliao_leibie := ""
  595. switch order.MedType {
  596. case "11":
  597. yiliao_leibie = "普通门诊"
  598. break
  599. case "12":
  600. yiliao_leibie = "门诊挂号"
  601. break
  602. case "13":
  603. yiliao_leibie = "急诊"
  604. break
  605. case "14":
  606. yiliao_leibie = "门诊特殊病"
  607. break
  608. case "15":
  609. yiliao_leibie = "门诊统筹"
  610. break
  611. case "16":
  612. yiliao_leibie = "门诊慢性病"
  613. break
  614. case "21":
  615. yiliao_leibie = "普通住院"
  616. break
  617. }
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "diagnosis": name,
  620. "order_infos": orderInfos,
  621. "number": order.MdtrtId,
  622. "date": order.SettleAccountsDate,
  623. "charge_admin": charge_admin,
  624. "printor_admin": printor_admin,
  625. "info": order,
  626. "order": order,
  627. "bedCostTotal": bedCostTotal,
  628. "bedCostSelfTotal": bedCostSelfTotal,
  629. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  630. "bedSelfTotal": bedSelfTotal,
  631. "bedInscpTotal": bedInscpTotal,
  632. "operationCostTotal": operationCostTotal,
  633. "operationCostSelfTotal": operationCostSelfTotal,
  634. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  635. "operationSelfTotal": operationSelfTotal,
  636. "operationInscpTotal": operationInscpTotal,
  637. "otherCostTotal": otherCostTotal,
  638. "otherCostSelfTotal": otherCostSelfTotal,
  639. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  640. "otherSelfTotal": otherSelfTotal,
  641. "otherInscpTotal": otherInscpTotal,
  642. "materialCostTotal": materialCostTotal,
  643. "materialCostSelfTotal": materialCostSelfTotal,
  644. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  645. "materialSelfTotal": materialSelfTotal,
  646. "materialInscpTotal": materialInscpTotal,
  647. "westernMedicineCostTotal": westernMedicineCostTotal,
  648. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  649. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  650. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  651. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  652. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  653. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  654. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  655. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  656. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  657. "checkCostTotal": checkCostTotal,
  658. "checkCostSelfTotal": checkCostSelfTotal,
  659. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  660. "checkSelfTotal": checkSelfTotal,
  661. "checkInscpTotal": checkInscpTotal,
  662. "laboratoryCostTotal": laboratoryCostTotal,
  663. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  664. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  665. "laboratorySelfTotal": laboratorySelfTotal,
  666. "laboratoryInscpTotal": laboratoryInscpTotal,
  667. "treatCostTotal": treatCostTotal,
  668. "treatCostSelfTotal": treatCostSelfTotal,
  669. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  670. "treatSelfTotal": treatSelfTotal,
  671. "treatInscpTotal": treatInscpTotal,
  672. "doctor_info": doctor_info,
  673. "doctor_name": doctor_name,
  674. "health_card_no": order.PsnNo,
  675. "yiliao_leibie": yiliao_leibie,
  676. "patient": patient,
  677. "org_name": miConfig.OrgName,
  678. "org_code": miConfig.Code,
  679. "order_number": order.Number,
  680. "his_hospital": his_hospital,
  681. "dia_config": dia_config,
  682. })
  683. }
  684. func (c *PublicApiController) GetBaiLinExportData() {
  685. data := service.GetBaiLinOrderData()
  686. fmt.Println(len(data))
  687. var new_data []*models.NewCustomHisOrder
  688. for _, item := range data {
  689. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  690. new_data = append(new_data, item)
  691. }
  692. }
  693. fmt.Println(len(new_data))
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "list": new_data,
  696. })
  697. }
  698. func (c *HisApiController) GetHisUnChargePatientList() {
  699. record_date := c.GetString("record_date")
  700. sch_type, _ := c.GetInt64("sch_type")
  701. timeLayout := "2006-01-02"
  702. loc, _ := time.LoadLocation("Local")
  703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  704. if err != nil {
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. recordDateTime := theTime.Unix()
  709. adminInfo := c.GetAdminUserInfo()
  710. var tempPatients []*service.NewTempPatients
  711. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  712. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  713. var patients []*service.NewTempPatients
  714. var patients_two []*service.NewTempPatients
  715. for _, item := range tempPatients {
  716. //过滤掉没挂号的和没开处方的
  717. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  718. patients = append(patients, item)
  719. }
  720. //过滤掉没挂号的
  721. if len(item.HisPatient) > 0 {
  722. patients_two = append(patients_two, item)
  723. }
  724. }
  725. c.ServeSuccessJSON(map[string]interface{}{
  726. "list": patients,
  727. "list_two": patients_two,
  728. })
  729. }
  730. func (c *HisApiController) GetPrivateExpensesOrder() {
  731. //id, _ := c.GetInt64("id")
  732. //record_time := c.GetString("record_time")
  733. order_id, _ := c.GetInt64("order_id")
  734. admin_user_id, _ := c.GetInt64("admin_user_id")
  735. //timeLayout := "2006-01-02"
  736. //loc, _ := time.LoadLocation("Local")
  737. //
  738. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  739. //if err != nil {
  740. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. // return
  742. //}
  743. //recordDateTime := theTime.Unix()
  744. adminUser := c.GetAdminUserInfo()
  745. order, _ := service.GetHisOrderByID(order_id)
  746. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  747. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  748. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  749. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  750. //var config []*models.HisXtDiagnoseConfig
  751. var name string
  752. if order.PType == 1 {
  753. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  754. for _, item := range diagnosis_ids {
  755. id, _ := strconv.ParseInt(item, 10, 64)
  756. diagnosisConfig, _ := service.FindDiagnoseById(id)
  757. if len(name) == 0 {
  758. name = diagnosisConfig.ClassName
  759. } else {
  760. name = name + "," + diagnosisConfig.ClassName
  761. }
  762. }
  763. } else {
  764. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  765. for _, item := range diagnosis_ids {
  766. id, _ := strconv.ParseInt(item, 10, 64)
  767. diagnosisConfig, _ := service.FindDiagnoseById(id)
  768. if len(name) == 0 {
  769. name = diagnosisConfig.ClassName
  770. } else {
  771. name = name + "," + diagnosisConfig.ClassName
  772. }
  773. }
  774. }
  775. var bedCostTotal float64 = 0 //床位总费
  776. //var bedCostSelfTotal float64 = 0 //床位自费
  777. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  778. var operationCostTotal float64 = 0 //手术费
  779. //var operationCostSelfTotal float64 = 0 //手术费
  780. var operationCostPartSelfTotal float64 = 0 //手术费
  781. var otherCostTotal float64 = 0 //其他费用
  782. //var otherCostSelfTotal float64 = 0 //其他费用
  783. var otherCostPartSelfTotal float64 = 0 //其他费用
  784. var materialCostTotal float64 = 0 //材料费
  785. //var materialCostSelfTotal float64 = 0 //材料费
  786. var materialCostPartSelfTotal float64 = 0 //材料费
  787. var westernMedicineCostTotal float64 = 0 //西药费
  788. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  789. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  790. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  791. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  792. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  793. var checkCostTotal float64 = 0 //检查费
  794. //var checkCostSelfTotal float64 = 0 //检查费
  795. var checkCostPartSelfTotal float64 = 0 //检查费
  796. var laboratoryCostTotal float64 = 0 //化验费
  797. //var laboratoryCostSelfTotal float64 = 0 //化验费
  798. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  799. var treatCostTotal float64 = 0 //治疗费用
  800. //var treatCostSelfTotal float64 = 0 //治疗费用
  801. var treatCostPartSelfTotal float64 = 0 //治疗费用
  802. var zhenChaCostTotal float64 = 0 //其他费用
  803. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  804. decimal.DivisionPrecision = 2
  805. for _, item := range orderInfos {
  806. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  807. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  808. item.MedChrgitmType = "09"
  809. }
  810. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  811. if item.HisPrescriptionProject.Type == 2 {
  812. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  813. fmt.Println("CostClassify")
  814. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  815. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  816. case 0:
  817. item.MedChrgitmType = "0"
  818. break
  819. case 1:
  820. item.MedChrgitmType = "14"
  821. break
  822. case 2:
  823. item.MedChrgitmType = "05"
  824. break
  825. case 3:
  826. item.MedChrgitmType = "03"
  827. break
  828. case 4:
  829. item.MedChrgitmType = "03"
  830. break
  831. case 5:
  832. item.MedChrgitmType = "08"
  833. break
  834. case 6:
  835. item.MedChrgitmType = "14"
  836. break
  837. case 7:
  838. item.MedChrgitmType = "14"
  839. break
  840. case 8:
  841. item.MedChrgitmType = "03"
  842. break
  843. case 9:
  844. item.MedChrgitmType = "14"
  845. break
  846. case 10:
  847. item.MedChrgitmType = "14"
  848. break
  849. case 11:
  850. item.MedChrgitmType = "06"
  851. break
  852. case 12:
  853. item.MedChrgitmType = "12"
  854. break
  855. case 13:
  856. item.MedChrgitmType = "01"
  857. break
  858. case 14:
  859. item.MedChrgitmType = "04"
  860. break
  861. case 15:
  862. item.MedChrgitmType = "14"
  863. break
  864. }
  865. } else {
  866. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  867. case 1:
  868. item.MedChrgitmType = "14"
  869. break
  870. case 2:
  871. item.MedChrgitmType = "05"
  872. break
  873. case 3:
  874. item.MedChrgitmType = "04"
  875. break
  876. case 4:
  877. item.MedChrgitmType = "14"
  878. break
  879. case 5:
  880. item.MedChrgitmType = "08"
  881. break
  882. case 6:
  883. item.MedChrgitmType = "14"
  884. break
  885. case 7:
  886. item.MedChrgitmType = "14"
  887. break
  888. case 8:
  889. item.MedChrgitmType = "03"
  890. break
  891. case 9:
  892. item.MedChrgitmType = "14"
  893. break
  894. }
  895. }
  896. } else if item.HisPrescriptionProject.Type == 3 {
  897. item.MedChrgitmType = "08"
  898. }
  899. }
  900. }
  901. order.PsnCashPay = order.MedfeeSumamt
  902. for _, item := range orderInfos {
  903. if item.MedChrgitmType == "01" { //床位费
  904. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  905. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  906. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  907. }
  908. if item.MedChrgitmType == "02" { //诊察费
  909. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  910. //zhenChaCostSelfTotal = zhenChaCostTotal
  911. }
  912. if item.MedChrgitmType == "03" { //检查费
  913. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  914. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  915. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  916. }
  917. if item.MedChrgitmType == "02" { //检查费
  918. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  919. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  920. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  921. }
  922. if item.MedChrgitmType == "04" { //化验费
  923. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  924. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  925. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  926. }
  927. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  928. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  929. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  930. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  931. }
  932. if item.MedChrgitmType == "06" { //手术费
  933. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  934. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  935. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  936. }
  937. if item.MedChrgitmType == "08" { //材料费
  938. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  939. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  940. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  941. }
  942. if item.MedChrgitmType == "09" { //西药费
  943. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  944. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  945. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  946. }
  947. if item.MedChrgitmType == "11" { //中成费
  948. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  949. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  950. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  951. }
  952. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  953. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  954. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  955. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  956. }
  957. }
  958. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  959. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  960. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  961. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  962. c.ServeSuccessJSON(map[string]interface{}{
  963. "patient": patient,
  964. "order_infos": orderInfos,
  965. "diagnosis": name,
  966. "bedCostTotal": bedCostTotal,
  967. "bedCostSelfTotal": bedCostTotal,
  968. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  969. "operationCostTotal": operationCostTotal,
  970. "operationCostSelfTotal": operationCostTotal,
  971. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  972. "otherCostTotal": otherCostTotal,
  973. "otherCostSelfTotal": otherCostTotal,
  974. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  975. "materialCostTotal": materialCostTotal,
  976. "materialCostSelfTotal": materialCostTotal,
  977. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  978. "westernMedicineCostTotal": westernMedicineCostTotal,
  979. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  980. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  981. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  982. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  983. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  984. "checkCostTotal": checkCostTotal,
  985. "checkCostSelfTotal": checkCostTotal,
  986. "zhenChaCostTotal": zhenChaCostTotal,
  987. "zhenChaCostSelfTotal": zhenChaCostTotal,
  988. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  989. "laboratoryCostTotal": laboratoryCostTotal,
  990. "laboratoryCostSelfTotal": laboratoryCostTotal,
  991. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  992. "treatCostTotal": treatCostTotal,
  993. "treatCostSelfTotal": treatCostTotal,
  994. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  995. "charge_admin": charge_admin,
  996. "printor_admin": printor_admin,
  997. "org_name": org.OrgName,
  998. "org_code": miConfig.Code,
  999. "name": patient.Name,
  1000. "number": order.MdtrtId,
  1001. "date": order.SettleAccountsDate,
  1002. "info": order,
  1003. "his_hospital": his_hospital,
  1004. "his": his,
  1005. })
  1006. }
  1007. func (c *HisApiController) RefudDetail() {
  1008. order_id, _ := c.GetInt64("order_id")
  1009. order, _ := service.GetHisOrderByID(order_id)
  1010. adminUser := c.GetAdminUserInfo()
  1011. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1012. c.ServeSuccessJSON(map[string]interface{}{
  1013. "msg": "撤销成功",
  1014. })
  1015. }
  1016. func (c *HisApiController) Sscard() {
  1017. //r := CardInit()
  1018. //if r == 0 {
  1019. // GetBaseInfo()
  1020. //}
  1021. //c.ServeSuccessJSON(map[string]interface{}{
  1022. // "list": "11",
  1023. //})
  1024. }
  1025. func GetBaseInfo() error {
  1026. //handle := syscall.MustLoadDLL("SSCard.dll")
  1027. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1028. //
  1029. //str := make([]byte, 256)
  1030. //str1 := make([]byte, 256)
  1031. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1032. //if ferr != nil {
  1033. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1034. // return ferr
  1035. //}
  1036. //
  1037. //fmt.Println(string(str))
  1038. //
  1039. //fmt.Println(r)
  1040. return nil
  1041. }
  1042. func CardInit() int {
  1043. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1044. //add := DllTestDef.MustFindProc("Init")
  1045. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1046. //if err != nil {
  1047. // fmt.Println("SSCard的运算结果为:", ret)
  1048. //}
  1049. //result := int(ret)
  1050. return 0
  1051. }
  1052. func IntPtr(n int) uintptr {
  1053. return uintptr(n)
  1054. }
  1055. func StrPtr(s string) uintptr {
  1056. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1057. }
  1058. func (c *HisApiController) GetHisPatientList() {
  1059. //types, _ := c.GetInt64("type", 0)
  1060. record_date := c.GetString("record_date")
  1061. sch_type, _ := c.GetInt64("sch_type")
  1062. timeLayout := "2006-01-02"
  1063. loc, _ := time.LoadLocation("Local")
  1064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1065. if err != nil {
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1067. return
  1068. }
  1069. recordDateTime := theTime.Unix()
  1070. adminInfo := c.GetAdminUserInfo()
  1071. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1072. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1073. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1074. //获取当前用户的信息
  1075. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1076. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1077. //获取所有科室信息
  1078. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1079. c.ServeSuccessJSON(map[string]interface{}{
  1080. "list": patients,
  1081. "list_two": patients_two,
  1082. "info": adminUserInfo,
  1083. "doctors": doctors,
  1084. "department": department,
  1085. })
  1086. }
  1087. type CustomTemplate struct {
  1088. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1089. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1090. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1091. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1092. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1093. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1094. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1095. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1096. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1097. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1098. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1099. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1100. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1101. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1102. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1103. }
  1104. func (c *HisApiController) GetHisPatientInfo() {
  1105. patient_id, _ := c.GetInt64("patient_id")
  1106. his_patient_id, _ := c.GetInt64("his_patient_id")
  1107. record_date := c.GetString("record_date")
  1108. number := c.GetString("number")
  1109. //start_time := c.GetString("start_time")
  1110. //end_time := c.GetString("end_time")
  1111. p_type, _ := c.GetInt64("p_type")
  1112. timeLayout := "2006-01-02"
  1113. loc, _ := time.LoadLocation("Local")
  1114. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1115. if err != nil {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. recordDateTime := theTime.Unix()
  1120. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1121. //if err != nil {
  1122. //
  1123. //}
  1124. //startRecordDateTime := startTime.Unix()
  1125. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1126. //if err != nil {
  1127. //
  1128. //}
  1129. //endRecordDateTime := endTime.Unix()
  1130. admin := c.GetAdminUserInfo()
  1131. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1132. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1133. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1134. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1135. var prescriptions []*models.HisPrescription
  1136. var last_prescriptions []*models.HisPrescription
  1137. var sch_prescriptions []CustomTemplate
  1138. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1139. if p_type == 1 { //住院
  1140. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1141. for _, item := range prescriptions {
  1142. for _, subItem := range item.HisDoctorAdviceInfo {
  1143. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1144. if info.RetailPrice > 0 {
  1145. subItem.Drug.MinPrice = info.RetailPrice
  1146. }
  1147. }
  1148. }
  1149. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1150. } else { //门诊
  1151. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1152. for _, item := range prescriptions {
  1153. for _, subItem := range item.HisDoctorAdviceInfo {
  1154. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1155. if info.RetailPrice > 0 {
  1156. subItem.Drug.MinPrice = info.RetailPrice
  1157. }
  1158. }
  1159. }
  1160. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1161. }
  1162. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1163. if sch.ID > 0 {
  1164. var week string
  1165. t := time.Now()
  1166. switch t.Weekday().String() {
  1167. case "Monday":
  1168. week = "周一"
  1169. break
  1170. case "Tuesday":
  1171. week = "周二"
  1172. break
  1173. case "Wednesday":
  1174. week = "周三"
  1175. break
  1176. case "Thursday":
  1177. week = "周四"
  1178. break
  1179. case "Friday":
  1180. week = "周五"
  1181. break
  1182. case "Saturday":
  1183. week = "周六"
  1184. break
  1185. case "Sunday":
  1186. week = "周日"
  1187. break
  1188. }
  1189. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1190. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1191. //根据推送频率组装新的数组
  1192. for _, item := range temp_sch_prescriptions {
  1193. var cus CustomTemplate
  1194. cus.ID = item.ID
  1195. cus.UserOrgId = item.UserOrgId
  1196. cus.PatientId = item.PatientId
  1197. cus.MedType = item.MedType
  1198. cus.RecordDate = item.RecordDate
  1199. cus.Type = item.Type
  1200. cus.PType = item.PType
  1201. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1202. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1203. if subItem.FrequencyType == 1 { //每次必推
  1204. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1205. }
  1206. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1207. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, 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. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1217. if len(advices) == 0 {
  1218. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1219. }
  1220. }
  1221. }
  1222. }
  1223. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1224. if subItem.Type == 2 {
  1225. if subItem.XtHisProject.MedicalStatus != 1 {
  1226. if subItem.FrequencyType == 1 {
  1227. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1228. }
  1229. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1230. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1231. }
  1232. if subItem.FrequencyType == 2 {
  1233. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1234. now := p.Unix()
  1235. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1236. dayStr2 := "-" + dayStr
  1237. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1238. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1239. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1240. if len(projects) == 0 {
  1241. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1242. }
  1243. }
  1244. }
  1245. } else if subItem.Type == 3 {
  1246. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1247. if subItem.FrequencyType == 1 {
  1248. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1249. }
  1250. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1251. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1252. }
  1253. if subItem.FrequencyType == 2 {
  1254. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1255. now := p.Unix()
  1256. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1257. dayStr2 := "-" + dayStr
  1258. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1259. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1260. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1261. if len(projects) == 0 {
  1262. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. sch_prescriptions = append(sch_prescriptions, cus)
  1269. }
  1270. for _, item := range sch_prescriptions {
  1271. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1272. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1273. }
  1274. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1275. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1276. }
  1277. }
  1278. }
  1279. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1280. if config.ID > 0 && config.IsOpen == 1 {
  1281. for _, item := range sch_prescriptions {
  1282. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1283. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1284. if info.RetailPrice > 0 {
  1285. subItem.Drug.MinPrice = info.RetailPrice
  1286. }
  1287. }
  1288. }
  1289. }
  1290. if config.ID > 0 && config.IsOpen == 1 {
  1291. for _, item := range sch_prescriptions {
  1292. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1293. if subItem.Type == 3 {
  1294. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1295. if info.Price > 0 {
  1296. subItem.GoodInfo.PackingPrice = info.Price
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1303. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1304. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1305. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1306. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1307. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1308. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1309. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1310. //获取所有科室信息
  1311. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "his_info": his_patient_info,
  1314. "xt_info": xt_patient_info,
  1315. "prescription": prescriptions,
  1316. "case_history": case_history,
  1317. "info": patientPrescriptionInfo,
  1318. //"month_prescriptions": monthPrescriptions,
  1319. "order": order,
  1320. "doctors": doctors,
  1321. "department": department,
  1322. "sch_prescriptions": sch_prescriptions,
  1323. "last_prescriptions": last_prescriptions,
  1324. "schedule": sch,
  1325. "count": count,
  1326. "drugStockConfig": drugStockConfig,
  1327. "last_info": lastPatientPrescriptionInfo,
  1328. })
  1329. return
  1330. }
  1331. func (c *HisApiController) GetHisPrescriptionConfig() {
  1332. adminInfo := c.GetAdminUserInfo()
  1333. //获取医嘱模版
  1334. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1335. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1336. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1337. //获取所有基础药
  1338. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1339. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1340. if config.ID > 0 && config.IsOpen == 1 {
  1341. for _, item := range drugs {
  1342. var index = 0
  1343. for _, subItem := range item.OtherDrugWarehouseInfo {
  1344. if index == 0 {
  1345. index = index + 1
  1346. if subItem.RetailPrice > 0 {
  1347. item.MinPrice = subItem.RetailPrice
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1354. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1355. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1356. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1357. //获取所有科室信息
  1358. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1359. //获取诊断信息
  1360. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1361. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1362. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1363. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1364. //获取是否开启保存耗材出库的开关
  1365. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1366. c.ServeSuccessJSON(map[string]interface{}{
  1367. "drugs": drugs,
  1368. "advices_template": advices,
  1369. "drugways": drugways,
  1370. "efs": efs,
  1371. "doctors": doctors,
  1372. "department": department,
  1373. "sick": sick,
  1374. "additions": additions,
  1375. "diagnose": diagnose,
  1376. "manufacturers": manufacturers,
  1377. "goodOutOpen": goodOutOpen,
  1378. "patientDiagnose": patientDiagnose,
  1379. })
  1380. }
  1381. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1382. //获取所有基础药
  1383. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1384. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1385. if config.ID > 0 && config.IsOpen == 1 {
  1386. for _, item := range drugs {
  1387. var index = 0
  1388. for _, subItem := range item.OtherDrugWarehouseInfo {
  1389. if index == 0 {
  1390. index = index + 1
  1391. if subItem.RetailPrice > 0 {
  1392. item.MinPrice = subItem.RetailPrice
  1393. }
  1394. }
  1395. }
  1396. }
  1397. }
  1398. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1399. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1400. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1401. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1402. //获取所有科室信息
  1403. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1404. //获取诊断信息
  1405. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1406. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1407. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1408. //获取是否开启保存耗材出库的开关
  1409. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1410. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1411. c.ServeSuccessJSON(map[string]interface{}{
  1412. "drugs": drugs,
  1413. "advices_template": advices,
  1414. "drugways": drugways,
  1415. "efs": efs,
  1416. "doctors": doctors,
  1417. "department": department,
  1418. "sick": sick,
  1419. "additions": additions,
  1420. "diagnose": diagnose,
  1421. "manufacturers": manufacturers,
  1422. "goodOutOpen": goodOutOpen,
  1423. "patientDiagnose": patientDiagnose,
  1424. })
  1425. }
  1426. }
  1427. func (c *HisApiController) CreateHisPrescription() {
  1428. record_date := c.GetString("record_date")
  1429. patient_id, _ := c.GetInt64("patient_id")
  1430. reg_type, _ := c.GetInt64("reg_type")
  1431. diagnose := c.GetString("diagnose")
  1432. sick_type, _ := c.GetInt64("sick_type")
  1433. sick_history := c.GetString("sick_history")
  1434. doctor_id, _ := c.GetInt64("doctor", 0)
  1435. department, _ := c.GetInt64("department", 0)
  1436. his_patient_id, _ := c.GetInt64("his_patient_id")
  1437. p_type, _ := c.GetInt64("p_type")
  1438. patient_diagnose := c.GetString("patient_diagnose")
  1439. dataBody := make(map[string]interface{}, 0)
  1440. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1441. if err != nil {
  1442. utils.ErrorLog(err.Error())
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1444. return
  1445. }
  1446. timeLayout := "2006-01-02"
  1447. loc, _ := time.LoadLocation("Local")
  1448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1449. if err != nil {
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1451. return
  1452. }
  1453. adminInfo := c.GetAdminUserInfo()
  1454. recordDateTime := theTime.Unix()
  1455. //查询默认出库仓库库存
  1456. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1457. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1458. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1459. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1460. if len(lists) == 1 {
  1461. his_patient_id = lists[0].ID
  1462. }
  1463. }
  1464. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1465. //保存处方出库
  1466. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1467. //自动出库
  1468. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1469. //耗材保存处方出库
  1470. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1471. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1472. //已发药和已收费限制逻辑
  1473. isMidicine := false
  1474. isCharge := false
  1475. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1476. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1477. if len(prescriptions) > 0 {
  1478. for _, item := range prescriptions {
  1479. items := item.(map[string]interface{})
  1480. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1481. utils.ErrorLog("id")
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. id := int64(items["id"].(float64))
  1486. if id > 0 {
  1487. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1488. if err != nil {
  1489. if new_prescription.OrderStatus == 4 {
  1490. isCharge = true
  1491. }
  1492. }
  1493. }
  1494. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1495. advices := items["advices"].([]interface{})
  1496. if len(advices) > 0 {
  1497. for _, advice := range advices {
  1498. var adviceId int64
  1499. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1500. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1501. }
  1502. if adviceId > 0 {
  1503. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1504. if err == nil {
  1505. if his_advice_info.IsMedicine == 1 {
  1506. isMidicine = true
  1507. }
  1508. }
  1509. }
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. }
  1516. if isMidicine == true {
  1517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1518. return
  1519. }
  1520. if isCharge == true {
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1522. return
  1523. }
  1524. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1525. //药品发药出库
  1526. if pharmacyConfig.IsOpen == 1 {
  1527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1529. if len(prescriptions) > 0 {
  1530. for _, item := range prescriptions {
  1531. items := item.(map[string]interface{})
  1532. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1533. advices := items["advices"].([]interface{})
  1534. if len(advices) > 0 {
  1535. for _, advice := range advices {
  1536. var drug_id int64
  1537. var prescribing_number float64
  1538. var prescribingNumberUnit string
  1539. var adviceId int64
  1540. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1541. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1542. }
  1543. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1544. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1545. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1546. }
  1547. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1548. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1549. }
  1550. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1551. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1552. }
  1553. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1554. if drug.ID == 0 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1556. return
  1557. }
  1558. //查询药品的所有库存
  1559. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1560. var total_count int64
  1561. for _, it := range list {
  1562. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1563. }
  1564. totals := strconv.FormatInt(total_count, 10)
  1565. //查询该药品是否存在开药记录
  1566. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1567. //新增处方
  1568. if advicelist.ID == 0 {
  1569. all_count, _ := strconv.ParseFloat(totals, 64)
  1570. if prescribingNumberUnit == drug.MinUnit {
  1571. if drug.IsUse != 1 {
  1572. if prescribing_number > all_count {
  1573. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1574. return
  1575. }
  1576. }
  1577. }
  1578. if prescribingNumberUnit == drug.MaxUnit {
  1579. num := prescribing_number * float64(drug.MinNumber)
  1580. if drug.IsUse != 1 {
  1581. if num > all_count {
  1582. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1583. return
  1584. }
  1585. }
  1586. }
  1587. }
  1588. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1589. if drugOutConfig.IsOpen != 1 {
  1590. //修改处方
  1591. for _, advice := range advices {
  1592. var drug_id int64
  1593. var prescribing_number float64
  1594. var prescribingNumberUnit string
  1595. var prescribingNumber string
  1596. var adviceId int64
  1597. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1598. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1599. }
  1600. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1601. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1602. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1603. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1604. }
  1605. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1606. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1607. }
  1608. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1609. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1610. }
  1611. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1612. if drug.ID == 0 {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1614. return
  1615. }
  1616. //查询药品的所有库存
  1617. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1618. var total_count int64
  1619. for _, it := range list {
  1620. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1621. }
  1622. totals := strconv.FormatInt(total_count, 10)
  1623. //查询该药品是否存在开药记录
  1624. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1625. //新增处方
  1626. if advicelist.ID == 0 {
  1627. all_count, _ := strconv.ParseFloat(totals, 64)
  1628. if prescribingNumberUnit == drug.MinUnit {
  1629. if drug.IsUse != 1 {
  1630. if prescribing_number > all_count {
  1631. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1632. return
  1633. }
  1634. }
  1635. } else {
  1636. if prescribingNumberUnit == drug.MaxUnit {
  1637. num := prescribing_number * float64(drug.MinNumber)
  1638. if drug.IsUse != 1 {
  1639. if num > all_count {
  1640. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1641. return
  1642. }
  1643. }
  1644. }
  1645. }
  1646. }
  1647. //修改处方
  1648. if advicelist.ID > 0 {
  1649. var device_number int64
  1650. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1651. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1652. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1653. device_number = prescribingNumberInt * drug.MinNumber
  1654. }
  1655. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1656. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1657. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1658. device_number = prescribingNumberInt
  1659. }
  1660. var number_count int64
  1661. if prescribingNumberUnit == drug.MaxUnit {
  1662. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1663. number_count = prescribingNumberInt * drug.MinNumber
  1664. }
  1665. if prescribingNumberUnit == drug.MinUnit {
  1666. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1667. number_count = prescribingNumberInt
  1668. }
  1669. //如果修改的数量大于之前修改的数量
  1670. if (number_count - device_number) > 0 {
  1671. //如果修改的差数量 大于库存数量
  1672. if drug.IsUse != 1 {
  1673. if (number_count - device_number) > total_count {
  1674. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1675. return
  1676. }
  1677. }
  1678. }
  1679. }
  1680. }
  1681. }
  1682. }
  1683. }
  1684. }
  1685. }
  1686. }
  1687. }
  1688. }
  1689. //已发药和已收费限制逻辑
  1690. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1691. //校验库存总量
  1692. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1693. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1694. if len(prescriptions) > 0 {
  1695. for _, item := range prescriptions {
  1696. items := item.(map[string]interface{})
  1697. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1698. advices := items["advices"].([]interface{})
  1699. if len(advices) > 0 {
  1700. for _, advice := range advices {
  1701. var drug_id int64
  1702. var prescribing_number float64
  1703. var prescribingNumberUnit string
  1704. var adviceId int64
  1705. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1706. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1709. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1710. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1711. }
  1712. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1713. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1714. }
  1715. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1716. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1717. }
  1718. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1719. if drug.ID == 0 {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1721. return
  1722. }
  1723. //查询药品的所有库存
  1724. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1725. var total_count int64
  1726. for _, it := range list {
  1727. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1728. }
  1729. totals := strconv.FormatInt(total_count, 10)
  1730. //查询该药品是否存在开药记录
  1731. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1732. //查询最新批次库存
  1733. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1734. var batch_number_count int64
  1735. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1736. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1737. //新增处方
  1738. if advicelist.ID == 0 {
  1739. all_count, _ := strconv.ParseFloat(totals, 64)
  1740. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1741. if prescribingNumberUnit == drug.MinUnit {
  1742. if drug.IsUse != 1 {
  1743. if prescribing_number > all_count {
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. if adminInfo.CurrentOrgId == 10215 {
  1748. if prescribing_number > batch_number_all_count {
  1749. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1750. return
  1751. }
  1752. }
  1753. }
  1754. }
  1755. if prescribingNumberUnit == drug.MaxUnit {
  1756. num := prescribing_number * float64(drug.MinNumber)
  1757. if drug.IsUse != 1 {
  1758. if num > all_count {
  1759. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1760. return
  1761. }
  1762. if adminInfo.CurrentOrgId == 10215 {
  1763. if num > batch_number_all_count {
  1764. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1765. return
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1772. if drugOutConfig.IsOpen != 1 {
  1773. //修改处方
  1774. for _, advice := range advices {
  1775. var drug_id int64
  1776. var prescribing_number float64
  1777. var prescribingNumberUnit string
  1778. var prescribingNumber string
  1779. var adviceId int64
  1780. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1781. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1782. }
  1783. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1784. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1785. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1786. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1787. }
  1788. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1789. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1790. }
  1791. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1792. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1793. }
  1794. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1795. if drug.ID == 0 {
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1797. return
  1798. }
  1799. //查询药品的所有库存
  1800. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1801. var total_count int64
  1802. for _, it := range list {
  1803. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1804. }
  1805. totals := strconv.FormatInt(total_count, 10)
  1806. //查询该药品是否存在开药记录
  1807. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1808. //新增处方
  1809. if advicelist.ID == 0 {
  1810. //查询最新批次库存
  1811. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1812. var batch_number_count int64
  1813. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1814. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1815. all_count, _ := strconv.ParseFloat(totals, 64)
  1816. if prescribingNumberUnit == drug.MinUnit {
  1817. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1818. if drug.IsUse != 1 {
  1819. if prescribing_number > all_count {
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. if adminInfo.CurrentOrgId == 10215 {
  1824. if prescribing_number > batch_number_all_count {
  1825. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1826. return
  1827. }
  1828. }
  1829. }
  1830. } else {
  1831. if prescribingNumberUnit == drug.MaxUnit {
  1832. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1833. num := prescribing_number * float64(drug.MinNumber)
  1834. if drug.IsUse != 1 {
  1835. if num > all_count {
  1836. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1837. return
  1838. }
  1839. if adminInfo.CurrentOrgId == 10215 {
  1840. if prescribing_number > batch_number_all_count {
  1841. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1842. return
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. //修改处方
  1850. if advicelist.ID > 0 {
  1851. //查询最新批次库存
  1852. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1853. var batch_number_count int64
  1854. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1855. var device_number int64
  1856. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1857. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1858. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1859. device_number = prescribingNumberInt * drug.MinNumber
  1860. }
  1861. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1862. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1863. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1864. device_number = prescribingNumberInt
  1865. }
  1866. var number_count int64
  1867. if prescribingNumberUnit == drug.MaxUnit {
  1868. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1869. number_count = prescribingNumberInt * drug.MinNumber
  1870. }
  1871. if prescribingNumberUnit == drug.MinUnit {
  1872. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1873. number_count = prescribingNumberInt
  1874. }
  1875. //如果修改的数量大于之前修改的数量
  1876. if (number_count - device_number) > 0 {
  1877. //如果修改的差数量 大于库存数量
  1878. if drug.IsUse != 1 {
  1879. if (number_count - device_number) > total_count {
  1880. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1881. return
  1882. }
  1883. if (number_count - device_number) > batch_number_count {
  1884. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1885. return
  1886. }
  1887. if adminInfo.CurrentOrgId == 10215 {
  1888. // 查询该药品最后一次出库记录
  1889. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1890. var out_count int64
  1891. var in_count int64
  1892. var stock_max_number int64
  1893. var stock_min_number int64
  1894. for _, it := range outInfo {
  1895. if it.CountUnit == drug.MaxUnit {
  1896. it.Count = it.Count * drug.MinNumber
  1897. }
  1898. out_count += it.Count
  1899. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1900. stock_max_number = warehouseInfoList.StockMaxNumber
  1901. stock_min_number = warehouseInfoList.StockMinNumber
  1902. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1903. }
  1904. if out_count > 0 {
  1905. if (number_count - device_number) > in_count {
  1906. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1907. return
  1908. }
  1909. }
  1910. // 未出库
  1911. if out_count == 0 {
  1912. var sum_in_count int64
  1913. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1914. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1915. fmt.Println("sum_in_count", sum_in_count)
  1916. //如果修改的数量大于有库存的第一个批次
  1917. if number_count > sum_in_count {
  1918. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1919. return
  1920. }
  1921. }
  1922. }
  1923. }
  1924. }
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. if pharmacyConfig.IsOpen != 1 {
  1927. if device_number != number_count {
  1928. // 查询该药品最后一次出库记录
  1929. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1930. //回退库存
  1931. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1932. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1933. }
  1934. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1935. var stock_max_number int64
  1936. var stock_min_number int64
  1937. if number_count >= drug.MinNumber {
  1938. stock_max_number = device_number / drug.MinNumber
  1939. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1940. stock_min_number = device_number % drug.MinNumber
  1941. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1942. } else {
  1943. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1944. }
  1945. }
  1946. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1947. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1948. }
  1949. //删除记录
  1950. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1951. //查询默认仓库剩余多少库存
  1952. var sum_count int64
  1953. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1954. for _, its := range stockInfo {
  1955. if its.MaxUnit == drug.MaxUnit {
  1956. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1957. }
  1958. sum_count += its.StockMaxNumber + its.StockMinNumber
  1959. }
  1960. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. //保存处方开药
  1967. if drugOutConfig.IsOpen == 1 {
  1968. //修改处方
  1969. for _, advice := range advices {
  1970. var drug_id int64
  1971. var prescribing_number float64
  1972. var prescribingNumberUnit string
  1973. var prescribingNumber string
  1974. var adviceId int64
  1975. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1976. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1977. }
  1978. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1979. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1980. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1981. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1982. }
  1983. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1984. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1985. }
  1986. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1987. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1988. }
  1989. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1990. if drug.ID == 0 {
  1991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1992. return
  1993. }
  1994. //查询药品的所有库存
  1995. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1996. var total_count int64
  1997. for _, it := range list {
  1998. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1999. }
  2000. totals := strconv.FormatInt(total_count, 10)
  2001. //查询该药品是否存在开药记录
  2002. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2003. //新增处方
  2004. if advicelist.ID == 0 {
  2005. //查询最新批次库存
  2006. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2007. var batch_number_count int64
  2008. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2009. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2010. all_count, _ := strconv.ParseFloat(totals, 64)
  2011. if prescribingNumberUnit == drug.MinUnit {
  2012. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2013. if drug.IsUse != 1 {
  2014. if prescribing_number > all_count {
  2015. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2016. return
  2017. }
  2018. if adminInfo.CurrentOrgId == 10215 {
  2019. if prescribing_number > batch_number_all_count {
  2020. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2021. return
  2022. }
  2023. }
  2024. }
  2025. } else {
  2026. if prescribingNumberUnit == drug.MaxUnit {
  2027. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2028. num := prescribing_number * float64(drug.MinNumber)
  2029. if drug.IsUse != 1 {
  2030. if num > all_count {
  2031. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2032. return
  2033. }
  2034. if adminInfo.CurrentOrgId == 10215 {
  2035. if prescribing_number > batch_number_all_count {
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2037. return
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. //修改处方
  2045. if advicelist.ID > 0 {
  2046. //查询最新批次库存
  2047. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2048. var batch_number_count int64
  2049. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2050. var device_number int64
  2051. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2052. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2053. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2054. device_number = prescribingNumberInt * drug.MinNumber
  2055. }
  2056. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2057. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2058. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2059. device_number = prescribingNumberInt
  2060. }
  2061. var number_count int64
  2062. if prescribingNumberUnit == drug.MaxUnit {
  2063. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2064. number_count = prescribingNumberInt * drug.MinNumber
  2065. }
  2066. if prescribingNumberUnit == drug.MinUnit {
  2067. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2068. number_count = prescribingNumberInt
  2069. }
  2070. //如果修改的数量大于之前修改的数量
  2071. if (number_count - device_number) > 0 {
  2072. //如果修改的差数量 大于库存数量
  2073. if drug.IsUse != 1 {
  2074. if (number_count - device_number) > total_count {
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. if adminInfo.CurrentOrgId == 10215 {
  2079. if (number_count - device_number) > batch_number_count {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2085. //查询历史出库数据总批次
  2086. // 查询该药品最后一次出库记录
  2087. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2088. var out_count int64
  2089. var in_count int64
  2090. var stock_max_number int64
  2091. var stock_min_number int64
  2092. for _, it := range outInfo {
  2093. if it.CountUnit == drug.MaxUnit {
  2094. it.Count = it.Count * drug.MinNumber
  2095. }
  2096. out_count += it.Count
  2097. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2098. stock_max_number = warehouseInfoList.StockMaxNumber
  2099. stock_min_number = warehouseInfoList.StockMinNumber
  2100. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2101. }
  2102. if out_count > 0 {
  2103. if (number_count - device_number) > in_count {
  2104. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2105. return
  2106. }
  2107. }
  2108. // 未出库
  2109. if out_count == 0 {
  2110. var sum_in_count int64
  2111. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2112. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2113. //如果修改的数量大于有库存的第一个批次
  2114. if number_count > sum_in_count {
  2115. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2116. return
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. //校验耗材库存
  2133. if goodOutConfig.IsOpen == 1 {
  2134. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2135. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2136. if len(prescriptions) > 0 {
  2137. for _, item := range prescriptions {
  2138. items := item.(map[string]interface{})
  2139. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2140. projects := items["project"].([]interface{})
  2141. if len(projects) > 0 {
  2142. for _, project := range projects {
  2143. var project_id int64
  2144. var project_type int64
  2145. var totals float64
  2146. var project_name string
  2147. var parsetotal int64
  2148. var id int64
  2149. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2150. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2151. }
  2152. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2153. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2154. }
  2155. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2156. total, _ := project.(map[string]interface{})["total"].(string)
  2157. totals, _ = strconv.ParseFloat(total, 64)
  2158. }
  2159. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2160. project_name = project.(map[string]interface{})["project_name"].(string)
  2161. }
  2162. if project_type == 3 {
  2163. //查找该耗材的出库记录
  2164. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2165. if len(goodWarehouseInfo) == 0 {
  2166. //查询耗材库存
  2167. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2168. var stock_count int64
  2169. for _, it := range list {
  2170. stock_count += it.StockCount
  2171. }
  2172. stock_counts := strconv.FormatInt(stock_count, 10)
  2173. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2174. if totals > stock_total_count {
  2175. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2176. return
  2177. }
  2178. }
  2179. if len(goodWarehouseInfo) > 0 {
  2180. //查询该患者耗材的历史数据
  2181. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2182. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2183. //数量发生改变
  2184. if parsetotal != count {
  2185. //如果现在的数量大于历史数量,就要看库存是否足够
  2186. if parsetotal > count {
  2187. //查询耗材所有库存
  2188. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2189. var stock_count int64
  2190. for _, it := range list {
  2191. stock_count += it.StockCount
  2192. }
  2193. //库存不足
  2194. if (parsetotal - count) > stock_count {
  2195. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2196. return
  2197. }
  2198. }
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. }
  2209. //不使用耗材保存处方出库
  2210. if goodOutConfig.IsOpen != 1 {
  2211. if stockConfig.IsOpen == 1 {
  2212. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2213. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2214. if len(prescriptions) > 0 {
  2215. for _, item := range prescriptions {
  2216. items := item.(map[string]interface{})
  2217. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2218. projects := items["project"].([]interface{})
  2219. if len(projects) > 0 {
  2220. for _, project := range projects {
  2221. var project_id int64
  2222. var project_type int64
  2223. var totals float64
  2224. var project_name string
  2225. var parsetotal int64
  2226. var id int64
  2227. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2228. id = int64(project.(map[string]interface{})["id"].(float64))
  2229. }
  2230. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2231. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2232. }
  2233. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2234. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2235. }
  2236. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2237. total, _ := project.(map[string]interface{})["total"].(string)
  2238. totals, _ = strconv.ParseFloat(total, 64)
  2239. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2240. }
  2241. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2242. project_name = project.(map[string]interface{})["project_name"].(string)
  2243. }
  2244. if project_type == 3 {
  2245. //查找该耗材的出库记录
  2246. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2247. //没有出库记录
  2248. if len(goodWarehouseInfo) == 0 {
  2249. //查询耗材库存
  2250. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2251. var stock_count int64
  2252. for _, it := range list {
  2253. stock_count += it.StockCount
  2254. }
  2255. stock_counts := strconv.FormatInt(stock_count, 10)
  2256. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2257. if totals > stock_total_count {
  2258. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2259. return
  2260. }
  2261. //查找今日该患者已经出库的所有耗材
  2262. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2263. for _, item := range goodList {
  2264. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2265. var flush_count int64
  2266. for _, it := range goodListSix {
  2267. flush_count += it.StockCount
  2268. }
  2269. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2270. creater := adminInfo.AdminUser.Id
  2271. if errs != nil {
  2272. goodErrcode := models.XtGoodErrcode{
  2273. UserOrgId: item.OrgId,
  2274. Errcode: "手动出库更新剩余出库失败",
  2275. GoodId: item.GoodId,
  2276. Status: 1,
  2277. Ctime: time.Now().Unix(),
  2278. Mtime: 0,
  2279. Count: 0,
  2280. StockCount: 0,
  2281. Creater: creater,
  2282. BatchNumberId: 0,
  2283. WarehouseOutId: 0,
  2284. }
  2285. service.CreateGoodErrcode(goodErrcode)
  2286. }
  2287. }
  2288. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2289. }
  2290. //有出库记录
  2291. if len(goodWarehouseInfo) > 0 {
  2292. //查询该患者耗材的历史数据
  2293. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2294. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2295. //数量发生改变
  2296. if parsetotal != count {
  2297. //查找今日该患者已经出库的所有耗材
  2298. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2299. for _, item := range goodList {
  2300. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2301. var flush_count int64
  2302. for _, it := range goodListSix {
  2303. flush_count += it.StockCount
  2304. }
  2305. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2306. //减少出库数量
  2307. creater := adminInfo.AdminUser.Id
  2308. if errs != nil {
  2309. goodErrcode := models.XtGoodErrcode{
  2310. UserOrgId: item.OrgId,
  2311. Errcode: "手动出库更新剩余出库失败",
  2312. GoodId: item.GoodId,
  2313. Status: 1,
  2314. Ctime: time.Now().Unix(),
  2315. Mtime: 0,
  2316. Count: 0,
  2317. StockCount: 0,
  2318. Creater: creater,
  2319. BatchNumberId: 0,
  2320. WarehouseOutId: 0,
  2321. }
  2322. service.CreateGoodErrcode(goodErrcode)
  2323. }
  2324. //查询默认仓库
  2325. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2326. var total_count int64
  2327. for _, it := range stockList {
  2328. total_count += it.StockCount
  2329. }
  2330. //基础库插入数据
  2331. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2332. }
  2333. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2334. }
  2335. }
  2336. }
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2346. var hpInfo models.HisPrescriptionInfo
  2347. if info.ID == 0 {
  2348. var randNum int
  2349. randNum = rand.Intn(10000) + 1000
  2350. timestamp := time.Now().Unix()
  2351. tempTime := time.Unix(timestamp, 0)
  2352. timeFormat := tempTime.Format("20060102150405")
  2353. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2354. hpInfo = models.HisPrescriptionInfo{
  2355. HisPatientId: his_patient_id,
  2356. UserOrgId: adminInfo.CurrentOrgId,
  2357. RecordDate: theTime.Unix(),
  2358. PatientId: patient_id,
  2359. Status: 1,
  2360. Ctime: time.Now().Unix(),
  2361. Mtime: time.Now().Unix(),
  2362. Creator: adminInfo.AdminUser.Id,
  2363. Modifier: adminInfo.AdminUser.Id,
  2364. Diagnosis: diagnose,
  2365. SickHistory: sick_history,
  2366. Departments: department,
  2367. RegisterType: reg_type,
  2368. PrescriptionNumber: p_number,
  2369. PrescriptionStatus: 1,
  2370. Doctor: role.UserName,
  2371. DoctorId: doctor_id,
  2372. SickType: sick_type,
  2373. PType: p_type,
  2374. PatientDiagnosis: patient_diagnose,
  2375. }
  2376. service.SavePatientPrescriptionInfo(hpInfo)
  2377. //创建步骤表
  2378. finish := models.XtDialysisFinish{
  2379. IsFinish: 1,
  2380. UserOrgId: adminInfo.CurrentOrgId,
  2381. Status: 1,
  2382. Ctime: time.Now().Unix(),
  2383. Mtime: 0,
  2384. Module: 4,
  2385. RecordDate: theTime.Unix(),
  2386. Sourse: 1,
  2387. PatientId: patient_id,
  2388. }
  2389. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2390. if dialysisFinish.ID == 0 {
  2391. service.CreateDialysisFinish(finish)
  2392. }
  2393. redis := service.RedisClient()
  2394. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2395. redis.Set(key, "", time.Second)
  2396. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2397. redis.Set(keyOne, "", time.Second)
  2398. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2399. redis.Set(keySeven, "", time.Second)
  2400. defer redis.Close()
  2401. } else {
  2402. hpInfo = models.HisPrescriptionInfo{
  2403. ID: info.ID,
  2404. UserOrgId: adminInfo.CurrentOrgId,
  2405. RecordDate: info.RecordDate,
  2406. PatientId: info.PatientId,
  2407. Status: 1,
  2408. Ctime: info.Ctime,
  2409. Mtime: time.Now().Unix(),
  2410. Creator: info.Creator,
  2411. Modifier: adminInfo.AdminUser.Id,
  2412. Diagnosis: diagnose,
  2413. SickHistory: sick_history,
  2414. Departments: department,
  2415. RegisterType: reg_type,
  2416. PrescriptionNumber: info.PrescriptionNumber,
  2417. Doctor: role.UserName,
  2418. PrescriptionStatus: info.PrescriptionStatus,
  2419. DoctorId: doctor_id,
  2420. SickType: sick_type,
  2421. PType: info.PType,
  2422. HisPatientId: info.HisPatientId,
  2423. PatientDiagnosis: patient_diagnose,
  2424. }
  2425. service.SavePatientPrescriptionInfo(hpInfo)
  2426. //创建步骤表
  2427. finish := models.XtDialysisFinish{
  2428. IsFinish: 1,
  2429. UserOrgId: adminInfo.CurrentOrgId,
  2430. Status: 1,
  2431. Ctime: time.Now().Unix(),
  2432. Mtime: 0,
  2433. Module: 4,
  2434. RecordDate: info.RecordDate,
  2435. Sourse: 1,
  2436. PatientId: info.PatientId,
  2437. }
  2438. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2439. if dialysisFinish.ID == 0 {
  2440. service.CreateDialysisFinish(finish)
  2441. }
  2442. redis := service.RedisClient()
  2443. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2444. redis.Set(key, "", time.Second)
  2445. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2446. redis.Set(keyOne, "", time.Second)
  2447. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2448. redis.Set(keySeven, "", time.Second)
  2449. defer redis.Close()
  2450. }
  2451. //定义切片
  2452. var adviceList []models.HisDoctorAdviceInfo
  2453. var projectList []models.HisPrescriptionProject
  2454. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2455. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2456. var tempPrescription *models.HisPrescription
  2457. if len(prescriptions) > 0 {
  2458. for _, item := range prescriptions {
  2459. items := item.(map[string]interface{})
  2460. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2461. utils.ErrorLog("id")
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2463. return
  2464. }
  2465. id := int64(items["id"].(float64))
  2466. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2467. tempPrescription = &new_prescription
  2468. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2469. utils.ErrorLog("type")
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2471. return
  2472. }
  2473. types := int64(items["type"].(float64))
  2474. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2475. utils.ErrorLog("med_type")
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2480. if med_type == "0" {
  2481. med_type = "14"
  2482. }
  2483. //if order_status == 0 {
  2484. // order_status = 1
  2485. //}
  2486. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2487. utils.ErrorLog("pre_time")
  2488. }
  2489. preTime, _ := items["pre_time"].(string)
  2490. timeLayout := "2006-01-02"
  2491. loc, _ := time.LoadLocation("Local")
  2492. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2493. if err != nil {
  2494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2495. return
  2496. }
  2497. pTime := theTime2.Unix()
  2498. ctime := time.Now().Unix()
  2499. if tempPrescription.ID == 0 {
  2500. prescription := &models.HisPrescription{
  2501. ID: 0,
  2502. PatientId: patient_id,
  2503. UserOrgId: adminInfo.CurrentOrgId,
  2504. RecordDate: recordDateTime,
  2505. Ctime: ctime,
  2506. Mtime: ctime,
  2507. Type: types,
  2508. Modifier: adminInfo.AdminUser.Id,
  2509. Creator: adminInfo.AdminUser.Id,
  2510. Status: 1,
  2511. Doctor: role.UserName,
  2512. HisPatientId: his_patient_id,
  2513. OrderStatus: 1,
  2514. BatchNumber: "",
  2515. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2516. PreTime: pTime,
  2517. PType: p_type,
  2518. MedType: med_type,
  2519. }
  2520. tempPrescription = prescription
  2521. service.SaveHisPrescription(tempPrescription)
  2522. redis := service.RedisClient()
  2523. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2524. redis.Set(key, "", time.Second)
  2525. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2526. redis.Set(keyOne, "", time.Second)
  2527. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2528. redis.Set(keySeven, "", time.Second)
  2529. defer redis.Close()
  2530. } else {
  2531. tempPrescription.ID = id
  2532. tempPrescription.Type = types
  2533. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2534. tempPrescription.Mtime = time.Now().Unix()
  2535. tempPrescription.Doctor = role.UserName
  2536. //tempPrescription.OrderStatus = order_status
  2537. tempPrescription.PreTime = pTime
  2538. tempPrescription.MedType = med_type
  2539. service.SaveHisPrescription(tempPrescription)
  2540. redis := service.RedisClient()
  2541. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2542. redis.Set(key, "", time.Second)
  2543. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2544. redis.Set(keyOne, "", time.Second)
  2545. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2546. redis.Set(keySeven, "", time.Second)
  2547. defer redis.Close()
  2548. }
  2549. //service.SaveHisPrescription(prescription)
  2550. //更改患者挂号状态
  2551. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2552. fmt.Println("更改失败", err2)
  2553. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2554. advices := items["advices"].([]interface{})
  2555. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2556. groupNo := int64(0)
  2557. ctime := time.Now().Unix()
  2558. mtime := ctime
  2559. if len(advices) > 0 {
  2560. for _, advice := range advices {
  2561. var s models.HisDoctorAdviceInfo
  2562. s.PrescriptionId = tempPrescription.ID
  2563. s.AdviceType = 2
  2564. s.AdviceDoctor = doctor_id
  2565. s.StopState = 2
  2566. s.ExecutionState = 2
  2567. s.AdviceDate = recordDateTime
  2568. s.Status = 1
  2569. s.UserOrgId = adminInfo.CurrentOrgId
  2570. s.RecordDate = recordDateTime
  2571. s.StartTime = tempPrescription.PreTime
  2572. s.Groupno = groupNo
  2573. s.CreatedTime = ctime
  2574. s.UpdatedTime = mtime
  2575. s.PatientId = patient_id
  2576. s.HisPatientId = his_patient_id
  2577. s.StartTime = pTime
  2578. s.IsSettle = 2
  2579. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2580. if errcode > 0 {
  2581. c.ServeFailJSONWithSGJErrorCode(errcode)
  2582. return
  2583. }
  2584. s.StartTime = pTime
  2585. var total_count int64 //处方总库存
  2586. //查询改药品信息
  2587. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2588. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2589. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2590. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2591. total_count += prescribingNumberSeven * medical.MinNumber
  2592. }
  2593. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2594. total_count += prescribingNumberSeven
  2595. }
  2596. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2597. total_count += prescribingNumberSeven
  2598. }
  2599. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2600. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2601. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2602. if s.Price != lastWarehouse.RetailPrice {
  2603. s.Price = lastWarehouse.RetailPrice
  2604. }
  2605. if s.Price == 0 {
  2606. s.Price = lastWarehouse.RetailPrice
  2607. }
  2608. }
  2609. service.CreateHisDoctorAdvice(&s)
  2610. //记录日志
  2611. byterequest, _ := json.Marshal(s)
  2612. adviceLog := models.XtDoctorAdviceLog{
  2613. UserOrgId: s.UserOrgId,
  2614. PatientId: s.PatientId,
  2615. AdminUserId: adminInfo.AdminUser.Id,
  2616. Module: 1,
  2617. ErrLog: string(byterequest),
  2618. Status: 1,
  2619. Ctime: time.Now().Unix(),
  2620. Mtime: 0,
  2621. Source: "电脑端新建his医嘱",
  2622. RecordDate: s.AdviceDate,
  2623. }
  2624. service.CreateDoctorAdviceLog(adviceLog)
  2625. //存储切片中
  2626. adviceList = append(adviceList, s)
  2627. redis := service.RedisClient()
  2628. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2629. redis.Set(key, "", time.Second)
  2630. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2631. redis.Set(keyOne, "", time.Second)
  2632. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2633. redis.Set(keySeven, "", time.Second)
  2634. var randNum int
  2635. randNum = rand.Intn(10000) + 1000
  2636. timestamp := time.Now().Unix()
  2637. tempTime := time.Unix(timestamp, 0)
  2638. timeFormat := tempTime.Format("20060102150405")
  2639. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2640. service.CreateHisDoctorAdvice(&s)
  2641. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2642. redis.Set(keySix, "", time.Second)
  2643. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2644. redis.Set(keyFive, "", time.Second)
  2645. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2646. redis.Set(keyEight, "", time.Second)
  2647. defer redis.Close()
  2648. }
  2649. }
  2650. }
  2651. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2652. projects := items["project"].([]interface{})
  2653. if len(projects) > 0 {
  2654. for _, project := range projects {
  2655. var p models.HisPrescriptionProject
  2656. p.PrescriptionId = tempPrescription.ID
  2657. p.Ctime = time.Now().Unix()
  2658. p.Mtime = time.Now().Unix()
  2659. p.PatientId = patient_id
  2660. p.RecordDate = recordDateTime
  2661. p.Doctor = doctor_id
  2662. p.UserOrgId = adminInfo.CurrentOrgId
  2663. p.HisPatientId = his_patient_id
  2664. p.Status = 1
  2665. p.StartTime = pTime
  2666. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2667. if errcode > 0 {
  2668. c.ServeFailJSONWithSGJErrorCode(errcode)
  2669. return
  2670. }
  2671. if p.ID == 0 {
  2672. p.IsOut = 2
  2673. }
  2674. if p.ID > 0 {
  2675. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2676. p.IsOut = projectDetail.IsOut
  2677. }
  2678. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2679. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2680. if p.Type == 3 {
  2681. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2682. if p.Price != lastWarehouse.PackingPrice {
  2683. p.Price = lastWarehouse.PackingPrice
  2684. }
  2685. if p.Unit == "" {
  2686. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2687. p.Unit = goodInfoOne.PackingUnit
  2688. }
  2689. }
  2690. }
  2691. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2692. //
  2693. // if p.Type == 3 {
  2694. // //查询该耗材是否停用
  2695. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2696. // //表示该耗材已经停用,不能保存
  2697. // if goodInfoSeven.ID == 0 {
  2698. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2699. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2700. // return
  2701. // }
  2702. // }
  2703. //
  2704. //}
  2705. service.CreateHisProjectTwo(&p)
  2706. //记录日志
  2707. byterequest, _ := json.Marshal(p)
  2708. adviceLog := models.XtDoctorAdviceLog{
  2709. UserOrgId: p.UserOrgId,
  2710. PatientId: p.PatientId,
  2711. AdminUserId: adminInfo.AdminUser.Id,
  2712. Module: 1,
  2713. ErrLog: string(byterequest),
  2714. Status: 1,
  2715. Ctime: time.Now().Unix(),
  2716. Mtime: 0,
  2717. Source: "电脑端新建his项目",
  2718. RecordDate: p.RecordDate,
  2719. }
  2720. service.CreateDoctorAdviceLog(adviceLog)
  2721. projectList = append(projectList, p)
  2722. var randNum int
  2723. randNum = rand.Intn(10000) + 1000
  2724. timestamp := time.Now().Unix()
  2725. tempTime := time.Unix(timestamp, 0)
  2726. timeFormat := tempTime.Format("20060102150405")
  2727. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2728. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2729. //新增或者编辑项目,修改对应的标签数据
  2730. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2731. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2732. var label models.HisLabelPrintInfo
  2733. project, _ := service.GetProjectDetail(p.ProjectId)
  2734. if project.CostClassify == 3 { //类别为检验检查
  2735. if p.TeamId > 0 { //检验检查组套
  2736. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2737. if tempLabel.ID == 0 {
  2738. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2739. label.Number = tempPrescription.PrescriptionNumber
  2740. label.ProjectId = project.ID
  2741. label.Status = 1
  2742. label.IsPrint = 2
  2743. label.DoctorId = info.DoctorId
  2744. label.UserOrgId = p.UserOrgId
  2745. label.PatientId = patient_id
  2746. label.RecordDate = recordDateTime
  2747. label.Ctime = time.Now().Unix()
  2748. label.Mtime = time.Now().Unix()
  2749. label.ItemId = p.TeamId
  2750. label.FeedetlSn = p.FeedetlSn
  2751. label.PProjectId = p.ID
  2752. label.ProjectName = team.ProjectTeam
  2753. label.PatientName = patient.Name
  2754. service.CreateHisLabelRecord(&label)
  2755. }
  2756. } else { //单条检验检查项目
  2757. label.Number = tempPrescription.PrescriptionNumber
  2758. label.ProjectId = project.ID
  2759. label.Status = 1
  2760. label.DoctorId = info.DoctorId
  2761. label.UserOrgId = p.UserOrgId
  2762. label.PatientId = patient_id
  2763. label.RecordDate = recordDateTime
  2764. label.IsPrint = 2
  2765. label.Ctime = time.Now().Unix()
  2766. label.Mtime = time.Now().Unix()
  2767. label.FeedetlSn = p.FeedetlSn
  2768. label.PProjectId = p.ID
  2769. label.ItemId = p.TeamId
  2770. label.ProjectName = project.ProjectName
  2771. label.PatientName = patient.Name
  2772. service.CreateHisLabelRecord(&label)
  2773. }
  2774. }
  2775. }
  2776. }
  2777. service.SaveHisProjectTwo(&p)
  2778. }
  2779. }
  2780. }
  2781. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2782. // addition := items["addition"].([]interface{})
  2783. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2784. // ctime := time.Now().Unix()
  2785. // mtime := ctime
  2786. // if len(addition) > 0 {
  2787. // for _, item := range addition {
  2788. // var s models.HisAdditionalCharge
  2789. // s.PrescriptionId = tempPrescription.ID
  2790. // s.Status = 1
  2791. // s.UserOrgId = adminInfo.CurrentOrgId
  2792. // s.RecordDate = recordDateTime
  2793. // s.CreatedTime = ctime
  2794. // s.UpdatedTime = mtime
  2795. // s.PatientId = patient_id
  2796. // s.HisPatientId = his_patient_id
  2797. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2798. // if errcode > 0 {
  2799. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2800. // return
  2801. // }
  2802. // service.CreateAdditionalCharge(&s)
  2803. // var randNum int
  2804. // randNum = rand.Intn(10000) + 1000
  2805. // timestamp := time.Now().Unix()
  2806. // tempTime := time.Unix(timestamp, 0)
  2807. // timeFormat := tempTime.Format("20060102150405")
  2808. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2809. // service.CreateAdditionalCharge(&s)
  2810. //
  2811. // }
  2812. // }
  2813. //}
  2814. }
  2815. }
  2816. //查询今日该患者开的药品处方
  2817. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2818. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2819. //药品出库
  2820. if drugOutConfig.IsOpen == 1 {
  2821. for _, item := range hisdoctorlist {
  2822. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2823. // 查询该药品最后一次出库记录
  2824. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2825. if len(druginfo) > 0 {
  2826. //回退库存
  2827. for _, it := range druginfo {
  2828. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2829. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2830. }
  2831. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2832. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2833. }
  2834. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2835. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2836. }
  2837. }
  2838. }
  2839. //删除记录
  2840. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2841. //查询最后一次数据
  2842. if drugOutConfig.IsOpen == 1 {
  2843. //出库
  2844. if drug.IsUse == 2 {
  2845. creater := adminInfo.AdminUser.Id
  2846. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2847. }
  2848. //更新字典里面的库存
  2849. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2850. var sum_count int64
  2851. for _, its := range stockInfo {
  2852. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2853. if its.MaxUnit == baseDrug.MaxUnit {
  2854. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2855. }
  2856. sum_count += its.StockMaxNumber + its.StockMinNumber
  2857. }
  2858. //更新基础库存
  2859. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2860. //剩余库存
  2861. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2862. }
  2863. }
  2864. }
  2865. //耗材保存处方出库
  2866. if goodOutConfig.IsOpen == 1 {
  2867. //查询今日耗材出库数量
  2868. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2869. for _, item := range hisgoodlist {
  2870. //查询历史出库数据
  2871. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2872. var out_count_five int64
  2873. for _, item := range flowGood {
  2874. out_count_five += item.Count
  2875. }
  2876. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2877. if out_count_five != parseIntCount {
  2878. //查询耗材最后一次出库记录
  2879. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2880. //查询默认出库仓库库存
  2881. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2882. if len(wareOut) > 0 {
  2883. for _, it := range wareOut {
  2884. //回退库存
  2885. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2886. //删除出库记录
  2887. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2888. }
  2889. }
  2890. timeStr := time.Now().Format("2006-01-02")
  2891. timeArr := strings.Split(timeStr, "-")
  2892. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2893. total = total + 1
  2894. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2895. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2896. number = number + total
  2897. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2898. operation_time := time.Now().Unix()
  2899. creater := c.GetAdminUserInfo().AdminUser.Id
  2900. recordDateStr := time.Now().Format("2006-01-02")
  2901. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2902. nowtime := recordDate.Unix()
  2903. warehouseOut := models.WarehouseOut{
  2904. WarehouseOutOrderNumber: warehousing_out_order,
  2905. OperationTime: operation_time,
  2906. OrgId: adminInfo.CurrentOrgId,
  2907. Creater: creater,
  2908. Ctime: time.Now().Unix(),
  2909. Status: 1,
  2910. WarehouseOutTime: nowtime,
  2911. Type: 1,
  2912. StorehouseId: storeConfig.StorehouseOutInfo,
  2913. IsCheck: 1,
  2914. IsSys: 1,
  2915. }
  2916. //查询是否生成出库单
  2917. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2918. if out.ID == 0 {
  2919. service.AddSigleWarehouseOut(&warehouseOut)
  2920. }
  2921. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2922. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2923. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2924. dialyPrepareOne := models.DialysisBeforePrepare{
  2925. GoodTypeId: goodObj.GoodTypeId,
  2926. GoodId: item.ProjectId,
  2927. PatientId: item.PatientId,
  2928. RecordDate: item.RecordDate,
  2929. UserOrgId: adminInfo.CurrentOrgId,
  2930. Count: parseIntCount,
  2931. Ctime: time.Now().Unix(),
  2932. Creater: creater,
  2933. Status: 1,
  2934. StorehouseId: houseConfig.StorehouseOutInfo,
  2935. ProjectId: item.ID,
  2936. }
  2937. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2938. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2939. //查询历史出库数据
  2940. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2941. var out_count int64
  2942. for _, item := range flowGood {
  2943. out_count += item.Count
  2944. }
  2945. //如果历史数和当前数据不想等才进行退库出库
  2946. if out_count != parseIntCount {
  2947. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2948. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2949. detail := models.AutomaticReduceDetail{
  2950. WarehouseOutId: 0,
  2951. WarehouseOutOrderNumber: "",
  2952. PatientId: item.PatientId,
  2953. Ctime: time.Now().Unix(),
  2954. Mtime: 0,
  2955. Status: 1,
  2956. RecordTime: item.RecordDate,
  2957. OrgId: item.UserOrgId,
  2958. GoodId: item.ProjectId,
  2959. GoodTypeId: 0,
  2960. Count: parseIntCount,
  2961. Type: 0,
  2962. ProjectId: item.ID,
  2963. StorehouseId: 0,
  2964. }
  2965. service.CreateAutoDetail(detail)
  2966. //查询剩余库存
  2967. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2968. var sum_count int64
  2969. for _, item := range goodList {
  2970. sum_count += item.StockCount
  2971. }
  2972. //更新剩余库存
  2973. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2974. //耗材
  2975. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2976. }
  2977. }
  2978. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2979. //查询历史出库数据
  2980. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2981. var out_count int64
  2982. for _, item := range flowGood {
  2983. out_count += item.Count
  2984. }
  2985. //如果历史数和当前数据不想等才进行退库出库
  2986. if out_count != parseIntCount {
  2987. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2988. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2989. detail := models.AutomaticReduceDetail{
  2990. WarehouseOutId: 0,
  2991. WarehouseOutOrderNumber: "",
  2992. PatientId: item.PatientId,
  2993. Ctime: time.Now().Unix(),
  2994. Mtime: 0,
  2995. Status: 1,
  2996. RecordTime: item.RecordDate,
  2997. OrgId: item.UserOrgId,
  2998. GoodId: item.ProjectId,
  2999. GoodTypeId: 0,
  3000. Count: parseIntCount,
  3001. Type: 0,
  3002. ProjectId: item.ID,
  3003. StorehouseId: 0,
  3004. }
  3005. service.CreateAutoDetail(detail)
  3006. //查询剩余库存
  3007. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3008. var sum_count int64
  3009. for _, item := range goodList {
  3010. sum_count += item.StockCount
  3011. }
  3012. //更新剩余库存
  3013. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3014. //耗材
  3015. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3016. }
  3017. }
  3018. }
  3019. }
  3020. }
  3021. }
  3022. //redisClient := service.RedisClient()
  3023. //defer redisClient.Close()
  3024. //
  3025. //list := models.HisList{
  3026. // Patient_id: patient_id,
  3027. // Advice_id:0,
  3028. // Record_date: 0,
  3029. // Advice: adviceList,
  3030. // Project: nil,
  3031. //}
  3032. //hisLis = append(hisLis, list)
  3033. //
  3034. //advice_json, _ := json.Marshal(&hisLis)
  3035. //redisClient.RPush("111", advice_json).Result()
  3036. //result, _ := redisClient.RPop("111").Result()
  3037. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3038. //
  3039. //var dat []map[string]interface{}
  3040. //json.Unmarshal([]byte(result), &dat)
  3041. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3042. //
  3043. //for k,v:=range dat{
  3044. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3045. //}
  3046. //project_json, _ := json.Marshal(&projectList)
  3047. //redisClient.LPush("222", project_json).Result()
  3048. if err == nil {
  3049. c.ServeSuccessJSON(map[string]interface{}{
  3050. "msg": "保存成功",
  3051. })
  3052. return
  3053. } else {
  3054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3055. return
  3056. }
  3057. }
  3058. func (c *HisApiController) EditHisPrescription() {
  3059. record_date := c.GetString("record_date")
  3060. patient_id, _ := c.GetInt64("patient_id")
  3061. reg_type, _ := c.GetInt64("reg_type")
  3062. //diagnose, _ := c.GetInt64("diagnose", 0)
  3063. diagnose := c.GetString("diagnose")
  3064. sick_type, _ := c.GetInt64("sick_type")
  3065. sick_history := c.GetString("sick_history")
  3066. doctor_id, _ := c.GetInt64("doctor", 0)
  3067. department, _ := c.GetInt64("department", 0)
  3068. his_patient_id, _ := c.GetInt64("his_patient_id")
  3069. p_type, _ := c.GetInt64("p_type")
  3070. dataBody := make(map[string]interface{}, 0)
  3071. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3072. if err != nil {
  3073. utils.ErrorLog(err.Error())
  3074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3075. return
  3076. }
  3077. timeLayout := "2006-01-02"
  3078. loc, _ := time.LoadLocation("Local")
  3079. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3080. if err != nil {
  3081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3082. return
  3083. }
  3084. adminInfo := c.GetAdminUserInfo()
  3085. recordDateTime := theTime.Unix()
  3086. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3087. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3088. var hpInfo models.HisPrescriptionInfo
  3089. if info.ID == 0 {
  3090. var randNum int
  3091. randNum = rand.Intn(10000) + 1000
  3092. timestamp := time.Now().Unix()
  3093. tempTime := time.Unix(timestamp, 0)
  3094. timeFormat := tempTime.Format("20060102150405")
  3095. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3096. hpInfo = models.HisPrescriptionInfo{
  3097. UserOrgId: adminInfo.CurrentOrgId,
  3098. RecordDate: theTime.Unix(),
  3099. PatientId: patient_id,
  3100. Status: 1,
  3101. Ctime: time.Now().Unix(),
  3102. Mtime: time.Now().Unix(),
  3103. Creator: adminInfo.AdminUser.Id,
  3104. Modifier: adminInfo.AdminUser.Id,
  3105. Diagnosis: diagnose,
  3106. SickHistory: sick_history,
  3107. Departments: department,
  3108. RegisterType: reg_type,
  3109. PrescriptionNumber: p_number,
  3110. PrescriptionStatus: 1,
  3111. Doctor: role.UserName,
  3112. DoctorId: doctor_id,
  3113. SickType: sick_type,
  3114. PType: p_type,
  3115. }
  3116. service.SavePatientPrescriptionInfo(hpInfo)
  3117. } else {
  3118. hpInfo = models.HisPrescriptionInfo{
  3119. ID: info.ID,
  3120. UserOrgId: adminInfo.CurrentOrgId,
  3121. RecordDate: info.RecordDate,
  3122. PatientId: info.PatientId,
  3123. Status: 1,
  3124. Ctime: info.Ctime,
  3125. Mtime: time.Now().Unix(),
  3126. Creator: info.Creator,
  3127. Modifier: adminInfo.AdminUser.Id,
  3128. Diagnosis: diagnose,
  3129. SickHistory: sick_history,
  3130. Departments: department,
  3131. RegisterType: reg_type,
  3132. PrescriptionNumber: info.PrescriptionNumber,
  3133. Doctor: role.UserName,
  3134. PrescriptionStatus: info.PrescriptionStatus,
  3135. DoctorId: doctor_id,
  3136. SickType: sick_type,
  3137. PType: info.PType,
  3138. }
  3139. service.SavePatientPrescriptionInfo(hpInfo)
  3140. }
  3141. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3142. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3143. if len(prescriptions) > 0 {
  3144. for _, item := range prescriptions {
  3145. items := item.(map[string]interface{})
  3146. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3147. utils.ErrorLog("id")
  3148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3149. return
  3150. }
  3151. id := int64(items["id"].(float64))
  3152. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3153. utils.ErrorLog("type")
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3155. return
  3156. }
  3157. types := int64(items["type"].(float64))
  3158. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3159. utils.ErrorLog("med_type")
  3160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3161. return
  3162. }
  3163. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3164. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3165. ctime := time.Now().Unix()
  3166. prescription := &models.HisPrescription{
  3167. ID: id,
  3168. PatientId: patient_id,
  3169. UserOrgId: adminInfo.CurrentOrgId,
  3170. RecordDate: recordDateTime,
  3171. Ctime: ctime,
  3172. Mtime: ctime,
  3173. Type: types,
  3174. Modifier: adminInfo.AdminUser.Id,
  3175. Creator: adminInfo.AdminUser.Id,
  3176. Status: 1,
  3177. Doctor: role.UserName,
  3178. HisPatientId: his_patient_id,
  3179. OrderStatus: 1,
  3180. BatchNumber: "",
  3181. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3182. PType: hpInfo.PType,
  3183. MedType: med_type,
  3184. }
  3185. if historyPrescription.ID > 0 {
  3186. prescription.PreTime = historyPrescription.PreTime
  3187. }
  3188. service.SaveHisPrescription(prescription)
  3189. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3190. advices := items["advices"].([]interface{})
  3191. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3192. groupNo := int64(0)
  3193. ctime := time.Now().Unix()
  3194. mtime := ctime
  3195. if len(advices) > 0 {
  3196. for _, advice := range advices {
  3197. var s models.HisDoctorAdviceInfo
  3198. s.PrescriptionId = prescription.ID
  3199. s.AdviceType = 2
  3200. s.AdviceDoctor = adminInfo.AdminUser.Id
  3201. s.StopState = 2
  3202. s.ExecutionState = 2
  3203. s.AdviceDate = recordDateTime
  3204. s.Status = 1
  3205. s.UserOrgId = adminInfo.CurrentOrgId
  3206. s.RecordDate = recordDateTime
  3207. s.StartTime = prescription.PreTime
  3208. s.Groupno = groupNo
  3209. s.CreatedTime = ctime
  3210. s.UpdatedTime = mtime
  3211. s.PatientId = patient_id
  3212. s.HisPatientId = his_patient_id
  3213. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3214. if errcode > 0 {
  3215. c.ServeFailJSONWithSGJErrorCode(errcode)
  3216. return
  3217. }
  3218. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3219. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3220. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3221. if s.Price == 0 {
  3222. s.Price = lastWarehouse.RetailPrice
  3223. }
  3224. }
  3225. service.CreateHisDoctorAdvice(&s)
  3226. //记录日志
  3227. byterequest, _ := json.Marshal(s)
  3228. adviceLog := models.XtDoctorAdviceLog{
  3229. UserOrgId: s.UserOrgId,
  3230. PatientId: s.PatientId,
  3231. AdminUserId: adminInfo.AdminUser.Id,
  3232. Module: 1,
  3233. ErrLog: string(byterequest),
  3234. Status: 1,
  3235. Ctime: time.Now().Unix(),
  3236. Mtime: 0,
  3237. Source: "电脑端his医嘱修改",
  3238. RecordDate: s.AdviceDate,
  3239. }
  3240. service.CreateDoctorAdviceLog(adviceLog)
  3241. redis := service.RedisClient()
  3242. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3243. redis.Set(key, "", time.Second)
  3244. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3245. fmt.Println("keyOne", keyOne)
  3246. redis.Set(keyOne, "", time.Second)
  3247. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3248. redis.Set(keySeven, "", time.Second)
  3249. redis.Close()
  3250. }
  3251. }
  3252. }
  3253. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3254. projects := items["project"].([]interface{})
  3255. if len(projects) > 0 {
  3256. for _, project := range projects {
  3257. var p models.HisPrescriptionProject
  3258. p.PrescriptionId = prescription.ID
  3259. p.Ctime = time.Now().Unix()
  3260. p.Mtime = time.Now().Unix()
  3261. p.PatientId = patient_id
  3262. p.RecordDate = recordDateTime
  3263. p.UserOrgId = adminInfo.CurrentOrgId
  3264. p.HisPatientId = his_patient_id
  3265. p.Status = 1
  3266. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3267. if errcode > 0 {
  3268. c.ServeFailJSONWithSGJErrorCode(errcode)
  3269. return
  3270. }
  3271. service.CreateHisProjectTwo(&p)
  3272. //记录日志
  3273. byterequest, _ := json.Marshal(p)
  3274. adviceLog := models.XtDoctorAdviceLog{
  3275. UserOrgId: p.UserOrgId,
  3276. PatientId: p.PatientId,
  3277. AdminUserId: adminInfo.AdminUser.Id,
  3278. Module: 1,
  3279. ErrLog: string(byterequest),
  3280. Status: 1,
  3281. Ctime: time.Now().Unix(),
  3282. Mtime: 0,
  3283. Source: "电脑端his项目修改",
  3284. RecordDate: p.RecordDate,
  3285. }
  3286. service.CreateDoctorAdviceLog(adviceLog)
  3287. }
  3288. }
  3289. }
  3290. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3291. addition := items["addition"].([]interface{})
  3292. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3293. ctime := time.Now().Unix()
  3294. mtime := ctime
  3295. if len(addition) > 0 {
  3296. for _, item := range addition {
  3297. var s models.HisAdditionalCharge
  3298. s.PrescriptionId = prescription.ID
  3299. s.Status = 1
  3300. s.UserOrgId = adminInfo.CurrentOrgId
  3301. s.RecordDate = recordDateTime
  3302. s.CreatedTime = ctime
  3303. s.UpdatedTime = mtime
  3304. s.PatientId = patient_id
  3305. s.HisPatientId = his_patient_id
  3306. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3307. if errcode > 0 {
  3308. c.ServeFailJSONWithSGJErrorCode(errcode)
  3309. return
  3310. }
  3311. service.CreateAdditionalCharge(&s)
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. if err == nil {
  3319. c.ServeSuccessJSON(map[string]interface{}{
  3320. "msg": "保存成功",
  3321. })
  3322. return
  3323. } else {
  3324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3325. return
  3326. }
  3327. }
  3328. func (c *HisApiController) DeletePrescription() {
  3329. prescription_id, _ := c.GetInt64("id")
  3330. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3331. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3332. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3333. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3334. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3335. //耗材保存处方出库
  3336. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3337. //已收费和已发药限制逻辑
  3338. isCharge := false
  3339. isMedicine := false
  3340. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3341. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3342. for _, item := range new_prescriptions {
  3343. if item.IsMedicine == 1 {
  3344. isMedicine = true
  3345. }
  3346. }
  3347. for _, item := range new_prescriptions {
  3348. if item.OrderStatus == 4 {
  3349. isCharge = true
  3350. }
  3351. }
  3352. if p_err != nil {
  3353. if new_prescription.ID > 0 {
  3354. if new_prescription.OrderStatus == 2 {
  3355. isCharge = true
  3356. }
  3357. }
  3358. }
  3359. for _, item := range advices {
  3360. if item.IsMedicine == 1 {
  3361. isMedicine = true
  3362. }
  3363. }
  3364. if isCharge {
  3365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3366. return
  3367. }
  3368. if isMedicine {
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3370. return
  3371. }
  3372. //已收费和已发药限制逻辑
  3373. if len(projects) > 0 {
  3374. for _, item := range projects {
  3375. service.DeletePrintInfo(item.ID) //删除打印信息
  3376. if goodOutConfig.IsOpen != 1 {
  3377. if stockConfig.IsOpen == 1 {
  3378. if item.Type == 3 && item.IsOut == 1 {
  3379. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3380. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3381. good.Total = good.Total + f_count
  3382. service.UpdateGoodInfo(&good)
  3383. operation_time := time.Now().Unix()
  3384. creater := c.GetAdminUserInfo().AdminUser.Id
  3385. //创建退库单
  3386. timeStr := time.Now().Format("2006-01-02")
  3387. timeArr := strings.Split(timeStr, "-")
  3388. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3389. total = total + 1
  3390. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3391. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3392. cancelStock := models.CancelStock{
  3393. OrderNumber: orderNumber,
  3394. OperaTime: operation_time,
  3395. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3396. Creater: creater,
  3397. Ctime: time.Now().Unix(),
  3398. Status: 1,
  3399. ReturnTime: item.RecordDate,
  3400. Type: 1,
  3401. StorehouseId: houseConfig.StorehouseOutInfo,
  3402. IsCheck: 1,
  3403. }
  3404. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3405. if msgerrkonde == gorm.ErrRecordNotFound {
  3406. service.AddSigleCancelStock(&cancelStock)
  3407. }
  3408. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3409. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3410. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3411. //查询该耗材是否出库
  3412. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3413. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3414. deaerler, _ := service.GetDealerById(info.Dealer)
  3415. var total_count int64
  3416. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3417. total_count += count
  3418. if info.ID > 0 {
  3419. if info.Count >= total_count {
  3420. //回退库存
  3421. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3422. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3423. var flush_count int64
  3424. for _, it := range goodList {
  3425. flush_count += it.StockCount
  3426. }
  3427. cancelStockInfo := models.CancelStockInfo{
  3428. GoodId: item.ProjectId,
  3429. CancelStockId: cancel.ID,
  3430. GoodTypeId: good.GoodTypeId,
  3431. Count: prescribingNumber,
  3432. Price: info.Price,
  3433. Total: 0,
  3434. ProductDate: info.ProductDate,
  3435. ExpiryDate: info.ExpiryDate,
  3436. Ctime: time.Now().Unix(),
  3437. Status: 1,
  3438. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3439. OrderNumber: cancel.OrderNumber,
  3440. Type: 0,
  3441. Dealer: deaerler.DealerName,
  3442. Manufacturer: manufacturer.ManufacturerName,
  3443. Number: info.Number,
  3444. RegisterAccount: "",
  3445. Remark: "",
  3446. WarehouseInfoId: info.WarehouseInfotId,
  3447. PatientId: info.PatientId,
  3448. RecordDate: info.SysRecordTime,
  3449. StorehouseId: houseConfig.StorehouseOutInfo,
  3450. IsCheck: 1,
  3451. }
  3452. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3453. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3454. flow := models.VmStockFlow{
  3455. WarehousingId: info.WarehouseInfotId,
  3456. GoodId: item.ProjectId,
  3457. Number: info.Number,
  3458. LicenseNumber: info.LicenseNumber,
  3459. Count: prescribingNumber,
  3460. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3461. PatientId: item.PatientId,
  3462. SystemTime: info.SysRecordTime,
  3463. ConsumableType: 7,
  3464. IsSys: 0,
  3465. WarehousingOrder: "",
  3466. WarehouseOutId: info.WarehouseOutId,
  3467. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3468. IsEdit: 0,
  3469. CancelStockId: cancel.ID,
  3470. CancelOrderNumber: cancel.OrderNumber,
  3471. Manufacturer: manufacturer.ID,
  3472. Dealer: 0,
  3473. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3474. UpdateCreator: 0,
  3475. Status: 1,
  3476. Ctime: time.Now().Unix(),
  3477. Mtime: 0,
  3478. Price: info.Price,
  3479. WarehousingDetailId: info.WarehouseInfotId,
  3480. WarehouseOutDetailId: info.ID,
  3481. CancelOutDetailId: cancelInfo.ID,
  3482. ProductDate: info.ProductDate,
  3483. ExpireDate: info.ExpiryDate,
  3484. StorehouseId: houseConfig.StorehouseOutInfo,
  3485. OverCount: flush_count,
  3486. }
  3487. service.CreateStockFlowOne(flow)
  3488. //退库数量增加
  3489. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3490. //出库数量减少
  3491. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3492. }
  3493. if info.Count < total_count {
  3494. //回退库存
  3495. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3496. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3497. var flush_count int64
  3498. for _, it := range goodList {
  3499. flush_count += it.StockCount
  3500. }
  3501. cancelStockInfo := models.CancelStockInfo{
  3502. GoodId: item.ProjectId,
  3503. CancelStockId: cancel.ID,
  3504. GoodTypeId: good.GoodTypeId,
  3505. Count: info.Count,
  3506. Price: info.Price,
  3507. Total: 0,
  3508. ProductDate: info.ProductDate,
  3509. ExpiryDate: info.ExpiryDate,
  3510. Ctime: time.Now().Unix(),
  3511. Status: 1,
  3512. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3513. OrderNumber: cancel.OrderNumber,
  3514. Type: 0,
  3515. Dealer: deaerler.DealerName,
  3516. Manufacturer: manufacturer.ManufacturerName,
  3517. Number: info.Number,
  3518. RegisterAccount: "",
  3519. Remark: "",
  3520. WarehouseInfoId: info.WarehouseInfotId,
  3521. PatientId: info.PatientId,
  3522. RecordDate: info.SysRecordTime,
  3523. StorehouseId: houseConfig.StorehouseOutInfo,
  3524. IsCheck: 1,
  3525. }
  3526. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3527. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3528. flow := models.VmStockFlow{
  3529. WarehousingId: info.WarehouseInfotId,
  3530. GoodId: item.ProjectId,
  3531. Number: info.Number,
  3532. LicenseNumber: info.LicenseNumber,
  3533. Count: info.Count,
  3534. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3535. PatientId: item.PatientId,
  3536. SystemTime: info.SysRecordTime,
  3537. ConsumableType: 7,
  3538. IsSys: 0,
  3539. WarehousingOrder: "",
  3540. WarehouseOutId: info.WarehouseOutId,
  3541. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3542. IsEdit: 0,
  3543. CancelStockId: cancel.ID,
  3544. CancelOrderNumber: cancel.OrderNumber,
  3545. Manufacturer: manufacturer.ID,
  3546. Dealer: 0,
  3547. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3548. UpdateCreator: 0,
  3549. Status: 1,
  3550. Ctime: time.Now().Unix(),
  3551. Mtime: 0,
  3552. Price: info.Price,
  3553. WarehousingDetailId: info.WarehouseInfotId,
  3554. WarehouseOutDetailId: info.ID,
  3555. CancelOutDetailId: cancelInfo.ID,
  3556. ProductDate: info.ProductDate,
  3557. ExpireDate: info.ExpiryDate,
  3558. StorehouseId: houseConfig.StorehouseOutInfo,
  3559. OverCount: flush_count,
  3560. }
  3561. service.CreateStockFlowOne(flow)
  3562. //退库数量增加
  3563. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3564. //出库数量减少
  3565. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3566. }
  3567. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3568. var flush_count int64
  3569. for _, it := range goodList {
  3570. flush_count += it.StockCount
  3571. }
  3572. //查询已出库数量
  3573. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3574. if prescribingNumber < dialysisInfo.Count {
  3575. //改变数量
  3576. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3577. }
  3578. if prescribingNumber >= dialysisInfo.Count {
  3579. //删除出库表
  3580. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3581. }
  3582. //更新库存
  3583. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3584. //更新基础库库存
  3585. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3586. }
  3587. }
  3588. }
  3589. }
  3590. //保存耗材出库
  3591. if goodOutConfig.IsOpen == 1 {
  3592. if item.Type == 3 {
  3593. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3594. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3595. good.Total = good.Total + f_count
  3596. service.UpdateGoodInfo(&good)
  3597. operation_time := time.Now().Unix()
  3598. creater := c.GetAdminUserInfo().AdminUser.Id
  3599. //创建退库单
  3600. timeStr := time.Now().Format("2006-01-02")
  3601. timeArr := strings.Split(timeStr, "-")
  3602. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3603. total = total + 1
  3604. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3605. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3606. cancelStock := models.CancelStock{
  3607. OrderNumber: orderNumber,
  3608. OperaTime: operation_time,
  3609. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3610. Creater: creater,
  3611. Ctime: time.Now().Unix(),
  3612. Status: 1,
  3613. ReturnTime: item.RecordDate,
  3614. Type: 1,
  3615. StorehouseId: houseConfig.StorehouseOutInfo,
  3616. IsCheck: 1,
  3617. }
  3618. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3619. if msgerrkonde == gorm.ErrRecordNotFound {
  3620. service.AddSigleCancelStock(&cancelStock)
  3621. }
  3622. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3623. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3624. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3625. //查询该耗材是否出库
  3626. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3627. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3628. deaerler, _ := service.GetDealerById(info.Dealer)
  3629. var total_count int64
  3630. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3631. total_count += count
  3632. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3633. var flush_count int64
  3634. for _, it := range goodList {
  3635. flush_count += it.StockCount
  3636. }
  3637. fmt.Println("历史出库数据", info.Count)
  3638. fmt.Println("出库数量", total_count)
  3639. if info.ID > 0 {
  3640. cancelStockInfo := models.CancelStockInfo{
  3641. GoodId: item.ProjectId,
  3642. CancelStockId: cancel.ID,
  3643. GoodTypeId: good.GoodTypeId,
  3644. Count: prescribingNumber,
  3645. Price: info.Price,
  3646. Total: 0,
  3647. ProductDate: info.ProductDate,
  3648. ExpiryDate: info.ExpiryDate,
  3649. Ctime: time.Now().Unix(),
  3650. Status: 1,
  3651. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3652. OrderNumber: cancel.OrderNumber,
  3653. Type: 0,
  3654. Dealer: deaerler.DealerName,
  3655. Manufacturer: manufacturer.ManufacturerName,
  3656. Number: info.Number,
  3657. RegisterAccount: "",
  3658. Remark: "",
  3659. WarehouseInfoId: info.WarehouseInfotId,
  3660. PatientId: info.PatientId,
  3661. RecordDate: info.SysRecordTime,
  3662. StorehouseId: houseConfig.StorehouseOutInfo,
  3663. IsCheck: 1,
  3664. }
  3665. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3666. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3667. //查询出库数量
  3668. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3669. //出库数据 大于 退库数量
  3670. if len(list) > 0 {
  3671. for _, it := range list {
  3672. //回退库存
  3673. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3674. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3675. var flush_count_one int64
  3676. for _, it := range goodList {
  3677. flush_count_one += it.StockCount
  3678. }
  3679. //查询该批次是否有退库数据
  3680. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3681. creater := c.GetAdminUserInfo().AdminUser.Id
  3682. flow := models.VmStockFlow{
  3683. WarehousingId: it.WarehouseInfotId,
  3684. GoodId: it.GoodId,
  3685. Number: it.Number,
  3686. LicenseNumber: it.LicenseNumber,
  3687. Count: it.Count,
  3688. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3689. PatientId: it.PatientId,
  3690. SystemTime: it.SysRecordTime,
  3691. ConsumableType: 7,
  3692. IsSys: 0,
  3693. WarehousingOrder: "",
  3694. WarehouseOutId: it.WarehouseOutId,
  3695. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3696. IsEdit: 0,
  3697. CancelStockId: cancel.ID,
  3698. CancelOrderNumber: cancel.OrderNumber,
  3699. Manufacturer: manufacturer.ID,
  3700. Dealer: 0,
  3701. Creator: creater,
  3702. UpdateCreator: 0,
  3703. Status: 1,
  3704. Ctime: time.Now().Unix(),
  3705. Mtime: 0,
  3706. Price: it.Price,
  3707. WarehousingDetailId: it.WarehouseInfotId,
  3708. WarehouseOutDetailId: it.ID,
  3709. CancelOutDetailId: cancelInfo.ID,
  3710. ProductDate: it.ProductDate,
  3711. ExpireDate: it.ExpiryDate,
  3712. StorehouseId: houseConfig.StorehouseOutInfo,
  3713. OverCount: flush_count_one,
  3714. }
  3715. service.CreateStockFlowOne(flow)
  3716. //if flow.ID > 0 {
  3717. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3718. //}
  3719. }
  3720. }
  3721. //flow := models.VmStockFlow{
  3722. // WarehousingId: info.WarehouseInfotId,
  3723. // GoodId: item.ProjectId,
  3724. // Number: info.Number,
  3725. // LicenseNumber: info.LicenseNumber,
  3726. // Count: prescribingNumber,
  3727. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3728. // PatientId: item.PatientId,
  3729. // SystemTime: info.SysRecordTime,
  3730. // ConsumableType: 7,
  3731. // IsSys: 0,
  3732. // WarehousingOrder: "",
  3733. // WarehouseOutId: info.WarehouseOutId,
  3734. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3735. // IsEdit: 0,
  3736. // CancelStockId: cancel.ID,
  3737. // CancelOrderNumber: cancel.OrderNumber,
  3738. // Manufacturer: manufacturer.ID,
  3739. // Dealer: 0,
  3740. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3741. // UpdateCreator: 0,
  3742. // Status: 1,
  3743. // Ctime: time.Now().Unix(),
  3744. // Mtime: 0,
  3745. // Price: info.Price,
  3746. // WarehousingDetailId: info.WarehouseInfotId,
  3747. // WarehouseOutDetailId: info.ID,
  3748. // CancelOutDetailId: cancelInfo.ID,
  3749. // ProductDate: info.ProductDate,
  3750. // ExpireDate: info.ExpiryDate,
  3751. // StorehouseId: houseConfig.StorehouseOutInfo,
  3752. // OverCount: flush_count,
  3753. //}
  3754. //service.CreateStockFlowOne(flow)
  3755. //退库数量增加
  3756. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3757. //出库数量减少
  3758. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3759. //查询已出库数量
  3760. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3761. if prescribingNumber < dialysisInfo.Count {
  3762. //改变数量
  3763. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3764. }
  3765. if prescribingNumber >= dialysisInfo.Count {
  3766. //删除出库表
  3767. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3768. }
  3769. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3770. var flush_count_one int64
  3771. for _, it := range goodList {
  3772. flush_count_one += it.StockCount
  3773. }
  3774. //更新库存
  3775. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3776. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3777. //更新基础库库存
  3778. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3779. }
  3780. }
  3781. }
  3782. }
  3783. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3784. fmt.Println(err)
  3785. }
  3786. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3787. fmt.Println(err)
  3788. if len(advices) > 0 {
  3789. for _, item := range advices {
  3790. redis := service.RedisClient()
  3791. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3792. redis.Set(keyFive, "", time.Second)
  3793. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3794. redis.Set(keyOne, "", time.Second)
  3795. redis.Close()
  3796. }
  3797. }
  3798. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3799. if len(advices) > 0 {
  3800. for _, item := range advices {
  3801. creater := c.GetAdminUserInfo().AdminUser.Id
  3802. service.DrugAutoAddCancelInfo(item, creater)
  3803. }
  3804. }
  3805. } else {
  3806. if drugOutConfig.IsOpen == 1 {
  3807. if len(advices) > 0 {
  3808. for _, item := range advices {
  3809. creater := c.GetAdminUserInfo().AdminUser.Id
  3810. service.DrugAutoAddCancelInfo(item, creater)
  3811. }
  3812. }
  3813. } else {
  3814. if len(advices) > 0 {
  3815. for _, item := range advices {
  3816. creater := c.GetAdminUserInfo().AdminUser.Id
  3817. service.DrugAutoAddCancelInfo(item, creater)
  3818. }
  3819. }
  3820. }
  3821. }
  3822. c.ServeSuccessJSON(map[string]interface{}{
  3823. "msg": "删除成功",
  3824. })
  3825. return
  3826. }
  3827. func (c *HisApiController) DeleteDoctorAdvice() {
  3828. id, _ := c.GetInt64("id")
  3829. advice, _ := service.GetHisDoctorAdvicesById(id)
  3830. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3831. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3832. //已收费和已发药的限制逻辑
  3833. isCharge := false
  3834. isMedicine := false
  3835. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3836. //获取今天该患者所有处方,判断是否发药或者收费
  3837. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3838. for _, item := range new_prescriptions {
  3839. if item.IsMedicine == 1 {
  3840. isMedicine = true
  3841. }
  3842. }
  3843. for _, item := range new_prescriptions {
  3844. if item.OrderStatus == 4 {
  3845. isCharge = true
  3846. }
  3847. }
  3848. if isMedicine {
  3849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3850. return
  3851. }
  3852. if isCharge {
  3853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3854. return
  3855. }
  3856. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3857. for _, item := range advices {
  3858. if item.IsMedicine == 1 {
  3859. isMedicine = true
  3860. }
  3861. }
  3862. if isMedicine {
  3863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3864. return
  3865. }
  3866. if new_prescription.ID > 0 {
  3867. if new_prescription.OrderStatus == 2 {
  3868. isCharge = true
  3869. }
  3870. }
  3871. if isCharge {
  3872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3873. return
  3874. }
  3875. //已收费和已发药的限制逻辑
  3876. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3877. redis := service.RedisClient()
  3878. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3879. redis.Set(keyFive, "", time.Second)
  3880. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3881. redis.Set(keyOne, "", time.Second)
  3882. defer redis.Close()
  3883. if err == nil {
  3884. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3885. //查询是否在处方中出库
  3886. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3887. if openConfig.IsOpen != 1 {
  3888. //判断该医嘱是否执行了
  3889. if advice.ExecutionState == 1 {
  3890. creater := c.GetAdminUserInfo().AdminUser.Id
  3891. service.DrugAutoAddCancelInfo(&advice, creater)
  3892. }
  3893. }
  3894. //开启保存处方扣减功能
  3895. if openConfig.IsOpen == 1 {
  3896. creater := c.GetAdminUserInfo().AdminUser.Id
  3897. service.DrugAutoAddCancelInfo(&advice, creater)
  3898. }
  3899. } else {
  3900. if drugOutConfig.IsOpen == 1 {
  3901. //查询是否在处方中出库
  3902. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3903. if openConfig.IsOpen != 1 {
  3904. //判断该医嘱是否执行了
  3905. if advice.ExecutionState == 1 {
  3906. creater := c.GetAdminUserInfo().AdminUser.Id
  3907. service.DrugAutoAddCancelInfo(&advice, creater)
  3908. }
  3909. }
  3910. //开启保存处方扣减功能
  3911. if openConfig.IsOpen == 1 {
  3912. creater := c.GetAdminUserInfo().AdminUser.Id
  3913. service.DrugAutoAddCancelInfo(&advice, creater)
  3914. }
  3915. } else {
  3916. //判断该医嘱是否执行了
  3917. if advice.ExecutionState == 1 {
  3918. creater := c.GetAdminUserInfo().AdminUser.Id
  3919. service.DrugAutoAddCancelInfo(&advice, creater)
  3920. }
  3921. }
  3922. }
  3923. c.ServeSuccessJSON(map[string]interface{}{
  3924. "msg": "删除成功",
  3925. })
  3926. return
  3927. } else {
  3928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3929. return
  3930. }
  3931. }
  3932. func (c *HisApiController) DeleteProject() {
  3933. id, _ := c.GetInt64("id")
  3934. adminInfo := c.GetAdminUserInfo()
  3935. project, _ := service.GetHisProjectByID(id)
  3936. // var consumable models.DialysisBeforePrepare
  3937. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3938. //耗材保存处方出库
  3939. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3940. isCharge := false
  3941. isMedicine := false
  3942. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3943. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3944. for _, item := range new_prescriptions {
  3945. if item.IsMedicine == 1 {
  3946. isMedicine = true
  3947. }
  3948. }
  3949. for _, item := range new_prescriptions {
  3950. if item.OrderStatus == 4 {
  3951. isCharge = true
  3952. }
  3953. }
  3954. if isMedicine {
  3955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3956. return
  3957. }
  3958. if isCharge {
  3959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3960. return
  3961. }
  3962. if new_prescription.ID > 0 {
  3963. if new_prescription.OrderStatus == 2 {
  3964. isCharge = true
  3965. }
  3966. }
  3967. if isCharge {
  3968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3969. return
  3970. }
  3971. service.DeletePrintInfo(id)
  3972. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3973. label.Status = 0
  3974. service.CreateHisLabelRecord(&label)
  3975. fmt.Println(goodOutConfig.IsOpen)
  3976. if goodOutConfig.IsOpen != 1 {
  3977. if stockConfig.IsOpen == 1 {
  3978. if project.Type == 2 {
  3979. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3980. fmt.Println(err)
  3981. }
  3982. if project.Type == 3 && project.IsOut == 1 {
  3983. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3984. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3985. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3986. operation_time := time.Now().Unix()
  3987. creater := adminInfo.AdminUser.Id
  3988. //创建退库单
  3989. timeStr := time.Now().Format("2006-01-02")
  3990. timeArr := strings.Split(timeStr, "-")
  3991. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3992. total = total + 1
  3993. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3994. cancelStock := models.CancelStock{
  3995. OrderNumber: orderNumber,
  3996. OperaTime: operation_time,
  3997. OrgId: adminInfo.CurrentOrgId,
  3998. Creater: creater,
  3999. Ctime: time.Now().Unix(),
  4000. Status: 1,
  4001. ReturnTime: project.RecordDate,
  4002. Type: 1,
  4003. StorehouseId: houseConfig.StorehouseOutInfo,
  4004. IsCheck: 1,
  4005. }
  4006. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4007. if msgerrkonde == gorm.ErrRecordNotFound {
  4008. service.AddSigleCancelStock(&cancelStock)
  4009. }
  4010. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4011. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4012. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4013. //查询是否有出库
  4014. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4015. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4016. deaerler, _ := service.GetDealerById(info.Dealer)
  4017. if info.ID > 0 {
  4018. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4019. if info.Count >= prescribingNumber {
  4020. cancelStockInfo := models.CancelStockInfo{
  4021. GoodId: project.ProjectId,
  4022. CancelStockId: cancel.ID,
  4023. GoodTypeId: good.GoodTypeId,
  4024. Count: prescribingNumber,
  4025. Price: info.Price,
  4026. Total: 0,
  4027. ProductDate: info.ProductDate,
  4028. ExpiryDate: info.ExpiryDate,
  4029. Ctime: time.Now().Unix(),
  4030. Status: 1,
  4031. OrgId: adminInfo.CurrentOrgId,
  4032. OrderNumber: cancel.OrderNumber,
  4033. Type: 0,
  4034. Dealer: deaerler.DealerName,
  4035. Manufacturer: manufacturer.ManufacturerName,
  4036. Number: info.Number,
  4037. RegisterAccount: "",
  4038. Remark: "",
  4039. WarehouseInfoId: info.WarehouseInfotId,
  4040. PatientId: info.PatientId,
  4041. RecordDate: info.SysRecordTime,
  4042. StorehouseId: houseConfig.StorehouseOutInfo,
  4043. IsCheck: 1,
  4044. }
  4045. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4046. //回退库存
  4047. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4048. //退库数量增加
  4049. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4050. //出库数量减少
  4051. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4052. }
  4053. if info.Count < prescribingNumber {
  4054. cancelStockInfo := models.CancelStockInfo{
  4055. GoodId: project.ProjectId,
  4056. CancelStockId: cancel.ID,
  4057. GoodTypeId: good.GoodTypeId,
  4058. Count: info.Count,
  4059. Price: info.Price,
  4060. Total: 0,
  4061. ProductDate: info.ProductDate,
  4062. ExpiryDate: info.ExpiryDate,
  4063. Ctime: time.Now().Unix(),
  4064. Status: 1,
  4065. OrgId: adminInfo.CurrentOrgId,
  4066. OrderNumber: cancel.OrderNumber,
  4067. Type: 0,
  4068. Dealer: deaerler.DealerName,
  4069. Manufacturer: manufacturer.ManufacturerName,
  4070. Number: info.Number,
  4071. RegisterAccount: "",
  4072. Remark: "",
  4073. WarehouseInfoId: info.WarehouseInfotId,
  4074. PatientId: info.PatientId,
  4075. RecordDate: info.SysRecordTime,
  4076. StorehouseId: houseConfig.StorehouseOutInfo,
  4077. IsCheck: 1,
  4078. }
  4079. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4080. //回退库存
  4081. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4082. //退库数量增加
  4083. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4084. //出库数量减少
  4085. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4086. }
  4087. //查询剩余库存
  4088. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4089. var over_count int64
  4090. for _, it := range goodList {
  4091. over_count += it.StockCount
  4092. }
  4093. //出库数据 大于 退库数量
  4094. if info.Count >= prescribingNumber {
  4095. flow := models.VmStockFlow{
  4096. WarehousingId: info.WarehouseInfotId,
  4097. GoodId: project.ProjectId,
  4098. Number: info.Number,
  4099. LicenseNumber: info.LicenseNumber,
  4100. Count: prescribingNumber,
  4101. UserOrgId: adminInfo.CurrentOrgId,
  4102. PatientId: project.PatientId,
  4103. SystemTime: info.SysRecordTime,
  4104. ConsumableType: 7,
  4105. IsSys: 0,
  4106. WarehousingOrder: "",
  4107. WarehouseOutId: info.WarehouseOutId,
  4108. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4109. IsEdit: 0,
  4110. CancelStockId: cancel.ID,
  4111. CancelOrderNumber: cancel.OrderNumber,
  4112. Manufacturer: manufacturer.ID,
  4113. Dealer: 0,
  4114. Creator: adminInfo.AdminUser.Id,
  4115. UpdateCreator: 0,
  4116. Status: 1,
  4117. Ctime: time.Now().Unix(),
  4118. Mtime: 0,
  4119. Price: info.Price,
  4120. WarehousingDetailId: info.WarehouseInfotId,
  4121. WarehouseOutDetailId: info.ID,
  4122. CancelOutDetailId: cancelInfo.ID,
  4123. ProductDate: info.ProductDate,
  4124. ExpireDate: info.ExpiryDate,
  4125. StorehouseId: houseConfig.StorehouseOutInfo,
  4126. OverCount: over_count,
  4127. }
  4128. service.CreateStockFlowOne(flow)
  4129. }
  4130. //出库数据小于退库数据
  4131. if info.Count < prescribingNumber {
  4132. flow := models.VmStockFlow{
  4133. WarehousingId: info.WarehouseInfotId,
  4134. GoodId: project.ProjectId,
  4135. Number: info.Number,
  4136. LicenseNumber: info.LicenseNumber,
  4137. Count: info.Count,
  4138. UserOrgId: adminInfo.CurrentOrgId,
  4139. PatientId: project.PatientId,
  4140. SystemTime: info.SysRecordTime,
  4141. ConsumableType: 7,
  4142. IsSys: 0,
  4143. WarehousingOrder: "",
  4144. WarehouseOutId: info.WarehouseOutId,
  4145. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4146. IsEdit: 0,
  4147. CancelStockId: cancel.ID,
  4148. CancelOrderNumber: cancel.OrderNumber,
  4149. Manufacturer: manufacturer.ID,
  4150. Dealer: 0,
  4151. Creator: adminInfo.AdminUser.Id,
  4152. UpdateCreator: 0,
  4153. Status: 1,
  4154. Ctime: time.Now().Unix(),
  4155. Mtime: 0,
  4156. Price: info.Price,
  4157. WarehousingDetailId: info.WarehouseInfotId,
  4158. WarehouseOutDetailId: info.ID,
  4159. CancelOutDetailId: cancelInfo.ID,
  4160. ProductDate: info.ProductDate,
  4161. ExpireDate: info.ExpiryDate,
  4162. StorehouseId: houseConfig.StorehouseOutInfo,
  4163. OverCount: over_count,
  4164. }
  4165. service.CreateStockFlowOne(flow)
  4166. }
  4167. //查询已出库数量
  4168. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4169. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4170. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4171. if prescribingNumber < dialysisInfo.Count {
  4172. //改变数量
  4173. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4174. }
  4175. if prescribingNumber >= dialysisInfo.Count {
  4176. //删除出库表
  4177. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4178. }
  4179. //更新剩余库存
  4180. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4181. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4182. var total_count_one int64
  4183. for _, it := range stockList {
  4184. total_count_one += it.StockCount
  4185. }
  4186. //基础库插入数据
  4187. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4188. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4189. var flush_count int64
  4190. for _, it := range goodListOne {
  4191. flush_count += it.StockCount
  4192. }
  4193. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4194. if errs != nil {
  4195. goodErrcode := models.XtGoodErrcode{
  4196. UserOrgId: project.UserOrgId,
  4197. Errcode: "手动出库更新剩余出库失败",
  4198. GoodId: project.ProjectId,
  4199. Status: 1,
  4200. Ctime: time.Now().Unix(),
  4201. Mtime: 0,
  4202. Count: 0,
  4203. StockCount: 0,
  4204. Creater: creater,
  4205. BatchNumberId: 0,
  4206. WarehouseOutId: 0,
  4207. }
  4208. service.CreateGoodErrcode(goodErrcode)
  4209. }
  4210. }
  4211. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4212. fmt.Println(err)
  4213. } else {
  4214. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4215. fmt.Println(err)
  4216. }
  4217. } else {
  4218. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4219. fmt.Println(err)
  4220. }
  4221. }
  4222. //保存处方出库
  4223. if goodOutConfig.IsOpen == 1 {
  4224. if project.Type == 3 {
  4225. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4226. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4227. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4228. operation_time := time.Now().Unix()
  4229. creater := adminInfo.AdminUser.Id
  4230. //创建退库单
  4231. timeStr := time.Now().Format("2006-01-02")
  4232. timeArr := strings.Split(timeStr, "-")
  4233. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4234. total = total + 1
  4235. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4236. cancelStock := models.CancelStock{
  4237. OrderNumber: orderNumber,
  4238. OperaTime: operation_time,
  4239. OrgId: adminInfo.CurrentOrgId,
  4240. Creater: creater,
  4241. Ctime: time.Now().Unix(),
  4242. Status: 1,
  4243. ReturnTime: project.RecordDate,
  4244. Type: 1,
  4245. StorehouseId: houseConfig.StorehouseOutInfo,
  4246. IsCheck: 1,
  4247. }
  4248. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4249. if msgerrkonde == gorm.ErrRecordNotFound {
  4250. service.AddSigleCancelStock(&cancelStock)
  4251. }
  4252. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4253. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4254. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4255. //获取出库数据
  4256. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4257. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4258. deaerler, _ := service.GetDealerById(info.Dealer)
  4259. if info.ID > 0 {
  4260. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4261. if info.Count >= prescribingNumber {
  4262. cancelStockInfo := models.CancelStockInfo{
  4263. GoodId: project.ProjectId,
  4264. CancelStockId: cancel.ID,
  4265. GoodTypeId: good.GoodTypeId,
  4266. Count: prescribingNumber,
  4267. Price: info.Price,
  4268. Total: 0,
  4269. ProductDate: info.ProductDate,
  4270. ExpiryDate: info.ExpiryDate,
  4271. Ctime: time.Now().Unix(),
  4272. Status: 1,
  4273. OrgId: adminInfo.CurrentOrgId,
  4274. OrderNumber: cancel.OrderNumber,
  4275. Type: 0,
  4276. Dealer: deaerler.DealerName,
  4277. Manufacturer: manufacturer.ManufacturerName,
  4278. Number: info.Number,
  4279. RegisterAccount: "",
  4280. Remark: "",
  4281. WarehouseInfoId: info.WarehouseInfotId,
  4282. PatientId: info.PatientId,
  4283. RecordDate: info.SysRecordTime,
  4284. StorehouseId: houseConfig.StorehouseOutInfo,
  4285. IsCheck: 1,
  4286. }
  4287. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4288. //退库数量增加
  4289. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4290. //出库数量减少
  4291. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4292. }
  4293. if info.Count < prescribingNumber {
  4294. cancelStockInfo := models.CancelStockInfo{
  4295. GoodId: project.ProjectId,
  4296. CancelStockId: cancel.ID,
  4297. GoodTypeId: good.GoodTypeId,
  4298. Count: prescribingNumber,
  4299. Price: info.Price,
  4300. Total: 0,
  4301. ProductDate: info.ProductDate,
  4302. ExpiryDate: info.ExpiryDate,
  4303. Ctime: time.Now().Unix(),
  4304. Status: 1,
  4305. OrgId: adminInfo.CurrentOrgId,
  4306. OrderNumber: cancel.OrderNumber,
  4307. Type: 0,
  4308. Dealer: deaerler.DealerName,
  4309. Manufacturer: manufacturer.ManufacturerName,
  4310. Number: info.Number,
  4311. RegisterAccount: "",
  4312. Remark: "",
  4313. WarehouseInfoId: info.WarehouseInfotId,
  4314. PatientId: info.PatientId,
  4315. RecordDate: info.SysRecordTime,
  4316. StorehouseId: houseConfig.StorehouseOutInfo,
  4317. IsCheck: 1,
  4318. }
  4319. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4320. //回退库存
  4321. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4322. }
  4323. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4324. var over_count int64
  4325. for _, it := range goodList {
  4326. over_count += it.StockCount
  4327. }
  4328. //查询出库数量
  4329. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4330. //出库数据 大于 退库数量
  4331. if len(list) > 0 {
  4332. for _, it := range list {
  4333. //回退库存
  4334. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4335. //退库数量增加
  4336. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4337. //出库数量减少
  4338. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4339. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4340. var over_count_one int64
  4341. for _, it := range goodList {
  4342. over_count_one += it.StockCount
  4343. }
  4344. //查询该批次是否有退库数据
  4345. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4346. flow := models.VmStockFlow{
  4347. WarehousingId: it.WarehouseInfotId,
  4348. GoodId: it.GoodId,
  4349. Number: it.Number,
  4350. LicenseNumber: it.LicenseNumber,
  4351. Count: it.Count,
  4352. UserOrgId: adminInfo.CurrentOrgId,
  4353. PatientId: it.PatientId,
  4354. SystemTime: it.SysRecordTime,
  4355. ConsumableType: 7,
  4356. IsSys: 0,
  4357. WarehousingOrder: "",
  4358. WarehouseOutId: it.WarehouseOutId,
  4359. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4360. IsEdit: 0,
  4361. CancelStockId: cancel.ID,
  4362. CancelOrderNumber: cancel.OrderNumber,
  4363. Manufacturer: manufacturer.ID,
  4364. Dealer: 0,
  4365. Creator: adminInfo.AdminUser.Id,
  4366. UpdateCreator: 0,
  4367. Status: 1,
  4368. Ctime: time.Now().Unix(),
  4369. Mtime: 0,
  4370. Price: it.Price,
  4371. WarehousingDetailId: it.WarehouseInfotId,
  4372. WarehouseOutDetailId: it.ID,
  4373. CancelOutDetailId: cancelInfo.ID,
  4374. ProductDate: it.ProductDate,
  4375. ExpireDate: it.ExpiryDate,
  4376. StorehouseId: houseConfig.StorehouseOutInfo,
  4377. OverCount: over_count_one,
  4378. }
  4379. service.CreateStockFlowOne(flow)
  4380. }
  4381. }
  4382. //查询已出库数量
  4383. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4384. if prescribingNumber < dialysisInfo.Count {
  4385. //改变数量
  4386. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4387. }
  4388. if prescribingNumber >= dialysisInfo.Count {
  4389. //删除出库表
  4390. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4391. }
  4392. //更新剩余库存
  4393. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4394. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4395. var total_count_one int64
  4396. for _, it := range stockList {
  4397. total_count_one += it.StockCount
  4398. }
  4399. //基础库插入数据
  4400. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4401. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4402. var flush_count int64
  4403. for _, it := range goodListOne {
  4404. flush_count += it.StockCount
  4405. }
  4406. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4407. if errs != nil {
  4408. goodErrcode := models.XtGoodErrcode{
  4409. UserOrgId: project.UserOrgId,
  4410. Errcode: "手动出库更新剩余出库失败",
  4411. GoodId: project.ProjectId,
  4412. Status: 1,
  4413. Ctime: time.Now().Unix(),
  4414. Mtime: 0,
  4415. Count: 0,
  4416. StockCount: 0,
  4417. Creater: creater,
  4418. BatchNumberId: 0,
  4419. WarehouseOutId: 0,
  4420. }
  4421. service.CreateGoodErrcode(goodErrcode)
  4422. }
  4423. }
  4424. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4425. fmt.Println(err)
  4426. } else {
  4427. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4428. fmt.Println(err)
  4429. }
  4430. }
  4431. c.ServeSuccessJSON(map[string]interface{}{
  4432. "msg": "删除成功",
  4433. })
  4434. return
  4435. }
  4436. func (c *HisApiController) CreateHisAdditionalCharge() {
  4437. his_patient_id, _ := c.GetInt64("his_patient_id")
  4438. patient_id, _ := c.GetInt64("patient_id")
  4439. record_date := c.GetString("record_date")
  4440. timeLayout := "2006-01-02"
  4441. loc, _ := time.LoadLocation("Local")
  4442. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4443. if err != nil {
  4444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4445. return
  4446. }
  4447. adminInfo := c.GetAdminUserInfo()
  4448. recordDateTime := theTime.Unix()
  4449. dataBody := make(map[string]interface{}, 0)
  4450. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4451. if err != nil {
  4452. utils.ErrorLog(err.Error())
  4453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4454. return
  4455. }
  4456. var additions []*models.HisAdditionalCharge
  4457. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4458. additions, _ := dataBody["addition"].([]interface{})
  4459. if len(additions) > 0 {
  4460. for _, item := range additions {
  4461. items := item.(map[string]interface{})
  4462. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4463. utils.ErrorLog("item_id")
  4464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4465. return
  4466. }
  4467. item_id := int64(items["item_id"].(float64))
  4468. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4469. utils.ErrorLog("item_name")
  4470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4471. return
  4472. }
  4473. item_name := items["item_name"].(string)
  4474. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4475. utils.ErrorLog("price")
  4476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4477. return
  4478. }
  4479. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4480. ctime := time.Now().Unix()
  4481. additional := &models.HisAdditionalCharge{
  4482. PatientId: patient_id,
  4483. HisPatientId: his_patient_id,
  4484. UserOrgId: adminInfo.CurrentOrgId,
  4485. RecordDate: recordDateTime,
  4486. CreatedTime: ctime,
  4487. UpdatedTime: ctime,
  4488. Modifier: adminInfo.AdminUser.Id,
  4489. Creator: adminInfo.AdminUser.Id,
  4490. Price: price,
  4491. ItemName: item_name,
  4492. ItemId: item_id,
  4493. Status: 1,
  4494. }
  4495. additions = append(additions, additional)
  4496. }
  4497. }
  4498. }
  4499. for _, item := range additions {
  4500. service.CreateAddtionalCharge(item)
  4501. }
  4502. c.ServeSuccessJSON(map[string]interface{}{
  4503. "msg": "创建成功",
  4504. })
  4505. }
  4506. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4507. blood_fat := c.GetString("blood_fat")
  4508. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4509. blood_sugar := c.GetString("blood_sugar")
  4510. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4511. chief_conplaint := c.GetString("chief_conplaint")
  4512. dbp := c.GetString("dbp")
  4513. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4514. delivery_way, _ := c.GetInt64("delivery_way")
  4515. diagnostic := c.GetString("diagnostic")
  4516. family_history := c.GetString("family_history")
  4517. height := c.GetString("height")
  4518. history_of_present_illness := c.GetString("history_of_present_illness")
  4519. is_infect, _ := c.GetInt64("is_infect")
  4520. past_history := c.GetString("past_history")
  4521. patient_id, _ := c.GetInt64("patient_id")
  4522. his_patient_id, _ := c.GetInt64("his_patient_id")
  4523. personal_history := c.GetString("personal_history")
  4524. pulse := c.GetString("pulse")
  4525. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4526. sbp := c.GetString("sbp")
  4527. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4528. heightfloat, _ := strconv.ParseFloat(height, 64)
  4529. sicktype := c.GetString("sick_type")
  4530. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4531. symptom := c.GetString("symptom")
  4532. sick_date := c.GetString("sick_date")
  4533. temperatures := c.GetString("temperature")
  4534. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4535. record_date := c.GetString("record_date")
  4536. breathing := c.GetString("breathing")
  4537. doctor_advice := c.GetString("doctor_advice")
  4538. remark := c.GetString("remark")
  4539. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4540. sick, _ := c.GetInt64("sick")
  4541. diagnose, _ := c.GetInt64("diagnose")
  4542. //id, _ := c.GetInt64("id")
  4543. timeLayout := "2006-01-02"
  4544. loc, _ := time.LoadLocation("Local")
  4545. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4546. allergic_history := c.GetString("allergic_history")
  4547. if err != nil {
  4548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4549. return
  4550. }
  4551. recordDateTime := theTime.Unix()
  4552. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4553. if err != nil {
  4554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4555. return
  4556. }
  4557. sickTimes := sickTime.Unix()
  4558. ctime := time.Now().Unix()
  4559. primary_disease := c.GetString("primary_disease")
  4560. confirm_failure_date := c.GetString("confirm_failure_date")
  4561. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4562. drug_allergy_history := c.GetString("drug_allergy_history")
  4563. physical_examination := c.GetString("physical_examination")
  4564. special_inspection := c.GetString("special_inspection")
  4565. lab_apparatus := c.GetString("lab_apparatus")
  4566. caseHistory := models.HisPatientCaseHistory{
  4567. HisPatientId: his_patient_id,
  4568. PatientId: patient_id,
  4569. Temperature: temperature,
  4570. BloodSugar: bloodsugarfloat,
  4571. Pulse: pulsefloat,
  4572. Sbp: sbpfloat,
  4573. Dbp: dbpfloat,
  4574. Height: heightfloat,
  4575. BloodFat: bloodfatfloat,
  4576. SickType: sick_type,
  4577. Symptom: symptom,
  4578. SickDate: sickTimes,
  4579. IsInfect: is_infect,
  4580. HistoryOfPresentIllness: history_of_present_illness,
  4581. PastHistory: past_history,
  4582. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4583. ChiefConplaint: chief_conplaint,
  4584. PersonalHistory: personal_history,
  4585. FamilyHistory: family_history,
  4586. Diagnostic: diagnostic,
  4587. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4588. Status: 1,
  4589. Ctime: ctime,
  4590. Mtime: ctime,
  4591. RecordDate: recordDateTime,
  4592. DeliveryWay: delivery_way,
  4593. Breathing: breathingfloat,
  4594. DoctorAdvice: doctor_advice,
  4595. Remark: remark,
  4596. Sick: sick,
  4597. Diagnose: diagnose,
  4598. AllergicHistory: allergic_history,
  4599. PrimaryDisease: primary_disease,
  4600. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4601. DrugAllergyHistory: drug_allergy_history,
  4602. PhysicalExamination: physical_examination,
  4603. SpecialInspection: special_inspection,
  4604. LabApparatus: lab_apparatus,
  4605. }
  4606. //查询该患者是否有病历
  4607. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4608. if errcodes == gorm.ErrRecordNotFound {
  4609. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4610. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4611. if err != nil {
  4612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4613. return
  4614. }
  4615. c.ServeSuccessJSON(map[string]interface{}{
  4616. "caseHistory": caseHistory,
  4617. "historyInfo": historyInfo,
  4618. })
  4619. return
  4620. } else if errcodes == nil {
  4621. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4622. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4623. if err != nil {
  4624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4625. return
  4626. }
  4627. c.ServeSuccessJSON(map[string]interface{}{
  4628. "caseHistory": caseHistory,
  4629. "historyInfo": historyInfo,
  4630. })
  4631. }
  4632. //查询该患者是否有病历
  4633. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4634. //if errcode == gorm.ErrRecordNotFound {
  4635. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4636. // if err != nil {
  4637. // c.ServeSuccessJSON(map[string]interface{}{
  4638. // "msg": "保存成功",
  4639. // })
  4640. // }
  4641. //} else if errcode == nil {
  4642. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4643. // return
  4644. //}
  4645. }
  4646. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4647. patient_id, _ := c.GetInt64("patient_id", 0)
  4648. adminUser := c.GetAdminUserInfo()
  4649. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4650. c.ServeSuccessJSON(map[string]interface{}{
  4651. "list": caseHistorys,
  4652. })
  4653. }
  4654. func (c *HisApiController) GetHisPatientCaseHistory() {
  4655. record_date, _ := c.GetInt64("record_date", 0)
  4656. patient_id, _ := c.GetInt64("patient_id", 0)
  4657. admin := c.GetAdminUserInfo()
  4658. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4659. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4660. c.ServeSuccessJSON(map[string]interface{}{
  4661. "info": info,
  4662. "case_history": case_history,
  4663. })
  4664. }
  4665. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4666. template_name := c.GetString("template_name")
  4667. template_remark := c.GetString("template_remark")
  4668. doctor := c.GetAdminUserInfo().AdminUser.Id
  4669. diagnostic := c.GetString("diagnostic")
  4670. chief_conplaint := c.GetString("chief_conplain")
  4671. history_of_present_illness := c.GetString("history_of_present_illness")
  4672. past_history := c.GetString("past_history")
  4673. personal_history := c.GetString("personal_history")
  4674. family_history := c.GetString("family_history")
  4675. user_name := c.GetString("user_name")
  4676. doctor_advice := c.GetString("doctor_advice")
  4677. remark := c.GetString("remark")
  4678. //record_date := c.GetString("record_date")
  4679. //fmt.Println("record_date--------",record_date)
  4680. //timeLayout := "2006-01-02"
  4681. //loc, _ := time.LoadLocation("Local")
  4682. //
  4683. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4684. //if err != nil {
  4685. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4686. // return
  4687. //}
  4688. //recordDateTime := theTime.Unix()
  4689. ctime := time.Now().Unix()
  4690. template := models.HisCaseHistoryTemplate{
  4691. HistoryOfPresentIllness: history_of_present_illness,
  4692. PastHistory: past_history,
  4693. ChiefConplaint: chief_conplaint,
  4694. PersonalHistory: personal_history,
  4695. FamilyHistory: family_history,
  4696. Diagnostic: diagnostic,
  4697. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4698. Status: 1,
  4699. Ctime: ctime,
  4700. Mtime: ctime,
  4701. RecordDate: time.Now().Unix(),
  4702. TemplateName: template_name,
  4703. TemplateRemark: template_remark,
  4704. Creator: doctor,
  4705. Modifier: doctor,
  4706. UserName: user_name,
  4707. DoctorAdvice: doctor_advice,
  4708. Remark: remark,
  4709. }
  4710. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4711. if err == nil {
  4712. c.ServeSuccessJSON(map[string]interface{}{
  4713. "msg": "保存成功",
  4714. })
  4715. } else {
  4716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4717. return
  4718. }
  4719. }
  4720. func (c *HisApiController) GetCaseHistoryTemplate() {
  4721. timeLayout := "2006-01-02"
  4722. loc, _ := time.LoadLocation("Local")
  4723. keyword := c.GetString("keyword")
  4724. start_time := c.GetString("start_time")
  4725. end_time := c.GetString("end_time")
  4726. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4727. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4728. admin := c.GetAdminUserInfo()
  4729. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4730. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4731. c.ServeSuccessJSON(map[string]interface{}{
  4732. "template": template,
  4733. //"history": history,
  4734. })
  4735. }
  4736. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4737. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4738. utils.ErrorLog("drug_name")
  4739. return enums.ErrorCodeParamWrong
  4740. }
  4741. adviceName, _ := json["drug_name"].(string)
  4742. if len(adviceName) == 0 {
  4743. utils.ErrorLog("len(advice_name) == 0")
  4744. return enums.ErrorCodeParamWrong
  4745. }
  4746. advice.AdviceName = adviceName
  4747. adviceDesc, _ := json["advice_desc"].(string)
  4748. advice.AdviceDesc = adviceDesc
  4749. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4750. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4751. advice.DrugSpec = drugSpec
  4752. }
  4753. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4754. remark, _ := json["remark"].(string)
  4755. advice.Remark = remark
  4756. }
  4757. if json["id"] == nil {
  4758. advice.DrugId = 0
  4759. } else {
  4760. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4761. drug_id := int64(json["id"].(float64))
  4762. advice.DrugId = drug_id
  4763. }
  4764. }
  4765. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4766. advice_id := int64(json["advice_id"].(float64))
  4767. advice.ID = advice_id
  4768. if advice.ID > 0 {
  4769. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4770. if err == nil {
  4771. if hisAdvice.ID > 0 {
  4772. advice.ExecutionTime = hisAdvice.ExecutionTime
  4773. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4774. advice.ExecutionState = hisAdvice.ExecutionState
  4775. advice.CheckTime = hisAdvice.CheckTime
  4776. advice.Checker = hisAdvice.Checker
  4777. advice.CheckState = hisAdvice.CheckState
  4778. advice.StartTime = hisAdvice.StartTime
  4779. advice.FeedetlSn = hisAdvice.FeedetlSn
  4780. }
  4781. }
  4782. }
  4783. }
  4784. //
  4785. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4786. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4787. // advice.ExecutionTime = execution_time
  4788. //}
  4789. //
  4790. //
  4791. //
  4792. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4793. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4794. // advice.ExecutionStaff = execution_staff
  4795. //}
  4796. //
  4797. //
  4798. //
  4799. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4800. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4801. // advice.ExecutionState = execution_state
  4802. //}
  4803. //
  4804. //
  4805. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4806. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4807. // advice.CheckTime = check_time
  4808. //}
  4809. //
  4810. //
  4811. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4812. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4813. // advice.CheckState = check_state
  4814. //}
  4815. //
  4816. //
  4817. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4818. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4819. // advice.Checker = checker
  4820. //}
  4821. //
  4822. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4823. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4824. // advice.StartTime = start_time
  4825. //}
  4826. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4827. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4828. advice.IsSelfDrug = is_self_drug
  4829. }
  4830. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4831. drugSpecUnit, _ := json["min_unit"].(string)
  4832. advice.DrugSpecUnit = drugSpecUnit
  4833. }
  4834. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4835. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4836. advice.SingleDose = singleDose
  4837. }
  4838. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4839. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4840. advice.SingleDoseUnit = singleDoseUnit
  4841. }
  4842. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4843. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4844. advice.PrescribingNumber = prescribingNumber
  4845. }
  4846. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4847. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4848. advice.PrescribingNumberUnit = prescribingNumberUnit
  4849. }
  4850. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4851. deliveryWay, _ := json["delivery_way"].(string)
  4852. advice.DeliveryWay = deliveryWay
  4853. }
  4854. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4855. executionFrequency, _ := json["execution_frequency"].(string)
  4856. advice.ExecutionFrequency = executionFrequency
  4857. }
  4858. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4859. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4860. advice.Price = price
  4861. }
  4862. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4863. med_list_codg, _ := json["medical_insurance_number"].(string)
  4864. advice.MedListCodg = med_list_codg
  4865. }
  4866. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4867. day := int64(json["day"].(float64))
  4868. advice.Day = day
  4869. }
  4870. return 0
  4871. }
  4872. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4873. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4874. id := int64(json["id"].(float64))
  4875. project.ID = id
  4876. historyProject, _ := service.GetHisProjectByID(id)
  4877. project.FeedetlSn = historyProject.FeedetlSn
  4878. }
  4879. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4880. project_id := int64(json["project_id"].(float64))
  4881. project.ProjectId = project_id
  4882. }
  4883. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4884. // price := int64(json["price"].(float64))
  4885. // formatInt_price := strconv.FormatInt(price, 10)
  4886. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4887. // project.Price = float_price
  4888. // }
  4889. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4890. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4891. project.Price = price
  4892. }
  4893. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4894. total, _ := json["total"].(string)
  4895. project.Count = total
  4896. }
  4897. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4898. medical_code, _ := json["medical_code"].(string)
  4899. project.MedListCodg = medical_code
  4900. }
  4901. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4902. single_dose, _ := json["single_dose"].(string)
  4903. project.SingleDose = single_dose
  4904. }
  4905. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4906. delivery_way, _ := json["delivery_way"].(string)
  4907. project.DeliveryWay = delivery_way
  4908. }
  4909. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4910. execution_frequency, _ := json["execution_frequency"].(string)
  4911. project.ExecutionFrequency = execution_frequency
  4912. }
  4913. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4914. remark, _ := json["remark"].(string)
  4915. project.Remark = remark
  4916. }
  4917. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4918. day, _ := json["number_days"].(string)
  4919. project.Day = day
  4920. }
  4921. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4922. unit, _ := json["unit"].(string)
  4923. project.Unit = unit
  4924. }
  4925. return 0
  4926. }
  4927. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4928. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4929. id := int64(json["id"].(float64))
  4930. historyAddtions, _ := service.GetHisAdditionByID(id)
  4931. additionalCharge.ID = id
  4932. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4933. }
  4934. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4935. item_id := int64(json["item_id"].(float64))
  4936. additionalCharge.ItemId = item_id
  4937. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4938. if config.ID > 0 {
  4939. if len(config.Code) > 0 {
  4940. additionalCharge.MedListCodg = config.Code
  4941. }
  4942. }
  4943. }
  4944. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4945. // price := int64(json["price"].(float64))
  4946. // formatInt_price := strconv.FormatInt(price, 10)
  4947. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4948. // additionalCharge.Price = float_price
  4949. // }
  4950. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4951. // price := int64(json["price"].(float64))
  4952. // formatInt_price := strconv.FormatInt(price, 10)
  4953. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4954. // additionalCharge.Price = float_price
  4955. //}
  4956. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4957. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4958. additionalCharge.Price = price
  4959. }
  4960. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4961. count, _ := json["count"].(string)
  4962. counts, _ := strconv.ParseInt(count, 10, 64)
  4963. additionalCharge.Count = counts
  4964. }
  4965. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4966. item_name, _ := json["item_name"].(string)
  4967. additionalCharge.ItemName = item_name
  4968. }
  4969. return 0
  4970. }
  4971. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4972. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4973. utils.ErrorLog("drug_name")
  4974. return enums.ErrorCodeParamWrong
  4975. }
  4976. adviceName, _ := json["drug_name"].(string)
  4977. if len(adviceName) == 0 {
  4978. utils.ErrorLog("len(advice_name) == 0")
  4979. return enums.ErrorCodeParamWrong
  4980. }
  4981. advice.AdviceName = adviceName
  4982. adviceDesc, _ := json["advice_desc"].(string)
  4983. advice.AdviceDesc = adviceDesc
  4984. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4985. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4986. advice.DrugSpec = drugSpec
  4987. }
  4988. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4989. remark, _ := json["remark"].(string)
  4990. advice.Remark = remark
  4991. }
  4992. if json["id"] == nil {
  4993. advice.DrugId = 0
  4994. } else {
  4995. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4996. drug_id := int64(json["id"].(float64))
  4997. advice.DrugId = drug_id
  4998. }
  4999. }
  5000. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5001. groupno := int64(json["groupno"].(float64))
  5002. advice.Groupno = groupno
  5003. }
  5004. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5005. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5006. advice.IsSelfDrug = is_self_drug
  5007. }
  5008. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5009. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5010. advice.HospApprFlag = hosp_appr_flag
  5011. }
  5012. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5013. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5014. advice.PrescribingNumber = prescribingNumber
  5015. }
  5016. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5017. // frequency_type := int64(json["frequency_type"].(float64))
  5018. // advice.FrequencyType = frequency_type
  5019. //}
  5020. //
  5021. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5022. // day_count := int64(json["day_count"].(float64))
  5023. // advice.DayCount = day_count
  5024. //}
  5025. //
  5026. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5027. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5028. // week_day, _ := json["week_day"].(string)
  5029. // advice.WeekDay = week_day
  5030. //}
  5031. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5032. drugSpecUnit, _ := json["min_unit"].(string)
  5033. advice.DrugSpecUnit = drugSpecUnit
  5034. }
  5035. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5036. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5037. advice.SingleDose = singleDose
  5038. }
  5039. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5040. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5041. advice.SingleDoseUnit = singleDoseUnit
  5042. }
  5043. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5044. deliveryWay, _ := json["delivery_way"].(string)
  5045. advice.DeliveryWay = deliveryWay
  5046. }
  5047. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5048. executionFrequency, _ := json["execution_frequency"].(string)
  5049. advice.ExecutionFrequency = executionFrequency
  5050. }
  5051. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5052. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5053. advice.Price = price
  5054. }
  5055. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5056. med_list_codg, _ := json["medical_insurance_number"].(string)
  5057. advice.MedListCodg = med_list_codg
  5058. }
  5059. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5060. day := int64(json["day"].(float64))
  5061. advice.Day = day
  5062. }
  5063. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5064. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5065. advice.PrescribingNumberUnit = prescribingNumberUnit
  5066. }
  5067. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5068. advice_id := int64(json["advice_id"].(float64))
  5069. advice.ID = advice_id
  5070. if advice.ID > 0 {
  5071. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5072. if err == nil {
  5073. if hisAdvice.ID > 0 {
  5074. advice.ExecutionTime = hisAdvice.ExecutionTime
  5075. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5076. advice.ExecutionState = hisAdvice.ExecutionState
  5077. advice.CheckTime = hisAdvice.CheckTime
  5078. advice.Checker = hisAdvice.Checker
  5079. advice.CheckState = hisAdvice.CheckState
  5080. advice.StartTime = hisAdvice.StartTime
  5081. advice.HospApprFlag = hisAdvice.HospApprFlag
  5082. advice.IsMedicine = hisAdvice.IsMedicine
  5083. if hisAdvice.UserOrgId == 10028 {
  5084. 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 {
  5085. advice.ExecutionTime = 0
  5086. advice.ExecutionStaff = 0
  5087. advice.ExecutionState = 2
  5088. advice.CheckTime = 0
  5089. advice.Checker = 0
  5090. advice.CheckState = 2
  5091. }
  5092. } else {
  5093. 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 {
  5094. advice.ExecutionTime = 0
  5095. advice.ExecutionStaff = 0
  5096. advice.ExecutionState = 2
  5097. advice.CheckTime = 0
  5098. advice.Checker = 0
  5099. advice.CheckState = 2
  5100. }
  5101. }
  5102. //advice.Groupno = hisAdvice.Groupno
  5103. }
  5104. }
  5105. }
  5106. }
  5107. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5108. //
  5109. //if drugStockConfig.IsOpen == 1 {
  5110. //
  5111. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5112. // if advice.ID == 0 { //医嘱不存在
  5113. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5114. // drug.Total = drug.Total - advice.PrescribingNumber
  5115. // service.UpdateBaseDrugLib(&drug)
  5116. //
  5117. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5118. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5119. // drug.Total = drug.Total - num
  5120. // service.UpdateBaseDrugLib(&drug)
  5121. // }
  5122. //
  5123. // } else if advice.ID > 0 { //医嘱存在
  5124. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5125. // var num float64
  5126. //
  5127. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5128. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5129. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5130. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5131. // drug.Total = drug.Total + num
  5132. // service.UpdateBaseDrugLib(&drug)
  5133. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5134. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5135. // drug.Total = drug.Total - num
  5136. // service.UpdateBaseDrugLib(&drug)
  5137. // }
  5138. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5139. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5140. // if num2 > advice.PrescribingNumber {
  5141. // num = num2 - advice.PrescribingNumber
  5142. // drug.Total = drug.Total + num
  5143. // service.UpdateBaseDrugLib(&drug)
  5144. // } else if num2 < advice.PrescribingNumber {
  5145. // num = advice.PrescribingNumber - num2
  5146. // drug.Total = drug.Total - num
  5147. // service.UpdateBaseDrugLib(&drug)
  5148. // }
  5149. //
  5150. // }
  5151. //
  5152. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5153. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5154. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5155. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5156. // if num1 > num2 {
  5157. // num = num1 - num2
  5158. // drug.Total = drug.Total + num
  5159. // service.UpdateBaseDrugLib(&drug)
  5160. // } else if num1 < num2 {
  5161. // num = num2 - num1
  5162. // drug.Total = drug.Total - num
  5163. // service.UpdateBaseDrugLib(&drug)
  5164. // }
  5165. //
  5166. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5167. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5168. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5169. // if hisAdvice.PrescribingNumber > num2 {
  5170. // num = hisAdvice.PrescribingNumber - num2
  5171. // drug.Total = drug.Total + num
  5172. // service.UpdateBaseDrugLib(&drug)
  5173. // } else if num2 < advice.PrescribingNumber {
  5174. // num = num2 - hisAdvice.PrescribingNumber
  5175. // drug.Total = drug.Total - num
  5176. // service.UpdateBaseDrugLib(&drug)
  5177. // }
  5178. //
  5179. // }
  5180. // }
  5181. // }
  5182. //}
  5183. //
  5184. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5185. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5186. // advice.ExecutionTime = execution_time
  5187. //}
  5188. //
  5189. //
  5190. //
  5191. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5192. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5193. // advice.ExecutionStaff = execution_staff
  5194. //}
  5195. //
  5196. //
  5197. //
  5198. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5199. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5200. // advice.ExecutionState = execution_state
  5201. //}
  5202. //
  5203. //
  5204. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5205. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5206. // advice.CheckTime = check_time
  5207. //}
  5208. //
  5209. //
  5210. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5211. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5212. // advice.CheckState = check_state
  5213. //}
  5214. //
  5215. //
  5216. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5217. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5218. // advice.Checker = checker
  5219. //}
  5220. //
  5221. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5222. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5223. // advice.StartTime = start_time
  5224. //}
  5225. return 0
  5226. }
  5227. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5228. project.ExecutionStaff = 0
  5229. project.ExecutionState = 2
  5230. project.ExecutionTime = 0
  5231. project.Checker = 0
  5232. project.CheckState = 2
  5233. project.CheckTime = 0
  5234. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5235. id := int64(json["id"].(float64))
  5236. project.ID = id
  5237. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5238. project.ExecutionStaff = temp_project.ExecutionStaff
  5239. project.ExecutionState = temp_project.ExecutionState
  5240. project.ExecutionTime = temp_project.ExecutionTime
  5241. project.Checker = temp_project.Checker
  5242. project.CheckState = temp_project.CheckState
  5243. project.CheckTime = temp_project.CheckTime
  5244. project.TeamId = temp_project.TeamId
  5245. }
  5246. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5247. types := int64(json["type"].(float64))
  5248. project.Type = types
  5249. }
  5250. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5251. project_id := int64(json["project_id"].(float64))
  5252. project.ProjectId = project_id
  5253. }
  5254. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5255. team_id := int64(json["team_id"].(float64))
  5256. project.TeamId = team_id
  5257. }
  5258. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5259. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5260. project.Price = price
  5261. }
  5262. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5263. total, _ := json["total"].(string)
  5264. //totals, _ := strconv.ParseInt(total, 10, 64)
  5265. project.Count = total
  5266. }
  5267. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5268. medical_code, _ := json["medical_code"].(string)
  5269. project.MedListCodg = medical_code
  5270. }
  5271. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5272. single_dose, _ := json["single_dose"].(string)
  5273. project.SingleDose = single_dose
  5274. }
  5275. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5276. delivery_way, _ := json["delivery_way"].(string)
  5277. project.DeliveryWay = delivery_way
  5278. }
  5279. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5280. execution_frequency, _ := json["execution_frequency"].(string)
  5281. project.ExecutionFrequency = execution_frequency
  5282. }
  5283. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5284. remark, _ := json["remark"].(string)
  5285. project.Remark = remark
  5286. }
  5287. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5288. day, _ := json["number_days"].(string)
  5289. project.Day = day
  5290. }
  5291. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5292. unit, _ := json["unit"].(string)
  5293. project.Unit = unit
  5294. }
  5295. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5296. // frequency_type := int64(json["frequency_type"].(float64))
  5297. // project.FrequencyType = frequency_type
  5298. //}
  5299. //
  5300. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5301. // day_count := int64(json["day_count"].(float64))
  5302. // project.DayCount = day_count
  5303. //}
  5304. //
  5305. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5306. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5307. // week_day, _ := json["week_day"].(string)
  5308. // project.WeekDay = week_day
  5309. //}
  5310. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5311. //
  5312. //if project.ID == 0 {
  5313. // if stockConfig.IsOpen == 1 {
  5314. // if project.Type == 3 {
  5315. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5316. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5317. // good.Total = good.Total - f_count
  5318. // service.UpdateGoodInfo(&good)
  5319. // }
  5320. // }
  5321. //
  5322. //} else {
  5323. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5324. //
  5325. // if stockConfig.IsOpen == 1 {
  5326. // if project.Type == 3 {
  5327. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5328. // if project.Count < temp_project.Count {
  5329. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5330. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5331. //
  5332. // other_count := f_count_two - f_count_one
  5333. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5334. // good.Total = good.Total + other_count_two
  5335. // service.UpdateGoodInfo(&good)
  5336. // } else if project.Count > temp_project.Count {
  5337. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5338. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5339. //
  5340. // other_count := f_count_one - f_count_two
  5341. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5342. // good.Total = good.Total - other_count_two
  5343. // service.UpdateGoodInfo(&good)
  5344. // }
  5345. //
  5346. // }
  5347. // }
  5348. //
  5349. //}
  5350. return 0
  5351. }
  5352. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5353. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5354. id := int64(json["id"].(float64))
  5355. additionalCharge.ID = id
  5356. }
  5357. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5358. item_id := int64(json["item_id"].(float64))
  5359. additionalCharge.ItemId = item_id
  5360. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5361. if config.ID > 0 {
  5362. if len(config.Code) > 0 {
  5363. additionalCharge.MedListCodg = config.Code
  5364. }
  5365. }
  5366. }
  5367. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5368. // price := int64(json["price"].(float64))
  5369. // formatInt_price := strconv.FormatInt(price, 10)
  5370. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5371. // additionalCharge.Price = float_price
  5372. // }
  5373. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5374. // price := int64(json["price"].(float64))
  5375. // formatInt_price := strconv.FormatInt(price, 10)
  5376. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5377. // additionalCharge.Price = float_price
  5378. //}
  5379. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5380. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5381. additionalCharge.Price = price
  5382. }
  5383. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5384. count, _ := json["count"].(string)
  5385. counts, _ := strconv.ParseInt(count, 10, 64)
  5386. additionalCharge.Count = counts
  5387. }
  5388. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5389. item_name, _ := json["item_name"].(string)
  5390. additionalCharge.ItemName = item_name
  5391. }
  5392. return 0
  5393. }
  5394. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5395. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5396. utils.ErrorLog("drug_name")
  5397. return enums.ErrorCodeParamWrong
  5398. }
  5399. adviceName, _ := json["drug_name"].(string)
  5400. if len(adviceName) == 0 {
  5401. utils.ErrorLog("len(advice_name) == 0")
  5402. return enums.ErrorCodeParamWrong
  5403. }
  5404. advice.AdviceName = adviceName
  5405. adviceDesc, _ := json["advice_desc"].(string)
  5406. advice.AdviceDesc = adviceDesc
  5407. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5408. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5409. advice.DrugSpec = drugSpec
  5410. }
  5411. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5412. remark, _ := json["remark"].(string)
  5413. advice.Remark = remark
  5414. }
  5415. if json["id"] == nil {
  5416. advice.DrugId = 0
  5417. } else {
  5418. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5419. drug_id := int64(json["id"].(float64))
  5420. advice.DrugId = drug_id
  5421. }
  5422. }
  5423. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5424. groupno := int64(json["groupno"].(float64))
  5425. advice.Groupno = groupno
  5426. }
  5427. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5428. drugSpecUnit, _ := json["min_unit"].(string)
  5429. advice.DrugSpecUnit = drugSpecUnit
  5430. }
  5431. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5432. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5433. advice.SingleDose = singleDose
  5434. }
  5435. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5436. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5437. advice.SingleDoseUnit = singleDoseUnit
  5438. }
  5439. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5440. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5441. advice.PrescribingNumber = prescribingNumber
  5442. }
  5443. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5444. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5445. advice.PrescribingNumberUnit = prescribingNumberUnit
  5446. }
  5447. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5448. deliveryWay, _ := json["delivery_way"].(string)
  5449. advice.DeliveryWay = deliveryWay
  5450. }
  5451. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5452. executionFrequency, _ := json["execution_frequency"].(string)
  5453. advice.ExecutionFrequency = executionFrequency
  5454. }
  5455. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5456. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5457. advice.Price = price
  5458. }
  5459. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5460. med_list_codg, _ := json["medical_insurance_number"].(string)
  5461. advice.MedListCodg = med_list_codg
  5462. }
  5463. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5464. day := int64(json["day"].(float64))
  5465. advice.Day = day
  5466. }
  5467. advice.FrequencyType = 1
  5468. return 0
  5469. }
  5470. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5471. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5472. types := int64(json["type"].(float64))
  5473. project.Type = types
  5474. }
  5475. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5476. project_id := int64(json["project_id"].(float64))
  5477. project.ProjectId = project_id
  5478. }
  5479. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5480. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5481. project.Price = price
  5482. }
  5483. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5484. total, _ := json["total"].(string)
  5485. //totals, _ := strconv.ParseInt(total, 10, 64)
  5486. project.Count = total
  5487. }
  5488. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5489. medical_code, _ := json["medical_code"].(string)
  5490. project.MedListCodg = medical_code
  5491. }
  5492. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5493. single_dose, _ := json["single_dose"].(string)
  5494. project.SingleDose = single_dose
  5495. }
  5496. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5497. delivery_way, _ := json["delivery_way"].(string)
  5498. project.DeliveryWay = delivery_way
  5499. }
  5500. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5501. execution_frequency, _ := json["execution_frequency"].(string)
  5502. project.ExecutionFrequency = execution_frequency
  5503. }
  5504. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5505. remark, _ := json["remark"].(string)
  5506. project.Remark = remark
  5507. }
  5508. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5509. day, _ := json["number_days"].(string)
  5510. project.Day = day
  5511. }
  5512. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5513. unit, _ := json["unit"].(string)
  5514. project.Unit = unit
  5515. }
  5516. project.FrequencyType = 1
  5517. return 0
  5518. }
  5519. func (c *HisApiController) GetHisOrderList() {
  5520. page, _ := c.GetInt64("page", -1)
  5521. limit, _ := c.GetInt64("limit", -1)
  5522. start_time := c.GetString("start_time")
  5523. end_time := c.GetString("end_time")
  5524. types, _ := c.GetInt64("type", 0)
  5525. keywords := c.GetString("keywords")
  5526. p_type, _ := c.GetInt64("p_type", 0)
  5527. sort_type, _ := c.GetInt64("sort_type", 0)
  5528. charge_type, _ := c.GetInt64("charge_type", 0)
  5529. sch_type, _ := c.GetInt64("sch_type", 0)
  5530. zone_type, _ := c.GetInt64("zone_type", 0)
  5531. med_type, _ := c.GetInt64("med_type", 0)
  5532. timeLayout := "2006-01-02"
  5533. loc, _ := time.LoadLocation("Local")
  5534. var startTime int64
  5535. if len(start_time) > 0 {
  5536. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5537. if err != nil {
  5538. //fmt.Println(err)
  5539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5540. return
  5541. }
  5542. startTime = theTime.Unix()
  5543. }
  5544. var endTime int64
  5545. if len(end_time) > 0 {
  5546. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5547. if err != nil {
  5548. utils.ErrorLog(err.Error())
  5549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5550. return
  5551. }
  5552. endTime = theTime.Unix()
  5553. }
  5554. adminUser := c.GetAdminUserInfo()
  5555. org_id := adminUser.CurrentOrgId
  5556. 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)
  5557. for _, item := range order {
  5558. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5559. item.DoctorName = info.Doctor
  5560. item.DepartmentName = info.XtHisDepartment.Name
  5561. }
  5562. if err == nil {
  5563. c.ServeSuccessJSON(map[string]interface{}{
  5564. "order": order,
  5565. "total": total,
  5566. })
  5567. } else {
  5568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5569. return
  5570. }
  5571. }
  5572. func (c *HisApiController) GetHisOrder() {
  5573. patient_id, _ := c.GetInt64("patient_id", 0)
  5574. number := c.GetString("number")
  5575. adminInfo := c.GetAdminUserInfo()
  5576. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5577. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5578. if err == nil {
  5579. c.ServeSuccessJSON(map[string]interface{}{
  5580. "order": order,
  5581. "prescription": prescriptions,
  5582. })
  5583. } else {
  5584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5585. return
  5586. }
  5587. }
  5588. func (c *HisApiController) GetHisPrescriptionList() {
  5589. record_date := c.GetString("record_date")
  5590. keywords := c.GetString("keywords")
  5591. page, _ := c.GetInt64("page")
  5592. limit, _ := c.GetInt64("limit")
  5593. sch_type, _ := c.GetInt64("sch_type")
  5594. timeLayout := "2006-01-02"
  5595. loc, _ := time.LoadLocation("Local")
  5596. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5597. if err != nil {
  5598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5599. return
  5600. }
  5601. recordDateTime := theTime.Unix()
  5602. adminInfo := c.GetAdminUserInfo()
  5603. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5604. //adminInfo := c.GetAdminUserInfo()
  5605. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5606. //fmt.Println(prescriptionOrder)
  5607. if err == nil {
  5608. c.ServeSuccessJSON(map[string]interface{}{
  5609. "order": prescriptionOrder,
  5610. "total": total,
  5611. })
  5612. } else {
  5613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5614. return
  5615. }
  5616. }
  5617. func (c *HisApiController) GetHisPrescriptionInfo() {
  5618. id, _ := c.GetInt64("id")
  5619. adminInfo := c.GetAdminUserInfo()
  5620. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5621. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5622. if err == nil {
  5623. c.ServeSuccessJSON(map[string]interface{}{
  5624. "order": prescriptionOrder,
  5625. "prescription": prescription,
  5626. })
  5627. } else {
  5628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5629. return
  5630. }
  5631. }
  5632. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5633. adminUser := c.GetAdminUserInfo()
  5634. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5635. c.ServeSuccessJSON(map[string]interface{}{
  5636. "config": config,
  5637. })
  5638. }
  5639. type ResultTwo struct {
  5640. ErrMsg interface{} `json:"err_msg"`
  5641. InfRefmsgid string `json:"inf_refmsgid"`
  5642. Infcode int64 `json:"infcode"`
  5643. Output struct {
  5644. Baseinfo struct {
  5645. Age float64 `json:"age"`
  5646. Brdy string `json:"brdy"`
  5647. Certno string `json:"certno"`
  5648. Gend string `json:"gend"`
  5649. Naty string `json:"naty"`
  5650. PsnCertType string `json:"psn_cert_type"`
  5651. PsnName string `json:"psn_name"`
  5652. PsnNo string `json:"psn_no"`
  5653. } `json:"baseinfo"`
  5654. Idetinfo []interface{} `json:"idetinfo"`
  5655. Iinfo []struct {
  5656. Balc float64 `json:"balc"`
  5657. CvlservFlag string `json:"cvlserv_flag"`
  5658. EmpName string `json:"emp_name"`
  5659. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5660. Insutype string `json:"insutype"`
  5661. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5662. PausInsuDate interface{} `json:"paus_insu_date"`
  5663. PsnInsuDate string `json:"psn_insu_date"`
  5664. PsnInsuStas string `json:"psn_insu_stas"`
  5665. PsnType string `json:"psn_type"`
  5666. } `json:"insuinfo"`
  5667. } `json:"output"`
  5668. RefmsgTime string `json:"refmsg_time"`
  5669. RespondTime string `json:"respond_time"`
  5670. Signtype interface{} `json:"signtype"`
  5671. WarnInfo interface{} `json:"warn_info"`
  5672. }
  5673. type ResultThree struct {
  5674. Cainfo interface{} `json:"cainfo"`
  5675. ErrMsg interface{} `json:"err_msg"`
  5676. InfRefmsgid string `json:"inf_refmsgid"`
  5677. Infcode int64 `json:"infcode"`
  5678. Output struct {
  5679. Data struct {
  5680. IptOtpNo string `json:"ipt_otp_no"`
  5681. MdtrtID string `json:"mdtrt_id"`
  5682. PsnNo string `json:"psn_no"`
  5683. } `json:"data"`
  5684. } `json:"output"`
  5685. RefmsgTime string `json:"refmsg_time"`
  5686. RespondTime string `json:"respond_time"`
  5687. Signtype interface{} `json:"signtype"`
  5688. WarnMsg interface{} `json:"warn_msg"`
  5689. }
  5690. type ResultFour struct {
  5691. Cainfo string `json:"cainfo"`
  5692. ErrMsg string `json:"err_msg"`
  5693. InfRefmsgid string `json:"inf_refmsgid"`
  5694. Infcode int64 `json:"infcode"`
  5695. Output struct {
  5696. Result []struct {
  5697. BasMednFlag string `json:"bas_medn_flag"`
  5698. ChldMedcFlag string `json:"chld_medc_flag"`
  5699. ChrgitmLv string `json:"chrgitm_lv"`
  5700. Cnt float64 `json:"cnt"`
  5701. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5702. DrtReimFlag string `json:"drt_reim_flag"`
  5703. FeedetlSn string `json:"feedetl_sn"`
  5704. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5705. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5706. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5707. ListSpItemFlag string `json:"list_sp_item_flag"`
  5708. LmtUsedFlag string `json:"lmt_used_flag"`
  5709. MedChrgitmType string `json:"med_chrgitm_type"`
  5710. Memo string `json:"memo"`
  5711. OverlmtAmt float64 `json:"overlmt_amt"`
  5712. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5713. Pric float64 `json:"pric"`
  5714. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5715. SelfpayProp float64 `json:"selfpay_prop"`
  5716. } `json:"result"`
  5717. } `json:"output"`
  5718. RefmsgTime string `json:"refmsg_time"`
  5719. RespondTime string `json:"respond_time"`
  5720. Signtype string `json:"signtype"`
  5721. WarnMsg string `json:"warn_msg"`
  5722. }
  5723. type ResultFive struct {
  5724. Insutype string `json:"insutype"`
  5725. }
  5726. type ResultSix struct {
  5727. Cainfo interface{} `json:"cainfo"`
  5728. ErrMsg interface{} `json:"err_msg"`
  5729. InfRefmsgid string `json:"inf_refmsgid"`
  5730. Infcode int64 `json:"infcode"`
  5731. Output struct {
  5732. } `json:"output"`
  5733. RefmsgTime string `json:"refmsg_time"`
  5734. RespondTime string `json:"respond_time"`
  5735. Signtype interface{} `json:"signtype"`
  5736. WarnMsg interface{} `json:"warn_msg"`
  5737. }
  5738. type ResultSeven struct {
  5739. Cainfo string `json:"cainfo"`
  5740. ErrMsg string `json:"err_msg"`
  5741. InfRefmsgid string `json:"inf_refmsgid"`
  5742. Infcode int64 `json:"infcode"`
  5743. Output struct {
  5744. Setldetail []interface{} `json:"setldetail"`
  5745. Setlinfo struct {
  5746. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5747. AcctPay float64 `json:"acct_pay"`
  5748. ActPayDedc float64 `json:"act_pay_dedc"`
  5749. Age float64 `json:"age"`
  5750. Balc float64 `json:"balc"`
  5751. Brdy string `json:"brdy"`
  5752. Certno string `json:"certno"`
  5753. ClrOptins string `json:"clr_optins"`
  5754. ClrType string `json:"clr_type"`
  5755. ClrWay string `json:"clr_way"`
  5756. CvlservFlag string `json:"cvlserv_flag"`
  5757. CvlservPay float64 `json:"cvlserv_pay"`
  5758. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5759. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5760. Gend string `json:"gend"`
  5761. HifesPay float64 `json:"hifes_pay"`
  5762. HifmiPay float64 `json:"hifmi_pay"`
  5763. HifobPay float64 `json:"hifob_pay"`
  5764. HifpPay float64 `json:"hifp_pay"`
  5765. HospPartAmt float64 `json:"hosp_part_amt"`
  5766. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5767. Insutype string `json:"insutype"`
  5768. MafPay float64 `json:"maf_pay"`
  5769. MdtrtCertType string `json:"mdtrt_cert_type"`
  5770. MdtrtID string `json:"mdtrt_id"`
  5771. MedType string `json:"med_type"`
  5772. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5773. MedinsSetlID string `json:"medins_setl_id"`
  5774. Naty string `json:"naty"`
  5775. OthPay float64 `json:"oth_pay"`
  5776. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5777. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5778. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5779. PsnCashPay float64 `json:"psn_cash_pay"`
  5780. PsnCertType string `json:"psn_cert_type"`
  5781. PsnName string `json:"psn_name"`
  5782. PsnNo string `json:"psn_no"`
  5783. PsnPartAmt float64 `json:"psn_part_amt"`
  5784. PsnType string `json:"psn_type"`
  5785. SetlID string `json:"setl_id"`
  5786. SetlTime string `json:"setl_time"`
  5787. } `json:"setlinfo"`
  5788. } `json:"output"`
  5789. RefmsgTime string `json:"refmsg_time"`
  5790. RespondTime string `json:"respond_time"`
  5791. Signtype interface{} `json:"signtype"`
  5792. WarnMsg interface{} `json:"warn_msg"`
  5793. }
  5794. type ResultEight struct {
  5795. Cainfo string `json:"cainfo"`
  5796. ErrMsg string `json:"err_msg"`
  5797. InfRefmsgid string `json:"inf_refmsgid"`
  5798. Infcode int64 `json:"infcode"`
  5799. Output struct {
  5800. Stmtinfo struct {
  5801. SetlOptins string `json:"setl_optins"`
  5802. StmtRslt string `json:"stmt_rslt"`
  5803. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5804. } `json:"stmtinfo"`
  5805. } `json:"output"`
  5806. RefmsgTime string `json:"refmsg_time"`
  5807. RespondTime string `json:"respond_time"`
  5808. Signtype interface{} `json:"signtype"`
  5809. WarnMsg interface{} `json:"warn_msg"`
  5810. }
  5811. type ResultNine struct {
  5812. Cainfo string `json:"cainfo"`
  5813. ErrMsg string `json:"err_msg"`
  5814. InfRefmsgid string `json:"inf_refmsgid"`
  5815. Infcode int64 `json:"infcode"`
  5816. Output struct {
  5817. FileQuryNo string `json:"file_qury_no"`
  5818. } `json:"output"`
  5819. RefmsgTime string `json:"refmsg_time"`
  5820. RespondTime string `json:"respond_time"`
  5821. Signtype interface{} `json:"signtype"`
  5822. WarnMsg interface{} `json:"warn_msg"`
  5823. }
  5824. type ResultTen struct {
  5825. Cainfo string `json:"cainfo"`
  5826. ErrMsg string `json:"err_msg"`
  5827. InfRefmsgid string `json:"inf_refmsgid"`
  5828. Infcode int64 `json:"infcode"`
  5829. Output struct {
  5830. DldEndtime string `json:"dld_endtime"`
  5831. FileQuryNo string `json:"file_qury_no"`
  5832. Filename string `json:"filename"`
  5833. } `json:"output"`
  5834. RefmsgTime string `json:"refmsg_time"`
  5835. RespondTime string `json:"respond_time"`
  5836. Signtype interface{} `json:"signtype"`
  5837. WarnMsg interface{} `json:"warn_msg"`
  5838. }
  5839. type ResultEleven struct {
  5840. Cainfo string `json:"cainfo"`
  5841. ErrMsg string `json:"err_msg"`
  5842. InfRefmsgid string `json:"inf_refmsgid"`
  5843. Infcode int64 `json:"infcode"`
  5844. Output struct {
  5845. Setlinfo struct {
  5846. FixmedinsName string `json:"fixmedins_name"`
  5847. FixmedinsCode string `json:"fixmedins_code"`
  5848. PsnNo string `json:"psn_no"`
  5849. PsnName string `json:"psn_name"`
  5850. HifobPay float64 `json:"hifob_pay"`
  5851. Gend string `json:"gend"`
  5852. Brdy string `json:"brdy"`
  5853. PsnCertType string `json:"psn_cert_type"`
  5854. PsnType string `json:"psn_type"`
  5855. EmpName string `json:"emp_name"`
  5856. Certno string `json:"certno"`
  5857. Insutype string `json:"insutype"`
  5858. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5859. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5860. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5861. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5862. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5863. ActPayDedc float64 `json:"act_pay_dedc"`
  5864. HifpPay float64 `json:"hifp_pay"`
  5865. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5866. CvlservPay float64 `json:"cvlserv_pay"`
  5867. HifesPay float64 `json:"hifes_pay"`
  5868. HifmiPay float64 `json:"hifmi_pay"`
  5869. MafPay float64 `json:"maf_pay"`
  5870. OthPay float64 `json:"oth_pay"`
  5871. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5872. PsnPay float64 `json:"psn_pay"`
  5873. AcctPay float64 `json:"acct_pay"`
  5874. CashPayamt float64 `json:"cash_payamt"`
  5875. Balc float64 `json:"balc"`
  5876. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5877. MedinsSetlId string `json:"medins_setl_id"`
  5878. RefdSetlFlag string `json:"refd_setl_flag"`
  5879. SetlTime string `json:"setl_time"`
  5880. MedType string `json:"med_type"`
  5881. } `json:"setlinfo"`
  5882. } `json:"output"`
  5883. RefmsgTime string `json:"refmsg_time"`
  5884. RespondTime string `json:"respond_time"`
  5885. Signtype interface{} `json:"signtype"`
  5886. WarnMsg interface{} `json:"warn_msg"`
  5887. }
  5888. type Custom struct {
  5889. DetItemFeeSumamt string
  5890. Cut string
  5891. FeedetlSn string
  5892. Price string
  5893. MedListCodg string
  5894. Type int64
  5895. AdviceId int64
  5896. ProjectId int64
  5897. ItemId int64
  5898. }
  5899. // 获取个人信息----挂号-----上传就诊信息
  5900. func (c *HisApiController) GetRegisterInfo() {
  5901. id, _ := c.GetInt64("id")
  5902. record_time := c.GetString("record_time")
  5903. settlementValue, _ := c.GetInt64("settlement_value")
  5904. medical_insurance_card := c.GetString("medical_insurance_card")
  5905. name := c.GetString("name")
  5906. id_card_type, _ := c.GetInt64("id_card_type")
  5907. certificates, _ := c.GetInt64("certificates")
  5908. medical_care, _ := c.GetInt64("medical_care")
  5909. birthday := c.GetString("birthday")
  5910. age, _ := c.GetInt64("age")
  5911. id_card := c.GetString("id_card")
  5912. register_type, _ := c.GetInt64("register")
  5913. doctor, _ := c.GetInt64("doctor")
  5914. department, _ := c.GetInt64("department")
  5915. gender, _ := c.GetInt64("sex")
  5916. phone := c.GetString("phone")
  5917. registration_fee, _ := c.GetFloat("registration_fee")
  5918. medical_expenses, _ := c.GetFloat("medical_expenses")
  5919. social_type, _ := c.GetInt64("social_type")
  5920. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5921. diagnosis_ids := c.GetString("diagnosis")
  5922. sick_type, _ := c.GetInt64("sick_type")
  5923. reg_type := c.GetString("p_type")
  5924. timeLayout := "2006-01-02"
  5925. loc, _ := time.LoadLocation("Local")
  5926. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5927. birthUnix := birthdays.Unix()
  5928. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5929. if err != nil {
  5930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5931. return
  5932. }
  5933. recordDateTime := theTime.Unix()
  5934. adminInfo := c.GetAdminUserInfo()
  5935. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5936. if tempPatient.ID == 0 {
  5937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5938. return
  5939. }
  5940. var patient service.Patients
  5941. if id == 0 {
  5942. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5943. } else {
  5944. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5945. }
  5946. if patient.ID == 0 {
  5947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5948. return
  5949. }
  5950. if len(patient.IdCardNo) == 0 {
  5951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5952. return
  5953. }
  5954. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5955. if len(his) >= 1 {
  5956. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5957. if len(his) >= 1 && order.ID == 0 {
  5958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5959. return
  5960. }
  5961. }
  5962. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5963. fmt.Println(timeStr)
  5964. timeArr := strings.Split(timeStr, " ")
  5965. fmt.Println(timeArr)
  5966. timeArrTwo := strings.Split(timeArr[0], "-")
  5967. timeArrThree := strings.Split(timeArr[1], ":")
  5968. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5969. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5970. if len(lists) == 0 {
  5971. var hisPatient models.XtHisPatient
  5972. hisPatient = models.XtHisPatient{
  5973. Name: name,
  5974. Age: age,
  5975. Gender: gender,
  5976. Birthday: birthUnix,
  5977. Phone: phone,
  5978. MedicalTreatmentType: medical_care,
  5979. IdType: certificates,
  5980. IdCardNo: id_card,
  5981. BalanceAccountsType: settlementValue,
  5982. SocialType: social_type,
  5983. MedicalInsuranceNumber: medical_insurance_card,
  5984. RegisterType: register_type,
  5985. RegisterCost: registration_fee,
  5986. TreatmentCost: medical_expenses,
  5987. AdminUserId: adminInfo.AdminUser.Id,
  5988. UserOrgId: adminInfo.CurrentOrgId,
  5989. Status: 1,
  5990. RecordDate: recordDateTime,
  5991. IsReturn: 1,
  5992. PatientId: patient.ID,
  5993. Ctime: time.Now().Unix(),
  5994. Mtime: time.Now().Unix(),
  5995. Number: str,
  5996. IdCardType: id_card_type,
  5997. Departments: department,
  5998. Doctor: doctor,
  5999. PType: reg_type,
  6000. Diagnosis: diagnosis_ids,
  6001. SickType: sick_type,
  6002. }
  6003. service.CreateHisPatient(&hisPatient)
  6004. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6005. c.ServeSuccessJSON(map[string]interface{}{
  6006. "his_info": hisPatient,
  6007. })
  6008. } else {
  6009. //chrgBchno := rand.Intn(1000000) + 10000
  6010. var hisPatient models.XtHisPatient
  6011. hisPatient = models.XtHisPatient{
  6012. Name: name,
  6013. Age: age,
  6014. Gender: gender,
  6015. Birthday: birthUnix,
  6016. Phone: phone,
  6017. MedicalTreatmentType: medical_care,
  6018. IdType: certificates,
  6019. IdCardNo: id_card,
  6020. BalanceAccountsType: settlementValue,
  6021. SocialType: social_type,
  6022. MedicalInsuranceNumber: medical_insurance_card,
  6023. RegisterType: register_type,
  6024. RegisterCost: registration_fee,
  6025. TreatmentCost: medical_expenses,
  6026. AdminUserId: adminInfo.AdminUser.Id,
  6027. UserOrgId: adminInfo.CurrentOrgId,
  6028. Status: 1,
  6029. RecordDate: recordDateTime,
  6030. IsReturn: 1,
  6031. PatientId: patient.ID,
  6032. Ctime: time.Now().Unix(),
  6033. Mtime: time.Now().Unix(),
  6034. Number: str,
  6035. IdCardType: id_card_type,
  6036. Departments: department,
  6037. Doctor: doctor,
  6038. PType: reg_type,
  6039. Diagnosis: diagnosis_ids,
  6040. SickType: sick_type,
  6041. }
  6042. service.CreateHisPatient(&hisPatient)
  6043. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6044. c.ServeSuccessJSON(map[string]interface{}{
  6045. "his_info": hisPatient,
  6046. })
  6047. }
  6048. }
  6049. // 上传明细----结算
  6050. func (c *HisApiController) GetUploadInfo() {
  6051. id, _ := c.GetInt64("id")
  6052. record_time := c.GetString("record_time")
  6053. his_patient_id, _ := c.GetInt64("his_patient_id")
  6054. oth_desc := c.GetString("oth_desc")
  6055. pay_way, _ := c.GetInt64("pay_way")
  6056. pay_ways := c.GetString("pay_ways")
  6057. pay_price, _ := c.GetFloat("pay_price")
  6058. pay_card_no := c.GetString("pay_card_no")
  6059. discount_price, _ := c.GetFloat("discount_price")
  6060. preferential_price, _ := c.GetFloat("preferential_price")
  6061. reality_price, _ := c.GetFloat("reality_price")
  6062. found_price, _ := c.GetFloat("found_price")
  6063. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6064. private_price, _ := c.GetFloat("private_price")
  6065. timeLayout := "2006-01-02"
  6066. loc, _ := time.LoadLocation("Local")
  6067. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6068. fapiao_code := c.GetString("fapiao_code")
  6069. fapiao_number := c.GetString("fapiao_number")
  6070. diagnosis_id := c.GetString("diagnosis")
  6071. sick_type, _ := c.GetInt64("sick_type")
  6072. reg_type, _ := c.GetInt64("p_type")
  6073. order_id, _ := c.GetInt64("order_id")
  6074. cash_pay := c.GetString("cash_pay")
  6075. wechat_pay := c.GetString("wechat_pay")
  6076. ali_pay := c.GetString("ali_pay")
  6077. jifen_pay := c.GetString("jifen_pay")
  6078. band_card_pay := c.GetString("band_card_pay")
  6079. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6080. tmp_decimal := c.GetString("tmp_decimal")
  6081. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6082. var decimal float64 //本次使用的押金
  6083. var errmsg error
  6084. tx := service.XTWriteDB().Begin() //开了事务
  6085. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6086. defer func() {
  6087. if errmsg != nil {
  6088. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6089. tx.Rollback()
  6090. } else {
  6091. tx.Commit()
  6092. }
  6093. }()
  6094. fmt.Println("dec_way", dec_way)
  6095. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6096. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6097. return
  6098. }
  6099. if len(tmp_decimal) > 0 {
  6100. if tmp_decimal[0] == 45 {
  6101. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6102. return
  6103. }
  6104. }
  6105. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6106. fmt.Println(errs)
  6107. decimal = tt
  6108. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6109. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6110. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6111. if err != nil {
  6112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6113. return
  6114. }
  6115. recordDateTime := theTime.Unix()
  6116. adminUser := c.GetAdminUserInfo()
  6117. var prescriptions []*models.HisPrescription
  6118. var prescriptionsOne []*models.HisPrescription
  6119. var start_time int64
  6120. var end_time int64
  6121. ids_str := c.GetString("ids")
  6122. ids_arr := strings.Split(ids_str, ",")
  6123. if tempOrder.ID == 0 {
  6124. if settle_accounts_type == 1 { //日结
  6125. fmt.Println(reg_type)
  6126. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6127. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6128. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6129. } else {
  6130. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6131. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6132. }
  6133. } else { //月结
  6134. start_time_str := c.GetString("start_time")
  6135. end_time_str := c.GetString("end_time")
  6136. timeLayout := "2006-01-02"
  6137. loc, _ := time.LoadLocation("Local")
  6138. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6139. if err != nil {
  6140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6141. return
  6142. }
  6143. recordStartTime := theStartTime.Unix()
  6144. start_time = recordStartTime
  6145. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6146. if err != nil {
  6147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6148. return
  6149. }
  6150. recordEndTime := theEndTime.Unix()
  6151. end_time = recordEndTime
  6152. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6153. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6154. }
  6155. var goods []*models.DialysisBeforePrepareGoods
  6156. var newGoods []*models.NewDialysisBeforePrepareGoods
  6157. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6158. var infos []*models.HisDoctorAdviceInfo
  6159. var infoList []*models.HisDoctorAdviceInfo
  6160. var hisAdvice []*models.HisDoctorAdviceInfo
  6161. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6162. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6163. //判断库存不足
  6164. //结算出库开关
  6165. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6166. if settConfig.IsOpen == 1 {
  6167. //判断库存的地方
  6168. for _, info := range prescriptions {
  6169. if info.Type == 1 {
  6170. infos = append(infos, info.HisDoctorAdviceInfo...)
  6171. }
  6172. if info.Type == 2 {
  6173. for _, sumItem := range info.HisPrescriptionProject {
  6174. if sumItem.Type == 3 {
  6175. var good models.DialysisBeforePrepareGoods
  6176. var newGood models.NewDialysisBeforePrepareGoods
  6177. good.GoodId = sumItem.GoodInfo.ID
  6178. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6179. count, _ := strconv.Atoi(sumItem.Count)
  6180. good.Count = int64(count)
  6181. good.StorehouseId = houseConfig.StorehouseOutInfo
  6182. good.ProjectId = sumItem.ID
  6183. goods = append(goods, &good)
  6184. newGood.GoodId = sumItem.GoodInfo.ID
  6185. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6186. count2, _ := strconv.Atoi(sumItem.Count)
  6187. newGood.Count = int64(count2)
  6188. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6189. newGood.ProjectId = sumItem.ID
  6190. newGoods = append(newGoods, &newGood)
  6191. }
  6192. }
  6193. }
  6194. }
  6195. for _, info := range prescriptionsOne {
  6196. if info.Type == 1 {
  6197. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6198. }
  6199. if info.Type == 2 {
  6200. for _, sumItem := range info.HisPrescriptionProject {
  6201. if sumItem.Type == 3 {
  6202. var newGood models.NewDialysisBeforePrepareGoods
  6203. newGood.GoodId = sumItem.GoodInfo.ID
  6204. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6205. count2, _ := strconv.Atoi(sumItem.Count)
  6206. newGood.Count = int64(count2)
  6207. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6208. newGood.ProjectId = sumItem.ID
  6209. newGoodOne = append(newGoodOne, &newGood)
  6210. }
  6211. }
  6212. }
  6213. }
  6214. //判断
  6215. for _, itemOne := range infos {
  6216. for _, itemTwo := range hisAdvice {
  6217. if itemOne.DrugId == itemTwo.DrugId {
  6218. itemTwo.Child = append(itemTwo.Child, itemOne)
  6219. }
  6220. }
  6221. }
  6222. for _, itemTwo := range hisAdvice {
  6223. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6224. var sum_out_count int64
  6225. for _, itemThree := range itemTwo.Child {
  6226. var prescribing_number int64
  6227. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6228. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6229. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6230. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6231. }
  6232. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6233. prescribing_number = parseIntPrescribingNumber
  6234. }
  6235. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6236. prescribing_number = parseIntPrescribingNumber
  6237. }
  6238. sum_out_count += prescribing_number
  6239. }
  6240. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6241. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6242. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6243. if sum_out_count > drugStockOut.FlushCount {
  6244. c.ServeSuccessJSON(map[string]interface{}{
  6245. "msg": "2",
  6246. "drug": medical,
  6247. })
  6248. return
  6249. }
  6250. }
  6251. fmt.Println("newGoods99999988882os", newGoods)
  6252. for _, itemOne := range newGoods {
  6253. for _, item := range newGoodOne {
  6254. if itemOne.GoodId == item.GoodId {
  6255. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6256. }
  6257. }
  6258. }
  6259. for _, item := range newGoodOne {
  6260. var sum_out_count_one int64
  6261. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6262. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6263. sum_out_count_one += itemOne.Count
  6264. }
  6265. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6266. fmt.Println("sum_out_count_one", sum_out_count_one)
  6267. fmt.Println("list.FlushCount", list.FlushCount)
  6268. if sum_out_count_one > list.FlushCount {
  6269. c.ServeSuccessJSON(map[string]interface{}{
  6270. "msg": "3",
  6271. "good": good,
  6272. })
  6273. return
  6274. }
  6275. }
  6276. }
  6277. timestamp := time.Now().Unix()
  6278. tempTime := time.Unix(timestamp, 0)
  6279. timeFormat := tempTime.Format("20060102150405")
  6280. chrgBchno := rand.Intn(100000) + 10000
  6281. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6282. strconv.FormatInt(his.PatientId, 10)
  6283. var ids []int64
  6284. for _, item := range prescriptions {
  6285. ids = append(ids, item.ID)
  6286. }
  6287. var total float64
  6288. for _, item := range prescriptions {
  6289. fmt.Println(item)
  6290. if item.Type == 1 { //药品
  6291. for _, subItem := range item.HisDoctorAdviceInfo {
  6292. total = total + (subItem.Price * subItem.PrescribingNumber)
  6293. }
  6294. }
  6295. if item.Type == 2 { //项目
  6296. for _, subItem := range item.HisPrescriptionProject {
  6297. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6298. total = total + (subItem.Price * cnt)
  6299. }
  6300. }
  6301. for _, subItem := range item.HisAdditionalCharge {
  6302. total = total + (subItem.Price * float64(subItem.Count))
  6303. }
  6304. }
  6305. if reg_type == 1111 || reg_type == 1112 {
  6306. reg_type = 11
  6307. }
  6308. tm := time.Unix(time.Now().Unix(), 0)
  6309. allTotal := fmt.Sprintf("%.4f", total)
  6310. totals, _ := strconv.ParseFloat(allTotal, 64)
  6311. order := &models.HisOrder{
  6312. UserOrgId: adminUser.CurrentOrgId,
  6313. HisPatientId: his.ID,
  6314. PatientId: id,
  6315. SettleAccountsDate: recordDateTime,
  6316. Ctime: time.Now().Unix(),
  6317. Mtime: time.Now().Unix(),
  6318. Status: 1,
  6319. OrderStatus: 2,
  6320. MdtrtId: his.Number,
  6321. Number: chrg_bchno,
  6322. MedfeeSumamt: totals,
  6323. PayWay: pay_way,
  6324. PayWays: pay_ways,
  6325. PayPrice: pay_price,
  6326. MedType: strconv.Itoa(int(reg_type)),
  6327. PayCardNo: pay_card_no,
  6328. DiscountPrice: discount_price,
  6329. PreferentialPrice: preferential_price,
  6330. RealityPrice: reality_price,
  6331. FoundPrice: found_price,
  6332. MedicalInsurancePrice: medical_insurance_price,
  6333. PrivatePrice: private_price,
  6334. SettleEndTime: end_time,
  6335. SettleStartTime: start_time,
  6336. PsnPartAmt: totals,
  6337. PsnCashPay: totals,
  6338. SettleType: settle_accounts_type,
  6339. FaPiaoCode: fapiao_code,
  6340. FaPiaoNumber: fapiao_number,
  6341. Diagnosis: diagnosis_id,
  6342. PType: 2,
  6343. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6344. Decimal: decimal,
  6345. OthDesc: oth_desc,
  6346. CashPay: cash_pay,
  6347. WechatPay: wechat_pay,
  6348. AliPay: ali_pay,
  6349. JifenPay: jifen_pay,
  6350. BandCardPay: band_card_pay,
  6351. }
  6352. err = service.CreateOrderTX(order, tx)
  6353. if err != nil {
  6354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6355. return
  6356. }
  6357. var customs []*Custom
  6358. for _, item := range prescriptions {
  6359. if item.Type == 1 { //药品a
  6360. for _, subItem := range item.HisDoctorAdviceInfo {
  6361. cus := &Custom{
  6362. AdviceId: subItem.ID,
  6363. ProjectId: 0,
  6364. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6365. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6366. FeedetlSn: subItem.FeedetlSn,
  6367. Price: fmt.Sprintf("%.4f", subItem.Price),
  6368. MedListCodg: subItem.MedListCodg,
  6369. Type: 1,
  6370. }
  6371. customs = append(customs, cus)
  6372. }
  6373. }
  6374. if item.Type == 2 { //项目
  6375. for _, subItem := range item.HisPrescriptionProject {
  6376. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6377. cus := &Custom{
  6378. AdviceId: 0,
  6379. ProjectId: subItem.ID,
  6380. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6381. Cut: fmt.Sprintf("%.4f", cnt),
  6382. FeedetlSn: subItem.FeedetlSn,
  6383. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6384. MedListCodg: subItem.MedListCodg,
  6385. Type: 2,
  6386. }
  6387. customs = append(customs, cus)
  6388. }
  6389. }
  6390. for _, item := range item.HisAdditionalCharge {
  6391. cus := &Custom{
  6392. ItemId: item.ID,
  6393. AdviceId: 0,
  6394. ProjectId: 0,
  6395. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6396. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6397. FeedetlSn: item.FeedetlSn,
  6398. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6399. MedListCodg: item.XtHisAddtionConfig.Code,
  6400. Type: 3,
  6401. }
  6402. customs = append(customs, cus)
  6403. }
  6404. }
  6405. for _, item := range customs {
  6406. var advice_id int64 = 0
  6407. var project_id int64 = 0
  6408. var item_id int64 = 0
  6409. var types int64 = 0
  6410. if item.Type == 1 {
  6411. advice_id = item.AdviceId
  6412. project_id = 0
  6413. item_id = 0
  6414. } else if item.Type == 2 {
  6415. advice_id = 0
  6416. item_id = 0
  6417. project_id = item.ProjectId
  6418. } else if item.Type == 3 {
  6419. advice_id = 0
  6420. item_id = item.ItemId
  6421. project_id = 0
  6422. }
  6423. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6424. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6425. pric, _ := strconv.ParseFloat(item.Price, 32)
  6426. info := &models.HisOrderInfo{
  6427. OrderNumber: order.Number,
  6428. UploadDate: time.Now().Unix(),
  6429. AdviceId: advice_id,
  6430. DetItemFeeSumamt: detItemFeeSumamt,
  6431. Cnt: cut,
  6432. Pric: pric,
  6433. PatientId: id,
  6434. Status: 1,
  6435. Mtime: time.Now().Unix(),
  6436. Ctime: time.Now().Unix(),
  6437. UserOrgId: adminUser.CurrentOrgId,
  6438. HisPatientId: his.ID,
  6439. OrderId: order.ID,
  6440. ProjectId: project_id,
  6441. Type: types,
  6442. ItemId: item_id,
  6443. }
  6444. service.CreateOrderInfoTX(info, tx)
  6445. }
  6446. his.Diagnosis = diagnosis_id
  6447. his.SickType = sick_type
  6448. his.RegisterType = reg_type
  6449. his.MedicalTreatmentType = reg_type
  6450. service.UpdataHisPateintTX(&his, tx)
  6451. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6452. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6453. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6454. //判断是否使用了押金
  6455. if dec_way == "true" {
  6456. tmpstring := strconv.FormatInt(order.ID, 10)
  6457. //扣押金
  6458. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6459. order.Decimal = decimal
  6460. service.UpDateOrderTwo(order, tx)
  6461. if errmsg != nil {
  6462. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6463. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6464. return
  6465. }
  6466. }
  6467. if err == nil {
  6468. for _, info := range prescriptions {
  6469. if info.Type == 1 {
  6470. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6471. }
  6472. if info.Type == 2 {
  6473. for _, sumItem := range info.HisPrescriptionProject {
  6474. if sumItem.Type == 3 {
  6475. var good models.DialysisBeforePrepareGoods
  6476. var newGood models.NewDialysisBeforePrepareGoods
  6477. var oldGood models.OldDialysisBeforePrepareGoods
  6478. good.GoodId = sumItem.GoodInfo.ID
  6479. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6480. count, _ := strconv.Atoi(sumItem.Count)
  6481. good.Count = int64(count)
  6482. good.StorehouseId = houseConfig.StorehouseOutInfo
  6483. good.ProjectId = sumItem.ID
  6484. good.PatientId = sumItem.PatientId
  6485. goods = append(goods, &good)
  6486. newGood.GoodId = sumItem.GoodInfo.ID
  6487. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6488. count2, _ := strconv.Atoi(sumItem.Count)
  6489. newGood.Count = int64(count2)
  6490. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6491. newGood.ProjectId = sumItem.ID
  6492. newGood.PatientId = sumItem.HisPatientId
  6493. newGoods = append(newGoods, &newGood)
  6494. oldGood.GoodId = sumItem.GoodInfo.ID
  6495. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6496. count3, _ := strconv.Atoi(sumItem.Count)
  6497. oldGood.Count = int64(count3)
  6498. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6499. oldGood.ProjectId = sumItem.ID
  6500. oldGood.RecordDate = sumItem.RecordDate
  6501. oldGood.PatientId = sumItem.HisPatientId
  6502. oldGoods = append(oldGoods, &oldGood)
  6503. }
  6504. }
  6505. }
  6506. }
  6507. if settConfig.IsOpen == 1 {
  6508. for _, item := range infoList {
  6509. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6510. if medical.IsUse == 2 {
  6511. //药品出库
  6512. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6513. //查询默认仓库
  6514. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6515. //查询默认仓库剩余多少库存
  6516. var sum_count int64
  6517. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6518. for _, its := range stockInfo {
  6519. if its.MaxUnit == medical.MaxUnit {
  6520. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6521. }
  6522. sum_count += its.StockMaxNumber + its.StockMinNumber
  6523. }
  6524. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6525. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6526. }
  6527. }
  6528. orgId := c.GetAdminUserInfo().CurrentOrgId
  6529. if len(oldGoods) > 0 {
  6530. timeStr := time.Now().Format("2006-01-02")
  6531. timeArr := strings.Split(timeStr, "-")
  6532. total, _ := service.FindAllWarehouseOut(orgId)
  6533. total = total + 1
  6534. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6535. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6536. number = number + total
  6537. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6538. operation_time := time.Now().Unix()
  6539. creater := c.GetAdminUserInfo().AdminUser.Id
  6540. //查询默认出库仓库库存
  6541. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6542. recordDateStr := time.Now().Format("2006-01-02")
  6543. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6544. nowtime := recordDate.Unix()
  6545. warehouseOut := models.WarehouseOut{
  6546. WarehouseOutOrderNumber: warehousing_out_order,
  6547. OperationTime: operation_time,
  6548. OrgId: orgId,
  6549. Creater: creater,
  6550. Ctime: time.Now().Unix(),
  6551. Status: 1,
  6552. WarehouseOutTime: nowtime,
  6553. Type: 1,
  6554. StorehouseId: storeConfig.StorehouseOutInfo,
  6555. IsCheck: 1,
  6556. OrderId: order.ID,
  6557. IsSys: 5,
  6558. }
  6559. //查询是否生成出库单
  6560. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6561. if out.ID == 0 {
  6562. service.AddSigleWarehouseOut(&warehouseOut)
  6563. }
  6564. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6565. for _, item := range oldGoods {
  6566. dialyPrepareOne := models.DialysisBeforePrepare{
  6567. GoodTypeId: item.GoodTypeId,
  6568. GoodId: item.GoodId,
  6569. PatientId: his.PatientId,
  6570. RecordDate: item.RecordDate,
  6571. UserOrgId: adminUser.CurrentOrgId,
  6572. Count: item.Count,
  6573. Ctime: time.Now().Unix(),
  6574. Creater: adminUser.AdminUser.Id,
  6575. CommdityCode: item.CommdityCode,
  6576. Status: 1,
  6577. StorehouseId: houseConfig.StorehouseOutInfo,
  6578. }
  6579. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6580. //非零用
  6581. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6582. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6583. //查询剩余库存
  6584. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6585. var sum_count int64
  6586. for _, item := range goodList {
  6587. sum_count += item.StockCount
  6588. }
  6589. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6590. //耗材
  6591. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6592. }
  6593. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6594. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6595. //查询剩余库存
  6596. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6597. var sum_count int64
  6598. for _, item := range goodList {
  6599. sum_count += item.StockCount
  6600. }
  6601. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6602. //耗材
  6603. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6604. }
  6605. }
  6606. }
  6607. }
  6608. c.ServeSuccessJSON(map[string]interface{}{
  6609. "msg": "结算成功",
  6610. })
  6611. }
  6612. }
  6613. }
  6614. // 退款
  6615. func (c *HisApiController) Refund() {
  6616. order_id, _ := c.GetInt64("order_id")
  6617. order, _ := service.GetHisOrderByID(order_id)
  6618. adminUser := c.GetAdminUserInfo()
  6619. orgid := c.GetAdminUserInfo().CurrentOrgId
  6620. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6621. if err != nil {
  6622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6623. return
  6624. }
  6625. tmp := strconv.FormatInt(order.ID, 10)
  6626. //当押金不为零时产生退费记录
  6627. if order.Decimal != 0 {
  6628. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6629. if err != nil {
  6630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6631. return
  6632. }
  6633. }
  6634. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6635. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6636. var goods []*models.DialysisBeforePrepareGoods
  6637. var newGoods []*models.NewDialysisBeforePrepareGoods
  6638. var infos []*models.HisDoctorAdviceInfo
  6639. for _, info := range orders {
  6640. if info.AdviceId > 0 && info.ProjectId == 0 {
  6641. infos = append(infos, &info.HisDoctorAdviceInfo)
  6642. }
  6643. if info.ProjectId > 0 && info.AdviceId == 0 {
  6644. if info.HisPrescriptionProject.Type == 3 {
  6645. var good models.DialysisBeforePrepareGoods
  6646. var newGood models.NewDialysisBeforePrepareGoods
  6647. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6648. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6649. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6650. good.Count = int64(count)
  6651. good.StorehouseId = houseConfig.StorehouseOutInfo
  6652. good.ProjectId = info.HisPrescriptionProject.ID
  6653. good.PatientId = info.PatientId
  6654. good.OrderId = order_id
  6655. goods = append(goods, &good)
  6656. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6657. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6658. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6659. newGood.Count = int64(count2)
  6660. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6661. newGood.ProjectId = info.HisPrescriptionProject.ID
  6662. newGood.RecordDate = order.SettleAccountsDate
  6663. newGood.UserOrgId = order.UserOrgId
  6664. newGood.PatientId = info.PatientId
  6665. newGood.OrderId = order_id
  6666. newGoods = append(newGoods, &newGood)
  6667. }
  6668. }
  6669. }
  6670. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6671. if settConfig.IsOpen == 1 {
  6672. for _, item := range infos {
  6673. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6674. }
  6675. for _, item := range newGoods {
  6676. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6677. }
  6678. }
  6679. c.ServeSuccessJSON(map[string]interface{}{
  6680. "msg": "退费成功",
  6681. })
  6682. }
  6683. func (c *HisApiController) RefundNumber() {
  6684. his_patient_id, _ := c.GetInt64("id")
  6685. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6686. info.Status = 0
  6687. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6688. if count > 0 {
  6689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6690. return
  6691. }
  6692. err := service.SaveHisPatient(info)
  6693. if err == nil {
  6694. c.ServeSuccessJSON(map[string]interface{}{
  6695. "msg": "退号成功",
  6696. })
  6697. } else {
  6698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6699. return
  6700. }
  6701. }
  6702. func (this *HisApiController) AdditionalCharge() {
  6703. dataBody := make(map[string]interface{}, 0)
  6704. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6705. fmt.Println(err)
  6706. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6707. patient_id := int64(dataBody["patient_id"].(float64))
  6708. medicineData, _ := dataBody["medicineData"].([]interface{})
  6709. adminUserInfo := this.GetAdminUserInfo()
  6710. orgId := adminUserInfo.CurrentOrgId
  6711. admin_user_id := adminUserInfo.AdminUser.Id
  6712. timeStr := time.Now().Format("2006-01-02")
  6713. timeLayout := "2006-01-02 15:04:05"
  6714. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6715. timenow := timeStringToTime.Unix()
  6716. var additionalCharges []*models.HisAdditionalCharge
  6717. for _, item := range medicineData {
  6718. var randNum int
  6719. randNum = rand.Intn(10000) + 1000
  6720. timestamp := time.Now().Unix()
  6721. tempTime := time.Unix(timestamp, 0)
  6722. timeFormat := tempTime.Format("20060102150405")
  6723. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6724. items := item.(map[string]interface{})
  6725. money := items["price"].(string)
  6726. item_id_str := items["item_id"].(string)
  6727. name := items["name"].(string)
  6728. id_str := items["id"].(string)
  6729. moneys, _ := strconv.ParseInt(money, 10, 64)
  6730. monStr := strconv.FormatInt(moneys, 10)
  6731. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6732. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6733. id, _ := strconv.ParseInt(id_str, 10, 64)
  6734. additionalCharge := &models.HisAdditionalCharge{
  6735. ID: id,
  6736. HisPatientId: his_patient_id,
  6737. UserOrgId: orgId,
  6738. PatientId: patient_id,
  6739. RecordDate: timenow,
  6740. Price: monneyStr,
  6741. Status: 1,
  6742. ItemName: name,
  6743. ItemId: item_id,
  6744. AdminUserId: admin_user_id,
  6745. CreatedTime: time.Now().Unix(),
  6746. OrderStatus: 0,
  6747. PrescriptionNumber: "",
  6748. BatchNumber: "",
  6749. FeedetlSn: p_number,
  6750. }
  6751. service.CreateAdditionalCharge(additionalCharge)
  6752. additionalCharges = append(additionalCharges, additionalCharge)
  6753. }
  6754. this.ServeSuccessJSON(map[string]interface{}{
  6755. "msg": "添加成功",
  6756. "additional_charges": additionalCharges,
  6757. })
  6758. }
  6759. func (this *HisApiController) DeleteAddition() {
  6760. id, _ := this.GetInt64("id")
  6761. //TODO 需要判断是否已经结算
  6762. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6763. if err == nil {
  6764. this.ServeSuccessJSON(map[string]interface{}{
  6765. "msg": "删除成功",
  6766. })
  6767. return
  6768. } else {
  6769. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6770. return
  6771. }
  6772. }
  6773. func (this *HisApiController) GetAdminUsers() {
  6774. adminUser := this.GetAdminUserInfo()
  6775. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6776. this.ServeSuccessJSON(map[string]interface{}{
  6777. "doctors": doctors,
  6778. })
  6779. }
  6780. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6781. change_type, _ := this.GetInt64("type", 0)
  6782. record_date := this.GetString("record_time")
  6783. patient_id, _ := this.GetInt64("patient_id", 0)
  6784. p_type, _ := this.GetInt64("p_type", 0)
  6785. timeLayout := "2006-01-02"
  6786. loc, _ := time.LoadLocation("Local")
  6787. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6788. record_time := theAdviceRecordTime.Unix()
  6789. adminUserInfo := this.GetAdminUserInfo()
  6790. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6791. if err == nil {
  6792. if len(prescriptions) == 0 {
  6793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6794. return
  6795. } else {
  6796. this.ServeSuccessJSON(map[string]interface{}{
  6797. "prescriptions": prescriptions,
  6798. })
  6799. return
  6800. }
  6801. } else {
  6802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6803. return
  6804. }
  6805. }
  6806. func (this *HisApiController) GetCallHisPrescription() {
  6807. patient_id, _ := this.GetInt64("patient_id", 0)
  6808. timeLayout := "2006-01-02"
  6809. loc, _ := time.LoadLocation("Local")
  6810. start_time := this.GetString("start_time")
  6811. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6812. end_time := this.GetString("end_time")
  6813. p_type, _ := this.GetInt64("p_type")
  6814. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6815. adminUserInfo := this.GetAdminUserInfo()
  6816. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6817. if err == nil {
  6818. this.ServeSuccessJSON(map[string]interface{}{
  6819. "prescriptions": prescriptions,
  6820. })
  6821. return
  6822. } else {
  6823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6824. return
  6825. }
  6826. }
  6827. func (this *HisApiController) GetHisDayPrescription() {
  6828. timeLayout := "2006-01-02"
  6829. loc, _ := time.LoadLocation("Local")
  6830. start_time := this.GetString("start_time")
  6831. patient_id, _ := this.GetInt64("patient_id", 0)
  6832. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6833. end_time := this.GetString("end_time")
  6834. p_type, _ := this.GetInt64("p_type")
  6835. order_status, _ := this.GetInt64("type")
  6836. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6837. adminUserInfo := this.GetAdminUserInfo()
  6838. var dayHisPrescription []*models.HisPrescription
  6839. var err error
  6840. if order_status == 1 || order_status == 0 {
  6841. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6842. } else if order_status == 2 {
  6843. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6844. }
  6845. var settle_total float64
  6846. for _, item := range dayHisPrescription {
  6847. if len(item.HisPrescriptionProject) > 0 {
  6848. for _, subItem := range item.HisPrescriptionProject {
  6849. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6850. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6851. settle_total = settle_total + total
  6852. }
  6853. }
  6854. if len(item.HisDoctorAdviceInfo) > 0 {
  6855. for _, subItem := range item.HisDoctorAdviceInfo {
  6856. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6857. settle_total = settle_total + total
  6858. }
  6859. }
  6860. }
  6861. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6862. if err == nil {
  6863. this.ServeSuccessJSON(map[string]interface{}{
  6864. "day_prescription": dayHisPrescription,
  6865. "settle_total": settle_total,
  6866. })
  6867. return
  6868. } else {
  6869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6870. return
  6871. }
  6872. }
  6873. func (c *HisApiController) GetHisChargePatientList() {
  6874. record_date := c.GetString("record_date")
  6875. order_status, _ := c.GetInt64("type")
  6876. sch_type, _ := c.GetInt64("sch_type")
  6877. timeLayout := "2006-01-02"
  6878. loc, _ := time.LoadLocation("Local")
  6879. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6880. if err != nil {
  6881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6882. return
  6883. }
  6884. recordDateTime := theTime.Unix()
  6885. adminInfo := c.GetAdminUserInfo()
  6886. var tempPatients []*service.NewTempPatients
  6887. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6888. if order_status != 2 {
  6889. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6890. } else {
  6891. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6892. }
  6893. var patients []*service.NewTempPatients
  6894. var patients_two []*service.NewTempPatients
  6895. for _, item := range tempPatients {
  6896. //过滤掉没挂号的和没开处方的
  6897. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6898. patients = append(patients, item)
  6899. }
  6900. //过滤掉没挂号的
  6901. if len(item.HisPatient) > 0 {
  6902. patients_two = append(patients_two, item)
  6903. }
  6904. }
  6905. c.ServeSuccessJSON(map[string]interface{}{
  6906. "list": patients,
  6907. "list_two": patients_two,
  6908. })
  6909. }
  6910. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6911. record_date := c.GetString("record_date")
  6912. timeLayout := "2006-01-02"
  6913. loc, _ := time.LoadLocation("Local")
  6914. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6915. if err != nil {
  6916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6917. return
  6918. }
  6919. recordDateTime := theTime.Unix()
  6920. adminUser := c.GetAdminUserInfo()
  6921. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6922. var patients []*service.Patients
  6923. for _, item := range tempPatients {
  6924. if item.HisPatient.ID == 0 {
  6925. patients = append(patients, item)
  6926. }
  6927. }
  6928. c.ServeSuccessJSON(map[string]interface{}{
  6929. "list": patients,
  6930. //"list_two": patients_two,
  6931. })
  6932. }
  6933. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6934. newArr = make([]*service.Patients, 0)
  6935. for i := 0; i < len(patient); i++ {
  6936. repeat := false
  6937. for j := i + 1; j < len(patient); j++ {
  6938. if patient[i].ID == patient[j].ID {
  6939. repeat = true
  6940. break
  6941. }
  6942. }
  6943. if !repeat {
  6944. newArr = append(newArr, patient[i])
  6945. }
  6946. }
  6947. return
  6948. }
  6949. func (c *HisApiController) GetHisChargePatientInfo() {
  6950. patient_id, _ := c.GetInt64("patient_id")
  6951. his_patient_id, _ := c.GetInt64("his_patient_id")
  6952. record_date := c.GetString("record_date")
  6953. //start_time := c.GetString("start_time")
  6954. //end_time := c.GetString("end_time")
  6955. order_status, _ := c.GetInt64("type", 0)
  6956. p_type, _ := c.GetInt64("p_type", 0)
  6957. order_id, _ := c.GetInt64("order_id", 0)
  6958. timeLayout := "2006-01-02"
  6959. loc, _ := time.LoadLocation("Local")
  6960. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6961. if err != nil {
  6962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6963. return
  6964. }
  6965. recordDateTime := theTime.Unix()
  6966. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6967. //if err != nil {
  6968. //
  6969. //}
  6970. //startRecordDateTime := startTime.Unix()
  6971. //
  6972. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6973. //if err != nil {
  6974. //
  6975. //}
  6976. //endRecordDateTime := endTime.Unix()
  6977. admin := c.GetAdminUserInfo()
  6978. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6979. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6980. var prescriptions []*models.HisPrescription
  6981. //var unChargeMonthPrescriptions []*models.HisPrescription
  6982. order, _ := service.GetHisOrderByID(order_id)
  6983. if order_status == 1 || order_status == 0 {
  6984. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6985. } else if order_status == 2 {
  6986. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6987. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6988. }
  6989. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6990. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6991. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6992. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6993. //获取所有科室信息
  6994. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6995. c.ServeSuccessJSON(map[string]interface{}{
  6996. "his_info": his_patient_info,
  6997. "xt_info": xt_patient_info,
  6998. "prescription": prescriptions,
  6999. "case_history": case_history,
  7000. "info": patientPrescriptionInfo,
  7001. "last_info": lastPatientPrescriptionInfo,
  7002. "order": order,
  7003. "doctors": doctors,
  7004. "department": department,
  7005. })
  7006. return
  7007. }
  7008. func (c *HisApiController) GetAllOrderDetail() {
  7009. order_id, _ := c.GetInt64("id", 0)
  7010. order, _ := service.GetHisOrderByID(order_id)
  7011. if order.ID == 0 {
  7012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7013. return
  7014. }
  7015. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7016. org_id := c.GetAdminUserInfo().CurrentOrgId
  7017. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7018. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7019. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7020. c.ServeSuccessJSON(map[string]interface{}{
  7021. "order": order,
  7022. "order_info": order_info,
  7023. "patient": patient,
  7024. "admin_info": adminInfo,
  7025. "hospital_record": record,
  7026. })
  7027. return
  7028. }
  7029. func (c *HisApiController) GetAllOrderDetailCollect() {
  7030. order_id, _ := c.GetInt64("id", 0)
  7031. order, _ := service.GetHisOrderByID(order_id)
  7032. if order.ID == 0 {
  7033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7034. return
  7035. }
  7036. org_id := c.GetAdminUserInfo().CurrentOrgId
  7037. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7038. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7039. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7040. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7041. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7042. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7043. var bedCostTotal float64 = 0 //床位总费
  7044. //var bedCostSelfTotal float64 = 0 //床位自费
  7045. var operationCostTotal float64 = 0 //手术费
  7046. //var operationCostSelfTotal float64 = 0 //手术费
  7047. var otherCostTotal float64 = 0 //其他费用
  7048. //var otherCostSelfTotal float64 = 0 //其他费用
  7049. var materialCostTotal float64 = 0 //材料费
  7050. //var materialCostSelfTotal float64 = 0 //材料费
  7051. var westernMedicineCostTotal float64 = 0 //西药费
  7052. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7053. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7054. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7055. var checkCostTotal float64 = 0 //检查费
  7056. //var checkCostSelfTotal float64 = 0 //检查费
  7057. var laboratoryCostTotal float64 = 0 //化验费
  7058. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7059. var treatCostTotal float64 = 0 //治疗费用
  7060. //var treatCostSelfTotal float64 = 0 //治疗费用
  7061. var zhenChaCostTotal float64 = 0 //其他费用
  7062. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7063. decimal.DivisionPrecision = 2
  7064. var BalanceAccountsType int64
  7065. if his.ID > 0 {
  7066. BalanceAccountsType = his.BalanceAccountsType
  7067. } else {
  7068. BalanceAccountsType = record.BalanceAccountsType
  7069. }
  7070. if BalanceAccountsType != 2 {
  7071. for _, item := range order_info {
  7072. if org_id == 10215 {
  7073. if item.MedChrgitmType == "01" { //床位费
  7074. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7075. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7076. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7077. }
  7078. if item.MedChrgitmType == "02" { //诊察费
  7079. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7080. //zhenChaCostSelfTotal = zhenChaCostTotal
  7081. }
  7082. if item.MedChrgitmType == "03" { //检查费
  7083. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7084. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7085. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7086. }
  7087. //if item.MedChrgitmType == "02" { //检查费
  7088. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7089. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7090. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7091. //}
  7092. if item.MedChrgitmType == "04" { //化验费
  7093. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7094. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7095. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7096. }
  7097. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7098. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7099. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7100. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7101. }
  7102. if item.MedChrgitmType == "06" { //手术费
  7103. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7104. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7105. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7106. }
  7107. if item.MedChrgitmType == "08" { //材料费
  7108. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7109. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7110. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7111. }
  7112. if item.MedChrgitmType == "09" { //西药费
  7113. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7114. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7115. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7116. }
  7117. if item.MedChrgitmType == "11" { //中成费
  7118. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7119. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7120. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7121. }
  7122. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7123. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7124. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7125. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7126. }
  7127. } else if org_id == 10188 || org_id == 10217 {
  7128. if item.MedChrgitmType == "01" { //床位费
  7129. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7130. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7131. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7132. }
  7133. if item.MedChrgitmType == "02" { //诊察费
  7134. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7135. //zhenChaCostSelfTotal = zhenChaCostTotal
  7136. }
  7137. if item.MedChrgitmType == "03" { //检查费
  7138. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7139. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7140. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7141. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7142. }
  7143. //if item.MedChrgitmType == "02" { //检查费
  7144. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7145. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7146. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7147. //}
  7148. if item.MedChrgitmType == "04" { //化验费
  7149. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7150. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7151. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7152. }
  7153. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7154. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7155. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7156. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7157. }
  7158. if item.MedChrgitmType == "06" { //手术费
  7159. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7160. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7161. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7162. }
  7163. if item.MedChrgitmType == "08" { //材料费
  7164. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7165. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7166. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7167. }
  7168. if item.MedChrgitmType == "09" { //西药费
  7169. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7170. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7171. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7172. }
  7173. if item.MedChrgitmType == "11" { //中成费
  7174. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7175. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7176. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7177. }
  7178. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7179. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7180. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7181. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7182. }
  7183. } else {
  7184. if item.MedChrgitmType == "01" { //床位费
  7185. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7186. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7187. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7188. }
  7189. //if item.MedChrgitmType == "02" { //诊察费
  7190. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7191. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7192. //}
  7193. if item.MedChrgitmType == "03" { //检查费
  7194. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7195. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7196. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7197. }
  7198. //if item.MedChrgitmType == "02" { //检查费
  7199. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7200. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7201. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7202. //}
  7203. if item.MedChrgitmType == "04" { //化验费
  7204. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7205. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7206. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7207. }
  7208. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7209. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7210. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7211. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7212. }
  7213. if item.MedChrgitmType == "06" { //手术费
  7214. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7215. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7216. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7217. }
  7218. if item.MedChrgitmType == "08" { //材料费
  7219. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7220. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7221. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7222. }
  7223. if item.MedChrgitmType == "09" { //西药费
  7224. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7225. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7226. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7227. }
  7228. if item.MedChrgitmType == "11" { //中成费
  7229. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7230. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7231. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7232. }
  7233. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7234. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7235. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7236. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7237. }
  7238. }
  7239. }
  7240. c.ServeSuccessJSON(map[string]interface{}{
  7241. "order": order,
  7242. "order_info": order_info,
  7243. "patient": patient,
  7244. "admin_info": adminInfo,
  7245. "his_hospital": record,
  7246. "bedCostTotal": bedCostTotal,
  7247. "operationCostTotal": operationCostTotal,
  7248. "otherCostTotal": otherCostTotal,
  7249. "materialCostTotal": materialCostTotal,
  7250. "westernMedicineCostTotal": westernMedicineCostTotal,
  7251. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7252. "checkCostTotal": checkCostTotal,
  7253. "zhenChaCostTotal": zhenChaCostTotal,
  7254. "laboratoryCostTotal": laboratoryCostTotal,
  7255. "treatCostTotal": treatCostTotal,
  7256. })
  7257. } else {
  7258. for _, item := range order_info {
  7259. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7260. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7261. item.MedChrgitmType = "09"
  7262. }
  7263. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7264. if item.HisPrescriptionProject.Type == 2 {
  7265. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7266. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7267. case 0:
  7268. item.MedChrgitmType = "0"
  7269. break
  7270. case 1:
  7271. item.MedChrgitmType = "14"
  7272. break
  7273. case 2:
  7274. item.MedChrgitmType = "05"
  7275. break
  7276. case 3:
  7277. item.MedChrgitmType = "03"
  7278. break
  7279. case 4:
  7280. item.MedChrgitmType = "03"
  7281. break
  7282. case 5:
  7283. item.MedChrgitmType = "08"
  7284. break
  7285. case 6:
  7286. item.MedChrgitmType = "14"
  7287. break
  7288. case 7:
  7289. item.MedChrgitmType = "14"
  7290. break
  7291. case 8:
  7292. item.MedChrgitmType = "03"
  7293. break
  7294. case 9:
  7295. item.MedChrgitmType = "14"
  7296. break
  7297. case 10:
  7298. item.MedChrgitmType = "14"
  7299. break
  7300. case 11:
  7301. item.MedChrgitmType = "06"
  7302. break
  7303. case 12:
  7304. item.MedChrgitmType = "12"
  7305. break
  7306. case 13:
  7307. item.MedChrgitmType = "01"
  7308. break
  7309. case 14:
  7310. item.MedChrgitmType = "04"
  7311. break
  7312. case 15:
  7313. item.MedChrgitmType = "14"
  7314. break
  7315. }
  7316. } else {
  7317. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7318. case 1:
  7319. item.MedChrgitmType = "14"
  7320. break
  7321. case 2:
  7322. item.MedChrgitmType = "05"
  7323. break
  7324. case 3:
  7325. item.MedChrgitmType = "04"
  7326. break
  7327. case 4:
  7328. item.MedChrgitmType = "14"
  7329. break
  7330. case 5:
  7331. item.MedChrgitmType = "08"
  7332. break
  7333. case 6:
  7334. item.MedChrgitmType = "14"
  7335. break
  7336. case 7:
  7337. item.MedChrgitmType = "14"
  7338. break
  7339. case 8:
  7340. item.MedChrgitmType = "03"
  7341. break
  7342. case 9:
  7343. item.MedChrgitmType = "14"
  7344. break
  7345. }
  7346. }
  7347. } else if item.HisPrescriptionProject.Type == 3 {
  7348. item.MedChrgitmType = "08"
  7349. }
  7350. }
  7351. }
  7352. for _, item := range order_info {
  7353. if org_id == 10215 {
  7354. if item.MedChrgitmType == "01" { //床位费
  7355. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7356. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7357. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7358. }
  7359. if item.MedChrgitmType == "02" { //诊察费
  7360. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7361. //zhenChaCostSelfTotal = zhenChaCostTotal
  7362. }
  7363. if item.MedChrgitmType == "03" { //检查费
  7364. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7365. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7366. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7367. }
  7368. //if item.MedChrgitmType == "02" { //检查费
  7369. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7370. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7371. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7372. //}
  7373. if item.MedChrgitmType == "04" { //化验费
  7374. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7375. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7376. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7377. }
  7378. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7379. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7380. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7381. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7382. }
  7383. if item.MedChrgitmType == "06" { //手术费
  7384. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7385. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7386. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7387. }
  7388. if item.MedChrgitmType == "08" { //材料费
  7389. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7390. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7391. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7392. }
  7393. if item.MedChrgitmType == "09" { //西药费
  7394. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7395. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7396. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7397. }
  7398. if item.MedChrgitmType == "11" { //中成费
  7399. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7400. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7401. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7402. }
  7403. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7404. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7405. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7406. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7407. }
  7408. } else {
  7409. if item.MedChrgitmType == "01" { //床位费
  7410. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7411. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7412. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7413. }
  7414. //if item.MedChrgitmType == "02" { //诊察费
  7415. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7416. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7417. //}
  7418. if item.MedChrgitmType == "03" { //检查费
  7419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7420. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7421. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7422. }
  7423. //if item.MedChrgitmType == "02" { //检查费
  7424. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7425. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7426. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7427. //}
  7428. if item.MedChrgitmType == "04" { //化验费
  7429. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7430. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7431. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7432. }
  7433. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7435. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7436. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7437. }
  7438. if item.MedChrgitmType == "06" { //手术费
  7439. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7440. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7441. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7442. }
  7443. if item.MedChrgitmType == "08" { //材料费
  7444. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7445. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7446. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7447. }
  7448. if item.MedChrgitmType == "09" { //西药费
  7449. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7450. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7451. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7452. }
  7453. if item.MedChrgitmType == "11" { //中成费
  7454. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7455. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7456. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7457. }
  7458. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7459. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7460. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7461. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7462. }
  7463. }
  7464. }
  7465. c.ServeSuccessJSON(map[string]interface{}{
  7466. "order": order,
  7467. "order_info": order_info,
  7468. "patient": patient,
  7469. "admin_info": adminInfo,
  7470. "his_hospital": record,
  7471. "bedCostTotal": bedCostTotal,
  7472. "operationCostTotal": operationCostTotal,
  7473. "otherCostTotal": otherCostTotal,
  7474. "materialCostTotal": materialCostTotal,
  7475. "westernMedicineCostTotal": westernMedicineCostTotal,
  7476. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7477. "checkCostTotal": checkCostTotal,
  7478. "zhenChaCostTotal": zhenChaCostTotal,
  7479. "laboratoryCostTotal": laboratoryCostTotal,
  7480. "treatCostTotal": treatCostTotal,
  7481. })
  7482. }
  7483. }
  7484. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7485. page, _ := c.GetInt64("page")
  7486. limit, _ := c.GetInt64("limit")
  7487. keywords := c.GetString("keywords")
  7488. start_time := c.GetString("start_time")
  7489. end_time := c.GetString("end_time")
  7490. //clr_type := c.GetString("clr_type")
  7491. insutype := c.GetString("insutype")
  7492. timeLayout := "2006-01-02"
  7493. loc, _ := time.LoadLocation("Local")
  7494. var theStartTIme int64
  7495. if len(start_time) > 0 {
  7496. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7497. theStartTIme = theTime.Unix()
  7498. }
  7499. var theEndtTIme int64
  7500. if len(end_time) > 0 {
  7501. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7502. theEndtTIme = theTime.Unix()
  7503. }
  7504. if page <= 0 {
  7505. page = 1
  7506. }
  7507. if limit <= 0 {
  7508. limit = 10
  7509. }
  7510. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7511. c.ServeSuccessJSON(map[string]interface{}{
  7512. "total": total,
  7513. "list": list,
  7514. })
  7515. return
  7516. }
  7517. func (c *HisApiController) GetPutOnRecordList() {
  7518. page, _ := c.GetInt64("page")
  7519. limit, _ := c.GetInt64("limit")
  7520. keywords := c.GetString("keywords")
  7521. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7522. if page <= 0 {
  7523. page = 1
  7524. }
  7525. if limit <= 0 {
  7526. limit = 10
  7527. }
  7528. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7529. c.ServeSuccessJSON(map[string]interface{}{
  7530. "total": total,
  7531. "list": list,
  7532. })
  7533. return
  7534. }
  7535. func (c *HisApiController) GetCompareData() {
  7536. start_time := c.GetString("start_time")
  7537. end_time := c.GetString("end_time")
  7538. insutype := c.GetString("insutype")
  7539. clr_type := c.GetString("clr_type")
  7540. timeLayout := "2006-01-02"
  7541. loc, _ := time.LoadLocation("Local")
  7542. var theStartTIme int64
  7543. if len(start_time) > 0 {
  7544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7545. if err != nil {
  7546. theStartTIme = 0
  7547. }
  7548. theStartTIme = theTime.Unix()
  7549. }
  7550. var theEndtTIme int64
  7551. if len(end_time) > 0 {
  7552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7553. if err != nil {
  7554. theEndtTIme = 0
  7555. }
  7556. theEndtTIme = theTime.Unix()
  7557. }
  7558. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7559. fmt.Println(err)
  7560. if err == nil {
  7561. c.ServeSuccessJSON(map[string]interface{}{
  7562. "list": formData,
  7563. })
  7564. } else {
  7565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7566. return
  7567. }
  7568. }
  7569. func (c *HisApiController) GetFaPiaoData() {
  7570. order_id, _ := c.GetInt64("order_id")
  7571. patient_id, _ := c.GetInt64("patient_id")
  7572. //number := c.GetString("number")
  7573. adminUser := c.GetAdminUserInfo()
  7574. order, _ := service.GetHisOrderByID(order_id)
  7575. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7576. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7577. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7578. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7579. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7580. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7581. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7582. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7583. var bedCostTotal float64 = 0 //床位总费
  7584. var bedCostSelfTotal float64 = 0 //床位自费
  7585. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7586. var operationCostTotal float64 = 0 //手术费
  7587. var operationCostSelfTotal float64 = 0 //手术费
  7588. var operationCostPartSelfTotal float64 = 0 //手术费
  7589. var otherCostTotal float64 = 0 //其他费用
  7590. var otherCostSelfTotal float64 = 0 //其他费用
  7591. var otherCostPartSelfTotal float64 = 0 //其他费用
  7592. var materialCostTotal float64 = 0 //材料费
  7593. var materialCostSelfTotal float64 = 0 //材料费
  7594. var materialCostPartSelfTotal float64 = 0 //材料费
  7595. var westernMedicineCostTotal float64 = 0 //西药费
  7596. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7597. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7601. var checkCostTotal float64 = 0 //检查费
  7602. var checkCostSelfTotal float64 = 0 //检查费
  7603. var checkCostPartSelfTotal float64 = 0 //检查费
  7604. var hiliCostTotal float64 = 0 //护理费
  7605. var hiliCostSelfTotal float64 = 0 //护理费
  7606. var hiliCostPartSelfTotal float64 = 0 //护理费
  7607. var laboratoryCostTotal float64 = 0 //化验费
  7608. var laboratoryCostSelfTotal float64 = 0 //化验费
  7609. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7610. var treatCostTotal float64 = 0 //治疗费用
  7611. var treatCostSelfTotal float64 = 0 //治疗费用
  7612. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7613. var zhenChaCostTotal float64 = 0 //其他费用
  7614. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7615. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7616. decimal.DivisionPrecision = 2
  7617. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7618. var balanceAccountsType int64
  7619. if his.ID > 0 {
  7620. balanceAccountsType = his.BalanceAccountsType
  7621. } else {
  7622. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7623. }
  7624. if balanceAccountsType == 2 {
  7625. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7626. for _, item := range orderInfos_two {
  7627. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7628. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7629. item.MedChrgitmType = "09"
  7630. }
  7631. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7632. if item.HisPrescriptionProject.Type == 2 {
  7633. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7634. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7635. case 0:
  7636. item.MedChrgitmType = "0"
  7637. break
  7638. case 1:
  7639. item.MedChrgitmType = "14"
  7640. break
  7641. case 2:
  7642. item.MedChrgitmType = "05"
  7643. break
  7644. case 3:
  7645. item.MedChrgitmType = "03"
  7646. break
  7647. case 4:
  7648. item.MedChrgitmType = "03"
  7649. break
  7650. case 5:
  7651. item.MedChrgitmType = "08"
  7652. break
  7653. case 6:
  7654. item.MedChrgitmType = "14"
  7655. break
  7656. case 7:
  7657. item.MedChrgitmType = "14"
  7658. break
  7659. case 8:
  7660. item.MedChrgitmType = "03"
  7661. break
  7662. case 9:
  7663. item.MedChrgitmType = "14"
  7664. break
  7665. case 10:
  7666. item.MedChrgitmType = "14"
  7667. break
  7668. case 11:
  7669. item.MedChrgitmType = "06"
  7670. break
  7671. case 12:
  7672. item.MedChrgitmType = "12"
  7673. break
  7674. case 13:
  7675. item.MedChrgitmType = "01"
  7676. break
  7677. case 14:
  7678. item.MedChrgitmType = "04"
  7679. break
  7680. case 15:
  7681. item.MedChrgitmType = "02"
  7682. break
  7683. }
  7684. } else {
  7685. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7686. case 1:
  7687. item.MedChrgitmType = "14"
  7688. break
  7689. case 2:
  7690. item.MedChrgitmType = "05"
  7691. break
  7692. case 3:
  7693. item.MedChrgitmType = "03"
  7694. break
  7695. case 4:
  7696. item.MedChrgitmType = "03"
  7697. break
  7698. case 5:
  7699. item.MedChrgitmType = "08"
  7700. break
  7701. case 6:
  7702. item.MedChrgitmType = "14"
  7703. break
  7704. case 7:
  7705. item.MedChrgitmType = "14"
  7706. break
  7707. case 8:
  7708. item.MedChrgitmType = "03"
  7709. break
  7710. case 9:
  7711. item.MedChrgitmType = "14"
  7712. break
  7713. }
  7714. }
  7715. } else if item.HisPrescriptionProject.Type == 3 {
  7716. item.MedChrgitmType = "08"
  7717. }
  7718. }
  7719. }
  7720. for _, item := range orderInfos_two {
  7721. fmt.Println(item.MedChrgitmType)
  7722. if item.MedChrgitmType == "07" { //床位费
  7723. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7724. hiliCostSelfTotal = hiliCostTotal
  7725. }
  7726. if item.MedChrgitmType == "01" { //床位费
  7727. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7728. bedCostSelfTotal = bedCostTotal
  7729. }
  7730. if item.MedChrgitmType == "02" { //诊察费
  7731. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7732. zhenChaCostSelfTotal = zhenChaCostTotal
  7733. }
  7734. if item.MedChrgitmType == "03" { //检查费
  7735. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7736. checkCostSelfTotal = checkCostTotal
  7737. }
  7738. if item.MedChrgitmType == "04" { //化验费
  7739. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7740. laboratoryCostSelfTotal = laboratoryCostTotal
  7741. }
  7742. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7743. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7744. treatCostSelfTotal = treatCostTotal
  7745. }
  7746. if item.MedChrgitmType == "06" { //手术费
  7747. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7748. operationCostSelfTotal = treatCostTotal
  7749. }
  7750. if item.MedChrgitmType == "08" { //材料费
  7751. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7752. materialCostSelfTotal = materialCostTotal
  7753. }
  7754. if item.MedChrgitmType == "09" { //西药费
  7755. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7756. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7757. }
  7758. if item.MedChrgitmType == "11" { //中成费
  7759. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7760. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7761. }
  7762. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7763. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7764. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7765. otherCostSelfTotal = otherCostTotal
  7766. }
  7767. } else {
  7768. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7769. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7770. otherCostSelfTotal = otherCostTotal
  7771. }
  7772. }
  7773. }
  7774. } else {
  7775. for _, item := range orderInfos {
  7776. if item.MedChrgitmType == "01" { //床位费
  7777. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7778. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7779. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7780. }
  7781. if item.MedChrgitmType == "02" { //诊察费
  7782. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7783. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7784. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7785. }
  7786. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7787. if item.MedChrgitmType == "03" { //检查费
  7788. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7789. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7790. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7791. }
  7792. } else {
  7793. if item.MedChrgitmType == "03" { //检查费
  7794. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7795. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7796. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7797. }
  7798. }
  7799. if item.MedChrgitmType == "04" { //化验费
  7800. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7801. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7802. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7803. }
  7804. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7805. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7806. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7807. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7808. }
  7809. if item.MedChrgitmType == "06" { //手术费
  7810. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7811. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7812. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7813. }
  7814. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7815. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7816. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7817. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7818. }
  7819. if item.MedChrgitmType == "07" { //西药费
  7820. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7821. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7822. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7823. }
  7824. if item.MedChrgitmType == "09" { //西药费
  7825. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7826. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7827. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7828. }
  7829. if item.MedChrgitmType == "11" { //中成费
  7830. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7831. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7832. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7833. }
  7834. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7835. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7836. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7837. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7838. }
  7839. }
  7840. }
  7841. timeLayout := "2006-01-02"
  7842. loc, _ := time.LoadLocation("Local")
  7843. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7844. if err != nil {
  7845. }
  7846. startRecordDateTime := startTime.Unix()
  7847. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7848. if err != nil {
  7849. }
  7850. endRecordDateTime := endTime.Unix()
  7851. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7852. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7853. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7854. c.ServeSuccessJSON(map[string]interface{}{
  7855. "order_number": order.Number, //业务流水号
  7856. "id_card_no": his.IdCardNo, //社会保障号
  7857. "patient": patient,
  7858. "department_name": department.Name, //科室
  7859. "number": his.Number, //门诊号
  7860. "date": order.SettleAccountsDate, //结算日期
  7861. "name": order.PsnName, //姓名
  7862. "gender": patient.Gender, //性别
  7863. "psn_cash_money": order.PsnCashPay, //个人支付
  7864. "pay_way": "门诊", //结算方式
  7865. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7866. "admin_user_name": admin.UserName, //收款员
  7867. "order": order,
  7868. "order_info": orderInfos_two,
  7869. "his": his,
  7870. "bedCostTotal": bedCostTotal,
  7871. "bedCostSelfTotal": bedCostSelfTotal,
  7872. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7873. "operationCostTotal": operationCostTotal,
  7874. "operationCostSelfTotal": operationCostSelfTotal,
  7875. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7876. "otherCostTotal": otherCostTotal,
  7877. "otherCostSelfTotal": otherCostSelfTotal,
  7878. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7879. "materialCostTotal": materialCostTotal,
  7880. "materialCostSelfTotal": materialCostSelfTotal,
  7881. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7882. "westernMedicineCostTotal": westernMedicineCostTotal,
  7883. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7884. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7885. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7886. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7887. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7888. "checkCostTotal": checkCostTotal,
  7889. "checkCostSelfTotal": checkCostSelfTotal,
  7890. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7891. "laboratoryCostTotal": laboratoryCostTotal,
  7892. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7893. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7894. "treatCostTotal": treatCostTotal,
  7895. "treatCostSelfTotal": treatCostSelfTotal,
  7896. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7897. "zhenChaCostTotal": zhenChaCostTotal,
  7898. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7899. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7900. "his_hospital_record": his_hospital_record,
  7901. "pre_pay_money": pre_pay_money,
  7902. "refund_sum": sum,
  7903. "doctor_info": doctor_info,
  7904. "hiliCostTotal": hiliCostTotal,
  7905. "hiliCostSelfTotal": hiliCostSelfTotal,
  7906. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  7907. })
  7908. }
  7909. //func (c *HisApiController) GetFaPiaoDatas() {
  7910. // order_ids := c.GetString("order_ids")
  7911. // patient_id, _ := c.GetInt64("patient_id")
  7912. // adminUser := c.GetAdminUserInfo()
  7913. //
  7914. // orders := strings.Split(order_ids, ",")
  7915. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7916. //
  7917. // for _, item := range orders {
  7918. // order_id, _ := strconv.ParseInt(item, 10, 64)
  7919. // order, _ := service.GetHisOrderByID(order_id)
  7920. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7921. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7922. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7923. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7924. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7925. //
  7926. // }
  7927. //
  7928. // var bedCostTotal float64 = 0 //床位总费
  7929. // var bedCostSelfTotal float64 = 0 //床位自费
  7930. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7931. //
  7932. // var operationCostTotal float64 = 0 //手术费
  7933. // var operationCostSelfTotal float64 = 0 //手术费
  7934. // var operationCostPartSelfTotal float64 = 0 //手术费
  7935. //
  7936. // var otherCostTotal float64 = 0 //其他费用
  7937. // var otherCostSelfTotal float64 = 0 //其他费用
  7938. // var otherCostPartSelfTotal float64 = 0 //其他费用
  7939. //
  7940. // var materialCostTotal float64 = 0 //材料费
  7941. // var materialCostSelfTotal float64 = 0 //材料费
  7942. // var materialCostPartSelfTotal float64 = 0 //材料费
  7943. //
  7944. // var westernMedicineCostTotal float64 = 0 //西药费
  7945. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  7946. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7947. //
  7948. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7949. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7950. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7951. //
  7952. // var checkCostTotal float64 = 0 //检查费
  7953. // var checkCostSelfTotal float64 = 0 //检查费
  7954. // var checkCostPartSelfTotal float64 = 0 //检查费
  7955. //
  7956. // var laboratoryCostTotal float64 = 0 //化验费
  7957. // var laboratoryCostSelfTotal float64 = 0 //化验费
  7958. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7959. //
  7960. // var treatCostTotal float64 = 0 //治疗费用
  7961. // var treatCostSelfTotal float64 = 0 //治疗费用
  7962. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  7963. //
  7964. // var zhenChaCostTotal float64 = 0 //其他费用
  7965. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  7966. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7967. //
  7968. // decimal.DivisionPrecision = 2
  7969. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7970. //
  7971. // var balanceAccountsType int64
  7972. // if his.ID > 0 {
  7973. // balanceAccountsType = his.BalanceAccountsType
  7974. // } else {
  7975. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  7976. // }
  7977. // if balanceAccountsType == 2 {
  7978. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7979. // for _, item := range orderInfos_two {
  7980. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7981. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7982. // item.MedChrgitmType = "09"
  7983. // }
  7984. //
  7985. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7986. // if item.HisPrescriptionProject.Type == 2 {
  7987. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7988. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7989. // case 0:
  7990. // item.MedChrgitmType = "0"
  7991. // break
  7992. // case 1:
  7993. // item.MedChrgitmType = "14"
  7994. // break
  7995. // case 2:
  7996. // item.MedChrgitmType = "05"
  7997. //
  7998. // break
  7999. // case 3:
  8000. // item.MedChrgitmType = "03"
  8001. //
  8002. // break
  8003. // case 4:
  8004. // item.MedChrgitmType = "03"
  8005. //
  8006. // break
  8007. // case 5:
  8008. // item.MedChrgitmType = "08"
  8009. //
  8010. // break
  8011. // case 6:
  8012. // item.MedChrgitmType = "14"
  8013. //
  8014. // break
  8015. // case 7:
  8016. // item.MedChrgitmType = "14"
  8017. //
  8018. // break
  8019. // case 8:
  8020. // item.MedChrgitmType = "03"
  8021. // break
  8022. // case 9:
  8023. // item.MedChrgitmType = "14"
  8024. // break
  8025. // case 10:
  8026. // item.MedChrgitmType = "14"
  8027. // break
  8028. // case 11:
  8029. // item.MedChrgitmType = "06"
  8030. // break
  8031. // case 12:
  8032. // item.MedChrgitmType = "12"
  8033. // break
  8034. // case 13:
  8035. // item.MedChrgitmType = "01"
  8036. // break
  8037. // case 14:
  8038. // item.MedChrgitmType = "04"
  8039. // break
  8040. // case 15:
  8041. // item.MedChrgitmType = "02"
  8042. // break
  8043. //
  8044. // }
  8045. //
  8046. // } else {
  8047. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8048. //
  8049. // case 1:
  8050. // item.MedChrgitmType = "14"
  8051. // break
  8052. // case 2:
  8053. // item.MedChrgitmType = "05"
  8054. //
  8055. // break
  8056. // case 3:
  8057. // item.MedChrgitmType = "03"
  8058. //
  8059. // break
  8060. // case 4:
  8061. // item.MedChrgitmType = "03"
  8062. //
  8063. // break
  8064. // case 5:
  8065. // item.MedChrgitmType = "08"
  8066. //
  8067. // break
  8068. // case 6:
  8069. // item.MedChrgitmType = "14"
  8070. //
  8071. // break
  8072. // case 7:
  8073. // item.MedChrgitmType = "14"
  8074. //
  8075. // break
  8076. // case 8:
  8077. // item.MedChrgitmType = "03"
  8078. // break
  8079. // case 9:
  8080. // item.MedChrgitmType = "14"
  8081. // break
  8082. //
  8083. // }
  8084. //
  8085. // }
  8086. //
  8087. // } else if item.HisPrescriptionProject.Type == 3 {
  8088. // item.MedChrgitmType = "08"
  8089. // }
  8090. // }
  8091. // }
  8092. //
  8093. // for _, item := range orderInfos_two {
  8094. // fmt.Println(item.MedChrgitmType)
  8095. // if item.MedChrgitmType == "01" { //床位费
  8096. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8097. // bedCostSelfTotal = bedCostTotal
  8098. // }
  8099. //
  8100. // if item.MedChrgitmType == "02" { //诊察费
  8101. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8102. // zhenChaCostSelfTotal = zhenChaCostTotal
  8103. // }
  8104. //
  8105. // if item.MedChrgitmType == "03" { //检查费
  8106. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8107. // checkCostSelfTotal = checkCostTotal
  8108. // }
  8109. //
  8110. // if item.MedChrgitmType == "04" { //化验费
  8111. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8112. // laboratoryCostSelfTotal = laboratoryCostTotal
  8113. // }
  8114. //
  8115. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8116. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8117. // treatCostSelfTotal = treatCostTotal
  8118. // }
  8119. //
  8120. // if item.MedChrgitmType == "06" { //手术费
  8121. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8122. // operationCostSelfTotal = treatCostTotal
  8123. // }
  8124. //
  8125. // if item.MedChrgitmType == "08" { //材料费
  8126. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8127. // materialCostSelfTotal = materialCostTotal
  8128. // }
  8129. //
  8130. // if item.MedChrgitmType == "09" { //西药费
  8131. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8132. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8133. // }
  8134. //
  8135. // if item.MedChrgitmType == "11" { //中成费
  8136. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8137. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8138. // }
  8139. //
  8140. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8141. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8142. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8143. // otherCostSelfTotal = otherCostTotal
  8144. // }
  8145. // } else {
  8146. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8147. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8148. // otherCostSelfTotal = otherCostTotal
  8149. // }
  8150. //
  8151. // }
  8152. //
  8153. // }
  8154. //
  8155. // } else {
  8156. // for _, item := range orderInfos {
  8157. // if item.MedChrgitmType == "01" { //床位费
  8158. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8159. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8160. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8161. // }
  8162. //
  8163. // if item.MedChrgitmType == "02" { //诊察费
  8164. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8165. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8166. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8167. // }
  8168. //
  8169. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8170. // if item.MedChrgitmType == "03" { //检查费
  8171. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8172. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8173. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8174. //
  8175. // }
  8176. // } else {
  8177. // if item.MedChrgitmType == "03" { //检查费
  8178. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8179. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8180. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8181. // }
  8182. //
  8183. // }
  8184. //
  8185. // if item.MedChrgitmType == "04" { //化验费
  8186. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8187. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8188. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8189. //
  8190. // }
  8191. //
  8192. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8193. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8194. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8195. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8196. //
  8197. // }
  8198. //
  8199. // if item.MedChrgitmType == "06" { //手术费
  8200. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8201. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8202. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8203. // }
  8204. //
  8205. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8206. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8207. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8208. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8209. // }
  8210. //
  8211. // if item.MedChrgitmType == "09" { //西药费
  8212. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8213. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8214. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8215. // }
  8216. //
  8217. // if item.MedChrgitmType == "11" { //中成费
  8218. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8219. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8220. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8221. // }
  8222. //
  8223. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8224. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8225. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8226. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8227. // }
  8228. //
  8229. // }
  8230. // }
  8231. // timeLayout := "2006-01-02"
  8232. // loc, _ := time.LoadLocation("Local")
  8233. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8234. // if err != nil {
  8235. // }
  8236. // startRecordDateTime := startTime.Unix()
  8237. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8238. // if err != nil {
  8239. // }
  8240. // endRecordDateTime := endTime.Unix()
  8241. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8242. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8243. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8244. //
  8245. // c.ServeSuccessJSON(map[string]interface{}{
  8246. // "order_number": order.Number, //业务流水号
  8247. // "id_card_no": his.IdCardNo, //社会保障号
  8248. // "department_name": department.Name, //科室
  8249. // "number": his.Number, //门诊号
  8250. // "date": order.SettleAccountsDate, //结算日期
  8251. // "name": order.PsnName, //姓名
  8252. // "gender": patient.Gender, //性别
  8253. // "psn_cash_money": order.PsnCashPay, //个人支付
  8254. // "pay_way": "门诊", //结算方式
  8255. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8256. // "admin_user_name": admin.UserName, //收款员
  8257. // "order": order,
  8258. // "order_info": orderInfos_two,
  8259. // "his": his,
  8260. // "bedCostTotal": bedCostTotal,
  8261. // "bedCostSelfTotal": bedCostSelfTotal,
  8262. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8263. // "operationCostTotal": operationCostTotal,
  8264. // "operationCostSelfTotal": operationCostSelfTotal,
  8265. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8266. // "otherCostTotal": otherCostTotal,
  8267. // "otherCostSelfTotal": otherCostSelfTotal,
  8268. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8269. // "materialCostTotal": materialCostTotal,
  8270. // "materialCostSelfTotal": materialCostSelfTotal,
  8271. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8272. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8273. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8274. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8275. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8276. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8277. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8278. // "checkCostTotal": checkCostTotal,
  8279. // "checkCostSelfTotal": checkCostSelfTotal,
  8280. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8281. // "laboratoryCostTotal": laboratoryCostTotal,
  8282. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8283. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8284. // "treatCostTotal": treatCostTotal,
  8285. // "treatCostSelfTotal": treatCostSelfTotal,
  8286. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8287. // "zhenChaCostTotal": zhenChaCostTotal,
  8288. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8289. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8290. // "his_hospital_record": his_hospital_record,
  8291. // "pre_pay_money": pre_pay_money,
  8292. // "refund_sum": sum,
  8293. // })
  8294. //
  8295. //}
  8296. func (this *HisApiController) GetIncomeStatisticsData() {
  8297. start_time := this.GetString("start_time")
  8298. end_time := this.GetString("end_time")
  8299. key_words := this.GetString("key_words")
  8300. limit, _ := this.GetInt64("limit")
  8301. page, _ := this.GetInt64("page")
  8302. if page <= 0 {
  8303. page = 1
  8304. }
  8305. if limit <= 0 {
  8306. limit = 10
  8307. }
  8308. statistics_type, _ := this.GetInt64("statistics_type")
  8309. admin := this.GetAdminUserInfo()
  8310. timeLayout := "2006-01-02"
  8311. loc, _ := time.LoadLocation("Local")
  8312. var theStartTIme int64
  8313. if len(start_time) > 0 {
  8314. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8315. if err != nil {
  8316. theStartTIme = 0
  8317. }
  8318. theStartTIme = theTime.Unix()
  8319. }
  8320. var theEndtTIme int64
  8321. if len(end_time) > 0 {
  8322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8323. if err != nil {
  8324. theEndtTIme = 0
  8325. }
  8326. theEndtTIme = theTime.Unix()
  8327. }
  8328. if statistics_type == 1 {
  8329. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8330. this.ServeSuccessJSON(map[string]interface{}{
  8331. "list": list,
  8332. "total": total,
  8333. })
  8334. } else {
  8335. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8336. this.ServeSuccessJSON(map[string]interface{}{
  8337. "list": list,
  8338. "total": total,
  8339. })
  8340. }
  8341. }
  8342. func (c *HisApiController) PostProjectInformation() {
  8343. adminUser := c.GetAdminUserInfo()
  8344. orgId := adminUser.CurrentOrgId
  8345. dataBody := make(map[string]interface{}, 0)
  8346. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8347. if err != nil {
  8348. utils.ErrorLog(err.Error())
  8349. return
  8350. }
  8351. utils.ErrorLog("%v", dataBody)
  8352. var projectList []*models.HisProject
  8353. var total_goods []interface{}
  8354. tempProjects := dataBody["projects"].([]interface{})
  8355. total_goods = tempProjects
  8356. for index, projectMap := range tempProjects {
  8357. projectM := projectMap.(map[string]interface{})
  8358. var project models.HisProject
  8359. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8360. utils.ErrorLog("project_name")
  8361. return
  8362. }
  8363. project_name, _ := projectM["project_name"].(string)
  8364. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8365. err_log := models.ExportErrLog{
  8366. LogType: 6,
  8367. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8368. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8369. Status: 1,
  8370. CreateTime: time.Now().Unix(),
  8371. UpdateTime: time.Now().Unix(),
  8372. ExportTime: time.Now().Unix(),
  8373. }
  8374. service.CreateExportErrLog(&err_log)
  8375. continue
  8376. }
  8377. project.ProjectName = project_name
  8378. prices := projectM["price"].(string)
  8379. price, _ := strconv.ParseFloat(prices, 64)
  8380. if price <= 0 { //名字为空则生成一条导入错误日志
  8381. err_log := models.ExportErrLog{
  8382. LogType: 6,
  8383. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8384. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8385. Status: 1,
  8386. CreateTime: time.Now().Unix(),
  8387. UpdateTime: time.Now().Unix(),
  8388. ExportTime: time.Now().Unix(),
  8389. }
  8390. service.CreateExportErrLog(&err_log)
  8391. continue
  8392. }
  8393. project.Price = price
  8394. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8395. utils.ErrorLog("unit_id")
  8396. return
  8397. }
  8398. unit := projectM["unit"].(string)
  8399. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8400. err_log := models.ExportErrLog{
  8401. LogType: 6,
  8402. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8403. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8404. Status: 1,
  8405. CreateTime: time.Now().Unix(),
  8406. UpdateTime: time.Now().Unix(),
  8407. ExportTime: time.Now().Unix(),
  8408. }
  8409. service.CreateExportErrLog(&err_log)
  8410. continue
  8411. }
  8412. project.Unit = unit
  8413. cost_classify := projectM["cost_classify"].(string)
  8414. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8415. err_log := models.ExportErrLog{
  8416. LogType: 6,
  8417. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8418. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8419. Status: 1,
  8420. CreateTime: time.Now().Unix(),
  8421. UpdateTime: time.Now().Unix(),
  8422. ExportTime: time.Now().Unix(),
  8423. }
  8424. service.CreateExportErrLog(&err_log)
  8425. continue
  8426. }
  8427. var costClassify = "费用类别"
  8428. var cost_classify_id int64
  8429. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8430. if len(cost_classify) != 0 {
  8431. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8432. if errcode == gorm.ErrRecordNotFound {
  8433. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8434. dataconfig := models.DictDataconfig{
  8435. ParentId: costClassifyConfig.ID,
  8436. Module: "system",
  8437. OrgId: orgId,
  8438. Name: cost_classify,
  8439. FieldName: "",
  8440. Value: costConfig.Value + 1,
  8441. CreatedTime: "",
  8442. UpdatedTime: "",
  8443. CreateUserId: adminUser.AdminUser.Id,
  8444. Status: 1,
  8445. Remark: "",
  8446. DeleteIdSystem: 0,
  8447. Title: "",
  8448. Content: "",
  8449. Order: 0,
  8450. Code: "",
  8451. }
  8452. service.CreatedDicConfig(&dataconfig)
  8453. }
  8454. }
  8455. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8456. for _, it := range costClassList {
  8457. if cost_classify == it.Name {
  8458. cost_classify_id = int64(it.Value)
  8459. }
  8460. }
  8461. project.CostClassify = cost_classify_id
  8462. executive_section := projectM["executive_section"].(string)
  8463. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8464. err_log := models.ExportErrLog{
  8465. LogType: 6,
  8466. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8467. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8468. Status: 1,
  8469. CreateTime: time.Now().Unix(),
  8470. UpdateTime: time.Now().Unix(),
  8471. ExportTime: time.Now().Unix(),
  8472. }
  8473. service.CreateExportErrLog(&err_log)
  8474. continue
  8475. }
  8476. if len(executive_section) != 0 {
  8477. //查找科室是否有内容
  8478. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8479. if errcodedepart == gorm.ErrRecordNotFound {
  8480. department := models.XtHisDepartment{
  8481. Name: executive_section,
  8482. Status: 1,
  8483. UserOrgId: adminUser.CurrentOrgId,
  8484. CreatedTime: time.Now().Unix(),
  8485. }
  8486. service.CreateDePartment(&department)
  8487. }
  8488. }
  8489. var executive_section_id int64
  8490. departMentList, _ := service.GetAllDepartMent(orgId)
  8491. for _, it := range departMentList {
  8492. if executive_section == it.Name {
  8493. executive_section_id = it.ID
  8494. }
  8495. }
  8496. project.ExecutiveSection = executive_section_id
  8497. medical_coverage := projectM["medical_coverage"].(string)
  8498. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8499. err_log := models.ExportErrLog{
  8500. LogType: 6,
  8501. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8502. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8503. Status: 1,
  8504. CreateTime: time.Now().Unix(),
  8505. UpdateTime: time.Now().Unix(),
  8506. ExportTime: time.Now().Unix(),
  8507. }
  8508. service.CreateExportErrLog(&err_log)
  8509. continue
  8510. }
  8511. var medicalCoverage = "医保等级"
  8512. var medical_coverage_id int64
  8513. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8514. if len(medical_coverage) != 0 {
  8515. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8516. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8517. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8518. dataconfig := models.DictDataconfig{
  8519. ParentId: medicalCoverageConfig.ID,
  8520. Module: "system",
  8521. OrgId: orgId,
  8522. Name: medical_coverage,
  8523. FieldName: "",
  8524. Value: medicalCoverageConfig.Value + 1,
  8525. CreatedTime: "",
  8526. UpdatedTime: "",
  8527. CreateUserId: adminUser.AdminUser.Id,
  8528. Status: 1,
  8529. Remark: "",
  8530. DeleteIdSystem: 0,
  8531. Title: "",
  8532. Content: "",
  8533. Order: 0,
  8534. Code: "",
  8535. }
  8536. service.CreatedDicConfig(&dataconfig)
  8537. }
  8538. }
  8539. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8540. for _, it := range medicalCoverageList {
  8541. if medical_coverage == it.Name {
  8542. medical_coverage_id = int64(it.Value)
  8543. }
  8544. }
  8545. project.MedicalCoverage = medical_coverage_id
  8546. pinyin := projectM["pinyin"].(string)
  8547. project.Pinyin = pinyin
  8548. wubi := projectM["wubi"].(string)
  8549. project.Wubi = wubi
  8550. statistical_classification := projectM["statistical_classification"].(string)
  8551. var statisticalClassification = "统计分类"
  8552. var statistical_classification_id int64
  8553. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8554. if len(statistical_classification) != 0 {
  8555. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8556. if classificationerrcodes == gorm.ErrRecordNotFound {
  8557. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8558. dataconfig := models.DictDataconfig{
  8559. ParentId: classiFication.ID,
  8560. Module: "system",
  8561. OrgId: orgId,
  8562. Name: statistical_classification,
  8563. FieldName: "",
  8564. Value: classiFicationConfig.Value + 1,
  8565. CreatedTime: "",
  8566. UpdatedTime: "",
  8567. CreateUserId: adminUser.AdminUser.Id,
  8568. Status: 1,
  8569. Remark: "",
  8570. DeleteIdSystem: 0,
  8571. Title: "",
  8572. Content: "",
  8573. Order: 0,
  8574. Code: "",
  8575. }
  8576. service.CreatedDicConfig(&dataconfig)
  8577. }
  8578. }
  8579. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8580. for _, it := range classiFicationList {
  8581. if statistical_classification == it.Name {
  8582. statistical_classification_id = int64(it.Value)
  8583. }
  8584. }
  8585. project.StatisticalClassification = statistical_classification_id
  8586. disease_directory := int64(projectM["disease_directory"].(float64))
  8587. project.DiseaseDirectory = disease_directory
  8588. is_record := int64(projectM["is_record"].(float64))
  8589. project.IsRecord = is_record
  8590. medical_code := projectM["medical_code"].(string)
  8591. project.MedicalCode = medical_code
  8592. tube_color := projectM["tube_color"].(string)
  8593. var tubeColor = "试管颜色"
  8594. var tube_color_id int64
  8595. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8596. if len(tube_color) != 0 {
  8597. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8598. if errcodetube == gorm.ErrRecordNotFound {
  8599. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8600. dataconfig := models.DictDataconfig{
  8601. ParentId: tubeColorConfig.ID,
  8602. Module: "system",
  8603. OrgId: orgId,
  8604. Name: tube_color,
  8605. FieldName: "",
  8606. Value: tubeConfig.Value + 1,
  8607. CreatedTime: "",
  8608. UpdatedTime: "",
  8609. CreateUserId: adminUser.AdminUser.Id,
  8610. Status: 1,
  8611. Remark: "",
  8612. DeleteIdSystem: 0,
  8613. Title: "",
  8614. Content: "",
  8615. Order: 0,
  8616. Code: "",
  8617. }
  8618. service.CreatedDicConfig(&dataconfig)
  8619. }
  8620. }
  8621. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8622. for _, it := range tubeColorList {
  8623. if tube_color == it.Name {
  8624. tube_color_id = int64(it.Value)
  8625. }
  8626. }
  8627. project.TubeColor = tube_color_id
  8628. single_dose := projectM["single_dose"].(string)
  8629. project.SingleDose = single_dose
  8630. execution_frequency := projectM["execution_frequency"].(string)
  8631. project.ExecutionFrequency = execution_frequency
  8632. delivery_way := projectM["delivery_way"].(string)
  8633. project.DeliveryWay = delivery_way
  8634. number_days := projectM["number_days"].(string)
  8635. project.NumberDays = number_days
  8636. total := projectM["total"].(string)
  8637. project.Total = total
  8638. medical_status := int64(projectM["medical_status"].(float64))
  8639. project.MedicalStatus = medical_status
  8640. category := int64(projectM["category"].(float64))
  8641. project.Category = category
  8642. specail_project := int64(projectM["specail_project"].(float64))
  8643. project.SpecailProject = specail_project
  8644. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8645. project.SocialSecurityDirectoryCode = social_security_directory_code
  8646. remark := projectM["remark"].(string)
  8647. project.Remark = remark
  8648. record_date := projectM["record_date"].(string)
  8649. timeLayout := "2006-01-02"
  8650. loc, _ := time.LoadLocation("Local")
  8651. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8652. project.RecordDate = theTime.Unix()
  8653. projectList = append(projectList, &project)
  8654. }
  8655. export_time := time.Now().Unix()
  8656. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8657. if len(projectList) > 0 {
  8658. for _, item := range projectList {
  8659. project := models.HisProject{
  8660. ProjectName: item.ProjectName,
  8661. Price: item.Price,
  8662. Unit: item.Unit,
  8663. CostClassify: item.CostClassify,
  8664. ExecutiveSection: item.ExecutiveSection,
  8665. MedicalCoverage: item.MedicalCoverage,
  8666. UserOrgId: orgId,
  8667. Status: 1,
  8668. CreatedTime: time.Now().Unix(),
  8669. Pinyin: item.Pinyin,
  8670. Wubi: item.Wubi,
  8671. StatisticalClassification: item.StatisticalClassification,
  8672. DiseaseDirectory: item.DiseaseDirectory,
  8673. IsRecord: item.IsRecord,
  8674. MedicalCode: item.MedicalCode,
  8675. TubeColor: item.TubeColor,
  8676. SingleDose: item.SingleDose,
  8677. DeliveryWay: item.DeliveryWay,
  8678. NumberDays: item.NumberDays,
  8679. Total: item.Total,
  8680. Category: item.Category,
  8681. MedicalStatus: item.MedicalStatus,
  8682. SpecailProject: item.SpecailProject,
  8683. RecordDate: item.RecordDate,
  8684. Remark: item.Remark,
  8685. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8686. ExecutionFrequency: item.ExecutionFrequency,
  8687. }
  8688. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8689. if errcodeproject == gorm.ErrRecordNotFound {
  8690. service.CreateProjectInfomation(&project)
  8691. } else if errcodeproject == nil {
  8692. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8693. }
  8694. log := models.ExportLog{
  8695. LogType: 6,
  8696. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8697. TotalNum: int64(len(total_goods)),
  8698. FailNum: int64(len(errLogs)),
  8699. SuccessNum: int64(len(projectList)),
  8700. CreateTime: time.Now().Unix(),
  8701. UpdateTime: time.Now().Unix(),
  8702. ExportTime: export_time,
  8703. Status: 1,
  8704. }
  8705. service.CreateExportLog(&log)
  8706. c.ServeSuccessJSON(map[string]interface{}{
  8707. "msg": "导入成功",
  8708. "total_num": len(total_goods),
  8709. "success_num": len(projectList),
  8710. "fail_num": int64(len(errLogs)),
  8711. })
  8712. }
  8713. } else {
  8714. log := models.ExportLog{
  8715. LogType: 6,
  8716. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8717. TotalNum: int64(len(total_goods)),
  8718. FailNum: int64(len(errLogs)),
  8719. SuccessNum: int64(len(projectList)),
  8720. CreateTime: time.Now().Unix(),
  8721. UpdateTime: time.Now().Unix(),
  8722. ExportTime: export_time,
  8723. Status: 1,
  8724. }
  8725. service.CreateExportLog(&log)
  8726. c.ServeSuccessJSON(map[string]interface{}{
  8727. "msg": "导入成功",
  8728. "total_num": len(total_goods),
  8729. "success_num": len(projectList),
  8730. "fail_num": int64(len(errLogs)),
  8731. })
  8732. }
  8733. }
  8734. //func (this *HisApiController) EditProjectInformation(){
  8735. //
  8736. // id, _ := this.GetInt64("id")
  8737. // project_team := this.GetString("project_team")
  8738. // price := this.GetString("price")
  8739. // price_float, _ := strconv.ParseFloat(price, 64)
  8740. // pinyin := this.GetString("pinyin")
  8741. // wubi := this.GetString("wubi")
  8742. // tube_color, _ := this.GetInt64("tube_color")
  8743. // team_type, _ := this.GetInt64("team_type")
  8744. // remark := this.GetString("remark")
  8745. // ids := this.GetString("ids")
  8746. // item_id := this.GetString("item_id")
  8747. // projectTeam := models.XtHisProjectTeam{
  8748. // ProjectTeam: project_team,
  8749. // Price: price_float,
  8750. // Pinyin: pinyin,
  8751. // Wubi: wubi,
  8752. // TubeColor: tube_color,
  8753. // TeamType: team_type,
  8754. // Remark: remark,
  8755. // ProjectId: ids,
  8756. // ItemId: item_id,
  8757. // }
  8758. //
  8759. //
  8760. // dataBody := make(map[string]interface{}, 0)
  8761. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8762. // if err != nil {
  8763. // utils.ErrorLog(err.Error())
  8764. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8765. // return
  8766. // }
  8767. //
  8768. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8769. //
  8770. //
  8771. // if err != nil {
  8772. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8773. // return
  8774. // }
  8775. //
  8776. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8777. // infos, _ := dataBody["info"].([]interface{})
  8778. // if len(infos) > 0 {
  8779. // var ids []string
  8780. //
  8781. // for _, item := range infos {
  8782. // items := item.(map[string]interface{})
  8783. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8784. // utils.ErrorLog("id")
  8785. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8786. // return
  8787. // }
  8788. // id := int64(items["id"].(float64))
  8789. //
  8790. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8791. // utils.ErrorLog("type")
  8792. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8793. // return
  8794. // }
  8795. // types := int64(items["type"].(float64))
  8796. //
  8797. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8798. // utils.ErrorLog("number")
  8799. // }
  8800. //
  8801. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8802. //
  8803. // projectList := models.XtHisProjectList{
  8804. // Number: number,
  8805. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8806. // ProjectId: id,
  8807. // Status: 1,
  8808. // CreatedTime: time.Now().Unix(),
  8809. // UpdatedTime: time.Now().Unix(),
  8810. // TeamId: projectTeam.ID,
  8811. // Type: types,
  8812. // }
  8813. // list := projectList
  8814. //
  8815. // service.CreateProjectList(&list)
  8816. //
  8817. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8818. //
  8819. // }
  8820. // ids_str := strings.Join(ids, ",")
  8821. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8822. // service.SaveProjectTeam(&projectTeam)
  8823. // this.ServeSuccessJSON(map[string]interface{}{
  8824. // "projectTeam": projectTeam,
  8825. // })
  8826. // }
  8827. // }
  8828. //}
  8829. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8830. name := c.GetString("name")
  8831. mode_id, _ := c.GetInt64("mode", 0)
  8832. types, _ := c.GetInt64("type", 0)
  8833. patient_id, _ := c.GetInt64("patient_id", 0)
  8834. types = 1
  8835. adminInfo := c.GetAdminUserInfo()
  8836. template := &models.HisPrescriptionTemplate{
  8837. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8838. PatientId: patient_id,
  8839. Type: types,
  8840. Status: 1,
  8841. Ctime: time.Now().Unix(),
  8842. Mtime: time.Now().Unix(),
  8843. Name: name,
  8844. Mode: mode_id,
  8845. }
  8846. dataBody := make(map[string]interface{}, 0)
  8847. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8848. if err != nil {
  8849. utils.ErrorLog(err.Error())
  8850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8851. return
  8852. }
  8853. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8854. //如果已经存在记录则删除处方
  8855. if template_one.ID > 0 {
  8856. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8857. for _, item := range ps {
  8858. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8859. }
  8860. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8861. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8862. if len(prescriptions) > 0 {
  8863. for _, item := range prescriptions {
  8864. items := item.(map[string]interface{})
  8865. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8866. utils.ErrorLog("type")
  8867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8868. return
  8869. }
  8870. types := int64(items["type"].(float64))
  8871. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8872. utils.ErrorLog("med_type")
  8873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8874. return
  8875. }
  8876. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8877. ctime := time.Now().Unix()
  8878. prescription := &models.HisPrescriptionInfoTemplate{
  8879. PatientId: patient_id,
  8880. UserOrgId: adminInfo.CurrentOrgId,
  8881. Ctime: ctime,
  8882. Mtime: ctime,
  8883. Type: types,
  8884. Modifier: adminInfo.AdminUser.Id,
  8885. Creator: adminInfo.AdminUser.Id,
  8886. Status: 1,
  8887. PTemplateId: template_one.ID,
  8888. MedType: med_type,
  8889. }
  8890. service.CreateHisPrescriptionInfoTemplate(prescription)
  8891. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8892. advices := items["advices"].([]interface{})
  8893. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8894. ctime := time.Now().Unix()
  8895. mtime := ctime
  8896. if len(advices) > 0 {
  8897. for _, advice := range advices {
  8898. var s models.HisPrescriptionAdviceTemplate
  8899. s.PrescriptionId = prescription.ID
  8900. s.AdviceType = 2
  8901. s.StopState = 2
  8902. s.ExecutionState = 2
  8903. s.Status = 1
  8904. s.UserOrgId = adminInfo.CurrentOrgId
  8905. s.CreatedTime = ctime
  8906. s.UpdatedTime = mtime
  8907. s.PatientId = patient_id
  8908. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8909. if errcode > 0 {
  8910. c.ServeFailJSONWithSGJErrorCode(errcode)
  8911. return
  8912. }
  8913. service.CreateHisPrescriptionAdviceTemplate(&s)
  8914. }
  8915. }
  8916. }
  8917. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8918. projects := items["project"].([]interface{})
  8919. if len(projects) > 0 {
  8920. for _, project := range projects {
  8921. var p models.HisPrescriptionProjectTemplate
  8922. p.PrescriptionId = prescription.ID
  8923. p.Ctime = time.Now().Unix()
  8924. p.Mtime = time.Now().Unix()
  8925. p.PatientId = patient_id
  8926. p.UserOrgId = adminInfo.CurrentOrgId
  8927. p.Status = 1
  8928. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8929. if errcode > 0 {
  8930. c.ServeFailJSONWithSGJErrorCode(errcode)
  8931. return
  8932. }
  8933. service.CreateHisPrescriptionProjectTemplate(&p)
  8934. }
  8935. }
  8936. }
  8937. }
  8938. c.ServeSuccessJSON(map[string]interface{}{
  8939. "msg": "创建成功",
  8940. })
  8941. }
  8942. }
  8943. } else {
  8944. err = service.CreateHisPrescriptionTemplate(template)
  8945. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8946. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8947. if len(prescriptions) > 0 {
  8948. for _, item := range prescriptions {
  8949. items := item.(map[string]interface{})
  8950. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8951. utils.ErrorLog("type")
  8952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8953. return
  8954. }
  8955. types := int64(items["type"].(float64))
  8956. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8957. utils.ErrorLog("med_type")
  8958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8959. return
  8960. }
  8961. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8962. ctime := time.Now().Unix()
  8963. prescription := &models.HisPrescriptionInfoTemplate{
  8964. PatientId: patient_id,
  8965. UserOrgId: adminInfo.CurrentOrgId,
  8966. Ctime: ctime,
  8967. Mtime: ctime,
  8968. Type: types,
  8969. Modifier: adminInfo.AdminUser.Id,
  8970. Creator: adminInfo.AdminUser.Id,
  8971. Status: 1,
  8972. PTemplateId: template.ID,
  8973. MedType: med_type,
  8974. }
  8975. service.CreateHisPrescriptionInfoTemplate(prescription)
  8976. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8977. advices := items["advices"].([]interface{})
  8978. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8979. ctime := time.Now().Unix()
  8980. mtime := ctime
  8981. if len(advices) > 0 {
  8982. for _, advice := range advices {
  8983. var s models.HisPrescriptionAdviceTemplate
  8984. s.PrescriptionId = prescription.ID
  8985. s.AdviceType = 2
  8986. s.StopState = 2
  8987. s.ExecutionState = 2
  8988. s.Status = 1
  8989. s.UserOrgId = adminInfo.CurrentOrgId
  8990. s.CreatedTime = ctime
  8991. s.UpdatedTime = mtime
  8992. s.PatientId = patient_id
  8993. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8994. if errcode > 0 {
  8995. c.ServeFailJSONWithSGJErrorCode(errcode)
  8996. return
  8997. }
  8998. service.CreateHisPrescriptionAdviceTemplate(&s)
  8999. }
  9000. }
  9001. }
  9002. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9003. projects := items["project"].([]interface{})
  9004. if len(projects) > 0 {
  9005. for _, project := range projects {
  9006. var p models.HisPrescriptionProjectTemplate
  9007. p.PrescriptionId = prescription.ID
  9008. p.Ctime = time.Now().Unix()
  9009. p.Mtime = time.Now().Unix()
  9010. p.PatientId = patient_id
  9011. p.UserOrgId = adminInfo.CurrentOrgId
  9012. p.Status = 1
  9013. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9014. if errcode > 0 {
  9015. c.ServeFailJSONWithSGJErrorCode(errcode)
  9016. return
  9017. }
  9018. service.CreateHisPrescriptionProjectTemplate(&p)
  9019. }
  9020. }
  9021. }
  9022. }
  9023. c.ServeSuccessJSON(map[string]interface{}{
  9024. "msg": "创建成功",
  9025. })
  9026. }
  9027. }
  9028. }
  9029. }
  9030. func (c *HisApiController) PreSettle() {
  9031. id, _ := c.GetInt64("id")
  9032. record_time := c.GetString("record_time")
  9033. his_patient_id, _ := c.GetInt64("his_patient_id")
  9034. timeLayout := "2006-01-02"
  9035. loc, _ := time.LoadLocation("Local")
  9036. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9037. diagnosis_id := c.GetString("diagnosis")
  9038. sick_type, _ := c.GetInt64("sick_type")
  9039. reg_type, _ := c.GetInt64("p_type")
  9040. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9041. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9042. if err != nil {
  9043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9044. return
  9045. }
  9046. recordDateTime := theTime.Unix()
  9047. adminUser := c.GetAdminUserInfo()
  9048. var prescriptions []*models.HisPrescription
  9049. var start_time int64
  9050. var end_time int64
  9051. ids_str := c.GetString("ids")
  9052. ids_arr := strings.Split(ids_str, ",")
  9053. fmt.Println(reg_type)
  9054. if settle_accounts_type == 1 { //日结
  9055. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9056. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9057. } else {
  9058. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9059. }
  9060. fmt.Println(prescriptions)
  9061. } else { //月结
  9062. start_time_str := c.GetString("start_time")
  9063. end_time_str := c.GetString("end_time")
  9064. timeLayout := "2006-01-02"
  9065. loc, _ := time.LoadLocation("Local")
  9066. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9067. if err != nil {
  9068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9069. return
  9070. }
  9071. recordStartTime := theStartTime.Unix()
  9072. start_time = recordStartTime
  9073. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9074. if err != nil {
  9075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9076. return
  9077. }
  9078. recordEndTime := theEndTime.Unix()
  9079. end_time = recordEndTime
  9080. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9081. }
  9082. if reg_type == 1111 || reg_type == 1112 {
  9083. reg_type = 11
  9084. }
  9085. timestamp := time.Now().Unix()
  9086. tempTime := time.Unix(timestamp, 0)
  9087. timeFormat := tempTime.Format("20060102150405")
  9088. chrgBchno := rand.Intn(100000) + 10000
  9089. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9090. strconv.FormatInt(his.PatientId, 10)
  9091. var ids []int64
  9092. for _, item := range prescriptions {
  9093. ids = append(ids, item.ID)
  9094. }
  9095. fmt.Println(ids)
  9096. var total float64
  9097. for _, item := range prescriptions {
  9098. fmt.Println(item)
  9099. if item.Type == 1 { //药品
  9100. for _, subItem := range item.HisDoctorAdviceInfo {
  9101. total = total + (subItem.Price * subItem.PrescribingNumber)
  9102. }
  9103. }
  9104. if item.Type == 2 { //项目
  9105. for _, subItem := range item.HisPrescriptionProject {
  9106. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9107. total = total + (subItem.Price * cnt)
  9108. }
  9109. }
  9110. for _, subItem := range item.HisAdditionalCharge {
  9111. total = total + (subItem.Price * float64(subItem.Count))
  9112. }
  9113. }
  9114. allTotal := fmt.Sprintf("%.2f", total)
  9115. totals, _ := strconv.ParseFloat(allTotal, 64)
  9116. order := &models.HisOrder{
  9117. UserOrgId: adminUser.CurrentOrgId,
  9118. HisPatientId: his.ID,
  9119. PatientId: id,
  9120. SettleAccountsDate: recordDateTime,
  9121. Ctime: time.Now().Unix(),
  9122. Mtime: time.Now().Unix(),
  9123. Status: 1,
  9124. OrderStatus: 1,
  9125. MdtrtId: his.Number,
  9126. Number: chrg_bchno,
  9127. MedfeeSumamt: totals,
  9128. SettleEndTime: end_time,
  9129. SettleStartTime: start_time,
  9130. SettleType: settle_accounts_type,
  9131. PsnPartAmt: totals,
  9132. PsnCashPay: totals,
  9133. PType: 2,
  9134. IsPre: 1,
  9135. MedType: strconv.Itoa(int(reg_type)),
  9136. Diagnosis: diagnosis_id,
  9137. }
  9138. err = service.CreateOrder(order)
  9139. if err != nil {
  9140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9141. return
  9142. }
  9143. var customs []*Custom
  9144. for _, item := range prescriptions {
  9145. fmt.Println(item.Type)
  9146. if item.Type == 1 { //药品
  9147. for _, subItem := range item.HisDoctorAdviceInfo {
  9148. cus := &Custom{
  9149. AdviceId: subItem.ID,
  9150. ProjectId: 0,
  9151. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9152. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9153. FeedetlSn: subItem.FeedetlSn,
  9154. Price: fmt.Sprintf("%.2f", subItem.Price),
  9155. MedListCodg: subItem.MedListCodg,
  9156. Type: 1,
  9157. }
  9158. customs = append(customs, cus)
  9159. }
  9160. }
  9161. if item.Type == 2 { //项目
  9162. for _, subItem := range item.HisPrescriptionProject {
  9163. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9164. cus := &Custom{
  9165. AdviceId: 0,
  9166. ProjectId: subItem.ID,
  9167. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9168. Cut: fmt.Sprintf("%.2f", cnt),
  9169. FeedetlSn: subItem.FeedetlSn,
  9170. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9171. MedListCodg: subItem.MedListCodg,
  9172. Type: 2,
  9173. }
  9174. customs = append(customs, cus)
  9175. }
  9176. }
  9177. for _, item := range item.HisAdditionalCharge {
  9178. cus := &Custom{
  9179. ItemId: item.ID,
  9180. AdviceId: 0,
  9181. ProjectId: 0,
  9182. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9183. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9184. FeedetlSn: item.FeedetlSn,
  9185. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9186. MedListCodg: item.XtHisAddtionConfig.Code,
  9187. Type: 3,
  9188. }
  9189. customs = append(customs, cus)
  9190. }
  9191. }
  9192. fmt.Println(customs)
  9193. for _, item := range customs {
  9194. var advice_id int64 = 0
  9195. var project_id int64 = 0
  9196. var item_id int64 = 0
  9197. var types int64 = 0
  9198. if item.Type == 1 {
  9199. advice_id = item.AdviceId
  9200. project_id = 0
  9201. item_id = 0
  9202. } else if item.Type == 2 {
  9203. advice_id = 0
  9204. item_id = 0
  9205. project_id = item.ProjectId
  9206. } else if item.Type == 3 {
  9207. advice_id = 0
  9208. item_id = item.ItemId
  9209. project_id = 0
  9210. }
  9211. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9212. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9213. pric, _ := strconv.ParseFloat(item.Price, 32)
  9214. info := &models.HisOrderInfo{
  9215. OrderNumber: order.Number,
  9216. UploadDate: time.Now().Unix(),
  9217. AdviceId: advice_id,
  9218. DetItemFeeSumamt: detItemFeeSumamt,
  9219. Cnt: cut,
  9220. Pric: pric,
  9221. PatientId: id,
  9222. Status: 1,
  9223. Mtime: time.Now().Unix(),
  9224. Ctime: time.Now().Unix(),
  9225. UserOrgId: adminUser.CurrentOrgId,
  9226. HisPatientId: his.ID,
  9227. OrderId: order.ID,
  9228. ProjectId: project_id,
  9229. Type: types,
  9230. ItemId: item_id,
  9231. }
  9232. service.CreateOrderInfo(info)
  9233. }
  9234. his.SickType = sick_type
  9235. service.UpdataHisPateint(&his)
  9236. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9237. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9238. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9239. if err == nil {
  9240. c.ServeSuccessJSON(map[string]interface{}{
  9241. "msg": "结算成功",
  9242. })
  9243. }
  9244. }
  9245. type CustomOrderInfo struct {
  9246. Name string
  9247. Spec string
  9248. Unit string
  9249. Count float64
  9250. Price float64
  9251. Total float64
  9252. }
  9253. func (c *HisApiController) GetPrivateExpensesInfo() {
  9254. order_id, _ := c.GetInt64("id", 0)
  9255. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9256. order, _ := service.GetHisOrderByID(order_id)
  9257. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9258. if order.ID == 0 {
  9259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9260. return
  9261. }
  9262. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9263. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9264. org_id := c.GetAdminUserInfo().CurrentOrgId
  9265. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9266. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9267. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9268. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9269. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9270. //var orderInfos_four []*models.HisOrderInfoTwo
  9271. //for _, item := range orderInfos_three {
  9272. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9273. // item.HisPrescriptionProject.IsCheckTeam = 1
  9274. // orderInfos_four = append(orderInfos_four, item)
  9275. //
  9276. // }
  9277. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9278. // item.HisPrescriptionProject.IsCheckTeam = 2
  9279. // orderInfos_two = append(orderInfos_two, item)
  9280. // }
  9281. //}
  9282. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9283. //var cus_slice []CustomOrderInfo
  9284. //for _, item := range new_order_info {
  9285. // var cus CustomOrderInfo
  9286. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9287. // cus.Unit = ""
  9288. // cus.Spec = ""
  9289. // var total float64
  9290. // for _, subItem := range orderInfos_four {
  9291. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9292. // total = total + subItem.DetItemFeeSumamt
  9293. // fmt.Println(subItem.DetItemFeeSumamt)
  9294. // }
  9295. // }
  9296. // cus.Count = 1
  9297. // cus.Total = total
  9298. // cus_slice = append(cus_slice, cus)
  9299. //}
  9300. orderInfos = append(orderInfos, orderInfos_two...)
  9301. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9302. //orderInfos = append(orderInfos, orderInfos_three...)
  9303. //}/**/
  9304. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9305. c.ServeSuccessJSON(map[string]interface{}{
  9306. "order": order,
  9307. "order_info": orderInfos,
  9308. "patient": patient,
  9309. "admin_info": adminInfo,
  9310. "his": his,
  9311. "current_admin": role,
  9312. "org_config": miConfig,
  9313. //"new_order_info": cus_slice,
  9314. })
  9315. }
  9316. func (this *HisApiController) ChangeMedType() {
  9317. med_type := this.GetString("med_type")
  9318. old_med_type := this.GetString("old_med_type")
  9319. ids := this.GetString("ids")
  9320. settle_type, _ := this.GetInt64("settle_type")
  9321. start_time := this.GetString("start_time")
  9322. end_time := this.GetString("end_time")
  9323. ids_arr := strings.Split(ids, ",")
  9324. if settle_type == 1 { //日结
  9325. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9326. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9327. prescription.MedType = med_type
  9328. err := service.SaveHisPrescription(&prescription)
  9329. if err == nil {
  9330. this.ServeSuccessJSON(map[string]interface{}{
  9331. "msg": "修改成功",
  9332. })
  9333. } else {
  9334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9335. return
  9336. }
  9337. } else if settle_type == 2 {
  9338. timeLayout := "2006-01-02"
  9339. loc, _ := time.LoadLocation("Local")
  9340. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9341. if err != nil {
  9342. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9343. return
  9344. }
  9345. recordStartTime := theStartTime.Unix()
  9346. start_time_timestamp := recordStartTime
  9347. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9348. if err != nil {
  9349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9350. return
  9351. }
  9352. recordEndTime := theEndTime.Unix()
  9353. end_time_timestamp := recordEndTime
  9354. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9355. if updateErr == nil {
  9356. this.ServeSuccessJSON(map[string]interface{}{
  9357. "msg": "修改成功",
  9358. })
  9359. } else {
  9360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9361. return
  9362. }
  9363. }
  9364. }
  9365. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9366. patient_id, _ := c.GetInt64("patient_id")
  9367. his_patient_id, _ := c.GetInt64("his_patient_id")
  9368. record_date := c.GetString("record_date")
  9369. start_time := c.GetString("start_time")
  9370. end_time := c.GetString("end_time")
  9371. order_status, _ := c.GetInt64("type", 0)
  9372. p_type, _ := c.GetInt64("p_type", 0)
  9373. order_id, _ := c.GetInt64("order_id", 0)
  9374. timeLayout := "2006-01-02"
  9375. loc, _ := time.LoadLocation("Local")
  9376. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9377. if err != nil {
  9378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9379. return
  9380. }
  9381. recordDateTime := theTime.Unix()
  9382. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9383. if err != nil {
  9384. }
  9385. startRecordDateTime := startTime.Unix()
  9386. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9387. if err != nil {
  9388. }
  9389. endRecordDateTime := endTime.Unix()
  9390. admin := c.GetAdminUserInfo()
  9391. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9392. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9393. order, _ := service.GetHisOrderByID(order_id)
  9394. var monthPrescriptions []*models.HisPrescription
  9395. if order_status == 1 || order_status == 0 {
  9396. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9397. } else if order_status == 2 {
  9398. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9399. }
  9400. var settle_total float64
  9401. for _, item := range monthPrescriptions {
  9402. if len(item.HisPrescriptionProject) > 0 {
  9403. for _, subItem := range item.HisPrescriptionProject {
  9404. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9405. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9406. settle_total = settle_total + total
  9407. }
  9408. }
  9409. if len(item.HisDoctorAdviceInfo) > 0 {
  9410. for _, subItem := range item.HisDoctorAdviceInfo {
  9411. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9412. settle_total = settle_total + total
  9413. }
  9414. }
  9415. }
  9416. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9417. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9418. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9419. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9420. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9421. //获取所有科室信息
  9422. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9423. c.ServeSuccessJSON(map[string]interface{}{
  9424. "his_info": his_patient_info,
  9425. "xt_info": xt_patient_info,
  9426. "case_history": case_history,
  9427. "info": patientPrescriptionInfo,
  9428. "last_info": lastPatientPrescriptionInfo,
  9429. "month_prescriptions": monthPrescriptions,
  9430. "order": order,
  9431. "doctors": doctors,
  9432. "department": department,
  9433. "settle_total": settle_total,
  9434. })
  9435. return
  9436. }
  9437. func (c *HisApiController) GetHisMonthPatientInfo() {
  9438. patient_id, _ := c.GetInt64("patient_id")
  9439. his_patient_id, _ := c.GetInt64("his_patient_id")
  9440. record_date := c.GetString("record_date")
  9441. number := c.GetString("number")
  9442. start_time := c.GetString("start_time")
  9443. end_time := c.GetString("end_time")
  9444. p_type, _ := c.GetInt64("p_type")
  9445. timeLayout := "2006-01-02"
  9446. loc, _ := time.LoadLocation("Local")
  9447. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9448. if err != nil {
  9449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9450. return
  9451. }
  9452. recordDateTime := theTime.Unix()
  9453. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9454. if err != nil {
  9455. }
  9456. startRecordDateTime := startTime.Unix()
  9457. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9458. if err != nil {
  9459. }
  9460. endRecordDateTime := endTime.Unix()
  9461. admin := c.GetAdminUserInfo()
  9462. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9463. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9464. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9465. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9466. var settle_total float64
  9467. for _, item := range monthPrescriptions {
  9468. if len(item.HisPrescriptionProject) > 0 {
  9469. for _, subItem := range item.HisPrescriptionProject {
  9470. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9471. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9472. settle_total = settle_total + total
  9473. }
  9474. }
  9475. if len(item.HisDoctorAdviceInfo) > 0 {
  9476. for _, subItem := range item.HisDoctorAdviceInfo {
  9477. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9478. settle_total = settle_total + total
  9479. }
  9480. }
  9481. }
  9482. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9483. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9484. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9485. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9486. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9487. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9488. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9489. //获取所有科室信息
  9490. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9491. c.ServeSuccessJSON(map[string]interface{}{
  9492. "his_info": his_patient_info,
  9493. "xt_info": xt_patient_info,
  9494. "case_history": case_history,
  9495. "info": patientPrescriptionInfo,
  9496. "month_prescriptions": monthPrescriptions,
  9497. "order": order,
  9498. "doctors": doctors,
  9499. "department": department,
  9500. "count": count,
  9501. "drugStockConfig": drugStockConfig,
  9502. "last_info": lastPatientPrescriptionInfo,
  9503. "settle_total": settle_total,
  9504. })
  9505. return
  9506. }
  9507. func (c *HisApiController) GetAllOrder() {
  9508. org_id := c.GetAdminUserInfo().CurrentOrgId
  9509. orders, _ := service.GetNewHisOrderList(org_id)
  9510. c.ServeSuccessJSON(map[string]interface{}{
  9511. "order": orders,
  9512. })
  9513. return
  9514. }
  9515. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9516. newArr = make([]*models.HisOrderInfoTwo, 0)
  9517. for i := 0; i < len(arr); i++ {
  9518. repeat := false
  9519. for j := i + 1; j < len(arr); j++ {
  9520. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9521. repeat = true
  9522. break
  9523. }
  9524. }
  9525. if !repeat {
  9526. newArr = append(newArr, arr[i])
  9527. }
  9528. }
  9529. return
  9530. }
  9531. // 修改处方退库操作 参数传修改之前的处方数据
  9532. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9533. if advice.ExecutionState == 1 {
  9534. //查询该病人该药品是否有库存记录
  9535. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9536. if errcode == gorm.ErrRecordNotFound {
  9537. } else {
  9538. //退库
  9539. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9540. if advice.PrescribingNumberUnit == drug.MinUnit {
  9541. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9542. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9543. //退库
  9544. warehouseInfo := models.DrugWarehouseInfo{
  9545. StockMinNumber: prescribingNumber,
  9546. }
  9547. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9548. operation_time := time.Now().Unix()
  9549. creater := advice.AdviceDoctor
  9550. ctime := time.Now().Unix()
  9551. timeStr := time.Now().Format("2006-01-02")
  9552. timeArr := strings.Split(timeStr, "-")
  9553. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9554. total = total + 1
  9555. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9556. cancelStock := models.DrugCancelStock{
  9557. OrderNumber: orderNumber,
  9558. OperaTime: operation_time,
  9559. OrgId: advice.UserOrgId,
  9560. Creater: creater,
  9561. Ctime: ctime,
  9562. Status: 1,
  9563. ReturnTime: advice.AdviceDate,
  9564. Dealer: info.Dealer,
  9565. Manufacturer: info.Manufacturer,
  9566. Type: 1,
  9567. }
  9568. service.AddSigleDrugCancelStock(&cancelStock)
  9569. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9570. dealer, _ := service.GetDealerById(info.Dealer)
  9571. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9572. cancelStockInfo := models.DrugCancelStockInfo{
  9573. OrderNumber: cancelInfo.OrderNumber,
  9574. CancelStockId: cancelInfo.ID,
  9575. DrugId: info.DrugId,
  9576. Count: info.Count,
  9577. Status: 1,
  9578. Ctime: ctime,
  9579. OrgId: advice.UserOrgId,
  9580. Type: 1,
  9581. Manufacturer: manufactureName.ManufacturerName,
  9582. Dealer: dealer.DealerName,
  9583. Total: 0,
  9584. RetailPrice: info.RetailPrice,
  9585. RetailTotalPrice: info.RetailTotalPrice,
  9586. Price: info.Price,
  9587. RegisterAccount: "",
  9588. Remark: info.Remark,
  9589. BatchNumber: info.BatchNumber,
  9590. MaxUnit: info.CountUnit,
  9591. ProductDate: info.ProductDate,
  9592. ExpiryDate: info.ExpiryDate,
  9593. BatchNumberId: info.WarehouseInfoId,
  9594. }
  9595. flow := models.DrugFlow{
  9596. WarehousingId: 0,
  9597. DrugId: info.DrugId,
  9598. Number: "",
  9599. BatchNumber: info.BatchNumber,
  9600. Count: info.Count,
  9601. UserOrgId: advice.UserOrgId,
  9602. PatientId: 0,
  9603. SystemTime: ctime,
  9604. ConsumableType: 4,
  9605. IsSys: 0,
  9606. WarehousingOrder: "",
  9607. WarehouseOutId: 0,
  9608. WarehouseOutOrderNumber: "",
  9609. IsEdit: 0,
  9610. CancelStockId: cancelStock.ID,
  9611. CancelOrderNumber: cancelStock.OrderNumber,
  9612. Manufacturer: info.Manufacturer,
  9613. Dealer: info.Dealer,
  9614. Creator: advice.UserOrgId,
  9615. UpdateCreator: 0,
  9616. Status: 1,
  9617. Ctime: time.Now().Unix(),
  9618. Mtime: 0,
  9619. Price: info.Price,
  9620. WarehousingDetailId: 0,
  9621. WarehouseOutDetailId: 0,
  9622. CancelOutDetailId: 0,
  9623. ExpireDate: info.ExpiryDate,
  9624. ProductDate: info.ProductDate,
  9625. MaxUnit: info.CountUnit,
  9626. MinUnit: "",
  9627. }
  9628. service.CreatedCancelStock(cancelStockInfo)
  9629. service.CreateDrugFlowOne(flow)
  9630. } else {
  9631. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9632. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9633. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9634. warehouseInfo := models.DrugWarehouseInfo{
  9635. StockMinNumber: prescribingNumber,
  9636. }
  9637. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9638. }
  9639. operation_time := time.Now().Unix()
  9640. creater := advice.AdviceDoctor
  9641. ctime := time.Now().Unix()
  9642. timeStr := time.Now().Format("2006-01-02")
  9643. timeArr := strings.Split(timeStr, "-")
  9644. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9645. total = total + 1
  9646. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9647. cancelStock := models.DrugCancelStock{
  9648. OrderNumber: orderNumber,
  9649. OperaTime: operation_time,
  9650. OrgId: advice.UserOrgId,
  9651. Creater: creater,
  9652. Ctime: ctime,
  9653. Status: 1,
  9654. ReturnTime: advice.AdviceDate,
  9655. Dealer: info.Dealer,
  9656. Manufacturer: info.Manufacturer,
  9657. Type: 1,
  9658. }
  9659. service.AddSigleDrugCancelStock(&cancelStock)
  9660. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9661. dealer, _ := service.GetDealerById(info.Dealer)
  9662. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9663. cancelStockInfo := models.DrugCancelStockInfo{
  9664. OrderNumber: cancelInfo.OrderNumber,
  9665. CancelStockId: cancelInfo.ID,
  9666. DrugId: info.DrugId,
  9667. Count: info.Count,
  9668. Status: 1,
  9669. Ctime: ctime,
  9670. OrgId: advice.UserOrgId,
  9671. Type: 1,
  9672. Manufacturer: manufactureName.ManufacturerName,
  9673. Dealer: dealer.DealerName,
  9674. Total: 0,
  9675. RetailPrice: info.RetailPrice,
  9676. RetailTotalPrice: info.RetailTotalPrice,
  9677. Price: info.Price,
  9678. RegisterAccount: "",
  9679. Remark: info.Remark,
  9680. BatchNumber: info.BatchNumber,
  9681. MaxUnit: info.CountUnit,
  9682. ProductDate: info.ProductDate,
  9683. ExpiryDate: info.ExpiryDate,
  9684. BatchNumberId: info.WarehouseInfoId,
  9685. }
  9686. flow := models.DrugFlow{
  9687. WarehousingId: 0,
  9688. DrugId: info.DrugId,
  9689. Number: "",
  9690. BatchNumber: info.BatchNumber,
  9691. Count: info.Count,
  9692. UserOrgId: advice.UserOrgId,
  9693. PatientId: 0,
  9694. SystemTime: ctime,
  9695. ConsumableType: 4,
  9696. IsSys: 0,
  9697. WarehousingOrder: "",
  9698. WarehouseOutId: 0,
  9699. WarehouseOutOrderNumber: "",
  9700. IsEdit: 0,
  9701. CancelStockId: cancelStock.ID,
  9702. CancelOrderNumber: cancelStock.OrderNumber,
  9703. Manufacturer: info.Manufacturer,
  9704. Dealer: info.Dealer,
  9705. Creator: advice.AdviceDoctor,
  9706. UpdateCreator: 0,
  9707. Status: 1,
  9708. Ctime: time.Now().Unix(),
  9709. Mtime: 0,
  9710. Price: info.Price,
  9711. WarehousingDetailId: 0,
  9712. WarehouseOutDetailId: 0,
  9713. CancelOutDetailId: 0,
  9714. ExpireDate: info.ExpiryDate,
  9715. ProductDate: info.ProductDate,
  9716. MaxUnit: info.CountUnit,
  9717. MinUnit: "",
  9718. }
  9719. service.CreatedCancelStock(cancelStockInfo)
  9720. service.CreateDrugFlowOne(flow)
  9721. }
  9722. }
  9723. }
  9724. return err
  9725. }
  9726. func (this *HisApiController) DeleteNCDS() {
  9727. id, _ := this.GetInt64("id", 0)
  9728. if id > 0 {
  9729. service.DeletePsnNCDSRecordById(id)
  9730. this.ServeSuccessJSON(map[string]interface{}{
  9731. "msg": "删除成功",
  9732. })
  9733. } else {
  9734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9735. return
  9736. }
  9737. }
  9738. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9739. id, _ := c.GetInt64("id")
  9740. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9741. c.ServeSuccessJSON(map[string]interface{}{
  9742. "advice": advice,
  9743. })
  9744. return
  9745. }
  9746. func (c *HisApiController) GetHisMonthChargePatientList() {
  9747. record_date := c.GetString("record_date")
  9748. start_time := c.GetString("start_time")
  9749. end_time := c.GetString("end_time")
  9750. timeLayout := "2006-01-02"
  9751. loc, _ := time.LoadLocation("Local")
  9752. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9753. if err != nil {
  9754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9755. return
  9756. }
  9757. if err != nil {
  9758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9759. return
  9760. }
  9761. recordDateTime := theTime.Unix()
  9762. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9763. if err != nil {
  9764. }
  9765. startRecordDateTime := startTime.Unix()
  9766. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9767. if err != nil {
  9768. }
  9769. endRecordDateTime := endTime.Unix()
  9770. adminInfo := c.GetAdminUserInfo()
  9771. var tempMonthChargePatients []*service.MonthChargePatients
  9772. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9773. for _, item := range tempPatients {
  9774. //过滤没有处方的
  9775. if len(item.HisPrescription) == 0 {
  9776. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9777. }
  9778. }
  9779. c.ServeSuccessJSON(map[string]interface{}{
  9780. "list": tempMonthChargePatients,
  9781. })
  9782. }