his_api_controller.go 243KB

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