his_api_controller.go 296KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858
  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. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1655. cancelStock := models.CancelStock{
  1656. OrderNumber: orderNumber,
  1657. OperaTime: operation_time,
  1658. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1659. Creater: creater,
  1660. Ctime: time.Now().Unix(),
  1661. Status: 1,
  1662. ReturnTime: item.RecordDate,
  1663. Type: 1,
  1664. StorehouseId: houseConfig.StorehouseOutInfo,
  1665. }
  1666. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1667. if msgerrkonde == gorm.ErrRecordNotFound {
  1668. service.AddSigleCancelStock(&cancelStock)
  1669. }
  1670. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1671. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1672. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1673. //查询该耗材是否出库
  1674. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1675. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1676. deaerler, _ := service.GetDealerById(info.Dealer)
  1677. if info.ID > 0 {
  1678. cancelStockInfo := models.CancelStockInfo{
  1679. GoodId: item.ProjectId,
  1680. CancelStockId: cancel.ID,
  1681. GoodTypeId: good.GoodTypeId,
  1682. Count: prescribingNumber,
  1683. Price: info.Price,
  1684. Total: 0,
  1685. ProductDate: info.ProductDate,
  1686. ExpiryDate: info.ExpiryDate,
  1687. Ctime: time.Now().Unix(),
  1688. Status: 1,
  1689. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1690. OrderNumber: cancel.OrderNumber,
  1691. Type: 0,
  1692. Dealer: deaerler.DealerName,
  1693. Manufacturer: manufacturer.ManufacturerName,
  1694. Number: info.Number,
  1695. RegisterAccount: "",
  1696. Remark: "",
  1697. WarehouseInfoId: info.WarehouseInfotId,
  1698. PatientId: info.PatientId,
  1699. RecordDate: info.SysRecordTime,
  1700. StorehouseId: houseConfig.StorehouseOutInfo,
  1701. }
  1702. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1703. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1704. flow := models.VmStockFlow{
  1705. WarehousingId: 0,
  1706. GoodId: item.ProjectId,
  1707. Number: info.Number,
  1708. LicenseNumber: info.LicenseNumber,
  1709. Count: prescribingNumber,
  1710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1711. PatientId: item.PatientId,
  1712. SystemTime: info.SysRecordTime,
  1713. ConsumableType: 7,
  1714. IsSys: 0,
  1715. WarehousingOrder: "",
  1716. WarehouseOutId: 0,
  1717. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1718. IsEdit: 0,
  1719. CancelStockId: cancel.ID,
  1720. CancelOrderNumber: cancel.OrderNumber,
  1721. Manufacturer: manufacturer.ID,
  1722. Dealer: 0,
  1723. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1724. UpdateCreator: 0,
  1725. Status: 1,
  1726. Ctime: time.Now().Unix(),
  1727. Mtime: 0,
  1728. Price: info.Price,
  1729. WarehousingDetailId: info.WarehouseInfotId,
  1730. WarehouseOutDetailId: 0,
  1731. CancelOutDetailId: cancelInfo.ID,
  1732. ProductDate: info.ProductDate,
  1733. ExpireDate: info.ExpiryDate,
  1734. StorehouseId: houseConfig.StorehouseOutInfo,
  1735. }
  1736. service.CreateStockFlowOne(flow)
  1737. //删除出库表
  1738. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1739. //查询今日该患者开了多少耗材
  1740. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1741. var total_count int64
  1742. var cha_count int64
  1743. for _, item := range projectList {
  1744. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1745. total_count += count
  1746. }
  1747. //回退库存
  1748. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1749. //查询今日该耗材退库数量
  1750. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1751. var cancel_Count int64
  1752. for _, items := range cancelInfoOne {
  1753. cancel_Count += items.Count
  1754. }
  1755. cha_count = total_count - cancel_Count
  1756. if total_count > cancel_Count {
  1757. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1758. if err == gorm.ErrRecordNotFound {
  1759. //没有记录,则创建出库单
  1760. timeStr := time.Now().Format("2006-01-02")
  1761. timeArr := strings.Split(timeStr, "-")
  1762. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1763. total = total + 1
  1764. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1765. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1766. number = number + total
  1767. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1768. warehouseOut := models.WarehouseOut{
  1769. WarehouseOutOrderNumber: warehousing_out_order,
  1770. OperationTime: time.Now().Unix(),
  1771. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1772. Creater: creater,
  1773. Ctime: time.Now().Unix(),
  1774. Status: 1,
  1775. WarehouseOutTime: info.SysRecordTime,
  1776. Dealer: 0,
  1777. Manufacturer: 0,
  1778. Type: 1,
  1779. IsSys: 1,
  1780. StorehouseId: houseConfig.StorehouseOutInfo,
  1781. }
  1782. err := service.AddSigleWarehouseOut(&warehouseOut)
  1783. if err != nil {
  1784. utils.TraceLog("创建出库单失败 err = %v", err)
  1785. return
  1786. }
  1787. prepare := &models.DialysisBeforePrepare{
  1788. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1789. PatientId: info.PatientId,
  1790. RecordDate: info.SysRecordTime,
  1791. GoodId: item.ProjectId,
  1792. GoodTypeId: info.GoodTypeId,
  1793. Count: cha_count,
  1794. StorehouseId: houseConfig.StorehouseOutInfo,
  1795. }
  1796. //出库
  1797. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1798. } else if err == nil {
  1799. prepare := &models.DialysisBeforePrepare{
  1800. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1801. PatientId: info.PatientId,
  1802. RecordDate: info.SysRecordTime,
  1803. GoodId: item.ProjectId,
  1804. GoodTypeId: info.GoodTypeId,
  1805. Count: cha_count,
  1806. StorehouseId: houseConfig.StorehouseOutInfo,
  1807. }
  1808. //出库
  1809. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1817. fmt.Println(err)
  1818. }
  1819. if drugStockConfig.IsOpen == 1 {
  1820. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1821. fmt.Println(err)
  1822. if len(advices) > 0 {
  1823. for _, item := range advices {
  1824. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1825. redis := service.RedisClient()
  1826. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1827. redis.Set(keyFive, "", time.Second)
  1828. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1829. redis.Set(keyOne, "", time.Second)
  1830. redis.Close()
  1831. //查询该药品是否存在出库记录
  1832. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1833. if errcode == gorm.ErrRecordNotFound {
  1834. } else if errcode == nil {
  1835. if item.PrescribingNumberUnit == drug.MinUnit {
  1836. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1837. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1838. //退库
  1839. warehouseInfo := models.DrugWarehouseInfo{
  1840. StockMinNumber: prescribingNumber,
  1841. }
  1842. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1843. adminUserInfo := c.GetAdminUserInfo()
  1844. operation_time := time.Now().Unix()
  1845. creater := adminUserInfo.AdminUser.Id
  1846. ctime := time.Now().Unix()
  1847. timeStr := time.Now().Format("2006-01-02")
  1848. timeArr := strings.Split(timeStr, "-")
  1849. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1850. total = total + 1
  1851. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1852. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1853. cancelStock := models.DrugCancelStock{
  1854. OrderNumber: orderNumber,
  1855. OperaTime: operation_time,
  1856. OrgId: adminUserInfo.CurrentOrgId,
  1857. Creater: creater,
  1858. Ctime: ctime,
  1859. Status: 1,
  1860. ReturnTime: item.AdviceDate,
  1861. Dealer: info.Dealer,
  1862. Manufacturer: info.Manufacturer,
  1863. Type: 1,
  1864. StorehouseId: houseConfig.DrugStorehouseOut,
  1865. }
  1866. service.AddSigleDrugCancelStock(&cancelStock)
  1867. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1868. dealer, _ := service.GetDealerById(info.Dealer)
  1869. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1870. cancelStockInfo := models.DrugCancelStockInfo{
  1871. OrderNumber: cancelInfo.OrderNumber,
  1872. CancelStockId: cancelInfo.ID,
  1873. DrugId: info.DrugId,
  1874. Count: prescribingNumber,
  1875. Status: 1,
  1876. Ctime: ctime,
  1877. OrgId: adminUserInfo.CurrentOrgId,
  1878. Type: 1,
  1879. Manufacturer: manufactureName.ManufacturerName,
  1880. Dealer: dealer.DealerName,
  1881. Total: 0,
  1882. RetailPrice: info.RetailPrice,
  1883. RetailTotalPrice: info.RetailTotalPrice,
  1884. Price: info.Price,
  1885. RegisterAccount: "",
  1886. Remark: info.Remark,
  1887. BatchNumber: info.BatchNumber,
  1888. MaxUnit: info.CountUnit,
  1889. ProductDate: info.ProductDate,
  1890. ExpiryDate: info.ExpiryDate,
  1891. BatchNumberId: info.WarehouseInfoId,
  1892. StorehouseId: houseConfig.DrugStorehouseOut,
  1893. }
  1894. flow := models.DrugFlow{
  1895. WarehousingId: 0,
  1896. DrugId: info.DrugId,
  1897. Number: "",
  1898. BatchNumber: info.BatchNumber,
  1899. Count: prescribingNumber,
  1900. UserOrgId: adminUserInfo.CurrentOrgId,
  1901. PatientId: 0,
  1902. SystemTime: info.SysRecordTime,
  1903. ConsumableType: 7,
  1904. IsSys: 0,
  1905. WarehousingOrder: "",
  1906. WarehouseOutId: 0,
  1907. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1908. IsEdit: 0,
  1909. CancelStockId: cancelStock.ID,
  1910. CancelOrderNumber: cancelStock.OrderNumber,
  1911. Manufacturer: info.Manufacturer,
  1912. Dealer: info.Dealer,
  1913. Creator: adminUserInfo.AdminUser.Id,
  1914. UpdateCreator: 0,
  1915. Status: 1,
  1916. Ctime: time.Now().Unix(),
  1917. Mtime: 0,
  1918. Price: info.Price,
  1919. WarehousingDetailId: 0,
  1920. WarehouseOutDetailId: 0,
  1921. CancelOutDetailId: 0,
  1922. ExpireDate: info.ExpiryDate,
  1923. ProductDate: info.ProductDate,
  1924. MaxUnit: info.CountUnit,
  1925. MinUnit: "",
  1926. AdviceId: info.AdviceId,
  1927. StorehouseId: houseConfig.DrugStorehouseOut,
  1928. }
  1929. service.CreatedCancelStock(cancelStockInfo)
  1930. service.CreateDrugFlowOne(flow)
  1931. //删除出库记录
  1932. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1933. //删除流水
  1934. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1935. } else {
  1936. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1937. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1938. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1939. if item.PrescribingNumberUnit == drug.MaxUnit {
  1940. warehouseInfo := models.DrugWarehouseInfo{
  1941. StockMaxNumber: prescribingNumber,
  1942. }
  1943. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1944. }
  1945. adminUserInfo := c.GetAdminUserInfo()
  1946. operation_time := time.Now().Unix()
  1947. creater := adminUserInfo.AdminUser.Id
  1948. ctime := time.Now().Unix()
  1949. timeStr := time.Now().Format("2006-01-02")
  1950. timeArr := strings.Split(timeStr, "-")
  1951. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1952. total = total + 1
  1953. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1954. cancelStock := models.DrugCancelStock{
  1955. OrderNumber: orderNumber,
  1956. OperaTime: operation_time,
  1957. OrgId: adminUserInfo.CurrentOrgId,
  1958. Creater: creater,
  1959. Ctime: ctime,
  1960. Status: 1,
  1961. ReturnTime: item.AdviceDate,
  1962. Dealer: info.Dealer,
  1963. Manufacturer: info.Manufacturer,
  1964. Type: 1,
  1965. StorehouseId: houseConfig.DrugStorehouseOut,
  1966. }
  1967. service.AddSigleDrugCancelStock(&cancelStock)
  1968. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1969. dealer, _ := service.GetDealerById(info.Dealer)
  1970. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1971. cancelStockInfo := models.DrugCancelStockInfo{
  1972. OrderNumber: cancelInfo.OrderNumber,
  1973. CancelStockId: cancelInfo.ID,
  1974. DrugId: info.DrugId,
  1975. // Count: info.Count,
  1976. Count: prescribingNumber,
  1977. Status: 1,
  1978. Ctime: ctime,
  1979. OrgId: adminUserInfo.CurrentOrgId,
  1980. Type: 1,
  1981. Manufacturer: manufactureName.ManufacturerName,
  1982. Dealer: dealer.DealerName,
  1983. Total: 0,
  1984. RetailPrice: info.RetailPrice,
  1985. RetailTotalPrice: info.RetailTotalPrice,
  1986. Price: info.Price,
  1987. RegisterAccount: "",
  1988. Remark: info.Remark,
  1989. BatchNumber: info.BatchNumber,
  1990. MaxUnit: info.CountUnit,
  1991. ProductDate: info.ProductDate,
  1992. ExpiryDate: info.ExpiryDate,
  1993. BatchNumberId: info.WarehouseInfoId,
  1994. StorehouseId: houseConfig.DrugStorehouseOut,
  1995. }
  1996. flow := models.DrugFlow{
  1997. WarehousingId: 0,
  1998. DrugId: info.DrugId,
  1999. Number: "",
  2000. BatchNumber: info.BatchNumber,
  2001. //Count: info.Count,
  2002. Count: prescribingNumber,
  2003. UserOrgId: adminUserInfo.CurrentOrgId,
  2004. PatientId: 0,
  2005. SystemTime: info.SysRecordTime,
  2006. ConsumableType: 7,
  2007. IsSys: 0,
  2008. WarehousingOrder: "",
  2009. WarehouseOutId: 0,
  2010. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2011. IsEdit: 0,
  2012. CancelStockId: cancelStock.ID,
  2013. CancelOrderNumber: cancelStock.OrderNumber,
  2014. Manufacturer: info.Manufacturer,
  2015. Dealer: info.Dealer,
  2016. Creator: adminUserInfo.AdminUser.Id,
  2017. UpdateCreator: 0,
  2018. Status: 1,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. Price: info.Price,
  2022. WarehousingDetailId: 0,
  2023. WarehouseOutDetailId: 0,
  2024. CancelOutDetailId: 0,
  2025. ExpireDate: info.ExpiryDate,
  2026. ProductDate: info.ProductDate,
  2027. MaxUnit: info.CountUnit,
  2028. MinUnit: "",
  2029. AdviceId: info.AdviceId,
  2030. StorehouseId: houseConfig.DrugStorehouseOut,
  2031. }
  2032. service.CreatedCancelStock(cancelStockInfo)
  2033. service.CreateDrugFlowOne(flow)
  2034. //删除出库记录
  2035. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2036. //删除流水
  2037. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2038. }
  2039. }
  2040. if item.PrescribingNumberUnit == drug.MinUnit {
  2041. drug.Total = drug.Total + item.PrescribingNumber
  2042. service.UpdateBaseDrugLib(&drug)
  2043. } else {
  2044. if item.PrescribingNumberUnit == drug.MaxUnit {
  2045. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  2046. drug.Total = drug.Total + item.PrescribingNumber
  2047. service.UpdateBaseDrugLib(&drug)
  2048. }
  2049. }
  2050. }
  2051. }
  2052. }
  2053. c.ServeSuccessJSON(map[string]interface{}{
  2054. "msg": "删除成功",
  2055. })
  2056. return
  2057. }
  2058. func (c *HisApiController) DeleteDoctorAdvice() {
  2059. id, _ := c.GetInt64("id")
  2060. advice, _ := service.GetHisDoctorAdvicesById(id)
  2061. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2062. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2063. redis := service.RedisClient()
  2064. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2065. redis.Set(keyFive, "", time.Second)
  2066. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2067. redis.Set(keyOne, "", time.Second)
  2068. defer redis.Close()
  2069. if err == nil {
  2070. if drugStockConfig.IsOpen == 1 {
  2071. //判断该医嘱是否执行了
  2072. if advice.ExecutionState == 1 {
  2073. //查询该病人该药品是否有库存记录
  2074. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  2075. if errcode == gorm.ErrRecordNotFound {
  2076. } else {
  2077. //退库
  2078. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  2079. if advice.PrescribingNumberUnit == drug.MinUnit {
  2080. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2081. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2082. //退库
  2083. warehouseInfo := models.DrugWarehouseInfo{
  2084. StockMinNumber: prescribingNumber,
  2085. }
  2086. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  2087. adminUserInfo := c.GetAdminUserInfo()
  2088. operation_time := time.Now().Unix()
  2089. creater := adminUserInfo.AdminUser.Id
  2090. ctime := time.Now().Unix()
  2091. timeStr := time.Now().Format("2006-01-02")
  2092. timeArr := strings.Split(timeStr, "-")
  2093. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2094. total = total + 1
  2095. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2096. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2097. cancelStock := models.DrugCancelStock{
  2098. OrderNumber: orderNumber,
  2099. OperaTime: operation_time,
  2100. OrgId: adminUserInfo.CurrentOrgId,
  2101. Creater: creater,
  2102. Ctime: ctime,
  2103. Status: 1,
  2104. ReturnTime: advice.AdviceDate,
  2105. Dealer: info.Dealer,
  2106. Manufacturer: info.Manufacturer,
  2107. Type: 1,
  2108. StorehouseId: houseConfig.DrugStorehouseOut,
  2109. }
  2110. service.AddSigleDrugCancelStock(&cancelStock)
  2111. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2112. dealer, _ := service.GetDealerById(info.Dealer)
  2113. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2114. cancelStockInfo := models.DrugCancelStockInfo{
  2115. OrderNumber: cancelInfo.OrderNumber,
  2116. CancelStockId: cancelInfo.ID,
  2117. DrugId: info.DrugId,
  2118. Count: info.Count,
  2119. Status: 1,
  2120. Ctime: ctime,
  2121. OrgId: adminUserInfo.CurrentOrgId,
  2122. Type: 1,
  2123. Manufacturer: manufactureName.ManufacturerName,
  2124. Dealer: dealer.DealerName,
  2125. Total: 0,
  2126. RetailPrice: info.RetailPrice,
  2127. RetailTotalPrice: info.RetailTotalPrice,
  2128. Price: info.Price,
  2129. RegisterAccount: "",
  2130. Remark: info.Remark,
  2131. BatchNumber: info.BatchNumber,
  2132. MaxUnit: info.CountUnit,
  2133. ProductDate: info.ProductDate,
  2134. ExpiryDate: info.ExpiryDate,
  2135. BatchNumberId: info.WarehouseInfoId,
  2136. StorehouseId: houseConfig.DrugStorehouseOut,
  2137. }
  2138. flow := models.DrugFlow{
  2139. WarehousingId: 0,
  2140. DrugId: info.DrugId,
  2141. Number: "",
  2142. BatchNumber: info.BatchNumber,
  2143. Count: info.Count,
  2144. UserOrgId: adminUserInfo.CurrentOrgId,
  2145. PatientId: 0,
  2146. SystemTime: info.SysRecordTime,
  2147. ConsumableType: 7,
  2148. IsSys: 0,
  2149. WarehousingOrder: "",
  2150. WarehouseOutId: 0,
  2151. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2152. IsEdit: 0,
  2153. CancelStockId: cancelStock.ID,
  2154. CancelOrderNumber: cancelStock.OrderNumber,
  2155. Manufacturer: info.Manufacturer,
  2156. Dealer: info.Dealer,
  2157. Creator: adminUserInfo.AdminUser.Id,
  2158. UpdateCreator: 0,
  2159. Status: 1,
  2160. Ctime: time.Now().Unix(),
  2161. Mtime: 0,
  2162. Price: info.Price,
  2163. WarehousingDetailId: 0,
  2164. WarehouseOutDetailId: 0,
  2165. CancelOutDetailId: 0,
  2166. ExpireDate: info.ExpiryDate,
  2167. ProductDate: info.ProductDate,
  2168. MaxUnit: info.CountUnit,
  2169. MinUnit: "",
  2170. AdviceId: info.AdviceId,
  2171. StorehouseId: houseConfig.DrugStorehouseOut,
  2172. }
  2173. service.CreatedCancelStock(cancelStockInfo)
  2174. service.CreateDrugFlowOne(flow)
  2175. //删除出库记录
  2176. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2177. //删除流水
  2178. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2179. } else {
  2180. adminUserInfo := c.GetAdminUserInfo()
  2181. houseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  2182. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2183. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2184. if advice.PrescribingNumberUnit == drug.MaxUnit {
  2185. warehouseInfo := models.DrugWarehouseInfo{
  2186. StockMaxNumber: prescribingNumber,
  2187. }
  2188. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2189. }
  2190. operation_time := time.Now().Unix()
  2191. creater := adminUserInfo.AdminUser.Id
  2192. ctime := time.Now().Unix()
  2193. timeStr := time.Now().Format("2006-01-02")
  2194. timeArr := strings.Split(timeStr, "-")
  2195. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2196. total = total + 1
  2197. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2198. cancelStock := models.DrugCancelStock{
  2199. OrderNumber: orderNumber,
  2200. OperaTime: operation_time,
  2201. OrgId: adminUserInfo.CurrentOrgId,
  2202. Creater: creater,
  2203. Ctime: ctime,
  2204. Status: 1,
  2205. ReturnTime: advice.AdviceDate,
  2206. Dealer: info.Dealer,
  2207. Manufacturer: info.Manufacturer,
  2208. Type: 1,
  2209. StorehouseId: houseConfig.DrugStorehouseOut,
  2210. }
  2211. service.AddSigleDrugCancelStock(&cancelStock)
  2212. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2213. dealer, _ := service.GetDealerById(info.Dealer)
  2214. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2215. cancelStockInfo := models.DrugCancelStockInfo{
  2216. OrderNumber: cancelInfo.OrderNumber,
  2217. CancelStockId: cancelInfo.ID,
  2218. DrugId: info.DrugId,
  2219. Count: info.Count,
  2220. Status: 1,
  2221. Ctime: ctime,
  2222. OrgId: adminUserInfo.CurrentOrgId,
  2223. Type: 1,
  2224. Manufacturer: manufactureName.ManufacturerName,
  2225. Dealer: dealer.DealerName,
  2226. Total: 0,
  2227. RetailPrice: info.RetailPrice,
  2228. RetailTotalPrice: info.RetailTotalPrice,
  2229. Price: info.Price,
  2230. RegisterAccount: "",
  2231. Remark: info.Remark,
  2232. BatchNumber: info.BatchNumber,
  2233. MaxUnit: info.CountUnit,
  2234. ProductDate: info.ProductDate,
  2235. ExpiryDate: info.ExpiryDate,
  2236. BatchNumberId: info.WarehouseInfoId,
  2237. StorehouseId: houseConfig.DrugStorehouseOut,
  2238. }
  2239. flow := models.DrugFlow{
  2240. WarehousingId: 0,
  2241. DrugId: info.DrugId,
  2242. Number: "",
  2243. BatchNumber: info.BatchNumber,
  2244. Count: info.Count,
  2245. UserOrgId: adminUserInfo.CurrentOrgId,
  2246. PatientId: 0,
  2247. SystemTime: info.SysRecordTime,
  2248. ConsumableType: 7,
  2249. IsSys: 0,
  2250. WarehousingOrder: "",
  2251. WarehouseOutId: 0,
  2252. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2253. IsEdit: 0,
  2254. CancelStockId: cancelStock.ID,
  2255. CancelOrderNumber: cancelStock.OrderNumber,
  2256. Manufacturer: info.Manufacturer,
  2257. Dealer: info.Dealer,
  2258. Creator: adminUserInfo.AdminUser.Id,
  2259. UpdateCreator: 0,
  2260. Status: 1,
  2261. Ctime: time.Now().Unix(),
  2262. Mtime: 0,
  2263. Price: info.Price,
  2264. WarehousingDetailId: 0,
  2265. WarehouseOutDetailId: 0,
  2266. CancelOutDetailId: 0,
  2267. ExpireDate: info.ExpiryDate,
  2268. ProductDate: info.ProductDate,
  2269. MaxUnit: info.CountUnit,
  2270. MinUnit: "",
  2271. AdviceId: info.AdviceId,
  2272. StorehouseId: houseConfig.DrugStorehouseOut,
  2273. }
  2274. service.CreatedCancelStock(cancelStockInfo)
  2275. service.CreateDrugFlowOne(flow)
  2276. //删除出库记录
  2277. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2278. //删除流水
  2279. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2280. }
  2281. }
  2282. }
  2283. }
  2284. c.ServeSuccessJSON(map[string]interface{}{
  2285. "msg": "删除成功",
  2286. })
  2287. return
  2288. } else {
  2289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2290. return
  2291. }
  2292. }
  2293. func (c *HisApiController) DeleteProject() {
  2294. id, _ := c.GetInt64("id")
  2295. adminInfo := c.GetAdminUserInfo()
  2296. project, _ := service.GetHisProjectByID(id)
  2297. // var consumable models.DialysisBeforePrepare
  2298. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2299. service.DeletePrintInfo(id)
  2300. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2301. label.Status = 0
  2302. service.CreateHisLabelRecord(&label)
  2303. if stockConfig.IsOpen == 1 {
  2304. if project.Type == 2 {
  2305. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2306. fmt.Println(err)
  2307. }
  2308. if project.Type == 3 {
  2309. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2310. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2311. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2312. good.Total = good.Total + f_count
  2313. service.UpdateGoodInfo(&good)
  2314. operation_time := time.Now().Unix()
  2315. creater := adminInfo.AdminUser.Id
  2316. //创建退库单
  2317. timeStr := time.Now().Format("2006-01-02")
  2318. timeArr := strings.Split(timeStr, "-")
  2319. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2320. total = total + 1
  2321. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2322. cancelStock := models.CancelStock{
  2323. OrderNumber: orderNumber,
  2324. OperaTime: operation_time,
  2325. OrgId: adminInfo.CurrentOrgId,
  2326. Creater: creater,
  2327. Ctime: time.Now().Unix(),
  2328. Status: 1,
  2329. ReturnTime: project.RecordDate,
  2330. Type: 1,
  2331. StorehouseId: houseConfig.StorehouseOutInfo,
  2332. }
  2333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2334. if msgerrkonde == gorm.ErrRecordNotFound {
  2335. service.AddSigleCancelStock(&cancelStock)
  2336. }
  2337. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2338. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2339. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2340. //获取该耗材有库存的第一条数据
  2341. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2342. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2343. deaerler, _ := service.GetDealerById(info.Dealer)
  2344. if info.ID > 0 {
  2345. cancelStockInfo := models.CancelStockInfo{
  2346. GoodId: project.ProjectId,
  2347. CancelStockId: cancel.ID,
  2348. GoodTypeId: good.GoodTypeId,
  2349. Count: prescribingNumber,
  2350. Price: info.Price,
  2351. Total: 0,
  2352. ProductDate: info.ProductDate,
  2353. ExpiryDate: info.ExpiryDate,
  2354. Ctime: time.Now().Unix(),
  2355. Status: 1,
  2356. OrgId: adminInfo.CurrentOrgId,
  2357. OrderNumber: cancel.OrderNumber,
  2358. Type: 0,
  2359. Dealer: deaerler.DealerName,
  2360. Manufacturer: manufacturer.ManufacturerName,
  2361. Number: info.Number,
  2362. RegisterAccount: "",
  2363. Remark: "",
  2364. WarehouseInfoId: info.WarehouseInfotId,
  2365. PatientId: info.PatientId,
  2366. RecordDate: info.SysRecordTime,
  2367. StorehouseId: houseConfig.StorehouseOutInfo,
  2368. }
  2369. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2370. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2371. flow := models.VmStockFlow{
  2372. WarehousingId: 0,
  2373. GoodId: project.ProjectId,
  2374. Number: info.Number,
  2375. LicenseNumber: info.LicenseNumber,
  2376. Count: prescribingNumber,
  2377. UserOrgId: adminInfo.CurrentOrgId,
  2378. PatientId: project.PatientId,
  2379. SystemTime: time.Now().Unix(),
  2380. ConsumableType: 7,
  2381. IsSys: 0,
  2382. WarehousingOrder: "",
  2383. WarehouseOutId: 0,
  2384. WarehouseOutOrderNumber: "",
  2385. IsEdit: 0,
  2386. CancelStockId: cancel.ID,
  2387. CancelOrderNumber: cancel.OrderNumber,
  2388. Manufacturer: manufacturer.ID,
  2389. Dealer: 0,
  2390. Creator: adminInfo.AdminUser.Id,
  2391. UpdateCreator: 0,
  2392. Status: 1,
  2393. Ctime: time.Now().Unix(),
  2394. Mtime: 0,
  2395. Price: info.Price,
  2396. WarehousingDetailId: info.WarehouseInfotId,
  2397. WarehouseOutDetailId: 0,
  2398. CancelOutDetailId: cancelInfo.ID,
  2399. ProductDate: info.ProductDate,
  2400. ExpireDate: info.ExpiryDate,
  2401. StorehouseId: houseConfig.StorehouseOutInfo,
  2402. }
  2403. service.CreateStockFlowOne(flow)
  2404. //删除出库表
  2405. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2406. //查询今日该患者开了多少耗材
  2407. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2408. var total_count int64
  2409. var cha_count int64
  2410. for _, item := range projectList {
  2411. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2412. total_count += count
  2413. }
  2414. //回退库存
  2415. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2416. //查询今日该耗材退库数量
  2417. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2418. var cancel_count int64
  2419. for _, items := range cancelInfoOne {
  2420. cancel_count += items.Count
  2421. }
  2422. cha_count = total_count - cancel_count
  2423. if total_count > cancel_count {
  2424. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2425. if err == gorm.ErrRecordNotFound {
  2426. //没有记录,则创建出库单
  2427. timeStr := time.Now().Format("2006-01-02")
  2428. timeArr := strings.Split(timeStr, "-")
  2429. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2430. total = total + 1
  2431. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2432. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2433. number = number + total
  2434. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2435. warehouseOut := models.WarehouseOut{
  2436. WarehouseOutOrderNumber: warehousing_out_order,
  2437. OperationTime: time.Now().Unix(),
  2438. OrgId: adminInfo.CurrentOrgId,
  2439. Creater: creater,
  2440. Ctime: time.Now().Unix(),
  2441. Status: 1,
  2442. WarehouseOutTime: info.SysRecordTime,
  2443. Dealer: 0,
  2444. Manufacturer: 0,
  2445. Type: 1,
  2446. IsSys: 1,
  2447. StorehouseId: houseConfig.StorehouseOutInfo,
  2448. }
  2449. err := service.AddSigleWarehouseOut(&warehouseOut)
  2450. if err != nil {
  2451. utils.TraceLog("创建出库单失败 err = %v", err)
  2452. return
  2453. }
  2454. prepare := &models.DialysisBeforePrepare{
  2455. UserOrgId: adminInfo.CurrentOrgId,
  2456. PatientId: info.PatientId,
  2457. RecordDate: info.SysRecordTime,
  2458. GoodId: project.ProjectId,
  2459. GoodTypeId: info.GoodTypeId,
  2460. Count: cha_count,
  2461. StorehouseId: houseConfig.StorehouseOutInfo,
  2462. }
  2463. //出库
  2464. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2465. } else if err == nil {
  2466. prepare := &models.DialysisBeforePrepare{
  2467. UserOrgId: adminInfo.CurrentOrgId,
  2468. PatientId: info.PatientId,
  2469. RecordDate: info.SysRecordTime,
  2470. GoodId: project.ProjectId,
  2471. GoodTypeId: info.GoodTypeId,
  2472. Count: cha_count,
  2473. StorehouseId: houseConfig.StorehouseOutInfo,
  2474. }
  2475. //出库
  2476. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2477. }
  2478. }
  2479. }
  2480. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2481. fmt.Println(err)
  2482. }
  2483. }
  2484. c.ServeSuccessJSON(map[string]interface{}{
  2485. "msg": "删除成功",
  2486. })
  2487. return
  2488. }
  2489. func (c *HisApiController) CreateHisAdditionalCharge() {
  2490. his_patient_id, _ := c.GetInt64("his_patient_id")
  2491. patient_id, _ := c.GetInt64("patient_id")
  2492. record_date := c.GetString("record_date")
  2493. timeLayout := "2006-01-02"
  2494. loc, _ := time.LoadLocation("Local")
  2495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2496. if err != nil {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2498. return
  2499. }
  2500. adminInfo := c.GetAdminUserInfo()
  2501. recordDateTime := theTime.Unix()
  2502. dataBody := make(map[string]interface{}, 0)
  2503. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2504. if err != nil {
  2505. utils.ErrorLog(err.Error())
  2506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2507. return
  2508. }
  2509. var additions []*models.HisAdditionalCharge
  2510. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2511. additions, _ := dataBody["addition"].([]interface{})
  2512. if len(additions) > 0 {
  2513. for _, item := range additions {
  2514. items := item.(map[string]interface{})
  2515. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2516. utils.ErrorLog("item_id")
  2517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2518. return
  2519. }
  2520. item_id := int64(items["item_id"].(float64))
  2521. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2522. utils.ErrorLog("item_name")
  2523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2524. return
  2525. }
  2526. item_name := items["item_name"].(string)
  2527. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2528. utils.ErrorLog("price")
  2529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2530. return
  2531. }
  2532. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2533. ctime := time.Now().Unix()
  2534. additional := &models.HisAdditionalCharge{
  2535. PatientId: patient_id,
  2536. HisPatientId: his_patient_id,
  2537. UserOrgId: adminInfo.CurrentOrgId,
  2538. RecordDate: recordDateTime,
  2539. CreatedTime: ctime,
  2540. UpdatedTime: ctime,
  2541. Modifier: adminInfo.AdminUser.Id,
  2542. Creator: adminInfo.AdminUser.Id,
  2543. Price: price,
  2544. ItemName: item_name,
  2545. ItemId: item_id,
  2546. Status: 1,
  2547. }
  2548. additions = append(additions, additional)
  2549. }
  2550. }
  2551. }
  2552. for _, item := range additions {
  2553. service.CreateAddtionalCharge(item)
  2554. }
  2555. c.ServeSuccessJSON(map[string]interface{}{
  2556. "msg": "创建成功",
  2557. })
  2558. }
  2559. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2560. blood_fat := c.GetString("blood_fat")
  2561. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2562. blood_sugar := c.GetString("blood_sugar")
  2563. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2564. chief_conplaint := c.GetString("chief_conplaint")
  2565. dbp := c.GetString("dbp")
  2566. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2567. delivery_way, _ := c.GetInt64("delivery_way")
  2568. diagnostic := c.GetString("diagnostic")
  2569. family_history := c.GetString("family_history")
  2570. height := c.GetString("height")
  2571. history_of_present_illness := c.GetString("history_of_present_illness")
  2572. is_infect, _ := c.GetInt64("is_infect")
  2573. past_history := c.GetString("past_history")
  2574. patient_id, _ := c.GetInt64("patient_id")
  2575. his_patient_id, _ := c.GetInt64("his_patient_id")
  2576. personal_history := c.GetString("personal_history")
  2577. pulse := c.GetString("pulse")
  2578. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2579. sbp := c.GetString("sbp")
  2580. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2581. heightfloat, _ := strconv.ParseFloat(height, 64)
  2582. sicktype := c.GetString("sick_type")
  2583. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2584. symptom := c.GetString("symptom")
  2585. sick_date := c.GetString("sick_date")
  2586. temperatures := c.GetString("temperature")
  2587. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2588. record_date := c.GetString("record_date")
  2589. breathing := c.GetString("breathing")
  2590. doctor_advice := c.GetString("doctor_advice")
  2591. remark := c.GetString("remark")
  2592. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2593. sick, _ := c.GetInt64("sick")
  2594. diagnose, _ := c.GetInt64("diagnose")
  2595. //id, _ := c.GetInt64("id")
  2596. timeLayout := "2006-01-02"
  2597. loc, _ := time.LoadLocation("Local")
  2598. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2599. allergic_history := c.GetString("allergic_history")
  2600. if err != nil {
  2601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2602. return
  2603. }
  2604. recordDateTime := theTime.Unix()
  2605. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2606. if err != nil {
  2607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2608. return
  2609. }
  2610. sickTimes := sickTime.Unix()
  2611. ctime := time.Now().Unix()
  2612. primary_disease := c.GetString("primary_disease")
  2613. confirm_failure_date := c.GetString("confirm_failure_date")
  2614. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  2615. drug_allergy_history := c.GetString("drug_allergy_history")
  2616. physical_examination := c.GetString("physical_examination")
  2617. special_inspection := c.GetString("special_inspection")
  2618. lab_apparatus := c.GetString("lab_apparatus")
  2619. caseHistory := models.HisPatientCaseHistory{
  2620. HisPatientId: his_patient_id,
  2621. PatientId: patient_id,
  2622. Temperature: temperature,
  2623. BloodSugar: bloodsugarfloat,
  2624. Pulse: pulsefloat,
  2625. Sbp: sbpfloat,
  2626. Dbp: dbpfloat,
  2627. Height: heightfloat,
  2628. BloodFat: bloodfatfloat,
  2629. SickType: sick_type,
  2630. Symptom: symptom,
  2631. SickDate: sickTimes,
  2632. IsInfect: is_infect,
  2633. HistoryOfPresentIllness: history_of_present_illness,
  2634. PastHistory: past_history,
  2635. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2636. ChiefConplaint: chief_conplaint,
  2637. PersonalHistory: personal_history,
  2638. FamilyHistory: family_history,
  2639. Diagnostic: diagnostic,
  2640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2641. Status: 1,
  2642. Ctime: ctime,
  2643. Mtime: ctime,
  2644. RecordDate: recordDateTime,
  2645. DeliveryWay: delivery_way,
  2646. Breathing: breathingfloat,
  2647. DoctorAdvice: doctor_advice,
  2648. Remark: remark,
  2649. Sick: sick,
  2650. Diagnose: diagnose,
  2651. AllergicHistory: allergic_history,
  2652. PrimaryDisease: primary_disease,
  2653. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  2654. DrugAllergyHistory: drug_allergy_history,
  2655. PhysicalExamination: physical_examination,
  2656. SpecialInspection: special_inspection,
  2657. LabApparatus: lab_apparatus,
  2658. }
  2659. //查询该患者是否有病历
  2660. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  2661. if errcodes == gorm.ErrRecordNotFound {
  2662. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2663. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2664. if err != nil {
  2665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2666. return
  2667. }
  2668. c.ServeSuccessJSON(map[string]interface{}{
  2669. "caseHistory": caseHistory,
  2670. "historyInfo": historyInfo,
  2671. })
  2672. return
  2673. } else if errcodes == nil {
  2674. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  2675. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2676. if err != nil {
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2678. return
  2679. }
  2680. c.ServeSuccessJSON(map[string]interface{}{
  2681. "caseHistory": caseHistory,
  2682. "historyInfo": historyInfo,
  2683. })
  2684. }
  2685. //查询该患者是否有病历
  2686. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2687. //if errcode == gorm.ErrRecordNotFound {
  2688. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2689. // if err != nil {
  2690. // c.ServeSuccessJSON(map[string]interface{}{
  2691. // "msg": "保存成功",
  2692. // })
  2693. // }
  2694. //} else if errcode == nil {
  2695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2696. // return
  2697. //}
  2698. }
  2699. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2700. patient_id, _ := c.GetInt64("patient_id", 0)
  2701. adminUser := c.GetAdminUserInfo()
  2702. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2703. c.ServeSuccessJSON(map[string]interface{}{
  2704. "list": caseHistorys,
  2705. })
  2706. }
  2707. func (c *HisApiController) GetHisPatientCaseHistory() {
  2708. record_date, _ := c.GetInt64("record_date", 0)
  2709. patient_id, _ := c.GetInt64("patient_id", 0)
  2710. admin := c.GetAdminUserInfo()
  2711. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2712. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2713. c.ServeSuccessJSON(map[string]interface{}{
  2714. "info": info,
  2715. "case_history": case_history,
  2716. })
  2717. }
  2718. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2719. template_name := c.GetString("template_name")
  2720. template_remark := c.GetString("template_remark")
  2721. doctor := c.GetAdminUserInfo().AdminUser.Id
  2722. diagnostic := c.GetString("diagnostic")
  2723. chief_conplaint := c.GetString("chief_conplain")
  2724. history_of_present_illness := c.GetString("history_of_present_illness")
  2725. past_history := c.GetString("past_history")
  2726. personal_history := c.GetString("personal_history")
  2727. family_history := c.GetString("family_history")
  2728. user_name := c.GetString("user_name")
  2729. doctor_advice := c.GetString("doctor_advice")
  2730. remark := c.GetString("remark")
  2731. //record_date := c.GetString("record_date")
  2732. //fmt.Println("record_date--------",record_date)
  2733. //timeLayout := "2006-01-02"
  2734. //loc, _ := time.LoadLocation("Local")
  2735. //
  2736. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2737. //if err != nil {
  2738. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2739. // return
  2740. //}
  2741. //recordDateTime := theTime.Unix()
  2742. ctime := time.Now().Unix()
  2743. template := models.HisCaseHistoryTemplate{
  2744. HistoryOfPresentIllness: history_of_present_illness,
  2745. PastHistory: past_history,
  2746. ChiefConplaint: chief_conplaint,
  2747. PersonalHistory: personal_history,
  2748. FamilyHistory: family_history,
  2749. Diagnostic: diagnostic,
  2750. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2751. Status: 1,
  2752. Ctime: ctime,
  2753. Mtime: ctime,
  2754. RecordDate: time.Now().Unix(),
  2755. TemplateName: template_name,
  2756. TemplateRemark: template_remark,
  2757. Creator: doctor,
  2758. Modifier: doctor,
  2759. UserName: user_name,
  2760. DoctorAdvice: doctor_advice,
  2761. Remark: remark,
  2762. }
  2763. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2764. if err == nil {
  2765. c.ServeSuccessJSON(map[string]interface{}{
  2766. "msg": "保存成功",
  2767. })
  2768. } else {
  2769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2770. return
  2771. }
  2772. }
  2773. func (c *HisApiController) GetCaseHistoryTemplate() {
  2774. timeLayout := "2006-01-02"
  2775. loc, _ := time.LoadLocation("Local")
  2776. keyword := c.GetString("keyword")
  2777. start_time := c.GetString("start_time")
  2778. end_time := c.GetString("end_time")
  2779. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2780. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2781. admin := c.GetAdminUserInfo()
  2782. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2783. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2784. c.ServeSuccessJSON(map[string]interface{}{
  2785. "template": template,
  2786. //"history": history,
  2787. })
  2788. }
  2789. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2790. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2791. utils.ErrorLog("drug_name")
  2792. return enums.ErrorCodeParamWrong
  2793. }
  2794. adviceName, _ := json["drug_name"].(string)
  2795. if len(adviceName) == 0 {
  2796. utils.ErrorLog("len(advice_name) == 0")
  2797. return enums.ErrorCodeParamWrong
  2798. }
  2799. advice.AdviceName = adviceName
  2800. adviceDesc, _ := json["advice_desc"].(string)
  2801. advice.AdviceDesc = adviceDesc
  2802. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2803. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2804. advice.DrugSpec = drugSpec
  2805. }
  2806. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2807. remark, _ := json["remark"].(string)
  2808. advice.Remark = remark
  2809. }
  2810. if json["id"] == nil {
  2811. advice.DrugId = 0
  2812. } else {
  2813. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2814. drug_id := int64(json["id"].(float64))
  2815. advice.DrugId = drug_id
  2816. }
  2817. }
  2818. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2819. advice_id := int64(json["advice_id"].(float64))
  2820. advice.ID = advice_id
  2821. if advice.ID > 0 {
  2822. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2823. if err == nil {
  2824. if hisAdvice.ID > 0 {
  2825. advice.ExecutionTime = hisAdvice.ExecutionTime
  2826. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2827. advice.ExecutionState = hisAdvice.ExecutionState
  2828. advice.CheckTime = hisAdvice.CheckTime
  2829. advice.Checker = hisAdvice.Checker
  2830. advice.CheckState = hisAdvice.CheckState
  2831. advice.StartTime = hisAdvice.StartTime
  2832. advice.FeedetlSn = hisAdvice.FeedetlSn
  2833. }
  2834. }
  2835. }
  2836. }
  2837. //
  2838. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2839. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2840. // advice.ExecutionTime = execution_time
  2841. //}
  2842. //
  2843. //
  2844. //
  2845. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2846. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2847. // advice.ExecutionStaff = execution_staff
  2848. //}
  2849. //
  2850. //
  2851. //
  2852. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2853. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2854. // advice.ExecutionState = execution_state
  2855. //}
  2856. //
  2857. //
  2858. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2859. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2860. // advice.CheckTime = check_time
  2861. //}
  2862. //
  2863. //
  2864. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2865. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2866. // advice.CheckState = check_state
  2867. //}
  2868. //
  2869. //
  2870. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2871. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2872. // advice.Checker = checker
  2873. //}
  2874. //
  2875. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2876. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2877. // advice.StartTime = start_time
  2878. //}
  2879. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2880. drugSpecUnit, _ := json["min_unit"].(string)
  2881. advice.DrugSpecUnit = drugSpecUnit
  2882. }
  2883. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2884. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2885. advice.SingleDose = singleDose
  2886. }
  2887. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2888. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2889. advice.SingleDoseUnit = singleDoseUnit
  2890. }
  2891. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2892. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2893. advice.PrescribingNumber = prescribingNumber
  2894. }
  2895. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2896. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2897. advice.PrescribingNumberUnit = prescribingNumberUnit
  2898. }
  2899. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2900. deliveryWay, _ := json["delivery_way"].(string)
  2901. advice.DeliveryWay = deliveryWay
  2902. }
  2903. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2904. executionFrequency, _ := json["execution_frequency"].(string)
  2905. advice.ExecutionFrequency = executionFrequency
  2906. }
  2907. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2908. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2909. advice.Price = price
  2910. }
  2911. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2912. med_list_codg, _ := json["medical_insurance_number"].(string)
  2913. advice.MedListCodg = med_list_codg
  2914. }
  2915. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2916. day := int64(json["day"].(float64))
  2917. advice.Day = day
  2918. }
  2919. return 0
  2920. }
  2921. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2922. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2923. id := int64(json["id"].(float64))
  2924. project.ID = id
  2925. historyProject, _ := service.GetHisProjectByID(id)
  2926. project.FeedetlSn = historyProject.FeedetlSn
  2927. }
  2928. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2929. project_id := int64(json["project_id"].(float64))
  2930. project.ProjectId = project_id
  2931. }
  2932. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2933. // price := int64(json["price"].(float64))
  2934. // formatInt_price := strconv.FormatInt(price, 10)
  2935. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2936. // project.Price = float_price
  2937. // }
  2938. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2939. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2940. project.Price = price
  2941. }
  2942. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2943. total, _ := json["total"].(string)
  2944. project.Count = total
  2945. }
  2946. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2947. medical_code, _ := json["medical_code"].(string)
  2948. project.MedListCodg = medical_code
  2949. }
  2950. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2951. single_dose, _ := json["single_dose"].(string)
  2952. project.SingleDose = single_dose
  2953. }
  2954. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2955. delivery_way, _ := json["delivery_way"].(string)
  2956. project.DeliveryWay = delivery_way
  2957. }
  2958. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2959. execution_frequency, _ := json["execution_frequency"].(string)
  2960. project.ExecutionFrequency = execution_frequency
  2961. }
  2962. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2963. remark, _ := json["remark"].(string)
  2964. project.Remark = remark
  2965. }
  2966. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2967. day, _ := json["number_days"].(string)
  2968. project.Day = day
  2969. }
  2970. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2971. unit, _ := json["unit"].(string)
  2972. project.Unit = unit
  2973. }
  2974. return 0
  2975. }
  2976. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2977. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2978. id := int64(json["id"].(float64))
  2979. historyAddtions, _ := service.GetHisAdditionByID(id)
  2980. additionalCharge.ID = id
  2981. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2982. }
  2983. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2984. item_id := int64(json["item_id"].(float64))
  2985. additionalCharge.ItemId = item_id
  2986. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2987. if config.ID > 0 {
  2988. if len(config.Code) > 0 {
  2989. additionalCharge.MedListCodg = config.Code
  2990. }
  2991. }
  2992. }
  2993. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2994. // price := int64(json["price"].(float64))
  2995. // formatInt_price := strconv.FormatInt(price, 10)
  2996. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2997. // additionalCharge.Price = float_price
  2998. // }
  2999. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3000. // price := int64(json["price"].(float64))
  3001. // formatInt_price := strconv.FormatInt(price, 10)
  3002. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3003. // additionalCharge.Price = float_price
  3004. //}
  3005. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3006. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3007. additionalCharge.Price = price
  3008. }
  3009. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3010. count, _ := json["count"].(string)
  3011. counts, _ := strconv.ParseInt(count, 10, 64)
  3012. additionalCharge.Count = counts
  3013. }
  3014. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3015. item_name, _ := json["item_name"].(string)
  3016. additionalCharge.ItemName = item_name
  3017. }
  3018. return 0
  3019. }
  3020. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3021. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3022. utils.ErrorLog("drug_name")
  3023. return enums.ErrorCodeParamWrong
  3024. }
  3025. adviceName, _ := json["drug_name"].(string)
  3026. if len(adviceName) == 0 {
  3027. utils.ErrorLog("len(advice_name) == 0")
  3028. return enums.ErrorCodeParamWrong
  3029. }
  3030. advice.AdviceName = adviceName
  3031. adviceDesc, _ := json["advice_desc"].(string)
  3032. advice.AdviceDesc = adviceDesc
  3033. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3034. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3035. advice.DrugSpec = drugSpec
  3036. }
  3037. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3038. remark, _ := json["remark"].(string)
  3039. advice.Remark = remark
  3040. }
  3041. if json["id"] == nil {
  3042. advice.DrugId = 0
  3043. } else {
  3044. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3045. drug_id := int64(json["id"].(float64))
  3046. advice.DrugId = drug_id
  3047. }
  3048. }
  3049. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3050. groupno := int64(json["groupno"].(float64))
  3051. advice.Groupno = groupno
  3052. }
  3053. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3054. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3055. advice.HospApprFlag = hosp_appr_flag
  3056. }
  3057. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3058. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3059. advice.PrescribingNumber = prescribingNumber
  3060. }
  3061. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3062. // frequency_type := int64(json["frequency_type"].(float64))
  3063. // advice.FrequencyType = frequency_type
  3064. //}
  3065. //
  3066. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3067. // day_count := int64(json["day_count"].(float64))
  3068. // advice.DayCount = day_count
  3069. //}
  3070. //
  3071. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3072. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3073. // week_day, _ := json["week_day"].(string)
  3074. // advice.WeekDay = week_day
  3075. //}
  3076. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3077. drugSpecUnit, _ := json["min_unit"].(string)
  3078. advice.DrugSpecUnit = drugSpecUnit
  3079. }
  3080. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3081. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3082. advice.SingleDose = singleDose
  3083. }
  3084. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3085. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3086. advice.SingleDoseUnit = singleDoseUnit
  3087. }
  3088. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3089. deliveryWay, _ := json["delivery_way"].(string)
  3090. advice.DeliveryWay = deliveryWay
  3091. }
  3092. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3093. executionFrequency, _ := json["execution_frequency"].(string)
  3094. advice.ExecutionFrequency = executionFrequency
  3095. }
  3096. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3097. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3098. advice.Price = price
  3099. }
  3100. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3101. med_list_codg, _ := json["medical_insurance_number"].(string)
  3102. advice.MedListCodg = med_list_codg
  3103. }
  3104. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3105. day := int64(json["day"].(float64))
  3106. advice.Day = day
  3107. }
  3108. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3109. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3110. advice.PrescribingNumberUnit = prescribingNumberUnit
  3111. }
  3112. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3113. advice_id := int64(json["advice_id"].(float64))
  3114. advice.ID = advice_id
  3115. if advice.ID > 0 {
  3116. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3117. if err == nil {
  3118. if hisAdvice.ID > 0 {
  3119. advice.ExecutionTime = hisAdvice.ExecutionTime
  3120. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3121. advice.ExecutionState = hisAdvice.ExecutionState
  3122. advice.CheckTime = hisAdvice.CheckTime
  3123. advice.Checker = hisAdvice.Checker
  3124. advice.CheckState = hisAdvice.CheckState
  3125. advice.StartTime = hisAdvice.StartTime
  3126. advice.HospApprFlag = hisAdvice.HospApprFlag
  3127. if hisAdvice.UserOrgId == 10028 {
  3128. 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 {
  3129. advice.ExecutionTime = 0
  3130. advice.ExecutionStaff = 0
  3131. advice.ExecutionState = 2
  3132. advice.CheckTime = 0
  3133. advice.Checker = 0
  3134. advice.CheckState = 2
  3135. }
  3136. } else {
  3137. 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 {
  3138. advice.ExecutionTime = 0
  3139. advice.ExecutionStaff = 0
  3140. advice.ExecutionState = 2
  3141. advice.CheckTime = 0
  3142. advice.Checker = 0
  3143. advice.CheckState = 2
  3144. }
  3145. }
  3146. //advice.Groupno = hisAdvice.Groupno
  3147. }
  3148. }
  3149. }
  3150. }
  3151. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3152. //
  3153. //if drugStockConfig.IsOpen == 1 {
  3154. //
  3155. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3156. // if advice.ID == 0 { //医嘱不存在
  3157. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3158. // drug.Total = drug.Total - advice.PrescribingNumber
  3159. // service.UpdateBaseDrugLib(&drug)
  3160. //
  3161. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3162. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3163. // drug.Total = drug.Total - num
  3164. // service.UpdateBaseDrugLib(&drug)
  3165. // }
  3166. //
  3167. // } else if advice.ID > 0 { //医嘱存在
  3168. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3169. // var num float64
  3170. //
  3171. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3172. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3173. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3174. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3175. // drug.Total = drug.Total + num
  3176. // service.UpdateBaseDrugLib(&drug)
  3177. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3178. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3179. // drug.Total = drug.Total - num
  3180. // service.UpdateBaseDrugLib(&drug)
  3181. // }
  3182. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3183. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3184. // if num2 > advice.PrescribingNumber {
  3185. // num = num2 - advice.PrescribingNumber
  3186. // drug.Total = drug.Total + num
  3187. // service.UpdateBaseDrugLib(&drug)
  3188. // } else if num2 < advice.PrescribingNumber {
  3189. // num = advice.PrescribingNumber - num2
  3190. // drug.Total = drug.Total - num
  3191. // service.UpdateBaseDrugLib(&drug)
  3192. // }
  3193. //
  3194. // }
  3195. //
  3196. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3197. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3198. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3199. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3200. // if num1 > num2 {
  3201. // num = num1 - num2
  3202. // drug.Total = drug.Total + num
  3203. // service.UpdateBaseDrugLib(&drug)
  3204. // } else if num1 < num2 {
  3205. // num = num2 - num1
  3206. // drug.Total = drug.Total - num
  3207. // service.UpdateBaseDrugLib(&drug)
  3208. // }
  3209. //
  3210. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3211. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3212. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3213. // if hisAdvice.PrescribingNumber > num2 {
  3214. // num = hisAdvice.PrescribingNumber - num2
  3215. // drug.Total = drug.Total + num
  3216. // service.UpdateBaseDrugLib(&drug)
  3217. // } else if num2 < advice.PrescribingNumber {
  3218. // num = num2 - hisAdvice.PrescribingNumber
  3219. // drug.Total = drug.Total - num
  3220. // service.UpdateBaseDrugLib(&drug)
  3221. // }
  3222. //
  3223. // }
  3224. // }
  3225. // }
  3226. //}
  3227. //
  3228. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3229. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3230. // advice.ExecutionTime = execution_time
  3231. //}
  3232. //
  3233. //
  3234. //
  3235. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3236. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3237. // advice.ExecutionStaff = execution_staff
  3238. //}
  3239. //
  3240. //
  3241. //
  3242. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3243. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3244. // advice.ExecutionState = execution_state
  3245. //}
  3246. //
  3247. //
  3248. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3249. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3250. // advice.CheckTime = check_time
  3251. //}
  3252. //
  3253. //
  3254. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3255. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3256. // advice.CheckState = check_state
  3257. //}
  3258. //
  3259. //
  3260. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3261. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3262. // advice.Checker = checker
  3263. //}
  3264. //
  3265. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3266. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3267. // advice.StartTime = start_time
  3268. //}
  3269. return 0
  3270. }
  3271. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3272. project.ExecutionStaff = 0
  3273. project.ExecutionState = 2
  3274. project.ExecutionTime = 0
  3275. project.Checker = 0
  3276. project.CheckState = 2
  3277. project.CheckTime = 0
  3278. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3279. id := int64(json["id"].(float64))
  3280. project.ID = id
  3281. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3282. project.ExecutionStaff = temp_project.ExecutionStaff
  3283. project.ExecutionState = temp_project.ExecutionState
  3284. project.ExecutionTime = temp_project.ExecutionTime
  3285. project.Checker = temp_project.Checker
  3286. project.CheckState = temp_project.CheckState
  3287. project.CheckTime = temp_project.CheckTime
  3288. project.TeamId = temp_project.TeamId
  3289. }
  3290. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3291. types := int64(json["type"].(float64))
  3292. project.Type = types
  3293. }
  3294. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3295. project_id := int64(json["project_id"].(float64))
  3296. project.ProjectId = project_id
  3297. }
  3298. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3299. team_id := int64(json["team_id"].(float64))
  3300. project.TeamId = team_id
  3301. }
  3302. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3303. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3304. project.Price = price
  3305. }
  3306. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3307. total, _ := json["total"].(string)
  3308. //totals, _ := strconv.ParseInt(total, 10, 64)
  3309. project.Count = total
  3310. }
  3311. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3312. medical_code, _ := json["medical_code"].(string)
  3313. project.MedListCodg = medical_code
  3314. }
  3315. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3316. single_dose, _ := json["single_dose"].(string)
  3317. project.SingleDose = single_dose
  3318. }
  3319. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3320. delivery_way, _ := json["delivery_way"].(string)
  3321. project.DeliveryWay = delivery_way
  3322. }
  3323. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3324. execution_frequency, _ := json["execution_frequency"].(string)
  3325. project.ExecutionFrequency = execution_frequency
  3326. }
  3327. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3328. remark, _ := json["remark"].(string)
  3329. project.Remark = remark
  3330. }
  3331. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3332. day, _ := json["number_days"].(string)
  3333. project.Day = day
  3334. }
  3335. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3336. unit, _ := json["unit"].(string)
  3337. project.Unit = unit
  3338. }
  3339. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3340. // frequency_type := int64(json["frequency_type"].(float64))
  3341. // project.FrequencyType = frequency_type
  3342. //}
  3343. //
  3344. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3345. // day_count := int64(json["day_count"].(float64))
  3346. // project.DayCount = day_count
  3347. //}
  3348. //
  3349. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3350. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3351. // week_day, _ := json["week_day"].(string)
  3352. // project.WeekDay = week_day
  3353. //}
  3354. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3355. //
  3356. //if project.ID == 0 {
  3357. // if stockConfig.IsOpen == 1 {
  3358. // if project.Type == 3 {
  3359. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3360. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3361. // good.Total = good.Total - f_count
  3362. // service.UpdateGoodInfo(&good)
  3363. // }
  3364. // }
  3365. //
  3366. //} else {
  3367. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3368. //
  3369. // if stockConfig.IsOpen == 1 {
  3370. // if project.Type == 3 {
  3371. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3372. // if project.Count < temp_project.Count {
  3373. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3374. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3375. //
  3376. // other_count := f_count_two - f_count_one
  3377. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3378. // good.Total = good.Total + other_count_two
  3379. // service.UpdateGoodInfo(&good)
  3380. // } else if project.Count > temp_project.Count {
  3381. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3382. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3383. //
  3384. // other_count := f_count_one - f_count_two
  3385. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3386. // good.Total = good.Total - other_count_two
  3387. // service.UpdateGoodInfo(&good)
  3388. // }
  3389. //
  3390. // }
  3391. // }
  3392. //
  3393. //}
  3394. return 0
  3395. }
  3396. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3397. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3398. id := int64(json["id"].(float64))
  3399. additionalCharge.ID = id
  3400. }
  3401. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3402. item_id := int64(json["item_id"].(float64))
  3403. additionalCharge.ItemId = item_id
  3404. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3405. if config.ID > 0 {
  3406. if len(config.Code) > 0 {
  3407. additionalCharge.MedListCodg = config.Code
  3408. }
  3409. }
  3410. }
  3411. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3412. // price := int64(json["price"].(float64))
  3413. // formatInt_price := strconv.FormatInt(price, 10)
  3414. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3415. // additionalCharge.Price = float_price
  3416. // }
  3417. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3418. // price := int64(json["price"].(float64))
  3419. // formatInt_price := strconv.FormatInt(price, 10)
  3420. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3421. // additionalCharge.Price = float_price
  3422. //}
  3423. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3424. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3425. additionalCharge.Price = price
  3426. }
  3427. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3428. count, _ := json["count"].(string)
  3429. counts, _ := strconv.ParseInt(count, 10, 64)
  3430. additionalCharge.Count = counts
  3431. }
  3432. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3433. item_name, _ := json["item_name"].(string)
  3434. additionalCharge.ItemName = item_name
  3435. }
  3436. return 0
  3437. }
  3438. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3439. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3440. utils.ErrorLog("drug_name")
  3441. return enums.ErrorCodeParamWrong
  3442. }
  3443. adviceName, _ := json["drug_name"].(string)
  3444. if len(adviceName) == 0 {
  3445. utils.ErrorLog("len(advice_name) == 0")
  3446. return enums.ErrorCodeParamWrong
  3447. }
  3448. advice.AdviceName = adviceName
  3449. adviceDesc, _ := json["advice_desc"].(string)
  3450. advice.AdviceDesc = adviceDesc
  3451. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3452. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3453. advice.DrugSpec = drugSpec
  3454. }
  3455. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3456. remark, _ := json["remark"].(string)
  3457. advice.Remark = remark
  3458. }
  3459. if json["id"] == nil {
  3460. advice.DrugId = 0
  3461. } else {
  3462. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3463. drug_id := int64(json["id"].(float64))
  3464. advice.DrugId = drug_id
  3465. }
  3466. }
  3467. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3468. drugSpecUnit, _ := json["min_unit"].(string)
  3469. advice.DrugSpecUnit = drugSpecUnit
  3470. }
  3471. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3472. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3473. advice.SingleDose = singleDose
  3474. }
  3475. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3476. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3477. advice.SingleDoseUnit = singleDoseUnit
  3478. }
  3479. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3480. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3481. advice.PrescribingNumber = prescribingNumber
  3482. }
  3483. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3484. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3485. advice.PrescribingNumberUnit = prescribingNumberUnit
  3486. }
  3487. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3488. deliveryWay, _ := json["delivery_way"].(string)
  3489. advice.DeliveryWay = deliveryWay
  3490. }
  3491. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3492. executionFrequency, _ := json["execution_frequency"].(string)
  3493. advice.ExecutionFrequency = executionFrequency
  3494. }
  3495. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3496. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3497. advice.Price = price
  3498. }
  3499. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3500. med_list_codg, _ := json["medical_insurance_number"].(string)
  3501. advice.MedListCodg = med_list_codg
  3502. }
  3503. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3504. day := int64(json["day"].(float64))
  3505. advice.Day = day
  3506. }
  3507. return 0
  3508. }
  3509. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3510. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3511. types := int64(json["type"].(float64))
  3512. project.Type = types
  3513. }
  3514. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3515. project_id := int64(json["project_id"].(float64))
  3516. project.ProjectId = project_id
  3517. }
  3518. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3519. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3520. project.Price = price
  3521. }
  3522. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3523. total, _ := json["total"].(string)
  3524. //totals, _ := strconv.ParseInt(total, 10, 64)
  3525. project.Count = total
  3526. }
  3527. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3528. medical_code, _ := json["medical_code"].(string)
  3529. project.MedListCodg = medical_code
  3530. }
  3531. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3532. single_dose, _ := json["single_dose"].(string)
  3533. project.SingleDose = single_dose
  3534. }
  3535. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3536. delivery_way, _ := json["delivery_way"].(string)
  3537. project.DeliveryWay = delivery_way
  3538. }
  3539. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3540. execution_frequency, _ := json["execution_frequency"].(string)
  3541. project.ExecutionFrequency = execution_frequency
  3542. }
  3543. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3544. remark, _ := json["remark"].(string)
  3545. project.Remark = remark
  3546. }
  3547. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3548. day, _ := json["number_days"].(string)
  3549. project.Day = day
  3550. }
  3551. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3552. unit, _ := json["unit"].(string)
  3553. project.Unit = unit
  3554. }
  3555. return 0
  3556. }
  3557. func (c *HisApiController) GetHisOrderList() {
  3558. page, _ := c.GetInt64("page", -1)
  3559. limit, _ := c.GetInt64("limit", -1)
  3560. start_time := c.GetString("start_time")
  3561. end_time := c.GetString("end_time")
  3562. types, _ := c.GetInt64("type", 0)
  3563. keywords := c.GetString("keywords")
  3564. p_type, _ := c.GetInt64("p_type", 0)
  3565. sort_type, _ := c.GetInt64("sort_type", 0)
  3566. charge_type, _ := c.GetInt64("charge_type", 0)
  3567. timeLayout := "2006-01-02"
  3568. loc, _ := time.LoadLocation("Local")
  3569. var startTime int64
  3570. if len(start_time) > 0 {
  3571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3572. if err != nil {
  3573. fmt.Println(err)
  3574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3575. return
  3576. }
  3577. startTime = theTime.Unix()
  3578. }
  3579. var endTime int64
  3580. if len(end_time) > 0 {
  3581. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3582. if err != nil {
  3583. utils.ErrorLog(err.Error())
  3584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3585. return
  3586. }
  3587. endTime = theTime.Unix()
  3588. }
  3589. adminUser := c.GetAdminUserInfo()
  3590. org_id := adminUser.CurrentOrgId
  3591. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  3592. for _, item := range order {
  3593. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3594. item.DoctorName = info.Doctor
  3595. item.DepartmentName = info.XtHisDepartment.Name
  3596. }
  3597. if err == nil {
  3598. c.ServeSuccessJSON(map[string]interface{}{
  3599. "order": order,
  3600. "total": total,
  3601. })
  3602. } else {
  3603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3604. return
  3605. }
  3606. }
  3607. func (c *HisApiController) GetHisOrder() {
  3608. patient_id, _ := c.GetInt64("patient_id", 0)
  3609. number := c.GetString("number")
  3610. adminInfo := c.GetAdminUserInfo()
  3611. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3612. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3613. if err == nil {
  3614. c.ServeSuccessJSON(map[string]interface{}{
  3615. "order": order,
  3616. "prescription": prescriptions,
  3617. })
  3618. } else {
  3619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3620. return
  3621. }
  3622. }
  3623. func (c *HisApiController) GetHisPrescriptionList() {
  3624. record_date := c.GetString("record_date")
  3625. keywords := c.GetString("keywords")
  3626. page, _ := c.GetInt64("page")
  3627. limit, _ := c.GetInt64("limit")
  3628. timeLayout := "2006-01-02"
  3629. loc, _ := time.LoadLocation("Local")
  3630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3631. if err != nil {
  3632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3633. return
  3634. }
  3635. recordDateTime := theTime.Unix()
  3636. adminInfo := c.GetAdminUserInfo()
  3637. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3638. //adminInfo := c.GetAdminUserInfo()
  3639. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3640. //fmt.Println(prescriptionOrder)
  3641. if err == nil {
  3642. c.ServeSuccessJSON(map[string]interface{}{
  3643. "order": prescriptionOrder,
  3644. "total": total,
  3645. })
  3646. } else {
  3647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3648. return
  3649. }
  3650. }
  3651. func (c *HisApiController) GetHisPrescriptionInfo() {
  3652. id, _ := c.GetInt64("id")
  3653. adminInfo := c.GetAdminUserInfo()
  3654. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3655. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3656. if err == nil {
  3657. c.ServeSuccessJSON(map[string]interface{}{
  3658. "order": prescriptionOrder,
  3659. "prescription": prescription,
  3660. })
  3661. } else {
  3662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3663. return
  3664. }
  3665. }
  3666. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3667. adminUser := c.GetAdminUserInfo()
  3668. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3669. c.ServeSuccessJSON(map[string]interface{}{
  3670. "config": config,
  3671. })
  3672. }
  3673. type ResultTwo struct {
  3674. ErrMsg interface{} `json:"err_msg"`
  3675. InfRefmsgid string `json:"inf_refmsgid"`
  3676. Infcode int64 `json:"infcode"`
  3677. Output struct {
  3678. Baseinfo struct {
  3679. Age float64 `json:"age"`
  3680. Brdy string `json:"brdy"`
  3681. Certno string `json:"certno"`
  3682. Gend string `json:"gend"`
  3683. Naty string `json:"naty"`
  3684. PsnCertType string `json:"psn_cert_type"`
  3685. PsnName string `json:"psn_name"`
  3686. PsnNo string `json:"psn_no"`
  3687. } `json:"baseinfo"`
  3688. Idetinfo []interface{} `json:"idetinfo"`
  3689. Iinfo []struct {
  3690. Balc float64 `json:"balc"`
  3691. CvlservFlag string `json:"cvlserv_flag"`
  3692. EmpName string `json:"emp_name"`
  3693. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3694. Insutype string `json:"insutype"`
  3695. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3696. PausInsuDate interface{} `json:"paus_insu_date"`
  3697. PsnInsuDate string `json:"psn_insu_date"`
  3698. PsnInsuStas string `json:"psn_insu_stas"`
  3699. PsnType string `json:"psn_type"`
  3700. } `json:"insuinfo"`
  3701. } `json:"output"`
  3702. RefmsgTime string `json:"refmsg_time"`
  3703. RespondTime string `json:"respond_time"`
  3704. Signtype interface{} `json:"signtype"`
  3705. WarnInfo interface{} `json:"warn_info"`
  3706. }
  3707. type ResultThree struct {
  3708. Cainfo interface{} `json:"cainfo"`
  3709. ErrMsg interface{} `json:"err_msg"`
  3710. InfRefmsgid string `json:"inf_refmsgid"`
  3711. Infcode int64 `json:"infcode"`
  3712. Output struct {
  3713. Data struct {
  3714. IptOtpNo string `json:"ipt_otp_no"`
  3715. MdtrtID string `json:"mdtrt_id"`
  3716. PsnNo string `json:"psn_no"`
  3717. } `json:"data"`
  3718. } `json:"output"`
  3719. RefmsgTime string `json:"refmsg_time"`
  3720. RespondTime string `json:"respond_time"`
  3721. Signtype interface{} `json:"signtype"`
  3722. WarnMsg interface{} `json:"warn_msg"`
  3723. }
  3724. type ResultFour struct {
  3725. Cainfo string `json:"cainfo"`
  3726. ErrMsg string `json:"err_msg"`
  3727. InfRefmsgid string `json:"inf_refmsgid"`
  3728. Infcode int64 `json:"infcode"`
  3729. Output struct {
  3730. Result []struct {
  3731. BasMednFlag string `json:"bas_medn_flag"`
  3732. ChldMedcFlag string `json:"chld_medc_flag"`
  3733. ChrgitmLv string `json:"chrgitm_lv"`
  3734. Cnt float64 `json:"cnt"`
  3735. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3736. DrtReimFlag string `json:"drt_reim_flag"`
  3737. FeedetlSn string `json:"feedetl_sn"`
  3738. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3739. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3740. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3741. ListSpItemFlag string `json:"list_sp_item_flag"`
  3742. LmtUsedFlag string `json:"lmt_used_flag"`
  3743. MedChrgitmType string `json:"med_chrgitm_type"`
  3744. Memo string `json:"memo"`
  3745. OverlmtAmt float64 `json:"overlmt_amt"`
  3746. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3747. Pric float64 `json:"pric"`
  3748. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3749. SelfpayProp float64 `json:"selfpay_prop"`
  3750. } `json:"result"`
  3751. } `json:"output"`
  3752. RefmsgTime string `json:"refmsg_time"`
  3753. RespondTime string `json:"respond_time"`
  3754. Signtype string `json:"signtype"`
  3755. WarnMsg string `json:"warn_msg"`
  3756. }
  3757. type ResultFive struct {
  3758. Insutype string `json:"insutype"`
  3759. }
  3760. type ResultSix struct {
  3761. Cainfo interface{} `json:"cainfo"`
  3762. ErrMsg interface{} `json:"err_msg"`
  3763. InfRefmsgid string `json:"inf_refmsgid"`
  3764. Infcode int64 `json:"infcode"`
  3765. Output struct {
  3766. } `json:"output"`
  3767. RefmsgTime string `json:"refmsg_time"`
  3768. RespondTime string `json:"respond_time"`
  3769. Signtype interface{} `json:"signtype"`
  3770. WarnMsg interface{} `json:"warn_msg"`
  3771. }
  3772. type ResultSeven struct {
  3773. Cainfo string `json:"cainfo"`
  3774. ErrMsg string `json:"err_msg"`
  3775. InfRefmsgid string `json:"inf_refmsgid"`
  3776. Infcode int64 `json:"infcode"`
  3777. Output struct {
  3778. Setldetail []interface{} `json:"setldetail"`
  3779. Setlinfo struct {
  3780. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3781. AcctPay float64 `json:"acct_pay"`
  3782. ActPayDedc float64 `json:"act_pay_dedc"`
  3783. Age float64 `json:"age"`
  3784. Balc float64 `json:"balc"`
  3785. Brdy string `json:"brdy"`
  3786. Certno string `json:"certno"`
  3787. ClrOptins string `json:"clr_optins"`
  3788. ClrType string `json:"clr_type"`
  3789. ClrWay string `json:"clr_way"`
  3790. CvlservFlag string `json:"cvlserv_flag"`
  3791. CvlservPay float64 `json:"cvlserv_pay"`
  3792. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3793. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3794. Gend string `json:"gend"`
  3795. HifesPay float64 `json:"hifes_pay"`
  3796. HifmiPay float64 `json:"hifmi_pay"`
  3797. HifobPay float64 `json:"hifob_pay"`
  3798. HifpPay float64 `json:"hifp_pay"`
  3799. HospPartAmt float64 `json:"hosp_part_amt"`
  3800. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3801. Insutype string `json:"insutype"`
  3802. MafPay float64 `json:"maf_pay"`
  3803. MdtrtCertType string `json:"mdtrt_cert_type"`
  3804. MdtrtID string `json:"mdtrt_id"`
  3805. MedType string `json:"med_type"`
  3806. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3807. MedinsSetlID string `json:"medins_setl_id"`
  3808. Naty string `json:"naty"`
  3809. OthPay float64 `json:"oth_pay"`
  3810. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3811. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3812. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3813. PsnCashPay float64 `json:"psn_cash_pay"`
  3814. PsnCertType string `json:"psn_cert_type"`
  3815. PsnName string `json:"psn_name"`
  3816. PsnNo string `json:"psn_no"`
  3817. PsnPartAmt float64 `json:"psn_part_amt"`
  3818. PsnType string `json:"psn_type"`
  3819. SetlID string `json:"setl_id"`
  3820. SetlTime string `json:"setl_time"`
  3821. } `json:"setlinfo"`
  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 ResultEight 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. Stmtinfo struct {
  3835. SetlOptins string `json:"setl_optins"`
  3836. StmtRslt string `json:"stmt_rslt"`
  3837. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3838. } `json:"stmtinfo"`
  3839. } `json:"output"`
  3840. RefmsgTime string `json:"refmsg_time"`
  3841. RespondTime string `json:"respond_time"`
  3842. Signtype interface{} `json:"signtype"`
  3843. WarnMsg interface{} `json:"warn_msg"`
  3844. }
  3845. type ResultNine struct {
  3846. Cainfo string `json:"cainfo"`
  3847. ErrMsg string `json:"err_msg"`
  3848. InfRefmsgid string `json:"inf_refmsgid"`
  3849. Infcode int64 `json:"infcode"`
  3850. Output struct {
  3851. FileQuryNo string `json:"file_qury_no"`
  3852. } `json:"output"`
  3853. RefmsgTime string `json:"refmsg_time"`
  3854. RespondTime string `json:"respond_time"`
  3855. Signtype interface{} `json:"signtype"`
  3856. WarnMsg interface{} `json:"warn_msg"`
  3857. }
  3858. type ResultTen struct {
  3859. Cainfo string `json:"cainfo"`
  3860. ErrMsg string `json:"err_msg"`
  3861. InfRefmsgid string `json:"inf_refmsgid"`
  3862. Infcode int64 `json:"infcode"`
  3863. Output struct {
  3864. DldEndtime string `json:"dld_endtime"`
  3865. FileQuryNo string `json:"file_qury_no"`
  3866. Filename string `json:"filename"`
  3867. } `json:"output"`
  3868. RefmsgTime string `json:"refmsg_time"`
  3869. RespondTime string `json:"respond_time"`
  3870. Signtype interface{} `json:"signtype"`
  3871. WarnMsg interface{} `json:"warn_msg"`
  3872. }
  3873. type ResultEleven struct {
  3874. Cainfo string `json:"cainfo"`
  3875. ErrMsg string `json:"err_msg"`
  3876. InfRefmsgid string `json:"inf_refmsgid"`
  3877. Infcode int64 `json:"infcode"`
  3878. Output struct {
  3879. Setlinfo struct {
  3880. FixmedinsName string `json:"fixmedins_name"`
  3881. FixmedinsCode string `json:"fixmedins_code"`
  3882. PsnNo string `json:"psn_no"`
  3883. PsnName string `json:"psn_name"`
  3884. HifobPay float64 `json:"hifob_pay"`
  3885. Gend string `json:"gend"`
  3886. Brdy string `json:"brdy"`
  3887. PsnCertType string `json:"psn_cert_type"`
  3888. PsnType string `json:"psn_type"`
  3889. EmpName string `json:"emp_name"`
  3890. Certno string `json:"certno"`
  3891. Insutype string `json:"insutype"`
  3892. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3893. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3894. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3895. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3896. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3897. ActPayDedc float64 `json:"act_pay_dedc"`
  3898. HifpPay float64 `json:"hifp_pay"`
  3899. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3900. CvlservPay float64 `json:"cvlserv_pay"`
  3901. HifesPay float64 `json:"hifes_pay"`
  3902. HifmiPay float64 `json:"hifmi_pay"`
  3903. MafPay float64 `json:"maf_pay"`
  3904. OthPay float64 `json:"oth_pay"`
  3905. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3906. PsnPay float64 `json:"psn_pay"`
  3907. AcctPay float64 `json:"acct_pay"`
  3908. CashPayamt float64 `json:"cash_payamt"`
  3909. Balc float64 `json:"balc"`
  3910. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3911. MedinsSetlId string `json:"medins_setl_id"`
  3912. RefdSetlFlag string `json:"refd_setl_flag"`
  3913. SetlTime string `json:"setl_time"`
  3914. MedType string `json:"med_type"`
  3915. } `json:"setlinfo"`
  3916. } `json:"output"`
  3917. RefmsgTime string `json:"refmsg_time"`
  3918. RespondTime string `json:"respond_time"`
  3919. Signtype interface{} `json:"signtype"`
  3920. WarnMsg interface{} `json:"warn_msg"`
  3921. }
  3922. type Custom struct {
  3923. DetItemFeeSumamt string
  3924. Cut string
  3925. FeedetlSn string
  3926. Price string
  3927. MedListCodg string
  3928. Type int64
  3929. AdviceId int64
  3930. ProjectId int64
  3931. ItemId int64
  3932. }
  3933. //获取个人信息----挂号-----上传就诊信息
  3934. func (c *HisApiController) GetRegisterInfo() {
  3935. id, _ := c.GetInt64("id")
  3936. record_time := c.GetString("record_time")
  3937. settlementValue, _ := c.GetInt64("settlement_value")
  3938. medical_insurance_card := c.GetString("medical_insurance_card")
  3939. name := c.GetString("name")
  3940. id_card_type, _ := c.GetInt64("id_card_type")
  3941. certificates, _ := c.GetInt64("certificates")
  3942. medical_care, _ := c.GetInt64("medical_care")
  3943. birthday := c.GetString("birthday")
  3944. age, _ := c.GetInt64("age")
  3945. id_card := c.GetString("id_card")
  3946. register_type, _ := c.GetInt64("register")
  3947. doctor, _ := c.GetInt64("doctor")
  3948. department, _ := c.GetInt64("department")
  3949. gender, _ := c.GetInt64("sex")
  3950. phone := c.GetString("phone")
  3951. registration_fee, _ := c.GetFloat("registration_fee")
  3952. medical_expenses, _ := c.GetFloat("medical_expenses")
  3953. social_type, _ := c.GetInt64("social_type")
  3954. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3955. diagnosis_ids := c.GetString("diagnosis")
  3956. sick_type, _ := c.GetInt64("sick_type")
  3957. reg_type := c.GetString("p_type")
  3958. timeLayout := "2006-01-02"
  3959. loc, _ := time.LoadLocation("Local")
  3960. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3961. birthUnix := birthdays.Unix()
  3962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3963. if err != nil {
  3964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3965. return
  3966. }
  3967. recordDateTime := theTime.Unix()
  3968. adminInfo := c.GetAdminUserInfo()
  3969. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3970. if tempPatient.ID == 0 {
  3971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3972. return
  3973. }
  3974. var patient service.Patients
  3975. if id == 0 {
  3976. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3977. } else {
  3978. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3979. }
  3980. if patient.ID == 0 {
  3981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3982. return
  3983. }
  3984. if len(patient.IdCardNo) == 0 {
  3985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3986. return
  3987. }
  3988. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3989. if len(his) >= 1 {
  3990. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3991. if len(his) >= 1 && order.ID == 0 {
  3992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3993. return
  3994. }
  3995. }
  3996. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3997. fmt.Println(timeStr)
  3998. timeArr := strings.Split(timeStr, " ")
  3999. fmt.Println(timeArr)
  4000. timeArrTwo := strings.Split(timeArr[0], "-")
  4001. timeArrThree := strings.Split(timeArr[1], ":")
  4002. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4003. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4004. if len(lists) == 0 {
  4005. var hisPatient models.XtHisPatient
  4006. hisPatient = models.XtHisPatient{
  4007. Name: name,
  4008. Age: age,
  4009. Gender: gender,
  4010. Birthday: birthUnix,
  4011. Phone: phone,
  4012. MedicalTreatmentType: medical_care,
  4013. IdType: certificates,
  4014. IdCardNo: id_card,
  4015. BalanceAccountsType: settlementValue,
  4016. SocialType: social_type,
  4017. MedicalInsuranceNumber: medical_insurance_card,
  4018. RegisterType: register_type,
  4019. RegisterCost: registration_fee,
  4020. TreatmentCost: medical_expenses,
  4021. AdminUserId: adminInfo.AdminUser.Id,
  4022. UserOrgId: adminInfo.CurrentOrgId,
  4023. Status: 1,
  4024. RecordDate: recordDateTime,
  4025. IsReturn: 1,
  4026. PatientId: patient.ID,
  4027. Ctime: time.Now().Unix(),
  4028. Mtime: time.Now().Unix(),
  4029. Number: str,
  4030. IdCardType: id_card_type,
  4031. Departments: department,
  4032. Doctor: doctor,
  4033. PType: reg_type,
  4034. Diagnosis: diagnosis_ids,
  4035. SickType: sick_type,
  4036. }
  4037. service.CreateHisPatient(&hisPatient)
  4038. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4039. c.ServeSuccessJSON(map[string]interface{}{
  4040. "his_info": hisPatient,
  4041. })
  4042. } else {
  4043. //chrgBchno := rand.Intn(1000000) + 10000
  4044. var hisPatient models.XtHisPatient
  4045. hisPatient = models.XtHisPatient{
  4046. Name: name,
  4047. Age: age,
  4048. Gender: gender,
  4049. Birthday: birthUnix,
  4050. Phone: phone,
  4051. MedicalTreatmentType: medical_care,
  4052. IdType: certificates,
  4053. IdCardNo: id_card,
  4054. BalanceAccountsType: settlementValue,
  4055. SocialType: social_type,
  4056. MedicalInsuranceNumber: medical_insurance_card,
  4057. RegisterType: register_type,
  4058. RegisterCost: registration_fee,
  4059. TreatmentCost: medical_expenses,
  4060. AdminUserId: adminInfo.AdminUser.Id,
  4061. UserOrgId: adminInfo.CurrentOrgId,
  4062. Status: 1,
  4063. RecordDate: recordDateTime,
  4064. IsReturn: 1,
  4065. PatientId: patient.ID,
  4066. Ctime: time.Now().Unix(),
  4067. Mtime: time.Now().Unix(),
  4068. Number: str,
  4069. IdCardType: id_card_type,
  4070. Departments: department,
  4071. Doctor: doctor,
  4072. PType: reg_type,
  4073. Diagnosis: diagnosis_ids,
  4074. SickType: sick_type,
  4075. }
  4076. service.CreateHisPatient(&hisPatient)
  4077. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4078. c.ServeSuccessJSON(map[string]interface{}{
  4079. "his_info": hisPatient,
  4080. })
  4081. }
  4082. }
  4083. //上传明细----结算
  4084. func (c *HisApiController) GetUploadInfo() {
  4085. id, _ := c.GetInt64("id")
  4086. record_time := c.GetString("record_time")
  4087. his_patient_id, _ := c.GetInt64("his_patient_id")
  4088. pay_way, _ := c.GetInt64("pay_way")
  4089. pay_price, _ := c.GetFloat("pay_price")
  4090. pay_card_no := c.GetString("pay_card_no")
  4091. discount_price, _ := c.GetFloat("discount_price")
  4092. preferential_price, _ := c.GetFloat("preferential_price")
  4093. reality_price, _ := c.GetFloat("reality_price")
  4094. found_price, _ := c.GetFloat("found_price")
  4095. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4096. private_price, _ := c.GetFloat("private_price")
  4097. timeLayout := "2006-01-02"
  4098. loc, _ := time.LoadLocation("Local")
  4099. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4100. fapiao_code := c.GetString("fapiao_code")
  4101. fapiao_number := c.GetString("fapiao_number")
  4102. diagnosis_id := c.GetString("diagnosis")
  4103. sick_type, _ := c.GetInt64("sick_type")
  4104. reg_type, _ := c.GetInt64("p_type")
  4105. order_id, _ := c.GetInt64("order_id")
  4106. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  4107. tmp_decimal := c.GetString("tmp_decimal")
  4108. var decimal float64 //本次使用的押金
  4109. var errmsg error
  4110. tx := service.XTWriteDB().Begin() //开了事务
  4111. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  4112. defer func() {
  4113. if errmsg != nil {
  4114. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  4115. tx.Rollback()
  4116. } else {
  4117. tx.Commit()
  4118. }
  4119. }()
  4120. if dec_way == "true" && tmp_decimal == "0" && tmp_decimal == "" {
  4121. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  4122. return
  4123. }
  4124. if len(tmp_decimal) > 0 {
  4125. if tmp_decimal[0] == 45 {
  4126. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  4127. return
  4128. }
  4129. }
  4130. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  4131. if errs != nil {
  4132. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  4133. return
  4134. }
  4135. decimal = tt
  4136. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  4137. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  4138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4139. if err != nil {
  4140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4141. return
  4142. }
  4143. recordDateTime := theTime.Unix()
  4144. adminUser := c.GetAdminUserInfo()
  4145. var prescriptions []*models.HisPrescription
  4146. var start_time int64
  4147. var end_time int64
  4148. ids_str := c.GetString("ids")
  4149. ids_arr := strings.Split(ids_str, ",")
  4150. if tempOrder.ID == 0 {
  4151. if settle_accounts_type == 1 { //日结
  4152. fmt.Println(reg_type)
  4153. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4154. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  4155. } else {
  4156. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  4157. }
  4158. } else { //月结
  4159. start_time_str := c.GetString("start_time")
  4160. end_time_str := c.GetString("end_time")
  4161. timeLayout := "2006-01-02"
  4162. loc, _ := time.LoadLocation("Local")
  4163. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4164. if err != nil {
  4165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4166. return
  4167. }
  4168. recordStartTime := theStartTime.Unix()
  4169. start_time = recordStartTime
  4170. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4171. if err != nil {
  4172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4173. return
  4174. }
  4175. recordEndTime := theEndTime.Unix()
  4176. end_time = recordEndTime
  4177. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  4178. }
  4179. timestamp := time.Now().Unix()
  4180. tempTime := time.Unix(timestamp, 0)
  4181. timeFormat := tempTime.Format("20060102150405")
  4182. chrgBchno := rand.Intn(100000) + 10000
  4183. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4184. strconv.FormatInt(his.PatientId, 10)
  4185. var ids []int64
  4186. for _, item := range prescriptions {
  4187. ids = append(ids, item.ID)
  4188. }
  4189. var total float64
  4190. for _, item := range prescriptions {
  4191. fmt.Println(item)
  4192. if item.Type == 1 { //药品
  4193. for _, subItem := range item.HisDoctorAdviceInfo {
  4194. total = total + (subItem.Price * subItem.PrescribingNumber)
  4195. }
  4196. }
  4197. if item.Type == 2 { //项目
  4198. for _, subItem := range item.HisPrescriptionProject {
  4199. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4200. total = total + (subItem.Price * cnt)
  4201. }
  4202. }
  4203. for _, subItem := range item.HisAdditionalCharge {
  4204. total = total + (subItem.Price * float64(subItem.Count))
  4205. }
  4206. }
  4207. if reg_type == 1111 || reg_type == 1112 {
  4208. reg_type = 11
  4209. }
  4210. tm := time.Unix(time.Now().Unix(), 0)
  4211. allTotal := fmt.Sprintf("%.4f", total)
  4212. totals, _ := strconv.ParseFloat(allTotal, 64)
  4213. order := &models.HisOrder{ //
  4214. UserOrgId: adminUser.CurrentOrgId,
  4215. HisPatientId: his.ID,
  4216. PatientId: id,
  4217. SettleAccountsDate: recordDateTime,
  4218. Ctime: time.Now().Unix(),
  4219. Mtime: time.Now().Unix(),
  4220. Status: 1,
  4221. OrderStatus: 2,
  4222. MdtrtId: his.Number,
  4223. Number: chrg_bchno,
  4224. MedfeeSumamt: totals,
  4225. PayWay: pay_way,
  4226. PayPrice: pay_price,
  4227. MedType: strconv.Itoa(int(reg_type)),
  4228. PayCardNo: pay_card_no,
  4229. DiscountPrice: discount_price,
  4230. PreferentialPrice: preferential_price,
  4231. RealityPrice: reality_price,
  4232. FoundPrice: found_price,
  4233. MedicalInsurancePrice: medical_insurance_price,
  4234. PrivatePrice: private_price,
  4235. SettleEndTime: end_time,
  4236. SettleStartTime: start_time,
  4237. SettleType: settle_accounts_type,
  4238. FaPiaoCode: fapiao_code,
  4239. FaPiaoNumber: fapiao_number,
  4240. Diagnosis: diagnosis_id,
  4241. PType: 2,
  4242. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4243. Decimal: decimal,
  4244. }
  4245. err = service.CreateOrderTX(order, tx)
  4246. if err != nil {
  4247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4248. return
  4249. }
  4250. var customs []*Custom
  4251. for _, item := range prescriptions {
  4252. if item.Type == 1 { //药品
  4253. for _, subItem := range item.HisDoctorAdviceInfo {
  4254. cus := &Custom{
  4255. AdviceId: subItem.ID,
  4256. ProjectId: 0,
  4257. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4258. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4259. FeedetlSn: subItem.FeedetlSn,
  4260. Price: fmt.Sprintf("%.2f", subItem.Price),
  4261. MedListCodg: subItem.MedListCodg,
  4262. Type: 1,
  4263. }
  4264. customs = append(customs, cus)
  4265. }
  4266. }
  4267. if item.Type == 2 { //项目
  4268. for _, subItem := range item.HisPrescriptionProject {
  4269. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4270. cus := &Custom{
  4271. AdviceId: 0,
  4272. ProjectId: subItem.ID,
  4273. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4274. Cut: fmt.Sprintf("%.4f", cnt),
  4275. FeedetlSn: subItem.FeedetlSn,
  4276. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4277. MedListCodg: subItem.MedListCodg,
  4278. Type: 2,
  4279. }
  4280. customs = append(customs, cus)
  4281. }
  4282. }
  4283. for _, item := range item.HisAdditionalCharge {
  4284. cus := &Custom{
  4285. ItemId: item.ID,
  4286. AdviceId: 0,
  4287. ProjectId: 0,
  4288. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4289. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4290. FeedetlSn: item.FeedetlSn,
  4291. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4292. MedListCodg: item.XtHisAddtionConfig.Code,
  4293. Type: 3,
  4294. }
  4295. customs = append(customs, cus)
  4296. }
  4297. }
  4298. for _, item := range customs {
  4299. var advice_id int64 = 0
  4300. var project_id int64 = 0
  4301. var item_id int64 = 0
  4302. var types int64 = 0
  4303. if item.Type == 1 {
  4304. advice_id = item.AdviceId
  4305. project_id = 0
  4306. item_id = 0
  4307. } else if item.Type == 2 {
  4308. advice_id = 0
  4309. item_id = 0
  4310. project_id = item.ProjectId
  4311. } else if item.Type == 3 {
  4312. advice_id = 0
  4313. item_id = item.ItemId
  4314. project_id = 0
  4315. }
  4316. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4317. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4318. pric, _ := strconv.ParseFloat(item.Price, 32)
  4319. info := &models.HisOrderInfo{
  4320. OrderNumber: order.Number,
  4321. UploadDate: time.Now().Unix(),
  4322. AdviceId: advice_id,
  4323. DetItemFeeSumamt: detItemFeeSumamt,
  4324. Cnt: cut,
  4325. Pric: pric,
  4326. PatientId: id,
  4327. Status: 1,
  4328. Mtime: time.Now().Unix(),
  4329. Ctime: time.Now().Unix(),
  4330. UserOrgId: adminUser.CurrentOrgId,
  4331. HisPatientId: his.ID,
  4332. OrderId: order.ID,
  4333. ProjectId: project_id,
  4334. Type: types,
  4335. ItemId: item_id,
  4336. }
  4337. service.CreateOrderInfoTX(info, tx)
  4338. }
  4339. his.Diagnosis = diagnosis_id
  4340. his.SickType = sick_type
  4341. his.RegisterType = reg_type
  4342. his.MedicalTreatmentType = reg_type
  4343. service.UpdataHisPateintTX(&his, tx)
  4344. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  4345. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  4346. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  4347. //判断是否使用了押金
  4348. if dec_way == "true" {
  4349. tmpstring := strconv.FormatInt(order.ID, 10)
  4350. //扣押金
  4351. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  4352. if errmsg != nil {
  4353. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  4354. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4355. return
  4356. }
  4357. }
  4358. if err == nil {
  4359. c.ServeSuccessJSON(map[string]interface{}{
  4360. "msg": "结算成功",
  4361. })
  4362. }
  4363. } else {
  4364. if tempOrder.IsPre > 0 {
  4365. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4366. totals, _ := strconv.ParseFloat(allTotal, 64)
  4367. tempOrder.OrderStatus = 2
  4368. tempOrder.PayWay = pay_way
  4369. tempOrder.PayPrice = pay_price
  4370. tempOrder.PayCardNo = pay_card_no
  4371. tempOrder.DiscountPrice = discount_price
  4372. tempOrder.PreferentialPrice = preferential_price
  4373. tempOrder.RealityPrice = reality_price
  4374. tempOrder.FoundPrice = found_price
  4375. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4376. tempOrder.PrivatePrice = private_price
  4377. tempOrder.FaPiaoCode = fapiao_code
  4378. tempOrder.FaPiaoNumber = fapiao_number
  4379. tempOrder.PType = 2
  4380. tempOrder.MedfeeSumamt = totals
  4381. tempOrder.Diagnosis = diagnosis_id
  4382. err = service.SaveHisOrder(&tempOrder)
  4383. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4384. if err != nil {
  4385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4386. return
  4387. }
  4388. if err == nil {
  4389. c.ServeSuccessJSON(map[string]interface{}{
  4390. "msg": "结算成功",
  4391. })
  4392. }
  4393. }
  4394. }
  4395. }
  4396. //退款
  4397. func (c *HisApiController) Refund() {
  4398. order_id, _ := c.GetInt64("order_id")
  4399. order, _ := service.GetHisOrderByID(order_id)
  4400. adminUser := c.GetAdminUserInfo()
  4401. orgid := c.GetAdminUserInfo().CurrentOrgId
  4402. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4403. if err != nil {
  4404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4405. return
  4406. }
  4407. tmp := strconv.FormatInt(order.ID, 10)
  4408. err = service.MoneyIncrease(orgid, order.HisPatientId, tmp, order.Decimal)
  4409. if err != nil {
  4410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4411. return
  4412. }
  4413. c.ServeSuccessJSON(map[string]interface{}{
  4414. "msg": "退费成功",
  4415. })
  4416. }
  4417. func (c *HisApiController) RefundNumber() {
  4418. his_patient_id, _ := c.GetInt64("id")
  4419. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4420. info.Status = 0
  4421. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4422. if count > 0 {
  4423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4424. return
  4425. }
  4426. err := service.SaveHisPatient(info)
  4427. if err == nil {
  4428. c.ServeSuccessJSON(map[string]interface{}{
  4429. "msg": "退号成功",
  4430. })
  4431. } else {
  4432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4433. return
  4434. }
  4435. }
  4436. func (this *HisApiController) AdditionalCharge() {
  4437. dataBody := make(map[string]interface{}, 0)
  4438. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4439. fmt.Println(err)
  4440. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4441. patient_id := int64(dataBody["patient_id"].(float64))
  4442. medicineData, _ := dataBody["medicineData"].([]interface{})
  4443. adminUserInfo := this.GetAdminUserInfo()
  4444. orgId := adminUserInfo.CurrentOrgId
  4445. admin_user_id := adminUserInfo.AdminUser.Id
  4446. timeStr := time.Now().Format("2006-01-02")
  4447. timeLayout := "2006-01-02 15:04:05"
  4448. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4449. timenow := timeStringToTime.Unix()
  4450. var additionalCharges []*models.HisAdditionalCharge
  4451. for _, item := range medicineData {
  4452. var randNum int
  4453. randNum = rand.Intn(10000) + 1000
  4454. timestamp := time.Now().Unix()
  4455. tempTime := time.Unix(timestamp, 0)
  4456. timeFormat := tempTime.Format("20060102150405")
  4457. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4458. items := item.(map[string]interface{})
  4459. money := items["price"].(string)
  4460. item_id_str := items["item_id"].(string)
  4461. name := items["name"].(string)
  4462. id_str := items["id"].(string)
  4463. moneys, _ := strconv.ParseInt(money, 10, 64)
  4464. monStr := strconv.FormatInt(moneys, 10)
  4465. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4466. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4467. id, _ := strconv.ParseInt(id_str, 10, 64)
  4468. additionalCharge := &models.HisAdditionalCharge{
  4469. ID: id,
  4470. HisPatientId: his_patient_id,
  4471. UserOrgId: orgId,
  4472. PatientId: patient_id,
  4473. RecordDate: timenow,
  4474. Price: monneyStr,
  4475. Status: 1,
  4476. ItemName: name,
  4477. ItemId: item_id,
  4478. AdminUserId: admin_user_id,
  4479. CreatedTime: time.Now().Unix(),
  4480. OrderStatus: 0,
  4481. PrescriptionNumber: "",
  4482. BatchNumber: "",
  4483. FeedetlSn: p_number,
  4484. }
  4485. service.CreateAdditionalCharge(additionalCharge)
  4486. additionalCharges = append(additionalCharges, additionalCharge)
  4487. }
  4488. this.ServeSuccessJSON(map[string]interface{}{
  4489. "msg": "添加成功",
  4490. "additional_charges": additionalCharges,
  4491. })
  4492. }
  4493. func (this *HisApiController) DeleteAddition() {
  4494. id, _ := this.GetInt64("id")
  4495. //TODO 需要判断是否已经结算
  4496. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4497. if err == nil {
  4498. this.ServeSuccessJSON(map[string]interface{}{
  4499. "msg": "删除成功",
  4500. })
  4501. return
  4502. } else {
  4503. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4504. return
  4505. }
  4506. }
  4507. func (this *HisApiController) GetAdminUsers() {
  4508. adminUser := this.GetAdminUserInfo()
  4509. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4510. this.ServeSuccessJSON(map[string]interface{}{
  4511. "doctors": doctors,
  4512. })
  4513. }
  4514. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4515. change_type, _ := this.GetInt64("type", 0)
  4516. record_date := this.GetString("record_time")
  4517. patient_id, _ := this.GetInt64("patient_id", 0)
  4518. p_type, _ := this.GetInt64("p_type", 0)
  4519. timeLayout := "2006-01-02"
  4520. loc, _ := time.LoadLocation("Local")
  4521. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4522. record_time := theAdviceRecordTime.Unix()
  4523. adminUserInfo := this.GetAdminUserInfo()
  4524. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4525. if err == nil {
  4526. if len(prescriptions) == 0 {
  4527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4528. return
  4529. } else {
  4530. this.ServeSuccessJSON(map[string]interface{}{
  4531. "prescriptions": prescriptions,
  4532. })
  4533. return
  4534. }
  4535. } else {
  4536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4537. return
  4538. }
  4539. }
  4540. func (this *HisApiController) GetCallHisPrescription() {
  4541. patient_id, _ := this.GetInt64("patient_id", 0)
  4542. timeLayout := "2006-01-02"
  4543. loc, _ := time.LoadLocation("Local")
  4544. start_time := this.GetString("start_time")
  4545. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4546. end_time := this.GetString("end_time")
  4547. p_type, _ := this.GetInt64("p_type")
  4548. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4549. adminUserInfo := this.GetAdminUserInfo()
  4550. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4551. if err == nil {
  4552. this.ServeSuccessJSON(map[string]interface{}{
  4553. "prescriptions": prescriptions,
  4554. })
  4555. return
  4556. } else {
  4557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4558. return
  4559. }
  4560. }
  4561. func (this *HisApiController) GetHisDayPrescription() {
  4562. timeLayout := "2006-01-02"
  4563. loc, _ := time.LoadLocation("Local")
  4564. start_time := this.GetString("start_time")
  4565. patient_id, _ := this.GetInt64("patient_id", 0)
  4566. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4567. end_time := this.GetString("end_time")
  4568. p_type, _ := this.GetInt64("p_type")
  4569. order_status, _ := this.GetInt64("type")
  4570. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4571. adminUserInfo := this.GetAdminUserInfo()
  4572. var dayHisPrescription []*models.HisPrescription
  4573. var err error
  4574. if order_status == 1 || order_status == 0 {
  4575. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4576. } else if order_status == 2 {
  4577. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4578. }
  4579. var settle_total float64
  4580. for _, item := range dayHisPrescription {
  4581. if len(item.HisPrescriptionProject) > 0 {
  4582. for _, subItem := range item.HisPrescriptionProject {
  4583. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4584. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4585. settle_total = settle_total + total
  4586. }
  4587. }
  4588. if len(item.HisDoctorAdviceInfo) > 0 {
  4589. for _, subItem := range item.HisDoctorAdviceInfo {
  4590. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4591. settle_total = settle_total + total
  4592. }
  4593. }
  4594. }
  4595. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4596. if err == nil {
  4597. this.ServeSuccessJSON(map[string]interface{}{
  4598. "day_prescription": dayHisPrescription,
  4599. "settle_total": settle_total,
  4600. })
  4601. return
  4602. } else {
  4603. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4604. return
  4605. }
  4606. }
  4607. func (c *HisApiController) GetHisChargePatientList() {
  4608. record_date := c.GetString("record_date")
  4609. order_status, _ := c.GetInt64("type")
  4610. timeLayout := "2006-01-02"
  4611. loc, _ := time.LoadLocation("Local")
  4612. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4613. if err != nil {
  4614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4615. return
  4616. }
  4617. recordDateTime := theTime.Unix()
  4618. adminInfo := c.GetAdminUserInfo()
  4619. var tempPatients []*service.NewTempPatients
  4620. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4621. if order_status != 2 {
  4622. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4623. } else {
  4624. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4625. }
  4626. var patients []*service.NewTempPatients
  4627. var patients_two []*service.NewTempPatients
  4628. for _, item := range tempPatients {
  4629. //过滤掉没挂号的和没开处方的
  4630. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4631. patients = append(patients, item)
  4632. }
  4633. //过滤掉没挂号的
  4634. if len(item.HisPatient) > 0 {
  4635. patients_two = append(patients_two, item)
  4636. }
  4637. }
  4638. c.ServeSuccessJSON(map[string]interface{}{
  4639. "list": patients,
  4640. "list_two": patients_two,
  4641. })
  4642. }
  4643. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4644. record_date := c.GetString("record_date")
  4645. timeLayout := "2006-01-02"
  4646. loc, _ := time.LoadLocation("Local")
  4647. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4648. if err != nil {
  4649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4650. return
  4651. }
  4652. recordDateTime := theTime.Unix()
  4653. adminUser := c.GetAdminUserInfo()
  4654. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4655. var patients []*service.Patients
  4656. for _, item := range tempPatients {
  4657. if item.HisPatient.ID == 0 {
  4658. patients = append(patients, item)
  4659. }
  4660. }
  4661. c.ServeSuccessJSON(map[string]interface{}{
  4662. "list": patients,
  4663. //"list_two": patients_two,
  4664. })
  4665. }
  4666. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4667. newArr = make([]*service.Patients, 0)
  4668. for i := 0; i < len(patient); i++ {
  4669. repeat := false
  4670. for j := i + 1; j < len(patient); j++ {
  4671. if patient[i].ID == patient[j].ID {
  4672. repeat = true
  4673. break
  4674. }
  4675. }
  4676. if !repeat {
  4677. newArr = append(newArr, patient[i])
  4678. }
  4679. }
  4680. return
  4681. }
  4682. func (c *HisApiController) GetHisChargePatientInfo() {
  4683. patient_id, _ := c.GetInt64("patient_id")
  4684. his_patient_id, _ := c.GetInt64("his_patient_id")
  4685. record_date := c.GetString("record_date")
  4686. //start_time := c.GetString("start_time")
  4687. //end_time := c.GetString("end_time")
  4688. order_status, _ := c.GetInt64("type", 0)
  4689. p_type, _ := c.GetInt64("p_type", 0)
  4690. order_id, _ := c.GetInt64("order_id", 0)
  4691. timeLayout := "2006-01-02"
  4692. loc, _ := time.LoadLocation("Local")
  4693. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4694. if err != nil {
  4695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4696. return
  4697. }
  4698. recordDateTime := theTime.Unix()
  4699. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4700. //if err != nil {
  4701. //
  4702. //}
  4703. //startRecordDateTime := startTime.Unix()
  4704. //
  4705. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4706. //if err != nil {
  4707. //
  4708. //}
  4709. //endRecordDateTime := endTime.Unix()
  4710. admin := c.GetAdminUserInfo()
  4711. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4712. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4713. var prescriptions []*models.HisPrescription
  4714. //var unChargeMonthPrescriptions []*models.HisPrescription
  4715. order, _ := service.GetHisOrderByID(order_id)
  4716. if order_status == 1 || order_status == 0 {
  4717. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4718. } else if order_status == 2 {
  4719. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4720. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4721. }
  4722. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4723. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4724. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4725. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4726. //获取所有科室信息
  4727. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4728. c.ServeSuccessJSON(map[string]interface{}{
  4729. "his_info": his_patient_info,
  4730. "xt_info": xt_patient_info,
  4731. "prescription": prescriptions,
  4732. "case_history": case_history,
  4733. "info": patientPrescriptionInfo,
  4734. "last_info": lastPatientPrescriptionInfo,
  4735. "order": order,
  4736. "doctors": doctors,
  4737. "department": department,
  4738. })
  4739. return
  4740. }
  4741. func (c *HisApiController) GetAllOrderDetail() {
  4742. order_id, _ := c.GetInt64("id", 0)
  4743. order, _ := service.GetHisOrderByID(order_id)
  4744. if order.ID == 0 {
  4745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4746. return
  4747. }
  4748. org_id := c.GetAdminUserInfo().CurrentOrgId
  4749. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4750. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4751. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4752. c.ServeSuccessJSON(map[string]interface{}{
  4753. "order": order,
  4754. "order_info": order_info,
  4755. "patient": patient,
  4756. "admin_info": adminInfo,
  4757. })
  4758. return
  4759. }
  4760. func (c *HisApiController) GetAllOrderDetailCollect() {
  4761. order_id, _ := c.GetInt64("id", 0)
  4762. order, _ := service.GetHisOrderByID(order_id)
  4763. if order.ID == 0 {
  4764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4765. return
  4766. }
  4767. org_id := c.GetAdminUserInfo().CurrentOrgId
  4768. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4769. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4770. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4771. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4772. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4773. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4774. var bedCostTotal float64 = 0 //床位总费
  4775. //var bedCostSelfTotal float64 = 0 //床位自费
  4776. var operationCostTotal float64 = 0 //手术费
  4777. //var operationCostSelfTotal float64 = 0 //手术费
  4778. var otherCostTotal float64 = 0 //其他费用
  4779. //var otherCostSelfTotal float64 = 0 //其他费用
  4780. var materialCostTotal float64 = 0 //材料费
  4781. //var materialCostSelfTotal float64 = 0 //材料费
  4782. var westernMedicineCostTotal float64 = 0 //西药费
  4783. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4784. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4785. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4786. var checkCostTotal float64 = 0 //检查费
  4787. //var checkCostSelfTotal float64 = 0 //检查费
  4788. var laboratoryCostTotal float64 = 0 //化验费
  4789. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4790. var treatCostTotal float64 = 0 //治疗费用
  4791. //var treatCostSelfTotal float64 = 0 //治疗费用
  4792. var zhenChaCostTotal float64 = 0 //其他费用
  4793. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4794. decimal.DivisionPrecision = 2
  4795. var BalanceAccountsType int64
  4796. if his.ID > 0 {
  4797. BalanceAccountsType = his.BalanceAccountsType
  4798. } else {
  4799. BalanceAccountsType = record.BalanceAccountsType
  4800. }
  4801. if BalanceAccountsType != 2 {
  4802. for _, item := range order_info {
  4803. if org_id == 10215 {
  4804. if item.MedChrgitmType == "01" { //床位费
  4805. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4806. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4807. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4808. }
  4809. if item.MedChrgitmType == "02" { //诊察费
  4810. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4811. //zhenChaCostSelfTotal = zhenChaCostTotal
  4812. }
  4813. if item.MedChrgitmType == "03" { //检查费
  4814. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4815. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4816. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4817. }
  4818. //if item.MedChrgitmType == "02" { //检查费
  4819. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4820. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4821. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4822. //}
  4823. if item.MedChrgitmType == "04" { //化验费
  4824. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4825. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4826. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4827. }
  4828. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4829. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4830. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4831. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4832. }
  4833. if item.MedChrgitmType == "06" { //手术费
  4834. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4835. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4836. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4837. }
  4838. if item.MedChrgitmType == "08" { //材料费
  4839. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4840. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4841. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4842. }
  4843. if item.MedChrgitmType == "09" { //西药费
  4844. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4845. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4846. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4847. }
  4848. if item.MedChrgitmType == "11" { //中成费
  4849. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4850. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4851. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4852. }
  4853. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4854. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4855. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4856. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4857. }
  4858. } else if org_id == 10188 || org_id == 10217 {
  4859. if item.MedChrgitmType == "01" { //床位费
  4860. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4861. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4862. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4863. }
  4864. if item.MedChrgitmType == "02" { //诊察费
  4865. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4866. //zhenChaCostSelfTotal = zhenChaCostTotal
  4867. }
  4868. if item.MedChrgitmType == "03" { //检查费
  4869. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4870. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4871. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4872. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4873. }
  4874. //if item.MedChrgitmType == "02" { //检查费
  4875. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4876. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4877. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4878. //}
  4879. if item.MedChrgitmType == "04" { //化验费
  4880. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4881. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4882. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4883. }
  4884. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4885. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4886. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4887. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4888. }
  4889. if item.MedChrgitmType == "06" { //手术费
  4890. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4891. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4892. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4893. }
  4894. if item.MedChrgitmType == "08" { //材料费
  4895. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4896. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4897. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4898. }
  4899. if item.MedChrgitmType == "09" { //西药费
  4900. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4901. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4902. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4903. }
  4904. if item.MedChrgitmType == "11" { //中成费
  4905. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4906. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4907. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4908. }
  4909. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4910. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4911. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4912. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4913. }
  4914. } else {
  4915. if item.MedChrgitmType == "01" { //床位费
  4916. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4917. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4918. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4919. }
  4920. //if item.MedChrgitmType == "02" { //诊察费
  4921. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4922. // //zhenChaCostSelfTotal = zhenChaCostTotal
  4923. //}
  4924. if item.MedChrgitmType == "03" { //检查费
  4925. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4926. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4927. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4928. }
  4929. //if item.MedChrgitmType == "02" { //检查费
  4930. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4931. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4932. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4933. //}
  4934. if item.MedChrgitmType == "04" { //化验费
  4935. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4936. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4937. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4938. }
  4939. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4940. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4941. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4942. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4943. }
  4944. if item.MedChrgitmType == "06" { //手术费
  4945. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4946. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4947. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4948. }
  4949. if item.MedChrgitmType == "08" { //材料费
  4950. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4951. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4952. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4953. }
  4954. if item.MedChrgitmType == "09" { //西药费
  4955. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4956. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4957. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4958. }
  4959. if item.MedChrgitmType == "11" { //中成费
  4960. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4961. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4962. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4963. }
  4964. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4965. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4966. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4967. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4968. }
  4969. }
  4970. }
  4971. c.ServeSuccessJSON(map[string]interface{}{
  4972. "order": order,
  4973. "order_info": order_info,
  4974. "patient": patient,
  4975. "admin_info": adminInfo,
  4976. "his_hospital": record,
  4977. "bedCostTotal": bedCostTotal,
  4978. "operationCostTotal": operationCostTotal,
  4979. "otherCostTotal": otherCostTotal,
  4980. "materialCostTotal": materialCostTotal,
  4981. "westernMedicineCostTotal": westernMedicineCostTotal,
  4982. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4983. "checkCostTotal": checkCostTotal,
  4984. "zhenChaCostTotal": zhenChaCostTotal,
  4985. "laboratoryCostTotal": laboratoryCostTotal,
  4986. "treatCostTotal": treatCostTotal,
  4987. })
  4988. } else {
  4989. for _, item := range order_info {
  4990. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4991. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4992. item.MedChrgitmType = "09"
  4993. }
  4994. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4995. if item.HisPrescriptionProject.Type == 2 {
  4996. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  4997. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4998. case 0:
  4999. item.MedChrgitmType = "0"
  5000. break
  5001. case 1:
  5002. item.MedChrgitmType = "14"
  5003. break
  5004. case 2:
  5005. item.MedChrgitmType = "05"
  5006. break
  5007. case 3:
  5008. item.MedChrgitmType = "03"
  5009. break
  5010. case 4:
  5011. item.MedChrgitmType = "03"
  5012. break
  5013. case 5:
  5014. item.MedChrgitmType = "08"
  5015. break
  5016. case 6:
  5017. item.MedChrgitmType = "14"
  5018. break
  5019. case 7:
  5020. item.MedChrgitmType = "14"
  5021. break
  5022. case 8:
  5023. item.MedChrgitmType = "03"
  5024. break
  5025. case 9:
  5026. item.MedChrgitmType = "14"
  5027. break
  5028. case 10:
  5029. item.MedChrgitmType = "14"
  5030. break
  5031. case 11:
  5032. item.MedChrgitmType = "06"
  5033. break
  5034. case 12:
  5035. item.MedChrgitmType = "12"
  5036. break
  5037. case 13:
  5038. item.MedChrgitmType = "01"
  5039. break
  5040. case 14:
  5041. item.MedChrgitmType = "04"
  5042. break
  5043. case 15:
  5044. item.MedChrgitmType = "14"
  5045. break
  5046. }
  5047. } else {
  5048. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5049. case 1:
  5050. item.MedChrgitmType = "14"
  5051. break
  5052. case 2:
  5053. item.MedChrgitmType = "05"
  5054. break
  5055. case 3:
  5056. item.MedChrgitmType = "04"
  5057. break
  5058. case 4:
  5059. item.MedChrgitmType = "14"
  5060. break
  5061. case 5:
  5062. item.MedChrgitmType = "08"
  5063. break
  5064. case 6:
  5065. item.MedChrgitmType = "14"
  5066. break
  5067. case 7:
  5068. item.MedChrgitmType = "14"
  5069. break
  5070. case 8:
  5071. item.MedChrgitmType = "03"
  5072. break
  5073. case 9:
  5074. item.MedChrgitmType = "14"
  5075. break
  5076. }
  5077. }
  5078. } else if item.HisPrescriptionProject.Type == 3 {
  5079. item.MedChrgitmType = "08"
  5080. }
  5081. }
  5082. }
  5083. for _, item := range order_info {
  5084. if org_id == 10215 {
  5085. if item.MedChrgitmType == "01" { //床位费
  5086. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5087. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5088. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5089. }
  5090. if item.MedChrgitmType == "02" { //诊察费
  5091. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5092. //zhenChaCostSelfTotal = zhenChaCostTotal
  5093. }
  5094. if item.MedChrgitmType == "03" { //检查费
  5095. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5096. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5097. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5098. }
  5099. //if item.MedChrgitmType == "02" { //检查费
  5100. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5101. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5102. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5103. //}
  5104. if item.MedChrgitmType == "04" { //化验费
  5105. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5106. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5107. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5108. }
  5109. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5110. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5111. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5112. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5113. }
  5114. if item.MedChrgitmType == "06" { //手术费
  5115. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5116. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5117. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5118. }
  5119. if item.MedChrgitmType == "08" { //材料费
  5120. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5121. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5122. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5123. }
  5124. if item.MedChrgitmType == "09" { //西药费
  5125. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5126. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5127. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5128. }
  5129. if item.MedChrgitmType == "11" { //中成费
  5130. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5131. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5132. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5133. }
  5134. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5135. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5136. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5137. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5138. }
  5139. } else {
  5140. if item.MedChrgitmType == "01" { //床位费
  5141. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5142. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5143. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5144. }
  5145. //if item.MedChrgitmType == "02" { //诊察费
  5146. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5147. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5148. //}
  5149. if item.MedChrgitmType == "03" { //检查费
  5150. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5151. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5152. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5153. }
  5154. //if item.MedChrgitmType == "02" { //检查费
  5155. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5156. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5157. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5158. //}
  5159. if item.MedChrgitmType == "04" { //化验费
  5160. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5161. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5162. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5163. }
  5164. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5165. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5166. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5167. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5168. }
  5169. if item.MedChrgitmType == "06" { //手术费
  5170. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5171. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5172. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5173. }
  5174. if item.MedChrgitmType == "08" { //材料费
  5175. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5176. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5177. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5178. }
  5179. if item.MedChrgitmType == "09" { //西药费
  5180. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5181. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5182. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5183. }
  5184. if item.MedChrgitmType == "11" { //中成费
  5185. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5186. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5187. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5188. }
  5189. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5190. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5191. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5192. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5193. }
  5194. }
  5195. }
  5196. c.ServeSuccessJSON(map[string]interface{}{
  5197. "order": order,
  5198. "order_info": order_info,
  5199. "patient": patient,
  5200. "admin_info": adminInfo,
  5201. "his_hospital": record,
  5202. "bedCostTotal": bedCostTotal,
  5203. "operationCostTotal": operationCostTotal,
  5204. "otherCostTotal": otherCostTotal,
  5205. "materialCostTotal": materialCostTotal,
  5206. "westernMedicineCostTotal": westernMedicineCostTotal,
  5207. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5208. "checkCostTotal": checkCostTotal,
  5209. "zhenChaCostTotal": zhenChaCostTotal,
  5210. "laboratoryCostTotal": laboratoryCostTotal,
  5211. "treatCostTotal": treatCostTotal,
  5212. })
  5213. }
  5214. }
  5215. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5216. page, _ := c.GetInt64("page")
  5217. limit, _ := c.GetInt64("limit")
  5218. keywords := c.GetString("keywords")
  5219. start_time := c.GetString("start_time")
  5220. end_time := c.GetString("end_time")
  5221. //clr_type := c.GetString("clr_type")
  5222. insutype := c.GetString("insutype")
  5223. timeLayout := "2006-01-02"
  5224. loc, _ := time.LoadLocation("Local")
  5225. var theStartTIme int64
  5226. if len(start_time) > 0 {
  5227. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5228. theStartTIme = theTime.Unix()
  5229. }
  5230. var theEndtTIme int64
  5231. if len(end_time) > 0 {
  5232. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5233. theEndtTIme = theTime.Unix()
  5234. }
  5235. if page <= 0 {
  5236. page = 1
  5237. }
  5238. if limit <= 0 {
  5239. limit = 10
  5240. }
  5241. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5242. c.ServeSuccessJSON(map[string]interface{}{
  5243. "total": total,
  5244. "list": list,
  5245. })
  5246. return
  5247. }
  5248. func (c *HisApiController) GetPutOnRecordList() {
  5249. page, _ := c.GetInt64("page")
  5250. limit, _ := c.GetInt64("limit")
  5251. keywords := c.GetString("keywords")
  5252. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5253. if page <= 0 {
  5254. page = 1
  5255. }
  5256. if limit <= 0 {
  5257. limit = 10
  5258. }
  5259. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5260. c.ServeSuccessJSON(map[string]interface{}{
  5261. "total": total,
  5262. "list": list,
  5263. })
  5264. return
  5265. }
  5266. func (c *HisApiController) GetCompareData() {
  5267. start_time := c.GetString("start_time")
  5268. end_time := c.GetString("end_time")
  5269. insutype := c.GetString("insutype")
  5270. clr_type := c.GetString("clr_type")
  5271. timeLayout := "2006-01-02"
  5272. loc, _ := time.LoadLocation("Local")
  5273. var theStartTIme int64
  5274. if len(start_time) > 0 {
  5275. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5276. if err != nil {
  5277. theStartTIme = 0
  5278. }
  5279. theStartTIme = theTime.Unix()
  5280. }
  5281. var theEndtTIme int64
  5282. if len(end_time) > 0 {
  5283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5284. if err != nil {
  5285. theEndtTIme = 0
  5286. }
  5287. theEndtTIme = theTime.Unix()
  5288. }
  5289. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5290. fmt.Println(err)
  5291. if err == nil {
  5292. c.ServeSuccessJSON(map[string]interface{}{
  5293. "list": formData,
  5294. })
  5295. } else {
  5296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5297. return
  5298. }
  5299. }
  5300. func (c *HisApiController) GetFaPiaoData() {
  5301. order_id, _ := c.GetInt64("order_id")
  5302. patient_id, _ := c.GetInt64("patient_id")
  5303. number := c.GetString("number")
  5304. adminUser := c.GetAdminUserInfo()
  5305. order, _ := service.GetHisOrderByID(order_id)
  5306. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5307. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5308. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5309. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5310. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5311. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5312. var bedCostTotal float64 = 0 //床位总费
  5313. var bedCostSelfTotal float64 = 0 //床位自费
  5314. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5315. var operationCostTotal float64 = 0 //手术费
  5316. var operationCostSelfTotal float64 = 0 //手术费
  5317. var operationCostPartSelfTotal float64 = 0 //手术费
  5318. var otherCostTotal float64 = 0 //其他费用
  5319. var otherCostSelfTotal float64 = 0 //其他费用
  5320. var otherCostPartSelfTotal float64 = 0 //其他费用
  5321. var materialCostTotal float64 = 0 //材料费
  5322. var materialCostSelfTotal float64 = 0 //材料费
  5323. var materialCostPartSelfTotal float64 = 0 //材料费
  5324. var westernMedicineCostTotal float64 = 0 //西药费
  5325. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5326. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5327. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5328. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5329. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5330. var checkCostTotal float64 = 0 //检查费
  5331. var checkCostSelfTotal float64 = 0 //检查费
  5332. var checkCostPartSelfTotal float64 = 0 //检查费
  5333. var laboratoryCostTotal float64 = 0 //化验费
  5334. var laboratoryCostSelfTotal float64 = 0 //化验费
  5335. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5336. var treatCostTotal float64 = 0 //治疗费用
  5337. var treatCostSelfTotal float64 = 0 //治疗费用
  5338. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5339. var zhenChaCostTotal float64 = 0 //其他费用
  5340. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5341. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5342. decimal.DivisionPrecision = 2
  5343. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5344. var balanceAccountsType int64
  5345. if his.ID > 0 {
  5346. balanceAccountsType = his.BalanceAccountsType
  5347. } else {
  5348. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5349. }
  5350. if balanceAccountsType == 2 {
  5351. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5352. for _, item := range orderInfos_two {
  5353. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5354. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5355. item.MedChrgitmType = "09"
  5356. }
  5357. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5358. if item.HisPrescriptionProject.Type == 2 {
  5359. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5360. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5361. case 0:
  5362. item.MedChrgitmType = "0"
  5363. break
  5364. case 1:
  5365. item.MedChrgitmType = "14"
  5366. break
  5367. case 2:
  5368. item.MedChrgitmType = "05"
  5369. break
  5370. case 3:
  5371. item.MedChrgitmType = "03"
  5372. break
  5373. case 4:
  5374. item.MedChrgitmType = "03"
  5375. break
  5376. case 5:
  5377. item.MedChrgitmType = "08"
  5378. break
  5379. case 6:
  5380. item.MedChrgitmType = "14"
  5381. break
  5382. case 7:
  5383. item.MedChrgitmType = "14"
  5384. break
  5385. case 8:
  5386. item.MedChrgitmType = "03"
  5387. break
  5388. case 9:
  5389. item.MedChrgitmType = "14"
  5390. break
  5391. case 10:
  5392. item.MedChrgitmType = "14"
  5393. break
  5394. case 11:
  5395. item.MedChrgitmType = "06"
  5396. break
  5397. case 12:
  5398. item.MedChrgitmType = "12"
  5399. break
  5400. case 13:
  5401. item.MedChrgitmType = "01"
  5402. break
  5403. case 14:
  5404. item.MedChrgitmType = "04"
  5405. break
  5406. case 15:
  5407. item.MedChrgitmType = "02"
  5408. break
  5409. }
  5410. } else {
  5411. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5412. case 1:
  5413. item.MedChrgitmType = "14"
  5414. break
  5415. case 2:
  5416. item.MedChrgitmType = "05"
  5417. break
  5418. case 3:
  5419. item.MedChrgitmType = "03"
  5420. break
  5421. case 4:
  5422. item.MedChrgitmType = "03"
  5423. break
  5424. case 5:
  5425. item.MedChrgitmType = "08"
  5426. break
  5427. case 6:
  5428. item.MedChrgitmType = "14"
  5429. break
  5430. case 7:
  5431. item.MedChrgitmType = "14"
  5432. break
  5433. case 8:
  5434. item.MedChrgitmType = "03"
  5435. break
  5436. case 9:
  5437. item.MedChrgitmType = "14"
  5438. break
  5439. }
  5440. }
  5441. } else if item.HisPrescriptionProject.Type == 3 {
  5442. item.MedChrgitmType = "08"
  5443. }
  5444. }
  5445. }
  5446. for _, item := range orderInfos_two {
  5447. fmt.Println(item.MedChrgitmType)
  5448. if item.MedChrgitmType == "01" { //床位费
  5449. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5450. bedCostSelfTotal = bedCostTotal
  5451. }
  5452. if item.MedChrgitmType == "02" { //诊察费
  5453. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5454. zhenChaCostSelfTotal = zhenChaCostTotal
  5455. }
  5456. if item.MedChrgitmType == "03" { //检查费
  5457. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5458. checkCostSelfTotal = checkCostTotal
  5459. }
  5460. if item.MedChrgitmType == "04" { //化验费
  5461. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5462. laboratoryCostSelfTotal = laboratoryCostTotal
  5463. }
  5464. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5465. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5466. treatCostSelfTotal = treatCostTotal
  5467. }
  5468. if item.MedChrgitmType == "06" { //手术费
  5469. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5470. operationCostSelfTotal = treatCostTotal
  5471. }
  5472. if item.MedChrgitmType == "08" { //材料费
  5473. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5474. materialCostSelfTotal = materialCostTotal
  5475. }
  5476. if item.MedChrgitmType == "09" { //西药费
  5477. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5478. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5479. }
  5480. if item.MedChrgitmType == "11" { //中成费
  5481. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5482. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5483. }
  5484. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5485. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5486. otherCostSelfTotal = otherCostTotal
  5487. }
  5488. }
  5489. } else {
  5490. for _, item := range orderInfos {
  5491. if item.MedChrgitmType == "01" { //床位费
  5492. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5493. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5494. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5495. }
  5496. if item.MedChrgitmType == "02" { //诊察费
  5497. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5498. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5499. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5500. }
  5501. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  5502. if item.MedChrgitmType == "03" { //检查费
  5503. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5504. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5505. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5506. }
  5507. } else {
  5508. if item.MedChrgitmType == "03" { //检查费
  5509. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5510. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5511. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5512. }
  5513. }
  5514. if item.MedChrgitmType == "04" { //化验费
  5515. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5516. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5517. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5518. }
  5519. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5520. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5521. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5522. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5523. }
  5524. if item.MedChrgitmType == "06" { //手术费
  5525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5526. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5527. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5528. }
  5529. if item.MedChrgitmType == "08" { //材料费
  5530. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5531. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5532. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5533. }
  5534. if item.MedChrgitmType == "09" { //西药费
  5535. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5536. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5537. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5538. }
  5539. if item.MedChrgitmType == "11" { //中成费
  5540. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5541. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5542. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5543. }
  5544. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5545. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5546. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5547. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5548. }
  5549. }
  5550. }
  5551. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5552. c.ServeSuccessJSON(map[string]interface{}{
  5553. "order_number": order.Number, //业务流水号
  5554. "id_card_no": his.IdCardNo, //社会保障号
  5555. "department_name": department.Name, //科室
  5556. "number": his.Number, //门诊号
  5557. "date": order.SettleAccountsDate, //结算日期
  5558. "name": order.PsnName, //姓名
  5559. "gender": order.Gend, //性别
  5560. "psn_cash_money": order.PsnCashPay, //个人支付
  5561. "pay_way": "门诊", //结算方式
  5562. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5563. "admin_user_name": admin.UserName, //收款员
  5564. "order": order,
  5565. "order_info": orderInfos_two,
  5566. "his": his,
  5567. "bedCostTotal": bedCostTotal,
  5568. "bedCostSelfTotal": bedCostSelfTotal,
  5569. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5570. "operationCostTotal": operationCostTotal,
  5571. "operationCostSelfTotal": operationCostSelfTotal,
  5572. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5573. "otherCostTotal": otherCostTotal,
  5574. "otherCostSelfTotal": otherCostSelfTotal,
  5575. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5576. "materialCostTotal": materialCostTotal,
  5577. "materialCostSelfTotal": materialCostSelfTotal,
  5578. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5579. "westernMedicineCostTotal": westernMedicineCostTotal,
  5580. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5581. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5582. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5583. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5584. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5585. "checkCostTotal": checkCostTotal,
  5586. "checkCostSelfTotal": checkCostSelfTotal,
  5587. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5588. "laboratoryCostTotal": laboratoryCostTotal,
  5589. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5590. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5591. "treatCostTotal": treatCostTotal,
  5592. "treatCostSelfTotal": treatCostSelfTotal,
  5593. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5594. "zhenChaCostTotal": zhenChaCostTotal,
  5595. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5596. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5597. "his_hospital_record": his_hospital_record,
  5598. })
  5599. }
  5600. func (this *HisApiController) GetIncomeStatisticsData() {
  5601. start_time := this.GetString("start_time")
  5602. end_time := this.GetString("end_time")
  5603. key_words := this.GetString("key_words")
  5604. limit, _ := this.GetInt64("limit")
  5605. page, _ := this.GetInt64("page")
  5606. if page <= 0 {
  5607. page = 1
  5608. }
  5609. if limit <= 0 {
  5610. limit = 10
  5611. }
  5612. statistics_type, _ := this.GetInt64("statistics_type")
  5613. admin := this.GetAdminUserInfo()
  5614. timeLayout := "2006-01-02"
  5615. loc, _ := time.LoadLocation("Local")
  5616. var theStartTIme int64
  5617. if len(start_time) > 0 {
  5618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5619. if err != nil {
  5620. theStartTIme = 0
  5621. }
  5622. theStartTIme = theTime.Unix()
  5623. }
  5624. var theEndtTIme int64
  5625. if len(end_time) > 0 {
  5626. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5627. if err != nil {
  5628. theEndtTIme = 0
  5629. }
  5630. theEndtTIme = theTime.Unix()
  5631. }
  5632. if statistics_type == 1 {
  5633. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5634. this.ServeSuccessJSON(map[string]interface{}{
  5635. "list": list,
  5636. "total": total,
  5637. })
  5638. } else {
  5639. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5640. this.ServeSuccessJSON(map[string]interface{}{
  5641. "list": list,
  5642. "total": total,
  5643. })
  5644. }
  5645. }
  5646. func (c *HisApiController) PostProjectInformation() {
  5647. adminUser := c.GetAdminUserInfo()
  5648. orgId := adminUser.CurrentOrgId
  5649. dataBody := make(map[string]interface{}, 0)
  5650. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5651. if err != nil {
  5652. utils.ErrorLog(err.Error())
  5653. return
  5654. }
  5655. utils.ErrorLog("%v", dataBody)
  5656. var projectList []*models.HisProject
  5657. var total_goods []interface{}
  5658. tempProjects := dataBody["projects"].([]interface{})
  5659. total_goods = tempProjects
  5660. for index, projectMap := range tempProjects {
  5661. projectM := projectMap.(map[string]interface{})
  5662. var project models.HisProject
  5663. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5664. utils.ErrorLog("project_name")
  5665. return
  5666. }
  5667. project_name, _ := projectM["project_name"].(string)
  5668. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5669. err_log := models.ExportErrLog{
  5670. LogType: 6,
  5671. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5672. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5673. Status: 1,
  5674. CreateTime: time.Now().Unix(),
  5675. UpdateTime: time.Now().Unix(),
  5676. ExportTime: time.Now().Unix(),
  5677. }
  5678. service.CreateExportErrLog(&err_log)
  5679. continue
  5680. }
  5681. project.ProjectName = project_name
  5682. prices := projectM["price"].(string)
  5683. price, _ := strconv.ParseFloat(prices, 64)
  5684. if price <= 0 { //名字为空则生成一条导入错误日志
  5685. err_log := models.ExportErrLog{
  5686. LogType: 6,
  5687. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5688. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5689. Status: 1,
  5690. CreateTime: time.Now().Unix(),
  5691. UpdateTime: time.Now().Unix(),
  5692. ExportTime: time.Now().Unix(),
  5693. }
  5694. service.CreateExportErrLog(&err_log)
  5695. continue
  5696. }
  5697. project.Price = price
  5698. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5699. utils.ErrorLog("unit_id")
  5700. return
  5701. }
  5702. unit := projectM["unit"].(string)
  5703. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5704. err_log := models.ExportErrLog{
  5705. LogType: 6,
  5706. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5707. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5708. Status: 1,
  5709. CreateTime: time.Now().Unix(),
  5710. UpdateTime: time.Now().Unix(),
  5711. ExportTime: time.Now().Unix(),
  5712. }
  5713. service.CreateExportErrLog(&err_log)
  5714. continue
  5715. }
  5716. project.Unit = unit
  5717. cost_classify := projectM["cost_classify"].(string)
  5718. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5719. err_log := models.ExportErrLog{
  5720. LogType: 6,
  5721. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5722. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5723. Status: 1,
  5724. CreateTime: time.Now().Unix(),
  5725. UpdateTime: time.Now().Unix(),
  5726. ExportTime: time.Now().Unix(),
  5727. }
  5728. service.CreateExportErrLog(&err_log)
  5729. continue
  5730. }
  5731. var costClassify = "费用类别"
  5732. var cost_classify_id int64
  5733. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5734. if len(cost_classify) != 0 {
  5735. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5736. if errcode == gorm.ErrRecordNotFound {
  5737. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5738. dataconfig := models.DictDataconfig{
  5739. ParentId: costClassifyConfig.ID,
  5740. Module: "system",
  5741. OrgId: orgId,
  5742. Name: cost_classify,
  5743. FieldName: "",
  5744. Value: costConfig.Value + 1,
  5745. CreatedTime: "",
  5746. UpdatedTime: "",
  5747. CreateUserId: adminUser.AdminUser.Id,
  5748. Status: 1,
  5749. Remark: "",
  5750. DeleteIdSystem: 0,
  5751. Title: "",
  5752. Content: "",
  5753. Order: 0,
  5754. Code: "",
  5755. }
  5756. service.CreatedDicConfig(&dataconfig)
  5757. }
  5758. }
  5759. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5760. for _, it := range costClassList {
  5761. if cost_classify == it.Name {
  5762. cost_classify_id = int64(it.Value)
  5763. }
  5764. }
  5765. project.CostClassify = cost_classify_id
  5766. executive_section := projectM["executive_section"].(string)
  5767. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5768. err_log := models.ExportErrLog{
  5769. LogType: 6,
  5770. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5771. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5772. Status: 1,
  5773. CreateTime: time.Now().Unix(),
  5774. UpdateTime: time.Now().Unix(),
  5775. ExportTime: time.Now().Unix(),
  5776. }
  5777. service.CreateExportErrLog(&err_log)
  5778. continue
  5779. }
  5780. if len(executive_section) != 0 {
  5781. //查找科室是否有内容
  5782. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5783. if errcodedepart == gorm.ErrRecordNotFound {
  5784. department := models.XtHisDepartment{
  5785. Name: executive_section,
  5786. Status: 1,
  5787. UserOrgId: adminUser.CurrentOrgId,
  5788. CreatedTime: time.Now().Unix(),
  5789. }
  5790. service.CreateDePartment(&department)
  5791. }
  5792. }
  5793. var executive_section_id int64
  5794. departMentList, _ := service.GetAllDepartMent(orgId)
  5795. for _, it := range departMentList {
  5796. if executive_section == it.Name {
  5797. executive_section_id = it.ID
  5798. }
  5799. }
  5800. project.ExecutiveSection = executive_section_id
  5801. medical_coverage := projectM["medical_coverage"].(string)
  5802. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5803. err_log := models.ExportErrLog{
  5804. LogType: 6,
  5805. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5806. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5807. Status: 1,
  5808. CreateTime: time.Now().Unix(),
  5809. UpdateTime: time.Now().Unix(),
  5810. ExportTime: time.Now().Unix(),
  5811. }
  5812. service.CreateExportErrLog(&err_log)
  5813. continue
  5814. }
  5815. var medicalCoverage = "医保等级"
  5816. var medical_coverage_id int64
  5817. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5818. if len(medical_coverage) != 0 {
  5819. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5820. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5821. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5822. dataconfig := models.DictDataconfig{
  5823. ParentId: medicalCoverageConfig.ID,
  5824. Module: "system",
  5825. OrgId: orgId,
  5826. Name: medical_coverage,
  5827. FieldName: "",
  5828. Value: medicalCoverageConfig.Value + 1,
  5829. CreatedTime: "",
  5830. UpdatedTime: "",
  5831. CreateUserId: adminUser.AdminUser.Id,
  5832. Status: 1,
  5833. Remark: "",
  5834. DeleteIdSystem: 0,
  5835. Title: "",
  5836. Content: "",
  5837. Order: 0,
  5838. Code: "",
  5839. }
  5840. service.CreatedDicConfig(&dataconfig)
  5841. }
  5842. }
  5843. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5844. for _, it := range medicalCoverageList {
  5845. if medical_coverage == it.Name {
  5846. medical_coverage_id = int64(it.Value)
  5847. }
  5848. }
  5849. project.MedicalCoverage = medical_coverage_id
  5850. pinyin := projectM["pinyin"].(string)
  5851. project.Pinyin = pinyin
  5852. wubi := projectM["wubi"].(string)
  5853. project.Wubi = wubi
  5854. statistical_classification := projectM["statistical_classification"].(string)
  5855. var statisticalClassification = "统计分类"
  5856. var statistical_classification_id int64
  5857. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5858. if len(statistical_classification) != 0 {
  5859. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5860. if classificationerrcodes == gorm.ErrRecordNotFound {
  5861. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5862. dataconfig := models.DictDataconfig{
  5863. ParentId: classiFication.ID,
  5864. Module: "system",
  5865. OrgId: orgId,
  5866. Name: statistical_classification,
  5867. FieldName: "",
  5868. Value: classiFicationConfig.Value + 1,
  5869. CreatedTime: "",
  5870. UpdatedTime: "",
  5871. CreateUserId: adminUser.AdminUser.Id,
  5872. Status: 1,
  5873. Remark: "",
  5874. DeleteIdSystem: 0,
  5875. Title: "",
  5876. Content: "",
  5877. Order: 0,
  5878. Code: "",
  5879. }
  5880. service.CreatedDicConfig(&dataconfig)
  5881. }
  5882. }
  5883. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5884. for _, it := range classiFicationList {
  5885. if statistical_classification == it.Name {
  5886. statistical_classification_id = int64(it.Value)
  5887. }
  5888. }
  5889. project.StatisticalClassification = statistical_classification_id
  5890. disease_directory := int64(projectM["disease_directory"].(float64))
  5891. project.DiseaseDirectory = disease_directory
  5892. is_record := int64(projectM["is_record"].(float64))
  5893. project.IsRecord = is_record
  5894. medical_code := projectM["medical_code"].(string)
  5895. project.MedicalCode = medical_code
  5896. tube_color := projectM["tube_color"].(string)
  5897. var tubeColor = "试管颜色"
  5898. var tube_color_id int64
  5899. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5900. if len(tube_color) != 0 {
  5901. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5902. if errcodetube == gorm.ErrRecordNotFound {
  5903. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5904. dataconfig := models.DictDataconfig{
  5905. ParentId: tubeColorConfig.ID,
  5906. Module: "system",
  5907. OrgId: orgId,
  5908. Name: tube_color,
  5909. FieldName: "",
  5910. Value: tubeConfig.Value + 1,
  5911. CreatedTime: "",
  5912. UpdatedTime: "",
  5913. CreateUserId: adminUser.AdminUser.Id,
  5914. Status: 1,
  5915. Remark: "",
  5916. DeleteIdSystem: 0,
  5917. Title: "",
  5918. Content: "",
  5919. Order: 0,
  5920. Code: "",
  5921. }
  5922. service.CreatedDicConfig(&dataconfig)
  5923. }
  5924. }
  5925. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5926. for _, it := range tubeColorList {
  5927. if tube_color == it.Name {
  5928. tube_color_id = int64(it.Value)
  5929. }
  5930. }
  5931. project.TubeColor = tube_color_id
  5932. single_dose := projectM["single_dose"].(string)
  5933. project.SingleDose = single_dose
  5934. execution_frequency := projectM["execution_frequency"].(string)
  5935. project.ExecutionFrequency = execution_frequency
  5936. delivery_way := projectM["delivery_way"].(string)
  5937. project.DeliveryWay = delivery_way
  5938. number_days := projectM["number_days"].(string)
  5939. project.NumberDays = number_days
  5940. total := projectM["total"].(string)
  5941. project.Total = total
  5942. medical_status := int64(projectM["medical_status"].(float64))
  5943. project.MedicalStatus = medical_status
  5944. category := int64(projectM["category"].(float64))
  5945. project.Category = category
  5946. specail_project := int64(projectM["specail_project"].(float64))
  5947. project.SpecailProject = specail_project
  5948. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5949. project.SocialSecurityDirectoryCode = social_security_directory_code
  5950. remark := projectM["remark"].(string)
  5951. project.Remark = remark
  5952. record_date := projectM["record_date"].(string)
  5953. timeLayout := "2006-01-02"
  5954. loc, _ := time.LoadLocation("Local")
  5955. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5956. project.RecordDate = theTime.Unix()
  5957. projectList = append(projectList, &project)
  5958. }
  5959. export_time := time.Now().Unix()
  5960. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5961. if len(projectList) > 0 {
  5962. for _, item := range projectList {
  5963. project := models.HisProject{
  5964. ProjectName: item.ProjectName,
  5965. Price: item.Price,
  5966. Unit: item.Unit,
  5967. CostClassify: item.CostClassify,
  5968. ExecutiveSection: item.ExecutiveSection,
  5969. MedicalCoverage: item.MedicalCoverage,
  5970. UserOrgId: orgId,
  5971. Status: 1,
  5972. CreatedTime: time.Now().Unix(),
  5973. Pinyin: item.Pinyin,
  5974. Wubi: item.Wubi,
  5975. StatisticalClassification: item.StatisticalClassification,
  5976. DiseaseDirectory: item.DiseaseDirectory,
  5977. IsRecord: item.IsRecord,
  5978. MedicalCode: item.MedicalCode,
  5979. TubeColor: item.TubeColor,
  5980. SingleDose: item.SingleDose,
  5981. DeliveryWay: item.DeliveryWay,
  5982. NumberDays: item.NumberDays,
  5983. Total: item.Total,
  5984. Category: item.Category,
  5985. MedicalStatus: item.MedicalStatus,
  5986. SpecailProject: item.SpecailProject,
  5987. RecordDate: item.RecordDate,
  5988. Remark: item.Remark,
  5989. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5990. ExecutionFrequency: item.ExecutionFrequency,
  5991. }
  5992. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5993. if errcodeproject == gorm.ErrRecordNotFound {
  5994. service.CreateProjectInfomation(&project)
  5995. } else if errcodeproject == nil {
  5996. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5997. }
  5998. log := models.ExportLog{
  5999. LogType: 6,
  6000. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6001. TotalNum: int64(len(total_goods)),
  6002. FailNum: int64(len(errLogs)),
  6003. SuccessNum: int64(len(projectList)),
  6004. CreateTime: time.Now().Unix(),
  6005. UpdateTime: time.Now().Unix(),
  6006. ExportTime: export_time,
  6007. Status: 1,
  6008. }
  6009. service.CreateExportLog(&log)
  6010. c.ServeSuccessJSON(map[string]interface{}{
  6011. "msg": "导入成功",
  6012. "total_num": len(total_goods),
  6013. "success_num": len(projectList),
  6014. "fail_num": int64(len(errLogs)),
  6015. })
  6016. }
  6017. } else {
  6018. log := models.ExportLog{
  6019. LogType: 6,
  6020. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6021. TotalNum: int64(len(total_goods)),
  6022. FailNum: int64(len(errLogs)),
  6023. SuccessNum: int64(len(projectList)),
  6024. CreateTime: time.Now().Unix(),
  6025. UpdateTime: time.Now().Unix(),
  6026. ExportTime: export_time,
  6027. Status: 1,
  6028. }
  6029. service.CreateExportLog(&log)
  6030. c.ServeSuccessJSON(map[string]interface{}{
  6031. "msg": "导入成功",
  6032. "total_num": len(total_goods),
  6033. "success_num": len(projectList),
  6034. "fail_num": int64(len(errLogs)),
  6035. })
  6036. }
  6037. }
  6038. //func (this *HisApiController) EditProjectInformation(){
  6039. //
  6040. // id, _ := this.GetInt64("id")
  6041. // project_team := this.GetString("project_team")
  6042. // price := this.GetString("price")
  6043. // price_float, _ := strconv.ParseFloat(price, 64)
  6044. // pinyin := this.GetString("pinyin")
  6045. // wubi := this.GetString("wubi")
  6046. // tube_color, _ := this.GetInt64("tube_color")
  6047. // team_type, _ := this.GetInt64("team_type")
  6048. // remark := this.GetString("remark")
  6049. // ids := this.GetString("ids")
  6050. // item_id := this.GetString("item_id")
  6051. // projectTeam := models.XtHisProjectTeam{
  6052. // ProjectTeam: project_team,
  6053. // Price: price_float,
  6054. // Pinyin: pinyin,
  6055. // Wubi: wubi,
  6056. // TubeColor: tube_color,
  6057. // TeamType: team_type,
  6058. // Remark: remark,
  6059. // ProjectId: ids,
  6060. // ItemId: item_id,
  6061. // }
  6062. //
  6063. //
  6064. // dataBody := make(map[string]interface{}, 0)
  6065. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6066. // if err != nil {
  6067. // utils.ErrorLog(err.Error())
  6068. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6069. // return
  6070. // }
  6071. //
  6072. // err = service.UpdatedProjectTeam(id, &projectTeam)
  6073. //
  6074. //
  6075. // if err != nil {
  6076. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6077. // return
  6078. // }
  6079. //
  6080. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  6081. // infos, _ := dataBody["info"].([]interface{})
  6082. // if len(infos) > 0 {
  6083. // var ids []string
  6084. //
  6085. // for _, item := range infos {
  6086. // items := item.(map[string]interface{})
  6087. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6088. // utils.ErrorLog("id")
  6089. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6090. // return
  6091. // }
  6092. // id := int64(items["id"].(float64))
  6093. //
  6094. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6095. // utils.ErrorLog("type")
  6096. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6097. // return
  6098. // }
  6099. // types := int64(items["type"].(float64))
  6100. //
  6101. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6102. // utils.ErrorLog("number")
  6103. // }
  6104. //
  6105. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  6106. //
  6107. // projectList := models.XtHisProjectList{
  6108. // Number: number,
  6109. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  6110. // ProjectId: id,
  6111. // Status: 1,
  6112. // CreatedTime: time.Now().Unix(),
  6113. // UpdatedTime: time.Now().Unix(),
  6114. // TeamId: projectTeam.ID,
  6115. // Type: types,
  6116. // }
  6117. // list := projectList
  6118. //
  6119. // service.CreateProjectList(&list)
  6120. //
  6121. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  6122. //
  6123. // }
  6124. // ids_str := strings.Join(ids, ",")
  6125. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  6126. // service.SaveProjectTeam(&projectTeam)
  6127. // this.ServeSuccessJSON(map[string]interface{}{
  6128. // "projectTeam": projectTeam,
  6129. // })
  6130. // }
  6131. // }
  6132. //}
  6133. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6134. name := c.GetString("name")
  6135. mode_id, _ := c.GetInt64("mode", 0)
  6136. types, _ := c.GetInt64("type", 0)
  6137. patient_id, _ := c.GetInt64("patient_id", 0)
  6138. types = 1
  6139. adminInfo := c.GetAdminUserInfo()
  6140. template := &models.HisPrescriptionTemplate{
  6141. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6142. PatientId: patient_id,
  6143. Type: types,
  6144. Status: 1,
  6145. Ctime: time.Now().Unix(),
  6146. Mtime: time.Now().Unix(),
  6147. Name: name,
  6148. Mode: mode_id,
  6149. }
  6150. dataBody := make(map[string]interface{}, 0)
  6151. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6152. if err != nil {
  6153. utils.ErrorLog(err.Error())
  6154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6155. return
  6156. }
  6157. err = service.CreateHisPrescriptionTemplate(template)
  6158. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6159. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6160. if len(prescriptions) > 0 {
  6161. for _, item := range prescriptions {
  6162. items := item.(map[string]interface{})
  6163. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6164. utils.ErrorLog("type")
  6165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6166. return
  6167. }
  6168. types := int64(items["type"].(float64))
  6169. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6170. utils.ErrorLog("med_type")
  6171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6172. return
  6173. }
  6174. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6175. ctime := time.Now().Unix()
  6176. prescription := &models.HisPrescriptionInfoTemplate{
  6177. PatientId: patient_id,
  6178. UserOrgId: adminInfo.CurrentOrgId,
  6179. Ctime: ctime,
  6180. Mtime: ctime,
  6181. Type: types,
  6182. Modifier: adminInfo.AdminUser.Id,
  6183. Creator: adminInfo.AdminUser.Id,
  6184. Status: 1,
  6185. PTemplateId: template.ID,
  6186. MedType: med_type,
  6187. }
  6188. service.CreateHisPrescriptionInfoTemplate(prescription)
  6189. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6190. advices := items["advices"].([]interface{})
  6191. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6192. ctime := time.Now().Unix()
  6193. mtime := ctime
  6194. if len(advices) > 0 {
  6195. for _, advice := range advices {
  6196. var s models.HisPrescriptionAdviceTemplate
  6197. s.PrescriptionId = prescription.ID
  6198. s.AdviceType = 2
  6199. s.StopState = 2
  6200. s.ExecutionState = 2
  6201. s.Status = 1
  6202. s.UserOrgId = adminInfo.CurrentOrgId
  6203. s.CreatedTime = ctime
  6204. s.UpdatedTime = mtime
  6205. s.PatientId = patient_id
  6206. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6207. if errcode > 0 {
  6208. c.ServeFailJSONWithSGJErrorCode(errcode)
  6209. return
  6210. }
  6211. service.CreateHisPrescriptionAdviceTemplate(&s)
  6212. }
  6213. }
  6214. }
  6215. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6216. projects := items["project"].([]interface{})
  6217. if len(projects) > 0 {
  6218. for _, project := range projects {
  6219. var p models.HisPrescriptionProjectTemplate
  6220. p.PrescriptionId = prescription.ID
  6221. p.Ctime = time.Now().Unix()
  6222. p.Mtime = time.Now().Unix()
  6223. p.PatientId = patient_id
  6224. p.UserOrgId = adminInfo.CurrentOrgId
  6225. p.Status = 1
  6226. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6227. if errcode > 0 {
  6228. c.ServeFailJSONWithSGJErrorCode(errcode)
  6229. return
  6230. }
  6231. service.CreateHisPrescriptionProjectTemplate(&p)
  6232. }
  6233. }
  6234. }
  6235. }
  6236. c.ServeSuccessJSON(map[string]interface{}{
  6237. "msg": "创建成功",
  6238. })
  6239. }
  6240. }
  6241. }
  6242. func (c *HisApiController) PreSettle() {
  6243. id, _ := c.GetInt64("id")
  6244. record_time := c.GetString("record_time")
  6245. his_patient_id, _ := c.GetInt64("his_patient_id")
  6246. timeLayout := "2006-01-02"
  6247. loc, _ := time.LoadLocation("Local")
  6248. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6249. diagnosis_id := c.GetString("diagnosis")
  6250. sick_type, _ := c.GetInt64("sick_type")
  6251. reg_type, _ := c.GetInt64("p_type")
  6252. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6254. if err != nil {
  6255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6256. return
  6257. }
  6258. recordDateTime := theTime.Unix()
  6259. adminUser := c.GetAdminUserInfo()
  6260. var prescriptions []*models.HisPrescription
  6261. var start_time int64
  6262. var end_time int64
  6263. ids_str := c.GetString("ids")
  6264. ids_arr := strings.Split(ids_str, ",")
  6265. fmt.Println(reg_type)
  6266. if settle_accounts_type == 1 { //日结
  6267. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6268. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6269. } else {
  6270. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6271. }
  6272. fmt.Println(prescriptions)
  6273. } else { //月结
  6274. start_time_str := c.GetString("start_time")
  6275. end_time_str := c.GetString("end_time")
  6276. timeLayout := "2006-01-02"
  6277. loc, _ := time.LoadLocation("Local")
  6278. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6279. if err != nil {
  6280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6281. return
  6282. }
  6283. recordStartTime := theStartTime.Unix()
  6284. start_time = recordStartTime
  6285. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6286. if err != nil {
  6287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6288. return
  6289. }
  6290. recordEndTime := theEndTime.Unix()
  6291. end_time = recordEndTime
  6292. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6293. }
  6294. if reg_type == 1111 || reg_type == 1112 {
  6295. reg_type = 11
  6296. }
  6297. timestamp := time.Now().Unix()
  6298. tempTime := time.Unix(timestamp, 0)
  6299. timeFormat := tempTime.Format("20060102150405")
  6300. chrgBchno := rand.Intn(100000) + 10000
  6301. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6302. strconv.FormatInt(his.PatientId, 10)
  6303. var ids []int64
  6304. for _, item := range prescriptions {
  6305. ids = append(ids, item.ID)
  6306. }
  6307. fmt.Println(ids)
  6308. var total float64
  6309. for _, item := range prescriptions {
  6310. fmt.Println(item)
  6311. if item.Type == 1 { //药品
  6312. for _, subItem := range item.HisDoctorAdviceInfo {
  6313. total = total + (subItem.Price * subItem.PrescribingNumber)
  6314. }
  6315. }
  6316. if item.Type == 2 { //项目
  6317. for _, subItem := range item.HisPrescriptionProject {
  6318. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6319. total = total + (subItem.Price * cnt)
  6320. }
  6321. }
  6322. for _, subItem := range item.HisAdditionalCharge {
  6323. total = total + (subItem.Price * float64(subItem.Count))
  6324. }
  6325. }
  6326. allTotal := fmt.Sprintf("%.2f", total)
  6327. totals, _ := strconv.ParseFloat(allTotal, 64)
  6328. order := &models.HisOrder{
  6329. UserOrgId: adminUser.CurrentOrgId,
  6330. HisPatientId: his.ID,
  6331. PatientId: id,
  6332. SettleAccountsDate: recordDateTime,
  6333. Ctime: time.Now().Unix(),
  6334. Mtime: time.Now().Unix(),
  6335. Status: 1,
  6336. OrderStatus: 1,
  6337. MdtrtId: his.Number,
  6338. Number: chrg_bchno,
  6339. MedfeeSumamt: totals,
  6340. SettleEndTime: end_time,
  6341. SettleStartTime: start_time,
  6342. SettleType: settle_accounts_type,
  6343. PType: 2,
  6344. IsPre: 1,
  6345. MedType: strconv.Itoa(int(reg_type)),
  6346. Diagnosis: diagnosis_id,
  6347. }
  6348. err = service.CreateOrder(order)
  6349. if err != nil {
  6350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6351. return
  6352. }
  6353. var customs []*Custom
  6354. for _, item := range prescriptions {
  6355. fmt.Println(item.Type)
  6356. if item.Type == 1 { //药品
  6357. for _, subItem := range item.HisDoctorAdviceInfo {
  6358. cus := &Custom{
  6359. AdviceId: subItem.ID,
  6360. ProjectId: 0,
  6361. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6362. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6363. FeedetlSn: subItem.FeedetlSn,
  6364. Price: fmt.Sprintf("%.2f", subItem.Price),
  6365. MedListCodg: subItem.MedListCodg,
  6366. Type: 1,
  6367. }
  6368. customs = append(customs, cus)
  6369. }
  6370. }
  6371. if item.Type == 2 { //项目
  6372. for _, subItem := range item.HisPrescriptionProject {
  6373. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6374. cus := &Custom{
  6375. AdviceId: 0,
  6376. ProjectId: subItem.ID,
  6377. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6378. Cut: fmt.Sprintf("%.2f", cnt),
  6379. FeedetlSn: subItem.FeedetlSn,
  6380. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6381. MedListCodg: subItem.MedListCodg,
  6382. Type: 2,
  6383. }
  6384. customs = append(customs, cus)
  6385. }
  6386. }
  6387. for _, item := range item.HisAdditionalCharge {
  6388. cus := &Custom{
  6389. ItemId: item.ID,
  6390. AdviceId: 0,
  6391. ProjectId: 0,
  6392. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6393. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6394. FeedetlSn: item.FeedetlSn,
  6395. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6396. MedListCodg: item.XtHisAddtionConfig.Code,
  6397. Type: 3,
  6398. }
  6399. customs = append(customs, cus)
  6400. }
  6401. }
  6402. fmt.Println(customs)
  6403. for _, item := range customs {
  6404. var advice_id int64 = 0
  6405. var project_id int64 = 0
  6406. var item_id int64 = 0
  6407. var types int64 = 0
  6408. if item.Type == 1 {
  6409. advice_id = item.AdviceId
  6410. project_id = 0
  6411. item_id = 0
  6412. } else if item.Type == 2 {
  6413. advice_id = 0
  6414. item_id = 0
  6415. project_id = item.ProjectId
  6416. } else if item.Type == 3 {
  6417. advice_id = 0
  6418. item_id = item.ItemId
  6419. project_id = 0
  6420. }
  6421. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6422. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6423. pric, _ := strconv.ParseFloat(item.Price, 32)
  6424. info := &models.HisOrderInfo{
  6425. OrderNumber: order.Number,
  6426. UploadDate: time.Now().Unix(),
  6427. AdviceId: advice_id,
  6428. DetItemFeeSumamt: detItemFeeSumamt,
  6429. Cnt: cut,
  6430. Pric: pric,
  6431. PatientId: id,
  6432. Status: 1,
  6433. Mtime: time.Now().Unix(),
  6434. Ctime: time.Now().Unix(),
  6435. UserOrgId: adminUser.CurrentOrgId,
  6436. HisPatientId: his.ID,
  6437. OrderId: order.ID,
  6438. ProjectId: project_id,
  6439. Type: types,
  6440. ItemId: item_id,
  6441. }
  6442. service.CreateOrderInfo(info)
  6443. }
  6444. his.SickType = sick_type
  6445. service.UpdataHisPateint(&his)
  6446. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6447. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6448. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6449. if err == nil {
  6450. c.ServeSuccessJSON(map[string]interface{}{
  6451. "msg": "结算成功",
  6452. })
  6453. }
  6454. }
  6455. type CustomOrderInfo struct {
  6456. Name string
  6457. Spec string
  6458. Unit string
  6459. Count float64
  6460. Price float64
  6461. Total float64
  6462. }
  6463. func (c *HisApiController) GetPrivateExpensesInfo() {
  6464. order_id, _ := c.GetInt64("id", 0)
  6465. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6466. order, _ := service.GetHisOrderByID(order_id)
  6467. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6468. if order.ID == 0 {
  6469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6470. return
  6471. }
  6472. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6473. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6474. org_id := c.GetAdminUserInfo().CurrentOrgId
  6475. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6476. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6477. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6478. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6479. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6480. var orderInfos_four []*models.HisOrderInfoTwo
  6481. for _, item := range orderInfos_three {
  6482. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6483. item.HisPrescriptionProject.IsCheckTeam = 1
  6484. orderInfos_four = append(orderInfos_four, item)
  6485. }
  6486. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6487. item.HisPrescriptionProject.IsCheckTeam = 2
  6488. orderInfos_two = append(orderInfos_two, item)
  6489. }
  6490. }
  6491. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6492. var cus_slice []CustomOrderInfo
  6493. for _, item := range new_order_info {
  6494. var cus CustomOrderInfo
  6495. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6496. cus.Unit = ""
  6497. cus.Spec = ""
  6498. var total float64
  6499. for _, subItem := range orderInfos_four {
  6500. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6501. total = total + subItem.DetItemFeeSumamt
  6502. fmt.Println(subItem.DetItemFeeSumamt)
  6503. }
  6504. }
  6505. cus.Count = 1
  6506. cus.Total = total
  6507. cus_slice = append(cus_slice, cus)
  6508. }
  6509. orderInfos = append(orderInfos, orderInfos_two...)
  6510. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6511. orderInfos = append(orderInfos, orderInfos_three...)
  6512. }
  6513. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6514. c.ServeSuccessJSON(map[string]interface{}{
  6515. "order": order,
  6516. "order_info": orderInfos,
  6517. "patient": patient,
  6518. "admin_info": adminInfo,
  6519. "his": his,
  6520. "current_admin": role,
  6521. "org_config": miConfig,
  6522. "new_order_info": cus_slice,
  6523. })
  6524. }
  6525. func (this *HisApiController) ChangeMedType() {
  6526. med_type := this.GetString("med_type")
  6527. old_med_type := this.GetString("old_med_type")
  6528. ids := this.GetString("ids")
  6529. settle_type, _ := this.GetInt64("settle_type")
  6530. start_time := this.GetString("start_time")
  6531. end_time := this.GetString("end_time")
  6532. ids_arr := strings.Split(ids, ",")
  6533. if settle_type == 1 { //日结
  6534. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6535. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6536. prescription.MedType = med_type
  6537. err := service.SaveHisPrescription(&prescription)
  6538. if err == nil {
  6539. this.ServeSuccessJSON(map[string]interface{}{
  6540. "msg": "修改成功",
  6541. })
  6542. } else {
  6543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6544. return
  6545. }
  6546. } else if settle_type == 2 {
  6547. timeLayout := "2006-01-02"
  6548. loc, _ := time.LoadLocation("Local")
  6549. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6550. if err != nil {
  6551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6552. return
  6553. }
  6554. recordStartTime := theStartTime.Unix()
  6555. start_time_timestamp := recordStartTime
  6556. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6557. if err != nil {
  6558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6559. return
  6560. }
  6561. recordEndTime := theEndTime.Unix()
  6562. end_time_timestamp := recordEndTime
  6563. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6564. if updateErr == nil {
  6565. this.ServeSuccessJSON(map[string]interface{}{
  6566. "msg": "修改成功",
  6567. })
  6568. } else {
  6569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6570. return
  6571. }
  6572. }
  6573. }
  6574. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6575. patient_id, _ := c.GetInt64("patient_id")
  6576. his_patient_id, _ := c.GetInt64("his_patient_id")
  6577. record_date := c.GetString("record_date")
  6578. start_time := c.GetString("start_time")
  6579. end_time := c.GetString("end_time")
  6580. order_status, _ := c.GetInt64("type", 0)
  6581. p_type, _ := c.GetInt64("p_type", 0)
  6582. order_id, _ := c.GetInt64("order_id", 0)
  6583. timeLayout := "2006-01-02"
  6584. loc, _ := time.LoadLocation("Local")
  6585. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6586. if err != nil {
  6587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6588. return
  6589. }
  6590. recordDateTime := theTime.Unix()
  6591. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6592. if err != nil {
  6593. }
  6594. startRecordDateTime := startTime.Unix()
  6595. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6596. if err != nil {
  6597. }
  6598. endRecordDateTime := endTime.Unix()
  6599. admin := c.GetAdminUserInfo()
  6600. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6601. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6602. order, _ := service.GetHisOrderByID(order_id)
  6603. var monthPrescriptions []*models.HisPrescription
  6604. if order_status == 1 || order_status == 0 {
  6605. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6606. } else if order_status == 2 {
  6607. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6608. }
  6609. var settle_total float64
  6610. for _, item := range monthPrescriptions {
  6611. if len(item.HisPrescriptionProject) > 0 {
  6612. for _, subItem := range item.HisPrescriptionProject {
  6613. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6614. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6615. settle_total = settle_total + total
  6616. }
  6617. }
  6618. if len(item.HisDoctorAdviceInfo) > 0 {
  6619. for _, subItem := range item.HisDoctorAdviceInfo {
  6620. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6621. settle_total = settle_total + total
  6622. }
  6623. }
  6624. }
  6625. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6626. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6627. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6628. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6629. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6630. //获取所有科室信息
  6631. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6632. c.ServeSuccessJSON(map[string]interface{}{
  6633. "his_info": his_patient_info,
  6634. "xt_info": xt_patient_info,
  6635. "case_history": case_history,
  6636. "info": patientPrescriptionInfo,
  6637. "last_info": lastPatientPrescriptionInfo,
  6638. "month_prescriptions": monthPrescriptions,
  6639. "order": order,
  6640. "doctors": doctors,
  6641. "department": department,
  6642. "settle_total": settle_total,
  6643. })
  6644. return
  6645. }
  6646. func (c *HisApiController) GetHisMonthPatientInfo() {
  6647. patient_id, _ := c.GetInt64("patient_id")
  6648. his_patient_id, _ := c.GetInt64("his_patient_id")
  6649. record_date := c.GetString("record_date")
  6650. number := c.GetString("number")
  6651. start_time := c.GetString("start_time")
  6652. end_time := c.GetString("end_time")
  6653. p_type, _ := c.GetInt64("p_type")
  6654. timeLayout := "2006-01-02"
  6655. loc, _ := time.LoadLocation("Local")
  6656. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6657. if err != nil {
  6658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6659. return
  6660. }
  6661. recordDateTime := theTime.Unix()
  6662. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6663. if err != nil {
  6664. }
  6665. startRecordDateTime := startTime.Unix()
  6666. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6667. if err != nil {
  6668. }
  6669. endRecordDateTime := endTime.Unix()
  6670. admin := c.GetAdminUserInfo()
  6671. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6672. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6673. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6674. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6675. var settle_total float64
  6676. for _, item := range monthPrescriptions {
  6677. if len(item.HisPrescriptionProject) > 0 {
  6678. for _, subItem := range item.HisPrescriptionProject {
  6679. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6680. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6681. settle_total = settle_total + total
  6682. }
  6683. }
  6684. if len(item.HisDoctorAdviceInfo) > 0 {
  6685. for _, subItem := range item.HisDoctorAdviceInfo {
  6686. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6687. settle_total = settle_total + total
  6688. }
  6689. }
  6690. }
  6691. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6692. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6693. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6694. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6695. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6696. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6697. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6698. //获取所有科室信息
  6699. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6700. c.ServeSuccessJSON(map[string]interface{}{
  6701. "his_info": his_patient_info,
  6702. "xt_info": xt_patient_info,
  6703. "case_history": case_history,
  6704. "info": patientPrescriptionInfo,
  6705. "month_prescriptions": monthPrescriptions,
  6706. "order": order,
  6707. "doctors": doctors,
  6708. "department": department,
  6709. "count": count,
  6710. "drugStockConfig": drugStockConfig,
  6711. "last_info": lastPatientPrescriptionInfo,
  6712. "settle_total": settle_total,
  6713. })
  6714. return
  6715. }
  6716. func (c *HisApiController) GetAllOrder() {
  6717. org_id := c.GetAdminUserInfo().CurrentOrgId
  6718. orders, _ := service.GetNewHisOrderList(org_id)
  6719. c.ServeSuccessJSON(map[string]interface{}{
  6720. "order": orders,
  6721. })
  6722. return
  6723. }
  6724. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6725. newArr = make([]*models.HisOrderInfoTwo, 0)
  6726. for i := 0; i < len(arr); i++ {
  6727. repeat := false
  6728. for j := i + 1; j < len(arr); j++ {
  6729. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6730. repeat = true
  6731. break
  6732. }
  6733. }
  6734. if !repeat {
  6735. newArr = append(newArr, arr[i])
  6736. }
  6737. }
  6738. return
  6739. }
  6740. //修改处方退库操作 参数传修改之前的处方数据
  6741. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6742. if advice.ExecutionState == 1 {
  6743. //查询该病人该药品是否有库存记录
  6744. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6745. if errcode == gorm.ErrRecordNotFound {
  6746. } else {
  6747. //退库
  6748. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6749. if advice.PrescribingNumberUnit == drug.MinUnit {
  6750. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6751. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6752. //退库
  6753. warehouseInfo := models.DrugWarehouseInfo{
  6754. StockMinNumber: prescribingNumber,
  6755. }
  6756. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6757. operation_time := time.Now().Unix()
  6758. creater := advice.AdviceDoctor
  6759. ctime := time.Now().Unix()
  6760. timeStr := time.Now().Format("2006-01-02")
  6761. timeArr := strings.Split(timeStr, "-")
  6762. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6763. total = total + 1
  6764. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6765. cancelStock := models.DrugCancelStock{
  6766. OrderNumber: orderNumber,
  6767. OperaTime: operation_time,
  6768. OrgId: advice.UserOrgId,
  6769. Creater: creater,
  6770. Ctime: ctime,
  6771. Status: 1,
  6772. ReturnTime: advice.AdviceDate,
  6773. Dealer: info.Dealer,
  6774. Manufacturer: info.Manufacturer,
  6775. Type: 1,
  6776. }
  6777. service.AddSigleDrugCancelStock(&cancelStock)
  6778. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6779. dealer, _ := service.GetDealerById(info.Dealer)
  6780. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6781. cancelStockInfo := models.DrugCancelStockInfo{
  6782. OrderNumber: cancelInfo.OrderNumber,
  6783. CancelStockId: cancelInfo.ID,
  6784. DrugId: info.DrugId,
  6785. Count: info.Count,
  6786. Status: 1,
  6787. Ctime: ctime,
  6788. OrgId: advice.UserOrgId,
  6789. Type: 1,
  6790. Manufacturer: manufactureName.ManufacturerName,
  6791. Dealer: dealer.DealerName,
  6792. Total: 0,
  6793. RetailPrice: info.RetailPrice,
  6794. RetailTotalPrice: info.RetailTotalPrice,
  6795. Price: info.Price,
  6796. RegisterAccount: "",
  6797. Remark: info.Remark,
  6798. BatchNumber: info.BatchNumber,
  6799. MaxUnit: info.CountUnit,
  6800. ProductDate: info.ProductDate,
  6801. ExpiryDate: info.ExpiryDate,
  6802. BatchNumberId: info.WarehouseInfoId,
  6803. }
  6804. flow := models.DrugFlow{
  6805. WarehousingId: 0,
  6806. DrugId: info.DrugId,
  6807. Number: "",
  6808. BatchNumber: info.BatchNumber,
  6809. Count: info.Count,
  6810. UserOrgId: advice.UserOrgId,
  6811. PatientId: 0,
  6812. SystemTime: ctime,
  6813. ConsumableType: 4,
  6814. IsSys: 0,
  6815. WarehousingOrder: "",
  6816. WarehouseOutId: 0,
  6817. WarehouseOutOrderNumber: "",
  6818. IsEdit: 0,
  6819. CancelStockId: cancelStock.ID,
  6820. CancelOrderNumber: cancelStock.OrderNumber,
  6821. Manufacturer: info.Manufacturer,
  6822. Dealer: info.Dealer,
  6823. Creator: advice.UserOrgId,
  6824. UpdateCreator: 0,
  6825. Status: 1,
  6826. Ctime: time.Now().Unix(),
  6827. Mtime: 0,
  6828. Price: info.Price,
  6829. WarehousingDetailId: 0,
  6830. WarehouseOutDetailId: 0,
  6831. CancelOutDetailId: 0,
  6832. ExpireDate: info.ExpiryDate,
  6833. ProductDate: info.ProductDate,
  6834. MaxUnit: info.CountUnit,
  6835. MinUnit: "",
  6836. }
  6837. service.CreatedCancelStock(cancelStockInfo)
  6838. service.CreateDrugFlowOne(flow)
  6839. } else {
  6840. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6841. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6842. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6843. warehouseInfo := models.DrugWarehouseInfo{
  6844. StockMinNumber: prescribingNumber,
  6845. }
  6846. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6847. }
  6848. operation_time := time.Now().Unix()
  6849. creater := advice.AdviceDoctor
  6850. ctime := time.Now().Unix()
  6851. timeStr := time.Now().Format("2006-01-02")
  6852. timeArr := strings.Split(timeStr, "-")
  6853. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6854. total = total + 1
  6855. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6856. cancelStock := models.DrugCancelStock{
  6857. OrderNumber: orderNumber,
  6858. OperaTime: operation_time,
  6859. OrgId: advice.UserOrgId,
  6860. Creater: creater,
  6861. Ctime: ctime,
  6862. Status: 1,
  6863. ReturnTime: advice.AdviceDate,
  6864. Dealer: info.Dealer,
  6865. Manufacturer: info.Manufacturer,
  6866. Type: 1,
  6867. }
  6868. service.AddSigleDrugCancelStock(&cancelStock)
  6869. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6870. dealer, _ := service.GetDealerById(info.Dealer)
  6871. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6872. cancelStockInfo := models.DrugCancelStockInfo{
  6873. OrderNumber: cancelInfo.OrderNumber,
  6874. CancelStockId: cancelInfo.ID,
  6875. DrugId: info.DrugId,
  6876. Count: info.Count,
  6877. Status: 1,
  6878. Ctime: ctime,
  6879. OrgId: advice.UserOrgId,
  6880. Type: 1,
  6881. Manufacturer: manufactureName.ManufacturerName,
  6882. Dealer: dealer.DealerName,
  6883. Total: 0,
  6884. RetailPrice: info.RetailPrice,
  6885. RetailTotalPrice: info.RetailTotalPrice,
  6886. Price: info.Price,
  6887. RegisterAccount: "",
  6888. Remark: info.Remark,
  6889. BatchNumber: info.BatchNumber,
  6890. MaxUnit: info.CountUnit,
  6891. ProductDate: info.ProductDate,
  6892. ExpiryDate: info.ExpiryDate,
  6893. BatchNumberId: info.WarehouseInfoId,
  6894. }
  6895. flow := models.DrugFlow{
  6896. WarehousingId: 0,
  6897. DrugId: info.DrugId,
  6898. Number: "",
  6899. BatchNumber: info.BatchNumber,
  6900. Count: info.Count,
  6901. UserOrgId: advice.UserOrgId,
  6902. PatientId: 0,
  6903. SystemTime: ctime,
  6904. ConsumableType: 4,
  6905. IsSys: 0,
  6906. WarehousingOrder: "",
  6907. WarehouseOutId: 0,
  6908. WarehouseOutOrderNumber: "",
  6909. IsEdit: 0,
  6910. CancelStockId: cancelStock.ID,
  6911. CancelOrderNumber: cancelStock.OrderNumber,
  6912. Manufacturer: info.Manufacturer,
  6913. Dealer: info.Dealer,
  6914. Creator: advice.AdviceDoctor,
  6915. UpdateCreator: 0,
  6916. Status: 1,
  6917. Ctime: time.Now().Unix(),
  6918. Mtime: 0,
  6919. Price: info.Price,
  6920. WarehousingDetailId: 0,
  6921. WarehouseOutDetailId: 0,
  6922. CancelOutDetailId: 0,
  6923. ExpireDate: info.ExpiryDate,
  6924. ProductDate: info.ProductDate,
  6925. MaxUnit: info.CountUnit,
  6926. MinUnit: "",
  6927. }
  6928. service.CreatedCancelStock(cancelStockInfo)
  6929. service.CreateDrugFlowOne(flow)
  6930. }
  6931. }
  6932. }
  6933. return err
  6934. }
  6935. func (this *HisApiController) DeleteNCDS() {
  6936. id, _ := this.GetInt64("id", 0)
  6937. if id > 0 {
  6938. service.DeletePsnNCDSRecordById(id)
  6939. this.ServeSuccessJSON(map[string]interface{}{
  6940. "msg": "删除成功",
  6941. })
  6942. } else {
  6943. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6944. return
  6945. }
  6946. }
  6947. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6948. id, _ := c.GetInt64("id")
  6949. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6950. c.ServeSuccessJSON(map[string]interface{}{
  6951. "advice": advice,
  6952. })
  6953. return
  6954. }
  6955. func (c *HisApiController) GetHisMonthChargePatientList() {
  6956. record_date := c.GetString("record_date")
  6957. start_time := c.GetString("start_time")
  6958. end_time := c.GetString("end_time")
  6959. timeLayout := "2006-01-02"
  6960. loc, _ := time.LoadLocation("Local")
  6961. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6962. if err != nil {
  6963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6964. return
  6965. }
  6966. if err != nil {
  6967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6968. return
  6969. }
  6970. recordDateTime := theTime.Unix()
  6971. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6972. if err != nil {
  6973. }
  6974. startRecordDateTime := startTime.Unix()
  6975. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6976. if err != nil {
  6977. }
  6978. endRecordDateTime := endTime.Unix()
  6979. adminInfo := c.GetAdminUserInfo()
  6980. var tempMonthChargePatients []*service.MonthChargePatients
  6981. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  6982. for _, item := range tempPatients {
  6983. //过滤没有处方的
  6984. if len(item.HisPrescription) == 0 {
  6985. tempMonthChargePatients = append(tempMonthChargePatients, item)
  6986. }
  6987. }
  6988. c.ServeSuccessJSON(map[string]interface{}{
  6989. "list": tempMonthChargePatients,
  6990. })
  6991. }