his_api_controller.go 244KB

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