his_api_controller.go 247KB

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