his_api_controller.go 288KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718
  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. cancelStock := models.CancelStock{
  1655. OrderNumber: orderNumber,
  1656. OperaTime: operation_time,
  1657. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1658. Creater: creater,
  1659. Ctime: time.Now().Unix(),
  1660. Status: 1,
  1661. ReturnTime: item.RecordDate,
  1662. Type: 1,
  1663. }
  1664. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1665. if msgerrkonde == gorm.ErrRecordNotFound {
  1666. service.AddSigleCancelStock(&cancelStock)
  1667. }
  1668. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1669. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1670. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1671. //查询该耗材是否出库
  1672. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1673. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1674. deaerler, _ := service.GetDealerById(info.Dealer)
  1675. if info.ID > 0 {
  1676. cancelStockInfo := models.CancelStockInfo{
  1677. GoodId: item.ProjectId,
  1678. CancelStockId: cancel.ID,
  1679. GoodTypeId: good.GoodTypeId,
  1680. Count: prescribingNumber,
  1681. Price: info.Price,
  1682. Total: 0,
  1683. ProductDate: info.ProductDate,
  1684. ExpiryDate: info.ExpiryDate,
  1685. Ctime: time.Now().Unix(),
  1686. Status: 1,
  1687. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1688. OrderNumber: cancel.OrderNumber,
  1689. Type: 0,
  1690. Dealer: deaerler.DealerName,
  1691. Manufacturer: manufacturer.ManufacturerName,
  1692. Number: info.Number,
  1693. RegisterAccount: "",
  1694. Remark: "",
  1695. WarehouseInfoId: info.WarehouseInfotId,
  1696. PatientId: info.PatientId,
  1697. RecordDate: info.SysRecordTime,
  1698. }
  1699. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1700. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1701. flow := models.VmStockFlow{
  1702. WarehousingId: 0,
  1703. GoodId: item.ProjectId,
  1704. Number: info.Number,
  1705. LicenseNumber: info.LicenseNumber,
  1706. Count: prescribingNumber,
  1707. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1708. PatientId: item.PatientId,
  1709. SystemTime: info.SysRecordTime,
  1710. ConsumableType: 7,
  1711. IsSys: 0,
  1712. WarehousingOrder: "",
  1713. WarehouseOutId: 0,
  1714. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1715. IsEdit: 0,
  1716. CancelStockId: cancel.ID,
  1717. CancelOrderNumber: cancel.OrderNumber,
  1718. Manufacturer: manufacturer.ID,
  1719. Dealer: 0,
  1720. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1721. UpdateCreator: 0,
  1722. Status: 1,
  1723. Ctime: time.Now().Unix(),
  1724. Mtime: 0,
  1725. Price: info.Price,
  1726. WarehousingDetailId: info.WarehouseInfotId,
  1727. WarehouseOutDetailId: 0,
  1728. CancelOutDetailId: cancelInfo.ID,
  1729. ProductDate: info.ProductDate,
  1730. ExpireDate: info.ExpiryDate,
  1731. }
  1732. service.CreateStockFlowOne(flow)
  1733. //删除出库表
  1734. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1735. //查询今日该患者开了多少耗材
  1736. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1737. var total_count int64
  1738. var cha_count int64
  1739. for _, item := range projectList {
  1740. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1741. total_count += count
  1742. }
  1743. //回退库存
  1744. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1745. //查询今日该耗材退库数量
  1746. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1747. var cancel_Count int64
  1748. for _, items := range cancelInfoOne {
  1749. cancel_Count += items.Count
  1750. }
  1751. cha_count = total_count - cancel_Count
  1752. if total_count > cancel_Count {
  1753. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1754. if err == gorm.ErrRecordNotFound {
  1755. //没有记录,则创建出库单
  1756. timeStr := time.Now().Format("2006-01-02")
  1757. timeArr := strings.Split(timeStr, "-")
  1758. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1759. total = total + 1
  1760. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1761. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1762. number = number + total
  1763. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1764. warehouseOut := models.WarehouseOut{
  1765. WarehouseOutOrderNumber: warehousing_out_order,
  1766. OperationTime: time.Now().Unix(),
  1767. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1768. Creater: creater,
  1769. Ctime: time.Now().Unix(),
  1770. Status: 1,
  1771. WarehouseOutTime: info.SysRecordTime,
  1772. Dealer: 0,
  1773. Manufacturer: 0,
  1774. Type: 1,
  1775. IsSys: 1,
  1776. }
  1777. err := service.AddSigleWarehouseOut(&warehouseOut)
  1778. if err != nil {
  1779. utils.TraceLog("创建出库单失败 err = %v", err)
  1780. return
  1781. }
  1782. prepare := &models.DialysisBeforePrepare{
  1783. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1784. PatientId: info.PatientId,
  1785. RecordDate: info.SysRecordTime,
  1786. GoodId: item.ProjectId,
  1787. GoodTypeId: info.GoodTypeId,
  1788. Count: cha_count,
  1789. }
  1790. //出库
  1791. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1792. } else if err == nil {
  1793. prepare := &models.DialysisBeforePrepare{
  1794. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1795. PatientId: info.PatientId,
  1796. RecordDate: info.SysRecordTime,
  1797. GoodId: item.ProjectId,
  1798. GoodTypeId: info.GoodTypeId,
  1799. Count: cha_count,
  1800. }
  1801. //出库
  1802. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. }
  1809. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1810. fmt.Println(err)
  1811. }
  1812. if drugStockConfig.IsOpen == 1 {
  1813. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1814. fmt.Println(err)
  1815. if len(advices) > 0 {
  1816. for _, item := range advices {
  1817. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1818. redis := service.RedisClient()
  1819. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1820. redis.Set(keyFive, "", time.Second)
  1821. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1822. redis.Set(keyOne, "", time.Second)
  1823. redis.Close()
  1824. //查询该药品是否存在出库记录
  1825. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1826. if errcode == gorm.ErrRecordNotFound {
  1827. } else if errcode == nil {
  1828. if item.PrescribingNumberUnit == drug.MinUnit {
  1829. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1830. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1831. //退库
  1832. warehouseInfo := models.DrugWarehouseInfo{
  1833. StockMinNumber: prescribingNumber,
  1834. }
  1835. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1836. adminUserInfo := c.GetAdminUserInfo()
  1837. operation_time := time.Now().Unix()
  1838. creater := adminUserInfo.AdminUser.Id
  1839. ctime := time.Now().Unix()
  1840. timeStr := time.Now().Format("2006-01-02")
  1841. timeArr := strings.Split(timeStr, "-")
  1842. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1843. total = total + 1
  1844. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1845. cancelStock := models.DrugCancelStock{
  1846. OrderNumber: orderNumber,
  1847. OperaTime: operation_time,
  1848. OrgId: adminUserInfo.CurrentOrgId,
  1849. Creater: creater,
  1850. Ctime: ctime,
  1851. Status: 1,
  1852. ReturnTime: item.AdviceDate,
  1853. Dealer: info.Dealer,
  1854. Manufacturer: info.Manufacturer,
  1855. Type: 1,
  1856. }
  1857. service.AddSigleDrugCancelStock(&cancelStock)
  1858. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1859. dealer, _ := service.GetDealerById(info.Dealer)
  1860. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1861. cancelStockInfo := models.DrugCancelStockInfo{
  1862. OrderNumber: cancelInfo.OrderNumber,
  1863. CancelStockId: cancelInfo.ID,
  1864. DrugId: info.DrugId,
  1865. Count: prescribingNumber,
  1866. Status: 1,
  1867. Ctime: ctime,
  1868. OrgId: adminUserInfo.CurrentOrgId,
  1869. Type: 1,
  1870. Manufacturer: manufactureName.ManufacturerName,
  1871. Dealer: dealer.DealerName,
  1872. Total: 0,
  1873. RetailPrice: info.RetailPrice,
  1874. RetailTotalPrice: info.RetailTotalPrice,
  1875. Price: info.Price,
  1876. RegisterAccount: "",
  1877. Remark: info.Remark,
  1878. BatchNumber: info.BatchNumber,
  1879. MaxUnit: info.CountUnit,
  1880. ProductDate: info.ProductDate,
  1881. ExpiryDate: info.ExpiryDate,
  1882. BatchNumberId: info.WarehouseInfoId,
  1883. }
  1884. flow := models.DrugFlow{
  1885. WarehousingId: 0,
  1886. DrugId: info.DrugId,
  1887. Number: "",
  1888. BatchNumber: info.BatchNumber,
  1889. Count: prescribingNumber,
  1890. UserOrgId: adminUserInfo.CurrentOrgId,
  1891. PatientId: 0,
  1892. SystemTime: info.SysRecordTime,
  1893. ConsumableType: 7,
  1894. IsSys: 0,
  1895. WarehousingOrder: "",
  1896. WarehouseOutId: 0,
  1897. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1898. IsEdit: 0,
  1899. CancelStockId: cancelStock.ID,
  1900. CancelOrderNumber: cancelStock.OrderNumber,
  1901. Manufacturer: info.Manufacturer,
  1902. Dealer: info.Dealer,
  1903. Creator: adminUserInfo.AdminUser.Id,
  1904. UpdateCreator: 0,
  1905. Status: 1,
  1906. Ctime: time.Now().Unix(),
  1907. Mtime: 0,
  1908. Price: info.Price,
  1909. WarehousingDetailId: 0,
  1910. WarehouseOutDetailId: 0,
  1911. CancelOutDetailId: 0,
  1912. ExpireDate: info.ExpiryDate,
  1913. ProductDate: info.ProductDate,
  1914. MaxUnit: info.CountUnit,
  1915. MinUnit: "",
  1916. AdviceId: info.AdviceId,
  1917. }
  1918. service.CreatedCancelStock(cancelStockInfo)
  1919. service.CreateDrugFlowOne(flow)
  1920. //删除出库记录
  1921. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1922. //删除流水
  1923. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1924. } else {
  1925. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1926. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1927. if item.PrescribingNumberUnit == drug.MaxUnit {
  1928. warehouseInfo := models.DrugWarehouseInfo{
  1929. StockMaxNumber: prescribingNumber,
  1930. }
  1931. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1932. }
  1933. adminUserInfo := c.GetAdminUserInfo()
  1934. operation_time := time.Now().Unix()
  1935. creater := adminUserInfo.AdminUser.Id
  1936. ctime := time.Now().Unix()
  1937. timeStr := time.Now().Format("2006-01-02")
  1938. timeArr := strings.Split(timeStr, "-")
  1939. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1940. total = total + 1
  1941. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1942. cancelStock := models.DrugCancelStock{
  1943. OrderNumber: orderNumber,
  1944. OperaTime: operation_time,
  1945. OrgId: adminUserInfo.CurrentOrgId,
  1946. Creater: creater,
  1947. Ctime: ctime,
  1948. Status: 1,
  1949. ReturnTime: item.AdviceDate,
  1950. Dealer: info.Dealer,
  1951. Manufacturer: info.Manufacturer,
  1952. Type: 1,
  1953. }
  1954. service.AddSigleDrugCancelStock(&cancelStock)
  1955. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1956. dealer, _ := service.GetDealerById(info.Dealer)
  1957. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1958. cancelStockInfo := models.DrugCancelStockInfo{
  1959. OrderNumber: cancelInfo.OrderNumber,
  1960. CancelStockId: cancelInfo.ID,
  1961. DrugId: info.DrugId,
  1962. // Count: info.Count,
  1963. Count: prescribingNumber,
  1964. Status: 1,
  1965. Ctime: ctime,
  1966. OrgId: adminUserInfo.CurrentOrgId,
  1967. Type: 1,
  1968. Manufacturer: manufactureName.ManufacturerName,
  1969. Dealer: dealer.DealerName,
  1970. Total: 0,
  1971. RetailPrice: info.RetailPrice,
  1972. RetailTotalPrice: info.RetailTotalPrice,
  1973. Price: info.Price,
  1974. RegisterAccount: "",
  1975. Remark: info.Remark,
  1976. BatchNumber: info.BatchNumber,
  1977. MaxUnit: info.CountUnit,
  1978. ProductDate: info.ProductDate,
  1979. ExpiryDate: info.ExpiryDate,
  1980. BatchNumberId: info.WarehouseInfoId,
  1981. }
  1982. flow := models.DrugFlow{
  1983. WarehousingId: 0,
  1984. DrugId: info.DrugId,
  1985. Number: "",
  1986. BatchNumber: info.BatchNumber,
  1987. //Count: info.Count,
  1988. Count: prescribingNumber,
  1989. UserOrgId: adminUserInfo.CurrentOrgId,
  1990. PatientId: 0,
  1991. SystemTime: info.SysRecordTime,
  1992. ConsumableType: 7,
  1993. IsSys: 0,
  1994. WarehousingOrder: "",
  1995. WarehouseOutId: 0,
  1996. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1997. IsEdit: 0,
  1998. CancelStockId: cancelStock.ID,
  1999. CancelOrderNumber: cancelStock.OrderNumber,
  2000. Manufacturer: info.Manufacturer,
  2001. Dealer: info.Dealer,
  2002. Creator: adminUserInfo.AdminUser.Id,
  2003. UpdateCreator: 0,
  2004. Status: 1,
  2005. Ctime: time.Now().Unix(),
  2006. Mtime: 0,
  2007. Price: info.Price,
  2008. WarehousingDetailId: 0,
  2009. WarehouseOutDetailId: 0,
  2010. CancelOutDetailId: 0,
  2011. ExpireDate: info.ExpiryDate,
  2012. ProductDate: info.ProductDate,
  2013. MaxUnit: info.CountUnit,
  2014. MinUnit: "",
  2015. AdviceId: info.AdviceId,
  2016. }
  2017. service.CreatedCancelStock(cancelStockInfo)
  2018. service.CreateDrugFlowOne(flow)
  2019. //删除出库记录
  2020. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2021. //删除流水
  2022. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2023. }
  2024. }
  2025. if item.PrescribingNumberUnit == drug.MinUnit {
  2026. drug.Total = drug.Total + item.PrescribingNumber
  2027. service.UpdateBaseDrugLib(&drug)
  2028. } else {
  2029. if item.PrescribingNumberUnit == drug.MaxUnit {
  2030. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  2031. drug.Total = drug.Total + item.PrescribingNumber
  2032. service.UpdateBaseDrugLib(&drug)
  2033. }
  2034. }
  2035. }
  2036. }
  2037. }
  2038. c.ServeSuccessJSON(map[string]interface{}{
  2039. "msg": "删除成功",
  2040. })
  2041. return
  2042. }
  2043. func (c *HisApiController) DeleteDoctorAdvice() {
  2044. id, _ := c.GetInt64("id")
  2045. advice, _ := service.GetHisDoctorAdvicesById(id)
  2046. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2047. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2048. redis := service.RedisClient()
  2049. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2050. redis.Set(keyFive, "", time.Second)
  2051. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2052. redis.Set(keyOne, "", time.Second)
  2053. defer redis.Close()
  2054. if err == nil {
  2055. if drugStockConfig.IsOpen == 1 {
  2056. //判断该医嘱是否执行了
  2057. if advice.ExecutionState == 1 {
  2058. //查询该病人该药品是否有库存记录
  2059. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  2060. if errcode == gorm.ErrRecordNotFound {
  2061. } else {
  2062. //退库
  2063. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  2064. if advice.PrescribingNumberUnit == drug.MinUnit {
  2065. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2066. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2067. //退库
  2068. warehouseInfo := models.DrugWarehouseInfo{
  2069. StockMinNumber: prescribingNumber,
  2070. }
  2071. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  2072. adminUserInfo := c.GetAdminUserInfo()
  2073. operation_time := time.Now().Unix()
  2074. creater := adminUserInfo.AdminUser.Id
  2075. ctime := time.Now().Unix()
  2076. timeStr := time.Now().Format("2006-01-02")
  2077. timeArr := strings.Split(timeStr, "-")
  2078. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2079. total = total + 1
  2080. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2081. cancelStock := models.DrugCancelStock{
  2082. OrderNumber: orderNumber,
  2083. OperaTime: operation_time,
  2084. OrgId: adminUserInfo.CurrentOrgId,
  2085. Creater: creater,
  2086. Ctime: ctime,
  2087. Status: 1,
  2088. ReturnTime: advice.AdviceDate,
  2089. Dealer: info.Dealer,
  2090. Manufacturer: info.Manufacturer,
  2091. Type: 1,
  2092. }
  2093. service.AddSigleDrugCancelStock(&cancelStock)
  2094. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2095. dealer, _ := service.GetDealerById(info.Dealer)
  2096. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2097. cancelStockInfo := models.DrugCancelStockInfo{
  2098. OrderNumber: cancelInfo.OrderNumber,
  2099. CancelStockId: cancelInfo.ID,
  2100. DrugId: info.DrugId,
  2101. Count: info.Count,
  2102. Status: 1,
  2103. Ctime: ctime,
  2104. OrgId: adminUserInfo.CurrentOrgId,
  2105. Type: 1,
  2106. Manufacturer: manufactureName.ManufacturerName,
  2107. Dealer: dealer.DealerName,
  2108. Total: 0,
  2109. RetailPrice: info.RetailPrice,
  2110. RetailTotalPrice: info.RetailTotalPrice,
  2111. Price: info.Price,
  2112. RegisterAccount: "",
  2113. Remark: info.Remark,
  2114. BatchNumber: info.BatchNumber,
  2115. MaxUnit: info.CountUnit,
  2116. ProductDate: info.ProductDate,
  2117. ExpiryDate: info.ExpiryDate,
  2118. BatchNumberId: info.WarehouseInfoId,
  2119. }
  2120. flow := models.DrugFlow{
  2121. WarehousingId: 0,
  2122. DrugId: info.DrugId,
  2123. Number: "",
  2124. BatchNumber: info.BatchNumber,
  2125. Count: info.Count,
  2126. UserOrgId: adminUserInfo.CurrentOrgId,
  2127. PatientId: 0,
  2128. SystemTime: info.SysRecordTime,
  2129. ConsumableType: 7,
  2130. IsSys: 0,
  2131. WarehousingOrder: "",
  2132. WarehouseOutId: 0,
  2133. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2134. IsEdit: 0,
  2135. CancelStockId: cancelStock.ID,
  2136. CancelOrderNumber: cancelStock.OrderNumber,
  2137. Manufacturer: info.Manufacturer,
  2138. Dealer: info.Dealer,
  2139. Creator: adminUserInfo.AdminUser.Id,
  2140. UpdateCreator: 0,
  2141. Status: 1,
  2142. Ctime: time.Now().Unix(),
  2143. Mtime: 0,
  2144. Price: info.Price,
  2145. WarehousingDetailId: 0,
  2146. WarehouseOutDetailId: 0,
  2147. CancelOutDetailId: 0,
  2148. ExpireDate: info.ExpiryDate,
  2149. ProductDate: info.ProductDate,
  2150. MaxUnit: info.CountUnit,
  2151. MinUnit: "",
  2152. AdviceId: info.AdviceId,
  2153. }
  2154. service.CreatedCancelStock(cancelStockInfo)
  2155. service.CreateDrugFlowOne(flow)
  2156. //删除出库记录
  2157. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2158. //删除流水
  2159. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2160. } else {
  2161. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2162. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2163. if advice.PrescribingNumberUnit == drug.MaxUnit {
  2164. warehouseInfo := models.DrugWarehouseInfo{
  2165. StockMaxNumber: prescribingNumber,
  2166. }
  2167. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2168. }
  2169. adminUserInfo := c.GetAdminUserInfo()
  2170. operation_time := time.Now().Unix()
  2171. creater := adminUserInfo.AdminUser.Id
  2172. ctime := time.Now().Unix()
  2173. timeStr := time.Now().Format("2006-01-02")
  2174. timeArr := strings.Split(timeStr, "-")
  2175. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2176. total = total + 1
  2177. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2178. cancelStock := models.DrugCancelStock{
  2179. OrderNumber: orderNumber,
  2180. OperaTime: operation_time,
  2181. OrgId: adminUserInfo.CurrentOrgId,
  2182. Creater: creater,
  2183. Ctime: ctime,
  2184. Status: 1,
  2185. ReturnTime: advice.AdviceDate,
  2186. Dealer: info.Dealer,
  2187. Manufacturer: info.Manufacturer,
  2188. Type: 1,
  2189. }
  2190. service.AddSigleDrugCancelStock(&cancelStock)
  2191. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2192. dealer, _ := service.GetDealerById(info.Dealer)
  2193. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2194. cancelStockInfo := models.DrugCancelStockInfo{
  2195. OrderNumber: cancelInfo.OrderNumber,
  2196. CancelStockId: cancelInfo.ID,
  2197. DrugId: info.DrugId,
  2198. Count: info.Count,
  2199. Status: 1,
  2200. Ctime: ctime,
  2201. OrgId: adminUserInfo.CurrentOrgId,
  2202. Type: 1,
  2203. Manufacturer: manufactureName.ManufacturerName,
  2204. Dealer: dealer.DealerName,
  2205. Total: 0,
  2206. RetailPrice: info.RetailPrice,
  2207. RetailTotalPrice: info.RetailTotalPrice,
  2208. Price: info.Price,
  2209. RegisterAccount: "",
  2210. Remark: info.Remark,
  2211. BatchNumber: info.BatchNumber,
  2212. MaxUnit: info.CountUnit,
  2213. ProductDate: info.ProductDate,
  2214. ExpiryDate: info.ExpiryDate,
  2215. BatchNumberId: info.WarehouseInfoId,
  2216. }
  2217. flow := models.DrugFlow{
  2218. WarehousingId: 0,
  2219. DrugId: info.DrugId,
  2220. Number: "",
  2221. BatchNumber: info.BatchNumber,
  2222. Count: info.Count,
  2223. UserOrgId: adminUserInfo.CurrentOrgId,
  2224. PatientId: 0,
  2225. SystemTime: info.SysRecordTime,
  2226. ConsumableType: 7,
  2227. IsSys: 0,
  2228. WarehousingOrder: "",
  2229. WarehouseOutId: 0,
  2230. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2231. IsEdit: 0,
  2232. CancelStockId: cancelStock.ID,
  2233. CancelOrderNumber: cancelStock.OrderNumber,
  2234. Manufacturer: info.Manufacturer,
  2235. Dealer: info.Dealer,
  2236. Creator: adminUserInfo.AdminUser.Id,
  2237. UpdateCreator: 0,
  2238. Status: 1,
  2239. Ctime: time.Now().Unix(),
  2240. Mtime: 0,
  2241. Price: info.Price,
  2242. WarehousingDetailId: 0,
  2243. WarehouseOutDetailId: 0,
  2244. CancelOutDetailId: 0,
  2245. ExpireDate: info.ExpiryDate,
  2246. ProductDate: info.ProductDate,
  2247. MaxUnit: info.CountUnit,
  2248. MinUnit: "",
  2249. AdviceId: info.AdviceId,
  2250. }
  2251. service.CreatedCancelStock(cancelStockInfo)
  2252. service.CreateDrugFlowOne(flow)
  2253. //删除出库记录
  2254. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2255. //删除流水
  2256. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2257. }
  2258. }
  2259. }
  2260. }
  2261. c.ServeSuccessJSON(map[string]interface{}{
  2262. "msg": "删除成功",
  2263. })
  2264. return
  2265. } else {
  2266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2267. return
  2268. }
  2269. }
  2270. func (c *HisApiController) DeleteProject() {
  2271. id, _ := c.GetInt64("id")
  2272. adminInfo := c.GetAdminUserInfo()
  2273. project, _ := service.GetHisProjectByID(id)
  2274. // var consumable models.DialysisBeforePrepare
  2275. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2276. service.DeletePrintInfo(id)
  2277. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2278. label.Status = 0
  2279. service.CreateHisLabelRecord(&label)
  2280. if stockConfig.IsOpen == 1 {
  2281. if project.Type == 2 {
  2282. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2283. fmt.Println(err)
  2284. }
  2285. if project.Type == 3 {
  2286. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2287. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2288. good.Total = good.Total + f_count
  2289. service.UpdateGoodInfo(&good)
  2290. operation_time := time.Now().Unix()
  2291. creater := adminInfo.AdminUser.Id
  2292. //创建退库单
  2293. timeStr := time.Now().Format("2006-01-02")
  2294. timeArr := strings.Split(timeStr, "-")
  2295. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2296. total = total + 1
  2297. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2298. cancelStock := models.CancelStock{
  2299. OrderNumber: orderNumber,
  2300. OperaTime: operation_time,
  2301. OrgId: adminInfo.CurrentOrgId,
  2302. Creater: creater,
  2303. Ctime: time.Now().Unix(),
  2304. Status: 1,
  2305. ReturnTime: project.RecordDate,
  2306. Type: 1,
  2307. }
  2308. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2309. if msgerrkonde == gorm.ErrRecordNotFound {
  2310. service.AddSigleCancelStock(&cancelStock)
  2311. }
  2312. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2313. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2314. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2315. //获取该耗材有库存的第一条数据
  2316. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2317. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2318. deaerler, _ := service.GetDealerById(info.Dealer)
  2319. if info.ID > 0 {
  2320. cancelStockInfo := models.CancelStockInfo{
  2321. GoodId: project.ProjectId,
  2322. CancelStockId: cancel.ID,
  2323. GoodTypeId: good.GoodTypeId,
  2324. Count: prescribingNumber,
  2325. Price: info.Price,
  2326. Total: 0,
  2327. ProductDate: info.ProductDate,
  2328. ExpiryDate: info.ExpiryDate,
  2329. Ctime: time.Now().Unix(),
  2330. Status: 1,
  2331. OrgId: adminInfo.CurrentOrgId,
  2332. OrderNumber: cancel.OrderNumber,
  2333. Type: 0,
  2334. Dealer: deaerler.DealerName,
  2335. Manufacturer: manufacturer.ManufacturerName,
  2336. Number: info.Number,
  2337. RegisterAccount: "",
  2338. Remark: "",
  2339. WarehouseInfoId: info.WarehouseInfotId,
  2340. PatientId: info.PatientId,
  2341. RecordDate: info.SysRecordTime,
  2342. }
  2343. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2344. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2345. flow := models.VmStockFlow{
  2346. WarehousingId: 0,
  2347. GoodId: project.ProjectId,
  2348. Number: info.Number,
  2349. LicenseNumber: info.LicenseNumber,
  2350. Count: prescribingNumber,
  2351. UserOrgId: adminInfo.CurrentOrgId,
  2352. PatientId: project.PatientId,
  2353. SystemTime: time.Now().Unix(),
  2354. ConsumableType: 7,
  2355. IsSys: 0,
  2356. WarehousingOrder: "",
  2357. WarehouseOutId: 0,
  2358. WarehouseOutOrderNumber: "",
  2359. IsEdit: 0,
  2360. CancelStockId: cancel.ID,
  2361. CancelOrderNumber: cancel.OrderNumber,
  2362. Manufacturer: manufacturer.ID,
  2363. Dealer: 0,
  2364. Creator: adminInfo.AdminUser.Id,
  2365. UpdateCreator: 0,
  2366. Status: 1,
  2367. Ctime: time.Now().Unix(),
  2368. Mtime: 0,
  2369. Price: info.Price,
  2370. WarehousingDetailId: info.WarehouseInfotId,
  2371. WarehouseOutDetailId: 0,
  2372. CancelOutDetailId: cancelInfo.ID,
  2373. ProductDate: info.ProductDate,
  2374. ExpireDate: info.ExpiryDate,
  2375. }
  2376. service.CreateStockFlowOne(flow)
  2377. //删除出库表
  2378. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2379. //查询今日该患者开了多少耗材
  2380. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2381. var total_count int64
  2382. var cha_count int64
  2383. for _, item := range projectList {
  2384. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2385. total_count += count
  2386. }
  2387. //回退库存
  2388. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2389. //查询今日该耗材退库数量
  2390. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2391. var cancel_count int64
  2392. for _, items := range cancelInfoOne {
  2393. cancel_count += items.Count
  2394. }
  2395. cha_count = total_count - cancel_count
  2396. if total_count > cancel_count {
  2397. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2398. if err == gorm.ErrRecordNotFound {
  2399. //没有记录,则创建出库单
  2400. timeStr := time.Now().Format("2006-01-02")
  2401. timeArr := strings.Split(timeStr, "-")
  2402. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2403. total = total + 1
  2404. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2405. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2406. number = number + total
  2407. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2408. warehouseOut := models.WarehouseOut{
  2409. WarehouseOutOrderNumber: warehousing_out_order,
  2410. OperationTime: time.Now().Unix(),
  2411. OrgId: adminInfo.CurrentOrgId,
  2412. Creater: creater,
  2413. Ctime: time.Now().Unix(),
  2414. Status: 1,
  2415. WarehouseOutTime: info.SysRecordTime,
  2416. Dealer: 0,
  2417. Manufacturer: 0,
  2418. Type: 1,
  2419. IsSys: 1,
  2420. }
  2421. err := service.AddSigleWarehouseOut(&warehouseOut)
  2422. if err != nil {
  2423. utils.TraceLog("创建出库单失败 err = %v", err)
  2424. return
  2425. }
  2426. prepare := &models.DialysisBeforePrepare{
  2427. UserOrgId: adminInfo.CurrentOrgId,
  2428. PatientId: info.PatientId,
  2429. RecordDate: info.SysRecordTime,
  2430. GoodId: project.ProjectId,
  2431. GoodTypeId: info.GoodTypeId,
  2432. Count: cha_count,
  2433. }
  2434. //出库
  2435. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2436. } else if err == nil {
  2437. prepare := &models.DialysisBeforePrepare{
  2438. UserOrgId: adminInfo.CurrentOrgId,
  2439. PatientId: info.PatientId,
  2440. RecordDate: info.SysRecordTime,
  2441. GoodId: project.ProjectId,
  2442. GoodTypeId: info.GoodTypeId,
  2443. Count: cha_count,
  2444. }
  2445. //出库
  2446. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2447. }
  2448. }
  2449. }
  2450. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2451. fmt.Println(err)
  2452. }
  2453. }
  2454. c.ServeSuccessJSON(map[string]interface{}{
  2455. "msg": "删除成功",
  2456. })
  2457. return
  2458. }
  2459. func (c *HisApiController) CreateHisAdditionalCharge() {
  2460. his_patient_id, _ := c.GetInt64("his_patient_id")
  2461. patient_id, _ := c.GetInt64("patient_id")
  2462. record_date := c.GetString("record_date")
  2463. timeLayout := "2006-01-02"
  2464. loc, _ := time.LoadLocation("Local")
  2465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2466. if err != nil {
  2467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2468. return
  2469. }
  2470. adminInfo := c.GetAdminUserInfo()
  2471. recordDateTime := theTime.Unix()
  2472. dataBody := make(map[string]interface{}, 0)
  2473. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2474. if err != nil {
  2475. utils.ErrorLog(err.Error())
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. var additions []*models.HisAdditionalCharge
  2480. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2481. additions, _ := dataBody["addition"].([]interface{})
  2482. if len(additions) > 0 {
  2483. for _, item := range additions {
  2484. items := item.(map[string]interface{})
  2485. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2486. utils.ErrorLog("item_id")
  2487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2488. return
  2489. }
  2490. item_id := int64(items["item_id"].(float64))
  2491. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2492. utils.ErrorLog("item_name")
  2493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2494. return
  2495. }
  2496. item_name := items["item_name"].(string)
  2497. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2498. utils.ErrorLog("price")
  2499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2500. return
  2501. }
  2502. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2503. ctime := time.Now().Unix()
  2504. additional := &models.HisAdditionalCharge{
  2505. PatientId: patient_id,
  2506. HisPatientId: his_patient_id,
  2507. UserOrgId: adminInfo.CurrentOrgId,
  2508. RecordDate: recordDateTime,
  2509. CreatedTime: ctime,
  2510. UpdatedTime: ctime,
  2511. Modifier: adminInfo.AdminUser.Id,
  2512. Creator: adminInfo.AdminUser.Id,
  2513. Price: price,
  2514. ItemName: item_name,
  2515. ItemId: item_id,
  2516. Status: 1,
  2517. }
  2518. additions = append(additions, additional)
  2519. }
  2520. }
  2521. }
  2522. for _, item := range additions {
  2523. service.CreateAddtionalCharge(item)
  2524. }
  2525. c.ServeSuccessJSON(map[string]interface{}{
  2526. "msg": "创建成功",
  2527. })
  2528. }
  2529. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2530. blood_fat := c.GetString("blood_fat")
  2531. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2532. blood_sugar := c.GetString("blood_sugar")
  2533. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2534. chief_conplaint := c.GetString("chief_conplaint")
  2535. dbp := c.GetString("dbp")
  2536. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2537. delivery_way, _ := c.GetInt64("delivery_way")
  2538. diagnostic := c.GetString("diagnostic")
  2539. family_history := c.GetString("family_history")
  2540. height := c.GetString("height")
  2541. history_of_present_illness := c.GetString("history_of_present_illness")
  2542. is_infect, _ := c.GetInt64("is_infect")
  2543. past_history := c.GetString("past_history")
  2544. patient_id, _ := c.GetInt64("patient_id")
  2545. his_patient_id, _ := c.GetInt64("his_patient_id")
  2546. personal_history := c.GetString("personal_history")
  2547. pulse := c.GetString("pulse")
  2548. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2549. sbp := c.GetString("sbp")
  2550. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2551. heightfloat, _ := strconv.ParseFloat(height, 64)
  2552. sicktype := c.GetString("sick_type")
  2553. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2554. symptom := c.GetString("symptom")
  2555. sick_date := c.GetString("sick_date")
  2556. temperatures := c.GetString("temperature")
  2557. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2558. record_date := c.GetString("record_date")
  2559. breathing := c.GetString("breathing")
  2560. doctor_advice := c.GetString("doctor_advice")
  2561. remark := c.GetString("remark")
  2562. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2563. sick, _ := c.GetInt64("sick")
  2564. diagnose, _ := c.GetInt64("diagnose")
  2565. //id, _ := c.GetInt64("id")
  2566. timeLayout := "2006-01-02"
  2567. loc, _ := time.LoadLocation("Local")
  2568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2569. allergic_history := c.GetString("allergic_history")
  2570. if err != nil {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2572. return
  2573. }
  2574. recordDateTime := theTime.Unix()
  2575. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2576. if err != nil {
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2578. return
  2579. }
  2580. sickTimes := sickTime.Unix()
  2581. ctime := time.Now().Unix()
  2582. primary_disease := c.GetString("primary_disease")
  2583. confirm_failure_date := c.GetString("confirm_failure_date")
  2584. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  2585. drug_allergy_history := c.GetString("drug_allergy_history")
  2586. physical_examination := c.GetString("physical_examination")
  2587. special_inspection := c.GetString("special_inspection")
  2588. lab_apparatus := c.GetString("lab_apparatus")
  2589. caseHistory := models.HisPatientCaseHistory{
  2590. HisPatientId: his_patient_id,
  2591. PatientId: patient_id,
  2592. Temperature: temperature,
  2593. BloodSugar: bloodsugarfloat,
  2594. Pulse: pulsefloat,
  2595. Sbp: sbpfloat,
  2596. Dbp: dbpfloat,
  2597. Height: heightfloat,
  2598. BloodFat: bloodfatfloat,
  2599. SickType: sick_type,
  2600. Symptom: symptom,
  2601. SickDate: sickTimes,
  2602. IsInfect: is_infect,
  2603. HistoryOfPresentIllness: history_of_present_illness,
  2604. PastHistory: past_history,
  2605. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2606. ChiefConplaint: chief_conplaint,
  2607. PersonalHistory: personal_history,
  2608. FamilyHistory: family_history,
  2609. Diagnostic: diagnostic,
  2610. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2611. Status: 1,
  2612. Ctime: ctime,
  2613. Mtime: ctime,
  2614. RecordDate: recordDateTime,
  2615. DeliveryWay: delivery_way,
  2616. Breathing: breathingfloat,
  2617. DoctorAdvice: doctor_advice,
  2618. Remark: remark,
  2619. Sick: sick,
  2620. Diagnose: diagnose,
  2621. AllergicHistory: allergic_history,
  2622. PrimaryDisease: primary_disease,
  2623. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  2624. DrugAllergyHistory: drug_allergy_history,
  2625. PhysicalExamination: physical_examination,
  2626. SpecialInspection: special_inspection,
  2627. LabApparatus: lab_apparatus,
  2628. }
  2629. //查询该患者是否有病历
  2630. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  2631. if errcodes == gorm.ErrRecordNotFound {
  2632. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2633. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2634. if err != nil {
  2635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2636. return
  2637. }
  2638. c.ServeSuccessJSON(map[string]interface{}{
  2639. "caseHistory": caseHistory,
  2640. "historyInfo": historyInfo,
  2641. })
  2642. return
  2643. } else if errcodes == nil {
  2644. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  2645. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2646. if err != nil {
  2647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2648. return
  2649. }
  2650. c.ServeSuccessJSON(map[string]interface{}{
  2651. "caseHistory": caseHistory,
  2652. "historyInfo": historyInfo,
  2653. })
  2654. }
  2655. //查询该患者是否有病历
  2656. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2657. //if errcode == gorm.ErrRecordNotFound {
  2658. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2659. // if err != nil {
  2660. // c.ServeSuccessJSON(map[string]interface{}{
  2661. // "msg": "保存成功",
  2662. // })
  2663. // }
  2664. //} else if errcode == nil {
  2665. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2666. // return
  2667. //}
  2668. }
  2669. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2670. patient_id, _ := c.GetInt64("patient_id", 0)
  2671. adminUser := c.GetAdminUserInfo()
  2672. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2673. c.ServeSuccessJSON(map[string]interface{}{
  2674. "list": caseHistorys,
  2675. })
  2676. }
  2677. func (c *HisApiController) GetHisPatientCaseHistory() {
  2678. record_date, _ := c.GetInt64("record_date", 0)
  2679. patient_id, _ := c.GetInt64("patient_id", 0)
  2680. admin := c.GetAdminUserInfo()
  2681. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2682. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2683. c.ServeSuccessJSON(map[string]interface{}{
  2684. "info": info,
  2685. "case_history": case_history,
  2686. })
  2687. }
  2688. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2689. template_name := c.GetString("template_name")
  2690. template_remark := c.GetString("template_remark")
  2691. doctor := c.GetAdminUserInfo().AdminUser.Id
  2692. diagnostic := c.GetString("diagnostic")
  2693. chief_conplaint := c.GetString("chief_conplain")
  2694. history_of_present_illness := c.GetString("history_of_present_illness")
  2695. past_history := c.GetString("past_history")
  2696. personal_history := c.GetString("personal_history")
  2697. family_history := c.GetString("family_history")
  2698. user_name := c.GetString("user_name")
  2699. doctor_advice := c.GetString("doctor_advice")
  2700. remark := c.GetString("remark")
  2701. //record_date := c.GetString("record_date")
  2702. //fmt.Println("record_date--------",record_date)
  2703. //timeLayout := "2006-01-02"
  2704. //loc, _ := time.LoadLocation("Local")
  2705. //
  2706. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2707. //if err != nil {
  2708. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2709. // return
  2710. //}
  2711. //recordDateTime := theTime.Unix()
  2712. ctime := time.Now().Unix()
  2713. template := models.HisCaseHistoryTemplate{
  2714. HistoryOfPresentIllness: history_of_present_illness,
  2715. PastHistory: past_history,
  2716. ChiefConplaint: chief_conplaint,
  2717. PersonalHistory: personal_history,
  2718. FamilyHistory: family_history,
  2719. Diagnostic: diagnostic,
  2720. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2721. Status: 1,
  2722. Ctime: ctime,
  2723. Mtime: ctime,
  2724. RecordDate: time.Now().Unix(),
  2725. TemplateName: template_name,
  2726. TemplateRemark: template_remark,
  2727. Creator: doctor,
  2728. Modifier: doctor,
  2729. UserName: user_name,
  2730. DoctorAdvice: doctor_advice,
  2731. Remark: remark,
  2732. }
  2733. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2734. if err == nil {
  2735. c.ServeSuccessJSON(map[string]interface{}{
  2736. "msg": "保存成功",
  2737. })
  2738. } else {
  2739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2740. return
  2741. }
  2742. }
  2743. func (c *HisApiController) GetCaseHistoryTemplate() {
  2744. timeLayout := "2006-01-02"
  2745. loc, _ := time.LoadLocation("Local")
  2746. keyword := c.GetString("keyword")
  2747. start_time := c.GetString("start_time")
  2748. end_time := c.GetString("end_time")
  2749. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2750. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2751. admin := c.GetAdminUserInfo()
  2752. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2753. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2754. c.ServeSuccessJSON(map[string]interface{}{
  2755. "template": template,
  2756. //"history": history,
  2757. })
  2758. }
  2759. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2760. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2761. utils.ErrorLog("drug_name")
  2762. return enums.ErrorCodeParamWrong
  2763. }
  2764. adviceName, _ := json["drug_name"].(string)
  2765. if len(adviceName) == 0 {
  2766. utils.ErrorLog("len(advice_name) == 0")
  2767. return enums.ErrorCodeParamWrong
  2768. }
  2769. advice.AdviceName = adviceName
  2770. adviceDesc, _ := json["advice_desc"].(string)
  2771. advice.AdviceDesc = adviceDesc
  2772. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2773. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2774. advice.DrugSpec = drugSpec
  2775. }
  2776. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2777. remark, _ := json["remark"].(string)
  2778. advice.Remark = remark
  2779. }
  2780. if json["id"] == nil {
  2781. advice.DrugId = 0
  2782. } else {
  2783. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2784. drug_id := int64(json["id"].(float64))
  2785. advice.DrugId = drug_id
  2786. }
  2787. }
  2788. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2789. advice_id := int64(json["advice_id"].(float64))
  2790. advice.ID = advice_id
  2791. if advice.ID > 0 {
  2792. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2793. if err == nil {
  2794. if hisAdvice.ID > 0 {
  2795. advice.ExecutionTime = hisAdvice.ExecutionTime
  2796. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2797. advice.ExecutionState = hisAdvice.ExecutionState
  2798. advice.CheckTime = hisAdvice.CheckTime
  2799. advice.Checker = hisAdvice.Checker
  2800. advice.CheckState = hisAdvice.CheckState
  2801. advice.StartTime = hisAdvice.StartTime
  2802. advice.FeedetlSn = hisAdvice.FeedetlSn
  2803. }
  2804. }
  2805. }
  2806. }
  2807. //
  2808. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2809. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2810. // advice.ExecutionTime = execution_time
  2811. //}
  2812. //
  2813. //
  2814. //
  2815. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2816. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2817. // advice.ExecutionStaff = execution_staff
  2818. //}
  2819. //
  2820. //
  2821. //
  2822. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2823. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2824. // advice.ExecutionState = execution_state
  2825. //}
  2826. //
  2827. //
  2828. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2829. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2830. // advice.CheckTime = check_time
  2831. //}
  2832. //
  2833. //
  2834. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2835. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2836. // advice.CheckState = check_state
  2837. //}
  2838. //
  2839. //
  2840. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2841. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2842. // advice.Checker = checker
  2843. //}
  2844. //
  2845. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2846. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2847. // advice.StartTime = start_time
  2848. //}
  2849. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2850. drugSpecUnit, _ := json["min_unit"].(string)
  2851. advice.DrugSpecUnit = drugSpecUnit
  2852. }
  2853. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2854. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2855. advice.SingleDose = singleDose
  2856. }
  2857. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2858. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2859. advice.SingleDoseUnit = singleDoseUnit
  2860. }
  2861. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2862. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2863. advice.PrescribingNumber = prescribingNumber
  2864. }
  2865. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2866. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2867. advice.PrescribingNumberUnit = prescribingNumberUnit
  2868. }
  2869. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2870. deliveryWay, _ := json["delivery_way"].(string)
  2871. advice.DeliveryWay = deliveryWay
  2872. }
  2873. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2874. executionFrequency, _ := json["execution_frequency"].(string)
  2875. advice.ExecutionFrequency = executionFrequency
  2876. }
  2877. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2878. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2879. advice.Price = price
  2880. }
  2881. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2882. med_list_codg, _ := json["medical_insurance_number"].(string)
  2883. advice.MedListCodg = med_list_codg
  2884. }
  2885. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2886. day := int64(json["day"].(float64))
  2887. advice.Day = day
  2888. }
  2889. return 0
  2890. }
  2891. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2892. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2893. id := int64(json["id"].(float64))
  2894. project.ID = id
  2895. historyProject, _ := service.GetHisProjectByID(id)
  2896. project.FeedetlSn = historyProject.FeedetlSn
  2897. }
  2898. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2899. project_id := int64(json["project_id"].(float64))
  2900. project.ProjectId = project_id
  2901. }
  2902. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2903. // price := int64(json["price"].(float64))
  2904. // formatInt_price := strconv.FormatInt(price, 10)
  2905. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2906. // project.Price = float_price
  2907. // }
  2908. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2909. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2910. project.Price = price
  2911. }
  2912. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2913. total, _ := json["total"].(string)
  2914. project.Count = total
  2915. }
  2916. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2917. medical_code, _ := json["medical_code"].(string)
  2918. project.MedListCodg = medical_code
  2919. }
  2920. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2921. single_dose, _ := json["single_dose"].(string)
  2922. project.SingleDose = single_dose
  2923. }
  2924. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2925. delivery_way, _ := json["delivery_way"].(string)
  2926. project.DeliveryWay = delivery_way
  2927. }
  2928. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2929. execution_frequency, _ := json["execution_frequency"].(string)
  2930. project.ExecutionFrequency = execution_frequency
  2931. }
  2932. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2933. remark, _ := json["remark"].(string)
  2934. project.Remark = remark
  2935. }
  2936. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2937. day, _ := json["number_days"].(string)
  2938. project.Day = day
  2939. }
  2940. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2941. unit, _ := json["unit"].(string)
  2942. project.Unit = unit
  2943. }
  2944. return 0
  2945. }
  2946. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2947. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2948. id := int64(json["id"].(float64))
  2949. historyAddtions, _ := service.GetHisAdditionByID(id)
  2950. additionalCharge.ID = id
  2951. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2952. }
  2953. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2954. item_id := int64(json["item_id"].(float64))
  2955. additionalCharge.ItemId = item_id
  2956. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2957. if config.ID > 0 {
  2958. if len(config.Code) > 0 {
  2959. additionalCharge.MedListCodg = config.Code
  2960. }
  2961. }
  2962. }
  2963. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2964. // price := int64(json["price"].(float64))
  2965. // formatInt_price := strconv.FormatInt(price, 10)
  2966. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2967. // additionalCharge.Price = float_price
  2968. // }
  2969. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2970. // price := int64(json["price"].(float64))
  2971. // formatInt_price := strconv.FormatInt(price, 10)
  2972. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2973. // additionalCharge.Price = float_price
  2974. //}
  2975. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2976. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2977. additionalCharge.Price = price
  2978. }
  2979. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  2980. count, _ := json["count"].(string)
  2981. counts, _ := strconv.ParseInt(count, 10, 64)
  2982. additionalCharge.Count = counts
  2983. }
  2984. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  2985. item_name, _ := json["item_name"].(string)
  2986. additionalCharge.ItemName = item_name
  2987. }
  2988. return 0
  2989. }
  2990. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2991. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2992. utils.ErrorLog("drug_name")
  2993. return enums.ErrorCodeParamWrong
  2994. }
  2995. adviceName, _ := json["drug_name"].(string)
  2996. if len(adviceName) == 0 {
  2997. utils.ErrorLog("len(advice_name) == 0")
  2998. return enums.ErrorCodeParamWrong
  2999. }
  3000. advice.AdviceName = adviceName
  3001. adviceDesc, _ := json["advice_desc"].(string)
  3002. advice.AdviceDesc = adviceDesc
  3003. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3004. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3005. advice.DrugSpec = drugSpec
  3006. }
  3007. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3008. remark, _ := json["remark"].(string)
  3009. advice.Remark = remark
  3010. }
  3011. if json["id"] == nil {
  3012. advice.DrugId = 0
  3013. } else {
  3014. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3015. drug_id := int64(json["id"].(float64))
  3016. advice.DrugId = drug_id
  3017. }
  3018. }
  3019. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3020. groupno := int64(json["groupno"].(float64))
  3021. advice.Groupno = groupno
  3022. }
  3023. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3024. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3025. advice.HospApprFlag = hosp_appr_flag
  3026. }
  3027. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3028. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3029. advice.PrescribingNumber = prescribingNumber
  3030. }
  3031. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3032. // frequency_type := int64(json["frequency_type"].(float64))
  3033. // advice.FrequencyType = frequency_type
  3034. //}
  3035. //
  3036. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3037. // day_count := int64(json["day_count"].(float64))
  3038. // advice.DayCount = day_count
  3039. //}
  3040. //
  3041. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3042. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3043. // week_day, _ := json["week_day"].(string)
  3044. // advice.WeekDay = week_day
  3045. //}
  3046. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3047. drugSpecUnit, _ := json["min_unit"].(string)
  3048. advice.DrugSpecUnit = drugSpecUnit
  3049. }
  3050. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3051. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3052. advice.SingleDose = singleDose
  3053. }
  3054. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3055. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3056. advice.SingleDoseUnit = singleDoseUnit
  3057. }
  3058. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3059. deliveryWay, _ := json["delivery_way"].(string)
  3060. advice.DeliveryWay = deliveryWay
  3061. }
  3062. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3063. executionFrequency, _ := json["execution_frequency"].(string)
  3064. advice.ExecutionFrequency = executionFrequency
  3065. }
  3066. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3067. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3068. advice.Price = price
  3069. }
  3070. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3071. med_list_codg, _ := json["medical_insurance_number"].(string)
  3072. advice.MedListCodg = med_list_codg
  3073. }
  3074. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3075. day := int64(json["day"].(float64))
  3076. advice.Day = day
  3077. }
  3078. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3079. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3080. advice.PrescribingNumberUnit = prescribingNumberUnit
  3081. }
  3082. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3083. advice_id := int64(json["advice_id"].(float64))
  3084. advice.ID = advice_id
  3085. if advice.ID > 0 {
  3086. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3087. if err == nil {
  3088. if hisAdvice.ID > 0 {
  3089. advice.ExecutionTime = hisAdvice.ExecutionTime
  3090. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3091. advice.ExecutionState = hisAdvice.ExecutionState
  3092. advice.CheckTime = hisAdvice.CheckTime
  3093. advice.Checker = hisAdvice.Checker
  3094. advice.CheckState = hisAdvice.CheckState
  3095. advice.StartTime = hisAdvice.StartTime
  3096. advice.HospApprFlag = hisAdvice.HospApprFlag
  3097. if hisAdvice.UserOrgId == 10028 {
  3098. 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 {
  3099. advice.ExecutionTime = 0
  3100. advice.ExecutionStaff = 0
  3101. advice.ExecutionState = 2
  3102. advice.CheckTime = 0
  3103. advice.Checker = 0
  3104. advice.CheckState = 2
  3105. }
  3106. } else {
  3107. 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 {
  3108. advice.ExecutionTime = 0
  3109. advice.ExecutionStaff = 0
  3110. advice.ExecutionState = 2
  3111. advice.CheckTime = 0
  3112. advice.Checker = 0
  3113. advice.CheckState = 2
  3114. }
  3115. }
  3116. //advice.Groupno = hisAdvice.Groupno
  3117. }
  3118. }
  3119. }
  3120. }
  3121. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3122. //
  3123. //if drugStockConfig.IsOpen == 1 {
  3124. //
  3125. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3126. // if advice.ID == 0 { //医嘱不存在
  3127. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3128. // drug.Total = drug.Total - advice.PrescribingNumber
  3129. // service.UpdateBaseDrugLib(&drug)
  3130. //
  3131. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3132. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3133. // drug.Total = drug.Total - num
  3134. // service.UpdateBaseDrugLib(&drug)
  3135. // }
  3136. //
  3137. // } else if advice.ID > 0 { //医嘱存在
  3138. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3139. // var num float64
  3140. //
  3141. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3142. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3143. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3144. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3145. // drug.Total = drug.Total + num
  3146. // service.UpdateBaseDrugLib(&drug)
  3147. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3148. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3149. // drug.Total = drug.Total - num
  3150. // service.UpdateBaseDrugLib(&drug)
  3151. // }
  3152. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3153. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3154. // if num2 > advice.PrescribingNumber {
  3155. // num = num2 - advice.PrescribingNumber
  3156. // drug.Total = drug.Total + num
  3157. // service.UpdateBaseDrugLib(&drug)
  3158. // } else if num2 < advice.PrescribingNumber {
  3159. // num = advice.PrescribingNumber - num2
  3160. // drug.Total = drug.Total - num
  3161. // service.UpdateBaseDrugLib(&drug)
  3162. // }
  3163. //
  3164. // }
  3165. //
  3166. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3167. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3168. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3169. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3170. // if num1 > num2 {
  3171. // num = num1 - num2
  3172. // drug.Total = drug.Total + num
  3173. // service.UpdateBaseDrugLib(&drug)
  3174. // } else if num1 < num2 {
  3175. // num = num2 - num1
  3176. // drug.Total = drug.Total - num
  3177. // service.UpdateBaseDrugLib(&drug)
  3178. // }
  3179. //
  3180. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3181. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3182. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3183. // if hisAdvice.PrescribingNumber > num2 {
  3184. // num = hisAdvice.PrescribingNumber - num2
  3185. // drug.Total = drug.Total + num
  3186. // service.UpdateBaseDrugLib(&drug)
  3187. // } else if num2 < advice.PrescribingNumber {
  3188. // num = num2 - hisAdvice.PrescribingNumber
  3189. // drug.Total = drug.Total - num
  3190. // service.UpdateBaseDrugLib(&drug)
  3191. // }
  3192. //
  3193. // }
  3194. // }
  3195. // }
  3196. //}
  3197. //
  3198. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3199. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3200. // advice.ExecutionTime = execution_time
  3201. //}
  3202. //
  3203. //
  3204. //
  3205. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3206. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3207. // advice.ExecutionStaff = execution_staff
  3208. //}
  3209. //
  3210. //
  3211. //
  3212. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3213. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3214. // advice.ExecutionState = execution_state
  3215. //}
  3216. //
  3217. //
  3218. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3219. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3220. // advice.CheckTime = check_time
  3221. //}
  3222. //
  3223. //
  3224. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3225. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3226. // advice.CheckState = check_state
  3227. //}
  3228. //
  3229. //
  3230. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3231. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3232. // advice.Checker = checker
  3233. //}
  3234. //
  3235. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3236. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3237. // advice.StartTime = start_time
  3238. //}
  3239. return 0
  3240. }
  3241. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3242. project.ExecutionStaff = 0
  3243. project.ExecutionState = 2
  3244. project.ExecutionTime = 0
  3245. project.Checker = 0
  3246. project.CheckState = 2
  3247. project.CheckTime = 0
  3248. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3249. id := int64(json["id"].(float64))
  3250. project.ID = id
  3251. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3252. project.ExecutionStaff = temp_project.ExecutionStaff
  3253. project.ExecutionState = temp_project.ExecutionState
  3254. project.ExecutionTime = temp_project.ExecutionTime
  3255. project.Checker = temp_project.Checker
  3256. project.CheckState = temp_project.CheckState
  3257. project.CheckTime = temp_project.CheckTime
  3258. project.TeamId = temp_project.TeamId
  3259. }
  3260. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3261. types := int64(json["type"].(float64))
  3262. project.Type = types
  3263. }
  3264. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3265. project_id := int64(json["project_id"].(float64))
  3266. project.ProjectId = project_id
  3267. }
  3268. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3269. team_id := int64(json["team_id"].(float64))
  3270. project.TeamId = team_id
  3271. }
  3272. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3273. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3274. project.Price = price
  3275. }
  3276. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3277. total, _ := json["total"].(string)
  3278. //totals, _ := strconv.ParseInt(total, 10, 64)
  3279. project.Count = total
  3280. }
  3281. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3282. medical_code, _ := json["medical_code"].(string)
  3283. project.MedListCodg = medical_code
  3284. }
  3285. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3286. single_dose, _ := json["single_dose"].(string)
  3287. project.SingleDose = single_dose
  3288. }
  3289. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3290. delivery_way, _ := json["delivery_way"].(string)
  3291. project.DeliveryWay = delivery_way
  3292. }
  3293. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3294. execution_frequency, _ := json["execution_frequency"].(string)
  3295. project.ExecutionFrequency = execution_frequency
  3296. }
  3297. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3298. remark, _ := json["remark"].(string)
  3299. project.Remark = remark
  3300. }
  3301. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3302. day, _ := json["number_days"].(string)
  3303. project.Day = day
  3304. }
  3305. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3306. unit, _ := json["unit"].(string)
  3307. project.Unit = unit
  3308. }
  3309. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3310. // frequency_type := int64(json["frequency_type"].(float64))
  3311. // project.FrequencyType = frequency_type
  3312. //}
  3313. //
  3314. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3315. // day_count := int64(json["day_count"].(float64))
  3316. // project.DayCount = day_count
  3317. //}
  3318. //
  3319. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3320. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3321. // week_day, _ := json["week_day"].(string)
  3322. // project.WeekDay = week_day
  3323. //}
  3324. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3325. //
  3326. //if project.ID == 0 {
  3327. // if stockConfig.IsOpen == 1 {
  3328. // if project.Type == 3 {
  3329. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3330. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3331. // good.Total = good.Total - f_count
  3332. // service.UpdateGoodInfo(&good)
  3333. // }
  3334. // }
  3335. //
  3336. //} else {
  3337. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3338. //
  3339. // if stockConfig.IsOpen == 1 {
  3340. // if project.Type == 3 {
  3341. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3342. // if project.Count < temp_project.Count {
  3343. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3344. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3345. //
  3346. // other_count := f_count_two - f_count_one
  3347. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3348. // good.Total = good.Total + other_count_two
  3349. // service.UpdateGoodInfo(&good)
  3350. // } else if project.Count > temp_project.Count {
  3351. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3352. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3353. //
  3354. // other_count := f_count_one - f_count_two
  3355. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3356. // good.Total = good.Total - other_count_two
  3357. // service.UpdateGoodInfo(&good)
  3358. // }
  3359. //
  3360. // }
  3361. // }
  3362. //
  3363. //}
  3364. return 0
  3365. }
  3366. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3367. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3368. id := int64(json["id"].(float64))
  3369. additionalCharge.ID = id
  3370. }
  3371. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3372. item_id := int64(json["item_id"].(float64))
  3373. additionalCharge.ItemId = item_id
  3374. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3375. if config.ID > 0 {
  3376. if len(config.Code) > 0 {
  3377. additionalCharge.MedListCodg = config.Code
  3378. }
  3379. }
  3380. }
  3381. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3382. // price := int64(json["price"].(float64))
  3383. // formatInt_price := strconv.FormatInt(price, 10)
  3384. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3385. // additionalCharge.Price = float_price
  3386. // }
  3387. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3388. // price := int64(json["price"].(float64))
  3389. // formatInt_price := strconv.FormatInt(price, 10)
  3390. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3391. // additionalCharge.Price = float_price
  3392. //}
  3393. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3394. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3395. additionalCharge.Price = price
  3396. }
  3397. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3398. count, _ := json["count"].(string)
  3399. counts, _ := strconv.ParseInt(count, 10, 64)
  3400. additionalCharge.Count = counts
  3401. }
  3402. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3403. item_name, _ := json["item_name"].(string)
  3404. additionalCharge.ItemName = item_name
  3405. }
  3406. return 0
  3407. }
  3408. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3409. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3410. utils.ErrorLog("drug_name")
  3411. return enums.ErrorCodeParamWrong
  3412. }
  3413. adviceName, _ := json["drug_name"].(string)
  3414. if len(adviceName) == 0 {
  3415. utils.ErrorLog("len(advice_name) == 0")
  3416. return enums.ErrorCodeParamWrong
  3417. }
  3418. advice.AdviceName = adviceName
  3419. adviceDesc, _ := json["advice_desc"].(string)
  3420. advice.AdviceDesc = adviceDesc
  3421. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3422. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3423. advice.DrugSpec = drugSpec
  3424. }
  3425. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3426. remark, _ := json["remark"].(string)
  3427. advice.Remark = remark
  3428. }
  3429. if json["id"] == nil {
  3430. advice.DrugId = 0
  3431. } else {
  3432. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3433. drug_id := int64(json["id"].(float64))
  3434. advice.DrugId = drug_id
  3435. }
  3436. }
  3437. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3438. drugSpecUnit, _ := json["min_unit"].(string)
  3439. advice.DrugSpecUnit = drugSpecUnit
  3440. }
  3441. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3442. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3443. advice.SingleDose = singleDose
  3444. }
  3445. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3446. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3447. advice.SingleDoseUnit = singleDoseUnit
  3448. }
  3449. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3450. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3451. advice.PrescribingNumber = prescribingNumber
  3452. }
  3453. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3454. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3455. advice.PrescribingNumberUnit = prescribingNumberUnit
  3456. }
  3457. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3458. deliveryWay, _ := json["delivery_way"].(string)
  3459. advice.DeliveryWay = deliveryWay
  3460. }
  3461. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3462. executionFrequency, _ := json["execution_frequency"].(string)
  3463. advice.ExecutionFrequency = executionFrequency
  3464. }
  3465. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3466. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3467. advice.Price = price
  3468. }
  3469. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3470. med_list_codg, _ := json["medical_insurance_number"].(string)
  3471. advice.MedListCodg = med_list_codg
  3472. }
  3473. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3474. day := int64(json["day"].(float64))
  3475. advice.Day = day
  3476. }
  3477. return 0
  3478. }
  3479. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3480. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3481. types := int64(json["type"].(float64))
  3482. project.Type = types
  3483. }
  3484. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3485. project_id := int64(json["project_id"].(float64))
  3486. project.ProjectId = project_id
  3487. }
  3488. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3489. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3490. project.Price = price
  3491. }
  3492. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3493. total, _ := json["total"].(string)
  3494. //totals, _ := strconv.ParseInt(total, 10, 64)
  3495. project.Count = total
  3496. }
  3497. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3498. medical_code, _ := json["medical_code"].(string)
  3499. project.MedListCodg = medical_code
  3500. }
  3501. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3502. single_dose, _ := json["single_dose"].(string)
  3503. project.SingleDose = single_dose
  3504. }
  3505. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3506. delivery_way, _ := json["delivery_way"].(string)
  3507. project.DeliveryWay = delivery_way
  3508. }
  3509. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3510. execution_frequency, _ := json["execution_frequency"].(string)
  3511. project.ExecutionFrequency = execution_frequency
  3512. }
  3513. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3514. remark, _ := json["remark"].(string)
  3515. project.Remark = remark
  3516. }
  3517. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3518. day, _ := json["number_days"].(string)
  3519. project.Day = day
  3520. }
  3521. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3522. unit, _ := json["unit"].(string)
  3523. project.Unit = unit
  3524. }
  3525. return 0
  3526. }
  3527. func (c *HisApiController) GetHisOrderList() {
  3528. page, _ := c.GetInt64("page", -1)
  3529. limit, _ := c.GetInt64("limit", -1)
  3530. start_time := c.GetString("start_time")
  3531. end_time := c.GetString("end_time")
  3532. types, _ := c.GetInt64("type", 0)
  3533. keywords := c.GetString("keywords")
  3534. p_type, _ := c.GetInt64("p_type", 0)
  3535. sort_type, _ := c.GetInt64("sort_type", 0)
  3536. timeLayout := "2006-01-02"
  3537. loc, _ := time.LoadLocation("Local")
  3538. var startTime int64
  3539. if len(start_time) > 0 {
  3540. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3541. if err != nil {
  3542. fmt.Println(err)
  3543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3544. return
  3545. }
  3546. startTime = theTime.Unix()
  3547. }
  3548. var endTime int64
  3549. if len(end_time) > 0 {
  3550. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3551. if err != nil {
  3552. utils.ErrorLog(err.Error())
  3553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3554. return
  3555. }
  3556. endTime = theTime.Unix()
  3557. }
  3558. adminUser := c.GetAdminUserInfo()
  3559. org_id := adminUser.CurrentOrgId
  3560. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time)
  3561. for _, item := range order {
  3562. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3563. item.DoctorName = info.Doctor
  3564. item.DepartmentName = info.XtHisDepartment.Name
  3565. }
  3566. if err == nil {
  3567. c.ServeSuccessJSON(map[string]interface{}{
  3568. "order": order,
  3569. "total": total,
  3570. })
  3571. } else {
  3572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3573. return
  3574. }
  3575. }
  3576. func (c *HisApiController) GetHisOrder() {
  3577. patient_id, _ := c.GetInt64("patient_id", 0)
  3578. number := c.GetString("number")
  3579. adminInfo := c.GetAdminUserInfo()
  3580. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3581. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3582. if err == nil {
  3583. c.ServeSuccessJSON(map[string]interface{}{
  3584. "order": order,
  3585. "prescription": prescriptions,
  3586. })
  3587. } else {
  3588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3589. return
  3590. }
  3591. }
  3592. func (c *HisApiController) GetHisPrescriptionList() {
  3593. record_date := c.GetString("record_date")
  3594. keywords := c.GetString("keywords")
  3595. page, _ := c.GetInt64("page")
  3596. limit, _ := c.GetInt64("limit")
  3597. timeLayout := "2006-01-02"
  3598. loc, _ := time.LoadLocation("Local")
  3599. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3600. if err != nil {
  3601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3602. return
  3603. }
  3604. recordDateTime := theTime.Unix()
  3605. adminInfo := c.GetAdminUserInfo()
  3606. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3607. //adminInfo := c.GetAdminUserInfo()
  3608. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3609. //fmt.Println(prescriptionOrder)
  3610. if err == nil {
  3611. c.ServeSuccessJSON(map[string]interface{}{
  3612. "order": prescriptionOrder,
  3613. "total": total,
  3614. })
  3615. } else {
  3616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3617. return
  3618. }
  3619. }
  3620. func (c *HisApiController) GetHisPrescriptionInfo() {
  3621. id, _ := c.GetInt64("id")
  3622. adminInfo := c.GetAdminUserInfo()
  3623. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3624. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3625. if err == nil {
  3626. c.ServeSuccessJSON(map[string]interface{}{
  3627. "order": prescriptionOrder,
  3628. "prescription": prescription,
  3629. })
  3630. } else {
  3631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3632. return
  3633. }
  3634. }
  3635. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3636. adminUser := c.GetAdminUserInfo()
  3637. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3638. c.ServeSuccessJSON(map[string]interface{}{
  3639. "config": config,
  3640. })
  3641. }
  3642. type ResultTwo struct {
  3643. ErrMsg interface{} `json:"err_msg"`
  3644. InfRefmsgid string `json:"inf_refmsgid"`
  3645. Infcode int64 `json:"infcode"`
  3646. Output struct {
  3647. Baseinfo struct {
  3648. Age float64 `json:"age"`
  3649. Brdy string `json:"brdy"`
  3650. Certno string `json:"certno"`
  3651. Gend string `json:"gend"`
  3652. Naty string `json:"naty"`
  3653. PsnCertType string `json:"psn_cert_type"`
  3654. PsnName string `json:"psn_name"`
  3655. PsnNo string `json:"psn_no"`
  3656. } `json:"baseinfo"`
  3657. Idetinfo []interface{} `json:"idetinfo"`
  3658. Iinfo []struct {
  3659. Balc float64 `json:"balc"`
  3660. CvlservFlag string `json:"cvlserv_flag"`
  3661. EmpName string `json:"emp_name"`
  3662. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3663. Insutype string `json:"insutype"`
  3664. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3665. PausInsuDate interface{} `json:"paus_insu_date"`
  3666. PsnInsuDate string `json:"psn_insu_date"`
  3667. PsnInsuStas string `json:"psn_insu_stas"`
  3668. PsnType string `json:"psn_type"`
  3669. } `json:"insuinfo"`
  3670. } `json:"output"`
  3671. RefmsgTime string `json:"refmsg_time"`
  3672. RespondTime string `json:"respond_time"`
  3673. Signtype interface{} `json:"signtype"`
  3674. WarnInfo interface{} `json:"warn_info"`
  3675. }
  3676. type ResultThree struct {
  3677. Cainfo interface{} `json:"cainfo"`
  3678. ErrMsg interface{} `json:"err_msg"`
  3679. InfRefmsgid string `json:"inf_refmsgid"`
  3680. Infcode int64 `json:"infcode"`
  3681. Output struct {
  3682. Data struct {
  3683. IptOtpNo string `json:"ipt_otp_no"`
  3684. MdtrtID string `json:"mdtrt_id"`
  3685. PsnNo string `json:"psn_no"`
  3686. } `json:"data"`
  3687. } `json:"output"`
  3688. RefmsgTime string `json:"refmsg_time"`
  3689. RespondTime string `json:"respond_time"`
  3690. Signtype interface{} `json:"signtype"`
  3691. WarnMsg interface{} `json:"warn_msg"`
  3692. }
  3693. type ResultFour struct {
  3694. Cainfo string `json:"cainfo"`
  3695. ErrMsg string `json:"err_msg"`
  3696. InfRefmsgid string `json:"inf_refmsgid"`
  3697. Infcode int64 `json:"infcode"`
  3698. Output struct {
  3699. Result []struct {
  3700. BasMednFlag string `json:"bas_medn_flag"`
  3701. ChldMedcFlag string `json:"chld_medc_flag"`
  3702. ChrgitmLv string `json:"chrgitm_lv"`
  3703. Cnt float64 `json:"cnt"`
  3704. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3705. DrtReimFlag string `json:"drt_reim_flag"`
  3706. FeedetlSn string `json:"feedetl_sn"`
  3707. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3708. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3709. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3710. ListSpItemFlag string `json:"list_sp_item_flag"`
  3711. LmtUsedFlag string `json:"lmt_used_flag"`
  3712. MedChrgitmType string `json:"med_chrgitm_type"`
  3713. Memo string `json:"memo"`
  3714. OverlmtAmt float64 `json:"overlmt_amt"`
  3715. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3716. Pric float64 `json:"pric"`
  3717. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3718. SelfpayProp float64 `json:"selfpay_prop"`
  3719. } `json:"result"`
  3720. } `json:"output"`
  3721. RefmsgTime string `json:"refmsg_time"`
  3722. RespondTime string `json:"respond_time"`
  3723. Signtype string `json:"signtype"`
  3724. WarnMsg string `json:"warn_msg"`
  3725. }
  3726. type ResultFive struct {
  3727. Insutype string `json:"insutype"`
  3728. }
  3729. type ResultSix struct {
  3730. Cainfo interface{} `json:"cainfo"`
  3731. ErrMsg interface{} `json:"err_msg"`
  3732. InfRefmsgid string `json:"inf_refmsgid"`
  3733. Infcode int64 `json:"infcode"`
  3734. Output struct {
  3735. } `json:"output"`
  3736. RefmsgTime string `json:"refmsg_time"`
  3737. RespondTime string `json:"respond_time"`
  3738. Signtype interface{} `json:"signtype"`
  3739. WarnMsg interface{} `json:"warn_msg"`
  3740. }
  3741. type ResultSeven struct {
  3742. Cainfo string `json:"cainfo"`
  3743. ErrMsg string `json:"err_msg"`
  3744. InfRefmsgid string `json:"inf_refmsgid"`
  3745. Infcode int64 `json:"infcode"`
  3746. Output struct {
  3747. Setldetail []interface{} `json:"setldetail"`
  3748. Setlinfo struct {
  3749. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3750. AcctPay float64 `json:"acct_pay"`
  3751. ActPayDedc float64 `json:"act_pay_dedc"`
  3752. Age float64 `json:"age"`
  3753. Balc float64 `json:"balc"`
  3754. Brdy string `json:"brdy"`
  3755. Certno string `json:"certno"`
  3756. ClrOptins string `json:"clr_optins"`
  3757. ClrType string `json:"clr_type"`
  3758. ClrWay string `json:"clr_way"`
  3759. CvlservFlag string `json:"cvlserv_flag"`
  3760. CvlservPay float64 `json:"cvlserv_pay"`
  3761. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3762. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3763. Gend string `json:"gend"`
  3764. HifesPay float64 `json:"hifes_pay"`
  3765. HifmiPay float64 `json:"hifmi_pay"`
  3766. HifobPay float64 `json:"hifob_pay"`
  3767. HifpPay float64 `json:"hifp_pay"`
  3768. HospPartAmt float64 `json:"hosp_part_amt"`
  3769. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3770. Insutype string `json:"insutype"`
  3771. MafPay float64 `json:"maf_pay"`
  3772. MdtrtCertType string `json:"mdtrt_cert_type"`
  3773. MdtrtID string `json:"mdtrt_id"`
  3774. MedType string `json:"med_type"`
  3775. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3776. MedinsSetlID string `json:"medins_setl_id"`
  3777. Naty string `json:"naty"`
  3778. OthPay float64 `json:"oth_pay"`
  3779. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3780. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3781. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3782. PsnCashPay float64 `json:"psn_cash_pay"`
  3783. PsnCertType string `json:"psn_cert_type"`
  3784. PsnName string `json:"psn_name"`
  3785. PsnNo string `json:"psn_no"`
  3786. PsnPartAmt float64 `json:"psn_part_amt"`
  3787. PsnType string `json:"psn_type"`
  3788. SetlID string `json:"setl_id"`
  3789. SetlTime string `json:"setl_time"`
  3790. } `json:"setlinfo"`
  3791. } `json:"output"`
  3792. RefmsgTime string `json:"refmsg_time"`
  3793. RespondTime string `json:"respond_time"`
  3794. Signtype interface{} `json:"signtype"`
  3795. WarnMsg interface{} `json:"warn_msg"`
  3796. }
  3797. type ResultEight struct {
  3798. Cainfo string `json:"cainfo"`
  3799. ErrMsg string `json:"err_msg"`
  3800. InfRefmsgid string `json:"inf_refmsgid"`
  3801. Infcode int64 `json:"infcode"`
  3802. Output struct {
  3803. Stmtinfo struct {
  3804. SetlOptins string `json:"setl_optins"`
  3805. StmtRslt string `json:"stmt_rslt"`
  3806. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3807. } `json:"stmtinfo"`
  3808. } `json:"output"`
  3809. RefmsgTime string `json:"refmsg_time"`
  3810. RespondTime string `json:"respond_time"`
  3811. Signtype interface{} `json:"signtype"`
  3812. WarnMsg interface{} `json:"warn_msg"`
  3813. }
  3814. type ResultNine struct {
  3815. Cainfo string `json:"cainfo"`
  3816. ErrMsg string `json:"err_msg"`
  3817. InfRefmsgid string `json:"inf_refmsgid"`
  3818. Infcode int64 `json:"infcode"`
  3819. Output struct {
  3820. FileQuryNo string `json:"file_qury_no"`
  3821. } `json:"output"`
  3822. RefmsgTime string `json:"refmsg_time"`
  3823. RespondTime string `json:"respond_time"`
  3824. Signtype interface{} `json:"signtype"`
  3825. WarnMsg interface{} `json:"warn_msg"`
  3826. }
  3827. type ResultTen struct {
  3828. Cainfo string `json:"cainfo"`
  3829. ErrMsg string `json:"err_msg"`
  3830. InfRefmsgid string `json:"inf_refmsgid"`
  3831. Infcode int64 `json:"infcode"`
  3832. Output struct {
  3833. DldEndtime string `json:"dld_endtime"`
  3834. FileQuryNo string `json:"file_qury_no"`
  3835. Filename string `json:"filename"`
  3836. } `json:"output"`
  3837. RefmsgTime string `json:"refmsg_time"`
  3838. RespondTime string `json:"respond_time"`
  3839. Signtype interface{} `json:"signtype"`
  3840. WarnMsg interface{} `json:"warn_msg"`
  3841. }
  3842. type ResultEleven struct {
  3843. Cainfo string `json:"cainfo"`
  3844. ErrMsg string `json:"err_msg"`
  3845. InfRefmsgid string `json:"inf_refmsgid"`
  3846. Infcode int64 `json:"infcode"`
  3847. Output struct {
  3848. Setlinfo struct {
  3849. FixmedinsName string `json:"fixmedins_name"`
  3850. FixmedinsCode string `json:"fixmedins_code"`
  3851. PsnNo string `json:"psn_no"`
  3852. PsnName string `json:"psn_name"`
  3853. HifobPay float64 `json:"hifob_pay"`
  3854. Gend string `json:"gend"`
  3855. Brdy string `json:"brdy"`
  3856. PsnCertType string `json:"psn_cert_type"`
  3857. PsnType string `json:"psn_type"`
  3858. EmpName string `json:"emp_name"`
  3859. Certno string `json:"certno"`
  3860. Insutype string `json:"insutype"`
  3861. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3862. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3863. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3864. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3865. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3866. ActPayDedc float64 `json:"act_pay_dedc"`
  3867. HifpPay float64 `json:"hifp_pay"`
  3868. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3869. CvlservPay float64 `json:"cvlserv_pay"`
  3870. HifesPay float64 `json:"hifes_pay"`
  3871. HifmiPay float64 `json:"hifmi_pay"`
  3872. MafPay float64 `json:"maf_pay"`
  3873. OthPay float64 `json:"oth_pay"`
  3874. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3875. PsnPay float64 `json:"psn_pay"`
  3876. AcctPay float64 `json:"acct_pay"`
  3877. CashPayamt float64 `json:"cash_payamt"`
  3878. Balc float64 `json:"balc"`
  3879. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3880. MedinsSetlId string `json:"medins_setl_id"`
  3881. RefdSetlFlag string `json:"refd_setl_flag"`
  3882. SetlTime string `json:"setl_time"`
  3883. MedType string `json:"med_type"`
  3884. } `json:"setlinfo"`
  3885. } `json:"output"`
  3886. RefmsgTime string `json:"refmsg_time"`
  3887. RespondTime string `json:"respond_time"`
  3888. Signtype interface{} `json:"signtype"`
  3889. WarnMsg interface{} `json:"warn_msg"`
  3890. }
  3891. type Custom struct {
  3892. DetItemFeeSumamt string
  3893. Cut string
  3894. FeedetlSn string
  3895. Price string
  3896. MedListCodg string
  3897. Type int64
  3898. AdviceId int64
  3899. ProjectId int64
  3900. ItemId int64
  3901. }
  3902. //获取个人信息----挂号-----上传就诊信息
  3903. func (c *HisApiController) GetRegisterInfo() {
  3904. id, _ := c.GetInt64("id")
  3905. record_time := c.GetString("record_time")
  3906. settlementValue, _ := c.GetInt64("settlement_value")
  3907. medical_insurance_card := c.GetString("medical_insurance_card")
  3908. name := c.GetString("name")
  3909. id_card_type, _ := c.GetInt64("id_card_type")
  3910. certificates, _ := c.GetInt64("certificates")
  3911. medical_care, _ := c.GetInt64("medical_care")
  3912. birthday := c.GetString("birthday")
  3913. age, _ := c.GetInt64("age")
  3914. id_card := c.GetString("id_card")
  3915. register_type, _ := c.GetInt64("register")
  3916. doctor, _ := c.GetInt64("doctor")
  3917. department, _ := c.GetInt64("department")
  3918. gender, _ := c.GetInt64("sex")
  3919. phone := c.GetString("phone")
  3920. registration_fee, _ := c.GetFloat("registration_fee")
  3921. medical_expenses, _ := c.GetFloat("medical_expenses")
  3922. social_type, _ := c.GetInt64("social_type")
  3923. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3924. diagnosis_ids := c.GetString("diagnosis")
  3925. sick_type, _ := c.GetInt64("sick_type")
  3926. reg_type := c.GetString("p_type")
  3927. timeLayout := "2006-01-02"
  3928. loc, _ := time.LoadLocation("Local")
  3929. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3930. birthUnix := birthdays.Unix()
  3931. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3932. if err != nil {
  3933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3934. return
  3935. }
  3936. recordDateTime := theTime.Unix()
  3937. adminInfo := c.GetAdminUserInfo()
  3938. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3939. if tempPatient.ID == 0 {
  3940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3941. return
  3942. }
  3943. var patient service.Patients
  3944. if id == 0 {
  3945. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3946. } else {
  3947. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3948. }
  3949. if patient.ID == 0 {
  3950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3951. return
  3952. }
  3953. if len(patient.IdCardNo) == 0 {
  3954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3955. return
  3956. }
  3957. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3958. if len(his) >= 1 {
  3959. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3960. if len(his) >= 1 && order.ID == 0 {
  3961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3962. return
  3963. }
  3964. }
  3965. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3966. fmt.Println(timeStr)
  3967. timeArr := strings.Split(timeStr, " ")
  3968. fmt.Println(timeArr)
  3969. timeArrTwo := strings.Split(timeArr[0], "-")
  3970. timeArrThree := strings.Split(timeArr[1], ":")
  3971. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  3972. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3973. if len(lists) == 0 {
  3974. var hisPatient models.XtHisPatient
  3975. hisPatient = models.XtHisPatient{
  3976. Name: name,
  3977. Age: age,
  3978. Gender: gender,
  3979. Birthday: birthUnix,
  3980. Phone: phone,
  3981. MedicalTreatmentType: medical_care,
  3982. IdType: certificates,
  3983. IdCardNo: id_card,
  3984. BalanceAccountsType: settlementValue,
  3985. SocialType: social_type,
  3986. MedicalInsuranceNumber: medical_insurance_card,
  3987. RegisterType: register_type,
  3988. RegisterCost: registration_fee,
  3989. TreatmentCost: medical_expenses,
  3990. AdminUserId: adminInfo.AdminUser.Id,
  3991. UserOrgId: adminInfo.CurrentOrgId,
  3992. Status: 1,
  3993. RecordDate: recordDateTime,
  3994. IsReturn: 1,
  3995. PatientId: patient.ID,
  3996. Ctime: time.Now().Unix(),
  3997. Mtime: time.Now().Unix(),
  3998. Number: str,
  3999. IdCardType: id_card_type,
  4000. Departments: department,
  4001. Doctor: doctor,
  4002. PType: reg_type,
  4003. Diagnosis: diagnosis_ids,
  4004. SickType: sick_type,
  4005. }
  4006. service.CreateHisPatient(&hisPatient)
  4007. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4008. c.ServeSuccessJSON(map[string]interface{}{
  4009. "his_info": hisPatient,
  4010. })
  4011. } else {
  4012. //chrgBchno := rand.Intn(1000000) + 10000
  4013. var hisPatient models.XtHisPatient
  4014. hisPatient = models.XtHisPatient{
  4015. Name: name,
  4016. Age: age,
  4017. Gender: gender,
  4018. Birthday: birthUnix,
  4019. Phone: phone,
  4020. MedicalTreatmentType: medical_care,
  4021. IdType: certificates,
  4022. IdCardNo: id_card,
  4023. BalanceAccountsType: settlementValue,
  4024. SocialType: social_type,
  4025. MedicalInsuranceNumber: medical_insurance_card,
  4026. RegisterType: register_type,
  4027. RegisterCost: registration_fee,
  4028. TreatmentCost: medical_expenses,
  4029. AdminUserId: adminInfo.AdminUser.Id,
  4030. UserOrgId: adminInfo.CurrentOrgId,
  4031. Status: 1,
  4032. RecordDate: recordDateTime,
  4033. IsReturn: 1,
  4034. PatientId: patient.ID,
  4035. Ctime: time.Now().Unix(),
  4036. Mtime: time.Now().Unix(),
  4037. Number: str,
  4038. IdCardType: id_card_type,
  4039. Departments: department,
  4040. Doctor: doctor,
  4041. PType: reg_type,
  4042. Diagnosis: diagnosis_ids,
  4043. SickType: sick_type,
  4044. }
  4045. service.CreateHisPatient(&hisPatient)
  4046. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4047. c.ServeSuccessJSON(map[string]interface{}{
  4048. "his_info": hisPatient,
  4049. })
  4050. }
  4051. }
  4052. //上传明细----结算
  4053. func (c *HisApiController) GetUploadInfo() {
  4054. id, _ := c.GetInt64("id")
  4055. record_time := c.GetString("record_time")
  4056. his_patient_id, _ := c.GetInt64("his_patient_id")
  4057. pay_way, _ := c.GetInt64("pay_way")
  4058. pay_price, _ := c.GetFloat("pay_price")
  4059. pay_card_no := c.GetString("pay_card_no")
  4060. discount_price, _ := c.GetFloat("discount_price")
  4061. preferential_price, _ := c.GetFloat("preferential_price")
  4062. reality_price, _ := c.GetFloat("reality_price")
  4063. found_price, _ := c.GetFloat("found_price")
  4064. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4065. private_price, _ := c.GetFloat("private_price")
  4066. timeLayout := "2006-01-02"
  4067. loc, _ := time.LoadLocation("Local")
  4068. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4069. fapiao_code := c.GetString("fapiao_code")
  4070. fapiao_number := c.GetString("fapiao_number")
  4071. diagnosis_id := c.GetString("diagnosis")
  4072. sick_type, _ := c.GetInt64("sick_type")
  4073. reg_type, _ := c.GetInt64("p_type")
  4074. order_id, _ := c.GetInt64("order_id")
  4075. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4076. tempOrder, _ := service.GetHisOrderByID(order_id)
  4077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4078. if err != nil {
  4079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4080. return
  4081. }
  4082. recordDateTime := theTime.Unix()
  4083. adminUser := c.GetAdminUserInfo()
  4084. var prescriptions []*models.HisPrescription
  4085. var start_time int64
  4086. var end_time int64
  4087. ids_str := c.GetString("ids")
  4088. ids_arr := strings.Split(ids_str, ",")
  4089. if tempOrder.ID == 0 {
  4090. if settle_accounts_type == 1 { //日结
  4091. fmt.Println(reg_type)
  4092. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4093. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  4094. } else {
  4095. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  4096. }
  4097. } else { //月结
  4098. start_time_str := c.GetString("start_time")
  4099. end_time_str := c.GetString("end_time")
  4100. timeLayout := "2006-01-02"
  4101. loc, _ := time.LoadLocation("Local")
  4102. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4103. if err != nil {
  4104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4105. return
  4106. }
  4107. recordStartTime := theStartTime.Unix()
  4108. start_time = recordStartTime
  4109. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4110. if err != nil {
  4111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4112. return
  4113. }
  4114. recordEndTime := theEndTime.Unix()
  4115. end_time = recordEndTime
  4116. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  4117. }
  4118. timestamp := time.Now().Unix()
  4119. tempTime := time.Unix(timestamp, 0)
  4120. timeFormat := tempTime.Format("20060102150405")
  4121. chrgBchno := rand.Intn(100000) + 10000
  4122. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4123. strconv.FormatInt(his.PatientId, 10)
  4124. var ids []int64
  4125. for _, item := range prescriptions {
  4126. ids = append(ids, item.ID)
  4127. }
  4128. var total float64
  4129. for _, item := range prescriptions {
  4130. fmt.Println(item)
  4131. if item.Type == 1 { //药品
  4132. for _, subItem := range item.HisDoctorAdviceInfo {
  4133. total = total + (subItem.Price * subItem.PrescribingNumber)
  4134. }
  4135. }
  4136. if item.Type == 2 { //项目
  4137. for _, subItem := range item.HisPrescriptionProject {
  4138. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4139. total = total + (subItem.Price * cnt)
  4140. }
  4141. }
  4142. for _, subItem := range item.HisAdditionalCharge {
  4143. total = total + (subItem.Price * float64(subItem.Count))
  4144. }
  4145. }
  4146. if reg_type == 1111 || reg_type == 1112 {
  4147. reg_type = 11
  4148. }
  4149. tm := time.Unix(time.Now().Unix(), 0)
  4150. allTotal := fmt.Sprintf("%.4f", total)
  4151. totals, _ := strconv.ParseFloat(allTotal, 64)
  4152. order := &models.HisOrder{
  4153. UserOrgId: adminUser.CurrentOrgId,
  4154. HisPatientId: his.ID,
  4155. PatientId: id,
  4156. SettleAccountsDate: recordDateTime,
  4157. Ctime: time.Now().Unix(),
  4158. Mtime: time.Now().Unix(),
  4159. Status: 1,
  4160. OrderStatus: 2,
  4161. MdtrtId: his.Number,
  4162. Number: chrg_bchno,
  4163. MedfeeSumamt: totals,
  4164. PayWay: pay_way,
  4165. PayPrice: pay_price,
  4166. MedType: strconv.Itoa(int(reg_type)),
  4167. PayCardNo: pay_card_no,
  4168. DiscountPrice: discount_price,
  4169. PreferentialPrice: preferential_price,
  4170. RealityPrice: reality_price,
  4171. FoundPrice: found_price,
  4172. MedicalInsurancePrice: medical_insurance_price,
  4173. PrivatePrice: private_price,
  4174. SettleEndTime: end_time,
  4175. SettleStartTime: start_time,
  4176. SettleType: settle_accounts_type,
  4177. FaPiaoCode: fapiao_code,
  4178. FaPiaoNumber: fapiao_number,
  4179. Diagnosis: diagnosis_id,
  4180. PType: 2,
  4181. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4182. }
  4183. err = service.CreateOrder(order)
  4184. if err != nil {
  4185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4186. return
  4187. }
  4188. var customs []*Custom
  4189. for _, item := range prescriptions {
  4190. if item.Type == 1 { //药品
  4191. for _, subItem := range item.HisDoctorAdviceInfo {
  4192. cus := &Custom{
  4193. AdviceId: subItem.ID,
  4194. ProjectId: 0,
  4195. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4196. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4197. FeedetlSn: subItem.FeedetlSn,
  4198. Price: fmt.Sprintf("%.2f", subItem.Price),
  4199. MedListCodg: subItem.MedListCodg,
  4200. Type: 1,
  4201. }
  4202. customs = append(customs, cus)
  4203. }
  4204. }
  4205. if item.Type == 2 { //项目
  4206. for _, subItem := range item.HisPrescriptionProject {
  4207. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4208. cus := &Custom{
  4209. AdviceId: 0,
  4210. ProjectId: subItem.ID,
  4211. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4212. Cut: fmt.Sprintf("%.4f", cnt),
  4213. FeedetlSn: subItem.FeedetlSn,
  4214. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4215. MedListCodg: subItem.MedListCodg,
  4216. Type: 2,
  4217. }
  4218. customs = append(customs, cus)
  4219. }
  4220. }
  4221. for _, item := range item.HisAdditionalCharge {
  4222. cus := &Custom{
  4223. ItemId: item.ID,
  4224. AdviceId: 0,
  4225. ProjectId: 0,
  4226. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4227. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4228. FeedetlSn: item.FeedetlSn,
  4229. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4230. MedListCodg: item.XtHisAddtionConfig.Code,
  4231. Type: 3,
  4232. }
  4233. customs = append(customs, cus)
  4234. }
  4235. }
  4236. for _, item := range customs {
  4237. var advice_id int64 = 0
  4238. var project_id int64 = 0
  4239. var item_id int64 = 0
  4240. var types int64 = 0
  4241. if item.Type == 1 {
  4242. advice_id = item.AdviceId
  4243. project_id = 0
  4244. item_id = 0
  4245. } else if item.Type == 2 {
  4246. advice_id = 0
  4247. item_id = 0
  4248. project_id = item.ProjectId
  4249. } else if item.Type == 3 {
  4250. advice_id = 0
  4251. item_id = item.ItemId
  4252. project_id = 0
  4253. }
  4254. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4255. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4256. pric, _ := strconv.ParseFloat(item.Price, 32)
  4257. info := &models.HisOrderInfo{
  4258. OrderNumber: order.Number,
  4259. UploadDate: time.Now().Unix(),
  4260. AdviceId: advice_id,
  4261. DetItemFeeSumamt: detItemFeeSumamt,
  4262. Cnt: cut,
  4263. Pric: pric,
  4264. PatientId: id,
  4265. Status: 1,
  4266. Mtime: time.Now().Unix(),
  4267. Ctime: time.Now().Unix(),
  4268. UserOrgId: adminUser.CurrentOrgId,
  4269. HisPatientId: his.ID,
  4270. OrderId: order.ID,
  4271. ProjectId: project_id,
  4272. Type: types,
  4273. ItemId: item_id,
  4274. }
  4275. service.CreateOrderInfo(info)
  4276. }
  4277. his.Diagnosis = diagnosis_id
  4278. his.SickType = sick_type
  4279. his.RegisterType = reg_type
  4280. his.MedicalTreatmentType = reg_type
  4281. service.UpdataHisPateint(&his)
  4282. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4283. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4284. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4285. if err == nil {
  4286. c.ServeSuccessJSON(map[string]interface{}{
  4287. "msg": "结算成功",
  4288. })
  4289. }
  4290. } else {
  4291. if tempOrder.IsPre > 0 {
  4292. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4293. totals, _ := strconv.ParseFloat(allTotal, 64)
  4294. tempOrder.OrderStatus = 2
  4295. tempOrder.PayWay = pay_way
  4296. tempOrder.PayPrice = pay_price
  4297. tempOrder.PayCardNo = pay_card_no
  4298. tempOrder.DiscountPrice = discount_price
  4299. tempOrder.PreferentialPrice = preferential_price
  4300. tempOrder.RealityPrice = reality_price
  4301. tempOrder.FoundPrice = found_price
  4302. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4303. tempOrder.PrivatePrice = private_price
  4304. tempOrder.FaPiaoCode = fapiao_code
  4305. tempOrder.FaPiaoNumber = fapiao_number
  4306. tempOrder.PType = 2
  4307. tempOrder.MedfeeSumamt = totals
  4308. tempOrder.Diagnosis = diagnosis_id
  4309. err = service.SaveHisOrder(&tempOrder)
  4310. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4311. if err != nil {
  4312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4313. return
  4314. }
  4315. if err == nil {
  4316. c.ServeSuccessJSON(map[string]interface{}{
  4317. "msg": "结算成功",
  4318. })
  4319. }
  4320. }
  4321. }
  4322. }
  4323. //退款
  4324. func (c *HisApiController) Refund() {
  4325. order_id, _ := c.GetInt64("order_id")
  4326. order, _ := service.GetHisOrderByID(order_id)
  4327. adminUser := c.GetAdminUserInfo()
  4328. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4329. if err == nil {
  4330. c.ServeSuccessJSON(map[string]interface{}{
  4331. "msg": "退费成功",
  4332. })
  4333. } else {
  4334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4335. return
  4336. }
  4337. }
  4338. func (c *HisApiController) RefundNumber() {
  4339. his_patient_id, _ := c.GetInt64("id")
  4340. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4341. info.Status = 0
  4342. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4343. if count > 0 {
  4344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4345. return
  4346. }
  4347. err := service.SaveHisPatient(info)
  4348. if err == nil {
  4349. c.ServeSuccessJSON(map[string]interface{}{
  4350. "msg": "退号成功",
  4351. })
  4352. } else {
  4353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4354. return
  4355. }
  4356. }
  4357. func (this *HisApiController) AdditionalCharge() {
  4358. dataBody := make(map[string]interface{}, 0)
  4359. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4360. fmt.Println(err)
  4361. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4362. patient_id := int64(dataBody["patient_id"].(float64))
  4363. medicineData, _ := dataBody["medicineData"].([]interface{})
  4364. adminUserInfo := this.GetAdminUserInfo()
  4365. orgId := adminUserInfo.CurrentOrgId
  4366. admin_user_id := adminUserInfo.AdminUser.Id
  4367. timeStr := time.Now().Format("2006-01-02")
  4368. timeLayout := "2006-01-02 15:04:05"
  4369. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4370. timenow := timeStringToTime.Unix()
  4371. var additionalCharges []*models.HisAdditionalCharge
  4372. for _, item := range medicineData {
  4373. var randNum int
  4374. randNum = rand.Intn(10000) + 1000
  4375. timestamp := time.Now().Unix()
  4376. tempTime := time.Unix(timestamp, 0)
  4377. timeFormat := tempTime.Format("20060102150405")
  4378. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4379. items := item.(map[string]interface{})
  4380. money := items["price"].(string)
  4381. item_id_str := items["item_id"].(string)
  4382. name := items["name"].(string)
  4383. id_str := items["id"].(string)
  4384. moneys, _ := strconv.ParseInt(money, 10, 64)
  4385. monStr := strconv.FormatInt(moneys, 10)
  4386. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4387. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4388. id, _ := strconv.ParseInt(id_str, 10, 64)
  4389. additionalCharge := &models.HisAdditionalCharge{
  4390. ID: id,
  4391. HisPatientId: his_patient_id,
  4392. UserOrgId: orgId,
  4393. PatientId: patient_id,
  4394. RecordDate: timenow,
  4395. Price: monneyStr,
  4396. Status: 1,
  4397. ItemName: name,
  4398. ItemId: item_id,
  4399. AdminUserId: admin_user_id,
  4400. CreatedTime: time.Now().Unix(),
  4401. OrderStatus: 0,
  4402. PrescriptionNumber: "",
  4403. BatchNumber: "",
  4404. FeedetlSn: p_number,
  4405. }
  4406. service.CreateAdditionalCharge(additionalCharge)
  4407. additionalCharges = append(additionalCharges, additionalCharge)
  4408. }
  4409. this.ServeSuccessJSON(map[string]interface{}{
  4410. "msg": "添加成功",
  4411. "additional_charges": additionalCharges,
  4412. })
  4413. }
  4414. func (this *HisApiController) DeleteAddition() {
  4415. id, _ := this.GetInt64("id")
  4416. //TODO 需要判断是否已经结算
  4417. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4418. if err == nil {
  4419. this.ServeSuccessJSON(map[string]interface{}{
  4420. "msg": "删除成功",
  4421. })
  4422. return
  4423. } else {
  4424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4425. return
  4426. }
  4427. }
  4428. func (this *HisApiController) GetAdminUsers() {
  4429. adminUser := this.GetAdminUserInfo()
  4430. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4431. this.ServeSuccessJSON(map[string]interface{}{
  4432. "doctors": doctors,
  4433. })
  4434. }
  4435. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4436. change_type, _ := this.GetInt64("type", 0)
  4437. record_date := this.GetString("record_time")
  4438. patient_id, _ := this.GetInt64("patient_id", 0)
  4439. p_type, _ := this.GetInt64("p_type", 0)
  4440. timeLayout := "2006-01-02"
  4441. loc, _ := time.LoadLocation("Local")
  4442. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4443. record_time := theAdviceRecordTime.Unix()
  4444. adminUserInfo := this.GetAdminUserInfo()
  4445. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4446. if err == nil {
  4447. if len(prescriptions) == 0 {
  4448. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4449. return
  4450. } else {
  4451. this.ServeSuccessJSON(map[string]interface{}{
  4452. "prescriptions": prescriptions,
  4453. })
  4454. return
  4455. }
  4456. } else {
  4457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4458. return
  4459. }
  4460. }
  4461. func (this *HisApiController) GetCallHisPrescription() {
  4462. patient_id, _ := this.GetInt64("patient_id", 0)
  4463. timeLayout := "2006-01-02"
  4464. loc, _ := time.LoadLocation("Local")
  4465. start_time := this.GetString("start_time")
  4466. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4467. end_time := this.GetString("end_time")
  4468. p_type, _ := this.GetInt64("p_type")
  4469. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4470. adminUserInfo := this.GetAdminUserInfo()
  4471. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4472. if err == nil {
  4473. this.ServeSuccessJSON(map[string]interface{}{
  4474. "prescriptions": prescriptions,
  4475. })
  4476. return
  4477. } else {
  4478. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4479. return
  4480. }
  4481. }
  4482. func (this *HisApiController) GetHisDayPrescription() {
  4483. timeLayout := "2006-01-02"
  4484. loc, _ := time.LoadLocation("Local")
  4485. start_time := this.GetString("start_time")
  4486. patient_id, _ := this.GetInt64("patient_id", 0)
  4487. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4488. end_time := this.GetString("end_time")
  4489. p_type, _ := this.GetInt64("p_type")
  4490. order_status, _ := this.GetInt64("type")
  4491. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4492. adminUserInfo := this.GetAdminUserInfo()
  4493. var dayHisPrescription []*models.HisPrescription
  4494. var err error
  4495. if order_status == 1 || order_status == 0 {
  4496. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4497. } else if order_status == 2 {
  4498. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4499. }
  4500. var settle_total float64
  4501. for _, item := range dayHisPrescription {
  4502. if len(item.HisPrescriptionProject) > 0 {
  4503. for _, subItem := range item.HisPrescriptionProject {
  4504. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4505. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4506. settle_total = settle_total + total
  4507. }
  4508. }
  4509. if len(item.HisDoctorAdviceInfo) > 0 {
  4510. for _, subItem := range item.HisDoctorAdviceInfo {
  4511. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4512. settle_total = settle_total + total
  4513. }
  4514. }
  4515. }
  4516. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4517. if err == nil {
  4518. this.ServeSuccessJSON(map[string]interface{}{
  4519. "day_prescription": dayHisPrescription,
  4520. "settle_total": settle_total,
  4521. })
  4522. return
  4523. } else {
  4524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4525. return
  4526. }
  4527. }
  4528. func (c *HisApiController) GetHisChargePatientList() {
  4529. record_date := c.GetString("record_date")
  4530. order_status, _ := c.GetInt64("type")
  4531. timeLayout := "2006-01-02"
  4532. loc, _ := time.LoadLocation("Local")
  4533. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4534. if err != nil {
  4535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4536. return
  4537. }
  4538. recordDateTime := theTime.Unix()
  4539. adminInfo := c.GetAdminUserInfo()
  4540. var tempPatients []*service.NewTempPatients
  4541. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4542. if order_status != 2 {
  4543. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4544. } else {
  4545. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4546. }
  4547. var patients []*service.NewTempPatients
  4548. var patients_two []*service.NewTempPatients
  4549. for _, item := range tempPatients {
  4550. //过滤掉没挂号的和没开处方的
  4551. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4552. patients = append(patients, item)
  4553. }
  4554. //过滤掉没挂号的
  4555. if len(item.HisPatient) > 0 {
  4556. patients_two = append(patients_two, item)
  4557. }
  4558. }
  4559. c.ServeSuccessJSON(map[string]interface{}{
  4560. "list": patients,
  4561. "list_two": patients_two,
  4562. })
  4563. }
  4564. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4565. record_date := c.GetString("record_date")
  4566. timeLayout := "2006-01-02"
  4567. loc, _ := time.LoadLocation("Local")
  4568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4569. if err != nil {
  4570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4571. return
  4572. }
  4573. recordDateTime := theTime.Unix()
  4574. adminUser := c.GetAdminUserInfo()
  4575. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4576. var patients []*service.Patients
  4577. for _, item := range tempPatients {
  4578. if item.HisPatient.ID == 0 {
  4579. patients = append(patients, item)
  4580. }
  4581. }
  4582. c.ServeSuccessJSON(map[string]interface{}{
  4583. "list": patients,
  4584. //"list_two": patients_two,
  4585. })
  4586. }
  4587. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4588. newArr = make([]*service.Patients, 0)
  4589. for i := 0; i < len(patient); i++ {
  4590. repeat := false
  4591. for j := i + 1; j < len(patient); j++ {
  4592. if patient[i].ID == patient[j].ID {
  4593. repeat = true
  4594. break
  4595. }
  4596. }
  4597. if !repeat {
  4598. newArr = append(newArr, patient[i])
  4599. }
  4600. }
  4601. return
  4602. }
  4603. func (c *HisApiController) GetHisChargePatientInfo() {
  4604. patient_id, _ := c.GetInt64("patient_id")
  4605. his_patient_id, _ := c.GetInt64("his_patient_id")
  4606. record_date := c.GetString("record_date")
  4607. //start_time := c.GetString("start_time")
  4608. //end_time := c.GetString("end_time")
  4609. order_status, _ := c.GetInt64("type", 0)
  4610. p_type, _ := c.GetInt64("p_type", 0)
  4611. order_id, _ := c.GetInt64("order_id", 0)
  4612. timeLayout := "2006-01-02"
  4613. loc, _ := time.LoadLocation("Local")
  4614. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4615. if err != nil {
  4616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4617. return
  4618. }
  4619. recordDateTime := theTime.Unix()
  4620. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4621. //if err != nil {
  4622. //
  4623. //}
  4624. //startRecordDateTime := startTime.Unix()
  4625. //
  4626. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4627. //if err != nil {
  4628. //
  4629. //}
  4630. //endRecordDateTime := endTime.Unix()
  4631. admin := c.GetAdminUserInfo()
  4632. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4633. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4634. var prescriptions []*models.HisPrescription
  4635. //var unChargeMonthPrescriptions []*models.HisPrescription
  4636. order, _ := service.GetHisOrderByID(order_id)
  4637. if order_status == 1 || order_status == 0 {
  4638. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4639. } else if order_status == 2 {
  4640. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4641. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4642. }
  4643. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4644. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4645. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4646. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4647. //获取所有科室信息
  4648. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4649. c.ServeSuccessJSON(map[string]interface{}{
  4650. "his_info": his_patient_info,
  4651. "xt_info": xt_patient_info,
  4652. "prescription": prescriptions,
  4653. "case_history": case_history,
  4654. "info": patientPrescriptionInfo,
  4655. "last_info": lastPatientPrescriptionInfo,
  4656. "order": order,
  4657. "doctors": doctors,
  4658. "department": department,
  4659. })
  4660. return
  4661. }
  4662. func (c *HisApiController) GetAllOrderDetail() {
  4663. order_id, _ := c.GetInt64("id", 0)
  4664. order, _ := service.GetHisOrderByID(order_id)
  4665. if order.ID == 0 {
  4666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4667. return
  4668. }
  4669. org_id := c.GetAdminUserInfo().CurrentOrgId
  4670. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4671. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4672. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4673. c.ServeSuccessJSON(map[string]interface{}{
  4674. "order": order,
  4675. "order_info": order_info,
  4676. "patient": patient,
  4677. "admin_info": adminInfo,
  4678. })
  4679. return
  4680. }
  4681. func (c *HisApiController) GetAllOrderDetailCollect() {
  4682. order_id, _ := c.GetInt64("id", 0)
  4683. order, _ := service.GetHisOrderByID(order_id)
  4684. if order.ID == 0 {
  4685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4686. return
  4687. }
  4688. org_id := c.GetAdminUserInfo().CurrentOrgId
  4689. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4690. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4691. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4692. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4693. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4694. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4695. var bedCostTotal float64 = 0 //床位总费
  4696. //var bedCostSelfTotal float64 = 0 //床位自费
  4697. var operationCostTotal float64 = 0 //手术费
  4698. //var operationCostSelfTotal float64 = 0 //手术费
  4699. var otherCostTotal float64 = 0 //其他费用
  4700. //var otherCostSelfTotal float64 = 0 //其他费用
  4701. var materialCostTotal float64 = 0 //材料费
  4702. //var materialCostSelfTotal float64 = 0 //材料费
  4703. var westernMedicineCostTotal float64 = 0 //西药费
  4704. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4705. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4706. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4707. var checkCostTotal float64 = 0 //检查费
  4708. //var checkCostSelfTotal float64 = 0 //检查费
  4709. var laboratoryCostTotal float64 = 0 //化验费
  4710. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4711. var treatCostTotal float64 = 0 //治疗费用
  4712. //var treatCostSelfTotal float64 = 0 //治疗费用
  4713. var zhenChaCostTotal float64 = 0 //其他费用
  4714. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4715. decimal.DivisionPrecision = 2
  4716. var BalanceAccountsType int64
  4717. if his.ID > 0 {
  4718. BalanceAccountsType = his.BalanceAccountsType
  4719. } else {
  4720. BalanceAccountsType = record.BalanceAccountsType
  4721. }
  4722. if BalanceAccountsType != 2 {
  4723. for _, item := range order_info {
  4724. if org_id == 10215 {
  4725. if item.MedChrgitmType == "01" { //床位费
  4726. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4727. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4728. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4729. }
  4730. if item.MedChrgitmType == "02" { //诊察费
  4731. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4732. //zhenChaCostSelfTotal = zhenChaCostTotal
  4733. }
  4734. if item.MedChrgitmType == "03" { //检查费
  4735. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4736. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4737. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4738. }
  4739. //if item.MedChrgitmType == "02" { //检查费
  4740. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4741. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4742. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4743. //}
  4744. if item.MedChrgitmType == "04" { //化验费
  4745. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4746. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4747. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4748. }
  4749. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4750. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4751. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4752. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4753. }
  4754. if item.MedChrgitmType == "06" { //手术费
  4755. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4756. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4757. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4758. }
  4759. if item.MedChrgitmType == "08" { //材料费
  4760. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4761. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4762. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4763. }
  4764. if item.MedChrgitmType == "09" { //西药费
  4765. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4766. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4767. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4768. }
  4769. if item.MedChrgitmType == "11" { //中成费
  4770. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4771. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4772. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4773. }
  4774. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4775. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4776. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4777. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4778. }
  4779. } else {
  4780. if item.MedChrgitmType == "01" { //床位费
  4781. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4782. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4783. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4784. }
  4785. //if item.MedChrgitmType == "02" { //诊察费
  4786. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4787. // //zhenChaCostSelfTotal = zhenChaCostTotal
  4788. //}
  4789. if item.MedChrgitmType == "03" { //检查费
  4790. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4791. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4792. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4793. }
  4794. //if item.MedChrgitmType == "02" { //检查费
  4795. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4796. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4797. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4798. //}
  4799. if item.MedChrgitmType == "04" { //化验费
  4800. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4801. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4802. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4803. }
  4804. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4805. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4806. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4807. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4808. }
  4809. if item.MedChrgitmType == "06" { //手术费
  4810. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4811. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4812. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4813. }
  4814. if item.MedChrgitmType == "08" { //材料费
  4815. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4816. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4817. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4818. }
  4819. if item.MedChrgitmType == "09" { //西药费
  4820. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4821. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4822. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4823. }
  4824. if item.MedChrgitmType == "11" { //中成费
  4825. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4826. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4827. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4828. }
  4829. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4830. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4831. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4832. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4833. }
  4834. }
  4835. }
  4836. c.ServeSuccessJSON(map[string]interface{}{
  4837. "order": order,
  4838. "order_info": order_info,
  4839. "patient": patient,
  4840. "admin_info": adminInfo,
  4841. "his_hospital": record,
  4842. "bedCostTotal": bedCostTotal,
  4843. "operationCostTotal": operationCostTotal,
  4844. "otherCostTotal": otherCostTotal,
  4845. "materialCostTotal": materialCostTotal,
  4846. "westernMedicineCostTotal": westernMedicineCostTotal,
  4847. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4848. "checkCostTotal": checkCostTotal,
  4849. "zhenChaCostTotal": zhenChaCostTotal,
  4850. "laboratoryCostTotal": laboratoryCostTotal,
  4851. "treatCostTotal": treatCostTotal,
  4852. })
  4853. } else {
  4854. for _, item := range order_info {
  4855. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4856. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4857. item.MedChrgitmType = "09"
  4858. }
  4859. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4860. if item.HisPrescriptionProject.Type == 2 {
  4861. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  4862. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4863. case 0:
  4864. item.MedChrgitmType = "0"
  4865. break
  4866. case 1:
  4867. item.MedChrgitmType = "14"
  4868. break
  4869. case 2:
  4870. item.MedChrgitmType = "05"
  4871. break
  4872. case 3:
  4873. item.MedChrgitmType = "03"
  4874. break
  4875. case 4:
  4876. item.MedChrgitmType = "03"
  4877. break
  4878. case 5:
  4879. item.MedChrgitmType = "08"
  4880. break
  4881. case 6:
  4882. item.MedChrgitmType = "14"
  4883. break
  4884. case 7:
  4885. item.MedChrgitmType = "14"
  4886. break
  4887. case 8:
  4888. item.MedChrgitmType = "03"
  4889. break
  4890. case 9:
  4891. item.MedChrgitmType = "14"
  4892. break
  4893. case 10:
  4894. item.MedChrgitmType = "14"
  4895. break
  4896. case 11:
  4897. item.MedChrgitmType = "06"
  4898. break
  4899. case 12:
  4900. item.MedChrgitmType = "12"
  4901. break
  4902. case 13:
  4903. item.MedChrgitmType = "01"
  4904. break
  4905. case 14:
  4906. item.MedChrgitmType = "04"
  4907. break
  4908. case 15:
  4909. item.MedChrgitmType = "14"
  4910. break
  4911. }
  4912. } else {
  4913. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4914. case 1:
  4915. item.MedChrgitmType = "14"
  4916. break
  4917. case 2:
  4918. item.MedChrgitmType = "05"
  4919. break
  4920. case 3:
  4921. item.MedChrgitmType = "04"
  4922. break
  4923. case 4:
  4924. item.MedChrgitmType = "14"
  4925. break
  4926. case 5:
  4927. item.MedChrgitmType = "08"
  4928. break
  4929. case 6:
  4930. item.MedChrgitmType = "14"
  4931. break
  4932. case 7:
  4933. item.MedChrgitmType = "14"
  4934. break
  4935. case 8:
  4936. item.MedChrgitmType = "03"
  4937. break
  4938. case 9:
  4939. item.MedChrgitmType = "14"
  4940. break
  4941. }
  4942. }
  4943. } else if item.HisPrescriptionProject.Type == 3 {
  4944. item.MedChrgitmType = "08"
  4945. }
  4946. }
  4947. }
  4948. for _, item := range order_info {
  4949. if org_id == 10215 {
  4950. if item.MedChrgitmType == "01" { //床位费
  4951. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4952. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4953. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4954. }
  4955. if item.MedChrgitmType == "02" { //诊察费
  4956. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4957. //zhenChaCostSelfTotal = zhenChaCostTotal
  4958. }
  4959. if item.MedChrgitmType == "03" { //检查费
  4960. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4961. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4962. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4963. }
  4964. //if item.MedChrgitmType == "02" { //检查费
  4965. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4966. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4967. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4968. //}
  4969. if item.MedChrgitmType == "04" { //化验费
  4970. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4971. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4972. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4973. }
  4974. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4975. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4976. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4977. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4978. }
  4979. if item.MedChrgitmType == "06" { //手术费
  4980. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4981. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4982. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4983. }
  4984. if item.MedChrgitmType == "08" { //材料费
  4985. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4986. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4987. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4988. }
  4989. if item.MedChrgitmType == "09" { //西药费
  4990. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4991. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4992. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4993. }
  4994. if item.MedChrgitmType == "11" { //中成费
  4995. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4996. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4997. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4998. }
  4999. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5000. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5001. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5002. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5003. }
  5004. } else {
  5005. if item.MedChrgitmType == "01" { //床位费
  5006. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5007. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5008. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5009. }
  5010. //if item.MedChrgitmType == "02" { //诊察费
  5011. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5012. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5013. //}
  5014. if item.MedChrgitmType == "03" { //检查费
  5015. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5016. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5017. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5018. }
  5019. //if item.MedChrgitmType == "02" { //检查费
  5020. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5021. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5022. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5023. //}
  5024. if item.MedChrgitmType == "04" { //化验费
  5025. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5026. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5027. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5028. }
  5029. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5030. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5031. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5032. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5033. }
  5034. if item.MedChrgitmType == "06" { //手术费
  5035. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5036. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5037. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5038. }
  5039. if item.MedChrgitmType == "08" { //材料费
  5040. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5041. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5042. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5043. }
  5044. if item.MedChrgitmType == "09" { //西药费
  5045. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5046. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5047. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5048. }
  5049. if item.MedChrgitmType == "11" { //中成费
  5050. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5051. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5052. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5053. }
  5054. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5055. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5056. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5057. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5058. }
  5059. }
  5060. }
  5061. c.ServeSuccessJSON(map[string]interface{}{
  5062. "order": order,
  5063. "order_info": order_info,
  5064. "patient": patient,
  5065. "admin_info": adminInfo,
  5066. "his_hospital": record,
  5067. "bedCostTotal": bedCostTotal,
  5068. "operationCostTotal": operationCostTotal,
  5069. "otherCostTotal": otherCostTotal,
  5070. "materialCostTotal": materialCostTotal,
  5071. "westernMedicineCostTotal": westernMedicineCostTotal,
  5072. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5073. "checkCostTotal": checkCostTotal,
  5074. "zhenChaCostTotal": zhenChaCostTotal,
  5075. "laboratoryCostTotal": laboratoryCostTotal,
  5076. "treatCostTotal": treatCostTotal,
  5077. })
  5078. }
  5079. }
  5080. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5081. page, _ := c.GetInt64("page")
  5082. limit, _ := c.GetInt64("limit")
  5083. keywords := c.GetString("keywords")
  5084. start_time := c.GetString("start_time")
  5085. end_time := c.GetString("end_time")
  5086. //clr_type := c.GetString("clr_type")
  5087. insutype := c.GetString("insutype")
  5088. timeLayout := "2006-01-02"
  5089. loc, _ := time.LoadLocation("Local")
  5090. var theStartTIme int64
  5091. if len(start_time) > 0 {
  5092. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5093. theStartTIme = theTime.Unix()
  5094. }
  5095. var theEndtTIme int64
  5096. if len(end_time) > 0 {
  5097. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5098. theEndtTIme = theTime.Unix()
  5099. }
  5100. if page <= 0 {
  5101. page = 1
  5102. }
  5103. if limit <= 0 {
  5104. limit = 10
  5105. }
  5106. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5107. c.ServeSuccessJSON(map[string]interface{}{
  5108. "total": total,
  5109. "list": list,
  5110. })
  5111. return
  5112. }
  5113. func (c *HisApiController) GetPutOnRecordList() {
  5114. page, _ := c.GetInt64("page")
  5115. limit, _ := c.GetInt64("limit")
  5116. keywords := c.GetString("keywords")
  5117. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5118. if page <= 0 {
  5119. page = 1
  5120. }
  5121. if limit <= 0 {
  5122. limit = 10
  5123. }
  5124. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5125. c.ServeSuccessJSON(map[string]interface{}{
  5126. "total": total,
  5127. "list": list,
  5128. })
  5129. return
  5130. }
  5131. func (c *HisApiController) GetCompareData() {
  5132. start_time := c.GetString("start_time")
  5133. end_time := c.GetString("end_time")
  5134. insutype := c.GetString("insutype")
  5135. clr_type := c.GetString("clr_type")
  5136. timeLayout := "2006-01-02"
  5137. loc, _ := time.LoadLocation("Local")
  5138. var theStartTIme int64
  5139. if len(start_time) > 0 {
  5140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5141. if err != nil {
  5142. theStartTIme = 0
  5143. }
  5144. theStartTIme = theTime.Unix()
  5145. }
  5146. var theEndtTIme int64
  5147. if len(end_time) > 0 {
  5148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5149. if err != nil {
  5150. theEndtTIme = 0
  5151. }
  5152. theEndtTIme = theTime.Unix()
  5153. }
  5154. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5155. fmt.Println(err)
  5156. if err == nil {
  5157. c.ServeSuccessJSON(map[string]interface{}{
  5158. "list": formData,
  5159. })
  5160. } else {
  5161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5162. return
  5163. }
  5164. }
  5165. func (c *HisApiController) GetFaPiaoData() {
  5166. order_id, _ := c.GetInt64("order_id")
  5167. patient_id, _ := c.GetInt64("patient_id")
  5168. number := c.GetString("number")
  5169. adminUser := c.GetAdminUserInfo()
  5170. order, _ := service.GetHisOrderByID(order_id)
  5171. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5172. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5173. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5174. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5175. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5176. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5177. var bedCostTotal float64 = 0 //床位总费
  5178. var bedCostSelfTotal float64 = 0 //床位自费
  5179. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5180. var operationCostTotal float64 = 0 //手术费
  5181. var operationCostSelfTotal float64 = 0 //手术费
  5182. var operationCostPartSelfTotal float64 = 0 //手术费
  5183. var otherCostTotal float64 = 0 //其他费用
  5184. var otherCostSelfTotal float64 = 0 //其他费用
  5185. var otherCostPartSelfTotal float64 = 0 //其他费用
  5186. var materialCostTotal float64 = 0 //材料费
  5187. var materialCostSelfTotal float64 = 0 //材料费
  5188. var materialCostPartSelfTotal float64 = 0 //材料费
  5189. var westernMedicineCostTotal float64 = 0 //西药费
  5190. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5191. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5192. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5193. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5194. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5195. var checkCostTotal float64 = 0 //检查费
  5196. var checkCostSelfTotal float64 = 0 //检查费
  5197. var checkCostPartSelfTotal float64 = 0 //检查费
  5198. var laboratoryCostTotal float64 = 0 //化验费
  5199. var laboratoryCostSelfTotal float64 = 0 //化验费
  5200. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5201. var treatCostTotal float64 = 0 //治疗费用
  5202. var treatCostSelfTotal float64 = 0 //治疗费用
  5203. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5204. var zhenChaCostTotal float64 = 0 //其他费用
  5205. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5206. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5207. decimal.DivisionPrecision = 2
  5208. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5209. var balanceAccountsType int64
  5210. if his.ID > 0 {
  5211. balanceAccountsType = his.BalanceAccountsType
  5212. } else {
  5213. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5214. }
  5215. if balanceAccountsType == 2 {
  5216. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5217. for _, item := range orderInfos_two {
  5218. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5219. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5220. item.MedChrgitmType = "09"
  5221. }
  5222. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5223. if item.HisPrescriptionProject.Type == 2 {
  5224. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5225. fmt.Println("CostClassify")
  5226. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  5227. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5228. case 0:
  5229. item.MedChrgitmType = "0"
  5230. break
  5231. case 1:
  5232. item.MedChrgitmType = "14"
  5233. break
  5234. case 2:
  5235. item.MedChrgitmType = "05"
  5236. break
  5237. case 3:
  5238. item.MedChrgitmType = "03"
  5239. break
  5240. case 4:
  5241. item.MedChrgitmType = "03"
  5242. break
  5243. case 5:
  5244. item.MedChrgitmType = "08"
  5245. break
  5246. case 6:
  5247. item.MedChrgitmType = "14"
  5248. break
  5249. case 7:
  5250. item.MedChrgitmType = "14"
  5251. break
  5252. case 8:
  5253. item.MedChrgitmType = "03"
  5254. break
  5255. case 9:
  5256. item.MedChrgitmType = "14"
  5257. break
  5258. case 10:
  5259. item.MedChrgitmType = "14"
  5260. break
  5261. case 11:
  5262. item.MedChrgitmType = "06"
  5263. break
  5264. case 12:
  5265. item.MedChrgitmType = "12"
  5266. break
  5267. case 13:
  5268. item.MedChrgitmType = "01"
  5269. break
  5270. case 14:
  5271. item.MedChrgitmType = "04"
  5272. break
  5273. case 15:
  5274. item.MedChrgitmType = "02"
  5275. break
  5276. }
  5277. } else {
  5278. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5279. case 1:
  5280. item.MedChrgitmType = "14"
  5281. break
  5282. case 2:
  5283. item.MedChrgitmType = "05"
  5284. break
  5285. case 3:
  5286. item.MedChrgitmType = "03"
  5287. break
  5288. case 4:
  5289. item.MedChrgitmType = "03"
  5290. break
  5291. case 5:
  5292. item.MedChrgitmType = "08"
  5293. break
  5294. case 6:
  5295. item.MedChrgitmType = "14"
  5296. break
  5297. case 7:
  5298. item.MedChrgitmType = "14"
  5299. break
  5300. case 8:
  5301. item.MedChrgitmType = "03"
  5302. break
  5303. case 9:
  5304. item.MedChrgitmType = "14"
  5305. break
  5306. }
  5307. }
  5308. } else if item.HisPrescriptionProject.Type == 3 {
  5309. item.MedChrgitmType = "08"
  5310. }
  5311. }
  5312. }
  5313. for _, item := range orderInfos_two {
  5314. fmt.Println(item.MedChrgitmType)
  5315. if item.MedChrgitmType == "01" { //床位费
  5316. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5317. bedCostSelfTotal = bedCostTotal
  5318. }
  5319. if item.MedChrgitmType == "02" { //诊察费
  5320. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5321. zhenChaCostSelfTotal = zhenChaCostTotal
  5322. }
  5323. if item.MedChrgitmType == "03" { //检查费
  5324. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5325. checkCostSelfTotal = checkCostTotal
  5326. }
  5327. if item.MedChrgitmType == "04" { //化验费
  5328. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5329. laboratoryCostSelfTotal = laboratoryCostTotal
  5330. }
  5331. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5332. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5333. treatCostSelfTotal = treatCostTotal
  5334. }
  5335. if item.MedChrgitmType == "06" { //手术费
  5336. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5337. operationCostSelfTotal = treatCostTotal
  5338. }
  5339. if item.MedChrgitmType == "08" { //材料费
  5340. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5341. materialCostSelfTotal = materialCostTotal
  5342. }
  5343. if item.MedChrgitmType == "09" { //西药费
  5344. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5345. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5346. }
  5347. if item.MedChrgitmType == "11" { //中成费
  5348. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5349. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5350. }
  5351. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5352. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5353. otherCostSelfTotal = otherCostTotal
  5354. }
  5355. }
  5356. } else {
  5357. for _, item := range orderInfos {
  5358. if item.MedChrgitmType == "01" { //床位费
  5359. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5360. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5361. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5362. }
  5363. if item.MedChrgitmType == "02" { //诊察费
  5364. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5365. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5366. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5367. }
  5368. if c.GetAdminUserInfo().CurrentOrgId == 10188 {
  5369. if item.MedChrgitmType == "03" { //检查费
  5370. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5371. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5372. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5373. }
  5374. } else {
  5375. if item.MedChrgitmType == "03" { //检查费
  5376. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5377. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5378. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5379. }
  5380. }
  5381. if item.MedChrgitmType == "04" { //化验费
  5382. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5383. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5384. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5385. }
  5386. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5387. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5388. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5389. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5390. }
  5391. if item.MedChrgitmType == "06" { //手术费
  5392. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5393. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5394. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5395. }
  5396. if item.MedChrgitmType == "08" { //材料费
  5397. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5398. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5399. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5400. }
  5401. if item.MedChrgitmType == "09" { //西药费
  5402. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5403. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5404. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5405. }
  5406. if item.MedChrgitmType == "11" { //中成费
  5407. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5408. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5409. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5410. }
  5411. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5412. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5413. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5414. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5415. }
  5416. }
  5417. }
  5418. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5419. c.ServeSuccessJSON(map[string]interface{}{
  5420. "order_number": order.Number, //业务流水号
  5421. "id_card_no": his.IdCardNo, //社会保障号
  5422. "department_name": department.Name, //科室
  5423. "number": his.Number, //门诊号
  5424. "date": order.SettleAccountsDate, //结算日期
  5425. "name": order.PsnName, //姓名
  5426. "gender": order.Gend, //性别
  5427. "psn_cash_money": order.PsnCashPay, //个人支付
  5428. "pay_way": "门诊", //结算方式
  5429. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5430. "admin_user_name": admin.UserName, //收款员
  5431. "order": order,
  5432. "order_info": orderInfos_two,
  5433. "his": his,
  5434. "bedCostTotal": bedCostTotal,
  5435. "bedCostSelfTotal": bedCostSelfTotal,
  5436. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5437. "operationCostTotal": operationCostTotal,
  5438. "operationCostSelfTotal": operationCostSelfTotal,
  5439. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5440. "otherCostTotal": otherCostTotal,
  5441. "otherCostSelfTotal": otherCostSelfTotal,
  5442. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5443. "materialCostTotal": materialCostTotal,
  5444. "materialCostSelfTotal": materialCostSelfTotal,
  5445. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5446. "westernMedicineCostTotal": westernMedicineCostTotal,
  5447. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5448. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5449. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5450. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5451. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5452. "checkCostTotal": checkCostTotal,
  5453. "checkCostSelfTotal": checkCostSelfTotal,
  5454. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5455. "laboratoryCostTotal": laboratoryCostTotal,
  5456. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5457. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5458. "treatCostTotal": treatCostTotal,
  5459. "treatCostSelfTotal": treatCostSelfTotal,
  5460. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5461. "zhenChaCostTotal": zhenChaCostTotal,
  5462. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5463. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5464. "his_hospital_record": his_hospital_record,
  5465. })
  5466. }
  5467. func (this *HisApiController) GetIncomeStatisticsData() {
  5468. start_time := this.GetString("start_time")
  5469. end_time := this.GetString("end_time")
  5470. key_words := this.GetString("key_words")
  5471. limit, _ := this.GetInt64("limit")
  5472. page, _ := this.GetInt64("page")
  5473. if page <= 0 {
  5474. page = 1
  5475. }
  5476. if limit <= 0 {
  5477. limit = 10
  5478. }
  5479. statistics_type, _ := this.GetInt64("statistics_type")
  5480. admin := this.GetAdminUserInfo()
  5481. timeLayout := "2006-01-02"
  5482. loc, _ := time.LoadLocation("Local")
  5483. var theStartTIme int64
  5484. if len(start_time) > 0 {
  5485. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5486. if err != nil {
  5487. theStartTIme = 0
  5488. }
  5489. theStartTIme = theTime.Unix()
  5490. }
  5491. var theEndtTIme int64
  5492. if len(end_time) > 0 {
  5493. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5494. if err != nil {
  5495. theEndtTIme = 0
  5496. }
  5497. theEndtTIme = theTime.Unix()
  5498. }
  5499. if statistics_type == 1 {
  5500. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5501. this.ServeSuccessJSON(map[string]interface{}{
  5502. "list": list,
  5503. "total": total,
  5504. })
  5505. } else {
  5506. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5507. this.ServeSuccessJSON(map[string]interface{}{
  5508. "list": list,
  5509. "total": total,
  5510. })
  5511. }
  5512. }
  5513. func (c *HisApiController) PostProjectInformation() {
  5514. adminUser := c.GetAdminUserInfo()
  5515. orgId := adminUser.CurrentOrgId
  5516. dataBody := make(map[string]interface{}, 0)
  5517. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5518. if err != nil {
  5519. utils.ErrorLog(err.Error())
  5520. return
  5521. }
  5522. utils.ErrorLog("%v", dataBody)
  5523. var projectList []*models.HisProject
  5524. var total_goods []interface{}
  5525. tempProjects := dataBody["projects"].([]interface{})
  5526. total_goods = tempProjects
  5527. for index, projectMap := range tempProjects {
  5528. projectM := projectMap.(map[string]interface{})
  5529. var project models.HisProject
  5530. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5531. utils.ErrorLog("project_name")
  5532. return
  5533. }
  5534. project_name, _ := projectM["project_name"].(string)
  5535. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5536. err_log := models.ExportErrLog{
  5537. LogType: 6,
  5538. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5539. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5540. Status: 1,
  5541. CreateTime: time.Now().Unix(),
  5542. UpdateTime: time.Now().Unix(),
  5543. ExportTime: time.Now().Unix(),
  5544. }
  5545. service.CreateExportErrLog(&err_log)
  5546. continue
  5547. }
  5548. project.ProjectName = project_name
  5549. prices := projectM["price"].(string)
  5550. price, _ := strconv.ParseFloat(prices, 64)
  5551. if price <= 0 { //名字为空则生成一条导入错误日志
  5552. err_log := models.ExportErrLog{
  5553. LogType: 6,
  5554. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5555. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5556. Status: 1,
  5557. CreateTime: time.Now().Unix(),
  5558. UpdateTime: time.Now().Unix(),
  5559. ExportTime: time.Now().Unix(),
  5560. }
  5561. service.CreateExportErrLog(&err_log)
  5562. continue
  5563. }
  5564. project.Price = price
  5565. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5566. utils.ErrorLog("unit_id")
  5567. return
  5568. }
  5569. unit := projectM["unit"].(string)
  5570. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5571. err_log := models.ExportErrLog{
  5572. LogType: 6,
  5573. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5574. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5575. Status: 1,
  5576. CreateTime: time.Now().Unix(),
  5577. UpdateTime: time.Now().Unix(),
  5578. ExportTime: time.Now().Unix(),
  5579. }
  5580. service.CreateExportErrLog(&err_log)
  5581. continue
  5582. }
  5583. project.Unit = unit
  5584. cost_classify := projectM["cost_classify"].(string)
  5585. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5586. err_log := models.ExportErrLog{
  5587. LogType: 6,
  5588. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5589. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5590. Status: 1,
  5591. CreateTime: time.Now().Unix(),
  5592. UpdateTime: time.Now().Unix(),
  5593. ExportTime: time.Now().Unix(),
  5594. }
  5595. service.CreateExportErrLog(&err_log)
  5596. continue
  5597. }
  5598. var costClassify = "费用类别"
  5599. var cost_classify_id int64
  5600. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5601. if len(cost_classify) != 0 {
  5602. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5603. if errcode == gorm.ErrRecordNotFound {
  5604. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5605. dataconfig := models.DictDataconfig{
  5606. ParentId: costClassifyConfig.ID,
  5607. Module: "system",
  5608. OrgId: orgId,
  5609. Name: cost_classify,
  5610. FieldName: "",
  5611. Value: costConfig.Value + 1,
  5612. CreatedTime: "",
  5613. UpdatedTime: "",
  5614. CreateUserId: adminUser.AdminUser.Id,
  5615. Status: 1,
  5616. Remark: "",
  5617. DeleteIdSystem: 0,
  5618. Title: "",
  5619. Content: "",
  5620. Order: 0,
  5621. Code: "",
  5622. }
  5623. service.CreatedDicConfig(&dataconfig)
  5624. }
  5625. }
  5626. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5627. for _, it := range costClassList {
  5628. if cost_classify == it.Name {
  5629. cost_classify_id = int64(it.Value)
  5630. }
  5631. }
  5632. project.CostClassify = cost_classify_id
  5633. executive_section := projectM["executive_section"].(string)
  5634. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5635. err_log := models.ExportErrLog{
  5636. LogType: 6,
  5637. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5638. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5639. Status: 1,
  5640. CreateTime: time.Now().Unix(),
  5641. UpdateTime: time.Now().Unix(),
  5642. ExportTime: time.Now().Unix(),
  5643. }
  5644. service.CreateExportErrLog(&err_log)
  5645. continue
  5646. }
  5647. if len(executive_section) != 0 {
  5648. //查找科室是否有内容
  5649. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5650. if errcodedepart == gorm.ErrRecordNotFound {
  5651. department := models.XtHisDepartment{
  5652. Name: executive_section,
  5653. Status: 1,
  5654. UserOrgId: adminUser.CurrentOrgId,
  5655. CreatedTime: time.Now().Unix(),
  5656. }
  5657. service.CreateDePartment(&department)
  5658. }
  5659. }
  5660. var executive_section_id int64
  5661. departMentList, _ := service.GetAllDepartMent(orgId)
  5662. for _, it := range departMentList {
  5663. if executive_section == it.Name {
  5664. executive_section_id = it.ID
  5665. }
  5666. }
  5667. project.ExecutiveSection = executive_section_id
  5668. medical_coverage := projectM["medical_coverage"].(string)
  5669. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5670. err_log := models.ExportErrLog{
  5671. LogType: 6,
  5672. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5673. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5674. Status: 1,
  5675. CreateTime: time.Now().Unix(),
  5676. UpdateTime: time.Now().Unix(),
  5677. ExportTime: time.Now().Unix(),
  5678. }
  5679. service.CreateExportErrLog(&err_log)
  5680. continue
  5681. }
  5682. var medicalCoverage = "医保等级"
  5683. var medical_coverage_id int64
  5684. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5685. if len(medical_coverage) != 0 {
  5686. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5687. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5688. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5689. dataconfig := models.DictDataconfig{
  5690. ParentId: medicalCoverageConfig.ID,
  5691. Module: "system",
  5692. OrgId: orgId,
  5693. Name: medical_coverage,
  5694. FieldName: "",
  5695. Value: medicalCoverageConfig.Value + 1,
  5696. CreatedTime: "",
  5697. UpdatedTime: "",
  5698. CreateUserId: adminUser.AdminUser.Id,
  5699. Status: 1,
  5700. Remark: "",
  5701. DeleteIdSystem: 0,
  5702. Title: "",
  5703. Content: "",
  5704. Order: 0,
  5705. Code: "",
  5706. }
  5707. service.CreatedDicConfig(&dataconfig)
  5708. }
  5709. }
  5710. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5711. for _, it := range medicalCoverageList {
  5712. if medical_coverage == it.Name {
  5713. medical_coverage_id = int64(it.Value)
  5714. }
  5715. }
  5716. project.MedicalCoverage = medical_coverage_id
  5717. pinyin := projectM["pinyin"].(string)
  5718. project.Pinyin = pinyin
  5719. wubi := projectM["wubi"].(string)
  5720. project.Wubi = wubi
  5721. statistical_classification := projectM["statistical_classification"].(string)
  5722. var statisticalClassification = "统计分类"
  5723. var statistical_classification_id int64
  5724. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5725. if len(statistical_classification) != 0 {
  5726. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5727. if classificationerrcodes == gorm.ErrRecordNotFound {
  5728. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5729. dataconfig := models.DictDataconfig{
  5730. ParentId: classiFication.ID,
  5731. Module: "system",
  5732. OrgId: orgId,
  5733. Name: statistical_classification,
  5734. FieldName: "",
  5735. Value: classiFicationConfig.Value + 1,
  5736. CreatedTime: "",
  5737. UpdatedTime: "",
  5738. CreateUserId: adminUser.AdminUser.Id,
  5739. Status: 1,
  5740. Remark: "",
  5741. DeleteIdSystem: 0,
  5742. Title: "",
  5743. Content: "",
  5744. Order: 0,
  5745. Code: "",
  5746. }
  5747. service.CreatedDicConfig(&dataconfig)
  5748. }
  5749. }
  5750. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5751. for _, it := range classiFicationList {
  5752. if statistical_classification == it.Name {
  5753. statistical_classification_id = int64(it.Value)
  5754. }
  5755. }
  5756. project.StatisticalClassification = statistical_classification_id
  5757. disease_directory := int64(projectM["disease_directory"].(float64))
  5758. project.DiseaseDirectory = disease_directory
  5759. is_record := int64(projectM["is_record"].(float64))
  5760. project.IsRecord = is_record
  5761. medical_code := projectM["medical_code"].(string)
  5762. project.MedicalCode = medical_code
  5763. tube_color := projectM["tube_color"].(string)
  5764. var tubeColor = "试管颜色"
  5765. var tube_color_id int64
  5766. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5767. if len(tube_color) != 0 {
  5768. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5769. if errcodetube == gorm.ErrRecordNotFound {
  5770. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5771. dataconfig := models.DictDataconfig{
  5772. ParentId: tubeColorConfig.ID,
  5773. Module: "system",
  5774. OrgId: orgId,
  5775. Name: tube_color,
  5776. FieldName: "",
  5777. Value: tubeConfig.Value + 1,
  5778. CreatedTime: "",
  5779. UpdatedTime: "",
  5780. CreateUserId: adminUser.AdminUser.Id,
  5781. Status: 1,
  5782. Remark: "",
  5783. DeleteIdSystem: 0,
  5784. Title: "",
  5785. Content: "",
  5786. Order: 0,
  5787. Code: "",
  5788. }
  5789. service.CreatedDicConfig(&dataconfig)
  5790. }
  5791. }
  5792. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5793. for _, it := range tubeColorList {
  5794. if tube_color == it.Name {
  5795. tube_color_id = int64(it.Value)
  5796. }
  5797. }
  5798. project.TubeColor = tube_color_id
  5799. single_dose := projectM["single_dose"].(string)
  5800. project.SingleDose = single_dose
  5801. execution_frequency := projectM["execution_frequency"].(string)
  5802. project.ExecutionFrequency = execution_frequency
  5803. delivery_way := projectM["delivery_way"].(string)
  5804. project.DeliveryWay = delivery_way
  5805. number_days := projectM["number_days"].(string)
  5806. project.NumberDays = number_days
  5807. total := projectM["total"].(string)
  5808. project.Total = total
  5809. medical_status := int64(projectM["medical_status"].(float64))
  5810. project.MedicalStatus = medical_status
  5811. category := int64(projectM["category"].(float64))
  5812. project.Category = category
  5813. specail_project := int64(projectM["specail_project"].(float64))
  5814. project.SpecailProject = specail_project
  5815. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5816. project.SocialSecurityDirectoryCode = social_security_directory_code
  5817. remark := projectM["remark"].(string)
  5818. project.Remark = remark
  5819. record_date := projectM["record_date"].(string)
  5820. timeLayout := "2006-01-02"
  5821. loc, _ := time.LoadLocation("Local")
  5822. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5823. project.RecordDate = theTime.Unix()
  5824. projectList = append(projectList, &project)
  5825. }
  5826. export_time := time.Now().Unix()
  5827. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5828. if len(projectList) > 0 {
  5829. for _, item := range projectList {
  5830. project := models.HisProject{
  5831. ProjectName: item.ProjectName,
  5832. Price: item.Price,
  5833. Unit: item.Unit,
  5834. CostClassify: item.CostClassify,
  5835. ExecutiveSection: item.ExecutiveSection,
  5836. MedicalCoverage: item.MedicalCoverage,
  5837. UserOrgId: orgId,
  5838. Status: 1,
  5839. CreatedTime: time.Now().Unix(),
  5840. Pinyin: item.Pinyin,
  5841. Wubi: item.Wubi,
  5842. StatisticalClassification: item.StatisticalClassification,
  5843. DiseaseDirectory: item.DiseaseDirectory,
  5844. IsRecord: item.IsRecord,
  5845. MedicalCode: item.MedicalCode,
  5846. TubeColor: item.TubeColor,
  5847. SingleDose: item.SingleDose,
  5848. DeliveryWay: item.DeliveryWay,
  5849. NumberDays: item.NumberDays,
  5850. Total: item.Total,
  5851. Category: item.Category,
  5852. MedicalStatus: item.MedicalStatus,
  5853. SpecailProject: item.SpecailProject,
  5854. RecordDate: item.RecordDate,
  5855. Remark: item.Remark,
  5856. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5857. ExecutionFrequency: item.ExecutionFrequency,
  5858. }
  5859. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5860. if errcodeproject == gorm.ErrRecordNotFound {
  5861. service.CreateProjectInfomation(&project)
  5862. } else if errcodeproject == nil {
  5863. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5864. }
  5865. log := models.ExportLog{
  5866. LogType: 6,
  5867. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5868. TotalNum: int64(len(total_goods)),
  5869. FailNum: int64(len(errLogs)),
  5870. SuccessNum: int64(len(projectList)),
  5871. CreateTime: time.Now().Unix(),
  5872. UpdateTime: time.Now().Unix(),
  5873. ExportTime: export_time,
  5874. Status: 1,
  5875. }
  5876. service.CreateExportLog(&log)
  5877. c.ServeSuccessJSON(map[string]interface{}{
  5878. "msg": "导入成功",
  5879. "total_num": len(total_goods),
  5880. "success_num": len(projectList),
  5881. "fail_num": int64(len(errLogs)),
  5882. })
  5883. }
  5884. } else {
  5885. log := models.ExportLog{
  5886. LogType: 6,
  5887. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5888. TotalNum: int64(len(total_goods)),
  5889. FailNum: int64(len(errLogs)),
  5890. SuccessNum: int64(len(projectList)),
  5891. CreateTime: time.Now().Unix(),
  5892. UpdateTime: time.Now().Unix(),
  5893. ExportTime: export_time,
  5894. Status: 1,
  5895. }
  5896. service.CreateExportLog(&log)
  5897. c.ServeSuccessJSON(map[string]interface{}{
  5898. "msg": "导入成功",
  5899. "total_num": len(total_goods),
  5900. "success_num": len(projectList),
  5901. "fail_num": int64(len(errLogs)),
  5902. })
  5903. }
  5904. }
  5905. //func (this *HisApiController) EditProjectInformation(){
  5906. //
  5907. // id, _ := this.GetInt64("id")
  5908. // project_team := this.GetString("project_team")
  5909. // price := this.GetString("price")
  5910. // price_float, _ := strconv.ParseFloat(price, 64)
  5911. // pinyin := this.GetString("pinyin")
  5912. // wubi := this.GetString("wubi")
  5913. // tube_color, _ := this.GetInt64("tube_color")
  5914. // team_type, _ := this.GetInt64("team_type")
  5915. // remark := this.GetString("remark")
  5916. // ids := this.GetString("ids")
  5917. // item_id := this.GetString("item_id")
  5918. // projectTeam := models.XtHisProjectTeam{
  5919. // ProjectTeam: project_team,
  5920. // Price: price_float,
  5921. // Pinyin: pinyin,
  5922. // Wubi: wubi,
  5923. // TubeColor: tube_color,
  5924. // TeamType: team_type,
  5925. // Remark: remark,
  5926. // ProjectId: ids,
  5927. // ItemId: item_id,
  5928. // }
  5929. //
  5930. //
  5931. // dataBody := make(map[string]interface{}, 0)
  5932. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5933. // if err != nil {
  5934. // utils.ErrorLog(err.Error())
  5935. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5936. // return
  5937. // }
  5938. //
  5939. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5940. //
  5941. //
  5942. // if err != nil {
  5943. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5944. // return
  5945. // }
  5946. //
  5947. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5948. // infos, _ := dataBody["info"].([]interface{})
  5949. // if len(infos) > 0 {
  5950. // var ids []string
  5951. //
  5952. // for _, item := range infos {
  5953. // items := item.(map[string]interface{})
  5954. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5955. // utils.ErrorLog("id")
  5956. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5957. // return
  5958. // }
  5959. // id := int64(items["id"].(float64))
  5960. //
  5961. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5962. // utils.ErrorLog("type")
  5963. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5964. // return
  5965. // }
  5966. // types := int64(items["type"].(float64))
  5967. //
  5968. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5969. // utils.ErrorLog("number")
  5970. // }
  5971. //
  5972. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5973. //
  5974. // projectList := models.XtHisProjectList{
  5975. // Number: number,
  5976. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5977. // ProjectId: id,
  5978. // Status: 1,
  5979. // CreatedTime: time.Now().Unix(),
  5980. // UpdatedTime: time.Now().Unix(),
  5981. // TeamId: projectTeam.ID,
  5982. // Type: types,
  5983. // }
  5984. // list := projectList
  5985. //
  5986. // service.CreateProjectList(&list)
  5987. //
  5988. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  5989. //
  5990. // }
  5991. // ids_str := strings.Join(ids, ",")
  5992. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  5993. // service.SaveProjectTeam(&projectTeam)
  5994. // this.ServeSuccessJSON(map[string]interface{}{
  5995. // "projectTeam": projectTeam,
  5996. // })
  5997. // }
  5998. // }
  5999. //}
  6000. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6001. name := c.GetString("name")
  6002. mode_id, _ := c.GetInt64("mode", 0)
  6003. types, _ := c.GetInt64("type", 0)
  6004. patient_id, _ := c.GetInt64("patient_id", 0)
  6005. types = 1
  6006. adminInfo := c.GetAdminUserInfo()
  6007. template := &models.HisPrescriptionTemplate{
  6008. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6009. PatientId: patient_id,
  6010. Type: types,
  6011. Status: 1,
  6012. Ctime: time.Now().Unix(),
  6013. Mtime: time.Now().Unix(),
  6014. Name: name,
  6015. Mode: mode_id,
  6016. }
  6017. dataBody := make(map[string]interface{}, 0)
  6018. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6019. if err != nil {
  6020. utils.ErrorLog(err.Error())
  6021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6022. return
  6023. }
  6024. err = service.CreateHisPrescriptionTemplate(template)
  6025. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6026. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6027. if len(prescriptions) > 0 {
  6028. for _, item := range prescriptions {
  6029. items := item.(map[string]interface{})
  6030. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6031. utils.ErrorLog("type")
  6032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6033. return
  6034. }
  6035. types := int64(items["type"].(float64))
  6036. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6037. utils.ErrorLog("med_type")
  6038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6039. return
  6040. }
  6041. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6042. ctime := time.Now().Unix()
  6043. prescription := &models.HisPrescriptionInfoTemplate{
  6044. PatientId: patient_id,
  6045. UserOrgId: adminInfo.CurrentOrgId,
  6046. Ctime: ctime,
  6047. Mtime: ctime,
  6048. Type: types,
  6049. Modifier: adminInfo.AdminUser.Id,
  6050. Creator: adminInfo.AdminUser.Id,
  6051. Status: 1,
  6052. PTemplateId: template.ID,
  6053. MedType: med_type,
  6054. }
  6055. service.CreateHisPrescriptionInfoTemplate(prescription)
  6056. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6057. advices := items["advices"].([]interface{})
  6058. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6059. ctime := time.Now().Unix()
  6060. mtime := ctime
  6061. if len(advices) > 0 {
  6062. for _, advice := range advices {
  6063. var s models.HisPrescriptionAdviceTemplate
  6064. s.PrescriptionId = prescription.ID
  6065. s.AdviceType = 2
  6066. s.StopState = 2
  6067. s.ExecutionState = 2
  6068. s.Status = 1
  6069. s.UserOrgId = adminInfo.CurrentOrgId
  6070. s.CreatedTime = ctime
  6071. s.UpdatedTime = mtime
  6072. s.PatientId = patient_id
  6073. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6074. if errcode > 0 {
  6075. c.ServeFailJSONWithSGJErrorCode(errcode)
  6076. return
  6077. }
  6078. service.CreateHisPrescriptionAdviceTemplate(&s)
  6079. }
  6080. }
  6081. }
  6082. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6083. projects := items["project"].([]interface{})
  6084. if len(projects) > 0 {
  6085. for _, project := range projects {
  6086. var p models.HisPrescriptionProjectTemplate
  6087. p.PrescriptionId = prescription.ID
  6088. p.Ctime = time.Now().Unix()
  6089. p.Mtime = time.Now().Unix()
  6090. p.PatientId = patient_id
  6091. p.UserOrgId = adminInfo.CurrentOrgId
  6092. p.Status = 1
  6093. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6094. if errcode > 0 {
  6095. c.ServeFailJSONWithSGJErrorCode(errcode)
  6096. return
  6097. }
  6098. service.CreateHisPrescriptionProjectTemplate(&p)
  6099. }
  6100. }
  6101. }
  6102. }
  6103. c.ServeSuccessJSON(map[string]interface{}{
  6104. "msg": "创建成功",
  6105. })
  6106. }
  6107. }
  6108. }
  6109. func (c *HisApiController) PreSettle() {
  6110. id, _ := c.GetInt64("id")
  6111. record_time := c.GetString("record_time")
  6112. his_patient_id, _ := c.GetInt64("his_patient_id")
  6113. timeLayout := "2006-01-02"
  6114. loc, _ := time.LoadLocation("Local")
  6115. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6116. diagnosis_id := c.GetString("diagnosis")
  6117. sick_type, _ := c.GetInt64("sick_type")
  6118. reg_type, _ := c.GetInt64("p_type")
  6119. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6120. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6121. if err != nil {
  6122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6123. return
  6124. }
  6125. recordDateTime := theTime.Unix()
  6126. adminUser := c.GetAdminUserInfo()
  6127. var prescriptions []*models.HisPrescription
  6128. var start_time int64
  6129. var end_time int64
  6130. ids_str := c.GetString("ids")
  6131. ids_arr := strings.Split(ids_str, ",")
  6132. fmt.Println(reg_type)
  6133. if settle_accounts_type == 1 { //日结
  6134. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6135. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6136. } else {
  6137. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6138. }
  6139. fmt.Println(prescriptions)
  6140. } else { //月结
  6141. start_time_str := c.GetString("start_time")
  6142. end_time_str := c.GetString("end_time")
  6143. timeLayout := "2006-01-02"
  6144. loc, _ := time.LoadLocation("Local")
  6145. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6146. if err != nil {
  6147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6148. return
  6149. }
  6150. recordStartTime := theStartTime.Unix()
  6151. start_time = recordStartTime
  6152. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6153. if err != nil {
  6154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6155. return
  6156. }
  6157. recordEndTime := theEndTime.Unix()
  6158. end_time = recordEndTime
  6159. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6160. }
  6161. if reg_type == 1111 || reg_type == 1112 {
  6162. reg_type = 11
  6163. }
  6164. timestamp := time.Now().Unix()
  6165. tempTime := time.Unix(timestamp, 0)
  6166. timeFormat := tempTime.Format("20060102150405")
  6167. chrgBchno := rand.Intn(100000) + 10000
  6168. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6169. strconv.FormatInt(his.PatientId, 10)
  6170. var ids []int64
  6171. for _, item := range prescriptions {
  6172. ids = append(ids, item.ID)
  6173. }
  6174. fmt.Println(ids)
  6175. var total float64
  6176. for _, item := range prescriptions {
  6177. fmt.Println(item)
  6178. if item.Type == 1 { //药品
  6179. for _, subItem := range item.HisDoctorAdviceInfo {
  6180. total = total + (subItem.Price * subItem.PrescribingNumber)
  6181. }
  6182. }
  6183. if item.Type == 2 { //项目
  6184. for _, subItem := range item.HisPrescriptionProject {
  6185. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6186. total = total + (subItem.Price * cnt)
  6187. }
  6188. }
  6189. for _, subItem := range item.HisAdditionalCharge {
  6190. total = total + (subItem.Price * float64(subItem.Count))
  6191. }
  6192. }
  6193. allTotal := fmt.Sprintf("%.2f", total)
  6194. totals, _ := strconv.ParseFloat(allTotal, 64)
  6195. order := &models.HisOrder{
  6196. UserOrgId: adminUser.CurrentOrgId,
  6197. HisPatientId: his.ID,
  6198. PatientId: id,
  6199. SettleAccountsDate: recordDateTime,
  6200. Ctime: time.Now().Unix(),
  6201. Mtime: time.Now().Unix(),
  6202. Status: 1,
  6203. OrderStatus: 1,
  6204. MdtrtId: his.Number,
  6205. Number: chrg_bchno,
  6206. MedfeeSumamt: totals,
  6207. SettleEndTime: end_time,
  6208. SettleStartTime: start_time,
  6209. SettleType: settle_accounts_type,
  6210. PType: 2,
  6211. IsPre: 1,
  6212. MedType: strconv.Itoa(int(reg_type)),
  6213. Diagnosis: diagnosis_id,
  6214. }
  6215. err = service.CreateOrder(order)
  6216. if err != nil {
  6217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6218. return
  6219. }
  6220. var customs []*Custom
  6221. for _, item := range prescriptions {
  6222. fmt.Println(item.Type)
  6223. if item.Type == 1 { //药品
  6224. for _, subItem := range item.HisDoctorAdviceInfo {
  6225. cus := &Custom{
  6226. AdviceId: subItem.ID,
  6227. ProjectId: 0,
  6228. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6229. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6230. FeedetlSn: subItem.FeedetlSn,
  6231. Price: fmt.Sprintf("%.2f", subItem.Price),
  6232. MedListCodg: subItem.MedListCodg,
  6233. Type: 1,
  6234. }
  6235. customs = append(customs, cus)
  6236. }
  6237. }
  6238. if item.Type == 2 { //项目
  6239. for _, subItem := range item.HisPrescriptionProject {
  6240. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6241. cus := &Custom{
  6242. AdviceId: 0,
  6243. ProjectId: subItem.ID,
  6244. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6245. Cut: fmt.Sprintf("%.2f", cnt),
  6246. FeedetlSn: subItem.FeedetlSn,
  6247. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6248. MedListCodg: subItem.MedListCodg,
  6249. Type: 2,
  6250. }
  6251. customs = append(customs, cus)
  6252. }
  6253. }
  6254. for _, item := range item.HisAdditionalCharge {
  6255. cus := &Custom{
  6256. ItemId: item.ID,
  6257. AdviceId: 0,
  6258. ProjectId: 0,
  6259. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6260. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6261. FeedetlSn: item.FeedetlSn,
  6262. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6263. MedListCodg: item.XtHisAddtionConfig.Code,
  6264. Type: 3,
  6265. }
  6266. customs = append(customs, cus)
  6267. }
  6268. }
  6269. fmt.Println(customs)
  6270. for _, item := range customs {
  6271. var advice_id int64 = 0
  6272. var project_id int64 = 0
  6273. var item_id int64 = 0
  6274. var types int64 = 0
  6275. if item.Type == 1 {
  6276. advice_id = item.AdviceId
  6277. project_id = 0
  6278. item_id = 0
  6279. } else if item.Type == 2 {
  6280. advice_id = 0
  6281. item_id = 0
  6282. project_id = item.ProjectId
  6283. } else if item.Type == 3 {
  6284. advice_id = 0
  6285. item_id = item.ItemId
  6286. project_id = 0
  6287. }
  6288. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6289. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6290. pric, _ := strconv.ParseFloat(item.Price, 32)
  6291. info := &models.HisOrderInfo{
  6292. OrderNumber: order.Number,
  6293. UploadDate: time.Now().Unix(),
  6294. AdviceId: advice_id,
  6295. DetItemFeeSumamt: detItemFeeSumamt,
  6296. Cnt: cut,
  6297. Pric: pric,
  6298. PatientId: id,
  6299. Status: 1,
  6300. Mtime: time.Now().Unix(),
  6301. Ctime: time.Now().Unix(),
  6302. UserOrgId: adminUser.CurrentOrgId,
  6303. HisPatientId: his.ID,
  6304. OrderId: order.ID,
  6305. ProjectId: project_id,
  6306. Type: types,
  6307. ItemId: item_id,
  6308. }
  6309. service.CreateOrderInfo(info)
  6310. }
  6311. his.SickType = sick_type
  6312. service.UpdataHisPateint(&his)
  6313. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6314. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6315. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6316. if err == nil {
  6317. c.ServeSuccessJSON(map[string]interface{}{
  6318. "msg": "结算成功",
  6319. })
  6320. }
  6321. }
  6322. type CustomOrderInfo struct {
  6323. Name string
  6324. Spec string
  6325. Unit string
  6326. Count float64
  6327. Price float64
  6328. Total float64
  6329. }
  6330. func (c *HisApiController) GetPrivateExpensesInfo() {
  6331. order_id, _ := c.GetInt64("id", 0)
  6332. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6333. order, _ := service.GetHisOrderByID(order_id)
  6334. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6335. if order.ID == 0 {
  6336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6337. return
  6338. }
  6339. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6340. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6341. org_id := c.GetAdminUserInfo().CurrentOrgId
  6342. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6343. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6344. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6345. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6346. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6347. var orderInfos_four []*models.HisOrderInfoTwo
  6348. for _, item := range orderInfos_three {
  6349. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6350. item.HisPrescriptionProject.IsCheckTeam = 1
  6351. orderInfos_four = append(orderInfos_four, item)
  6352. }
  6353. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6354. item.HisPrescriptionProject.IsCheckTeam = 2
  6355. orderInfos_two = append(orderInfos_two, item)
  6356. }
  6357. }
  6358. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6359. var cus_slice []CustomOrderInfo
  6360. for _, item := range new_order_info {
  6361. var cus CustomOrderInfo
  6362. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6363. cus.Unit = ""
  6364. cus.Spec = ""
  6365. var total float64
  6366. for _, subItem := range orderInfos_four {
  6367. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6368. total = total + subItem.DetItemFeeSumamt
  6369. fmt.Println(subItem.DetItemFeeSumamt)
  6370. }
  6371. }
  6372. cus.Count = 1
  6373. cus.Total = total
  6374. cus_slice = append(cus_slice, cus)
  6375. }
  6376. orderInfos = append(orderInfos, orderInfos_two...)
  6377. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6378. orderInfos = append(orderInfos, orderInfos_three...)
  6379. }
  6380. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6381. c.ServeSuccessJSON(map[string]interface{}{
  6382. "order": order,
  6383. "order_info": orderInfos,
  6384. "patient": patient,
  6385. "admin_info": adminInfo,
  6386. "his": his,
  6387. "current_admin": role,
  6388. "org_config": miConfig,
  6389. "new_order_info": cus_slice,
  6390. })
  6391. }
  6392. func (this *HisApiController) ChangeMedType() {
  6393. med_type := this.GetString("med_type")
  6394. old_med_type := this.GetString("old_med_type")
  6395. ids := this.GetString("ids")
  6396. settle_type, _ := this.GetInt64("settle_type")
  6397. start_time := this.GetString("start_time")
  6398. end_time := this.GetString("end_time")
  6399. ids_arr := strings.Split(ids, ",")
  6400. if settle_type == 1 { //日结
  6401. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6402. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6403. prescription.MedType = med_type
  6404. err := service.SaveHisPrescription(&prescription)
  6405. if err == nil {
  6406. this.ServeSuccessJSON(map[string]interface{}{
  6407. "msg": "修改成功",
  6408. })
  6409. } else {
  6410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6411. return
  6412. }
  6413. } else if settle_type == 2 {
  6414. timeLayout := "2006-01-02"
  6415. loc, _ := time.LoadLocation("Local")
  6416. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6417. if err != nil {
  6418. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6419. return
  6420. }
  6421. recordStartTime := theStartTime.Unix()
  6422. start_time_timestamp := recordStartTime
  6423. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6424. if err != nil {
  6425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6426. return
  6427. }
  6428. recordEndTime := theEndTime.Unix()
  6429. end_time_timestamp := recordEndTime
  6430. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6431. if updateErr == nil {
  6432. this.ServeSuccessJSON(map[string]interface{}{
  6433. "msg": "修改成功",
  6434. })
  6435. } else {
  6436. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6437. return
  6438. }
  6439. }
  6440. }
  6441. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6442. patient_id, _ := c.GetInt64("patient_id")
  6443. his_patient_id, _ := c.GetInt64("his_patient_id")
  6444. record_date := c.GetString("record_date")
  6445. start_time := c.GetString("start_time")
  6446. end_time := c.GetString("end_time")
  6447. order_status, _ := c.GetInt64("type", 0)
  6448. p_type, _ := c.GetInt64("p_type", 0)
  6449. order_id, _ := c.GetInt64("order_id", 0)
  6450. timeLayout := "2006-01-02"
  6451. loc, _ := time.LoadLocation("Local")
  6452. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6453. if err != nil {
  6454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6455. return
  6456. }
  6457. recordDateTime := theTime.Unix()
  6458. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6459. if err != nil {
  6460. }
  6461. startRecordDateTime := startTime.Unix()
  6462. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6463. if err != nil {
  6464. }
  6465. endRecordDateTime := endTime.Unix()
  6466. admin := c.GetAdminUserInfo()
  6467. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6468. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6469. order, _ := service.GetHisOrderByID(order_id)
  6470. var monthPrescriptions []*models.HisPrescription
  6471. if order_status == 1 || order_status == 0 {
  6472. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6473. } else if order_status == 2 {
  6474. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6475. }
  6476. var settle_total float64
  6477. for _, item := range monthPrescriptions {
  6478. if len(item.HisPrescriptionProject) > 0 {
  6479. for _, subItem := range item.HisPrescriptionProject {
  6480. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6481. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6482. settle_total = settle_total + total
  6483. }
  6484. }
  6485. if len(item.HisDoctorAdviceInfo) > 0 {
  6486. for _, subItem := range item.HisDoctorAdviceInfo {
  6487. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6488. settle_total = settle_total + total
  6489. }
  6490. }
  6491. }
  6492. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6493. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6494. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6495. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6496. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6497. //获取所有科室信息
  6498. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6499. c.ServeSuccessJSON(map[string]interface{}{
  6500. "his_info": his_patient_info,
  6501. "xt_info": xt_patient_info,
  6502. "case_history": case_history,
  6503. "info": patientPrescriptionInfo,
  6504. "last_info": lastPatientPrescriptionInfo,
  6505. "month_prescriptions": monthPrescriptions,
  6506. "order": order,
  6507. "doctors": doctors,
  6508. "department": department,
  6509. "settle_total": settle_total,
  6510. })
  6511. return
  6512. }
  6513. func (c *HisApiController) GetHisMonthPatientInfo() {
  6514. patient_id, _ := c.GetInt64("patient_id")
  6515. his_patient_id, _ := c.GetInt64("his_patient_id")
  6516. record_date := c.GetString("record_date")
  6517. number := c.GetString("number")
  6518. start_time := c.GetString("start_time")
  6519. end_time := c.GetString("end_time")
  6520. p_type, _ := c.GetInt64("p_type")
  6521. timeLayout := "2006-01-02"
  6522. loc, _ := time.LoadLocation("Local")
  6523. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6524. if err != nil {
  6525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6526. return
  6527. }
  6528. recordDateTime := theTime.Unix()
  6529. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6530. if err != nil {
  6531. }
  6532. startRecordDateTime := startTime.Unix()
  6533. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6534. if err != nil {
  6535. }
  6536. endRecordDateTime := endTime.Unix()
  6537. admin := c.GetAdminUserInfo()
  6538. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6539. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6540. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6541. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6542. var settle_total float64
  6543. for _, item := range monthPrescriptions {
  6544. if len(item.HisPrescriptionProject) > 0 {
  6545. for _, subItem := range item.HisPrescriptionProject {
  6546. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6547. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6548. settle_total = settle_total + total
  6549. }
  6550. }
  6551. if len(item.HisDoctorAdviceInfo) > 0 {
  6552. for _, subItem := range item.HisDoctorAdviceInfo {
  6553. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6554. settle_total = settle_total + total
  6555. }
  6556. }
  6557. }
  6558. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6559. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6560. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6561. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6562. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6563. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6564. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6565. //获取所有科室信息
  6566. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6567. c.ServeSuccessJSON(map[string]interface{}{
  6568. "his_info": his_patient_info,
  6569. "xt_info": xt_patient_info,
  6570. "case_history": case_history,
  6571. "info": patientPrescriptionInfo,
  6572. "month_prescriptions": monthPrescriptions,
  6573. "order": order,
  6574. "doctors": doctors,
  6575. "department": department,
  6576. "count": count,
  6577. "drugStockConfig": drugStockConfig,
  6578. "last_info": lastPatientPrescriptionInfo,
  6579. "settle_total": settle_total,
  6580. })
  6581. return
  6582. }
  6583. func (c *HisApiController) GetAllOrder() {
  6584. org_id := c.GetAdminUserInfo().CurrentOrgId
  6585. orders, _ := service.GetNewHisOrderList(org_id)
  6586. c.ServeSuccessJSON(map[string]interface{}{
  6587. "order": orders,
  6588. })
  6589. return
  6590. }
  6591. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6592. newArr = make([]*models.HisOrderInfoTwo, 0)
  6593. for i := 0; i < len(arr); i++ {
  6594. repeat := false
  6595. for j := i + 1; j < len(arr); j++ {
  6596. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6597. repeat = true
  6598. break
  6599. }
  6600. }
  6601. if !repeat {
  6602. newArr = append(newArr, arr[i])
  6603. }
  6604. }
  6605. return
  6606. }
  6607. //修改处方退库操作 参数传修改之前的处方数据
  6608. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6609. if advice.ExecutionState == 1 {
  6610. //查询该病人该药品是否有库存记录
  6611. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6612. if errcode == gorm.ErrRecordNotFound {
  6613. } else {
  6614. //退库
  6615. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6616. if advice.PrescribingNumberUnit == drug.MinUnit {
  6617. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6618. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6619. //退库
  6620. warehouseInfo := models.DrugWarehouseInfo{
  6621. StockMinNumber: prescribingNumber,
  6622. }
  6623. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6624. operation_time := time.Now().Unix()
  6625. creater := advice.AdviceDoctor
  6626. ctime := time.Now().Unix()
  6627. timeStr := time.Now().Format("2006-01-02")
  6628. timeArr := strings.Split(timeStr, "-")
  6629. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6630. total = total + 1
  6631. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6632. cancelStock := models.DrugCancelStock{
  6633. OrderNumber: orderNumber,
  6634. OperaTime: operation_time,
  6635. OrgId: advice.UserOrgId,
  6636. Creater: creater,
  6637. Ctime: ctime,
  6638. Status: 1,
  6639. ReturnTime: advice.AdviceDate,
  6640. Dealer: info.Dealer,
  6641. Manufacturer: info.Manufacturer,
  6642. Type: 1,
  6643. }
  6644. service.AddSigleDrugCancelStock(&cancelStock)
  6645. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6646. dealer, _ := service.GetDealerById(info.Dealer)
  6647. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6648. cancelStockInfo := models.DrugCancelStockInfo{
  6649. OrderNumber: cancelInfo.OrderNumber,
  6650. CancelStockId: cancelInfo.ID,
  6651. DrugId: info.DrugId,
  6652. Count: info.Count,
  6653. Status: 1,
  6654. Ctime: ctime,
  6655. OrgId: advice.UserOrgId,
  6656. Type: 1,
  6657. Manufacturer: manufactureName.ManufacturerName,
  6658. Dealer: dealer.DealerName,
  6659. Total: 0,
  6660. RetailPrice: info.RetailPrice,
  6661. RetailTotalPrice: info.RetailTotalPrice,
  6662. Price: info.Price,
  6663. RegisterAccount: "",
  6664. Remark: info.Remark,
  6665. BatchNumber: info.BatchNumber,
  6666. MaxUnit: info.CountUnit,
  6667. ProductDate: info.ProductDate,
  6668. ExpiryDate: info.ExpiryDate,
  6669. BatchNumberId: info.WarehouseInfoId,
  6670. }
  6671. flow := models.DrugFlow{
  6672. WarehousingId: 0,
  6673. DrugId: info.DrugId,
  6674. Number: "",
  6675. BatchNumber: info.BatchNumber,
  6676. Count: info.Count,
  6677. UserOrgId: advice.UserOrgId,
  6678. PatientId: 0,
  6679. SystemTime: ctime,
  6680. ConsumableType: 4,
  6681. IsSys: 0,
  6682. WarehousingOrder: "",
  6683. WarehouseOutId: 0,
  6684. WarehouseOutOrderNumber: "",
  6685. IsEdit: 0,
  6686. CancelStockId: cancelStock.ID,
  6687. CancelOrderNumber: cancelStock.OrderNumber,
  6688. Manufacturer: info.Manufacturer,
  6689. Dealer: info.Dealer,
  6690. Creator: advice.UserOrgId,
  6691. UpdateCreator: 0,
  6692. Status: 1,
  6693. Ctime: time.Now().Unix(),
  6694. Mtime: 0,
  6695. Price: info.Price,
  6696. WarehousingDetailId: 0,
  6697. WarehouseOutDetailId: 0,
  6698. CancelOutDetailId: 0,
  6699. ExpireDate: info.ExpiryDate,
  6700. ProductDate: info.ProductDate,
  6701. MaxUnit: info.CountUnit,
  6702. MinUnit: "",
  6703. }
  6704. service.CreatedCancelStock(cancelStockInfo)
  6705. service.CreateDrugFlowOne(flow)
  6706. } else {
  6707. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6708. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6709. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6710. warehouseInfo := models.DrugWarehouseInfo{
  6711. StockMinNumber: prescribingNumber,
  6712. }
  6713. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6714. }
  6715. operation_time := time.Now().Unix()
  6716. creater := advice.AdviceDoctor
  6717. ctime := time.Now().Unix()
  6718. timeStr := time.Now().Format("2006-01-02")
  6719. timeArr := strings.Split(timeStr, "-")
  6720. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6721. total = total + 1
  6722. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6723. cancelStock := models.DrugCancelStock{
  6724. OrderNumber: orderNumber,
  6725. OperaTime: operation_time,
  6726. OrgId: advice.UserOrgId,
  6727. Creater: creater,
  6728. Ctime: ctime,
  6729. Status: 1,
  6730. ReturnTime: advice.AdviceDate,
  6731. Dealer: info.Dealer,
  6732. Manufacturer: info.Manufacturer,
  6733. Type: 1,
  6734. }
  6735. service.AddSigleDrugCancelStock(&cancelStock)
  6736. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6737. dealer, _ := service.GetDealerById(info.Dealer)
  6738. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6739. cancelStockInfo := models.DrugCancelStockInfo{
  6740. OrderNumber: cancelInfo.OrderNumber,
  6741. CancelStockId: cancelInfo.ID,
  6742. DrugId: info.DrugId,
  6743. Count: info.Count,
  6744. Status: 1,
  6745. Ctime: ctime,
  6746. OrgId: advice.UserOrgId,
  6747. Type: 1,
  6748. Manufacturer: manufactureName.ManufacturerName,
  6749. Dealer: dealer.DealerName,
  6750. Total: 0,
  6751. RetailPrice: info.RetailPrice,
  6752. RetailTotalPrice: info.RetailTotalPrice,
  6753. Price: info.Price,
  6754. RegisterAccount: "",
  6755. Remark: info.Remark,
  6756. BatchNumber: info.BatchNumber,
  6757. MaxUnit: info.CountUnit,
  6758. ProductDate: info.ProductDate,
  6759. ExpiryDate: info.ExpiryDate,
  6760. BatchNumberId: info.WarehouseInfoId,
  6761. }
  6762. flow := models.DrugFlow{
  6763. WarehousingId: 0,
  6764. DrugId: info.DrugId,
  6765. Number: "",
  6766. BatchNumber: info.BatchNumber,
  6767. Count: info.Count,
  6768. UserOrgId: advice.UserOrgId,
  6769. PatientId: 0,
  6770. SystemTime: ctime,
  6771. ConsumableType: 4,
  6772. IsSys: 0,
  6773. WarehousingOrder: "",
  6774. WarehouseOutId: 0,
  6775. WarehouseOutOrderNumber: "",
  6776. IsEdit: 0,
  6777. CancelStockId: cancelStock.ID,
  6778. CancelOrderNumber: cancelStock.OrderNumber,
  6779. Manufacturer: info.Manufacturer,
  6780. Dealer: info.Dealer,
  6781. Creator: advice.AdviceDoctor,
  6782. UpdateCreator: 0,
  6783. Status: 1,
  6784. Ctime: time.Now().Unix(),
  6785. Mtime: 0,
  6786. Price: info.Price,
  6787. WarehousingDetailId: 0,
  6788. WarehouseOutDetailId: 0,
  6789. CancelOutDetailId: 0,
  6790. ExpireDate: info.ExpiryDate,
  6791. ProductDate: info.ProductDate,
  6792. MaxUnit: info.CountUnit,
  6793. MinUnit: "",
  6794. }
  6795. service.CreatedCancelStock(cancelStockInfo)
  6796. service.CreateDrugFlowOne(flow)
  6797. }
  6798. }
  6799. }
  6800. return err
  6801. }
  6802. func (this *HisApiController) DeleteNCDS() {
  6803. id, _ := this.GetInt64("id", 0)
  6804. if id > 0 {
  6805. service.DeletePsnNCDSRecordById(id)
  6806. this.ServeSuccessJSON(map[string]interface{}{
  6807. "msg": "删除成功",
  6808. })
  6809. } else {
  6810. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6811. return
  6812. }
  6813. }
  6814. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6815. id, _ := c.GetInt64("id")
  6816. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6817. c.ServeSuccessJSON(map[string]interface{}{
  6818. "advice": advice,
  6819. })
  6820. return
  6821. }
  6822. func (c *HisApiController) GetHisMonthChargePatientList() {
  6823. record_date := c.GetString("record_date")
  6824. start_time := c.GetString("start_time")
  6825. end_time := c.GetString("end_time")
  6826. timeLayout := "2006-01-02"
  6827. loc, _ := time.LoadLocation("Local")
  6828. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6829. if err != nil {
  6830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6831. return
  6832. }
  6833. if err != nil {
  6834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6835. return
  6836. }
  6837. recordDateTime := theTime.Unix()
  6838. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6839. if err != nil {
  6840. }
  6841. startRecordDateTime := startTime.Unix()
  6842. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6843. if err != nil {
  6844. }
  6845. endRecordDateTime := endTime.Unix()
  6846. adminInfo := c.GetAdminUserInfo()
  6847. var tempMonthChargePatients []*service.MonthChargePatients
  6848. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  6849. for _, item := range tempPatients {
  6850. //过滤没有处方的
  6851. if len(item.HisPrescription) == 0 {
  6852. tempMonthChargePatients = append(tempMonthChargePatients, item)
  6853. }
  6854. }
  6855. c.ServeSuccessJSON(map[string]interface{}{
  6856. "list": tempMonthChargePatients,
  6857. })
  6858. }