his_api_controller.go 433KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114
  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. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. }
  88. func (c *HisApiController) GetFaPiaoNumber() {
  89. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  90. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  91. fmt.Println(count)
  92. var zero string
  93. number := count + 1
  94. if number >= 1000 {
  95. zero = "0000" + strconv.FormatInt(number, 10)
  96. } else if number >= 10000 {
  97. zero = "000" + strconv.FormatInt(number, 10)
  98. } else if number >= 100000 {
  99. zero = "00" + strconv.FormatInt(number, 10)
  100. } else if number >= 1000000 {
  101. zero = "0" + strconv.FormatInt(number, 10)
  102. } else {
  103. zero = strconv.FormatInt(number, 10)
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "fapiao_number": zero,
  107. })
  108. return
  109. }
  110. func (c *HisApiController) ChangeOrderDesc() {
  111. id, _ := c.GetInt64("id")
  112. desc := c.GetString("desc")
  113. change_type := c.GetString("change_type")
  114. order, _ := service.GetHisOrderByID(id)
  115. if order.ID == 0 {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. switch change_type {
  120. case "oth_desc":
  121. order.OthDesc = desc
  122. break
  123. case "cash_pay":
  124. order.CashPay = desc
  125. break
  126. case "jifen_pay":
  127. order.JifenPay = desc
  128. break
  129. case "band_card_pay":
  130. order.BandCardPay = desc
  131. break
  132. case "ali_pay":
  133. order.AliPay = desc
  134. break
  135. case "wechat_pay":
  136. order.WechatPay = desc
  137. break
  138. }
  139. err := service.SaveHisOrder(&order)
  140. if err == nil {
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "msg": "修改成功",
  143. })
  144. return
  145. } else {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  147. return
  148. }
  149. }
  150. func (c *HisApiController) GetMonthHisPatient() {
  151. record_date := c.GetString("record_date")
  152. //order_status, _ := c.GetInt64("type")
  153. timeLayout := "2006-01-02"
  154. loc, _ := time.LoadLocation("Local")
  155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  156. if err != nil {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. recordDateTime := theTime.Unix()
  161. adminInfo := c.GetAdminUserInfo()
  162. var tempPatients []service.NewTempPatients
  163. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  164. // 获取当前时间
  165. now := time.Now()
  166. // 获取本月的第一天
  167. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  168. // 获取下个月的第一天
  169. nextMonth := firstDay.AddDate(0, 1, 0)
  170. // 获取本月的最后一天
  171. lastDay := nextMonth.Add(-time.Nanosecond)
  172. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  173. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  174. var patients []service.NewTempPatients
  175. var patients_two []service.NewTempPatients
  176. for _, item := range tempPatients {
  177. //过滤掉没挂号的和没开处方的
  178. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  179. patients = append(patients, item)
  180. }
  181. ////过滤掉没挂号的
  182. //if len(item.HisPatient) > 0 {
  183. // patients_two = append(patients_two, item)
  184. //}
  185. }
  186. c.ServeSuccessJSON(map[string]interface{}{
  187. "list": patients,
  188. "list_two": patients_two,
  189. "chargePatients": chargePatients,
  190. })
  191. }
  192. func (c *HisApiController) GetBatchSettleAccounts() {
  193. order_ids := c.GetString("order_ids")
  194. admin_user_id, _ := c.GetInt64("admin_user_id")
  195. adminUser := c.GetAdminUserInfo()
  196. orders := strings.Split(order_ids, ",")
  197. var newOrders []models.Orders
  198. for _, item := range orders {
  199. order, _ := service.GetHisOrderByIDTenOne(item)
  200. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  201. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  202. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  203. orderInfos = append(orderInfos, orderInfos_two...)
  204. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  205. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  206. var diagnosis_ids []string
  207. if his.ID > 0 {
  208. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  209. } else {
  210. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  211. }
  212. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  213. var dia_config []*models.HisXtDiagnoseConfig
  214. var name string
  215. for _, item := range diagnosis_ids {
  216. id, _ := strconv.ParseInt(item, 10, 64)
  217. diagnosisConfig, _ := service.FindDiagnoseById(id)
  218. dia_config = append(dia_config, diagnosisConfig)
  219. if len(name) == 0 {
  220. name = diagnosisConfig.ClassName
  221. } else {
  222. name = name + "," + diagnosisConfig.ClassName
  223. }
  224. }
  225. var bedCostTotal float64 = 0 //床位总费
  226. var bedCostSelfTotal float64 = 0 //床位自费
  227. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  228. var bedSelfTotal float64 = 0 //床位部分项目自费
  229. var bedInscpTotal float64 = 0 //床位部分项目自费
  230. var operationCostTotal float64 = 0 //手术费
  231. var operationCostSelfTotal float64 = 0 //手术费
  232. var operationCostPartSelfTotal float64 = 0 //手术费
  233. var operationSelfTotal float64 = 0 //床位部分项目自费
  234. var operationInscpTotal float64 = 0 //床位部分项目自费
  235. var otherCostTotal float64 = 0 //其他费用
  236. var otherCostSelfTotal float64 = 0 //其他费用
  237. var otherCostPartSelfTotal float64 = 0 //其他费用
  238. var otherSelfTotal float64 = 0 //床位部分项目自费
  239. var otherInscpTotal float64 = 0 //床位部分项目自费
  240. var materialCostTotal float64 = 0 //材料费
  241. var materialCostSelfTotal float64 = 0 //材料费
  242. var materialCostPartSelfTotal float64 = 0 //材料费
  243. var materialSelfTotal float64 = 0 //床位部分项目自费
  244. var materialInscpTotal float64 = 0 //床位部分项目自费
  245. var westernMedicineCostTotal float64 = 0 //西药费
  246. var westernMedicineCostSelfTotal float64 = 0 //西药费
  247. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  248. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  249. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  250. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  251. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  252. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  253. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  254. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  255. var checkCostTotal float64 = 0 //检查费
  256. var checkCostSelfTotal float64 = 0 //检查费
  257. var checkCostPartSelfTotal float64 = 0 //检查费
  258. var checkSelfTotal float64 = 0 //床位部分项目自费
  259. var checkInscpTotal float64 = 0 //床位部分项目自费
  260. var laboratoryCostTotal float64 = 0 //化验费
  261. var laboratoryCostSelfTotal float64 = 0 //化验费
  262. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  263. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  264. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  265. var treatCostTotal float64 = 0 //治疗费用
  266. var treatCostSelfTotal float64 = 0 //治疗费用
  267. var treatCostPartSelfTotal float64 = 0 //治疗费用
  268. var treatSelfTotal float64 = 0 //床位部分项目自费
  269. var treatInscpTotal float64 = 0 //床位部分项目自费
  270. decimal.DivisionPrecision = 2
  271. for _, item := range orderInfos {
  272. if item.MedChrgitmType == "01" { //床位费
  273. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  274. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  275. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  276. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  277. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  278. }
  279. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  280. if item.MedChrgitmType == "03" { //检查费
  281. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. } else {
  288. if item.MedChrgitmType == "03" { //检查费
  289. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  290. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  291. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  292. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  293. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  294. }
  295. }
  296. if item.MedChrgitmType == "04" { //化验费
  297. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  298. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  299. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  300. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  301. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  302. }
  303. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  304. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  305. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  306. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  307. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  308. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  309. }
  310. if item.MedChrgitmType == "06" { //手术费
  311. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  315. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  316. }
  317. if item.MedChrgitmType == "08" { //材料费
  318. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  319. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  320. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  321. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  322. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  323. }
  324. if item.MedChrgitmType == "09" { //西药费
  325. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  326. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  327. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  328. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  329. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  330. }
  331. if item.MedChrgitmType == "11" { //中成费
  332. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  333. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  334. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  335. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  336. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  337. }
  338. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  339. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  340. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  341. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  342. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  343. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  344. }
  345. }
  346. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  347. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  348. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  349. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  350. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  351. var doctor_name string
  352. if roles.ID == 0 {
  353. doctor_name = "管理员"
  354. } else {
  355. doctor_name = roles.UserName
  356. }
  357. yiliao_leibie := ""
  358. switch order.MedType {
  359. case "11":
  360. yiliao_leibie = "普通门诊"
  361. break
  362. case "12":
  363. yiliao_leibie = "门诊挂号"
  364. break
  365. case "13":
  366. yiliao_leibie = "急诊"
  367. break
  368. case "14":
  369. yiliao_leibie = "门诊特殊病"
  370. break
  371. case "15":
  372. yiliao_leibie = "门诊统筹"
  373. break
  374. case "16":
  375. yiliao_leibie = "门诊慢性病"
  376. break
  377. case "21":
  378. yiliao_leibie = "普通住院"
  379. break
  380. }
  381. var newOrder models.Orders
  382. newOrder.Diagnosis = name
  383. newOrder.OrderInfos = orderInfos
  384. newOrder.Number = order.MdtrtId
  385. newOrder.Date = order.SettleAccountsDate
  386. newOrder.ChargeAdmin = charge_admin
  387. newOrder.PrintorAdmin = printor_admin
  388. newOrder.Order = order
  389. newOrder.BedCostTotal = bedCostTotal
  390. newOrder.BedCostSelfTotal = bedCostSelfTotal
  391. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  392. newOrder.BedSelfTotal = bedSelfTotal
  393. newOrder.BedInscpTotal = bedInscpTotal
  394. newOrder.OperationCostTotal = operationCostTotal
  395. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  396. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  397. newOrder.OperationSelfTotal = operationSelfTotal
  398. newOrder.OperationInscpTotal = operationInscpTotal
  399. newOrder.OtherCostTotal = otherCostTotal
  400. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  401. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  402. newOrder.OtherSelfTotal = otherSelfTotal
  403. newOrder.OtherInscpTotal = otherInscpTotal
  404. newOrder.MaterialCostTotal = materialCostTotal
  405. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  406. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  407. newOrder.MaterialSelfTotal = materialSelfTotal
  408. newOrder.MaterialInscpTotal = materialInscpTotal
  409. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  410. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  411. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  412. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  413. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  414. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  415. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  416. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  417. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  418. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  419. newOrder.CheckCostTotal = checkCostTotal
  420. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  421. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  422. newOrder.CheckSelfTotal = checkSelfTotal
  423. newOrder.CheckInscpTotal = checkInscpTotal
  424. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  425. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  426. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  427. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  428. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  429. newOrder.TreatCostTotal = treatCostTotal
  430. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  431. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  432. newOrder.TreatSelfTotal = treatSelfTotal
  433. newOrder.TreatInscpTotal = treatInscpTotal
  434. newOrder.DoctorInfo = doctor_info
  435. newOrder.DoctorName = doctor_name
  436. newOrder.HealthCardNo = order.PsnNo
  437. newOrder.YiliaoLeibie = yiliao_leibie
  438. newOrder.Patient = patient
  439. newOrder.OrgName = miConfig.OrgName
  440. newOrder.OrgCode = miConfig.Code
  441. newOrder.OrderNumber = order.Number
  442. newOrder.HisPatient = his
  443. newOrder.DiaConfig = dia_config
  444. newOrders = append(newOrders, newOrder)
  445. }
  446. c.ServeSuccessJSON(map[string]interface{}{
  447. "orders": newOrders,
  448. })
  449. }
  450. func (c *HisApiController) GetTestOrder() {
  451. order_id, _ := c.GetInt64("order_id")
  452. admin_user_id, _ := c.GetInt64("admin_user_id")
  453. adminUser := c.GetAdminUserInfo()
  454. order, _ := service.GetHisOrderByID(order_id)
  455. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  456. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  457. orderInfos = append(orderInfos, orderInfos_two...)
  458. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  459. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  460. var dia_config []*models.HisXtDiagnoseConfig
  461. var name string
  462. var bedCostTotal float64 = 0 //床位总费
  463. var bedCostSelfTotal float64 = 0 //床位自费
  464. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  465. var bedSelfTotal float64 = 0 //床位部分项目自费
  466. var bedInscpTotal float64 = 0 //床位部分项目自费
  467. var operationCostTotal float64 = 0 //手术费
  468. var operationCostSelfTotal float64 = 0 //手术费
  469. var operationCostPartSelfTotal float64 = 0 //手术费
  470. var operationSelfTotal float64 = 0 //床位部分项目自费
  471. var operationInscpTotal float64 = 0 //床位部分项目自费
  472. var otherCostTotal float64 = 0 //其他费用
  473. var otherCostSelfTotal float64 = 0 //其他费用
  474. var otherCostPartSelfTotal float64 = 0 //其他费用
  475. var otherSelfTotal float64 = 0 //床位部分项目自费
  476. var otherInscpTotal float64 = 0 //床位部分项目自费
  477. var materialCostTotal float64 = 0 //材料费
  478. var materialCostSelfTotal float64 = 0 //材料费
  479. var materialCostPartSelfTotal float64 = 0 //材料费
  480. var materialSelfTotal float64 = 0 //床位部分项目自费
  481. var materialInscpTotal float64 = 0 //床位部分项目自费
  482. var westernMedicineCostTotal float64 = 0 //西药费
  483. var westernMedicineCostSelfTotal float64 = 0 //西药费
  484. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  485. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  486. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  487. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  488. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  489. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  490. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  491. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  492. var checkCostTotal float64 = 0 //检查费
  493. var checkCostSelfTotal float64 = 0 //检查费
  494. var checkCostPartSelfTotal float64 = 0 //检查费
  495. var checkSelfTotal float64 = 0 //床位部分项目自费
  496. var checkInscpTotal float64 = 0 //床位部分项目自费
  497. var laboratoryCostTotal float64 = 0 //化验费
  498. var laboratoryCostSelfTotal float64 = 0 //化验费
  499. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  500. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  501. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  502. var treatCostTotal float64 = 0 //治疗费用
  503. var treatCostSelfTotal float64 = 0 //治疗费用
  504. var treatCostPartSelfTotal float64 = 0 //治疗费用
  505. var treatSelfTotal float64 = 0 //床位部分项目自费
  506. var treatInscpTotal float64 = 0 //床位部分项目自费
  507. decimal.DivisionPrecision = 2
  508. for _, item := range orderInfos {
  509. if item.MedChrgitmType == "01" { //床位费
  510. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  511. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  512. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  513. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  514. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  515. }
  516. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  517. if item.MedChrgitmType == "03" { //检查费
  518. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. } else {
  525. if item.MedChrgitmType == "03" { //检查费
  526. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  527. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  528. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  529. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  530. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  531. }
  532. }
  533. if item.MedChrgitmType == "04" { //化验费
  534. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  535. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  536. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  537. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  538. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  539. }
  540. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  541. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  542. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  543. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  544. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  545. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  546. }
  547. if item.MedChrgitmType == "06" { //手术费
  548. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  549. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  550. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  551. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  552. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  553. }
  554. if item.MedChrgitmType == "08" { //材料费
  555. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  556. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  557. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  558. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  559. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  560. }
  561. if item.MedChrgitmType == "09" { //西药费
  562. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  563. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  564. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  565. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  566. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  567. }
  568. if item.MedChrgitmType == "11" { //中成费
  569. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  570. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  571. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  572. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  573. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  574. }
  575. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  576. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  577. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  578. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  579. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  580. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  581. }
  582. }
  583. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  584. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  585. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  586. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  587. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  588. var doctor_name string
  589. if roles.ID == 0 {
  590. doctor_name = "管理员"
  591. } else {
  592. doctor_name = roles.UserName
  593. }
  594. yiliao_leibie := ""
  595. switch order.MedType {
  596. case "11":
  597. yiliao_leibie = "普通门诊"
  598. break
  599. case "12":
  600. yiliao_leibie = "门诊挂号"
  601. break
  602. case "13":
  603. yiliao_leibie = "急诊"
  604. break
  605. case "14":
  606. yiliao_leibie = "门诊特殊病"
  607. break
  608. case "15":
  609. yiliao_leibie = "门诊统筹"
  610. break
  611. case "16":
  612. yiliao_leibie = "门诊慢性病"
  613. break
  614. case "21":
  615. yiliao_leibie = "普通住院"
  616. break
  617. }
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "diagnosis": name,
  620. "order_infos": orderInfos,
  621. "number": order.MdtrtId,
  622. "date": order.SettleAccountsDate,
  623. "charge_admin": charge_admin,
  624. "printor_admin": printor_admin,
  625. "info": order,
  626. "order": order,
  627. "bedCostTotal": bedCostTotal,
  628. "bedCostSelfTotal": bedCostSelfTotal,
  629. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  630. "bedSelfTotal": bedSelfTotal,
  631. "bedInscpTotal": bedInscpTotal,
  632. "operationCostTotal": operationCostTotal,
  633. "operationCostSelfTotal": operationCostSelfTotal,
  634. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  635. "operationSelfTotal": operationSelfTotal,
  636. "operationInscpTotal": operationInscpTotal,
  637. "otherCostTotal": otherCostTotal,
  638. "otherCostSelfTotal": otherCostSelfTotal,
  639. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  640. "otherSelfTotal": otherSelfTotal,
  641. "otherInscpTotal": otherInscpTotal,
  642. "materialCostTotal": materialCostTotal,
  643. "materialCostSelfTotal": materialCostSelfTotal,
  644. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  645. "materialSelfTotal": materialSelfTotal,
  646. "materialInscpTotal": materialInscpTotal,
  647. "westernMedicineCostTotal": westernMedicineCostTotal,
  648. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  649. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  650. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  651. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  652. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  653. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  654. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  655. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  656. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  657. "checkCostTotal": checkCostTotal,
  658. "checkCostSelfTotal": checkCostSelfTotal,
  659. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  660. "checkSelfTotal": checkSelfTotal,
  661. "checkInscpTotal": checkInscpTotal,
  662. "laboratoryCostTotal": laboratoryCostTotal,
  663. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  664. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  665. "laboratorySelfTotal": laboratorySelfTotal,
  666. "laboratoryInscpTotal": laboratoryInscpTotal,
  667. "treatCostTotal": treatCostTotal,
  668. "treatCostSelfTotal": treatCostSelfTotal,
  669. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  670. "treatSelfTotal": treatSelfTotal,
  671. "treatInscpTotal": treatInscpTotal,
  672. "doctor_info": doctor_info,
  673. "doctor_name": doctor_name,
  674. "health_card_no": order.PsnNo,
  675. "yiliao_leibie": yiliao_leibie,
  676. "patient": patient,
  677. "org_name": miConfig.OrgName,
  678. "org_code": miConfig.Code,
  679. "order_number": order.Number,
  680. "his_hospital": his_hospital,
  681. "dia_config": dia_config,
  682. })
  683. }
  684. func (c *PublicApiController) GetBaiLinExportData() {
  685. data := service.GetBaiLinOrderData()
  686. fmt.Println(len(data))
  687. var new_data []*models.NewCustomHisOrder
  688. for _, item := range data {
  689. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  690. new_data = append(new_data, item)
  691. }
  692. }
  693. fmt.Println(len(new_data))
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "list": new_data,
  696. })
  697. }
  698. func (c *HisApiController) GetHisUnChargePatientList() {
  699. record_date := c.GetString("record_date")
  700. sch_type, _ := c.GetInt64("sch_type")
  701. timeLayout := "2006-01-02"
  702. loc, _ := time.LoadLocation("Local")
  703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  704. if err != nil {
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. recordDateTime := theTime.Unix()
  709. adminInfo := c.GetAdminUserInfo()
  710. var tempPatients []*service.NewTempPatients
  711. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  712. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  713. var patients []*service.NewTempPatients
  714. var patients_two []*service.NewTempPatients
  715. for _, item := range tempPatients {
  716. //过滤掉没挂号的和没开处方的
  717. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  718. patients = append(patients, item)
  719. }
  720. //过滤掉没挂号的
  721. if len(item.HisPatient) > 0 {
  722. patients_two = append(patients_two, item)
  723. }
  724. }
  725. c.ServeSuccessJSON(map[string]interface{}{
  726. "list": patients,
  727. "list_two": patients_two,
  728. })
  729. }
  730. func (c *HisApiController) GetPrivateExpensesOrder() {
  731. //id, _ := c.GetInt64("id")
  732. //record_time := c.GetString("record_time")
  733. order_id, _ := c.GetInt64("order_id")
  734. admin_user_id, _ := c.GetInt64("admin_user_id")
  735. //timeLayout := "2006-01-02"
  736. //loc, _ := time.LoadLocation("Local")
  737. //
  738. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  739. //if err != nil {
  740. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. // return
  742. //}
  743. //recordDateTime := theTime.Unix()
  744. adminUser := c.GetAdminUserInfo()
  745. order, _ := service.GetHisOrderByID(order_id)
  746. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  747. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  748. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  749. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  750. //var config []*models.HisXtDiagnoseConfig
  751. var name string
  752. if order.PType == 1 {
  753. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  754. for _, item := range diagnosis_ids {
  755. id, _ := strconv.ParseInt(item, 10, 64)
  756. diagnosisConfig, _ := service.FindDiagnoseById(id)
  757. if len(name) == 0 {
  758. name = diagnosisConfig.ClassName
  759. } else {
  760. name = name + "," + diagnosisConfig.ClassName
  761. }
  762. }
  763. } else {
  764. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  765. for _, item := range diagnosis_ids {
  766. id, _ := strconv.ParseInt(item, 10, 64)
  767. diagnosisConfig, _ := service.FindDiagnoseById(id)
  768. if len(name) == 0 {
  769. name = diagnosisConfig.ClassName
  770. } else {
  771. name = name + "," + diagnosisConfig.ClassName
  772. }
  773. }
  774. }
  775. var bedCostTotal float64 = 0 //床位总费
  776. //var bedCostSelfTotal float64 = 0 //床位自费
  777. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  778. var operationCostTotal float64 = 0 //手术费
  779. //var operationCostSelfTotal float64 = 0 //手术费
  780. var operationCostPartSelfTotal float64 = 0 //手术费
  781. var otherCostTotal float64 = 0 //其他费用
  782. //var otherCostSelfTotal float64 = 0 //其他费用
  783. var otherCostPartSelfTotal float64 = 0 //其他费用
  784. var materialCostTotal float64 = 0 //材料费
  785. //var materialCostSelfTotal float64 = 0 //材料费
  786. var materialCostPartSelfTotal float64 = 0 //材料费
  787. var westernMedicineCostTotal float64 = 0 //西药费
  788. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  789. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  790. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  791. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  792. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  793. var checkCostTotal float64 = 0 //检查费
  794. //var checkCostSelfTotal float64 = 0 //检查费
  795. var checkCostPartSelfTotal float64 = 0 //检查费
  796. var laboratoryCostTotal float64 = 0 //化验费
  797. //var laboratoryCostSelfTotal float64 = 0 //化验费
  798. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  799. var treatCostTotal float64 = 0 //治疗费用
  800. //var treatCostSelfTotal float64 = 0 //治疗费用
  801. var treatCostPartSelfTotal float64 = 0 //治疗费用
  802. var zhenChaCostTotal float64 = 0 //其他费用
  803. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  804. decimal.DivisionPrecision = 2
  805. for _, item := range orderInfos {
  806. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  807. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  808. item.MedChrgitmType = "09"
  809. }
  810. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  811. if item.HisPrescriptionProject.Type == 2 {
  812. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  813. fmt.Println("CostClassify")
  814. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  815. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  816. case 0:
  817. item.MedChrgitmType = "0"
  818. break
  819. case 1:
  820. item.MedChrgitmType = "14"
  821. break
  822. case 2:
  823. item.MedChrgitmType = "05"
  824. break
  825. case 3:
  826. item.MedChrgitmType = "03"
  827. break
  828. case 4:
  829. item.MedChrgitmType = "03"
  830. break
  831. case 5:
  832. item.MedChrgitmType = "08"
  833. break
  834. case 6:
  835. item.MedChrgitmType = "14"
  836. break
  837. case 7:
  838. item.MedChrgitmType = "14"
  839. break
  840. case 8:
  841. item.MedChrgitmType = "03"
  842. break
  843. case 9:
  844. item.MedChrgitmType = "14"
  845. break
  846. case 10:
  847. item.MedChrgitmType = "14"
  848. break
  849. case 11:
  850. item.MedChrgitmType = "06"
  851. break
  852. case 12:
  853. item.MedChrgitmType = "12"
  854. break
  855. case 13:
  856. item.MedChrgitmType = "01"
  857. break
  858. case 14:
  859. item.MedChrgitmType = "04"
  860. break
  861. case 15:
  862. item.MedChrgitmType = "14"
  863. break
  864. }
  865. } else {
  866. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  867. case 1:
  868. item.MedChrgitmType = "14"
  869. break
  870. case 2:
  871. item.MedChrgitmType = "05"
  872. break
  873. case 3:
  874. item.MedChrgitmType = "04"
  875. break
  876. case 4:
  877. item.MedChrgitmType = "14"
  878. break
  879. case 5:
  880. item.MedChrgitmType = "08"
  881. break
  882. case 6:
  883. item.MedChrgitmType = "14"
  884. break
  885. case 7:
  886. item.MedChrgitmType = "14"
  887. break
  888. case 8:
  889. item.MedChrgitmType = "03"
  890. break
  891. case 9:
  892. item.MedChrgitmType = "14"
  893. break
  894. }
  895. }
  896. } else if item.HisPrescriptionProject.Type == 3 {
  897. item.MedChrgitmType = "08"
  898. }
  899. }
  900. }
  901. order.PsnCashPay = order.MedfeeSumamt
  902. for _, item := range orderInfos {
  903. if item.MedChrgitmType == "01" { //床位费
  904. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  905. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  906. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  907. }
  908. if item.MedChrgitmType == "02" { //诊察费
  909. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  910. //zhenChaCostSelfTotal = zhenChaCostTotal
  911. }
  912. if item.MedChrgitmType == "03" { //检查费
  913. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  914. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  915. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  916. }
  917. if item.MedChrgitmType == "02" { //检查费
  918. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  919. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  920. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  921. }
  922. if item.MedChrgitmType == "04" { //化验费
  923. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  924. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  925. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  926. }
  927. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  928. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  929. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  930. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  931. }
  932. if item.MedChrgitmType == "06" { //手术费
  933. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  934. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  935. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  936. }
  937. if item.MedChrgitmType == "08" { //材料费
  938. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  939. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  940. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  941. }
  942. if item.MedChrgitmType == "09" { //西药费
  943. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  944. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  945. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  946. }
  947. if item.MedChrgitmType == "11" { //中成费
  948. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  949. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  950. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  951. }
  952. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  953. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  954. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  955. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  956. }
  957. }
  958. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  959. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  960. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  961. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  962. c.ServeSuccessJSON(map[string]interface{}{
  963. "patient": patient,
  964. "order_infos": orderInfos,
  965. "diagnosis": name,
  966. "bedCostTotal": bedCostTotal,
  967. "bedCostSelfTotal": bedCostTotal,
  968. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  969. "operationCostTotal": operationCostTotal,
  970. "operationCostSelfTotal": operationCostTotal,
  971. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  972. "otherCostTotal": otherCostTotal,
  973. "otherCostSelfTotal": otherCostTotal,
  974. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  975. "materialCostTotal": materialCostTotal,
  976. "materialCostSelfTotal": materialCostTotal,
  977. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  978. "westernMedicineCostTotal": westernMedicineCostTotal,
  979. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  980. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  981. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  982. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  983. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  984. "checkCostTotal": checkCostTotal,
  985. "checkCostSelfTotal": checkCostTotal,
  986. "zhenChaCostTotal": zhenChaCostTotal,
  987. "zhenChaCostSelfTotal": zhenChaCostTotal,
  988. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  989. "laboratoryCostTotal": laboratoryCostTotal,
  990. "laboratoryCostSelfTotal": laboratoryCostTotal,
  991. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  992. "treatCostTotal": treatCostTotal,
  993. "treatCostSelfTotal": treatCostTotal,
  994. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  995. "charge_admin": charge_admin,
  996. "printor_admin": printor_admin,
  997. "org_name": org.OrgName,
  998. "org_code": miConfig.Code,
  999. "name": patient.Name,
  1000. "number": order.MdtrtId,
  1001. "date": order.SettleAccountsDate,
  1002. "info": order,
  1003. "his_hospital": his_hospital,
  1004. "his": his,
  1005. })
  1006. }
  1007. func (c *HisApiController) RefudDetail() {
  1008. order_id, _ := c.GetInt64("order_id")
  1009. order, _ := service.GetHisOrderByID(order_id)
  1010. adminUser := c.GetAdminUserInfo()
  1011. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1012. c.ServeSuccessJSON(map[string]interface{}{
  1013. "msg": "撤销成功",
  1014. })
  1015. }
  1016. func (c *HisApiController) Sscard() {
  1017. //r := CardInit()
  1018. //if r == 0 {
  1019. // GetBaseInfo()
  1020. //}
  1021. //c.ServeSuccessJSON(map[string]interface{}{
  1022. // "list": "11",
  1023. //})
  1024. }
  1025. func GetBaseInfo() error {
  1026. //handle := syscall.MustLoadDLL("SSCard.dll")
  1027. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1028. //
  1029. //str := make([]byte, 256)
  1030. //str1 := make([]byte, 256)
  1031. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1032. //if ferr != nil {
  1033. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1034. // return ferr
  1035. //}
  1036. //
  1037. //fmt.Println(string(str))
  1038. //
  1039. //fmt.Println(r)
  1040. return nil
  1041. }
  1042. func CardInit() int {
  1043. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1044. //add := DllTestDef.MustFindProc("Init")
  1045. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1046. //if err != nil {
  1047. // fmt.Println("SSCard的运算结果为:", ret)
  1048. //}
  1049. //result := int(ret)
  1050. return 0
  1051. }
  1052. func IntPtr(n int) uintptr {
  1053. return uintptr(n)
  1054. }
  1055. func StrPtr(s string) uintptr {
  1056. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1057. }
  1058. func (c *HisApiController) GetHisPatientList() {
  1059. //types, _ := c.GetInt64("type", 0)
  1060. record_date := c.GetString("record_date")
  1061. sch_type, _ := c.GetInt64("sch_type")
  1062. timeLayout := "2006-01-02"
  1063. loc, _ := time.LoadLocation("Local")
  1064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1065. if err != nil {
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1067. return
  1068. }
  1069. recordDateTime := theTime.Unix()
  1070. adminInfo := c.GetAdminUserInfo()
  1071. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1072. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1073. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1074. //获取当前用户的信息
  1075. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1076. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1077. //获取所有科室信息
  1078. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1079. c.ServeSuccessJSON(map[string]interface{}{
  1080. "list": patients,
  1081. "list_two": patients_two,
  1082. "info": adminUserInfo,
  1083. "doctors": doctors,
  1084. "department": department,
  1085. })
  1086. }
  1087. type CustomTemplate struct {
  1088. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1089. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1090. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1091. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1092. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1093. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1094. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1095. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1096. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1097. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1098. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1099. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1100. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1101. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1102. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1103. }
  1104. func (c *HisApiController) GetHisPatientInfo() {
  1105. patient_id, _ := c.GetInt64("patient_id")
  1106. his_patient_id, _ := c.GetInt64("his_patient_id")
  1107. record_date := c.GetString("record_date")
  1108. number := c.GetString("number")
  1109. //start_time := c.GetString("start_time")
  1110. //end_time := c.GetString("end_time")
  1111. p_type, _ := c.GetInt64("p_type")
  1112. timeLayout := "2006-01-02"
  1113. loc, _ := time.LoadLocation("Local")
  1114. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1115. if err != nil {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. recordDateTime := theTime.Unix()
  1120. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1121. //if err != nil {
  1122. //
  1123. //}
  1124. //startRecordDateTime := startTime.Unix()
  1125. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1126. //if err != nil {
  1127. //
  1128. //}
  1129. //endRecordDateTime := endTime.Unix()
  1130. admin := c.GetAdminUserInfo()
  1131. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1132. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1133. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1134. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1135. var prescriptions []*models.HisPrescription
  1136. var last_prescriptions []*models.HisPrescription
  1137. var sch_prescriptions []CustomTemplate
  1138. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1139. if p_type == 1 { //住院
  1140. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1141. for _, item := range prescriptions {
  1142. for _, subItem := range item.HisDoctorAdviceInfo {
  1143. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1144. if info.RetailPrice > 0 {
  1145. subItem.Drug.MinPrice = info.RetailPrice
  1146. }
  1147. }
  1148. }
  1149. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1150. } else { //门诊
  1151. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1152. for _, item := range prescriptions {
  1153. for _, subItem := range item.HisDoctorAdviceInfo {
  1154. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1155. if info.RetailPrice > 0 {
  1156. subItem.Drug.MinPrice = info.RetailPrice
  1157. }
  1158. }
  1159. }
  1160. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1161. }
  1162. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1163. if sch.ID > 0 {
  1164. var week string
  1165. t := time.Now()
  1166. switch t.Weekday().String() {
  1167. case "Monday":
  1168. week = "周一"
  1169. break
  1170. case "Tuesday":
  1171. week = "周二"
  1172. break
  1173. case "Wednesday":
  1174. week = "周三"
  1175. break
  1176. case "Thursday":
  1177. week = "周四"
  1178. break
  1179. case "Friday":
  1180. week = "周五"
  1181. break
  1182. case "Saturday":
  1183. week = "周六"
  1184. break
  1185. case "Sunday":
  1186. week = "周日"
  1187. break
  1188. }
  1189. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1190. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1191. //根据推送频率组装新的数组
  1192. for _, item := range temp_sch_prescriptions {
  1193. var cus CustomTemplate
  1194. cus.ID = item.ID
  1195. cus.UserOrgId = item.UserOrgId
  1196. cus.PatientId = item.PatientId
  1197. cus.MedType = item.MedType
  1198. cus.RecordDate = item.RecordDate
  1199. cus.Type = item.Type
  1200. cus.PType = item.PType
  1201. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1202. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1203. if subItem.FrequencyType == 1 { //每次必推
  1204. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1205. }
  1206. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1207. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1208. }
  1209. if subItem.FrequencyType == 2 { //按照天数频率
  1210. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1211. now := p.Unix()
  1212. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1213. dayStr2 := "-" + dayStr
  1214. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1215. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1216. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1217. if len(advices) == 0 {
  1218. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1219. }
  1220. }
  1221. }
  1222. }
  1223. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1224. if subItem.Type == 2 {
  1225. if subItem.XtHisProject.MedicalStatus != 1 {
  1226. if subItem.FrequencyType == 1 {
  1227. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1228. }
  1229. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1230. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1231. }
  1232. if subItem.FrequencyType == 2 {
  1233. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1234. now := p.Unix()
  1235. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1236. dayStr2 := "-" + dayStr
  1237. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1238. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1239. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1240. if len(projects) == 0 {
  1241. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1242. }
  1243. }
  1244. }
  1245. } else if subItem.Type == 3 {
  1246. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1247. if subItem.FrequencyType == 1 {
  1248. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1249. }
  1250. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1251. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1252. }
  1253. if subItem.FrequencyType == 2 {
  1254. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1255. now := p.Unix()
  1256. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1257. dayStr2 := "-" + dayStr
  1258. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1259. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1260. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1261. if len(projects) == 0 {
  1262. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. sch_prescriptions = append(sch_prescriptions, cus)
  1269. }
  1270. for _, item := range sch_prescriptions {
  1271. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1272. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1273. }
  1274. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1275. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1276. }
  1277. }
  1278. }
  1279. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1280. if config.ID > 0 && config.IsOpen == 1 {
  1281. for _, item := range sch_prescriptions {
  1282. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1283. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1284. if info.RetailPrice > 0 {
  1285. subItem.Drug.MinPrice = info.RetailPrice
  1286. }
  1287. }
  1288. }
  1289. }
  1290. if config.ID > 0 && config.IsOpen == 1 {
  1291. for _, item := range sch_prescriptions {
  1292. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1293. if subItem.Type == 3 {
  1294. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1295. if info.Price > 0 {
  1296. subItem.GoodInfo.PackingPrice = info.Price
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1303. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1304. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1305. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1306. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1307. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1308. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1309. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1310. //获取所有科室信息
  1311. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "his_info": his_patient_info,
  1314. "xt_info": xt_patient_info,
  1315. "prescription": prescriptions,
  1316. "case_history": case_history,
  1317. "info": patientPrescriptionInfo,
  1318. //"month_prescriptions": monthPrescriptions,
  1319. "order": order,
  1320. "doctors": doctors,
  1321. "department": department,
  1322. "sch_prescriptions": sch_prescriptions,
  1323. "last_prescriptions": last_prescriptions,
  1324. "schedule": sch,
  1325. "count": count,
  1326. "drugStockConfig": drugStockConfig,
  1327. "last_info": lastPatientPrescriptionInfo,
  1328. })
  1329. return
  1330. }
  1331. func (c *HisApiController) GetHisPrescriptionConfig() {
  1332. adminInfo := c.GetAdminUserInfo()
  1333. //获取医嘱模版
  1334. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1335. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1336. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1337. //获取所有基础药
  1338. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1339. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1340. if config.ID > 0 && config.IsOpen == 1 {
  1341. for _, item := range drugs {
  1342. var index = 0
  1343. for _, subItem := range item.OtherDrugWarehouseInfo {
  1344. if index == 0 {
  1345. index = index + 1
  1346. if subItem.RetailPrice > 0 {
  1347. item.MinPrice = subItem.RetailPrice
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1354. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1355. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1356. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1357. //获取所有科室信息
  1358. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1359. //获取诊断信息
  1360. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1361. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1362. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1363. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1364. //获取是否开启保存耗材出库的开关
  1365. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1366. c.ServeSuccessJSON(map[string]interface{}{
  1367. "drugs": drugs,
  1368. "advices_template": advices,
  1369. "drugways": drugways,
  1370. "efs": efs,
  1371. "doctors": doctors,
  1372. "department": department,
  1373. "sick": sick,
  1374. "additions": additions,
  1375. "diagnose": diagnose,
  1376. "manufacturers": manufacturers,
  1377. "goodOutOpen": goodOutOpen,
  1378. "patientDiagnose": patientDiagnose,
  1379. })
  1380. }
  1381. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1382. //获取所有基础药
  1383. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1384. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1385. if config.ID > 0 && config.IsOpen == 1 {
  1386. for _, item := range drugs {
  1387. var index = 0
  1388. for _, subItem := range item.OtherDrugWarehouseInfo {
  1389. if index == 0 {
  1390. index = index + 1
  1391. if subItem.RetailPrice > 0 {
  1392. item.MinPrice = subItem.RetailPrice
  1393. }
  1394. }
  1395. }
  1396. }
  1397. }
  1398. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1399. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1400. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1401. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1402. //获取所有科室信息
  1403. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1404. //获取诊断信息
  1405. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1406. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1407. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1408. //获取是否开启保存耗材出库的开关
  1409. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1410. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1411. c.ServeSuccessJSON(map[string]interface{}{
  1412. "drugs": drugs,
  1413. "advices_template": advices,
  1414. "drugways": drugways,
  1415. "efs": efs,
  1416. "doctors": doctors,
  1417. "department": department,
  1418. "sick": sick,
  1419. "additions": additions,
  1420. "diagnose": diagnose,
  1421. "manufacturers": manufacturers,
  1422. "goodOutOpen": goodOutOpen,
  1423. "patientDiagnose": patientDiagnose,
  1424. })
  1425. }
  1426. }
  1427. func (c *HisApiController) CreateHisPrescription() {
  1428. record_date := c.GetString("record_date")
  1429. patient_id, _ := c.GetInt64("patient_id")
  1430. reg_type, _ := c.GetInt64("reg_type")
  1431. diagnose := c.GetString("diagnose")
  1432. sick_type, _ := c.GetInt64("sick_type")
  1433. sick_history := c.GetString("sick_history")
  1434. doctor_id, _ := c.GetInt64("doctor", 0)
  1435. department, _ := c.GetInt64("department", 0)
  1436. his_patient_id, _ := c.GetInt64("his_patient_id")
  1437. p_type, _ := c.GetInt64("p_type")
  1438. patient_diagnose := c.GetString("patient_diagnose")
  1439. dataBody := make(map[string]interface{}, 0)
  1440. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1441. if err != nil {
  1442. utils.ErrorLog(err.Error())
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1444. return
  1445. }
  1446. timeLayout := "2006-01-02"
  1447. loc, _ := time.LoadLocation("Local")
  1448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1449. if err != nil {
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1451. return
  1452. }
  1453. adminInfo := c.GetAdminUserInfo()
  1454. recordDateTime := theTime.Unix()
  1455. //查询默认出库仓库库存
  1456. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1457. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1458. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1459. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1460. if len(lists) == 1 {
  1461. his_patient_id = lists[0].ID
  1462. }
  1463. }
  1464. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1465. //保存处方出库
  1466. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1467. //自动出库
  1468. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1469. //耗材保存处方出库
  1470. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1471. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1472. //已发药和已收费限制逻辑
  1473. isMidicine := false
  1474. isCharge := false
  1475. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1476. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1477. if len(prescriptions) > 0 {
  1478. for _, item := range prescriptions {
  1479. items := item.(map[string]interface{})
  1480. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1481. utils.ErrorLog("id")
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. id := int64(items["id"].(float64))
  1486. if id > 0 {
  1487. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1488. if err != nil {
  1489. if new_prescription.OrderStatus == 4 {
  1490. isCharge = true
  1491. }
  1492. }
  1493. }
  1494. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1495. advices := items["advices"].([]interface{})
  1496. if len(advices) > 0 {
  1497. for _, advice := range advices {
  1498. var adviceId int64
  1499. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1500. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1501. }
  1502. if adviceId > 0 {
  1503. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1504. if err == nil {
  1505. if his_advice_info.IsMedicine == 1 {
  1506. isMidicine = true
  1507. }
  1508. }
  1509. }
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. }
  1516. if isMidicine == true {
  1517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1518. return
  1519. }
  1520. if isCharge == true {
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1522. return
  1523. }
  1524. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1525. //药品发药出库
  1526. if pharmacyConfig.IsOpen == 1 {
  1527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1529. if len(prescriptions) > 0 {
  1530. for _, item := range prescriptions {
  1531. items := item.(map[string]interface{})
  1532. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1533. advices := items["advices"].([]interface{})
  1534. if len(advices) > 0 {
  1535. for _, advice := range advices {
  1536. var drug_id int64
  1537. var prescribing_number float64
  1538. var prescribingNumberUnit string
  1539. var adviceId int64
  1540. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1541. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1542. }
  1543. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1544. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1545. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1546. }
  1547. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1548. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1549. }
  1550. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1551. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1552. }
  1553. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1554. if drug.ID == 0 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1556. return
  1557. }
  1558. //查询药品的所有库存
  1559. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1560. var total_count int64
  1561. for _, it := range list {
  1562. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1563. }
  1564. totals := strconv.FormatInt(total_count, 10)
  1565. //查询该药品是否存在开药记录
  1566. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1567. fmt.Println("wooooooooooooo", advicelist.ID)
  1568. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1569. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1570. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1571. //新增处方
  1572. if advicelist.ID == 0 {
  1573. all_count, _ := strconv.ParseFloat(totals, 64)
  1574. if prescribingNumberUnit == drug.MinUnit {
  1575. fmt.Println("prescribing_number", prescribing_number)
  1576. fmt.Println("all_count", all_count)
  1577. if drug.IsUse != 1 {
  1578. if all_count == 0 {
  1579. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1580. return
  1581. }
  1582. if prescribing_number > all_count {
  1583. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1584. return
  1585. }
  1586. }
  1587. }
  1588. if prescribingNumberUnit == drug.MaxUnit {
  1589. num := prescribing_number * float64(drug.MinNumber)
  1590. if drug.IsUse != 1 {
  1591. if all_count == 0 {
  1592. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1593. return
  1594. }
  1595. if num > all_count {
  1596. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1597. return
  1598. }
  1599. }
  1600. }
  1601. }
  1602. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1603. if drugOutConfig.IsOpen != 1 {
  1604. //修改处方
  1605. for _, advice := range advices {
  1606. var drug_id int64
  1607. var prescribing_number float64
  1608. var prescribingNumberUnit string
  1609. var prescribingNumber string
  1610. var adviceId int64
  1611. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1612. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1613. }
  1614. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1615. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1616. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1617. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1618. }
  1619. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1620. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1621. }
  1622. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1623. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1624. }
  1625. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1626. if drug.ID == 0 {
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1628. return
  1629. }
  1630. //查询药品的所有库存
  1631. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1632. var total_count int64
  1633. for _, it := range list {
  1634. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1635. }
  1636. totals := strconv.FormatInt(total_count, 10)
  1637. //查询该药品是否存在开药记录
  1638. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1639. //新增处方
  1640. if advicelist.ID == 0 {
  1641. all_count, _ := strconv.ParseFloat(totals, 64)
  1642. if prescribingNumberUnit == drug.MinUnit {
  1643. if drug.IsUse != 1 {
  1644. if all_count == 0 {
  1645. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1646. return
  1647. }
  1648. if prescribing_number > all_count {
  1649. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1650. return
  1651. }
  1652. }
  1653. } else {
  1654. if prescribingNumberUnit == drug.MaxUnit {
  1655. num := prescribing_number * float64(drug.MinNumber)
  1656. if drug.IsUse != 1 {
  1657. if all_count == 0 {
  1658. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1659. return
  1660. }
  1661. if num > all_count {
  1662. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1663. return
  1664. }
  1665. }
  1666. }
  1667. }
  1668. }
  1669. //修改处方
  1670. if advicelist.ID > 0 {
  1671. var device_number int64
  1672. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1673. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1674. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1675. device_number = prescribingNumberInt * drug.MinNumber
  1676. }
  1677. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1678. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1679. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1680. device_number = prescribingNumberInt
  1681. }
  1682. var number_count int64
  1683. if prescribingNumberUnit == drug.MaxUnit {
  1684. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1685. number_count = prescribingNumberInt * drug.MinNumber
  1686. }
  1687. if prescribingNumberUnit == drug.MinUnit {
  1688. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1689. number_count = prescribingNumberInt
  1690. }
  1691. //如果修改的数量大于之前修改的数量
  1692. if (number_count - device_number) > 0 {
  1693. //如果修改的差数量 大于库存数量
  1694. if drug.IsUse != 1 {
  1695. if (number_count - device_number) > total_count {
  1696. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1697. return
  1698. }
  1699. }
  1700. }
  1701. }
  1702. }
  1703. }
  1704. }
  1705. }
  1706. }
  1707. }
  1708. }
  1709. }
  1710. }
  1711. //已发药和已收费限制逻辑
  1712. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1713. //校验库存总量
  1714. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1715. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1716. if len(prescriptions) > 0 {
  1717. for _, item := range prescriptions {
  1718. items := item.(map[string]interface{})
  1719. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1720. advices := items["advices"].([]interface{})
  1721. if len(advices) > 0 {
  1722. for _, advice := range advices {
  1723. var drug_id int64
  1724. var prescribing_number float64
  1725. var prescribingNumberUnit string
  1726. var adviceId int64
  1727. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1728. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1729. }
  1730. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1731. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1732. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1733. }
  1734. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1735. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1736. }
  1737. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1738. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1739. }
  1740. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1741. if drug.ID == 0 {
  1742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1743. return
  1744. }
  1745. //查询药品的所有库存
  1746. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1747. var total_count int64
  1748. for _, it := range list {
  1749. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1750. }
  1751. totals := strconv.FormatInt(total_count, 10)
  1752. //查询该药品是否存在开药记录
  1753. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1754. //查询最新批次库存
  1755. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1756. var batch_number_count int64
  1757. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1758. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1759. fmt.Println("woowowowowowwowowo", advicelist.ID)
  1760. fmt.Println("prescribing_number", prescribing_number)
  1761. fmt.Println("totototootto", totals)
  1762. //新增处方
  1763. if advicelist.ID == 0 {
  1764. all_count, _ := strconv.ParseFloat(totals, 64)
  1765. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1766. if prescribingNumberUnit == drug.MinUnit {
  1767. if drug.IsUse != 1 {
  1768. if all_count == 0 {
  1769. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1770. return
  1771. }
  1772. if prescribing_number > all_count {
  1773. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1774. return
  1775. }
  1776. if adminInfo.CurrentOrgId == 10215 {
  1777. if prescribing_number > batch_number_all_count {
  1778. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1779. return
  1780. }
  1781. }
  1782. }
  1783. }
  1784. if prescribingNumberUnit == drug.MaxUnit {
  1785. num := prescribing_number * float64(drug.MinNumber)
  1786. if drug.IsUse != 1 {
  1787. if all_count == 0 {
  1788. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1789. return
  1790. }
  1791. if num > all_count {
  1792. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1793. return
  1794. }
  1795. if adminInfo.CurrentOrgId == 10215 {
  1796. if num > batch_number_all_count {
  1797. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1798. return
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1805. if drugOutConfig.IsOpen != 1 {
  1806. //修改处方
  1807. for _, advice := range advices {
  1808. var drug_id int64
  1809. var prescribing_number float64
  1810. var prescribingNumberUnit string
  1811. var prescribingNumber string
  1812. var adviceId int64
  1813. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1814. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1815. }
  1816. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1817. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1818. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1819. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1820. }
  1821. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1822. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1823. }
  1824. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1825. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1826. }
  1827. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1828. if drug.ID == 0 {
  1829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1830. return
  1831. }
  1832. //查询药品的所有库存
  1833. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1834. var total_count int64
  1835. for _, it := range list {
  1836. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1837. }
  1838. totals := strconv.FormatInt(total_count, 10)
  1839. //查询该药品是否存在开药记录
  1840. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1841. //新增处方
  1842. if advicelist.ID == 0 {
  1843. //查询最新批次库存
  1844. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1845. var batch_number_count int64
  1846. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1847. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1848. all_count, _ := strconv.ParseFloat(totals, 64)
  1849. if prescribingNumberUnit == drug.MinUnit {
  1850. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1851. if drug.IsUse != 1 {
  1852. if all_count == 0 {
  1853. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1854. return
  1855. }
  1856. if prescribing_number > all_count {
  1857. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1858. return
  1859. }
  1860. if adminInfo.CurrentOrgId == 10215 {
  1861. if prescribing_number > batch_number_all_count {
  1862. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1863. return
  1864. }
  1865. }
  1866. }
  1867. } else {
  1868. if prescribingNumberUnit == drug.MaxUnit {
  1869. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1870. num := prescribing_number * float64(drug.MinNumber)
  1871. if drug.IsUse != 1 {
  1872. if all_count == 0 {
  1873. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1874. return
  1875. }
  1876. if num > all_count {
  1877. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1878. return
  1879. }
  1880. if adminInfo.CurrentOrgId == 10215 {
  1881. if prescribing_number > batch_number_all_count {
  1882. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1883. return
  1884. }
  1885. }
  1886. }
  1887. }
  1888. }
  1889. }
  1890. //修改处方
  1891. if advicelist.ID > 0 {
  1892. //查询最新批次库存
  1893. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1894. var batch_number_count int64
  1895. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1896. var device_number int64
  1897. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1898. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1899. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1900. device_number = prescribingNumberInt * drug.MinNumber
  1901. }
  1902. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1903. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1904. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1905. device_number = prescribingNumberInt
  1906. }
  1907. var number_count int64
  1908. if prescribingNumberUnit == drug.MaxUnit {
  1909. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1910. number_count = prescribingNumberInt * drug.MinNumber
  1911. }
  1912. if prescribingNumberUnit == drug.MinUnit {
  1913. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1914. number_count = prescribingNumberInt
  1915. }
  1916. //如果修改的数量大于之前修改的数量
  1917. if (number_count - device_number) > 0 {
  1918. //如果修改的差数量 大于库存数量
  1919. if drug.IsUse != 1 {
  1920. if total_count == 0 {
  1921. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1922. return
  1923. }
  1924. if (number_count - device_number) > total_count {
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1926. return
  1927. }
  1928. if (number_count - device_number) > batch_number_count {
  1929. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1930. return
  1931. }
  1932. if adminInfo.CurrentOrgId == 10215 {
  1933. // 查询该药品最后一次出库记录
  1934. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1935. var out_count int64
  1936. var in_count int64
  1937. var stock_max_number int64
  1938. var stock_min_number int64
  1939. for _, it := range outInfo {
  1940. if it.CountUnit == drug.MaxUnit {
  1941. it.Count = it.Count * drug.MinNumber
  1942. }
  1943. out_count += it.Count
  1944. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1945. stock_max_number = warehouseInfoList.StockMaxNumber
  1946. stock_min_number = warehouseInfoList.StockMinNumber
  1947. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1948. }
  1949. if out_count > 0 {
  1950. if (number_count - device_number) > in_count {
  1951. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1952. return
  1953. }
  1954. }
  1955. // 未出库
  1956. if out_count == 0 {
  1957. var sum_in_count int64
  1958. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1959. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1960. fmt.Println("sum_in_count", sum_in_count)
  1961. //如果修改的数量大于有库存的第一个批次
  1962. if number_count > sum_in_count {
  1963. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1964. return
  1965. }
  1966. }
  1967. }
  1968. }
  1969. }
  1970. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1971. if pharmacyConfig.IsOpen != 1 {
  1972. if device_number != number_count {
  1973. // 查询该药品最后一次出库记录
  1974. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1975. //回退库存
  1976. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1977. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1978. }
  1979. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1980. var stock_max_number int64
  1981. var stock_min_number int64
  1982. if number_count >= drug.MinNumber {
  1983. stock_max_number = device_number / drug.MinNumber
  1984. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1985. stock_min_number = device_number % drug.MinNumber
  1986. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1987. } else {
  1988. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1989. }
  1990. }
  1991. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1992. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1993. }
  1994. //删除记录
  1995. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1996. //查询默认仓库剩余多少库存
  1997. var sum_count int64
  1998. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1999. for _, its := range stockInfo {
  2000. if its.MaxUnit == drug.MaxUnit {
  2001. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2002. }
  2003. sum_count += its.StockMaxNumber + its.StockMinNumber
  2004. }
  2005. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. //保存处方开药
  2012. if drugOutConfig.IsOpen == 1 {
  2013. //修改处方
  2014. for _, advice := range advices {
  2015. var drug_id int64
  2016. var prescribing_number float64
  2017. var prescribingNumberUnit string
  2018. var prescribingNumber string
  2019. var adviceId int64
  2020. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2021. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2022. }
  2023. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2024. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2025. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2026. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2027. }
  2028. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2029. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2030. }
  2031. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2032. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2033. }
  2034. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2035. if drug.ID == 0 {
  2036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2037. return
  2038. }
  2039. //查询药品的所有库存
  2040. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2041. var total_count int64
  2042. for _, it := range list {
  2043. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2044. }
  2045. totals := strconv.FormatInt(total_count, 10)
  2046. //查询该药品是否存在开药记录
  2047. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2048. //新增处方
  2049. if advicelist.ID == 0 {
  2050. //查询最新批次库存
  2051. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2052. var batch_number_count int64
  2053. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2054. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2055. all_count, _ := strconv.ParseFloat(totals, 64)
  2056. if prescribingNumberUnit == drug.MinUnit {
  2057. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2058. if drug.IsUse != 1 {
  2059. if all_count == 0 {
  2060. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2061. return
  2062. }
  2063. if prescribing_number > all_count {
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2065. return
  2066. }
  2067. if adminInfo.CurrentOrgId == 10215 {
  2068. if prescribing_number > batch_number_all_count {
  2069. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2070. return
  2071. }
  2072. }
  2073. }
  2074. } else {
  2075. if prescribingNumberUnit == drug.MaxUnit {
  2076. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2077. num := prescribing_number * float64(drug.MinNumber)
  2078. if drug.IsUse != 1 {
  2079. if all_count == 0 {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2081. return
  2082. }
  2083. if num > all_count {
  2084. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2085. return
  2086. }
  2087. if adminInfo.CurrentOrgId == 10215 {
  2088. if prescribing_number > batch_number_all_count {
  2089. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2090. return
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. //修改处方
  2098. if advicelist.ID > 0 {
  2099. //查询最新批次库存
  2100. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2101. var batch_number_count int64
  2102. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2103. var device_number int64
  2104. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2105. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2106. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2107. device_number = prescribingNumberInt * drug.MinNumber
  2108. }
  2109. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2110. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2111. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2112. device_number = prescribingNumberInt
  2113. }
  2114. var number_count int64
  2115. if prescribingNumberUnit == drug.MaxUnit {
  2116. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2117. number_count = prescribingNumberInt * drug.MinNumber
  2118. }
  2119. if prescribingNumberUnit == drug.MinUnit {
  2120. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2121. number_count = prescribingNumberInt
  2122. }
  2123. //如果修改的数量大于之前修改的数量
  2124. if (number_count - device_number) > 0 {
  2125. //如果修改的差数量 大于库存数量
  2126. if drug.IsUse != 1 {
  2127. if total_count == 0 {
  2128. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2129. return
  2130. }
  2131. if (number_count - device_number) > total_count {
  2132. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2133. return
  2134. }
  2135. if adminInfo.CurrentOrgId == 10215 {
  2136. if (number_count - device_number) > batch_number_count {
  2137. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2138. return
  2139. }
  2140. }
  2141. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2142. //查询历史出库数据总批次
  2143. // 查询该药品最后一次出库记录
  2144. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2145. var out_count int64
  2146. var in_count int64
  2147. var stock_max_number int64
  2148. var stock_min_number int64
  2149. for _, it := range outInfo {
  2150. if it.CountUnit == drug.MaxUnit {
  2151. it.Count = it.Count * drug.MinNumber
  2152. }
  2153. out_count += it.Count
  2154. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2155. stock_max_number = warehouseInfoList.StockMaxNumber
  2156. stock_min_number = warehouseInfoList.StockMinNumber
  2157. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2158. }
  2159. if out_count > 0 {
  2160. if (number_count - device_number) > in_count {
  2161. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2162. return
  2163. }
  2164. }
  2165. // 未出库
  2166. if out_count == 0 {
  2167. var sum_in_count int64
  2168. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2169. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2170. if sum_in_count == 0 {
  2171. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2172. return
  2173. }
  2174. //如果修改的数量大于有库存的第一个批次
  2175. if number_count > sum_in_count {
  2176. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2177. return
  2178. }
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. }
  2192. }
  2193. //校验耗材库存
  2194. if goodOutConfig.IsOpen == 1 {
  2195. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2196. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2197. if len(prescriptions) > 0 {
  2198. for _, item := range prescriptions {
  2199. items := item.(map[string]interface{})
  2200. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2201. projects := items["project"].([]interface{})
  2202. if len(projects) > 0 {
  2203. for _, project := range projects {
  2204. var project_id int64
  2205. var project_type int64
  2206. var totals float64
  2207. var project_name string
  2208. var parsetotal int64
  2209. var id int64
  2210. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2211. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2212. }
  2213. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2214. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2215. }
  2216. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2217. total, _ := project.(map[string]interface{})["total"].(string)
  2218. totals, _ = strconv.ParseFloat(total, 64)
  2219. }
  2220. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2221. project_name = project.(map[string]interface{})["project_name"].(string)
  2222. }
  2223. if project_type == 3 {
  2224. //查找该耗材的出库记录
  2225. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2226. if len(goodWarehouseInfo) == 0 {
  2227. //查询耗材库存
  2228. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  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 stock_total_count == 0 {
  2236. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2237. return
  2238. }
  2239. if totals > stock_total_count {
  2240. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2241. return
  2242. }
  2243. }
  2244. if len(goodWarehouseInfo) > 0 {
  2245. //查询该患者耗材的历史数据
  2246. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2247. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2248. //数量发生改变
  2249. if parsetotal != count {
  2250. //如果现在的数量大于历史数量,就要看库存是否足够
  2251. if parsetotal > count {
  2252. //查询耗材所有库存
  2253. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2254. var stock_count int64
  2255. for _, it := range list {
  2256. stock_count += it.StockCount
  2257. }
  2258. //库存不足
  2259. if stock_count == 0 {
  2260. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2261. return
  2262. }
  2263. if (parsetotal - count) > stock_count {
  2264. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2265. return
  2266. }
  2267. }
  2268. }
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }
  2274. }
  2275. }
  2276. }
  2277. }
  2278. //不使用耗材保存处方出库
  2279. if goodOutConfig.IsOpen != 1 {
  2280. if stockConfig.IsOpen == 1 {
  2281. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2282. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2283. if len(prescriptions) > 0 {
  2284. for _, item := range prescriptions {
  2285. items := item.(map[string]interface{})
  2286. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2287. projects := items["project"].([]interface{})
  2288. if len(projects) > 0 {
  2289. for _, project := range projects {
  2290. var project_id int64
  2291. var project_type int64
  2292. var totals float64
  2293. var project_name string
  2294. var parsetotal int64
  2295. var id int64
  2296. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2297. id = int64(project.(map[string]interface{})["id"].(float64))
  2298. }
  2299. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2300. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2301. }
  2302. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2303. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2304. }
  2305. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2306. total, _ := project.(map[string]interface{})["total"].(string)
  2307. totals, _ = strconv.ParseFloat(total, 64)
  2308. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2309. }
  2310. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2311. project_name = project.(map[string]interface{})["project_name"].(string)
  2312. }
  2313. if project_type == 3 {
  2314. //查找该耗材的出库记录
  2315. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2316. //没有出库记录
  2317. if len(goodWarehouseInfo) == 0 {
  2318. //查询耗材库存
  2319. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2320. var stock_count int64
  2321. for _, it := range list {
  2322. stock_count += it.StockCount
  2323. }
  2324. stock_counts := strconv.FormatInt(stock_count, 10)
  2325. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2326. if stock_total_count == 0 {
  2327. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2328. return
  2329. }
  2330. if totals > stock_total_count {
  2331. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2332. return
  2333. }
  2334. //查找今日该患者已经出库的所有耗材
  2335. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2336. for _, item := range goodList {
  2337. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2338. var flush_count int64
  2339. for _, it := range goodListSix {
  2340. flush_count += it.StockCount
  2341. }
  2342. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2343. creater := adminInfo.AdminUser.Id
  2344. if errs != nil {
  2345. goodErrcode := models.XtGoodErrcode{
  2346. UserOrgId: item.OrgId,
  2347. Errcode: "手动出库更新剩余出库失败",
  2348. GoodId: item.GoodId,
  2349. Status: 1,
  2350. Ctime: time.Now().Unix(),
  2351. Mtime: 0,
  2352. Count: 0,
  2353. StockCount: 0,
  2354. Creater: creater,
  2355. BatchNumberId: 0,
  2356. WarehouseOutId: 0,
  2357. }
  2358. service.CreateGoodErrcode(goodErrcode)
  2359. }
  2360. }
  2361. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2362. }
  2363. //有出库记录
  2364. if len(goodWarehouseInfo) > 0 {
  2365. //查询该患者耗材的历史数据
  2366. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2367. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2368. //数量发生改变
  2369. if parsetotal != count {
  2370. //查找今日该患者已经出库的所有耗材
  2371. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2372. for _, item := range goodList {
  2373. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2374. var flush_count int64
  2375. for _, it := range goodListSix {
  2376. flush_count += it.StockCount
  2377. }
  2378. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2379. //减少出库数量
  2380. creater := adminInfo.AdminUser.Id
  2381. if errs != nil {
  2382. goodErrcode := models.XtGoodErrcode{
  2383. UserOrgId: item.OrgId,
  2384. Errcode: "手动出库更新剩余出库失败",
  2385. GoodId: item.GoodId,
  2386. Status: 1,
  2387. Ctime: time.Now().Unix(),
  2388. Mtime: 0,
  2389. Count: 0,
  2390. StockCount: 0,
  2391. Creater: creater,
  2392. BatchNumberId: 0,
  2393. WarehouseOutId: 0,
  2394. }
  2395. service.CreateGoodErrcode(goodErrcode)
  2396. }
  2397. //查询默认仓库
  2398. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2399. var total_count int64
  2400. for _, it := range stockList {
  2401. total_count += it.StockCount
  2402. }
  2403. //基础库插入数据
  2404. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2405. }
  2406. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. }
  2416. }
  2417. }
  2418. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2419. var hpInfo models.HisPrescriptionInfo
  2420. if info.ID == 0 {
  2421. var randNum int
  2422. randNum = rand.Intn(10000) + 1000
  2423. timestamp := time.Now().Unix()
  2424. tempTime := time.Unix(timestamp, 0)
  2425. timeFormat := tempTime.Format("20060102150405")
  2426. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2427. hpInfo = models.HisPrescriptionInfo{
  2428. HisPatientId: his_patient_id,
  2429. UserOrgId: adminInfo.CurrentOrgId,
  2430. RecordDate: theTime.Unix(),
  2431. PatientId: patient_id,
  2432. Status: 1,
  2433. Ctime: time.Now().Unix(),
  2434. Mtime: time.Now().Unix(),
  2435. Creator: adminInfo.AdminUser.Id,
  2436. Modifier: adminInfo.AdminUser.Id,
  2437. Diagnosis: diagnose,
  2438. SickHistory: sick_history,
  2439. Departments: department,
  2440. RegisterType: reg_type,
  2441. PrescriptionNumber: p_number,
  2442. PrescriptionStatus: 1,
  2443. Doctor: role.UserName,
  2444. DoctorId: doctor_id,
  2445. SickType: sick_type,
  2446. PType: p_type,
  2447. PatientDiagnosis: patient_diagnose,
  2448. }
  2449. service.SavePatientPrescriptionInfo(hpInfo)
  2450. //创建步骤表
  2451. finish := models.XtDialysisFinish{
  2452. IsFinish: 1,
  2453. UserOrgId: adminInfo.CurrentOrgId,
  2454. Status: 1,
  2455. Ctime: time.Now().Unix(),
  2456. Mtime: 0,
  2457. Module: 4,
  2458. RecordDate: theTime.Unix(),
  2459. Sourse: 1,
  2460. PatientId: patient_id,
  2461. }
  2462. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2463. if dialysisFinish.ID == 0 {
  2464. service.CreateDialysisFinish(finish)
  2465. }
  2466. redis := service.RedisClient()
  2467. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2468. redis.Set(key, "", time.Second)
  2469. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2470. redis.Set(keyOne, "", time.Second)
  2471. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2472. redis.Set(keySeven, "", time.Second)
  2473. defer redis.Close()
  2474. } else {
  2475. hpInfo = models.HisPrescriptionInfo{
  2476. ID: info.ID,
  2477. UserOrgId: adminInfo.CurrentOrgId,
  2478. RecordDate: info.RecordDate,
  2479. PatientId: info.PatientId,
  2480. Status: 1,
  2481. Ctime: info.Ctime,
  2482. Mtime: time.Now().Unix(),
  2483. Creator: info.Creator,
  2484. Modifier: adminInfo.AdminUser.Id,
  2485. Diagnosis: diagnose,
  2486. SickHistory: sick_history,
  2487. Departments: department,
  2488. RegisterType: reg_type,
  2489. PrescriptionNumber: info.PrescriptionNumber,
  2490. Doctor: role.UserName,
  2491. PrescriptionStatus: info.PrescriptionStatus,
  2492. DoctorId: doctor_id,
  2493. SickType: sick_type,
  2494. PType: info.PType,
  2495. HisPatientId: info.HisPatientId,
  2496. PatientDiagnosis: patient_diagnose,
  2497. }
  2498. service.SavePatientPrescriptionInfo(hpInfo)
  2499. //创建步骤表
  2500. finish := models.XtDialysisFinish{
  2501. IsFinish: 1,
  2502. UserOrgId: adminInfo.CurrentOrgId,
  2503. Status: 1,
  2504. Ctime: time.Now().Unix(),
  2505. Mtime: 0,
  2506. Module: 4,
  2507. RecordDate: info.RecordDate,
  2508. Sourse: 1,
  2509. PatientId: info.PatientId,
  2510. }
  2511. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2512. if dialysisFinish.ID == 0 {
  2513. service.CreateDialysisFinish(finish)
  2514. }
  2515. redis := service.RedisClient()
  2516. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2517. redis.Set(key, "", time.Second)
  2518. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2519. redis.Set(keyOne, "", time.Second)
  2520. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2521. redis.Set(keySeven, "", time.Second)
  2522. defer redis.Close()
  2523. }
  2524. //定义切片
  2525. var adviceList []models.HisDoctorAdviceInfo
  2526. var projectList []models.HisPrescriptionProject
  2527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2529. var tempPrescription *models.HisPrescription
  2530. if len(prescriptions) > 0 {
  2531. for _, item := range prescriptions {
  2532. items := item.(map[string]interface{})
  2533. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2534. utils.ErrorLog("id")
  2535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2536. return
  2537. }
  2538. id := int64(items["id"].(float64))
  2539. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2540. tempPrescription = &new_prescription
  2541. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2542. utils.ErrorLog("type")
  2543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2544. return
  2545. }
  2546. types := int64(items["type"].(float64))
  2547. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2548. utils.ErrorLog("med_type")
  2549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2550. return
  2551. }
  2552. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2553. if med_type == "0" {
  2554. med_type = "14"
  2555. }
  2556. //if order_status == 0 {
  2557. // order_status = 1
  2558. //}
  2559. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2560. utils.ErrorLog("pre_time")
  2561. }
  2562. preTime, _ := items["pre_time"].(string)
  2563. timeLayout := "2006-01-02"
  2564. loc, _ := time.LoadLocation("Local")
  2565. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2566. if err != nil {
  2567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2568. return
  2569. }
  2570. pTime := theTime2.Unix()
  2571. ctime := time.Now().Unix()
  2572. if tempPrescription.ID == 0 {
  2573. prescription := &models.HisPrescription{
  2574. ID: 0,
  2575. PatientId: patient_id,
  2576. UserOrgId: adminInfo.CurrentOrgId,
  2577. RecordDate: recordDateTime,
  2578. Ctime: ctime,
  2579. Mtime: ctime,
  2580. Type: types,
  2581. Modifier: adminInfo.AdminUser.Id,
  2582. Creator: adminInfo.AdminUser.Id,
  2583. Status: 1,
  2584. Doctor: role.UserName,
  2585. HisPatientId: his_patient_id,
  2586. OrderStatus: 1,
  2587. BatchNumber: "",
  2588. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2589. PreTime: pTime,
  2590. PType: p_type,
  2591. MedType: med_type,
  2592. }
  2593. tempPrescription = prescription
  2594. service.SaveHisPrescription(tempPrescription)
  2595. redis := service.RedisClient()
  2596. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2597. redis.Set(key, "", time.Second)
  2598. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2599. redis.Set(keyOne, "", time.Second)
  2600. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2601. redis.Set(keySeven, "", time.Second)
  2602. defer redis.Close()
  2603. } else {
  2604. tempPrescription.ID = id
  2605. tempPrescription.Type = types
  2606. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2607. tempPrescription.Mtime = time.Now().Unix()
  2608. tempPrescription.Doctor = role.UserName
  2609. //tempPrescription.OrderStatus = order_status
  2610. tempPrescription.PreTime = pTime
  2611. tempPrescription.MedType = med_type
  2612. service.SaveHisPrescription(tempPrescription)
  2613. redis := service.RedisClient()
  2614. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2615. redis.Set(key, "", time.Second)
  2616. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2617. redis.Set(keyOne, "", time.Second)
  2618. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2619. redis.Set(keySeven, "", time.Second)
  2620. defer redis.Close()
  2621. }
  2622. //service.SaveHisPrescription(prescription)
  2623. //更改患者挂号状态
  2624. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2625. fmt.Println("更改失败", err2)
  2626. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2627. advices := items["advices"].([]interface{})
  2628. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2629. groupNo := int64(0)
  2630. ctime := time.Now().Unix()
  2631. mtime := ctime
  2632. if len(advices) > 0 {
  2633. for _, advice := range advices {
  2634. var s models.HisDoctorAdviceInfo
  2635. s.PrescriptionId = tempPrescription.ID
  2636. s.AdviceType = 2
  2637. s.AdviceDoctor = doctor_id
  2638. s.StopState = 2
  2639. s.ExecutionState = 2
  2640. s.AdviceDate = recordDateTime
  2641. s.Status = 1
  2642. s.UserOrgId = adminInfo.CurrentOrgId
  2643. s.RecordDate = recordDateTime
  2644. s.StartTime = tempPrescription.PreTime
  2645. s.Groupno = groupNo
  2646. s.CreatedTime = ctime
  2647. s.UpdatedTime = mtime
  2648. s.PatientId = patient_id
  2649. s.HisPatientId = his_patient_id
  2650. s.StartTime = pTime
  2651. s.IsSettle = 2
  2652. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2653. if errcode > 0 {
  2654. c.ServeFailJSONWithSGJErrorCode(errcode)
  2655. return
  2656. }
  2657. s.StartTime = pTime
  2658. var total_count int64 //处方总库存
  2659. //查询改药品信息
  2660. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2661. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2662. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2663. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2664. total_count += prescribingNumberSeven * medical.MinNumber
  2665. }
  2666. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2667. total_count += prescribingNumberSeven
  2668. }
  2669. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2670. total_count += prescribingNumberSeven
  2671. }
  2672. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2673. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2674. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2675. if s.Price != lastWarehouse.RetailPrice {
  2676. s.Price = lastWarehouse.RetailPrice
  2677. }
  2678. if s.Price == 0 {
  2679. s.Price = lastWarehouse.RetailPrice
  2680. }
  2681. }
  2682. service.CreateHisDoctorAdvice(&s)
  2683. //记录日志
  2684. byterequest, _ := json.Marshal(s)
  2685. adviceLog := models.XtDoctorAdviceLog{
  2686. UserOrgId: s.UserOrgId,
  2687. PatientId: s.PatientId,
  2688. AdminUserId: adminInfo.AdminUser.Id,
  2689. Module: 1,
  2690. ErrLog: string(byterequest),
  2691. Status: 1,
  2692. Ctime: time.Now().Unix(),
  2693. Mtime: 0,
  2694. Source: "电脑端新建his医嘱",
  2695. RecordDate: s.AdviceDate,
  2696. }
  2697. service.CreateDoctorAdviceLog(adviceLog)
  2698. //存储切片中
  2699. adviceList = append(adviceList, s)
  2700. redis := service.RedisClient()
  2701. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2702. redis.Set(key, "", time.Second)
  2703. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2704. redis.Set(keyOne, "", time.Second)
  2705. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2706. redis.Set(keySeven, "", time.Second)
  2707. var randNum int
  2708. randNum = rand.Intn(10000) + 1000
  2709. timestamp := time.Now().Unix()
  2710. tempTime := time.Unix(timestamp, 0)
  2711. timeFormat := tempTime.Format("20060102150405")
  2712. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2713. service.CreateHisDoctorAdvice(&s)
  2714. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2715. redis.Set(keySix, "", time.Second)
  2716. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2717. redis.Set(keyFive, "", time.Second)
  2718. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2719. redis.Set(keyEight, "", time.Second)
  2720. defer redis.Close()
  2721. }
  2722. }
  2723. }
  2724. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2725. projects := items["project"].([]interface{})
  2726. if len(projects) > 0 {
  2727. for _, project := range projects {
  2728. var p models.HisPrescriptionProject
  2729. p.PrescriptionId = tempPrescription.ID
  2730. p.Ctime = time.Now().Unix()
  2731. p.Mtime = time.Now().Unix()
  2732. p.PatientId = patient_id
  2733. p.RecordDate = recordDateTime
  2734. p.Doctor = doctor_id
  2735. p.UserOrgId = adminInfo.CurrentOrgId
  2736. p.HisPatientId = his_patient_id
  2737. p.Status = 1
  2738. p.StartTime = pTime
  2739. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2740. if errcode > 0 {
  2741. c.ServeFailJSONWithSGJErrorCode(errcode)
  2742. return
  2743. }
  2744. if p.ID == 0 {
  2745. p.IsOut = 2
  2746. }
  2747. if p.ID > 0 {
  2748. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2749. p.IsOut = projectDetail.IsOut
  2750. }
  2751. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2752. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2753. if p.Type == 3 {
  2754. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2755. if p.Price != lastWarehouse.PackingPrice {
  2756. p.Price = lastWarehouse.PackingPrice
  2757. }
  2758. if p.Unit == "" {
  2759. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2760. p.Unit = goodInfoOne.PackingUnit
  2761. }
  2762. }
  2763. }
  2764. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2765. //
  2766. // if p.Type == 3 {
  2767. // //查询该耗材是否停用
  2768. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2769. // //表示该耗材已经停用,不能保存
  2770. // if goodInfoSeven.ID == 0 {
  2771. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2772. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2773. // return
  2774. // }
  2775. // }
  2776. //
  2777. //}
  2778. service.CreateHisProjectTwo(&p)
  2779. //记录日志
  2780. byterequest, _ := json.Marshal(p)
  2781. adviceLog := models.XtDoctorAdviceLog{
  2782. UserOrgId: p.UserOrgId,
  2783. PatientId: p.PatientId,
  2784. AdminUserId: adminInfo.AdminUser.Id,
  2785. Module: 1,
  2786. ErrLog: string(byterequest),
  2787. Status: 1,
  2788. Ctime: time.Now().Unix(),
  2789. Mtime: 0,
  2790. Source: "电脑端新建his项目",
  2791. RecordDate: p.RecordDate,
  2792. }
  2793. service.CreateDoctorAdviceLog(adviceLog)
  2794. projectList = append(projectList, p)
  2795. var randNum int
  2796. randNum = rand.Intn(10000) + 1000
  2797. timestamp := time.Now().Unix()
  2798. tempTime := time.Unix(timestamp, 0)
  2799. timeFormat := tempTime.Format("20060102150405")
  2800. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2801. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2802. //新增或者编辑项目,修改对应的标签数据
  2803. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2804. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2805. var label models.HisLabelPrintInfo
  2806. project, _ := service.GetProjectDetail(p.ProjectId)
  2807. if project.CostClassify == 3 { //类别为检验检查
  2808. if p.TeamId > 0 { //检验检查组套
  2809. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2810. if tempLabel.ID == 0 {
  2811. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2812. label.Number = tempPrescription.PrescriptionNumber
  2813. label.ProjectId = project.ID
  2814. label.Status = 1
  2815. label.IsPrint = 2
  2816. label.DoctorId = info.DoctorId
  2817. label.UserOrgId = p.UserOrgId
  2818. label.PatientId = patient_id
  2819. label.RecordDate = recordDateTime
  2820. label.Ctime = time.Now().Unix()
  2821. label.Mtime = time.Now().Unix()
  2822. label.ItemId = p.TeamId
  2823. label.FeedetlSn = p.FeedetlSn
  2824. label.PProjectId = p.ID
  2825. label.ProjectName = team.ProjectTeam
  2826. label.PatientName = patient.Name
  2827. service.CreateHisLabelRecord(&label)
  2828. }
  2829. } else { //单条检验检查项目
  2830. label.Number = tempPrescription.PrescriptionNumber
  2831. label.ProjectId = project.ID
  2832. label.Status = 1
  2833. label.DoctorId = info.DoctorId
  2834. label.UserOrgId = p.UserOrgId
  2835. label.PatientId = patient_id
  2836. label.RecordDate = recordDateTime
  2837. label.IsPrint = 2
  2838. label.Ctime = time.Now().Unix()
  2839. label.Mtime = time.Now().Unix()
  2840. label.FeedetlSn = p.FeedetlSn
  2841. label.PProjectId = p.ID
  2842. label.ItemId = p.TeamId
  2843. label.ProjectName = project.ProjectName
  2844. label.PatientName = patient.Name
  2845. service.CreateHisLabelRecord(&label)
  2846. }
  2847. }
  2848. }
  2849. }
  2850. service.SaveHisProjectTwo(&p)
  2851. }
  2852. }
  2853. }
  2854. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2855. // addition := items["addition"].([]interface{})
  2856. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2857. // ctime := time.Now().Unix()
  2858. // mtime := ctime
  2859. // if len(addition) > 0 {
  2860. // for _, item := range addition {
  2861. // var s models.HisAdditionalCharge
  2862. // s.PrescriptionId = tempPrescription.ID
  2863. // s.Status = 1
  2864. // s.UserOrgId = adminInfo.CurrentOrgId
  2865. // s.RecordDate = recordDateTime
  2866. // s.CreatedTime = ctime
  2867. // s.UpdatedTime = mtime
  2868. // s.PatientId = patient_id
  2869. // s.HisPatientId = his_patient_id
  2870. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2871. // if errcode > 0 {
  2872. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2873. // return
  2874. // }
  2875. // service.CreateAdditionalCharge(&s)
  2876. // var randNum int
  2877. // randNum = rand.Intn(10000) + 1000
  2878. // timestamp := time.Now().Unix()
  2879. // tempTime := time.Unix(timestamp, 0)
  2880. // timeFormat := tempTime.Format("20060102150405")
  2881. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2882. // service.CreateAdditionalCharge(&s)
  2883. //
  2884. // }
  2885. // }
  2886. //}
  2887. }
  2888. }
  2889. //查询今日该患者开的药品处方
  2890. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2891. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2892. //药品出库
  2893. if drugOutConfig.IsOpen == 1 {
  2894. for _, item := range hisdoctorlist {
  2895. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2896. // 查询该药品最后一次出库记录
  2897. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2898. if len(druginfo) > 0 {
  2899. //回退库存
  2900. for _, it := range druginfo {
  2901. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2902. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2903. }
  2904. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2905. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2906. }
  2907. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2908. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2909. }
  2910. }
  2911. }
  2912. //删除记录
  2913. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2914. //查询最后一次数据
  2915. if drugOutConfig.IsOpen == 1 {
  2916. //出库
  2917. if drug.IsUse == 2 {
  2918. creater := adminInfo.AdminUser.Id
  2919. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2920. }
  2921. //更新字典里面的库存
  2922. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2923. var sum_count int64
  2924. for _, its := range stockInfo {
  2925. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2926. if its.MaxUnit == baseDrug.MaxUnit {
  2927. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2928. }
  2929. sum_count += its.StockMaxNumber + its.StockMinNumber
  2930. }
  2931. //更新基础库存
  2932. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2933. //剩余库存
  2934. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2935. }
  2936. }
  2937. }
  2938. //耗材保存处方出库
  2939. if goodOutConfig.IsOpen == 1 {
  2940. //查询今日耗材出库数量
  2941. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2942. for _, item := range hisgoodlist {
  2943. //查询历史出库数据
  2944. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2945. var out_count_five int64
  2946. for _, item := range flowGood {
  2947. out_count_five += item.Count
  2948. }
  2949. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2950. if out_count_five != parseIntCount {
  2951. //查询耗材最后一次出库记录
  2952. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2953. //查询默认出库仓库库存
  2954. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2955. if len(wareOut) > 0 {
  2956. for _, it := range wareOut {
  2957. //回退库存
  2958. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2959. //删除出库记录
  2960. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2961. }
  2962. }
  2963. timeStr := time.Now().Format("2006-01-02")
  2964. timeArr := strings.Split(timeStr, "-")
  2965. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2966. total = total + 1
  2967. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2968. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2969. number = number + total
  2970. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2971. operation_time := time.Now().Unix()
  2972. creater := c.GetAdminUserInfo().AdminUser.Id
  2973. recordDateStr := time.Now().Format("2006-01-02")
  2974. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2975. nowtime := recordDate.Unix()
  2976. warehouseOut := models.WarehouseOut{
  2977. WarehouseOutOrderNumber: warehousing_out_order,
  2978. OperationTime: operation_time,
  2979. OrgId: adminInfo.CurrentOrgId,
  2980. Creater: creater,
  2981. Ctime: time.Now().Unix(),
  2982. Status: 1,
  2983. WarehouseOutTime: nowtime,
  2984. Type: 1,
  2985. StorehouseId: storeConfig.StorehouseOutInfo,
  2986. IsCheck: 1,
  2987. IsSys: 1,
  2988. }
  2989. //查询是否生成出库单
  2990. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2991. if out.ID == 0 {
  2992. service.AddSigleWarehouseOut(&warehouseOut)
  2993. }
  2994. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2995. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2996. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2997. dialyPrepareOne := models.DialysisBeforePrepare{
  2998. GoodTypeId: goodObj.GoodTypeId,
  2999. GoodId: item.ProjectId,
  3000. PatientId: item.PatientId,
  3001. RecordDate: item.RecordDate,
  3002. UserOrgId: adminInfo.CurrentOrgId,
  3003. Count: parseIntCount,
  3004. Ctime: time.Now().Unix(),
  3005. Creater: creater,
  3006. Status: 1,
  3007. StorehouseId: houseConfig.StorehouseOutInfo,
  3008. ProjectId: item.ID,
  3009. }
  3010. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3011. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3012. //查询历史出库数据
  3013. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3014. var out_count int64
  3015. for _, item := range flowGood {
  3016. out_count += item.Count
  3017. }
  3018. //如果历史数和当前数据不想等才进行退库出库
  3019. if out_count != parseIntCount {
  3020. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3021. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3022. detail := models.AutomaticReduceDetail{
  3023. WarehouseOutId: 0,
  3024. WarehouseOutOrderNumber: "",
  3025. PatientId: item.PatientId,
  3026. Ctime: time.Now().Unix(),
  3027. Mtime: 0,
  3028. Status: 1,
  3029. RecordTime: item.RecordDate,
  3030. OrgId: item.UserOrgId,
  3031. GoodId: item.ProjectId,
  3032. GoodTypeId: 0,
  3033. Count: parseIntCount,
  3034. Type: 0,
  3035. ProjectId: item.ID,
  3036. StorehouseId: 0,
  3037. }
  3038. service.CreateAutoDetail(detail)
  3039. //查询剩余库存
  3040. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3041. var sum_count int64
  3042. for _, item := range goodList {
  3043. sum_count += item.StockCount
  3044. }
  3045. //更新剩余库存
  3046. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3047. //耗材
  3048. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3049. }
  3050. }
  3051. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3052. //查询历史出库数据
  3053. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3054. var out_count int64
  3055. for _, item := range flowGood {
  3056. out_count += item.Count
  3057. }
  3058. //如果历史数和当前数据不想等才进行退库出库
  3059. if out_count != parseIntCount {
  3060. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3061. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3062. detail := models.AutomaticReduceDetail{
  3063. WarehouseOutId: 0,
  3064. WarehouseOutOrderNumber: "",
  3065. PatientId: item.PatientId,
  3066. Ctime: time.Now().Unix(),
  3067. Mtime: 0,
  3068. Status: 1,
  3069. RecordTime: item.RecordDate,
  3070. OrgId: item.UserOrgId,
  3071. GoodId: item.ProjectId,
  3072. GoodTypeId: 0,
  3073. Count: parseIntCount,
  3074. Type: 0,
  3075. ProjectId: item.ID,
  3076. StorehouseId: 0,
  3077. }
  3078. service.CreateAutoDetail(detail)
  3079. //查询剩余库存
  3080. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3081. var sum_count int64
  3082. for _, item := range goodList {
  3083. sum_count += item.StockCount
  3084. }
  3085. //更新剩余库存
  3086. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3087. //耗材
  3088. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3089. }
  3090. }
  3091. }
  3092. }
  3093. }
  3094. }
  3095. //redisClient := service.RedisClient()
  3096. //defer redisClient.Close()
  3097. //
  3098. //list := models.HisList{
  3099. // Patient_id: patient_id,
  3100. // Advice_id:0,
  3101. // Record_date: 0,
  3102. // Advice: adviceList,
  3103. // Project: nil,
  3104. //}
  3105. //hisLis = append(hisLis, list)
  3106. //
  3107. //advice_json, _ := json.Marshal(&hisLis)
  3108. //redisClient.RPush("111", advice_json).Result()
  3109. //result, _ := redisClient.RPop("111").Result()
  3110. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3111. //
  3112. //var dat []map[string]interface{}
  3113. //json.Unmarshal([]byte(result), &dat)
  3114. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3115. //
  3116. //for k,v:=range dat{
  3117. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3118. //}
  3119. //project_json, _ := json.Marshal(&projectList)
  3120. //redisClient.LPush("222", project_json).Result()
  3121. if err == nil {
  3122. c.ServeSuccessJSON(map[string]interface{}{
  3123. "msg": "保存成功",
  3124. })
  3125. return
  3126. } else {
  3127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3128. return
  3129. }
  3130. }
  3131. func (c *HisApiController) EditHisPrescription() {
  3132. record_date := c.GetString("record_date")
  3133. patient_id, _ := c.GetInt64("patient_id")
  3134. reg_type, _ := c.GetInt64("reg_type")
  3135. //diagnose, _ := c.GetInt64("diagnose", 0)
  3136. diagnose := c.GetString("diagnose")
  3137. sick_type, _ := c.GetInt64("sick_type")
  3138. sick_history := c.GetString("sick_history")
  3139. doctor_id, _ := c.GetInt64("doctor", 0)
  3140. department, _ := c.GetInt64("department", 0)
  3141. his_patient_id, _ := c.GetInt64("his_patient_id")
  3142. p_type, _ := c.GetInt64("p_type")
  3143. dataBody := make(map[string]interface{}, 0)
  3144. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3145. if err != nil {
  3146. utils.ErrorLog(err.Error())
  3147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3148. return
  3149. }
  3150. timeLayout := "2006-01-02"
  3151. loc, _ := time.LoadLocation("Local")
  3152. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3153. if err != nil {
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3155. return
  3156. }
  3157. adminInfo := c.GetAdminUserInfo()
  3158. recordDateTime := theTime.Unix()
  3159. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3160. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3161. var hpInfo models.HisPrescriptionInfo
  3162. if info.ID == 0 {
  3163. var randNum int
  3164. randNum = rand.Intn(10000) + 1000
  3165. timestamp := time.Now().Unix()
  3166. tempTime := time.Unix(timestamp, 0)
  3167. timeFormat := tempTime.Format("20060102150405")
  3168. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3169. hpInfo = models.HisPrescriptionInfo{
  3170. UserOrgId: adminInfo.CurrentOrgId,
  3171. RecordDate: theTime.Unix(),
  3172. PatientId: patient_id,
  3173. Status: 1,
  3174. Ctime: time.Now().Unix(),
  3175. Mtime: time.Now().Unix(),
  3176. Creator: adminInfo.AdminUser.Id,
  3177. Modifier: adminInfo.AdminUser.Id,
  3178. Diagnosis: diagnose,
  3179. SickHistory: sick_history,
  3180. Departments: department,
  3181. RegisterType: reg_type,
  3182. PrescriptionNumber: p_number,
  3183. PrescriptionStatus: 1,
  3184. Doctor: role.UserName,
  3185. DoctorId: doctor_id,
  3186. SickType: sick_type,
  3187. PType: p_type,
  3188. }
  3189. service.SavePatientPrescriptionInfo(hpInfo)
  3190. } else {
  3191. hpInfo = models.HisPrescriptionInfo{
  3192. ID: info.ID,
  3193. UserOrgId: adminInfo.CurrentOrgId,
  3194. RecordDate: info.RecordDate,
  3195. PatientId: info.PatientId,
  3196. Status: 1,
  3197. Ctime: info.Ctime,
  3198. Mtime: time.Now().Unix(),
  3199. Creator: info.Creator,
  3200. Modifier: adminInfo.AdminUser.Id,
  3201. Diagnosis: diagnose,
  3202. SickHistory: sick_history,
  3203. Departments: department,
  3204. RegisterType: reg_type,
  3205. PrescriptionNumber: info.PrescriptionNumber,
  3206. Doctor: role.UserName,
  3207. PrescriptionStatus: info.PrescriptionStatus,
  3208. DoctorId: doctor_id,
  3209. SickType: sick_type,
  3210. PType: info.PType,
  3211. }
  3212. service.SavePatientPrescriptionInfo(hpInfo)
  3213. }
  3214. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3215. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3216. if len(prescriptions) > 0 {
  3217. for _, item := range prescriptions {
  3218. items := item.(map[string]interface{})
  3219. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3220. utils.ErrorLog("id")
  3221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3222. return
  3223. }
  3224. id := int64(items["id"].(float64))
  3225. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3226. utils.ErrorLog("type")
  3227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3228. return
  3229. }
  3230. types := int64(items["type"].(float64))
  3231. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3232. utils.ErrorLog("med_type")
  3233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3234. return
  3235. }
  3236. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3237. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3238. ctime := time.Now().Unix()
  3239. prescription := &models.HisPrescription{
  3240. ID: id,
  3241. PatientId: patient_id,
  3242. UserOrgId: adminInfo.CurrentOrgId,
  3243. RecordDate: recordDateTime,
  3244. Ctime: ctime,
  3245. Mtime: ctime,
  3246. Type: types,
  3247. Modifier: adminInfo.AdminUser.Id,
  3248. Creator: adminInfo.AdminUser.Id,
  3249. Status: 1,
  3250. Doctor: role.UserName,
  3251. HisPatientId: his_patient_id,
  3252. OrderStatus: 1,
  3253. BatchNumber: "",
  3254. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3255. PType: hpInfo.PType,
  3256. MedType: med_type,
  3257. }
  3258. if historyPrescription.ID > 0 {
  3259. prescription.PreTime = historyPrescription.PreTime
  3260. }
  3261. service.SaveHisPrescription(prescription)
  3262. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3263. advices := items["advices"].([]interface{})
  3264. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3265. groupNo := int64(0)
  3266. ctime := time.Now().Unix()
  3267. mtime := ctime
  3268. if len(advices) > 0 {
  3269. for _, advice := range advices {
  3270. var s models.HisDoctorAdviceInfo
  3271. s.PrescriptionId = prescription.ID
  3272. s.AdviceType = 2
  3273. s.AdviceDoctor = adminInfo.AdminUser.Id
  3274. s.StopState = 2
  3275. s.ExecutionState = 2
  3276. s.AdviceDate = recordDateTime
  3277. s.Status = 1
  3278. s.UserOrgId = adminInfo.CurrentOrgId
  3279. s.RecordDate = recordDateTime
  3280. s.StartTime = prescription.PreTime
  3281. s.Groupno = groupNo
  3282. s.CreatedTime = ctime
  3283. s.UpdatedTime = mtime
  3284. s.PatientId = patient_id
  3285. s.HisPatientId = his_patient_id
  3286. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3287. if errcode > 0 {
  3288. c.ServeFailJSONWithSGJErrorCode(errcode)
  3289. return
  3290. }
  3291. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3292. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3293. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3294. if s.Price == 0 {
  3295. s.Price = lastWarehouse.RetailPrice
  3296. }
  3297. }
  3298. service.CreateHisDoctorAdvice(&s)
  3299. //记录日志
  3300. byterequest, _ := json.Marshal(s)
  3301. adviceLog := models.XtDoctorAdviceLog{
  3302. UserOrgId: s.UserOrgId,
  3303. PatientId: s.PatientId,
  3304. AdminUserId: adminInfo.AdminUser.Id,
  3305. Module: 1,
  3306. ErrLog: string(byterequest),
  3307. Status: 1,
  3308. Ctime: time.Now().Unix(),
  3309. Mtime: 0,
  3310. Source: "电脑端his医嘱修改",
  3311. RecordDate: s.AdviceDate,
  3312. }
  3313. service.CreateDoctorAdviceLog(adviceLog)
  3314. redis := service.RedisClient()
  3315. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3316. redis.Set(key, "", time.Second)
  3317. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3318. fmt.Println("keyOne", keyOne)
  3319. redis.Set(keyOne, "", time.Second)
  3320. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3321. redis.Set(keySeven, "", time.Second)
  3322. redis.Close()
  3323. }
  3324. }
  3325. }
  3326. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3327. projects := items["project"].([]interface{})
  3328. if len(projects) > 0 {
  3329. for _, project := range projects {
  3330. var p models.HisPrescriptionProject
  3331. p.PrescriptionId = prescription.ID
  3332. p.Ctime = time.Now().Unix()
  3333. p.Mtime = time.Now().Unix()
  3334. p.PatientId = patient_id
  3335. p.RecordDate = recordDateTime
  3336. p.UserOrgId = adminInfo.CurrentOrgId
  3337. p.HisPatientId = his_patient_id
  3338. p.Status = 1
  3339. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3340. if errcode > 0 {
  3341. c.ServeFailJSONWithSGJErrorCode(errcode)
  3342. return
  3343. }
  3344. service.CreateHisProjectTwo(&p)
  3345. //记录日志
  3346. byterequest, _ := json.Marshal(p)
  3347. adviceLog := models.XtDoctorAdviceLog{
  3348. UserOrgId: p.UserOrgId,
  3349. PatientId: p.PatientId,
  3350. AdminUserId: adminInfo.AdminUser.Id,
  3351. Module: 1,
  3352. ErrLog: string(byterequest),
  3353. Status: 1,
  3354. Ctime: time.Now().Unix(),
  3355. Mtime: 0,
  3356. Source: "电脑端his项目修改",
  3357. RecordDate: p.RecordDate,
  3358. }
  3359. service.CreateDoctorAdviceLog(adviceLog)
  3360. }
  3361. }
  3362. }
  3363. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3364. addition := items["addition"].([]interface{})
  3365. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3366. ctime := time.Now().Unix()
  3367. mtime := ctime
  3368. if len(addition) > 0 {
  3369. for _, item := range addition {
  3370. var s models.HisAdditionalCharge
  3371. s.PrescriptionId = prescription.ID
  3372. s.Status = 1
  3373. s.UserOrgId = adminInfo.CurrentOrgId
  3374. s.RecordDate = recordDateTime
  3375. s.CreatedTime = ctime
  3376. s.UpdatedTime = mtime
  3377. s.PatientId = patient_id
  3378. s.HisPatientId = his_patient_id
  3379. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3380. if errcode > 0 {
  3381. c.ServeFailJSONWithSGJErrorCode(errcode)
  3382. return
  3383. }
  3384. service.CreateAdditionalCharge(&s)
  3385. }
  3386. }
  3387. }
  3388. }
  3389. }
  3390. }
  3391. if err == nil {
  3392. c.ServeSuccessJSON(map[string]interface{}{
  3393. "msg": "保存成功",
  3394. })
  3395. return
  3396. } else {
  3397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3398. return
  3399. }
  3400. }
  3401. func (c *HisApiController) DeletePrescription() {
  3402. prescription_id, _ := c.GetInt64("id")
  3403. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3404. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3405. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3406. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3407. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3408. //耗材保存处方出库
  3409. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3410. //已收费和已发药限制逻辑
  3411. isCharge := false
  3412. isMedicine := false
  3413. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3414. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3415. for _, item := range new_prescriptions {
  3416. if item.IsMedicine == 1 {
  3417. isMedicine = true
  3418. }
  3419. }
  3420. for _, item := range new_prescriptions {
  3421. if item.OrderStatus == 4 {
  3422. isCharge = true
  3423. }
  3424. }
  3425. if p_err != nil {
  3426. if new_prescription.ID > 0 {
  3427. if new_prescription.OrderStatus == 2 {
  3428. isCharge = true
  3429. }
  3430. }
  3431. }
  3432. for _, item := range advices {
  3433. if item.IsMedicine == 1 {
  3434. isMedicine = true
  3435. }
  3436. }
  3437. if isCharge {
  3438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3439. return
  3440. }
  3441. if isMedicine {
  3442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3443. return
  3444. }
  3445. //已收费和已发药限制逻辑
  3446. if len(projects) > 0 {
  3447. for _, item := range projects {
  3448. service.DeletePrintInfo(item.ID) //删除打印信息
  3449. if goodOutConfig.IsOpen != 1 {
  3450. if stockConfig.IsOpen == 1 {
  3451. if item.Type == 3 && item.IsOut == 1 {
  3452. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3453. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3454. good.Total = good.Total + f_count
  3455. service.UpdateGoodInfo(&good)
  3456. operation_time := time.Now().Unix()
  3457. creater := c.GetAdminUserInfo().AdminUser.Id
  3458. //创建退库单
  3459. timeStr := time.Now().Format("2006-01-02")
  3460. timeArr := strings.Split(timeStr, "-")
  3461. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3462. total = total + 1
  3463. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3464. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3465. cancelStock := models.CancelStock{
  3466. OrderNumber: orderNumber,
  3467. OperaTime: operation_time,
  3468. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3469. Creater: creater,
  3470. Ctime: time.Now().Unix(),
  3471. Status: 1,
  3472. ReturnTime: item.RecordDate,
  3473. Type: 1,
  3474. StorehouseId: houseConfig.StorehouseOutInfo,
  3475. IsCheck: 1,
  3476. }
  3477. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3478. if msgerrkonde == gorm.ErrRecordNotFound {
  3479. service.AddSigleCancelStock(&cancelStock)
  3480. }
  3481. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3482. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3483. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3484. //查询该耗材是否出库
  3485. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3486. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3487. deaerler, _ := service.GetDealerById(info.Dealer)
  3488. var total_count int64
  3489. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3490. total_count += count
  3491. if info.ID > 0 {
  3492. if info.Count >= total_count {
  3493. //回退库存
  3494. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3495. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3496. var flush_count int64
  3497. for _, it := range goodList {
  3498. flush_count += it.StockCount
  3499. }
  3500. cancelStockInfo := models.CancelStockInfo{
  3501. GoodId: item.ProjectId,
  3502. CancelStockId: cancel.ID,
  3503. GoodTypeId: good.GoodTypeId,
  3504. Count: prescribingNumber,
  3505. Price: info.Price,
  3506. Total: 0,
  3507. ProductDate: info.ProductDate,
  3508. ExpiryDate: info.ExpiryDate,
  3509. Ctime: time.Now().Unix(),
  3510. Status: 1,
  3511. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3512. OrderNumber: cancel.OrderNumber,
  3513. Type: 0,
  3514. Dealer: deaerler.DealerName,
  3515. Manufacturer: manufacturer.ManufacturerName,
  3516. Number: info.Number,
  3517. RegisterAccount: "",
  3518. Remark: "",
  3519. WarehouseInfoId: info.WarehouseInfotId,
  3520. PatientId: info.PatientId,
  3521. RecordDate: info.SysRecordTime,
  3522. StorehouseId: houseConfig.StorehouseOutInfo,
  3523. IsCheck: 1,
  3524. }
  3525. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3526. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3527. flow := models.VmStockFlow{
  3528. WarehousingId: info.WarehouseInfotId,
  3529. GoodId: item.ProjectId,
  3530. Number: info.Number,
  3531. LicenseNumber: info.LicenseNumber,
  3532. Count: prescribingNumber,
  3533. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3534. PatientId: item.PatientId,
  3535. SystemTime: info.SysRecordTime,
  3536. ConsumableType: 7,
  3537. IsSys: 0,
  3538. WarehousingOrder: "",
  3539. WarehouseOutId: info.WarehouseOutId,
  3540. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3541. IsEdit: 0,
  3542. CancelStockId: cancel.ID,
  3543. CancelOrderNumber: cancel.OrderNumber,
  3544. Manufacturer: manufacturer.ID,
  3545. Dealer: 0,
  3546. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3547. UpdateCreator: 0,
  3548. Status: 1,
  3549. Ctime: time.Now().Unix(),
  3550. Mtime: 0,
  3551. Price: info.Price,
  3552. WarehousingDetailId: info.WarehouseInfotId,
  3553. WarehouseOutDetailId: info.ID,
  3554. CancelOutDetailId: cancelInfo.ID,
  3555. ProductDate: info.ProductDate,
  3556. ExpireDate: info.ExpiryDate,
  3557. StorehouseId: houseConfig.StorehouseOutInfo,
  3558. OverCount: flush_count,
  3559. }
  3560. service.CreateStockFlowOne(flow)
  3561. //退库数量增加
  3562. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3563. //出库数量减少
  3564. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3565. }
  3566. if info.Count < total_count {
  3567. //回退库存
  3568. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3569. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3570. var flush_count int64
  3571. for _, it := range goodList {
  3572. flush_count += it.StockCount
  3573. }
  3574. cancelStockInfo := models.CancelStockInfo{
  3575. GoodId: item.ProjectId,
  3576. CancelStockId: cancel.ID,
  3577. GoodTypeId: good.GoodTypeId,
  3578. Count: info.Count,
  3579. Price: info.Price,
  3580. Total: 0,
  3581. ProductDate: info.ProductDate,
  3582. ExpiryDate: info.ExpiryDate,
  3583. Ctime: time.Now().Unix(),
  3584. Status: 1,
  3585. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3586. OrderNumber: cancel.OrderNumber,
  3587. Type: 0,
  3588. Dealer: deaerler.DealerName,
  3589. Manufacturer: manufacturer.ManufacturerName,
  3590. Number: info.Number,
  3591. RegisterAccount: "",
  3592. Remark: "",
  3593. WarehouseInfoId: info.WarehouseInfotId,
  3594. PatientId: info.PatientId,
  3595. RecordDate: info.SysRecordTime,
  3596. StorehouseId: houseConfig.StorehouseOutInfo,
  3597. IsCheck: 1,
  3598. }
  3599. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3600. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3601. flow := models.VmStockFlow{
  3602. WarehousingId: info.WarehouseInfotId,
  3603. GoodId: item.ProjectId,
  3604. Number: info.Number,
  3605. LicenseNumber: info.LicenseNumber,
  3606. Count: info.Count,
  3607. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3608. PatientId: item.PatientId,
  3609. SystemTime: info.SysRecordTime,
  3610. ConsumableType: 7,
  3611. IsSys: 0,
  3612. WarehousingOrder: "",
  3613. WarehouseOutId: info.WarehouseOutId,
  3614. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3615. IsEdit: 0,
  3616. CancelStockId: cancel.ID,
  3617. CancelOrderNumber: cancel.OrderNumber,
  3618. Manufacturer: manufacturer.ID,
  3619. Dealer: 0,
  3620. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3621. UpdateCreator: 0,
  3622. Status: 1,
  3623. Ctime: time.Now().Unix(),
  3624. Mtime: 0,
  3625. Price: info.Price,
  3626. WarehousingDetailId: info.WarehouseInfotId,
  3627. WarehouseOutDetailId: info.ID,
  3628. CancelOutDetailId: cancelInfo.ID,
  3629. ProductDate: info.ProductDate,
  3630. ExpireDate: info.ExpiryDate,
  3631. StorehouseId: houseConfig.StorehouseOutInfo,
  3632. OverCount: flush_count,
  3633. }
  3634. service.CreateStockFlowOne(flow)
  3635. //退库数量增加
  3636. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3637. //出库数量减少
  3638. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3639. }
  3640. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3641. var flush_count int64
  3642. for _, it := range goodList {
  3643. flush_count += it.StockCount
  3644. }
  3645. //查询已出库数量
  3646. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3647. if prescribingNumber < dialysisInfo.Count {
  3648. //改变数量
  3649. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3650. }
  3651. if prescribingNumber >= dialysisInfo.Count {
  3652. //删除出库表
  3653. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3654. }
  3655. //更新库存
  3656. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3657. //更新基础库库存
  3658. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3659. }
  3660. }
  3661. }
  3662. }
  3663. //保存耗材出库
  3664. if goodOutConfig.IsOpen == 1 {
  3665. if item.Type == 3 {
  3666. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3667. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3668. good.Total = good.Total + f_count
  3669. service.UpdateGoodInfo(&good)
  3670. operation_time := time.Now().Unix()
  3671. creater := c.GetAdminUserInfo().AdminUser.Id
  3672. //创建退库单
  3673. timeStr := time.Now().Format("2006-01-02")
  3674. timeArr := strings.Split(timeStr, "-")
  3675. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3676. total = total + 1
  3677. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3678. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3679. cancelStock := models.CancelStock{
  3680. OrderNumber: orderNumber,
  3681. OperaTime: operation_time,
  3682. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3683. Creater: creater,
  3684. Ctime: time.Now().Unix(),
  3685. Status: 1,
  3686. ReturnTime: item.RecordDate,
  3687. Type: 1,
  3688. StorehouseId: houseConfig.StorehouseOutInfo,
  3689. IsCheck: 1,
  3690. }
  3691. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3692. if msgerrkonde == gorm.ErrRecordNotFound {
  3693. service.AddSigleCancelStock(&cancelStock)
  3694. }
  3695. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3696. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3697. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3698. //查询该耗材是否出库
  3699. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3700. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3701. deaerler, _ := service.GetDealerById(info.Dealer)
  3702. var total_count int64
  3703. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3704. total_count += count
  3705. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3706. var flush_count int64
  3707. for _, it := range goodList {
  3708. flush_count += it.StockCount
  3709. }
  3710. fmt.Println("历史出库数据", info.Count)
  3711. fmt.Println("出库数量", total_count)
  3712. if info.ID > 0 {
  3713. cancelStockInfo := models.CancelStockInfo{
  3714. GoodId: item.ProjectId,
  3715. CancelStockId: cancel.ID,
  3716. GoodTypeId: good.GoodTypeId,
  3717. Count: prescribingNumber,
  3718. Price: info.Price,
  3719. Total: 0,
  3720. ProductDate: info.ProductDate,
  3721. ExpiryDate: info.ExpiryDate,
  3722. Ctime: time.Now().Unix(),
  3723. Status: 1,
  3724. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3725. OrderNumber: cancel.OrderNumber,
  3726. Type: 0,
  3727. Dealer: deaerler.DealerName,
  3728. Manufacturer: manufacturer.ManufacturerName,
  3729. Number: info.Number,
  3730. RegisterAccount: "",
  3731. Remark: "",
  3732. WarehouseInfoId: info.WarehouseInfotId,
  3733. PatientId: info.PatientId,
  3734. RecordDate: info.SysRecordTime,
  3735. StorehouseId: houseConfig.StorehouseOutInfo,
  3736. IsCheck: 1,
  3737. }
  3738. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3739. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3740. //查询出库数量
  3741. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3742. //出库数据 大于 退库数量
  3743. if len(list) > 0 {
  3744. for _, it := range list {
  3745. //回退库存
  3746. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3747. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3748. var flush_count_one int64
  3749. for _, it := range goodList {
  3750. flush_count_one += it.StockCount
  3751. }
  3752. //查询该批次是否有退库数据
  3753. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3754. creater := c.GetAdminUserInfo().AdminUser.Id
  3755. flow := models.VmStockFlow{
  3756. WarehousingId: it.WarehouseInfotId,
  3757. GoodId: it.GoodId,
  3758. Number: it.Number,
  3759. LicenseNumber: it.LicenseNumber,
  3760. Count: it.Count,
  3761. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3762. PatientId: it.PatientId,
  3763. SystemTime: it.SysRecordTime,
  3764. ConsumableType: 7,
  3765. IsSys: 0,
  3766. WarehousingOrder: "",
  3767. WarehouseOutId: it.WarehouseOutId,
  3768. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3769. IsEdit: 0,
  3770. CancelStockId: cancel.ID,
  3771. CancelOrderNumber: cancel.OrderNumber,
  3772. Manufacturer: manufacturer.ID,
  3773. Dealer: 0,
  3774. Creator: creater,
  3775. UpdateCreator: 0,
  3776. Status: 1,
  3777. Ctime: time.Now().Unix(),
  3778. Mtime: 0,
  3779. Price: it.Price,
  3780. WarehousingDetailId: it.WarehouseInfotId,
  3781. WarehouseOutDetailId: it.ID,
  3782. CancelOutDetailId: cancelInfo.ID,
  3783. ProductDate: it.ProductDate,
  3784. ExpireDate: it.ExpiryDate,
  3785. StorehouseId: houseConfig.StorehouseOutInfo,
  3786. OverCount: flush_count_one,
  3787. }
  3788. service.CreateStockFlowOne(flow)
  3789. //if flow.ID > 0 {
  3790. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3791. //}
  3792. }
  3793. }
  3794. //flow := models.VmStockFlow{
  3795. // WarehousingId: info.WarehouseInfotId,
  3796. // GoodId: item.ProjectId,
  3797. // Number: info.Number,
  3798. // LicenseNumber: info.LicenseNumber,
  3799. // Count: prescribingNumber,
  3800. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3801. // PatientId: item.PatientId,
  3802. // SystemTime: info.SysRecordTime,
  3803. // ConsumableType: 7,
  3804. // IsSys: 0,
  3805. // WarehousingOrder: "",
  3806. // WarehouseOutId: info.WarehouseOutId,
  3807. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3808. // IsEdit: 0,
  3809. // CancelStockId: cancel.ID,
  3810. // CancelOrderNumber: cancel.OrderNumber,
  3811. // Manufacturer: manufacturer.ID,
  3812. // Dealer: 0,
  3813. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3814. // UpdateCreator: 0,
  3815. // Status: 1,
  3816. // Ctime: time.Now().Unix(),
  3817. // Mtime: 0,
  3818. // Price: info.Price,
  3819. // WarehousingDetailId: info.WarehouseInfotId,
  3820. // WarehouseOutDetailId: info.ID,
  3821. // CancelOutDetailId: cancelInfo.ID,
  3822. // ProductDate: info.ProductDate,
  3823. // ExpireDate: info.ExpiryDate,
  3824. // StorehouseId: houseConfig.StorehouseOutInfo,
  3825. // OverCount: flush_count,
  3826. //}
  3827. //service.CreateStockFlowOne(flow)
  3828. //退库数量增加
  3829. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3830. //出库数量减少
  3831. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3832. //查询已出库数量
  3833. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3834. if prescribingNumber < dialysisInfo.Count {
  3835. //改变数量
  3836. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3837. }
  3838. if prescribingNumber >= dialysisInfo.Count {
  3839. //删除出库表
  3840. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3841. }
  3842. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3843. var flush_count_one int64
  3844. for _, it := range goodList {
  3845. flush_count_one += it.StockCount
  3846. }
  3847. //更新库存
  3848. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3849. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3850. //更新基础库库存
  3851. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3852. }
  3853. }
  3854. }
  3855. }
  3856. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3857. fmt.Println(err)
  3858. }
  3859. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3860. fmt.Println(err)
  3861. if len(advices) > 0 {
  3862. for _, item := range advices {
  3863. redis := service.RedisClient()
  3864. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3865. redis.Set(keyFive, "", time.Second)
  3866. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3867. redis.Set(keyOne, "", time.Second)
  3868. redis.Close()
  3869. }
  3870. }
  3871. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3872. if len(advices) > 0 {
  3873. for _, item := range advices {
  3874. creater := c.GetAdminUserInfo().AdminUser.Id
  3875. service.DrugAutoAddCancelInfo(item, creater)
  3876. }
  3877. }
  3878. } else {
  3879. if drugOutConfig.IsOpen == 1 {
  3880. if len(advices) > 0 {
  3881. for _, item := range advices {
  3882. creater := c.GetAdminUserInfo().AdminUser.Id
  3883. service.DrugAutoAddCancelInfo(item, creater)
  3884. }
  3885. }
  3886. } else {
  3887. if len(advices) > 0 {
  3888. for _, item := range advices {
  3889. creater := c.GetAdminUserInfo().AdminUser.Id
  3890. service.DrugAutoAddCancelInfo(item, creater)
  3891. }
  3892. }
  3893. }
  3894. }
  3895. c.ServeSuccessJSON(map[string]interface{}{
  3896. "msg": "删除成功",
  3897. })
  3898. return
  3899. }
  3900. func (c *HisApiController) DeleteDoctorAdvice() {
  3901. id, _ := c.GetInt64("id")
  3902. advice, _ := service.GetHisDoctorAdvicesById(id)
  3903. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3904. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3905. //已收费和已发药的限制逻辑
  3906. isCharge := false
  3907. isMedicine := false
  3908. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3909. //获取今天该患者所有处方,判断是否发药或者收费
  3910. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3911. for _, item := range new_prescriptions {
  3912. if item.IsMedicine == 1 {
  3913. isMedicine = true
  3914. }
  3915. }
  3916. for _, item := range new_prescriptions {
  3917. if item.OrderStatus == 4 {
  3918. isCharge = true
  3919. }
  3920. }
  3921. if isMedicine {
  3922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3923. return
  3924. }
  3925. if isCharge {
  3926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3927. return
  3928. }
  3929. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3930. for _, item := range advices {
  3931. if item.IsMedicine == 1 {
  3932. isMedicine = true
  3933. }
  3934. }
  3935. if isMedicine {
  3936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3937. return
  3938. }
  3939. if new_prescription.ID > 0 {
  3940. if new_prescription.OrderStatus == 2 {
  3941. isCharge = true
  3942. }
  3943. }
  3944. if isCharge {
  3945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3946. return
  3947. }
  3948. //已收费和已发药的限制逻辑
  3949. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3950. redis := service.RedisClient()
  3951. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3952. redis.Set(keyFive, "", time.Second)
  3953. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3954. redis.Set(keyOne, "", time.Second)
  3955. defer redis.Close()
  3956. if err == nil {
  3957. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3958. //查询是否在处方中出库
  3959. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3960. if openConfig.IsOpen != 1 {
  3961. //判断该医嘱是否执行了
  3962. if advice.ExecutionState == 1 {
  3963. creater := c.GetAdminUserInfo().AdminUser.Id
  3964. service.DrugAutoAddCancelInfo(&advice, creater)
  3965. }
  3966. }
  3967. //开启保存处方扣减功能
  3968. if openConfig.IsOpen == 1 {
  3969. creater := c.GetAdminUserInfo().AdminUser.Id
  3970. service.DrugAutoAddCancelInfo(&advice, creater)
  3971. }
  3972. } else {
  3973. if drugOutConfig.IsOpen == 1 {
  3974. //查询是否在处方中出库
  3975. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3976. if openConfig.IsOpen != 1 {
  3977. //判断该医嘱是否执行了
  3978. if advice.ExecutionState == 1 {
  3979. creater := c.GetAdminUserInfo().AdminUser.Id
  3980. service.DrugAutoAddCancelInfo(&advice, creater)
  3981. }
  3982. }
  3983. //开启保存处方扣减功能
  3984. if openConfig.IsOpen == 1 {
  3985. creater := c.GetAdminUserInfo().AdminUser.Id
  3986. service.DrugAutoAddCancelInfo(&advice, creater)
  3987. }
  3988. } else {
  3989. //判断该医嘱是否执行了
  3990. if advice.ExecutionState == 1 {
  3991. creater := c.GetAdminUserInfo().AdminUser.Id
  3992. service.DrugAutoAddCancelInfo(&advice, creater)
  3993. }
  3994. }
  3995. }
  3996. c.ServeSuccessJSON(map[string]interface{}{
  3997. "msg": "删除成功",
  3998. })
  3999. return
  4000. } else {
  4001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4002. return
  4003. }
  4004. }
  4005. func (c *HisApiController) DeleteProject() {
  4006. id, _ := c.GetInt64("id")
  4007. adminInfo := c.GetAdminUserInfo()
  4008. project, _ := service.GetHisProjectByID(id)
  4009. // var consumable models.DialysisBeforePrepare
  4010. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4011. //耗材保存处方出库
  4012. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4013. isCharge := false
  4014. isMedicine := false
  4015. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4016. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4017. for _, item := range new_prescriptions {
  4018. if item.IsMedicine == 1 {
  4019. isMedicine = true
  4020. }
  4021. }
  4022. for _, item := range new_prescriptions {
  4023. if item.OrderStatus == 4 {
  4024. isCharge = true
  4025. }
  4026. }
  4027. if isMedicine {
  4028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4029. return
  4030. }
  4031. if isCharge {
  4032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4033. return
  4034. }
  4035. if new_prescription.ID > 0 {
  4036. if new_prescription.OrderStatus == 2 {
  4037. isCharge = true
  4038. }
  4039. }
  4040. if isCharge {
  4041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4042. return
  4043. }
  4044. service.DeletePrintInfo(id)
  4045. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4046. label.Status = 0
  4047. service.CreateHisLabelRecord(&label)
  4048. fmt.Println(goodOutConfig.IsOpen)
  4049. if goodOutConfig.IsOpen != 1 {
  4050. if stockConfig.IsOpen == 1 {
  4051. if project.Type == 2 {
  4052. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4053. fmt.Println(err)
  4054. }
  4055. if project.Type == 3 && project.IsOut == 1 {
  4056. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4057. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4058. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4059. operation_time := time.Now().Unix()
  4060. creater := adminInfo.AdminUser.Id
  4061. //创建退库单
  4062. timeStr := time.Now().Format("2006-01-02")
  4063. timeArr := strings.Split(timeStr, "-")
  4064. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4065. total = total + 1
  4066. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4067. cancelStock := models.CancelStock{
  4068. OrderNumber: orderNumber,
  4069. OperaTime: operation_time,
  4070. OrgId: adminInfo.CurrentOrgId,
  4071. Creater: creater,
  4072. Ctime: time.Now().Unix(),
  4073. Status: 1,
  4074. ReturnTime: project.RecordDate,
  4075. Type: 1,
  4076. StorehouseId: houseConfig.StorehouseOutInfo,
  4077. IsCheck: 1,
  4078. }
  4079. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4080. if msgerrkonde == gorm.ErrRecordNotFound {
  4081. service.AddSigleCancelStock(&cancelStock)
  4082. }
  4083. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4084. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4085. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4086. //查询是否有出库
  4087. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4088. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4089. deaerler, _ := service.GetDealerById(info.Dealer)
  4090. if info.ID > 0 {
  4091. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4092. if info.Count >= prescribingNumber {
  4093. cancelStockInfo := models.CancelStockInfo{
  4094. GoodId: project.ProjectId,
  4095. CancelStockId: cancel.ID,
  4096. GoodTypeId: good.GoodTypeId,
  4097. Count: prescribingNumber,
  4098. Price: info.Price,
  4099. Total: 0,
  4100. ProductDate: info.ProductDate,
  4101. ExpiryDate: info.ExpiryDate,
  4102. Ctime: time.Now().Unix(),
  4103. Status: 1,
  4104. OrgId: adminInfo.CurrentOrgId,
  4105. OrderNumber: cancel.OrderNumber,
  4106. Type: 0,
  4107. Dealer: deaerler.DealerName,
  4108. Manufacturer: manufacturer.ManufacturerName,
  4109. Number: info.Number,
  4110. RegisterAccount: "",
  4111. Remark: "",
  4112. WarehouseInfoId: info.WarehouseInfotId,
  4113. PatientId: info.PatientId,
  4114. RecordDate: info.SysRecordTime,
  4115. StorehouseId: houseConfig.StorehouseOutInfo,
  4116. IsCheck: 1,
  4117. }
  4118. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4119. //回退库存
  4120. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4121. //退库数量增加
  4122. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4123. //出库数量减少
  4124. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4125. }
  4126. if info.Count < prescribingNumber {
  4127. cancelStockInfo := models.CancelStockInfo{
  4128. GoodId: project.ProjectId,
  4129. CancelStockId: cancel.ID,
  4130. GoodTypeId: good.GoodTypeId,
  4131. Count: info.Count,
  4132. Price: info.Price,
  4133. Total: 0,
  4134. ProductDate: info.ProductDate,
  4135. ExpiryDate: info.ExpiryDate,
  4136. Ctime: time.Now().Unix(),
  4137. Status: 1,
  4138. OrgId: adminInfo.CurrentOrgId,
  4139. OrderNumber: cancel.OrderNumber,
  4140. Type: 0,
  4141. Dealer: deaerler.DealerName,
  4142. Manufacturer: manufacturer.ManufacturerName,
  4143. Number: info.Number,
  4144. RegisterAccount: "",
  4145. Remark: "",
  4146. WarehouseInfoId: info.WarehouseInfotId,
  4147. PatientId: info.PatientId,
  4148. RecordDate: info.SysRecordTime,
  4149. StorehouseId: houseConfig.StorehouseOutInfo,
  4150. IsCheck: 1,
  4151. }
  4152. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4153. //回退库存
  4154. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4155. //退库数量增加
  4156. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4157. //出库数量减少
  4158. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4159. }
  4160. //查询剩余库存
  4161. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4162. var over_count int64
  4163. for _, it := range goodList {
  4164. over_count += it.StockCount
  4165. }
  4166. //出库数据 大于 退库数量
  4167. if info.Count >= prescribingNumber {
  4168. flow := models.VmStockFlow{
  4169. WarehousingId: info.WarehouseInfotId,
  4170. GoodId: project.ProjectId,
  4171. Number: info.Number,
  4172. LicenseNumber: info.LicenseNumber,
  4173. Count: prescribingNumber,
  4174. UserOrgId: adminInfo.CurrentOrgId,
  4175. PatientId: project.PatientId,
  4176. SystemTime: info.SysRecordTime,
  4177. ConsumableType: 7,
  4178. IsSys: 0,
  4179. WarehousingOrder: "",
  4180. WarehouseOutId: info.WarehouseOutId,
  4181. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4182. IsEdit: 0,
  4183. CancelStockId: cancel.ID,
  4184. CancelOrderNumber: cancel.OrderNumber,
  4185. Manufacturer: manufacturer.ID,
  4186. Dealer: 0,
  4187. Creator: adminInfo.AdminUser.Id,
  4188. UpdateCreator: 0,
  4189. Status: 1,
  4190. Ctime: time.Now().Unix(),
  4191. Mtime: 0,
  4192. Price: info.Price,
  4193. WarehousingDetailId: info.WarehouseInfotId,
  4194. WarehouseOutDetailId: info.ID,
  4195. CancelOutDetailId: cancelInfo.ID,
  4196. ProductDate: info.ProductDate,
  4197. ExpireDate: info.ExpiryDate,
  4198. StorehouseId: houseConfig.StorehouseOutInfo,
  4199. OverCount: over_count,
  4200. }
  4201. service.CreateStockFlowOne(flow)
  4202. }
  4203. //出库数据小于退库数据
  4204. if info.Count < prescribingNumber {
  4205. flow := models.VmStockFlow{
  4206. WarehousingId: info.WarehouseInfotId,
  4207. GoodId: project.ProjectId,
  4208. Number: info.Number,
  4209. LicenseNumber: info.LicenseNumber,
  4210. Count: info.Count,
  4211. UserOrgId: adminInfo.CurrentOrgId,
  4212. PatientId: project.PatientId,
  4213. SystemTime: info.SysRecordTime,
  4214. ConsumableType: 7,
  4215. IsSys: 0,
  4216. WarehousingOrder: "",
  4217. WarehouseOutId: info.WarehouseOutId,
  4218. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4219. IsEdit: 0,
  4220. CancelStockId: cancel.ID,
  4221. CancelOrderNumber: cancel.OrderNumber,
  4222. Manufacturer: manufacturer.ID,
  4223. Dealer: 0,
  4224. Creator: adminInfo.AdminUser.Id,
  4225. UpdateCreator: 0,
  4226. Status: 1,
  4227. Ctime: time.Now().Unix(),
  4228. Mtime: 0,
  4229. Price: info.Price,
  4230. WarehousingDetailId: info.WarehouseInfotId,
  4231. WarehouseOutDetailId: info.ID,
  4232. CancelOutDetailId: cancelInfo.ID,
  4233. ProductDate: info.ProductDate,
  4234. ExpireDate: info.ExpiryDate,
  4235. StorehouseId: houseConfig.StorehouseOutInfo,
  4236. OverCount: over_count,
  4237. }
  4238. service.CreateStockFlowOne(flow)
  4239. }
  4240. //查询已出库数量
  4241. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4242. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4243. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4244. if prescribingNumber < dialysisInfo.Count {
  4245. //改变数量
  4246. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4247. }
  4248. if prescribingNumber >= dialysisInfo.Count {
  4249. //删除出库表
  4250. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4251. }
  4252. //更新剩余库存
  4253. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4254. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4255. var total_count_one int64
  4256. for _, it := range stockList {
  4257. total_count_one += it.StockCount
  4258. }
  4259. //基础库插入数据
  4260. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4261. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4262. var flush_count int64
  4263. for _, it := range goodListOne {
  4264. flush_count += it.StockCount
  4265. }
  4266. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4267. if errs != nil {
  4268. goodErrcode := models.XtGoodErrcode{
  4269. UserOrgId: project.UserOrgId,
  4270. Errcode: "手动出库更新剩余出库失败",
  4271. GoodId: project.ProjectId,
  4272. Status: 1,
  4273. Ctime: time.Now().Unix(),
  4274. Mtime: 0,
  4275. Count: 0,
  4276. StockCount: 0,
  4277. Creater: creater,
  4278. BatchNumberId: 0,
  4279. WarehouseOutId: 0,
  4280. }
  4281. service.CreateGoodErrcode(goodErrcode)
  4282. }
  4283. }
  4284. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4285. fmt.Println(err)
  4286. } else {
  4287. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4288. fmt.Println(err)
  4289. }
  4290. } else {
  4291. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4292. fmt.Println(err)
  4293. }
  4294. }
  4295. //保存处方出库
  4296. if goodOutConfig.IsOpen == 1 {
  4297. if project.Type == 3 {
  4298. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4299. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4300. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4301. operation_time := time.Now().Unix()
  4302. creater := adminInfo.AdminUser.Id
  4303. //创建退库单
  4304. timeStr := time.Now().Format("2006-01-02")
  4305. timeArr := strings.Split(timeStr, "-")
  4306. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4307. total = total + 1
  4308. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4309. cancelStock := models.CancelStock{
  4310. OrderNumber: orderNumber,
  4311. OperaTime: operation_time,
  4312. OrgId: adminInfo.CurrentOrgId,
  4313. Creater: creater,
  4314. Ctime: time.Now().Unix(),
  4315. Status: 1,
  4316. ReturnTime: project.RecordDate,
  4317. Type: 1,
  4318. StorehouseId: houseConfig.StorehouseOutInfo,
  4319. IsCheck: 1,
  4320. }
  4321. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4322. if msgerrkonde == gorm.ErrRecordNotFound {
  4323. service.AddSigleCancelStock(&cancelStock)
  4324. }
  4325. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4326. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4327. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4328. //获取出库数据
  4329. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4330. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4331. deaerler, _ := service.GetDealerById(info.Dealer)
  4332. if info.ID > 0 {
  4333. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4334. if info.Count >= prescribingNumber {
  4335. cancelStockInfo := models.CancelStockInfo{
  4336. GoodId: project.ProjectId,
  4337. CancelStockId: cancel.ID,
  4338. GoodTypeId: good.GoodTypeId,
  4339. Count: prescribingNumber,
  4340. Price: info.Price,
  4341. Total: 0,
  4342. ProductDate: info.ProductDate,
  4343. ExpiryDate: info.ExpiryDate,
  4344. Ctime: time.Now().Unix(),
  4345. Status: 1,
  4346. OrgId: adminInfo.CurrentOrgId,
  4347. OrderNumber: cancel.OrderNumber,
  4348. Type: 0,
  4349. Dealer: deaerler.DealerName,
  4350. Manufacturer: manufacturer.ManufacturerName,
  4351. Number: info.Number,
  4352. RegisterAccount: "",
  4353. Remark: "",
  4354. WarehouseInfoId: info.WarehouseInfotId,
  4355. PatientId: info.PatientId,
  4356. RecordDate: info.SysRecordTime,
  4357. StorehouseId: houseConfig.StorehouseOutInfo,
  4358. IsCheck: 1,
  4359. }
  4360. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4361. //退库数量增加
  4362. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4363. //出库数量减少
  4364. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4365. }
  4366. if info.Count < prescribingNumber {
  4367. cancelStockInfo := models.CancelStockInfo{
  4368. GoodId: project.ProjectId,
  4369. CancelStockId: cancel.ID,
  4370. GoodTypeId: good.GoodTypeId,
  4371. Count: prescribingNumber,
  4372. Price: info.Price,
  4373. Total: 0,
  4374. ProductDate: info.ProductDate,
  4375. ExpiryDate: info.ExpiryDate,
  4376. Ctime: time.Now().Unix(),
  4377. Status: 1,
  4378. OrgId: adminInfo.CurrentOrgId,
  4379. OrderNumber: cancel.OrderNumber,
  4380. Type: 0,
  4381. Dealer: deaerler.DealerName,
  4382. Manufacturer: manufacturer.ManufacturerName,
  4383. Number: info.Number,
  4384. RegisterAccount: "",
  4385. Remark: "",
  4386. WarehouseInfoId: info.WarehouseInfotId,
  4387. PatientId: info.PatientId,
  4388. RecordDate: info.SysRecordTime,
  4389. StorehouseId: houseConfig.StorehouseOutInfo,
  4390. IsCheck: 1,
  4391. }
  4392. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4393. //回退库存
  4394. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4395. }
  4396. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4397. var over_count int64
  4398. for _, it := range goodList {
  4399. over_count += it.StockCount
  4400. }
  4401. //查询出库数量
  4402. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4403. //出库数据 大于 退库数量
  4404. if len(list) > 0 {
  4405. for _, it := range list {
  4406. //回退库存
  4407. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4408. //退库数量增加
  4409. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4410. //出库数量减少
  4411. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4412. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4413. var over_count_one int64
  4414. for _, it := range goodList {
  4415. over_count_one += it.StockCount
  4416. }
  4417. //查询该批次是否有退库数据
  4418. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4419. flow := models.VmStockFlow{
  4420. WarehousingId: it.WarehouseInfotId,
  4421. GoodId: it.GoodId,
  4422. Number: it.Number,
  4423. LicenseNumber: it.LicenseNumber,
  4424. Count: it.Count,
  4425. UserOrgId: adminInfo.CurrentOrgId,
  4426. PatientId: it.PatientId,
  4427. SystemTime: it.SysRecordTime,
  4428. ConsumableType: 7,
  4429. IsSys: 0,
  4430. WarehousingOrder: "",
  4431. WarehouseOutId: it.WarehouseOutId,
  4432. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4433. IsEdit: 0,
  4434. CancelStockId: cancel.ID,
  4435. CancelOrderNumber: cancel.OrderNumber,
  4436. Manufacturer: manufacturer.ID,
  4437. Dealer: 0,
  4438. Creator: adminInfo.AdminUser.Id,
  4439. UpdateCreator: 0,
  4440. Status: 1,
  4441. Ctime: time.Now().Unix(),
  4442. Mtime: 0,
  4443. Price: it.Price,
  4444. WarehousingDetailId: it.WarehouseInfotId,
  4445. WarehouseOutDetailId: it.ID,
  4446. CancelOutDetailId: cancelInfo.ID,
  4447. ProductDate: it.ProductDate,
  4448. ExpireDate: it.ExpiryDate,
  4449. StorehouseId: houseConfig.StorehouseOutInfo,
  4450. OverCount: over_count_one,
  4451. }
  4452. service.CreateStockFlowOne(flow)
  4453. }
  4454. }
  4455. //查询已出库数量
  4456. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4457. if prescribingNumber < dialysisInfo.Count {
  4458. //改变数量
  4459. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4460. }
  4461. if prescribingNumber >= dialysisInfo.Count {
  4462. //删除出库表
  4463. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4464. }
  4465. //更新剩余库存
  4466. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4467. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4468. var total_count_one int64
  4469. for _, it := range stockList {
  4470. total_count_one += it.StockCount
  4471. }
  4472. //基础库插入数据
  4473. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4474. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4475. var flush_count int64
  4476. for _, it := range goodListOne {
  4477. flush_count += it.StockCount
  4478. }
  4479. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4480. if errs != nil {
  4481. goodErrcode := models.XtGoodErrcode{
  4482. UserOrgId: project.UserOrgId,
  4483. Errcode: "手动出库更新剩余出库失败",
  4484. GoodId: project.ProjectId,
  4485. Status: 1,
  4486. Ctime: time.Now().Unix(),
  4487. Mtime: 0,
  4488. Count: 0,
  4489. StockCount: 0,
  4490. Creater: creater,
  4491. BatchNumberId: 0,
  4492. WarehouseOutId: 0,
  4493. }
  4494. service.CreateGoodErrcode(goodErrcode)
  4495. }
  4496. }
  4497. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4498. fmt.Println(err)
  4499. } else {
  4500. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4501. fmt.Println(err)
  4502. }
  4503. }
  4504. c.ServeSuccessJSON(map[string]interface{}{
  4505. "msg": "删除成功",
  4506. })
  4507. return
  4508. }
  4509. func (c *HisApiController) CreateHisAdditionalCharge() {
  4510. his_patient_id, _ := c.GetInt64("his_patient_id")
  4511. patient_id, _ := c.GetInt64("patient_id")
  4512. record_date := c.GetString("record_date")
  4513. timeLayout := "2006-01-02"
  4514. loc, _ := time.LoadLocation("Local")
  4515. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4516. if err != nil {
  4517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4518. return
  4519. }
  4520. adminInfo := c.GetAdminUserInfo()
  4521. recordDateTime := theTime.Unix()
  4522. dataBody := make(map[string]interface{}, 0)
  4523. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4524. if err != nil {
  4525. utils.ErrorLog(err.Error())
  4526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4527. return
  4528. }
  4529. var additions []*models.HisAdditionalCharge
  4530. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4531. additions, _ := dataBody["addition"].([]interface{})
  4532. if len(additions) > 0 {
  4533. for _, item := range additions {
  4534. items := item.(map[string]interface{})
  4535. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4536. utils.ErrorLog("item_id")
  4537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4538. return
  4539. }
  4540. item_id := int64(items["item_id"].(float64))
  4541. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4542. utils.ErrorLog("item_name")
  4543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4544. return
  4545. }
  4546. item_name := items["item_name"].(string)
  4547. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4548. utils.ErrorLog("price")
  4549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4550. return
  4551. }
  4552. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4553. ctime := time.Now().Unix()
  4554. additional := &models.HisAdditionalCharge{
  4555. PatientId: patient_id,
  4556. HisPatientId: his_patient_id,
  4557. UserOrgId: adminInfo.CurrentOrgId,
  4558. RecordDate: recordDateTime,
  4559. CreatedTime: ctime,
  4560. UpdatedTime: ctime,
  4561. Modifier: adminInfo.AdminUser.Id,
  4562. Creator: adminInfo.AdminUser.Id,
  4563. Price: price,
  4564. ItemName: item_name,
  4565. ItemId: item_id,
  4566. Status: 1,
  4567. }
  4568. additions = append(additions, additional)
  4569. }
  4570. }
  4571. }
  4572. for _, item := range additions {
  4573. service.CreateAddtionalCharge(item)
  4574. }
  4575. c.ServeSuccessJSON(map[string]interface{}{
  4576. "msg": "创建成功",
  4577. })
  4578. }
  4579. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4580. blood_fat := c.GetString("blood_fat")
  4581. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4582. blood_sugar := c.GetString("blood_sugar")
  4583. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4584. chief_conplaint := c.GetString("chief_conplaint")
  4585. dbp := c.GetString("dbp")
  4586. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4587. delivery_way, _ := c.GetInt64("delivery_way")
  4588. diagnostic := c.GetString("diagnostic")
  4589. family_history := c.GetString("family_history")
  4590. height := c.GetString("height")
  4591. history_of_present_illness := c.GetString("history_of_present_illness")
  4592. is_infect, _ := c.GetInt64("is_infect")
  4593. past_history := c.GetString("past_history")
  4594. patient_id, _ := c.GetInt64("patient_id")
  4595. his_patient_id, _ := c.GetInt64("his_patient_id")
  4596. personal_history := c.GetString("personal_history")
  4597. pulse := c.GetString("pulse")
  4598. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4599. sbp := c.GetString("sbp")
  4600. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4601. heightfloat, _ := strconv.ParseFloat(height, 64)
  4602. sicktype := c.GetString("sick_type")
  4603. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4604. symptom := c.GetString("symptom")
  4605. sick_date := c.GetString("sick_date")
  4606. temperatures := c.GetString("temperature")
  4607. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4608. record_date := c.GetString("record_date")
  4609. breathing := c.GetString("breathing")
  4610. doctor_advice := c.GetString("doctor_advice")
  4611. remark := c.GetString("remark")
  4612. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4613. sick, _ := c.GetInt64("sick")
  4614. diagnose, _ := c.GetInt64("diagnose")
  4615. //id, _ := c.GetInt64("id")
  4616. timeLayout := "2006-01-02"
  4617. loc, _ := time.LoadLocation("Local")
  4618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4619. allergic_history := c.GetString("allergic_history")
  4620. if err != nil {
  4621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4622. return
  4623. }
  4624. recordDateTime := theTime.Unix()
  4625. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4626. if err != nil {
  4627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4628. return
  4629. }
  4630. sickTimes := sickTime.Unix()
  4631. ctime := time.Now().Unix()
  4632. primary_disease := c.GetString("primary_disease")
  4633. confirm_failure_date := c.GetString("confirm_failure_date")
  4634. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4635. drug_allergy_history := c.GetString("drug_allergy_history")
  4636. physical_examination := c.GetString("physical_examination")
  4637. special_inspection := c.GetString("special_inspection")
  4638. lab_apparatus := c.GetString("lab_apparatus")
  4639. caseHistory := models.HisPatientCaseHistory{
  4640. HisPatientId: his_patient_id,
  4641. PatientId: patient_id,
  4642. Temperature: temperature,
  4643. BloodSugar: bloodsugarfloat,
  4644. Pulse: pulsefloat,
  4645. Sbp: sbpfloat,
  4646. Dbp: dbpfloat,
  4647. Height: heightfloat,
  4648. BloodFat: bloodfatfloat,
  4649. SickType: sick_type,
  4650. Symptom: symptom,
  4651. SickDate: sickTimes,
  4652. IsInfect: is_infect,
  4653. HistoryOfPresentIllness: history_of_present_illness,
  4654. PastHistory: past_history,
  4655. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4656. ChiefConplaint: chief_conplaint,
  4657. PersonalHistory: personal_history,
  4658. FamilyHistory: family_history,
  4659. Diagnostic: diagnostic,
  4660. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4661. Status: 1,
  4662. Ctime: ctime,
  4663. Mtime: ctime,
  4664. RecordDate: recordDateTime,
  4665. DeliveryWay: delivery_way,
  4666. Breathing: breathingfloat,
  4667. DoctorAdvice: doctor_advice,
  4668. Remark: remark,
  4669. Sick: sick,
  4670. Diagnose: diagnose,
  4671. AllergicHistory: allergic_history,
  4672. PrimaryDisease: primary_disease,
  4673. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4674. DrugAllergyHistory: drug_allergy_history,
  4675. PhysicalExamination: physical_examination,
  4676. SpecialInspection: special_inspection,
  4677. LabApparatus: lab_apparatus,
  4678. }
  4679. //查询该患者是否有病历
  4680. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4681. if errcodes == gorm.ErrRecordNotFound {
  4682. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4683. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4684. if err != nil {
  4685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4686. return
  4687. }
  4688. c.ServeSuccessJSON(map[string]interface{}{
  4689. "caseHistory": caseHistory,
  4690. "historyInfo": historyInfo,
  4691. })
  4692. return
  4693. } else if errcodes == nil {
  4694. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4695. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4696. if err != nil {
  4697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4698. return
  4699. }
  4700. c.ServeSuccessJSON(map[string]interface{}{
  4701. "caseHistory": caseHistory,
  4702. "historyInfo": historyInfo,
  4703. })
  4704. }
  4705. //查询该患者是否有病历
  4706. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4707. //if errcode == gorm.ErrRecordNotFound {
  4708. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4709. // if err != nil {
  4710. // c.ServeSuccessJSON(map[string]interface{}{
  4711. // "msg": "保存成功",
  4712. // })
  4713. // }
  4714. //} else if errcode == nil {
  4715. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4716. // return
  4717. //}
  4718. }
  4719. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4720. patient_id, _ := c.GetInt64("patient_id", 0)
  4721. adminUser := c.GetAdminUserInfo()
  4722. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4723. c.ServeSuccessJSON(map[string]interface{}{
  4724. "list": caseHistorys,
  4725. })
  4726. }
  4727. func (c *HisApiController) GetHisPatientCaseHistory() {
  4728. record_date, _ := c.GetInt64("record_date", 0)
  4729. patient_id, _ := c.GetInt64("patient_id", 0)
  4730. admin := c.GetAdminUserInfo()
  4731. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4732. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4733. c.ServeSuccessJSON(map[string]interface{}{
  4734. "info": info,
  4735. "case_history": case_history,
  4736. })
  4737. }
  4738. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4739. template_name := c.GetString("template_name")
  4740. template_remark := c.GetString("template_remark")
  4741. doctor := c.GetAdminUserInfo().AdminUser.Id
  4742. diagnostic := c.GetString("diagnostic")
  4743. chief_conplaint := c.GetString("chief_conplain")
  4744. history_of_present_illness := c.GetString("history_of_present_illness")
  4745. past_history := c.GetString("past_history")
  4746. personal_history := c.GetString("personal_history")
  4747. family_history := c.GetString("family_history")
  4748. user_name := c.GetString("user_name")
  4749. doctor_advice := c.GetString("doctor_advice")
  4750. remark := c.GetString("remark")
  4751. //record_date := c.GetString("record_date")
  4752. //fmt.Println("record_date--------",record_date)
  4753. //timeLayout := "2006-01-02"
  4754. //loc, _ := time.LoadLocation("Local")
  4755. //
  4756. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4757. //if err != nil {
  4758. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4759. // return
  4760. //}
  4761. //recordDateTime := theTime.Unix()
  4762. ctime := time.Now().Unix()
  4763. template := models.HisCaseHistoryTemplate{
  4764. HistoryOfPresentIllness: history_of_present_illness,
  4765. PastHistory: past_history,
  4766. ChiefConplaint: chief_conplaint,
  4767. PersonalHistory: personal_history,
  4768. FamilyHistory: family_history,
  4769. Diagnostic: diagnostic,
  4770. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4771. Status: 1,
  4772. Ctime: ctime,
  4773. Mtime: ctime,
  4774. RecordDate: time.Now().Unix(),
  4775. TemplateName: template_name,
  4776. TemplateRemark: template_remark,
  4777. Creator: doctor,
  4778. Modifier: doctor,
  4779. UserName: user_name,
  4780. DoctorAdvice: doctor_advice,
  4781. Remark: remark,
  4782. }
  4783. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4784. if err == nil {
  4785. c.ServeSuccessJSON(map[string]interface{}{
  4786. "msg": "保存成功",
  4787. })
  4788. } else {
  4789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4790. return
  4791. }
  4792. }
  4793. func (c *HisApiController) GetCaseHistoryTemplate() {
  4794. timeLayout := "2006-01-02"
  4795. loc, _ := time.LoadLocation("Local")
  4796. keyword := c.GetString("keyword")
  4797. start_time := c.GetString("start_time")
  4798. end_time := c.GetString("end_time")
  4799. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4800. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4801. admin := c.GetAdminUserInfo()
  4802. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4803. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4804. c.ServeSuccessJSON(map[string]interface{}{
  4805. "template": template,
  4806. //"history": history,
  4807. })
  4808. }
  4809. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4810. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4811. utils.ErrorLog("drug_name")
  4812. return enums.ErrorCodeParamWrong
  4813. }
  4814. adviceName, _ := json["drug_name"].(string)
  4815. if len(adviceName) == 0 {
  4816. utils.ErrorLog("len(advice_name) == 0")
  4817. return enums.ErrorCodeParamWrong
  4818. }
  4819. advice.AdviceName = adviceName
  4820. adviceDesc, _ := json["advice_desc"].(string)
  4821. advice.AdviceDesc = adviceDesc
  4822. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4823. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4824. advice.DrugSpec = drugSpec
  4825. }
  4826. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4827. remark, _ := json["remark"].(string)
  4828. advice.Remark = remark
  4829. }
  4830. if json["id"] == nil {
  4831. advice.DrugId = 0
  4832. } else {
  4833. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4834. drug_id := int64(json["id"].(float64))
  4835. advice.DrugId = drug_id
  4836. }
  4837. }
  4838. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4839. advice_id := int64(json["advice_id"].(float64))
  4840. advice.ID = advice_id
  4841. if advice.ID > 0 {
  4842. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4843. if err == nil {
  4844. if hisAdvice.ID > 0 {
  4845. advice.ExecutionTime = hisAdvice.ExecutionTime
  4846. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4847. advice.ExecutionState = hisAdvice.ExecutionState
  4848. advice.CheckTime = hisAdvice.CheckTime
  4849. advice.Checker = hisAdvice.Checker
  4850. advice.CheckState = hisAdvice.CheckState
  4851. advice.StartTime = hisAdvice.StartTime
  4852. advice.FeedetlSn = hisAdvice.FeedetlSn
  4853. }
  4854. }
  4855. }
  4856. }
  4857. //
  4858. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4859. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4860. // advice.ExecutionTime = execution_time
  4861. //}
  4862. //
  4863. //
  4864. //
  4865. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4866. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4867. // advice.ExecutionStaff = execution_staff
  4868. //}
  4869. //
  4870. //
  4871. //
  4872. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4873. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4874. // advice.ExecutionState = execution_state
  4875. //}
  4876. //
  4877. //
  4878. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4879. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4880. // advice.CheckTime = check_time
  4881. //}
  4882. //
  4883. //
  4884. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4885. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4886. // advice.CheckState = check_state
  4887. //}
  4888. //
  4889. //
  4890. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4891. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4892. // advice.Checker = checker
  4893. //}
  4894. //
  4895. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4896. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4897. // advice.StartTime = start_time
  4898. //}
  4899. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  4900. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  4901. advice.IsSelfDrug = is_self_drug
  4902. }
  4903. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4904. drugSpecUnit, _ := json["min_unit"].(string)
  4905. advice.DrugSpecUnit = drugSpecUnit
  4906. }
  4907. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4908. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4909. advice.SingleDose = singleDose
  4910. }
  4911. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4912. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4913. advice.SingleDoseUnit = singleDoseUnit
  4914. }
  4915. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4916. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4917. advice.PrescribingNumber = prescribingNumber
  4918. }
  4919. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4920. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4921. advice.PrescribingNumberUnit = prescribingNumberUnit
  4922. }
  4923. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4924. deliveryWay, _ := json["delivery_way"].(string)
  4925. advice.DeliveryWay = deliveryWay
  4926. }
  4927. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4928. executionFrequency, _ := json["execution_frequency"].(string)
  4929. advice.ExecutionFrequency = executionFrequency
  4930. }
  4931. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4932. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4933. advice.Price = price
  4934. }
  4935. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4936. med_list_codg, _ := json["medical_insurance_number"].(string)
  4937. advice.MedListCodg = med_list_codg
  4938. }
  4939. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4940. day := int64(json["day"].(float64))
  4941. advice.Day = day
  4942. }
  4943. return 0
  4944. }
  4945. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4946. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4947. id := int64(json["id"].(float64))
  4948. project.ID = id
  4949. historyProject, _ := service.GetHisProjectByID(id)
  4950. project.FeedetlSn = historyProject.FeedetlSn
  4951. }
  4952. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4953. project_id := int64(json["project_id"].(float64))
  4954. project.ProjectId = project_id
  4955. }
  4956. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4957. // price := int64(json["price"].(float64))
  4958. // formatInt_price := strconv.FormatInt(price, 10)
  4959. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4960. // project.Price = float_price
  4961. // }
  4962. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4963. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4964. project.Price = price
  4965. }
  4966. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4967. total, _ := json["total"].(string)
  4968. project.Count = total
  4969. }
  4970. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4971. medical_code, _ := json["medical_code"].(string)
  4972. project.MedListCodg = medical_code
  4973. }
  4974. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4975. single_dose, _ := json["single_dose"].(string)
  4976. project.SingleDose = single_dose
  4977. }
  4978. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4979. delivery_way, _ := json["delivery_way"].(string)
  4980. project.DeliveryWay = delivery_way
  4981. }
  4982. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4983. execution_frequency, _ := json["execution_frequency"].(string)
  4984. project.ExecutionFrequency = execution_frequency
  4985. }
  4986. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4987. remark, _ := json["remark"].(string)
  4988. project.Remark = remark
  4989. }
  4990. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4991. day, _ := json["number_days"].(string)
  4992. project.Day = day
  4993. }
  4994. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4995. unit, _ := json["unit"].(string)
  4996. project.Unit = unit
  4997. }
  4998. return 0
  4999. }
  5000. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5001. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5002. id := int64(json["id"].(float64))
  5003. historyAddtions, _ := service.GetHisAdditionByID(id)
  5004. additionalCharge.ID = id
  5005. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5006. }
  5007. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5008. item_id := int64(json["item_id"].(float64))
  5009. additionalCharge.ItemId = item_id
  5010. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5011. if config.ID > 0 {
  5012. if len(config.Code) > 0 {
  5013. additionalCharge.MedListCodg = config.Code
  5014. }
  5015. }
  5016. }
  5017. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5018. // price := int64(json["price"].(float64))
  5019. // formatInt_price := strconv.FormatInt(price, 10)
  5020. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5021. // additionalCharge.Price = float_price
  5022. // }
  5023. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5024. // price := int64(json["price"].(float64))
  5025. // formatInt_price := strconv.FormatInt(price, 10)
  5026. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5027. // additionalCharge.Price = float_price
  5028. //}
  5029. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5030. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5031. additionalCharge.Price = price
  5032. }
  5033. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5034. count, _ := json["count"].(string)
  5035. counts, _ := strconv.ParseInt(count, 10, 64)
  5036. additionalCharge.Count = counts
  5037. }
  5038. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5039. item_name, _ := json["item_name"].(string)
  5040. additionalCharge.ItemName = item_name
  5041. }
  5042. return 0
  5043. }
  5044. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5045. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5046. utils.ErrorLog("drug_name")
  5047. return enums.ErrorCodeParamWrong
  5048. }
  5049. adviceName, _ := json["drug_name"].(string)
  5050. if len(adviceName) == 0 {
  5051. utils.ErrorLog("len(advice_name) == 0")
  5052. return enums.ErrorCodeParamWrong
  5053. }
  5054. advice.AdviceName = adviceName
  5055. adviceDesc, _ := json["advice_desc"].(string)
  5056. advice.AdviceDesc = adviceDesc
  5057. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5058. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5059. advice.DrugSpec = drugSpec
  5060. }
  5061. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5062. remark, _ := json["remark"].(string)
  5063. advice.Remark = remark
  5064. }
  5065. if json["id"] == nil {
  5066. advice.DrugId = 0
  5067. } else {
  5068. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5069. drug_id := int64(json["id"].(float64))
  5070. advice.DrugId = drug_id
  5071. }
  5072. }
  5073. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5074. groupno := int64(json["groupno"].(float64))
  5075. advice.Groupno = groupno
  5076. }
  5077. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5078. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5079. advice.IsSelfDrug = is_self_drug
  5080. }
  5081. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5082. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5083. advice.HospApprFlag = hosp_appr_flag
  5084. }
  5085. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5086. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5087. advice.PrescribingNumber = prescribingNumber
  5088. }
  5089. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5090. // frequency_type := int64(json["frequency_type"].(float64))
  5091. // advice.FrequencyType = frequency_type
  5092. //}
  5093. //
  5094. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5095. // day_count := int64(json["day_count"].(float64))
  5096. // advice.DayCount = day_count
  5097. //}
  5098. //
  5099. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5100. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5101. // week_day, _ := json["week_day"].(string)
  5102. // advice.WeekDay = week_day
  5103. //}
  5104. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5105. drugSpecUnit, _ := json["min_unit"].(string)
  5106. advice.DrugSpecUnit = drugSpecUnit
  5107. }
  5108. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5109. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5110. advice.SingleDose = singleDose
  5111. }
  5112. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5113. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5114. advice.SingleDoseUnit = singleDoseUnit
  5115. }
  5116. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5117. deliveryWay, _ := json["delivery_way"].(string)
  5118. advice.DeliveryWay = deliveryWay
  5119. }
  5120. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5121. executionFrequency, _ := json["execution_frequency"].(string)
  5122. advice.ExecutionFrequency = executionFrequency
  5123. }
  5124. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5125. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5126. advice.Price = price
  5127. }
  5128. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5129. med_list_codg, _ := json["medical_insurance_number"].(string)
  5130. advice.MedListCodg = med_list_codg
  5131. }
  5132. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5133. day := int64(json["day"].(float64))
  5134. advice.Day = day
  5135. }
  5136. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5137. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5138. advice.PrescribingNumberUnit = prescribingNumberUnit
  5139. }
  5140. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5141. advice_id := int64(json["advice_id"].(float64))
  5142. advice.ID = advice_id
  5143. if advice.ID > 0 {
  5144. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5145. if err == nil {
  5146. if hisAdvice.ID > 0 {
  5147. advice.ExecutionTime = hisAdvice.ExecutionTime
  5148. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5149. advice.ExecutionState = hisAdvice.ExecutionState
  5150. advice.CheckTime = hisAdvice.CheckTime
  5151. advice.Checker = hisAdvice.Checker
  5152. advice.CheckState = hisAdvice.CheckState
  5153. advice.StartTime = hisAdvice.StartTime
  5154. advice.HospApprFlag = hisAdvice.HospApprFlag
  5155. advice.IsMedicine = hisAdvice.IsMedicine
  5156. if hisAdvice.UserOrgId == 10028 {
  5157. 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 {
  5158. advice.ExecutionTime = 0
  5159. advice.ExecutionStaff = 0
  5160. advice.ExecutionState = 2
  5161. advice.CheckTime = 0
  5162. advice.Checker = 0
  5163. advice.CheckState = 2
  5164. }
  5165. } else {
  5166. 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 {
  5167. advice.ExecutionTime = 0
  5168. advice.ExecutionStaff = 0
  5169. advice.ExecutionState = 2
  5170. advice.CheckTime = 0
  5171. advice.Checker = 0
  5172. advice.CheckState = 2
  5173. }
  5174. }
  5175. //advice.Groupno = hisAdvice.Groupno
  5176. }
  5177. }
  5178. }
  5179. }
  5180. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5181. //
  5182. //if drugStockConfig.IsOpen == 1 {
  5183. //
  5184. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5185. // if advice.ID == 0 { //医嘱不存在
  5186. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5187. // drug.Total = drug.Total - advice.PrescribingNumber
  5188. // service.UpdateBaseDrugLib(&drug)
  5189. //
  5190. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5191. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5192. // drug.Total = drug.Total - num
  5193. // service.UpdateBaseDrugLib(&drug)
  5194. // }
  5195. //
  5196. // } else if advice.ID > 0 { //医嘱存在
  5197. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5198. // var num float64
  5199. //
  5200. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5201. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5202. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5203. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5204. // drug.Total = drug.Total + num
  5205. // service.UpdateBaseDrugLib(&drug)
  5206. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5207. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5208. // drug.Total = drug.Total - num
  5209. // service.UpdateBaseDrugLib(&drug)
  5210. // }
  5211. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5212. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5213. // if num2 > advice.PrescribingNumber {
  5214. // num = num2 - advice.PrescribingNumber
  5215. // drug.Total = drug.Total + num
  5216. // service.UpdateBaseDrugLib(&drug)
  5217. // } else if num2 < advice.PrescribingNumber {
  5218. // num = advice.PrescribingNumber - num2
  5219. // drug.Total = drug.Total - num
  5220. // service.UpdateBaseDrugLib(&drug)
  5221. // }
  5222. //
  5223. // }
  5224. //
  5225. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5226. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5227. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5228. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5229. // if num1 > num2 {
  5230. // num = num1 - num2
  5231. // drug.Total = drug.Total + num
  5232. // service.UpdateBaseDrugLib(&drug)
  5233. // } else if num1 < num2 {
  5234. // num = num2 - num1
  5235. // drug.Total = drug.Total - num
  5236. // service.UpdateBaseDrugLib(&drug)
  5237. // }
  5238. //
  5239. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5240. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5241. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5242. // if hisAdvice.PrescribingNumber > num2 {
  5243. // num = hisAdvice.PrescribingNumber - num2
  5244. // drug.Total = drug.Total + num
  5245. // service.UpdateBaseDrugLib(&drug)
  5246. // } else if num2 < advice.PrescribingNumber {
  5247. // num = num2 - hisAdvice.PrescribingNumber
  5248. // drug.Total = drug.Total - num
  5249. // service.UpdateBaseDrugLib(&drug)
  5250. // }
  5251. //
  5252. // }
  5253. // }
  5254. // }
  5255. //}
  5256. //
  5257. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5258. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5259. // advice.ExecutionTime = execution_time
  5260. //}
  5261. //
  5262. //
  5263. //
  5264. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5265. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5266. // advice.ExecutionStaff = execution_staff
  5267. //}
  5268. //
  5269. //
  5270. //
  5271. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5272. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5273. // advice.ExecutionState = execution_state
  5274. //}
  5275. //
  5276. //
  5277. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5278. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5279. // advice.CheckTime = check_time
  5280. //}
  5281. //
  5282. //
  5283. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5284. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5285. // advice.CheckState = check_state
  5286. //}
  5287. //
  5288. //
  5289. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5290. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5291. // advice.Checker = checker
  5292. //}
  5293. //
  5294. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5295. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5296. // advice.StartTime = start_time
  5297. //}
  5298. return 0
  5299. }
  5300. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5301. project.ExecutionStaff = 0
  5302. project.ExecutionState = 2
  5303. project.ExecutionTime = 0
  5304. project.Checker = 0
  5305. project.CheckState = 2
  5306. project.CheckTime = 0
  5307. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5308. id := int64(json["id"].(float64))
  5309. project.ID = id
  5310. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5311. project.ExecutionStaff = temp_project.ExecutionStaff
  5312. project.ExecutionState = temp_project.ExecutionState
  5313. project.ExecutionTime = temp_project.ExecutionTime
  5314. project.Checker = temp_project.Checker
  5315. project.CheckState = temp_project.CheckState
  5316. project.CheckTime = temp_project.CheckTime
  5317. project.TeamId = temp_project.TeamId
  5318. }
  5319. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5320. types := int64(json["type"].(float64))
  5321. project.Type = types
  5322. }
  5323. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5324. project_id := int64(json["project_id"].(float64))
  5325. project.ProjectId = project_id
  5326. }
  5327. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5328. team_id := int64(json["team_id"].(float64))
  5329. project.TeamId = team_id
  5330. }
  5331. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5332. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5333. project.Price = price
  5334. }
  5335. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5336. total, _ := json["total"].(string)
  5337. //totals, _ := strconv.ParseInt(total, 10, 64)
  5338. project.Count = total
  5339. }
  5340. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5341. medical_code, _ := json["medical_code"].(string)
  5342. project.MedListCodg = medical_code
  5343. }
  5344. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5345. single_dose, _ := json["single_dose"].(string)
  5346. project.SingleDose = single_dose
  5347. }
  5348. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5349. delivery_way, _ := json["delivery_way"].(string)
  5350. project.DeliveryWay = delivery_way
  5351. }
  5352. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5353. execution_frequency, _ := json["execution_frequency"].(string)
  5354. project.ExecutionFrequency = execution_frequency
  5355. }
  5356. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5357. remark, _ := json["remark"].(string)
  5358. project.Remark = remark
  5359. }
  5360. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5361. day, _ := json["number_days"].(string)
  5362. project.Day = day
  5363. }
  5364. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5365. unit, _ := json["unit"].(string)
  5366. project.Unit = unit
  5367. }
  5368. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5369. // frequency_type := int64(json["frequency_type"].(float64))
  5370. // project.FrequencyType = frequency_type
  5371. //}
  5372. //
  5373. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5374. // day_count := int64(json["day_count"].(float64))
  5375. // project.DayCount = day_count
  5376. //}
  5377. //
  5378. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5379. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5380. // week_day, _ := json["week_day"].(string)
  5381. // project.WeekDay = week_day
  5382. //}
  5383. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5384. //
  5385. //if project.ID == 0 {
  5386. // if stockConfig.IsOpen == 1 {
  5387. // if project.Type == 3 {
  5388. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5389. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5390. // good.Total = good.Total - f_count
  5391. // service.UpdateGoodInfo(&good)
  5392. // }
  5393. // }
  5394. //
  5395. //} else {
  5396. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5397. //
  5398. // if stockConfig.IsOpen == 1 {
  5399. // if project.Type == 3 {
  5400. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5401. // if project.Count < temp_project.Count {
  5402. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5403. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5404. //
  5405. // other_count := f_count_two - f_count_one
  5406. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5407. // good.Total = good.Total + other_count_two
  5408. // service.UpdateGoodInfo(&good)
  5409. // } else if project.Count > temp_project.Count {
  5410. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5411. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5412. //
  5413. // other_count := f_count_one - f_count_two
  5414. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5415. // good.Total = good.Total - other_count_two
  5416. // service.UpdateGoodInfo(&good)
  5417. // }
  5418. //
  5419. // }
  5420. // }
  5421. //
  5422. //}
  5423. return 0
  5424. }
  5425. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5426. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5427. id := int64(json["id"].(float64))
  5428. additionalCharge.ID = id
  5429. }
  5430. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5431. item_id := int64(json["item_id"].(float64))
  5432. additionalCharge.ItemId = item_id
  5433. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5434. if config.ID > 0 {
  5435. if len(config.Code) > 0 {
  5436. additionalCharge.MedListCodg = config.Code
  5437. }
  5438. }
  5439. }
  5440. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5441. // price := int64(json["price"].(float64))
  5442. // formatInt_price := strconv.FormatInt(price, 10)
  5443. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5444. // additionalCharge.Price = float_price
  5445. // }
  5446. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5447. // price := int64(json["price"].(float64))
  5448. // formatInt_price := strconv.FormatInt(price, 10)
  5449. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5450. // additionalCharge.Price = float_price
  5451. //}
  5452. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5453. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5454. additionalCharge.Price = price
  5455. }
  5456. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5457. count, _ := json["count"].(string)
  5458. counts, _ := strconv.ParseInt(count, 10, 64)
  5459. additionalCharge.Count = counts
  5460. }
  5461. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5462. item_name, _ := json["item_name"].(string)
  5463. additionalCharge.ItemName = item_name
  5464. }
  5465. return 0
  5466. }
  5467. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5468. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5469. utils.ErrorLog("drug_name")
  5470. return enums.ErrorCodeParamWrong
  5471. }
  5472. adviceName, _ := json["drug_name"].(string)
  5473. if len(adviceName) == 0 {
  5474. utils.ErrorLog("len(advice_name) == 0")
  5475. return enums.ErrorCodeParamWrong
  5476. }
  5477. advice.AdviceName = adviceName
  5478. adviceDesc, _ := json["advice_desc"].(string)
  5479. advice.AdviceDesc = adviceDesc
  5480. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5481. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5482. advice.DrugSpec = drugSpec
  5483. }
  5484. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5485. remark, _ := json["remark"].(string)
  5486. advice.Remark = remark
  5487. }
  5488. if json["id"] == nil {
  5489. advice.DrugId = 0
  5490. } else {
  5491. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5492. drug_id := int64(json["id"].(float64))
  5493. advice.DrugId = drug_id
  5494. }
  5495. }
  5496. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5497. groupno := int64(json["groupno"].(float64))
  5498. advice.Groupno = groupno
  5499. }
  5500. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5501. drugSpecUnit, _ := json["min_unit"].(string)
  5502. advice.DrugSpecUnit = drugSpecUnit
  5503. }
  5504. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5505. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5506. advice.SingleDose = singleDose
  5507. }
  5508. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5509. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5510. advice.SingleDoseUnit = singleDoseUnit
  5511. }
  5512. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5513. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5514. advice.PrescribingNumber = prescribingNumber
  5515. }
  5516. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5517. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5518. advice.PrescribingNumberUnit = prescribingNumberUnit
  5519. }
  5520. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5521. deliveryWay, _ := json["delivery_way"].(string)
  5522. advice.DeliveryWay = deliveryWay
  5523. }
  5524. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5525. executionFrequency, _ := json["execution_frequency"].(string)
  5526. advice.ExecutionFrequency = executionFrequency
  5527. }
  5528. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5529. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5530. advice.Price = price
  5531. }
  5532. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5533. med_list_codg, _ := json["medical_insurance_number"].(string)
  5534. advice.MedListCodg = med_list_codg
  5535. }
  5536. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5537. day := int64(json["day"].(float64))
  5538. advice.Day = day
  5539. }
  5540. advice.FrequencyType = 1
  5541. return 0
  5542. }
  5543. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5544. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5545. types := int64(json["type"].(float64))
  5546. project.Type = types
  5547. }
  5548. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5549. project_id := int64(json["project_id"].(float64))
  5550. project.ProjectId = project_id
  5551. }
  5552. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5553. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5554. project.Price = price
  5555. }
  5556. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5557. total, _ := json["total"].(string)
  5558. //totals, _ := strconv.ParseInt(total, 10, 64)
  5559. project.Count = total
  5560. }
  5561. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5562. medical_code, _ := json["medical_code"].(string)
  5563. project.MedListCodg = medical_code
  5564. }
  5565. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5566. single_dose, _ := json["single_dose"].(string)
  5567. project.SingleDose = single_dose
  5568. }
  5569. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5570. delivery_way, _ := json["delivery_way"].(string)
  5571. project.DeliveryWay = delivery_way
  5572. }
  5573. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5574. execution_frequency, _ := json["execution_frequency"].(string)
  5575. project.ExecutionFrequency = execution_frequency
  5576. }
  5577. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5578. remark, _ := json["remark"].(string)
  5579. project.Remark = remark
  5580. }
  5581. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5582. day, _ := json["number_days"].(string)
  5583. project.Day = day
  5584. }
  5585. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5586. unit, _ := json["unit"].(string)
  5587. project.Unit = unit
  5588. }
  5589. project.FrequencyType = 1
  5590. return 0
  5591. }
  5592. func (c *HisApiController) GetHisOrderList() {
  5593. page, _ := c.GetInt64("page", -1)
  5594. limit, _ := c.GetInt64("limit", -1)
  5595. start_time := c.GetString("start_time")
  5596. end_time := c.GetString("end_time")
  5597. types, _ := c.GetInt64("type", 0)
  5598. keywords := c.GetString("keywords")
  5599. p_type, _ := c.GetInt64("p_type", 0)
  5600. sort_type, _ := c.GetInt64("sort_type", 0)
  5601. charge_type, _ := c.GetInt64("charge_type", 0)
  5602. sch_type, _ := c.GetInt64("sch_type", 0)
  5603. zone_type, _ := c.GetInt64("zone_type", 0)
  5604. med_type, _ := c.GetInt64("med_type", 0)
  5605. timeLayout := "2006-01-02"
  5606. loc, _ := time.LoadLocation("Local")
  5607. var startTime int64
  5608. if len(start_time) > 0 {
  5609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5610. if err != nil {
  5611. //fmt.Println(err)
  5612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5613. return
  5614. }
  5615. startTime = theTime.Unix()
  5616. }
  5617. var endTime int64
  5618. if len(end_time) > 0 {
  5619. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5620. if err != nil {
  5621. utils.ErrorLog(err.Error())
  5622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5623. return
  5624. }
  5625. endTime = theTime.Unix()
  5626. }
  5627. adminUser := c.GetAdminUserInfo()
  5628. org_id := adminUser.CurrentOrgId
  5629. 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, med_type)
  5630. for _, item := range order {
  5631. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5632. item.DoctorName = info.Doctor
  5633. item.DepartmentName = info.XtHisDepartment.Name
  5634. }
  5635. if err == nil {
  5636. c.ServeSuccessJSON(map[string]interface{}{
  5637. "order": order,
  5638. "total": total,
  5639. })
  5640. } else {
  5641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5642. return
  5643. }
  5644. }
  5645. func (c *HisApiController) GetHisOrder() {
  5646. patient_id, _ := c.GetInt64("patient_id", 0)
  5647. number := c.GetString("number")
  5648. adminInfo := c.GetAdminUserInfo()
  5649. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5650. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5651. if err == nil {
  5652. c.ServeSuccessJSON(map[string]interface{}{
  5653. "order": order,
  5654. "prescription": prescriptions,
  5655. })
  5656. } else {
  5657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5658. return
  5659. }
  5660. }
  5661. func (c *HisApiController) GetHisPrescriptionList() {
  5662. record_date := c.GetString("record_date")
  5663. keywords := c.GetString("keywords")
  5664. page, _ := c.GetInt64("page")
  5665. limit, _ := c.GetInt64("limit")
  5666. sch_type, _ := c.GetInt64("sch_type")
  5667. timeLayout := "2006-01-02"
  5668. loc, _ := time.LoadLocation("Local")
  5669. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5670. if err != nil {
  5671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5672. return
  5673. }
  5674. recordDateTime := theTime.Unix()
  5675. adminInfo := c.GetAdminUserInfo()
  5676. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5677. //adminInfo := c.GetAdminUserInfo()
  5678. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5679. //fmt.Println(prescriptionOrder)
  5680. if err == nil {
  5681. c.ServeSuccessJSON(map[string]interface{}{
  5682. "order": prescriptionOrder,
  5683. "total": total,
  5684. })
  5685. } else {
  5686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5687. return
  5688. }
  5689. }
  5690. func (c *HisApiController) GetHisPrescriptionInfo() {
  5691. id, _ := c.GetInt64("id")
  5692. adminInfo := c.GetAdminUserInfo()
  5693. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5694. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5695. if err == nil {
  5696. c.ServeSuccessJSON(map[string]interface{}{
  5697. "order": prescriptionOrder,
  5698. "prescription": prescription,
  5699. })
  5700. } else {
  5701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5702. return
  5703. }
  5704. }
  5705. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5706. adminUser := c.GetAdminUserInfo()
  5707. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5708. c.ServeSuccessJSON(map[string]interface{}{
  5709. "config": config,
  5710. })
  5711. }
  5712. type ResultTwo struct {
  5713. ErrMsg interface{} `json:"err_msg"`
  5714. InfRefmsgid string `json:"inf_refmsgid"`
  5715. Infcode int64 `json:"infcode"`
  5716. Output struct {
  5717. Baseinfo struct {
  5718. Age float64 `json:"age"`
  5719. Brdy string `json:"brdy"`
  5720. Certno string `json:"certno"`
  5721. Gend string `json:"gend"`
  5722. Naty string `json:"naty"`
  5723. PsnCertType string `json:"psn_cert_type"`
  5724. PsnName string `json:"psn_name"`
  5725. PsnNo string `json:"psn_no"`
  5726. } `json:"baseinfo"`
  5727. Idetinfo []interface{} `json:"idetinfo"`
  5728. Iinfo []struct {
  5729. Balc float64 `json:"balc"`
  5730. CvlservFlag string `json:"cvlserv_flag"`
  5731. EmpName string `json:"emp_name"`
  5732. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5733. Insutype string `json:"insutype"`
  5734. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5735. PausInsuDate interface{} `json:"paus_insu_date"`
  5736. PsnInsuDate string `json:"psn_insu_date"`
  5737. PsnInsuStas string `json:"psn_insu_stas"`
  5738. PsnType string `json:"psn_type"`
  5739. } `json:"insuinfo"`
  5740. } `json:"output"`
  5741. RefmsgTime string `json:"refmsg_time"`
  5742. RespondTime string `json:"respond_time"`
  5743. Signtype interface{} `json:"signtype"`
  5744. WarnInfo interface{} `json:"warn_info"`
  5745. }
  5746. type ResultThree struct {
  5747. Cainfo interface{} `json:"cainfo"`
  5748. ErrMsg interface{} `json:"err_msg"`
  5749. InfRefmsgid string `json:"inf_refmsgid"`
  5750. Infcode int64 `json:"infcode"`
  5751. Output struct {
  5752. Data struct {
  5753. IptOtpNo string `json:"ipt_otp_no"`
  5754. MdtrtID string `json:"mdtrt_id"`
  5755. PsnNo string `json:"psn_no"`
  5756. } `json:"data"`
  5757. } `json:"output"`
  5758. RefmsgTime string `json:"refmsg_time"`
  5759. RespondTime string `json:"respond_time"`
  5760. Signtype interface{} `json:"signtype"`
  5761. WarnMsg interface{} `json:"warn_msg"`
  5762. }
  5763. type ResultFour struct {
  5764. Cainfo string `json:"cainfo"`
  5765. ErrMsg string `json:"err_msg"`
  5766. InfRefmsgid string `json:"inf_refmsgid"`
  5767. Infcode int64 `json:"infcode"`
  5768. Output struct {
  5769. Result []struct {
  5770. BasMednFlag string `json:"bas_medn_flag"`
  5771. ChldMedcFlag string `json:"chld_medc_flag"`
  5772. ChrgitmLv string `json:"chrgitm_lv"`
  5773. Cnt float64 `json:"cnt"`
  5774. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5775. DrtReimFlag string `json:"drt_reim_flag"`
  5776. FeedetlSn string `json:"feedetl_sn"`
  5777. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5778. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5779. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5780. ListSpItemFlag string `json:"list_sp_item_flag"`
  5781. LmtUsedFlag string `json:"lmt_used_flag"`
  5782. MedChrgitmType string `json:"med_chrgitm_type"`
  5783. Memo string `json:"memo"`
  5784. OverlmtAmt float64 `json:"overlmt_amt"`
  5785. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5786. Pric float64 `json:"pric"`
  5787. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5788. SelfpayProp float64 `json:"selfpay_prop"`
  5789. } `json:"result"`
  5790. } `json:"output"`
  5791. RefmsgTime string `json:"refmsg_time"`
  5792. RespondTime string `json:"respond_time"`
  5793. Signtype string `json:"signtype"`
  5794. WarnMsg string `json:"warn_msg"`
  5795. }
  5796. type ResultFive struct {
  5797. Insutype string `json:"insutype"`
  5798. }
  5799. type ResultSix struct {
  5800. Cainfo interface{} `json:"cainfo"`
  5801. ErrMsg interface{} `json:"err_msg"`
  5802. InfRefmsgid string `json:"inf_refmsgid"`
  5803. Infcode int64 `json:"infcode"`
  5804. Output struct {
  5805. } `json:"output"`
  5806. RefmsgTime string `json:"refmsg_time"`
  5807. RespondTime string `json:"respond_time"`
  5808. Signtype interface{} `json:"signtype"`
  5809. WarnMsg interface{} `json:"warn_msg"`
  5810. }
  5811. type ResultSeven struct {
  5812. Cainfo string `json:"cainfo"`
  5813. ErrMsg string `json:"err_msg"`
  5814. InfRefmsgid string `json:"inf_refmsgid"`
  5815. Infcode int64 `json:"infcode"`
  5816. Output struct {
  5817. Setldetail []interface{} `json:"setldetail"`
  5818. Setlinfo struct {
  5819. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5820. AcctPay float64 `json:"acct_pay"`
  5821. ActPayDedc float64 `json:"act_pay_dedc"`
  5822. Age float64 `json:"age"`
  5823. Balc float64 `json:"balc"`
  5824. Brdy string `json:"brdy"`
  5825. Certno string `json:"certno"`
  5826. ClrOptins string `json:"clr_optins"`
  5827. ClrType string `json:"clr_type"`
  5828. ClrWay string `json:"clr_way"`
  5829. CvlservFlag string `json:"cvlserv_flag"`
  5830. CvlservPay float64 `json:"cvlserv_pay"`
  5831. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5832. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5833. Gend string `json:"gend"`
  5834. HifesPay float64 `json:"hifes_pay"`
  5835. HifmiPay float64 `json:"hifmi_pay"`
  5836. HifobPay float64 `json:"hifob_pay"`
  5837. HifpPay float64 `json:"hifp_pay"`
  5838. HospPartAmt float64 `json:"hosp_part_amt"`
  5839. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5840. Insutype string `json:"insutype"`
  5841. MafPay float64 `json:"maf_pay"`
  5842. MdtrtCertType string `json:"mdtrt_cert_type"`
  5843. MdtrtID string `json:"mdtrt_id"`
  5844. MedType string `json:"med_type"`
  5845. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5846. MedinsSetlID string `json:"medins_setl_id"`
  5847. Naty string `json:"naty"`
  5848. OthPay float64 `json:"oth_pay"`
  5849. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5850. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5851. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5852. PsnCashPay float64 `json:"psn_cash_pay"`
  5853. PsnCertType string `json:"psn_cert_type"`
  5854. PsnName string `json:"psn_name"`
  5855. PsnNo string `json:"psn_no"`
  5856. PsnPartAmt float64 `json:"psn_part_amt"`
  5857. PsnType string `json:"psn_type"`
  5858. SetlID string `json:"setl_id"`
  5859. SetlTime string `json:"setl_time"`
  5860. } `json:"setlinfo"`
  5861. } `json:"output"`
  5862. RefmsgTime string `json:"refmsg_time"`
  5863. RespondTime string `json:"respond_time"`
  5864. Signtype interface{} `json:"signtype"`
  5865. WarnMsg interface{} `json:"warn_msg"`
  5866. }
  5867. type ResultEight struct {
  5868. Cainfo string `json:"cainfo"`
  5869. ErrMsg string `json:"err_msg"`
  5870. InfRefmsgid string `json:"inf_refmsgid"`
  5871. Infcode int64 `json:"infcode"`
  5872. Output struct {
  5873. Stmtinfo struct {
  5874. SetlOptins string `json:"setl_optins"`
  5875. StmtRslt string `json:"stmt_rslt"`
  5876. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5877. } `json:"stmtinfo"`
  5878. } `json:"output"`
  5879. RefmsgTime string `json:"refmsg_time"`
  5880. RespondTime string `json:"respond_time"`
  5881. Signtype interface{} `json:"signtype"`
  5882. WarnMsg interface{} `json:"warn_msg"`
  5883. }
  5884. type ResultNine struct {
  5885. Cainfo string `json:"cainfo"`
  5886. ErrMsg string `json:"err_msg"`
  5887. InfRefmsgid string `json:"inf_refmsgid"`
  5888. Infcode int64 `json:"infcode"`
  5889. Output struct {
  5890. FileQuryNo string `json:"file_qury_no"`
  5891. } `json:"output"`
  5892. RefmsgTime string `json:"refmsg_time"`
  5893. RespondTime string `json:"respond_time"`
  5894. Signtype interface{} `json:"signtype"`
  5895. WarnMsg interface{} `json:"warn_msg"`
  5896. }
  5897. type ResultTen struct {
  5898. Cainfo string `json:"cainfo"`
  5899. ErrMsg string `json:"err_msg"`
  5900. InfRefmsgid string `json:"inf_refmsgid"`
  5901. Infcode int64 `json:"infcode"`
  5902. Output struct {
  5903. DldEndtime string `json:"dld_endtime"`
  5904. FileQuryNo string `json:"file_qury_no"`
  5905. Filename string `json:"filename"`
  5906. } `json:"output"`
  5907. RefmsgTime string `json:"refmsg_time"`
  5908. RespondTime string `json:"respond_time"`
  5909. Signtype interface{} `json:"signtype"`
  5910. WarnMsg interface{} `json:"warn_msg"`
  5911. }
  5912. type ResultEleven struct {
  5913. Cainfo string `json:"cainfo"`
  5914. ErrMsg string `json:"err_msg"`
  5915. InfRefmsgid string `json:"inf_refmsgid"`
  5916. Infcode int64 `json:"infcode"`
  5917. Output struct {
  5918. Setlinfo struct {
  5919. FixmedinsName string `json:"fixmedins_name"`
  5920. FixmedinsCode string `json:"fixmedins_code"`
  5921. PsnNo string `json:"psn_no"`
  5922. PsnName string `json:"psn_name"`
  5923. HifobPay float64 `json:"hifob_pay"`
  5924. Gend string `json:"gend"`
  5925. Brdy string `json:"brdy"`
  5926. PsnCertType string `json:"psn_cert_type"`
  5927. PsnType string `json:"psn_type"`
  5928. EmpName string `json:"emp_name"`
  5929. Certno string `json:"certno"`
  5930. Insutype string `json:"insutype"`
  5931. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5932. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5933. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5934. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5935. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5936. ActPayDedc float64 `json:"act_pay_dedc"`
  5937. HifpPay float64 `json:"hifp_pay"`
  5938. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5939. CvlservPay float64 `json:"cvlserv_pay"`
  5940. HifesPay float64 `json:"hifes_pay"`
  5941. HifmiPay float64 `json:"hifmi_pay"`
  5942. MafPay float64 `json:"maf_pay"`
  5943. OthPay float64 `json:"oth_pay"`
  5944. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5945. PsnPay float64 `json:"psn_pay"`
  5946. AcctPay float64 `json:"acct_pay"`
  5947. CashPayamt float64 `json:"cash_payamt"`
  5948. Balc float64 `json:"balc"`
  5949. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5950. MedinsSetlId string `json:"medins_setl_id"`
  5951. RefdSetlFlag string `json:"refd_setl_flag"`
  5952. SetlTime string `json:"setl_time"`
  5953. MedType string `json:"med_type"`
  5954. } `json:"setlinfo"`
  5955. } `json:"output"`
  5956. RefmsgTime string `json:"refmsg_time"`
  5957. RespondTime string `json:"respond_time"`
  5958. Signtype interface{} `json:"signtype"`
  5959. WarnMsg interface{} `json:"warn_msg"`
  5960. }
  5961. type Custom struct {
  5962. DetItemFeeSumamt string
  5963. Cut string
  5964. FeedetlSn string
  5965. Price string
  5966. MedListCodg string
  5967. Type int64
  5968. AdviceId int64
  5969. ProjectId int64
  5970. ItemId int64
  5971. }
  5972. // 获取个人信息----挂号-----上传就诊信息
  5973. func (c *HisApiController) GetRegisterInfo() {
  5974. id, _ := c.GetInt64("id")
  5975. record_time := c.GetString("record_time")
  5976. settlementValue, _ := c.GetInt64("settlement_value")
  5977. medical_insurance_card := c.GetString("medical_insurance_card")
  5978. name := c.GetString("name")
  5979. id_card_type, _ := c.GetInt64("id_card_type")
  5980. certificates, _ := c.GetInt64("certificates")
  5981. medical_care, _ := c.GetInt64("medical_care")
  5982. birthday := c.GetString("birthday")
  5983. age, _ := c.GetInt64("age")
  5984. id_card := c.GetString("id_card")
  5985. register_type, _ := c.GetInt64("register")
  5986. doctor, _ := c.GetInt64("doctor")
  5987. department, _ := c.GetInt64("department")
  5988. gender, _ := c.GetInt64("sex")
  5989. phone := c.GetString("phone")
  5990. registration_fee, _ := c.GetFloat("registration_fee")
  5991. medical_expenses, _ := c.GetFloat("medical_expenses")
  5992. social_type, _ := c.GetInt64("social_type")
  5993. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5994. diagnosis_ids := c.GetString("diagnosis")
  5995. sick_type, _ := c.GetInt64("sick_type")
  5996. reg_type := c.GetString("p_type")
  5997. timeLayout := "2006-01-02"
  5998. loc, _ := time.LoadLocation("Local")
  5999. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6000. birthUnix := birthdays.Unix()
  6001. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6002. if err != nil {
  6003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6004. return
  6005. }
  6006. recordDateTime := theTime.Unix()
  6007. adminInfo := c.GetAdminUserInfo()
  6008. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6009. if tempPatient.ID == 0 {
  6010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6011. return
  6012. }
  6013. var patient service.Patients
  6014. if id == 0 {
  6015. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6016. } else {
  6017. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6018. }
  6019. if patient.ID == 0 {
  6020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6021. return
  6022. }
  6023. if len(patient.IdCardNo) == 0 {
  6024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6025. return
  6026. }
  6027. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6028. if len(his) >= 1 {
  6029. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6030. if len(his) >= 1 && order.ID == 0 {
  6031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6032. return
  6033. }
  6034. }
  6035. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6036. fmt.Println(timeStr)
  6037. timeArr := strings.Split(timeStr, " ")
  6038. fmt.Println(timeArr)
  6039. timeArrTwo := strings.Split(timeArr[0], "-")
  6040. timeArrThree := strings.Split(timeArr[1], ":")
  6041. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6042. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6043. if len(lists) == 0 {
  6044. var hisPatient models.XtHisPatient
  6045. hisPatient = models.XtHisPatient{
  6046. Name: name,
  6047. Age: age,
  6048. Gender: gender,
  6049. Birthday: birthUnix,
  6050. Phone: phone,
  6051. MedicalTreatmentType: medical_care,
  6052. IdType: certificates,
  6053. IdCardNo: id_card,
  6054. BalanceAccountsType: settlementValue,
  6055. SocialType: social_type,
  6056. MedicalInsuranceNumber: medical_insurance_card,
  6057. RegisterType: register_type,
  6058. RegisterCost: registration_fee,
  6059. TreatmentCost: medical_expenses,
  6060. AdminUserId: adminInfo.AdminUser.Id,
  6061. UserOrgId: adminInfo.CurrentOrgId,
  6062. Status: 1,
  6063. RecordDate: recordDateTime,
  6064. IsReturn: 1,
  6065. PatientId: patient.ID,
  6066. Ctime: time.Now().Unix(),
  6067. Mtime: time.Now().Unix(),
  6068. Number: str,
  6069. IdCardType: id_card_type,
  6070. Departments: department,
  6071. Doctor: doctor,
  6072. PType: reg_type,
  6073. Diagnosis: diagnosis_ids,
  6074. SickType: sick_type,
  6075. }
  6076. service.CreateHisPatient(&hisPatient)
  6077. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6078. c.ServeSuccessJSON(map[string]interface{}{
  6079. "his_info": hisPatient,
  6080. })
  6081. } else {
  6082. //chrgBchno := rand.Intn(1000000) + 10000
  6083. var hisPatient models.XtHisPatient
  6084. hisPatient = models.XtHisPatient{
  6085. Name: name,
  6086. Age: age,
  6087. Gender: gender,
  6088. Birthday: birthUnix,
  6089. Phone: phone,
  6090. MedicalTreatmentType: medical_care,
  6091. IdType: certificates,
  6092. IdCardNo: id_card,
  6093. BalanceAccountsType: settlementValue,
  6094. SocialType: social_type,
  6095. MedicalInsuranceNumber: medical_insurance_card,
  6096. RegisterType: register_type,
  6097. RegisterCost: registration_fee,
  6098. TreatmentCost: medical_expenses,
  6099. AdminUserId: adminInfo.AdminUser.Id,
  6100. UserOrgId: adminInfo.CurrentOrgId,
  6101. Status: 1,
  6102. RecordDate: recordDateTime,
  6103. IsReturn: 1,
  6104. PatientId: patient.ID,
  6105. Ctime: time.Now().Unix(),
  6106. Mtime: time.Now().Unix(),
  6107. Number: str,
  6108. IdCardType: id_card_type,
  6109. Departments: department,
  6110. Doctor: doctor,
  6111. PType: reg_type,
  6112. Diagnosis: diagnosis_ids,
  6113. SickType: sick_type,
  6114. }
  6115. service.CreateHisPatient(&hisPatient)
  6116. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6117. c.ServeSuccessJSON(map[string]interface{}{
  6118. "his_info": hisPatient,
  6119. })
  6120. }
  6121. }
  6122. // 上传明细----结算
  6123. func (c *HisApiController) GetUploadInfo() {
  6124. id, _ := c.GetInt64("id")
  6125. record_time := c.GetString("record_time")
  6126. his_patient_id, _ := c.GetInt64("his_patient_id")
  6127. oth_desc := c.GetString("oth_desc")
  6128. pay_way, _ := c.GetInt64("pay_way")
  6129. pay_ways := c.GetString("pay_ways")
  6130. pay_price, _ := c.GetFloat("pay_price")
  6131. pay_card_no := c.GetString("pay_card_no")
  6132. discount_price, _ := c.GetFloat("discount_price")
  6133. preferential_price, _ := c.GetFloat("preferential_price")
  6134. reality_price, _ := c.GetFloat("reality_price")
  6135. found_price, _ := c.GetFloat("found_price")
  6136. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6137. private_price, _ := c.GetFloat("private_price")
  6138. timeLayout := "2006-01-02"
  6139. loc, _ := time.LoadLocation("Local")
  6140. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6141. fapiao_code := c.GetString("fapiao_code")
  6142. fapiao_number := c.GetString("fapiao_number")
  6143. diagnosis_id := c.GetString("diagnosis")
  6144. sick_type, _ := c.GetInt64("sick_type")
  6145. reg_type, _ := c.GetInt64("p_type")
  6146. order_id, _ := c.GetInt64("order_id")
  6147. cash_pay := c.GetString("cash_pay")
  6148. wechat_pay := c.GetString("wechat_pay")
  6149. ali_pay := c.GetString("ali_pay")
  6150. jifen_pay := c.GetString("jifen_pay")
  6151. band_card_pay := c.GetString("band_card_pay")
  6152. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6153. tmp_decimal := c.GetString("tmp_decimal")
  6154. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6155. var decimal float64 //本次使用的押金
  6156. var errmsg error
  6157. tx := service.XTWriteDB().Begin() //开了事务
  6158. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6159. defer func() {
  6160. if errmsg != nil {
  6161. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6162. tx.Rollback()
  6163. } else {
  6164. tx.Commit()
  6165. }
  6166. }()
  6167. fmt.Println("dec_way", dec_way)
  6168. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6169. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6170. return
  6171. }
  6172. if len(tmp_decimal) > 0 {
  6173. if tmp_decimal[0] == 45 {
  6174. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6175. return
  6176. }
  6177. }
  6178. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6179. fmt.Println(errs)
  6180. decimal = tt
  6181. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6182. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6183. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6184. if err != nil {
  6185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6186. return
  6187. }
  6188. recordDateTime := theTime.Unix()
  6189. adminUser := c.GetAdminUserInfo()
  6190. var prescriptions []*models.HisPrescription
  6191. var prescriptionsOne []*models.HisPrescription
  6192. var start_time int64
  6193. var end_time int64
  6194. ids_str := c.GetString("ids")
  6195. ids_arr := strings.Split(ids_str, ",")
  6196. if tempOrder.ID == 0 {
  6197. if settle_accounts_type == 1 { //日结
  6198. fmt.Println(reg_type)
  6199. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6200. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6201. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6202. } else {
  6203. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6204. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6205. }
  6206. } else { //月结
  6207. start_time_str := c.GetString("start_time")
  6208. end_time_str := c.GetString("end_time")
  6209. timeLayout := "2006-01-02"
  6210. loc, _ := time.LoadLocation("Local")
  6211. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6212. if err != nil {
  6213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6214. return
  6215. }
  6216. recordStartTime := theStartTime.Unix()
  6217. start_time = recordStartTime
  6218. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6219. if err != nil {
  6220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6221. return
  6222. }
  6223. recordEndTime := theEndTime.Unix()
  6224. end_time = recordEndTime
  6225. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6226. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6227. }
  6228. var goods []*models.DialysisBeforePrepareGoods
  6229. var newGoods []*models.NewDialysisBeforePrepareGoods
  6230. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6231. var infos []*models.HisDoctorAdviceInfo
  6232. var infoList []*models.HisDoctorAdviceInfo
  6233. var hisAdvice []*models.HisDoctorAdviceInfo
  6234. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6235. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6236. //判断库存不足
  6237. //结算出库开关
  6238. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6239. if settConfig.IsOpen == 1 {
  6240. //判断库存的地方
  6241. for _, info := range prescriptions {
  6242. if info.Type == 1 {
  6243. infos = append(infos, info.HisDoctorAdviceInfo...)
  6244. }
  6245. if info.Type == 2 {
  6246. for _, sumItem := range info.HisPrescriptionProject {
  6247. if sumItem.Type == 3 {
  6248. var good models.DialysisBeforePrepareGoods
  6249. var newGood models.NewDialysisBeforePrepareGoods
  6250. good.GoodId = sumItem.GoodInfo.ID
  6251. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6252. count, _ := strconv.Atoi(sumItem.Count)
  6253. good.Count = int64(count)
  6254. good.StorehouseId = houseConfig.StorehouseOutInfo
  6255. good.ProjectId = sumItem.ID
  6256. goods = append(goods, &good)
  6257. newGood.GoodId = sumItem.GoodInfo.ID
  6258. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6259. count2, _ := strconv.Atoi(sumItem.Count)
  6260. newGood.Count = int64(count2)
  6261. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6262. newGood.ProjectId = sumItem.ID
  6263. newGoods = append(newGoods, &newGood)
  6264. }
  6265. }
  6266. }
  6267. }
  6268. for _, info := range prescriptionsOne {
  6269. if info.Type == 1 {
  6270. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6271. }
  6272. if info.Type == 2 {
  6273. for _, sumItem := range info.HisPrescriptionProject {
  6274. if sumItem.Type == 3 {
  6275. var newGood models.NewDialysisBeforePrepareGoods
  6276. newGood.GoodId = sumItem.GoodInfo.ID
  6277. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6278. count2, _ := strconv.Atoi(sumItem.Count)
  6279. newGood.Count = int64(count2)
  6280. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6281. newGood.ProjectId = sumItem.ID
  6282. newGoodOne = append(newGoodOne, &newGood)
  6283. }
  6284. }
  6285. }
  6286. }
  6287. //判断
  6288. for _, itemOne := range infos {
  6289. for _, itemTwo := range hisAdvice {
  6290. if itemOne.DrugId == itemTwo.DrugId {
  6291. itemTwo.Child = append(itemTwo.Child, itemOne)
  6292. }
  6293. }
  6294. }
  6295. for _, itemTwo := range hisAdvice {
  6296. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6297. var sum_out_count int64
  6298. for _, itemThree := range itemTwo.Child {
  6299. var prescribing_number int64
  6300. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6301. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6302. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6303. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6304. }
  6305. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6306. prescribing_number = parseIntPrescribingNumber
  6307. }
  6308. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6309. prescribing_number = parseIntPrescribingNumber
  6310. }
  6311. sum_out_count += prescribing_number
  6312. }
  6313. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6314. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6315. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6316. if sum_out_count > drugStockOut.FlushCount {
  6317. c.ServeSuccessJSON(map[string]interface{}{
  6318. "msg": "2",
  6319. "drug": medical,
  6320. })
  6321. return
  6322. }
  6323. }
  6324. fmt.Println("newGoods99999988882os", newGoods)
  6325. for _, itemOne := range newGoods {
  6326. for _, item := range newGoodOne {
  6327. if itemOne.GoodId == item.GoodId {
  6328. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6329. }
  6330. }
  6331. }
  6332. for _, item := range newGoodOne {
  6333. var sum_out_count_one int64
  6334. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6335. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6336. sum_out_count_one += itemOne.Count
  6337. }
  6338. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6339. fmt.Println("sum_out_count_one", sum_out_count_one)
  6340. fmt.Println("list.FlushCount", list.FlushCount)
  6341. if sum_out_count_one > list.FlushCount {
  6342. c.ServeSuccessJSON(map[string]interface{}{
  6343. "msg": "3",
  6344. "good": good,
  6345. })
  6346. return
  6347. }
  6348. }
  6349. }
  6350. timestamp := time.Now().Unix()
  6351. tempTime := time.Unix(timestamp, 0)
  6352. timeFormat := tempTime.Format("20060102150405")
  6353. chrgBchno := rand.Intn(100000) + 10000
  6354. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6355. strconv.FormatInt(his.PatientId, 10)
  6356. var ids []int64
  6357. for _, item := range prescriptions {
  6358. ids = append(ids, item.ID)
  6359. }
  6360. var total float64
  6361. for _, item := range prescriptions {
  6362. fmt.Println(item)
  6363. if item.Type == 1 { //药品
  6364. for _, subItem := range item.HisDoctorAdviceInfo {
  6365. total = total + (subItem.Price * subItem.PrescribingNumber)
  6366. }
  6367. }
  6368. if item.Type == 2 { //项目
  6369. for _, subItem := range item.HisPrescriptionProject {
  6370. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6371. total = total + (subItem.Price * cnt)
  6372. }
  6373. }
  6374. for _, subItem := range item.HisAdditionalCharge {
  6375. total = total + (subItem.Price * float64(subItem.Count))
  6376. }
  6377. }
  6378. if reg_type == 1111 || reg_type == 1112 {
  6379. reg_type = 11
  6380. }
  6381. tm := time.Unix(time.Now().Unix(), 0)
  6382. allTotal := fmt.Sprintf("%.4f", total)
  6383. totals, _ := strconv.ParseFloat(allTotal, 64)
  6384. order := &models.HisOrder{
  6385. UserOrgId: adminUser.CurrentOrgId,
  6386. HisPatientId: his.ID,
  6387. PatientId: id,
  6388. SettleAccountsDate: recordDateTime,
  6389. Ctime: time.Now().Unix(),
  6390. Mtime: time.Now().Unix(),
  6391. Status: 1,
  6392. OrderStatus: 2,
  6393. MdtrtId: his.Number,
  6394. Number: chrg_bchno,
  6395. MedfeeSumamt: totals,
  6396. PayWay: pay_way,
  6397. PayWays: pay_ways,
  6398. PayPrice: pay_price,
  6399. MedType: strconv.Itoa(int(reg_type)),
  6400. PayCardNo: pay_card_no,
  6401. DiscountPrice: discount_price,
  6402. PreferentialPrice: preferential_price,
  6403. RealityPrice: reality_price,
  6404. FoundPrice: found_price,
  6405. MedicalInsurancePrice: medical_insurance_price,
  6406. PrivatePrice: private_price,
  6407. SettleEndTime: end_time,
  6408. SettleStartTime: start_time,
  6409. PsnPartAmt: totals,
  6410. PsnCashPay: totals,
  6411. SettleType: settle_accounts_type,
  6412. FaPiaoCode: fapiao_code,
  6413. FaPiaoNumber: fapiao_number,
  6414. Diagnosis: diagnosis_id,
  6415. PType: 2,
  6416. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6417. Decimal: decimal,
  6418. OthDesc: oth_desc,
  6419. CashPay: cash_pay,
  6420. WechatPay: wechat_pay,
  6421. AliPay: ali_pay,
  6422. JifenPay: jifen_pay,
  6423. BandCardPay: band_card_pay,
  6424. }
  6425. err = service.CreateOrderTX(order, tx)
  6426. if err != nil {
  6427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6428. return
  6429. }
  6430. var customs []*Custom
  6431. for _, item := range prescriptions {
  6432. if item.Type == 1 { //药品a
  6433. for _, subItem := range item.HisDoctorAdviceInfo {
  6434. cus := &Custom{
  6435. AdviceId: subItem.ID,
  6436. ProjectId: 0,
  6437. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6438. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6439. FeedetlSn: subItem.FeedetlSn,
  6440. Price: fmt.Sprintf("%.4f", subItem.Price),
  6441. MedListCodg: subItem.MedListCodg,
  6442. Type: 1,
  6443. }
  6444. customs = append(customs, cus)
  6445. }
  6446. }
  6447. if item.Type == 2 { //项目
  6448. for _, subItem := range item.HisPrescriptionProject {
  6449. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6450. cus := &Custom{
  6451. AdviceId: 0,
  6452. ProjectId: subItem.ID,
  6453. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6454. Cut: fmt.Sprintf("%.4f", cnt),
  6455. FeedetlSn: subItem.FeedetlSn,
  6456. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6457. MedListCodg: subItem.MedListCodg,
  6458. Type: 2,
  6459. }
  6460. customs = append(customs, cus)
  6461. }
  6462. }
  6463. for _, item := range item.HisAdditionalCharge {
  6464. cus := &Custom{
  6465. ItemId: item.ID,
  6466. AdviceId: 0,
  6467. ProjectId: 0,
  6468. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6469. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6470. FeedetlSn: item.FeedetlSn,
  6471. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6472. MedListCodg: item.XtHisAddtionConfig.Code,
  6473. Type: 3,
  6474. }
  6475. customs = append(customs, cus)
  6476. }
  6477. }
  6478. for _, item := range customs {
  6479. var advice_id int64 = 0
  6480. var project_id int64 = 0
  6481. var item_id int64 = 0
  6482. var types int64 = 0
  6483. if item.Type == 1 {
  6484. advice_id = item.AdviceId
  6485. project_id = 0
  6486. item_id = 0
  6487. } else if item.Type == 2 {
  6488. advice_id = 0
  6489. item_id = 0
  6490. project_id = item.ProjectId
  6491. } else if item.Type == 3 {
  6492. advice_id = 0
  6493. item_id = item.ItemId
  6494. project_id = 0
  6495. }
  6496. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6497. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6498. pric, _ := strconv.ParseFloat(item.Price, 32)
  6499. info := &models.HisOrderInfo{
  6500. OrderNumber: order.Number,
  6501. UploadDate: time.Now().Unix(),
  6502. AdviceId: advice_id,
  6503. DetItemFeeSumamt: detItemFeeSumamt,
  6504. Cnt: cut,
  6505. Pric: pric,
  6506. PatientId: id,
  6507. Status: 1,
  6508. Mtime: time.Now().Unix(),
  6509. Ctime: time.Now().Unix(),
  6510. UserOrgId: adminUser.CurrentOrgId,
  6511. HisPatientId: his.ID,
  6512. OrderId: order.ID,
  6513. ProjectId: project_id,
  6514. Type: types,
  6515. ItemId: item_id,
  6516. }
  6517. service.CreateOrderInfoTX(info, tx)
  6518. }
  6519. his.Diagnosis = diagnosis_id
  6520. his.SickType = sick_type
  6521. his.RegisterType = reg_type
  6522. his.MedicalTreatmentType = reg_type
  6523. service.UpdataHisPateintTX(&his, tx)
  6524. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6525. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6526. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6527. //判断是否使用了押金
  6528. if dec_way == "true" {
  6529. tmpstring := strconv.FormatInt(order.ID, 10)
  6530. //扣押金
  6531. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6532. order.Decimal = decimal
  6533. service.UpDateOrderTwo(order, tx)
  6534. if errmsg != nil {
  6535. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6536. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6537. return
  6538. }
  6539. }
  6540. if err == nil {
  6541. for _, info := range prescriptions {
  6542. if info.Type == 1 {
  6543. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6544. }
  6545. if info.Type == 2 {
  6546. for _, sumItem := range info.HisPrescriptionProject {
  6547. if sumItem.Type == 3 {
  6548. var good models.DialysisBeforePrepareGoods
  6549. var newGood models.NewDialysisBeforePrepareGoods
  6550. var oldGood models.OldDialysisBeforePrepareGoods
  6551. good.GoodId = sumItem.GoodInfo.ID
  6552. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6553. count, _ := strconv.Atoi(sumItem.Count)
  6554. good.Count = int64(count)
  6555. good.StorehouseId = houseConfig.StorehouseOutInfo
  6556. good.ProjectId = sumItem.ID
  6557. good.PatientId = sumItem.PatientId
  6558. goods = append(goods, &good)
  6559. newGood.GoodId = sumItem.GoodInfo.ID
  6560. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6561. count2, _ := strconv.Atoi(sumItem.Count)
  6562. newGood.Count = int64(count2)
  6563. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6564. newGood.ProjectId = sumItem.ID
  6565. newGood.PatientId = sumItem.HisPatientId
  6566. newGoods = append(newGoods, &newGood)
  6567. oldGood.GoodId = sumItem.GoodInfo.ID
  6568. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6569. count3, _ := strconv.Atoi(sumItem.Count)
  6570. oldGood.Count = int64(count3)
  6571. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6572. oldGood.ProjectId = sumItem.ID
  6573. oldGood.RecordDate = sumItem.RecordDate
  6574. oldGood.PatientId = sumItem.HisPatientId
  6575. oldGoods = append(oldGoods, &oldGood)
  6576. }
  6577. }
  6578. }
  6579. }
  6580. if settConfig.IsOpen == 1 {
  6581. for _, item := range infoList {
  6582. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6583. if medical.IsUse == 2 {
  6584. //药品出库
  6585. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6586. //查询默认仓库
  6587. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6588. //查询默认仓库剩余多少库存
  6589. var sum_count int64
  6590. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6591. for _, its := range stockInfo {
  6592. if its.MaxUnit == medical.MaxUnit {
  6593. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6594. }
  6595. sum_count += its.StockMaxNumber + its.StockMinNumber
  6596. }
  6597. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6598. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6599. }
  6600. }
  6601. orgId := c.GetAdminUserInfo().CurrentOrgId
  6602. if len(oldGoods) > 0 {
  6603. timeStr := time.Now().Format("2006-01-02")
  6604. timeArr := strings.Split(timeStr, "-")
  6605. total, _ := service.FindAllWarehouseOut(orgId)
  6606. total = total + 1
  6607. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6608. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6609. number = number + total
  6610. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6611. operation_time := time.Now().Unix()
  6612. creater := c.GetAdminUserInfo().AdminUser.Id
  6613. //查询默认出库仓库库存
  6614. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6615. recordDateStr := time.Now().Format("2006-01-02")
  6616. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6617. nowtime := recordDate.Unix()
  6618. warehouseOut := models.WarehouseOut{
  6619. WarehouseOutOrderNumber: warehousing_out_order,
  6620. OperationTime: operation_time,
  6621. OrgId: orgId,
  6622. Creater: creater,
  6623. Ctime: time.Now().Unix(),
  6624. Status: 1,
  6625. WarehouseOutTime: nowtime,
  6626. Type: 1,
  6627. StorehouseId: storeConfig.StorehouseOutInfo,
  6628. IsCheck: 1,
  6629. OrderId: order.ID,
  6630. IsSys: 5,
  6631. }
  6632. //查询是否生成出库单
  6633. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6634. if out.ID == 0 {
  6635. service.AddSigleWarehouseOut(&warehouseOut)
  6636. }
  6637. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6638. for _, item := range oldGoods {
  6639. dialyPrepareOne := models.DialysisBeforePrepare{
  6640. GoodTypeId: item.GoodTypeId,
  6641. GoodId: item.GoodId,
  6642. PatientId: his.PatientId,
  6643. RecordDate: item.RecordDate,
  6644. UserOrgId: adminUser.CurrentOrgId,
  6645. Count: item.Count,
  6646. Ctime: time.Now().Unix(),
  6647. Creater: adminUser.AdminUser.Id,
  6648. CommdityCode: item.CommdityCode,
  6649. Status: 1,
  6650. StorehouseId: houseConfig.StorehouseOutInfo,
  6651. }
  6652. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6653. //非零用
  6654. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6655. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6656. //查询剩余库存
  6657. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6658. var sum_count int64
  6659. for _, item := range goodList {
  6660. sum_count += item.StockCount
  6661. }
  6662. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6663. //耗材
  6664. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6665. }
  6666. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6667. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6668. //查询剩余库存
  6669. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6670. var sum_count int64
  6671. for _, item := range goodList {
  6672. sum_count += item.StockCount
  6673. }
  6674. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6675. //耗材
  6676. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6677. }
  6678. }
  6679. }
  6680. }
  6681. c.ServeSuccessJSON(map[string]interface{}{
  6682. "msg": "结算成功",
  6683. })
  6684. }
  6685. }
  6686. }
  6687. // 退款
  6688. func (c *HisApiController) Refund() {
  6689. order_id, _ := c.GetInt64("order_id")
  6690. order, _ := service.GetHisOrderByID(order_id)
  6691. adminUser := c.GetAdminUserInfo()
  6692. orgid := c.GetAdminUserInfo().CurrentOrgId
  6693. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6694. if err != nil {
  6695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6696. return
  6697. }
  6698. tmp := strconv.FormatInt(order.ID, 10)
  6699. //当押金不为零时产生退费记录
  6700. if order.Decimal != 0 {
  6701. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6702. if err != nil {
  6703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6704. return
  6705. }
  6706. }
  6707. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6708. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6709. var goods []*models.DialysisBeforePrepareGoods
  6710. var newGoods []*models.NewDialysisBeforePrepareGoods
  6711. var infos []*models.HisDoctorAdviceInfo
  6712. for _, info := range orders {
  6713. if info.AdviceId > 0 && info.ProjectId == 0 {
  6714. infos = append(infos, &info.HisDoctorAdviceInfo)
  6715. }
  6716. if info.ProjectId > 0 && info.AdviceId == 0 {
  6717. if info.HisPrescriptionProject.Type == 3 {
  6718. var good models.DialysisBeforePrepareGoods
  6719. var newGood models.NewDialysisBeforePrepareGoods
  6720. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6721. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6722. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6723. good.Count = int64(count)
  6724. good.StorehouseId = houseConfig.StorehouseOutInfo
  6725. good.ProjectId = info.HisPrescriptionProject.ID
  6726. good.PatientId = info.PatientId
  6727. good.OrderId = order_id
  6728. goods = append(goods, &good)
  6729. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6730. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6731. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6732. newGood.Count = int64(count2)
  6733. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6734. newGood.ProjectId = info.HisPrescriptionProject.ID
  6735. newGood.RecordDate = order.SettleAccountsDate
  6736. newGood.UserOrgId = order.UserOrgId
  6737. newGood.PatientId = info.PatientId
  6738. newGood.OrderId = order_id
  6739. newGoods = append(newGoods, &newGood)
  6740. }
  6741. }
  6742. }
  6743. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6744. if settConfig.IsOpen == 1 {
  6745. for _, item := range infos {
  6746. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6747. }
  6748. for _, item := range newGoods {
  6749. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6750. }
  6751. }
  6752. c.ServeSuccessJSON(map[string]interface{}{
  6753. "msg": "退费成功",
  6754. })
  6755. }
  6756. func (c *HisApiController) RefundNumber() {
  6757. his_patient_id, _ := c.GetInt64("id")
  6758. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6759. info.Status = 0
  6760. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6761. if count > 0 {
  6762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6763. return
  6764. }
  6765. err := service.SaveHisPatient(info)
  6766. if err == nil {
  6767. c.ServeSuccessJSON(map[string]interface{}{
  6768. "msg": "退号成功",
  6769. })
  6770. } else {
  6771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6772. return
  6773. }
  6774. }
  6775. func (this *HisApiController) AdditionalCharge() {
  6776. dataBody := make(map[string]interface{}, 0)
  6777. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6778. fmt.Println(err)
  6779. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6780. patient_id := int64(dataBody["patient_id"].(float64))
  6781. medicineData, _ := dataBody["medicineData"].([]interface{})
  6782. adminUserInfo := this.GetAdminUserInfo()
  6783. orgId := adminUserInfo.CurrentOrgId
  6784. admin_user_id := adminUserInfo.AdminUser.Id
  6785. timeStr := time.Now().Format("2006-01-02")
  6786. timeLayout := "2006-01-02 15:04:05"
  6787. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6788. timenow := timeStringToTime.Unix()
  6789. var additionalCharges []*models.HisAdditionalCharge
  6790. for _, item := range medicineData {
  6791. var randNum int
  6792. randNum = rand.Intn(10000) + 1000
  6793. timestamp := time.Now().Unix()
  6794. tempTime := time.Unix(timestamp, 0)
  6795. timeFormat := tempTime.Format("20060102150405")
  6796. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6797. items := item.(map[string]interface{})
  6798. money := items["price"].(string)
  6799. item_id_str := items["item_id"].(string)
  6800. name := items["name"].(string)
  6801. id_str := items["id"].(string)
  6802. moneys, _ := strconv.ParseInt(money, 10, 64)
  6803. monStr := strconv.FormatInt(moneys, 10)
  6804. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6805. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6806. id, _ := strconv.ParseInt(id_str, 10, 64)
  6807. additionalCharge := &models.HisAdditionalCharge{
  6808. ID: id,
  6809. HisPatientId: his_patient_id,
  6810. UserOrgId: orgId,
  6811. PatientId: patient_id,
  6812. RecordDate: timenow,
  6813. Price: monneyStr,
  6814. Status: 1,
  6815. ItemName: name,
  6816. ItemId: item_id,
  6817. AdminUserId: admin_user_id,
  6818. CreatedTime: time.Now().Unix(),
  6819. OrderStatus: 0,
  6820. PrescriptionNumber: "",
  6821. BatchNumber: "",
  6822. FeedetlSn: p_number,
  6823. }
  6824. service.CreateAdditionalCharge(additionalCharge)
  6825. additionalCharges = append(additionalCharges, additionalCharge)
  6826. }
  6827. this.ServeSuccessJSON(map[string]interface{}{
  6828. "msg": "添加成功",
  6829. "additional_charges": additionalCharges,
  6830. })
  6831. }
  6832. func (this *HisApiController) DeleteAddition() {
  6833. id, _ := this.GetInt64("id")
  6834. //TODO 需要判断是否已经结算
  6835. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6836. if err == nil {
  6837. this.ServeSuccessJSON(map[string]interface{}{
  6838. "msg": "删除成功",
  6839. })
  6840. return
  6841. } else {
  6842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6843. return
  6844. }
  6845. }
  6846. func (this *HisApiController) GetAdminUsers() {
  6847. adminUser := this.GetAdminUserInfo()
  6848. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6849. this.ServeSuccessJSON(map[string]interface{}{
  6850. "doctors": doctors,
  6851. })
  6852. }
  6853. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6854. change_type, _ := this.GetInt64("type", 0)
  6855. record_date := this.GetString("record_time")
  6856. patient_id, _ := this.GetInt64("patient_id", 0)
  6857. p_type, _ := this.GetInt64("p_type", 0)
  6858. timeLayout := "2006-01-02"
  6859. loc, _ := time.LoadLocation("Local")
  6860. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6861. record_time := theAdviceRecordTime.Unix()
  6862. adminUserInfo := this.GetAdminUserInfo()
  6863. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6864. if err == nil {
  6865. if len(prescriptions) == 0 {
  6866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6867. return
  6868. } else {
  6869. this.ServeSuccessJSON(map[string]interface{}{
  6870. "prescriptions": prescriptions,
  6871. })
  6872. return
  6873. }
  6874. } else {
  6875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6876. return
  6877. }
  6878. }
  6879. func (this *HisApiController) GetCallHisPrescription() {
  6880. patient_id, _ := this.GetInt64("patient_id", 0)
  6881. timeLayout := "2006-01-02"
  6882. loc, _ := time.LoadLocation("Local")
  6883. start_time := this.GetString("start_time")
  6884. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6885. end_time := this.GetString("end_time")
  6886. p_type, _ := this.GetInt64("p_type")
  6887. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6888. adminUserInfo := this.GetAdminUserInfo()
  6889. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6890. if err == nil {
  6891. this.ServeSuccessJSON(map[string]interface{}{
  6892. "prescriptions": prescriptions,
  6893. })
  6894. return
  6895. } else {
  6896. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6897. return
  6898. }
  6899. }
  6900. func (this *HisApiController) GetHisDayPrescription() {
  6901. timeLayout := "2006-01-02"
  6902. loc, _ := time.LoadLocation("Local")
  6903. start_time := this.GetString("start_time")
  6904. patient_id, _ := this.GetInt64("patient_id", 0)
  6905. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6906. end_time := this.GetString("end_time")
  6907. p_type, _ := this.GetInt64("p_type")
  6908. order_status, _ := this.GetInt64("type")
  6909. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6910. adminUserInfo := this.GetAdminUserInfo()
  6911. var dayHisPrescription []*models.HisPrescription
  6912. var err error
  6913. if order_status == 1 || order_status == 0 {
  6914. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6915. } else if order_status == 2 {
  6916. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6917. }
  6918. var settle_total float64
  6919. for _, item := range dayHisPrescription {
  6920. if len(item.HisPrescriptionProject) > 0 {
  6921. for _, subItem := range item.HisPrescriptionProject {
  6922. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6923. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6924. settle_total = settle_total + total
  6925. }
  6926. }
  6927. if len(item.HisDoctorAdviceInfo) > 0 {
  6928. for _, subItem := range item.HisDoctorAdviceInfo {
  6929. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6930. settle_total = settle_total + total
  6931. }
  6932. }
  6933. }
  6934. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6935. if err == nil {
  6936. this.ServeSuccessJSON(map[string]interface{}{
  6937. "day_prescription": dayHisPrescription,
  6938. "settle_total": settle_total,
  6939. })
  6940. return
  6941. } else {
  6942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6943. return
  6944. }
  6945. }
  6946. func (c *HisApiController) GetHisChargePatientList() {
  6947. record_date := c.GetString("record_date")
  6948. order_status, _ := c.GetInt64("type")
  6949. sch_type, _ := c.GetInt64("sch_type")
  6950. timeLayout := "2006-01-02"
  6951. loc, _ := time.LoadLocation("Local")
  6952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6953. if err != nil {
  6954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6955. return
  6956. }
  6957. recordDateTime := theTime.Unix()
  6958. adminInfo := c.GetAdminUserInfo()
  6959. var tempPatients []*service.NewTempPatients
  6960. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6961. if order_status != 2 {
  6962. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6963. } else {
  6964. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6965. }
  6966. var patients []*service.NewTempPatients
  6967. var patients_two []*service.NewTempPatients
  6968. for _, item := range tempPatients {
  6969. //过滤掉没挂号的和没开处方的
  6970. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6971. patients = append(patients, item)
  6972. }
  6973. //过滤掉没挂号的
  6974. if len(item.HisPatient) > 0 {
  6975. patients_two = append(patients_two, item)
  6976. }
  6977. }
  6978. c.ServeSuccessJSON(map[string]interface{}{
  6979. "list": patients,
  6980. "list_two": patients_two,
  6981. })
  6982. }
  6983. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6984. record_date := c.GetString("record_date")
  6985. timeLayout := "2006-01-02"
  6986. loc, _ := time.LoadLocation("Local")
  6987. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6988. if err != nil {
  6989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6990. return
  6991. }
  6992. recordDateTime := theTime.Unix()
  6993. adminUser := c.GetAdminUserInfo()
  6994. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6995. var patients []*service.Patients
  6996. for _, item := range tempPatients {
  6997. if item.HisPatient.ID == 0 {
  6998. patients = append(patients, item)
  6999. }
  7000. }
  7001. c.ServeSuccessJSON(map[string]interface{}{
  7002. "list": patients,
  7003. //"list_two": patients_two,
  7004. })
  7005. }
  7006. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7007. newArr = make([]*service.Patients, 0)
  7008. for i := 0; i < len(patient); i++ {
  7009. repeat := false
  7010. for j := i + 1; j < len(patient); j++ {
  7011. if patient[i].ID == patient[j].ID {
  7012. repeat = true
  7013. break
  7014. }
  7015. }
  7016. if !repeat {
  7017. newArr = append(newArr, patient[i])
  7018. }
  7019. }
  7020. return
  7021. }
  7022. func (c *HisApiController) GetHisChargePatientInfo() {
  7023. patient_id, _ := c.GetInt64("patient_id")
  7024. his_patient_id, _ := c.GetInt64("his_patient_id")
  7025. record_date := c.GetString("record_date")
  7026. //start_time := c.GetString("start_time")
  7027. //end_time := c.GetString("end_time")
  7028. order_status, _ := c.GetInt64("type", 0)
  7029. p_type, _ := c.GetInt64("p_type", 0)
  7030. order_id, _ := c.GetInt64("order_id", 0)
  7031. timeLayout := "2006-01-02"
  7032. loc, _ := time.LoadLocation("Local")
  7033. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7034. if err != nil {
  7035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7036. return
  7037. }
  7038. recordDateTime := theTime.Unix()
  7039. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7040. //if err != nil {
  7041. //
  7042. //}
  7043. //startRecordDateTime := startTime.Unix()
  7044. //
  7045. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7046. //if err != nil {
  7047. //
  7048. //}
  7049. //endRecordDateTime := endTime.Unix()
  7050. admin := c.GetAdminUserInfo()
  7051. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7052. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7053. var prescriptions []*models.HisPrescription
  7054. //var unChargeMonthPrescriptions []*models.HisPrescription
  7055. order, _ := service.GetHisOrderByID(order_id)
  7056. if order_status == 1 || order_status == 0 {
  7057. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7058. } else if order_status == 2 {
  7059. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7060. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7061. }
  7062. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7063. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7064. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7065. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7066. //获取所有科室信息
  7067. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7068. c.ServeSuccessJSON(map[string]interface{}{
  7069. "his_info": his_patient_info,
  7070. "xt_info": xt_patient_info,
  7071. "prescription": prescriptions,
  7072. "case_history": case_history,
  7073. "info": patientPrescriptionInfo,
  7074. "last_info": lastPatientPrescriptionInfo,
  7075. "order": order,
  7076. "doctors": doctors,
  7077. "department": department,
  7078. })
  7079. return
  7080. }
  7081. func (c *HisApiController) GetAllOrderDetail() {
  7082. order_id, _ := c.GetInt64("id", 0)
  7083. order, _ := service.GetHisOrderByID(order_id)
  7084. if order.ID == 0 {
  7085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7086. return
  7087. }
  7088. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7089. org_id := c.GetAdminUserInfo().CurrentOrgId
  7090. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7091. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7092. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7093. c.ServeSuccessJSON(map[string]interface{}{
  7094. "order": order,
  7095. "order_info": order_info,
  7096. "patient": patient,
  7097. "admin_info": adminInfo,
  7098. "hospital_record": record,
  7099. })
  7100. return
  7101. }
  7102. func (c *HisApiController) GetAllOrderDetailCollect() {
  7103. order_id, _ := c.GetInt64("id", 0)
  7104. order, _ := service.GetHisOrderByID(order_id)
  7105. if order.ID == 0 {
  7106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7107. return
  7108. }
  7109. org_id := c.GetAdminUserInfo().CurrentOrgId
  7110. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7111. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7112. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7113. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7114. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7115. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7116. var bedCostTotal float64 = 0 //床位总费
  7117. //var bedCostSelfTotal float64 = 0 //床位自费
  7118. var operationCostTotal float64 = 0 //手术费
  7119. //var operationCostSelfTotal float64 = 0 //手术费
  7120. var otherCostTotal float64 = 0 //其他费用
  7121. //var otherCostSelfTotal float64 = 0 //其他费用
  7122. var materialCostTotal float64 = 0 //材料费
  7123. //var materialCostSelfTotal float64 = 0 //材料费
  7124. var westernMedicineCostTotal float64 = 0 //西药费
  7125. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7126. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7127. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7128. var checkCostTotal float64 = 0 //检查费
  7129. //var checkCostSelfTotal float64 = 0 //检查费
  7130. var laboratoryCostTotal float64 = 0 //化验费
  7131. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7132. var treatCostTotal float64 = 0 //治疗费用
  7133. //var treatCostSelfTotal float64 = 0 //治疗费用
  7134. var zhenChaCostTotal float64 = 0 //其他费用
  7135. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7136. decimal.DivisionPrecision = 2
  7137. var BalanceAccountsType int64
  7138. if his.ID > 0 {
  7139. BalanceAccountsType = his.BalanceAccountsType
  7140. } else {
  7141. BalanceAccountsType = record.BalanceAccountsType
  7142. }
  7143. if BalanceAccountsType != 2 {
  7144. for _, item := range order_info {
  7145. if org_id == 10215 {
  7146. if item.MedChrgitmType == "01" { //床位费
  7147. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7148. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7149. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7150. }
  7151. if item.MedChrgitmType == "02" { //诊察费
  7152. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7153. //zhenChaCostSelfTotal = zhenChaCostTotal
  7154. }
  7155. if item.MedChrgitmType == "03" { //检查费
  7156. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7157. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7158. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7159. }
  7160. //if item.MedChrgitmType == "02" { //检查费
  7161. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7162. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7163. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7164. //}
  7165. if item.MedChrgitmType == "04" { //化验费
  7166. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7167. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7168. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7169. }
  7170. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7171. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7172. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7173. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7174. }
  7175. if item.MedChrgitmType == "06" { //手术费
  7176. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7177. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7178. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7179. }
  7180. if item.MedChrgitmType == "08" { //材料费
  7181. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7182. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7183. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7184. }
  7185. if item.MedChrgitmType == "09" { //西药费
  7186. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7187. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7188. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7189. }
  7190. if item.MedChrgitmType == "11" { //中成费
  7191. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7192. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7193. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7194. }
  7195. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7196. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7197. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7198. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7199. }
  7200. } else if org_id == 10188 || org_id == 10217 {
  7201. if item.MedChrgitmType == "01" { //床位费
  7202. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7203. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7204. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7205. }
  7206. if item.MedChrgitmType == "02" { //诊察费
  7207. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7208. //zhenChaCostSelfTotal = zhenChaCostTotal
  7209. }
  7210. if item.MedChrgitmType == "03" { //检查费
  7211. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7212. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7213. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7214. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7215. }
  7216. //if item.MedChrgitmType == "02" { //检查费
  7217. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7218. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7219. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7220. //}
  7221. if item.MedChrgitmType == "04" { //化验费
  7222. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7223. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7224. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7225. }
  7226. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7227. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7228. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7229. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7230. }
  7231. if item.MedChrgitmType == "06" { //手术费
  7232. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7233. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7234. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7235. }
  7236. if item.MedChrgitmType == "08" { //材料费
  7237. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7238. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7239. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7240. }
  7241. if item.MedChrgitmType == "09" { //西药费
  7242. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7243. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7244. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7245. }
  7246. if item.MedChrgitmType == "11" { //中成费
  7247. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7248. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7249. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7250. }
  7251. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7252. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7253. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7254. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7255. }
  7256. } else {
  7257. if item.MedChrgitmType == "01" { //床位费
  7258. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7259. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7260. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7261. }
  7262. //if item.MedChrgitmType == "02" { //诊察费
  7263. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7264. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7265. //}
  7266. if item.MedChrgitmType == "03" { //检查费
  7267. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7268. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7269. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7270. }
  7271. //if item.MedChrgitmType == "02" { //检查费
  7272. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7273. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7274. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7275. //}
  7276. if item.MedChrgitmType == "04" { //化验费
  7277. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7278. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7279. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7280. }
  7281. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7282. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7283. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7284. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7285. }
  7286. if item.MedChrgitmType == "06" { //手术费
  7287. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7288. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7289. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7290. }
  7291. if item.MedChrgitmType == "08" { //材料费
  7292. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7293. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7294. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7295. }
  7296. if item.MedChrgitmType == "09" { //西药费
  7297. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7298. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7299. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7300. }
  7301. if item.MedChrgitmType == "11" { //中成费
  7302. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7303. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7304. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7305. }
  7306. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7307. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7308. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7309. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7310. }
  7311. }
  7312. }
  7313. c.ServeSuccessJSON(map[string]interface{}{
  7314. "order": order,
  7315. "order_info": order_info,
  7316. "patient": patient,
  7317. "admin_info": adminInfo,
  7318. "his_hospital": record,
  7319. "bedCostTotal": bedCostTotal,
  7320. "operationCostTotal": operationCostTotal,
  7321. "otherCostTotal": otherCostTotal,
  7322. "materialCostTotal": materialCostTotal,
  7323. "westernMedicineCostTotal": westernMedicineCostTotal,
  7324. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7325. "checkCostTotal": checkCostTotal,
  7326. "zhenChaCostTotal": zhenChaCostTotal,
  7327. "laboratoryCostTotal": laboratoryCostTotal,
  7328. "treatCostTotal": treatCostTotal,
  7329. })
  7330. } else {
  7331. for _, item := range order_info {
  7332. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7333. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7334. item.MedChrgitmType = "09"
  7335. }
  7336. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7337. if item.HisPrescriptionProject.Type == 2 {
  7338. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7339. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7340. case 0:
  7341. item.MedChrgitmType = "0"
  7342. break
  7343. case 1:
  7344. item.MedChrgitmType = "14"
  7345. break
  7346. case 2:
  7347. item.MedChrgitmType = "05"
  7348. break
  7349. case 3:
  7350. item.MedChrgitmType = "03"
  7351. break
  7352. case 4:
  7353. item.MedChrgitmType = "03"
  7354. break
  7355. case 5:
  7356. item.MedChrgitmType = "08"
  7357. break
  7358. case 6:
  7359. item.MedChrgitmType = "14"
  7360. break
  7361. case 7:
  7362. item.MedChrgitmType = "14"
  7363. break
  7364. case 8:
  7365. item.MedChrgitmType = "03"
  7366. break
  7367. case 9:
  7368. item.MedChrgitmType = "14"
  7369. break
  7370. case 10:
  7371. item.MedChrgitmType = "14"
  7372. break
  7373. case 11:
  7374. item.MedChrgitmType = "06"
  7375. break
  7376. case 12:
  7377. item.MedChrgitmType = "12"
  7378. break
  7379. case 13:
  7380. item.MedChrgitmType = "01"
  7381. break
  7382. case 14:
  7383. item.MedChrgitmType = "04"
  7384. break
  7385. case 15:
  7386. item.MedChrgitmType = "14"
  7387. break
  7388. }
  7389. } else {
  7390. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7391. case 1:
  7392. item.MedChrgitmType = "14"
  7393. break
  7394. case 2:
  7395. item.MedChrgitmType = "05"
  7396. break
  7397. case 3:
  7398. item.MedChrgitmType = "04"
  7399. break
  7400. case 4:
  7401. item.MedChrgitmType = "14"
  7402. break
  7403. case 5:
  7404. item.MedChrgitmType = "08"
  7405. break
  7406. case 6:
  7407. item.MedChrgitmType = "14"
  7408. break
  7409. case 7:
  7410. item.MedChrgitmType = "14"
  7411. break
  7412. case 8:
  7413. item.MedChrgitmType = "03"
  7414. break
  7415. case 9:
  7416. item.MedChrgitmType = "14"
  7417. break
  7418. }
  7419. }
  7420. } else if item.HisPrescriptionProject.Type == 3 {
  7421. item.MedChrgitmType = "08"
  7422. }
  7423. }
  7424. }
  7425. for _, item := range order_info {
  7426. if org_id == 10215 {
  7427. if item.MedChrgitmType == "01" { //床位费
  7428. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7429. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7430. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7431. }
  7432. if item.MedChrgitmType == "02" { //诊察费
  7433. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7434. //zhenChaCostSelfTotal = zhenChaCostTotal
  7435. }
  7436. if item.MedChrgitmType == "03" { //检查费
  7437. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7438. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7439. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7440. }
  7441. //if item.MedChrgitmType == "02" { //检查费
  7442. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7443. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7444. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7445. //}
  7446. if item.MedChrgitmType == "04" { //化验费
  7447. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7448. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7449. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7450. }
  7451. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7452. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7453. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7454. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7455. }
  7456. if item.MedChrgitmType == "06" { //手术费
  7457. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7458. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7459. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7460. }
  7461. if item.MedChrgitmType == "08" { //材料费
  7462. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7463. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7464. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7465. }
  7466. if item.MedChrgitmType == "09" { //西药费
  7467. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7468. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7469. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7470. }
  7471. if item.MedChrgitmType == "11" { //中成费
  7472. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7473. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7474. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7475. }
  7476. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7477. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7478. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7479. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7480. }
  7481. } else {
  7482. if item.MedChrgitmType == "01" { //床位费
  7483. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7484. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7485. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7486. }
  7487. //if item.MedChrgitmType == "02" { //诊察费
  7488. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7489. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7490. //}
  7491. if item.MedChrgitmType == "03" { //检查费
  7492. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7493. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7494. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7495. }
  7496. //if item.MedChrgitmType == "02" { //检查费
  7497. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7498. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7499. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7500. //}
  7501. if item.MedChrgitmType == "04" { //化验费
  7502. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7503. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7504. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7505. }
  7506. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7507. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7508. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7509. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7510. }
  7511. if item.MedChrgitmType == "06" { //手术费
  7512. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7513. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7514. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7515. }
  7516. if item.MedChrgitmType == "08" { //材料费
  7517. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7518. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7519. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7520. }
  7521. if item.MedChrgitmType == "09" { //西药费
  7522. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7523. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7524. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7525. }
  7526. if item.MedChrgitmType == "11" { //中成费
  7527. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7528. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7529. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7530. }
  7531. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7532. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7533. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7534. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7535. }
  7536. }
  7537. }
  7538. c.ServeSuccessJSON(map[string]interface{}{
  7539. "order": order,
  7540. "order_info": order_info,
  7541. "patient": patient,
  7542. "admin_info": adminInfo,
  7543. "his_hospital": record,
  7544. "bedCostTotal": bedCostTotal,
  7545. "operationCostTotal": operationCostTotal,
  7546. "otherCostTotal": otherCostTotal,
  7547. "materialCostTotal": materialCostTotal,
  7548. "westernMedicineCostTotal": westernMedicineCostTotal,
  7549. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7550. "checkCostTotal": checkCostTotal,
  7551. "zhenChaCostTotal": zhenChaCostTotal,
  7552. "laboratoryCostTotal": laboratoryCostTotal,
  7553. "treatCostTotal": treatCostTotal,
  7554. })
  7555. }
  7556. }
  7557. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7558. page, _ := c.GetInt64("page")
  7559. limit, _ := c.GetInt64("limit")
  7560. keywords := c.GetString("keywords")
  7561. start_time := c.GetString("start_time")
  7562. end_time := c.GetString("end_time")
  7563. //clr_type := c.GetString("clr_type")
  7564. insutype := c.GetString("insutype")
  7565. timeLayout := "2006-01-02"
  7566. loc, _ := time.LoadLocation("Local")
  7567. var theStartTIme int64
  7568. if len(start_time) > 0 {
  7569. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7570. theStartTIme = theTime.Unix()
  7571. }
  7572. var theEndtTIme int64
  7573. if len(end_time) > 0 {
  7574. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7575. theEndtTIme = theTime.Unix()
  7576. }
  7577. if page <= 0 {
  7578. page = 1
  7579. }
  7580. if limit <= 0 {
  7581. limit = 10
  7582. }
  7583. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7584. c.ServeSuccessJSON(map[string]interface{}{
  7585. "total": total,
  7586. "list": list,
  7587. })
  7588. return
  7589. }
  7590. func (c *HisApiController) GetPutOnRecordList() {
  7591. page, _ := c.GetInt64("page")
  7592. limit, _ := c.GetInt64("limit")
  7593. keywords := c.GetString("keywords")
  7594. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7595. if page <= 0 {
  7596. page = 1
  7597. }
  7598. if limit <= 0 {
  7599. limit = 10
  7600. }
  7601. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7602. c.ServeSuccessJSON(map[string]interface{}{
  7603. "total": total,
  7604. "list": list,
  7605. })
  7606. return
  7607. }
  7608. func (c *HisApiController) GetCompareData() {
  7609. start_time := c.GetString("start_time")
  7610. end_time := c.GetString("end_time")
  7611. insutype := c.GetString("insutype")
  7612. clr_type := c.GetString("clr_type")
  7613. timeLayout := "2006-01-02"
  7614. loc, _ := time.LoadLocation("Local")
  7615. var theStartTIme int64
  7616. if len(start_time) > 0 {
  7617. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7618. if err != nil {
  7619. theStartTIme = 0
  7620. }
  7621. theStartTIme = theTime.Unix()
  7622. }
  7623. var theEndtTIme int64
  7624. if len(end_time) > 0 {
  7625. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7626. if err != nil {
  7627. theEndtTIme = 0
  7628. }
  7629. theEndtTIme = theTime.Unix()
  7630. }
  7631. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7632. fmt.Println(err)
  7633. if err == nil {
  7634. c.ServeSuccessJSON(map[string]interface{}{
  7635. "list": formData,
  7636. })
  7637. } else {
  7638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7639. return
  7640. }
  7641. }
  7642. func (c *HisApiController) GetFaPiaoData() {
  7643. order_id, _ := c.GetInt64("order_id")
  7644. patient_id, _ := c.GetInt64("patient_id")
  7645. //number := c.GetString("number")
  7646. adminUser := c.GetAdminUserInfo()
  7647. order, _ := service.GetHisOrderByID(order_id)
  7648. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7649. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7650. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7651. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7652. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7653. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7654. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7655. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7656. var bedCostTotal float64 = 0 //床位总费
  7657. var bedCostSelfTotal float64 = 0 //床位自费
  7658. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7659. var operationCostTotal float64 = 0 //手术费
  7660. var operationCostSelfTotal float64 = 0 //手术费
  7661. var operationCostPartSelfTotal float64 = 0 //手术费
  7662. var otherCostTotal float64 = 0 //其他费用
  7663. var otherCostSelfTotal float64 = 0 //其他费用
  7664. var otherCostPartSelfTotal float64 = 0 //其他费用
  7665. var materialCostTotal float64 = 0 //材料费
  7666. var materialCostSelfTotal float64 = 0 //材料费
  7667. var materialCostPartSelfTotal float64 = 0 //材料费
  7668. var westernMedicineCostTotal float64 = 0 //西药费
  7669. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7670. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7671. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7672. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7673. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7674. var checkCostTotal float64 = 0 //检查费
  7675. var checkCostSelfTotal float64 = 0 //检查费
  7676. var checkCostPartSelfTotal float64 = 0 //检查费
  7677. var hiliCostTotal float64 = 0 //护理费
  7678. var hiliCostSelfTotal float64 = 0 //护理费
  7679. var hiliCostPartSelfTotal float64 = 0 //护理费
  7680. var laboratoryCostTotal float64 = 0 //化验费
  7681. var laboratoryCostSelfTotal float64 = 0 //化验费
  7682. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7683. var treatCostTotal float64 = 0 //治疗费用
  7684. var treatCostSelfTotal float64 = 0 //治疗费用
  7685. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7686. var zhenChaCostTotal float64 = 0 //其他费用
  7687. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7688. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7689. decimal.DivisionPrecision = 2
  7690. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7691. var balanceAccountsType int64
  7692. if his.ID > 0 {
  7693. balanceAccountsType = his.BalanceAccountsType
  7694. } else {
  7695. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7696. }
  7697. if balanceAccountsType == 2 {
  7698. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7699. for _, item := range orderInfos_two {
  7700. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7701. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7702. item.MedChrgitmType = "09"
  7703. }
  7704. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7705. if item.HisPrescriptionProject.Type == 2 {
  7706. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7707. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7708. case 0:
  7709. item.MedChrgitmType = "0"
  7710. break
  7711. case 1:
  7712. item.MedChrgitmType = "14"
  7713. break
  7714. case 2:
  7715. item.MedChrgitmType = "05"
  7716. break
  7717. case 3:
  7718. item.MedChrgitmType = "03"
  7719. break
  7720. case 4:
  7721. item.MedChrgitmType = "03"
  7722. break
  7723. case 5:
  7724. item.MedChrgitmType = "08"
  7725. break
  7726. case 6:
  7727. item.MedChrgitmType = "14"
  7728. break
  7729. case 7:
  7730. item.MedChrgitmType = "14"
  7731. break
  7732. case 8:
  7733. item.MedChrgitmType = "03"
  7734. break
  7735. case 9:
  7736. item.MedChrgitmType = "14"
  7737. break
  7738. case 10:
  7739. item.MedChrgitmType = "14"
  7740. break
  7741. case 11:
  7742. item.MedChrgitmType = "06"
  7743. break
  7744. case 12:
  7745. item.MedChrgitmType = "12"
  7746. break
  7747. case 13:
  7748. item.MedChrgitmType = "01"
  7749. break
  7750. case 14:
  7751. item.MedChrgitmType = "04"
  7752. break
  7753. case 15:
  7754. item.MedChrgitmType = "02"
  7755. break
  7756. }
  7757. } else {
  7758. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7759. case 1:
  7760. item.MedChrgitmType = "14"
  7761. break
  7762. case 2:
  7763. item.MedChrgitmType = "05"
  7764. break
  7765. case 3:
  7766. item.MedChrgitmType = "03"
  7767. break
  7768. case 4:
  7769. item.MedChrgitmType = "03"
  7770. break
  7771. case 5:
  7772. item.MedChrgitmType = "08"
  7773. break
  7774. case 6:
  7775. item.MedChrgitmType = "14"
  7776. break
  7777. case 7:
  7778. item.MedChrgitmType = "14"
  7779. break
  7780. case 8:
  7781. item.MedChrgitmType = "03"
  7782. break
  7783. case 9:
  7784. item.MedChrgitmType = "14"
  7785. break
  7786. }
  7787. }
  7788. } else if item.HisPrescriptionProject.Type == 3 {
  7789. item.MedChrgitmType = "08"
  7790. }
  7791. }
  7792. }
  7793. for _, item := range orderInfos_two {
  7794. fmt.Println(item.MedChrgitmType)
  7795. if item.MedChrgitmType == "07" { //床位费
  7796. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7797. hiliCostSelfTotal = hiliCostTotal
  7798. }
  7799. if item.MedChrgitmType == "01" { //床位费
  7800. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7801. bedCostSelfTotal = bedCostTotal
  7802. }
  7803. if item.MedChrgitmType == "02" { //诊察费
  7804. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7805. zhenChaCostSelfTotal = zhenChaCostTotal
  7806. }
  7807. if item.MedChrgitmType == "03" { //检查费
  7808. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7809. checkCostSelfTotal = checkCostTotal
  7810. }
  7811. if item.MedChrgitmType == "04" { //化验费
  7812. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7813. laboratoryCostSelfTotal = laboratoryCostTotal
  7814. }
  7815. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7816. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7817. treatCostSelfTotal = treatCostTotal
  7818. }
  7819. if item.MedChrgitmType == "06" { //手术费
  7820. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7821. operationCostSelfTotal = treatCostTotal
  7822. }
  7823. if item.MedChrgitmType == "08" { //材料费
  7824. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7825. materialCostSelfTotal = materialCostTotal
  7826. }
  7827. if item.MedChrgitmType == "09" { //西药费
  7828. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7829. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7830. }
  7831. if item.MedChrgitmType == "11" { //中成费
  7832. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7833. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7834. }
  7835. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7836. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7837. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7838. otherCostSelfTotal = otherCostTotal
  7839. }
  7840. } else {
  7841. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7842. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7843. otherCostSelfTotal = otherCostTotal
  7844. }
  7845. }
  7846. }
  7847. } else {
  7848. for _, item := range orderInfos {
  7849. if item.MedChrgitmType == "01" { //床位费
  7850. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7851. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7852. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7853. }
  7854. if item.MedChrgitmType == "02" { //诊察费
  7855. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7856. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7857. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7858. }
  7859. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7860. if item.MedChrgitmType == "03" { //检查费
  7861. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7862. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7863. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7864. }
  7865. } else {
  7866. if item.MedChrgitmType == "03" { //检查费
  7867. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7868. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7869. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7870. }
  7871. }
  7872. if item.MedChrgitmType == "04" { //化验费
  7873. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7874. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7875. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7876. }
  7877. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7878. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7879. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7880. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7881. }
  7882. if item.MedChrgitmType == "06" { //手术费
  7883. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7884. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7885. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7886. }
  7887. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7888. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7889. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7890. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7891. }
  7892. if item.MedChrgitmType == "07" { //西药费
  7893. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7894. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7895. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7896. }
  7897. if item.MedChrgitmType == "09" { //西药费
  7898. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7899. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7900. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7901. }
  7902. if item.MedChrgitmType == "11" { //中成费
  7903. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7904. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7905. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7906. }
  7907. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7908. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7909. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7910. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7911. }
  7912. }
  7913. }
  7914. timeLayout := "2006-01-02"
  7915. loc, _ := time.LoadLocation("Local")
  7916. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7917. if err != nil {
  7918. }
  7919. startRecordDateTime := startTime.Unix()
  7920. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7921. if err != nil {
  7922. }
  7923. endRecordDateTime := endTime.Unix()
  7924. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7925. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7926. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7927. c.ServeSuccessJSON(map[string]interface{}{
  7928. "order_number": order.Number, //业务流水号
  7929. "id_card_no": his.IdCardNo, //社会保障号
  7930. "patient": patient,
  7931. "department_name": department.Name, //科室
  7932. "number": his.Number, //门诊号
  7933. "date": order.SettleAccountsDate, //结算日期
  7934. "name": order.PsnName, //姓名
  7935. "gender": patient.Gender, //性别
  7936. "psn_cash_money": order.PsnCashPay, //个人支付
  7937. "pay_way": "门诊", //结算方式
  7938. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7939. "admin_user_name": admin.UserName, //收款员
  7940. "order": order,
  7941. "order_info": orderInfos_two,
  7942. "his": his,
  7943. "bedCostTotal": bedCostTotal,
  7944. "bedCostSelfTotal": bedCostSelfTotal,
  7945. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7946. "operationCostTotal": operationCostTotal,
  7947. "operationCostSelfTotal": operationCostSelfTotal,
  7948. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7949. "otherCostTotal": otherCostTotal,
  7950. "otherCostSelfTotal": otherCostSelfTotal,
  7951. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7952. "materialCostTotal": materialCostTotal,
  7953. "materialCostSelfTotal": materialCostSelfTotal,
  7954. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7955. "westernMedicineCostTotal": westernMedicineCostTotal,
  7956. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7957. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7958. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7959. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7960. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7961. "checkCostTotal": checkCostTotal,
  7962. "checkCostSelfTotal": checkCostSelfTotal,
  7963. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7964. "laboratoryCostTotal": laboratoryCostTotal,
  7965. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7966. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7967. "treatCostTotal": treatCostTotal,
  7968. "treatCostSelfTotal": treatCostSelfTotal,
  7969. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7970. "zhenChaCostTotal": zhenChaCostTotal,
  7971. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7972. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7973. "his_hospital_record": his_hospital_record,
  7974. "pre_pay_money": pre_pay_money,
  7975. "refund_sum": sum,
  7976. "doctor_info": doctor_info,
  7977. "hiliCostTotal": hiliCostTotal,
  7978. "hiliCostSelfTotal": hiliCostSelfTotal,
  7979. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  7980. })
  7981. }
  7982. //func (c *HisApiController) GetFaPiaoDatas() {
  7983. // order_ids := c.GetString("order_ids")
  7984. // patient_id, _ := c.GetInt64("patient_id")
  7985. // adminUser := c.GetAdminUserInfo()
  7986. //
  7987. // orders := strings.Split(order_ids, ",")
  7988. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7989. //
  7990. // for _, item := range orders {
  7991. // order_id, _ := strconv.ParseInt(item, 10, 64)
  7992. // order, _ := service.GetHisOrderByID(order_id)
  7993. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7994. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7995. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7996. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7997. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7998. //
  7999. // }
  8000. //
  8001. // var bedCostTotal float64 = 0 //床位总费
  8002. // var bedCostSelfTotal float64 = 0 //床位自费
  8003. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8004. //
  8005. // var operationCostTotal float64 = 0 //手术费
  8006. // var operationCostSelfTotal float64 = 0 //手术费
  8007. // var operationCostPartSelfTotal float64 = 0 //手术费
  8008. //
  8009. // var otherCostTotal float64 = 0 //其他费用
  8010. // var otherCostSelfTotal float64 = 0 //其他费用
  8011. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8012. //
  8013. // var materialCostTotal float64 = 0 //材料费
  8014. // var materialCostSelfTotal float64 = 0 //材料费
  8015. // var materialCostPartSelfTotal float64 = 0 //材料费
  8016. //
  8017. // var westernMedicineCostTotal float64 = 0 //西药费
  8018. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8019. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8020. //
  8021. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8022. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8023. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8024. //
  8025. // var checkCostTotal float64 = 0 //检查费
  8026. // var checkCostSelfTotal float64 = 0 //检查费
  8027. // var checkCostPartSelfTotal float64 = 0 //检查费
  8028. //
  8029. // var laboratoryCostTotal float64 = 0 //化验费
  8030. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8031. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8032. //
  8033. // var treatCostTotal float64 = 0 //治疗费用
  8034. // var treatCostSelfTotal float64 = 0 //治疗费用
  8035. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8036. //
  8037. // var zhenChaCostTotal float64 = 0 //其他费用
  8038. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8039. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8040. //
  8041. // decimal.DivisionPrecision = 2
  8042. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8043. //
  8044. // var balanceAccountsType int64
  8045. // if his.ID > 0 {
  8046. // balanceAccountsType = his.BalanceAccountsType
  8047. // } else {
  8048. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8049. // }
  8050. // if balanceAccountsType == 2 {
  8051. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8052. // for _, item := range orderInfos_two {
  8053. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8054. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8055. // item.MedChrgitmType = "09"
  8056. // }
  8057. //
  8058. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8059. // if item.HisPrescriptionProject.Type == 2 {
  8060. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8061. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8062. // case 0:
  8063. // item.MedChrgitmType = "0"
  8064. // break
  8065. // case 1:
  8066. // item.MedChrgitmType = "14"
  8067. // break
  8068. // case 2:
  8069. // item.MedChrgitmType = "05"
  8070. //
  8071. // break
  8072. // case 3:
  8073. // item.MedChrgitmType = "03"
  8074. //
  8075. // break
  8076. // case 4:
  8077. // item.MedChrgitmType = "03"
  8078. //
  8079. // break
  8080. // case 5:
  8081. // item.MedChrgitmType = "08"
  8082. //
  8083. // break
  8084. // case 6:
  8085. // item.MedChrgitmType = "14"
  8086. //
  8087. // break
  8088. // case 7:
  8089. // item.MedChrgitmType = "14"
  8090. //
  8091. // break
  8092. // case 8:
  8093. // item.MedChrgitmType = "03"
  8094. // break
  8095. // case 9:
  8096. // item.MedChrgitmType = "14"
  8097. // break
  8098. // case 10:
  8099. // item.MedChrgitmType = "14"
  8100. // break
  8101. // case 11:
  8102. // item.MedChrgitmType = "06"
  8103. // break
  8104. // case 12:
  8105. // item.MedChrgitmType = "12"
  8106. // break
  8107. // case 13:
  8108. // item.MedChrgitmType = "01"
  8109. // break
  8110. // case 14:
  8111. // item.MedChrgitmType = "04"
  8112. // break
  8113. // case 15:
  8114. // item.MedChrgitmType = "02"
  8115. // break
  8116. //
  8117. // }
  8118. //
  8119. // } else {
  8120. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8121. //
  8122. // case 1:
  8123. // item.MedChrgitmType = "14"
  8124. // break
  8125. // case 2:
  8126. // item.MedChrgitmType = "05"
  8127. //
  8128. // break
  8129. // case 3:
  8130. // item.MedChrgitmType = "03"
  8131. //
  8132. // break
  8133. // case 4:
  8134. // item.MedChrgitmType = "03"
  8135. //
  8136. // break
  8137. // case 5:
  8138. // item.MedChrgitmType = "08"
  8139. //
  8140. // break
  8141. // case 6:
  8142. // item.MedChrgitmType = "14"
  8143. //
  8144. // break
  8145. // case 7:
  8146. // item.MedChrgitmType = "14"
  8147. //
  8148. // break
  8149. // case 8:
  8150. // item.MedChrgitmType = "03"
  8151. // break
  8152. // case 9:
  8153. // item.MedChrgitmType = "14"
  8154. // break
  8155. //
  8156. // }
  8157. //
  8158. // }
  8159. //
  8160. // } else if item.HisPrescriptionProject.Type == 3 {
  8161. // item.MedChrgitmType = "08"
  8162. // }
  8163. // }
  8164. // }
  8165. //
  8166. // for _, item := range orderInfos_two {
  8167. // fmt.Println(item.MedChrgitmType)
  8168. // if item.MedChrgitmType == "01" { //床位费
  8169. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8170. // bedCostSelfTotal = bedCostTotal
  8171. // }
  8172. //
  8173. // if item.MedChrgitmType == "02" { //诊察费
  8174. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8175. // zhenChaCostSelfTotal = zhenChaCostTotal
  8176. // }
  8177. //
  8178. // if item.MedChrgitmType == "03" { //检查费
  8179. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8180. // checkCostSelfTotal = checkCostTotal
  8181. // }
  8182. //
  8183. // if item.MedChrgitmType == "04" { //化验费
  8184. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8185. // laboratoryCostSelfTotal = laboratoryCostTotal
  8186. // }
  8187. //
  8188. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8189. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8190. // treatCostSelfTotal = treatCostTotal
  8191. // }
  8192. //
  8193. // if item.MedChrgitmType == "06" { //手术费
  8194. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8195. // operationCostSelfTotal = treatCostTotal
  8196. // }
  8197. //
  8198. // if item.MedChrgitmType == "08" { //材料费
  8199. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8200. // materialCostSelfTotal = materialCostTotal
  8201. // }
  8202. //
  8203. // if item.MedChrgitmType == "09" { //西药费
  8204. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8205. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8206. // }
  8207. //
  8208. // if item.MedChrgitmType == "11" { //中成费
  8209. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8210. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8211. // }
  8212. //
  8213. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8214. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8215. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8216. // otherCostSelfTotal = otherCostTotal
  8217. // }
  8218. // } else {
  8219. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8220. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8221. // otherCostSelfTotal = otherCostTotal
  8222. // }
  8223. //
  8224. // }
  8225. //
  8226. // }
  8227. //
  8228. // } else {
  8229. // for _, item := range orderInfos {
  8230. // if item.MedChrgitmType == "01" { //床位费
  8231. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8232. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8233. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8234. // }
  8235. //
  8236. // if item.MedChrgitmType == "02" { //诊察费
  8237. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8238. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8239. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8240. // }
  8241. //
  8242. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8243. // if item.MedChrgitmType == "03" { //检查费
  8244. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8245. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8246. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8247. //
  8248. // }
  8249. // } else {
  8250. // if item.MedChrgitmType == "03" { //检查费
  8251. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8252. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8253. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8254. // }
  8255. //
  8256. // }
  8257. //
  8258. // if item.MedChrgitmType == "04" { //化验费
  8259. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8260. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8261. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8262. //
  8263. // }
  8264. //
  8265. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8266. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8267. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8268. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8269. //
  8270. // }
  8271. //
  8272. // if item.MedChrgitmType == "06" { //手术费
  8273. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8274. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8275. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8276. // }
  8277. //
  8278. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8279. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8280. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8281. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8282. // }
  8283. //
  8284. // if item.MedChrgitmType == "09" { //西药费
  8285. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8286. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8287. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8288. // }
  8289. //
  8290. // if item.MedChrgitmType == "11" { //中成费
  8291. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8292. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8293. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8294. // }
  8295. //
  8296. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8297. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8298. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8299. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8300. // }
  8301. //
  8302. // }
  8303. // }
  8304. // timeLayout := "2006-01-02"
  8305. // loc, _ := time.LoadLocation("Local")
  8306. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8307. // if err != nil {
  8308. // }
  8309. // startRecordDateTime := startTime.Unix()
  8310. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8311. // if err != nil {
  8312. // }
  8313. // endRecordDateTime := endTime.Unix()
  8314. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8315. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8316. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8317. //
  8318. // c.ServeSuccessJSON(map[string]interface{}{
  8319. // "order_number": order.Number, //业务流水号
  8320. // "id_card_no": his.IdCardNo, //社会保障号
  8321. // "department_name": department.Name, //科室
  8322. // "number": his.Number, //门诊号
  8323. // "date": order.SettleAccountsDate, //结算日期
  8324. // "name": order.PsnName, //姓名
  8325. // "gender": patient.Gender, //性别
  8326. // "psn_cash_money": order.PsnCashPay, //个人支付
  8327. // "pay_way": "门诊", //结算方式
  8328. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8329. // "admin_user_name": admin.UserName, //收款员
  8330. // "order": order,
  8331. // "order_info": orderInfos_two,
  8332. // "his": his,
  8333. // "bedCostTotal": bedCostTotal,
  8334. // "bedCostSelfTotal": bedCostSelfTotal,
  8335. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8336. // "operationCostTotal": operationCostTotal,
  8337. // "operationCostSelfTotal": operationCostSelfTotal,
  8338. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8339. // "otherCostTotal": otherCostTotal,
  8340. // "otherCostSelfTotal": otherCostSelfTotal,
  8341. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8342. // "materialCostTotal": materialCostTotal,
  8343. // "materialCostSelfTotal": materialCostSelfTotal,
  8344. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8345. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8346. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8347. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8348. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8349. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8350. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8351. // "checkCostTotal": checkCostTotal,
  8352. // "checkCostSelfTotal": checkCostSelfTotal,
  8353. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8354. // "laboratoryCostTotal": laboratoryCostTotal,
  8355. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8356. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8357. // "treatCostTotal": treatCostTotal,
  8358. // "treatCostSelfTotal": treatCostSelfTotal,
  8359. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8360. // "zhenChaCostTotal": zhenChaCostTotal,
  8361. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8362. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8363. // "his_hospital_record": his_hospital_record,
  8364. // "pre_pay_money": pre_pay_money,
  8365. // "refund_sum": sum,
  8366. // })
  8367. //
  8368. //}
  8369. func (this *HisApiController) GetIncomeStatisticsData() {
  8370. start_time := this.GetString("start_time")
  8371. end_time := this.GetString("end_time")
  8372. key_words := this.GetString("key_words")
  8373. limit, _ := this.GetInt64("limit")
  8374. page, _ := this.GetInt64("page")
  8375. if page <= 0 {
  8376. page = 1
  8377. }
  8378. if limit <= 0 {
  8379. limit = 10
  8380. }
  8381. statistics_type, _ := this.GetInt64("statistics_type")
  8382. admin := this.GetAdminUserInfo()
  8383. timeLayout := "2006-01-02"
  8384. loc, _ := time.LoadLocation("Local")
  8385. var theStartTIme int64
  8386. if len(start_time) > 0 {
  8387. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8388. if err != nil {
  8389. theStartTIme = 0
  8390. }
  8391. theStartTIme = theTime.Unix()
  8392. }
  8393. var theEndtTIme int64
  8394. if len(end_time) > 0 {
  8395. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8396. if err != nil {
  8397. theEndtTIme = 0
  8398. }
  8399. theEndtTIme = theTime.Unix()
  8400. }
  8401. if statistics_type == 1 {
  8402. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8403. this.ServeSuccessJSON(map[string]interface{}{
  8404. "list": list,
  8405. "total": total,
  8406. })
  8407. } else {
  8408. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8409. this.ServeSuccessJSON(map[string]interface{}{
  8410. "list": list,
  8411. "total": total,
  8412. })
  8413. }
  8414. }
  8415. func (c *HisApiController) PostProjectInformation() {
  8416. adminUser := c.GetAdminUserInfo()
  8417. orgId := adminUser.CurrentOrgId
  8418. dataBody := make(map[string]interface{}, 0)
  8419. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8420. if err != nil {
  8421. utils.ErrorLog(err.Error())
  8422. return
  8423. }
  8424. utils.ErrorLog("%v", dataBody)
  8425. var projectList []*models.HisProject
  8426. var total_goods []interface{}
  8427. tempProjects := dataBody["projects"].([]interface{})
  8428. total_goods = tempProjects
  8429. for index, projectMap := range tempProjects {
  8430. projectM := projectMap.(map[string]interface{})
  8431. var project models.HisProject
  8432. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8433. utils.ErrorLog("project_name")
  8434. return
  8435. }
  8436. project_name, _ := projectM["project_name"].(string)
  8437. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8438. err_log := models.ExportErrLog{
  8439. LogType: 6,
  8440. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8441. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8442. Status: 1,
  8443. CreateTime: time.Now().Unix(),
  8444. UpdateTime: time.Now().Unix(),
  8445. ExportTime: time.Now().Unix(),
  8446. }
  8447. service.CreateExportErrLog(&err_log)
  8448. continue
  8449. }
  8450. project.ProjectName = project_name
  8451. prices := projectM["price"].(string)
  8452. price, _ := strconv.ParseFloat(prices, 64)
  8453. if price <= 0 { //名字为空则生成一条导入错误日志
  8454. err_log := models.ExportErrLog{
  8455. LogType: 6,
  8456. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8457. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8458. Status: 1,
  8459. CreateTime: time.Now().Unix(),
  8460. UpdateTime: time.Now().Unix(),
  8461. ExportTime: time.Now().Unix(),
  8462. }
  8463. service.CreateExportErrLog(&err_log)
  8464. continue
  8465. }
  8466. project.Price = price
  8467. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8468. utils.ErrorLog("unit_id")
  8469. return
  8470. }
  8471. unit := projectM["unit"].(string)
  8472. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8473. err_log := models.ExportErrLog{
  8474. LogType: 6,
  8475. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8476. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8477. Status: 1,
  8478. CreateTime: time.Now().Unix(),
  8479. UpdateTime: time.Now().Unix(),
  8480. ExportTime: time.Now().Unix(),
  8481. }
  8482. service.CreateExportErrLog(&err_log)
  8483. continue
  8484. }
  8485. project.Unit = unit
  8486. cost_classify := projectM["cost_classify"].(string)
  8487. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8488. err_log := models.ExportErrLog{
  8489. LogType: 6,
  8490. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8491. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8492. Status: 1,
  8493. CreateTime: time.Now().Unix(),
  8494. UpdateTime: time.Now().Unix(),
  8495. ExportTime: time.Now().Unix(),
  8496. }
  8497. service.CreateExportErrLog(&err_log)
  8498. continue
  8499. }
  8500. var costClassify = "费用类别"
  8501. var cost_classify_id int64
  8502. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8503. if len(cost_classify) != 0 {
  8504. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8505. if errcode == gorm.ErrRecordNotFound {
  8506. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8507. dataconfig := models.DictDataconfig{
  8508. ParentId: costClassifyConfig.ID,
  8509. Module: "system",
  8510. OrgId: orgId,
  8511. Name: cost_classify,
  8512. FieldName: "",
  8513. Value: costConfig.Value + 1,
  8514. CreatedTime: "",
  8515. UpdatedTime: "",
  8516. CreateUserId: adminUser.AdminUser.Id,
  8517. Status: 1,
  8518. Remark: "",
  8519. DeleteIdSystem: 0,
  8520. Title: "",
  8521. Content: "",
  8522. Order: 0,
  8523. Code: "",
  8524. }
  8525. service.CreatedDicConfig(&dataconfig)
  8526. }
  8527. }
  8528. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8529. for _, it := range costClassList {
  8530. if cost_classify == it.Name {
  8531. cost_classify_id = int64(it.Value)
  8532. }
  8533. }
  8534. project.CostClassify = cost_classify_id
  8535. executive_section := projectM["executive_section"].(string)
  8536. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8537. err_log := models.ExportErrLog{
  8538. LogType: 6,
  8539. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8540. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8541. Status: 1,
  8542. CreateTime: time.Now().Unix(),
  8543. UpdateTime: time.Now().Unix(),
  8544. ExportTime: time.Now().Unix(),
  8545. }
  8546. service.CreateExportErrLog(&err_log)
  8547. continue
  8548. }
  8549. if len(executive_section) != 0 {
  8550. //查找科室是否有内容
  8551. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8552. if errcodedepart == gorm.ErrRecordNotFound {
  8553. department := models.XtHisDepartment{
  8554. Name: executive_section,
  8555. Status: 1,
  8556. UserOrgId: adminUser.CurrentOrgId,
  8557. CreatedTime: time.Now().Unix(),
  8558. }
  8559. service.CreateDePartment(&department)
  8560. }
  8561. }
  8562. var executive_section_id int64
  8563. departMentList, _ := service.GetAllDepartMent(orgId)
  8564. for _, it := range departMentList {
  8565. if executive_section == it.Name {
  8566. executive_section_id = it.ID
  8567. }
  8568. }
  8569. project.ExecutiveSection = executive_section_id
  8570. medical_coverage := projectM["medical_coverage"].(string)
  8571. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8572. err_log := models.ExportErrLog{
  8573. LogType: 6,
  8574. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8575. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8576. Status: 1,
  8577. CreateTime: time.Now().Unix(),
  8578. UpdateTime: time.Now().Unix(),
  8579. ExportTime: time.Now().Unix(),
  8580. }
  8581. service.CreateExportErrLog(&err_log)
  8582. continue
  8583. }
  8584. var medicalCoverage = "医保等级"
  8585. var medical_coverage_id int64
  8586. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8587. if len(medical_coverage) != 0 {
  8588. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8589. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8590. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8591. dataconfig := models.DictDataconfig{
  8592. ParentId: medicalCoverageConfig.ID,
  8593. Module: "system",
  8594. OrgId: orgId,
  8595. Name: medical_coverage,
  8596. FieldName: "",
  8597. Value: medicalCoverageConfig.Value + 1,
  8598. CreatedTime: "",
  8599. UpdatedTime: "",
  8600. CreateUserId: adminUser.AdminUser.Id,
  8601. Status: 1,
  8602. Remark: "",
  8603. DeleteIdSystem: 0,
  8604. Title: "",
  8605. Content: "",
  8606. Order: 0,
  8607. Code: "",
  8608. }
  8609. service.CreatedDicConfig(&dataconfig)
  8610. }
  8611. }
  8612. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8613. for _, it := range medicalCoverageList {
  8614. if medical_coverage == it.Name {
  8615. medical_coverage_id = int64(it.Value)
  8616. }
  8617. }
  8618. project.MedicalCoverage = medical_coverage_id
  8619. pinyin := projectM["pinyin"].(string)
  8620. project.Pinyin = pinyin
  8621. wubi := projectM["wubi"].(string)
  8622. project.Wubi = wubi
  8623. statistical_classification := projectM["statistical_classification"].(string)
  8624. var statisticalClassification = "统计分类"
  8625. var statistical_classification_id int64
  8626. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8627. if len(statistical_classification) != 0 {
  8628. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8629. if classificationerrcodes == gorm.ErrRecordNotFound {
  8630. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8631. dataconfig := models.DictDataconfig{
  8632. ParentId: classiFication.ID,
  8633. Module: "system",
  8634. OrgId: orgId,
  8635. Name: statistical_classification,
  8636. FieldName: "",
  8637. Value: classiFicationConfig.Value + 1,
  8638. CreatedTime: "",
  8639. UpdatedTime: "",
  8640. CreateUserId: adminUser.AdminUser.Id,
  8641. Status: 1,
  8642. Remark: "",
  8643. DeleteIdSystem: 0,
  8644. Title: "",
  8645. Content: "",
  8646. Order: 0,
  8647. Code: "",
  8648. }
  8649. service.CreatedDicConfig(&dataconfig)
  8650. }
  8651. }
  8652. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8653. for _, it := range classiFicationList {
  8654. if statistical_classification == it.Name {
  8655. statistical_classification_id = int64(it.Value)
  8656. }
  8657. }
  8658. project.StatisticalClassification = statistical_classification_id
  8659. disease_directory := int64(projectM["disease_directory"].(float64))
  8660. project.DiseaseDirectory = disease_directory
  8661. is_record := int64(projectM["is_record"].(float64))
  8662. project.IsRecord = is_record
  8663. medical_code := projectM["medical_code"].(string)
  8664. project.MedicalCode = medical_code
  8665. tube_color := projectM["tube_color"].(string)
  8666. var tubeColor = "试管颜色"
  8667. var tube_color_id int64
  8668. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8669. if len(tube_color) != 0 {
  8670. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8671. if errcodetube == gorm.ErrRecordNotFound {
  8672. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8673. dataconfig := models.DictDataconfig{
  8674. ParentId: tubeColorConfig.ID,
  8675. Module: "system",
  8676. OrgId: orgId,
  8677. Name: tube_color,
  8678. FieldName: "",
  8679. Value: tubeConfig.Value + 1,
  8680. CreatedTime: "",
  8681. UpdatedTime: "",
  8682. CreateUserId: adminUser.AdminUser.Id,
  8683. Status: 1,
  8684. Remark: "",
  8685. DeleteIdSystem: 0,
  8686. Title: "",
  8687. Content: "",
  8688. Order: 0,
  8689. Code: "",
  8690. }
  8691. service.CreatedDicConfig(&dataconfig)
  8692. }
  8693. }
  8694. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8695. for _, it := range tubeColorList {
  8696. if tube_color == it.Name {
  8697. tube_color_id = int64(it.Value)
  8698. }
  8699. }
  8700. project.TubeColor = tube_color_id
  8701. single_dose := projectM["single_dose"].(string)
  8702. project.SingleDose = single_dose
  8703. execution_frequency := projectM["execution_frequency"].(string)
  8704. project.ExecutionFrequency = execution_frequency
  8705. delivery_way := projectM["delivery_way"].(string)
  8706. project.DeliveryWay = delivery_way
  8707. number_days := projectM["number_days"].(string)
  8708. project.NumberDays = number_days
  8709. total := projectM["total"].(string)
  8710. project.Total = total
  8711. medical_status := int64(projectM["medical_status"].(float64))
  8712. project.MedicalStatus = medical_status
  8713. category := int64(projectM["category"].(float64))
  8714. project.Category = category
  8715. specail_project := int64(projectM["specail_project"].(float64))
  8716. project.SpecailProject = specail_project
  8717. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8718. project.SocialSecurityDirectoryCode = social_security_directory_code
  8719. remark := projectM["remark"].(string)
  8720. project.Remark = remark
  8721. record_date := projectM["record_date"].(string)
  8722. timeLayout := "2006-01-02"
  8723. loc, _ := time.LoadLocation("Local")
  8724. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8725. project.RecordDate = theTime.Unix()
  8726. projectList = append(projectList, &project)
  8727. }
  8728. export_time := time.Now().Unix()
  8729. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8730. if len(projectList) > 0 {
  8731. for _, item := range projectList {
  8732. project := models.HisProject{
  8733. ProjectName: item.ProjectName,
  8734. Price: item.Price,
  8735. Unit: item.Unit,
  8736. CostClassify: item.CostClassify,
  8737. ExecutiveSection: item.ExecutiveSection,
  8738. MedicalCoverage: item.MedicalCoverage,
  8739. UserOrgId: orgId,
  8740. Status: 1,
  8741. CreatedTime: time.Now().Unix(),
  8742. Pinyin: item.Pinyin,
  8743. Wubi: item.Wubi,
  8744. StatisticalClassification: item.StatisticalClassification,
  8745. DiseaseDirectory: item.DiseaseDirectory,
  8746. IsRecord: item.IsRecord,
  8747. MedicalCode: item.MedicalCode,
  8748. TubeColor: item.TubeColor,
  8749. SingleDose: item.SingleDose,
  8750. DeliveryWay: item.DeliveryWay,
  8751. NumberDays: item.NumberDays,
  8752. Total: item.Total,
  8753. Category: item.Category,
  8754. MedicalStatus: item.MedicalStatus,
  8755. SpecailProject: item.SpecailProject,
  8756. RecordDate: item.RecordDate,
  8757. Remark: item.Remark,
  8758. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8759. ExecutionFrequency: item.ExecutionFrequency,
  8760. }
  8761. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8762. if errcodeproject == gorm.ErrRecordNotFound {
  8763. service.CreateProjectInfomation(&project)
  8764. } else if errcodeproject == nil {
  8765. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8766. }
  8767. log := models.ExportLog{
  8768. LogType: 6,
  8769. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8770. TotalNum: int64(len(total_goods)),
  8771. FailNum: int64(len(errLogs)),
  8772. SuccessNum: int64(len(projectList)),
  8773. CreateTime: time.Now().Unix(),
  8774. UpdateTime: time.Now().Unix(),
  8775. ExportTime: export_time,
  8776. Status: 1,
  8777. }
  8778. service.CreateExportLog(&log)
  8779. c.ServeSuccessJSON(map[string]interface{}{
  8780. "msg": "导入成功",
  8781. "total_num": len(total_goods),
  8782. "success_num": len(projectList),
  8783. "fail_num": int64(len(errLogs)),
  8784. })
  8785. }
  8786. } else {
  8787. log := models.ExportLog{
  8788. LogType: 6,
  8789. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8790. TotalNum: int64(len(total_goods)),
  8791. FailNum: int64(len(errLogs)),
  8792. SuccessNum: int64(len(projectList)),
  8793. CreateTime: time.Now().Unix(),
  8794. UpdateTime: time.Now().Unix(),
  8795. ExportTime: export_time,
  8796. Status: 1,
  8797. }
  8798. service.CreateExportLog(&log)
  8799. c.ServeSuccessJSON(map[string]interface{}{
  8800. "msg": "导入成功",
  8801. "total_num": len(total_goods),
  8802. "success_num": len(projectList),
  8803. "fail_num": int64(len(errLogs)),
  8804. })
  8805. }
  8806. }
  8807. //func (this *HisApiController) EditProjectInformation(){
  8808. //
  8809. // id, _ := this.GetInt64("id")
  8810. // project_team := this.GetString("project_team")
  8811. // price := this.GetString("price")
  8812. // price_float, _ := strconv.ParseFloat(price, 64)
  8813. // pinyin := this.GetString("pinyin")
  8814. // wubi := this.GetString("wubi")
  8815. // tube_color, _ := this.GetInt64("tube_color")
  8816. // team_type, _ := this.GetInt64("team_type")
  8817. // remark := this.GetString("remark")
  8818. // ids := this.GetString("ids")
  8819. // item_id := this.GetString("item_id")
  8820. // projectTeam := models.XtHisProjectTeam{
  8821. // ProjectTeam: project_team,
  8822. // Price: price_float,
  8823. // Pinyin: pinyin,
  8824. // Wubi: wubi,
  8825. // TubeColor: tube_color,
  8826. // TeamType: team_type,
  8827. // Remark: remark,
  8828. // ProjectId: ids,
  8829. // ItemId: item_id,
  8830. // }
  8831. //
  8832. //
  8833. // dataBody := make(map[string]interface{}, 0)
  8834. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8835. // if err != nil {
  8836. // utils.ErrorLog(err.Error())
  8837. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8838. // return
  8839. // }
  8840. //
  8841. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8842. //
  8843. //
  8844. // if err != nil {
  8845. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8846. // return
  8847. // }
  8848. //
  8849. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8850. // infos, _ := dataBody["info"].([]interface{})
  8851. // if len(infos) > 0 {
  8852. // var ids []string
  8853. //
  8854. // for _, item := range infos {
  8855. // items := item.(map[string]interface{})
  8856. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8857. // utils.ErrorLog("id")
  8858. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8859. // return
  8860. // }
  8861. // id := int64(items["id"].(float64))
  8862. //
  8863. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8864. // utils.ErrorLog("type")
  8865. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8866. // return
  8867. // }
  8868. // types := int64(items["type"].(float64))
  8869. //
  8870. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8871. // utils.ErrorLog("number")
  8872. // }
  8873. //
  8874. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8875. //
  8876. // projectList := models.XtHisProjectList{
  8877. // Number: number,
  8878. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8879. // ProjectId: id,
  8880. // Status: 1,
  8881. // CreatedTime: time.Now().Unix(),
  8882. // UpdatedTime: time.Now().Unix(),
  8883. // TeamId: projectTeam.ID,
  8884. // Type: types,
  8885. // }
  8886. // list := projectList
  8887. //
  8888. // service.CreateProjectList(&list)
  8889. //
  8890. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8891. //
  8892. // }
  8893. // ids_str := strings.Join(ids, ",")
  8894. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8895. // service.SaveProjectTeam(&projectTeam)
  8896. // this.ServeSuccessJSON(map[string]interface{}{
  8897. // "projectTeam": projectTeam,
  8898. // })
  8899. // }
  8900. // }
  8901. //}
  8902. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8903. name := c.GetString("name")
  8904. mode_id, _ := c.GetInt64("mode", 0)
  8905. types, _ := c.GetInt64("type", 0)
  8906. patient_id, _ := c.GetInt64("patient_id", 0)
  8907. types = 1
  8908. adminInfo := c.GetAdminUserInfo()
  8909. template := &models.HisPrescriptionTemplate{
  8910. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8911. PatientId: patient_id,
  8912. Type: types,
  8913. Status: 1,
  8914. Ctime: time.Now().Unix(),
  8915. Mtime: time.Now().Unix(),
  8916. Name: name,
  8917. Mode: mode_id,
  8918. }
  8919. dataBody := make(map[string]interface{}, 0)
  8920. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8921. if err != nil {
  8922. utils.ErrorLog(err.Error())
  8923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8924. return
  8925. }
  8926. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8927. //如果已经存在记录则删除处方
  8928. if template_one.ID > 0 {
  8929. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8930. for _, item := range ps {
  8931. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8932. }
  8933. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8934. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8935. if len(prescriptions) > 0 {
  8936. for _, item := range prescriptions {
  8937. items := item.(map[string]interface{})
  8938. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8939. utils.ErrorLog("type")
  8940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8941. return
  8942. }
  8943. types := int64(items["type"].(float64))
  8944. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8945. utils.ErrorLog("med_type")
  8946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8947. return
  8948. }
  8949. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8950. ctime := time.Now().Unix()
  8951. prescription := &models.HisPrescriptionInfoTemplate{
  8952. PatientId: patient_id,
  8953. UserOrgId: adminInfo.CurrentOrgId,
  8954. Ctime: ctime,
  8955. Mtime: ctime,
  8956. Type: types,
  8957. Modifier: adminInfo.AdminUser.Id,
  8958. Creator: adminInfo.AdminUser.Id,
  8959. Status: 1,
  8960. PTemplateId: template_one.ID,
  8961. MedType: med_type,
  8962. }
  8963. service.CreateHisPrescriptionInfoTemplate(prescription)
  8964. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8965. advices := items["advices"].([]interface{})
  8966. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8967. ctime := time.Now().Unix()
  8968. mtime := ctime
  8969. if len(advices) > 0 {
  8970. for _, advice := range advices {
  8971. var s models.HisPrescriptionAdviceTemplate
  8972. s.PrescriptionId = prescription.ID
  8973. s.AdviceType = 2
  8974. s.StopState = 2
  8975. s.ExecutionState = 2
  8976. s.Status = 1
  8977. s.UserOrgId = adminInfo.CurrentOrgId
  8978. s.CreatedTime = ctime
  8979. s.UpdatedTime = mtime
  8980. s.PatientId = patient_id
  8981. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8982. if errcode > 0 {
  8983. c.ServeFailJSONWithSGJErrorCode(errcode)
  8984. return
  8985. }
  8986. service.CreateHisPrescriptionAdviceTemplate(&s)
  8987. }
  8988. }
  8989. }
  8990. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8991. projects := items["project"].([]interface{})
  8992. if len(projects) > 0 {
  8993. for _, project := range projects {
  8994. var p models.HisPrescriptionProjectTemplate
  8995. p.PrescriptionId = prescription.ID
  8996. p.Ctime = time.Now().Unix()
  8997. p.Mtime = time.Now().Unix()
  8998. p.PatientId = patient_id
  8999. p.UserOrgId = adminInfo.CurrentOrgId
  9000. p.Status = 1
  9001. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9002. if errcode > 0 {
  9003. c.ServeFailJSONWithSGJErrorCode(errcode)
  9004. return
  9005. }
  9006. service.CreateHisPrescriptionProjectTemplate(&p)
  9007. }
  9008. }
  9009. }
  9010. }
  9011. c.ServeSuccessJSON(map[string]interface{}{
  9012. "msg": "创建成功",
  9013. })
  9014. }
  9015. }
  9016. } else {
  9017. err = service.CreateHisPrescriptionTemplate(template)
  9018. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9019. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9020. if len(prescriptions) > 0 {
  9021. for _, item := range prescriptions {
  9022. items := item.(map[string]interface{})
  9023. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9024. utils.ErrorLog("type")
  9025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9026. return
  9027. }
  9028. types := int64(items["type"].(float64))
  9029. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9030. utils.ErrorLog("med_type")
  9031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9032. return
  9033. }
  9034. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9035. ctime := time.Now().Unix()
  9036. prescription := &models.HisPrescriptionInfoTemplate{
  9037. PatientId: patient_id,
  9038. UserOrgId: adminInfo.CurrentOrgId,
  9039. Ctime: ctime,
  9040. Mtime: ctime,
  9041. Type: types,
  9042. Modifier: adminInfo.AdminUser.Id,
  9043. Creator: adminInfo.AdminUser.Id,
  9044. Status: 1,
  9045. PTemplateId: template.ID,
  9046. MedType: med_type,
  9047. }
  9048. service.CreateHisPrescriptionInfoTemplate(prescription)
  9049. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9050. advices := items["advices"].([]interface{})
  9051. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9052. ctime := time.Now().Unix()
  9053. mtime := ctime
  9054. if len(advices) > 0 {
  9055. for _, advice := range advices {
  9056. var s models.HisPrescriptionAdviceTemplate
  9057. s.PrescriptionId = prescription.ID
  9058. s.AdviceType = 2
  9059. s.StopState = 2
  9060. s.ExecutionState = 2
  9061. s.Status = 1
  9062. s.UserOrgId = adminInfo.CurrentOrgId
  9063. s.CreatedTime = ctime
  9064. s.UpdatedTime = mtime
  9065. s.PatientId = patient_id
  9066. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9067. if errcode > 0 {
  9068. c.ServeFailJSONWithSGJErrorCode(errcode)
  9069. return
  9070. }
  9071. service.CreateHisPrescriptionAdviceTemplate(&s)
  9072. }
  9073. }
  9074. }
  9075. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9076. projects := items["project"].([]interface{})
  9077. if len(projects) > 0 {
  9078. for _, project := range projects {
  9079. var p models.HisPrescriptionProjectTemplate
  9080. p.PrescriptionId = prescription.ID
  9081. p.Ctime = time.Now().Unix()
  9082. p.Mtime = time.Now().Unix()
  9083. p.PatientId = patient_id
  9084. p.UserOrgId = adminInfo.CurrentOrgId
  9085. p.Status = 1
  9086. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9087. if errcode > 0 {
  9088. c.ServeFailJSONWithSGJErrorCode(errcode)
  9089. return
  9090. }
  9091. service.CreateHisPrescriptionProjectTemplate(&p)
  9092. }
  9093. }
  9094. }
  9095. }
  9096. c.ServeSuccessJSON(map[string]interface{}{
  9097. "msg": "创建成功",
  9098. })
  9099. }
  9100. }
  9101. }
  9102. }
  9103. func (c *HisApiController) PreSettle() {
  9104. id, _ := c.GetInt64("id")
  9105. record_time := c.GetString("record_time")
  9106. his_patient_id, _ := c.GetInt64("his_patient_id")
  9107. timeLayout := "2006-01-02"
  9108. loc, _ := time.LoadLocation("Local")
  9109. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9110. diagnosis_id := c.GetString("diagnosis")
  9111. sick_type, _ := c.GetInt64("sick_type")
  9112. reg_type, _ := c.GetInt64("p_type")
  9113. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9114. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9115. if err != nil {
  9116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9117. return
  9118. }
  9119. recordDateTime := theTime.Unix()
  9120. adminUser := c.GetAdminUserInfo()
  9121. var prescriptions []*models.HisPrescription
  9122. var start_time int64
  9123. var end_time int64
  9124. ids_str := c.GetString("ids")
  9125. ids_arr := strings.Split(ids_str, ",")
  9126. fmt.Println(reg_type)
  9127. if settle_accounts_type == 1 { //日结
  9128. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9129. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9130. } else {
  9131. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9132. }
  9133. fmt.Println(prescriptions)
  9134. } else { //月结
  9135. start_time_str := c.GetString("start_time")
  9136. end_time_str := c.GetString("end_time")
  9137. timeLayout := "2006-01-02"
  9138. loc, _ := time.LoadLocation("Local")
  9139. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9140. if err != nil {
  9141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9142. return
  9143. }
  9144. recordStartTime := theStartTime.Unix()
  9145. start_time = recordStartTime
  9146. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9147. if err != nil {
  9148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9149. return
  9150. }
  9151. recordEndTime := theEndTime.Unix()
  9152. end_time = recordEndTime
  9153. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9154. }
  9155. if reg_type == 1111 || reg_type == 1112 {
  9156. reg_type = 11
  9157. }
  9158. timestamp := time.Now().Unix()
  9159. tempTime := time.Unix(timestamp, 0)
  9160. timeFormat := tempTime.Format("20060102150405")
  9161. chrgBchno := rand.Intn(100000) + 10000
  9162. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9163. strconv.FormatInt(his.PatientId, 10)
  9164. var ids []int64
  9165. for _, item := range prescriptions {
  9166. ids = append(ids, item.ID)
  9167. }
  9168. fmt.Println(ids)
  9169. var total float64
  9170. for _, item := range prescriptions {
  9171. fmt.Println(item)
  9172. if item.Type == 1 { //药品
  9173. for _, subItem := range item.HisDoctorAdviceInfo {
  9174. total = total + (subItem.Price * subItem.PrescribingNumber)
  9175. }
  9176. }
  9177. if item.Type == 2 { //项目
  9178. for _, subItem := range item.HisPrescriptionProject {
  9179. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9180. total = total + (subItem.Price * cnt)
  9181. }
  9182. }
  9183. for _, subItem := range item.HisAdditionalCharge {
  9184. total = total + (subItem.Price * float64(subItem.Count))
  9185. }
  9186. }
  9187. allTotal := fmt.Sprintf("%.2f", total)
  9188. totals, _ := strconv.ParseFloat(allTotal, 64)
  9189. order := &models.HisOrder{
  9190. UserOrgId: adminUser.CurrentOrgId,
  9191. HisPatientId: his.ID,
  9192. PatientId: id,
  9193. SettleAccountsDate: recordDateTime,
  9194. Ctime: time.Now().Unix(),
  9195. Mtime: time.Now().Unix(),
  9196. Status: 1,
  9197. OrderStatus: 1,
  9198. MdtrtId: his.Number,
  9199. Number: chrg_bchno,
  9200. MedfeeSumamt: totals,
  9201. SettleEndTime: end_time,
  9202. SettleStartTime: start_time,
  9203. SettleType: settle_accounts_type,
  9204. PsnPartAmt: totals,
  9205. PsnCashPay: totals,
  9206. PType: 2,
  9207. IsPre: 1,
  9208. MedType: strconv.Itoa(int(reg_type)),
  9209. Diagnosis: diagnosis_id,
  9210. }
  9211. err = service.CreateOrder(order)
  9212. if err != nil {
  9213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9214. return
  9215. }
  9216. var customs []*Custom
  9217. for _, item := range prescriptions {
  9218. fmt.Println(item.Type)
  9219. if item.Type == 1 { //药品
  9220. for _, subItem := range item.HisDoctorAdviceInfo {
  9221. cus := &Custom{
  9222. AdviceId: subItem.ID,
  9223. ProjectId: 0,
  9224. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9225. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9226. FeedetlSn: subItem.FeedetlSn,
  9227. Price: fmt.Sprintf("%.2f", subItem.Price),
  9228. MedListCodg: subItem.MedListCodg,
  9229. Type: 1,
  9230. }
  9231. customs = append(customs, cus)
  9232. }
  9233. }
  9234. if item.Type == 2 { //项目
  9235. for _, subItem := range item.HisPrescriptionProject {
  9236. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9237. cus := &Custom{
  9238. AdviceId: 0,
  9239. ProjectId: subItem.ID,
  9240. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9241. Cut: fmt.Sprintf("%.2f", cnt),
  9242. FeedetlSn: subItem.FeedetlSn,
  9243. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9244. MedListCodg: subItem.MedListCodg,
  9245. Type: 2,
  9246. }
  9247. customs = append(customs, cus)
  9248. }
  9249. }
  9250. for _, item := range item.HisAdditionalCharge {
  9251. cus := &Custom{
  9252. ItemId: item.ID,
  9253. AdviceId: 0,
  9254. ProjectId: 0,
  9255. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9256. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9257. FeedetlSn: item.FeedetlSn,
  9258. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9259. MedListCodg: item.XtHisAddtionConfig.Code,
  9260. Type: 3,
  9261. }
  9262. customs = append(customs, cus)
  9263. }
  9264. }
  9265. fmt.Println(customs)
  9266. for _, item := range customs {
  9267. var advice_id int64 = 0
  9268. var project_id int64 = 0
  9269. var item_id int64 = 0
  9270. var types int64 = 0
  9271. if item.Type == 1 {
  9272. advice_id = item.AdviceId
  9273. project_id = 0
  9274. item_id = 0
  9275. } else if item.Type == 2 {
  9276. advice_id = 0
  9277. item_id = 0
  9278. project_id = item.ProjectId
  9279. } else if item.Type == 3 {
  9280. advice_id = 0
  9281. item_id = item.ItemId
  9282. project_id = 0
  9283. }
  9284. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9285. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9286. pric, _ := strconv.ParseFloat(item.Price, 32)
  9287. info := &models.HisOrderInfo{
  9288. OrderNumber: order.Number,
  9289. UploadDate: time.Now().Unix(),
  9290. AdviceId: advice_id,
  9291. DetItemFeeSumamt: detItemFeeSumamt,
  9292. Cnt: cut,
  9293. Pric: pric,
  9294. PatientId: id,
  9295. Status: 1,
  9296. Mtime: time.Now().Unix(),
  9297. Ctime: time.Now().Unix(),
  9298. UserOrgId: adminUser.CurrentOrgId,
  9299. HisPatientId: his.ID,
  9300. OrderId: order.ID,
  9301. ProjectId: project_id,
  9302. Type: types,
  9303. ItemId: item_id,
  9304. }
  9305. service.CreateOrderInfo(info)
  9306. }
  9307. his.SickType = sick_type
  9308. service.UpdataHisPateint(&his)
  9309. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9310. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9311. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9312. if err == nil {
  9313. c.ServeSuccessJSON(map[string]interface{}{
  9314. "msg": "结算成功",
  9315. })
  9316. }
  9317. }
  9318. type CustomOrderInfo struct {
  9319. Name string
  9320. Spec string
  9321. Unit string
  9322. Count float64
  9323. Price float64
  9324. Total float64
  9325. }
  9326. func (c *HisApiController) GetPrivateExpensesInfo() {
  9327. order_id, _ := c.GetInt64("id", 0)
  9328. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9329. order, _ := service.GetHisOrderByID(order_id)
  9330. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9331. if order.ID == 0 {
  9332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9333. return
  9334. }
  9335. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9336. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9337. org_id := c.GetAdminUserInfo().CurrentOrgId
  9338. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9339. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9340. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9341. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9342. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9343. //var orderInfos_four []*models.HisOrderInfoTwo
  9344. //for _, item := range orderInfos_three {
  9345. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9346. // item.HisPrescriptionProject.IsCheckTeam = 1
  9347. // orderInfos_four = append(orderInfos_four, item)
  9348. //
  9349. // }
  9350. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9351. // item.HisPrescriptionProject.IsCheckTeam = 2
  9352. // orderInfos_two = append(orderInfos_two, item)
  9353. // }
  9354. //}
  9355. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9356. //var cus_slice []CustomOrderInfo
  9357. //for _, item := range new_order_info {
  9358. // var cus CustomOrderInfo
  9359. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9360. // cus.Unit = ""
  9361. // cus.Spec = ""
  9362. // var total float64
  9363. // for _, subItem := range orderInfos_four {
  9364. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9365. // total = total + subItem.DetItemFeeSumamt
  9366. // fmt.Println(subItem.DetItemFeeSumamt)
  9367. // }
  9368. // }
  9369. // cus.Count = 1
  9370. // cus.Total = total
  9371. // cus_slice = append(cus_slice, cus)
  9372. //}
  9373. orderInfos = append(orderInfos, orderInfos_two...)
  9374. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9375. //orderInfos = append(orderInfos, orderInfos_three...)
  9376. //}/**/
  9377. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9378. c.ServeSuccessJSON(map[string]interface{}{
  9379. "order": order,
  9380. "order_info": orderInfos,
  9381. "patient": patient,
  9382. "admin_info": adminInfo,
  9383. "his": his,
  9384. "current_admin": role,
  9385. "org_config": miConfig,
  9386. //"new_order_info": cus_slice,
  9387. })
  9388. }
  9389. func (this *HisApiController) ChangeMedType() {
  9390. med_type := this.GetString("med_type")
  9391. old_med_type := this.GetString("old_med_type")
  9392. ids := this.GetString("ids")
  9393. settle_type, _ := this.GetInt64("settle_type")
  9394. start_time := this.GetString("start_time")
  9395. end_time := this.GetString("end_time")
  9396. ids_arr := strings.Split(ids, ",")
  9397. if settle_type == 1 { //日结
  9398. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9399. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9400. prescription.MedType = med_type
  9401. err := service.SaveHisPrescription(&prescription)
  9402. if err == nil {
  9403. this.ServeSuccessJSON(map[string]interface{}{
  9404. "msg": "修改成功",
  9405. })
  9406. } else {
  9407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9408. return
  9409. }
  9410. } else if settle_type == 2 {
  9411. timeLayout := "2006-01-02"
  9412. loc, _ := time.LoadLocation("Local")
  9413. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9414. if err != nil {
  9415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9416. return
  9417. }
  9418. recordStartTime := theStartTime.Unix()
  9419. start_time_timestamp := recordStartTime
  9420. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9421. if err != nil {
  9422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9423. return
  9424. }
  9425. recordEndTime := theEndTime.Unix()
  9426. end_time_timestamp := recordEndTime
  9427. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9428. if updateErr == nil {
  9429. this.ServeSuccessJSON(map[string]interface{}{
  9430. "msg": "修改成功",
  9431. })
  9432. } else {
  9433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9434. return
  9435. }
  9436. }
  9437. }
  9438. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9439. patient_id, _ := c.GetInt64("patient_id")
  9440. his_patient_id, _ := c.GetInt64("his_patient_id")
  9441. record_date := c.GetString("record_date")
  9442. start_time := c.GetString("start_time")
  9443. end_time := c.GetString("end_time")
  9444. order_status, _ := c.GetInt64("type", 0)
  9445. p_type, _ := c.GetInt64("p_type", 0)
  9446. order_id, _ := c.GetInt64("order_id", 0)
  9447. timeLayout := "2006-01-02"
  9448. loc, _ := time.LoadLocation("Local")
  9449. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9450. if err != nil {
  9451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9452. return
  9453. }
  9454. recordDateTime := theTime.Unix()
  9455. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9456. if err != nil {
  9457. }
  9458. startRecordDateTime := startTime.Unix()
  9459. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9460. if err != nil {
  9461. }
  9462. endRecordDateTime := endTime.Unix()
  9463. admin := c.GetAdminUserInfo()
  9464. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9465. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9466. order, _ := service.GetHisOrderByID(order_id)
  9467. var monthPrescriptions []*models.HisPrescription
  9468. if order_status == 1 || order_status == 0 {
  9469. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9470. } else if order_status == 2 {
  9471. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9472. }
  9473. var settle_total float64
  9474. for _, item := range monthPrescriptions {
  9475. if len(item.HisPrescriptionProject) > 0 {
  9476. for _, subItem := range item.HisPrescriptionProject {
  9477. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9478. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9479. settle_total = settle_total + total
  9480. }
  9481. }
  9482. if len(item.HisDoctorAdviceInfo) > 0 {
  9483. for _, subItem := range item.HisDoctorAdviceInfo {
  9484. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9485. settle_total = settle_total + total
  9486. }
  9487. }
  9488. }
  9489. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9490. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9491. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9492. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9493. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9494. //获取所有科室信息
  9495. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9496. c.ServeSuccessJSON(map[string]interface{}{
  9497. "his_info": his_patient_info,
  9498. "xt_info": xt_patient_info,
  9499. "case_history": case_history,
  9500. "info": patientPrescriptionInfo,
  9501. "last_info": lastPatientPrescriptionInfo,
  9502. "month_prescriptions": monthPrescriptions,
  9503. "order": order,
  9504. "doctors": doctors,
  9505. "department": department,
  9506. "settle_total": settle_total,
  9507. })
  9508. return
  9509. }
  9510. func (c *HisApiController) GetHisMonthPatientInfo() {
  9511. patient_id, _ := c.GetInt64("patient_id")
  9512. his_patient_id, _ := c.GetInt64("his_patient_id")
  9513. record_date := c.GetString("record_date")
  9514. number := c.GetString("number")
  9515. start_time := c.GetString("start_time")
  9516. end_time := c.GetString("end_time")
  9517. p_type, _ := c.GetInt64("p_type")
  9518. timeLayout := "2006-01-02"
  9519. loc, _ := time.LoadLocation("Local")
  9520. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9521. if err != nil {
  9522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9523. return
  9524. }
  9525. recordDateTime := theTime.Unix()
  9526. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9527. if err != nil {
  9528. }
  9529. startRecordDateTime := startTime.Unix()
  9530. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9531. if err != nil {
  9532. }
  9533. endRecordDateTime := endTime.Unix()
  9534. admin := c.GetAdminUserInfo()
  9535. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9536. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9537. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9538. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9539. var settle_total float64
  9540. for _, item := range monthPrescriptions {
  9541. if len(item.HisPrescriptionProject) > 0 {
  9542. for _, subItem := range item.HisPrescriptionProject {
  9543. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9544. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9545. settle_total = settle_total + total
  9546. }
  9547. }
  9548. if len(item.HisDoctorAdviceInfo) > 0 {
  9549. for _, subItem := range item.HisDoctorAdviceInfo {
  9550. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9551. settle_total = settle_total + total
  9552. }
  9553. }
  9554. }
  9555. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9556. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9557. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9558. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9559. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9560. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9561. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9562. //获取所有科室信息
  9563. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9564. c.ServeSuccessJSON(map[string]interface{}{
  9565. "his_info": his_patient_info,
  9566. "xt_info": xt_patient_info,
  9567. "case_history": case_history,
  9568. "info": patientPrescriptionInfo,
  9569. "month_prescriptions": monthPrescriptions,
  9570. "order": order,
  9571. "doctors": doctors,
  9572. "department": department,
  9573. "count": count,
  9574. "drugStockConfig": drugStockConfig,
  9575. "last_info": lastPatientPrescriptionInfo,
  9576. "settle_total": settle_total,
  9577. })
  9578. return
  9579. }
  9580. func (c *HisApiController) GetAllOrder() {
  9581. org_id := c.GetAdminUserInfo().CurrentOrgId
  9582. orders, _ := service.GetNewHisOrderList(org_id)
  9583. c.ServeSuccessJSON(map[string]interface{}{
  9584. "order": orders,
  9585. })
  9586. return
  9587. }
  9588. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9589. newArr = make([]*models.HisOrderInfoTwo, 0)
  9590. for i := 0; i < len(arr); i++ {
  9591. repeat := false
  9592. for j := i + 1; j < len(arr); j++ {
  9593. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9594. repeat = true
  9595. break
  9596. }
  9597. }
  9598. if !repeat {
  9599. newArr = append(newArr, arr[i])
  9600. }
  9601. }
  9602. return
  9603. }
  9604. // 修改处方退库操作 参数传修改之前的处方数据
  9605. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9606. if advice.ExecutionState == 1 {
  9607. //查询该病人该药品是否有库存记录
  9608. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9609. if errcode == gorm.ErrRecordNotFound {
  9610. } else {
  9611. //退库
  9612. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9613. if advice.PrescribingNumberUnit == drug.MinUnit {
  9614. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9615. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9616. //退库
  9617. warehouseInfo := models.DrugWarehouseInfo{
  9618. StockMinNumber: prescribingNumber,
  9619. }
  9620. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9621. operation_time := time.Now().Unix()
  9622. creater := advice.AdviceDoctor
  9623. ctime := time.Now().Unix()
  9624. timeStr := time.Now().Format("2006-01-02")
  9625. timeArr := strings.Split(timeStr, "-")
  9626. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9627. total = total + 1
  9628. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9629. cancelStock := models.DrugCancelStock{
  9630. OrderNumber: orderNumber,
  9631. OperaTime: operation_time,
  9632. OrgId: advice.UserOrgId,
  9633. Creater: creater,
  9634. Ctime: ctime,
  9635. Status: 1,
  9636. ReturnTime: advice.AdviceDate,
  9637. Dealer: info.Dealer,
  9638. Manufacturer: info.Manufacturer,
  9639. Type: 1,
  9640. }
  9641. service.AddSigleDrugCancelStock(&cancelStock)
  9642. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9643. dealer, _ := service.GetDealerById(info.Dealer)
  9644. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9645. cancelStockInfo := models.DrugCancelStockInfo{
  9646. OrderNumber: cancelInfo.OrderNumber,
  9647. CancelStockId: cancelInfo.ID,
  9648. DrugId: info.DrugId,
  9649. Count: info.Count,
  9650. Status: 1,
  9651. Ctime: ctime,
  9652. OrgId: advice.UserOrgId,
  9653. Type: 1,
  9654. Manufacturer: manufactureName.ManufacturerName,
  9655. Dealer: dealer.DealerName,
  9656. Total: 0,
  9657. RetailPrice: info.RetailPrice,
  9658. RetailTotalPrice: info.RetailTotalPrice,
  9659. Price: info.Price,
  9660. RegisterAccount: "",
  9661. Remark: info.Remark,
  9662. BatchNumber: info.BatchNumber,
  9663. MaxUnit: info.CountUnit,
  9664. ProductDate: info.ProductDate,
  9665. ExpiryDate: info.ExpiryDate,
  9666. BatchNumberId: info.WarehouseInfoId,
  9667. }
  9668. flow := models.DrugFlow{
  9669. WarehousingId: 0,
  9670. DrugId: info.DrugId,
  9671. Number: "",
  9672. BatchNumber: info.BatchNumber,
  9673. Count: info.Count,
  9674. UserOrgId: advice.UserOrgId,
  9675. PatientId: 0,
  9676. SystemTime: ctime,
  9677. ConsumableType: 4,
  9678. IsSys: 0,
  9679. WarehousingOrder: "",
  9680. WarehouseOutId: 0,
  9681. WarehouseOutOrderNumber: "",
  9682. IsEdit: 0,
  9683. CancelStockId: cancelStock.ID,
  9684. CancelOrderNumber: cancelStock.OrderNumber,
  9685. Manufacturer: info.Manufacturer,
  9686. Dealer: info.Dealer,
  9687. Creator: advice.UserOrgId,
  9688. UpdateCreator: 0,
  9689. Status: 1,
  9690. Ctime: time.Now().Unix(),
  9691. Mtime: 0,
  9692. Price: info.Price,
  9693. WarehousingDetailId: 0,
  9694. WarehouseOutDetailId: 0,
  9695. CancelOutDetailId: 0,
  9696. ExpireDate: info.ExpiryDate,
  9697. ProductDate: info.ProductDate,
  9698. MaxUnit: info.CountUnit,
  9699. MinUnit: "",
  9700. }
  9701. service.CreatedCancelStock(cancelStockInfo)
  9702. service.CreateDrugFlowOne(flow)
  9703. } else {
  9704. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9705. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9706. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9707. warehouseInfo := models.DrugWarehouseInfo{
  9708. StockMinNumber: prescribingNumber,
  9709. }
  9710. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9711. }
  9712. operation_time := time.Now().Unix()
  9713. creater := advice.AdviceDoctor
  9714. ctime := time.Now().Unix()
  9715. timeStr := time.Now().Format("2006-01-02")
  9716. timeArr := strings.Split(timeStr, "-")
  9717. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9718. total = total + 1
  9719. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9720. cancelStock := models.DrugCancelStock{
  9721. OrderNumber: orderNumber,
  9722. OperaTime: operation_time,
  9723. OrgId: advice.UserOrgId,
  9724. Creater: creater,
  9725. Ctime: ctime,
  9726. Status: 1,
  9727. ReturnTime: advice.AdviceDate,
  9728. Dealer: info.Dealer,
  9729. Manufacturer: info.Manufacturer,
  9730. Type: 1,
  9731. }
  9732. service.AddSigleDrugCancelStock(&cancelStock)
  9733. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9734. dealer, _ := service.GetDealerById(info.Dealer)
  9735. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9736. cancelStockInfo := models.DrugCancelStockInfo{
  9737. OrderNumber: cancelInfo.OrderNumber,
  9738. CancelStockId: cancelInfo.ID,
  9739. DrugId: info.DrugId,
  9740. Count: info.Count,
  9741. Status: 1,
  9742. Ctime: ctime,
  9743. OrgId: advice.UserOrgId,
  9744. Type: 1,
  9745. Manufacturer: manufactureName.ManufacturerName,
  9746. Dealer: dealer.DealerName,
  9747. Total: 0,
  9748. RetailPrice: info.RetailPrice,
  9749. RetailTotalPrice: info.RetailTotalPrice,
  9750. Price: info.Price,
  9751. RegisterAccount: "",
  9752. Remark: info.Remark,
  9753. BatchNumber: info.BatchNumber,
  9754. MaxUnit: info.CountUnit,
  9755. ProductDate: info.ProductDate,
  9756. ExpiryDate: info.ExpiryDate,
  9757. BatchNumberId: info.WarehouseInfoId,
  9758. }
  9759. flow := models.DrugFlow{
  9760. WarehousingId: 0,
  9761. DrugId: info.DrugId,
  9762. Number: "",
  9763. BatchNumber: info.BatchNumber,
  9764. Count: info.Count,
  9765. UserOrgId: advice.UserOrgId,
  9766. PatientId: 0,
  9767. SystemTime: ctime,
  9768. ConsumableType: 4,
  9769. IsSys: 0,
  9770. WarehousingOrder: "",
  9771. WarehouseOutId: 0,
  9772. WarehouseOutOrderNumber: "",
  9773. IsEdit: 0,
  9774. CancelStockId: cancelStock.ID,
  9775. CancelOrderNumber: cancelStock.OrderNumber,
  9776. Manufacturer: info.Manufacturer,
  9777. Dealer: info.Dealer,
  9778. Creator: advice.AdviceDoctor,
  9779. UpdateCreator: 0,
  9780. Status: 1,
  9781. Ctime: time.Now().Unix(),
  9782. Mtime: 0,
  9783. Price: info.Price,
  9784. WarehousingDetailId: 0,
  9785. WarehouseOutDetailId: 0,
  9786. CancelOutDetailId: 0,
  9787. ExpireDate: info.ExpiryDate,
  9788. ProductDate: info.ProductDate,
  9789. MaxUnit: info.CountUnit,
  9790. MinUnit: "",
  9791. }
  9792. service.CreatedCancelStock(cancelStockInfo)
  9793. service.CreateDrugFlowOne(flow)
  9794. }
  9795. }
  9796. }
  9797. return err
  9798. }
  9799. func (this *HisApiController) DeleteNCDS() {
  9800. id, _ := this.GetInt64("id", 0)
  9801. if id > 0 {
  9802. service.DeletePsnNCDSRecordById(id)
  9803. this.ServeSuccessJSON(map[string]interface{}{
  9804. "msg": "删除成功",
  9805. })
  9806. } else {
  9807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9808. return
  9809. }
  9810. }
  9811. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9812. id, _ := c.GetInt64("id")
  9813. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9814. c.ServeSuccessJSON(map[string]interface{}{
  9815. "advice": advice,
  9816. })
  9817. return
  9818. }
  9819. func (c *HisApiController) GetHisMonthChargePatientList() {
  9820. record_date := c.GetString("record_date")
  9821. start_time := c.GetString("start_time")
  9822. end_time := c.GetString("end_time")
  9823. timeLayout := "2006-01-02"
  9824. loc, _ := time.LoadLocation("Local")
  9825. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9826. if err != nil {
  9827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9828. return
  9829. }
  9830. if err != nil {
  9831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9832. return
  9833. }
  9834. recordDateTime := theTime.Unix()
  9835. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9836. if err != nil {
  9837. }
  9838. startRecordDateTime := startTime.Unix()
  9839. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9840. if err != nil {
  9841. }
  9842. endRecordDateTime := endTime.Unix()
  9843. adminInfo := c.GetAdminUserInfo()
  9844. var tempMonthChargePatients []*service.MonthChargePatients
  9845. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9846. for _, item := range tempPatients {
  9847. //过滤没有处方的
  9848. if len(item.HisPrescription) == 0 {
  9849. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9850. }
  9851. }
  9852. c.ServeSuccessJSON(map[string]interface{}{
  9853. "list": tempMonthChargePatients,
  9854. })
  9855. }