his_api_controller.go 246KB

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