his_api_controller.go 245KB

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