his_api_controller.go 407KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496
  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. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. }
  87. func (c *HisApiController) ChangeOrderDesc() {
  88. id, _ := c.GetInt64("id")
  89. desc := c.GetString("desc")
  90. change_type := c.GetString("change_type")
  91. order, _ := service.GetHisOrderByID(id)
  92. if order.ID == 0 {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. switch change_type {
  97. case "oth_desc":
  98. order.OthDesc = desc
  99. break
  100. case "cash_pay":
  101. order.CashPay = desc
  102. break
  103. case "jifen_pay":
  104. order.JifenPay = desc
  105. break
  106. case "band_card_pay":
  107. order.BandCardPay = desc
  108. break
  109. case "ali_pay":
  110. order.AliPay = desc
  111. break
  112. case "wechat_pay":
  113. order.WechatPay = desc
  114. break
  115. }
  116. err := service.SaveHisOrder(&order)
  117. if err == nil {
  118. c.ServeSuccessJSON(map[string]interface{}{
  119. "msg": "修改成功",
  120. })
  121. return
  122. } else {
  123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  124. return
  125. }
  126. }
  127. func (c *HisApiController) GetMonthHisPatient() {
  128. record_date := c.GetString("record_date")
  129. //order_status, _ := c.GetInt64("type")
  130. timeLayout := "2006-01-02"
  131. loc, _ := time.LoadLocation("Local")
  132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  133. if err != nil {
  134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. return
  136. }
  137. recordDateTime := theTime.Unix()
  138. adminInfo := c.GetAdminUserInfo()
  139. var tempPatients []service.NewTempPatients
  140. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  141. // 获取当前时间
  142. now := time.Now()
  143. // 获取本月的第一天
  144. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  145. // 获取下个月的第一天
  146. nextMonth := firstDay.AddDate(0, 1, 0)
  147. // 获取本月的最后一天
  148. lastDay := nextMonth.Add(-time.Nanosecond)
  149. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  150. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  151. var patients []service.NewTempPatients
  152. var patients_two []service.NewTempPatients
  153. for _, item := range tempPatients {
  154. //过滤掉没挂号的和没开处方的
  155. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  156. patients = append(patients, item)
  157. }
  158. ////过滤掉没挂号的
  159. //if len(item.HisPatient) > 0 {
  160. // patients_two = append(patients_two, item)
  161. //}
  162. }
  163. c.ServeSuccessJSON(map[string]interface{}{
  164. "list": patients,
  165. "list_two": patients_two,
  166. "chargePatients": chargePatients,
  167. })
  168. }
  169. func (c *HisApiController) GetBatchSettleAccounts() {
  170. order_ids := c.GetString("order_ids")
  171. admin_user_id, _ := c.GetInt64("admin_user_id")
  172. adminUser := c.GetAdminUserInfo()
  173. orders := strings.Split(order_ids, ",")
  174. var newOrders []models.Orders
  175. for _, item := range orders {
  176. order, _ := service.GetHisOrderByIDTenOne(item)
  177. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  178. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  179. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  180. orderInfos = append(orderInfos, orderInfos_two...)
  181. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  182. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  183. var diagnosis_ids []string
  184. if his.ID > 0 {
  185. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  186. } else {
  187. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  188. }
  189. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  190. var dia_config []*models.HisXtDiagnoseConfig
  191. var name string
  192. for _, item := range diagnosis_ids {
  193. id, _ := strconv.ParseInt(item, 10, 64)
  194. diagnosisConfig, _ := service.FindDiagnoseById(id)
  195. dia_config = append(dia_config, diagnosisConfig)
  196. if len(name) == 0 {
  197. name = diagnosisConfig.ClassName
  198. } else {
  199. name = name + "," + diagnosisConfig.ClassName
  200. }
  201. }
  202. var bedCostTotal float64 = 0 //床位总费
  203. var bedCostSelfTotal float64 = 0 //床位自费
  204. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  205. var bedSelfTotal float64 = 0 //床位部分项目自费
  206. var bedInscpTotal float64 = 0 //床位部分项目自费
  207. var operationCostTotal float64 = 0 //手术费
  208. var operationCostSelfTotal float64 = 0 //手术费
  209. var operationCostPartSelfTotal float64 = 0 //手术费
  210. var operationSelfTotal float64 = 0 //床位部分项目自费
  211. var operationInscpTotal float64 = 0 //床位部分项目自费
  212. var otherCostTotal float64 = 0 //其他费用
  213. var otherCostSelfTotal float64 = 0 //其他费用
  214. var otherCostPartSelfTotal float64 = 0 //其他费用
  215. var otherSelfTotal float64 = 0 //床位部分项目自费
  216. var otherInscpTotal float64 = 0 //床位部分项目自费
  217. var materialCostTotal float64 = 0 //材料费
  218. var materialCostSelfTotal float64 = 0 //材料费
  219. var materialCostPartSelfTotal float64 = 0 //材料费
  220. var materialSelfTotal float64 = 0 //床位部分项目自费
  221. var materialInscpTotal float64 = 0 //床位部分项目自费
  222. var westernMedicineCostTotal float64 = 0 //西药费
  223. var westernMedicineCostSelfTotal float64 = 0 //西药费
  224. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  225. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  226. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  227. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  228. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  229. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  230. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  231. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  232. var checkCostTotal float64 = 0 //检查费
  233. var checkCostSelfTotal float64 = 0 //检查费
  234. var checkCostPartSelfTotal float64 = 0 //检查费
  235. var checkSelfTotal float64 = 0 //床位部分项目自费
  236. var checkInscpTotal float64 = 0 //床位部分项目自费
  237. var laboratoryCostTotal float64 = 0 //化验费
  238. var laboratoryCostSelfTotal float64 = 0 //化验费
  239. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  240. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  241. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  242. var treatCostTotal float64 = 0 //治疗费用
  243. var treatCostSelfTotal float64 = 0 //治疗费用
  244. var treatCostPartSelfTotal float64 = 0 //治疗费用
  245. var treatSelfTotal float64 = 0 //床位部分项目自费
  246. var treatInscpTotal float64 = 0 //床位部分项目自费
  247. decimal.DivisionPrecision = 2
  248. for _, item := range orderInfos {
  249. if item.MedChrgitmType == "01" { //床位费
  250. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  251. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  253. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  254. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  255. }
  256. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  257. if item.MedChrgitmType == "03" { //检查费
  258. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  259. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  260. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  261. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  262. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  263. }
  264. } else {
  265. if item.MedChrgitmType == "03" { //检查费
  266. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  267. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  268. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  269. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  270. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  271. }
  272. }
  273. if item.MedChrgitmType == "04" { //化验费
  274. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  275. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  276. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  277. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  278. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  279. }
  280. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  281. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. if item.MedChrgitmType == "06" { //手术费
  288. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  289. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  290. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  291. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  292. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  293. }
  294. if item.MedChrgitmType == "08" { //材料费
  295. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  296. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  298. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  299. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  300. }
  301. if item.MedChrgitmType == "09" { //西药费
  302. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  306. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  307. }
  308. if item.MedChrgitmType == "11" { //中成费
  309. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  310. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  311. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  312. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  313. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  316. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  320. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  321. }
  322. }
  323. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  324. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  325. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  326. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  327. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  328. var doctor_name string
  329. if roles.ID == 0 {
  330. doctor_name = "管理员"
  331. } else {
  332. doctor_name = roles.UserName
  333. }
  334. yiliao_leibie := ""
  335. switch order.MedType {
  336. case "11":
  337. yiliao_leibie = "普通门诊"
  338. break
  339. case "12":
  340. yiliao_leibie = "门诊挂号"
  341. break
  342. case "13":
  343. yiliao_leibie = "急诊"
  344. break
  345. case "14":
  346. yiliao_leibie = "门诊特殊病"
  347. break
  348. case "15":
  349. yiliao_leibie = "门诊统筹"
  350. break
  351. case "16":
  352. yiliao_leibie = "门诊慢性病"
  353. break
  354. case "21":
  355. yiliao_leibie = "普通住院"
  356. break
  357. }
  358. var newOrder models.Orders
  359. newOrder.Diagnosis = name
  360. newOrder.OrderInfos = orderInfos
  361. newOrder.Number = order.MdtrtId
  362. newOrder.Date = order.SettleAccountsDate
  363. newOrder.ChargeAdmin = charge_admin
  364. newOrder.PrintorAdmin = printor_admin
  365. newOrder.Order = order
  366. newOrder.BedCostTotal = bedCostTotal
  367. newOrder.BedCostSelfTotal = bedCostSelfTotal
  368. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  369. newOrder.BedSelfTotal = bedSelfTotal
  370. newOrder.BedInscpTotal = bedInscpTotal
  371. newOrder.OperationCostTotal = operationCostTotal
  372. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  373. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  374. newOrder.OperationSelfTotal = operationSelfTotal
  375. newOrder.OperationInscpTotal = operationInscpTotal
  376. newOrder.OtherCostTotal = otherCostTotal
  377. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  378. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  379. newOrder.OtherSelfTotal = otherSelfTotal
  380. newOrder.OtherInscpTotal = otherInscpTotal
  381. newOrder.MaterialCostTotal = materialCostTotal
  382. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  383. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  384. newOrder.MaterialSelfTotal = materialSelfTotal
  385. newOrder.MaterialInscpTotal = materialInscpTotal
  386. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  387. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  388. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  389. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  390. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  391. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  392. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  393. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  394. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  395. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  396. newOrder.CheckCostTotal = checkCostTotal
  397. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  398. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  399. newOrder.CheckSelfTotal = checkSelfTotal
  400. newOrder.CheckInscpTotal = checkInscpTotal
  401. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  402. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  403. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  404. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  405. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  406. newOrder.TreatCostTotal = treatCostTotal
  407. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  408. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  409. newOrder.TreatSelfTotal = treatSelfTotal
  410. newOrder.TreatInscpTotal = treatInscpTotal
  411. newOrder.DoctorInfo = doctor_info
  412. newOrder.DoctorName = doctor_name
  413. newOrder.HealthCardNo = order.PsnNo
  414. newOrder.YiliaoLeibie = yiliao_leibie
  415. newOrder.Patient = patient
  416. newOrder.OrgName = miConfig.OrgName
  417. newOrder.OrgCode = miConfig.Code
  418. newOrder.OrderNumber = order.Number
  419. newOrder.HisPatient = his
  420. newOrder.DiaConfig = dia_config
  421. newOrders = append(newOrders, newOrder)
  422. }
  423. c.ServeSuccessJSON(map[string]interface{}{
  424. "orders": newOrders,
  425. })
  426. }
  427. func (c *HisApiController) GetTestOrder() {
  428. order_id, _ := c.GetInt64("order_id")
  429. admin_user_id, _ := c.GetInt64("admin_user_id")
  430. adminUser := c.GetAdminUserInfo()
  431. order, _ := service.GetHisOrderByID(order_id)
  432. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  433. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  434. orderInfos = append(orderInfos, orderInfos_two...)
  435. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  436. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  437. var dia_config []*models.HisXtDiagnoseConfig
  438. var name string
  439. var bedCostTotal float64 = 0 //床位总费
  440. var bedCostSelfTotal float64 = 0 //床位自费
  441. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  442. var bedSelfTotal float64 = 0 //床位部分项目自费
  443. var bedInscpTotal float64 = 0 //床位部分项目自费
  444. var operationCostTotal float64 = 0 //手术费
  445. var operationCostSelfTotal float64 = 0 //手术费
  446. var operationCostPartSelfTotal float64 = 0 //手术费
  447. var operationSelfTotal float64 = 0 //床位部分项目自费
  448. var operationInscpTotal float64 = 0 //床位部分项目自费
  449. var otherCostTotal float64 = 0 //其他费用
  450. var otherCostSelfTotal float64 = 0 //其他费用
  451. var otherCostPartSelfTotal float64 = 0 //其他费用
  452. var otherSelfTotal float64 = 0 //床位部分项目自费
  453. var otherInscpTotal float64 = 0 //床位部分项目自费
  454. var materialCostTotal float64 = 0 //材料费
  455. var materialCostSelfTotal float64 = 0 //材料费
  456. var materialCostPartSelfTotal float64 = 0 //材料费
  457. var materialSelfTotal float64 = 0 //床位部分项目自费
  458. var materialInscpTotal float64 = 0 //床位部分项目自费
  459. var westernMedicineCostTotal float64 = 0 //西药费
  460. var westernMedicineCostSelfTotal float64 = 0 //西药费
  461. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  462. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  463. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  464. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  465. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  466. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  467. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  468. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  469. var checkCostTotal float64 = 0 //检查费
  470. var checkCostSelfTotal float64 = 0 //检查费
  471. var checkCostPartSelfTotal float64 = 0 //检查费
  472. var checkSelfTotal float64 = 0 //床位部分项目自费
  473. var checkInscpTotal float64 = 0 //床位部分项目自费
  474. var laboratoryCostTotal float64 = 0 //化验费
  475. var laboratoryCostSelfTotal float64 = 0 //化验费
  476. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  477. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  478. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  479. var treatCostTotal float64 = 0 //治疗费用
  480. var treatCostSelfTotal float64 = 0 //治疗费用
  481. var treatCostPartSelfTotal float64 = 0 //治疗费用
  482. var treatSelfTotal float64 = 0 //床位部分项目自费
  483. var treatInscpTotal float64 = 0 //床位部分项目自费
  484. decimal.DivisionPrecision = 2
  485. for _, item := range orderInfos {
  486. if item.MedChrgitmType == "01" { //床位费
  487. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  488. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  489. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  490. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  491. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  492. }
  493. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  494. if item.MedChrgitmType == "03" { //检查费
  495. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  496. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  497. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  498. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  499. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  500. }
  501. } else {
  502. if item.MedChrgitmType == "03" { //检查费
  503. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  504. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  505. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  506. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  507. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  508. }
  509. }
  510. if item.MedChrgitmType == "04" { //化验费
  511. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  512. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  513. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  514. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  515. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  516. }
  517. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  518. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. if item.MedChrgitmType == "06" { //手术费
  525. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  526. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  527. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  528. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  529. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  530. }
  531. if item.MedChrgitmType == "08" { //材料费
  532. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  533. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  534. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  535. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  536. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  537. }
  538. if item.MedChrgitmType == "09" { //西药费
  539. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  540. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  541. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  542. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  543. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  544. }
  545. if item.MedChrgitmType == "11" { //中成费
  546. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  547. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  548. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  549. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  550. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  551. }
  552. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  553. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  554. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  555. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  556. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  557. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  558. }
  559. }
  560. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  561. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  562. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  563. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  564. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  565. var doctor_name string
  566. if roles.ID == 0 {
  567. doctor_name = "管理员"
  568. } else {
  569. doctor_name = roles.UserName
  570. }
  571. yiliao_leibie := ""
  572. switch order.MedType {
  573. case "11":
  574. yiliao_leibie = "普通门诊"
  575. break
  576. case "12":
  577. yiliao_leibie = "门诊挂号"
  578. break
  579. case "13":
  580. yiliao_leibie = "急诊"
  581. break
  582. case "14":
  583. yiliao_leibie = "门诊特殊病"
  584. break
  585. case "15":
  586. yiliao_leibie = "门诊统筹"
  587. break
  588. case "16":
  589. yiliao_leibie = "门诊慢性病"
  590. break
  591. case "21":
  592. yiliao_leibie = "普通住院"
  593. break
  594. }
  595. c.ServeSuccessJSON(map[string]interface{}{
  596. "diagnosis": name,
  597. "order_infos": orderInfos,
  598. "number": order.MdtrtId,
  599. "date": order.SettleAccountsDate,
  600. "charge_admin": charge_admin,
  601. "printor_admin": printor_admin,
  602. "info": order,
  603. "order": order,
  604. "bedCostTotal": bedCostTotal,
  605. "bedCostSelfTotal": bedCostSelfTotal,
  606. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  607. "bedSelfTotal": bedSelfTotal,
  608. "bedInscpTotal": bedInscpTotal,
  609. "operationCostTotal": operationCostTotal,
  610. "operationCostSelfTotal": operationCostSelfTotal,
  611. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  612. "operationSelfTotal": operationSelfTotal,
  613. "operationInscpTotal": operationInscpTotal,
  614. "otherCostTotal": otherCostTotal,
  615. "otherCostSelfTotal": otherCostSelfTotal,
  616. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  617. "otherSelfTotal": otherSelfTotal,
  618. "otherInscpTotal": otherInscpTotal,
  619. "materialCostTotal": materialCostTotal,
  620. "materialCostSelfTotal": materialCostSelfTotal,
  621. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  622. "materialSelfTotal": materialSelfTotal,
  623. "materialInscpTotal": materialInscpTotal,
  624. "westernMedicineCostTotal": westernMedicineCostTotal,
  625. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  626. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  627. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  628. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  629. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  630. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  631. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  632. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  633. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  634. "checkCostTotal": checkCostTotal,
  635. "checkCostSelfTotal": checkCostSelfTotal,
  636. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  637. "checkSelfTotal": checkSelfTotal,
  638. "checkInscpTotal": checkInscpTotal,
  639. "laboratoryCostTotal": laboratoryCostTotal,
  640. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  641. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  642. "laboratorySelfTotal": laboratorySelfTotal,
  643. "laboratoryInscpTotal": laboratoryInscpTotal,
  644. "treatCostTotal": treatCostTotal,
  645. "treatCostSelfTotal": treatCostSelfTotal,
  646. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  647. "treatSelfTotal": treatSelfTotal,
  648. "treatInscpTotal": treatInscpTotal,
  649. "doctor_info": doctor_info,
  650. "doctor_name": doctor_name,
  651. "health_card_no": order.PsnNo,
  652. "yiliao_leibie": yiliao_leibie,
  653. "patient": patient,
  654. "org_name": miConfig.OrgName,
  655. "org_code": miConfig.Code,
  656. "order_number": order.Number,
  657. "his_hospital": his_hospital,
  658. "dia_config": dia_config,
  659. })
  660. }
  661. func (c *PublicApiController) GetBaiLinExportData() {
  662. data := service.GetBaiLinOrderData()
  663. fmt.Println(len(data))
  664. var new_data []*models.NewCustomHisOrder
  665. for _, item := range data {
  666. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  667. new_data = append(new_data, item)
  668. }
  669. }
  670. fmt.Println(len(new_data))
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "list": new_data,
  673. })
  674. }
  675. func (c *HisApiController) GetHisUnChargePatientList() {
  676. record_date := c.GetString("record_date")
  677. timeLayout := "2006-01-02"
  678. loc, _ := time.LoadLocation("Local")
  679. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  680. if err != nil {
  681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  682. return
  683. }
  684. recordDateTime := theTime.Unix()
  685. adminInfo := c.GetAdminUserInfo()
  686. var tempPatients []*service.NewTempPatients
  687. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  688. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  689. var patients []*service.NewTempPatients
  690. var patients_two []*service.NewTempPatients
  691. for _, item := range tempPatients {
  692. //过滤掉没挂号的和没开处方的
  693. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  694. patients = append(patients, item)
  695. }
  696. //过滤掉没挂号的
  697. if len(item.HisPatient) > 0 {
  698. patients_two = append(patients_two, item)
  699. }
  700. }
  701. c.ServeSuccessJSON(map[string]interface{}{
  702. "list": patients,
  703. "list_two": patients_two,
  704. })
  705. }
  706. func (c *HisApiController) GetPrivateExpensesOrder() {
  707. //id, _ := c.GetInt64("id")
  708. //record_time := c.GetString("record_time")
  709. order_id, _ := c.GetInt64("order_id")
  710. admin_user_id, _ := c.GetInt64("admin_user_id")
  711. //timeLayout := "2006-01-02"
  712. //loc, _ := time.LoadLocation("Local")
  713. //
  714. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  715. //if err != nil {
  716. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. // return
  718. //}
  719. //recordDateTime := theTime.Unix()
  720. adminUser := c.GetAdminUserInfo()
  721. order, _ := service.GetHisOrderByID(order_id)
  722. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  723. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  724. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  725. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  726. //var config []*models.HisXtDiagnoseConfig
  727. var name string
  728. if order.PType == 1 {
  729. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  730. for _, item := range diagnosis_ids {
  731. id, _ := strconv.ParseInt(item, 10, 64)
  732. diagnosisConfig, _ := service.FindDiagnoseById(id)
  733. if len(name) == 0 {
  734. name = diagnosisConfig.ClassName
  735. } else {
  736. name = name + "," + diagnosisConfig.ClassName
  737. }
  738. }
  739. } else {
  740. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  741. for _, item := range diagnosis_ids {
  742. id, _ := strconv.ParseInt(item, 10, 64)
  743. diagnosisConfig, _ := service.FindDiagnoseById(id)
  744. if len(name) == 0 {
  745. name = diagnosisConfig.ClassName
  746. } else {
  747. name = name + "," + diagnosisConfig.ClassName
  748. }
  749. }
  750. }
  751. var bedCostTotal float64 = 0 //床位总费
  752. //var bedCostSelfTotal float64 = 0 //床位自费
  753. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  754. var operationCostTotal float64 = 0 //手术费
  755. //var operationCostSelfTotal float64 = 0 //手术费
  756. var operationCostPartSelfTotal float64 = 0 //手术费
  757. var otherCostTotal float64 = 0 //其他费用
  758. //var otherCostSelfTotal float64 = 0 //其他费用
  759. var otherCostPartSelfTotal float64 = 0 //其他费用
  760. var materialCostTotal float64 = 0 //材料费
  761. //var materialCostSelfTotal float64 = 0 //材料费
  762. var materialCostPartSelfTotal float64 = 0 //材料费
  763. var westernMedicineCostTotal float64 = 0 //西药费
  764. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  765. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  766. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  767. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  768. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  769. var checkCostTotal float64 = 0 //检查费
  770. //var checkCostSelfTotal float64 = 0 //检查费
  771. var checkCostPartSelfTotal float64 = 0 //检查费
  772. var laboratoryCostTotal float64 = 0 //化验费
  773. //var laboratoryCostSelfTotal float64 = 0 //化验费
  774. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  775. var treatCostTotal float64 = 0 //治疗费用
  776. //var treatCostSelfTotal float64 = 0 //治疗费用
  777. var treatCostPartSelfTotal float64 = 0 //治疗费用
  778. var zhenChaCostTotal float64 = 0 //其他费用
  779. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  780. decimal.DivisionPrecision = 2
  781. for _, item := range orderInfos {
  782. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  783. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  784. item.MedChrgitmType = "09"
  785. }
  786. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  787. if item.HisPrescriptionProject.Type == 2 {
  788. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  789. fmt.Println("CostClassify")
  790. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  791. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  792. case 0:
  793. item.MedChrgitmType = "0"
  794. break
  795. case 1:
  796. item.MedChrgitmType = "14"
  797. break
  798. case 2:
  799. item.MedChrgitmType = "05"
  800. break
  801. case 3:
  802. item.MedChrgitmType = "03"
  803. break
  804. case 4:
  805. item.MedChrgitmType = "03"
  806. break
  807. case 5:
  808. item.MedChrgitmType = "08"
  809. break
  810. case 6:
  811. item.MedChrgitmType = "14"
  812. break
  813. case 7:
  814. item.MedChrgitmType = "14"
  815. break
  816. case 8:
  817. item.MedChrgitmType = "03"
  818. break
  819. case 9:
  820. item.MedChrgitmType = "14"
  821. break
  822. case 10:
  823. item.MedChrgitmType = "14"
  824. break
  825. case 11:
  826. item.MedChrgitmType = "06"
  827. break
  828. case 12:
  829. item.MedChrgitmType = "12"
  830. break
  831. case 13:
  832. item.MedChrgitmType = "01"
  833. break
  834. case 14:
  835. item.MedChrgitmType = "04"
  836. break
  837. case 15:
  838. item.MedChrgitmType = "14"
  839. break
  840. }
  841. } else {
  842. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  843. case 1:
  844. item.MedChrgitmType = "14"
  845. break
  846. case 2:
  847. item.MedChrgitmType = "05"
  848. break
  849. case 3:
  850. item.MedChrgitmType = "04"
  851. break
  852. case 4:
  853. item.MedChrgitmType = "14"
  854. break
  855. case 5:
  856. item.MedChrgitmType = "08"
  857. break
  858. case 6:
  859. item.MedChrgitmType = "14"
  860. break
  861. case 7:
  862. item.MedChrgitmType = "14"
  863. break
  864. case 8:
  865. item.MedChrgitmType = "03"
  866. break
  867. case 9:
  868. item.MedChrgitmType = "14"
  869. break
  870. }
  871. }
  872. } else if item.HisPrescriptionProject.Type == 3 {
  873. item.MedChrgitmType = "08"
  874. }
  875. }
  876. }
  877. order.PsnCashPay = order.MedfeeSumamt
  878. for _, item := range orderInfos {
  879. if item.MedChrgitmType == "01" { //床位费
  880. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  881. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  882. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  883. }
  884. if item.MedChrgitmType == "02" { //诊察费
  885. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  886. //zhenChaCostSelfTotal = zhenChaCostTotal
  887. }
  888. if item.MedChrgitmType == "03" { //检查费
  889. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  890. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  891. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  892. }
  893. if item.MedChrgitmType == "02" { //检查费
  894. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  895. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  896. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  897. }
  898. if item.MedChrgitmType == "04" { //化验费
  899. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  900. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  901. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  902. }
  903. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  904. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  905. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  906. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  907. }
  908. if item.MedChrgitmType == "06" { //手术费
  909. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  910. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  911. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  912. }
  913. if item.MedChrgitmType == "08" { //材料费
  914. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  915. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  916. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  917. }
  918. if item.MedChrgitmType == "09" { //西药费
  919. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  920. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  921. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  922. }
  923. if item.MedChrgitmType == "11" { //中成费
  924. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  925. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  926. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  927. }
  928. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  929. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  930. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  931. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  932. }
  933. }
  934. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  935. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  936. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  937. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  938. c.ServeSuccessJSON(map[string]interface{}{
  939. "patient": patient,
  940. "order_infos": orderInfos,
  941. "diagnosis": name,
  942. "bedCostTotal": bedCostTotal,
  943. "bedCostSelfTotal": bedCostTotal,
  944. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  945. "operationCostTotal": operationCostTotal,
  946. "operationCostSelfTotal": operationCostTotal,
  947. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  948. "otherCostTotal": otherCostTotal,
  949. "otherCostSelfTotal": otherCostTotal,
  950. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  951. "materialCostTotal": materialCostTotal,
  952. "materialCostSelfTotal": materialCostTotal,
  953. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  954. "westernMedicineCostTotal": westernMedicineCostTotal,
  955. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  956. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  957. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  958. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  959. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  960. "checkCostTotal": checkCostTotal,
  961. "checkCostSelfTotal": checkCostTotal,
  962. "zhenChaCostTotal": zhenChaCostTotal,
  963. "zhenChaCostSelfTotal": zhenChaCostTotal,
  964. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  965. "laboratoryCostTotal": laboratoryCostTotal,
  966. "laboratoryCostSelfTotal": laboratoryCostTotal,
  967. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  968. "treatCostTotal": treatCostTotal,
  969. "treatCostSelfTotal": treatCostTotal,
  970. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  971. "charge_admin": charge_admin,
  972. "printor_admin": printor_admin,
  973. "org_name": org.OrgName,
  974. "org_code": miConfig.Code,
  975. "name": patient.Name,
  976. "number": order.MdtrtId,
  977. "date": order.SettleAccountsDate,
  978. "info": order,
  979. "his_hospital": his_hospital,
  980. "his": his,
  981. })
  982. }
  983. func (c *HisApiController) RefudDetail() {
  984. order_id, _ := c.GetInt64("order_id")
  985. order, _ := service.GetHisOrderByID(order_id)
  986. adminUser := c.GetAdminUserInfo()
  987. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "msg": "撤销成功",
  990. })
  991. }
  992. func (c *HisApiController) Sscard() {
  993. //r := CardInit()
  994. //if r == 0 {
  995. // GetBaseInfo()
  996. //}
  997. //c.ServeSuccessJSON(map[string]interface{}{
  998. // "list": "11",
  999. //})
  1000. }
  1001. func GetBaseInfo() error {
  1002. //handle := syscall.MustLoadDLL("SSCard.dll")
  1003. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1004. //
  1005. //str := make([]byte, 256)
  1006. //str1 := make([]byte, 256)
  1007. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1008. //if ferr != nil {
  1009. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1010. // return ferr
  1011. //}
  1012. //
  1013. //fmt.Println(string(str))
  1014. //
  1015. //fmt.Println(r)
  1016. return nil
  1017. }
  1018. func CardInit() int {
  1019. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1020. //add := DllTestDef.MustFindProc("Init")
  1021. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1022. //if err != nil {
  1023. // fmt.Println("SSCard的运算结果为:", ret)
  1024. //}
  1025. //result := int(ret)
  1026. return 0
  1027. }
  1028. func IntPtr(n int) uintptr {
  1029. return uintptr(n)
  1030. }
  1031. func StrPtr(s string) uintptr {
  1032. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1033. }
  1034. func (c *HisApiController) GetHisPatientList() {
  1035. //types, _ := c.GetInt64("type", 0)
  1036. record_date := c.GetString("record_date")
  1037. sch_type, _ := c.GetInt64("sch_type")
  1038. timeLayout := "2006-01-02"
  1039. loc, _ := time.LoadLocation("Local")
  1040. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1041. if err != nil {
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1043. return
  1044. }
  1045. recordDateTime := theTime.Unix()
  1046. adminInfo := c.GetAdminUserInfo()
  1047. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1048. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1049. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1050. //获取当前用户的信息
  1051. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1052. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1053. //获取所有科室信息
  1054. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1055. c.ServeSuccessJSON(map[string]interface{}{
  1056. "list": patients,
  1057. "list_two": patients_two,
  1058. "info": adminUserInfo,
  1059. "doctors": doctors,
  1060. "department": department,
  1061. })
  1062. }
  1063. type CustomTemplate struct {
  1064. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1065. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1066. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1067. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1068. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1069. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1070. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1071. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1072. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1073. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1074. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1075. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1076. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1077. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1078. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1079. }
  1080. func (c *HisApiController) GetHisPatientInfo() {
  1081. patient_id, _ := c.GetInt64("patient_id")
  1082. his_patient_id, _ := c.GetInt64("his_patient_id")
  1083. record_date := c.GetString("record_date")
  1084. number := c.GetString("number")
  1085. //start_time := c.GetString("start_time")
  1086. //end_time := c.GetString("end_time")
  1087. p_type, _ := c.GetInt64("p_type")
  1088. timeLayout := "2006-01-02"
  1089. loc, _ := time.LoadLocation("Local")
  1090. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1091. if err != nil {
  1092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1093. return
  1094. }
  1095. recordDateTime := theTime.Unix()
  1096. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1097. //if err != nil {
  1098. //
  1099. //}
  1100. //startRecordDateTime := startTime.Unix()
  1101. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1102. //if err != nil {
  1103. //
  1104. //}
  1105. //endRecordDateTime := endTime.Unix()
  1106. admin := c.GetAdminUserInfo()
  1107. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1108. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1109. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1110. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1111. var prescriptions []*models.HisPrescription
  1112. var last_prescriptions []*models.HisPrescription
  1113. var sch_prescriptions []CustomTemplate
  1114. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1115. if p_type == 1 { //住院
  1116. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1117. for _, item := range prescriptions {
  1118. for _, subItem := range item.HisDoctorAdviceInfo {
  1119. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1120. if info.RetailPrice > 0 {
  1121. subItem.Drug.MinPrice = info.RetailPrice
  1122. }
  1123. }
  1124. }
  1125. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1126. } else { //门诊
  1127. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1128. for _, item := range prescriptions {
  1129. for _, subItem := range item.HisDoctorAdviceInfo {
  1130. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1131. if info.RetailPrice > 0 {
  1132. subItem.Drug.MinPrice = info.RetailPrice
  1133. }
  1134. }
  1135. }
  1136. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1137. }
  1138. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1139. if sch.ID > 0 {
  1140. var week string
  1141. t := time.Now()
  1142. switch t.Weekday().String() {
  1143. case "Monday":
  1144. week = "周一"
  1145. break
  1146. case "Tuesday":
  1147. week = "周二"
  1148. break
  1149. case "Wednesday":
  1150. week = "周三"
  1151. break
  1152. case "Thursday":
  1153. week = "周四"
  1154. break
  1155. case "Friday":
  1156. week = "周五"
  1157. break
  1158. case "Saturday":
  1159. week = "周六"
  1160. break
  1161. case "Sunday":
  1162. week = "周日"
  1163. break
  1164. }
  1165. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1166. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1167. //根据推送频率组装新的数组
  1168. for _, item := range temp_sch_prescriptions {
  1169. var cus CustomTemplate
  1170. cus.ID = item.ID
  1171. cus.UserOrgId = item.UserOrgId
  1172. cus.PatientId = item.PatientId
  1173. cus.MedType = item.MedType
  1174. cus.RecordDate = item.RecordDate
  1175. cus.Type = item.Type
  1176. cus.PType = item.PType
  1177. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1178. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1179. if subItem.FrequencyType == 1 { //每次必推
  1180. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1181. }
  1182. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1183. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1184. }
  1185. if subItem.FrequencyType == 2 { //按照天数频率
  1186. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1187. now := p.Unix()
  1188. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1189. dayStr2 := "-" + dayStr
  1190. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1191. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1192. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1193. if len(advices) == 0 {
  1194. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1195. }
  1196. }
  1197. }
  1198. }
  1199. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1200. if subItem.Type == 2 {
  1201. if subItem.XtHisProject.MedicalStatus != 1 {
  1202. if subItem.FrequencyType == 1 {
  1203. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1204. }
  1205. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1206. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1207. }
  1208. if subItem.FrequencyType == 2 {
  1209. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1210. now := p.Unix()
  1211. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1212. dayStr2 := "-" + dayStr
  1213. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1214. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1215. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1216. if len(projects) == 0 {
  1217. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1218. }
  1219. }
  1220. }
  1221. } else if subItem.Type == 3 {
  1222. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1223. if subItem.FrequencyType == 1 {
  1224. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1225. }
  1226. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1227. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1228. }
  1229. if subItem.FrequencyType == 2 {
  1230. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1231. now := p.Unix()
  1232. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1233. dayStr2 := "-" + dayStr
  1234. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1235. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1236. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1237. if len(projects) == 0 {
  1238. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1239. }
  1240. }
  1241. }
  1242. }
  1243. }
  1244. sch_prescriptions = append(sch_prescriptions, cus)
  1245. }
  1246. for _, item := range sch_prescriptions {
  1247. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1248. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1249. }
  1250. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1251. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1252. }
  1253. }
  1254. }
  1255. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1256. if config.ID > 0 && config.IsOpen == 1 {
  1257. for _, item := range sch_prescriptions {
  1258. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1259. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1260. if info.RetailPrice > 0 {
  1261. subItem.Drug.MinPrice = info.RetailPrice
  1262. }
  1263. }
  1264. }
  1265. }
  1266. if config.ID > 0 && config.IsOpen == 1 {
  1267. for _, item := range sch_prescriptions {
  1268. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1269. if subItem.Type == 3 {
  1270. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1271. if info.Price > 0 {
  1272. subItem.GoodInfo.PackingPrice = info.Price
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1279. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1280. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1281. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1282. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1283. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1284. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1285. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1286. //获取所有科室信息
  1287. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1288. c.ServeSuccessJSON(map[string]interface{}{
  1289. "his_info": his_patient_info,
  1290. "xt_info": xt_patient_info,
  1291. "prescription": prescriptions,
  1292. "case_history": case_history,
  1293. "info": patientPrescriptionInfo,
  1294. //"month_prescriptions": monthPrescriptions,
  1295. "order": order,
  1296. "doctors": doctors,
  1297. "department": department,
  1298. "sch_prescriptions": sch_prescriptions,
  1299. "last_prescriptions": last_prescriptions,
  1300. "schedule": sch,
  1301. "count": count,
  1302. "drugStockConfig": drugStockConfig,
  1303. "last_info": lastPatientPrescriptionInfo,
  1304. })
  1305. return
  1306. }
  1307. func (c *HisApiController) GetHisPrescriptionConfig() {
  1308. adminInfo := c.GetAdminUserInfo()
  1309. //获取医嘱模版
  1310. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1311. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1312. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1313. //获取所有基础药
  1314. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1315. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1316. if config.ID > 0 && config.IsOpen == 1 {
  1317. for _, item := range drugs {
  1318. var index = 0
  1319. for _, subItem := range item.OtherDrugWarehouseInfo {
  1320. if index == 0 {
  1321. index = index + 1
  1322. if subItem.RetailPrice > 0 {
  1323. item.MinPrice = subItem.RetailPrice
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1330. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1331. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1332. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1333. //获取所有科室信息
  1334. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1335. //获取诊断信息
  1336. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1337. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1338. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1339. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1340. //获取是否开启保存耗材出库的开关
  1341. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1342. c.ServeSuccessJSON(map[string]interface{}{
  1343. "drugs": drugs,
  1344. "advices_template": advices,
  1345. "drugways": drugways,
  1346. "efs": efs,
  1347. "doctors": doctors,
  1348. "department": department,
  1349. "sick": sick,
  1350. "additions": additions,
  1351. "diagnose": diagnose,
  1352. "manufacturers": manufacturers,
  1353. "goodOutOpen": goodOutOpen,
  1354. "patientDiagnose": patientDiagnose,
  1355. })
  1356. }
  1357. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1358. //获取所有基础药
  1359. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1360. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1361. if config.ID > 0 && config.IsOpen == 1 {
  1362. for _, item := range drugs {
  1363. var index = 0
  1364. for _, subItem := range item.OtherDrugWarehouseInfo {
  1365. if index == 0 {
  1366. index = index + 1
  1367. if subItem.RetailPrice > 0 {
  1368. item.MinPrice = subItem.RetailPrice
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1375. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1376. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1377. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1378. //获取所有科室信息
  1379. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1380. //获取诊断信息
  1381. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1382. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1383. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1384. //获取是否开启保存耗材出库的开关
  1385. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1386. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1387. c.ServeSuccessJSON(map[string]interface{}{
  1388. "drugs": drugs,
  1389. "advices_template": advices,
  1390. "drugways": drugways,
  1391. "efs": efs,
  1392. "doctors": doctors,
  1393. "department": department,
  1394. "sick": sick,
  1395. "additions": additions,
  1396. "diagnose": diagnose,
  1397. "manufacturers": manufacturers,
  1398. "goodOutOpen": goodOutOpen,
  1399. "patientDiagnose": patientDiagnose,
  1400. })
  1401. }
  1402. }
  1403. func (c *HisApiController) CreateHisPrescription() {
  1404. record_date := c.GetString("record_date")
  1405. patient_id, _ := c.GetInt64("patient_id")
  1406. reg_type, _ := c.GetInt64("reg_type")
  1407. diagnose := c.GetString("diagnose")
  1408. sick_type, _ := c.GetInt64("sick_type")
  1409. sick_history := c.GetString("sick_history")
  1410. doctor_id, _ := c.GetInt64("doctor", 0)
  1411. department, _ := c.GetInt64("department", 0)
  1412. his_patient_id, _ := c.GetInt64("his_patient_id")
  1413. p_type, _ := c.GetInt64("p_type")
  1414. patient_diagnose := c.GetString("patient_diagnose")
  1415. dataBody := make(map[string]interface{}, 0)
  1416. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1417. if err != nil {
  1418. utils.ErrorLog(err.Error())
  1419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1420. return
  1421. }
  1422. timeLayout := "2006-01-02"
  1423. loc, _ := time.LoadLocation("Local")
  1424. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1425. if err != nil {
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. adminInfo := c.GetAdminUserInfo()
  1430. recordDateTime := theTime.Unix()
  1431. //查询默认出库仓库库存
  1432. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1433. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1434. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1435. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1436. if len(lists) == 1 {
  1437. his_patient_id = lists[0].ID
  1438. }
  1439. }
  1440. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1441. //保存处方出库
  1442. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1443. //自动出库
  1444. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1445. //耗材保存处方出库
  1446. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1447. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1448. //已发药和已收费限制逻辑
  1449. isMidicine := false
  1450. isCharge := false
  1451. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1452. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1453. if len(prescriptions) > 0 {
  1454. for _, item := range prescriptions {
  1455. items := item.(map[string]interface{})
  1456. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1457. utils.ErrorLog("id")
  1458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1459. return
  1460. }
  1461. id := int64(items["id"].(float64))
  1462. if id > 0 {
  1463. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1464. if err != nil {
  1465. if new_prescription.OrderStatus == 4 {
  1466. isCharge = true
  1467. }
  1468. }
  1469. }
  1470. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1471. advices := items["advices"].([]interface{})
  1472. if len(advices) > 0 {
  1473. for _, advice := range advices {
  1474. var adviceId int64
  1475. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1476. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1477. }
  1478. if adviceId > 0 {
  1479. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1480. if err == nil {
  1481. if his_advice_info.IsMedicine == 1 {
  1482. isMidicine = true
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. if isMidicine == true {
  1493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1494. return
  1495. }
  1496. if isCharge == true {
  1497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1498. return
  1499. }
  1500. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1501. //药品发药出库
  1502. if pharmacyConfig.IsOpen == 1 {
  1503. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1504. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1505. if len(prescriptions) > 0 {
  1506. for _, item := range prescriptions {
  1507. items := item.(map[string]interface{})
  1508. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1509. advices := items["advices"].([]interface{})
  1510. if len(advices) > 0 {
  1511. for _, advice := range advices {
  1512. var drug_id int64
  1513. var prescribing_number float64
  1514. var prescribingNumberUnit string
  1515. var adviceId int64
  1516. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1517. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1518. }
  1519. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1520. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1521. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1522. }
  1523. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1524. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1525. }
  1526. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1527. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1528. }
  1529. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1530. if drug.ID == 0 {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. //查询药品的所有库存
  1535. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1536. var total_count int64
  1537. for _, it := range list {
  1538. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1539. }
  1540. totals := strconv.FormatInt(total_count, 10)
  1541. //查询该药品是否存在开药记录
  1542. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1543. //新增处方
  1544. if advicelist.ID == 0 {
  1545. all_count, _ := strconv.ParseFloat(totals, 64)
  1546. if prescribingNumberUnit == drug.MinUnit {
  1547. if drug.IsUse != 1 {
  1548. if prescribing_number > all_count {
  1549. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1550. return
  1551. }
  1552. }
  1553. }
  1554. if prescribingNumberUnit == drug.MaxUnit {
  1555. num := prescribing_number * float64(drug.MinNumber)
  1556. if drug.IsUse != 1 {
  1557. if num > all_count {
  1558. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1559. return
  1560. }
  1561. }
  1562. }
  1563. }
  1564. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1565. if drugOutConfig.IsOpen != 1 {
  1566. //修改处方
  1567. for _, advice := range advices {
  1568. var drug_id int64
  1569. var prescribing_number float64
  1570. var prescribingNumberUnit string
  1571. var prescribingNumber string
  1572. var adviceId int64
  1573. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1574. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1575. }
  1576. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1577. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1578. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1579. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1580. }
  1581. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1582. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1583. }
  1584. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1585. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1586. }
  1587. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1588. if drug.ID == 0 {
  1589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1590. return
  1591. }
  1592. //查询药品的所有库存
  1593. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1594. var total_count int64
  1595. for _, it := range list {
  1596. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1597. }
  1598. totals := strconv.FormatInt(total_count, 10)
  1599. //查询该药品是否存在开药记录
  1600. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1601. //新增处方
  1602. if advicelist.ID == 0 {
  1603. all_count, _ := strconv.ParseFloat(totals, 64)
  1604. if prescribingNumberUnit == drug.MinUnit {
  1605. if drug.IsUse != 1 {
  1606. if prescribing_number > all_count {
  1607. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1608. return
  1609. }
  1610. }
  1611. } else {
  1612. if prescribingNumberUnit == drug.MaxUnit {
  1613. num := prescribing_number * float64(drug.MinNumber)
  1614. if drug.IsUse != 1 {
  1615. if num > all_count {
  1616. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1617. return
  1618. }
  1619. }
  1620. }
  1621. }
  1622. }
  1623. //修改处方
  1624. if advicelist.ID > 0 {
  1625. var device_number int64
  1626. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1627. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1628. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1629. device_number = prescribingNumberInt * drug.MinNumber
  1630. }
  1631. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1632. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1633. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1634. device_number = prescribingNumberInt
  1635. }
  1636. var number_count int64
  1637. if prescribingNumberUnit == drug.MaxUnit {
  1638. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1639. number_count = prescribingNumberInt * drug.MinNumber
  1640. }
  1641. if prescribingNumberUnit == drug.MinUnit {
  1642. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1643. number_count = prescribingNumberInt
  1644. }
  1645. //如果修改的数量大于之前修改的数量
  1646. if (number_count - device_number) > 0 {
  1647. //如果修改的差数量 大于库存数量
  1648. if drug.IsUse != 1 {
  1649. if (number_count - device_number) > total_count {
  1650. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1651. return
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. //已发药和已收费限制逻辑
  1666. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1667. //校验库存总量
  1668. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1669. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1670. if len(prescriptions) > 0 {
  1671. for _, item := range prescriptions {
  1672. items := item.(map[string]interface{})
  1673. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1674. advices := items["advices"].([]interface{})
  1675. if len(advices) > 0 {
  1676. for _, advice := range advices {
  1677. var drug_id int64
  1678. var prescribing_number float64
  1679. var prescribingNumberUnit string
  1680. var adviceId int64
  1681. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1682. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1683. }
  1684. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1685. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1686. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1687. }
  1688. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1689. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1690. }
  1691. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1692. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1693. }
  1694. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1695. if drug.ID == 0 {
  1696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1697. return
  1698. }
  1699. //查询药品的所有库存
  1700. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1701. var total_count int64
  1702. for _, it := range list {
  1703. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1704. }
  1705. totals := strconv.FormatInt(total_count, 10)
  1706. //查询该药品是否存在开药记录
  1707. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1708. //查询最新批次库存
  1709. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1710. var batch_number_count int64
  1711. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1712. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1713. //新增处方
  1714. if advicelist.ID == 0 {
  1715. all_count, _ := strconv.ParseFloat(totals, 64)
  1716. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1717. if prescribingNumberUnit == drug.MinUnit {
  1718. if drug.IsUse != 1 {
  1719. if prescribing_number > all_count {
  1720. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1721. return
  1722. }
  1723. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1724. if prescribing_number > batch_number_all_count {
  1725. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1726. return
  1727. }
  1728. }
  1729. }
  1730. }
  1731. if prescribingNumberUnit == drug.MaxUnit {
  1732. num := prescribing_number * float64(drug.MinNumber)
  1733. if drug.IsUse != 1 {
  1734. if num > all_count {
  1735. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1736. return
  1737. }
  1738. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1739. if num > batch_number_all_count {
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1741. return
  1742. }
  1743. }
  1744. }
  1745. }
  1746. }
  1747. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1748. if drugOutConfig.IsOpen != 1 {
  1749. //修改处方
  1750. for _, advice := range advices {
  1751. var drug_id int64
  1752. var prescribing_number float64
  1753. var prescribingNumberUnit string
  1754. var prescribingNumber string
  1755. var adviceId int64
  1756. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1757. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1758. }
  1759. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1760. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1761. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1762. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1765. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1768. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1769. }
  1770. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1771. if drug.ID == 0 {
  1772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1773. return
  1774. }
  1775. //查询药品的所有库存
  1776. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1777. var total_count int64
  1778. for _, it := range list {
  1779. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1780. }
  1781. totals := strconv.FormatInt(total_count, 10)
  1782. //查询该药品是否存在开药记录
  1783. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1784. //新增处方
  1785. if advicelist.ID == 0 {
  1786. //查询最新批次库存
  1787. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1788. var batch_number_count int64
  1789. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1790. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1791. all_count, _ := strconv.ParseFloat(totals, 64)
  1792. if prescribingNumberUnit == drug.MinUnit {
  1793. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1794. if drug.IsUse != 1 {
  1795. if prescribing_number > all_count {
  1796. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1797. return
  1798. }
  1799. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1800. if prescribing_number > batch_number_all_count {
  1801. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1802. return
  1803. }
  1804. }
  1805. }
  1806. } else {
  1807. if prescribingNumberUnit == drug.MaxUnit {
  1808. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1809. num := prescribing_number * float64(drug.MinNumber)
  1810. if drug.IsUse != 1 {
  1811. if num > all_count {
  1812. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1813. return
  1814. }
  1815. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1816. if prescribing_number > batch_number_all_count {
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1818. return
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. //修改处方
  1826. if advicelist.ID > 0 {
  1827. //查询最新批次库存
  1828. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1829. var batch_number_count int64
  1830. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1831. var device_number int64
  1832. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1833. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1834. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1835. device_number = prescribingNumberInt * drug.MinNumber
  1836. }
  1837. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1838. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1839. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1840. device_number = prescribingNumberInt
  1841. }
  1842. var number_count int64
  1843. if prescribingNumberUnit == drug.MaxUnit {
  1844. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1845. number_count = prescribingNumberInt * drug.MinNumber
  1846. }
  1847. if prescribingNumberUnit == drug.MinUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt
  1850. }
  1851. //如果修改的数量大于之前修改的数量
  1852. if (number_count - device_number) > 0 {
  1853. //如果修改的差数量 大于库存数量
  1854. if drug.IsUse != 1 {
  1855. if (number_count - device_number) > total_count {
  1856. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1857. return
  1858. }
  1859. if (number_count - device_number) > batch_number_count {
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1861. return
  1862. }
  1863. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1864. // 查询该药品最后一次出库记录
  1865. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1866. var out_count int64
  1867. var in_count int64
  1868. var stock_max_number int64
  1869. var stock_min_number int64
  1870. for _, it := range outInfo {
  1871. if it.CountUnit == drug.MaxUnit {
  1872. it.Count = it.Count * drug.MinNumber
  1873. }
  1874. out_count += it.Count
  1875. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1876. stock_max_number = warehouseInfoList.StockMaxNumber
  1877. stock_min_number = warehouseInfoList.StockMinNumber
  1878. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1879. }
  1880. if out_count > 0 {
  1881. if (number_count - device_number) > in_count {
  1882. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1883. return
  1884. }
  1885. }
  1886. // 未出库
  1887. if out_count == 0 {
  1888. var sum_in_count int64
  1889. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1890. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1891. fmt.Println("sum_in_count", sum_in_count)
  1892. //如果修改的数量大于有库存的第一个批次
  1893. if number_count > sum_in_count {
  1894. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1895. return
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1902. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1903. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1904. if pharmacyConfig.IsOpen != 1 {
  1905. if device_number != number_count {
  1906. // 查询该药品最后一次出库记录
  1907. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1908. //回退库存
  1909. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1910. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1911. }
  1912. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1913. var stock_max_number int64
  1914. var stock_min_number int64
  1915. if number_count >= drug.MinNumber {
  1916. stock_max_number = device_number / drug.MinNumber
  1917. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1918. stock_min_number = device_number % drug.MinNumber
  1919. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1920. } else {
  1921. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1922. }
  1923. }
  1924. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1925. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1926. }
  1927. //删除记录
  1928. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1929. //查询默认仓库剩余多少库存
  1930. var sum_count int64
  1931. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1932. for _, its := range stockInfo {
  1933. if its.MaxUnit == drug.MaxUnit {
  1934. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1935. }
  1936. sum_count += its.StockMaxNumber + its.StockMinNumber
  1937. }
  1938. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. //保存处方开药
  1945. if drugOutConfig.IsOpen == 1 {
  1946. //修改处方
  1947. for _, advice := range advices {
  1948. var drug_id int64
  1949. var prescribing_number float64
  1950. var prescribingNumberUnit string
  1951. var prescribingNumber string
  1952. var adviceId int64
  1953. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1954. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1955. }
  1956. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1957. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1958. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1959. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1960. }
  1961. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1962. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1963. }
  1964. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1965. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1966. }
  1967. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1968. if drug.ID == 0 {
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. //查询药品的所有库存
  1973. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1974. var total_count int64
  1975. for _, it := range list {
  1976. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1977. }
  1978. totals := strconv.FormatInt(total_count, 10)
  1979. //查询该药品是否存在开药记录
  1980. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1981. //新增处方
  1982. if advicelist.ID == 0 {
  1983. //查询最新批次库存
  1984. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1985. var batch_number_count int64
  1986. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1987. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1988. all_count, _ := strconv.ParseFloat(totals, 64)
  1989. if prescribingNumberUnit == drug.MinUnit {
  1990. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1991. if drug.IsUse != 1 {
  1992. if prescribing_number > all_count {
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1994. return
  1995. }
  1996. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1997. if prescribing_number > batch_number_all_count {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1999. return
  2000. }
  2001. }
  2002. }
  2003. } else {
  2004. if prescribingNumberUnit == drug.MaxUnit {
  2005. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2006. num := prescribing_number * float64(drug.MinNumber)
  2007. if drug.IsUse != 1 {
  2008. if num > all_count {
  2009. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2010. return
  2011. }
  2012. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2013. if prescribing_number > batch_number_all_count {
  2014. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2015. return
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. //修改处方
  2023. if advicelist.ID > 0 {
  2024. //查询最新批次库存
  2025. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2026. var batch_number_count int64
  2027. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2028. var device_number int64
  2029. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2030. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2031. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2032. device_number = prescribingNumberInt * drug.MinNumber
  2033. }
  2034. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2035. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2036. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2037. device_number = prescribingNumberInt
  2038. }
  2039. var number_count int64
  2040. if prescribingNumberUnit == drug.MaxUnit {
  2041. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2042. number_count = prescribingNumberInt * drug.MinNumber
  2043. }
  2044. if prescribingNumberUnit == drug.MinUnit {
  2045. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2046. number_count = prescribingNumberInt
  2047. }
  2048. //如果修改的数量大于之前修改的数量
  2049. if (number_count - device_number) > 0 {
  2050. //如果修改的差数量 大于库存数量
  2051. if drug.IsUse != 1 {
  2052. if (number_count - device_number) > total_count {
  2053. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2054. return
  2055. }
  2056. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2057. if (number_count - device_number) > batch_number_count {
  2058. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2059. return
  2060. }
  2061. }
  2062. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2063. //查询历史出库数据总批次
  2064. // 查询该药品最后一次出库记录
  2065. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2066. var out_count int64
  2067. var in_count int64
  2068. var stock_max_number int64
  2069. var stock_min_number int64
  2070. for _, it := range outInfo {
  2071. if it.CountUnit == drug.MaxUnit {
  2072. it.Count = it.Count * drug.MinNumber
  2073. }
  2074. out_count += it.Count
  2075. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2076. stock_max_number = warehouseInfoList.StockMaxNumber
  2077. stock_min_number = warehouseInfoList.StockMinNumber
  2078. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2079. }
  2080. if out_count > 0 {
  2081. if (number_count - device_number) > in_count {
  2082. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2083. return
  2084. }
  2085. }
  2086. // 未出库
  2087. if out_count == 0 {
  2088. var sum_in_count int64
  2089. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2090. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2091. //如果修改的数量大于有库存的第一个批次
  2092. if number_count > sum_in_count {
  2093. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2094. return
  2095. }
  2096. }
  2097. }
  2098. }
  2099. }
  2100. }
  2101. }
  2102. }
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. }
  2109. }
  2110. //校验耗材库存
  2111. if goodOutConfig.IsOpen == 1 {
  2112. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2113. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2114. if len(prescriptions) > 0 {
  2115. for _, item := range prescriptions {
  2116. items := item.(map[string]interface{})
  2117. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2118. projects := items["project"].([]interface{})
  2119. if len(projects) > 0 {
  2120. for _, project := range projects {
  2121. var project_id int64
  2122. var project_type int64
  2123. var totals float64
  2124. var project_name string
  2125. var parsetotal int64
  2126. var id int64
  2127. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2128. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2129. }
  2130. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2131. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2132. }
  2133. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2134. total, _ := project.(map[string]interface{})["total"].(string)
  2135. totals, _ = strconv.ParseFloat(total, 64)
  2136. }
  2137. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2138. project_name = project.(map[string]interface{})["project_name"].(string)
  2139. }
  2140. if project_type == 3 {
  2141. //查找该耗材的出库记录
  2142. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2143. if len(goodWarehouseInfo) == 0 {
  2144. //查询耗材库存
  2145. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2146. var stock_count int64
  2147. for _, it := range list {
  2148. stock_count += it.StockCount
  2149. }
  2150. stock_counts := strconv.FormatInt(stock_count, 10)
  2151. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2152. if totals > stock_total_count {
  2153. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2154. return
  2155. }
  2156. }
  2157. if len(goodWarehouseInfo) > 0 {
  2158. //查询该患者耗材的历史数据
  2159. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2160. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2161. //数量发生改变
  2162. if parsetotal != count {
  2163. //如果现在的数量大于历史数量,就要看库存是否足够
  2164. if parsetotal > count {
  2165. //查询耗材所有库存
  2166. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2167. var stock_count int64
  2168. for _, it := range list {
  2169. stock_count += it.StockCount
  2170. }
  2171. //库存不足
  2172. if (parsetotal - count) > stock_count {
  2173. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2174. return
  2175. }
  2176. }
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. //不使用耗材保存处方出库
  2188. if goodOutConfig.IsOpen != 1 {
  2189. if stockConfig.IsOpen == 1 {
  2190. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2191. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2192. if len(prescriptions) > 0 {
  2193. for _, item := range prescriptions {
  2194. items := item.(map[string]interface{})
  2195. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2196. projects := items["project"].([]interface{})
  2197. if len(projects) > 0 {
  2198. for _, project := range projects {
  2199. var project_id int64
  2200. var project_type int64
  2201. var totals float64
  2202. var project_name string
  2203. var parsetotal int64
  2204. var id int64
  2205. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2206. id = int64(project.(map[string]interface{})["id"].(float64))
  2207. }
  2208. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2209. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2210. }
  2211. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2212. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2213. }
  2214. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2215. total, _ := project.(map[string]interface{})["total"].(string)
  2216. totals, _ = strconv.ParseFloat(total, 64)
  2217. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2218. }
  2219. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2220. project_name = project.(map[string]interface{})["project_name"].(string)
  2221. }
  2222. if project_type == 3 {
  2223. //查找该耗材的出库记录
  2224. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2225. //没有出库记录
  2226. if len(goodWarehouseInfo) == 0 {
  2227. //查询耗材库存
  2228. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2229. var stock_count int64
  2230. for _, it := range list {
  2231. stock_count += it.StockCount
  2232. }
  2233. stock_counts := strconv.FormatInt(stock_count, 10)
  2234. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2235. if totals > stock_total_count {
  2236. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2237. return
  2238. }
  2239. //查找今日该患者已经出库的所有耗材
  2240. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2241. for _, item := range goodList {
  2242. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2243. var flush_count int64
  2244. for _, it := range goodListSix {
  2245. flush_count += it.StockCount
  2246. }
  2247. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2248. creater := adminInfo.AdminUser.Id
  2249. if errs != nil {
  2250. goodErrcode := models.XtGoodErrcode{
  2251. UserOrgId: item.OrgId,
  2252. Errcode: "手动出库更新剩余出库失败",
  2253. GoodId: item.GoodId,
  2254. Status: 1,
  2255. Ctime: time.Now().Unix(),
  2256. Mtime: 0,
  2257. Count: 0,
  2258. StockCount: 0,
  2259. Creater: creater,
  2260. BatchNumberId: 0,
  2261. WarehouseOutId: 0,
  2262. }
  2263. service.CreateGoodErrcode(goodErrcode)
  2264. }
  2265. }
  2266. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2267. }
  2268. //有出库记录
  2269. if len(goodWarehouseInfo) > 0 {
  2270. //查询该患者耗材的历史数据
  2271. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2272. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2273. //数量发生改变
  2274. if parsetotal != count {
  2275. //查找今日该患者已经出库的所有耗材
  2276. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2277. for _, item := range goodList {
  2278. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2279. var flush_count int64
  2280. for _, it := range goodListSix {
  2281. flush_count += it.StockCount
  2282. }
  2283. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2284. //减少出库数量
  2285. creater := adminInfo.AdminUser.Id
  2286. if errs != nil {
  2287. goodErrcode := models.XtGoodErrcode{
  2288. UserOrgId: item.OrgId,
  2289. Errcode: "手动出库更新剩余出库失败",
  2290. GoodId: item.GoodId,
  2291. Status: 1,
  2292. Ctime: time.Now().Unix(),
  2293. Mtime: 0,
  2294. Count: 0,
  2295. StockCount: 0,
  2296. Creater: creater,
  2297. BatchNumberId: 0,
  2298. WarehouseOutId: 0,
  2299. }
  2300. service.CreateGoodErrcode(goodErrcode)
  2301. }
  2302. //查询默认仓库
  2303. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2304. var total_count int64
  2305. for _, it := range stockList {
  2306. total_count += it.StockCount
  2307. }
  2308. //基础库插入数据
  2309. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2310. }
  2311. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. }
  2322. }
  2323. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2324. var hpInfo models.HisPrescriptionInfo
  2325. if info.ID == 0 {
  2326. var randNum int
  2327. randNum = rand.Intn(10000) + 1000
  2328. timestamp := time.Now().Unix()
  2329. tempTime := time.Unix(timestamp, 0)
  2330. timeFormat := tempTime.Format("20060102150405")
  2331. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2332. hpInfo = models.HisPrescriptionInfo{
  2333. HisPatientId: his_patient_id,
  2334. UserOrgId: adminInfo.CurrentOrgId,
  2335. RecordDate: theTime.Unix(),
  2336. PatientId: patient_id,
  2337. Status: 1,
  2338. Ctime: time.Now().Unix(),
  2339. Mtime: time.Now().Unix(),
  2340. Creator: adminInfo.AdminUser.Id,
  2341. Modifier: adminInfo.AdminUser.Id,
  2342. Diagnosis: diagnose,
  2343. SickHistory: sick_history,
  2344. Departments: department,
  2345. RegisterType: reg_type,
  2346. PrescriptionNumber: p_number,
  2347. PrescriptionStatus: 1,
  2348. Doctor: role.UserName,
  2349. DoctorId: doctor_id,
  2350. SickType: sick_type,
  2351. PType: p_type,
  2352. PatientDiagnosis: patient_diagnose,
  2353. }
  2354. service.SavePatientPrescriptionInfo(hpInfo)
  2355. //创建步骤表
  2356. finish := models.XtDialysisFinish{
  2357. IsFinish: 1,
  2358. UserOrgId: adminInfo.CurrentOrgId,
  2359. Status: 1,
  2360. Ctime: time.Now().Unix(),
  2361. Mtime: 0,
  2362. Module: 4,
  2363. RecordDate: theTime.Unix(),
  2364. Sourse: 1,
  2365. PatientId: patient_id,
  2366. }
  2367. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2368. if dialysisFinish.ID == 0 {
  2369. service.CreateDialysisFinish(finish)
  2370. }
  2371. redis := service.RedisClient()
  2372. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2373. redis.Set(key, "", time.Second)
  2374. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2375. redis.Set(keyOne, "", time.Second)
  2376. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2377. redis.Set(keySeven, "", time.Second)
  2378. defer redis.Close()
  2379. } else {
  2380. hpInfo = models.HisPrescriptionInfo{
  2381. ID: info.ID,
  2382. UserOrgId: adminInfo.CurrentOrgId,
  2383. RecordDate: info.RecordDate,
  2384. PatientId: info.PatientId,
  2385. Status: 1,
  2386. Ctime: info.Ctime,
  2387. Mtime: time.Now().Unix(),
  2388. Creator: info.Creator,
  2389. Modifier: adminInfo.AdminUser.Id,
  2390. Diagnosis: diagnose,
  2391. SickHistory: sick_history,
  2392. Departments: department,
  2393. RegisterType: reg_type,
  2394. PrescriptionNumber: info.PrescriptionNumber,
  2395. Doctor: role.UserName,
  2396. PrescriptionStatus: info.PrescriptionStatus,
  2397. DoctorId: doctor_id,
  2398. SickType: sick_type,
  2399. PType: info.PType,
  2400. HisPatientId: info.HisPatientId,
  2401. PatientDiagnosis: patient_diagnose,
  2402. }
  2403. service.SavePatientPrescriptionInfo(hpInfo)
  2404. //创建步骤表
  2405. finish := models.XtDialysisFinish{
  2406. IsFinish: 1,
  2407. UserOrgId: adminInfo.CurrentOrgId,
  2408. Status: 1,
  2409. Ctime: time.Now().Unix(),
  2410. Mtime: 0,
  2411. Module: 4,
  2412. RecordDate: info.RecordDate,
  2413. Sourse: 1,
  2414. PatientId: info.PatientId,
  2415. }
  2416. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2417. if dialysisFinish.ID == 0 {
  2418. service.CreateDialysisFinish(finish)
  2419. }
  2420. redis := service.RedisClient()
  2421. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2422. redis.Set(key, "", time.Second)
  2423. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2424. redis.Set(keyOne, "", time.Second)
  2425. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2426. redis.Set(keySeven, "", time.Second)
  2427. defer redis.Close()
  2428. }
  2429. //定义切片
  2430. var adviceList []models.HisDoctorAdviceInfo
  2431. var projectList []models.HisPrescriptionProject
  2432. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2433. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2434. var tempPrescription *models.HisPrescription
  2435. if len(prescriptions) > 0 {
  2436. for _, item := range prescriptions {
  2437. items := item.(map[string]interface{})
  2438. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2439. utils.ErrorLog("id")
  2440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2441. return
  2442. }
  2443. id := int64(items["id"].(float64))
  2444. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2445. tempPrescription = &new_prescription
  2446. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2447. utils.ErrorLog("type")
  2448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2449. return
  2450. }
  2451. types := int64(items["type"].(float64))
  2452. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2453. utils.ErrorLog("med_type")
  2454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2455. return
  2456. }
  2457. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2458. if med_type == "0" {
  2459. med_type = "14"
  2460. }
  2461. //if order_status == 0 {
  2462. // order_status = 1
  2463. //}
  2464. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2465. utils.ErrorLog("pre_time")
  2466. }
  2467. preTime, _ := items["pre_time"].(string)
  2468. timeLayout := "2006-01-02"
  2469. loc, _ := time.LoadLocation("Local")
  2470. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2471. if err != nil {
  2472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2473. return
  2474. }
  2475. pTime := theTime2.Unix()
  2476. ctime := time.Now().Unix()
  2477. if tempPrescription.ID == 0 {
  2478. prescription := &models.HisPrescription{
  2479. ID: 0,
  2480. PatientId: patient_id,
  2481. UserOrgId: adminInfo.CurrentOrgId,
  2482. RecordDate: recordDateTime,
  2483. Ctime: ctime,
  2484. Mtime: ctime,
  2485. Type: types,
  2486. Modifier: adminInfo.AdminUser.Id,
  2487. Creator: adminInfo.AdminUser.Id,
  2488. Status: 1,
  2489. Doctor: role.UserName,
  2490. HisPatientId: his_patient_id,
  2491. OrderStatus: 1,
  2492. BatchNumber: "",
  2493. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2494. PreTime: pTime,
  2495. PType: p_type,
  2496. MedType: med_type,
  2497. }
  2498. tempPrescription = prescription
  2499. service.SaveHisPrescription(tempPrescription)
  2500. redis := service.RedisClient()
  2501. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2502. redis.Set(key, "", time.Second)
  2503. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2504. redis.Set(keyOne, "", time.Second)
  2505. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2506. redis.Set(keySeven, "", time.Second)
  2507. defer redis.Close()
  2508. } else {
  2509. tempPrescription.ID = id
  2510. tempPrescription.Type = types
  2511. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2512. tempPrescription.Mtime = time.Now().Unix()
  2513. tempPrescription.Doctor = role.UserName
  2514. //tempPrescription.OrderStatus = order_status
  2515. tempPrescription.PreTime = pTime
  2516. tempPrescription.MedType = med_type
  2517. service.SaveHisPrescription(tempPrescription)
  2518. redis := service.RedisClient()
  2519. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2520. redis.Set(key, "", time.Second)
  2521. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2522. redis.Set(keyOne, "", time.Second)
  2523. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2524. redis.Set(keySeven, "", time.Second)
  2525. defer redis.Close()
  2526. }
  2527. //service.SaveHisPrescription(prescription)
  2528. //更改患者挂号状态
  2529. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2530. fmt.Println("更改失败", err2)
  2531. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2532. advices := items["advices"].([]interface{})
  2533. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2534. groupNo := int64(0)
  2535. ctime := time.Now().Unix()
  2536. mtime := ctime
  2537. if len(advices) > 0 {
  2538. for _, advice := range advices {
  2539. var s models.HisDoctorAdviceInfo
  2540. s.PrescriptionId = tempPrescription.ID
  2541. s.AdviceType = 2
  2542. s.AdviceDoctor = doctor_id
  2543. s.StopState = 2
  2544. s.ExecutionState = 2
  2545. s.AdviceDate = recordDateTime
  2546. s.Status = 1
  2547. s.UserOrgId = adminInfo.CurrentOrgId
  2548. s.RecordDate = recordDateTime
  2549. s.StartTime = tempPrescription.PreTime
  2550. s.Groupno = groupNo
  2551. s.CreatedTime = ctime
  2552. s.UpdatedTime = mtime
  2553. s.PatientId = patient_id
  2554. s.HisPatientId = his_patient_id
  2555. s.StartTime = pTime
  2556. s.IsSettle = 2
  2557. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2558. if errcode > 0 {
  2559. c.ServeFailJSONWithSGJErrorCode(errcode)
  2560. return
  2561. }
  2562. s.StartTime = pTime
  2563. var total_count int64 //处方总库存
  2564. //查询改药品信息
  2565. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2566. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2567. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2568. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2569. total_count += prescribingNumberSeven * medical.MinNumber
  2570. }
  2571. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2572. total_count += prescribingNumberSeven
  2573. }
  2574. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2575. total_count += prescribingNumberSeven
  2576. }
  2577. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2578. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2579. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2580. if s.Price != lastWarehouse.RetailPrice {
  2581. s.Price = lastWarehouse.RetailPrice
  2582. }
  2583. }
  2584. service.CreateHisDoctorAdvice(&s)
  2585. //存储切片中
  2586. adviceList = append(adviceList, s)
  2587. redis := service.RedisClient()
  2588. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2589. redis.Set(key, "", time.Second)
  2590. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2591. redis.Set(keyOne, "", time.Second)
  2592. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2593. redis.Set(keySeven, "", time.Second)
  2594. var randNum int
  2595. randNum = rand.Intn(10000) + 1000
  2596. timestamp := time.Now().Unix()
  2597. tempTime := time.Unix(timestamp, 0)
  2598. timeFormat := tempTime.Format("20060102150405")
  2599. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2600. service.CreateHisDoctorAdvice(&s)
  2601. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2602. redis.Set(keySix, "", time.Second)
  2603. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2604. redis.Set(keyFive, "", time.Second)
  2605. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2606. redis.Set(keyEight, "", time.Second)
  2607. defer redis.Close()
  2608. }
  2609. }
  2610. }
  2611. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2612. projects := items["project"].([]interface{})
  2613. if len(projects) > 0 {
  2614. for _, project := range projects {
  2615. var p models.HisPrescriptionProject
  2616. p.PrescriptionId = tempPrescription.ID
  2617. p.Ctime = time.Now().Unix()
  2618. p.Mtime = time.Now().Unix()
  2619. p.PatientId = patient_id
  2620. p.RecordDate = recordDateTime
  2621. p.Doctor = doctor_id
  2622. p.UserOrgId = adminInfo.CurrentOrgId
  2623. p.HisPatientId = his_patient_id
  2624. p.Status = 1
  2625. p.StartTime = pTime
  2626. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2627. if errcode > 0 {
  2628. c.ServeFailJSONWithSGJErrorCode(errcode)
  2629. return
  2630. }
  2631. if p.ID == 0 {
  2632. p.IsOut = 2
  2633. }
  2634. if p.ID > 0 {
  2635. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2636. p.IsOut = projectDetail.IsOut
  2637. }
  2638. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2639. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2640. if p.Type == 3 {
  2641. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2642. if p.Price != lastWarehouse.PackingPrice {
  2643. p.Price = lastWarehouse.PackingPrice
  2644. }
  2645. }
  2646. }
  2647. service.CreateHisProjectTwo(&p)
  2648. projectList = append(projectList, p)
  2649. var randNum int
  2650. randNum = rand.Intn(10000) + 1000
  2651. timestamp := time.Now().Unix()
  2652. tempTime := time.Unix(timestamp, 0)
  2653. timeFormat := tempTime.Format("20060102150405")
  2654. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2655. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2656. //新增或者编辑项目,修改对应的标签数据
  2657. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2658. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2659. var label models.HisLabelPrintInfo
  2660. project, _ := service.GetProjectDetail(p.ProjectId)
  2661. if project.CostClassify == 3 { //类别为检验检查
  2662. if p.TeamId > 0 { //检验检查组套
  2663. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2664. if tempLabel.ID == 0 {
  2665. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2666. label.Number = tempPrescription.PrescriptionNumber
  2667. label.ProjectId = project.ID
  2668. label.Status = 1
  2669. label.IsPrint = 2
  2670. label.DoctorId = info.DoctorId
  2671. label.UserOrgId = p.UserOrgId
  2672. label.PatientId = patient_id
  2673. label.RecordDate = recordDateTime
  2674. label.Ctime = time.Now().Unix()
  2675. label.Mtime = time.Now().Unix()
  2676. label.ItemId = p.TeamId
  2677. label.FeedetlSn = p.FeedetlSn
  2678. label.PProjectId = p.ID
  2679. label.ProjectName = team.ProjectTeam
  2680. label.PatientName = patient.Name
  2681. service.CreateHisLabelRecord(&label)
  2682. }
  2683. } else { //单条检验检查项目
  2684. label.Number = tempPrescription.PrescriptionNumber
  2685. label.ProjectId = project.ID
  2686. label.Status = 1
  2687. label.DoctorId = info.DoctorId
  2688. label.UserOrgId = p.UserOrgId
  2689. label.PatientId = patient_id
  2690. label.RecordDate = recordDateTime
  2691. label.IsPrint = 2
  2692. label.Ctime = time.Now().Unix()
  2693. label.Mtime = time.Now().Unix()
  2694. label.FeedetlSn = p.FeedetlSn
  2695. label.PProjectId = p.ID
  2696. label.ItemId = p.TeamId
  2697. label.ProjectName = project.ProjectName
  2698. label.PatientName = patient.Name
  2699. service.CreateHisLabelRecord(&label)
  2700. }
  2701. }
  2702. }
  2703. }
  2704. service.SaveHisProjectTwo(&p)
  2705. }
  2706. }
  2707. }
  2708. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2709. // addition := items["addition"].([]interface{})
  2710. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2711. // ctime := time.Now().Unix()
  2712. // mtime := ctime
  2713. // if len(addition) > 0 {
  2714. // for _, item := range addition {
  2715. // var s models.HisAdditionalCharge
  2716. // s.PrescriptionId = tempPrescription.ID
  2717. // s.Status = 1
  2718. // s.UserOrgId = adminInfo.CurrentOrgId
  2719. // s.RecordDate = recordDateTime
  2720. // s.CreatedTime = ctime
  2721. // s.UpdatedTime = mtime
  2722. // s.PatientId = patient_id
  2723. // s.HisPatientId = his_patient_id
  2724. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2725. // if errcode > 0 {
  2726. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2727. // return
  2728. // }
  2729. // service.CreateAdditionalCharge(&s)
  2730. // var randNum int
  2731. // randNum = rand.Intn(10000) + 1000
  2732. // timestamp := time.Now().Unix()
  2733. // tempTime := time.Unix(timestamp, 0)
  2734. // timeFormat := tempTime.Format("20060102150405")
  2735. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2736. // service.CreateAdditionalCharge(&s)
  2737. //
  2738. // }
  2739. // }
  2740. //}
  2741. }
  2742. }
  2743. //查询今日该患者开的药品处方
  2744. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2745. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2746. //药品出库
  2747. if drugOutConfig.IsOpen == 1 {
  2748. for _, item := range hisdoctorlist {
  2749. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2750. // 查询该药品最后一次出库记录
  2751. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2752. if len(druginfo) > 0 {
  2753. //回退库存
  2754. for _, it := range druginfo {
  2755. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2756. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2757. }
  2758. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2759. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2760. }
  2761. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2762. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2763. }
  2764. }
  2765. }
  2766. //删除记录
  2767. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2768. //查询最后一次数据
  2769. if drugOutConfig.IsOpen == 1 {
  2770. //出库
  2771. if drug.IsUse == 2 {
  2772. creater := adminInfo.AdminUser.Id
  2773. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2774. }
  2775. //更新字典里面的库存
  2776. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2777. var sum_count int64
  2778. for _, its := range stockInfo {
  2779. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2780. if its.MaxUnit == baseDrug.MaxUnit {
  2781. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2782. }
  2783. sum_count += its.StockMaxNumber + its.StockMinNumber
  2784. }
  2785. //更新基础库存
  2786. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2787. //剩余库存
  2788. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2789. }
  2790. }
  2791. }
  2792. //耗材保存处方出库
  2793. if goodOutConfig.IsOpen == 1 {
  2794. //查询今日耗材出库数量
  2795. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2796. for _, item := range hisgoodlist {
  2797. //查询历史出库数据
  2798. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2799. var out_count_five int64
  2800. for _, item := range flowGood {
  2801. out_count_five += item.Count
  2802. }
  2803. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2804. if out_count_five != parseIntCount {
  2805. //查询耗材最后一次出库记录
  2806. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2807. //查询默认出库仓库库存
  2808. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2809. if len(wareOut) > 0 {
  2810. for _, it := range wareOut {
  2811. //回退库存
  2812. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2813. //删除出库记录
  2814. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2815. }
  2816. }
  2817. timeStr := time.Now().Format("2006-01-02")
  2818. timeArr := strings.Split(timeStr, "-")
  2819. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2820. total = total + 1
  2821. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2822. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2823. number = number + total
  2824. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2825. operation_time := time.Now().Unix()
  2826. creater := c.GetAdminUserInfo().AdminUser.Id
  2827. recordDateStr := time.Now().Format("2006-01-02")
  2828. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2829. nowtime := recordDate.Unix()
  2830. warehouseOut := models.WarehouseOut{
  2831. WarehouseOutOrderNumber: warehousing_out_order,
  2832. OperationTime: operation_time,
  2833. OrgId: adminInfo.CurrentOrgId,
  2834. Creater: creater,
  2835. Ctime: time.Now().Unix(),
  2836. Status: 1,
  2837. WarehouseOutTime: nowtime,
  2838. Type: 1,
  2839. StorehouseId: storeConfig.StorehouseOutInfo,
  2840. IsCheck: 1,
  2841. IsSys: 1,
  2842. }
  2843. //查询是否生成出库单
  2844. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2845. if out.ID == 0 {
  2846. service.AddSigleWarehouseOut(&warehouseOut)
  2847. }
  2848. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2849. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2850. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2851. dialyPrepareOne := models.DialysisBeforePrepare{
  2852. GoodTypeId: goodObj.GoodTypeId,
  2853. GoodId: item.ProjectId,
  2854. PatientId: item.PatientId,
  2855. RecordDate: item.RecordDate,
  2856. UserOrgId: adminInfo.CurrentOrgId,
  2857. Count: parseIntCount,
  2858. Ctime: time.Now().Unix(),
  2859. Creater: creater,
  2860. Status: 1,
  2861. StorehouseId: houseConfig.StorehouseOutInfo,
  2862. ProjectId: item.ID,
  2863. }
  2864. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2865. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2866. //查询历史出库数据
  2867. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2868. var out_count int64
  2869. for _, item := range flowGood {
  2870. out_count += item.Count
  2871. }
  2872. //如果历史数和当前数据不想等才进行退库出库
  2873. if out_count != parseIntCount {
  2874. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2875. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2876. detail := models.AutomaticReduceDetail{
  2877. WarehouseOutId: 0,
  2878. WarehouseOutOrderNumber: "",
  2879. PatientId: item.PatientId,
  2880. Ctime: time.Now().Unix(),
  2881. Mtime: 0,
  2882. Status: 1,
  2883. RecordTime: item.RecordDate,
  2884. OrgId: item.UserOrgId,
  2885. GoodId: item.ProjectId,
  2886. GoodTypeId: 0,
  2887. Count: parseIntCount,
  2888. Type: 0,
  2889. ProjectId: item.ID,
  2890. StorehouseId: 0,
  2891. }
  2892. service.CreateAutoDetail(detail)
  2893. //查询剩余库存
  2894. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2895. var sum_count int64
  2896. for _, item := range goodList {
  2897. sum_count += item.StockCount
  2898. }
  2899. //更新剩余库存
  2900. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2901. //耗材
  2902. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2903. }
  2904. }
  2905. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2906. //查询历史出库数据
  2907. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2908. var out_count int64
  2909. for _, item := range flowGood {
  2910. out_count += item.Count
  2911. }
  2912. //如果历史数和当前数据不想等才进行退库出库
  2913. if out_count != parseIntCount {
  2914. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2915. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2916. detail := models.AutomaticReduceDetail{
  2917. WarehouseOutId: 0,
  2918. WarehouseOutOrderNumber: "",
  2919. PatientId: item.PatientId,
  2920. Ctime: time.Now().Unix(),
  2921. Mtime: 0,
  2922. Status: 1,
  2923. RecordTime: item.RecordDate,
  2924. OrgId: item.UserOrgId,
  2925. GoodId: item.ProjectId,
  2926. GoodTypeId: 0,
  2927. Count: parseIntCount,
  2928. Type: 0,
  2929. ProjectId: item.ID,
  2930. StorehouseId: 0,
  2931. }
  2932. service.CreateAutoDetail(detail)
  2933. //查询剩余库存
  2934. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2935. var sum_count int64
  2936. for _, item := range goodList {
  2937. sum_count += item.StockCount
  2938. }
  2939. //更新剩余库存
  2940. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2941. //耗材
  2942. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2943. }
  2944. }
  2945. }
  2946. }
  2947. }
  2948. }
  2949. //redisClient := service.RedisClient()
  2950. //defer redisClient.Close()
  2951. //
  2952. //list := models.HisList{
  2953. // Patient_id: patient_id,
  2954. // Advice_id:0,
  2955. // Record_date: 0,
  2956. // Advice: adviceList,
  2957. // Project: nil,
  2958. //}
  2959. //hisLis = append(hisLis, list)
  2960. //
  2961. //advice_json, _ := json.Marshal(&hisLis)
  2962. //redisClient.RPush("111", advice_json).Result()
  2963. //result, _ := redisClient.RPop("111").Result()
  2964. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2965. //
  2966. //var dat []map[string]interface{}
  2967. //json.Unmarshal([]byte(result), &dat)
  2968. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2969. //
  2970. //for k,v:=range dat{
  2971. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2972. //}
  2973. //project_json, _ := json.Marshal(&projectList)
  2974. //redisClient.LPush("222", project_json).Result()
  2975. if err == nil {
  2976. c.ServeSuccessJSON(map[string]interface{}{
  2977. "msg": "保存成功",
  2978. })
  2979. return
  2980. } else {
  2981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2982. return
  2983. }
  2984. }
  2985. func (c *HisApiController) EditHisPrescription() {
  2986. record_date := c.GetString("record_date")
  2987. patient_id, _ := c.GetInt64("patient_id")
  2988. reg_type, _ := c.GetInt64("reg_type")
  2989. //diagnose, _ := c.GetInt64("diagnose", 0)
  2990. diagnose := c.GetString("diagnose")
  2991. sick_type, _ := c.GetInt64("sick_type")
  2992. sick_history := c.GetString("sick_history")
  2993. doctor_id, _ := c.GetInt64("doctor", 0)
  2994. department, _ := c.GetInt64("department", 0)
  2995. his_patient_id, _ := c.GetInt64("his_patient_id")
  2996. p_type, _ := c.GetInt64("p_type")
  2997. dataBody := make(map[string]interface{}, 0)
  2998. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2999. if err != nil {
  3000. utils.ErrorLog(err.Error())
  3001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3002. return
  3003. }
  3004. timeLayout := "2006-01-02"
  3005. loc, _ := time.LoadLocation("Local")
  3006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3007. if err != nil {
  3008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3009. return
  3010. }
  3011. adminInfo := c.GetAdminUserInfo()
  3012. recordDateTime := theTime.Unix()
  3013. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3014. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3015. var hpInfo models.HisPrescriptionInfo
  3016. if info.ID == 0 {
  3017. var randNum int
  3018. randNum = rand.Intn(10000) + 1000
  3019. timestamp := time.Now().Unix()
  3020. tempTime := time.Unix(timestamp, 0)
  3021. timeFormat := tempTime.Format("20060102150405")
  3022. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3023. hpInfo = models.HisPrescriptionInfo{
  3024. UserOrgId: adminInfo.CurrentOrgId,
  3025. RecordDate: theTime.Unix(),
  3026. PatientId: patient_id,
  3027. Status: 1,
  3028. Ctime: time.Now().Unix(),
  3029. Mtime: time.Now().Unix(),
  3030. Creator: adminInfo.AdminUser.Id,
  3031. Modifier: adminInfo.AdminUser.Id,
  3032. Diagnosis: diagnose,
  3033. SickHistory: sick_history,
  3034. Departments: department,
  3035. RegisterType: reg_type,
  3036. PrescriptionNumber: p_number,
  3037. PrescriptionStatus: 1,
  3038. Doctor: role.UserName,
  3039. DoctorId: doctor_id,
  3040. SickType: sick_type,
  3041. PType: p_type,
  3042. }
  3043. service.SavePatientPrescriptionInfo(hpInfo)
  3044. } else {
  3045. hpInfo = models.HisPrescriptionInfo{
  3046. ID: info.ID,
  3047. UserOrgId: adminInfo.CurrentOrgId,
  3048. RecordDate: info.RecordDate,
  3049. PatientId: info.PatientId,
  3050. Status: 1,
  3051. Ctime: info.Ctime,
  3052. Mtime: time.Now().Unix(),
  3053. Creator: info.Creator,
  3054. Modifier: adminInfo.AdminUser.Id,
  3055. Diagnosis: diagnose,
  3056. SickHistory: sick_history,
  3057. Departments: department,
  3058. RegisterType: reg_type,
  3059. PrescriptionNumber: info.PrescriptionNumber,
  3060. Doctor: role.UserName,
  3061. PrescriptionStatus: info.PrescriptionStatus,
  3062. DoctorId: doctor_id,
  3063. SickType: sick_type,
  3064. PType: info.PType,
  3065. }
  3066. service.SavePatientPrescriptionInfo(hpInfo)
  3067. }
  3068. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3069. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3070. if len(prescriptions) > 0 {
  3071. for _, item := range prescriptions {
  3072. items := item.(map[string]interface{})
  3073. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3074. utils.ErrorLog("id")
  3075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3076. return
  3077. }
  3078. id := int64(items["id"].(float64))
  3079. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3080. utils.ErrorLog("type")
  3081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3082. return
  3083. }
  3084. types := int64(items["type"].(float64))
  3085. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3086. utils.ErrorLog("med_type")
  3087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3088. return
  3089. }
  3090. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3091. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3092. ctime := time.Now().Unix()
  3093. prescription := &models.HisPrescription{
  3094. ID: id,
  3095. PatientId: patient_id,
  3096. UserOrgId: adminInfo.CurrentOrgId,
  3097. RecordDate: recordDateTime,
  3098. Ctime: ctime,
  3099. Mtime: ctime,
  3100. Type: types,
  3101. Modifier: adminInfo.AdminUser.Id,
  3102. Creator: adminInfo.AdminUser.Id,
  3103. Status: 1,
  3104. Doctor: role.UserName,
  3105. HisPatientId: his_patient_id,
  3106. OrderStatus: 1,
  3107. BatchNumber: "",
  3108. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3109. PType: hpInfo.PType,
  3110. MedType: med_type,
  3111. }
  3112. if historyPrescription.ID > 0 {
  3113. prescription.PreTime = historyPrescription.PreTime
  3114. }
  3115. service.SaveHisPrescription(prescription)
  3116. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3117. advices := items["advices"].([]interface{})
  3118. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3119. groupNo := int64(0)
  3120. ctime := time.Now().Unix()
  3121. mtime := ctime
  3122. if len(advices) > 0 {
  3123. for _, advice := range advices {
  3124. var s models.HisDoctorAdviceInfo
  3125. s.PrescriptionId = prescription.ID
  3126. s.AdviceType = 2
  3127. s.AdviceDoctor = adminInfo.AdminUser.Id
  3128. s.StopState = 2
  3129. s.ExecutionState = 2
  3130. s.AdviceDate = recordDateTime
  3131. s.Status = 1
  3132. s.UserOrgId = adminInfo.CurrentOrgId
  3133. s.RecordDate = recordDateTime
  3134. s.StartTime = prescription.PreTime
  3135. s.Groupno = groupNo
  3136. s.CreatedTime = ctime
  3137. s.UpdatedTime = mtime
  3138. s.PatientId = patient_id
  3139. s.HisPatientId = his_patient_id
  3140. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3141. if errcode > 0 {
  3142. c.ServeFailJSONWithSGJErrorCode(errcode)
  3143. return
  3144. }
  3145. service.CreateHisDoctorAdvice(&s)
  3146. redis := service.RedisClient()
  3147. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3148. redis.Set(key, "", time.Second)
  3149. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3150. fmt.Println("keyOne", keyOne)
  3151. redis.Set(keyOne, "", time.Second)
  3152. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3153. redis.Set(keySeven, "", time.Second)
  3154. redis.Close()
  3155. }
  3156. }
  3157. }
  3158. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3159. projects := items["project"].([]interface{})
  3160. if len(projects) > 0 {
  3161. for _, project := range projects {
  3162. var p models.HisPrescriptionProject
  3163. p.PrescriptionId = prescription.ID
  3164. p.Ctime = time.Now().Unix()
  3165. p.Mtime = time.Now().Unix()
  3166. p.PatientId = patient_id
  3167. p.RecordDate = recordDateTime
  3168. p.UserOrgId = adminInfo.CurrentOrgId
  3169. p.HisPatientId = his_patient_id
  3170. p.Status = 1
  3171. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3172. if errcode > 0 {
  3173. c.ServeFailJSONWithSGJErrorCode(errcode)
  3174. return
  3175. }
  3176. service.CreateHisProjectTwo(&p)
  3177. }
  3178. }
  3179. }
  3180. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3181. addition := items["addition"].([]interface{})
  3182. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3183. ctime := time.Now().Unix()
  3184. mtime := ctime
  3185. if len(addition) > 0 {
  3186. for _, item := range addition {
  3187. var s models.HisAdditionalCharge
  3188. s.PrescriptionId = prescription.ID
  3189. s.Status = 1
  3190. s.UserOrgId = adminInfo.CurrentOrgId
  3191. s.RecordDate = recordDateTime
  3192. s.CreatedTime = ctime
  3193. s.UpdatedTime = mtime
  3194. s.PatientId = patient_id
  3195. s.HisPatientId = his_patient_id
  3196. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3197. if errcode > 0 {
  3198. c.ServeFailJSONWithSGJErrorCode(errcode)
  3199. return
  3200. }
  3201. service.CreateAdditionalCharge(&s)
  3202. }
  3203. }
  3204. }
  3205. }
  3206. }
  3207. }
  3208. if err == nil {
  3209. c.ServeSuccessJSON(map[string]interface{}{
  3210. "msg": "保存成功",
  3211. })
  3212. return
  3213. } else {
  3214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3215. return
  3216. }
  3217. }
  3218. func (c *HisApiController) DeletePrescription() {
  3219. prescription_id, _ := c.GetInt64("id")
  3220. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3221. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3222. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3223. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3224. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3225. //耗材保存处方出库
  3226. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3227. //已收费和已发药限制逻辑
  3228. isCharge := false
  3229. isMedicine := false
  3230. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3231. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3232. for _, item := range new_prescriptions {
  3233. if item.IsMedicine == 1 {
  3234. isMedicine = true
  3235. }
  3236. }
  3237. for _, item := range new_prescriptions {
  3238. if item.OrderStatus == 4 {
  3239. isCharge = true
  3240. }
  3241. }
  3242. if p_err != nil {
  3243. if new_prescription.ID > 0 {
  3244. if new_prescription.OrderStatus == 2 {
  3245. isCharge = true
  3246. }
  3247. }
  3248. }
  3249. for _, item := range advices {
  3250. if item.IsMedicine == 1 {
  3251. isMedicine = true
  3252. }
  3253. }
  3254. if isCharge {
  3255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3256. return
  3257. }
  3258. if isMedicine {
  3259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3260. return
  3261. }
  3262. //已收费和已发药限制逻辑
  3263. if len(projects) > 0 {
  3264. for _, item := range projects {
  3265. service.DeletePrintInfo(item.ID) //删除打印信息
  3266. if goodOutConfig.IsOpen != 1 {
  3267. if stockConfig.IsOpen == 1 {
  3268. if item.Type == 3 && item.IsOut == 1 {
  3269. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3270. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3271. good.Total = good.Total + f_count
  3272. service.UpdateGoodInfo(&good)
  3273. operation_time := time.Now().Unix()
  3274. creater := c.GetAdminUserInfo().AdminUser.Id
  3275. //创建退库单
  3276. timeStr := time.Now().Format("2006-01-02")
  3277. timeArr := strings.Split(timeStr, "-")
  3278. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3279. total = total + 1
  3280. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3281. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3282. cancelStock := models.CancelStock{
  3283. OrderNumber: orderNumber,
  3284. OperaTime: operation_time,
  3285. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3286. Creater: creater,
  3287. Ctime: time.Now().Unix(),
  3288. Status: 1,
  3289. ReturnTime: item.RecordDate,
  3290. Type: 1,
  3291. StorehouseId: houseConfig.StorehouseOutInfo,
  3292. IsCheck: 1,
  3293. }
  3294. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3295. if msgerrkonde == gorm.ErrRecordNotFound {
  3296. service.AddSigleCancelStock(&cancelStock)
  3297. }
  3298. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3299. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3300. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3301. //查询该耗材是否出库
  3302. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3303. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3304. deaerler, _ := service.GetDealerById(info.Dealer)
  3305. var total_count int64
  3306. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3307. total_count += count
  3308. if info.ID > 0 {
  3309. if info.Count >= total_count {
  3310. //回退库存
  3311. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3312. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3313. var flush_count int64
  3314. for _, it := range goodList {
  3315. flush_count += it.StockCount
  3316. }
  3317. cancelStockInfo := models.CancelStockInfo{
  3318. GoodId: item.ProjectId,
  3319. CancelStockId: cancel.ID,
  3320. GoodTypeId: good.GoodTypeId,
  3321. Count: prescribingNumber,
  3322. Price: info.Price,
  3323. Total: 0,
  3324. ProductDate: info.ProductDate,
  3325. ExpiryDate: info.ExpiryDate,
  3326. Ctime: time.Now().Unix(),
  3327. Status: 1,
  3328. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3329. OrderNumber: cancel.OrderNumber,
  3330. Type: 0,
  3331. Dealer: deaerler.DealerName,
  3332. Manufacturer: manufacturer.ManufacturerName,
  3333. Number: info.Number,
  3334. RegisterAccount: "",
  3335. Remark: "",
  3336. WarehouseInfoId: info.WarehouseInfotId,
  3337. PatientId: info.PatientId,
  3338. RecordDate: info.SysRecordTime,
  3339. StorehouseId: houseConfig.StorehouseOutInfo,
  3340. IsCheck: 1,
  3341. }
  3342. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3343. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3344. flow := models.VmStockFlow{
  3345. WarehousingId: info.WarehouseInfotId,
  3346. GoodId: item.ProjectId,
  3347. Number: info.Number,
  3348. LicenseNumber: info.LicenseNumber,
  3349. Count: prescribingNumber,
  3350. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3351. PatientId: item.PatientId,
  3352. SystemTime: info.SysRecordTime,
  3353. ConsumableType: 7,
  3354. IsSys: 0,
  3355. WarehousingOrder: "",
  3356. WarehouseOutId: info.WarehouseOutId,
  3357. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3358. IsEdit: 0,
  3359. CancelStockId: cancel.ID,
  3360. CancelOrderNumber: cancel.OrderNumber,
  3361. Manufacturer: manufacturer.ID,
  3362. Dealer: 0,
  3363. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3364. UpdateCreator: 0,
  3365. Status: 1,
  3366. Ctime: time.Now().Unix(),
  3367. Mtime: 0,
  3368. Price: info.Price,
  3369. WarehousingDetailId: info.WarehouseInfotId,
  3370. WarehouseOutDetailId: info.ID,
  3371. CancelOutDetailId: cancelInfo.ID,
  3372. ProductDate: info.ProductDate,
  3373. ExpireDate: info.ExpiryDate,
  3374. StorehouseId: houseConfig.StorehouseOutInfo,
  3375. OverCount: flush_count,
  3376. }
  3377. service.CreateStockFlowOne(flow)
  3378. //退库数量增加
  3379. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3380. //出库数量减少
  3381. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3382. }
  3383. if info.Count < total_count {
  3384. //回退库存
  3385. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3386. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3387. var flush_count int64
  3388. for _, it := range goodList {
  3389. flush_count += it.StockCount
  3390. }
  3391. cancelStockInfo := models.CancelStockInfo{
  3392. GoodId: item.ProjectId,
  3393. CancelStockId: cancel.ID,
  3394. GoodTypeId: good.GoodTypeId,
  3395. Count: info.Count,
  3396. Price: info.Price,
  3397. Total: 0,
  3398. ProductDate: info.ProductDate,
  3399. ExpiryDate: info.ExpiryDate,
  3400. Ctime: time.Now().Unix(),
  3401. Status: 1,
  3402. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3403. OrderNumber: cancel.OrderNumber,
  3404. Type: 0,
  3405. Dealer: deaerler.DealerName,
  3406. Manufacturer: manufacturer.ManufacturerName,
  3407. Number: info.Number,
  3408. RegisterAccount: "",
  3409. Remark: "",
  3410. WarehouseInfoId: info.WarehouseInfotId,
  3411. PatientId: info.PatientId,
  3412. RecordDate: info.SysRecordTime,
  3413. StorehouseId: houseConfig.StorehouseOutInfo,
  3414. IsCheck: 1,
  3415. }
  3416. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3417. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3418. flow := models.VmStockFlow{
  3419. WarehousingId: info.WarehouseInfotId,
  3420. GoodId: item.ProjectId,
  3421. Number: info.Number,
  3422. LicenseNumber: info.LicenseNumber,
  3423. Count: info.Count,
  3424. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3425. PatientId: item.PatientId,
  3426. SystemTime: info.SysRecordTime,
  3427. ConsumableType: 7,
  3428. IsSys: 0,
  3429. WarehousingOrder: "",
  3430. WarehouseOutId: info.WarehouseOutId,
  3431. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3432. IsEdit: 0,
  3433. CancelStockId: cancel.ID,
  3434. CancelOrderNumber: cancel.OrderNumber,
  3435. Manufacturer: manufacturer.ID,
  3436. Dealer: 0,
  3437. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3438. UpdateCreator: 0,
  3439. Status: 1,
  3440. Ctime: time.Now().Unix(),
  3441. Mtime: 0,
  3442. Price: info.Price,
  3443. WarehousingDetailId: info.WarehouseInfotId,
  3444. WarehouseOutDetailId: info.ID,
  3445. CancelOutDetailId: cancelInfo.ID,
  3446. ProductDate: info.ProductDate,
  3447. ExpireDate: info.ExpiryDate,
  3448. StorehouseId: houseConfig.StorehouseOutInfo,
  3449. OverCount: flush_count,
  3450. }
  3451. service.CreateStockFlowOne(flow)
  3452. //退库数量增加
  3453. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3454. //出库数量减少
  3455. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3456. }
  3457. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3458. var flush_count int64
  3459. for _, it := range goodList {
  3460. flush_count += it.StockCount
  3461. }
  3462. //查询已出库数量
  3463. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3464. if prescribingNumber < dialysisInfo.Count {
  3465. //改变数量
  3466. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3467. }
  3468. if prescribingNumber >= dialysisInfo.Count {
  3469. //删除出库表
  3470. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3471. }
  3472. //更新库存
  3473. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3474. //更新基础库库存
  3475. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3476. }
  3477. }
  3478. }
  3479. }
  3480. //保存耗材出库
  3481. if goodOutConfig.IsOpen == 1 {
  3482. if item.Type == 3 {
  3483. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3484. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3485. good.Total = good.Total + f_count
  3486. service.UpdateGoodInfo(&good)
  3487. operation_time := time.Now().Unix()
  3488. creater := c.GetAdminUserInfo().AdminUser.Id
  3489. //创建退库单
  3490. timeStr := time.Now().Format("2006-01-02")
  3491. timeArr := strings.Split(timeStr, "-")
  3492. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3493. total = total + 1
  3494. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3495. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3496. cancelStock := models.CancelStock{
  3497. OrderNumber: orderNumber,
  3498. OperaTime: operation_time,
  3499. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3500. Creater: creater,
  3501. Ctime: time.Now().Unix(),
  3502. Status: 1,
  3503. ReturnTime: item.RecordDate,
  3504. Type: 1,
  3505. StorehouseId: houseConfig.StorehouseOutInfo,
  3506. IsCheck: 1,
  3507. }
  3508. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3509. if msgerrkonde == gorm.ErrRecordNotFound {
  3510. service.AddSigleCancelStock(&cancelStock)
  3511. }
  3512. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3513. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3514. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3515. //查询该耗材是否出库
  3516. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3517. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3518. deaerler, _ := service.GetDealerById(info.Dealer)
  3519. var total_count int64
  3520. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3521. total_count += count
  3522. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3523. var flush_count int64
  3524. for _, it := range goodList {
  3525. flush_count += it.StockCount
  3526. }
  3527. fmt.Println("历史出库数据", info.Count)
  3528. fmt.Println("出库数量", total_count)
  3529. if info.ID > 0 {
  3530. cancelStockInfo := models.CancelStockInfo{
  3531. GoodId: item.ProjectId,
  3532. CancelStockId: cancel.ID,
  3533. GoodTypeId: good.GoodTypeId,
  3534. Count: prescribingNumber,
  3535. Price: info.Price,
  3536. Total: 0,
  3537. ProductDate: info.ProductDate,
  3538. ExpiryDate: info.ExpiryDate,
  3539. Ctime: time.Now().Unix(),
  3540. Status: 1,
  3541. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3542. OrderNumber: cancel.OrderNumber,
  3543. Type: 0,
  3544. Dealer: deaerler.DealerName,
  3545. Manufacturer: manufacturer.ManufacturerName,
  3546. Number: info.Number,
  3547. RegisterAccount: "",
  3548. Remark: "",
  3549. WarehouseInfoId: info.WarehouseInfotId,
  3550. PatientId: info.PatientId,
  3551. RecordDate: info.SysRecordTime,
  3552. StorehouseId: houseConfig.StorehouseOutInfo,
  3553. IsCheck: 1,
  3554. }
  3555. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3556. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3557. //查询出库数量
  3558. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3559. //出库数据 大于 退库数量
  3560. if len(list) > 0 {
  3561. for _, it := range list {
  3562. //回退库存
  3563. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3564. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3565. var flush_count_one int64
  3566. for _, it := range goodList {
  3567. flush_count_one += it.StockCount
  3568. }
  3569. //查询该批次是否有退库数据
  3570. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3571. creater := c.GetAdminUserInfo().AdminUser.Id
  3572. flow := models.VmStockFlow{
  3573. WarehousingId: it.WarehouseInfotId,
  3574. GoodId: it.GoodId,
  3575. Number: it.Number,
  3576. LicenseNumber: it.LicenseNumber,
  3577. Count: it.Count,
  3578. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3579. PatientId: it.PatientId,
  3580. SystemTime: it.SysRecordTime,
  3581. ConsumableType: 7,
  3582. IsSys: 0,
  3583. WarehousingOrder: "",
  3584. WarehouseOutId: it.WarehouseOutId,
  3585. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3586. IsEdit: 0,
  3587. CancelStockId: cancel.ID,
  3588. CancelOrderNumber: cancel.OrderNumber,
  3589. Manufacturer: manufacturer.ID,
  3590. Dealer: 0,
  3591. Creator: creater,
  3592. UpdateCreator: 0,
  3593. Status: 1,
  3594. Ctime: time.Now().Unix(),
  3595. Mtime: 0,
  3596. Price: it.Price,
  3597. WarehousingDetailId: it.WarehouseInfotId,
  3598. WarehouseOutDetailId: it.ID,
  3599. CancelOutDetailId: cancelInfo.ID,
  3600. ProductDate: it.ProductDate,
  3601. ExpireDate: it.ExpiryDate,
  3602. StorehouseId: houseConfig.StorehouseOutInfo,
  3603. OverCount: flush_count_one,
  3604. }
  3605. service.CreateStockFlowOne(flow)
  3606. //if flow.ID > 0 {
  3607. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3608. //}
  3609. }
  3610. }
  3611. //flow := models.VmStockFlow{
  3612. // WarehousingId: info.WarehouseInfotId,
  3613. // GoodId: item.ProjectId,
  3614. // Number: info.Number,
  3615. // LicenseNumber: info.LicenseNumber,
  3616. // Count: prescribingNumber,
  3617. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3618. // PatientId: item.PatientId,
  3619. // SystemTime: info.SysRecordTime,
  3620. // ConsumableType: 7,
  3621. // IsSys: 0,
  3622. // WarehousingOrder: "",
  3623. // WarehouseOutId: info.WarehouseOutId,
  3624. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3625. // IsEdit: 0,
  3626. // CancelStockId: cancel.ID,
  3627. // CancelOrderNumber: cancel.OrderNumber,
  3628. // Manufacturer: manufacturer.ID,
  3629. // Dealer: 0,
  3630. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3631. // UpdateCreator: 0,
  3632. // Status: 1,
  3633. // Ctime: time.Now().Unix(),
  3634. // Mtime: 0,
  3635. // Price: info.Price,
  3636. // WarehousingDetailId: info.WarehouseInfotId,
  3637. // WarehouseOutDetailId: info.ID,
  3638. // CancelOutDetailId: cancelInfo.ID,
  3639. // ProductDate: info.ProductDate,
  3640. // ExpireDate: info.ExpiryDate,
  3641. // StorehouseId: houseConfig.StorehouseOutInfo,
  3642. // OverCount: flush_count,
  3643. //}
  3644. //service.CreateStockFlowOne(flow)
  3645. //退库数量增加
  3646. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3647. //出库数量减少
  3648. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3649. //查询已出库数量
  3650. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3651. if prescribingNumber < dialysisInfo.Count {
  3652. //改变数量
  3653. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3654. }
  3655. if prescribingNumber >= dialysisInfo.Count {
  3656. //删除出库表
  3657. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3658. }
  3659. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3660. var flush_count_one int64
  3661. for _, it := range goodList {
  3662. flush_count_one += it.StockCount
  3663. }
  3664. //更新库存
  3665. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3666. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3667. //更新基础库库存
  3668. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3669. }
  3670. }
  3671. }
  3672. }
  3673. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3674. fmt.Println(err)
  3675. }
  3676. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3677. fmt.Println(err)
  3678. if len(advices) > 0 {
  3679. for _, item := range advices {
  3680. redis := service.RedisClient()
  3681. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3682. redis.Set(keyFive, "", time.Second)
  3683. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3684. redis.Set(keyOne, "", time.Second)
  3685. redis.Close()
  3686. }
  3687. }
  3688. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3689. if len(advices) > 0 {
  3690. for _, item := range advices {
  3691. creater := c.GetAdminUserInfo().AdminUser.Id
  3692. service.DrugAutoAddCancelInfo(item, creater)
  3693. }
  3694. }
  3695. } else {
  3696. if drugOutConfig.IsOpen == 1 {
  3697. if len(advices) > 0 {
  3698. for _, item := range advices {
  3699. creater := c.GetAdminUserInfo().AdminUser.Id
  3700. service.DrugAutoAddCancelInfo(item, creater)
  3701. }
  3702. }
  3703. } else {
  3704. if len(advices) > 0 {
  3705. for _, item := range advices {
  3706. creater := c.GetAdminUserInfo().AdminUser.Id
  3707. service.DrugAutoAddCancelInfo(item, creater)
  3708. }
  3709. }
  3710. }
  3711. }
  3712. c.ServeSuccessJSON(map[string]interface{}{
  3713. "msg": "删除成功",
  3714. })
  3715. return
  3716. }
  3717. func (c *HisApiController) DeleteDoctorAdvice() {
  3718. id, _ := c.GetInt64("id")
  3719. advice, _ := service.GetHisDoctorAdvicesById(id)
  3720. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3721. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3722. //已收费和已发药的限制逻辑
  3723. isCharge := false
  3724. isMedicine := false
  3725. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3726. //获取今天该患者所有处方,判断是否发药或者收费
  3727. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3728. for _, item := range new_prescriptions {
  3729. if item.IsMedicine == 1 {
  3730. isMedicine = true
  3731. }
  3732. }
  3733. for _, item := range new_prescriptions {
  3734. if item.OrderStatus == 4 {
  3735. isCharge = true
  3736. }
  3737. }
  3738. if isMedicine {
  3739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3740. return
  3741. }
  3742. if isCharge {
  3743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3744. return
  3745. }
  3746. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3747. for _, item := range advices {
  3748. if item.IsMedicine == 1 {
  3749. isMedicine = true
  3750. }
  3751. }
  3752. if isMedicine {
  3753. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3754. return
  3755. }
  3756. if new_prescription.ID > 0 {
  3757. if new_prescription.OrderStatus == 2 {
  3758. isCharge = true
  3759. }
  3760. }
  3761. if isCharge {
  3762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3763. return
  3764. }
  3765. //已收费和已发药的限制逻辑
  3766. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3767. redis := service.RedisClient()
  3768. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3769. redis.Set(keyFive, "", time.Second)
  3770. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3771. redis.Set(keyOne, "", time.Second)
  3772. defer redis.Close()
  3773. if err == nil {
  3774. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3775. //查询是否在处方中出库
  3776. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3777. if openConfig.IsOpen != 1 {
  3778. //判断该医嘱是否执行了
  3779. if advice.ExecutionState == 1 {
  3780. creater := c.GetAdminUserInfo().AdminUser.Id
  3781. service.DrugAutoAddCancelInfo(&advice, creater)
  3782. }
  3783. }
  3784. //开启保存处方扣减功能
  3785. if openConfig.IsOpen == 1 {
  3786. creater := c.GetAdminUserInfo().AdminUser.Id
  3787. service.DrugAutoAddCancelInfo(&advice, creater)
  3788. }
  3789. } else {
  3790. if drugOutConfig.IsOpen == 1 {
  3791. //查询是否在处方中出库
  3792. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3793. if openConfig.IsOpen != 1 {
  3794. //判断该医嘱是否执行了
  3795. if advice.ExecutionState == 1 {
  3796. creater := c.GetAdminUserInfo().AdminUser.Id
  3797. service.DrugAutoAddCancelInfo(&advice, creater)
  3798. }
  3799. }
  3800. //开启保存处方扣减功能
  3801. if openConfig.IsOpen == 1 {
  3802. creater := c.GetAdminUserInfo().AdminUser.Id
  3803. service.DrugAutoAddCancelInfo(&advice, creater)
  3804. }
  3805. } else {
  3806. //判断该医嘱是否执行了
  3807. if advice.ExecutionState == 1 {
  3808. creater := c.GetAdminUserInfo().AdminUser.Id
  3809. service.DrugAutoAddCancelInfo(&advice, creater)
  3810. }
  3811. }
  3812. }
  3813. c.ServeSuccessJSON(map[string]interface{}{
  3814. "msg": "删除成功",
  3815. })
  3816. return
  3817. } else {
  3818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3819. return
  3820. }
  3821. }
  3822. func (c *HisApiController) DeleteProject() {
  3823. id, _ := c.GetInt64("id")
  3824. adminInfo := c.GetAdminUserInfo()
  3825. project, _ := service.GetHisProjectByID(id)
  3826. // var consumable models.DialysisBeforePrepare
  3827. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3828. //耗材保存处方出库
  3829. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3830. isCharge := false
  3831. isMedicine := false
  3832. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3833. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3834. for _, item := range new_prescriptions {
  3835. if item.IsMedicine == 1 {
  3836. isMedicine = true
  3837. }
  3838. }
  3839. for _, item := range new_prescriptions {
  3840. if item.OrderStatus == 4 {
  3841. isCharge = true
  3842. }
  3843. }
  3844. if isMedicine {
  3845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3846. return
  3847. }
  3848. if isCharge {
  3849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3850. return
  3851. }
  3852. if new_prescription.ID > 0 {
  3853. if new_prescription.OrderStatus == 2 {
  3854. isCharge = true
  3855. }
  3856. }
  3857. if isCharge {
  3858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3859. return
  3860. }
  3861. service.DeletePrintInfo(id)
  3862. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3863. label.Status = 0
  3864. service.CreateHisLabelRecord(&label)
  3865. fmt.Println(goodOutConfig.IsOpen)
  3866. if goodOutConfig.IsOpen != 1 {
  3867. if stockConfig.IsOpen == 1 {
  3868. if project.Type == 2 {
  3869. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3870. fmt.Println(err)
  3871. }
  3872. if project.Type == 3 && project.IsOut == 1 {
  3873. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3874. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3875. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3876. operation_time := time.Now().Unix()
  3877. creater := adminInfo.AdminUser.Id
  3878. //创建退库单
  3879. timeStr := time.Now().Format("2006-01-02")
  3880. timeArr := strings.Split(timeStr, "-")
  3881. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3882. total = total + 1
  3883. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3884. cancelStock := models.CancelStock{
  3885. OrderNumber: orderNumber,
  3886. OperaTime: operation_time,
  3887. OrgId: adminInfo.CurrentOrgId,
  3888. Creater: creater,
  3889. Ctime: time.Now().Unix(),
  3890. Status: 1,
  3891. ReturnTime: project.RecordDate,
  3892. Type: 1,
  3893. StorehouseId: houseConfig.StorehouseOutInfo,
  3894. IsCheck: 1,
  3895. }
  3896. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3897. if msgerrkonde == gorm.ErrRecordNotFound {
  3898. service.AddSigleCancelStock(&cancelStock)
  3899. }
  3900. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3901. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3902. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3903. //查询是否有出库
  3904. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3905. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3906. deaerler, _ := service.GetDealerById(info.Dealer)
  3907. if info.ID > 0 {
  3908. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3909. if info.Count >= prescribingNumber {
  3910. cancelStockInfo := models.CancelStockInfo{
  3911. GoodId: project.ProjectId,
  3912. CancelStockId: cancel.ID,
  3913. GoodTypeId: good.GoodTypeId,
  3914. Count: prescribingNumber,
  3915. Price: info.Price,
  3916. Total: 0,
  3917. ProductDate: info.ProductDate,
  3918. ExpiryDate: info.ExpiryDate,
  3919. Ctime: time.Now().Unix(),
  3920. Status: 1,
  3921. OrgId: adminInfo.CurrentOrgId,
  3922. OrderNumber: cancel.OrderNumber,
  3923. Type: 0,
  3924. Dealer: deaerler.DealerName,
  3925. Manufacturer: manufacturer.ManufacturerName,
  3926. Number: info.Number,
  3927. RegisterAccount: "",
  3928. Remark: "",
  3929. WarehouseInfoId: info.WarehouseInfotId,
  3930. PatientId: info.PatientId,
  3931. RecordDate: info.SysRecordTime,
  3932. StorehouseId: houseConfig.StorehouseOutInfo,
  3933. IsCheck: 1,
  3934. }
  3935. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3936. //回退库存
  3937. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3938. //退库数量增加
  3939. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3940. //出库数量减少
  3941. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3942. }
  3943. if info.Count < prescribingNumber {
  3944. cancelStockInfo := models.CancelStockInfo{
  3945. GoodId: project.ProjectId,
  3946. CancelStockId: cancel.ID,
  3947. GoodTypeId: good.GoodTypeId,
  3948. Count: info.Count,
  3949. Price: info.Price,
  3950. Total: 0,
  3951. ProductDate: info.ProductDate,
  3952. ExpiryDate: info.ExpiryDate,
  3953. Ctime: time.Now().Unix(),
  3954. Status: 1,
  3955. OrgId: adminInfo.CurrentOrgId,
  3956. OrderNumber: cancel.OrderNumber,
  3957. Type: 0,
  3958. Dealer: deaerler.DealerName,
  3959. Manufacturer: manufacturer.ManufacturerName,
  3960. Number: info.Number,
  3961. RegisterAccount: "",
  3962. Remark: "",
  3963. WarehouseInfoId: info.WarehouseInfotId,
  3964. PatientId: info.PatientId,
  3965. RecordDate: info.SysRecordTime,
  3966. StorehouseId: houseConfig.StorehouseOutInfo,
  3967. IsCheck: 1,
  3968. }
  3969. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3970. //回退库存
  3971. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3972. //退库数量增加
  3973. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3974. //出库数量减少
  3975. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3976. }
  3977. //查询剩余库存
  3978. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3979. var over_count int64
  3980. for _, it := range goodList {
  3981. over_count += it.StockCount
  3982. }
  3983. //出库数据 大于 退库数量
  3984. if info.Count >= prescribingNumber {
  3985. flow := models.VmStockFlow{
  3986. WarehousingId: info.WarehouseInfotId,
  3987. GoodId: project.ProjectId,
  3988. Number: info.Number,
  3989. LicenseNumber: info.LicenseNumber,
  3990. Count: prescribingNumber,
  3991. UserOrgId: adminInfo.CurrentOrgId,
  3992. PatientId: project.PatientId,
  3993. SystemTime: info.SysRecordTime,
  3994. ConsumableType: 7,
  3995. IsSys: 0,
  3996. WarehousingOrder: "",
  3997. WarehouseOutId: info.WarehouseOutId,
  3998. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3999. IsEdit: 0,
  4000. CancelStockId: cancel.ID,
  4001. CancelOrderNumber: cancel.OrderNumber,
  4002. Manufacturer: manufacturer.ID,
  4003. Dealer: 0,
  4004. Creator: adminInfo.AdminUser.Id,
  4005. UpdateCreator: 0,
  4006. Status: 1,
  4007. Ctime: time.Now().Unix(),
  4008. Mtime: 0,
  4009. Price: info.Price,
  4010. WarehousingDetailId: info.WarehouseInfotId,
  4011. WarehouseOutDetailId: info.ID,
  4012. CancelOutDetailId: cancelInfo.ID,
  4013. ProductDate: info.ProductDate,
  4014. ExpireDate: info.ExpiryDate,
  4015. StorehouseId: houseConfig.StorehouseOutInfo,
  4016. OverCount: over_count,
  4017. }
  4018. service.CreateStockFlowOne(flow)
  4019. }
  4020. //出库数据小于退库数据
  4021. if info.Count < prescribingNumber {
  4022. flow := models.VmStockFlow{
  4023. WarehousingId: info.WarehouseInfotId,
  4024. GoodId: project.ProjectId,
  4025. Number: info.Number,
  4026. LicenseNumber: info.LicenseNumber,
  4027. Count: info.Count,
  4028. UserOrgId: adminInfo.CurrentOrgId,
  4029. PatientId: project.PatientId,
  4030. SystemTime: info.SysRecordTime,
  4031. ConsumableType: 7,
  4032. IsSys: 0,
  4033. WarehousingOrder: "",
  4034. WarehouseOutId: info.WarehouseOutId,
  4035. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4036. IsEdit: 0,
  4037. CancelStockId: cancel.ID,
  4038. CancelOrderNumber: cancel.OrderNumber,
  4039. Manufacturer: manufacturer.ID,
  4040. Dealer: 0,
  4041. Creator: adminInfo.AdminUser.Id,
  4042. UpdateCreator: 0,
  4043. Status: 1,
  4044. Ctime: time.Now().Unix(),
  4045. Mtime: 0,
  4046. Price: info.Price,
  4047. WarehousingDetailId: info.WarehouseInfotId,
  4048. WarehouseOutDetailId: info.ID,
  4049. CancelOutDetailId: cancelInfo.ID,
  4050. ProductDate: info.ProductDate,
  4051. ExpireDate: info.ExpiryDate,
  4052. StorehouseId: houseConfig.StorehouseOutInfo,
  4053. OverCount: over_count,
  4054. }
  4055. service.CreateStockFlowOne(flow)
  4056. }
  4057. //查询已出库数量
  4058. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4059. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4060. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4061. if prescribingNumber < dialysisInfo.Count {
  4062. //改变数量
  4063. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4064. }
  4065. if prescribingNumber >= dialysisInfo.Count {
  4066. //删除出库表
  4067. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4068. }
  4069. //更新剩余库存
  4070. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4071. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4072. var total_count_one int64
  4073. for _, it := range stockList {
  4074. total_count_one += it.StockCount
  4075. }
  4076. //基础库插入数据
  4077. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4078. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4079. var flush_count int64
  4080. for _, it := range goodListOne {
  4081. flush_count += it.StockCount
  4082. }
  4083. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4084. if errs != nil {
  4085. goodErrcode := models.XtGoodErrcode{
  4086. UserOrgId: project.UserOrgId,
  4087. Errcode: "手动出库更新剩余出库失败",
  4088. GoodId: project.ProjectId,
  4089. Status: 1,
  4090. Ctime: time.Now().Unix(),
  4091. Mtime: 0,
  4092. Count: 0,
  4093. StockCount: 0,
  4094. Creater: creater,
  4095. BatchNumberId: 0,
  4096. WarehouseOutId: 0,
  4097. }
  4098. service.CreateGoodErrcode(goodErrcode)
  4099. }
  4100. }
  4101. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4102. fmt.Println(err)
  4103. } else {
  4104. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4105. fmt.Println(err)
  4106. }
  4107. } else {
  4108. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4109. fmt.Println(err)
  4110. }
  4111. }
  4112. //保存处方出库
  4113. if goodOutConfig.IsOpen == 1 {
  4114. if project.Type == 3 {
  4115. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4116. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4117. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4118. operation_time := time.Now().Unix()
  4119. creater := adminInfo.AdminUser.Id
  4120. //创建退库单
  4121. timeStr := time.Now().Format("2006-01-02")
  4122. timeArr := strings.Split(timeStr, "-")
  4123. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4124. total = total + 1
  4125. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4126. cancelStock := models.CancelStock{
  4127. OrderNumber: orderNumber,
  4128. OperaTime: operation_time,
  4129. OrgId: adminInfo.CurrentOrgId,
  4130. Creater: creater,
  4131. Ctime: time.Now().Unix(),
  4132. Status: 1,
  4133. ReturnTime: project.RecordDate,
  4134. Type: 1,
  4135. StorehouseId: houseConfig.StorehouseOutInfo,
  4136. IsCheck: 1,
  4137. }
  4138. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4139. if msgerrkonde == gorm.ErrRecordNotFound {
  4140. service.AddSigleCancelStock(&cancelStock)
  4141. }
  4142. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4143. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4144. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4145. //获取出库数据
  4146. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4147. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4148. deaerler, _ := service.GetDealerById(info.Dealer)
  4149. if info.ID > 0 {
  4150. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4151. if info.Count >= prescribingNumber {
  4152. cancelStockInfo := models.CancelStockInfo{
  4153. GoodId: project.ProjectId,
  4154. CancelStockId: cancel.ID,
  4155. GoodTypeId: good.GoodTypeId,
  4156. Count: prescribingNumber,
  4157. Price: info.Price,
  4158. Total: 0,
  4159. ProductDate: info.ProductDate,
  4160. ExpiryDate: info.ExpiryDate,
  4161. Ctime: time.Now().Unix(),
  4162. Status: 1,
  4163. OrgId: adminInfo.CurrentOrgId,
  4164. OrderNumber: cancel.OrderNumber,
  4165. Type: 0,
  4166. Dealer: deaerler.DealerName,
  4167. Manufacturer: manufacturer.ManufacturerName,
  4168. Number: info.Number,
  4169. RegisterAccount: "",
  4170. Remark: "",
  4171. WarehouseInfoId: info.WarehouseInfotId,
  4172. PatientId: info.PatientId,
  4173. RecordDate: info.SysRecordTime,
  4174. StorehouseId: houseConfig.StorehouseOutInfo,
  4175. IsCheck: 1,
  4176. }
  4177. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4178. //退库数量增加
  4179. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4180. //出库数量减少
  4181. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4182. }
  4183. if info.Count < prescribingNumber {
  4184. cancelStockInfo := models.CancelStockInfo{
  4185. GoodId: project.ProjectId,
  4186. CancelStockId: cancel.ID,
  4187. GoodTypeId: good.GoodTypeId,
  4188. Count: prescribingNumber,
  4189. Price: info.Price,
  4190. Total: 0,
  4191. ProductDate: info.ProductDate,
  4192. ExpiryDate: info.ExpiryDate,
  4193. Ctime: time.Now().Unix(),
  4194. Status: 1,
  4195. OrgId: adminInfo.CurrentOrgId,
  4196. OrderNumber: cancel.OrderNumber,
  4197. Type: 0,
  4198. Dealer: deaerler.DealerName,
  4199. Manufacturer: manufacturer.ManufacturerName,
  4200. Number: info.Number,
  4201. RegisterAccount: "",
  4202. Remark: "",
  4203. WarehouseInfoId: info.WarehouseInfotId,
  4204. PatientId: info.PatientId,
  4205. RecordDate: info.SysRecordTime,
  4206. StorehouseId: houseConfig.StorehouseOutInfo,
  4207. IsCheck: 1,
  4208. }
  4209. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4210. //回退库存
  4211. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4212. }
  4213. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4214. var over_count int64
  4215. for _, it := range goodList {
  4216. over_count += it.StockCount
  4217. }
  4218. //查询出库数量
  4219. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4220. //出库数据 大于 退库数量
  4221. if len(list) > 0 {
  4222. for _, it := range list {
  4223. //回退库存
  4224. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4225. //退库数量增加
  4226. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4227. //出库数量减少
  4228. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4229. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4230. var over_count_one int64
  4231. for _, it := range goodList {
  4232. over_count_one += it.StockCount
  4233. }
  4234. //查询该批次是否有退库数据
  4235. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4236. flow := models.VmStockFlow{
  4237. WarehousingId: it.WarehouseInfotId,
  4238. GoodId: it.GoodId,
  4239. Number: it.Number,
  4240. LicenseNumber: it.LicenseNumber,
  4241. Count: it.Count,
  4242. UserOrgId: adminInfo.CurrentOrgId,
  4243. PatientId: it.PatientId,
  4244. SystemTime: it.SysRecordTime,
  4245. ConsumableType: 7,
  4246. IsSys: 0,
  4247. WarehousingOrder: "",
  4248. WarehouseOutId: it.WarehouseOutId,
  4249. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4250. IsEdit: 0,
  4251. CancelStockId: cancel.ID,
  4252. CancelOrderNumber: cancel.OrderNumber,
  4253. Manufacturer: manufacturer.ID,
  4254. Dealer: 0,
  4255. Creator: adminInfo.AdminUser.Id,
  4256. UpdateCreator: 0,
  4257. Status: 1,
  4258. Ctime: time.Now().Unix(),
  4259. Mtime: 0,
  4260. Price: it.Price,
  4261. WarehousingDetailId: it.WarehouseInfotId,
  4262. WarehouseOutDetailId: it.ID,
  4263. CancelOutDetailId: cancelInfo.ID,
  4264. ProductDate: it.ProductDate,
  4265. ExpireDate: it.ExpiryDate,
  4266. StorehouseId: houseConfig.StorehouseOutInfo,
  4267. OverCount: over_count_one,
  4268. }
  4269. service.CreateStockFlowOne(flow)
  4270. }
  4271. }
  4272. //查询已出库数量
  4273. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4274. if prescribingNumber < dialysisInfo.Count {
  4275. //改变数量
  4276. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4277. }
  4278. if prescribingNumber >= dialysisInfo.Count {
  4279. //删除出库表
  4280. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4281. }
  4282. //更新剩余库存
  4283. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4284. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4285. var total_count_one int64
  4286. for _, it := range stockList {
  4287. total_count_one += it.StockCount
  4288. }
  4289. //基础库插入数据
  4290. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4291. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4292. var flush_count int64
  4293. for _, it := range goodListOne {
  4294. flush_count += it.StockCount
  4295. }
  4296. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4297. if errs != nil {
  4298. goodErrcode := models.XtGoodErrcode{
  4299. UserOrgId: project.UserOrgId,
  4300. Errcode: "手动出库更新剩余出库失败",
  4301. GoodId: project.ProjectId,
  4302. Status: 1,
  4303. Ctime: time.Now().Unix(),
  4304. Mtime: 0,
  4305. Count: 0,
  4306. StockCount: 0,
  4307. Creater: creater,
  4308. BatchNumberId: 0,
  4309. WarehouseOutId: 0,
  4310. }
  4311. service.CreateGoodErrcode(goodErrcode)
  4312. }
  4313. }
  4314. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4315. fmt.Println(err)
  4316. } else {
  4317. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4318. fmt.Println(err)
  4319. }
  4320. }
  4321. c.ServeSuccessJSON(map[string]interface{}{
  4322. "msg": "删除成功",
  4323. })
  4324. return
  4325. }
  4326. func (c *HisApiController) CreateHisAdditionalCharge() {
  4327. his_patient_id, _ := c.GetInt64("his_patient_id")
  4328. patient_id, _ := c.GetInt64("patient_id")
  4329. record_date := c.GetString("record_date")
  4330. timeLayout := "2006-01-02"
  4331. loc, _ := time.LoadLocation("Local")
  4332. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4333. if err != nil {
  4334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4335. return
  4336. }
  4337. adminInfo := c.GetAdminUserInfo()
  4338. recordDateTime := theTime.Unix()
  4339. dataBody := make(map[string]interface{}, 0)
  4340. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4341. if err != nil {
  4342. utils.ErrorLog(err.Error())
  4343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4344. return
  4345. }
  4346. var additions []*models.HisAdditionalCharge
  4347. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4348. additions, _ := dataBody["addition"].([]interface{})
  4349. if len(additions) > 0 {
  4350. for _, item := range additions {
  4351. items := item.(map[string]interface{})
  4352. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4353. utils.ErrorLog("item_id")
  4354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4355. return
  4356. }
  4357. item_id := int64(items["item_id"].(float64))
  4358. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4359. utils.ErrorLog("item_name")
  4360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4361. return
  4362. }
  4363. item_name := items["item_name"].(string)
  4364. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4365. utils.ErrorLog("price")
  4366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4367. return
  4368. }
  4369. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4370. ctime := time.Now().Unix()
  4371. additional := &models.HisAdditionalCharge{
  4372. PatientId: patient_id,
  4373. HisPatientId: his_patient_id,
  4374. UserOrgId: adminInfo.CurrentOrgId,
  4375. RecordDate: recordDateTime,
  4376. CreatedTime: ctime,
  4377. UpdatedTime: ctime,
  4378. Modifier: adminInfo.AdminUser.Id,
  4379. Creator: adminInfo.AdminUser.Id,
  4380. Price: price,
  4381. ItemName: item_name,
  4382. ItemId: item_id,
  4383. Status: 1,
  4384. }
  4385. additions = append(additions, additional)
  4386. }
  4387. }
  4388. }
  4389. for _, item := range additions {
  4390. service.CreateAddtionalCharge(item)
  4391. }
  4392. c.ServeSuccessJSON(map[string]interface{}{
  4393. "msg": "创建成功",
  4394. })
  4395. }
  4396. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4397. blood_fat := c.GetString("blood_fat")
  4398. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4399. blood_sugar := c.GetString("blood_sugar")
  4400. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4401. chief_conplaint := c.GetString("chief_conplaint")
  4402. dbp := c.GetString("dbp")
  4403. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4404. delivery_way, _ := c.GetInt64("delivery_way")
  4405. diagnostic := c.GetString("diagnostic")
  4406. family_history := c.GetString("family_history")
  4407. height := c.GetString("height")
  4408. history_of_present_illness := c.GetString("history_of_present_illness")
  4409. is_infect, _ := c.GetInt64("is_infect")
  4410. past_history := c.GetString("past_history")
  4411. patient_id, _ := c.GetInt64("patient_id")
  4412. his_patient_id, _ := c.GetInt64("his_patient_id")
  4413. personal_history := c.GetString("personal_history")
  4414. pulse := c.GetString("pulse")
  4415. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4416. sbp := c.GetString("sbp")
  4417. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4418. heightfloat, _ := strconv.ParseFloat(height, 64)
  4419. sicktype := c.GetString("sick_type")
  4420. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4421. symptom := c.GetString("symptom")
  4422. sick_date := c.GetString("sick_date")
  4423. temperatures := c.GetString("temperature")
  4424. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4425. record_date := c.GetString("record_date")
  4426. breathing := c.GetString("breathing")
  4427. doctor_advice := c.GetString("doctor_advice")
  4428. remark := c.GetString("remark")
  4429. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4430. sick, _ := c.GetInt64("sick")
  4431. diagnose, _ := c.GetInt64("diagnose")
  4432. //id, _ := c.GetInt64("id")
  4433. timeLayout := "2006-01-02"
  4434. loc, _ := time.LoadLocation("Local")
  4435. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4436. allergic_history := c.GetString("allergic_history")
  4437. if err != nil {
  4438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4439. return
  4440. }
  4441. recordDateTime := theTime.Unix()
  4442. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4443. if err != nil {
  4444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4445. return
  4446. }
  4447. sickTimes := sickTime.Unix()
  4448. ctime := time.Now().Unix()
  4449. primary_disease := c.GetString("primary_disease")
  4450. confirm_failure_date := c.GetString("confirm_failure_date")
  4451. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4452. drug_allergy_history := c.GetString("drug_allergy_history")
  4453. physical_examination := c.GetString("physical_examination")
  4454. special_inspection := c.GetString("special_inspection")
  4455. lab_apparatus := c.GetString("lab_apparatus")
  4456. caseHistory := models.HisPatientCaseHistory{
  4457. HisPatientId: his_patient_id,
  4458. PatientId: patient_id,
  4459. Temperature: temperature,
  4460. BloodSugar: bloodsugarfloat,
  4461. Pulse: pulsefloat,
  4462. Sbp: sbpfloat,
  4463. Dbp: dbpfloat,
  4464. Height: heightfloat,
  4465. BloodFat: bloodfatfloat,
  4466. SickType: sick_type,
  4467. Symptom: symptom,
  4468. SickDate: sickTimes,
  4469. IsInfect: is_infect,
  4470. HistoryOfPresentIllness: history_of_present_illness,
  4471. PastHistory: past_history,
  4472. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4473. ChiefConplaint: chief_conplaint,
  4474. PersonalHistory: personal_history,
  4475. FamilyHistory: family_history,
  4476. Diagnostic: diagnostic,
  4477. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4478. Status: 1,
  4479. Ctime: ctime,
  4480. Mtime: ctime,
  4481. RecordDate: recordDateTime,
  4482. DeliveryWay: delivery_way,
  4483. Breathing: breathingfloat,
  4484. DoctorAdvice: doctor_advice,
  4485. Remark: remark,
  4486. Sick: sick,
  4487. Diagnose: diagnose,
  4488. AllergicHistory: allergic_history,
  4489. PrimaryDisease: primary_disease,
  4490. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4491. DrugAllergyHistory: drug_allergy_history,
  4492. PhysicalExamination: physical_examination,
  4493. SpecialInspection: special_inspection,
  4494. LabApparatus: lab_apparatus,
  4495. }
  4496. //查询该患者是否有病历
  4497. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4498. if errcodes == gorm.ErrRecordNotFound {
  4499. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4500. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4501. if err != nil {
  4502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4503. return
  4504. }
  4505. c.ServeSuccessJSON(map[string]interface{}{
  4506. "caseHistory": caseHistory,
  4507. "historyInfo": historyInfo,
  4508. })
  4509. return
  4510. } else if errcodes == nil {
  4511. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4512. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4513. if err != nil {
  4514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4515. return
  4516. }
  4517. c.ServeSuccessJSON(map[string]interface{}{
  4518. "caseHistory": caseHistory,
  4519. "historyInfo": historyInfo,
  4520. })
  4521. }
  4522. //查询该患者是否有病历
  4523. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4524. //if errcode == gorm.ErrRecordNotFound {
  4525. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4526. // if err != nil {
  4527. // c.ServeSuccessJSON(map[string]interface{}{
  4528. // "msg": "保存成功",
  4529. // })
  4530. // }
  4531. //} else if errcode == nil {
  4532. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4533. // return
  4534. //}
  4535. }
  4536. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4537. patient_id, _ := c.GetInt64("patient_id", 0)
  4538. adminUser := c.GetAdminUserInfo()
  4539. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4540. c.ServeSuccessJSON(map[string]interface{}{
  4541. "list": caseHistorys,
  4542. })
  4543. }
  4544. func (c *HisApiController) GetHisPatientCaseHistory() {
  4545. record_date, _ := c.GetInt64("record_date", 0)
  4546. patient_id, _ := c.GetInt64("patient_id", 0)
  4547. admin := c.GetAdminUserInfo()
  4548. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4549. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4550. c.ServeSuccessJSON(map[string]interface{}{
  4551. "info": info,
  4552. "case_history": case_history,
  4553. })
  4554. }
  4555. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4556. template_name := c.GetString("template_name")
  4557. template_remark := c.GetString("template_remark")
  4558. doctor := c.GetAdminUserInfo().AdminUser.Id
  4559. diagnostic := c.GetString("diagnostic")
  4560. chief_conplaint := c.GetString("chief_conplain")
  4561. history_of_present_illness := c.GetString("history_of_present_illness")
  4562. past_history := c.GetString("past_history")
  4563. personal_history := c.GetString("personal_history")
  4564. family_history := c.GetString("family_history")
  4565. user_name := c.GetString("user_name")
  4566. doctor_advice := c.GetString("doctor_advice")
  4567. remark := c.GetString("remark")
  4568. //record_date := c.GetString("record_date")
  4569. //fmt.Println("record_date--------",record_date)
  4570. //timeLayout := "2006-01-02"
  4571. //loc, _ := time.LoadLocation("Local")
  4572. //
  4573. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4574. //if err != nil {
  4575. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4576. // return
  4577. //}
  4578. //recordDateTime := theTime.Unix()
  4579. ctime := time.Now().Unix()
  4580. template := models.HisCaseHistoryTemplate{
  4581. HistoryOfPresentIllness: history_of_present_illness,
  4582. PastHistory: past_history,
  4583. ChiefConplaint: chief_conplaint,
  4584. PersonalHistory: personal_history,
  4585. FamilyHistory: family_history,
  4586. Diagnostic: diagnostic,
  4587. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4588. Status: 1,
  4589. Ctime: ctime,
  4590. Mtime: ctime,
  4591. RecordDate: time.Now().Unix(),
  4592. TemplateName: template_name,
  4593. TemplateRemark: template_remark,
  4594. Creator: doctor,
  4595. Modifier: doctor,
  4596. UserName: user_name,
  4597. DoctorAdvice: doctor_advice,
  4598. Remark: remark,
  4599. }
  4600. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4601. if err == nil {
  4602. c.ServeSuccessJSON(map[string]interface{}{
  4603. "msg": "保存成功",
  4604. })
  4605. } else {
  4606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4607. return
  4608. }
  4609. }
  4610. func (c *HisApiController) GetCaseHistoryTemplate() {
  4611. timeLayout := "2006-01-02"
  4612. loc, _ := time.LoadLocation("Local")
  4613. keyword := c.GetString("keyword")
  4614. start_time := c.GetString("start_time")
  4615. end_time := c.GetString("end_time")
  4616. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4617. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4618. admin := c.GetAdminUserInfo()
  4619. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4620. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4621. c.ServeSuccessJSON(map[string]interface{}{
  4622. "template": template,
  4623. //"history": history,
  4624. })
  4625. }
  4626. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4627. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4628. utils.ErrorLog("drug_name")
  4629. return enums.ErrorCodeParamWrong
  4630. }
  4631. adviceName, _ := json["drug_name"].(string)
  4632. if len(adviceName) == 0 {
  4633. utils.ErrorLog("len(advice_name) == 0")
  4634. return enums.ErrorCodeParamWrong
  4635. }
  4636. advice.AdviceName = adviceName
  4637. adviceDesc, _ := json["advice_desc"].(string)
  4638. advice.AdviceDesc = adviceDesc
  4639. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4640. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4641. advice.DrugSpec = drugSpec
  4642. }
  4643. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4644. remark, _ := json["remark"].(string)
  4645. advice.Remark = remark
  4646. }
  4647. if json["id"] == nil {
  4648. advice.DrugId = 0
  4649. } else {
  4650. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4651. drug_id := int64(json["id"].(float64))
  4652. advice.DrugId = drug_id
  4653. }
  4654. }
  4655. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4656. advice_id := int64(json["advice_id"].(float64))
  4657. advice.ID = advice_id
  4658. if advice.ID > 0 {
  4659. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4660. if err == nil {
  4661. if hisAdvice.ID > 0 {
  4662. advice.ExecutionTime = hisAdvice.ExecutionTime
  4663. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4664. advice.ExecutionState = hisAdvice.ExecutionState
  4665. advice.CheckTime = hisAdvice.CheckTime
  4666. advice.Checker = hisAdvice.Checker
  4667. advice.CheckState = hisAdvice.CheckState
  4668. advice.StartTime = hisAdvice.StartTime
  4669. advice.FeedetlSn = hisAdvice.FeedetlSn
  4670. }
  4671. }
  4672. }
  4673. }
  4674. //
  4675. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4676. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4677. // advice.ExecutionTime = execution_time
  4678. //}
  4679. //
  4680. //
  4681. //
  4682. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4683. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4684. // advice.ExecutionStaff = execution_staff
  4685. //}
  4686. //
  4687. //
  4688. //
  4689. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4690. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4691. // advice.ExecutionState = execution_state
  4692. //}
  4693. //
  4694. //
  4695. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4696. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4697. // advice.CheckTime = check_time
  4698. //}
  4699. //
  4700. //
  4701. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4702. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4703. // advice.CheckState = check_state
  4704. //}
  4705. //
  4706. //
  4707. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4708. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4709. // advice.Checker = checker
  4710. //}
  4711. //
  4712. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4713. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4714. // advice.StartTime = start_time
  4715. //}
  4716. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4717. drugSpecUnit, _ := json["min_unit"].(string)
  4718. advice.DrugSpecUnit = drugSpecUnit
  4719. }
  4720. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4721. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4722. advice.SingleDose = singleDose
  4723. }
  4724. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4725. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4726. advice.SingleDoseUnit = singleDoseUnit
  4727. }
  4728. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4729. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4730. advice.PrescribingNumber = prescribingNumber
  4731. }
  4732. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4733. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4734. advice.PrescribingNumberUnit = prescribingNumberUnit
  4735. }
  4736. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4737. deliveryWay, _ := json["delivery_way"].(string)
  4738. advice.DeliveryWay = deliveryWay
  4739. }
  4740. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4741. executionFrequency, _ := json["execution_frequency"].(string)
  4742. advice.ExecutionFrequency = executionFrequency
  4743. }
  4744. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4745. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4746. advice.Price = price
  4747. }
  4748. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4749. med_list_codg, _ := json["medical_insurance_number"].(string)
  4750. advice.MedListCodg = med_list_codg
  4751. }
  4752. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4753. day := int64(json["day"].(float64))
  4754. advice.Day = day
  4755. }
  4756. return 0
  4757. }
  4758. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4759. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4760. id := int64(json["id"].(float64))
  4761. project.ID = id
  4762. historyProject, _ := service.GetHisProjectByID(id)
  4763. project.FeedetlSn = historyProject.FeedetlSn
  4764. }
  4765. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4766. project_id := int64(json["project_id"].(float64))
  4767. project.ProjectId = project_id
  4768. }
  4769. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4770. // price := int64(json["price"].(float64))
  4771. // formatInt_price := strconv.FormatInt(price, 10)
  4772. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4773. // project.Price = float_price
  4774. // }
  4775. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4776. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4777. project.Price = price
  4778. }
  4779. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4780. total, _ := json["total"].(string)
  4781. project.Count = total
  4782. }
  4783. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4784. medical_code, _ := json["medical_code"].(string)
  4785. project.MedListCodg = medical_code
  4786. }
  4787. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4788. single_dose, _ := json["single_dose"].(string)
  4789. project.SingleDose = single_dose
  4790. }
  4791. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4792. delivery_way, _ := json["delivery_way"].(string)
  4793. project.DeliveryWay = delivery_way
  4794. }
  4795. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4796. execution_frequency, _ := json["execution_frequency"].(string)
  4797. project.ExecutionFrequency = execution_frequency
  4798. }
  4799. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4800. remark, _ := json["remark"].(string)
  4801. project.Remark = remark
  4802. }
  4803. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4804. day, _ := json["number_days"].(string)
  4805. project.Day = day
  4806. }
  4807. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4808. unit, _ := json["unit"].(string)
  4809. project.Unit = unit
  4810. }
  4811. return 0
  4812. }
  4813. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4814. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4815. id := int64(json["id"].(float64))
  4816. historyAddtions, _ := service.GetHisAdditionByID(id)
  4817. additionalCharge.ID = id
  4818. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4819. }
  4820. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4821. item_id := int64(json["item_id"].(float64))
  4822. additionalCharge.ItemId = item_id
  4823. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4824. if config.ID > 0 {
  4825. if len(config.Code) > 0 {
  4826. additionalCharge.MedListCodg = config.Code
  4827. }
  4828. }
  4829. }
  4830. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4831. // price := int64(json["price"].(float64))
  4832. // formatInt_price := strconv.FormatInt(price, 10)
  4833. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4834. // additionalCharge.Price = float_price
  4835. // }
  4836. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4837. // price := int64(json["price"].(float64))
  4838. // formatInt_price := strconv.FormatInt(price, 10)
  4839. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4840. // additionalCharge.Price = float_price
  4841. //}
  4842. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4843. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4844. additionalCharge.Price = price
  4845. }
  4846. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4847. count, _ := json["count"].(string)
  4848. counts, _ := strconv.ParseInt(count, 10, 64)
  4849. additionalCharge.Count = counts
  4850. }
  4851. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4852. item_name, _ := json["item_name"].(string)
  4853. additionalCharge.ItemName = item_name
  4854. }
  4855. return 0
  4856. }
  4857. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4858. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4859. utils.ErrorLog("drug_name")
  4860. return enums.ErrorCodeParamWrong
  4861. }
  4862. adviceName, _ := json["drug_name"].(string)
  4863. if len(adviceName) == 0 {
  4864. utils.ErrorLog("len(advice_name) == 0")
  4865. return enums.ErrorCodeParamWrong
  4866. }
  4867. advice.AdviceName = adviceName
  4868. adviceDesc, _ := json["advice_desc"].(string)
  4869. advice.AdviceDesc = adviceDesc
  4870. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4871. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4872. advice.DrugSpec = drugSpec
  4873. }
  4874. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4875. remark, _ := json["remark"].(string)
  4876. advice.Remark = remark
  4877. }
  4878. if json["id"] == nil {
  4879. advice.DrugId = 0
  4880. } else {
  4881. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4882. drug_id := int64(json["id"].(float64))
  4883. advice.DrugId = drug_id
  4884. }
  4885. }
  4886. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4887. groupno := int64(json["groupno"].(float64))
  4888. advice.Groupno = groupno
  4889. }
  4890. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4891. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4892. advice.HospApprFlag = hosp_appr_flag
  4893. }
  4894. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4895. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4896. advice.PrescribingNumber = prescribingNumber
  4897. }
  4898. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4899. // frequency_type := int64(json["frequency_type"].(float64))
  4900. // advice.FrequencyType = frequency_type
  4901. //}
  4902. //
  4903. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4904. // day_count := int64(json["day_count"].(float64))
  4905. // advice.DayCount = day_count
  4906. //}
  4907. //
  4908. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4909. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4910. // week_day, _ := json["week_day"].(string)
  4911. // advice.WeekDay = week_day
  4912. //}
  4913. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4914. drugSpecUnit, _ := json["min_unit"].(string)
  4915. advice.DrugSpecUnit = drugSpecUnit
  4916. }
  4917. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4918. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4919. advice.SingleDose = singleDose
  4920. }
  4921. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4922. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4923. advice.SingleDoseUnit = singleDoseUnit
  4924. }
  4925. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4926. deliveryWay, _ := json["delivery_way"].(string)
  4927. advice.DeliveryWay = deliveryWay
  4928. }
  4929. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4930. executionFrequency, _ := json["execution_frequency"].(string)
  4931. advice.ExecutionFrequency = executionFrequency
  4932. }
  4933. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4934. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4935. advice.Price = price
  4936. }
  4937. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4938. med_list_codg, _ := json["medical_insurance_number"].(string)
  4939. advice.MedListCodg = med_list_codg
  4940. }
  4941. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4942. day := int64(json["day"].(float64))
  4943. advice.Day = day
  4944. }
  4945. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4946. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4947. advice.PrescribingNumberUnit = prescribingNumberUnit
  4948. }
  4949. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4950. advice_id := int64(json["advice_id"].(float64))
  4951. advice.ID = advice_id
  4952. if advice.ID > 0 {
  4953. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4954. if err == nil {
  4955. if hisAdvice.ID > 0 {
  4956. advice.ExecutionTime = hisAdvice.ExecutionTime
  4957. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4958. advice.ExecutionState = hisAdvice.ExecutionState
  4959. advice.CheckTime = hisAdvice.CheckTime
  4960. advice.Checker = hisAdvice.Checker
  4961. advice.CheckState = hisAdvice.CheckState
  4962. advice.StartTime = hisAdvice.StartTime
  4963. advice.HospApprFlag = hisAdvice.HospApprFlag
  4964. advice.IsMedicine = hisAdvice.IsMedicine
  4965. if hisAdvice.UserOrgId == 10028 {
  4966. 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 {
  4967. advice.ExecutionTime = 0
  4968. advice.ExecutionStaff = 0
  4969. advice.ExecutionState = 2
  4970. advice.CheckTime = 0
  4971. advice.Checker = 0
  4972. advice.CheckState = 2
  4973. }
  4974. } else {
  4975. 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 {
  4976. advice.ExecutionTime = 0
  4977. advice.ExecutionStaff = 0
  4978. advice.ExecutionState = 2
  4979. advice.CheckTime = 0
  4980. advice.Checker = 0
  4981. advice.CheckState = 2
  4982. }
  4983. }
  4984. //advice.Groupno = hisAdvice.Groupno
  4985. }
  4986. }
  4987. }
  4988. }
  4989. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4990. //
  4991. //if drugStockConfig.IsOpen == 1 {
  4992. //
  4993. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4994. // if advice.ID == 0 { //医嘱不存在
  4995. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4996. // drug.Total = drug.Total - advice.PrescribingNumber
  4997. // service.UpdateBaseDrugLib(&drug)
  4998. //
  4999. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5000. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5001. // drug.Total = drug.Total - num
  5002. // service.UpdateBaseDrugLib(&drug)
  5003. // }
  5004. //
  5005. // } else if advice.ID > 0 { //医嘱存在
  5006. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5007. // var num float64
  5008. //
  5009. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5010. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5011. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5012. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5013. // drug.Total = drug.Total + num
  5014. // service.UpdateBaseDrugLib(&drug)
  5015. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5016. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5017. // drug.Total = drug.Total - num
  5018. // service.UpdateBaseDrugLib(&drug)
  5019. // }
  5020. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5021. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5022. // if num2 > advice.PrescribingNumber {
  5023. // num = num2 - advice.PrescribingNumber
  5024. // drug.Total = drug.Total + num
  5025. // service.UpdateBaseDrugLib(&drug)
  5026. // } else if num2 < advice.PrescribingNumber {
  5027. // num = advice.PrescribingNumber - num2
  5028. // drug.Total = drug.Total - num
  5029. // service.UpdateBaseDrugLib(&drug)
  5030. // }
  5031. //
  5032. // }
  5033. //
  5034. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5035. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5036. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5037. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5038. // if num1 > num2 {
  5039. // num = num1 - num2
  5040. // drug.Total = drug.Total + num
  5041. // service.UpdateBaseDrugLib(&drug)
  5042. // } else if num1 < num2 {
  5043. // num = num2 - num1
  5044. // drug.Total = drug.Total - num
  5045. // service.UpdateBaseDrugLib(&drug)
  5046. // }
  5047. //
  5048. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5049. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5050. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5051. // if hisAdvice.PrescribingNumber > num2 {
  5052. // num = hisAdvice.PrescribingNumber - num2
  5053. // drug.Total = drug.Total + num
  5054. // service.UpdateBaseDrugLib(&drug)
  5055. // } else if num2 < advice.PrescribingNumber {
  5056. // num = num2 - hisAdvice.PrescribingNumber
  5057. // drug.Total = drug.Total - num
  5058. // service.UpdateBaseDrugLib(&drug)
  5059. // }
  5060. //
  5061. // }
  5062. // }
  5063. // }
  5064. //}
  5065. //
  5066. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5067. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5068. // advice.ExecutionTime = execution_time
  5069. //}
  5070. //
  5071. //
  5072. //
  5073. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5074. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5075. // advice.ExecutionStaff = execution_staff
  5076. //}
  5077. //
  5078. //
  5079. //
  5080. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5081. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5082. // advice.ExecutionState = execution_state
  5083. //}
  5084. //
  5085. //
  5086. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5087. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5088. // advice.CheckTime = check_time
  5089. //}
  5090. //
  5091. //
  5092. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5093. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5094. // advice.CheckState = check_state
  5095. //}
  5096. //
  5097. //
  5098. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5099. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5100. // advice.Checker = checker
  5101. //}
  5102. //
  5103. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5104. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5105. // advice.StartTime = start_time
  5106. //}
  5107. return 0
  5108. }
  5109. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5110. project.ExecutionStaff = 0
  5111. project.ExecutionState = 2
  5112. project.ExecutionTime = 0
  5113. project.Checker = 0
  5114. project.CheckState = 2
  5115. project.CheckTime = 0
  5116. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5117. id := int64(json["id"].(float64))
  5118. project.ID = id
  5119. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5120. project.ExecutionStaff = temp_project.ExecutionStaff
  5121. project.ExecutionState = temp_project.ExecutionState
  5122. project.ExecutionTime = temp_project.ExecutionTime
  5123. project.Checker = temp_project.Checker
  5124. project.CheckState = temp_project.CheckState
  5125. project.CheckTime = temp_project.CheckTime
  5126. project.TeamId = temp_project.TeamId
  5127. }
  5128. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5129. types := int64(json["type"].(float64))
  5130. project.Type = types
  5131. }
  5132. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5133. project_id := int64(json["project_id"].(float64))
  5134. project.ProjectId = project_id
  5135. }
  5136. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5137. team_id := int64(json["team_id"].(float64))
  5138. project.TeamId = team_id
  5139. }
  5140. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5141. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5142. project.Price = price
  5143. }
  5144. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5145. total, _ := json["total"].(string)
  5146. //totals, _ := strconv.ParseInt(total, 10, 64)
  5147. project.Count = total
  5148. }
  5149. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5150. medical_code, _ := json["medical_code"].(string)
  5151. project.MedListCodg = medical_code
  5152. }
  5153. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5154. single_dose, _ := json["single_dose"].(string)
  5155. project.SingleDose = single_dose
  5156. }
  5157. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5158. delivery_way, _ := json["delivery_way"].(string)
  5159. project.DeliveryWay = delivery_way
  5160. }
  5161. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5162. execution_frequency, _ := json["execution_frequency"].(string)
  5163. project.ExecutionFrequency = execution_frequency
  5164. }
  5165. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5166. remark, _ := json["remark"].(string)
  5167. project.Remark = remark
  5168. }
  5169. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5170. day, _ := json["number_days"].(string)
  5171. project.Day = day
  5172. }
  5173. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5174. unit, _ := json["unit"].(string)
  5175. project.Unit = unit
  5176. }
  5177. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5178. // frequency_type := int64(json["frequency_type"].(float64))
  5179. // project.FrequencyType = frequency_type
  5180. //}
  5181. //
  5182. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5183. // day_count := int64(json["day_count"].(float64))
  5184. // project.DayCount = day_count
  5185. //}
  5186. //
  5187. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5188. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5189. // week_day, _ := json["week_day"].(string)
  5190. // project.WeekDay = week_day
  5191. //}
  5192. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5193. //
  5194. //if project.ID == 0 {
  5195. // if stockConfig.IsOpen == 1 {
  5196. // if project.Type == 3 {
  5197. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5198. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5199. // good.Total = good.Total - f_count
  5200. // service.UpdateGoodInfo(&good)
  5201. // }
  5202. // }
  5203. //
  5204. //} else {
  5205. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5206. //
  5207. // if stockConfig.IsOpen == 1 {
  5208. // if project.Type == 3 {
  5209. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5210. // if project.Count < temp_project.Count {
  5211. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5212. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5213. //
  5214. // other_count := f_count_two - f_count_one
  5215. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5216. // good.Total = good.Total + other_count_two
  5217. // service.UpdateGoodInfo(&good)
  5218. // } else if project.Count > temp_project.Count {
  5219. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5220. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5221. //
  5222. // other_count := f_count_one - f_count_two
  5223. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5224. // good.Total = good.Total - other_count_two
  5225. // service.UpdateGoodInfo(&good)
  5226. // }
  5227. //
  5228. // }
  5229. // }
  5230. //
  5231. //}
  5232. return 0
  5233. }
  5234. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5235. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5236. id := int64(json["id"].(float64))
  5237. additionalCharge.ID = id
  5238. }
  5239. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5240. item_id := int64(json["item_id"].(float64))
  5241. additionalCharge.ItemId = item_id
  5242. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5243. if config.ID > 0 {
  5244. if len(config.Code) > 0 {
  5245. additionalCharge.MedListCodg = config.Code
  5246. }
  5247. }
  5248. }
  5249. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5250. // price := int64(json["price"].(float64))
  5251. // formatInt_price := strconv.FormatInt(price, 10)
  5252. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5253. // additionalCharge.Price = float_price
  5254. // }
  5255. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5256. // price := int64(json["price"].(float64))
  5257. // formatInt_price := strconv.FormatInt(price, 10)
  5258. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5259. // additionalCharge.Price = float_price
  5260. //}
  5261. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5262. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5263. additionalCharge.Price = price
  5264. }
  5265. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5266. count, _ := json["count"].(string)
  5267. counts, _ := strconv.ParseInt(count, 10, 64)
  5268. additionalCharge.Count = counts
  5269. }
  5270. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5271. item_name, _ := json["item_name"].(string)
  5272. additionalCharge.ItemName = item_name
  5273. }
  5274. return 0
  5275. }
  5276. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5277. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5278. utils.ErrorLog("drug_name")
  5279. return enums.ErrorCodeParamWrong
  5280. }
  5281. adviceName, _ := json["drug_name"].(string)
  5282. if len(adviceName) == 0 {
  5283. utils.ErrorLog("len(advice_name) == 0")
  5284. return enums.ErrorCodeParamWrong
  5285. }
  5286. advice.AdviceName = adviceName
  5287. adviceDesc, _ := json["advice_desc"].(string)
  5288. advice.AdviceDesc = adviceDesc
  5289. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5290. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5291. advice.DrugSpec = drugSpec
  5292. }
  5293. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5294. remark, _ := json["remark"].(string)
  5295. advice.Remark = remark
  5296. }
  5297. if json["id"] == nil {
  5298. advice.DrugId = 0
  5299. } else {
  5300. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5301. drug_id := int64(json["id"].(float64))
  5302. advice.DrugId = drug_id
  5303. }
  5304. }
  5305. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5306. drugSpecUnit, _ := json["min_unit"].(string)
  5307. advice.DrugSpecUnit = drugSpecUnit
  5308. }
  5309. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5310. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5311. advice.SingleDose = singleDose
  5312. }
  5313. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5314. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5315. advice.SingleDoseUnit = singleDoseUnit
  5316. }
  5317. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5318. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5319. advice.PrescribingNumber = prescribingNumber
  5320. }
  5321. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5322. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5323. advice.PrescribingNumberUnit = prescribingNumberUnit
  5324. }
  5325. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5326. deliveryWay, _ := json["delivery_way"].(string)
  5327. advice.DeliveryWay = deliveryWay
  5328. }
  5329. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5330. executionFrequency, _ := json["execution_frequency"].(string)
  5331. advice.ExecutionFrequency = executionFrequency
  5332. }
  5333. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5334. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5335. advice.Price = price
  5336. }
  5337. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5338. med_list_codg, _ := json["medical_insurance_number"].(string)
  5339. advice.MedListCodg = med_list_codg
  5340. }
  5341. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5342. day := int64(json["day"].(float64))
  5343. advice.Day = day
  5344. }
  5345. advice.FrequencyType = 1
  5346. return 0
  5347. }
  5348. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5349. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5350. types := int64(json["type"].(float64))
  5351. project.Type = types
  5352. }
  5353. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5354. project_id := int64(json["project_id"].(float64))
  5355. project.ProjectId = project_id
  5356. }
  5357. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5358. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5359. project.Price = price
  5360. }
  5361. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5362. total, _ := json["total"].(string)
  5363. //totals, _ := strconv.ParseInt(total, 10, 64)
  5364. project.Count = total
  5365. }
  5366. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5367. medical_code, _ := json["medical_code"].(string)
  5368. project.MedListCodg = medical_code
  5369. }
  5370. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5371. single_dose, _ := json["single_dose"].(string)
  5372. project.SingleDose = single_dose
  5373. }
  5374. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5375. delivery_way, _ := json["delivery_way"].(string)
  5376. project.DeliveryWay = delivery_way
  5377. }
  5378. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5379. execution_frequency, _ := json["execution_frequency"].(string)
  5380. project.ExecutionFrequency = execution_frequency
  5381. }
  5382. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5383. remark, _ := json["remark"].(string)
  5384. project.Remark = remark
  5385. }
  5386. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5387. day, _ := json["number_days"].(string)
  5388. project.Day = day
  5389. }
  5390. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5391. unit, _ := json["unit"].(string)
  5392. project.Unit = unit
  5393. }
  5394. project.FrequencyType = 1
  5395. return 0
  5396. }
  5397. func (c *HisApiController) GetHisOrderList() {
  5398. page, _ := c.GetInt64("page", -1)
  5399. limit, _ := c.GetInt64("limit", -1)
  5400. start_time := c.GetString("start_time")
  5401. end_time := c.GetString("end_time")
  5402. types, _ := c.GetInt64("type", 0)
  5403. keywords := c.GetString("keywords")
  5404. p_type, _ := c.GetInt64("p_type", 0)
  5405. sort_type, _ := c.GetInt64("sort_type", 0)
  5406. charge_type, _ := c.GetInt64("charge_type", 0)
  5407. sch_type, _ := c.GetInt64("sch_type", 0)
  5408. zone_type, _ := c.GetInt64("zone_type", 0)
  5409. timeLayout := "2006-01-02"
  5410. loc, _ := time.LoadLocation("Local")
  5411. var startTime int64
  5412. if len(start_time) > 0 {
  5413. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5414. if err != nil {
  5415. //fmt.Println(err)
  5416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5417. return
  5418. }
  5419. startTime = theTime.Unix()
  5420. }
  5421. var endTime int64
  5422. if len(end_time) > 0 {
  5423. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5424. if err != nil {
  5425. utils.ErrorLog(err.Error())
  5426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5427. return
  5428. }
  5429. endTime = theTime.Unix()
  5430. }
  5431. adminUser := c.GetAdminUserInfo()
  5432. org_id := adminUser.CurrentOrgId
  5433. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type)
  5434. for _, item := range order {
  5435. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5436. item.DoctorName = info.Doctor
  5437. item.DepartmentName = info.XtHisDepartment.Name
  5438. }
  5439. if err == nil {
  5440. c.ServeSuccessJSON(map[string]interface{}{
  5441. "order": order,
  5442. "total": total,
  5443. })
  5444. } else {
  5445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5446. return
  5447. }
  5448. }
  5449. func (c *HisApiController) GetHisOrder() {
  5450. patient_id, _ := c.GetInt64("patient_id", 0)
  5451. number := c.GetString("number")
  5452. adminInfo := c.GetAdminUserInfo()
  5453. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5454. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5455. if err == nil {
  5456. c.ServeSuccessJSON(map[string]interface{}{
  5457. "order": order,
  5458. "prescription": prescriptions,
  5459. })
  5460. } else {
  5461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5462. return
  5463. }
  5464. }
  5465. func (c *HisApiController) GetHisPrescriptionList() {
  5466. record_date := c.GetString("record_date")
  5467. keywords := c.GetString("keywords")
  5468. page, _ := c.GetInt64("page")
  5469. limit, _ := c.GetInt64("limit")
  5470. sch_type, _ := c.GetInt64("sch_type")
  5471. timeLayout := "2006-01-02"
  5472. loc, _ := time.LoadLocation("Local")
  5473. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5474. if err != nil {
  5475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5476. return
  5477. }
  5478. recordDateTime := theTime.Unix()
  5479. adminInfo := c.GetAdminUserInfo()
  5480. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5481. //adminInfo := c.GetAdminUserInfo()
  5482. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5483. //fmt.Println(prescriptionOrder)
  5484. if err == nil {
  5485. c.ServeSuccessJSON(map[string]interface{}{
  5486. "order": prescriptionOrder,
  5487. "total": total,
  5488. })
  5489. } else {
  5490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5491. return
  5492. }
  5493. }
  5494. func (c *HisApiController) GetHisPrescriptionInfo() {
  5495. id, _ := c.GetInt64("id")
  5496. adminInfo := c.GetAdminUserInfo()
  5497. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5498. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5499. if err == nil {
  5500. c.ServeSuccessJSON(map[string]interface{}{
  5501. "order": prescriptionOrder,
  5502. "prescription": prescription,
  5503. })
  5504. } else {
  5505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5506. return
  5507. }
  5508. }
  5509. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5510. adminUser := c.GetAdminUserInfo()
  5511. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5512. c.ServeSuccessJSON(map[string]interface{}{
  5513. "config": config,
  5514. })
  5515. }
  5516. type ResultTwo struct {
  5517. ErrMsg interface{} `json:"err_msg"`
  5518. InfRefmsgid string `json:"inf_refmsgid"`
  5519. Infcode int64 `json:"infcode"`
  5520. Output struct {
  5521. Baseinfo struct {
  5522. Age float64 `json:"age"`
  5523. Brdy string `json:"brdy"`
  5524. Certno string `json:"certno"`
  5525. Gend string `json:"gend"`
  5526. Naty string `json:"naty"`
  5527. PsnCertType string `json:"psn_cert_type"`
  5528. PsnName string `json:"psn_name"`
  5529. PsnNo string `json:"psn_no"`
  5530. } `json:"baseinfo"`
  5531. Idetinfo []interface{} `json:"idetinfo"`
  5532. Iinfo []struct {
  5533. Balc float64 `json:"balc"`
  5534. CvlservFlag string `json:"cvlserv_flag"`
  5535. EmpName string `json:"emp_name"`
  5536. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5537. Insutype string `json:"insutype"`
  5538. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5539. PausInsuDate interface{} `json:"paus_insu_date"`
  5540. PsnInsuDate string `json:"psn_insu_date"`
  5541. PsnInsuStas string `json:"psn_insu_stas"`
  5542. PsnType string `json:"psn_type"`
  5543. } `json:"insuinfo"`
  5544. } `json:"output"`
  5545. RefmsgTime string `json:"refmsg_time"`
  5546. RespondTime string `json:"respond_time"`
  5547. Signtype interface{} `json:"signtype"`
  5548. WarnInfo interface{} `json:"warn_info"`
  5549. }
  5550. type ResultThree struct {
  5551. Cainfo interface{} `json:"cainfo"`
  5552. ErrMsg interface{} `json:"err_msg"`
  5553. InfRefmsgid string `json:"inf_refmsgid"`
  5554. Infcode int64 `json:"infcode"`
  5555. Output struct {
  5556. Data struct {
  5557. IptOtpNo string `json:"ipt_otp_no"`
  5558. MdtrtID string `json:"mdtrt_id"`
  5559. PsnNo string `json:"psn_no"`
  5560. } `json:"data"`
  5561. } `json:"output"`
  5562. RefmsgTime string `json:"refmsg_time"`
  5563. RespondTime string `json:"respond_time"`
  5564. Signtype interface{} `json:"signtype"`
  5565. WarnMsg interface{} `json:"warn_msg"`
  5566. }
  5567. type ResultFour struct {
  5568. Cainfo string `json:"cainfo"`
  5569. ErrMsg string `json:"err_msg"`
  5570. InfRefmsgid string `json:"inf_refmsgid"`
  5571. Infcode int64 `json:"infcode"`
  5572. Output struct {
  5573. Result []struct {
  5574. BasMednFlag string `json:"bas_medn_flag"`
  5575. ChldMedcFlag string `json:"chld_medc_flag"`
  5576. ChrgitmLv string `json:"chrgitm_lv"`
  5577. Cnt float64 `json:"cnt"`
  5578. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5579. DrtReimFlag string `json:"drt_reim_flag"`
  5580. FeedetlSn string `json:"feedetl_sn"`
  5581. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5582. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5583. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5584. ListSpItemFlag string `json:"list_sp_item_flag"`
  5585. LmtUsedFlag string `json:"lmt_used_flag"`
  5586. MedChrgitmType string `json:"med_chrgitm_type"`
  5587. Memo string `json:"memo"`
  5588. OverlmtAmt float64 `json:"overlmt_amt"`
  5589. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5590. Pric float64 `json:"pric"`
  5591. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5592. SelfpayProp float64 `json:"selfpay_prop"`
  5593. } `json:"result"`
  5594. } `json:"output"`
  5595. RefmsgTime string `json:"refmsg_time"`
  5596. RespondTime string `json:"respond_time"`
  5597. Signtype string `json:"signtype"`
  5598. WarnMsg string `json:"warn_msg"`
  5599. }
  5600. type ResultFive struct {
  5601. Insutype string `json:"insutype"`
  5602. }
  5603. type ResultSix struct {
  5604. Cainfo interface{} `json:"cainfo"`
  5605. ErrMsg interface{} `json:"err_msg"`
  5606. InfRefmsgid string `json:"inf_refmsgid"`
  5607. Infcode int64 `json:"infcode"`
  5608. Output struct {
  5609. } `json:"output"`
  5610. RefmsgTime string `json:"refmsg_time"`
  5611. RespondTime string `json:"respond_time"`
  5612. Signtype interface{} `json:"signtype"`
  5613. WarnMsg interface{} `json:"warn_msg"`
  5614. }
  5615. type ResultSeven struct {
  5616. Cainfo string `json:"cainfo"`
  5617. ErrMsg string `json:"err_msg"`
  5618. InfRefmsgid string `json:"inf_refmsgid"`
  5619. Infcode int64 `json:"infcode"`
  5620. Output struct {
  5621. Setldetail []interface{} `json:"setldetail"`
  5622. Setlinfo struct {
  5623. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5624. AcctPay float64 `json:"acct_pay"`
  5625. ActPayDedc float64 `json:"act_pay_dedc"`
  5626. Age float64 `json:"age"`
  5627. Balc float64 `json:"balc"`
  5628. Brdy string `json:"brdy"`
  5629. Certno string `json:"certno"`
  5630. ClrOptins string `json:"clr_optins"`
  5631. ClrType string `json:"clr_type"`
  5632. ClrWay string `json:"clr_way"`
  5633. CvlservFlag string `json:"cvlserv_flag"`
  5634. CvlservPay float64 `json:"cvlserv_pay"`
  5635. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5636. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5637. Gend string `json:"gend"`
  5638. HifesPay float64 `json:"hifes_pay"`
  5639. HifmiPay float64 `json:"hifmi_pay"`
  5640. HifobPay float64 `json:"hifob_pay"`
  5641. HifpPay float64 `json:"hifp_pay"`
  5642. HospPartAmt float64 `json:"hosp_part_amt"`
  5643. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5644. Insutype string `json:"insutype"`
  5645. MafPay float64 `json:"maf_pay"`
  5646. MdtrtCertType string `json:"mdtrt_cert_type"`
  5647. MdtrtID string `json:"mdtrt_id"`
  5648. MedType string `json:"med_type"`
  5649. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5650. MedinsSetlID string `json:"medins_setl_id"`
  5651. Naty string `json:"naty"`
  5652. OthPay float64 `json:"oth_pay"`
  5653. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5654. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5655. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5656. PsnCashPay float64 `json:"psn_cash_pay"`
  5657. PsnCertType string `json:"psn_cert_type"`
  5658. PsnName string `json:"psn_name"`
  5659. PsnNo string `json:"psn_no"`
  5660. PsnPartAmt float64 `json:"psn_part_amt"`
  5661. PsnType string `json:"psn_type"`
  5662. SetlID string `json:"setl_id"`
  5663. SetlTime string `json:"setl_time"`
  5664. } `json:"setlinfo"`
  5665. } `json:"output"`
  5666. RefmsgTime string `json:"refmsg_time"`
  5667. RespondTime string `json:"respond_time"`
  5668. Signtype interface{} `json:"signtype"`
  5669. WarnMsg interface{} `json:"warn_msg"`
  5670. }
  5671. type ResultEight struct {
  5672. Cainfo string `json:"cainfo"`
  5673. ErrMsg string `json:"err_msg"`
  5674. InfRefmsgid string `json:"inf_refmsgid"`
  5675. Infcode int64 `json:"infcode"`
  5676. Output struct {
  5677. Stmtinfo struct {
  5678. SetlOptins string `json:"setl_optins"`
  5679. StmtRslt string `json:"stmt_rslt"`
  5680. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5681. } `json:"stmtinfo"`
  5682. } `json:"output"`
  5683. RefmsgTime string `json:"refmsg_time"`
  5684. RespondTime string `json:"respond_time"`
  5685. Signtype interface{} `json:"signtype"`
  5686. WarnMsg interface{} `json:"warn_msg"`
  5687. }
  5688. type ResultNine struct {
  5689. Cainfo string `json:"cainfo"`
  5690. ErrMsg string `json:"err_msg"`
  5691. InfRefmsgid string `json:"inf_refmsgid"`
  5692. Infcode int64 `json:"infcode"`
  5693. Output struct {
  5694. FileQuryNo string `json:"file_qury_no"`
  5695. } `json:"output"`
  5696. RefmsgTime string `json:"refmsg_time"`
  5697. RespondTime string `json:"respond_time"`
  5698. Signtype interface{} `json:"signtype"`
  5699. WarnMsg interface{} `json:"warn_msg"`
  5700. }
  5701. type ResultTen struct {
  5702. Cainfo string `json:"cainfo"`
  5703. ErrMsg string `json:"err_msg"`
  5704. InfRefmsgid string `json:"inf_refmsgid"`
  5705. Infcode int64 `json:"infcode"`
  5706. Output struct {
  5707. DldEndtime string `json:"dld_endtime"`
  5708. FileQuryNo string `json:"file_qury_no"`
  5709. Filename string `json:"filename"`
  5710. } `json:"output"`
  5711. RefmsgTime string `json:"refmsg_time"`
  5712. RespondTime string `json:"respond_time"`
  5713. Signtype interface{} `json:"signtype"`
  5714. WarnMsg interface{} `json:"warn_msg"`
  5715. }
  5716. type ResultEleven struct {
  5717. Cainfo string `json:"cainfo"`
  5718. ErrMsg string `json:"err_msg"`
  5719. InfRefmsgid string `json:"inf_refmsgid"`
  5720. Infcode int64 `json:"infcode"`
  5721. Output struct {
  5722. Setlinfo struct {
  5723. FixmedinsName string `json:"fixmedins_name"`
  5724. FixmedinsCode string `json:"fixmedins_code"`
  5725. PsnNo string `json:"psn_no"`
  5726. PsnName string `json:"psn_name"`
  5727. HifobPay float64 `json:"hifob_pay"`
  5728. Gend string `json:"gend"`
  5729. Brdy string `json:"brdy"`
  5730. PsnCertType string `json:"psn_cert_type"`
  5731. PsnType string `json:"psn_type"`
  5732. EmpName string `json:"emp_name"`
  5733. Certno string `json:"certno"`
  5734. Insutype string `json:"insutype"`
  5735. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5736. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5737. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5738. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5739. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5740. ActPayDedc float64 `json:"act_pay_dedc"`
  5741. HifpPay float64 `json:"hifp_pay"`
  5742. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5743. CvlservPay float64 `json:"cvlserv_pay"`
  5744. HifesPay float64 `json:"hifes_pay"`
  5745. HifmiPay float64 `json:"hifmi_pay"`
  5746. MafPay float64 `json:"maf_pay"`
  5747. OthPay float64 `json:"oth_pay"`
  5748. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5749. PsnPay float64 `json:"psn_pay"`
  5750. AcctPay float64 `json:"acct_pay"`
  5751. CashPayamt float64 `json:"cash_payamt"`
  5752. Balc float64 `json:"balc"`
  5753. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5754. MedinsSetlId string `json:"medins_setl_id"`
  5755. RefdSetlFlag string `json:"refd_setl_flag"`
  5756. SetlTime string `json:"setl_time"`
  5757. MedType string `json:"med_type"`
  5758. } `json:"setlinfo"`
  5759. } `json:"output"`
  5760. RefmsgTime string `json:"refmsg_time"`
  5761. RespondTime string `json:"respond_time"`
  5762. Signtype interface{} `json:"signtype"`
  5763. WarnMsg interface{} `json:"warn_msg"`
  5764. }
  5765. type Custom struct {
  5766. DetItemFeeSumamt string
  5767. Cut string
  5768. FeedetlSn string
  5769. Price string
  5770. MedListCodg string
  5771. Type int64
  5772. AdviceId int64
  5773. ProjectId int64
  5774. ItemId int64
  5775. }
  5776. // 获取个人信息----挂号-----上传就诊信息
  5777. func (c *HisApiController) GetRegisterInfo() {
  5778. id, _ := c.GetInt64("id")
  5779. record_time := c.GetString("record_time")
  5780. settlementValue, _ := c.GetInt64("settlement_value")
  5781. medical_insurance_card := c.GetString("medical_insurance_card")
  5782. name := c.GetString("name")
  5783. id_card_type, _ := c.GetInt64("id_card_type")
  5784. certificates, _ := c.GetInt64("certificates")
  5785. medical_care, _ := c.GetInt64("medical_care")
  5786. birthday := c.GetString("birthday")
  5787. age, _ := c.GetInt64("age")
  5788. id_card := c.GetString("id_card")
  5789. register_type, _ := c.GetInt64("register")
  5790. doctor, _ := c.GetInt64("doctor")
  5791. department, _ := c.GetInt64("department")
  5792. gender, _ := c.GetInt64("sex")
  5793. phone := c.GetString("phone")
  5794. registration_fee, _ := c.GetFloat("registration_fee")
  5795. medical_expenses, _ := c.GetFloat("medical_expenses")
  5796. social_type, _ := c.GetInt64("social_type")
  5797. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5798. diagnosis_ids := c.GetString("diagnosis")
  5799. sick_type, _ := c.GetInt64("sick_type")
  5800. reg_type := c.GetString("p_type")
  5801. timeLayout := "2006-01-02"
  5802. loc, _ := time.LoadLocation("Local")
  5803. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5804. birthUnix := birthdays.Unix()
  5805. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5806. if err != nil {
  5807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5808. return
  5809. }
  5810. recordDateTime := theTime.Unix()
  5811. adminInfo := c.GetAdminUserInfo()
  5812. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5813. if tempPatient.ID == 0 {
  5814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5815. return
  5816. }
  5817. var patient service.Patients
  5818. if id == 0 {
  5819. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5820. } else {
  5821. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5822. }
  5823. if patient.ID == 0 {
  5824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5825. return
  5826. }
  5827. if len(patient.IdCardNo) == 0 {
  5828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5829. return
  5830. }
  5831. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5832. if len(his) >= 1 {
  5833. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5834. if len(his) >= 1 && order.ID == 0 {
  5835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5836. return
  5837. }
  5838. }
  5839. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5840. fmt.Println(timeStr)
  5841. timeArr := strings.Split(timeStr, " ")
  5842. fmt.Println(timeArr)
  5843. timeArrTwo := strings.Split(timeArr[0], "-")
  5844. timeArrThree := strings.Split(timeArr[1], ":")
  5845. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5846. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5847. if len(lists) == 0 {
  5848. var hisPatient models.XtHisPatient
  5849. hisPatient = models.XtHisPatient{
  5850. Name: name,
  5851. Age: age,
  5852. Gender: gender,
  5853. Birthday: birthUnix,
  5854. Phone: phone,
  5855. MedicalTreatmentType: medical_care,
  5856. IdType: certificates,
  5857. IdCardNo: id_card,
  5858. BalanceAccountsType: settlementValue,
  5859. SocialType: social_type,
  5860. MedicalInsuranceNumber: medical_insurance_card,
  5861. RegisterType: register_type,
  5862. RegisterCost: registration_fee,
  5863. TreatmentCost: medical_expenses,
  5864. AdminUserId: adminInfo.AdminUser.Id,
  5865. UserOrgId: adminInfo.CurrentOrgId,
  5866. Status: 1,
  5867. RecordDate: recordDateTime,
  5868. IsReturn: 1,
  5869. PatientId: patient.ID,
  5870. Ctime: time.Now().Unix(),
  5871. Mtime: time.Now().Unix(),
  5872. Number: str,
  5873. IdCardType: id_card_type,
  5874. Departments: department,
  5875. Doctor: doctor,
  5876. PType: reg_type,
  5877. Diagnosis: diagnosis_ids,
  5878. SickType: sick_type,
  5879. }
  5880. service.CreateHisPatient(&hisPatient)
  5881. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5882. c.ServeSuccessJSON(map[string]interface{}{
  5883. "his_info": hisPatient,
  5884. })
  5885. } else {
  5886. //chrgBchno := rand.Intn(1000000) + 10000
  5887. var hisPatient models.XtHisPatient
  5888. hisPatient = models.XtHisPatient{
  5889. Name: name,
  5890. Age: age,
  5891. Gender: gender,
  5892. Birthday: birthUnix,
  5893. Phone: phone,
  5894. MedicalTreatmentType: medical_care,
  5895. IdType: certificates,
  5896. IdCardNo: id_card,
  5897. BalanceAccountsType: settlementValue,
  5898. SocialType: social_type,
  5899. MedicalInsuranceNumber: medical_insurance_card,
  5900. RegisterType: register_type,
  5901. RegisterCost: registration_fee,
  5902. TreatmentCost: medical_expenses,
  5903. AdminUserId: adminInfo.AdminUser.Id,
  5904. UserOrgId: adminInfo.CurrentOrgId,
  5905. Status: 1,
  5906. RecordDate: recordDateTime,
  5907. IsReturn: 1,
  5908. PatientId: patient.ID,
  5909. Ctime: time.Now().Unix(),
  5910. Mtime: time.Now().Unix(),
  5911. Number: str,
  5912. IdCardType: id_card_type,
  5913. Departments: department,
  5914. Doctor: doctor,
  5915. PType: reg_type,
  5916. Diagnosis: diagnosis_ids,
  5917. SickType: sick_type,
  5918. }
  5919. service.CreateHisPatient(&hisPatient)
  5920. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5921. c.ServeSuccessJSON(map[string]interface{}{
  5922. "his_info": hisPatient,
  5923. })
  5924. }
  5925. }
  5926. // 上传明细----结算
  5927. func (c *HisApiController) GetUploadInfo() {
  5928. id, _ := c.GetInt64("id")
  5929. record_time := c.GetString("record_time")
  5930. his_patient_id, _ := c.GetInt64("his_patient_id")
  5931. oth_desc := c.GetString("oth_desc")
  5932. pay_way, _ := c.GetInt64("pay_way")
  5933. pay_ways := c.GetString("pay_ways")
  5934. pay_price, _ := c.GetFloat("pay_price")
  5935. pay_card_no := c.GetString("pay_card_no")
  5936. discount_price, _ := c.GetFloat("discount_price")
  5937. preferential_price, _ := c.GetFloat("preferential_price")
  5938. reality_price, _ := c.GetFloat("reality_price")
  5939. found_price, _ := c.GetFloat("found_price")
  5940. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5941. private_price, _ := c.GetFloat("private_price")
  5942. timeLayout := "2006-01-02"
  5943. loc, _ := time.LoadLocation("Local")
  5944. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5945. fapiao_code := c.GetString("fapiao_code")
  5946. fapiao_number := c.GetString("fapiao_number")
  5947. diagnosis_id := c.GetString("diagnosis")
  5948. sick_type, _ := c.GetInt64("sick_type")
  5949. reg_type, _ := c.GetInt64("p_type")
  5950. order_id, _ := c.GetInt64("order_id")
  5951. cash_pay := c.GetString("cash_pay")
  5952. wechat_pay := c.GetString("wechat_pay")
  5953. ali_pay := c.GetString("ali_pay")
  5954. jifen_pay := c.GetString("jifen_pay")
  5955. band_card_pay := c.GetString("band_card_pay")
  5956. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5957. tmp_decimal := c.GetString("tmp_decimal")
  5958. var decimal float64 //本次使用的押金
  5959. var errmsg error
  5960. tx := service.XTWriteDB().Begin() //开了事务
  5961. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5962. defer func() {
  5963. if errmsg != nil {
  5964. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5965. tx.Rollback()
  5966. } else {
  5967. tx.Commit()
  5968. }
  5969. }()
  5970. fmt.Println("dec_way", dec_way)
  5971. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5972. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5973. return
  5974. }
  5975. if len(tmp_decimal) > 0 {
  5976. if tmp_decimal[0] == 45 {
  5977. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5978. return
  5979. }
  5980. }
  5981. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5982. fmt.Println(errs)
  5983. decimal = tt
  5984. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5985. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5986. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5987. if err != nil {
  5988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5989. return
  5990. }
  5991. recordDateTime := theTime.Unix()
  5992. adminUser := c.GetAdminUserInfo()
  5993. var prescriptions []*models.HisPrescription
  5994. var prescriptionsOne []*models.HisPrescription
  5995. var start_time int64
  5996. var end_time int64
  5997. ids_str := c.GetString("ids")
  5998. ids_arr := strings.Split(ids_str, ",")
  5999. if tempOrder.ID == 0 {
  6000. if settle_accounts_type == 1 { //日结
  6001. fmt.Println(reg_type)
  6002. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6003. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6004. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6005. } else {
  6006. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6007. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6008. }
  6009. } else { //月结
  6010. start_time_str := c.GetString("start_time")
  6011. end_time_str := c.GetString("end_time")
  6012. timeLayout := "2006-01-02"
  6013. loc, _ := time.LoadLocation("Local")
  6014. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6015. if err != nil {
  6016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6017. return
  6018. }
  6019. recordStartTime := theStartTime.Unix()
  6020. start_time = recordStartTime
  6021. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6022. if err != nil {
  6023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6024. return
  6025. }
  6026. recordEndTime := theEndTime.Unix()
  6027. end_time = recordEndTime
  6028. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6029. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6030. }
  6031. var goods []*models.DialysisBeforePrepareGoods
  6032. var newGoods []*models.NewDialysisBeforePrepareGoods
  6033. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6034. var infos []*models.HisDoctorAdviceInfo
  6035. var infoList []*models.HisDoctorAdviceInfo
  6036. var hisAdvice []*models.HisDoctorAdviceInfo
  6037. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6038. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6039. //判断库存不足
  6040. //结算出库开关
  6041. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6042. if settConfig.IsOpen == 1 {
  6043. //判断库存的地方
  6044. for _, info := range prescriptions {
  6045. if info.Type == 1 {
  6046. infos = append(infos, info.HisDoctorAdviceInfo...)
  6047. }
  6048. if info.Type == 2 {
  6049. for _, sumItem := range info.HisPrescriptionProject {
  6050. if sumItem.Type == 3 {
  6051. var good models.DialysisBeforePrepareGoods
  6052. var newGood models.NewDialysisBeforePrepareGoods
  6053. good.GoodId = sumItem.GoodInfo.ID
  6054. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6055. count, _ := strconv.Atoi(sumItem.Count)
  6056. good.Count = int64(count)
  6057. good.StorehouseId = houseConfig.StorehouseOutInfo
  6058. good.ProjectId = sumItem.ID
  6059. goods = append(goods, &good)
  6060. newGood.GoodId = sumItem.GoodInfo.ID
  6061. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6062. count2, _ := strconv.Atoi(sumItem.Count)
  6063. newGood.Count = int64(count2)
  6064. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6065. newGood.ProjectId = sumItem.ID
  6066. newGoods = append(newGoods, &newGood)
  6067. }
  6068. }
  6069. }
  6070. }
  6071. for _, info := range prescriptionsOne {
  6072. if info.Type == 1 {
  6073. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6074. }
  6075. if info.Type == 2 {
  6076. for _, sumItem := range info.HisPrescriptionProject {
  6077. if sumItem.Type == 3 {
  6078. var newGood models.NewDialysisBeforePrepareGoods
  6079. newGood.GoodId = sumItem.GoodInfo.ID
  6080. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6081. count2, _ := strconv.Atoi(sumItem.Count)
  6082. newGood.Count = int64(count2)
  6083. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6084. newGood.ProjectId = sumItem.ID
  6085. newGoodOne = append(newGoodOne, &newGood)
  6086. }
  6087. }
  6088. }
  6089. }
  6090. //判断
  6091. for _, itemOne := range infos {
  6092. for _, itemTwo := range hisAdvice {
  6093. if itemOne.DrugId == itemTwo.DrugId {
  6094. itemTwo.Child = append(itemTwo.Child, itemOne)
  6095. }
  6096. }
  6097. }
  6098. for _, itemTwo := range hisAdvice {
  6099. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6100. var sum_out_count int64
  6101. for _, itemThree := range itemTwo.Child {
  6102. var prescribing_number int64
  6103. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6104. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6105. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6106. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6107. }
  6108. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6109. prescribing_number = parseIntPrescribingNumber
  6110. }
  6111. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6112. prescribing_number = parseIntPrescribingNumber
  6113. }
  6114. sum_out_count += prescribing_number
  6115. }
  6116. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6117. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6118. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6119. if sum_out_count > drugStockOut.FlushCount {
  6120. c.ServeSuccessJSON(map[string]interface{}{
  6121. "msg": "2",
  6122. "drug": medical,
  6123. })
  6124. return
  6125. }
  6126. }
  6127. fmt.Println("newGoods99999988882os", newGoods)
  6128. for _, itemOne := range newGoods {
  6129. for _, item := range newGoodOne {
  6130. if itemOne.GoodId == item.GoodId {
  6131. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6132. }
  6133. }
  6134. }
  6135. for _, item := range newGoodOne {
  6136. var sum_out_count_one int64
  6137. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6138. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6139. sum_out_count_one += itemOne.Count
  6140. }
  6141. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6142. fmt.Println("sum_out_count_one", sum_out_count_one)
  6143. fmt.Println("list.FlushCount", list.FlushCount)
  6144. if sum_out_count_one > list.FlushCount {
  6145. c.ServeSuccessJSON(map[string]interface{}{
  6146. "msg": "3",
  6147. "good": good,
  6148. })
  6149. return
  6150. }
  6151. }
  6152. }
  6153. timestamp := time.Now().Unix()
  6154. tempTime := time.Unix(timestamp, 0)
  6155. timeFormat := tempTime.Format("20060102150405")
  6156. chrgBchno := rand.Intn(100000) + 10000
  6157. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6158. strconv.FormatInt(his.PatientId, 10)
  6159. var ids []int64
  6160. for _, item := range prescriptions {
  6161. ids = append(ids, item.ID)
  6162. }
  6163. var total float64
  6164. for _, item := range prescriptions {
  6165. fmt.Println(item)
  6166. if item.Type == 1 { //药品
  6167. for _, subItem := range item.HisDoctorAdviceInfo {
  6168. total = total + (subItem.Price * subItem.PrescribingNumber)
  6169. }
  6170. }
  6171. if item.Type == 2 { //项目
  6172. for _, subItem := range item.HisPrescriptionProject {
  6173. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6174. total = total + (subItem.Price * cnt)
  6175. }
  6176. }
  6177. for _, subItem := range item.HisAdditionalCharge {
  6178. total = total + (subItem.Price * float64(subItem.Count))
  6179. }
  6180. }
  6181. if reg_type == 1111 || reg_type == 1112 {
  6182. reg_type = 11
  6183. }
  6184. tm := time.Unix(time.Now().Unix(), 0)
  6185. allTotal := fmt.Sprintf("%.4f", total)
  6186. totals, _ := strconv.ParseFloat(allTotal, 64)
  6187. order := &models.HisOrder{
  6188. UserOrgId: adminUser.CurrentOrgId,
  6189. HisPatientId: his.ID,
  6190. PatientId: id,
  6191. SettleAccountsDate: recordDateTime,
  6192. Ctime: time.Now().Unix(),
  6193. Mtime: time.Now().Unix(),
  6194. Status: 1,
  6195. OrderStatus: 2,
  6196. MdtrtId: his.Number,
  6197. Number: chrg_bchno,
  6198. MedfeeSumamt: totals,
  6199. PayWay: pay_way,
  6200. PayWays: pay_ways,
  6201. PayPrice: pay_price,
  6202. MedType: strconv.Itoa(int(reg_type)),
  6203. PayCardNo: pay_card_no,
  6204. DiscountPrice: discount_price,
  6205. PreferentialPrice: preferential_price,
  6206. RealityPrice: reality_price,
  6207. FoundPrice: found_price,
  6208. MedicalInsurancePrice: medical_insurance_price,
  6209. PrivatePrice: private_price,
  6210. SettleEndTime: end_time,
  6211. SettleStartTime: start_time,
  6212. PsnPartAmt: totals,
  6213. PsnCashPay: totals,
  6214. SettleType: settle_accounts_type,
  6215. FaPiaoCode: fapiao_code,
  6216. FaPiaoNumber: fapiao_number,
  6217. Diagnosis: diagnosis_id,
  6218. PType: 2,
  6219. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6220. Decimal: decimal,
  6221. OthDesc: oth_desc,
  6222. CashPay: cash_pay,
  6223. WechatPay: wechat_pay,
  6224. AliPay: ali_pay,
  6225. JifenPay: jifen_pay,
  6226. BandCardPay: band_card_pay,
  6227. }
  6228. err = service.CreateOrderTX(order, tx)
  6229. if err != nil {
  6230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6231. return
  6232. }
  6233. var customs []*Custom
  6234. for _, item := range prescriptions {
  6235. if item.Type == 1 { //药品a
  6236. for _, subItem := range item.HisDoctorAdviceInfo {
  6237. cus := &Custom{
  6238. AdviceId: subItem.ID,
  6239. ProjectId: 0,
  6240. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6241. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6242. FeedetlSn: subItem.FeedetlSn,
  6243. Price: fmt.Sprintf("%.4f", subItem.Price),
  6244. MedListCodg: subItem.MedListCodg,
  6245. Type: 1,
  6246. }
  6247. customs = append(customs, cus)
  6248. }
  6249. }
  6250. if item.Type == 2 { //项目
  6251. for _, subItem := range item.HisPrescriptionProject {
  6252. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6253. cus := &Custom{
  6254. AdviceId: 0,
  6255. ProjectId: subItem.ID,
  6256. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6257. Cut: fmt.Sprintf("%.4f", cnt),
  6258. FeedetlSn: subItem.FeedetlSn,
  6259. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6260. MedListCodg: subItem.MedListCodg,
  6261. Type: 2,
  6262. }
  6263. customs = append(customs, cus)
  6264. }
  6265. }
  6266. for _, item := range item.HisAdditionalCharge {
  6267. cus := &Custom{
  6268. ItemId: item.ID,
  6269. AdviceId: 0,
  6270. ProjectId: 0,
  6271. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6272. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6273. FeedetlSn: item.FeedetlSn,
  6274. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6275. MedListCodg: item.XtHisAddtionConfig.Code,
  6276. Type: 3,
  6277. }
  6278. customs = append(customs, cus)
  6279. }
  6280. }
  6281. for _, item := range customs {
  6282. var advice_id int64 = 0
  6283. var project_id int64 = 0
  6284. var item_id int64 = 0
  6285. var types int64 = 0
  6286. if item.Type == 1 {
  6287. advice_id = item.AdviceId
  6288. project_id = 0
  6289. item_id = 0
  6290. } else if item.Type == 2 {
  6291. advice_id = 0
  6292. item_id = 0
  6293. project_id = item.ProjectId
  6294. } else if item.Type == 3 {
  6295. advice_id = 0
  6296. item_id = item.ItemId
  6297. project_id = 0
  6298. }
  6299. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6300. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6301. pric, _ := strconv.ParseFloat(item.Price, 32)
  6302. info := &models.HisOrderInfo{
  6303. OrderNumber: order.Number,
  6304. UploadDate: time.Now().Unix(),
  6305. AdviceId: advice_id,
  6306. DetItemFeeSumamt: detItemFeeSumamt,
  6307. Cnt: cut,
  6308. Pric: pric,
  6309. PatientId: id,
  6310. Status: 1,
  6311. Mtime: time.Now().Unix(),
  6312. Ctime: time.Now().Unix(),
  6313. UserOrgId: adminUser.CurrentOrgId,
  6314. HisPatientId: his.ID,
  6315. OrderId: order.ID,
  6316. ProjectId: project_id,
  6317. Type: types,
  6318. ItemId: item_id,
  6319. }
  6320. service.CreateOrderInfoTX(info, tx)
  6321. }
  6322. his.Diagnosis = diagnosis_id
  6323. his.SickType = sick_type
  6324. his.RegisterType = reg_type
  6325. his.MedicalTreatmentType = reg_type
  6326. service.UpdataHisPateintTX(&his, tx)
  6327. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6328. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6329. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6330. //判断是否使用了押金
  6331. if dec_way == "true" {
  6332. tmpstring := strconv.FormatInt(order.ID, 10)
  6333. //扣押金
  6334. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6335. order.Decimal = decimal
  6336. service.UpDateOrderTwo(order, tx)
  6337. if errmsg != nil {
  6338. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6339. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6340. return
  6341. }
  6342. }
  6343. if err == nil {
  6344. for _, info := range prescriptions {
  6345. if info.Type == 1 {
  6346. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6347. }
  6348. if info.Type == 2 {
  6349. for _, sumItem := range info.HisPrescriptionProject {
  6350. if sumItem.Type == 3 {
  6351. var good models.DialysisBeforePrepareGoods
  6352. var newGood models.NewDialysisBeforePrepareGoods
  6353. var oldGood models.OldDialysisBeforePrepareGoods
  6354. good.GoodId = sumItem.GoodInfo.ID
  6355. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6356. count, _ := strconv.Atoi(sumItem.Count)
  6357. good.Count = int64(count)
  6358. good.StorehouseId = houseConfig.StorehouseOutInfo
  6359. good.ProjectId = sumItem.ID
  6360. good.PatientId = sumItem.PatientId
  6361. goods = append(goods, &good)
  6362. newGood.GoodId = sumItem.GoodInfo.ID
  6363. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6364. count2, _ := strconv.Atoi(sumItem.Count)
  6365. newGood.Count = int64(count2)
  6366. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6367. newGood.ProjectId = sumItem.ID
  6368. newGood.PatientId = sumItem.HisPatientId
  6369. newGoods = append(newGoods, &newGood)
  6370. oldGood.GoodId = sumItem.GoodInfo.ID
  6371. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6372. count3, _ := strconv.Atoi(sumItem.Count)
  6373. oldGood.Count = int64(count3)
  6374. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6375. oldGood.ProjectId = sumItem.ID
  6376. oldGood.RecordDate = sumItem.RecordDate
  6377. oldGood.PatientId = sumItem.HisPatientId
  6378. oldGoods = append(oldGoods, &oldGood)
  6379. }
  6380. }
  6381. }
  6382. }
  6383. if settConfig.IsOpen == 1 {
  6384. for _, item := range infoList {
  6385. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6386. if medical.IsUse == 2 {
  6387. //药品出库
  6388. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6389. //查询默认仓库
  6390. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6391. //查询默认仓库剩余多少库存
  6392. var sum_count int64
  6393. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6394. for _, its := range stockInfo {
  6395. if its.MaxUnit == medical.MaxUnit {
  6396. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6397. }
  6398. sum_count += its.StockMaxNumber + its.StockMinNumber
  6399. }
  6400. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6401. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6402. }
  6403. }
  6404. orgId := c.GetAdminUserInfo().CurrentOrgId
  6405. if len(oldGoods) > 0 {
  6406. timeStr := time.Now().Format("2006-01-02")
  6407. timeArr := strings.Split(timeStr, "-")
  6408. total, _ := service.FindAllWarehouseOut(orgId)
  6409. total = total + 1
  6410. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6411. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6412. number = number + total
  6413. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6414. operation_time := time.Now().Unix()
  6415. creater := c.GetAdminUserInfo().AdminUser.Id
  6416. //查询默认出库仓库库存
  6417. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6418. recordDateStr := time.Now().Format("2006-01-02")
  6419. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6420. nowtime := recordDate.Unix()
  6421. warehouseOut := models.WarehouseOut{
  6422. WarehouseOutOrderNumber: warehousing_out_order,
  6423. OperationTime: operation_time,
  6424. OrgId: orgId,
  6425. Creater: creater,
  6426. Ctime: time.Now().Unix(),
  6427. Status: 1,
  6428. WarehouseOutTime: nowtime,
  6429. Type: 1,
  6430. StorehouseId: storeConfig.StorehouseOutInfo,
  6431. IsCheck: 1,
  6432. OrderId: order.ID,
  6433. IsSys: 5,
  6434. }
  6435. //查询是否生成出库单
  6436. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6437. if out.ID == 0 {
  6438. service.AddSigleWarehouseOut(&warehouseOut)
  6439. }
  6440. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6441. for _, item := range oldGoods {
  6442. dialyPrepareOne := models.DialysisBeforePrepare{
  6443. GoodTypeId: item.GoodTypeId,
  6444. GoodId: item.GoodId,
  6445. PatientId: his.PatientId,
  6446. RecordDate: item.RecordDate,
  6447. UserOrgId: adminUser.CurrentOrgId,
  6448. Count: item.Count,
  6449. Ctime: time.Now().Unix(),
  6450. Creater: adminUser.AdminUser.Id,
  6451. CommdityCode: item.CommdityCode,
  6452. Status: 1,
  6453. StorehouseId: houseConfig.StorehouseOutInfo,
  6454. }
  6455. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6456. //非零用
  6457. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6458. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6459. //查询剩余库存
  6460. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6461. var sum_count int64
  6462. for _, item := range goodList {
  6463. sum_count += item.StockCount
  6464. }
  6465. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6466. //耗材
  6467. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6468. }
  6469. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6470. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6471. //查询剩余库存
  6472. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6473. var sum_count int64
  6474. for _, item := range goodList {
  6475. sum_count += item.StockCount
  6476. }
  6477. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6478. //耗材
  6479. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6480. }
  6481. }
  6482. }
  6483. }
  6484. c.ServeSuccessJSON(map[string]interface{}{
  6485. "msg": "结算成功",
  6486. })
  6487. }
  6488. }
  6489. }
  6490. // 退款
  6491. func (c *HisApiController) Refund() {
  6492. order_id, _ := c.GetInt64("order_id")
  6493. order, _ := service.GetHisOrderByID(order_id)
  6494. adminUser := c.GetAdminUserInfo()
  6495. orgid := c.GetAdminUserInfo().CurrentOrgId
  6496. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6497. if err != nil {
  6498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6499. return
  6500. }
  6501. tmp := strconv.FormatInt(order.ID, 10)
  6502. //当押金不为零时产生退费记录
  6503. if order.Decimal != 0 {
  6504. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6505. if err != nil {
  6506. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6507. return
  6508. }
  6509. }
  6510. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6511. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6512. var goods []*models.DialysisBeforePrepareGoods
  6513. var newGoods []*models.NewDialysisBeforePrepareGoods
  6514. var infos []*models.HisDoctorAdviceInfo
  6515. for _, info := range orders {
  6516. if info.AdviceId > 0 && info.ProjectId == 0 {
  6517. infos = append(infos, &info.HisDoctorAdviceInfo)
  6518. }
  6519. if info.ProjectId > 0 && info.AdviceId == 0 {
  6520. if info.HisPrescriptionProject.Type == 3 {
  6521. var good models.DialysisBeforePrepareGoods
  6522. var newGood models.NewDialysisBeforePrepareGoods
  6523. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6524. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6525. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6526. good.Count = int64(count)
  6527. good.StorehouseId = houseConfig.StorehouseOutInfo
  6528. good.ProjectId = info.HisPrescriptionProject.ID
  6529. good.PatientId = info.PatientId
  6530. good.OrderId = order_id
  6531. goods = append(goods, &good)
  6532. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6533. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6534. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6535. newGood.Count = int64(count2)
  6536. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6537. newGood.ProjectId = info.HisPrescriptionProject.ID
  6538. newGood.RecordDate = order.SettleAccountsDate
  6539. newGood.UserOrgId = order.UserOrgId
  6540. newGood.PatientId = info.PatientId
  6541. newGood.OrderId = order_id
  6542. newGoods = append(newGoods, &newGood)
  6543. }
  6544. }
  6545. }
  6546. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6547. if settConfig.IsOpen == 1 {
  6548. for _, item := range infos {
  6549. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6550. }
  6551. for _, item := range newGoods {
  6552. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6553. }
  6554. }
  6555. c.ServeSuccessJSON(map[string]interface{}{
  6556. "msg": "退费成功",
  6557. })
  6558. }
  6559. func (c *HisApiController) RefundNumber() {
  6560. his_patient_id, _ := c.GetInt64("id")
  6561. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6562. info.Status = 0
  6563. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6564. if count > 0 {
  6565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6566. return
  6567. }
  6568. err := service.SaveHisPatient(info)
  6569. if err == nil {
  6570. c.ServeSuccessJSON(map[string]interface{}{
  6571. "msg": "退号成功",
  6572. })
  6573. } else {
  6574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6575. return
  6576. }
  6577. }
  6578. func (this *HisApiController) AdditionalCharge() {
  6579. dataBody := make(map[string]interface{}, 0)
  6580. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6581. fmt.Println(err)
  6582. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6583. patient_id := int64(dataBody["patient_id"].(float64))
  6584. medicineData, _ := dataBody["medicineData"].([]interface{})
  6585. adminUserInfo := this.GetAdminUserInfo()
  6586. orgId := adminUserInfo.CurrentOrgId
  6587. admin_user_id := adminUserInfo.AdminUser.Id
  6588. timeStr := time.Now().Format("2006-01-02")
  6589. timeLayout := "2006-01-02 15:04:05"
  6590. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6591. timenow := timeStringToTime.Unix()
  6592. var additionalCharges []*models.HisAdditionalCharge
  6593. for _, item := range medicineData {
  6594. var randNum int
  6595. randNum = rand.Intn(10000) + 1000
  6596. timestamp := time.Now().Unix()
  6597. tempTime := time.Unix(timestamp, 0)
  6598. timeFormat := tempTime.Format("20060102150405")
  6599. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6600. items := item.(map[string]interface{})
  6601. money := items["price"].(string)
  6602. item_id_str := items["item_id"].(string)
  6603. name := items["name"].(string)
  6604. id_str := items["id"].(string)
  6605. moneys, _ := strconv.ParseInt(money, 10, 64)
  6606. monStr := strconv.FormatInt(moneys, 10)
  6607. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6608. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6609. id, _ := strconv.ParseInt(id_str, 10, 64)
  6610. additionalCharge := &models.HisAdditionalCharge{
  6611. ID: id,
  6612. HisPatientId: his_patient_id,
  6613. UserOrgId: orgId,
  6614. PatientId: patient_id,
  6615. RecordDate: timenow,
  6616. Price: monneyStr,
  6617. Status: 1,
  6618. ItemName: name,
  6619. ItemId: item_id,
  6620. AdminUserId: admin_user_id,
  6621. CreatedTime: time.Now().Unix(),
  6622. OrderStatus: 0,
  6623. PrescriptionNumber: "",
  6624. BatchNumber: "",
  6625. FeedetlSn: p_number,
  6626. }
  6627. service.CreateAdditionalCharge(additionalCharge)
  6628. additionalCharges = append(additionalCharges, additionalCharge)
  6629. }
  6630. this.ServeSuccessJSON(map[string]interface{}{
  6631. "msg": "添加成功",
  6632. "additional_charges": additionalCharges,
  6633. })
  6634. }
  6635. func (this *HisApiController) DeleteAddition() {
  6636. id, _ := this.GetInt64("id")
  6637. //TODO 需要判断是否已经结算
  6638. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6639. if err == nil {
  6640. this.ServeSuccessJSON(map[string]interface{}{
  6641. "msg": "删除成功",
  6642. })
  6643. return
  6644. } else {
  6645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6646. return
  6647. }
  6648. }
  6649. func (this *HisApiController) GetAdminUsers() {
  6650. adminUser := this.GetAdminUserInfo()
  6651. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6652. this.ServeSuccessJSON(map[string]interface{}{
  6653. "doctors": doctors,
  6654. })
  6655. }
  6656. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6657. change_type, _ := this.GetInt64("type", 0)
  6658. record_date := this.GetString("record_time")
  6659. patient_id, _ := this.GetInt64("patient_id", 0)
  6660. p_type, _ := this.GetInt64("p_type", 0)
  6661. timeLayout := "2006-01-02"
  6662. loc, _ := time.LoadLocation("Local")
  6663. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6664. record_time := theAdviceRecordTime.Unix()
  6665. adminUserInfo := this.GetAdminUserInfo()
  6666. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6667. if err == nil {
  6668. if len(prescriptions) == 0 {
  6669. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6670. return
  6671. } else {
  6672. this.ServeSuccessJSON(map[string]interface{}{
  6673. "prescriptions": prescriptions,
  6674. })
  6675. return
  6676. }
  6677. } else {
  6678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6679. return
  6680. }
  6681. }
  6682. func (this *HisApiController) GetCallHisPrescription() {
  6683. patient_id, _ := this.GetInt64("patient_id", 0)
  6684. timeLayout := "2006-01-02"
  6685. loc, _ := time.LoadLocation("Local")
  6686. start_time := this.GetString("start_time")
  6687. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6688. end_time := this.GetString("end_time")
  6689. p_type, _ := this.GetInt64("p_type")
  6690. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6691. adminUserInfo := this.GetAdminUserInfo()
  6692. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6693. if err == nil {
  6694. this.ServeSuccessJSON(map[string]interface{}{
  6695. "prescriptions": prescriptions,
  6696. })
  6697. return
  6698. } else {
  6699. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6700. return
  6701. }
  6702. }
  6703. func (this *HisApiController) GetHisDayPrescription() {
  6704. timeLayout := "2006-01-02"
  6705. loc, _ := time.LoadLocation("Local")
  6706. start_time := this.GetString("start_time")
  6707. patient_id, _ := this.GetInt64("patient_id", 0)
  6708. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6709. end_time := this.GetString("end_time")
  6710. p_type, _ := this.GetInt64("p_type")
  6711. order_status, _ := this.GetInt64("type")
  6712. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6713. adminUserInfo := this.GetAdminUserInfo()
  6714. var dayHisPrescription []*models.HisPrescription
  6715. var err error
  6716. if order_status == 1 || order_status == 0 {
  6717. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6718. } else if order_status == 2 {
  6719. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6720. }
  6721. var settle_total float64
  6722. for _, item := range dayHisPrescription {
  6723. if len(item.HisPrescriptionProject) > 0 {
  6724. for _, subItem := range item.HisPrescriptionProject {
  6725. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6726. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6727. settle_total = settle_total + total
  6728. }
  6729. }
  6730. if len(item.HisDoctorAdviceInfo) > 0 {
  6731. for _, subItem := range item.HisDoctorAdviceInfo {
  6732. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6733. settle_total = settle_total + total
  6734. }
  6735. }
  6736. }
  6737. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6738. if err == nil {
  6739. this.ServeSuccessJSON(map[string]interface{}{
  6740. "day_prescription": dayHisPrescription,
  6741. "settle_total": settle_total,
  6742. })
  6743. return
  6744. } else {
  6745. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6746. return
  6747. }
  6748. }
  6749. func (c *HisApiController) GetHisChargePatientList() {
  6750. record_date := c.GetString("record_date")
  6751. order_status, _ := c.GetInt64("type")
  6752. timeLayout := "2006-01-02"
  6753. loc, _ := time.LoadLocation("Local")
  6754. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6755. if err != nil {
  6756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6757. return
  6758. }
  6759. recordDateTime := theTime.Unix()
  6760. adminInfo := c.GetAdminUserInfo()
  6761. var tempPatients []*service.NewTempPatients
  6762. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6763. if order_status != 2 {
  6764. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6765. } else {
  6766. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6767. }
  6768. var patients []*service.NewTempPatients
  6769. var patients_two []*service.NewTempPatients
  6770. for _, item := range tempPatients {
  6771. //过滤掉没挂号的和没开处方的
  6772. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6773. patients = append(patients, item)
  6774. }
  6775. //过滤掉没挂号的
  6776. if len(item.HisPatient) > 0 {
  6777. patients_two = append(patients_two, item)
  6778. }
  6779. }
  6780. c.ServeSuccessJSON(map[string]interface{}{
  6781. "list": patients,
  6782. "list_two": patients_two,
  6783. })
  6784. }
  6785. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6786. record_date := c.GetString("record_date")
  6787. timeLayout := "2006-01-02"
  6788. loc, _ := time.LoadLocation("Local")
  6789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6790. if err != nil {
  6791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6792. return
  6793. }
  6794. recordDateTime := theTime.Unix()
  6795. adminUser := c.GetAdminUserInfo()
  6796. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6797. var patients []*service.Patients
  6798. for _, item := range tempPatients {
  6799. if item.HisPatient.ID == 0 {
  6800. patients = append(patients, item)
  6801. }
  6802. }
  6803. c.ServeSuccessJSON(map[string]interface{}{
  6804. "list": patients,
  6805. //"list_two": patients_two,
  6806. })
  6807. }
  6808. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6809. newArr = make([]*service.Patients, 0)
  6810. for i := 0; i < len(patient); i++ {
  6811. repeat := false
  6812. for j := i + 1; j < len(patient); j++ {
  6813. if patient[i].ID == patient[j].ID {
  6814. repeat = true
  6815. break
  6816. }
  6817. }
  6818. if !repeat {
  6819. newArr = append(newArr, patient[i])
  6820. }
  6821. }
  6822. return
  6823. }
  6824. func (c *HisApiController) GetHisChargePatientInfo() {
  6825. patient_id, _ := c.GetInt64("patient_id")
  6826. his_patient_id, _ := c.GetInt64("his_patient_id")
  6827. record_date := c.GetString("record_date")
  6828. //start_time := c.GetString("start_time")
  6829. //end_time := c.GetString("end_time")
  6830. order_status, _ := c.GetInt64("type", 0)
  6831. p_type, _ := c.GetInt64("p_type", 0)
  6832. order_id, _ := c.GetInt64("order_id", 0)
  6833. timeLayout := "2006-01-02"
  6834. loc, _ := time.LoadLocation("Local")
  6835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6836. if err != nil {
  6837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6838. return
  6839. }
  6840. recordDateTime := theTime.Unix()
  6841. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6842. //if err != nil {
  6843. //
  6844. //}
  6845. //startRecordDateTime := startTime.Unix()
  6846. //
  6847. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6848. //if err != nil {
  6849. //
  6850. //}
  6851. //endRecordDateTime := endTime.Unix()
  6852. admin := c.GetAdminUserInfo()
  6853. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6854. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6855. var prescriptions []*models.HisPrescription
  6856. //var unChargeMonthPrescriptions []*models.HisPrescription
  6857. order, _ := service.GetHisOrderByID(order_id)
  6858. if order_status == 1 || order_status == 0 {
  6859. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6860. } else if order_status == 2 {
  6861. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6862. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6863. }
  6864. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6865. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6866. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6867. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6868. //获取所有科室信息
  6869. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6870. c.ServeSuccessJSON(map[string]interface{}{
  6871. "his_info": his_patient_info,
  6872. "xt_info": xt_patient_info,
  6873. "prescription": prescriptions,
  6874. "case_history": case_history,
  6875. "info": patientPrescriptionInfo,
  6876. "last_info": lastPatientPrescriptionInfo,
  6877. "order": order,
  6878. "doctors": doctors,
  6879. "department": department,
  6880. })
  6881. return
  6882. }
  6883. func (c *HisApiController) GetAllOrderDetail() {
  6884. order_id, _ := c.GetInt64("id", 0)
  6885. order, _ := service.GetHisOrderByID(order_id)
  6886. if order.ID == 0 {
  6887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6888. return
  6889. }
  6890. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6891. org_id := c.GetAdminUserInfo().CurrentOrgId
  6892. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6893. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6894. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6895. c.ServeSuccessJSON(map[string]interface{}{
  6896. "order": order,
  6897. "order_info": order_info,
  6898. "patient": patient,
  6899. "admin_info": adminInfo,
  6900. "hospital_record": record,
  6901. })
  6902. return
  6903. }
  6904. func (c *HisApiController) GetAllOrderDetailCollect() {
  6905. order_id, _ := c.GetInt64("id", 0)
  6906. order, _ := service.GetHisOrderByID(order_id)
  6907. if order.ID == 0 {
  6908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6909. return
  6910. }
  6911. org_id := c.GetAdminUserInfo().CurrentOrgId
  6912. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6913. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6914. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  6915. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6916. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6917. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6918. var bedCostTotal float64 = 0 //床位总费
  6919. //var bedCostSelfTotal float64 = 0 //床位自费
  6920. var operationCostTotal float64 = 0 //手术费
  6921. //var operationCostSelfTotal float64 = 0 //手术费
  6922. var otherCostTotal float64 = 0 //其他费用
  6923. //var otherCostSelfTotal float64 = 0 //其他费用
  6924. var materialCostTotal float64 = 0 //材料费
  6925. //var materialCostSelfTotal float64 = 0 //材料费
  6926. var westernMedicineCostTotal float64 = 0 //西药费
  6927. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6928. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6929. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6930. var checkCostTotal float64 = 0 //检查费
  6931. //var checkCostSelfTotal float64 = 0 //检查费
  6932. var laboratoryCostTotal float64 = 0 //化验费
  6933. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6934. var treatCostTotal float64 = 0 //治疗费用
  6935. //var treatCostSelfTotal float64 = 0 //治疗费用
  6936. var zhenChaCostTotal float64 = 0 //其他费用
  6937. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6938. decimal.DivisionPrecision = 2
  6939. var BalanceAccountsType int64
  6940. if his.ID > 0 {
  6941. BalanceAccountsType = his.BalanceAccountsType
  6942. } else {
  6943. BalanceAccountsType = record.BalanceAccountsType
  6944. }
  6945. if BalanceAccountsType != 2 {
  6946. for _, item := range order_info {
  6947. if org_id == 10215 {
  6948. if item.MedChrgitmType == "01" { //床位费
  6949. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6950. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6951. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6952. }
  6953. if item.MedChrgitmType == "02" { //诊察费
  6954. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6955. //zhenChaCostSelfTotal = zhenChaCostTotal
  6956. }
  6957. if item.MedChrgitmType == "03" { //检查费
  6958. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6959. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6960. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6961. }
  6962. //if item.MedChrgitmType == "02" { //检查费
  6963. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6964. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6965. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6966. //}
  6967. if item.MedChrgitmType == "04" { //化验费
  6968. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6969. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6970. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6971. }
  6972. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6973. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6974. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6975. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6976. }
  6977. if item.MedChrgitmType == "06" { //手术费
  6978. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6979. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6980. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6981. }
  6982. if item.MedChrgitmType == "08" { //材料费
  6983. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6984. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6985. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6986. }
  6987. if item.MedChrgitmType == "09" { //西药费
  6988. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6989. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6990. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6991. }
  6992. if item.MedChrgitmType == "11" { //中成费
  6993. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6994. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6995. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6996. }
  6997. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6998. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6999. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7000. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7001. }
  7002. } else if org_id == 10188 || org_id == 10217 {
  7003. if item.MedChrgitmType == "01" { //床位费
  7004. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7005. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7006. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7007. }
  7008. if item.MedChrgitmType == "02" { //诊察费
  7009. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7010. //zhenChaCostSelfTotal = zhenChaCostTotal
  7011. }
  7012. if item.MedChrgitmType == "03" { //检查费
  7013. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7014. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7015. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7016. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7017. }
  7018. //if item.MedChrgitmType == "02" { //检查费
  7019. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7020. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7021. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7022. //}
  7023. if item.MedChrgitmType == "04" { //化验费
  7024. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7025. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7026. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7027. }
  7028. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7029. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7030. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7031. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7032. }
  7033. if item.MedChrgitmType == "06" { //手术费
  7034. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7035. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7036. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7037. }
  7038. if item.MedChrgitmType == "08" { //材料费
  7039. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7040. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7041. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7042. }
  7043. if item.MedChrgitmType == "09" { //西药费
  7044. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7045. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7046. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7047. }
  7048. if item.MedChrgitmType == "11" { //中成费
  7049. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7050. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7051. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7052. }
  7053. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7054. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7055. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7056. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7057. }
  7058. } else {
  7059. if item.MedChrgitmType == "01" { //床位费
  7060. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7061. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7062. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7063. }
  7064. //if item.MedChrgitmType == "02" { //诊察费
  7065. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7066. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7067. //}
  7068. if item.MedChrgitmType == "03" { //检查费
  7069. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7070. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7071. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7072. }
  7073. //if item.MedChrgitmType == "02" { //检查费
  7074. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7075. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7076. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7077. //}
  7078. if item.MedChrgitmType == "04" { //化验费
  7079. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7080. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7081. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7082. }
  7083. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7084. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7085. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7086. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7087. }
  7088. if item.MedChrgitmType == "06" { //手术费
  7089. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7090. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7091. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7092. }
  7093. if item.MedChrgitmType == "08" { //材料费
  7094. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7095. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7096. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7097. }
  7098. if item.MedChrgitmType == "09" { //西药费
  7099. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7100. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7101. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7102. }
  7103. if item.MedChrgitmType == "11" { //中成费
  7104. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7105. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7106. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7107. }
  7108. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7109. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7110. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7111. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7112. }
  7113. }
  7114. }
  7115. c.ServeSuccessJSON(map[string]interface{}{
  7116. "order": order,
  7117. "order_info": order_info,
  7118. "patient": patient,
  7119. "admin_info": adminInfo,
  7120. "his_hospital": record,
  7121. "bedCostTotal": bedCostTotal,
  7122. "operationCostTotal": operationCostTotal,
  7123. "otherCostTotal": otherCostTotal,
  7124. "materialCostTotal": materialCostTotal,
  7125. "westernMedicineCostTotal": westernMedicineCostTotal,
  7126. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7127. "checkCostTotal": checkCostTotal,
  7128. "zhenChaCostTotal": zhenChaCostTotal,
  7129. "laboratoryCostTotal": laboratoryCostTotal,
  7130. "treatCostTotal": treatCostTotal,
  7131. })
  7132. } else {
  7133. for _, item := range order_info {
  7134. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7135. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7136. item.MedChrgitmType = "09"
  7137. }
  7138. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7139. if item.HisPrescriptionProject.Type == 2 {
  7140. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7141. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7142. case 0:
  7143. item.MedChrgitmType = "0"
  7144. break
  7145. case 1:
  7146. item.MedChrgitmType = "14"
  7147. break
  7148. case 2:
  7149. item.MedChrgitmType = "05"
  7150. break
  7151. case 3:
  7152. item.MedChrgitmType = "03"
  7153. break
  7154. case 4:
  7155. item.MedChrgitmType = "03"
  7156. break
  7157. case 5:
  7158. item.MedChrgitmType = "08"
  7159. break
  7160. case 6:
  7161. item.MedChrgitmType = "14"
  7162. break
  7163. case 7:
  7164. item.MedChrgitmType = "14"
  7165. break
  7166. case 8:
  7167. item.MedChrgitmType = "03"
  7168. break
  7169. case 9:
  7170. item.MedChrgitmType = "14"
  7171. break
  7172. case 10:
  7173. item.MedChrgitmType = "14"
  7174. break
  7175. case 11:
  7176. item.MedChrgitmType = "06"
  7177. break
  7178. case 12:
  7179. item.MedChrgitmType = "12"
  7180. break
  7181. case 13:
  7182. item.MedChrgitmType = "01"
  7183. break
  7184. case 14:
  7185. item.MedChrgitmType = "04"
  7186. break
  7187. case 15:
  7188. item.MedChrgitmType = "14"
  7189. break
  7190. }
  7191. } else {
  7192. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7193. case 1:
  7194. item.MedChrgitmType = "14"
  7195. break
  7196. case 2:
  7197. item.MedChrgitmType = "05"
  7198. break
  7199. case 3:
  7200. item.MedChrgitmType = "04"
  7201. break
  7202. case 4:
  7203. item.MedChrgitmType = "14"
  7204. break
  7205. case 5:
  7206. item.MedChrgitmType = "08"
  7207. break
  7208. case 6:
  7209. item.MedChrgitmType = "14"
  7210. break
  7211. case 7:
  7212. item.MedChrgitmType = "14"
  7213. break
  7214. case 8:
  7215. item.MedChrgitmType = "03"
  7216. break
  7217. case 9:
  7218. item.MedChrgitmType = "14"
  7219. break
  7220. }
  7221. }
  7222. } else if item.HisPrescriptionProject.Type == 3 {
  7223. item.MedChrgitmType = "08"
  7224. }
  7225. }
  7226. }
  7227. for _, item := range order_info {
  7228. if org_id == 10215 {
  7229. if item.MedChrgitmType == "01" { //床位费
  7230. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7231. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7232. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7233. }
  7234. if item.MedChrgitmType == "02" { //诊察费
  7235. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7236. //zhenChaCostSelfTotal = zhenChaCostTotal
  7237. }
  7238. if item.MedChrgitmType == "03" { //检查费
  7239. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7240. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7241. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7242. }
  7243. //if item.MedChrgitmType == "02" { //检查费
  7244. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7245. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7246. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7247. //}
  7248. if item.MedChrgitmType == "04" { //化验费
  7249. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7250. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7251. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7252. }
  7253. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7254. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7255. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7256. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7257. }
  7258. if item.MedChrgitmType == "06" { //手术费
  7259. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7260. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7261. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7262. }
  7263. if item.MedChrgitmType == "08" { //材料费
  7264. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7265. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7266. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7267. }
  7268. if item.MedChrgitmType == "09" { //西药费
  7269. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7270. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7271. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7272. }
  7273. if item.MedChrgitmType == "11" { //中成费
  7274. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7275. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7276. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7277. }
  7278. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7279. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7280. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7281. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7282. }
  7283. } else {
  7284. if item.MedChrgitmType == "01" { //床位费
  7285. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7286. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7287. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7288. }
  7289. //if item.MedChrgitmType == "02" { //诊察费
  7290. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7291. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7292. //}
  7293. if item.MedChrgitmType == "03" { //检查费
  7294. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7295. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7296. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7297. }
  7298. //if item.MedChrgitmType == "02" { //检查费
  7299. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7300. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7301. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7302. //}
  7303. if item.MedChrgitmType == "04" { //化验费
  7304. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7305. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7306. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7307. }
  7308. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7309. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7310. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7311. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7312. }
  7313. if item.MedChrgitmType == "06" { //手术费
  7314. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7315. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7316. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7317. }
  7318. if item.MedChrgitmType == "08" { //材料费
  7319. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7320. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7321. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7322. }
  7323. if item.MedChrgitmType == "09" { //西药费
  7324. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7325. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7326. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7327. }
  7328. if item.MedChrgitmType == "11" { //中成费
  7329. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7330. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7331. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7332. }
  7333. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7334. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7336. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7337. }
  7338. }
  7339. }
  7340. c.ServeSuccessJSON(map[string]interface{}{
  7341. "order": order,
  7342. "order_info": order_info,
  7343. "patient": patient,
  7344. "admin_info": adminInfo,
  7345. "his_hospital": record,
  7346. "bedCostTotal": bedCostTotal,
  7347. "operationCostTotal": operationCostTotal,
  7348. "otherCostTotal": otherCostTotal,
  7349. "materialCostTotal": materialCostTotal,
  7350. "westernMedicineCostTotal": westernMedicineCostTotal,
  7351. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7352. "checkCostTotal": checkCostTotal,
  7353. "zhenChaCostTotal": zhenChaCostTotal,
  7354. "laboratoryCostTotal": laboratoryCostTotal,
  7355. "treatCostTotal": treatCostTotal,
  7356. })
  7357. }
  7358. }
  7359. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7360. page, _ := c.GetInt64("page")
  7361. limit, _ := c.GetInt64("limit")
  7362. keywords := c.GetString("keywords")
  7363. start_time := c.GetString("start_time")
  7364. end_time := c.GetString("end_time")
  7365. //clr_type := c.GetString("clr_type")
  7366. insutype := c.GetString("insutype")
  7367. timeLayout := "2006-01-02"
  7368. loc, _ := time.LoadLocation("Local")
  7369. var theStartTIme int64
  7370. if len(start_time) > 0 {
  7371. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7372. theStartTIme = theTime.Unix()
  7373. }
  7374. var theEndtTIme int64
  7375. if len(end_time) > 0 {
  7376. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7377. theEndtTIme = theTime.Unix()
  7378. }
  7379. if page <= 0 {
  7380. page = 1
  7381. }
  7382. if limit <= 0 {
  7383. limit = 10
  7384. }
  7385. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7386. c.ServeSuccessJSON(map[string]interface{}{
  7387. "total": total,
  7388. "list": list,
  7389. })
  7390. return
  7391. }
  7392. func (c *HisApiController) GetPutOnRecordList() {
  7393. page, _ := c.GetInt64("page")
  7394. limit, _ := c.GetInt64("limit")
  7395. keywords := c.GetString("keywords")
  7396. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7397. if page <= 0 {
  7398. page = 1
  7399. }
  7400. if limit <= 0 {
  7401. limit = 10
  7402. }
  7403. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7404. c.ServeSuccessJSON(map[string]interface{}{
  7405. "total": total,
  7406. "list": list,
  7407. })
  7408. return
  7409. }
  7410. func (c *HisApiController) GetCompareData() {
  7411. start_time := c.GetString("start_time")
  7412. end_time := c.GetString("end_time")
  7413. insutype := c.GetString("insutype")
  7414. clr_type := c.GetString("clr_type")
  7415. timeLayout := "2006-01-02"
  7416. loc, _ := time.LoadLocation("Local")
  7417. var theStartTIme int64
  7418. if len(start_time) > 0 {
  7419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7420. if err != nil {
  7421. theStartTIme = 0
  7422. }
  7423. theStartTIme = theTime.Unix()
  7424. }
  7425. var theEndtTIme int64
  7426. if len(end_time) > 0 {
  7427. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7428. if err != nil {
  7429. theEndtTIme = 0
  7430. }
  7431. theEndtTIme = theTime.Unix()
  7432. }
  7433. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7434. fmt.Println(err)
  7435. if err == nil {
  7436. c.ServeSuccessJSON(map[string]interface{}{
  7437. "list": formData,
  7438. })
  7439. } else {
  7440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7441. return
  7442. }
  7443. }
  7444. func (c *HisApiController) GetFaPiaoData() {
  7445. order_id, _ := c.GetInt64("order_id")
  7446. patient_id, _ := c.GetInt64("patient_id")
  7447. number := c.GetString("number")
  7448. adminUser := c.GetAdminUserInfo()
  7449. order, _ := service.GetHisOrderByID(order_id)
  7450. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7451. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7452. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7453. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7454. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7455. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7456. var bedCostTotal float64 = 0 //床位总费
  7457. var bedCostSelfTotal float64 = 0 //床位自费
  7458. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7459. var operationCostTotal float64 = 0 //手术费
  7460. var operationCostSelfTotal float64 = 0 //手术费
  7461. var operationCostPartSelfTotal float64 = 0 //手术费
  7462. var otherCostTotal float64 = 0 //其他费用
  7463. var otherCostSelfTotal float64 = 0 //其他费用
  7464. var otherCostPartSelfTotal float64 = 0 //其他费用
  7465. var materialCostTotal float64 = 0 //材料费
  7466. var materialCostSelfTotal float64 = 0 //材料费
  7467. var materialCostPartSelfTotal float64 = 0 //材料费
  7468. var westernMedicineCostTotal float64 = 0 //西药费
  7469. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7470. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7471. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7472. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7473. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7474. var checkCostTotal float64 = 0 //检查费
  7475. var checkCostSelfTotal float64 = 0 //检查费
  7476. var checkCostPartSelfTotal float64 = 0 //检查费
  7477. var laboratoryCostTotal float64 = 0 //化验费
  7478. var laboratoryCostSelfTotal float64 = 0 //化验费
  7479. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7480. var treatCostTotal float64 = 0 //治疗费用
  7481. var treatCostSelfTotal float64 = 0 //治疗费用
  7482. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7483. var zhenChaCostTotal float64 = 0 //其他费用
  7484. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7485. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7486. decimal.DivisionPrecision = 2
  7487. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7488. var balanceAccountsType int64
  7489. if his.ID > 0 {
  7490. balanceAccountsType = his.BalanceAccountsType
  7491. } else {
  7492. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7493. }
  7494. if balanceAccountsType == 2 {
  7495. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7496. for _, item := range orderInfos_two {
  7497. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7498. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7499. item.MedChrgitmType = "09"
  7500. }
  7501. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7502. if item.HisPrescriptionProject.Type == 2 {
  7503. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7504. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7505. case 0:
  7506. item.MedChrgitmType = "0"
  7507. break
  7508. case 1:
  7509. item.MedChrgitmType = "14"
  7510. break
  7511. case 2:
  7512. item.MedChrgitmType = "05"
  7513. break
  7514. case 3:
  7515. item.MedChrgitmType = "03"
  7516. break
  7517. case 4:
  7518. item.MedChrgitmType = "03"
  7519. break
  7520. case 5:
  7521. item.MedChrgitmType = "08"
  7522. break
  7523. case 6:
  7524. item.MedChrgitmType = "14"
  7525. break
  7526. case 7:
  7527. item.MedChrgitmType = "14"
  7528. break
  7529. case 8:
  7530. item.MedChrgitmType = "03"
  7531. break
  7532. case 9:
  7533. item.MedChrgitmType = "14"
  7534. break
  7535. case 10:
  7536. item.MedChrgitmType = "14"
  7537. break
  7538. case 11:
  7539. item.MedChrgitmType = "06"
  7540. break
  7541. case 12:
  7542. item.MedChrgitmType = "12"
  7543. break
  7544. case 13:
  7545. item.MedChrgitmType = "01"
  7546. break
  7547. case 14:
  7548. item.MedChrgitmType = "04"
  7549. break
  7550. case 15:
  7551. item.MedChrgitmType = "02"
  7552. break
  7553. }
  7554. } else {
  7555. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7556. case 1:
  7557. item.MedChrgitmType = "14"
  7558. break
  7559. case 2:
  7560. item.MedChrgitmType = "05"
  7561. break
  7562. case 3:
  7563. item.MedChrgitmType = "03"
  7564. break
  7565. case 4:
  7566. item.MedChrgitmType = "03"
  7567. break
  7568. case 5:
  7569. item.MedChrgitmType = "08"
  7570. break
  7571. case 6:
  7572. item.MedChrgitmType = "14"
  7573. break
  7574. case 7:
  7575. item.MedChrgitmType = "14"
  7576. break
  7577. case 8:
  7578. item.MedChrgitmType = "03"
  7579. break
  7580. case 9:
  7581. item.MedChrgitmType = "14"
  7582. break
  7583. }
  7584. }
  7585. } else if item.HisPrescriptionProject.Type == 3 {
  7586. item.MedChrgitmType = "08"
  7587. }
  7588. }
  7589. }
  7590. for _, item := range orderInfos_two {
  7591. fmt.Println(item.MedChrgitmType)
  7592. if item.MedChrgitmType == "01" { //床位费
  7593. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7594. bedCostSelfTotal = bedCostTotal
  7595. }
  7596. if item.MedChrgitmType == "02" { //诊察费
  7597. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7598. zhenChaCostSelfTotal = zhenChaCostTotal
  7599. }
  7600. if item.MedChrgitmType == "03" { //检查费
  7601. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7602. checkCostSelfTotal = checkCostTotal
  7603. }
  7604. if item.MedChrgitmType == "04" { //化验费
  7605. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7606. laboratoryCostSelfTotal = laboratoryCostTotal
  7607. }
  7608. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7609. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7610. treatCostSelfTotal = treatCostTotal
  7611. }
  7612. if item.MedChrgitmType == "06" { //手术费
  7613. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7614. operationCostSelfTotal = treatCostTotal
  7615. }
  7616. if item.MedChrgitmType == "08" { //材料费
  7617. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7618. materialCostSelfTotal = materialCostTotal
  7619. }
  7620. if item.MedChrgitmType == "09" { //西药费
  7621. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7622. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7623. }
  7624. if item.MedChrgitmType == "11" { //中成费
  7625. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7626. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7627. }
  7628. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7629. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7630. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7631. otherCostSelfTotal = otherCostTotal
  7632. }
  7633. } else {
  7634. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7635. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7636. otherCostSelfTotal = otherCostTotal
  7637. }
  7638. }
  7639. }
  7640. } else {
  7641. for _, item := range orderInfos {
  7642. if item.MedChrgitmType == "01" { //床位费
  7643. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7644. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7645. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7646. }
  7647. if item.MedChrgitmType == "02" { //诊察费
  7648. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7649. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7650. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7651. }
  7652. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7653. if item.MedChrgitmType == "03" { //检查费
  7654. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7655. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7656. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7657. }
  7658. } else {
  7659. if item.MedChrgitmType == "03" { //检查费
  7660. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7661. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7662. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7663. }
  7664. }
  7665. if item.MedChrgitmType == "04" { //化验费
  7666. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7667. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7668. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7669. }
  7670. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7671. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7672. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7673. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7674. }
  7675. if item.MedChrgitmType == "06" { //手术费
  7676. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7677. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7678. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7679. }
  7680. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7681. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7682. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7683. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7684. }
  7685. if item.MedChrgitmType == "09" { //西药费
  7686. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7687. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7688. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7689. }
  7690. if item.MedChrgitmType == "11" { //中成费
  7691. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7692. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7693. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7694. }
  7695. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7696. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7697. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7698. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7699. }
  7700. }
  7701. }
  7702. timeLayout := "2006-01-02"
  7703. loc, _ := time.LoadLocation("Local")
  7704. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7705. if err != nil {
  7706. }
  7707. startRecordDateTime := startTime.Unix()
  7708. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7709. if err != nil {
  7710. }
  7711. endRecordDateTime := endTime.Unix()
  7712. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7713. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7714. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7715. c.ServeSuccessJSON(map[string]interface{}{
  7716. "order_number": order.Number, //业务流水号
  7717. "id_card_no": his.IdCardNo, //社会保障号
  7718. "department_name": department.Name, //科室
  7719. "number": his.Number, //门诊号
  7720. "date": order.SettleAccountsDate, //结算日期
  7721. "name": order.PsnName, //姓名
  7722. "gender": patient.Gender, //性别
  7723. "psn_cash_money": order.PsnCashPay, //个人支付
  7724. "pay_way": "门诊", //结算方式
  7725. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7726. "admin_user_name": admin.UserName, //收款员
  7727. "order": order,
  7728. "order_info": orderInfos_two,
  7729. "his": his,
  7730. "bedCostTotal": bedCostTotal,
  7731. "bedCostSelfTotal": bedCostSelfTotal,
  7732. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7733. "operationCostTotal": operationCostTotal,
  7734. "operationCostSelfTotal": operationCostSelfTotal,
  7735. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7736. "otherCostTotal": otherCostTotal,
  7737. "otherCostSelfTotal": otherCostSelfTotal,
  7738. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7739. "materialCostTotal": materialCostTotal,
  7740. "materialCostSelfTotal": materialCostSelfTotal,
  7741. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7742. "westernMedicineCostTotal": westernMedicineCostTotal,
  7743. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7744. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7745. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7746. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7747. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7748. "checkCostTotal": checkCostTotal,
  7749. "checkCostSelfTotal": checkCostSelfTotal,
  7750. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7751. "laboratoryCostTotal": laboratoryCostTotal,
  7752. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7753. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7754. "treatCostTotal": treatCostTotal,
  7755. "treatCostSelfTotal": treatCostSelfTotal,
  7756. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7757. "zhenChaCostTotal": zhenChaCostTotal,
  7758. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7759. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7760. "his_hospital_record": his_hospital_record,
  7761. "pre_pay_money": pre_pay_money,
  7762. "refund_sum": sum,
  7763. })
  7764. }
  7765. func (this *HisApiController) GetIncomeStatisticsData() {
  7766. start_time := this.GetString("start_time")
  7767. end_time := this.GetString("end_time")
  7768. key_words := this.GetString("key_words")
  7769. limit, _ := this.GetInt64("limit")
  7770. page, _ := this.GetInt64("page")
  7771. if page <= 0 {
  7772. page = 1
  7773. }
  7774. if limit <= 0 {
  7775. limit = 10
  7776. }
  7777. statistics_type, _ := this.GetInt64("statistics_type")
  7778. admin := this.GetAdminUserInfo()
  7779. timeLayout := "2006-01-02"
  7780. loc, _ := time.LoadLocation("Local")
  7781. var theStartTIme int64
  7782. if len(start_time) > 0 {
  7783. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7784. if err != nil {
  7785. theStartTIme = 0
  7786. }
  7787. theStartTIme = theTime.Unix()
  7788. }
  7789. var theEndtTIme int64
  7790. if len(end_time) > 0 {
  7791. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7792. if err != nil {
  7793. theEndtTIme = 0
  7794. }
  7795. theEndtTIme = theTime.Unix()
  7796. }
  7797. if statistics_type == 1 {
  7798. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7799. this.ServeSuccessJSON(map[string]interface{}{
  7800. "list": list,
  7801. "total": total,
  7802. })
  7803. } else {
  7804. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7805. this.ServeSuccessJSON(map[string]interface{}{
  7806. "list": list,
  7807. "total": total,
  7808. })
  7809. }
  7810. }
  7811. func (c *HisApiController) PostProjectInformation() {
  7812. adminUser := c.GetAdminUserInfo()
  7813. orgId := adminUser.CurrentOrgId
  7814. dataBody := make(map[string]interface{}, 0)
  7815. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7816. if err != nil {
  7817. utils.ErrorLog(err.Error())
  7818. return
  7819. }
  7820. utils.ErrorLog("%v", dataBody)
  7821. var projectList []*models.HisProject
  7822. var total_goods []interface{}
  7823. tempProjects := dataBody["projects"].([]interface{})
  7824. total_goods = tempProjects
  7825. for index, projectMap := range tempProjects {
  7826. projectM := projectMap.(map[string]interface{})
  7827. var project models.HisProject
  7828. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7829. utils.ErrorLog("project_name")
  7830. return
  7831. }
  7832. project_name, _ := projectM["project_name"].(string)
  7833. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7834. err_log := models.ExportErrLog{
  7835. LogType: 6,
  7836. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7837. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7838. Status: 1,
  7839. CreateTime: time.Now().Unix(),
  7840. UpdateTime: time.Now().Unix(),
  7841. ExportTime: time.Now().Unix(),
  7842. }
  7843. service.CreateExportErrLog(&err_log)
  7844. continue
  7845. }
  7846. project.ProjectName = project_name
  7847. prices := projectM["price"].(string)
  7848. price, _ := strconv.ParseFloat(prices, 64)
  7849. if price <= 0 { //名字为空则生成一条导入错误日志
  7850. err_log := models.ExportErrLog{
  7851. LogType: 6,
  7852. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7853. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7854. Status: 1,
  7855. CreateTime: time.Now().Unix(),
  7856. UpdateTime: time.Now().Unix(),
  7857. ExportTime: time.Now().Unix(),
  7858. }
  7859. service.CreateExportErrLog(&err_log)
  7860. continue
  7861. }
  7862. project.Price = price
  7863. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7864. utils.ErrorLog("unit_id")
  7865. return
  7866. }
  7867. unit := projectM["unit"].(string)
  7868. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7869. err_log := models.ExportErrLog{
  7870. LogType: 6,
  7871. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7872. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7873. Status: 1,
  7874. CreateTime: time.Now().Unix(),
  7875. UpdateTime: time.Now().Unix(),
  7876. ExportTime: time.Now().Unix(),
  7877. }
  7878. service.CreateExportErrLog(&err_log)
  7879. continue
  7880. }
  7881. project.Unit = unit
  7882. cost_classify := projectM["cost_classify"].(string)
  7883. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7884. err_log := models.ExportErrLog{
  7885. LogType: 6,
  7886. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7887. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7888. Status: 1,
  7889. CreateTime: time.Now().Unix(),
  7890. UpdateTime: time.Now().Unix(),
  7891. ExportTime: time.Now().Unix(),
  7892. }
  7893. service.CreateExportErrLog(&err_log)
  7894. continue
  7895. }
  7896. var costClassify = "费用类别"
  7897. var cost_classify_id int64
  7898. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7899. if len(cost_classify) != 0 {
  7900. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7901. if errcode == gorm.ErrRecordNotFound {
  7902. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7903. dataconfig := models.DictDataconfig{
  7904. ParentId: costClassifyConfig.ID,
  7905. Module: "system",
  7906. OrgId: orgId,
  7907. Name: cost_classify,
  7908. FieldName: "",
  7909. Value: costConfig.Value + 1,
  7910. CreatedTime: "",
  7911. UpdatedTime: "",
  7912. CreateUserId: adminUser.AdminUser.Id,
  7913. Status: 1,
  7914. Remark: "",
  7915. DeleteIdSystem: 0,
  7916. Title: "",
  7917. Content: "",
  7918. Order: 0,
  7919. Code: "",
  7920. }
  7921. service.CreatedDicConfig(&dataconfig)
  7922. }
  7923. }
  7924. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7925. for _, it := range costClassList {
  7926. if cost_classify == it.Name {
  7927. cost_classify_id = int64(it.Value)
  7928. }
  7929. }
  7930. project.CostClassify = cost_classify_id
  7931. executive_section := projectM["executive_section"].(string)
  7932. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7933. err_log := models.ExportErrLog{
  7934. LogType: 6,
  7935. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7936. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7937. Status: 1,
  7938. CreateTime: time.Now().Unix(),
  7939. UpdateTime: time.Now().Unix(),
  7940. ExportTime: time.Now().Unix(),
  7941. }
  7942. service.CreateExportErrLog(&err_log)
  7943. continue
  7944. }
  7945. if len(executive_section) != 0 {
  7946. //查找科室是否有内容
  7947. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7948. if errcodedepart == gorm.ErrRecordNotFound {
  7949. department := models.XtHisDepartment{
  7950. Name: executive_section,
  7951. Status: 1,
  7952. UserOrgId: adminUser.CurrentOrgId,
  7953. CreatedTime: time.Now().Unix(),
  7954. }
  7955. service.CreateDePartment(&department)
  7956. }
  7957. }
  7958. var executive_section_id int64
  7959. departMentList, _ := service.GetAllDepartMent(orgId)
  7960. for _, it := range departMentList {
  7961. if executive_section == it.Name {
  7962. executive_section_id = it.ID
  7963. }
  7964. }
  7965. project.ExecutiveSection = executive_section_id
  7966. medical_coverage := projectM["medical_coverage"].(string)
  7967. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7968. err_log := models.ExportErrLog{
  7969. LogType: 6,
  7970. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7971. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7972. Status: 1,
  7973. CreateTime: time.Now().Unix(),
  7974. UpdateTime: time.Now().Unix(),
  7975. ExportTime: time.Now().Unix(),
  7976. }
  7977. service.CreateExportErrLog(&err_log)
  7978. continue
  7979. }
  7980. var medicalCoverage = "医保等级"
  7981. var medical_coverage_id int64
  7982. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7983. if len(medical_coverage) != 0 {
  7984. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7985. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7986. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7987. dataconfig := models.DictDataconfig{
  7988. ParentId: medicalCoverageConfig.ID,
  7989. Module: "system",
  7990. OrgId: orgId,
  7991. Name: medical_coverage,
  7992. FieldName: "",
  7993. Value: medicalCoverageConfig.Value + 1,
  7994. CreatedTime: "",
  7995. UpdatedTime: "",
  7996. CreateUserId: adminUser.AdminUser.Id,
  7997. Status: 1,
  7998. Remark: "",
  7999. DeleteIdSystem: 0,
  8000. Title: "",
  8001. Content: "",
  8002. Order: 0,
  8003. Code: "",
  8004. }
  8005. service.CreatedDicConfig(&dataconfig)
  8006. }
  8007. }
  8008. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8009. for _, it := range medicalCoverageList {
  8010. if medical_coverage == it.Name {
  8011. medical_coverage_id = int64(it.Value)
  8012. }
  8013. }
  8014. project.MedicalCoverage = medical_coverage_id
  8015. pinyin := projectM["pinyin"].(string)
  8016. project.Pinyin = pinyin
  8017. wubi := projectM["wubi"].(string)
  8018. project.Wubi = wubi
  8019. statistical_classification := projectM["statistical_classification"].(string)
  8020. var statisticalClassification = "统计分类"
  8021. var statistical_classification_id int64
  8022. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8023. if len(statistical_classification) != 0 {
  8024. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8025. if classificationerrcodes == gorm.ErrRecordNotFound {
  8026. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8027. dataconfig := models.DictDataconfig{
  8028. ParentId: classiFication.ID,
  8029. Module: "system",
  8030. OrgId: orgId,
  8031. Name: statistical_classification,
  8032. FieldName: "",
  8033. Value: classiFicationConfig.Value + 1,
  8034. CreatedTime: "",
  8035. UpdatedTime: "",
  8036. CreateUserId: adminUser.AdminUser.Id,
  8037. Status: 1,
  8038. Remark: "",
  8039. DeleteIdSystem: 0,
  8040. Title: "",
  8041. Content: "",
  8042. Order: 0,
  8043. Code: "",
  8044. }
  8045. service.CreatedDicConfig(&dataconfig)
  8046. }
  8047. }
  8048. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8049. for _, it := range classiFicationList {
  8050. if statistical_classification == it.Name {
  8051. statistical_classification_id = int64(it.Value)
  8052. }
  8053. }
  8054. project.StatisticalClassification = statistical_classification_id
  8055. disease_directory := int64(projectM["disease_directory"].(float64))
  8056. project.DiseaseDirectory = disease_directory
  8057. is_record := int64(projectM["is_record"].(float64))
  8058. project.IsRecord = is_record
  8059. medical_code := projectM["medical_code"].(string)
  8060. project.MedicalCode = medical_code
  8061. tube_color := projectM["tube_color"].(string)
  8062. var tubeColor = "试管颜色"
  8063. var tube_color_id int64
  8064. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8065. if len(tube_color) != 0 {
  8066. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8067. if errcodetube == gorm.ErrRecordNotFound {
  8068. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8069. dataconfig := models.DictDataconfig{
  8070. ParentId: tubeColorConfig.ID,
  8071. Module: "system",
  8072. OrgId: orgId,
  8073. Name: tube_color,
  8074. FieldName: "",
  8075. Value: tubeConfig.Value + 1,
  8076. CreatedTime: "",
  8077. UpdatedTime: "",
  8078. CreateUserId: adminUser.AdminUser.Id,
  8079. Status: 1,
  8080. Remark: "",
  8081. DeleteIdSystem: 0,
  8082. Title: "",
  8083. Content: "",
  8084. Order: 0,
  8085. Code: "",
  8086. }
  8087. service.CreatedDicConfig(&dataconfig)
  8088. }
  8089. }
  8090. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8091. for _, it := range tubeColorList {
  8092. if tube_color == it.Name {
  8093. tube_color_id = int64(it.Value)
  8094. }
  8095. }
  8096. project.TubeColor = tube_color_id
  8097. single_dose := projectM["single_dose"].(string)
  8098. project.SingleDose = single_dose
  8099. execution_frequency := projectM["execution_frequency"].(string)
  8100. project.ExecutionFrequency = execution_frequency
  8101. delivery_way := projectM["delivery_way"].(string)
  8102. project.DeliveryWay = delivery_way
  8103. number_days := projectM["number_days"].(string)
  8104. project.NumberDays = number_days
  8105. total := projectM["total"].(string)
  8106. project.Total = total
  8107. medical_status := int64(projectM["medical_status"].(float64))
  8108. project.MedicalStatus = medical_status
  8109. category := int64(projectM["category"].(float64))
  8110. project.Category = category
  8111. specail_project := int64(projectM["specail_project"].(float64))
  8112. project.SpecailProject = specail_project
  8113. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8114. project.SocialSecurityDirectoryCode = social_security_directory_code
  8115. remark := projectM["remark"].(string)
  8116. project.Remark = remark
  8117. record_date := projectM["record_date"].(string)
  8118. timeLayout := "2006-01-02"
  8119. loc, _ := time.LoadLocation("Local")
  8120. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8121. project.RecordDate = theTime.Unix()
  8122. projectList = append(projectList, &project)
  8123. }
  8124. export_time := time.Now().Unix()
  8125. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8126. if len(projectList) > 0 {
  8127. for _, item := range projectList {
  8128. project := models.HisProject{
  8129. ProjectName: item.ProjectName,
  8130. Price: item.Price,
  8131. Unit: item.Unit,
  8132. CostClassify: item.CostClassify,
  8133. ExecutiveSection: item.ExecutiveSection,
  8134. MedicalCoverage: item.MedicalCoverage,
  8135. UserOrgId: orgId,
  8136. Status: 1,
  8137. CreatedTime: time.Now().Unix(),
  8138. Pinyin: item.Pinyin,
  8139. Wubi: item.Wubi,
  8140. StatisticalClassification: item.StatisticalClassification,
  8141. DiseaseDirectory: item.DiseaseDirectory,
  8142. IsRecord: item.IsRecord,
  8143. MedicalCode: item.MedicalCode,
  8144. TubeColor: item.TubeColor,
  8145. SingleDose: item.SingleDose,
  8146. DeliveryWay: item.DeliveryWay,
  8147. NumberDays: item.NumberDays,
  8148. Total: item.Total,
  8149. Category: item.Category,
  8150. MedicalStatus: item.MedicalStatus,
  8151. SpecailProject: item.SpecailProject,
  8152. RecordDate: item.RecordDate,
  8153. Remark: item.Remark,
  8154. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8155. ExecutionFrequency: item.ExecutionFrequency,
  8156. }
  8157. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8158. if errcodeproject == gorm.ErrRecordNotFound {
  8159. service.CreateProjectInfomation(&project)
  8160. } else if errcodeproject == nil {
  8161. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8162. }
  8163. log := models.ExportLog{
  8164. LogType: 6,
  8165. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8166. TotalNum: int64(len(total_goods)),
  8167. FailNum: int64(len(errLogs)),
  8168. SuccessNum: int64(len(projectList)),
  8169. CreateTime: time.Now().Unix(),
  8170. UpdateTime: time.Now().Unix(),
  8171. ExportTime: export_time,
  8172. Status: 1,
  8173. }
  8174. service.CreateExportLog(&log)
  8175. c.ServeSuccessJSON(map[string]interface{}{
  8176. "msg": "导入成功",
  8177. "total_num": len(total_goods),
  8178. "success_num": len(projectList),
  8179. "fail_num": int64(len(errLogs)),
  8180. })
  8181. }
  8182. } else {
  8183. log := models.ExportLog{
  8184. LogType: 6,
  8185. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8186. TotalNum: int64(len(total_goods)),
  8187. FailNum: int64(len(errLogs)),
  8188. SuccessNum: int64(len(projectList)),
  8189. CreateTime: time.Now().Unix(),
  8190. UpdateTime: time.Now().Unix(),
  8191. ExportTime: export_time,
  8192. Status: 1,
  8193. }
  8194. service.CreateExportLog(&log)
  8195. c.ServeSuccessJSON(map[string]interface{}{
  8196. "msg": "导入成功",
  8197. "total_num": len(total_goods),
  8198. "success_num": len(projectList),
  8199. "fail_num": int64(len(errLogs)),
  8200. })
  8201. }
  8202. }
  8203. //func (this *HisApiController) EditProjectInformation(){
  8204. //
  8205. // id, _ := this.GetInt64("id")
  8206. // project_team := this.GetString("project_team")
  8207. // price := this.GetString("price")
  8208. // price_float, _ := strconv.ParseFloat(price, 64)
  8209. // pinyin := this.GetString("pinyin")
  8210. // wubi := this.GetString("wubi")
  8211. // tube_color, _ := this.GetInt64("tube_color")
  8212. // team_type, _ := this.GetInt64("team_type")
  8213. // remark := this.GetString("remark")
  8214. // ids := this.GetString("ids")
  8215. // item_id := this.GetString("item_id")
  8216. // projectTeam := models.XtHisProjectTeam{
  8217. // ProjectTeam: project_team,
  8218. // Price: price_float,
  8219. // Pinyin: pinyin,
  8220. // Wubi: wubi,
  8221. // TubeColor: tube_color,
  8222. // TeamType: team_type,
  8223. // Remark: remark,
  8224. // ProjectId: ids,
  8225. // ItemId: item_id,
  8226. // }
  8227. //
  8228. //
  8229. // dataBody := make(map[string]interface{}, 0)
  8230. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8231. // if err != nil {
  8232. // utils.ErrorLog(err.Error())
  8233. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8234. // return
  8235. // }
  8236. //
  8237. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8238. //
  8239. //
  8240. // if err != nil {
  8241. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8242. // return
  8243. // }
  8244. //
  8245. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8246. // infos, _ := dataBody["info"].([]interface{})
  8247. // if len(infos) > 0 {
  8248. // var ids []string
  8249. //
  8250. // for _, item := range infos {
  8251. // items := item.(map[string]interface{})
  8252. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8253. // utils.ErrorLog("id")
  8254. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8255. // return
  8256. // }
  8257. // id := int64(items["id"].(float64))
  8258. //
  8259. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8260. // utils.ErrorLog("type")
  8261. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8262. // return
  8263. // }
  8264. // types := int64(items["type"].(float64))
  8265. //
  8266. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8267. // utils.ErrorLog("number")
  8268. // }
  8269. //
  8270. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8271. //
  8272. // projectList := models.XtHisProjectList{
  8273. // Number: number,
  8274. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8275. // ProjectId: id,
  8276. // Status: 1,
  8277. // CreatedTime: time.Now().Unix(),
  8278. // UpdatedTime: time.Now().Unix(),
  8279. // TeamId: projectTeam.ID,
  8280. // Type: types,
  8281. // }
  8282. // list := projectList
  8283. //
  8284. // service.CreateProjectList(&list)
  8285. //
  8286. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8287. //
  8288. // }
  8289. // ids_str := strings.Join(ids, ",")
  8290. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8291. // service.SaveProjectTeam(&projectTeam)
  8292. // this.ServeSuccessJSON(map[string]interface{}{
  8293. // "projectTeam": projectTeam,
  8294. // })
  8295. // }
  8296. // }
  8297. //}
  8298. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8299. name := c.GetString("name")
  8300. mode_id, _ := c.GetInt64("mode", 0)
  8301. types, _ := c.GetInt64("type", 0)
  8302. patient_id, _ := c.GetInt64("patient_id", 0)
  8303. types = 1
  8304. adminInfo := c.GetAdminUserInfo()
  8305. template := &models.HisPrescriptionTemplate{
  8306. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8307. PatientId: patient_id,
  8308. Type: types,
  8309. Status: 1,
  8310. Ctime: time.Now().Unix(),
  8311. Mtime: time.Now().Unix(),
  8312. Name: name,
  8313. Mode: mode_id,
  8314. }
  8315. dataBody := make(map[string]interface{}, 0)
  8316. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8317. if err != nil {
  8318. utils.ErrorLog(err.Error())
  8319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8320. return
  8321. }
  8322. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8323. //如果已经存在记录则删除处方
  8324. if template_one.ID > 0 {
  8325. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8326. for _, item := range ps {
  8327. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8328. }
  8329. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8330. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8331. if len(prescriptions) > 0 {
  8332. for _, item := range prescriptions {
  8333. items := item.(map[string]interface{})
  8334. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8335. utils.ErrorLog("type")
  8336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8337. return
  8338. }
  8339. types := int64(items["type"].(float64))
  8340. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8341. utils.ErrorLog("med_type")
  8342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8343. return
  8344. }
  8345. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8346. ctime := time.Now().Unix()
  8347. prescription := &models.HisPrescriptionInfoTemplate{
  8348. PatientId: patient_id,
  8349. UserOrgId: adminInfo.CurrentOrgId,
  8350. Ctime: ctime,
  8351. Mtime: ctime,
  8352. Type: types,
  8353. Modifier: adminInfo.AdminUser.Id,
  8354. Creator: adminInfo.AdminUser.Id,
  8355. Status: 1,
  8356. PTemplateId: template_one.ID,
  8357. MedType: med_type,
  8358. }
  8359. service.CreateHisPrescriptionInfoTemplate(prescription)
  8360. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8361. advices := items["advices"].([]interface{})
  8362. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8363. ctime := time.Now().Unix()
  8364. mtime := ctime
  8365. if len(advices) > 0 {
  8366. for _, advice := range advices {
  8367. var s models.HisPrescriptionAdviceTemplate
  8368. s.PrescriptionId = prescription.ID
  8369. s.AdviceType = 2
  8370. s.StopState = 2
  8371. s.ExecutionState = 2
  8372. s.Status = 1
  8373. s.UserOrgId = adminInfo.CurrentOrgId
  8374. s.CreatedTime = ctime
  8375. s.UpdatedTime = mtime
  8376. s.PatientId = patient_id
  8377. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8378. if errcode > 0 {
  8379. c.ServeFailJSONWithSGJErrorCode(errcode)
  8380. return
  8381. }
  8382. service.CreateHisPrescriptionAdviceTemplate(&s)
  8383. }
  8384. }
  8385. }
  8386. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8387. projects := items["project"].([]interface{})
  8388. if len(projects) > 0 {
  8389. for _, project := range projects {
  8390. var p models.HisPrescriptionProjectTemplate
  8391. p.PrescriptionId = prescription.ID
  8392. p.Ctime = time.Now().Unix()
  8393. p.Mtime = time.Now().Unix()
  8394. p.PatientId = patient_id
  8395. p.UserOrgId = adminInfo.CurrentOrgId
  8396. p.Status = 1
  8397. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8398. if errcode > 0 {
  8399. c.ServeFailJSONWithSGJErrorCode(errcode)
  8400. return
  8401. }
  8402. service.CreateHisPrescriptionProjectTemplate(&p)
  8403. }
  8404. }
  8405. }
  8406. }
  8407. c.ServeSuccessJSON(map[string]interface{}{
  8408. "msg": "创建成功",
  8409. })
  8410. }
  8411. }
  8412. } else {
  8413. err = service.CreateHisPrescriptionTemplate(template)
  8414. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8415. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8416. if len(prescriptions) > 0 {
  8417. for _, item := range prescriptions {
  8418. items := item.(map[string]interface{})
  8419. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8420. utils.ErrorLog("type")
  8421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8422. return
  8423. }
  8424. types := int64(items["type"].(float64))
  8425. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8426. utils.ErrorLog("med_type")
  8427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8428. return
  8429. }
  8430. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8431. ctime := time.Now().Unix()
  8432. prescription := &models.HisPrescriptionInfoTemplate{
  8433. PatientId: patient_id,
  8434. UserOrgId: adminInfo.CurrentOrgId,
  8435. Ctime: ctime,
  8436. Mtime: ctime,
  8437. Type: types,
  8438. Modifier: adminInfo.AdminUser.Id,
  8439. Creator: adminInfo.AdminUser.Id,
  8440. Status: 1,
  8441. PTemplateId: template.ID,
  8442. MedType: med_type,
  8443. }
  8444. service.CreateHisPrescriptionInfoTemplate(prescription)
  8445. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8446. advices := items["advices"].([]interface{})
  8447. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8448. ctime := time.Now().Unix()
  8449. mtime := ctime
  8450. if len(advices) > 0 {
  8451. for _, advice := range advices {
  8452. var s models.HisPrescriptionAdviceTemplate
  8453. s.PrescriptionId = prescription.ID
  8454. s.AdviceType = 2
  8455. s.StopState = 2
  8456. s.ExecutionState = 2
  8457. s.Status = 1
  8458. s.UserOrgId = adminInfo.CurrentOrgId
  8459. s.CreatedTime = ctime
  8460. s.UpdatedTime = mtime
  8461. s.PatientId = patient_id
  8462. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8463. if errcode > 0 {
  8464. c.ServeFailJSONWithSGJErrorCode(errcode)
  8465. return
  8466. }
  8467. service.CreateHisPrescriptionAdviceTemplate(&s)
  8468. }
  8469. }
  8470. }
  8471. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8472. projects := items["project"].([]interface{})
  8473. if len(projects) > 0 {
  8474. for _, project := range projects {
  8475. var p models.HisPrescriptionProjectTemplate
  8476. p.PrescriptionId = prescription.ID
  8477. p.Ctime = time.Now().Unix()
  8478. p.Mtime = time.Now().Unix()
  8479. p.PatientId = patient_id
  8480. p.UserOrgId = adminInfo.CurrentOrgId
  8481. p.Status = 1
  8482. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8483. if errcode > 0 {
  8484. c.ServeFailJSONWithSGJErrorCode(errcode)
  8485. return
  8486. }
  8487. service.CreateHisPrescriptionProjectTemplate(&p)
  8488. }
  8489. }
  8490. }
  8491. }
  8492. c.ServeSuccessJSON(map[string]interface{}{
  8493. "msg": "创建成功",
  8494. })
  8495. }
  8496. }
  8497. }
  8498. }
  8499. func (c *HisApiController) PreSettle() {
  8500. id, _ := c.GetInt64("id")
  8501. record_time := c.GetString("record_time")
  8502. his_patient_id, _ := c.GetInt64("his_patient_id")
  8503. timeLayout := "2006-01-02"
  8504. loc, _ := time.LoadLocation("Local")
  8505. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8506. diagnosis_id := c.GetString("diagnosis")
  8507. sick_type, _ := c.GetInt64("sick_type")
  8508. reg_type, _ := c.GetInt64("p_type")
  8509. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8510. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8511. if err != nil {
  8512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8513. return
  8514. }
  8515. recordDateTime := theTime.Unix()
  8516. adminUser := c.GetAdminUserInfo()
  8517. var prescriptions []*models.HisPrescription
  8518. var start_time int64
  8519. var end_time int64
  8520. ids_str := c.GetString("ids")
  8521. ids_arr := strings.Split(ids_str, ",")
  8522. fmt.Println(reg_type)
  8523. if settle_accounts_type == 1 { //日结
  8524. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8525. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8526. } else {
  8527. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8528. }
  8529. fmt.Println(prescriptions)
  8530. } else { //月结
  8531. start_time_str := c.GetString("start_time")
  8532. end_time_str := c.GetString("end_time")
  8533. timeLayout := "2006-01-02"
  8534. loc, _ := time.LoadLocation("Local")
  8535. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8536. if err != nil {
  8537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8538. return
  8539. }
  8540. recordStartTime := theStartTime.Unix()
  8541. start_time = recordStartTime
  8542. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8543. if err != nil {
  8544. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8545. return
  8546. }
  8547. recordEndTime := theEndTime.Unix()
  8548. end_time = recordEndTime
  8549. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8550. }
  8551. if reg_type == 1111 || reg_type == 1112 {
  8552. reg_type = 11
  8553. }
  8554. timestamp := time.Now().Unix()
  8555. tempTime := time.Unix(timestamp, 0)
  8556. timeFormat := tempTime.Format("20060102150405")
  8557. chrgBchno := rand.Intn(100000) + 10000
  8558. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8559. strconv.FormatInt(his.PatientId, 10)
  8560. var ids []int64
  8561. for _, item := range prescriptions {
  8562. ids = append(ids, item.ID)
  8563. }
  8564. fmt.Println(ids)
  8565. var total float64
  8566. for _, item := range prescriptions {
  8567. fmt.Println(item)
  8568. if item.Type == 1 { //药品
  8569. for _, subItem := range item.HisDoctorAdviceInfo {
  8570. total = total + (subItem.Price * subItem.PrescribingNumber)
  8571. }
  8572. }
  8573. if item.Type == 2 { //项目
  8574. for _, subItem := range item.HisPrescriptionProject {
  8575. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8576. total = total + (subItem.Price * cnt)
  8577. }
  8578. }
  8579. for _, subItem := range item.HisAdditionalCharge {
  8580. total = total + (subItem.Price * float64(subItem.Count))
  8581. }
  8582. }
  8583. allTotal := fmt.Sprintf("%.2f", total)
  8584. totals, _ := strconv.ParseFloat(allTotal, 64)
  8585. order := &models.HisOrder{
  8586. UserOrgId: adminUser.CurrentOrgId,
  8587. HisPatientId: his.ID,
  8588. PatientId: id,
  8589. SettleAccountsDate: recordDateTime,
  8590. Ctime: time.Now().Unix(),
  8591. Mtime: time.Now().Unix(),
  8592. Status: 1,
  8593. OrderStatus: 1,
  8594. MdtrtId: his.Number,
  8595. Number: chrg_bchno,
  8596. MedfeeSumamt: totals,
  8597. SettleEndTime: end_time,
  8598. SettleStartTime: start_time,
  8599. SettleType: settle_accounts_type,
  8600. PsnPartAmt: totals,
  8601. PsnCashPay: totals,
  8602. PType: 2,
  8603. IsPre: 1,
  8604. MedType: strconv.Itoa(int(reg_type)),
  8605. Diagnosis: diagnosis_id,
  8606. }
  8607. err = service.CreateOrder(order)
  8608. if err != nil {
  8609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8610. return
  8611. }
  8612. var customs []*Custom
  8613. for _, item := range prescriptions {
  8614. fmt.Println(item.Type)
  8615. if item.Type == 1 { //药品
  8616. for _, subItem := range item.HisDoctorAdviceInfo {
  8617. cus := &Custom{
  8618. AdviceId: subItem.ID,
  8619. ProjectId: 0,
  8620. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8621. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8622. FeedetlSn: subItem.FeedetlSn,
  8623. Price: fmt.Sprintf("%.2f", subItem.Price),
  8624. MedListCodg: subItem.MedListCodg,
  8625. Type: 1,
  8626. }
  8627. customs = append(customs, cus)
  8628. }
  8629. }
  8630. if item.Type == 2 { //项目
  8631. for _, subItem := range item.HisPrescriptionProject {
  8632. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8633. cus := &Custom{
  8634. AdviceId: 0,
  8635. ProjectId: subItem.ID,
  8636. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8637. Cut: fmt.Sprintf("%.2f", cnt),
  8638. FeedetlSn: subItem.FeedetlSn,
  8639. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8640. MedListCodg: subItem.MedListCodg,
  8641. Type: 2,
  8642. }
  8643. customs = append(customs, cus)
  8644. }
  8645. }
  8646. for _, item := range item.HisAdditionalCharge {
  8647. cus := &Custom{
  8648. ItemId: item.ID,
  8649. AdviceId: 0,
  8650. ProjectId: 0,
  8651. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8652. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8653. FeedetlSn: item.FeedetlSn,
  8654. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8655. MedListCodg: item.XtHisAddtionConfig.Code,
  8656. Type: 3,
  8657. }
  8658. customs = append(customs, cus)
  8659. }
  8660. }
  8661. fmt.Println(customs)
  8662. for _, item := range customs {
  8663. var advice_id int64 = 0
  8664. var project_id int64 = 0
  8665. var item_id int64 = 0
  8666. var types int64 = 0
  8667. if item.Type == 1 {
  8668. advice_id = item.AdviceId
  8669. project_id = 0
  8670. item_id = 0
  8671. } else if item.Type == 2 {
  8672. advice_id = 0
  8673. item_id = 0
  8674. project_id = item.ProjectId
  8675. } else if item.Type == 3 {
  8676. advice_id = 0
  8677. item_id = item.ItemId
  8678. project_id = 0
  8679. }
  8680. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8681. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8682. pric, _ := strconv.ParseFloat(item.Price, 32)
  8683. info := &models.HisOrderInfo{
  8684. OrderNumber: order.Number,
  8685. UploadDate: time.Now().Unix(),
  8686. AdviceId: advice_id,
  8687. DetItemFeeSumamt: detItemFeeSumamt,
  8688. Cnt: cut,
  8689. Pric: pric,
  8690. PatientId: id,
  8691. Status: 1,
  8692. Mtime: time.Now().Unix(),
  8693. Ctime: time.Now().Unix(),
  8694. UserOrgId: adminUser.CurrentOrgId,
  8695. HisPatientId: his.ID,
  8696. OrderId: order.ID,
  8697. ProjectId: project_id,
  8698. Type: types,
  8699. ItemId: item_id,
  8700. }
  8701. service.CreateOrderInfo(info)
  8702. }
  8703. his.SickType = sick_type
  8704. service.UpdataHisPateint(&his)
  8705. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8706. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8707. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8708. if err == nil {
  8709. c.ServeSuccessJSON(map[string]interface{}{
  8710. "msg": "结算成功",
  8711. })
  8712. }
  8713. }
  8714. type CustomOrderInfo struct {
  8715. Name string
  8716. Spec string
  8717. Unit string
  8718. Count float64
  8719. Price float64
  8720. Total float64
  8721. }
  8722. func (c *HisApiController) GetPrivateExpensesInfo() {
  8723. order_id, _ := c.GetInt64("id", 0)
  8724. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8725. order, _ := service.GetHisOrderByID(order_id)
  8726. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8727. if order.ID == 0 {
  8728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8729. return
  8730. }
  8731. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8732. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8733. org_id := c.GetAdminUserInfo().CurrentOrgId
  8734. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8735. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8736. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8737. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8738. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8739. //var orderInfos_four []*models.HisOrderInfoTwo
  8740. //for _, item := range orderInfos_three {
  8741. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8742. // item.HisPrescriptionProject.IsCheckTeam = 1
  8743. // orderInfos_four = append(orderInfos_four, item)
  8744. //
  8745. // }
  8746. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8747. // item.HisPrescriptionProject.IsCheckTeam = 2
  8748. // orderInfos_two = append(orderInfos_two, item)
  8749. // }
  8750. //}
  8751. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8752. //var cus_slice []CustomOrderInfo
  8753. //for _, item := range new_order_info {
  8754. // var cus CustomOrderInfo
  8755. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8756. // cus.Unit = ""
  8757. // cus.Spec = ""
  8758. // var total float64
  8759. // for _, subItem := range orderInfos_four {
  8760. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8761. // total = total + subItem.DetItemFeeSumamt
  8762. // fmt.Println(subItem.DetItemFeeSumamt)
  8763. // }
  8764. // }
  8765. // cus.Count = 1
  8766. // cus.Total = total
  8767. // cus_slice = append(cus_slice, cus)
  8768. //}
  8769. orderInfos = append(orderInfos, orderInfos_two...)
  8770. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8771. //orderInfos = append(orderInfos, orderInfos_three...)
  8772. //}/**/
  8773. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8774. c.ServeSuccessJSON(map[string]interface{}{
  8775. "order": order,
  8776. "order_info": orderInfos,
  8777. "patient": patient,
  8778. "admin_info": adminInfo,
  8779. "his": his,
  8780. "current_admin": role,
  8781. "org_config": miConfig,
  8782. //"new_order_info": cus_slice,
  8783. })
  8784. }
  8785. func (this *HisApiController) ChangeMedType() {
  8786. med_type := this.GetString("med_type")
  8787. old_med_type := this.GetString("old_med_type")
  8788. ids := this.GetString("ids")
  8789. settle_type, _ := this.GetInt64("settle_type")
  8790. start_time := this.GetString("start_time")
  8791. end_time := this.GetString("end_time")
  8792. ids_arr := strings.Split(ids, ",")
  8793. if settle_type == 1 { //日结
  8794. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8795. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8796. prescription.MedType = med_type
  8797. err := service.SaveHisPrescription(&prescription)
  8798. if err == nil {
  8799. this.ServeSuccessJSON(map[string]interface{}{
  8800. "msg": "修改成功",
  8801. })
  8802. } else {
  8803. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8804. return
  8805. }
  8806. } else if settle_type == 2 {
  8807. timeLayout := "2006-01-02"
  8808. loc, _ := time.LoadLocation("Local")
  8809. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8810. if err != nil {
  8811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8812. return
  8813. }
  8814. recordStartTime := theStartTime.Unix()
  8815. start_time_timestamp := recordStartTime
  8816. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8817. if err != nil {
  8818. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8819. return
  8820. }
  8821. recordEndTime := theEndTime.Unix()
  8822. end_time_timestamp := recordEndTime
  8823. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8824. if updateErr == nil {
  8825. this.ServeSuccessJSON(map[string]interface{}{
  8826. "msg": "修改成功",
  8827. })
  8828. } else {
  8829. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8830. return
  8831. }
  8832. }
  8833. }
  8834. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8835. patient_id, _ := c.GetInt64("patient_id")
  8836. his_patient_id, _ := c.GetInt64("his_patient_id")
  8837. record_date := c.GetString("record_date")
  8838. start_time := c.GetString("start_time")
  8839. end_time := c.GetString("end_time")
  8840. order_status, _ := c.GetInt64("type", 0)
  8841. p_type, _ := c.GetInt64("p_type", 0)
  8842. order_id, _ := c.GetInt64("order_id", 0)
  8843. timeLayout := "2006-01-02"
  8844. loc, _ := time.LoadLocation("Local")
  8845. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8846. if err != nil {
  8847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8848. return
  8849. }
  8850. recordDateTime := theTime.Unix()
  8851. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8852. if err != nil {
  8853. }
  8854. startRecordDateTime := startTime.Unix()
  8855. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8856. if err != nil {
  8857. }
  8858. endRecordDateTime := endTime.Unix()
  8859. admin := c.GetAdminUserInfo()
  8860. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8861. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8862. order, _ := service.GetHisOrderByID(order_id)
  8863. var monthPrescriptions []*models.HisPrescription
  8864. if order_status == 1 || order_status == 0 {
  8865. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8866. } else if order_status == 2 {
  8867. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8868. }
  8869. var settle_total float64
  8870. for _, item := range monthPrescriptions {
  8871. if len(item.HisPrescriptionProject) > 0 {
  8872. for _, subItem := range item.HisPrescriptionProject {
  8873. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8874. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8875. settle_total = settle_total + total
  8876. }
  8877. }
  8878. if len(item.HisDoctorAdviceInfo) > 0 {
  8879. for _, subItem := range item.HisDoctorAdviceInfo {
  8880. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8881. settle_total = settle_total + total
  8882. }
  8883. }
  8884. }
  8885. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8886. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8887. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8888. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8889. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8890. //获取所有科室信息
  8891. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8892. c.ServeSuccessJSON(map[string]interface{}{
  8893. "his_info": his_patient_info,
  8894. "xt_info": xt_patient_info,
  8895. "case_history": case_history,
  8896. "info": patientPrescriptionInfo,
  8897. "last_info": lastPatientPrescriptionInfo,
  8898. "month_prescriptions": monthPrescriptions,
  8899. "order": order,
  8900. "doctors": doctors,
  8901. "department": department,
  8902. "settle_total": settle_total,
  8903. })
  8904. return
  8905. }
  8906. func (c *HisApiController) GetHisMonthPatientInfo() {
  8907. patient_id, _ := c.GetInt64("patient_id")
  8908. his_patient_id, _ := c.GetInt64("his_patient_id")
  8909. record_date := c.GetString("record_date")
  8910. number := c.GetString("number")
  8911. start_time := c.GetString("start_time")
  8912. end_time := c.GetString("end_time")
  8913. p_type, _ := c.GetInt64("p_type")
  8914. timeLayout := "2006-01-02"
  8915. loc, _ := time.LoadLocation("Local")
  8916. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8917. if err != nil {
  8918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8919. return
  8920. }
  8921. recordDateTime := theTime.Unix()
  8922. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8923. if err != nil {
  8924. }
  8925. startRecordDateTime := startTime.Unix()
  8926. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8927. if err != nil {
  8928. }
  8929. endRecordDateTime := endTime.Unix()
  8930. admin := c.GetAdminUserInfo()
  8931. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8932. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8933. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8934. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8935. var settle_total float64
  8936. for _, item := range monthPrescriptions {
  8937. if len(item.HisPrescriptionProject) > 0 {
  8938. for _, subItem := range item.HisPrescriptionProject {
  8939. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8940. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8941. settle_total = settle_total + total
  8942. }
  8943. }
  8944. if len(item.HisDoctorAdviceInfo) > 0 {
  8945. for _, subItem := range item.HisDoctorAdviceInfo {
  8946. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8947. settle_total = settle_total + total
  8948. }
  8949. }
  8950. }
  8951. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8952. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8953. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8954. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8955. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8956. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8957. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8958. //获取所有科室信息
  8959. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8960. c.ServeSuccessJSON(map[string]interface{}{
  8961. "his_info": his_patient_info,
  8962. "xt_info": xt_patient_info,
  8963. "case_history": case_history,
  8964. "info": patientPrescriptionInfo,
  8965. "month_prescriptions": monthPrescriptions,
  8966. "order": order,
  8967. "doctors": doctors,
  8968. "department": department,
  8969. "count": count,
  8970. "drugStockConfig": drugStockConfig,
  8971. "last_info": lastPatientPrescriptionInfo,
  8972. "settle_total": settle_total,
  8973. })
  8974. return
  8975. }
  8976. func (c *HisApiController) GetAllOrder() {
  8977. org_id := c.GetAdminUserInfo().CurrentOrgId
  8978. orders, _ := service.GetNewHisOrderList(org_id)
  8979. c.ServeSuccessJSON(map[string]interface{}{
  8980. "order": orders,
  8981. })
  8982. return
  8983. }
  8984. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8985. newArr = make([]*models.HisOrderInfoTwo, 0)
  8986. for i := 0; i < len(arr); i++ {
  8987. repeat := false
  8988. for j := i + 1; j < len(arr); j++ {
  8989. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8990. repeat = true
  8991. break
  8992. }
  8993. }
  8994. if !repeat {
  8995. newArr = append(newArr, arr[i])
  8996. }
  8997. }
  8998. return
  8999. }
  9000. // 修改处方退库操作 参数传修改之前的处方数据
  9001. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9002. if advice.ExecutionState == 1 {
  9003. //查询该病人该药品是否有库存记录
  9004. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9005. if errcode == gorm.ErrRecordNotFound {
  9006. } else {
  9007. //退库
  9008. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9009. if advice.PrescribingNumberUnit == drug.MinUnit {
  9010. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9011. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9012. //退库
  9013. warehouseInfo := models.DrugWarehouseInfo{
  9014. StockMinNumber: prescribingNumber,
  9015. }
  9016. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9017. operation_time := time.Now().Unix()
  9018. creater := advice.AdviceDoctor
  9019. ctime := time.Now().Unix()
  9020. timeStr := time.Now().Format("2006-01-02")
  9021. timeArr := strings.Split(timeStr, "-")
  9022. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9023. total = total + 1
  9024. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9025. cancelStock := models.DrugCancelStock{
  9026. OrderNumber: orderNumber,
  9027. OperaTime: operation_time,
  9028. OrgId: advice.UserOrgId,
  9029. Creater: creater,
  9030. Ctime: ctime,
  9031. Status: 1,
  9032. ReturnTime: advice.AdviceDate,
  9033. Dealer: info.Dealer,
  9034. Manufacturer: info.Manufacturer,
  9035. Type: 1,
  9036. }
  9037. service.AddSigleDrugCancelStock(&cancelStock)
  9038. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9039. dealer, _ := service.GetDealerById(info.Dealer)
  9040. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9041. cancelStockInfo := models.DrugCancelStockInfo{
  9042. OrderNumber: cancelInfo.OrderNumber,
  9043. CancelStockId: cancelInfo.ID,
  9044. DrugId: info.DrugId,
  9045. Count: info.Count,
  9046. Status: 1,
  9047. Ctime: ctime,
  9048. OrgId: advice.UserOrgId,
  9049. Type: 1,
  9050. Manufacturer: manufactureName.ManufacturerName,
  9051. Dealer: dealer.DealerName,
  9052. Total: 0,
  9053. RetailPrice: info.RetailPrice,
  9054. RetailTotalPrice: info.RetailTotalPrice,
  9055. Price: info.Price,
  9056. RegisterAccount: "",
  9057. Remark: info.Remark,
  9058. BatchNumber: info.BatchNumber,
  9059. MaxUnit: info.CountUnit,
  9060. ProductDate: info.ProductDate,
  9061. ExpiryDate: info.ExpiryDate,
  9062. BatchNumberId: info.WarehouseInfoId,
  9063. }
  9064. flow := models.DrugFlow{
  9065. WarehousingId: 0,
  9066. DrugId: info.DrugId,
  9067. Number: "",
  9068. BatchNumber: info.BatchNumber,
  9069. Count: info.Count,
  9070. UserOrgId: advice.UserOrgId,
  9071. PatientId: 0,
  9072. SystemTime: ctime,
  9073. ConsumableType: 4,
  9074. IsSys: 0,
  9075. WarehousingOrder: "",
  9076. WarehouseOutId: 0,
  9077. WarehouseOutOrderNumber: "",
  9078. IsEdit: 0,
  9079. CancelStockId: cancelStock.ID,
  9080. CancelOrderNumber: cancelStock.OrderNumber,
  9081. Manufacturer: info.Manufacturer,
  9082. Dealer: info.Dealer,
  9083. Creator: advice.UserOrgId,
  9084. UpdateCreator: 0,
  9085. Status: 1,
  9086. Ctime: time.Now().Unix(),
  9087. Mtime: 0,
  9088. Price: info.Price,
  9089. WarehousingDetailId: 0,
  9090. WarehouseOutDetailId: 0,
  9091. CancelOutDetailId: 0,
  9092. ExpireDate: info.ExpiryDate,
  9093. ProductDate: info.ProductDate,
  9094. MaxUnit: info.CountUnit,
  9095. MinUnit: "",
  9096. }
  9097. service.CreatedCancelStock(cancelStockInfo)
  9098. service.CreateDrugFlowOne(flow)
  9099. } else {
  9100. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9101. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9102. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9103. warehouseInfo := models.DrugWarehouseInfo{
  9104. StockMinNumber: prescribingNumber,
  9105. }
  9106. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9107. }
  9108. operation_time := time.Now().Unix()
  9109. creater := advice.AdviceDoctor
  9110. ctime := time.Now().Unix()
  9111. timeStr := time.Now().Format("2006-01-02")
  9112. timeArr := strings.Split(timeStr, "-")
  9113. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9114. total = total + 1
  9115. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9116. cancelStock := models.DrugCancelStock{
  9117. OrderNumber: orderNumber,
  9118. OperaTime: operation_time,
  9119. OrgId: advice.UserOrgId,
  9120. Creater: creater,
  9121. Ctime: ctime,
  9122. Status: 1,
  9123. ReturnTime: advice.AdviceDate,
  9124. Dealer: info.Dealer,
  9125. Manufacturer: info.Manufacturer,
  9126. Type: 1,
  9127. }
  9128. service.AddSigleDrugCancelStock(&cancelStock)
  9129. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9130. dealer, _ := service.GetDealerById(info.Dealer)
  9131. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9132. cancelStockInfo := models.DrugCancelStockInfo{
  9133. OrderNumber: cancelInfo.OrderNumber,
  9134. CancelStockId: cancelInfo.ID,
  9135. DrugId: info.DrugId,
  9136. Count: info.Count,
  9137. Status: 1,
  9138. Ctime: ctime,
  9139. OrgId: advice.UserOrgId,
  9140. Type: 1,
  9141. Manufacturer: manufactureName.ManufacturerName,
  9142. Dealer: dealer.DealerName,
  9143. Total: 0,
  9144. RetailPrice: info.RetailPrice,
  9145. RetailTotalPrice: info.RetailTotalPrice,
  9146. Price: info.Price,
  9147. RegisterAccount: "",
  9148. Remark: info.Remark,
  9149. BatchNumber: info.BatchNumber,
  9150. MaxUnit: info.CountUnit,
  9151. ProductDate: info.ProductDate,
  9152. ExpiryDate: info.ExpiryDate,
  9153. BatchNumberId: info.WarehouseInfoId,
  9154. }
  9155. flow := models.DrugFlow{
  9156. WarehousingId: 0,
  9157. DrugId: info.DrugId,
  9158. Number: "",
  9159. BatchNumber: info.BatchNumber,
  9160. Count: info.Count,
  9161. UserOrgId: advice.UserOrgId,
  9162. PatientId: 0,
  9163. SystemTime: ctime,
  9164. ConsumableType: 4,
  9165. IsSys: 0,
  9166. WarehousingOrder: "",
  9167. WarehouseOutId: 0,
  9168. WarehouseOutOrderNumber: "",
  9169. IsEdit: 0,
  9170. CancelStockId: cancelStock.ID,
  9171. CancelOrderNumber: cancelStock.OrderNumber,
  9172. Manufacturer: info.Manufacturer,
  9173. Dealer: info.Dealer,
  9174. Creator: advice.AdviceDoctor,
  9175. UpdateCreator: 0,
  9176. Status: 1,
  9177. Ctime: time.Now().Unix(),
  9178. Mtime: 0,
  9179. Price: info.Price,
  9180. WarehousingDetailId: 0,
  9181. WarehouseOutDetailId: 0,
  9182. CancelOutDetailId: 0,
  9183. ExpireDate: info.ExpiryDate,
  9184. ProductDate: info.ProductDate,
  9185. MaxUnit: info.CountUnit,
  9186. MinUnit: "",
  9187. }
  9188. service.CreatedCancelStock(cancelStockInfo)
  9189. service.CreateDrugFlowOne(flow)
  9190. }
  9191. }
  9192. }
  9193. return err
  9194. }
  9195. func (this *HisApiController) DeleteNCDS() {
  9196. id, _ := this.GetInt64("id", 0)
  9197. if id > 0 {
  9198. service.DeletePsnNCDSRecordById(id)
  9199. this.ServeSuccessJSON(map[string]interface{}{
  9200. "msg": "删除成功",
  9201. })
  9202. } else {
  9203. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9204. return
  9205. }
  9206. }
  9207. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9208. id, _ := c.GetInt64("id")
  9209. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9210. c.ServeSuccessJSON(map[string]interface{}{
  9211. "advice": advice,
  9212. })
  9213. return
  9214. }
  9215. func (c *HisApiController) GetHisMonthChargePatientList() {
  9216. record_date := c.GetString("record_date")
  9217. start_time := c.GetString("start_time")
  9218. end_time := c.GetString("end_time")
  9219. timeLayout := "2006-01-02"
  9220. loc, _ := time.LoadLocation("Local")
  9221. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9222. if err != nil {
  9223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9224. return
  9225. }
  9226. if err != nil {
  9227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9228. return
  9229. }
  9230. recordDateTime := theTime.Unix()
  9231. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9232. if err != nil {
  9233. }
  9234. startRecordDateTime := startTime.Unix()
  9235. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9236. if err != nil {
  9237. }
  9238. endRecordDateTime := endTime.Unix()
  9239. adminInfo := c.GetAdminUserInfo()
  9240. var tempMonthChargePatients []*service.MonthChargePatients
  9241. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9242. for _, item := range tempPatients {
  9243. //过滤没有处方的
  9244. if len(item.HisPrescription) == 0 {
  9245. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9246. }
  9247. }
  9248. c.ServeSuccessJSON(map[string]interface{}{
  9249. "list": tempMonthChargePatients,
  9250. })
  9251. }