his_api_controller.go 296KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862
  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. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  540. } else { //门诊
  541. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  542. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  543. }
  544. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  545. if sch.ID > 0 {
  546. var week string
  547. t := time.Now()
  548. switch t.Weekday().String() {
  549. case "Monday":
  550. week = "周一"
  551. break
  552. case "Tuesday":
  553. week = "周二"
  554. break
  555. case "Wednesday":
  556. week = "周三"
  557. break
  558. case "Thursday":
  559. week = "周四"
  560. break
  561. case "Friday":
  562. week = "周五"
  563. break
  564. case "Saturday":
  565. week = "周六"
  566. break
  567. case "Sunday":
  568. week = "周日"
  569. break
  570. }
  571. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  572. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  573. //根据推送频率组装新的数组
  574. for _, item := range temp_sch_prescriptions {
  575. var cus CustomTemplate
  576. cus.ID = item.ID
  577. cus.UserOrgId = item.UserOrgId
  578. cus.PatientId = item.PatientId
  579. cus.MedType = item.MedType
  580. cus.RecordDate = item.RecordDate
  581. cus.Type = item.Type
  582. cus.PType = item.PType
  583. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  584. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  585. if subItem.FrequencyType == 1 { //每次必推
  586. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  587. }
  588. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  589. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  590. }
  591. if subItem.FrequencyType == 2 { //按照天数频率
  592. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  593. now := p.Unix()
  594. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  595. dayStr2 := "-" + dayStr
  596. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  597. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  598. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  599. if len(advices) == 0 {
  600. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  601. }
  602. }
  603. }
  604. }
  605. for _, subItem := range item.HisPrescriptionProjectTemplate {
  606. if subItem.Type == 2 {
  607. if subItem.XtHisProject.MedicalStatus != 1 {
  608. if subItem.FrequencyType == 1 {
  609. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  610. }
  611. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  612. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  613. }
  614. if subItem.FrequencyType == 2 {
  615. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  616. now := p.Unix()
  617. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  618. dayStr2 := "-" + dayStr
  619. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  620. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  621. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  622. if len(projects) == 0 {
  623. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  624. }
  625. }
  626. }
  627. } else if subItem.Type == 3 {
  628. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  629. if subItem.FrequencyType == 1 {
  630. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  631. }
  632. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  633. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  634. }
  635. if subItem.FrequencyType == 2 {
  636. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  637. now := p.Unix()
  638. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  639. dayStr2 := "-" + dayStr
  640. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  641. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  642. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  643. if len(projects) == 0 {
  644. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  645. }
  646. }
  647. }
  648. }
  649. }
  650. sch_prescriptions = append(sch_prescriptions, cus)
  651. }
  652. for _, item := range sch_prescriptions {
  653. if len(item.HisPrescriptionProjectTemplate) == 0 {
  654. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  655. }
  656. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  657. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  658. }
  659. }
  660. }
  661. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  662. if config.ID > 0 && config.IsOpen == 1 {
  663. for _, item := range sch_prescriptions {
  664. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  665. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  666. if info.RetailPrice > 0 {
  667. subItem.Drug.MinPrice = info.RetailPrice
  668. }
  669. }
  670. }
  671. }
  672. if config.ID > 0 && config.IsOpen == 1 {
  673. for _, item := range sch_prescriptions {
  674. for _, subItem := range item.HisPrescriptionProjectTemplate {
  675. if subItem.Type == 3 {
  676. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  677. if info.Price > 0 {
  678. subItem.GoodInfo.PackingPrice = info.Price
  679. }
  680. }
  681. }
  682. }
  683. }
  684. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  685. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  686. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  687. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  688. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  689. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  691. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  692. //获取所有科室信息
  693. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "his_info": his_patient_info,
  696. "xt_info": xt_patient_info,
  697. "prescription": prescriptions,
  698. "case_history": case_history,
  699. "info": patientPrescriptionInfo,
  700. //"month_prescriptions": monthPrescriptions,
  701. "order": order,
  702. "doctors": doctors,
  703. "department": department,
  704. "sch_prescriptions": sch_prescriptions,
  705. "last_prescriptions": last_prescriptions,
  706. "schedule": sch,
  707. "count": count,
  708. "drugStockConfig": drugStockConfig,
  709. "last_info": lastPatientPrescriptionInfo,
  710. })
  711. return
  712. }
  713. func (c *HisApiController) GetHisPrescriptionConfig() {
  714. adminInfo := c.GetAdminUserInfo()
  715. //获取医嘱模版
  716. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  717. //获取所有基础药
  718. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  719. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  720. if config.ID > 0 && config.IsOpen == 1 {
  721. for _, item := range drugs {
  722. var index = 0
  723. for _, subItem := range item.OtherDrugWarehouseInfo {
  724. if index == 0 {
  725. index = index + 1
  726. if subItem.RetailPrice > 0 {
  727. item.MinPrice = subItem.RetailPrice
  728. }
  729. }
  730. }
  731. }
  732. }
  733. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  734. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  735. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  736. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  737. //获取所有科室信息
  738. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  739. //获取诊断信息
  740. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  741. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  742. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  743. c.ServeSuccessJSON(map[string]interface{}{
  744. "drugs": drugs,
  745. "advices_template": advices,
  746. "drugways": drugways,
  747. "efs": efs,
  748. "doctors": doctors,
  749. "department": department,
  750. "sick": sick,
  751. "additions": additions,
  752. "diagnose": diagnose,
  753. "manufacturers": manufacturers,
  754. })
  755. }
  756. func (c *HisApiController) CreateHisPrescription() {
  757. record_date := c.GetString("record_date")
  758. patient_id, _ := c.GetInt64("patient_id")
  759. reg_type, _ := c.GetInt64("reg_type")
  760. diagnose := c.GetString("diagnose")
  761. sick_type, _ := c.GetInt64("sick_type")
  762. sick_history := c.GetString("sick_history")
  763. doctor_id, _ := c.GetInt64("doctor", 0)
  764. department, _ := c.GetInt64("department", 0)
  765. his_patient_id, _ := c.GetInt64("his_patient_id")
  766. p_type, _ := c.GetInt64("p_type")
  767. dataBody := make(map[string]interface{}, 0)
  768. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  769. if err != nil {
  770. utils.ErrorLog(err.Error())
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. timeLayout := "2006-01-02"
  775. loc, _ := time.LoadLocation("Local")
  776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  777. if err != nil {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. adminInfo := c.GetAdminUserInfo()
  782. recordDateTime := theTime.Unix()
  783. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  784. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  785. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  786. if len(lists) == 1 {
  787. his_patient_id = lists[0].ID
  788. }
  789. }
  790. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  791. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  792. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  793. if drugStockConfig.IsOpen == 1 {
  794. //校验库存总量
  795. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  796. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  797. if len(prescriptions) > 0 {
  798. for _, item := range prescriptions {
  799. items := item.(map[string]interface{})
  800. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  801. advices := items["advices"].([]interface{})
  802. if len(advices) > 0 {
  803. for _, advice := range advices {
  804. var drug_id int64
  805. var prescribing_number float64
  806. var prescribingNumberUnit string
  807. var prescribingNumber string
  808. var adviceId int64
  809. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  810. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  811. }
  812. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  813. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  814. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  815. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  816. }
  817. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  818. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  819. }
  820. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  821. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  822. }
  823. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  824. if drug.ID == 0 {
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. //查询药品的所有库存
  829. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  830. var total_count int64
  831. for _, it := range list {
  832. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  833. }
  834. totals := strconv.FormatInt(total_count, 10)
  835. //查询该药品是否存在开药记录
  836. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  837. //新增处方
  838. if advicelist.ID == 0 {
  839. all_count, _ := strconv.ParseFloat(totals, 64)
  840. if prescribingNumberUnit == drug.MinUnit {
  841. if prescribing_number > all_count {
  842. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  843. return
  844. }
  845. } else {
  846. if prescribingNumberUnit == drug.MaxUnit {
  847. num := prescribing_number * float64(drug.MinNumber)
  848. if num > all_count {
  849. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  850. return
  851. }
  852. }
  853. }
  854. }
  855. //修改处方
  856. if advicelist.ID > 0 {
  857. var device_number int64
  858. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  859. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  860. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  861. device_number = prescribingNumberInt * drug.MinNumber
  862. }
  863. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  864. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  865. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  866. device_number = prescribingNumberInt
  867. }
  868. var number_count int64
  869. if prescribingNumberUnit == drug.MaxUnit {
  870. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  871. number_count = prescribingNumberInt * drug.MinNumber
  872. }
  873. if prescribingNumberUnit == drug.MinUnit {
  874. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  875. number_count = prescribingNumberInt
  876. }
  877. //如果修改的数量大于之前修改的数量
  878. if (number_count - device_number) > 0 {
  879. //如果修改的差数量 大于库存数量
  880. if (number_count - device_number) > total_count {
  881. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  882. return
  883. }
  884. }
  885. if device_number != number_count {
  886. // 查询该药品最后一次出库记录
  887. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  888. //回退库存
  889. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  890. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  891. }
  892. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  893. var stock_max_number int64
  894. var stock_min_number int64
  895. if number_count >= drug.MinNumber {
  896. stock_max_number = device_number / drug.MinNumber
  897. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  898. stock_min_number = device_number % drug.MinNumber
  899. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  900. } else {
  901. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  902. }
  903. }
  904. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  905. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  906. }
  907. //删除记录
  908. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  909. }
  910. }
  911. }
  912. }
  913. }
  914. }
  915. }
  916. }
  917. }
  918. if stockConfig.IsOpen == 1 {
  919. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  920. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  921. if len(prescriptions) > 0 {
  922. for _, item := range prescriptions {
  923. items := item.(map[string]interface{})
  924. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  925. projects := items["project"].([]interface{})
  926. if len(projects) > 0 {
  927. for _, project := range projects {
  928. var project_id int64
  929. var project_type int64
  930. var totals float64
  931. var project_name string
  932. var parsetotal int64
  933. var id int64
  934. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  935. id = int64(project.(map[string]interface{})["id"].(float64))
  936. }
  937. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  938. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  939. }
  940. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  941. project_type = int64(project.(map[string]interface{})["type"].(float64))
  942. }
  943. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  944. total, _ := project.(map[string]interface{})["total"].(string)
  945. totals, _ = strconv.ParseFloat(total, 64)
  946. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  947. }
  948. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  949. project_name = project.(map[string]interface{})["project_name"].(string)
  950. }
  951. if project_type == 3 {
  952. //查找该耗材的出库记录
  953. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  954. //var total_count int64
  955. //for _, it := range goodWarehouseInfo {
  956. // total_count += it.Count
  957. //}
  958. if len(goodWarehouseInfo) == 0 {
  959. //查询耗材库存
  960. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  961. var stock_count int64
  962. for _, it := range list {
  963. stock_count += it.StockCount
  964. }
  965. stock_counts := strconv.FormatInt(stock_count, 10)
  966. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  967. if totals > stock_total_count {
  968. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  969. return
  970. }
  971. //查找今日该患者已经出库的所有耗材
  972. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  973. for _, item := range goodList {
  974. //回退库存
  975. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  976. }
  977. //删除记录
  978. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  979. }
  980. if len(goodWarehouseInfo) > 0 {
  981. //查询该患者耗材的历史数据
  982. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  983. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  984. //数量发生改变
  985. if parsetotal != count {
  986. //查找今日该患者已经出库的所有耗材
  987. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  988. for _, item := range goodList {
  989. //回退库存
  990. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  991. }
  992. //删除记录
  993. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  994. }
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. }
  1001. }
  1002. }
  1003. }
  1004. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1005. var hpInfo models.HisPrescriptionInfo
  1006. if info.ID == 0 {
  1007. var randNum int
  1008. randNum = rand.Intn(10000) + 1000
  1009. timestamp := time.Now().Unix()
  1010. tempTime := time.Unix(timestamp, 0)
  1011. timeFormat := tempTime.Format("20060102150405")
  1012. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1013. hpInfo = models.HisPrescriptionInfo{
  1014. HisPatientId: his_patient_id,
  1015. UserOrgId: adminInfo.CurrentOrgId,
  1016. RecordDate: theTime.Unix(),
  1017. PatientId: patient_id,
  1018. Status: 1,
  1019. Ctime: time.Now().Unix(),
  1020. Mtime: time.Now().Unix(),
  1021. Creator: adminInfo.AdminUser.Id,
  1022. Modifier: adminInfo.AdminUser.Id,
  1023. Diagnosis: diagnose,
  1024. SickHistory: sick_history,
  1025. Departments: department,
  1026. RegisterType: reg_type,
  1027. PrescriptionNumber: p_number,
  1028. PrescriptionStatus: 1,
  1029. Doctor: role.UserName,
  1030. DoctorId: doctor_id,
  1031. SickType: sick_type,
  1032. PType: p_type,
  1033. }
  1034. service.SavePatientPrescriptionInfo(hpInfo)
  1035. redis := service.RedisClient()
  1036. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1037. redis.Set(key, "", time.Second)
  1038. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1039. redis.Set(keyOne, "", time.Second)
  1040. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1041. redis.Set(keySeven, "", time.Second)
  1042. defer redis.Close()
  1043. } else {
  1044. hpInfo = models.HisPrescriptionInfo{
  1045. ID: info.ID,
  1046. UserOrgId: adminInfo.CurrentOrgId,
  1047. RecordDate: info.RecordDate,
  1048. PatientId: info.PatientId,
  1049. Status: 1,
  1050. Ctime: info.Ctime,
  1051. Mtime: time.Now().Unix(),
  1052. Creator: info.Creator,
  1053. Modifier: adminInfo.AdminUser.Id,
  1054. Diagnosis: diagnose,
  1055. SickHistory: sick_history,
  1056. Departments: department,
  1057. RegisterType: reg_type,
  1058. PrescriptionNumber: info.PrescriptionNumber,
  1059. Doctor: role.UserName,
  1060. PrescriptionStatus: info.PrescriptionStatus,
  1061. DoctorId: doctor_id,
  1062. SickType: sick_type,
  1063. PType: info.PType,
  1064. HisPatientId: info.HisPatientId,
  1065. }
  1066. service.SavePatientPrescriptionInfo(hpInfo)
  1067. redis := service.RedisClient()
  1068. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1069. redis.Set(key, "", time.Second)
  1070. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1071. redis.Set(keyOne, "", time.Second)
  1072. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1073. redis.Set(keySeven, "", time.Second)
  1074. defer redis.Close()
  1075. }
  1076. //定义切片
  1077. var adviceList []models.HisDoctorAdviceInfo
  1078. var projectList []models.HisPrescriptionProject
  1079. //var hisLis []models.HisList
  1080. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1081. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1082. var tempPrescription *models.HisPrescription
  1083. if len(prescriptions) > 0 {
  1084. for _, item := range prescriptions {
  1085. items := item.(map[string]interface{})
  1086. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1087. utils.ErrorLog("id")
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. return
  1090. }
  1091. id := int64(items["id"].(float64))
  1092. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1093. tempPrescription = &new_prescription
  1094. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1095. utils.ErrorLog("type")
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. types := int64(items["type"].(float64))
  1100. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1101. utils.ErrorLog("med_type")
  1102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. return
  1104. }
  1105. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1106. if med_type == "0" {
  1107. med_type = "14"
  1108. }
  1109. //if order_status == 0 {
  1110. // order_status = 1
  1111. //}
  1112. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1113. utils.ErrorLog("pre_time")
  1114. }
  1115. preTime, _ := items["pre_time"].(string)
  1116. timeLayout := "2006-01-02"
  1117. loc, _ := time.LoadLocation("Local")
  1118. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1119. if err != nil {
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. pTime := theTime2.Unix()
  1124. ctime := time.Now().Unix()
  1125. if tempPrescription.ID == 0 {
  1126. prescription := &models.HisPrescription{
  1127. ID: 0,
  1128. PatientId: patient_id,
  1129. UserOrgId: adminInfo.CurrentOrgId,
  1130. RecordDate: recordDateTime,
  1131. Ctime: ctime,
  1132. Mtime: ctime,
  1133. Type: types,
  1134. Modifier: adminInfo.AdminUser.Id,
  1135. Creator: adminInfo.AdminUser.Id,
  1136. Status: 1,
  1137. Doctor: role.UserName,
  1138. HisPatientId: his_patient_id,
  1139. OrderStatus: 1,
  1140. BatchNumber: "",
  1141. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1142. PreTime: pTime,
  1143. PType: p_type,
  1144. MedType: med_type,
  1145. }
  1146. tempPrescription = prescription
  1147. service.SaveHisPrescription(tempPrescription)
  1148. redis := service.RedisClient()
  1149. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1150. redis.Set(key, "", time.Second)
  1151. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1152. redis.Set(keyOne, "", time.Second)
  1153. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1154. redis.Set(keySeven, "", time.Second)
  1155. defer redis.Close()
  1156. } else {
  1157. tempPrescription.ID = id
  1158. tempPrescription.Type = types
  1159. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1160. tempPrescription.Mtime = time.Now().Unix()
  1161. tempPrescription.Doctor = role.UserName
  1162. //tempPrescription.OrderStatus = order_status
  1163. tempPrescription.PreTime = pTime
  1164. tempPrescription.MedType = med_type
  1165. service.SaveHisPrescription(tempPrescription)
  1166. redis := service.RedisClient()
  1167. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1168. redis.Set(key, "", time.Second)
  1169. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1170. redis.Set(keyOne, "", time.Second)
  1171. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1172. redis.Set(keySeven, "", time.Second)
  1173. defer redis.Close()
  1174. }
  1175. //service.SaveHisPrescription(prescription)
  1176. //更改患者挂号状态
  1177. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1178. fmt.Println("更改失败", err2)
  1179. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1180. advices := items["advices"].([]interface{})
  1181. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1182. groupNo := int64(0)
  1183. ctime := time.Now().Unix()
  1184. mtime := ctime
  1185. if len(advices) > 0 {
  1186. for _, advice := range advices {
  1187. var s models.HisDoctorAdviceInfo
  1188. s.PrescriptionId = tempPrescription.ID
  1189. s.AdviceType = 2
  1190. s.AdviceDoctor = doctor_id
  1191. s.StopState = 2
  1192. s.ExecutionState = 2
  1193. s.AdviceDate = recordDateTime
  1194. s.Status = 1
  1195. s.UserOrgId = adminInfo.CurrentOrgId
  1196. s.RecordDate = recordDateTime
  1197. s.StartTime = tempPrescription.PreTime
  1198. s.Groupno = groupNo
  1199. s.CreatedTime = ctime
  1200. s.UpdatedTime = mtime
  1201. s.PatientId = patient_id
  1202. s.HisPatientId = his_patient_id
  1203. s.StartTime = pTime
  1204. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1205. if errcode > 0 {
  1206. c.ServeFailJSONWithSGJErrorCode(errcode)
  1207. return
  1208. }
  1209. s.StartTime = pTime
  1210. service.CreateHisDoctorAdvice(&s)
  1211. //存储切片中
  1212. adviceList = append(adviceList, s)
  1213. redis := service.RedisClient()
  1214. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1215. redis.Set(key, "", time.Second)
  1216. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1217. redis.Set(keyOne, "", time.Second)
  1218. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1219. redis.Set(keySeven, "", time.Second)
  1220. var randNum int
  1221. randNum = rand.Intn(10000) + 1000
  1222. timestamp := time.Now().Unix()
  1223. tempTime := time.Unix(timestamp, 0)
  1224. timeFormat := tempTime.Format("20060102150405")
  1225. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1226. service.CreateHisDoctorAdvice(&s)
  1227. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1228. redis.Set(keySix, "", time.Second)
  1229. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1230. redis.Set(keyFive, "", time.Second)
  1231. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1232. redis.Set(keyEight, "", time.Second)
  1233. defer redis.Close()
  1234. }
  1235. }
  1236. }
  1237. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1238. projects := items["project"].([]interface{})
  1239. if len(projects) > 0 {
  1240. for _, project := range projects {
  1241. var p models.HisPrescriptionProject
  1242. p.PrescriptionId = tempPrescription.ID
  1243. p.Ctime = time.Now().Unix()
  1244. p.Mtime = time.Now().Unix()
  1245. p.PatientId = patient_id
  1246. p.RecordDate = recordDateTime
  1247. p.Doctor = doctor_id
  1248. p.UserOrgId = adminInfo.CurrentOrgId
  1249. p.HisPatientId = his_patient_id
  1250. p.Status = 1
  1251. p.StartTime = pTime
  1252. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1253. if errcode > 0 {
  1254. c.ServeFailJSONWithSGJErrorCode(errcode)
  1255. return
  1256. }
  1257. service.CreateHisProjectTwo(&p)
  1258. projectList = append(projectList, p)
  1259. var randNum int
  1260. randNum = rand.Intn(10000) + 1000
  1261. timestamp := time.Now().Unix()
  1262. tempTime := time.Unix(timestamp, 0)
  1263. timeFormat := tempTime.Format("20060102150405")
  1264. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1265. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1266. //新增或者编辑项目,修改对应的标签数据
  1267. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1268. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1269. var label models.HisLabelPrintInfo
  1270. project, _ := service.GetProjectDetail(p.ProjectId)
  1271. if project.CostClassify == 3 { //类别为检验检查
  1272. if p.TeamId > 0 { //检验检查组套
  1273. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1274. if tempLabel.ID == 0 {
  1275. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1276. label.Number = tempPrescription.PrescriptionNumber
  1277. label.ProjectId = project.ID
  1278. label.Status = 1
  1279. label.IsPrint = 2
  1280. label.DoctorId = info.DoctorId
  1281. label.UserOrgId = p.UserOrgId
  1282. label.PatientId = patient_id
  1283. label.RecordDate = recordDateTime
  1284. label.Ctime = time.Now().Unix()
  1285. label.Mtime = time.Now().Unix()
  1286. label.ItemId = p.TeamId
  1287. label.FeedetlSn = p.FeedetlSn
  1288. label.PProjectId = p.ID
  1289. label.ProjectName = team.ProjectTeam
  1290. label.PatientName = patient.Name
  1291. service.CreateHisLabelRecord(&label)
  1292. }
  1293. } else { //单条检验检查项目
  1294. label.Number = tempPrescription.PrescriptionNumber
  1295. label.ProjectId = project.ID
  1296. label.Status = 1
  1297. label.DoctorId = info.DoctorId
  1298. label.UserOrgId = p.UserOrgId
  1299. label.PatientId = patient_id
  1300. label.RecordDate = recordDateTime
  1301. label.IsPrint = 2
  1302. label.Ctime = time.Now().Unix()
  1303. label.Mtime = time.Now().Unix()
  1304. label.FeedetlSn = p.FeedetlSn
  1305. label.PProjectId = p.ID
  1306. label.ItemId = p.TeamId
  1307. label.ProjectName = project.ProjectName
  1308. label.PatientName = patient.Name
  1309. service.CreateHisLabelRecord(&label)
  1310. }
  1311. }
  1312. }
  1313. }
  1314. service.SaveHisProjectTwo(&p)
  1315. //if p.Type == 3 { //处理透前准备耗材数量数据
  1316. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1317. // if consumables.ID > 0 {
  1318. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1319. // consumables.Count = cnt
  1320. // service.UpdateConsumables(&consumables)
  1321. // }
  1322. //}
  1323. }
  1324. }
  1325. }
  1326. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1327. // addition := items["addition"].([]interface{})
  1328. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1329. // ctime := time.Now().Unix()
  1330. // mtime := ctime
  1331. // if len(addition) > 0 {
  1332. // for _, item := range addition {
  1333. // var s models.HisAdditionalCharge
  1334. // s.PrescriptionId = tempPrescription.ID
  1335. // s.Status = 1
  1336. // s.UserOrgId = adminInfo.CurrentOrgId
  1337. // s.RecordDate = recordDateTime
  1338. // s.CreatedTime = ctime
  1339. // s.UpdatedTime = mtime
  1340. // s.PatientId = patient_id
  1341. // s.HisPatientId = his_patient_id
  1342. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1343. // if errcode > 0 {
  1344. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1345. // return
  1346. // }
  1347. // service.CreateAdditionalCharge(&s)
  1348. // var randNum int
  1349. // randNum = rand.Intn(10000) + 1000
  1350. // timestamp := time.Now().Unix()
  1351. // tempTime := time.Unix(timestamp, 0)
  1352. // timeFormat := tempTime.Format("20060102150405")
  1353. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1354. // service.CreateAdditionalCharge(&s)
  1355. //
  1356. // }
  1357. // }
  1358. //}
  1359. }
  1360. }
  1361. }
  1362. //redisClient := service.RedisClient()
  1363. //defer redisClient.Close()
  1364. //
  1365. //list := models.HisList{
  1366. // Patient_id: patient_id,
  1367. // Advice_id:0,
  1368. // Record_date: 0,
  1369. // Advice: adviceList,
  1370. // Project: nil,
  1371. //}
  1372. //hisLis = append(hisLis, list)
  1373. //
  1374. //advice_json, _ := json.Marshal(&hisLis)
  1375. //redisClient.RPush("111", advice_json).Result()
  1376. //result, _ := redisClient.RPop("111").Result()
  1377. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1378. //
  1379. //var dat []map[string]interface{}
  1380. //json.Unmarshal([]byte(result), &dat)
  1381. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1382. //
  1383. //for k,v:=range dat{
  1384. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1385. //}
  1386. //project_json, _ := json.Marshal(&projectList)
  1387. //redisClient.LPush("222", project_json).Result()
  1388. if err == nil {
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "msg": "保存成功",
  1391. })
  1392. return
  1393. } else {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1395. return
  1396. }
  1397. }
  1398. func (c *HisApiController) EditHisPrescription() {
  1399. record_date := c.GetString("record_date")
  1400. patient_id, _ := c.GetInt64("patient_id")
  1401. reg_type, _ := c.GetInt64("reg_type")
  1402. //diagnose, _ := c.GetInt64("diagnose", 0)
  1403. diagnose := c.GetString("diagnose")
  1404. sick_type, _ := c.GetInt64("sick_type")
  1405. sick_history := c.GetString("sick_history")
  1406. doctor_id, _ := c.GetInt64("doctor", 0)
  1407. department, _ := c.GetInt64("department", 0)
  1408. his_patient_id, _ := c.GetInt64("his_patient_id")
  1409. p_type, _ := c.GetInt64("p_type")
  1410. dataBody := make(map[string]interface{}, 0)
  1411. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1412. if err != nil {
  1413. utils.ErrorLog(err.Error())
  1414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1415. return
  1416. }
  1417. timeLayout := "2006-01-02"
  1418. loc, _ := time.LoadLocation("Local")
  1419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1420. if err != nil {
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1422. return
  1423. }
  1424. adminInfo := c.GetAdminUserInfo()
  1425. recordDateTime := theTime.Unix()
  1426. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1427. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1428. var hpInfo models.HisPrescriptionInfo
  1429. if info.ID == 0 {
  1430. var randNum int
  1431. randNum = rand.Intn(10000) + 1000
  1432. timestamp := time.Now().Unix()
  1433. tempTime := time.Unix(timestamp, 0)
  1434. timeFormat := tempTime.Format("20060102150405")
  1435. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1436. hpInfo = models.HisPrescriptionInfo{
  1437. UserOrgId: adminInfo.CurrentOrgId,
  1438. RecordDate: theTime.Unix(),
  1439. PatientId: patient_id,
  1440. Status: 1,
  1441. Ctime: time.Now().Unix(),
  1442. Mtime: time.Now().Unix(),
  1443. Creator: adminInfo.AdminUser.Id,
  1444. Modifier: adminInfo.AdminUser.Id,
  1445. Diagnosis: diagnose,
  1446. SickHistory: sick_history,
  1447. Departments: department,
  1448. RegisterType: reg_type,
  1449. PrescriptionNumber: p_number,
  1450. PrescriptionStatus: 1,
  1451. Doctor: role.UserName,
  1452. DoctorId: doctor_id,
  1453. SickType: sick_type,
  1454. PType: p_type,
  1455. }
  1456. service.SavePatientPrescriptionInfo(hpInfo)
  1457. } else {
  1458. hpInfo = models.HisPrescriptionInfo{
  1459. ID: info.ID,
  1460. UserOrgId: adminInfo.CurrentOrgId,
  1461. RecordDate: info.RecordDate,
  1462. PatientId: info.PatientId,
  1463. Status: 1,
  1464. Ctime: info.Ctime,
  1465. Mtime: time.Now().Unix(),
  1466. Creator: info.Creator,
  1467. Modifier: adminInfo.AdminUser.Id,
  1468. Diagnosis: diagnose,
  1469. SickHistory: sick_history,
  1470. Departments: department,
  1471. RegisterType: reg_type,
  1472. PrescriptionNumber: info.PrescriptionNumber,
  1473. Doctor: role.UserName,
  1474. PrescriptionStatus: info.PrescriptionStatus,
  1475. DoctorId: doctor_id,
  1476. SickType: sick_type,
  1477. PType: info.PType,
  1478. }
  1479. service.SavePatientPrescriptionInfo(hpInfo)
  1480. }
  1481. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1482. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1483. if len(prescriptions) > 0 {
  1484. for _, item := range prescriptions {
  1485. items := item.(map[string]interface{})
  1486. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1487. utils.ErrorLog("id")
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1489. return
  1490. }
  1491. id := int64(items["id"].(float64))
  1492. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1493. utils.ErrorLog("type")
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1495. return
  1496. }
  1497. types := int64(items["type"].(float64))
  1498. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1499. utils.ErrorLog("med_type")
  1500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1504. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1505. ctime := time.Now().Unix()
  1506. prescription := &models.HisPrescription{
  1507. ID: id,
  1508. PatientId: patient_id,
  1509. UserOrgId: adminInfo.CurrentOrgId,
  1510. RecordDate: recordDateTime,
  1511. Ctime: ctime,
  1512. Mtime: ctime,
  1513. Type: types,
  1514. Modifier: adminInfo.AdminUser.Id,
  1515. Creator: adminInfo.AdminUser.Id,
  1516. Status: 1,
  1517. Doctor: role.UserName,
  1518. HisPatientId: his_patient_id,
  1519. OrderStatus: 1,
  1520. BatchNumber: "",
  1521. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1522. PType: hpInfo.PType,
  1523. MedType: med_type,
  1524. }
  1525. if historyPrescription.ID > 0 {
  1526. prescription.PreTime = historyPrescription.PreTime
  1527. }
  1528. service.SaveHisPrescription(prescription)
  1529. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1530. advices := items["advices"].([]interface{})
  1531. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1532. groupNo := int64(0)
  1533. ctime := time.Now().Unix()
  1534. mtime := ctime
  1535. if len(advices) > 0 {
  1536. for _, advice := range advices {
  1537. var s models.HisDoctorAdviceInfo
  1538. s.PrescriptionId = prescription.ID
  1539. s.AdviceType = 2
  1540. s.AdviceDoctor = adminInfo.AdminUser.Id
  1541. s.StopState = 2
  1542. s.ExecutionState = 2
  1543. s.AdviceDate = recordDateTime
  1544. s.Status = 1
  1545. s.UserOrgId = adminInfo.CurrentOrgId
  1546. s.RecordDate = recordDateTime
  1547. s.StartTime = prescription.PreTime
  1548. s.Groupno = groupNo
  1549. s.CreatedTime = ctime
  1550. s.UpdatedTime = mtime
  1551. s.PatientId = patient_id
  1552. s.HisPatientId = his_patient_id
  1553. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1554. if errcode > 0 {
  1555. c.ServeFailJSONWithSGJErrorCode(errcode)
  1556. return
  1557. }
  1558. service.CreateHisDoctorAdvice(&s)
  1559. redis := service.RedisClient()
  1560. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1561. redis.Set(key, "", time.Second)
  1562. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1563. fmt.Println("keyOne", keyOne)
  1564. redis.Set(keyOne, "", time.Second)
  1565. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1566. redis.Set(keySeven, "", time.Second)
  1567. redis.Close()
  1568. }
  1569. }
  1570. }
  1571. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1572. projects := items["project"].([]interface{})
  1573. if len(projects) > 0 {
  1574. for _, project := range projects {
  1575. var p models.HisPrescriptionProject
  1576. p.PrescriptionId = prescription.ID
  1577. p.Ctime = time.Now().Unix()
  1578. p.Mtime = time.Now().Unix()
  1579. p.PatientId = patient_id
  1580. p.RecordDate = recordDateTime
  1581. p.UserOrgId = adminInfo.CurrentOrgId
  1582. p.HisPatientId = his_patient_id
  1583. p.Status = 1
  1584. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1585. if errcode > 0 {
  1586. c.ServeFailJSONWithSGJErrorCode(errcode)
  1587. return
  1588. }
  1589. service.CreateHisProjectTwo(&p)
  1590. }
  1591. }
  1592. }
  1593. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1594. addition := items["addition"].([]interface{})
  1595. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1596. ctime := time.Now().Unix()
  1597. mtime := ctime
  1598. if len(addition) > 0 {
  1599. for _, item := range addition {
  1600. var s models.HisAdditionalCharge
  1601. s.PrescriptionId = prescription.ID
  1602. s.Status = 1
  1603. s.UserOrgId = adminInfo.CurrentOrgId
  1604. s.RecordDate = recordDateTime
  1605. s.CreatedTime = ctime
  1606. s.UpdatedTime = mtime
  1607. s.PatientId = patient_id
  1608. s.HisPatientId = his_patient_id
  1609. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1610. if errcode > 0 {
  1611. c.ServeFailJSONWithSGJErrorCode(errcode)
  1612. return
  1613. }
  1614. service.CreateAdditionalCharge(&s)
  1615. }
  1616. }
  1617. }
  1618. }
  1619. }
  1620. }
  1621. if err == nil {
  1622. c.ServeSuccessJSON(map[string]interface{}{
  1623. "msg": "保存成功",
  1624. })
  1625. return
  1626. } else {
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1628. return
  1629. }
  1630. }
  1631. func (c *HisApiController) DeletePrescription() {
  1632. prescription_id, _ := c.GetInt64("id")
  1633. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1634. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1635. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1636. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1637. if len(projects) > 0 {
  1638. for _, item := range projects {
  1639. service.DeletePrintInfo(item.ID) //删除打印信息
  1640. if stockConfig.IsOpen == 1 {
  1641. if item.Type == 3 {
  1642. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1643. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1644. good.Total = good.Total + f_count
  1645. service.UpdateGoodInfo(&good)
  1646. operation_time := time.Now().Unix()
  1647. creater := c.GetAdminUserInfo().AdminUser.Id
  1648. //创建退库单
  1649. timeStr := time.Now().Format("2006-01-02")
  1650. timeArr := strings.Split(timeStr, "-")
  1651. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1652. total = total + 1
  1653. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1654. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1655. cancelStock := models.CancelStock{
  1656. OrderNumber: orderNumber,
  1657. OperaTime: operation_time,
  1658. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1659. Creater: creater,
  1660. Ctime: time.Now().Unix(),
  1661. Status: 1,
  1662. ReturnTime: item.RecordDate,
  1663. Type: 1,
  1664. StorehouseId: houseConfig.StorehouseOutInfo,
  1665. }
  1666. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1667. if msgerrkonde == gorm.ErrRecordNotFound {
  1668. service.AddSigleCancelStock(&cancelStock)
  1669. }
  1670. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1671. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1672. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1673. //查询该耗材是否出库
  1674. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1675. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1676. deaerler, _ := service.GetDealerById(info.Dealer)
  1677. if info.ID > 0 {
  1678. cancelStockInfo := models.CancelStockInfo{
  1679. GoodId: item.ProjectId,
  1680. CancelStockId: cancel.ID,
  1681. GoodTypeId: good.GoodTypeId,
  1682. Count: prescribingNumber,
  1683. Price: info.Price,
  1684. Total: 0,
  1685. ProductDate: info.ProductDate,
  1686. ExpiryDate: info.ExpiryDate,
  1687. Ctime: time.Now().Unix(),
  1688. Status: 1,
  1689. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1690. OrderNumber: cancel.OrderNumber,
  1691. Type: 0,
  1692. Dealer: deaerler.DealerName,
  1693. Manufacturer: manufacturer.ManufacturerName,
  1694. Number: info.Number,
  1695. RegisterAccount: "",
  1696. Remark: "",
  1697. WarehouseInfoId: info.WarehouseInfotId,
  1698. PatientId: info.PatientId,
  1699. RecordDate: info.SysRecordTime,
  1700. StorehouseId: houseConfig.StorehouseOutInfo,
  1701. }
  1702. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1703. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1704. flow := models.VmStockFlow{
  1705. WarehousingId: 0,
  1706. GoodId: item.ProjectId,
  1707. Number: info.Number,
  1708. LicenseNumber: info.LicenseNumber,
  1709. Count: prescribingNumber,
  1710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1711. PatientId: item.PatientId,
  1712. SystemTime: info.SysRecordTime,
  1713. ConsumableType: 7,
  1714. IsSys: 0,
  1715. WarehousingOrder: "",
  1716. WarehouseOutId: 0,
  1717. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1718. IsEdit: 0,
  1719. CancelStockId: cancel.ID,
  1720. CancelOrderNumber: cancel.OrderNumber,
  1721. Manufacturer: manufacturer.ID,
  1722. Dealer: 0,
  1723. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1724. UpdateCreator: 0,
  1725. Status: 1,
  1726. Ctime: time.Now().Unix(),
  1727. Mtime: 0,
  1728. Price: info.Price,
  1729. WarehousingDetailId: info.WarehouseInfotId,
  1730. WarehouseOutDetailId: 0,
  1731. CancelOutDetailId: cancelInfo.ID,
  1732. ProductDate: info.ProductDate,
  1733. ExpireDate: info.ExpiryDate,
  1734. StorehouseId: houseConfig.StorehouseOutInfo,
  1735. }
  1736. service.CreateStockFlowOne(flow)
  1737. //删除出库表
  1738. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1739. //查询今日该患者开了多少耗材
  1740. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1741. var total_count int64
  1742. var cha_count int64
  1743. for _, item := range projectList {
  1744. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1745. total_count += count
  1746. }
  1747. //回退库存
  1748. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1749. //查询今日该耗材退库数量
  1750. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1751. var cancel_Count int64
  1752. for _, items := range cancelInfoOne {
  1753. cancel_Count += items.Count
  1754. }
  1755. cha_count = total_count - cancel_Count
  1756. if total_count > cancel_Count {
  1757. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1758. if err == gorm.ErrRecordNotFound {
  1759. //没有记录,则创建出库单
  1760. timeStr := time.Now().Format("2006-01-02")
  1761. timeArr := strings.Split(timeStr, "-")
  1762. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1763. total = total + 1
  1764. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1765. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1766. number = number + total
  1767. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1768. warehouseOut := models.WarehouseOut{
  1769. WarehouseOutOrderNumber: warehousing_out_order,
  1770. OperationTime: time.Now().Unix(),
  1771. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1772. Creater: creater,
  1773. Ctime: time.Now().Unix(),
  1774. Status: 1,
  1775. WarehouseOutTime: info.SysRecordTime,
  1776. Dealer: 0,
  1777. Manufacturer: 0,
  1778. Type: 1,
  1779. IsSys: 1,
  1780. StorehouseId: houseConfig.StorehouseOutInfo,
  1781. }
  1782. err := service.AddSigleWarehouseOut(&warehouseOut)
  1783. if err != nil {
  1784. utils.TraceLog("创建出库单失败 err = %v", err)
  1785. return
  1786. }
  1787. prepare := &models.DialysisBeforePrepare{
  1788. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1789. PatientId: info.PatientId,
  1790. RecordDate: info.SysRecordTime,
  1791. GoodId: item.ProjectId,
  1792. GoodTypeId: info.GoodTypeId,
  1793. Count: cha_count,
  1794. StorehouseId: houseConfig.StorehouseOutInfo,
  1795. }
  1796. //出库
  1797. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1798. } else if err == nil {
  1799. prepare := &models.DialysisBeforePrepare{
  1800. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1801. PatientId: info.PatientId,
  1802. RecordDate: info.SysRecordTime,
  1803. GoodId: item.ProjectId,
  1804. GoodTypeId: info.GoodTypeId,
  1805. Count: cha_count,
  1806. StorehouseId: houseConfig.StorehouseOutInfo,
  1807. }
  1808. //出库
  1809. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1817. fmt.Println(err)
  1818. }
  1819. if drugStockConfig.IsOpen == 1 {
  1820. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1821. fmt.Println(err)
  1822. if len(advices) > 0 {
  1823. for _, item := range advices {
  1824. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1825. redis := service.RedisClient()
  1826. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1827. redis.Set(keyFive, "", time.Second)
  1828. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1829. redis.Set(keyOne, "", time.Second)
  1830. redis.Close()
  1831. //查询该药品是否存在出库记录
  1832. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1833. if errcode == gorm.ErrRecordNotFound {
  1834. } else if errcode == nil {
  1835. if item.PrescribingNumberUnit == drug.MinUnit {
  1836. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1837. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1838. //退库
  1839. warehouseInfo := models.DrugWarehouseInfo{
  1840. StockMinNumber: prescribingNumber,
  1841. }
  1842. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1843. adminUserInfo := c.GetAdminUserInfo()
  1844. operation_time := time.Now().Unix()
  1845. creater := adminUserInfo.AdminUser.Id
  1846. ctime := time.Now().Unix()
  1847. timeStr := time.Now().Format("2006-01-02")
  1848. timeArr := strings.Split(timeStr, "-")
  1849. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1850. total = total + 1
  1851. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1852. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1853. cancelStock := models.DrugCancelStock{
  1854. OrderNumber: orderNumber,
  1855. OperaTime: operation_time,
  1856. OrgId: adminUserInfo.CurrentOrgId,
  1857. Creater: creater,
  1858. Ctime: ctime,
  1859. Status: 1,
  1860. ReturnTime: item.AdviceDate,
  1861. Dealer: info.Dealer,
  1862. Manufacturer: info.Manufacturer,
  1863. Type: 1,
  1864. StorehouseId: houseConfig.DrugStorehouseOut,
  1865. }
  1866. service.AddSigleDrugCancelStock(&cancelStock)
  1867. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1868. dealer, _ := service.GetDealerById(info.Dealer)
  1869. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1870. cancelStockInfo := models.DrugCancelStockInfo{
  1871. OrderNumber: cancelInfo.OrderNumber,
  1872. CancelStockId: cancelInfo.ID,
  1873. DrugId: info.DrugId,
  1874. Count: prescribingNumber,
  1875. Status: 1,
  1876. Ctime: ctime,
  1877. OrgId: adminUserInfo.CurrentOrgId,
  1878. Type: 1,
  1879. Manufacturer: manufactureName.ManufacturerName,
  1880. Dealer: dealer.DealerName,
  1881. Total: 0,
  1882. RetailPrice: info.RetailPrice,
  1883. RetailTotalPrice: info.RetailTotalPrice,
  1884. Price: info.Price,
  1885. RegisterAccount: "",
  1886. Remark: info.Remark,
  1887. BatchNumber: info.BatchNumber,
  1888. MaxUnit: info.CountUnit,
  1889. ProductDate: info.ProductDate,
  1890. ExpiryDate: info.ExpiryDate,
  1891. BatchNumberId: info.WarehouseInfoId,
  1892. StorehouseId: houseConfig.DrugStorehouseOut,
  1893. }
  1894. flow := models.DrugFlow{
  1895. WarehousingId: 0,
  1896. DrugId: info.DrugId,
  1897. Number: "",
  1898. BatchNumber: info.BatchNumber,
  1899. Count: prescribingNumber,
  1900. UserOrgId: adminUserInfo.CurrentOrgId,
  1901. PatientId: 0,
  1902. SystemTime: info.SysRecordTime,
  1903. ConsumableType: 7,
  1904. IsSys: 0,
  1905. WarehousingOrder: "",
  1906. WarehouseOutId: 0,
  1907. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1908. IsEdit: 0,
  1909. CancelStockId: cancelStock.ID,
  1910. CancelOrderNumber: cancelStock.OrderNumber,
  1911. Manufacturer: info.Manufacturer,
  1912. Dealer: info.Dealer,
  1913. Creator: adminUserInfo.AdminUser.Id,
  1914. UpdateCreator: 0,
  1915. Status: 1,
  1916. Ctime: time.Now().Unix(),
  1917. Mtime: 0,
  1918. Price: info.Price,
  1919. WarehousingDetailId: 0,
  1920. WarehouseOutDetailId: 0,
  1921. CancelOutDetailId: 0,
  1922. ExpireDate: info.ExpiryDate,
  1923. ProductDate: info.ProductDate,
  1924. MaxUnit: info.CountUnit,
  1925. MinUnit: "",
  1926. AdviceId: info.AdviceId,
  1927. StorehouseId: houseConfig.DrugStorehouseOut,
  1928. }
  1929. service.CreatedCancelStock(cancelStockInfo)
  1930. service.CreateDrugFlowOne(flow)
  1931. //删除出库记录
  1932. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1933. //删除流水
  1934. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1935. } else {
  1936. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1937. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1938. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1939. if item.PrescribingNumberUnit == drug.MaxUnit {
  1940. warehouseInfo := models.DrugWarehouseInfo{
  1941. StockMaxNumber: prescribingNumber,
  1942. }
  1943. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1944. }
  1945. adminUserInfo := c.GetAdminUserInfo()
  1946. operation_time := time.Now().Unix()
  1947. creater := adminUserInfo.AdminUser.Id
  1948. ctime := time.Now().Unix()
  1949. timeStr := time.Now().Format("2006-01-02")
  1950. timeArr := strings.Split(timeStr, "-")
  1951. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1952. total = total + 1
  1953. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1954. cancelStock := models.DrugCancelStock{
  1955. OrderNumber: orderNumber,
  1956. OperaTime: operation_time,
  1957. OrgId: adminUserInfo.CurrentOrgId,
  1958. Creater: creater,
  1959. Ctime: ctime,
  1960. Status: 1,
  1961. ReturnTime: item.AdviceDate,
  1962. Dealer: info.Dealer,
  1963. Manufacturer: info.Manufacturer,
  1964. Type: 1,
  1965. StorehouseId: houseConfig.DrugStorehouseOut,
  1966. }
  1967. service.AddSigleDrugCancelStock(&cancelStock)
  1968. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1969. dealer, _ := service.GetDealerById(info.Dealer)
  1970. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1971. cancelStockInfo := models.DrugCancelStockInfo{
  1972. OrderNumber: cancelInfo.OrderNumber,
  1973. CancelStockId: cancelInfo.ID,
  1974. DrugId: info.DrugId,
  1975. // Count: info.Count,
  1976. Count: prescribingNumber,
  1977. Status: 1,
  1978. Ctime: ctime,
  1979. OrgId: adminUserInfo.CurrentOrgId,
  1980. Type: 1,
  1981. Manufacturer: manufactureName.ManufacturerName,
  1982. Dealer: dealer.DealerName,
  1983. Total: 0,
  1984. RetailPrice: info.RetailPrice,
  1985. RetailTotalPrice: info.RetailTotalPrice,
  1986. Price: info.Price,
  1987. RegisterAccount: "",
  1988. Remark: info.Remark,
  1989. BatchNumber: info.BatchNumber,
  1990. MaxUnit: info.CountUnit,
  1991. ProductDate: info.ProductDate,
  1992. ExpiryDate: info.ExpiryDate,
  1993. BatchNumberId: info.WarehouseInfoId,
  1994. StorehouseId: houseConfig.DrugStorehouseOut,
  1995. }
  1996. flow := models.DrugFlow{
  1997. WarehousingId: 0,
  1998. DrugId: info.DrugId,
  1999. Number: "",
  2000. BatchNumber: info.BatchNumber,
  2001. //Count: info.Count,
  2002. Count: prescribingNumber,
  2003. UserOrgId: adminUserInfo.CurrentOrgId,
  2004. PatientId: 0,
  2005. SystemTime: info.SysRecordTime,
  2006. ConsumableType: 7,
  2007. IsSys: 0,
  2008. WarehousingOrder: "",
  2009. WarehouseOutId: 0,
  2010. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2011. IsEdit: 0,
  2012. CancelStockId: cancelStock.ID,
  2013. CancelOrderNumber: cancelStock.OrderNumber,
  2014. Manufacturer: info.Manufacturer,
  2015. Dealer: info.Dealer,
  2016. Creator: adminUserInfo.AdminUser.Id,
  2017. UpdateCreator: 0,
  2018. Status: 1,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. Price: info.Price,
  2022. WarehousingDetailId: 0,
  2023. WarehouseOutDetailId: 0,
  2024. CancelOutDetailId: 0,
  2025. ExpireDate: info.ExpiryDate,
  2026. ProductDate: info.ProductDate,
  2027. MaxUnit: info.CountUnit,
  2028. MinUnit: "",
  2029. AdviceId: info.AdviceId,
  2030. StorehouseId: houseConfig.DrugStorehouseOut,
  2031. }
  2032. service.CreatedCancelStock(cancelStockInfo)
  2033. service.CreateDrugFlowOne(flow)
  2034. //删除出库记录
  2035. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2036. //删除流水
  2037. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2038. }
  2039. }
  2040. if item.PrescribingNumberUnit == drug.MinUnit {
  2041. drug.Total = drug.Total + item.PrescribingNumber
  2042. service.UpdateBaseDrugLib(&drug)
  2043. } else {
  2044. if item.PrescribingNumberUnit == drug.MaxUnit {
  2045. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  2046. drug.Total = drug.Total + item.PrescribingNumber
  2047. service.UpdateBaseDrugLib(&drug)
  2048. }
  2049. }
  2050. }
  2051. }
  2052. }
  2053. c.ServeSuccessJSON(map[string]interface{}{
  2054. "msg": "删除成功",
  2055. })
  2056. return
  2057. }
  2058. func (c *HisApiController) DeleteDoctorAdvice() {
  2059. id, _ := c.GetInt64("id")
  2060. advice, _ := service.GetHisDoctorAdvicesById(id)
  2061. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2062. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2063. redis := service.RedisClient()
  2064. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2065. redis.Set(keyFive, "", time.Second)
  2066. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2067. redis.Set(keyOne, "", time.Second)
  2068. defer redis.Close()
  2069. if err == nil {
  2070. if drugStockConfig.IsOpen == 1 {
  2071. //判断该医嘱是否执行了
  2072. if advice.ExecutionState == 1 {
  2073. //查询该病人该药品是否有库存记录
  2074. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  2075. if errcode == gorm.ErrRecordNotFound {
  2076. } else {
  2077. //退库
  2078. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  2079. if advice.PrescribingNumberUnit == drug.MinUnit {
  2080. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2081. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2082. //退库
  2083. warehouseInfo := models.DrugWarehouseInfo{
  2084. StockMinNumber: prescribingNumber,
  2085. }
  2086. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  2087. adminUserInfo := c.GetAdminUserInfo()
  2088. operation_time := time.Now().Unix()
  2089. creater := adminUserInfo.AdminUser.Id
  2090. ctime := time.Now().Unix()
  2091. timeStr := time.Now().Format("2006-01-02")
  2092. timeArr := strings.Split(timeStr, "-")
  2093. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2094. total = total + 1
  2095. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2096. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2097. cancelStock := models.DrugCancelStock{
  2098. OrderNumber: orderNumber,
  2099. OperaTime: operation_time,
  2100. OrgId: adminUserInfo.CurrentOrgId,
  2101. Creater: creater,
  2102. Ctime: ctime,
  2103. Status: 1,
  2104. ReturnTime: advice.AdviceDate,
  2105. Dealer: info.Dealer,
  2106. Manufacturer: info.Manufacturer,
  2107. Type: 1,
  2108. StorehouseId: houseConfig.DrugStorehouseOut,
  2109. }
  2110. service.AddSigleDrugCancelStock(&cancelStock)
  2111. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2112. dealer, _ := service.GetDealerById(info.Dealer)
  2113. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2114. cancelStockInfo := models.DrugCancelStockInfo{
  2115. OrderNumber: cancelInfo.OrderNumber,
  2116. CancelStockId: cancelInfo.ID,
  2117. DrugId: info.DrugId,
  2118. Count: info.Count,
  2119. Status: 1,
  2120. Ctime: ctime,
  2121. OrgId: adminUserInfo.CurrentOrgId,
  2122. Type: 1,
  2123. Manufacturer: manufactureName.ManufacturerName,
  2124. Dealer: dealer.DealerName,
  2125. Total: 0,
  2126. RetailPrice: info.RetailPrice,
  2127. RetailTotalPrice: info.RetailTotalPrice,
  2128. Price: info.Price,
  2129. RegisterAccount: "",
  2130. Remark: info.Remark,
  2131. BatchNumber: info.BatchNumber,
  2132. MaxUnit: info.CountUnit,
  2133. ProductDate: info.ProductDate,
  2134. ExpiryDate: info.ExpiryDate,
  2135. BatchNumberId: info.WarehouseInfoId,
  2136. StorehouseId: houseConfig.DrugStorehouseOut,
  2137. }
  2138. flow := models.DrugFlow{
  2139. WarehousingId: 0,
  2140. DrugId: info.DrugId,
  2141. Number: "",
  2142. BatchNumber: info.BatchNumber,
  2143. Count: info.Count,
  2144. UserOrgId: adminUserInfo.CurrentOrgId,
  2145. PatientId: 0,
  2146. SystemTime: info.SysRecordTime,
  2147. ConsumableType: 7,
  2148. IsSys: 0,
  2149. WarehousingOrder: "",
  2150. WarehouseOutId: 0,
  2151. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2152. IsEdit: 0,
  2153. CancelStockId: cancelStock.ID,
  2154. CancelOrderNumber: cancelStock.OrderNumber,
  2155. Manufacturer: info.Manufacturer,
  2156. Dealer: info.Dealer,
  2157. Creator: adminUserInfo.AdminUser.Id,
  2158. UpdateCreator: 0,
  2159. Status: 1,
  2160. Ctime: time.Now().Unix(),
  2161. Mtime: 0,
  2162. Price: info.Price,
  2163. WarehousingDetailId: 0,
  2164. WarehouseOutDetailId: 0,
  2165. CancelOutDetailId: 0,
  2166. ExpireDate: info.ExpiryDate,
  2167. ProductDate: info.ProductDate,
  2168. MaxUnit: info.CountUnit,
  2169. MinUnit: "",
  2170. AdviceId: info.AdviceId,
  2171. StorehouseId: houseConfig.DrugStorehouseOut,
  2172. }
  2173. service.CreatedCancelStock(cancelStockInfo)
  2174. service.CreateDrugFlowOne(flow)
  2175. //删除出库记录
  2176. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2177. //删除流水
  2178. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2179. } else {
  2180. adminUserInfo := c.GetAdminUserInfo()
  2181. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2182. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2183. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2184. if advice.PrescribingNumberUnit == drug.MaxUnit {
  2185. warehouseInfo := models.DrugWarehouseInfo{
  2186. StockMaxNumber: prescribingNumber,
  2187. }
  2188. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2189. }
  2190. operation_time := time.Now().Unix()
  2191. creater := adminUserInfo.AdminUser.Id
  2192. ctime := time.Now().Unix()
  2193. timeStr := time.Now().Format("2006-01-02")
  2194. timeArr := strings.Split(timeStr, "-")
  2195. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2196. total = total + 1
  2197. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2198. cancelStock := models.DrugCancelStock{
  2199. OrderNumber: orderNumber,
  2200. OperaTime: operation_time,
  2201. OrgId: adminUserInfo.CurrentOrgId,
  2202. Creater: creater,
  2203. Ctime: ctime,
  2204. Status: 1,
  2205. ReturnTime: advice.AdviceDate,
  2206. Dealer: info.Dealer,
  2207. Manufacturer: info.Manufacturer,
  2208. Type: 1,
  2209. StorehouseId: houseConfig.DrugStorehouseOut,
  2210. }
  2211. service.AddSigleDrugCancelStock(&cancelStock)
  2212. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2213. dealer, _ := service.GetDealerById(info.Dealer)
  2214. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2215. cancelStockInfo := models.DrugCancelStockInfo{
  2216. OrderNumber: cancelInfo.OrderNumber,
  2217. CancelStockId: cancelInfo.ID,
  2218. DrugId: info.DrugId,
  2219. Count: info.Count,
  2220. Status: 1,
  2221. Ctime: ctime,
  2222. OrgId: adminUserInfo.CurrentOrgId,
  2223. Type: 1,
  2224. Manufacturer: manufactureName.ManufacturerName,
  2225. Dealer: dealer.DealerName,
  2226. Total: 0,
  2227. RetailPrice: info.RetailPrice,
  2228. RetailTotalPrice: info.RetailTotalPrice,
  2229. Price: info.Price,
  2230. RegisterAccount: "",
  2231. Remark: info.Remark,
  2232. BatchNumber: info.BatchNumber,
  2233. MaxUnit: info.CountUnit,
  2234. ProductDate: info.ProductDate,
  2235. ExpiryDate: info.ExpiryDate,
  2236. BatchNumberId: info.WarehouseInfoId,
  2237. StorehouseId: houseConfig.DrugStorehouseOut,
  2238. }
  2239. flow := models.DrugFlow{
  2240. WarehousingId: 0,
  2241. DrugId: info.DrugId,
  2242. Number: "",
  2243. BatchNumber: info.BatchNumber,
  2244. Count: info.Count,
  2245. UserOrgId: adminUserInfo.CurrentOrgId,
  2246. PatientId: 0,
  2247. SystemTime: info.SysRecordTime,
  2248. ConsumableType: 7,
  2249. IsSys: 0,
  2250. WarehousingOrder: "",
  2251. WarehouseOutId: 0,
  2252. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2253. IsEdit: 0,
  2254. CancelStockId: cancelStock.ID,
  2255. CancelOrderNumber: cancelStock.OrderNumber,
  2256. Manufacturer: info.Manufacturer,
  2257. Dealer: info.Dealer,
  2258. Creator: adminUserInfo.AdminUser.Id,
  2259. UpdateCreator: 0,
  2260. Status: 1,
  2261. Ctime: time.Now().Unix(),
  2262. Mtime: 0,
  2263. Price: info.Price,
  2264. WarehousingDetailId: 0,
  2265. WarehouseOutDetailId: 0,
  2266. CancelOutDetailId: 0,
  2267. ExpireDate: info.ExpiryDate,
  2268. ProductDate: info.ProductDate,
  2269. MaxUnit: info.CountUnit,
  2270. MinUnit: "",
  2271. AdviceId: info.AdviceId,
  2272. StorehouseId: houseConfig.DrugStorehouseOut,
  2273. }
  2274. service.CreatedCancelStock(cancelStockInfo)
  2275. service.CreateDrugFlowOne(flow)
  2276. //删除出库记录
  2277. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2278. //删除流水
  2279. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2280. }
  2281. }
  2282. }
  2283. }
  2284. c.ServeSuccessJSON(map[string]interface{}{
  2285. "msg": "删除成功",
  2286. })
  2287. return
  2288. } else {
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2290. return
  2291. }
  2292. }
  2293. func (c *HisApiController) DeleteProject() {
  2294. id, _ := c.GetInt64("id")
  2295. adminInfo := c.GetAdminUserInfo()
  2296. project, _ := service.GetHisProjectByID(id)
  2297. // var consumable models.DialysisBeforePrepare
  2298. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2299. service.DeletePrintInfo(id)
  2300. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2301. label.Status = 0
  2302. service.CreateHisLabelRecord(&label)
  2303. if stockConfig.IsOpen == 1 {
  2304. if project.Type == 2 {
  2305. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2306. fmt.Println(err)
  2307. }
  2308. if project.Type == 3 {
  2309. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2310. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2311. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2312. good.Total = good.Total + f_count
  2313. service.UpdateGoodInfo(&good)
  2314. operation_time := time.Now().Unix()
  2315. creater := adminInfo.AdminUser.Id
  2316. //创建退库单
  2317. timeStr := time.Now().Format("2006-01-02")
  2318. timeArr := strings.Split(timeStr, "-")
  2319. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2320. total = total + 1
  2321. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2322. cancelStock := models.CancelStock{
  2323. OrderNumber: orderNumber,
  2324. OperaTime: operation_time,
  2325. OrgId: adminInfo.CurrentOrgId,
  2326. Creater: creater,
  2327. Ctime: time.Now().Unix(),
  2328. Status: 1,
  2329. ReturnTime: project.RecordDate,
  2330. Type: 1,
  2331. StorehouseId: houseConfig.StorehouseOutInfo,
  2332. }
  2333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2334. if msgerrkonde == gorm.ErrRecordNotFound {
  2335. service.AddSigleCancelStock(&cancelStock)
  2336. }
  2337. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2338. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2339. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2340. //获取该耗材有库存的第一条数据
  2341. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2342. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2343. deaerler, _ := service.GetDealerById(info.Dealer)
  2344. if info.ID > 0 {
  2345. cancelStockInfo := models.CancelStockInfo{
  2346. GoodId: project.ProjectId,
  2347. CancelStockId: cancel.ID,
  2348. GoodTypeId: good.GoodTypeId,
  2349. Count: prescribingNumber,
  2350. Price: info.Price,
  2351. Total: 0,
  2352. ProductDate: info.ProductDate,
  2353. ExpiryDate: info.ExpiryDate,
  2354. Ctime: time.Now().Unix(),
  2355. Status: 1,
  2356. OrgId: adminInfo.CurrentOrgId,
  2357. OrderNumber: cancel.OrderNumber,
  2358. Type: 0,
  2359. Dealer: deaerler.DealerName,
  2360. Manufacturer: manufacturer.ManufacturerName,
  2361. Number: info.Number,
  2362. RegisterAccount: "",
  2363. Remark: "",
  2364. WarehouseInfoId: info.WarehouseInfotId,
  2365. PatientId: info.PatientId,
  2366. RecordDate: info.SysRecordTime,
  2367. StorehouseId: houseConfig.StorehouseOutInfo,
  2368. }
  2369. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2370. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2371. flow := models.VmStockFlow{
  2372. WarehousingId: 0,
  2373. GoodId: project.ProjectId,
  2374. Number: info.Number,
  2375. LicenseNumber: info.LicenseNumber,
  2376. Count: prescribingNumber,
  2377. UserOrgId: adminInfo.CurrentOrgId,
  2378. PatientId: project.PatientId,
  2379. SystemTime: time.Now().Unix(),
  2380. ConsumableType: 7,
  2381. IsSys: 0,
  2382. WarehousingOrder: "",
  2383. WarehouseOutId: 0,
  2384. WarehouseOutOrderNumber: "",
  2385. IsEdit: 0,
  2386. CancelStockId: cancel.ID,
  2387. CancelOrderNumber: cancel.OrderNumber,
  2388. Manufacturer: manufacturer.ID,
  2389. Dealer: 0,
  2390. Creator: adminInfo.AdminUser.Id,
  2391. UpdateCreator: 0,
  2392. Status: 1,
  2393. Ctime: time.Now().Unix(),
  2394. Mtime: 0,
  2395. Price: info.Price,
  2396. WarehousingDetailId: info.WarehouseInfotId,
  2397. WarehouseOutDetailId: 0,
  2398. CancelOutDetailId: cancelInfo.ID,
  2399. ProductDate: info.ProductDate,
  2400. ExpireDate: info.ExpiryDate,
  2401. StorehouseId: houseConfig.StorehouseOutInfo,
  2402. }
  2403. service.CreateStockFlowOne(flow)
  2404. //删除出库表
  2405. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2406. //查询今日该患者开了多少耗材
  2407. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2408. var total_count int64
  2409. var cha_count int64
  2410. for _, item := range projectList {
  2411. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2412. total_count += count
  2413. }
  2414. //回退库存
  2415. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2416. //查询今日该耗材退库数量
  2417. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2418. var cancel_count int64
  2419. for _, items := range cancelInfoOne {
  2420. cancel_count += items.Count
  2421. }
  2422. cha_count = total_count - cancel_count
  2423. if total_count > cancel_count {
  2424. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2425. if err == gorm.ErrRecordNotFound {
  2426. //没有记录,则创建出库单
  2427. timeStr := time.Now().Format("2006-01-02")
  2428. timeArr := strings.Split(timeStr, "-")
  2429. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2430. total = total + 1
  2431. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2432. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2433. number = number + total
  2434. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2435. warehouseOut := models.WarehouseOut{
  2436. WarehouseOutOrderNumber: warehousing_out_order,
  2437. OperationTime: time.Now().Unix(),
  2438. OrgId: adminInfo.CurrentOrgId,
  2439. Creater: creater,
  2440. Ctime: time.Now().Unix(),
  2441. Status: 1,
  2442. WarehouseOutTime: info.SysRecordTime,
  2443. Dealer: 0,
  2444. Manufacturer: 0,
  2445. Type: 1,
  2446. IsSys: 1,
  2447. StorehouseId: houseConfig.StorehouseOutInfo,
  2448. }
  2449. err := service.AddSigleWarehouseOut(&warehouseOut)
  2450. if err != nil {
  2451. utils.TraceLog("创建出库单失败 err = %v", err)
  2452. return
  2453. }
  2454. prepare := &models.DialysisBeforePrepare{
  2455. UserOrgId: adminInfo.CurrentOrgId,
  2456. PatientId: info.PatientId,
  2457. RecordDate: info.SysRecordTime,
  2458. GoodId: project.ProjectId,
  2459. GoodTypeId: info.GoodTypeId,
  2460. Count: cha_count,
  2461. StorehouseId: houseConfig.StorehouseOutInfo,
  2462. }
  2463. //出库
  2464. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2465. } else if err == nil {
  2466. prepare := &models.DialysisBeforePrepare{
  2467. UserOrgId: adminInfo.CurrentOrgId,
  2468. PatientId: info.PatientId,
  2469. RecordDate: info.SysRecordTime,
  2470. GoodId: project.ProjectId,
  2471. GoodTypeId: info.GoodTypeId,
  2472. Count: cha_count,
  2473. StorehouseId: houseConfig.StorehouseOutInfo,
  2474. }
  2475. //出库
  2476. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2477. }
  2478. }
  2479. }
  2480. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2481. fmt.Println(err)
  2482. }
  2483. }
  2484. c.ServeSuccessJSON(map[string]interface{}{
  2485. "msg": "删除成功",
  2486. })
  2487. return
  2488. }
  2489. func (c *HisApiController) CreateHisAdditionalCharge() {
  2490. his_patient_id, _ := c.GetInt64("his_patient_id")
  2491. patient_id, _ := c.GetInt64("patient_id")
  2492. record_date := c.GetString("record_date")
  2493. timeLayout := "2006-01-02"
  2494. loc, _ := time.LoadLocation("Local")
  2495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2496. if err != nil {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2498. return
  2499. }
  2500. adminInfo := c.GetAdminUserInfo()
  2501. recordDateTime := theTime.Unix()
  2502. dataBody := make(map[string]interface{}, 0)
  2503. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2504. if err != nil {
  2505. utils.ErrorLog(err.Error())
  2506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2507. return
  2508. }
  2509. var additions []*models.HisAdditionalCharge
  2510. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2511. additions, _ := dataBody["addition"].([]interface{})
  2512. if len(additions) > 0 {
  2513. for _, item := range additions {
  2514. items := item.(map[string]interface{})
  2515. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2516. utils.ErrorLog("item_id")
  2517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2518. return
  2519. }
  2520. item_id := int64(items["item_id"].(float64))
  2521. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2522. utils.ErrorLog("item_name")
  2523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2524. return
  2525. }
  2526. item_name := items["item_name"].(string)
  2527. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2528. utils.ErrorLog("price")
  2529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2530. return
  2531. }
  2532. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2533. ctime := time.Now().Unix()
  2534. additional := &models.HisAdditionalCharge{
  2535. PatientId: patient_id,
  2536. HisPatientId: his_patient_id,
  2537. UserOrgId: adminInfo.CurrentOrgId,
  2538. RecordDate: recordDateTime,
  2539. CreatedTime: ctime,
  2540. UpdatedTime: ctime,
  2541. Modifier: adminInfo.AdminUser.Id,
  2542. Creator: adminInfo.AdminUser.Id,
  2543. Price: price,
  2544. ItemName: item_name,
  2545. ItemId: item_id,
  2546. Status: 1,
  2547. }
  2548. additions = append(additions, additional)
  2549. }
  2550. }
  2551. }
  2552. for _, item := range additions {
  2553. service.CreateAddtionalCharge(item)
  2554. }
  2555. c.ServeSuccessJSON(map[string]interface{}{
  2556. "msg": "创建成功",
  2557. })
  2558. }
  2559. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2560. blood_fat := c.GetString("blood_fat")
  2561. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2562. blood_sugar := c.GetString("blood_sugar")
  2563. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2564. chief_conplaint := c.GetString("chief_conplaint")
  2565. dbp := c.GetString("dbp")
  2566. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2567. delivery_way, _ := c.GetInt64("delivery_way")
  2568. diagnostic := c.GetString("diagnostic")
  2569. family_history := c.GetString("family_history")
  2570. height := c.GetString("height")
  2571. history_of_present_illness := c.GetString("history_of_present_illness")
  2572. is_infect, _ := c.GetInt64("is_infect")
  2573. past_history := c.GetString("past_history")
  2574. patient_id, _ := c.GetInt64("patient_id")
  2575. his_patient_id, _ := c.GetInt64("his_patient_id")
  2576. personal_history := c.GetString("personal_history")
  2577. pulse := c.GetString("pulse")
  2578. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2579. sbp := c.GetString("sbp")
  2580. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2581. heightfloat, _ := strconv.ParseFloat(height, 64)
  2582. sicktype := c.GetString("sick_type")
  2583. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2584. symptom := c.GetString("symptom")
  2585. sick_date := c.GetString("sick_date")
  2586. temperatures := c.GetString("temperature")
  2587. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2588. record_date := c.GetString("record_date")
  2589. breathing := c.GetString("breathing")
  2590. doctor_advice := c.GetString("doctor_advice")
  2591. remark := c.GetString("remark")
  2592. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2593. sick, _ := c.GetInt64("sick")
  2594. diagnose, _ := c.GetInt64("diagnose")
  2595. //id, _ := c.GetInt64("id")
  2596. timeLayout := "2006-01-02"
  2597. loc, _ := time.LoadLocation("Local")
  2598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2599. allergic_history := c.GetString("allergic_history")
  2600. if err != nil {
  2601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. recordDateTime := theTime.Unix()
  2605. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2606. if err != nil {
  2607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2608. return
  2609. }
  2610. sickTimes := sickTime.Unix()
  2611. ctime := time.Now().Unix()
  2612. primary_disease := c.GetString("primary_disease")
  2613. confirm_failure_date := c.GetString("confirm_failure_date")
  2614. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  2615. drug_allergy_history := c.GetString("drug_allergy_history")
  2616. physical_examination := c.GetString("physical_examination")
  2617. special_inspection := c.GetString("special_inspection")
  2618. lab_apparatus := c.GetString("lab_apparatus")
  2619. caseHistory := models.HisPatientCaseHistory{
  2620. HisPatientId: his_patient_id,
  2621. PatientId: patient_id,
  2622. Temperature: temperature,
  2623. BloodSugar: bloodsugarfloat,
  2624. Pulse: pulsefloat,
  2625. Sbp: sbpfloat,
  2626. Dbp: dbpfloat,
  2627. Height: heightfloat,
  2628. BloodFat: bloodfatfloat,
  2629. SickType: sick_type,
  2630. Symptom: symptom,
  2631. SickDate: sickTimes,
  2632. IsInfect: is_infect,
  2633. HistoryOfPresentIllness: history_of_present_illness,
  2634. PastHistory: past_history,
  2635. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2636. ChiefConplaint: chief_conplaint,
  2637. PersonalHistory: personal_history,
  2638. FamilyHistory: family_history,
  2639. Diagnostic: diagnostic,
  2640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2641. Status: 1,
  2642. Ctime: ctime,
  2643. Mtime: ctime,
  2644. RecordDate: recordDateTime,
  2645. DeliveryWay: delivery_way,
  2646. Breathing: breathingfloat,
  2647. DoctorAdvice: doctor_advice,
  2648. Remark: remark,
  2649. Sick: sick,
  2650. Diagnose: diagnose,
  2651. AllergicHistory: allergic_history,
  2652. PrimaryDisease: primary_disease,
  2653. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  2654. DrugAllergyHistory: drug_allergy_history,
  2655. PhysicalExamination: physical_examination,
  2656. SpecialInspection: special_inspection,
  2657. LabApparatus: lab_apparatus,
  2658. }
  2659. //查询该患者是否有病历
  2660. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  2661. if errcodes == gorm.ErrRecordNotFound {
  2662. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2663. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2664. if err != nil {
  2665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2666. return
  2667. }
  2668. c.ServeSuccessJSON(map[string]interface{}{
  2669. "caseHistory": caseHistory,
  2670. "historyInfo": historyInfo,
  2671. })
  2672. return
  2673. } else if errcodes == nil {
  2674. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  2675. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2676. if err != nil {
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2678. return
  2679. }
  2680. c.ServeSuccessJSON(map[string]interface{}{
  2681. "caseHistory": caseHistory,
  2682. "historyInfo": historyInfo,
  2683. })
  2684. }
  2685. //查询该患者是否有病历
  2686. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2687. //if errcode == gorm.ErrRecordNotFound {
  2688. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2689. // if err != nil {
  2690. // c.ServeSuccessJSON(map[string]interface{}{
  2691. // "msg": "保存成功",
  2692. // })
  2693. // }
  2694. //} else if errcode == nil {
  2695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2696. // return
  2697. //}
  2698. }
  2699. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2700. patient_id, _ := c.GetInt64("patient_id", 0)
  2701. adminUser := c.GetAdminUserInfo()
  2702. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2703. c.ServeSuccessJSON(map[string]interface{}{
  2704. "list": caseHistorys,
  2705. })
  2706. }
  2707. func (c *HisApiController) GetHisPatientCaseHistory() {
  2708. record_date, _ := c.GetInt64("record_date", 0)
  2709. patient_id, _ := c.GetInt64("patient_id", 0)
  2710. admin := c.GetAdminUserInfo()
  2711. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2712. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2713. c.ServeSuccessJSON(map[string]interface{}{
  2714. "info": info,
  2715. "case_history": case_history,
  2716. })
  2717. }
  2718. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2719. template_name := c.GetString("template_name")
  2720. template_remark := c.GetString("template_remark")
  2721. doctor := c.GetAdminUserInfo().AdminUser.Id
  2722. diagnostic := c.GetString("diagnostic")
  2723. chief_conplaint := c.GetString("chief_conplain")
  2724. history_of_present_illness := c.GetString("history_of_present_illness")
  2725. past_history := c.GetString("past_history")
  2726. personal_history := c.GetString("personal_history")
  2727. family_history := c.GetString("family_history")
  2728. user_name := c.GetString("user_name")
  2729. doctor_advice := c.GetString("doctor_advice")
  2730. remark := c.GetString("remark")
  2731. //record_date := c.GetString("record_date")
  2732. //fmt.Println("record_date--------",record_date)
  2733. //timeLayout := "2006-01-02"
  2734. //loc, _ := time.LoadLocation("Local")
  2735. //
  2736. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2737. //if err != nil {
  2738. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2739. // return
  2740. //}
  2741. //recordDateTime := theTime.Unix()
  2742. ctime := time.Now().Unix()
  2743. template := models.HisCaseHistoryTemplate{
  2744. HistoryOfPresentIllness: history_of_present_illness,
  2745. PastHistory: past_history,
  2746. ChiefConplaint: chief_conplaint,
  2747. PersonalHistory: personal_history,
  2748. FamilyHistory: family_history,
  2749. Diagnostic: diagnostic,
  2750. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2751. Status: 1,
  2752. Ctime: ctime,
  2753. Mtime: ctime,
  2754. RecordDate: time.Now().Unix(),
  2755. TemplateName: template_name,
  2756. TemplateRemark: template_remark,
  2757. Creator: doctor,
  2758. Modifier: doctor,
  2759. UserName: user_name,
  2760. DoctorAdvice: doctor_advice,
  2761. Remark: remark,
  2762. }
  2763. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2764. if err == nil {
  2765. c.ServeSuccessJSON(map[string]interface{}{
  2766. "msg": "保存成功",
  2767. })
  2768. } else {
  2769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2770. return
  2771. }
  2772. }
  2773. func (c *HisApiController) GetCaseHistoryTemplate() {
  2774. timeLayout := "2006-01-02"
  2775. loc, _ := time.LoadLocation("Local")
  2776. keyword := c.GetString("keyword")
  2777. start_time := c.GetString("start_time")
  2778. end_time := c.GetString("end_time")
  2779. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2780. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2781. admin := c.GetAdminUserInfo()
  2782. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2783. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2784. c.ServeSuccessJSON(map[string]interface{}{
  2785. "template": template,
  2786. //"history": history,
  2787. })
  2788. }
  2789. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2790. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2791. utils.ErrorLog("drug_name")
  2792. return enums.ErrorCodeParamWrong
  2793. }
  2794. adviceName, _ := json["drug_name"].(string)
  2795. if len(adviceName) == 0 {
  2796. utils.ErrorLog("len(advice_name) == 0")
  2797. return enums.ErrorCodeParamWrong
  2798. }
  2799. advice.AdviceName = adviceName
  2800. adviceDesc, _ := json["advice_desc"].(string)
  2801. advice.AdviceDesc = adviceDesc
  2802. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2803. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2804. advice.DrugSpec = drugSpec
  2805. }
  2806. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2807. remark, _ := json["remark"].(string)
  2808. advice.Remark = remark
  2809. }
  2810. if json["id"] == nil {
  2811. advice.DrugId = 0
  2812. } else {
  2813. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2814. drug_id := int64(json["id"].(float64))
  2815. advice.DrugId = drug_id
  2816. }
  2817. }
  2818. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2819. advice_id := int64(json["advice_id"].(float64))
  2820. advice.ID = advice_id
  2821. if advice.ID > 0 {
  2822. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2823. if err == nil {
  2824. if hisAdvice.ID > 0 {
  2825. advice.ExecutionTime = hisAdvice.ExecutionTime
  2826. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2827. advice.ExecutionState = hisAdvice.ExecutionState
  2828. advice.CheckTime = hisAdvice.CheckTime
  2829. advice.Checker = hisAdvice.Checker
  2830. advice.CheckState = hisAdvice.CheckState
  2831. advice.StartTime = hisAdvice.StartTime
  2832. advice.FeedetlSn = hisAdvice.FeedetlSn
  2833. }
  2834. }
  2835. }
  2836. }
  2837. //
  2838. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2839. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2840. // advice.ExecutionTime = execution_time
  2841. //}
  2842. //
  2843. //
  2844. //
  2845. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2846. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2847. // advice.ExecutionStaff = execution_staff
  2848. //}
  2849. //
  2850. //
  2851. //
  2852. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2853. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2854. // advice.ExecutionState = execution_state
  2855. //}
  2856. //
  2857. //
  2858. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2859. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2860. // advice.CheckTime = check_time
  2861. //}
  2862. //
  2863. //
  2864. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2865. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2866. // advice.CheckState = check_state
  2867. //}
  2868. //
  2869. //
  2870. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2871. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2872. // advice.Checker = checker
  2873. //}
  2874. //
  2875. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2876. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2877. // advice.StartTime = start_time
  2878. //}
  2879. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2880. drugSpecUnit, _ := json["min_unit"].(string)
  2881. advice.DrugSpecUnit = drugSpecUnit
  2882. }
  2883. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2884. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2885. advice.SingleDose = singleDose
  2886. }
  2887. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2888. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2889. advice.SingleDoseUnit = singleDoseUnit
  2890. }
  2891. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2892. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2893. advice.PrescribingNumber = prescribingNumber
  2894. }
  2895. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2896. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2897. advice.PrescribingNumberUnit = prescribingNumberUnit
  2898. }
  2899. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2900. deliveryWay, _ := json["delivery_way"].(string)
  2901. advice.DeliveryWay = deliveryWay
  2902. }
  2903. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2904. executionFrequency, _ := json["execution_frequency"].(string)
  2905. advice.ExecutionFrequency = executionFrequency
  2906. }
  2907. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2908. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2909. advice.Price = price
  2910. }
  2911. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2912. med_list_codg, _ := json["medical_insurance_number"].(string)
  2913. advice.MedListCodg = med_list_codg
  2914. }
  2915. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2916. day := int64(json["day"].(float64))
  2917. advice.Day = day
  2918. }
  2919. return 0
  2920. }
  2921. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2922. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2923. id := int64(json["id"].(float64))
  2924. project.ID = id
  2925. historyProject, _ := service.GetHisProjectByID(id)
  2926. project.FeedetlSn = historyProject.FeedetlSn
  2927. }
  2928. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2929. project_id := int64(json["project_id"].(float64))
  2930. project.ProjectId = project_id
  2931. }
  2932. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2933. // price := int64(json["price"].(float64))
  2934. // formatInt_price := strconv.FormatInt(price, 10)
  2935. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2936. // project.Price = float_price
  2937. // }
  2938. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2939. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2940. project.Price = price
  2941. }
  2942. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2943. total, _ := json["total"].(string)
  2944. project.Count = total
  2945. }
  2946. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2947. medical_code, _ := json["medical_code"].(string)
  2948. project.MedListCodg = medical_code
  2949. }
  2950. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2951. single_dose, _ := json["single_dose"].(string)
  2952. project.SingleDose = single_dose
  2953. }
  2954. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2955. delivery_way, _ := json["delivery_way"].(string)
  2956. project.DeliveryWay = delivery_way
  2957. }
  2958. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2959. execution_frequency, _ := json["execution_frequency"].(string)
  2960. project.ExecutionFrequency = execution_frequency
  2961. }
  2962. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2963. remark, _ := json["remark"].(string)
  2964. project.Remark = remark
  2965. }
  2966. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2967. day, _ := json["number_days"].(string)
  2968. project.Day = day
  2969. }
  2970. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2971. unit, _ := json["unit"].(string)
  2972. project.Unit = unit
  2973. }
  2974. return 0
  2975. }
  2976. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2977. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2978. id := int64(json["id"].(float64))
  2979. historyAddtions, _ := service.GetHisAdditionByID(id)
  2980. additionalCharge.ID = id
  2981. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2982. }
  2983. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2984. item_id := int64(json["item_id"].(float64))
  2985. additionalCharge.ItemId = item_id
  2986. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2987. if config.ID > 0 {
  2988. if len(config.Code) > 0 {
  2989. additionalCharge.MedListCodg = config.Code
  2990. }
  2991. }
  2992. }
  2993. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2994. // price := int64(json["price"].(float64))
  2995. // formatInt_price := strconv.FormatInt(price, 10)
  2996. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2997. // additionalCharge.Price = float_price
  2998. // }
  2999. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3000. // price := int64(json["price"].(float64))
  3001. // formatInt_price := strconv.FormatInt(price, 10)
  3002. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3003. // additionalCharge.Price = float_price
  3004. //}
  3005. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3006. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3007. additionalCharge.Price = price
  3008. }
  3009. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3010. count, _ := json["count"].(string)
  3011. counts, _ := strconv.ParseInt(count, 10, 64)
  3012. additionalCharge.Count = counts
  3013. }
  3014. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3015. item_name, _ := json["item_name"].(string)
  3016. additionalCharge.ItemName = item_name
  3017. }
  3018. return 0
  3019. }
  3020. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3021. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3022. utils.ErrorLog("drug_name")
  3023. return enums.ErrorCodeParamWrong
  3024. }
  3025. adviceName, _ := json["drug_name"].(string)
  3026. if len(adviceName) == 0 {
  3027. utils.ErrorLog("len(advice_name) == 0")
  3028. return enums.ErrorCodeParamWrong
  3029. }
  3030. advice.AdviceName = adviceName
  3031. adviceDesc, _ := json["advice_desc"].(string)
  3032. advice.AdviceDesc = adviceDesc
  3033. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3034. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3035. advice.DrugSpec = drugSpec
  3036. }
  3037. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3038. remark, _ := json["remark"].(string)
  3039. advice.Remark = remark
  3040. }
  3041. if json["id"] == nil {
  3042. advice.DrugId = 0
  3043. } else {
  3044. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3045. drug_id := int64(json["id"].(float64))
  3046. advice.DrugId = drug_id
  3047. }
  3048. }
  3049. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3050. groupno := int64(json["groupno"].(float64))
  3051. advice.Groupno = groupno
  3052. }
  3053. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3054. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3055. advice.HospApprFlag = hosp_appr_flag
  3056. }
  3057. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3058. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3059. advice.PrescribingNumber = prescribingNumber
  3060. }
  3061. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3062. // frequency_type := int64(json["frequency_type"].(float64))
  3063. // advice.FrequencyType = frequency_type
  3064. //}
  3065. //
  3066. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3067. // day_count := int64(json["day_count"].(float64))
  3068. // advice.DayCount = day_count
  3069. //}
  3070. //
  3071. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3072. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3073. // week_day, _ := json["week_day"].(string)
  3074. // advice.WeekDay = week_day
  3075. //}
  3076. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3077. drugSpecUnit, _ := json["min_unit"].(string)
  3078. advice.DrugSpecUnit = drugSpecUnit
  3079. }
  3080. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3081. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3082. advice.SingleDose = singleDose
  3083. }
  3084. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3085. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3086. advice.SingleDoseUnit = singleDoseUnit
  3087. }
  3088. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3089. deliveryWay, _ := json["delivery_way"].(string)
  3090. advice.DeliveryWay = deliveryWay
  3091. }
  3092. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3093. executionFrequency, _ := json["execution_frequency"].(string)
  3094. advice.ExecutionFrequency = executionFrequency
  3095. }
  3096. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3097. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3098. advice.Price = price
  3099. }
  3100. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3101. med_list_codg, _ := json["medical_insurance_number"].(string)
  3102. advice.MedListCodg = med_list_codg
  3103. }
  3104. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3105. day := int64(json["day"].(float64))
  3106. advice.Day = day
  3107. }
  3108. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3109. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3110. advice.PrescribingNumberUnit = prescribingNumberUnit
  3111. }
  3112. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3113. advice_id := int64(json["advice_id"].(float64))
  3114. advice.ID = advice_id
  3115. if advice.ID > 0 {
  3116. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3117. if err == nil {
  3118. if hisAdvice.ID > 0 {
  3119. advice.ExecutionTime = hisAdvice.ExecutionTime
  3120. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3121. advice.ExecutionState = hisAdvice.ExecutionState
  3122. advice.CheckTime = hisAdvice.CheckTime
  3123. advice.Checker = hisAdvice.Checker
  3124. advice.CheckState = hisAdvice.CheckState
  3125. advice.StartTime = hisAdvice.StartTime
  3126. advice.HospApprFlag = hisAdvice.HospApprFlag
  3127. if hisAdvice.UserOrgId == 10028 {
  3128. 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 {
  3129. advice.ExecutionTime = 0
  3130. advice.ExecutionStaff = 0
  3131. advice.ExecutionState = 2
  3132. advice.CheckTime = 0
  3133. advice.Checker = 0
  3134. advice.CheckState = 2
  3135. }
  3136. } else {
  3137. 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 {
  3138. advice.ExecutionTime = 0
  3139. advice.ExecutionStaff = 0
  3140. advice.ExecutionState = 2
  3141. advice.CheckTime = 0
  3142. advice.Checker = 0
  3143. advice.CheckState = 2
  3144. }
  3145. }
  3146. //advice.Groupno = hisAdvice.Groupno
  3147. }
  3148. }
  3149. }
  3150. }
  3151. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3152. //
  3153. //if drugStockConfig.IsOpen == 1 {
  3154. //
  3155. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3156. // if advice.ID == 0 { //医嘱不存在
  3157. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3158. // drug.Total = drug.Total - advice.PrescribingNumber
  3159. // service.UpdateBaseDrugLib(&drug)
  3160. //
  3161. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3162. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3163. // drug.Total = drug.Total - num
  3164. // service.UpdateBaseDrugLib(&drug)
  3165. // }
  3166. //
  3167. // } else if advice.ID > 0 { //医嘱存在
  3168. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3169. // var num float64
  3170. //
  3171. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3172. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3173. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3174. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3175. // drug.Total = drug.Total + num
  3176. // service.UpdateBaseDrugLib(&drug)
  3177. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3178. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3179. // drug.Total = drug.Total - num
  3180. // service.UpdateBaseDrugLib(&drug)
  3181. // }
  3182. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3183. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3184. // if num2 > advice.PrescribingNumber {
  3185. // num = num2 - advice.PrescribingNumber
  3186. // drug.Total = drug.Total + num
  3187. // service.UpdateBaseDrugLib(&drug)
  3188. // } else if num2 < advice.PrescribingNumber {
  3189. // num = advice.PrescribingNumber - num2
  3190. // drug.Total = drug.Total - num
  3191. // service.UpdateBaseDrugLib(&drug)
  3192. // }
  3193. //
  3194. // }
  3195. //
  3196. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3197. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3198. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3199. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3200. // if num1 > num2 {
  3201. // num = num1 - num2
  3202. // drug.Total = drug.Total + num
  3203. // service.UpdateBaseDrugLib(&drug)
  3204. // } else if num1 < num2 {
  3205. // num = num2 - num1
  3206. // drug.Total = drug.Total - num
  3207. // service.UpdateBaseDrugLib(&drug)
  3208. // }
  3209. //
  3210. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3211. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3212. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3213. // if hisAdvice.PrescribingNumber > num2 {
  3214. // num = hisAdvice.PrescribingNumber - num2
  3215. // drug.Total = drug.Total + num
  3216. // service.UpdateBaseDrugLib(&drug)
  3217. // } else if num2 < advice.PrescribingNumber {
  3218. // num = num2 - hisAdvice.PrescribingNumber
  3219. // drug.Total = drug.Total - num
  3220. // service.UpdateBaseDrugLib(&drug)
  3221. // }
  3222. //
  3223. // }
  3224. // }
  3225. // }
  3226. //}
  3227. //
  3228. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3229. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3230. // advice.ExecutionTime = execution_time
  3231. //}
  3232. //
  3233. //
  3234. //
  3235. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3236. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3237. // advice.ExecutionStaff = execution_staff
  3238. //}
  3239. //
  3240. //
  3241. //
  3242. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3243. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3244. // advice.ExecutionState = execution_state
  3245. //}
  3246. //
  3247. //
  3248. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3249. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3250. // advice.CheckTime = check_time
  3251. //}
  3252. //
  3253. //
  3254. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3255. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3256. // advice.CheckState = check_state
  3257. //}
  3258. //
  3259. //
  3260. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3261. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3262. // advice.Checker = checker
  3263. //}
  3264. //
  3265. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3266. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3267. // advice.StartTime = start_time
  3268. //}
  3269. return 0
  3270. }
  3271. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3272. project.ExecutionStaff = 0
  3273. project.ExecutionState = 2
  3274. project.ExecutionTime = 0
  3275. project.Checker = 0
  3276. project.CheckState = 2
  3277. project.CheckTime = 0
  3278. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3279. id := int64(json["id"].(float64))
  3280. project.ID = id
  3281. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3282. project.ExecutionStaff = temp_project.ExecutionStaff
  3283. project.ExecutionState = temp_project.ExecutionState
  3284. project.ExecutionTime = temp_project.ExecutionTime
  3285. project.Checker = temp_project.Checker
  3286. project.CheckState = temp_project.CheckState
  3287. project.CheckTime = temp_project.CheckTime
  3288. project.TeamId = temp_project.TeamId
  3289. }
  3290. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3291. types := int64(json["type"].(float64))
  3292. project.Type = types
  3293. }
  3294. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3295. project_id := int64(json["project_id"].(float64))
  3296. project.ProjectId = project_id
  3297. }
  3298. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3299. team_id := int64(json["team_id"].(float64))
  3300. project.TeamId = team_id
  3301. }
  3302. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3303. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3304. project.Price = price
  3305. }
  3306. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3307. total, _ := json["total"].(string)
  3308. //totals, _ := strconv.ParseInt(total, 10, 64)
  3309. project.Count = total
  3310. }
  3311. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3312. medical_code, _ := json["medical_code"].(string)
  3313. project.MedListCodg = medical_code
  3314. }
  3315. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3316. single_dose, _ := json["single_dose"].(string)
  3317. project.SingleDose = single_dose
  3318. }
  3319. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3320. delivery_way, _ := json["delivery_way"].(string)
  3321. project.DeliveryWay = delivery_way
  3322. }
  3323. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3324. execution_frequency, _ := json["execution_frequency"].(string)
  3325. project.ExecutionFrequency = execution_frequency
  3326. }
  3327. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3328. remark, _ := json["remark"].(string)
  3329. project.Remark = remark
  3330. }
  3331. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3332. day, _ := json["number_days"].(string)
  3333. project.Day = day
  3334. }
  3335. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3336. unit, _ := json["unit"].(string)
  3337. project.Unit = unit
  3338. }
  3339. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3340. // frequency_type := int64(json["frequency_type"].(float64))
  3341. // project.FrequencyType = frequency_type
  3342. //}
  3343. //
  3344. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3345. // day_count := int64(json["day_count"].(float64))
  3346. // project.DayCount = day_count
  3347. //}
  3348. //
  3349. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3350. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3351. // week_day, _ := json["week_day"].(string)
  3352. // project.WeekDay = week_day
  3353. //}
  3354. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3355. //
  3356. //if project.ID == 0 {
  3357. // if stockConfig.IsOpen == 1 {
  3358. // if project.Type == 3 {
  3359. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3360. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3361. // good.Total = good.Total - f_count
  3362. // service.UpdateGoodInfo(&good)
  3363. // }
  3364. // }
  3365. //
  3366. //} else {
  3367. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3368. //
  3369. // if stockConfig.IsOpen == 1 {
  3370. // if project.Type == 3 {
  3371. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3372. // if project.Count < temp_project.Count {
  3373. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3374. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3375. //
  3376. // other_count := f_count_two - f_count_one
  3377. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3378. // good.Total = good.Total + other_count_two
  3379. // service.UpdateGoodInfo(&good)
  3380. // } else if project.Count > temp_project.Count {
  3381. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3382. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3383. //
  3384. // other_count := f_count_one - f_count_two
  3385. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3386. // good.Total = good.Total - other_count_two
  3387. // service.UpdateGoodInfo(&good)
  3388. // }
  3389. //
  3390. // }
  3391. // }
  3392. //
  3393. //}
  3394. return 0
  3395. }
  3396. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3397. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3398. id := int64(json["id"].(float64))
  3399. additionalCharge.ID = id
  3400. }
  3401. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3402. item_id := int64(json["item_id"].(float64))
  3403. additionalCharge.ItemId = item_id
  3404. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3405. if config.ID > 0 {
  3406. if len(config.Code) > 0 {
  3407. additionalCharge.MedListCodg = config.Code
  3408. }
  3409. }
  3410. }
  3411. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3412. // price := int64(json["price"].(float64))
  3413. // formatInt_price := strconv.FormatInt(price, 10)
  3414. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3415. // additionalCharge.Price = float_price
  3416. // }
  3417. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3418. // price := int64(json["price"].(float64))
  3419. // formatInt_price := strconv.FormatInt(price, 10)
  3420. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3421. // additionalCharge.Price = float_price
  3422. //}
  3423. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3424. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3425. additionalCharge.Price = price
  3426. }
  3427. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3428. count, _ := json["count"].(string)
  3429. counts, _ := strconv.ParseInt(count, 10, 64)
  3430. additionalCharge.Count = counts
  3431. }
  3432. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3433. item_name, _ := json["item_name"].(string)
  3434. additionalCharge.ItemName = item_name
  3435. }
  3436. return 0
  3437. }
  3438. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3439. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3440. utils.ErrorLog("drug_name")
  3441. return enums.ErrorCodeParamWrong
  3442. }
  3443. adviceName, _ := json["drug_name"].(string)
  3444. if len(adviceName) == 0 {
  3445. utils.ErrorLog("len(advice_name) == 0")
  3446. return enums.ErrorCodeParamWrong
  3447. }
  3448. advice.AdviceName = adviceName
  3449. adviceDesc, _ := json["advice_desc"].(string)
  3450. advice.AdviceDesc = adviceDesc
  3451. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3452. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3453. advice.DrugSpec = drugSpec
  3454. }
  3455. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3456. remark, _ := json["remark"].(string)
  3457. advice.Remark = remark
  3458. }
  3459. if json["id"] == nil {
  3460. advice.DrugId = 0
  3461. } else {
  3462. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3463. drug_id := int64(json["id"].(float64))
  3464. advice.DrugId = drug_id
  3465. }
  3466. }
  3467. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3468. drugSpecUnit, _ := json["min_unit"].(string)
  3469. advice.DrugSpecUnit = drugSpecUnit
  3470. }
  3471. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3472. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3473. advice.SingleDose = singleDose
  3474. }
  3475. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3476. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3477. advice.SingleDoseUnit = singleDoseUnit
  3478. }
  3479. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3480. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3481. advice.PrescribingNumber = prescribingNumber
  3482. }
  3483. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3484. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3485. advice.PrescribingNumberUnit = prescribingNumberUnit
  3486. }
  3487. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3488. deliveryWay, _ := json["delivery_way"].(string)
  3489. advice.DeliveryWay = deliveryWay
  3490. }
  3491. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3492. executionFrequency, _ := json["execution_frequency"].(string)
  3493. advice.ExecutionFrequency = executionFrequency
  3494. }
  3495. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3496. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3497. advice.Price = price
  3498. }
  3499. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3500. med_list_codg, _ := json["medical_insurance_number"].(string)
  3501. advice.MedListCodg = med_list_codg
  3502. }
  3503. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3504. day := int64(json["day"].(float64))
  3505. advice.Day = day
  3506. }
  3507. return 0
  3508. }
  3509. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3510. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3511. types := int64(json["type"].(float64))
  3512. project.Type = types
  3513. }
  3514. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3515. project_id := int64(json["project_id"].(float64))
  3516. project.ProjectId = project_id
  3517. }
  3518. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3519. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3520. project.Price = price
  3521. }
  3522. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3523. total, _ := json["total"].(string)
  3524. //totals, _ := strconv.ParseInt(total, 10, 64)
  3525. project.Count = total
  3526. }
  3527. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3528. medical_code, _ := json["medical_code"].(string)
  3529. project.MedListCodg = medical_code
  3530. }
  3531. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3532. single_dose, _ := json["single_dose"].(string)
  3533. project.SingleDose = single_dose
  3534. }
  3535. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3536. delivery_way, _ := json["delivery_way"].(string)
  3537. project.DeliveryWay = delivery_way
  3538. }
  3539. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3540. execution_frequency, _ := json["execution_frequency"].(string)
  3541. project.ExecutionFrequency = execution_frequency
  3542. }
  3543. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3544. remark, _ := json["remark"].(string)
  3545. project.Remark = remark
  3546. }
  3547. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3548. day, _ := json["number_days"].(string)
  3549. project.Day = day
  3550. }
  3551. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3552. unit, _ := json["unit"].(string)
  3553. project.Unit = unit
  3554. }
  3555. return 0
  3556. }
  3557. func (c *HisApiController) GetHisOrderList() {
  3558. page, _ := c.GetInt64("page", -1)
  3559. limit, _ := c.GetInt64("limit", -1)
  3560. start_time := c.GetString("start_time")
  3561. end_time := c.GetString("end_time")
  3562. types, _ := c.GetInt64("type", 0)
  3563. keywords := c.GetString("keywords")
  3564. p_type, _ := c.GetInt64("p_type", 0)
  3565. sort_type, _ := c.GetInt64("sort_type", 0)
  3566. charge_type, _ := c.GetInt64("charge_type", 0)
  3567. timeLayout := "2006-01-02"
  3568. loc, _ := time.LoadLocation("Local")
  3569. var startTime int64
  3570. if len(start_time) > 0 {
  3571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3572. if err != nil {
  3573. //fmt.Println(err)
  3574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3575. return
  3576. }
  3577. startTime = theTime.Unix()
  3578. }
  3579. var endTime int64
  3580. if len(end_time) > 0 {
  3581. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3582. if err != nil {
  3583. utils.ErrorLog(err.Error())
  3584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3585. return
  3586. }
  3587. endTime = theTime.Unix()
  3588. }
  3589. adminUser := c.GetAdminUserInfo()
  3590. org_id := adminUser.CurrentOrgId
  3591. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  3592. for _, item := range order {
  3593. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3594. item.DoctorName = info.Doctor
  3595. item.DepartmentName = info.XtHisDepartment.Name
  3596. }
  3597. if err == nil {
  3598. c.ServeSuccessJSON(map[string]interface{}{
  3599. "order": order,
  3600. "total": total,
  3601. })
  3602. } else {
  3603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3604. return
  3605. }
  3606. }
  3607. func (c *HisApiController) GetHisOrder() {
  3608. patient_id, _ := c.GetInt64("patient_id", 0)
  3609. number := c.GetString("number")
  3610. adminInfo := c.GetAdminUserInfo()
  3611. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3612. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3613. if err == nil {
  3614. c.ServeSuccessJSON(map[string]interface{}{
  3615. "order": order,
  3616. "prescription": prescriptions,
  3617. })
  3618. } else {
  3619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3620. return
  3621. }
  3622. }
  3623. func (c *HisApiController) GetHisPrescriptionList() {
  3624. record_date := c.GetString("record_date")
  3625. keywords := c.GetString("keywords")
  3626. page, _ := c.GetInt64("page")
  3627. limit, _ := c.GetInt64("limit")
  3628. timeLayout := "2006-01-02"
  3629. loc, _ := time.LoadLocation("Local")
  3630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3631. if err != nil {
  3632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3633. return
  3634. }
  3635. recordDateTime := theTime.Unix()
  3636. adminInfo := c.GetAdminUserInfo()
  3637. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3638. //adminInfo := c.GetAdminUserInfo()
  3639. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3640. //fmt.Println(prescriptionOrder)
  3641. if err == nil {
  3642. c.ServeSuccessJSON(map[string]interface{}{
  3643. "order": prescriptionOrder,
  3644. "total": total,
  3645. })
  3646. } else {
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3648. return
  3649. }
  3650. }
  3651. func (c *HisApiController) GetHisPrescriptionInfo() {
  3652. id, _ := c.GetInt64("id")
  3653. adminInfo := c.GetAdminUserInfo()
  3654. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3655. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3656. if err == nil {
  3657. c.ServeSuccessJSON(map[string]interface{}{
  3658. "order": prescriptionOrder,
  3659. "prescription": prescription,
  3660. })
  3661. } else {
  3662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3663. return
  3664. }
  3665. }
  3666. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3667. adminUser := c.GetAdminUserInfo()
  3668. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3669. c.ServeSuccessJSON(map[string]interface{}{
  3670. "config": config,
  3671. })
  3672. }
  3673. type ResultTwo struct {
  3674. ErrMsg interface{} `json:"err_msg"`
  3675. InfRefmsgid string `json:"inf_refmsgid"`
  3676. Infcode int64 `json:"infcode"`
  3677. Output struct {
  3678. Baseinfo struct {
  3679. Age float64 `json:"age"`
  3680. Brdy string `json:"brdy"`
  3681. Certno string `json:"certno"`
  3682. Gend string `json:"gend"`
  3683. Naty string `json:"naty"`
  3684. PsnCertType string `json:"psn_cert_type"`
  3685. PsnName string `json:"psn_name"`
  3686. PsnNo string `json:"psn_no"`
  3687. } `json:"baseinfo"`
  3688. Idetinfo []interface{} `json:"idetinfo"`
  3689. Iinfo []struct {
  3690. Balc float64 `json:"balc"`
  3691. CvlservFlag string `json:"cvlserv_flag"`
  3692. EmpName string `json:"emp_name"`
  3693. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3694. Insutype string `json:"insutype"`
  3695. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3696. PausInsuDate interface{} `json:"paus_insu_date"`
  3697. PsnInsuDate string `json:"psn_insu_date"`
  3698. PsnInsuStas string `json:"psn_insu_stas"`
  3699. PsnType string `json:"psn_type"`
  3700. } `json:"insuinfo"`
  3701. } `json:"output"`
  3702. RefmsgTime string `json:"refmsg_time"`
  3703. RespondTime string `json:"respond_time"`
  3704. Signtype interface{} `json:"signtype"`
  3705. WarnInfo interface{} `json:"warn_info"`
  3706. }
  3707. type ResultThree struct {
  3708. Cainfo interface{} `json:"cainfo"`
  3709. ErrMsg interface{} `json:"err_msg"`
  3710. InfRefmsgid string `json:"inf_refmsgid"`
  3711. Infcode int64 `json:"infcode"`
  3712. Output struct {
  3713. Data struct {
  3714. IptOtpNo string `json:"ipt_otp_no"`
  3715. MdtrtID string `json:"mdtrt_id"`
  3716. PsnNo string `json:"psn_no"`
  3717. } `json:"data"`
  3718. } `json:"output"`
  3719. RefmsgTime string `json:"refmsg_time"`
  3720. RespondTime string `json:"respond_time"`
  3721. Signtype interface{} `json:"signtype"`
  3722. WarnMsg interface{} `json:"warn_msg"`
  3723. }
  3724. type ResultFour struct {
  3725. Cainfo string `json:"cainfo"`
  3726. ErrMsg string `json:"err_msg"`
  3727. InfRefmsgid string `json:"inf_refmsgid"`
  3728. Infcode int64 `json:"infcode"`
  3729. Output struct {
  3730. Result []struct {
  3731. BasMednFlag string `json:"bas_medn_flag"`
  3732. ChldMedcFlag string `json:"chld_medc_flag"`
  3733. ChrgitmLv string `json:"chrgitm_lv"`
  3734. Cnt float64 `json:"cnt"`
  3735. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3736. DrtReimFlag string `json:"drt_reim_flag"`
  3737. FeedetlSn string `json:"feedetl_sn"`
  3738. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3739. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3740. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3741. ListSpItemFlag string `json:"list_sp_item_flag"`
  3742. LmtUsedFlag string `json:"lmt_used_flag"`
  3743. MedChrgitmType string `json:"med_chrgitm_type"`
  3744. Memo string `json:"memo"`
  3745. OverlmtAmt float64 `json:"overlmt_amt"`
  3746. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3747. Pric float64 `json:"pric"`
  3748. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3749. SelfpayProp float64 `json:"selfpay_prop"`
  3750. } `json:"result"`
  3751. } `json:"output"`
  3752. RefmsgTime string `json:"refmsg_time"`
  3753. RespondTime string `json:"respond_time"`
  3754. Signtype string `json:"signtype"`
  3755. WarnMsg string `json:"warn_msg"`
  3756. }
  3757. type ResultFive struct {
  3758. Insutype string `json:"insutype"`
  3759. }
  3760. type ResultSix struct {
  3761. Cainfo interface{} `json:"cainfo"`
  3762. ErrMsg interface{} `json:"err_msg"`
  3763. InfRefmsgid string `json:"inf_refmsgid"`
  3764. Infcode int64 `json:"infcode"`
  3765. Output struct {
  3766. } `json:"output"`
  3767. RefmsgTime string `json:"refmsg_time"`
  3768. RespondTime string `json:"respond_time"`
  3769. Signtype interface{} `json:"signtype"`
  3770. WarnMsg interface{} `json:"warn_msg"`
  3771. }
  3772. type ResultSeven struct {
  3773. Cainfo string `json:"cainfo"`
  3774. ErrMsg string `json:"err_msg"`
  3775. InfRefmsgid string `json:"inf_refmsgid"`
  3776. Infcode int64 `json:"infcode"`
  3777. Output struct {
  3778. Setldetail []interface{} `json:"setldetail"`
  3779. Setlinfo struct {
  3780. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3781. AcctPay float64 `json:"acct_pay"`
  3782. ActPayDedc float64 `json:"act_pay_dedc"`
  3783. Age float64 `json:"age"`
  3784. Balc float64 `json:"balc"`
  3785. Brdy string `json:"brdy"`
  3786. Certno string `json:"certno"`
  3787. ClrOptins string `json:"clr_optins"`
  3788. ClrType string `json:"clr_type"`
  3789. ClrWay string `json:"clr_way"`
  3790. CvlservFlag string `json:"cvlserv_flag"`
  3791. CvlservPay float64 `json:"cvlserv_pay"`
  3792. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3793. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3794. Gend string `json:"gend"`
  3795. HifesPay float64 `json:"hifes_pay"`
  3796. HifmiPay float64 `json:"hifmi_pay"`
  3797. HifobPay float64 `json:"hifob_pay"`
  3798. HifpPay float64 `json:"hifp_pay"`
  3799. HospPartAmt float64 `json:"hosp_part_amt"`
  3800. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3801. Insutype string `json:"insutype"`
  3802. MafPay float64 `json:"maf_pay"`
  3803. MdtrtCertType string `json:"mdtrt_cert_type"`
  3804. MdtrtID string `json:"mdtrt_id"`
  3805. MedType string `json:"med_type"`
  3806. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3807. MedinsSetlID string `json:"medins_setl_id"`
  3808. Naty string `json:"naty"`
  3809. OthPay float64 `json:"oth_pay"`
  3810. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3811. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3812. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3813. PsnCashPay float64 `json:"psn_cash_pay"`
  3814. PsnCertType string `json:"psn_cert_type"`
  3815. PsnName string `json:"psn_name"`
  3816. PsnNo string `json:"psn_no"`
  3817. PsnPartAmt float64 `json:"psn_part_amt"`
  3818. PsnType string `json:"psn_type"`
  3819. SetlID string `json:"setl_id"`
  3820. SetlTime string `json:"setl_time"`
  3821. } `json:"setlinfo"`
  3822. } `json:"output"`
  3823. RefmsgTime string `json:"refmsg_time"`
  3824. RespondTime string `json:"respond_time"`
  3825. Signtype interface{} `json:"signtype"`
  3826. WarnMsg interface{} `json:"warn_msg"`
  3827. }
  3828. type ResultEight struct {
  3829. Cainfo string `json:"cainfo"`
  3830. ErrMsg string `json:"err_msg"`
  3831. InfRefmsgid string `json:"inf_refmsgid"`
  3832. Infcode int64 `json:"infcode"`
  3833. Output struct {
  3834. Stmtinfo struct {
  3835. SetlOptins string `json:"setl_optins"`
  3836. StmtRslt string `json:"stmt_rslt"`
  3837. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3838. } `json:"stmtinfo"`
  3839. } `json:"output"`
  3840. RefmsgTime string `json:"refmsg_time"`
  3841. RespondTime string `json:"respond_time"`
  3842. Signtype interface{} `json:"signtype"`
  3843. WarnMsg interface{} `json:"warn_msg"`
  3844. }
  3845. type ResultNine struct {
  3846. Cainfo string `json:"cainfo"`
  3847. ErrMsg string `json:"err_msg"`
  3848. InfRefmsgid string `json:"inf_refmsgid"`
  3849. Infcode int64 `json:"infcode"`
  3850. Output struct {
  3851. FileQuryNo string `json:"file_qury_no"`
  3852. } `json:"output"`
  3853. RefmsgTime string `json:"refmsg_time"`
  3854. RespondTime string `json:"respond_time"`
  3855. Signtype interface{} `json:"signtype"`
  3856. WarnMsg interface{} `json:"warn_msg"`
  3857. }
  3858. type ResultTen struct {
  3859. Cainfo string `json:"cainfo"`
  3860. ErrMsg string `json:"err_msg"`
  3861. InfRefmsgid string `json:"inf_refmsgid"`
  3862. Infcode int64 `json:"infcode"`
  3863. Output struct {
  3864. DldEndtime string `json:"dld_endtime"`
  3865. FileQuryNo string `json:"file_qury_no"`
  3866. Filename string `json:"filename"`
  3867. } `json:"output"`
  3868. RefmsgTime string `json:"refmsg_time"`
  3869. RespondTime string `json:"respond_time"`
  3870. Signtype interface{} `json:"signtype"`
  3871. WarnMsg interface{} `json:"warn_msg"`
  3872. }
  3873. type ResultEleven struct {
  3874. Cainfo string `json:"cainfo"`
  3875. ErrMsg string `json:"err_msg"`
  3876. InfRefmsgid string `json:"inf_refmsgid"`
  3877. Infcode int64 `json:"infcode"`
  3878. Output struct {
  3879. Setlinfo struct {
  3880. FixmedinsName string `json:"fixmedins_name"`
  3881. FixmedinsCode string `json:"fixmedins_code"`
  3882. PsnNo string `json:"psn_no"`
  3883. PsnName string `json:"psn_name"`
  3884. HifobPay float64 `json:"hifob_pay"`
  3885. Gend string `json:"gend"`
  3886. Brdy string `json:"brdy"`
  3887. PsnCertType string `json:"psn_cert_type"`
  3888. PsnType string `json:"psn_type"`
  3889. EmpName string `json:"emp_name"`
  3890. Certno string `json:"certno"`
  3891. Insutype string `json:"insutype"`
  3892. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3893. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3894. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3895. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3896. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3897. ActPayDedc float64 `json:"act_pay_dedc"`
  3898. HifpPay float64 `json:"hifp_pay"`
  3899. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3900. CvlservPay float64 `json:"cvlserv_pay"`
  3901. HifesPay float64 `json:"hifes_pay"`
  3902. HifmiPay float64 `json:"hifmi_pay"`
  3903. MafPay float64 `json:"maf_pay"`
  3904. OthPay float64 `json:"oth_pay"`
  3905. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3906. PsnPay float64 `json:"psn_pay"`
  3907. AcctPay float64 `json:"acct_pay"`
  3908. CashPayamt float64 `json:"cash_payamt"`
  3909. Balc float64 `json:"balc"`
  3910. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3911. MedinsSetlId string `json:"medins_setl_id"`
  3912. RefdSetlFlag string `json:"refd_setl_flag"`
  3913. SetlTime string `json:"setl_time"`
  3914. MedType string `json:"med_type"`
  3915. } `json:"setlinfo"`
  3916. } `json:"output"`
  3917. RefmsgTime string `json:"refmsg_time"`
  3918. RespondTime string `json:"respond_time"`
  3919. Signtype interface{} `json:"signtype"`
  3920. WarnMsg interface{} `json:"warn_msg"`
  3921. }
  3922. type Custom struct {
  3923. DetItemFeeSumamt string
  3924. Cut string
  3925. FeedetlSn string
  3926. Price string
  3927. MedListCodg string
  3928. Type int64
  3929. AdviceId int64
  3930. ProjectId int64
  3931. ItemId int64
  3932. }
  3933. //获取个人信息----挂号-----上传就诊信息
  3934. func (c *HisApiController) GetRegisterInfo() {
  3935. id, _ := c.GetInt64("id")
  3936. record_time := c.GetString("record_time")
  3937. settlementValue, _ := c.GetInt64("settlement_value")
  3938. medical_insurance_card := c.GetString("medical_insurance_card")
  3939. name := c.GetString("name")
  3940. id_card_type, _ := c.GetInt64("id_card_type")
  3941. certificates, _ := c.GetInt64("certificates")
  3942. medical_care, _ := c.GetInt64("medical_care")
  3943. birthday := c.GetString("birthday")
  3944. age, _ := c.GetInt64("age")
  3945. id_card := c.GetString("id_card")
  3946. register_type, _ := c.GetInt64("register")
  3947. doctor, _ := c.GetInt64("doctor")
  3948. department, _ := c.GetInt64("department")
  3949. gender, _ := c.GetInt64("sex")
  3950. phone := c.GetString("phone")
  3951. registration_fee, _ := c.GetFloat("registration_fee")
  3952. medical_expenses, _ := c.GetFloat("medical_expenses")
  3953. social_type, _ := c.GetInt64("social_type")
  3954. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3955. diagnosis_ids := c.GetString("diagnosis")
  3956. sick_type, _ := c.GetInt64("sick_type")
  3957. reg_type := c.GetString("p_type")
  3958. timeLayout := "2006-01-02"
  3959. loc, _ := time.LoadLocation("Local")
  3960. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3961. birthUnix := birthdays.Unix()
  3962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3963. if err != nil {
  3964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3965. return
  3966. }
  3967. recordDateTime := theTime.Unix()
  3968. adminInfo := c.GetAdminUserInfo()
  3969. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3970. if tempPatient.ID == 0 {
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3972. return
  3973. }
  3974. var patient service.Patients
  3975. if id == 0 {
  3976. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3977. } else {
  3978. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3979. }
  3980. if patient.ID == 0 {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3982. return
  3983. }
  3984. if len(patient.IdCardNo) == 0 {
  3985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3986. return
  3987. }
  3988. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3989. if len(his) >= 1 {
  3990. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3991. if len(his) >= 1 && order.ID == 0 {
  3992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3993. return
  3994. }
  3995. }
  3996. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3997. fmt.Println(timeStr)
  3998. timeArr := strings.Split(timeStr, " ")
  3999. fmt.Println(timeArr)
  4000. timeArrTwo := strings.Split(timeArr[0], "-")
  4001. timeArrThree := strings.Split(timeArr[1], ":")
  4002. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4003. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4004. if len(lists) == 0 {
  4005. var hisPatient models.XtHisPatient
  4006. hisPatient = models.XtHisPatient{
  4007. Name: name,
  4008. Age: age,
  4009. Gender: gender,
  4010. Birthday: birthUnix,
  4011. Phone: phone,
  4012. MedicalTreatmentType: medical_care,
  4013. IdType: certificates,
  4014. IdCardNo: id_card,
  4015. BalanceAccountsType: settlementValue,
  4016. SocialType: social_type,
  4017. MedicalInsuranceNumber: medical_insurance_card,
  4018. RegisterType: register_type,
  4019. RegisterCost: registration_fee,
  4020. TreatmentCost: medical_expenses,
  4021. AdminUserId: adminInfo.AdminUser.Id,
  4022. UserOrgId: adminInfo.CurrentOrgId,
  4023. Status: 1,
  4024. RecordDate: recordDateTime,
  4025. IsReturn: 1,
  4026. PatientId: patient.ID,
  4027. Ctime: time.Now().Unix(),
  4028. Mtime: time.Now().Unix(),
  4029. Number: str,
  4030. IdCardType: id_card_type,
  4031. Departments: department,
  4032. Doctor: doctor,
  4033. PType: reg_type,
  4034. Diagnosis: diagnosis_ids,
  4035. SickType: sick_type,
  4036. }
  4037. service.CreateHisPatient(&hisPatient)
  4038. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4039. c.ServeSuccessJSON(map[string]interface{}{
  4040. "his_info": hisPatient,
  4041. })
  4042. } else {
  4043. //chrgBchno := rand.Intn(1000000) + 10000
  4044. var hisPatient models.XtHisPatient
  4045. hisPatient = models.XtHisPatient{
  4046. Name: name,
  4047. Age: age,
  4048. Gender: gender,
  4049. Birthday: birthUnix,
  4050. Phone: phone,
  4051. MedicalTreatmentType: medical_care,
  4052. IdType: certificates,
  4053. IdCardNo: id_card,
  4054. BalanceAccountsType: settlementValue,
  4055. SocialType: social_type,
  4056. MedicalInsuranceNumber: medical_insurance_card,
  4057. RegisterType: register_type,
  4058. RegisterCost: registration_fee,
  4059. TreatmentCost: medical_expenses,
  4060. AdminUserId: adminInfo.AdminUser.Id,
  4061. UserOrgId: adminInfo.CurrentOrgId,
  4062. Status: 1,
  4063. RecordDate: recordDateTime,
  4064. IsReturn: 1,
  4065. PatientId: patient.ID,
  4066. Ctime: time.Now().Unix(),
  4067. Mtime: time.Now().Unix(),
  4068. Number: str,
  4069. IdCardType: id_card_type,
  4070. Departments: department,
  4071. Doctor: doctor,
  4072. PType: reg_type,
  4073. Diagnosis: diagnosis_ids,
  4074. SickType: sick_type,
  4075. }
  4076. service.CreateHisPatient(&hisPatient)
  4077. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4078. c.ServeSuccessJSON(map[string]interface{}{
  4079. "his_info": hisPatient,
  4080. })
  4081. }
  4082. }
  4083. //上传明细----结算
  4084. func (c *HisApiController) GetUploadInfo() {
  4085. id, _ := c.GetInt64("id")
  4086. record_time := c.GetString("record_time")
  4087. his_patient_id, _ := c.GetInt64("his_patient_id")
  4088. pay_way, _ := c.GetInt64("pay_way")
  4089. pay_price, _ := c.GetFloat("pay_price")
  4090. pay_card_no := c.GetString("pay_card_no")
  4091. discount_price, _ := c.GetFloat("discount_price")
  4092. preferential_price, _ := c.GetFloat("preferential_price")
  4093. reality_price, _ := c.GetFloat("reality_price")
  4094. found_price, _ := c.GetFloat("found_price")
  4095. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4096. private_price, _ := c.GetFloat("private_price")
  4097. timeLayout := "2006-01-02"
  4098. loc, _ := time.LoadLocation("Local")
  4099. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4100. fapiao_code := c.GetString("fapiao_code")
  4101. fapiao_number := c.GetString("fapiao_number")
  4102. diagnosis_id := c.GetString("diagnosis")
  4103. sick_type, _ := c.GetInt64("sick_type")
  4104. reg_type, _ := c.GetInt64("p_type")
  4105. order_id, _ := c.GetInt64("order_id")
  4106. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  4107. tmp_decimal := c.GetString("tmp_decimal")
  4108. var decimal float64 //本次使用的押金
  4109. var errmsg error
  4110. tx := service.XTWriteDB().Begin() //开了事务
  4111. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  4112. defer func() {
  4113. if errmsg != nil {
  4114. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  4115. tx.Rollback()
  4116. } else {
  4117. tx.Commit()
  4118. }
  4119. }()
  4120. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  4121. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  4122. return
  4123. }
  4124. if len(tmp_decimal) > 0 {
  4125. if tmp_decimal[0] == 45 {
  4126. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  4127. return
  4128. }
  4129. }
  4130. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  4131. fmt.Println(errs)
  4132. //if errs != nil {
  4133. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  4134. // return
  4135. //}
  4136. decimal = tt
  4137. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  4138. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  4139. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4140. if err != nil {
  4141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4142. return
  4143. }
  4144. recordDateTime := theTime.Unix()
  4145. adminUser := c.GetAdminUserInfo()
  4146. var prescriptions []*models.HisPrescription
  4147. var start_time int64
  4148. var end_time int64
  4149. ids_str := c.GetString("ids")
  4150. ids_arr := strings.Split(ids_str, ",")
  4151. if tempOrder.ID == 0 {
  4152. if settle_accounts_type == 1 { //日结
  4153. fmt.Println(reg_type)
  4154. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4155. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  4156. } else {
  4157. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  4158. }
  4159. } else { //月结
  4160. start_time_str := c.GetString("start_time")
  4161. end_time_str := c.GetString("end_time")
  4162. timeLayout := "2006-01-02"
  4163. loc, _ := time.LoadLocation("Local")
  4164. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4165. if err != nil {
  4166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4167. return
  4168. }
  4169. recordStartTime := theStartTime.Unix()
  4170. start_time = recordStartTime
  4171. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4172. if err != nil {
  4173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4174. return
  4175. }
  4176. recordEndTime := theEndTime.Unix()
  4177. end_time = recordEndTime
  4178. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  4179. }
  4180. timestamp := time.Now().Unix()
  4181. tempTime := time.Unix(timestamp, 0)
  4182. timeFormat := tempTime.Format("20060102150405")
  4183. chrgBchno := rand.Intn(100000) + 10000
  4184. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4185. strconv.FormatInt(his.PatientId, 10)
  4186. var ids []int64
  4187. for _, item := range prescriptions {
  4188. ids = append(ids, item.ID)
  4189. }
  4190. var total float64
  4191. for _, item := range prescriptions {
  4192. fmt.Println(item)
  4193. if item.Type == 1 { //药品
  4194. for _, subItem := range item.HisDoctorAdviceInfo {
  4195. total = total + (subItem.Price * subItem.PrescribingNumber)
  4196. }
  4197. }
  4198. if item.Type == 2 { //项目
  4199. for _, subItem := range item.HisPrescriptionProject {
  4200. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4201. total = total + (subItem.Price * cnt)
  4202. }
  4203. }
  4204. for _, subItem := range item.HisAdditionalCharge {
  4205. total = total + (subItem.Price * float64(subItem.Count))
  4206. }
  4207. }
  4208. if reg_type == 1111 || reg_type == 1112 {
  4209. reg_type = 11
  4210. }
  4211. tm := time.Unix(time.Now().Unix(), 0)
  4212. allTotal := fmt.Sprintf("%.4f", total)
  4213. totals, _ := strconv.ParseFloat(allTotal, 64)
  4214. order := &models.HisOrder{ //
  4215. UserOrgId: adminUser.CurrentOrgId,
  4216. HisPatientId: his.ID,
  4217. PatientId: id,
  4218. SettleAccountsDate: recordDateTime,
  4219. Ctime: time.Now().Unix(),
  4220. Mtime: time.Now().Unix(),
  4221. Status: 1,
  4222. OrderStatus: 2,
  4223. MdtrtId: his.Number,
  4224. Number: chrg_bchno,
  4225. MedfeeSumamt: totals,
  4226. PayWay: pay_way,
  4227. PayPrice: pay_price,
  4228. MedType: strconv.Itoa(int(reg_type)),
  4229. PayCardNo: pay_card_no,
  4230. DiscountPrice: discount_price,
  4231. PreferentialPrice: preferential_price,
  4232. RealityPrice: reality_price,
  4233. FoundPrice: found_price,
  4234. MedicalInsurancePrice: medical_insurance_price,
  4235. PrivatePrice: private_price,
  4236. SettleEndTime: end_time,
  4237. SettleStartTime: start_time,
  4238. SettleType: settle_accounts_type,
  4239. FaPiaoCode: fapiao_code,
  4240. FaPiaoNumber: fapiao_number,
  4241. Diagnosis: diagnosis_id,
  4242. PType: 2,
  4243. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4244. Decimal: decimal,
  4245. }
  4246. err = service.CreateOrderTX(order, tx)
  4247. if err != nil {
  4248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4249. return
  4250. }
  4251. var customs []*Custom
  4252. for _, item := range prescriptions {
  4253. if item.Type == 1 { //药品
  4254. for _, subItem := range item.HisDoctorAdviceInfo {
  4255. cus := &Custom{
  4256. AdviceId: subItem.ID,
  4257. ProjectId: 0,
  4258. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4259. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4260. FeedetlSn: subItem.FeedetlSn,
  4261. Price: fmt.Sprintf("%.2f", subItem.Price),
  4262. MedListCodg: subItem.MedListCodg,
  4263. Type: 1,
  4264. }
  4265. customs = append(customs, cus)
  4266. }
  4267. }
  4268. if item.Type == 2 { //项目
  4269. for _, subItem := range item.HisPrescriptionProject {
  4270. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4271. cus := &Custom{
  4272. AdviceId: 0,
  4273. ProjectId: subItem.ID,
  4274. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4275. Cut: fmt.Sprintf("%.4f", cnt),
  4276. FeedetlSn: subItem.FeedetlSn,
  4277. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4278. MedListCodg: subItem.MedListCodg,
  4279. Type: 2,
  4280. }
  4281. customs = append(customs, cus)
  4282. }
  4283. }
  4284. for _, item := range item.HisAdditionalCharge {
  4285. cus := &Custom{
  4286. ItemId: item.ID,
  4287. AdviceId: 0,
  4288. ProjectId: 0,
  4289. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4290. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4291. FeedetlSn: item.FeedetlSn,
  4292. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4293. MedListCodg: item.XtHisAddtionConfig.Code,
  4294. Type: 3,
  4295. }
  4296. customs = append(customs, cus)
  4297. }
  4298. }
  4299. for _, item := range customs {
  4300. var advice_id int64 = 0
  4301. var project_id int64 = 0
  4302. var item_id int64 = 0
  4303. var types int64 = 0
  4304. if item.Type == 1 {
  4305. advice_id = item.AdviceId
  4306. project_id = 0
  4307. item_id = 0
  4308. } else if item.Type == 2 {
  4309. advice_id = 0
  4310. item_id = 0
  4311. project_id = item.ProjectId
  4312. } else if item.Type == 3 {
  4313. advice_id = 0
  4314. item_id = item.ItemId
  4315. project_id = 0
  4316. }
  4317. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4318. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4319. pric, _ := strconv.ParseFloat(item.Price, 32)
  4320. info := &models.HisOrderInfo{
  4321. OrderNumber: order.Number,
  4322. UploadDate: time.Now().Unix(),
  4323. AdviceId: advice_id,
  4324. DetItemFeeSumamt: detItemFeeSumamt,
  4325. Cnt: cut,
  4326. Pric: pric,
  4327. PatientId: id,
  4328. Status: 1,
  4329. Mtime: time.Now().Unix(),
  4330. Ctime: time.Now().Unix(),
  4331. UserOrgId: adminUser.CurrentOrgId,
  4332. HisPatientId: his.ID,
  4333. OrderId: order.ID,
  4334. ProjectId: project_id,
  4335. Type: types,
  4336. ItemId: item_id,
  4337. }
  4338. service.CreateOrderInfoTX(info, tx)
  4339. }
  4340. his.Diagnosis = diagnosis_id
  4341. his.SickType = sick_type
  4342. his.RegisterType = reg_type
  4343. his.MedicalTreatmentType = reg_type
  4344. service.UpdataHisPateintTX(&his, tx)
  4345. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  4346. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  4347. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  4348. //判断是否使用了押金
  4349. if dec_way == "true" {
  4350. tmpstring := strconv.FormatInt(order.ID, 10)
  4351. //扣押金
  4352. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  4353. if errmsg != nil {
  4354. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  4355. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4356. return
  4357. }
  4358. }
  4359. if err == nil {
  4360. c.ServeSuccessJSON(map[string]interface{}{
  4361. "msg": "结算成功",
  4362. })
  4363. }
  4364. } else {
  4365. if tempOrder.IsPre > 0 {
  4366. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4367. totals, _ := strconv.ParseFloat(allTotal, 64)
  4368. tempOrder.OrderStatus = 2
  4369. tempOrder.PayWay = pay_way
  4370. tempOrder.PayPrice = pay_price
  4371. tempOrder.PayCardNo = pay_card_no
  4372. tempOrder.DiscountPrice = discount_price
  4373. tempOrder.PreferentialPrice = preferential_price
  4374. tempOrder.RealityPrice = reality_price
  4375. tempOrder.FoundPrice = found_price
  4376. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4377. tempOrder.PrivatePrice = private_price
  4378. tempOrder.FaPiaoCode = fapiao_code
  4379. tempOrder.FaPiaoNumber = fapiao_number
  4380. tempOrder.PType = 2
  4381. tempOrder.MedfeeSumamt = totals
  4382. tempOrder.Diagnosis = diagnosis_id
  4383. err = service.SaveHisOrder(&tempOrder)
  4384. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4385. if err != nil {
  4386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4387. return
  4388. }
  4389. if err == nil {
  4390. c.ServeSuccessJSON(map[string]interface{}{
  4391. "msg": "结算成功",
  4392. })
  4393. }
  4394. }
  4395. }
  4396. }
  4397. //退款
  4398. func (c *HisApiController) Refund() {
  4399. order_id, _ := c.GetInt64("order_id")
  4400. order, _ := service.GetHisOrderByID(order_id)
  4401. adminUser := c.GetAdminUserInfo()
  4402. orgid := c.GetAdminUserInfo().CurrentOrgId
  4403. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4404. if err != nil {
  4405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4406. return
  4407. }
  4408. tmp := strconv.FormatInt(order.ID, 10)
  4409. //当押金不为零时产生退费记录
  4410. if order.Decimal != 0 {
  4411. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  4412. if err != nil {
  4413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4414. return
  4415. }
  4416. }
  4417. c.ServeSuccessJSON(map[string]interface{}{
  4418. "msg": "退费成功",
  4419. })
  4420. }
  4421. func (c *HisApiController) RefundNumber() {
  4422. his_patient_id, _ := c.GetInt64("id")
  4423. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4424. info.Status = 0
  4425. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4426. if count > 0 {
  4427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4428. return
  4429. }
  4430. err := service.SaveHisPatient(info)
  4431. if err == nil {
  4432. c.ServeSuccessJSON(map[string]interface{}{
  4433. "msg": "退号成功",
  4434. })
  4435. } else {
  4436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4437. return
  4438. }
  4439. }
  4440. func (this *HisApiController) AdditionalCharge() {
  4441. dataBody := make(map[string]interface{}, 0)
  4442. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4443. fmt.Println(err)
  4444. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4445. patient_id := int64(dataBody["patient_id"].(float64))
  4446. medicineData, _ := dataBody["medicineData"].([]interface{})
  4447. adminUserInfo := this.GetAdminUserInfo()
  4448. orgId := adminUserInfo.CurrentOrgId
  4449. admin_user_id := adminUserInfo.AdminUser.Id
  4450. timeStr := time.Now().Format("2006-01-02")
  4451. timeLayout := "2006-01-02 15:04:05"
  4452. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4453. timenow := timeStringToTime.Unix()
  4454. var additionalCharges []*models.HisAdditionalCharge
  4455. for _, item := range medicineData {
  4456. var randNum int
  4457. randNum = rand.Intn(10000) + 1000
  4458. timestamp := time.Now().Unix()
  4459. tempTime := time.Unix(timestamp, 0)
  4460. timeFormat := tempTime.Format("20060102150405")
  4461. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4462. items := item.(map[string]interface{})
  4463. money := items["price"].(string)
  4464. item_id_str := items["item_id"].(string)
  4465. name := items["name"].(string)
  4466. id_str := items["id"].(string)
  4467. moneys, _ := strconv.ParseInt(money, 10, 64)
  4468. monStr := strconv.FormatInt(moneys, 10)
  4469. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4470. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4471. id, _ := strconv.ParseInt(id_str, 10, 64)
  4472. additionalCharge := &models.HisAdditionalCharge{
  4473. ID: id,
  4474. HisPatientId: his_patient_id,
  4475. UserOrgId: orgId,
  4476. PatientId: patient_id,
  4477. RecordDate: timenow,
  4478. Price: monneyStr,
  4479. Status: 1,
  4480. ItemName: name,
  4481. ItemId: item_id,
  4482. AdminUserId: admin_user_id,
  4483. CreatedTime: time.Now().Unix(),
  4484. OrderStatus: 0,
  4485. PrescriptionNumber: "",
  4486. BatchNumber: "",
  4487. FeedetlSn: p_number,
  4488. }
  4489. service.CreateAdditionalCharge(additionalCharge)
  4490. additionalCharges = append(additionalCharges, additionalCharge)
  4491. }
  4492. this.ServeSuccessJSON(map[string]interface{}{
  4493. "msg": "添加成功",
  4494. "additional_charges": additionalCharges,
  4495. })
  4496. }
  4497. func (this *HisApiController) DeleteAddition() {
  4498. id, _ := this.GetInt64("id")
  4499. //TODO 需要判断是否已经结算
  4500. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4501. if err == nil {
  4502. this.ServeSuccessJSON(map[string]interface{}{
  4503. "msg": "删除成功",
  4504. })
  4505. return
  4506. } else {
  4507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4508. return
  4509. }
  4510. }
  4511. func (this *HisApiController) GetAdminUsers() {
  4512. adminUser := this.GetAdminUserInfo()
  4513. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4514. this.ServeSuccessJSON(map[string]interface{}{
  4515. "doctors": doctors,
  4516. })
  4517. }
  4518. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4519. change_type, _ := this.GetInt64("type", 0)
  4520. record_date := this.GetString("record_time")
  4521. patient_id, _ := this.GetInt64("patient_id", 0)
  4522. p_type, _ := this.GetInt64("p_type", 0)
  4523. timeLayout := "2006-01-02"
  4524. loc, _ := time.LoadLocation("Local")
  4525. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4526. record_time := theAdviceRecordTime.Unix()
  4527. adminUserInfo := this.GetAdminUserInfo()
  4528. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4529. if err == nil {
  4530. if len(prescriptions) == 0 {
  4531. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4532. return
  4533. } else {
  4534. this.ServeSuccessJSON(map[string]interface{}{
  4535. "prescriptions": prescriptions,
  4536. })
  4537. return
  4538. }
  4539. } else {
  4540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4541. return
  4542. }
  4543. }
  4544. func (this *HisApiController) GetCallHisPrescription() {
  4545. patient_id, _ := this.GetInt64("patient_id", 0)
  4546. timeLayout := "2006-01-02"
  4547. loc, _ := time.LoadLocation("Local")
  4548. start_time := this.GetString("start_time")
  4549. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4550. end_time := this.GetString("end_time")
  4551. p_type, _ := this.GetInt64("p_type")
  4552. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4553. adminUserInfo := this.GetAdminUserInfo()
  4554. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4555. if err == nil {
  4556. this.ServeSuccessJSON(map[string]interface{}{
  4557. "prescriptions": prescriptions,
  4558. })
  4559. return
  4560. } else {
  4561. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4562. return
  4563. }
  4564. }
  4565. func (this *HisApiController) GetHisDayPrescription() {
  4566. timeLayout := "2006-01-02"
  4567. loc, _ := time.LoadLocation("Local")
  4568. start_time := this.GetString("start_time")
  4569. patient_id, _ := this.GetInt64("patient_id", 0)
  4570. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4571. end_time := this.GetString("end_time")
  4572. p_type, _ := this.GetInt64("p_type")
  4573. order_status, _ := this.GetInt64("type")
  4574. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4575. adminUserInfo := this.GetAdminUserInfo()
  4576. var dayHisPrescription []*models.HisPrescription
  4577. var err error
  4578. if order_status == 1 || order_status == 0 {
  4579. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4580. } else if order_status == 2 {
  4581. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4582. }
  4583. var settle_total float64
  4584. for _, item := range dayHisPrescription {
  4585. if len(item.HisPrescriptionProject) > 0 {
  4586. for _, subItem := range item.HisPrescriptionProject {
  4587. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4588. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4589. settle_total = settle_total + total
  4590. }
  4591. }
  4592. if len(item.HisDoctorAdviceInfo) > 0 {
  4593. for _, subItem := range item.HisDoctorAdviceInfo {
  4594. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4595. settle_total = settle_total + total
  4596. }
  4597. }
  4598. }
  4599. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4600. if err == nil {
  4601. this.ServeSuccessJSON(map[string]interface{}{
  4602. "day_prescription": dayHisPrescription,
  4603. "settle_total": settle_total,
  4604. })
  4605. return
  4606. } else {
  4607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4608. return
  4609. }
  4610. }
  4611. func (c *HisApiController) GetHisChargePatientList() {
  4612. record_date := c.GetString("record_date")
  4613. order_status, _ := c.GetInt64("type")
  4614. timeLayout := "2006-01-02"
  4615. loc, _ := time.LoadLocation("Local")
  4616. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4617. if err != nil {
  4618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4619. return
  4620. }
  4621. recordDateTime := theTime.Unix()
  4622. adminInfo := c.GetAdminUserInfo()
  4623. var tempPatients []*service.NewTempPatients
  4624. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4625. if order_status != 2 {
  4626. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4627. } else {
  4628. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4629. }
  4630. var patients []*service.NewTempPatients
  4631. var patients_two []*service.NewTempPatients
  4632. for _, item := range tempPatients {
  4633. //过滤掉没挂号的和没开处方的
  4634. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4635. patients = append(patients, item)
  4636. }
  4637. //过滤掉没挂号的
  4638. if len(item.HisPatient) > 0 {
  4639. patients_two = append(patients_two, item)
  4640. }
  4641. }
  4642. c.ServeSuccessJSON(map[string]interface{}{
  4643. "list": patients,
  4644. "list_two": patients_two,
  4645. })
  4646. }
  4647. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4648. record_date := c.GetString("record_date")
  4649. timeLayout := "2006-01-02"
  4650. loc, _ := time.LoadLocation("Local")
  4651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4652. if err != nil {
  4653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4654. return
  4655. }
  4656. recordDateTime := theTime.Unix()
  4657. adminUser := c.GetAdminUserInfo()
  4658. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4659. var patients []*service.Patients
  4660. for _, item := range tempPatients {
  4661. if item.HisPatient.ID == 0 {
  4662. patients = append(patients, item)
  4663. }
  4664. }
  4665. c.ServeSuccessJSON(map[string]interface{}{
  4666. "list": patients,
  4667. //"list_two": patients_two,
  4668. })
  4669. }
  4670. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4671. newArr = make([]*service.Patients, 0)
  4672. for i := 0; i < len(patient); i++ {
  4673. repeat := false
  4674. for j := i + 1; j < len(patient); j++ {
  4675. if patient[i].ID == patient[j].ID {
  4676. repeat = true
  4677. break
  4678. }
  4679. }
  4680. if !repeat {
  4681. newArr = append(newArr, patient[i])
  4682. }
  4683. }
  4684. return
  4685. }
  4686. func (c *HisApiController) GetHisChargePatientInfo() {
  4687. patient_id, _ := c.GetInt64("patient_id")
  4688. his_patient_id, _ := c.GetInt64("his_patient_id")
  4689. record_date := c.GetString("record_date")
  4690. //start_time := c.GetString("start_time")
  4691. //end_time := c.GetString("end_time")
  4692. order_status, _ := c.GetInt64("type", 0)
  4693. p_type, _ := c.GetInt64("p_type", 0)
  4694. order_id, _ := c.GetInt64("order_id", 0)
  4695. timeLayout := "2006-01-02"
  4696. loc, _ := time.LoadLocation("Local")
  4697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4698. if err != nil {
  4699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4700. return
  4701. }
  4702. recordDateTime := theTime.Unix()
  4703. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4704. //if err != nil {
  4705. //
  4706. //}
  4707. //startRecordDateTime := startTime.Unix()
  4708. //
  4709. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4710. //if err != nil {
  4711. //
  4712. //}
  4713. //endRecordDateTime := endTime.Unix()
  4714. admin := c.GetAdminUserInfo()
  4715. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4716. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4717. var prescriptions []*models.HisPrescription
  4718. //var unChargeMonthPrescriptions []*models.HisPrescription
  4719. order, _ := service.GetHisOrderByID(order_id)
  4720. if order_status == 1 || order_status == 0 {
  4721. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4722. } else if order_status == 2 {
  4723. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4724. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4725. }
  4726. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4727. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4728. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4729. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4730. //获取所有科室信息
  4731. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4732. c.ServeSuccessJSON(map[string]interface{}{
  4733. "his_info": his_patient_info,
  4734. "xt_info": xt_patient_info,
  4735. "prescription": prescriptions,
  4736. "case_history": case_history,
  4737. "info": patientPrescriptionInfo,
  4738. "last_info": lastPatientPrescriptionInfo,
  4739. "order": order,
  4740. "doctors": doctors,
  4741. "department": department,
  4742. })
  4743. return
  4744. }
  4745. func (c *HisApiController) GetAllOrderDetail() {
  4746. order_id, _ := c.GetInt64("id", 0)
  4747. order, _ := service.GetHisOrderByID(order_id)
  4748. if order.ID == 0 {
  4749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4750. return
  4751. }
  4752. org_id := c.GetAdminUserInfo().CurrentOrgId
  4753. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4754. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4755. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4756. c.ServeSuccessJSON(map[string]interface{}{
  4757. "order": order,
  4758. "order_info": order_info,
  4759. "patient": patient,
  4760. "admin_info": adminInfo,
  4761. })
  4762. return
  4763. }
  4764. func (c *HisApiController) GetAllOrderDetailCollect() {
  4765. order_id, _ := c.GetInt64("id", 0)
  4766. order, _ := service.GetHisOrderByID(order_id)
  4767. if order.ID == 0 {
  4768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4769. return
  4770. }
  4771. org_id := c.GetAdminUserInfo().CurrentOrgId
  4772. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4773. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4774. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4775. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4776. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4777. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4778. var bedCostTotal float64 = 0 //床位总费
  4779. //var bedCostSelfTotal float64 = 0 //床位自费
  4780. var operationCostTotal float64 = 0 //手术费
  4781. //var operationCostSelfTotal float64 = 0 //手术费
  4782. var otherCostTotal float64 = 0 //其他费用
  4783. //var otherCostSelfTotal float64 = 0 //其他费用
  4784. var materialCostTotal float64 = 0 //材料费
  4785. //var materialCostSelfTotal float64 = 0 //材料费
  4786. var westernMedicineCostTotal float64 = 0 //西药费
  4787. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4788. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4789. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4790. var checkCostTotal float64 = 0 //检查费
  4791. //var checkCostSelfTotal float64 = 0 //检查费
  4792. var laboratoryCostTotal float64 = 0 //化验费
  4793. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4794. var treatCostTotal float64 = 0 //治疗费用
  4795. //var treatCostSelfTotal float64 = 0 //治疗费用
  4796. var zhenChaCostTotal float64 = 0 //其他费用
  4797. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4798. decimal.DivisionPrecision = 2
  4799. var BalanceAccountsType int64
  4800. if his.ID > 0 {
  4801. BalanceAccountsType = his.BalanceAccountsType
  4802. } else {
  4803. BalanceAccountsType = record.BalanceAccountsType
  4804. }
  4805. if BalanceAccountsType != 2 {
  4806. for _, item := range order_info {
  4807. if org_id == 10215 {
  4808. if item.MedChrgitmType == "01" { //床位费
  4809. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4810. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4811. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4812. }
  4813. if item.MedChrgitmType == "02" { //诊察费
  4814. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4815. //zhenChaCostSelfTotal = zhenChaCostTotal
  4816. }
  4817. if item.MedChrgitmType == "03" { //检查费
  4818. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4819. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4820. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4821. }
  4822. //if item.MedChrgitmType == "02" { //检查费
  4823. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4824. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4825. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4826. //}
  4827. if item.MedChrgitmType == "04" { //化验费
  4828. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4829. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4830. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4831. }
  4832. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4833. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4834. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4835. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4836. }
  4837. if item.MedChrgitmType == "06" { //手术费
  4838. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4839. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4840. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4841. }
  4842. if item.MedChrgitmType == "08" { //材料费
  4843. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4844. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4845. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4846. }
  4847. if item.MedChrgitmType == "09" { //西药费
  4848. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4849. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4850. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4851. }
  4852. if item.MedChrgitmType == "11" { //中成费
  4853. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4854. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4855. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4856. }
  4857. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4858. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4859. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4860. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4861. }
  4862. } else if org_id == 10188 || org_id == 10217 {
  4863. if item.MedChrgitmType == "01" { //床位费
  4864. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4865. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4866. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4867. }
  4868. if item.MedChrgitmType == "02" { //诊察费
  4869. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4870. //zhenChaCostSelfTotal = zhenChaCostTotal
  4871. }
  4872. if item.MedChrgitmType == "03" { //检查费
  4873. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4874. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4875. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4876. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4877. }
  4878. //if item.MedChrgitmType == "02" { //检查费
  4879. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4880. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4881. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4882. //}
  4883. if item.MedChrgitmType == "04" { //化验费
  4884. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4885. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4886. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4887. }
  4888. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4889. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4890. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4891. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4892. }
  4893. if item.MedChrgitmType == "06" { //手术费
  4894. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4895. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4896. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4897. }
  4898. if item.MedChrgitmType == "08" { //材料费
  4899. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4900. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4901. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4902. }
  4903. if item.MedChrgitmType == "09" { //西药费
  4904. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4905. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4906. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4907. }
  4908. if item.MedChrgitmType == "11" { //中成费
  4909. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4910. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4911. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4912. }
  4913. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4914. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4915. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4916. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4917. }
  4918. } else {
  4919. if item.MedChrgitmType == "01" { //床位费
  4920. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4921. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4922. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4923. }
  4924. //if item.MedChrgitmType == "02" { //诊察费
  4925. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4926. // //zhenChaCostSelfTotal = zhenChaCostTotal
  4927. //}
  4928. if item.MedChrgitmType == "03" { //检查费
  4929. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4930. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4931. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4932. }
  4933. //if item.MedChrgitmType == "02" { //检查费
  4934. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4935. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4936. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4937. //}
  4938. if item.MedChrgitmType == "04" { //化验费
  4939. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4940. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4941. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4942. }
  4943. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4944. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4945. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4946. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4947. }
  4948. if item.MedChrgitmType == "06" { //手术费
  4949. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4950. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4951. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4952. }
  4953. if item.MedChrgitmType == "08" { //材料费
  4954. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4955. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4956. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4957. }
  4958. if item.MedChrgitmType == "09" { //西药费
  4959. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4960. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4961. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4962. }
  4963. if item.MedChrgitmType == "11" { //中成费
  4964. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4965. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4966. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4967. }
  4968. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4969. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4970. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4971. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4972. }
  4973. }
  4974. }
  4975. c.ServeSuccessJSON(map[string]interface{}{
  4976. "order": order,
  4977. "order_info": order_info,
  4978. "patient": patient,
  4979. "admin_info": adminInfo,
  4980. "his_hospital": record,
  4981. "bedCostTotal": bedCostTotal,
  4982. "operationCostTotal": operationCostTotal,
  4983. "otherCostTotal": otherCostTotal,
  4984. "materialCostTotal": materialCostTotal,
  4985. "westernMedicineCostTotal": westernMedicineCostTotal,
  4986. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4987. "checkCostTotal": checkCostTotal,
  4988. "zhenChaCostTotal": zhenChaCostTotal,
  4989. "laboratoryCostTotal": laboratoryCostTotal,
  4990. "treatCostTotal": treatCostTotal,
  4991. })
  4992. } else {
  4993. for _, item := range order_info {
  4994. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4995. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4996. item.MedChrgitmType = "09"
  4997. }
  4998. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4999. if item.HisPrescriptionProject.Type == 2 {
  5000. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5001. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5002. case 0:
  5003. item.MedChrgitmType = "0"
  5004. break
  5005. case 1:
  5006. item.MedChrgitmType = "14"
  5007. break
  5008. case 2:
  5009. item.MedChrgitmType = "05"
  5010. break
  5011. case 3:
  5012. item.MedChrgitmType = "03"
  5013. break
  5014. case 4:
  5015. item.MedChrgitmType = "03"
  5016. break
  5017. case 5:
  5018. item.MedChrgitmType = "08"
  5019. break
  5020. case 6:
  5021. item.MedChrgitmType = "14"
  5022. break
  5023. case 7:
  5024. item.MedChrgitmType = "14"
  5025. break
  5026. case 8:
  5027. item.MedChrgitmType = "03"
  5028. break
  5029. case 9:
  5030. item.MedChrgitmType = "14"
  5031. break
  5032. case 10:
  5033. item.MedChrgitmType = "14"
  5034. break
  5035. case 11:
  5036. item.MedChrgitmType = "06"
  5037. break
  5038. case 12:
  5039. item.MedChrgitmType = "12"
  5040. break
  5041. case 13:
  5042. item.MedChrgitmType = "01"
  5043. break
  5044. case 14:
  5045. item.MedChrgitmType = "04"
  5046. break
  5047. case 15:
  5048. item.MedChrgitmType = "14"
  5049. break
  5050. }
  5051. } else {
  5052. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5053. case 1:
  5054. item.MedChrgitmType = "14"
  5055. break
  5056. case 2:
  5057. item.MedChrgitmType = "05"
  5058. break
  5059. case 3:
  5060. item.MedChrgitmType = "04"
  5061. break
  5062. case 4:
  5063. item.MedChrgitmType = "14"
  5064. break
  5065. case 5:
  5066. item.MedChrgitmType = "08"
  5067. break
  5068. case 6:
  5069. item.MedChrgitmType = "14"
  5070. break
  5071. case 7:
  5072. item.MedChrgitmType = "14"
  5073. break
  5074. case 8:
  5075. item.MedChrgitmType = "03"
  5076. break
  5077. case 9:
  5078. item.MedChrgitmType = "14"
  5079. break
  5080. }
  5081. }
  5082. } else if item.HisPrescriptionProject.Type == 3 {
  5083. item.MedChrgitmType = "08"
  5084. }
  5085. }
  5086. }
  5087. for _, item := range order_info {
  5088. if org_id == 10215 {
  5089. if item.MedChrgitmType == "01" { //床位费
  5090. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5091. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5092. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5093. }
  5094. if item.MedChrgitmType == "02" { //诊察费
  5095. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5096. //zhenChaCostSelfTotal = zhenChaCostTotal
  5097. }
  5098. if item.MedChrgitmType == "03" { //检查费
  5099. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5100. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5101. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5102. }
  5103. //if item.MedChrgitmType == "02" { //检查费
  5104. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5105. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5106. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5107. //}
  5108. if item.MedChrgitmType == "04" { //化验费
  5109. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5110. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5111. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5112. }
  5113. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5114. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5115. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5116. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5117. }
  5118. if item.MedChrgitmType == "06" { //手术费
  5119. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5120. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5121. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5122. }
  5123. if item.MedChrgitmType == "08" { //材料费
  5124. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5125. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5126. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5127. }
  5128. if item.MedChrgitmType == "09" { //西药费
  5129. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5130. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5131. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5132. }
  5133. if item.MedChrgitmType == "11" { //中成费
  5134. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5135. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5136. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5137. }
  5138. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5139. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5140. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5141. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5142. }
  5143. } else {
  5144. if item.MedChrgitmType == "01" { //床位费
  5145. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5146. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5147. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5148. }
  5149. //if item.MedChrgitmType == "02" { //诊察费
  5150. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5151. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5152. //}
  5153. if item.MedChrgitmType == "03" { //检查费
  5154. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5155. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5156. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5157. }
  5158. //if item.MedChrgitmType == "02" { //检查费
  5159. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5160. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5161. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5162. //}
  5163. if item.MedChrgitmType == "04" { //化验费
  5164. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5165. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5166. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5167. }
  5168. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5169. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5170. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5171. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5172. }
  5173. if item.MedChrgitmType == "06" { //手术费
  5174. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5175. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5176. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5177. }
  5178. if item.MedChrgitmType == "08" { //材料费
  5179. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5180. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5181. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5182. }
  5183. if item.MedChrgitmType == "09" { //西药费
  5184. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5185. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5186. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5187. }
  5188. if item.MedChrgitmType == "11" { //中成费
  5189. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5190. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5191. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5192. }
  5193. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5194. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5195. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5196. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5197. }
  5198. }
  5199. }
  5200. c.ServeSuccessJSON(map[string]interface{}{
  5201. "order": order,
  5202. "order_info": order_info,
  5203. "patient": patient,
  5204. "admin_info": adminInfo,
  5205. "his_hospital": record,
  5206. "bedCostTotal": bedCostTotal,
  5207. "operationCostTotal": operationCostTotal,
  5208. "otherCostTotal": otherCostTotal,
  5209. "materialCostTotal": materialCostTotal,
  5210. "westernMedicineCostTotal": westernMedicineCostTotal,
  5211. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5212. "checkCostTotal": checkCostTotal,
  5213. "zhenChaCostTotal": zhenChaCostTotal,
  5214. "laboratoryCostTotal": laboratoryCostTotal,
  5215. "treatCostTotal": treatCostTotal,
  5216. })
  5217. }
  5218. }
  5219. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5220. page, _ := c.GetInt64("page")
  5221. limit, _ := c.GetInt64("limit")
  5222. keywords := c.GetString("keywords")
  5223. start_time := c.GetString("start_time")
  5224. end_time := c.GetString("end_time")
  5225. //clr_type := c.GetString("clr_type")
  5226. insutype := c.GetString("insutype")
  5227. timeLayout := "2006-01-02"
  5228. loc, _ := time.LoadLocation("Local")
  5229. var theStartTIme int64
  5230. if len(start_time) > 0 {
  5231. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5232. theStartTIme = theTime.Unix()
  5233. }
  5234. var theEndtTIme int64
  5235. if len(end_time) > 0 {
  5236. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5237. theEndtTIme = theTime.Unix()
  5238. }
  5239. if page <= 0 {
  5240. page = 1
  5241. }
  5242. if limit <= 0 {
  5243. limit = 10
  5244. }
  5245. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5246. c.ServeSuccessJSON(map[string]interface{}{
  5247. "total": total,
  5248. "list": list,
  5249. })
  5250. return
  5251. }
  5252. func (c *HisApiController) GetPutOnRecordList() {
  5253. page, _ := c.GetInt64("page")
  5254. limit, _ := c.GetInt64("limit")
  5255. keywords := c.GetString("keywords")
  5256. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5257. if page <= 0 {
  5258. page = 1
  5259. }
  5260. if limit <= 0 {
  5261. limit = 10
  5262. }
  5263. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5264. c.ServeSuccessJSON(map[string]interface{}{
  5265. "total": total,
  5266. "list": list,
  5267. })
  5268. return
  5269. }
  5270. func (c *HisApiController) GetCompareData() {
  5271. start_time := c.GetString("start_time")
  5272. end_time := c.GetString("end_time")
  5273. insutype := c.GetString("insutype")
  5274. clr_type := c.GetString("clr_type")
  5275. timeLayout := "2006-01-02"
  5276. loc, _ := time.LoadLocation("Local")
  5277. var theStartTIme int64
  5278. if len(start_time) > 0 {
  5279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5280. if err != nil {
  5281. theStartTIme = 0
  5282. }
  5283. theStartTIme = theTime.Unix()
  5284. }
  5285. var theEndtTIme int64
  5286. if len(end_time) > 0 {
  5287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5288. if err != nil {
  5289. theEndtTIme = 0
  5290. }
  5291. theEndtTIme = theTime.Unix()
  5292. }
  5293. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5294. fmt.Println(err)
  5295. if err == nil {
  5296. c.ServeSuccessJSON(map[string]interface{}{
  5297. "list": formData,
  5298. })
  5299. } else {
  5300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5301. return
  5302. }
  5303. }
  5304. func (c *HisApiController) GetFaPiaoData() {
  5305. order_id, _ := c.GetInt64("order_id")
  5306. patient_id, _ := c.GetInt64("patient_id")
  5307. number := c.GetString("number")
  5308. adminUser := c.GetAdminUserInfo()
  5309. order, _ := service.GetHisOrderByID(order_id)
  5310. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5311. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5312. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5313. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5314. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5315. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5316. var bedCostTotal float64 = 0 //床位总费
  5317. var bedCostSelfTotal float64 = 0 //床位自费
  5318. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5319. var operationCostTotal float64 = 0 //手术费
  5320. var operationCostSelfTotal float64 = 0 //手术费
  5321. var operationCostPartSelfTotal float64 = 0 //手术费
  5322. var otherCostTotal float64 = 0 //其他费用
  5323. var otherCostSelfTotal float64 = 0 //其他费用
  5324. var otherCostPartSelfTotal float64 = 0 //其他费用
  5325. var materialCostTotal float64 = 0 //材料费
  5326. var materialCostSelfTotal float64 = 0 //材料费
  5327. var materialCostPartSelfTotal float64 = 0 //材料费
  5328. var westernMedicineCostTotal float64 = 0 //西药费
  5329. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5330. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5331. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5332. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5333. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5334. var checkCostTotal float64 = 0 //检查费
  5335. var checkCostSelfTotal float64 = 0 //检查费
  5336. var checkCostPartSelfTotal float64 = 0 //检查费
  5337. var laboratoryCostTotal float64 = 0 //化验费
  5338. var laboratoryCostSelfTotal float64 = 0 //化验费
  5339. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5340. var treatCostTotal float64 = 0 //治疗费用
  5341. var treatCostSelfTotal float64 = 0 //治疗费用
  5342. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5343. var zhenChaCostTotal float64 = 0 //其他费用
  5344. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5345. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5346. decimal.DivisionPrecision = 2
  5347. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5348. var balanceAccountsType int64
  5349. if his.ID > 0 {
  5350. balanceAccountsType = his.BalanceAccountsType
  5351. } else {
  5352. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5353. }
  5354. if balanceAccountsType == 2 {
  5355. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5356. for _, item := range orderInfos_two {
  5357. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5358. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5359. item.MedChrgitmType = "09"
  5360. }
  5361. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5362. if item.HisPrescriptionProject.Type == 2 {
  5363. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5364. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5365. case 0:
  5366. item.MedChrgitmType = "0"
  5367. break
  5368. case 1:
  5369. item.MedChrgitmType = "14"
  5370. break
  5371. case 2:
  5372. item.MedChrgitmType = "05"
  5373. break
  5374. case 3:
  5375. item.MedChrgitmType = "03"
  5376. break
  5377. case 4:
  5378. item.MedChrgitmType = "03"
  5379. break
  5380. case 5:
  5381. item.MedChrgitmType = "08"
  5382. break
  5383. case 6:
  5384. item.MedChrgitmType = "14"
  5385. break
  5386. case 7:
  5387. item.MedChrgitmType = "14"
  5388. break
  5389. case 8:
  5390. item.MedChrgitmType = "03"
  5391. break
  5392. case 9:
  5393. item.MedChrgitmType = "14"
  5394. break
  5395. case 10:
  5396. item.MedChrgitmType = "14"
  5397. break
  5398. case 11:
  5399. item.MedChrgitmType = "06"
  5400. break
  5401. case 12:
  5402. item.MedChrgitmType = "12"
  5403. break
  5404. case 13:
  5405. item.MedChrgitmType = "01"
  5406. break
  5407. case 14:
  5408. item.MedChrgitmType = "04"
  5409. break
  5410. case 15:
  5411. item.MedChrgitmType = "02"
  5412. break
  5413. }
  5414. } else {
  5415. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5416. case 1:
  5417. item.MedChrgitmType = "14"
  5418. break
  5419. case 2:
  5420. item.MedChrgitmType = "05"
  5421. break
  5422. case 3:
  5423. item.MedChrgitmType = "03"
  5424. break
  5425. case 4:
  5426. item.MedChrgitmType = "03"
  5427. break
  5428. case 5:
  5429. item.MedChrgitmType = "08"
  5430. break
  5431. case 6:
  5432. item.MedChrgitmType = "14"
  5433. break
  5434. case 7:
  5435. item.MedChrgitmType = "14"
  5436. break
  5437. case 8:
  5438. item.MedChrgitmType = "03"
  5439. break
  5440. case 9:
  5441. item.MedChrgitmType = "14"
  5442. break
  5443. }
  5444. }
  5445. } else if item.HisPrescriptionProject.Type == 3 {
  5446. item.MedChrgitmType = "08"
  5447. }
  5448. }
  5449. }
  5450. for _, item := range orderInfos_two {
  5451. fmt.Println(item.MedChrgitmType)
  5452. if item.MedChrgitmType == "01" { //床位费
  5453. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5454. bedCostSelfTotal = bedCostTotal
  5455. }
  5456. if item.MedChrgitmType == "02" { //诊察费
  5457. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5458. zhenChaCostSelfTotal = zhenChaCostTotal
  5459. }
  5460. if item.MedChrgitmType == "03" { //检查费
  5461. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5462. checkCostSelfTotal = checkCostTotal
  5463. }
  5464. if item.MedChrgitmType == "04" { //化验费
  5465. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5466. laboratoryCostSelfTotal = laboratoryCostTotal
  5467. }
  5468. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5469. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5470. treatCostSelfTotal = treatCostTotal
  5471. }
  5472. if item.MedChrgitmType == "06" { //手术费
  5473. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5474. operationCostSelfTotal = treatCostTotal
  5475. }
  5476. if item.MedChrgitmType == "08" { //材料费
  5477. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5478. materialCostSelfTotal = materialCostTotal
  5479. }
  5480. if item.MedChrgitmType == "09" { //西药费
  5481. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5482. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5483. }
  5484. if item.MedChrgitmType == "11" { //中成费
  5485. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5486. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5487. }
  5488. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5489. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5490. otherCostSelfTotal = otherCostTotal
  5491. }
  5492. }
  5493. } else {
  5494. for _, item := range orderInfos {
  5495. if item.MedChrgitmType == "01" { //床位费
  5496. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5497. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5498. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5499. }
  5500. if item.MedChrgitmType == "02" { //诊察费
  5501. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5502. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5503. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5504. }
  5505. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  5506. if item.MedChrgitmType == "03" { //检查费
  5507. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5508. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5509. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5510. }
  5511. } else {
  5512. if item.MedChrgitmType == "03" { //检查费
  5513. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5514. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5515. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5516. }
  5517. }
  5518. if item.MedChrgitmType == "04" { //化验费
  5519. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5520. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5521. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5522. }
  5523. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5524. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5525. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5526. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5527. }
  5528. if item.MedChrgitmType == "06" { //手术费
  5529. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5530. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5531. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5532. }
  5533. if item.MedChrgitmType == "08" { //材料费
  5534. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5535. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5536. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5537. }
  5538. if item.MedChrgitmType == "09" { //西药费
  5539. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5540. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5541. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5542. }
  5543. if item.MedChrgitmType == "11" { //中成费
  5544. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5545. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5546. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5547. }
  5548. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5549. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5550. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5551. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5552. }
  5553. }
  5554. }
  5555. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5556. c.ServeSuccessJSON(map[string]interface{}{
  5557. "order_number": order.Number, //业务流水号
  5558. "id_card_no": his.IdCardNo, //社会保障号
  5559. "department_name": department.Name, //科室
  5560. "number": his.Number, //门诊号
  5561. "date": order.SettleAccountsDate, //结算日期
  5562. "name": order.PsnName, //姓名
  5563. "gender": order.Gend, //性别
  5564. "psn_cash_money": order.PsnCashPay, //个人支付
  5565. "pay_way": "门诊", //结算方式
  5566. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5567. "admin_user_name": admin.UserName, //收款员
  5568. "order": order,
  5569. "order_info": orderInfos_two,
  5570. "his": his,
  5571. "bedCostTotal": bedCostTotal,
  5572. "bedCostSelfTotal": bedCostSelfTotal,
  5573. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5574. "operationCostTotal": operationCostTotal,
  5575. "operationCostSelfTotal": operationCostSelfTotal,
  5576. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5577. "otherCostTotal": otherCostTotal,
  5578. "otherCostSelfTotal": otherCostSelfTotal,
  5579. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5580. "materialCostTotal": materialCostTotal,
  5581. "materialCostSelfTotal": materialCostSelfTotal,
  5582. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5583. "westernMedicineCostTotal": westernMedicineCostTotal,
  5584. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5585. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5586. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5587. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5588. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5589. "checkCostTotal": checkCostTotal,
  5590. "checkCostSelfTotal": checkCostSelfTotal,
  5591. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5592. "laboratoryCostTotal": laboratoryCostTotal,
  5593. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5594. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5595. "treatCostTotal": treatCostTotal,
  5596. "treatCostSelfTotal": treatCostSelfTotal,
  5597. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5598. "zhenChaCostTotal": zhenChaCostTotal,
  5599. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5600. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5601. "his_hospital_record": his_hospital_record,
  5602. })
  5603. }
  5604. func (this *HisApiController) GetIncomeStatisticsData() {
  5605. start_time := this.GetString("start_time")
  5606. end_time := this.GetString("end_time")
  5607. key_words := this.GetString("key_words")
  5608. limit, _ := this.GetInt64("limit")
  5609. page, _ := this.GetInt64("page")
  5610. if page <= 0 {
  5611. page = 1
  5612. }
  5613. if limit <= 0 {
  5614. limit = 10
  5615. }
  5616. statistics_type, _ := this.GetInt64("statistics_type")
  5617. admin := this.GetAdminUserInfo()
  5618. timeLayout := "2006-01-02"
  5619. loc, _ := time.LoadLocation("Local")
  5620. var theStartTIme int64
  5621. if len(start_time) > 0 {
  5622. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5623. if err != nil {
  5624. theStartTIme = 0
  5625. }
  5626. theStartTIme = theTime.Unix()
  5627. }
  5628. var theEndtTIme int64
  5629. if len(end_time) > 0 {
  5630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5631. if err != nil {
  5632. theEndtTIme = 0
  5633. }
  5634. theEndtTIme = theTime.Unix()
  5635. }
  5636. if statistics_type == 1 {
  5637. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5638. this.ServeSuccessJSON(map[string]interface{}{
  5639. "list": list,
  5640. "total": total,
  5641. })
  5642. } else {
  5643. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5644. this.ServeSuccessJSON(map[string]interface{}{
  5645. "list": list,
  5646. "total": total,
  5647. })
  5648. }
  5649. }
  5650. func (c *HisApiController) PostProjectInformation() {
  5651. adminUser := c.GetAdminUserInfo()
  5652. orgId := adminUser.CurrentOrgId
  5653. dataBody := make(map[string]interface{}, 0)
  5654. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5655. if err != nil {
  5656. utils.ErrorLog(err.Error())
  5657. return
  5658. }
  5659. utils.ErrorLog("%v", dataBody)
  5660. var projectList []*models.HisProject
  5661. var total_goods []interface{}
  5662. tempProjects := dataBody["projects"].([]interface{})
  5663. total_goods = tempProjects
  5664. for index, projectMap := range tempProjects {
  5665. projectM := projectMap.(map[string]interface{})
  5666. var project models.HisProject
  5667. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5668. utils.ErrorLog("project_name")
  5669. return
  5670. }
  5671. project_name, _ := projectM["project_name"].(string)
  5672. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5673. err_log := models.ExportErrLog{
  5674. LogType: 6,
  5675. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5676. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5677. Status: 1,
  5678. CreateTime: time.Now().Unix(),
  5679. UpdateTime: time.Now().Unix(),
  5680. ExportTime: time.Now().Unix(),
  5681. }
  5682. service.CreateExportErrLog(&err_log)
  5683. continue
  5684. }
  5685. project.ProjectName = project_name
  5686. prices := projectM["price"].(string)
  5687. price, _ := strconv.ParseFloat(prices, 64)
  5688. if price <= 0 { //名字为空则生成一条导入错误日志
  5689. err_log := models.ExportErrLog{
  5690. LogType: 6,
  5691. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5692. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5693. Status: 1,
  5694. CreateTime: time.Now().Unix(),
  5695. UpdateTime: time.Now().Unix(),
  5696. ExportTime: time.Now().Unix(),
  5697. }
  5698. service.CreateExportErrLog(&err_log)
  5699. continue
  5700. }
  5701. project.Price = price
  5702. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5703. utils.ErrorLog("unit_id")
  5704. return
  5705. }
  5706. unit := projectM["unit"].(string)
  5707. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5708. err_log := models.ExportErrLog{
  5709. LogType: 6,
  5710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5711. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5712. Status: 1,
  5713. CreateTime: time.Now().Unix(),
  5714. UpdateTime: time.Now().Unix(),
  5715. ExportTime: time.Now().Unix(),
  5716. }
  5717. service.CreateExportErrLog(&err_log)
  5718. continue
  5719. }
  5720. project.Unit = unit
  5721. cost_classify := projectM["cost_classify"].(string)
  5722. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5723. err_log := models.ExportErrLog{
  5724. LogType: 6,
  5725. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5726. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5727. Status: 1,
  5728. CreateTime: time.Now().Unix(),
  5729. UpdateTime: time.Now().Unix(),
  5730. ExportTime: time.Now().Unix(),
  5731. }
  5732. service.CreateExportErrLog(&err_log)
  5733. continue
  5734. }
  5735. var costClassify = "费用类别"
  5736. var cost_classify_id int64
  5737. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5738. if len(cost_classify) != 0 {
  5739. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5740. if errcode == gorm.ErrRecordNotFound {
  5741. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5742. dataconfig := models.DictDataconfig{
  5743. ParentId: costClassifyConfig.ID,
  5744. Module: "system",
  5745. OrgId: orgId,
  5746. Name: cost_classify,
  5747. FieldName: "",
  5748. Value: costConfig.Value + 1,
  5749. CreatedTime: "",
  5750. UpdatedTime: "",
  5751. CreateUserId: adminUser.AdminUser.Id,
  5752. Status: 1,
  5753. Remark: "",
  5754. DeleteIdSystem: 0,
  5755. Title: "",
  5756. Content: "",
  5757. Order: 0,
  5758. Code: "",
  5759. }
  5760. service.CreatedDicConfig(&dataconfig)
  5761. }
  5762. }
  5763. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5764. for _, it := range costClassList {
  5765. if cost_classify == it.Name {
  5766. cost_classify_id = int64(it.Value)
  5767. }
  5768. }
  5769. project.CostClassify = cost_classify_id
  5770. executive_section := projectM["executive_section"].(string)
  5771. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5772. err_log := models.ExportErrLog{
  5773. LogType: 6,
  5774. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5775. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5776. Status: 1,
  5777. CreateTime: time.Now().Unix(),
  5778. UpdateTime: time.Now().Unix(),
  5779. ExportTime: time.Now().Unix(),
  5780. }
  5781. service.CreateExportErrLog(&err_log)
  5782. continue
  5783. }
  5784. if len(executive_section) != 0 {
  5785. //查找科室是否有内容
  5786. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5787. if errcodedepart == gorm.ErrRecordNotFound {
  5788. department := models.XtHisDepartment{
  5789. Name: executive_section,
  5790. Status: 1,
  5791. UserOrgId: adminUser.CurrentOrgId,
  5792. CreatedTime: time.Now().Unix(),
  5793. }
  5794. service.CreateDePartment(&department)
  5795. }
  5796. }
  5797. var executive_section_id int64
  5798. departMentList, _ := service.GetAllDepartMent(orgId)
  5799. for _, it := range departMentList {
  5800. if executive_section == it.Name {
  5801. executive_section_id = it.ID
  5802. }
  5803. }
  5804. project.ExecutiveSection = executive_section_id
  5805. medical_coverage := projectM["medical_coverage"].(string)
  5806. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5807. err_log := models.ExportErrLog{
  5808. LogType: 6,
  5809. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5810. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5811. Status: 1,
  5812. CreateTime: time.Now().Unix(),
  5813. UpdateTime: time.Now().Unix(),
  5814. ExportTime: time.Now().Unix(),
  5815. }
  5816. service.CreateExportErrLog(&err_log)
  5817. continue
  5818. }
  5819. var medicalCoverage = "医保等级"
  5820. var medical_coverage_id int64
  5821. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5822. if len(medical_coverage) != 0 {
  5823. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5824. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5825. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5826. dataconfig := models.DictDataconfig{
  5827. ParentId: medicalCoverageConfig.ID,
  5828. Module: "system",
  5829. OrgId: orgId,
  5830. Name: medical_coverage,
  5831. FieldName: "",
  5832. Value: medicalCoverageConfig.Value + 1,
  5833. CreatedTime: "",
  5834. UpdatedTime: "",
  5835. CreateUserId: adminUser.AdminUser.Id,
  5836. Status: 1,
  5837. Remark: "",
  5838. DeleteIdSystem: 0,
  5839. Title: "",
  5840. Content: "",
  5841. Order: 0,
  5842. Code: "",
  5843. }
  5844. service.CreatedDicConfig(&dataconfig)
  5845. }
  5846. }
  5847. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5848. for _, it := range medicalCoverageList {
  5849. if medical_coverage == it.Name {
  5850. medical_coverage_id = int64(it.Value)
  5851. }
  5852. }
  5853. project.MedicalCoverage = medical_coverage_id
  5854. pinyin := projectM["pinyin"].(string)
  5855. project.Pinyin = pinyin
  5856. wubi := projectM["wubi"].(string)
  5857. project.Wubi = wubi
  5858. statistical_classification := projectM["statistical_classification"].(string)
  5859. var statisticalClassification = "统计分类"
  5860. var statistical_classification_id int64
  5861. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5862. if len(statistical_classification) != 0 {
  5863. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5864. if classificationerrcodes == gorm.ErrRecordNotFound {
  5865. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5866. dataconfig := models.DictDataconfig{
  5867. ParentId: classiFication.ID,
  5868. Module: "system",
  5869. OrgId: orgId,
  5870. Name: statistical_classification,
  5871. FieldName: "",
  5872. Value: classiFicationConfig.Value + 1,
  5873. CreatedTime: "",
  5874. UpdatedTime: "",
  5875. CreateUserId: adminUser.AdminUser.Id,
  5876. Status: 1,
  5877. Remark: "",
  5878. DeleteIdSystem: 0,
  5879. Title: "",
  5880. Content: "",
  5881. Order: 0,
  5882. Code: "",
  5883. }
  5884. service.CreatedDicConfig(&dataconfig)
  5885. }
  5886. }
  5887. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5888. for _, it := range classiFicationList {
  5889. if statistical_classification == it.Name {
  5890. statistical_classification_id = int64(it.Value)
  5891. }
  5892. }
  5893. project.StatisticalClassification = statistical_classification_id
  5894. disease_directory := int64(projectM["disease_directory"].(float64))
  5895. project.DiseaseDirectory = disease_directory
  5896. is_record := int64(projectM["is_record"].(float64))
  5897. project.IsRecord = is_record
  5898. medical_code := projectM["medical_code"].(string)
  5899. project.MedicalCode = medical_code
  5900. tube_color := projectM["tube_color"].(string)
  5901. var tubeColor = "试管颜色"
  5902. var tube_color_id int64
  5903. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5904. if len(tube_color) != 0 {
  5905. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5906. if errcodetube == gorm.ErrRecordNotFound {
  5907. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5908. dataconfig := models.DictDataconfig{
  5909. ParentId: tubeColorConfig.ID,
  5910. Module: "system",
  5911. OrgId: orgId,
  5912. Name: tube_color,
  5913. FieldName: "",
  5914. Value: tubeConfig.Value + 1,
  5915. CreatedTime: "",
  5916. UpdatedTime: "",
  5917. CreateUserId: adminUser.AdminUser.Id,
  5918. Status: 1,
  5919. Remark: "",
  5920. DeleteIdSystem: 0,
  5921. Title: "",
  5922. Content: "",
  5923. Order: 0,
  5924. Code: "",
  5925. }
  5926. service.CreatedDicConfig(&dataconfig)
  5927. }
  5928. }
  5929. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5930. for _, it := range tubeColorList {
  5931. if tube_color == it.Name {
  5932. tube_color_id = int64(it.Value)
  5933. }
  5934. }
  5935. project.TubeColor = tube_color_id
  5936. single_dose := projectM["single_dose"].(string)
  5937. project.SingleDose = single_dose
  5938. execution_frequency := projectM["execution_frequency"].(string)
  5939. project.ExecutionFrequency = execution_frequency
  5940. delivery_way := projectM["delivery_way"].(string)
  5941. project.DeliveryWay = delivery_way
  5942. number_days := projectM["number_days"].(string)
  5943. project.NumberDays = number_days
  5944. total := projectM["total"].(string)
  5945. project.Total = total
  5946. medical_status := int64(projectM["medical_status"].(float64))
  5947. project.MedicalStatus = medical_status
  5948. category := int64(projectM["category"].(float64))
  5949. project.Category = category
  5950. specail_project := int64(projectM["specail_project"].(float64))
  5951. project.SpecailProject = specail_project
  5952. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5953. project.SocialSecurityDirectoryCode = social_security_directory_code
  5954. remark := projectM["remark"].(string)
  5955. project.Remark = remark
  5956. record_date := projectM["record_date"].(string)
  5957. timeLayout := "2006-01-02"
  5958. loc, _ := time.LoadLocation("Local")
  5959. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5960. project.RecordDate = theTime.Unix()
  5961. projectList = append(projectList, &project)
  5962. }
  5963. export_time := time.Now().Unix()
  5964. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5965. if len(projectList) > 0 {
  5966. for _, item := range projectList {
  5967. project := models.HisProject{
  5968. ProjectName: item.ProjectName,
  5969. Price: item.Price,
  5970. Unit: item.Unit,
  5971. CostClassify: item.CostClassify,
  5972. ExecutiveSection: item.ExecutiveSection,
  5973. MedicalCoverage: item.MedicalCoverage,
  5974. UserOrgId: orgId,
  5975. Status: 1,
  5976. CreatedTime: time.Now().Unix(),
  5977. Pinyin: item.Pinyin,
  5978. Wubi: item.Wubi,
  5979. StatisticalClassification: item.StatisticalClassification,
  5980. DiseaseDirectory: item.DiseaseDirectory,
  5981. IsRecord: item.IsRecord,
  5982. MedicalCode: item.MedicalCode,
  5983. TubeColor: item.TubeColor,
  5984. SingleDose: item.SingleDose,
  5985. DeliveryWay: item.DeliveryWay,
  5986. NumberDays: item.NumberDays,
  5987. Total: item.Total,
  5988. Category: item.Category,
  5989. MedicalStatus: item.MedicalStatus,
  5990. SpecailProject: item.SpecailProject,
  5991. RecordDate: item.RecordDate,
  5992. Remark: item.Remark,
  5993. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5994. ExecutionFrequency: item.ExecutionFrequency,
  5995. }
  5996. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5997. if errcodeproject == gorm.ErrRecordNotFound {
  5998. service.CreateProjectInfomation(&project)
  5999. } else if errcodeproject == nil {
  6000. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  6001. }
  6002. log := models.ExportLog{
  6003. LogType: 6,
  6004. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6005. TotalNum: int64(len(total_goods)),
  6006. FailNum: int64(len(errLogs)),
  6007. SuccessNum: int64(len(projectList)),
  6008. CreateTime: time.Now().Unix(),
  6009. UpdateTime: time.Now().Unix(),
  6010. ExportTime: export_time,
  6011. Status: 1,
  6012. }
  6013. service.CreateExportLog(&log)
  6014. c.ServeSuccessJSON(map[string]interface{}{
  6015. "msg": "导入成功",
  6016. "total_num": len(total_goods),
  6017. "success_num": len(projectList),
  6018. "fail_num": int64(len(errLogs)),
  6019. })
  6020. }
  6021. } else {
  6022. log := models.ExportLog{
  6023. LogType: 6,
  6024. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6025. TotalNum: int64(len(total_goods)),
  6026. FailNum: int64(len(errLogs)),
  6027. SuccessNum: int64(len(projectList)),
  6028. CreateTime: time.Now().Unix(),
  6029. UpdateTime: time.Now().Unix(),
  6030. ExportTime: export_time,
  6031. Status: 1,
  6032. }
  6033. service.CreateExportLog(&log)
  6034. c.ServeSuccessJSON(map[string]interface{}{
  6035. "msg": "导入成功",
  6036. "total_num": len(total_goods),
  6037. "success_num": len(projectList),
  6038. "fail_num": int64(len(errLogs)),
  6039. })
  6040. }
  6041. }
  6042. //func (this *HisApiController) EditProjectInformation(){
  6043. //
  6044. // id, _ := this.GetInt64("id")
  6045. // project_team := this.GetString("project_team")
  6046. // price := this.GetString("price")
  6047. // price_float, _ := strconv.ParseFloat(price, 64)
  6048. // pinyin := this.GetString("pinyin")
  6049. // wubi := this.GetString("wubi")
  6050. // tube_color, _ := this.GetInt64("tube_color")
  6051. // team_type, _ := this.GetInt64("team_type")
  6052. // remark := this.GetString("remark")
  6053. // ids := this.GetString("ids")
  6054. // item_id := this.GetString("item_id")
  6055. // projectTeam := models.XtHisProjectTeam{
  6056. // ProjectTeam: project_team,
  6057. // Price: price_float,
  6058. // Pinyin: pinyin,
  6059. // Wubi: wubi,
  6060. // TubeColor: tube_color,
  6061. // TeamType: team_type,
  6062. // Remark: remark,
  6063. // ProjectId: ids,
  6064. // ItemId: item_id,
  6065. // }
  6066. //
  6067. //
  6068. // dataBody := make(map[string]interface{}, 0)
  6069. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6070. // if err != nil {
  6071. // utils.ErrorLog(err.Error())
  6072. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6073. // return
  6074. // }
  6075. //
  6076. // err = service.UpdatedProjectTeam(id, &projectTeam)
  6077. //
  6078. //
  6079. // if err != nil {
  6080. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6081. // return
  6082. // }
  6083. //
  6084. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  6085. // infos, _ := dataBody["info"].([]interface{})
  6086. // if len(infos) > 0 {
  6087. // var ids []string
  6088. //
  6089. // for _, item := range infos {
  6090. // items := item.(map[string]interface{})
  6091. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6092. // utils.ErrorLog("id")
  6093. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6094. // return
  6095. // }
  6096. // id := int64(items["id"].(float64))
  6097. //
  6098. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6099. // utils.ErrorLog("type")
  6100. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6101. // return
  6102. // }
  6103. // types := int64(items["type"].(float64))
  6104. //
  6105. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6106. // utils.ErrorLog("number")
  6107. // }
  6108. //
  6109. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  6110. //
  6111. // projectList := models.XtHisProjectList{
  6112. // Number: number,
  6113. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  6114. // ProjectId: id,
  6115. // Status: 1,
  6116. // CreatedTime: time.Now().Unix(),
  6117. // UpdatedTime: time.Now().Unix(),
  6118. // TeamId: projectTeam.ID,
  6119. // Type: types,
  6120. // }
  6121. // list := projectList
  6122. //
  6123. // service.CreateProjectList(&list)
  6124. //
  6125. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  6126. //
  6127. // }
  6128. // ids_str := strings.Join(ids, ",")
  6129. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  6130. // service.SaveProjectTeam(&projectTeam)
  6131. // this.ServeSuccessJSON(map[string]interface{}{
  6132. // "projectTeam": projectTeam,
  6133. // })
  6134. // }
  6135. // }
  6136. //}
  6137. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6138. name := c.GetString("name")
  6139. mode_id, _ := c.GetInt64("mode", 0)
  6140. types, _ := c.GetInt64("type", 0)
  6141. patient_id, _ := c.GetInt64("patient_id", 0)
  6142. types = 1
  6143. adminInfo := c.GetAdminUserInfo()
  6144. template := &models.HisPrescriptionTemplate{
  6145. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6146. PatientId: patient_id,
  6147. Type: types,
  6148. Status: 1,
  6149. Ctime: time.Now().Unix(),
  6150. Mtime: time.Now().Unix(),
  6151. Name: name,
  6152. Mode: mode_id,
  6153. }
  6154. dataBody := make(map[string]interface{}, 0)
  6155. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6156. if err != nil {
  6157. utils.ErrorLog(err.Error())
  6158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6159. return
  6160. }
  6161. err = service.CreateHisPrescriptionTemplate(template)
  6162. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6163. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6164. if len(prescriptions) > 0 {
  6165. for _, item := range prescriptions {
  6166. items := item.(map[string]interface{})
  6167. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6168. utils.ErrorLog("type")
  6169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6170. return
  6171. }
  6172. types := int64(items["type"].(float64))
  6173. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6174. utils.ErrorLog("med_type")
  6175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6176. return
  6177. }
  6178. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6179. ctime := time.Now().Unix()
  6180. prescription := &models.HisPrescriptionInfoTemplate{
  6181. PatientId: patient_id,
  6182. UserOrgId: adminInfo.CurrentOrgId,
  6183. Ctime: ctime,
  6184. Mtime: ctime,
  6185. Type: types,
  6186. Modifier: adminInfo.AdminUser.Id,
  6187. Creator: adminInfo.AdminUser.Id,
  6188. Status: 1,
  6189. PTemplateId: template.ID,
  6190. MedType: med_type,
  6191. }
  6192. service.CreateHisPrescriptionInfoTemplate(prescription)
  6193. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6194. advices := items["advices"].([]interface{})
  6195. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6196. ctime := time.Now().Unix()
  6197. mtime := ctime
  6198. if len(advices) > 0 {
  6199. for _, advice := range advices {
  6200. var s models.HisPrescriptionAdviceTemplate
  6201. s.PrescriptionId = prescription.ID
  6202. s.AdviceType = 2
  6203. s.StopState = 2
  6204. s.ExecutionState = 2
  6205. s.Status = 1
  6206. s.UserOrgId = adminInfo.CurrentOrgId
  6207. s.CreatedTime = ctime
  6208. s.UpdatedTime = mtime
  6209. s.PatientId = patient_id
  6210. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6211. if errcode > 0 {
  6212. c.ServeFailJSONWithSGJErrorCode(errcode)
  6213. return
  6214. }
  6215. service.CreateHisPrescriptionAdviceTemplate(&s)
  6216. }
  6217. }
  6218. }
  6219. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6220. projects := items["project"].([]interface{})
  6221. if len(projects) > 0 {
  6222. for _, project := range projects {
  6223. var p models.HisPrescriptionProjectTemplate
  6224. p.PrescriptionId = prescription.ID
  6225. p.Ctime = time.Now().Unix()
  6226. p.Mtime = time.Now().Unix()
  6227. p.PatientId = patient_id
  6228. p.UserOrgId = adminInfo.CurrentOrgId
  6229. p.Status = 1
  6230. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6231. if errcode > 0 {
  6232. c.ServeFailJSONWithSGJErrorCode(errcode)
  6233. return
  6234. }
  6235. service.CreateHisPrescriptionProjectTemplate(&p)
  6236. }
  6237. }
  6238. }
  6239. }
  6240. c.ServeSuccessJSON(map[string]interface{}{
  6241. "msg": "创建成功",
  6242. })
  6243. }
  6244. }
  6245. }
  6246. func (c *HisApiController) PreSettle() {
  6247. id, _ := c.GetInt64("id")
  6248. record_time := c.GetString("record_time")
  6249. his_patient_id, _ := c.GetInt64("his_patient_id")
  6250. timeLayout := "2006-01-02"
  6251. loc, _ := time.LoadLocation("Local")
  6252. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6253. diagnosis_id := c.GetString("diagnosis")
  6254. sick_type, _ := c.GetInt64("sick_type")
  6255. reg_type, _ := c.GetInt64("p_type")
  6256. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6258. if err != nil {
  6259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6260. return
  6261. }
  6262. recordDateTime := theTime.Unix()
  6263. adminUser := c.GetAdminUserInfo()
  6264. var prescriptions []*models.HisPrescription
  6265. var start_time int64
  6266. var end_time int64
  6267. ids_str := c.GetString("ids")
  6268. ids_arr := strings.Split(ids_str, ",")
  6269. fmt.Println(reg_type)
  6270. if settle_accounts_type == 1 { //日结
  6271. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6272. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6273. } else {
  6274. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6275. }
  6276. fmt.Println(prescriptions)
  6277. } else { //月结
  6278. start_time_str := c.GetString("start_time")
  6279. end_time_str := c.GetString("end_time")
  6280. timeLayout := "2006-01-02"
  6281. loc, _ := time.LoadLocation("Local")
  6282. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6283. if err != nil {
  6284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6285. return
  6286. }
  6287. recordStartTime := theStartTime.Unix()
  6288. start_time = recordStartTime
  6289. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6290. if err != nil {
  6291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6292. return
  6293. }
  6294. recordEndTime := theEndTime.Unix()
  6295. end_time = recordEndTime
  6296. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6297. }
  6298. if reg_type == 1111 || reg_type == 1112 {
  6299. reg_type = 11
  6300. }
  6301. timestamp := time.Now().Unix()
  6302. tempTime := time.Unix(timestamp, 0)
  6303. timeFormat := tempTime.Format("20060102150405")
  6304. chrgBchno := rand.Intn(100000) + 10000
  6305. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6306. strconv.FormatInt(his.PatientId, 10)
  6307. var ids []int64
  6308. for _, item := range prescriptions {
  6309. ids = append(ids, item.ID)
  6310. }
  6311. fmt.Println(ids)
  6312. var total float64
  6313. for _, item := range prescriptions {
  6314. fmt.Println(item)
  6315. if item.Type == 1 { //药品
  6316. for _, subItem := range item.HisDoctorAdviceInfo {
  6317. total = total + (subItem.Price * subItem.PrescribingNumber)
  6318. }
  6319. }
  6320. if item.Type == 2 { //项目
  6321. for _, subItem := range item.HisPrescriptionProject {
  6322. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6323. total = total + (subItem.Price * cnt)
  6324. }
  6325. }
  6326. for _, subItem := range item.HisAdditionalCharge {
  6327. total = total + (subItem.Price * float64(subItem.Count))
  6328. }
  6329. }
  6330. allTotal := fmt.Sprintf("%.2f", total)
  6331. totals, _ := strconv.ParseFloat(allTotal, 64)
  6332. order := &models.HisOrder{
  6333. UserOrgId: adminUser.CurrentOrgId,
  6334. HisPatientId: his.ID,
  6335. PatientId: id,
  6336. SettleAccountsDate: recordDateTime,
  6337. Ctime: time.Now().Unix(),
  6338. Mtime: time.Now().Unix(),
  6339. Status: 1,
  6340. OrderStatus: 1,
  6341. MdtrtId: his.Number,
  6342. Number: chrg_bchno,
  6343. MedfeeSumamt: totals,
  6344. SettleEndTime: end_time,
  6345. SettleStartTime: start_time,
  6346. SettleType: settle_accounts_type,
  6347. PType: 2,
  6348. IsPre: 1,
  6349. MedType: strconv.Itoa(int(reg_type)),
  6350. Diagnosis: diagnosis_id,
  6351. }
  6352. err = service.CreateOrder(order)
  6353. if err != nil {
  6354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6355. return
  6356. }
  6357. var customs []*Custom
  6358. for _, item := range prescriptions {
  6359. fmt.Println(item.Type)
  6360. if item.Type == 1 { //药品
  6361. for _, subItem := range item.HisDoctorAdviceInfo {
  6362. cus := &Custom{
  6363. AdviceId: subItem.ID,
  6364. ProjectId: 0,
  6365. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6366. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6367. FeedetlSn: subItem.FeedetlSn,
  6368. Price: fmt.Sprintf("%.2f", subItem.Price),
  6369. MedListCodg: subItem.MedListCodg,
  6370. Type: 1,
  6371. }
  6372. customs = append(customs, cus)
  6373. }
  6374. }
  6375. if item.Type == 2 { //项目
  6376. for _, subItem := range item.HisPrescriptionProject {
  6377. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6378. cus := &Custom{
  6379. AdviceId: 0,
  6380. ProjectId: subItem.ID,
  6381. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6382. Cut: fmt.Sprintf("%.2f", cnt),
  6383. FeedetlSn: subItem.FeedetlSn,
  6384. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6385. MedListCodg: subItem.MedListCodg,
  6386. Type: 2,
  6387. }
  6388. customs = append(customs, cus)
  6389. }
  6390. }
  6391. for _, item := range item.HisAdditionalCharge {
  6392. cus := &Custom{
  6393. ItemId: item.ID,
  6394. AdviceId: 0,
  6395. ProjectId: 0,
  6396. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6397. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6398. FeedetlSn: item.FeedetlSn,
  6399. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6400. MedListCodg: item.XtHisAddtionConfig.Code,
  6401. Type: 3,
  6402. }
  6403. customs = append(customs, cus)
  6404. }
  6405. }
  6406. fmt.Println(customs)
  6407. for _, item := range customs {
  6408. var advice_id int64 = 0
  6409. var project_id int64 = 0
  6410. var item_id int64 = 0
  6411. var types int64 = 0
  6412. if item.Type == 1 {
  6413. advice_id = item.AdviceId
  6414. project_id = 0
  6415. item_id = 0
  6416. } else if item.Type == 2 {
  6417. advice_id = 0
  6418. item_id = 0
  6419. project_id = item.ProjectId
  6420. } else if item.Type == 3 {
  6421. advice_id = 0
  6422. item_id = item.ItemId
  6423. project_id = 0
  6424. }
  6425. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6426. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6427. pric, _ := strconv.ParseFloat(item.Price, 32)
  6428. info := &models.HisOrderInfo{
  6429. OrderNumber: order.Number,
  6430. UploadDate: time.Now().Unix(),
  6431. AdviceId: advice_id,
  6432. DetItemFeeSumamt: detItemFeeSumamt,
  6433. Cnt: cut,
  6434. Pric: pric,
  6435. PatientId: id,
  6436. Status: 1,
  6437. Mtime: time.Now().Unix(),
  6438. Ctime: time.Now().Unix(),
  6439. UserOrgId: adminUser.CurrentOrgId,
  6440. HisPatientId: his.ID,
  6441. OrderId: order.ID,
  6442. ProjectId: project_id,
  6443. Type: types,
  6444. ItemId: item_id,
  6445. }
  6446. service.CreateOrderInfo(info)
  6447. }
  6448. his.SickType = sick_type
  6449. service.UpdataHisPateint(&his)
  6450. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6451. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6452. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6453. if err == nil {
  6454. c.ServeSuccessJSON(map[string]interface{}{
  6455. "msg": "结算成功",
  6456. })
  6457. }
  6458. }
  6459. type CustomOrderInfo struct {
  6460. Name string
  6461. Spec string
  6462. Unit string
  6463. Count float64
  6464. Price float64
  6465. Total float64
  6466. }
  6467. func (c *HisApiController) GetPrivateExpensesInfo() {
  6468. order_id, _ := c.GetInt64("id", 0)
  6469. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6470. order, _ := service.GetHisOrderByID(order_id)
  6471. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6472. if order.ID == 0 {
  6473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6474. return
  6475. }
  6476. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6477. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6478. org_id := c.GetAdminUserInfo().CurrentOrgId
  6479. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6480. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6481. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6482. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6483. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6484. var orderInfos_four []*models.HisOrderInfoTwo
  6485. for _, item := range orderInfos_three {
  6486. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6487. item.HisPrescriptionProject.IsCheckTeam = 1
  6488. orderInfos_four = append(orderInfos_four, item)
  6489. }
  6490. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6491. item.HisPrescriptionProject.IsCheckTeam = 2
  6492. orderInfos_two = append(orderInfos_two, item)
  6493. }
  6494. }
  6495. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6496. var cus_slice []CustomOrderInfo
  6497. for _, item := range new_order_info {
  6498. var cus CustomOrderInfo
  6499. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6500. cus.Unit = ""
  6501. cus.Spec = ""
  6502. var total float64
  6503. for _, subItem := range orderInfos_four {
  6504. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6505. total = total + subItem.DetItemFeeSumamt
  6506. fmt.Println(subItem.DetItemFeeSumamt)
  6507. }
  6508. }
  6509. cus.Count = 1
  6510. cus.Total = total
  6511. cus_slice = append(cus_slice, cus)
  6512. }
  6513. orderInfos = append(orderInfos, orderInfos_two...)
  6514. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6515. orderInfos = append(orderInfos, orderInfos_three...)
  6516. }
  6517. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6518. c.ServeSuccessJSON(map[string]interface{}{
  6519. "order": order,
  6520. "order_info": orderInfos,
  6521. "patient": patient,
  6522. "admin_info": adminInfo,
  6523. "his": his,
  6524. "current_admin": role,
  6525. "org_config": miConfig,
  6526. "new_order_info": cus_slice,
  6527. })
  6528. }
  6529. func (this *HisApiController) ChangeMedType() {
  6530. med_type := this.GetString("med_type")
  6531. old_med_type := this.GetString("old_med_type")
  6532. ids := this.GetString("ids")
  6533. settle_type, _ := this.GetInt64("settle_type")
  6534. start_time := this.GetString("start_time")
  6535. end_time := this.GetString("end_time")
  6536. ids_arr := strings.Split(ids, ",")
  6537. if settle_type == 1 { //日结
  6538. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6539. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6540. prescription.MedType = med_type
  6541. err := service.SaveHisPrescription(&prescription)
  6542. if err == nil {
  6543. this.ServeSuccessJSON(map[string]interface{}{
  6544. "msg": "修改成功",
  6545. })
  6546. } else {
  6547. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6548. return
  6549. }
  6550. } else if settle_type == 2 {
  6551. timeLayout := "2006-01-02"
  6552. loc, _ := time.LoadLocation("Local")
  6553. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6554. if err != nil {
  6555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6556. return
  6557. }
  6558. recordStartTime := theStartTime.Unix()
  6559. start_time_timestamp := recordStartTime
  6560. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6561. if err != nil {
  6562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6563. return
  6564. }
  6565. recordEndTime := theEndTime.Unix()
  6566. end_time_timestamp := recordEndTime
  6567. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6568. if updateErr == nil {
  6569. this.ServeSuccessJSON(map[string]interface{}{
  6570. "msg": "修改成功",
  6571. })
  6572. } else {
  6573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6574. return
  6575. }
  6576. }
  6577. }
  6578. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6579. patient_id, _ := c.GetInt64("patient_id")
  6580. his_patient_id, _ := c.GetInt64("his_patient_id")
  6581. record_date := c.GetString("record_date")
  6582. start_time := c.GetString("start_time")
  6583. end_time := c.GetString("end_time")
  6584. order_status, _ := c.GetInt64("type", 0)
  6585. p_type, _ := c.GetInt64("p_type", 0)
  6586. order_id, _ := c.GetInt64("order_id", 0)
  6587. timeLayout := "2006-01-02"
  6588. loc, _ := time.LoadLocation("Local")
  6589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6590. if err != nil {
  6591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6592. return
  6593. }
  6594. recordDateTime := theTime.Unix()
  6595. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6596. if err != nil {
  6597. }
  6598. startRecordDateTime := startTime.Unix()
  6599. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6600. if err != nil {
  6601. }
  6602. endRecordDateTime := endTime.Unix()
  6603. admin := c.GetAdminUserInfo()
  6604. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6605. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6606. order, _ := service.GetHisOrderByID(order_id)
  6607. var monthPrescriptions []*models.HisPrescription
  6608. if order_status == 1 || order_status == 0 {
  6609. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6610. } else if order_status == 2 {
  6611. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6612. }
  6613. var settle_total float64
  6614. for _, item := range monthPrescriptions {
  6615. if len(item.HisPrescriptionProject) > 0 {
  6616. for _, subItem := range item.HisPrescriptionProject {
  6617. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6618. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6619. settle_total = settle_total + total
  6620. }
  6621. }
  6622. if len(item.HisDoctorAdviceInfo) > 0 {
  6623. for _, subItem := range item.HisDoctorAdviceInfo {
  6624. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6625. settle_total = settle_total + total
  6626. }
  6627. }
  6628. }
  6629. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6630. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6631. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6632. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6633. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6634. //获取所有科室信息
  6635. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6636. c.ServeSuccessJSON(map[string]interface{}{
  6637. "his_info": his_patient_info,
  6638. "xt_info": xt_patient_info,
  6639. "case_history": case_history,
  6640. "info": patientPrescriptionInfo,
  6641. "last_info": lastPatientPrescriptionInfo,
  6642. "month_prescriptions": monthPrescriptions,
  6643. "order": order,
  6644. "doctors": doctors,
  6645. "department": department,
  6646. "settle_total": settle_total,
  6647. })
  6648. return
  6649. }
  6650. func (c *HisApiController) GetHisMonthPatientInfo() {
  6651. patient_id, _ := c.GetInt64("patient_id")
  6652. his_patient_id, _ := c.GetInt64("his_patient_id")
  6653. record_date := c.GetString("record_date")
  6654. number := c.GetString("number")
  6655. start_time := c.GetString("start_time")
  6656. end_time := c.GetString("end_time")
  6657. p_type, _ := c.GetInt64("p_type")
  6658. timeLayout := "2006-01-02"
  6659. loc, _ := time.LoadLocation("Local")
  6660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6661. if err != nil {
  6662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6663. return
  6664. }
  6665. recordDateTime := theTime.Unix()
  6666. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6667. if err != nil {
  6668. }
  6669. startRecordDateTime := startTime.Unix()
  6670. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6671. if err != nil {
  6672. }
  6673. endRecordDateTime := endTime.Unix()
  6674. admin := c.GetAdminUserInfo()
  6675. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6676. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6677. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6678. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6679. var settle_total float64
  6680. for _, item := range monthPrescriptions {
  6681. if len(item.HisPrescriptionProject) > 0 {
  6682. for _, subItem := range item.HisPrescriptionProject {
  6683. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6684. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6685. settle_total = settle_total + total
  6686. }
  6687. }
  6688. if len(item.HisDoctorAdviceInfo) > 0 {
  6689. for _, subItem := range item.HisDoctorAdviceInfo {
  6690. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6691. settle_total = settle_total + total
  6692. }
  6693. }
  6694. }
  6695. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6696. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6697. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6698. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6699. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6700. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6701. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6702. //获取所有科室信息
  6703. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6704. c.ServeSuccessJSON(map[string]interface{}{
  6705. "his_info": his_patient_info,
  6706. "xt_info": xt_patient_info,
  6707. "case_history": case_history,
  6708. "info": patientPrescriptionInfo,
  6709. "month_prescriptions": monthPrescriptions,
  6710. "order": order,
  6711. "doctors": doctors,
  6712. "department": department,
  6713. "count": count,
  6714. "drugStockConfig": drugStockConfig,
  6715. "last_info": lastPatientPrescriptionInfo,
  6716. "settle_total": settle_total,
  6717. })
  6718. return
  6719. }
  6720. func (c *HisApiController) GetAllOrder() {
  6721. org_id := c.GetAdminUserInfo().CurrentOrgId
  6722. orders, _ := service.GetNewHisOrderList(org_id)
  6723. c.ServeSuccessJSON(map[string]interface{}{
  6724. "order": orders,
  6725. })
  6726. return
  6727. }
  6728. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6729. newArr = make([]*models.HisOrderInfoTwo, 0)
  6730. for i := 0; i < len(arr); i++ {
  6731. repeat := false
  6732. for j := i + 1; j < len(arr); j++ {
  6733. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6734. repeat = true
  6735. break
  6736. }
  6737. }
  6738. if !repeat {
  6739. newArr = append(newArr, arr[i])
  6740. }
  6741. }
  6742. return
  6743. }
  6744. //修改处方退库操作 参数传修改之前的处方数据
  6745. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6746. if advice.ExecutionState == 1 {
  6747. //查询该病人该药品是否有库存记录
  6748. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6749. if errcode == gorm.ErrRecordNotFound {
  6750. } else {
  6751. //退库
  6752. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6753. if advice.PrescribingNumberUnit == drug.MinUnit {
  6754. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6755. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6756. //退库
  6757. warehouseInfo := models.DrugWarehouseInfo{
  6758. StockMinNumber: prescribingNumber,
  6759. }
  6760. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6761. operation_time := time.Now().Unix()
  6762. creater := advice.AdviceDoctor
  6763. ctime := time.Now().Unix()
  6764. timeStr := time.Now().Format("2006-01-02")
  6765. timeArr := strings.Split(timeStr, "-")
  6766. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6767. total = total + 1
  6768. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6769. cancelStock := models.DrugCancelStock{
  6770. OrderNumber: orderNumber,
  6771. OperaTime: operation_time,
  6772. OrgId: advice.UserOrgId,
  6773. Creater: creater,
  6774. Ctime: ctime,
  6775. Status: 1,
  6776. ReturnTime: advice.AdviceDate,
  6777. Dealer: info.Dealer,
  6778. Manufacturer: info.Manufacturer,
  6779. Type: 1,
  6780. }
  6781. service.AddSigleDrugCancelStock(&cancelStock)
  6782. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6783. dealer, _ := service.GetDealerById(info.Dealer)
  6784. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6785. cancelStockInfo := models.DrugCancelStockInfo{
  6786. OrderNumber: cancelInfo.OrderNumber,
  6787. CancelStockId: cancelInfo.ID,
  6788. DrugId: info.DrugId,
  6789. Count: info.Count,
  6790. Status: 1,
  6791. Ctime: ctime,
  6792. OrgId: advice.UserOrgId,
  6793. Type: 1,
  6794. Manufacturer: manufactureName.ManufacturerName,
  6795. Dealer: dealer.DealerName,
  6796. Total: 0,
  6797. RetailPrice: info.RetailPrice,
  6798. RetailTotalPrice: info.RetailTotalPrice,
  6799. Price: info.Price,
  6800. RegisterAccount: "",
  6801. Remark: info.Remark,
  6802. BatchNumber: info.BatchNumber,
  6803. MaxUnit: info.CountUnit,
  6804. ProductDate: info.ProductDate,
  6805. ExpiryDate: info.ExpiryDate,
  6806. BatchNumberId: info.WarehouseInfoId,
  6807. }
  6808. flow := models.DrugFlow{
  6809. WarehousingId: 0,
  6810. DrugId: info.DrugId,
  6811. Number: "",
  6812. BatchNumber: info.BatchNumber,
  6813. Count: info.Count,
  6814. UserOrgId: advice.UserOrgId,
  6815. PatientId: 0,
  6816. SystemTime: ctime,
  6817. ConsumableType: 4,
  6818. IsSys: 0,
  6819. WarehousingOrder: "",
  6820. WarehouseOutId: 0,
  6821. WarehouseOutOrderNumber: "",
  6822. IsEdit: 0,
  6823. CancelStockId: cancelStock.ID,
  6824. CancelOrderNumber: cancelStock.OrderNumber,
  6825. Manufacturer: info.Manufacturer,
  6826. Dealer: info.Dealer,
  6827. Creator: advice.UserOrgId,
  6828. UpdateCreator: 0,
  6829. Status: 1,
  6830. Ctime: time.Now().Unix(),
  6831. Mtime: 0,
  6832. Price: info.Price,
  6833. WarehousingDetailId: 0,
  6834. WarehouseOutDetailId: 0,
  6835. CancelOutDetailId: 0,
  6836. ExpireDate: info.ExpiryDate,
  6837. ProductDate: info.ProductDate,
  6838. MaxUnit: info.CountUnit,
  6839. MinUnit: "",
  6840. }
  6841. service.CreatedCancelStock(cancelStockInfo)
  6842. service.CreateDrugFlowOne(flow)
  6843. } else {
  6844. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6845. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6846. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6847. warehouseInfo := models.DrugWarehouseInfo{
  6848. StockMinNumber: prescribingNumber,
  6849. }
  6850. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6851. }
  6852. operation_time := time.Now().Unix()
  6853. creater := advice.AdviceDoctor
  6854. ctime := time.Now().Unix()
  6855. timeStr := time.Now().Format("2006-01-02")
  6856. timeArr := strings.Split(timeStr, "-")
  6857. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6858. total = total + 1
  6859. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6860. cancelStock := models.DrugCancelStock{
  6861. OrderNumber: orderNumber,
  6862. OperaTime: operation_time,
  6863. OrgId: advice.UserOrgId,
  6864. Creater: creater,
  6865. Ctime: ctime,
  6866. Status: 1,
  6867. ReturnTime: advice.AdviceDate,
  6868. Dealer: info.Dealer,
  6869. Manufacturer: info.Manufacturer,
  6870. Type: 1,
  6871. }
  6872. service.AddSigleDrugCancelStock(&cancelStock)
  6873. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6874. dealer, _ := service.GetDealerById(info.Dealer)
  6875. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6876. cancelStockInfo := models.DrugCancelStockInfo{
  6877. OrderNumber: cancelInfo.OrderNumber,
  6878. CancelStockId: cancelInfo.ID,
  6879. DrugId: info.DrugId,
  6880. Count: info.Count,
  6881. Status: 1,
  6882. Ctime: ctime,
  6883. OrgId: advice.UserOrgId,
  6884. Type: 1,
  6885. Manufacturer: manufactureName.ManufacturerName,
  6886. Dealer: dealer.DealerName,
  6887. Total: 0,
  6888. RetailPrice: info.RetailPrice,
  6889. RetailTotalPrice: info.RetailTotalPrice,
  6890. Price: info.Price,
  6891. RegisterAccount: "",
  6892. Remark: info.Remark,
  6893. BatchNumber: info.BatchNumber,
  6894. MaxUnit: info.CountUnit,
  6895. ProductDate: info.ProductDate,
  6896. ExpiryDate: info.ExpiryDate,
  6897. BatchNumberId: info.WarehouseInfoId,
  6898. }
  6899. flow := models.DrugFlow{
  6900. WarehousingId: 0,
  6901. DrugId: info.DrugId,
  6902. Number: "",
  6903. BatchNumber: info.BatchNumber,
  6904. Count: info.Count,
  6905. UserOrgId: advice.UserOrgId,
  6906. PatientId: 0,
  6907. SystemTime: ctime,
  6908. ConsumableType: 4,
  6909. IsSys: 0,
  6910. WarehousingOrder: "",
  6911. WarehouseOutId: 0,
  6912. WarehouseOutOrderNumber: "",
  6913. IsEdit: 0,
  6914. CancelStockId: cancelStock.ID,
  6915. CancelOrderNumber: cancelStock.OrderNumber,
  6916. Manufacturer: info.Manufacturer,
  6917. Dealer: info.Dealer,
  6918. Creator: advice.AdviceDoctor,
  6919. UpdateCreator: 0,
  6920. Status: 1,
  6921. Ctime: time.Now().Unix(),
  6922. Mtime: 0,
  6923. Price: info.Price,
  6924. WarehousingDetailId: 0,
  6925. WarehouseOutDetailId: 0,
  6926. CancelOutDetailId: 0,
  6927. ExpireDate: info.ExpiryDate,
  6928. ProductDate: info.ProductDate,
  6929. MaxUnit: info.CountUnit,
  6930. MinUnit: "",
  6931. }
  6932. service.CreatedCancelStock(cancelStockInfo)
  6933. service.CreateDrugFlowOne(flow)
  6934. }
  6935. }
  6936. }
  6937. return err
  6938. }
  6939. func (this *HisApiController) DeleteNCDS() {
  6940. id, _ := this.GetInt64("id", 0)
  6941. if id > 0 {
  6942. service.DeletePsnNCDSRecordById(id)
  6943. this.ServeSuccessJSON(map[string]interface{}{
  6944. "msg": "删除成功",
  6945. })
  6946. } else {
  6947. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6948. return
  6949. }
  6950. }
  6951. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6952. id, _ := c.GetInt64("id")
  6953. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6954. c.ServeSuccessJSON(map[string]interface{}{
  6955. "advice": advice,
  6956. })
  6957. return
  6958. }
  6959. func (c *HisApiController) GetHisMonthChargePatientList() {
  6960. record_date := c.GetString("record_date")
  6961. start_time := c.GetString("start_time")
  6962. end_time := c.GetString("end_time")
  6963. timeLayout := "2006-01-02"
  6964. loc, _ := time.LoadLocation("Local")
  6965. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6966. if err != nil {
  6967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6968. return
  6969. }
  6970. if err != nil {
  6971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6972. return
  6973. }
  6974. recordDateTime := theTime.Unix()
  6975. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6976. if err != nil {
  6977. }
  6978. startRecordDateTime := startTime.Unix()
  6979. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6980. if err != nil {
  6981. }
  6982. endRecordDateTime := endTime.Unix()
  6983. adminInfo := c.GetAdminUserInfo()
  6984. var tempMonthChargePatients []*service.MonthChargePatients
  6985. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  6986. for _, item := range tempPatients {
  6987. //过滤没有处方的
  6988. if len(item.HisPrescription) == 0 {
  6989. tempMonthChargePatients = append(tempMonthChargePatients, item)
  6990. }
  6991. }
  6992. c.ServeSuccessJSON(map[string]interface{}{
  6993. "list": tempMonthChargePatients,
  6994. })
  6995. }