his_api_controller.go 293KB

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