his_api_controller.go 241KB

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